VirtualBox

Changeset 82189 in vbox for trunk/src


Ignore:
Timestamp:
Nov 25, 2019 5:37:49 PM (5 years ago)
Author:
vboxsync
Message:

DevPS2: Saved state, prefixes, ++. bugref:9218

Location:
trunk/src/VBox/Devices/Input
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Input/DevPS2.cpp

    r82173 r82189  
    462462#ifdef IN_RING3
    463463
    464 static void kbd_reset(void *opaque)
    465 {
    466     KBDState *s = (KBDState*)opaque;
    467     s->mode = KBD_MODE_KBD_INT | KBD_MODE_MOUSE_INT;
    468     s->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED;
    469     /* Resetting everything, keyword was not working right on NT4 reboot. */
    470     s->write_cmd = 0;
    471     s->translate = 0;
    472 }
    473 
    474 static void kbd_save(PSSMHANDLE pSSM, KBDState *s)
    475 {
    476     SSMR3PutU8(pSSM, s->write_cmd);
    477     SSMR3PutU8(pSSM, s->status);
    478     SSMR3PutU8(pSSM, s->mode);
    479     SSMR3PutU8(pSSM, s->dbbout);
    480 
    481     /* terminator */
    482     SSMR3PutU32(pSSM, UINT32_MAX);
    483 }
    484 
    485 static int kbd_load(PSSMHANDLE pSSM, KBDState *s, uint32_t version_id)
     464static int kbd_load(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, KBDState *s, uint32_t version_id)
    486465{
    487466    uint32_t    u32, i;
     
    498477    if (version_id < 2 || version_id > PCKBD_SAVED_STATE_VERSION)
    499478        return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
    500     SSMR3GetU8(pSSM, &s->write_cmd);
    501     SSMR3GetU8(pSSM, &s->status);
    502     SSMR3GetU8(pSSM, &s->mode);
     479    pHlp->pfnSSMGetU8(pSSM, &s->write_cmd);
     480    pHlp->pfnSSMGetU8(pSSM, &s->status);
     481    pHlp->pfnSSMGetU8(pSSM, &s->mode);
    503482    if (version_id <= 5)
    504483    {
    505         SSMR3GetU32(pSSM, &u32Dummy);
    506         SSMR3GetU32(pSSM, &u32Dummy);
     484        pHlp->pfnSSMGetU32(pSSM, &u32Dummy);
     485        pHlp->pfnSSMGetU32(pSSM, &u32Dummy);
    507486    }
    508487    else
    509488    {
    510         SSMR3GetU8(pSSM, &s->dbbout);
     489        pHlp->pfnSSMGetU8(pSSM, &s->dbbout);
    511490    }
    512491    if (version_id <= 7)
     
    517496        uint8_t     u8Proto;
    518497
    519         SSMR3GetU32(pSSM, &u32Dummy);
    520         SSMR3GetU8(pSSM, &u8State);
    521         SSMR3GetU8(pSSM, &u8Dummy);
    522         SSMR3GetU8(pSSM, &u8Rate);
    523         SSMR3GetU8(pSSM, &u8Dummy);
    524         SSMR3GetU8(pSSM, &u8Proto);
    525         SSMR3GetU8(pSSM, &u8Dummy);
    526         SSMR3GetS32(pSSM, &i32Dummy);
    527         SSMR3GetS32(pSSM, &i32Dummy);
    528         SSMR3GetS32(pSSM, &i32Dummy);
     498        pHlp->pfnSSMGetU32(pSSM, &u32Dummy);
     499        pHlp->pfnSSMGetU8(pSSM, &u8State);
     500        pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
     501        pHlp->pfnSSMGetU8(pSSM, &u8Rate);
     502        pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
     503        pHlp->pfnSSMGetU8(pSSM, &u8Proto);
     504        pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
     505        pHlp->pfnSSMGetS32(pSSM, &i32Dummy);
     506        pHlp->pfnSSMGetS32(pSSM, &i32Dummy);
     507        pHlp->pfnSSMGetS32(pSSM, &i32Dummy);
    529508        if (version_id > 2)
    530509        {
    531             SSMR3GetS32(pSSM, &i32Dummy);
    532             SSMR3GetS32(pSSM, &i32Dummy);
     510            pHlp->pfnSSMGetS32(pSSM, &i32Dummy);
     511            pHlp->pfnSSMGetS32(pSSM, &i32Dummy);
    533512        }
    534         rc = SSMR3GetU8(pSSM, &u8Dummy);
     513        rc = pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
    535514        if (version_id == 4)
    536515        {
    537             SSMR3GetU32(pSSM, &u32Dummy);
    538             rc = SSMR3GetU32(pSSM, &u32Dummy);
     516            pHlp->pfnSSMGetU32(pSSM, &u32Dummy);
     517            rc = pHlp->pfnSSMGetU32(pSSM, &u32Dummy);
    539518        }
    540519        if (version_id > 3)
    541             rc = SSMR3GetU8(pSSM, &u8Dummy);
     520            rc = pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
    542521        if (version_id == 4)
    543             rc = SSMR3GetU8(pSSM, &u8Dummy);
     522            rc = pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
    544523        AssertLogRelRCReturn(rc, rc);
    545524
    546         PS2MFixupState(&s->Aux, u8State, u8Rate, u8Proto);
     525        PS2MR3FixupState(&s->Aux, u8State, u8Rate, u8Proto);
    547526    }
    548527
     
    555534    if (version_id <= 5)
    556535    {
    557         rc = SSMR3GetU32(pSSM, &u32);
     536        rc = pHlp->pfnSSMGetU32(pSSM, &u32);
    558537        if (RT_FAILURE(rc))
    559538            return rc;
    560539        for (i = 0; i < u32; i++)
    561540        {
    562             rc = SSMR3GetU8(pSSM, &u8Dummy);
     541            rc = pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
    563542            if (RT_FAILURE(rc))
    564543                return rc;
     
    569548    if (version_id <= 7)
    570549    {
    571         rc = SSMR3GetU32(pSSM, &u32);
     550        rc = pHlp->pfnSSMGetU32(pSSM, &u32);
    572551        if (RT_FAILURE(rc))
    573552            return rc;
    574553        for (i = 0; i < u32; i++)
    575554        {
    576             rc = SSMR3GetU8(pSSM, &u8Dummy);
     555            rc = pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
    577556            if (RT_FAILURE(rc))
    578557                return rc;
     
    580559        Log(("kbd_load: %d mouse event queue items discarded from old saved state\n", u32));
    581560
    582         rc = SSMR3GetU32(pSSM, &u32);
     561        rc = pHlp->pfnSSMGetU32(pSSM, &u32);
    583562        if (RT_FAILURE(rc))
    584563            return rc;
    585564        for (i = 0; i < u32; i++)
    586565        {
    587             rc = SSMR3GetU8(pSSM, &u8Dummy);
     566            rc = pHlp->pfnSSMGetU8(pSSM, &u8Dummy);
    588567            if (RT_FAILURE(rc))
    589568                return rc;
     
    593572
    594573    /* terminator */
    595     rc = SSMR3GetU32(pSSM, &u32);
     574    rc = pHlp->pfnSSMGetU32(pSSM, &u32);
    596575    if (RT_FAILURE(rc))
    597576        return rc;
     
    603582    return 0;
    604583}
     584
    605585#endif /* IN_RING3 */
    606586
     
    624604{
    625605    uint32_t    fluff = 0;
    626     KBDState    *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     606    PKBDSTATE    pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    627607
    628608    NOREF(pvUser);
     
    684664{
    685665    uint32_t    fluff = 0;
    686     KBDState    *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     666    PKBDSTATE    pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    687667
    688668    NOREF(pvUser);
     
    730710}
    731711
     712/**
     713 * Clear a queue.
     714 *
     715 * @param   pQ                  Pointer to the queue.
     716 */
     717void PS2CmnClearQueue(GeneriQ *pQ)
     718{
     719    LogFlowFunc(("Clearing queue %p\n", pQ));
     720    pQ->wpos  = pQ->rpos;
     721    pQ->cUsed = 0;
     722}
     723
     724
     725/**
     726 * Add a byte to a queue.
     727 *
     728 * @param   pQ                  Pointer to the queue.
     729 * @param   val                 The byte to store.
     730 */
     731void PS2CmnInsertQueue(GeneriQ *pQ, uint8_t val)
     732{
     733    /* Check if queue is full. */
     734    if (pQ->cUsed >= pQ->cSize)
     735    {
     736        LogRelFlowFunc(("queue %p full (%d entries)\n", pQ, pQ->cUsed));
     737        return;
     738    }
     739    /* Insert data and update circular buffer write position. */
     740    pQ->abQueue[pQ->wpos] = val;
     741    if (++pQ->wpos == pQ->cSize)
     742        pQ->wpos = 0;   /* Roll over. */
     743    ++pQ->cUsed;
     744    LogRelFlowFunc(("inserted 0x%02X into queue %p\n", val, pQ));
     745}
     746
    732747#ifdef IN_RING3
    733748
    734749/**
    735  * Saves a state of the keyboard device.
     750 * Save a queue state.
     751 *
     752 * @param   pHlp                The device helpers.
     753 * @param   pSSM                SSM handle to write the state to.
     754 * @param   pQ                  Pointer to the queue.
     755 */
     756void PS2CmnR3SaveQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, GeneriQ *pQ)
     757{
     758    uint32_t    cItems = pQ->cUsed;
     759    uint32_t    i;
     760
     761    /* Only save the number of items. Note that the read/write
     762     * positions aren't saved as they will be rebuilt on load.
     763     */
     764    pHlp->pfnSSMPutU32(pSSM, cItems);
     765
     766    LogFlow(("Storing %d items from queue %p\n", cItems, pQ));
     767
     768    /* Save queue data - only the bytes actually used (typically zero). */
     769    for (i = pQ->rpos % pQ->cSize; cItems-- > 0; i = (i + 1) % pQ->cSize)
     770        pHlp->pfnSSMPutU8(pSSM, pQ->abQueue[i]);
     771}
     772
     773/**
     774 * Load a queue state.
     775 *
     776 * @param   pHlp                The device helpers.
     777 * @param   pSSM                SSM handle to read the state from.
     778 * @param   pQ                  Pointer to the queue.
     779 *
     780 * @return  int                 VBox status/error code.
     781 */
     782int PS2CmnR3LoadQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, GeneriQ *pQ)
     783{
     784    int         rc;
     785
     786    /* On load, always put the read pointer at zero. */
     787    rc = pHlp->pfnSSMGetU32(pSSM, &pQ->cUsed);
     788    AssertRCReturn(rc, rc);
     789
     790    LogFlow(("Loading %d items to queue %p\n", pQ->cUsed, pQ));
     791
     792    AssertMsgReturn(pQ->cUsed <= pQ->cSize, ("Saved size=%u, actual=%u\n", pQ->cUsed, pQ->cSize),
     793                    VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     794
     795    /* Recalculate queue positions and load data in one go. */
     796    pQ->rpos = 0;
     797    pQ->wpos = pQ->cUsed;
     798    return pHlp->pfnSSMGetMem(pSSM, pQ->abQueue, pQ->cUsed);
     799}
     800
     801
     802/**
     803 * @callback_method_impl{FNSSMDEVSAVEEXEC, Saves a state of the keyboard device.}
    736804 *
    737805 * @returns VBox status code.
     
    739807 * @param   pSSM  The handle to save the state to.
    740808 */
    741 static DECLCALLBACK(int) kbdSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    742 {
    743     KBDState    *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
    744     kbd_save(pSSM, pThis);
    745     PS2KSaveState(&pThis->Kbd, pSSM);
    746     PS2MSaveState(&pThis->Aux, pSSM);
     809static DECLCALLBACK(int) kbdR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     810{
     811    PKBDSTATE       pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
     812    PCPDMDEVHLPR3   pHlp = pDevIns->pHlpR3;
     813
     814    pHlp->pfnSSMPutU8(pSSM, pThis->write_cmd);
     815    pHlp->pfnSSMPutU8(pSSM, pThis->status);
     816    pHlp->pfnSSMPutU8(pSSM, pThis->mode);
     817    pHlp->pfnSSMPutU8(pSSM, pThis->dbbout);
     818    /* terminator */
     819    pHlp->pfnSSMPutU32(pSSM, UINT32_MAX);
     820
     821    PS2KR3SaveState(pDevIns, &pThis->Kbd, pSSM);
     822    PS2MR3SaveState(pDevIns, &pThis->Aux, pSSM);
    747823    return VINF_SUCCESS;
    748824}
     
    750826
    751827/**
    752  * Loads a saved keyboard device state.
    753  *
    754  * @returns VBox status code.
    755  * @param   pDevIns     The device instance.
    756  * @param   pSSM  The handle to the saved state.
    757  * @param   uVersion    The data unit version number.
    758  * @param   uPass       The data pass.
    759  */
    760 static DECLCALLBACK(int) kbdLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    761 {
    762     KBDState    *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     828 * @callback_method_impl{FNSSMDEVLOADEXEC, Loads a saved keyboard device state.}
     829 */
     830static DECLCALLBACK(int) kbdR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
     831{
     832    PKBDSTATE    pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    763833    int rc;
    764834
    765835    Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
    766     rc = kbd_load(pSSM, pThis, uVersion);
     836    rc = kbd_load(pDevIns->pHlpR3, pSSM, pThis, uVersion);
     837    AssertRCReturn(rc, rc);
     838
    767839    if (uVersion >= 6)
    768         rc = PS2KLoadState(&pThis->Kbd, pSSM, uVersion);
     840        rc = PS2KR3LoadState(pDevIns, &pThis->Kbd, pSSM, uVersion);
     841    AssertRCReturn(rc, rc);
     842
    769843    if (uVersion >= 8)
    770         rc = PS2MLoadState(&pThis->Aux, pSSM, uVersion);
     844        rc = PS2MR3LoadState(pDevIns, &pThis->Aux, pSSM, uVersion);
     845    AssertRCReturn(rc, rc);
    771846    return rc;
    772847}
     
    775850 * @callback_method_impl{FNSSMDEVLOADDONE, Key state fix-up after loading}
    776851 */
    777 static DECLCALLBACK(int) kbdLoadDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    778 {
    779     KBDState    *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
    780     int rc;
    781 
    782     rc = PS2KLoadDone(&pThis->Kbd, pSSM);
    783     return rc;
     852static DECLCALLBACK(int) kbdR3LoadDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     853{
     854    PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
     855    return PS2KR3LoadDone(&pThis->Kbd, pSSM);
    784856}
    785857
     
    790862 * @param   pDevIns     The device instance data.
    791863 */
    792 static DECLCALLBACK(void)  kbdReset(PPDMDEVINS pDevIns)
    793 {
    794     KBDState   *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
    795 
    796     kbd_reset(pThis);
    797     PS2KReset(&pThis->Kbd);
    798     PS2MReset(&pThis->Aux);
     864static DECLCALLBACK(void)  kbdR3Reset(PPDMDEVINS pDevIns)
     865{
     866    PKBDSTATE    pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
     867
     868    pThis->mode = KBD_MODE_KBD_INT | KBD_MODE_MOUSE_INT;
     869    pThis->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED;
     870    /* Resetting everything, keyword was not working right on NT4 reboot. */
     871    pThis->write_cmd = 0;
     872    pThis->translate = 0;
     873
     874    PS2KR3Reset(&pThis->Kbd);
     875    PS2MR3Reset(&pThis->Aux);
    799876}
    800877
     
    804881
    805882/**
    806  * Attach command.
    807  *
    808  * This is called to let the device attach to a driver for a specified LUN
    809  * during runtime. This is not called during VM construction, the device
    810  * constructor have to attach to all the available drivers.
    811  *
    812  * This is like plugging in the keyboard or mouse after turning on the PC.
    813  *
    814  * @returns VBox status code.
    815  * @param   pDevIns     The device instance.
    816  * @param   iLUN        The logical unit which is being detached.
    817  * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
     883 * @interface_method_impl{PDMDEVREGR3,pfnAttach}
     884 *
    818885 * @remark  The keyboard controller doesn't support this action, this is just
    819886 *          implemented to try out the driver<->device structure.
    820887 */
    821 static DECLCALLBACK(int)  kbdAttach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     888static DECLCALLBACK(int)  kbdR3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    822889{
    823890    int         rc;
    824     KBDState   *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     891    PKBDSTATE   pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    825892
    826893    AssertMsgReturn(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
     
    832899        /* LUN #0: keyboard */
    833900        case 0:
    834             rc = PS2KAttach(&pThis->Kbd, pDevIns, iLUN, fFlags);
    835             if (RT_FAILURE(rc))
    836                 return rc;
     901            rc = PS2KR3Attach(&pThis->Kbd, pDevIns, iLUN, fFlags);
    837902            break;
    838903
    839904        /* LUN #1: aux/mouse */
    840905        case 1:
    841             rc = PS2MAttach(&pThis->Aux, pDevIns, iLUN, fFlags);
     906            rc = PS2MR3Attach(&pThis->Aux, pDevIns, iLUN, fFlags);
    842907            break;
    843908
     
    852917
    853918/**
    854  * Detach notification.
    855  *
    856  * This is called when a driver is detaching itself from a LUN of the device.
    857  * The device should adjust it's state to reflect this.
    858  *
    859  * This is like unplugging the network cable to use it for the laptop or
    860  * something while the PC is still running.
    861  *
    862  * @param   pDevIns     The device instance.
    863  * @param   iLUN        The logical unit which is being detached.
    864  * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
     919 * @interface_method_impl{PDMDEVREGR3,pfnDetach}
    865920 * @remark  The keyboard controller doesn't support this action, this is just
    866921 *          implemented to try out the driver<->device structure.
    867922 */
    868 static DECLCALLBACK(void)  kbdDetach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     923static DECLCALLBACK(void)  kbdR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    869924{
    870925#if 0
     
    872927     * Reset the interfaces and update the controller state.
    873928     */
    874     KBDState   *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     929    PKBDSTATE    pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    875930    switch (iLUN)
    876931    {
     
    898953
    899954/**
    900  * @copydoc FNPDMDEVRELOCATE
    901  */
    902 static DECLCALLBACK(void) kbdRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    903 {
    904     KBDState   *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     955 * @interface_method_impl{PDMDEVREGR3,pfnRelocate}
     956 */
     957static DECLCALLBACK(void) kbdR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
     958{
     959    PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    905960    pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    906     PS2KRelocate(&pThis->Kbd, offDelta, pDevIns);
    907     PS2MRelocate(&pThis->Aux, offDelta, pDevIns);
    908 }
    909 
    910 
    911 /**
    912  * @interface_method_impl{PDMDEVREG,pfnConstruct}
    913  */
    914 static DECLCALLBACK(int) kbdConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    915 {
    916     KBDState   *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     961    PS2KR3Relocate(&pThis->Kbd, offDelta, pDevIns);
     962    PS2MR3Relocate(&pThis->Aux, offDelta, pDevIns);
     963}
     964
     965
     966/**
     967 * @interface_method_impl{PDMDEVREGR3,pfnConstruct}
     968 */
     969static DECLCALLBACK(int) kbdR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
     970{
     971    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     972    PKBDSTATE   pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    917973    int         rc;
    918     bool        fGCEnabled;
    919     bool        fR0Enabled;
    920974    Assert(iInstance == 0);
    921 
    922     PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    923975
    924976    /*
    925977     * Validate and read the configuration.
    926978     */
    927     if (!CFGMR3AreValuesValid(pCfg, "GCEnabled\0R0Enabled\0KbdThrottleEnabled\0"))
    928         return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
    929     rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fGCEnabled, true);
    930     if (RT_FAILURE(rc))
    931         return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to query \"GCEnabled\" from the config"));
    932     rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true);
    933     if (RT_FAILURE(rc))
    934         return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to query \"R0Enabled\" from the config"));
    935     Log(("pckbd: fGCEnabled=%RTbool fR0Enabled=%RTbool\n", fGCEnabled, fR0Enabled));
    936 
     979    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns,  "KbdThrottleEnabled", "");
     980    Log(("pckbd: fRCEnabled=%RTbool fR0Enabled=%RTbool\n", pDevIns->fRCEnabled, pDevIns->fR0Enabled));
    937981
    938982    /*
     
    943987    pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    944988
    945     rc = PS2KConstruct(&pThis->Kbd, pDevIns, pThis, iInstance, pCfg);
    946     if (RT_FAILURE(rc))
    947         return rc;
    948 
    949     rc = PS2MConstruct(&pThis->Aux, pDevIns, pThis, iInstance);
    950     if (RT_FAILURE(rc))
    951         return rc;
     989    rc = PS2KR3Construct(&pThis->Kbd, pDevIns, pThis, iInstance, pCfg);
     990    AssertRCReturn(rc, rc);
     991
     992    rc = PS2MR3Construct(&pThis->Aux, pDevIns, pThis, iInstance);
     993    AssertRCReturn(rc, rc);
    952994
    953995    /*
    954      * Register I/O ports, save state, keyboard event handler and mouse event handlers.
     996     * Register I/O ports.
    955997     */
    956998    rc = PDMDevHlpIOPortRegister(pDevIns, 0x60, 1, NULL, kbdIOPortDataWrite,    kbdIOPortDataRead, NULL, NULL,   "PC Keyboard - Data");
    957     if (RT_FAILURE(rc))
    958         return rc;
     999    AssertRCReturn(rc, rc);
    9591000    rc = PDMDevHlpIOPortRegister(pDevIns, 0x64, 1, NULL, kbdIOPortCommandWrite, kbdIOPortStatusRead, NULL, NULL, "PC Keyboard - Command / Status");
    960     if (RT_FAILURE(rc))
    961         return rc;
    962     if (fGCEnabled)
     1001    AssertRCReturn(rc, rc);
     1002    if (pDevIns->fRCEnabled)
    9631003    {
    9641004        rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x60, 1, 0, "kbdIOPortDataWrite",    "kbdIOPortDataRead", NULL, NULL,   "PC Keyboard - Data");
     
    9691009            return rc;
    9701010    }
    971     if (fR0Enabled)
     1011    if (pDevIns->fR0Enabled)
    9721012    {
    9731013        rc = PDMDevHlpIOPortRegisterR0(pDevIns, 0x60, 1, 0, "kbdIOPortDataWrite",    "kbdIOPortDataRead", NULL, NULL,   "PC Keyboard - Data");
     
    9781018            return rc;
    9791019    }
     1020
     1021    /*
     1022     * Saved state.
     1023     */
    9801024    rc = PDMDevHlpSSMRegisterEx(pDevIns, PCKBD_SAVED_STATE_VERSION, sizeof(*pThis), NULL,
    9811025                                NULL, NULL, NULL,
    982                                 NULL, kbdSaveExec, NULL,
    983                                 NULL, kbdLoadExec, kbdLoadDone);
    984     if (RT_FAILURE(rc))
    985         return rc;
     1026                                NULL, kbdR3SaveExec, NULL,
     1027                                NULL, kbdR3LoadExec, kbdR3LoadDone);
     1028    AssertRCReturn(rc, rc);
    9861029
    9871030    /*
    9881031     * Attach to the keyboard and mouse drivers.
    9891032     */
    990     rc = kbdAttach(pDevIns, 0 /* keyboard LUN # */, PDM_TACH_FLAGS_NOT_HOT_PLUG);
    991     if (RT_FAILURE(rc))
    992         return rc;
    993     rc = kbdAttach(pDevIns, 1 /* aux/mouse LUN # */, PDM_TACH_FLAGS_NOT_HOT_PLUG);
    994     if (RT_FAILURE(rc))
    995         return rc;
     1033    rc = kbdR3Attach(pDevIns, 0 /* keyboard LUN # */, PDM_TACH_FLAGS_NOT_HOT_PLUG);
     1034    AssertRCReturn(rc, rc);
     1035    rc = kbdR3Attach(pDevIns, 1 /* aux/mouse LUN # */, PDM_TACH_FLAGS_NOT_HOT_PLUG);
     1036    AssertRCReturn(rc, rc);
    9961037
    9971038    /*
    9981039     * Initialize the device state.
    9991040     */
    1000     kbdReset(pDevIns);
     1041    kbdR3Reset(pDevIns);
    10011042
    10021043    return VINF_SUCCESS;
     
    10281069    /* .pszRCMod = */               "VBoxDDRC.rc",
    10291070    /* .pszR0Mod = */               "VBoxDDR0.r0",
    1030     /* .pfnConstruct = */           kbdConstruct,
     1071    /* .pfnConstruct = */           kbdR3Construct,
    10311072    /* .pfnDestruct = */            NULL,
    1032     /* .pfnRelocate = */            kbdRelocate,
     1073    /* .pfnRelocate = */            kbdR3Relocate,
    10331074    /* .pfnMemSetup = */            NULL,
    10341075    /* .pfnPowerOn = */             NULL,
    1035     /* .pfnReset = */               kbdReset,
     1076    /* .pfnReset = */               kbdR3Reset,
    10361077    /* .pfnSuspend = */             NULL,
    10371078    /* .pfnResume = */              NULL,
    1038     /* .pfnAttach = */              kbdAttach,
    1039     /* .pfnDetach = */              kbdDetach,
     1079    /* .pfnAttach = */              kbdR3Attach,
     1080    /* .pfnDetach = */              kbdR3Detach,
    10401081    /* .pfnQueryInterface = */      NULL,
    10411082    /* .pfnInitComplete = */        NULL,
  • trunk/src/VBox/Devices/Input/DevPS2.h

    r82173 r82189  
    4040
    4141DEF_PS2Q_TYPE(GeneriQ, 1);
     42void PS2CmnClearQueue(GeneriQ *pQ);
     43void PS2CmnInsertQueue(GeneriQ *pQ, uint8_t val);
     44void PS2CmnR3SaveQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, GeneriQ *pQ);
     45int  PS2CmnR3LoadQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, GeneriQ *pQ);
    4246
    4347
     
    174178int  PS2KByteFromKbd(PPS2K pThis, uint8_t *pVal);
    175179
    176 int  PS2KConstruct(PPS2K pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance, PCFGMNODE pCfg);
    177 int  PS2KAttach(PPS2K pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
    178 void PS2KReset(PPS2K pThis);
    179 void PS2KRelocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
    180 void PS2KSaveState(PPS2K pThis, PSSMHANDLE pSSM);
    181 int  PS2KLoadState(PPS2K pThis, PSSMHANDLE pSSM, uint32_t uVersion);
    182 int  PS2KLoadDone(PPS2K pThis, PSSMHANDLE pSSM);
     180int  PS2KR3Construct(PPS2K pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance, PCFGMNODE pCfg);
     181int  PS2KR3Attach(PPS2K pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
     182void PS2KR3Reset(PPS2K pThis);
     183void PS2KR3Relocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
     184void PS2KR3SaveState(PPDMDEVINS pDevIns, PPS2K pThis, PSSMHANDLE pSSM);
     185int  PS2KR3LoadState(PPDMDEVINS pDevIns, PPS2K pThis, PSSMHANDLE pSSM, uint32_t uVersion);
     186int  PS2KR3LoadDone(PPS2K pThis, PSSMHANDLE pSSM);
    183187
    184188PS2K *KBDGetPS2KFromDevIns(PPDMDEVINS pDevIns);
     
    325329int  PS2MByteFromAux(PPS2M pThis, uint8_t *pVal);
    326330
    327 int  PS2MConstruct(PPS2M pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance);
    328 int  PS2MAttach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
    329 void PS2MReset(PPS2M pThis);
    330 void PS2MRelocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
    331 void PS2MSaveState(PPS2M pThis, PSSMHANDLE pSSM);
    332 int  PS2MLoadState(PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion);
    333 void PS2MFixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto);
     331int  PS2MR3Construct(PPS2M pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance);
     332int  PS2MR3Attach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
     333void PS2MR3Reset(PPS2M pThis);
     334void PS2MR3Relocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
     335void PS2MR3SaveState(PPDMDEVINS pDevIns, PPS2M pThis, PSSMHANDLE pSSM);
     336int  PS2MR3LoadState(PPDMDEVINS pDevIns, PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion);
     337void PS2MR3FixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto);
    334338
    335339PS2M *KBDGetPS2MFromDevIns(PPDMDEVINS pDevIns);
  • trunk/src/VBox/Devices/Input/DevPS2K.cpp

    r82173 r82189  
    377377#endif /* IN_RING3 */
    378378
    379 
    380 
    381 /**
    382  * Clear a queue.
    383  *
    384  * @param   pQ                  Pointer to the queue.
    385  */
    386 static void ps2kClearQueue(GeneriQ *pQ)
    387 {
    388     LogFlowFunc(("Clearing queue %p\n", pQ));
    389     pQ->wpos  = pQ->rpos;
    390     pQ->cUsed = 0;
    391 }
    392 
    393 
    394 /**
    395  * Add a byte to a queue.
    396  *
    397  * @param   pQ                  Pointer to the queue.
    398  * @param   val                 The byte to store.
    399  */
    400 static void ps2kInsertQueue(GeneriQ *pQ, uint8_t val)
    401 {
    402     /* Check if queue is full. */
    403     if (pQ->cUsed >= pQ->cSize)
    404     {
    405         LogRelFlowFunc(("queue %p full (%d entries)\n", pQ, pQ->cUsed));
    406         return;
    407     }
    408     /* Insert data and update circular buffer write position. */
    409     pQ->abQueue[pQ->wpos] = val;
    410     if (++pQ->wpos == pQ->cSize)
    411         pQ->wpos = 0;   /* Roll over. */
    412     ++pQ->cUsed;
    413     LogRelFlowFunc(("inserted 0x%02X into queue %p\n", val, pQ));
    414 }
    415 
    416379#ifdef IN_RING3
    417380
     
    425388 * @return  int                 VBox status/error code.
    426389 */
    427 static int ps2kInsertStrQueue(GeneriQ *pQ, const uint8_t *pStr, uint32_t uReserve)
     390static int ps2kR3InsertStrQueue(GeneriQ *pQ, const uint8_t *pStr, uint32_t uReserve)
    428391{
    429392    uint32_t    cbStr;
     
    452415
    453416/**
    454  * Save a queue state.
    455  *
    456  * @param   pSSM                SSM handle to write the state to.
    457  * @param   pQ                  Pointer to the queue.
    458  */
    459 static void ps2kSaveQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
    460 {
    461     uint32_t    cItems = pQ->cUsed;
    462     int         i;
    463 
    464     /* Only save the number of items. Note that the read/write
    465      * positions aren't saved as they will be rebuilt on load.
    466      */
    467     SSMR3PutU32(pSSM, cItems);
    468 
    469     LogFlow(("Storing %d items from queue %p\n", cItems, pQ));
    470 
    471     /* Save queue data - only the bytes actually used (typically zero). */
    472     for (i = pQ->rpos; cItems-- > 0; i = (i + 1) % pQ->cSize)
    473         SSMR3PutU8(pSSM, pQ->abQueue[i]);
    474 }
    475 
    476 /**
    477  * Load a queue state.
    478  *
    479  * @param   pSSM                SSM handle to read the state from.
    480  * @param   pQ                  Pointer to the queue.
    481  *
    482  * @return  int                 VBox status/error code.
    483  */
    484 static int ps2kLoadQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
    485 {
    486     /* On load, always put the read pointer at zero. */
    487     int rc = SSMR3GetU32(pSSM, &pQ->cUsed);
    488     AssertRCReturn(rc, rc);
    489     LogFlow(("Loading %u items to queue %p\n", pQ->cUsed, pQ));
    490     AssertMsgReturn(pQ->cUsed <= pQ->cSize, ("Saved size=%u, actual=%u\n", pQ->cUsed, pQ->cSize),
    491                     VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
    492 
    493     /* Recalculate queue positions and load data in one go. */
    494     pQ->rpos = 0;
    495     pQ->wpos = pQ->cUsed;
    496     rc = SSMR3GetMem(pSSM, pQ->abQueue, pQ->cUsed);
    497 
    498     return rc;
    499 }
    500 
    501 /**
    502417 * Notify listener about LEDs state change.
    503418 *
     
    505420 * @param   u8State         Bitfield which reflects LEDs state.
    506421 */
    507 static void ps2kNotifyLedsState(PPS2K pThis, uint8_t u8State)
     422static void ps2kR3NotifyLedsState(PPS2K pThis, uint8_t u8State)
    508423{
    509424
     
    528443 * @return  uint32_t            Number of items in queue.
    529444 */
    530 static uint32_t ps2kInQueue(GeneriQ *pQ)
     445static uint32_t ps2R3kInQueue(GeneriQ *pQ)
    531446{
    532447    return pQ->cUsed;
     
    597512{
    598513    LogFlowFunc(("Set keyboard defaults\n"));
    599     ps2kClearQueue((GeneriQ *)&pThis->keyQ);
     514    PS2CmnClearQueue((GeneriQ *)&pThis->keyQ);
    600515    /* Set default Scan Set 3 typematic values. */
    601516    /* Set default typematic rate/delay. */
     
    624539    {
    625540        case KCMD_ECHO:
    626             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ECHO);
     541            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ECHO);
    627542            pThis->u8CurrCmd = 0;
    628543            break;
    629544        case KCMD_READ_ID:
    630             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    631             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID1);
    632             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID2);
     545            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     546            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID1);
     547            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID2);
    633548            pThis->u8CurrCmd = 0;
    634549            break;
    635550        case KCMD_ENABLE:
    636551            pThis->fScanning = true;
    637             ps2kClearQueue((GeneriQ *)&pThis->keyQ);
     552            PS2CmnClearQueue((GeneriQ *)&pThis->keyQ);
    638553            ps2kStopTypematicRepeat(pThis);
    639             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     554            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    640555            pThis->u8CurrCmd = 0;
    641556            break;
     
    643558            pThis->fScanning = false;
    644559            ps2kSetDefaults(pThis); /* Also clears buffer/typematic state. */
    645             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     560            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    646561            pThis->u8CurrCmd = 0;
    647562            break;
    648563        case KCMD_SET_DEFAULT:
    649564            ps2kSetDefaults(pThis);
    650             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     565            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    651566            pThis->u8CurrCmd = 0;
    652567            break;
     
    656571        case KCMD_ALL_TMB:
    657572            /// @todo Set the key types here.
    658             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     573            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    659574            pThis->u8CurrCmd = 0;
    660575            break;
     
    666581            ps2kSetDefaults(pThis);
    667582            /// @todo reset more?
    668             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     583            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    669584            pThis->u8CurrCmd = cmd;
    670585            /* Delay BAT completion; the test may take hundreds of ms. */
     
    678593        case KCMD_TYPE_MK_BRK:
    679594        case KCMD_TYPE_MAKE:
    680             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     595            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    681596            pThis->u8CurrCmd = cmd;
    682597            break;
     
    690605#else
    691606                    {
    692                         ps2kNotifyLedsState(pThis, cmd);
     607                        ps2kR3NotifyLedsState(pThis, cmd);
    693608                        pThis->fNumLockOn = !!(cmd & 0x02); /* Sync internal Num Lock state. */
    694                         ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     609                        PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    695610                        pThis->u8LEDs = cmd;
    696611                        pThis->u8CurrCmd = 0;
     
    699614                    break;
    700615                case KCMD_SCANSET:
    701                     ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     616                    PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    702617                    if (cmd == 0)
    703                         ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8ScanSet);
     618                        PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8ScanSet);
    704619                    else if (cmd < 4)
    705620                    {
     
    712627                case KCMD_RATE_DELAY:
    713628                    ps2kSetupTypematic(pThis, cmd);
    714                     ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     629                    PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    715630                    pThis->u8CurrCmd = 0;
    716631                    break;
     
    725640        case KCMD_INVALID_1:
    726641        case KCMD_INVALID_2:
    727             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_RESEND);
     642            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_RESEND);
    728643            pThis->u8CurrCmd = 0;
    729644            break;
     
    770685#ifdef IN_RING3
    771686
    772 static int ps2kProcessKeyEvent(PPS2K pThis, uint32_t u32HidCode, bool fKeyDown)
     687static int ps2kR3ProcessKeyEvent(PPS2K pThis, uint32_t u32HidCode, bool fKeyDown)
    773688{
    774689    key_def const   *pKeyDef;
     
    912827            /* Feed the bytes to the queue if there is room. */
    913828            /// @todo Send overrun code if sequence won't fit?
    914             ps2kInsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
     829            ps2kR3InsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
    915830        }
    916831        else if (!(pKeyDef->keyFlags & (KF_NB | KF_PB)))
     
    967882            /* Feed the bytes to the queue if there is room. */
    968883            /// @todo Send overrun code if sequence won't fit?
    969             ps2kInsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
     884            ps2kR3InsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
    970885        }
    971886    }
     
    992907        /* Feed the bytes to the queue if there is room. */
    993908        /// @todo Send overrun code if sequence won't fit?
    994         ps2kInsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
     909        ps2kR3InsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
    995910    }
    996911
     
    1032947}
    1033948
    1034 /* Throttling timer to emulate the finite keyboard communication speed. A PS/2 keyboard is
     949/**
     950 * @callback_function_impl{FNTMTIMERDEV}
     951 *
     952 * Throttling timer to emulate the finite keyboard communication speed. A PS/2 keyboard is
    1035953 * limited by the serial link speed and cannot send much more than 1,000 bytes per second.
    1036954 * Some software (notably Borland Pascal and programs built with its run-time) relies on
     
    1043961 * done because it would needlessly slow things down.
    1044962 */
    1045 static DECLCALLBACK(void) ps2kThrottleTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
     963static DECLCALLBACK(void) ps2kR3ThrottleTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    1046964{
    1047965    RT_NOREF(pDevIns, pTimer);
     
    1057975     */
    1058976    pThis->fThrottleActive = false;
    1059     uHaveData = ps2kInQueue((GeneriQ *)&pThis->keyQ);
     977    uHaveData = ps2R3kInQueue((GeneriQ *)&pThis->keyQ);
    1060978    LogFlowFunc(("Have%s bytes\n", uHaveData ? "" : " no"));
    1061979    if (uHaveData)
     
    1065983}
    1066984
    1067 /* Timer handler for emulating typematic keys. Note that only the last key
    1068  * held down repeats (if typematic).
    1069  */
    1070 static DECLCALLBACK(void) ps2kTypematicTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
     985/**
     986 * @callback_function_impl{FNTMTIMERDEV,
     987 * Timer handler for emulating typematic keys.}
     988 *
     989 * @note    Note that only the last key held down repeats (if typematic).
     990 */
     991static DECLCALLBACK(void) ps2kR3TypematicTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    1071992{
    1072993    RT_NOREF(pDevIns, pTimer);
     
    10841005        if (pThis->enmTypematicState == KBD_TMS_REPEAT)
    10851006        {
    1086             ps2kProcessKeyEvent(pThis, pThis->u32TypematicKey, true /* Key down */ );
     1007            ps2kR3ProcessKeyEvent(pThis, pThis->u32TypematicKey, true /* Key down */ );
    10871008            TMTimerSetMillies(pThis->CTX_SUFF(pKbdTypematicTimer), pThis->uTypematicRepeat);
    10881009        }
     
    10901011}
    10911012
    1092 /* The keyboard BAT is specified to take several hundred milliseconds. We need
     1013/**
     1014 * @callback_function_impl{FNTMTIMERDEV}
     1015 *
     1016 * The keyboard BAT is specified to take several hundred milliseconds. We need
    10931017 * to delay sending the result to the host for at least a tiny little while.
    10941018 */
    1095 static DECLCALLBACK(void) ps2kDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
     1019static DECLCALLBACK(void) ps2kR3DelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    10961020{
    10971021    RT_NOREF(pDevIns, pTimer);
     
    11011025
    11021026    AssertMsg(pThis->u8CurrCmd == KCMD_RESET, ("u8CurrCmd=%02x\n", pThis->u8CurrCmd));
    1103     ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_BAT_OK);
     1027    PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_BAT_OK);
    11041028    pThis->fScanning = true;    /* BAT completion enables scanning! */
    11051029    pThis->u8CurrCmd = 0;
     
    11141038 * or resuming a suspended host.
    11151039 */
    1116 static void ps2kReleaseKeys(PPS2K pThis)
     1040static void ps2kR3ReleaseKeys(PPS2K pThis)
    11171041{
    11181042    LogFlowFunc(("Releasing keys...\n"));
     
    11211045        if (pThis->abDepressedKeys[uKey])
    11221046        {
    1123             ps2kProcessKeyEvent(pThis, RT_MAKE_U32(USB_HID_KB_PAGE, uKey), false /* key up */);
     1047            ps2kR3ProcessKeyEvent(pThis, RT_MAKE_U32(USB_HID_KB_PAGE, uKey), false /* key up */);
    11241048            pThis->abDepressedKeys[uKey] = 0;
    11251049        }
     
    11351059 * @param   pszArgs     Argument string. Optional and specific to the handler.
    11361060 */
    1137 static DECLCALLBACK(void) ps2kInfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     1061static DECLCALLBACK(void) ps2kR3InfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    11381062{
    11391063    PPS2K   pThis = KBDGetPS2KFromDevIns(pDevIns);
     
    11611085 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
    11621086 */
    1163 static DECLCALLBACK(void *) ps2kQueryInterface(PPDMIBASE pInterface, const char *pszIID)
     1087static DECLCALLBACK(void *) ps2kR3QueryInterface(PPDMIBASE pInterface, const char *pszIID)
    11641088{
    11651089    PPS2K pThis = RT_FROM_MEMBER(pInterface, PS2K, Keyboard.IBase);
     
    11801104 *                          press/release flag.
    11811105 */
    1182 static int ps2kPutEventWorker(PPS2K pThis, uint32_t u32Usage)
     1106static int ps2kR3PutEventWorker(PPS2K pThis, uint32_t u32Usage)
    11831107{
    11841108    uint32_t        u32HidCode;
     
    12211145        AssertReleaseRC(rc);
    12221146
    1223         rc = ps2kProcessKeyEvent(pThis, u32HidCode, fKeyDown);
     1147        rc = ps2kR3ProcessKeyEvent(pThis, u32HidCode, fKeyDown);
    12241148
    12251149        PDMCritSectLeave(pThis->pCritSectR3);
     
    12291153}
    12301154
    1231 static DECLCALLBACK(int) ps2kPutEventWrapper(PPDMIKEYBOARDPORT pInterface, uint32_t u32UsageCode)
     1155
     1156/**
     1157 * @interface_method_impl{PDMIKEYBOARDPORT,pfnPutEventHid}
     1158 */
     1159static DECLCALLBACK(int) ps2kR3KeyboardPort_PutEventHid(PPDMIKEYBOARDPORT pInterface, uint32_t u32UsageCode)
    12321160{
    12331161    PPS2K       pThis = RT_FROM_MEMBER(pInterface, PS2K, Keyboard.IPort);
     
    12441172    if (RT_UNLIKELY(u32UsageCode == KRSP_BAT_FAIL))
    12451173    {
    1246         ps2kReleaseKeys(pThis);
     1174        ps2kR3ReleaseKeys(pThis);
    12471175    }
    12481176    else
    12491177    {
    1250         ps2kPutEventWorker(pThis, u32UsageCode);
     1178        ps2kR3PutEventWorker(pThis, u32UsageCode);
    12511179    }
    12521180
     
    12721200 * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    12731201 */
    1274 int PS2KAttach(PPS2K pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     1202int PS2KR3Attach(PPS2K pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    12751203{
    12761204    int         rc;
     
    13051233}
    13061234
    1307 void PS2KSaveState(PPS2K pThis, PSSMHANDLE pSSM)
    1308 {
    1309     uint32_t    cPressed = 0;
    1310     uint32_t    cbTMSSize = 0;
     1235void PS2KR3SaveState(PPDMDEVINS pDevIns, PPS2K pThis, PSSMHANDLE pSSM)
     1236{
     1237    PCPDMDEVHLPR3   pHlp = pDevIns->pHlpR3;
     1238    uint32_t        cPressed = 0;
     1239    uint32_t        cbTMSSize = 0;
    13111240
    13121241    LogFlowFunc(("Saving PS2K state\n"));
    13131242
    13141243    /* Save the basic keyboard state. */
    1315     SSMR3PutU8(pSSM, pThis->u8CurrCmd);
    1316     SSMR3PutU8(pSSM, pThis->u8LEDs);
    1317     SSMR3PutU8(pSSM, pThis->u8TypematicCfg);
    1318     SSMR3PutU8(pSSM, (uint8_t)pThis->u32TypematicKey);
    1319     SSMR3PutU8(pSSM, pThis->u8Modifiers);
    1320     SSMR3PutU8(pSSM, pThis->u8ScanSet);
    1321     SSMR3PutU8(pSSM, pThis->enmTypematicState);
    1322     SSMR3PutBool(pSSM, pThis->fNumLockOn);
    1323     SSMR3PutBool(pSSM, pThis->fScanning);
     1244    pHlp->pfnSSMPutU8(pSSM, pThis->u8CurrCmd);
     1245    pHlp->pfnSSMPutU8(pSSM, pThis->u8LEDs);
     1246    pHlp->pfnSSMPutU8(pSSM, pThis->u8TypematicCfg);
     1247    pHlp->pfnSSMPutU8(pSSM, (uint8_t)pThis->u32TypematicKey);
     1248    pHlp->pfnSSMPutU8(pSSM, pThis->u8Modifiers);
     1249    pHlp->pfnSSMPutU8(pSSM, pThis->u8ScanSet);
     1250    pHlp->pfnSSMPutU8(pSSM, pThis->enmTypematicState);
     1251    pHlp->pfnSSMPutBool(pSSM, pThis->fNumLockOn);
     1252    pHlp->pfnSSMPutBool(pSSM, pThis->fScanning);
    13241253
    13251254    /* Save the command and keystroke queues. */
    1326     ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
    1327     ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->keyQ);
     1255    PS2CmnR3SaveQueue(pHlp, pSSM, (GeneriQ *)&pThis->cmdQ);
     1256    PS2CmnR3SaveQueue(pHlp, pSSM, (GeneriQ *)&pThis->keyQ);
    13281257
    13291258    /* Save the command delay timer. Note that the typematic repeat
     
    13391268            ++cPressed;
    13401269
    1341     SSMR3PutU32(pSSM, cPressed);
     1270    pHlp->pfnSSMPutU32(pSSM, cPressed);
    13421271
    13431272    for (unsigned uKey = 0; uKey < sizeof(pThis->abDepressedKeys); ++uKey)
    13441273        if (pThis->abDepressedKeys[uKey])
    1345             SSMR3PutU8(pSSM, uKey);
     1274            pHlp->pfnSSMPutU8(pSSM, uKey);
    13461275
    13471276    /* Save the typematic settings for Scan Set 3. */
    1348     SSMR3PutU32(pSSM, cbTMSSize);
     1277    pHlp->pfnSSMPutU32(pSSM, cbTMSSize);
    13491278    /* Currently not implemented. */
    13501279}
    13511280
    1352 int PS2KLoadState(PPS2K pThis, PSSMHANDLE pSSM, uint32_t uVersion)
    1353 {
    1354     uint8_t     u8;
    1355     uint32_t    cPressed;
    1356     uint32_t    cbTMSSize;
    1357     int         rc;
     1281int PS2KR3LoadState(PPDMDEVINS pDevIns, PPS2K pThis, PSSMHANDLE pSSM, uint32_t uVersion)
     1282{
     1283    PCPDMDEVHLPR3   pHlp = pDevIns->pHlpR3;
     1284    uint8_t         u8;
     1285    uint32_t        cPressed;
     1286    uint32_t        cbTMSSize;
     1287    int             rc;
    13581288
    13591289    NOREF(uVersion);
     
    13611291
    13621292    /* Load the basic keyboard state. */
    1363     SSMR3GetU8(pSSM, &pThis->u8CurrCmd);
    1364     SSMR3GetU8(pSSM, &pThis->u8LEDs);
    1365     SSMR3GetU8(pSSM, &pThis->u8TypematicCfg);
    1366     SSMR3GetU8(pSSM, &u8);
     1293    pHlp->pfnSSMGetU8(pSSM, &pThis->u8CurrCmd);
     1294    pHlp->pfnSSMGetU8(pSSM, &pThis->u8LEDs);
     1295    pHlp->pfnSSMGetU8(pSSM, &pThis->u8TypematicCfg);
     1296    pHlp->pfnSSMGetU8(pSSM, &u8);
    13671297    /* Reconstruct the 32-bit code from the 8-bit value in saved state. */
    13681298    pThis->u32TypematicKey = u8 ? RT_MAKE_U32(USB_HID_KB_PAGE, u8) : 0;
    1369     SSMR3GetU8(pSSM, &pThis->u8Modifiers);
    1370     SSMR3GetU8(pSSM, &pThis->u8ScanSet);
    1371     SSMR3GetU8(pSSM, &u8);
     1299    pHlp->pfnSSMGetU8(pSSM, &pThis->u8Modifiers);
     1300    pHlp->pfnSSMGetU8(pSSM, &pThis->u8ScanSet);
     1301    pHlp->pfnSSMGetU8(pSSM, &u8);
    13721302    pThis->enmTypematicState = (tmatic_state_t)u8;
    1373     SSMR3GetBool(pSSM, &pThis->fNumLockOn);
    1374     SSMR3GetBool(pSSM, &pThis->fScanning);
     1303    pHlp->pfnSSMGetBool(pSSM, &pThis->fNumLockOn);
     1304    pHlp->pfnSSMGetBool(pSSM, &pThis->fScanning);
    13751305
    13761306    /* Load the command and keystroke queues. */
    1377     rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
     1307    rc = PS2CmnR3LoadQueue(pHlp, pSSM, (GeneriQ *)&pThis->cmdQ);
    13781308    AssertRCReturn(rc, rc);
    1379     rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->keyQ);
     1309    rc = PS2CmnR3LoadQueue(pHlp, pSSM, (GeneriQ *)&pThis->keyQ);
    13801310    AssertRCReturn(rc, rc);
    13811311
     
    13881318
    13891319    /* Fake key up events for keys that were held down at the time the state was saved. */
    1390     rc = SSMR3GetU32(pSSM, &cPressed);
     1320    rc = pHlp->pfnSSMGetU32(pSSM, &cPressed);
    13911321    AssertRCReturn(rc, rc);
    13921322
     
    13961326        for (unsigned i = 0; i < cPressed; ++i)
    13971327        {
    1398             rc = SSMR3GetU8(pSSM, &u8);
     1328            rc = pHlp->pfnSSMGetU8(pSSM, &u8);
    13991329            AssertRCReturn(rc, rc);
    14001330            pThis->abDepressedKeys[u8] = 1;
     
    14031333
    14041334    /* Load typematic settings for Scan Set 3. */
    1405     rc = SSMR3GetU32(pSSM, &cbTMSSize);
     1335    rc = pHlp->pfnSSMGetU32(pSSM, &cbTMSSize);
    14061336    AssertRCReturn(rc, rc);
    14071337
    14081338    while (cbTMSSize--)
    14091339    {
    1410         rc = SSMR3GetU8(pSSM, &u8);
     1340        rc = pHlp->pfnSSMGetU8(pSSM, &u8);
    14111341        AssertRCReturn(rc, rc);
    14121342    }
     
    14151345}
    14161346
    1417 int PS2KLoadDone(PPS2K pThis, PSSMHANDLE pSSM)
     1347int PS2KR3LoadDone(PPS2K pThis, PSSMHANDLE pSSM)
    14181348{
    14191349    RT_NOREF(pSSM);
     
    14221352     * interrupts and change the interrupt controller state.
    14231353     */
    1424     ps2kReleaseKeys(pThis);
    1425     ps2kNotifyLedsState(pThis, pThis->u8LEDs);
     1354    ps2kR3ReleaseKeys(pThis);
     1355    ps2kR3NotifyLedsState(pThis, pThis->u8LEDs);
    14261356    return VINF_SUCCESS;
    14271357}
    14281358
    1429 void PS2KReset(PPS2K pThis)
     1359void PS2KR3Reset(PPS2K pThis)
    14301360{
    14311361    LogFlowFunc(("Resetting PS2K\n"));
     
    14411371    /* Clear queues and any pressed keys. */
    14421372    memset(pThis->abDepressedKeys, 0, sizeof(pThis->abDepressedKeys));
    1443     ps2kClearQueue((GeneriQ *)&pThis->cmdQ);
     1373    PS2CmnClearQueue((GeneriQ *)&pThis->cmdQ);
    14441374    ps2kSetDefaults(pThis);     /* Also clears keystroke queue. */
    14451375
     
    14491379}
    14501380
    1451 void PS2KRelocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
     1381void PS2KR3Relocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
    14521382{
    14531383    RT_NOREF(pDevIns);
     
    14591389}
    14601390
    1461 int PS2KConstruct(PPS2K pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance, PCFGMNODE pCfg)
    1462 {
     1391int PS2KR3Construct(PPS2K pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance, PCFGMNODE pCfg)
     1392{
     1393    PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
    14631394    RT_NOREF(pDevIns, iInstance);
    14641395    LogFlowFunc(("iInstance=%u\n", iInstance));
     
    14671398
    14681399    bool fThrottleEnabled;
    1469     int rc = CFGMR3QueryBoolDef(pCfg, "KbdThrottleEnabled", &fThrottleEnabled, true);
     1400    int rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "KbdThrottleEnabled", &fThrottleEnabled, true);
    14701401    if (RT_FAILURE(rc))
    14711402        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to query \"KbdThrottleEnabled\" from the config"));
    1472     Log(("KbdThrottleEnabled=%u\n", fThrottleEnabled));
     1403    Log(("KbdThrottleEnabled=%RTbool\n", fThrottleEnabled));
    14731404    pThis->fThrottleEnabled = fThrottleEnabled;
    14741405
     
    14771408    pThis->cmdQ.cSize = KBD_CMD_QUEUE_SIZE;
    14781409
    1479     pThis->Keyboard.IBase.pfnQueryInterface = ps2kQueryInterface;
    1480     pThis->Keyboard.IPort.pfnPutEventHid    = ps2kPutEventWrapper;
     1410    pThis->Keyboard.IBase.pfnQueryInterface = ps2kR3QueryInterface;
     1411    pThis->Keyboard.IPort.pfnPutEventHid    = ps2kR3KeyboardPort_PutEventHid;
    14811412
    14821413    /*
     
    14891420     */
    14901421    PTMTIMER pTimer;
    1491     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kThrottleTimer, pThis,
     1422    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3ThrottleTimer, pThis,
    14921423                                TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Throttle Timer", &pTimer);
    1493     if (RT_FAILURE(rc))
    1494         return rc;
     1424    AssertRCReturn(rc, rc);
    14951425
    14961426    pThis->pThrottleTimerR3 = pTimer;
     
    15011431     * Create the typematic delay/repeat timer.
    15021432     */
    1503     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kTypematicTimer, pThis,
     1433    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3TypematicTimer, pThis,
    15041434                                TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Typematic Timer", &pTimer);
    1505     if (RT_FAILURE(rc))
    1506         return rc;
     1435    AssertRCReturn(rc, rc);
    15071436
    15081437    pThis->pKbdTypematicTimerR3 = pTimer;
     
    15131442     * Create the command delay timer.
    15141443     */
    1515     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kDelayTimer, pThis,
     1444    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3DelayTimer, pThis,
    15161445                                TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Delay Timer", &pTimer);
    1517     if (RT_FAILURE(rc))
    1518         return rc;
     1446    AssertRCReturn(rc, rc);
    15191447
    15201448    pThis->pKbdDelayTimerR3 = pTimer;
     
    15251453     * Register debugger info callbacks.
    15261454     */
    1527     PDMDevHlpDBGFInfoRegister(pDevIns, "ps2k", "Display PS/2 keyboard state.", ps2kInfoState);
     1455    PDMDevHlpDBGFInfoRegister(pDevIns, "ps2k", "Display PS/2 keyboard state.", ps2kR3InfoState);
    15281456
    15291457    return rc;
    15301458}
    15311459
    1532 #endif
     1460#endif /* IN _RING3 */
    15331461
    15341462/// @todo The following should live with the KBC implementation.
  • trunk/src/VBox/Devices/Input/DevPS2M.cpp

    r82173 r82189  
    205205*********************************************************************************************************************************/
    206206#if defined(RT_STRICT) && defined(IN_RING3)
    207 static void ps2mTestAccumulation(void);
     207static void ps2mR3TestAccumulation(void);
    208208#endif
    209209
    210210
    211 /**
    212  * Clear a queue.
    213  *
    214  * @param   pQ                  Pointer to the queue.
    215  */
    216 static void ps2kClearQueue(GeneriQ *pQ)
    217 {
    218     LogFlowFunc(("Clearing queue %p\n", pQ));
    219     pQ->wpos  = pQ->rpos;
    220     pQ->cUsed = 0;
    221 }
    222 
    223 
    224 /**
    225  * Add a byte to a queue.
    226  *
    227  * @param   pQ                  Pointer to the queue.
    228  * @param   val                 The byte to store.
    229  */
    230 static void ps2kInsertQueue(GeneriQ *pQ, uint8_t val)
    231 {
    232     /* Check if queue is full. */
    233     if (pQ->cUsed >= pQ->cSize)
    234     {
    235         LogRelFlowFunc(("queue %p full (%d entries)\n", pQ, pQ->cUsed));
    236         return;
    237     }
    238     /* Insert data and update circular buffer write position. */
    239     pQ->abQueue[pQ->wpos] = val;
    240     if (++pQ->wpos == pQ->cSize)
    241         pQ->wpos = 0;   /* Roll over. */
    242     ++pQ->cUsed;
    243     LogRelFlowFunc(("inserted 0x%02X into queue %p\n", val, pQ));
    244 }
    245 
    246211#ifdef IN_RING3
    247212
    248 /**
    249  * Save a queue state.
    250  *
    251  * @param   pSSM                SSM handle to write the state to.
    252  * @param   pQ                  Pointer to the queue.
    253  */
    254 static void ps2kSaveQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
    255 {
    256     uint32_t    cItems = pQ->cUsed;
    257     int         i;
    258 
    259     /* Only save the number of items. Note that the read/write
    260      * positions aren't saved as they will be rebuilt on load.
    261      */
    262     SSMR3PutU32(pSSM, cItems);
    263 
    264     LogFlow(("Storing %d items from queue %p\n", cItems, pQ));
    265 
    266     /* Save queue data - only the bytes actually used (typically zero). */
    267     for (i = pQ->rpos; cItems-- > 0; i = (i + 1) % pQ->cSize)
    268         SSMR3PutU8(pSSM, pQ->abQueue[i]);
    269 }
    270 
    271 /**
    272  * Load a queue state.
    273  *
    274  * @param   pSSM                SSM handle to read the state from.
    275  * @param   pQ                  Pointer to the queue.
    276  *
    277  * @return  int                 VBox status/error code.
    278  */
    279 static int ps2kLoadQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
    280 {
    281     int         rc;
    282 
    283     /* On load, always put the read pointer at zero. */
    284     SSMR3GetU32(pSSM, &pQ->cUsed);
    285 
    286     LogFlow(("Loading %d items to queue %p\n", pQ->cUsed, pQ));
    287 
    288     if (pQ->cUsed > pQ->cSize)
    289     {
    290         AssertMsgFailed(("Saved size=%u, actual=%u\n", pQ->cUsed, pQ->cSize));
    291         return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
    292     }
    293 
    294     /* Recalculate queue positions and load data in one go. */
    295     pQ->rpos = 0;
    296     pQ->wpos = pQ->cUsed;
    297     rc = SSMR3GetMem(pSSM, pQ->abQueue, pQ->cUsed);
    298 
    299     return rc;
    300 }
    301 
    302213/* Report a change in status down (or is it up?) the driver chain. */
    303 static void ps2mSetDriverState(PPS2M pThis, bool fEnabled)
     214static void ps2mR3SetDriverState(PPS2M pThis, bool fEnabled)
    304215{
    305216    PPDMIMOUSECONNECTOR pDrv = pThis->Mouse.pDrv;
     
    309220
    310221/* Reset the pointing device. */
    311 static void ps2mReset(PPS2M pThis)
    312 {
    313     ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_BAT_OK);
    314     ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, 0);
     222static void ps2mR3Reset(PPS2M pThis)
     223{
     224    PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_BAT_OK);
     225    PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, 0);
    315226    pThis->enmMode   = AUX_MODE_STD;
    316227    pThis->u8CurrCmd = 0;
    317228
    318229    /// @todo move to its proper home!
    319     ps2mSetDriverState(pThis, true);
     230    ps2mR3SetDriverState(pThis, true);
    320231}
    321232
     
    369280
    370281    /* Event queue, eccumulators, and button status bits are cleared. */
    371     ps2kClearQueue((GeneriQ *)&pThis->evtQ);
     282    PS2CmnClearQueue((GeneriQ *)&pThis->evtQ);
    372283    pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->iAccumW = pThis->fAccumB = 0;
    373284}
     
    445356
    446357    /* Send the standard 3-byte packet (always the same). */
    447     ps2kInsertQueue(pQueue, val);
    448     ps2kInsertQueue(pQueue, dX);
    449     ps2kInsertQueue(pQueue, dY);
     358    PS2CmnInsertQueue(pQueue, val);
     359    PS2CmnInsertQueue(pQueue, dX);
     360    PS2CmnInsertQueue(pQueue, dY);
    450361
    451362    /* Add fourth byte if an extended protocol is in use. */
     
    458369        {
    459370            /* NB: Only uses 4-bit dZ range, despite using a full byte. */
    460             ps2kInsertQueue(pQueue, dZ);
     371            PS2CmnInsertQueue(pQueue, dZ);
    461372            pThis->iAccumZ -= dZ;
    462373        }
     
    467378           val |= dZ & 0x0f;
    468379           pThis->iAccumZ -= dZ;
    469            ps2kInsertQueue(pQueue, val);
     380           PS2CmnInsertQueue(pQueue, val);
    470381        }
    471382        else
     
    499410               val = (fBtnState & PS2M_IMEX_BTN_MASK) << 1;
    500411            }
    501             ps2kInsertQueue(pQueue, val);
     412            PS2CmnInsertQueue(pQueue, val);
    502413        }
    503414    }
     
    549460
    550461    /* If there's anything left in the command response queue, trash it. */
    551     ps2kClearQueue((GeneriQ *)&pThis->cmdQ);
     462    PS2CmnClearQueue((GeneriQ *)&pThis->cmdQ);
    552463
    553464    if (pThis->enmMode == AUX_MODE_WRAP)
     
    558469        else
    559470        {
    560             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, cmd);
     471            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, cmd);
    561472            return VINF_SUCCESS;
    562473        }
     
    573484        case ACMD_SET_SCALE_11:
    574485            pThis->u8State &= ~AUX_STATE_SCALING;
    575             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     486            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    576487            pThis->u8CurrCmd = 0;
    577488            break;
    578489        case ACMD_SET_SCALE_21:
    579490            pThis->u8State |= AUX_STATE_SCALING;
    580             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     491            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    581492            pThis->u8CurrCmd = 0;
    582493            break;
     
    584495            /* Report current status, sample rate, and resolution. */
    585496            u8Val  = (pThis->u8State & AUX_STATE_EXTERNAL) | (pThis->fCurrB & PS2M_STD_BTN_MASK);
    586             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    587             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val);
    588             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8Resolution);
    589             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8SampleRate);
     497            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     498            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val);
     499            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8Resolution);
     500            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8SampleRate);
    590501            pThis->u8CurrCmd = 0;
    591502            break;
    592503        case ACMD_SET_STREAM:
    593504            pThis->u8State &= ~AUX_STATE_REMOTE;
    594             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     505            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    595506            pThis->u8CurrCmd = 0;
    596507            break;
    597508        case ACMD_READ_REMOTE:
    598             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     509            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    599510            ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->cmdQ, false);
    600511            pThis->u8CurrCmd = 0;
     
    603514            pThis->enmMode = AUX_MODE_STD;
    604515            /* NB: Stream mode reporting remains disabled! */
    605             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     516            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    606517            pThis->u8CurrCmd = 0;
    607518            break;
     
    609520            pThis->enmMode = AUX_MODE_WRAP;
    610521            pThis->u8State &= ~AUX_STATE_ENABLED;
    611             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     522            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    612523            pThis->u8CurrCmd = 0;
    613524            break;
    614525        case ACMD_SET_REMOTE:
    615526            pThis->u8State |= AUX_STATE_REMOTE;
    616             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     527            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    617528            pThis->u8CurrCmd = 0;
    618529            break;
    619530        case ACMD_READ_ID:
    620             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     531            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    621532            /* ImEx + horizontal is protocol 4, just like plain ImEx. */
    622533            u8Val = pThis->enmProtocol == PS2M_PROTO_IMEX_HORZ ? PS2M_PROTO_IMEX : pThis->enmProtocol;
    623             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val);
     534            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val);
    624535            pThis->u8CurrCmd = 0;
    625536            break;
     
    627538            pThis->u8State |= AUX_STATE_ENABLED;
    628539#ifdef IN_RING3
    629             ps2mSetDriverState(pThis, true);
     540            ps2mR3SetDriverState(pThis, true);
    630541#else
    631542            AssertLogRelMsgFailed(("Invalid ACMD_ENABLE outside R3!\n"));
    632543#endif
    633             ps2kClearQueue((GeneriQ *)&pThis->evtQ);
    634             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     544            PS2CmnClearQueue((GeneriQ *)&pThis->evtQ);
     545            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    635546            pThis->u8CurrCmd = 0;
    636547            break;
    637548        case ACMD_DISABLE:
    638549            pThis->u8State &= ~AUX_STATE_ENABLED;
    639             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     550            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    640551            pThis->u8CurrCmd = 0;
    641552            break;
    642553        case ACMD_SET_DEFAULT:
    643554            ps2mSetDefaults(pThis);
    644             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     555            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    645556            pThis->u8CurrCmd = 0;
    646557            break;
     
    653564            pThis->u8CurrCmd = cmd;
    654565            pThis->enmMode   = AUX_MODE_RESET;
    655             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     566            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    656567            if (pThis->fDelayReset)
    657568                /* Slightly delay reset completion; it might take hundreds of ms. */
     
    659570            else
    660571#ifdef IN_RING3
    661                 ps2mReset(pThis);
     572                ps2mR3Reset(pThis);
    662573#else
    663574                AssertLogRelMsgFailed(("Invalid ACMD_RESET outside R3!\n"));
     
    667578        case ACMD_SET_RES:
    668579        case ACMD_SET_SAMP_RATE:
    669             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     580            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    670581            pThis->u8CurrCmd = cmd;
    671582            break;
     
    679590                        pThis->u8Resolution = cmd;
    680591                        pThis->u8State &= ~AUX_STATE_RES_ERR;
    681                         ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     592                        PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    682593                        pThis->u8CurrCmd = 0;
    683594                    }
     
    688599                        {
    689600                            pThis->u8State &= ~AUX_STATE_RES_ERR;
    690                             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
     601                            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
    691602                            pThis->u8CurrCmd = 0;
    692603                        }
     
    694605                        {
    695606                            pThis->u8State |= AUX_STATE_RES_ERR;
    696                             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
     607                            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
    697608                            /* NB: Current command remains unchanged. */
    698609                        }
     
    705616                        ps2mSetRate(pThis, cmd);
    706617                        ps2mRateProtocolKnock(pThis, cmd);
    707                         ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     618                        PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    708619                        pThis->u8CurrCmd = 0;
    709620                    }
     
    714625                        {
    715626                            pThis->u8State &= ~AUX_STATE_RATE_ERR;
    716                             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
     627                            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
    717628                            pThis->u8CurrCmd = 0;
    718629                        }
     
    720631                        {
    721632                            pThis->u8State |= AUX_STATE_RATE_ERR;
    722                             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
     633                            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
    723634                            /* NB: Current command remains unchanged. */
    724635                        }
     
    744655        case ACMD_INVALID_10:
    745656            Log(("Unsupported command 0x%02X!\n", cmd));
    746             ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
     657            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
    747658            pThis->u8CurrCmd = 0;
    748659            break;
     
    790701}
    791702
    792 /* Event rate throttling timer to emulate the auxiliary device sampling rate.
    793  */
    794 static DECLCALLBACK(void) ps2mThrottleTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
     703/**
     704 * @callback_function_impl{FNTMTIMERDEV,
     705 * Event rate throttling timer to emulate the auxiliary device sampling rate.}
     706 */
     707static DECLCALLBACK(void) ps2mR3ThrottleTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    795708{
    796709    RT_NOREF(pDevIns, pTimer);
     
    819732}
    820733
    821 /* The auxiliary device reset is specified to take up to about 500 milliseconds. We need
    822  * to delay sending the result to the host for at least a tiny little while.
    823  */
    824 static DECLCALLBACK(void) ps2mDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
     734/**
     735 * @callback_function_impl{FNTMTIMERDEV}
     736 *
     737 * The auxiliary device reset is specified to take up to about 500 milliseconds.
     738 * We need to delay sending the result to the host for at least a tiny little
     739 * while.
     740 */
     741static DECLCALLBACK(void) ps2mR3DelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    825742{
    826743    RT_NOREF(pDevIns, pTimer);
     
    830747
    831748    Assert(pThis->u8CurrCmd == ACMD_RESET);
    832     ps2mReset(pThis);
     749    ps2mR3Reset(pThis);
    833750
    834751    /// @todo Might want a PS2MCompleteCommand() to push last response, clear command, and kick the KBC...
     
    845762 * @param   pszArgs     Argument string. Optional and specific to the handler.
    846763 */
    847 static DECLCALLBACK(void) ps2mInfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     764static DECLCALLBACK(void) ps2mR3InfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    848765{
    849766    static const char   *pcszModes[] = { "normal", "reset", "wrap" };
     
    875792 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
    876793 */
    877 static DECLCALLBACK(void *) ps2mQueryInterface(PPDMIBASE pInterface, const char *pszIID)
     794static DECLCALLBACK(void *) ps2mR3QueryInterface(PPDMIBASE pInterface, const char *pszIID)
    878795{
    879796    PPS2M pThis = RT_FROM_MEMBER(pInterface, PS2M, Mouse.IBase);
     
    897814 * @param   fButtons        Depressed button mask.
    898815 */
    899 static int ps2mPutEventWorker(PPS2M pThis, int32_t dx, int32_t dy,
    900                               int32_t dz, int32_t dw, uint32_t fButtons)
    901 {
    902     int             rc = VINF_SUCCESS;
    903 
     816static int ps2mR3PutEventWorker(PPS2M pThis, int32_t dx, int32_t dy, int32_t dz, int32_t dw, uint32_t fButtons)
     817{
    904818    /* Update internal accumulators and button state. Ignore any buttons beyond 5. */
    905819    pThis->iAccumX += dx;
     
    915829     */
    916830    if (pThis->enmProtocol < PS2M_PROTO_IMEX_HORZ)
    917        pThis->iAccumW = 0; /* No horizontal scroll. */
     831        pThis->iAccumW = 0; /* No horizontal scroll. */
    918832
    919833    if (pThis->enmProtocol < PS2M_PROTO_IMEX)
    920834    {
    921        pThis->fAccumB &= PS2M_STD_BTN_MASK;   /* Only buttons 1-3. */
    922        pThis->fCurrB  &= PS2M_STD_BTN_MASK;
     835        pThis->fAccumB &= PS2M_STD_BTN_MASK;   /* Only buttons 1-3. */
     836        pThis->fCurrB  &= PS2M_STD_BTN_MASK;
    923837    }
    924838
    925839    if (pThis->enmProtocol < PS2M_PROTO_IMPS2)
    926        pThis->iAccumZ = 0; /* No vertical scroll. */
     840        pThis->iAccumZ = 0; /* No vertical scroll. */
    927841
    928842    /* Report the event (if any) and start the throttle timer unless it's already running. */
     
    935849    }
    936850
    937     return rc;
     851    return VINF_SUCCESS;
    938852}
    939853
     
    943857 * @interface_method_impl{PDMIMOUSEPORT,pfnPutEvent}
    944858 */
    945 static DECLCALLBACK(int) ps2mPutEvent(PPDMIMOUSEPORT pInterface, int32_t dx, int32_t dy,
    946                                       int32_t dz, int32_t dw, uint32_t fButtons)
     859static DECLCALLBACK(int) ps2mR3MousePort_PutEvent(PPDMIMOUSEPORT pInterface, int32_t dx, int32_t dy,
     860                                                  int32_t dz, int32_t dw, uint32_t fButtons)
    947861{
    948862    PPS2M       pThis = RT_FROM_MEMBER(pInterface, PS2M, Mouse.IPort);
     
    952866    LogRelFlowFunc(("dX=%d dY=%d dZ=%d dW=%d buttons=%02X\n", dx, dy, dz, dw, fButtons));
    953867    /* NB: The PS/2 Y axis direction is inverted relative to ours. */
    954     ps2mPutEventWorker(pThis, dx, -dy, dz, dw, fButtons);
     868    ps2mR3PutEventWorker(pThis, dx, -dy, dz, dw, fButtons);
    955869
    956870    PDMCritSectLeave(pThis->pCritSectR3);
     
    961875 * @interface_method_impl{PDMIMOUSEPORT,pfnPutEventAbs}
    962876 */
    963 static DECLCALLBACK(int) ps2mPutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t x, uint32_t y,
    964                                          int32_t dz, int32_t dw, uint32_t fButtons)
     877static DECLCALLBACK(int) ps2mR3MousePort_PutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t x, uint32_t y,
     878                                                     int32_t dz, int32_t dw, uint32_t fButtons)
    965879{
    966880    AssertFailedReturn(VERR_NOT_SUPPORTED);
     
    971885 * @interface_method_impl{PDMIMOUSEPORT,pfnPutEventMultiTouch}
    972886 */
    973 static DECLCALLBACK(int) ps2mPutEventMT(PPDMIMOUSEPORT pInterface, uint8_t cContacts,
    974                                         const uint64_t *pau64Contacts, uint32_t u32ScanTime)
     887static DECLCALLBACK(int) ps2mR3MousePort_PutEventMT(PPDMIMOUSEPORT pInterface, uint8_t cContacts,
     888                                                    const uint64_t *pau64Contacts, uint32_t u32ScanTime)
    975889{
    976890    AssertFailedReturn(VERR_NOT_SUPPORTED);
     
    995909 * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    996910 */
    997 int PS2MAttach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     911int PS2MR3Attach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    998912{
    999913    int         rc;
     
    1028942}
    1029943
    1030 void PS2MSaveState(PPS2M pThis, PSSMHANDLE pSSM)
    1031 {
     944void PS2MR3SaveState(PPDMDEVINS pDevIns, PPS2M pThis, PSSMHANDLE pSSM)
     945{
     946    PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
    1032947    LogFlowFunc(("Saving PS2M state\n"));
    1033948
    1034949    /* Save the core auxiliary device state. */
    1035     SSMR3PutU8(pSSM, pThis->u8State);
    1036     SSMR3PutU8(pSSM, pThis->u8SampleRate);
    1037     SSMR3PutU8(pSSM, pThis->u8Resolution);
    1038     SSMR3PutU8(pSSM, pThis->u8CurrCmd);
    1039     SSMR3PutU8(pSSM, pThis->enmMode);
    1040     SSMR3PutU8(pSSM, pThis->enmProtocol);
    1041     SSMR3PutU8(pSSM, pThis->enmKnockState);
     950    pHlp->pfnSSMPutU8(pSSM, pThis->u8State);
     951    pHlp->pfnSSMPutU8(pSSM, pThis->u8SampleRate);
     952    pHlp->pfnSSMPutU8(pSSM, pThis->u8Resolution);
     953    pHlp->pfnSSMPutU8(pSSM, pThis->u8CurrCmd);
     954    pHlp->pfnSSMPutU8(pSSM, pThis->enmMode);
     955    pHlp->pfnSSMPutU8(pSSM, pThis->enmProtocol);
     956    pHlp->pfnSSMPutU8(pSSM, pThis->enmKnockState);
    1042957
    1043958    /* Save the command and event queues. */
    1044     ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
    1045     ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->evtQ);
     959    PS2CmnR3SaveQueue(pHlp, pSSM, (GeneriQ *)&pThis->cmdQ);
     960    PS2CmnR3SaveQueue(pHlp, pSSM, (GeneriQ *)&pThis->evtQ);
    1046961
    1047962    /* Save the command delay timer. Note that the rate throttling
     
    1051966}
    1052967
    1053 int PS2MLoadState(PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion)
    1054 {
    1055     uint8_t     u8;
    1056     int         rc;
     968int PS2MR3LoadState(PPDMDEVINS pDevIns, PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion)
     969{
     970    PCPDMDEVHLPR3   pHlp = pDevIns->pHlpR3;
     971    uint8_t         u8;
     972    int             rc;
    1057973
    1058974    NOREF(uVersion);
     
    1060976
    1061977    /* Load the basic auxiliary device state. */
    1062     SSMR3GetU8(pSSM, &pThis->u8State);
    1063     SSMR3GetU8(pSSM, &pThis->u8SampleRate);
    1064     SSMR3GetU8(pSSM, &pThis->u8Resolution);
    1065     SSMR3GetU8(pSSM, &pThis->u8CurrCmd);
    1066     SSMR3GetU8(pSSM, &u8);
     978    pHlp->pfnSSMGetU8(pSSM, &pThis->u8State);
     979    pHlp->pfnSSMGetU8(pSSM, &pThis->u8SampleRate);
     980    pHlp->pfnSSMGetU8(pSSM, &pThis->u8Resolution);
     981    pHlp->pfnSSMGetU8(pSSM, &pThis->u8CurrCmd);
     982    pHlp->pfnSSMGetU8(pSSM, &u8);
    1067983    pThis->enmMode       = (PS2M_MODE)u8;
    1068     SSMR3GetU8(pSSM, &u8);
     984    pHlp->pfnSSMGetU8(pSSM, &u8);
    1069985    pThis->enmProtocol   = (PS2M_PROTO)u8;
    1070     SSMR3GetU8(pSSM, &u8);
     986    pHlp->pfnSSMGetU8(pSSM, &u8);
    1071987    pThis->enmKnockState = (PS2M_KNOCK_STATE)u8;
    1072988
    1073989    /* Load the command and event queues. */
    1074     rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
     990    rc = PS2CmnR3LoadQueue(pHlp, pSSM, (GeneriQ *)&pThis->cmdQ);
    1075991    AssertRCReturn(rc, rc);
    1076     rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->evtQ);
     992    rc = PS2CmnR3LoadQueue(pHlp, pSSM, (GeneriQ *)&pThis->evtQ);
    1077993    AssertRCReturn(rc, rc);
    1078994
     
    10841000    ps2mSetRate(pThis, pThis->u8SampleRate);
    10851001
    1086     ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
    1087 
    1088     return rc;
    1089 }
    1090 
    1091 void PS2MFixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto)
     1002    ps2mR3SetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
     1003
     1004    return VINF_SUCCESS;
     1005}
     1006
     1007void PS2MR3FixupState(PPS2M pThis, uint8_t u8State, uint8_t u8Rate, uint8_t u8Proto)
    10921008{
    10931009    LogFlowFunc(("Fixing up old PS2M state version\n"));
     
    11011017    ps2mSetRate(pThis, pThis->u8SampleRate);
    11021018
    1103     ps2mSetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
    1104 }
    1105 
    1106 void PS2MReset(PPS2M pThis)
     1019    ps2mR3SetDriverState(pThis, !!(pThis->u8State & AUX_STATE_ENABLED));
     1020}
     1021
     1022void PS2MR3Reset(PPS2M pThis)
    11071023{
    11081024    LogFlowFunc(("Resetting PS2M\n"));
     
    11111027
    11121028    /* Clear the queues. */
    1113     ps2kClearQueue((GeneriQ *)&pThis->cmdQ);
     1029    PS2CmnClearQueue((GeneriQ *)&pThis->cmdQ);
    11141030    ps2mSetDefaults(pThis);     /* Also clears event queue. */
    11151031}
    11161032
    1117 void PS2MRelocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
     1033void PS2MR3Relocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
    11181034{
    11191035    RT_NOREF(pDevIns, offDelta);
     
    11231039}
    11241040
    1125 int PS2MConstruct(PPS2M pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance)
     1041int PS2MR3Construct(PPS2M pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance)
    11261042{
    11271043    RT_NOREF(iInstance);
     
    11301046
    11311047#ifdef RT_STRICT
    1132     ps2mTestAccumulation();
     1048    ps2mR3TestAccumulation();
    11331049#endif
    11341050
     
    11391055    pThis->cmdQ.cSize = AUX_CMD_QUEUE_SIZE;
    11401056
    1141     pThis->Mouse.IBase.pfnQueryInterface     = ps2mQueryInterface;
    1142     pThis->Mouse.IPort.pfnPutEvent           = ps2mPutEvent;
    1143     pThis->Mouse.IPort.pfnPutEventAbs        = ps2mPutEventAbs;
    1144     pThis->Mouse.IPort.pfnPutEventMultiTouch = ps2mPutEventMT;
     1057    pThis->Mouse.IBase.pfnQueryInterface     = ps2mR3QueryInterface;
     1058    pThis->Mouse.IPort.pfnPutEvent           = ps2mR3MousePort_PutEvent;
     1059    pThis->Mouse.IPort.pfnPutEventAbs        = ps2mR3MousePort_PutEventAbs;
     1060    pThis->Mouse.IPort.pfnPutEventMultiTouch = ps2mR3MousePort_PutEventMT;
    11451061
    11461062    /*
     
    11531069     */
    11541070    PTMTIMER pTimer;
    1155     int rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_REAL, ps2mThrottleTimer, pThis,
     1071    int rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_REAL, ps2mR3ThrottleTimer, pThis,
    11561072                                    TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Throttle Timer", &pTimer);
    1157     if (RT_FAILURE(rc))
    1158         return rc;
     1073    AssertRCReturn(rc, rc);
    11591074
    11601075    pThis->pThrottleTimerR3 = pTimer;
     
    11651080     * Create the command delay timer.
    11661081     */
    1167     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2mDelayTimer, pThis,
     1082    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2mR3DelayTimer, pThis,
    11681083                                TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Delay Timer", &pTimer);
    1169     if (RT_FAILURE(rc))
    1170         return rc;
     1084    AssertRCReturn(rc, rc);
    11711085
    11721086    pThis->pDelayTimerR3 = pTimer;
     
    11771091     * Register debugger info callbacks.
    11781092     */
    1179     PDMDevHlpDBGFInfoRegister(pDevIns, "ps2m", "Display PS/2 mouse state.", ps2mInfoState);
     1093    PDMDevHlpDBGFInfoRegister(pDevIns, "ps2m", "Display PS/2 mouse state.", ps2mR3InfoState);
    11801094
    11811095    /// @todo Where should we do this?
    1182     ps2mSetDriverState(pThis, true);
     1096    ps2mR3SetDriverState(pThis, true);
    11831097    pThis->u8State = 0;
    11841098    pThis->enmMode = AUX_MODE_STD;
     
    11941108/** Test the event accumulation mechanism which we use to delay events going
    11951109 * to the guest to one per 10ms (the default PS/2 mouse event rate).  This
    1196  * test depends on ps2mPutEventWorker() not touching the timer if
     1110 * test depends on ps2mR3PutEventWorker() not touching the timer if
    11971111 * This.fThrottleActive is true. */
    11981112/** @todo if we add any more tests it might be worth using a table of test
    11991113 * operations and checks. */
    1200 static void ps2mTestAccumulation(void)
     1114static void ps2mR3TestAccumulation(void)
    12011115{
    12021116    PS2M This;
     
    12121126     * a release-press-release all within a single 10ms interval.  Simulate
    12131127     * this to check that it is handled right. */
    1214     ps2mPutEventWorker(&This, 0, 0, 0, 0, 1);
     1128    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
    12151129    if (ps2mHaveEvents(&This))
    12161130        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    1217     ps2mPutEventWorker(&This, 0, 0, 0, 0, 0);
     1131    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 0);
    12181132    if (ps2mHaveEvents(&This))
    12191133        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    1220     ps2mPutEventWorker(&This, 0, 0, 0, 0, 1);
    1221     ps2mPutEventWorker(&This, 0, 0, 0, 0, 0);
     1134    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
     1135    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 0);
    12221136    if (ps2mHaveEvents(&This))
    12231137        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
     
    12361150    /* Button hold down during mouse drags was broken at some point during
    12371151     * testing fixes for the previous issue.  Test that that works. */
    1238     ps2mPutEventWorker(&This, 0, 0, 0, 0, 1);
     1152    ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
    12391153    if (ps2mHaveEvents(&This))
    12401154        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette