VirtualBox

Changeset 44806 in vbox


Ignore:
Timestamp:
Feb 22, 2013 8:47:57 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
83926
Message:

DevPS2.cpp++: Drop two critsects in favor of the default device critsect. This is simpler and avoid confusion as to the locking saftety of the PS2KByteFromKbd and PS2KByteToKbd interfaces exposed by PS2K and used by DevPS2. Misc cleanups (didn't do a full cleanup, sorry).

Location:
trunk/src/VBox/Devices
Files:
5 edited

Legend:

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

    r44528 r44806  
    165165#define MOUSE_EVENT_QUEUE_SIZE 256
    166166
    167 typedef struct {
     167typedef struct
     168{
    168169    uint8_t data[MOUSE_EVENT_QUEUE_SIZE];
    169     int rptr, wptr, count;
     170    int     rptr;
     171    int     wptr;
     172    int     count;
    170173} MouseEventQueue;
    171174
    172 typedef struct KBDState {
     175/**
     176 * The keyboard controller/device state.
     177 *
     178 * @note We use the default critical section for serialize data access.
     179 */
     180typedef struct KBDState
     181{
    173182    MouseCmdQueue mouse_command_queue;
    174183    MouseEventQueue mouse_event_queue;
     
    204213    /** Pointer to the device instance. */
    205214    PPDMDEVINSR0                pDevInsR0;
    206 
    207     /** Critical section protecting the state. */
    208     PDMCRITSECT                 CritSect;
    209215
    210216    /** Keyboard state (implemented in separate PS2K module). */
     
    543549}
    544550
    545 PS2K *GetPS2KFromDevIns(PPDMDEVINS pDevIns)
     551PS2K *KBDGetPS2KFromDevIns(PPDMDEVINS pDevIns)
    546552{
    547553    KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
     
    12001206    {
    12011207        KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
    1202         int rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_R3_IOPORT_READ);
    1203         if (RT_LIKELY(rc == VINF_SUCCESS))
    1204         {
    1205             *pu32 = kbd_read_data(pThis, Port);
    1206             PDMCritSectLeave(&pThis->CritSect);
    1207             Log2(("kbdIOPortDataRead: Port=%#x cb=%d *pu32=%#x\n", Port, cb, *pu32));
    1208         }
    1209         return rc;
     1208        *pu32 = kbd_read_data(pThis, Port);
     1209        Log2(("kbdIOPortDataRead: Port=%#x cb=%d *pu32=%#x\n", Port, cb, *pu32));
     1210        return VINF_SUCCESS;
    12101211    }
    12111212    AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
     
    12311232    {
    12321233        KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
    1233         rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_R3_IOPORT_WRITE);
    1234         if (RT_LIKELY(rc == VINF_SUCCESS))
    1235         {
    1236             rc = kbd_write_data(pThis, Port, u32);
    1237             PDMCritSectLeave(&pThis->CritSect);
    1238             Log2(("kbdIOPortDataWrite: Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
    1239         }
     1234        rc = kbd_write_data(pThis, Port, u32);
     1235        Log2(("kbdIOPortDataWrite: Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
    12401236    }
    12411237    else
     
    12611257    {
    12621258        KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
    1263         int rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_R3_IOPORT_READ);
    1264         if (RT_LIKELY(rc == VINF_SUCCESS))
    1265         {
    1266             *pu32 = kbd_read_status(pThis, Port);
    1267             PDMCritSectLeave(&pThis->CritSect);
    1268             Log2(("kbdIOPortStatusRead: Port=%#x cb=%d -> *pu32=%#x\n", Port, cb, *pu32));
    1269         }
    1270         return rc;
     1259        *pu32 = kbd_read_status(pThis, Port);
     1260        Log2(("kbdIOPortStatusRead: Port=%#x cb=%d -> *pu32=%#x\n", Port, cb, *pu32));
     1261        return VINF_SUCCESS;
    12711262    }
    12721263    AssertMsgFailed(("Port=%#x cb=%d\n", Port, cb));
     
    12921283    {
    12931284        KBDState *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
    1294         rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_R3_IOPORT_WRITE);
    1295         if (RT_LIKELY(rc == VINF_SUCCESS))
    1296         {
    1297             rc = kbd_write_command(pThis, Port, u32);
    1298             PDMCritSectLeave(&pThis->CritSect);
    1299             Log2(("kbdIOPortCommandWrite: Port=%#x cb=%d u32=%#x rc=%Rrc\n", Port, cb, u32, rc));
    1300         }
     1285        rc = kbd_write_command(pThis, Port, u32);
     1286        Log2(("kbdIOPortCommandWrite: Port=%#x cb=%d u32=%#x rc=%Rrc\n", Port, cb, u32, rc));
    13011287    }
    13021288    else
     
    13121298 * @returns VBox status code.
    13131299 * @param   pDevIns     The device instance.
    1314  * @param   pSSMHandle  The handle to save the state to.
    1315  */
    1316 static DECLCALLBACK(int) kbdSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
     1300 * @param   pSSM  The handle to save the state to.
     1301 */
     1302static DECLCALLBACK(int) kbdSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    13171303{
    13181304    KBDState    *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
    1319     kbd_save(pSSMHandle, pThis);
    1320     PS2KSaveState(pSSMHandle, &pThis->Kbd);
     1305    kbd_save(pSSM, pThis);
     1306    PS2KSaveState(&pThis->Kbd, pSSM);
    13211307    return VINF_SUCCESS;
    13221308}
     
    13281314 * @returns VBox status code.
    13291315 * @param   pDevIns     The device instance.
    1330  * @param   pSSMHandle  The handle to the saved state.
     1316 * @param   pSSM  The handle to the saved state.
    13311317 * @param   uVersion    The data unit version number.
    13321318 * @param   uPass       The data pass.
    13331319 */
    1334 static DECLCALLBACK(int) kbdLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t uVersion, uint32_t uPass)
     1320static DECLCALLBACK(int) kbdLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    13351321{
    13361322    KBDState    *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
     
    13381324
    13391325    Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
    1340     rc = kbd_load(pSSMHandle, pThis, uVersion);
     1326    rc = kbd_load(pSSM, pThis, uVersion);
    13411327    if (uVersion >= 6)
    1342         rc = PS2KLoadState(pSSMHandle, &pThis->Kbd, uVersion);
     1328        rc = PS2KLoadState(&pThis->Kbd, pSSM, uVersion);
    13431329    return rc;
    13441330}
     
    13821368{
    13831369    KBDState *pThis = RT_FROM_MEMBER(pInterface, KBDState, Mouse.IPort);
    1384     int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
     1370    int rc = PDMCritSectEnter(pThis->pDevInsR3->pCritSectRoR3, VERR_SEM_BUSY);
    13851371    AssertReleaseRC(rc);
    13861372
    13871373    pc_kbd_mouse_event(pThis, iDeltaX, iDeltaY, iDeltaZ, iDeltaW, fButtonStates);
    13881374
    1389     PDMCritSectLeave(&pThis->CritSect);
     1375    PDMCritSectLeave(pThis->pDevInsR3->pCritSectRoR3);
    13901376    return VINF_SUCCESS;
    13911377}
     
    14331419        /* LUN #0: keyboard */
    14341420        case 0:
    1435             rc = PS2KAttach(pDevIns, &pThis->Kbd, iLUN, fFlags);
     1421            rc = PS2KAttach(&pThis->Kbd, pDevIns, iLUN, fFlags);
    14361422            if (RT_FAILURE(rc))
    14371423                return rc;
     
    15211507    KBDState   *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
    15221508    pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    1523     PS2KRelocate(&pThis->Kbd, offDelta);
    1524 }
    1525 
    1526 
    1527 /**
    1528  * Destruct a device instance for a VM.
    1529  *
    1530  * @returns VBox status.
    1531  * @param   pDevIns     The device instance data.
    1532  */
    1533 static DECLCALLBACK(int) kbdDestruct(PPDMDEVINS pDevIns)
    1534 {
    1535     KBDState   *pThis = PDMINS_2_DATA(pDevIns, KBDState *);
    1536     PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
    1537 
    1538     PDMR3CritSectDelete(&pThis->CritSect);
    1539 
    1540     return VINF_SUCCESS;
     1509    PS2KRelocate(&pThis->Kbd, offDelta, pDevIns);
    15411510}
    15421511
     
    15761545    pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    15771546
    1578     rc = PS2KConstruct(pDevIns, &pThis->Kbd, pThis, iInstance);
     1547    rc = PS2KConstruct(&pThis->Kbd, pDevIns, pThis, iInstance);
    15791548    if (RT_FAILURE(rc))
    15801549        return rc;
     
    15831552    pThis->Mouse.IPort.pfnPutEvent          = kbdMousePutEvent;
    15841553    pThis->Mouse.IPort.pfnPutEventAbs       = kbdMousePutEventAbs;
    1585 
    1586     /*
    1587      * Initialize the critical section.
    1588      */
    1589     rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "PS2KM#%u", iInstance);
    1590     if (RT_FAILURE(rc))
    1591         return rc;
    15921554
    15931555    /*
     
    16691631    kbdConstruct,
    16701632    /* pfnDestruct */
    1671     kbdDestruct,
     1633    NULL,
    16721634    /* pfnRelocate */
    16731635    kbdRelocate,
  • trunk/src/VBox/Devices/Input/PS2Dev.h

    r39972 r44806  
    1818#define PS2DEV_H
    1919
    20 /* Must be at least as big as the real struct. */
    21 #define PS2K_STRUCT_FILLER  768
     20/** The size of the PS2K structure filler.
     21 * @note Must be at least as big as the real struct. Compile time assert
     22 *       makes sure this is so. */
     23#define PS2K_STRUCT_FILLER  512
    2224
    2325/* Hide the internal structure. */
    2426#if !(defined(IN_PS2K) || defined(VBOX_DEVICE_STRUCT_TESTCASE))
    25 typedef struct PS2K {
     27typedef struct PS2K
     28{
    2629    uint8_t     abFiller[PS2K_STRUCT_FILLER];
    2730} PS2K;
     
    3336int  PS2KByteFromKbd(PPS2K pThis, uint8_t *pVal);
    3437
    35 int  PS2KConstruct(PPDMDEVINS pDevIns, PPS2K pThis, void *pParent, int iInstance);
    36 int  PS2KAttach(PPDMDEVINS pDevIns, PPS2K pThis, unsigned iLUN, uint32_t fFlags);
     38int  PS2KConstruct(PPS2K pThis, PPDMDEVINS pDevIns, void *pParent, int iInstance);
     39int  PS2KAttach(PPS2K pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
    3740void PS2KReset(PPS2K pThis);
    38 void PS2KRelocate(PPS2K pThis, RTGCINTPTR offDelta);
    39 void PS2KSaveState(PSSMHANDLE pSSM, PPS2K pThis);
    40 int  PS2KLoadState(PSSMHANDLE pSSM, PPS2K pThis, uint32_t uVersion);
     41void PS2KRelocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
     42void PS2KSaveState(PPS2K pThis, PSSMHANDLE pSSM);
     43int  PS2KLoadState(PPS2K pThis, PSSMHANDLE pSSM, uint32_t uVersion);
    4144
    4245void KBCUpdateInterrupts(void *pKbc);
    4346
    44 PS2K *GetPS2KFromDevIns(PPDMDEVINS pDevIns);
     47PS2K *KBDGetPS2KFromDevIns(PPDMDEVINS pDevIns);
    4548
    46 //@todo: This should live with the KBC implementation.
     49///@todo: This should live with the KBC implementation.
    4750/** AT to PC scancode translator state.  */
    48 typedef enum {
     51typedef enum
     52{
    4953    XS_IDLE,    /**< Starting state. */
    5054    XS_BREAK,   /**< F0 break byte was received. */
  • trunk/src/VBox/Devices/Input/PS2K.cpp

    r44023 r44806  
    188188    uint32_t            Alignment0;
    189189#endif
    190     /** Critical section protecting the state. */
    191     PDMCRITSECT         KbdCritSect;
     190
    192191    /** Command delay timer - RC Ptr. */
    193192    PTMTIMERRC          pKbdDelayTimerRC;
    194193    /** Typematic timer - RC Ptr. */
    195194    PTMTIMERRC          pKbdTypematicTimerRC;
     195
     196    /** The device critical section protecting everything - R3 Ptr */
     197    R3PTRTYPE(PPDMCRITSECT) pCritSectR3;
    196198    /** Command delay timer - R3 Ptr. */
    197199    PTMTIMERR3          pKbdDelayTimerR3;
    198200    /** Typematic timer - R3 Ptr. */
    199201    PTMTIMERR3          pKbdTypematicTimerR3;
     202    RTR3PTR             Alignment2;
     203
    200204    /** Command delay timer - R0 Ptr. */
    201205    PTMTIMERR0          pKbdDelayTimerR0;
     
    203207    PTMTIMERR0          pKbdTypematicTimerR0;
    204208
    205     scan_state_t        XlatState;      //@todo: temporary
     209    scan_state_t        XlatState;      ///@todo: temporary
    206210    uint32_t            Alignment1;
    207211
     
    561565 * @param   pQ                  Pointer to the queue.
    562566 */
    563 static void PS2ClearQueue(GeneriQ *pQ)
     567static void ps2kClearQueue(GeneriQ *pQ)
    564568{
    565569    LogFlowFunc(("Clearing queue %p\n", pQ));
     
    575579 * @param   val                 The byte to store.
    576580 */
    577 static void PS2InsertQueue(GeneriQ *pQ, uint8_t val)
     581static void ps2kInsertQueue(GeneriQ *pQ, uint8_t val)
    578582{
    579583    /* Check if queue is full. */
     
    599603 * @param   pQ                  Pointer to the queue.
    600604 */
    601 static void PS2SaveQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
     605static void ps2kSaveQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
    602606{
    603607    uint32_t    cItems = pQ->cUsed;
     
    624628 * @return  int                 VBox status/error code.
    625629 */
    626 static int PS2LoadQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
     630static int ps2kLoadQueue(PSSMHANDLE pSSM, GeneriQ *pQ)
    627631{
    628632    int         rc;
     
    647651}
    648652
    649 #endif
     653#endif /* IN_RING3 */
    650654
    651655/**
     
    658662 *                              VINF_SUCCESS if a byte was read.
    659663 */
    660 int PS2RemoveQueue(GeneriQ *pQ, uint8_t *pVal)
     664static int ps2kRemoveQueue(GeneriQ *pQ, uint8_t *pVal)
    661665{
    662666    int     rc = VINF_TRY_AGAIN;
     
    679683 * with +/- 20% accuracy, so there's no need for high precision.
    680684 */
    681 static void PS2KSetupTypematic(PPS2K pThis, uint8_t val)
     685static void ps2kSetupTypematic(PPS2K pThis, uint8_t val)
    682686{
    683687    int         A, B;
     
    693697    pThis->uTypematicRepeat = period;
    694698    Log(("Typematic delay %u ms, repeat period %u ms\n",
    695             pThis->uTypematicDelay, pThis->uTypematicRepeat));
    696 }
    697 
    698 static void PS2KSetDefaults(PPS2K pThis)
     699         pThis->uTypematicDelay, pThis->uTypematicRepeat));
     700}
     701
     702static void ps2kSetDefaults(PPS2K pThis)
    699703{
    700704    LogFlowFunc(("Set keyboard defaults\n"));
    701     PS2ClearQueue((GeneriQ *)&pThis->keyQ);
     705    ps2kClearQueue((GeneriQ *)&pThis->keyQ);
    702706    /* Set default Scan Set 3 typematic values. */
    703707    /* Set default typematic rate/delay. */
    704     PS2KSetupTypematic(pThis, KBD_DFL_RATE_DELAY);
     708    ps2kSetupTypematic(pThis, KBD_DFL_RATE_DELAY);
    705709    /* Clear last typematic key?? */
    706710}
     
    709713 * Receive and process a byte sent by the keyboard controller.
    710714 *
    711  * @param   pThis               The keyboard.
     715 * @param   pThis               The PS/2 keyboard instance data.
    712716 * @param   cmd                 The command (or data) byte.
    713717 */
     
    718722    LogFlowFunc(("new cmd=0x%02X, active cmd=0x%02X\n", cmd, pThis->u8CurrCmd));
    719723
    720     switch (cmd) {
    721     case KCMD_ECHO:
    722         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ECHO);
    723         pThis->u8CurrCmd = 0;
    724         break;
    725     case KCMD_READ_ID:
    726         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    727         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID1);
    728         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID2);
    729         pThis->u8CurrCmd = 0;
    730         break;
    731     case KCMD_ENABLE:
    732         pThis->fScanning = true;
    733         PS2ClearQueue((GeneriQ *)&pThis->keyQ);
    734         /* Clear last typematic key?? */
    735         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    736         pThis->u8CurrCmd = 0;
    737         break;
    738     case KCMD_DFLT_DISABLE:
    739         pThis->fScanning = false;
    740         PS2KSetDefaults(pThis);
    741         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    742         pThis->u8CurrCmd = 0;
    743         break;
    744     case KCMD_SET_DEFAULT:
    745         PS2KSetDefaults(pThis);
    746         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    747         pThis->u8CurrCmd = 0;
    748         break;
    749     case KCMD_ALL_TYPEMATIC:
    750     case KCMD_ALL_MK_BRK:
    751     case KCMD_ALL_MAKE:
    752     case KCMD_ALL_TMB:
    753         //@todo: Set the key types here.
    754         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    755         pThis->u8CurrCmd = 0;
    756         break;
    757     case KCMD_RESEND:
    758         pThis->u8CurrCmd = 0;
    759         break;
    760     case KCMD_RESET:
    761         pThis->u8ScanSet = 2;
    762         PS2KSetDefaults(pThis);
    763         //@todo: reset more?
    764         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    765         pThis->u8CurrCmd = cmd;
    766         /* Delay BAT completion; the test may take hundreds of ms. */
    767         TMTimerSetMillies(pThis->CTX_SUFF(pKbdDelayTimer), 2);
    768         break;
    769     /* The following commands need a parameter. */
    770     case KCMD_LEDS:
    771     case KCMD_SCANSET:
    772     case KCMD_RATE_DELAY:
    773     case KCMD_TYPE_MATIC:
    774     case KCMD_TYPE_MK_BRK:
    775     case KCMD_TYPE_MAKE:
    776         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    777         pThis->u8CurrCmd = cmd;
    778         break;
    779     default:
    780         /* Sending a command instead of a parameter starts the new command. */
    781         switch (pThis->u8CurrCmd) {
    782         case KCMD_LEDS:
    783 #ifndef IN_RING3
    784             return VINF_IOM_R3_IOPORT_WRITE;
    785 #else
    786             {
    787                 PDMKEYBLEDS enmLeds = PDMKEYBLEDS_NONE;
    788 
    789                 if (cmd & 0x01)
    790                     enmLeds = (PDMKEYBLEDS)(enmLeds | PDMKEYBLEDS_SCROLLLOCK);
    791                 if (cmd & 0x02)
    792                     enmLeds = (PDMKEYBLEDS)(enmLeds | PDMKEYBLEDS_NUMLOCK);
    793                 if (cmd & 0x04)
    794                     enmLeds = (PDMKEYBLEDS)(enmLeds | PDMKEYBLEDS_CAPSLOCK);
    795                 pThis->Keyboard.pDrv->pfnLedStatusChange(pThis->Keyboard.pDrv, enmLeds);
    796                 pThis->fNumLockOn = !!(cmd & 0x02); /* Sync internal Num Lock state. */
    797                 PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    798                 pThis->u8LEDs = cmd;
    799                 pThis->u8CurrCmd = 0;
    800             }
    801 #endif
    802             break;
    803         case KCMD_SCANSET:
    804             PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    805             if (cmd == 0)
    806                 PS2InsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8ScanSet);
    807             else if (cmd < 4)
    808             {
    809                 pThis->u8ScanSet = cmd;
    810                 LogRel(("PS2K: Selected scan set %d.\n", cmd));
    811             }
    812             /* Other values are simply ignored. */
     724    switch (cmd)
     725    {
     726        case KCMD_ECHO:
     727            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ECHO);
    813728            pThis->u8CurrCmd = 0;
    814729            break;
    815         case KCMD_RATE_DELAY:
    816             PS2KSetupTypematic(pThis, cmd);
    817             PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     730        case KCMD_READ_ID:
     731            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     732            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID1);
     733            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID2);
    818734            pThis->u8CurrCmd = 0;
    819735            break;
     736        case KCMD_ENABLE:
     737            pThis->fScanning = true;
     738            ps2kClearQueue((GeneriQ *)&pThis->keyQ);
     739            /* Clear last typematic key?? */
     740            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     741            pThis->u8CurrCmd = 0;
     742            break;
     743        case KCMD_DFLT_DISABLE:
     744            pThis->fScanning = false;
     745            ps2kSetDefaults(pThis);
     746            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     747            pThis->u8CurrCmd = 0;
     748            break;
     749        case KCMD_SET_DEFAULT:
     750            ps2kSetDefaults(pThis);
     751            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     752            pThis->u8CurrCmd = 0;
     753            break;
     754        case KCMD_ALL_TYPEMATIC:
     755        case KCMD_ALL_MK_BRK:
     756        case KCMD_ALL_MAKE:
     757        case KCMD_ALL_TMB:
     758            ///@todo Set the key types here.
     759            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     760            pThis->u8CurrCmd = 0;
     761            break;
     762        case KCMD_RESEND:
     763            pThis->u8CurrCmd = 0;
     764            break;
     765        case KCMD_RESET:
     766            pThis->u8ScanSet = 2;
     767            ps2kSetDefaults(pThis);
     768            ///@todo reset more?
     769            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     770            pThis->u8CurrCmd = cmd;
     771            /* Delay BAT completion; the test may take hundreds of ms. */
     772            TMTimerSetMillies(pThis->CTX_SUFF(pKbdDelayTimer), 2);
     773            break;
     774        /* The following commands need a parameter. */
     775        case KCMD_LEDS:
     776        case KCMD_SCANSET:
     777        case KCMD_RATE_DELAY:
     778        case KCMD_TYPE_MATIC:
     779        case KCMD_TYPE_MK_BRK:
     780        case KCMD_TYPE_MAKE:
     781            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     782            pThis->u8CurrCmd = cmd;
     783            break;
    820784        default:
    821             fHandled = false;
    822         }
    823         /* Fall through only to handle unrecognized commands. */
    824         if (fHandled)
     785            /* Sending a command instead of a parameter starts the new command. */
     786            switch (pThis->u8CurrCmd)
     787            {
     788                case KCMD_LEDS:
     789#ifndef IN_RING3
     790                    return VINF_IOM_R3_IOPORT_WRITE;
     791#else
     792                    {
     793                        PDMKEYBLEDS enmLeds = PDMKEYBLEDS_NONE;
     794
     795                        if (cmd & 0x01)
     796                            enmLeds = (PDMKEYBLEDS)(enmLeds | PDMKEYBLEDS_SCROLLLOCK);
     797                        if (cmd & 0x02)
     798                            enmLeds = (PDMKEYBLEDS)(enmLeds | PDMKEYBLEDS_NUMLOCK);
     799                        if (cmd & 0x04)
     800                            enmLeds = (PDMKEYBLEDS)(enmLeds | PDMKEYBLEDS_CAPSLOCK);
     801                        pThis->Keyboard.pDrv->pfnLedStatusChange(pThis->Keyboard.pDrv, enmLeds);
     802                        pThis->fNumLockOn = !!(cmd & 0x02); /* Sync internal Num Lock state. */
     803                        ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     804                        pThis->u8LEDs = cmd;
     805                        pThis->u8CurrCmd = 0;
     806                    }
     807#endif
     808                    break;
     809                case KCMD_SCANSET:
     810                    ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     811                    if (cmd == 0)
     812                        ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8ScanSet);
     813                    else if (cmd < 4)
     814                    {
     815                        pThis->u8ScanSet = cmd;
     816                        LogRel(("PS2K: Selected scan set %d.\n", cmd));
     817                    }
     818                    /* Other values are simply ignored. */
     819                    pThis->u8CurrCmd = 0;
     820                    break;
     821                case KCMD_RATE_DELAY:
     822                    ps2kSetupTypematic(pThis, cmd);
     823                    ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     824                    pThis->u8CurrCmd = 0;
     825                    break;
     826                default:
     827                    fHandled = false;
     828            }
     829            /* Fall through only to handle unrecognized commands. */
     830            if (fHandled)
     831                break;
     832
     833        case KCMD_INVALID_1:
     834        case KCMD_INVALID_2:
     835            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_RESEND);
     836            pThis->u8CurrCmd = 0;
    825837            break;
    826 
    827     case KCMD_INVALID_1:
    828     case KCMD_INVALID_2:
    829         PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_RESEND);
    830         pThis->u8CurrCmd = 0;
    831         break;
    832838    }
    833839    LogFlowFunc(("Active cmd now 0x%02X; updating interrupts\n", pThis->u8CurrCmd));
     
    839845 * Send a byte (keystroke or command response) to the keyboard controller.
    840846 *
    841  * @param   pThis               The keyboard.
    842  */
    843 int PS2KByteFromKbd(PPS2K pThis, uint8_t *pVal)
     847 * @returns VINF_SUCCESS or VINF_TRY_AGAIN.
     848 * @param   pThis               The PS/2 keyboard instance data.
     849 * @param   pb                  Where to return the byte we've read.
     850 * @remarks Caller must have entered the device critical section.
     851 */
     852int PS2KByteFromKbd(PPS2K pThis, uint8_t *pb)
    844853{
    845854    int         rc;
    846855
    847     Assert(pVal);
     856    AssertPtr(pb);
    848857
    849858    /* Anything in the command queue has priority over data
     
    852861     * the command queue is empty.
    853862     */
    854     rc = PS2RemoveQueue((GeneriQ *)&pThis->cmdQ, pVal);
     863    rc = ps2kRemoveQueue((GeneriQ *)&pThis->cmdQ, pb);
    855864    if (rc != VINF_SUCCESS && !pThis->u8CurrCmd && pThis->fScanning)
    856         rc = PS2RemoveQueue((GeneriQ *)&pThis->keyQ, pVal);
    857 
    858     LogFlowFunc(("keyboard sends 0x%02x (%svalid data)\n", *pVal, rc == VINF_SUCCESS ? "" : "not "));
     865        rc = ps2kRemoveQueue((GeneriQ *)&pThis->keyQ, pb);
     866
     867    LogFlowFunc(("keyboard sends 0x%02x (%svalid data)\n", *pb, rc == VINF_SUCCESS ? "" : "not "));
    859868    return rc;
    860869}
     
    862871#ifdef IN_RING3
    863872
    864 static int PS2KProcessKeyEvent(PPS2K pThis, uint8_t u8HidCode, bool fKeyDown)
     873static int psk2ProcessKeyEvent(PPS2K pThis, uint8_t u8HidCode, bool fKeyDown)
    865874{
    866875    unsigned int    i = 0;
     
    939948            }
    940949            /* Feed the bytes to the queue if there is room. */
    941             //@todo: check empty space!
     950            ///@todo check empty space!
    942951            while (abCodes[i])
    943                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, abCodes[i++]);
     952                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, abCodes[i++]);
    944953            Assert(i < sizeof(abCodes));
    945954
     
    948957            {
    949958                if (pKeyDef->keyFlags & (KF_E0 | KF_GK | KF_NS))
    950                     PS2InsertQueue((GeneriQ *)&pThis->keyQ, 0xE0);
    951                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS2);
     959                    ps2kInsertQueue((GeneriQ *)&pThis->keyQ, 0xE0);
     960                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS2);
    952961            }
    953962        }
     
    971980                /* Process base scan code for less unusual keys. */
    972981                if (pKeyDef->keyFlags & (KF_E0 | KF_GK | KF_NS))
    973                     PS2InsertQueue((GeneriQ *)&pThis->keyQ, 0xE0);
    974                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, 0xF0);
    975                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS2);
     982                    ps2kInsertQueue((GeneriQ *)&pThis->keyQ, 0xE0);
     983                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, 0xF0);
     984                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS2);
    976985
    977986                /* Restore shift state for gray keys. */
     
    9941003
    9951004            /* Feed any additional bytes to the queue if there is room. */
    996             //@todo: check empty space!
     1005            ///@todo check empty space!
    9971006            while (abCodes[i])
    998                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, abCodes[i++]);
     1007                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, abCodes[i++]);
    9991008            Assert(i < sizeof(abCodes));
    10001009        }
     
    10061015        {
    10071016            if (pKeyDef->keyFlags & (KF_E0 | KF_GK | KF_NS | KF_PS))
    1008                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, 0xE0);
    1009             PS2InsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS1);
     1017                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, 0xE0);
     1018            ps2kInsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS1);
    10101019        }
    10111020        else if (!(pKeyDef->keyFlags & (KF_NB | KF_PB))) {
    10121021            if (pKeyDef->keyFlags & (KF_E0 | KF_GK | KF_NS | KF_PS))
    1013                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, 0xE0);
    1014             PS2InsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS1 | 0x80);
     1022                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, 0xE0);
     1023            ps2kInsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS1 | 0x80);
    10151024        }
    10161025    }
     
    10201029        if (fKeyDown)
    10211030        {
    1022             PS2InsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS3);
     1031            ps2kInsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS3);
    10231032        }
    10241033        else
    10251034        {
    10261035            /* Send a key release code unless it's a make only key. */
    1027             //@todo: Look up the current typematic setting, not the default!
     1036            ///@todo Look up the current typematic setting, not the default!
    10281037            if (pKeyDef->keyMatic != T_M)
    10291038            {
    1030                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, 0xF0);
    1031                 PS2InsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS3);
     1039                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, 0xF0);
     1040                ps2kInsertQueue((GeneriQ *)&pThis->keyQ, pKeyDef->makeS3);
    10321041            }
    10331042        }
     
    10491058        pThis->u8TypematicKey    = 0;
    10501059        pThis->enmTypematicState = KBD_TMS_IDLE;
    1051         //@todo: Cancel timer right away?
    1052         //@todo: Cancel timer before pushing key up code!?
     1060        ///@todo Cancel timer right away?
     1061        ///@todo Cancel timer before pushing key up code!?
    10531062    }
    10541063
     
    10621071 * held down repeats (if typematic).
    10631072 */
    1064 static DECLCALLBACK(void) PS2KTypematicTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    1065 {
    1066     PPS2K pThis = (PS2K *)pvUser; //PDMINS_2_DATA(pDevIns, PS2K *);
    1067     int rc = PDMCritSectEnter(&pThis->KbdCritSect, VERR_SEM_BUSY);
    1068     AssertReleaseRC(rc);
    1069 
     1073static DECLCALLBACK(void) ps2kTypematicTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
     1074{
     1075    PPS2K pThis = (PS2K *)pvUser; NOREF(pDevIns);
    10701076    LogFlowFunc(("Typematic state=%d, key %02X\n", pThis->enmTypematicState, pThis->u8TypematicKey));
    10711077
     
    10801086        if (pThis->enmTypematicState == KBD_TMS_REPEAT)
    10811087        {
    1082             PS2KProcessKeyEvent(pThis, pThis->u8TypematicKey, true /* Key down */ );
     1088            psk2ProcessKeyEvent(pThis, pThis->u8TypematicKey, true /* Key down */ );
    10831089            TMTimerSetMillies(pThis->CTX_SUFF(pKbdTypematicTimer), pThis->uTypematicRepeat);
    10841090        }
    10851091    }
    1086 
    1087     PDMCritSectLeave(&pThis->KbdCritSect);
    10881092}
    10891093
     
    10911095 * to delay sending the result to the host for at least a tiny little while.
    10921096 */
    1093 static DECLCALLBACK(void) PS2KDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    1094 {
    1095     PPS2K   pThis = GetPS2KFromDevIns(pDevIns);
    1096     int rc = PDMCritSectEnter(&pThis->KbdCritSect, VERR_SEM_BUSY);
    1097     AssertReleaseRC(rc);
     1097static DECLCALLBACK(void) ps2kDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
     1098{
     1099    PPS2K pThis = (PS2K *)pvUser; NOREF(pDevIns);
    10981100
    10991101    LogFlowFunc(("Delay timer: cmd %02X\n", pThis->u8CurrCmd));
    11001102
    11011103    Assert(pThis->u8CurrCmd == KCMD_RESET);
    1102     PS2InsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_BAT_OK);
     1104    ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_BAT_OK);
    11031105    pThis->fScanning = true;    /* BAT completion enables scanning! */
    11041106    pThis->u8CurrCmd = 0;
    11051107
    1106     //@todo: Might want a PS2KCompleteCommand() to push last response, clear command, and kick the KBC...
     1108    ///@todo Might want a PS2KCompleteCommand() to push last response, clear command, and kick the KBC...
    11071109    /* Give the KBC a kick. */
    11081110    KBCUpdateInterrupts(pThis->pParent);
    1109 
    1110     PDMCritSectLeave(&pThis->KbdCritSect);
    11111111}
    11121112
     
    11191119 * @param   pszArgs     Argument string. Optional and specific to the handler.
    11201120 */
    1121 static DECLCALLBACK(void) PS2KInfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    1122 {
    1123     PPS2K   pThis = GetPS2KFromDevIns(pDevIns);
     1121static DECLCALLBACK(void) ps2kInfoState(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     1122{
     1123    PPS2K   pThis = KBDGetPS2KFromDevIns(pDevIns);
    11241124    NOREF(pszArgs);
    11251125
     
    11451145 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
    11461146 */
    1147 static DECLCALLBACK(void *) PS2KQueryInterface(PPDMIBASE pInterface, const char *pszIID)
     1147static DECLCALLBACK(void *) ps2kQueryInterface(PPDMIBASE pInterface, const char *pszIID)
    11481148{
    11491149    PPS2K pThis = RT_FROM_MEMBER(pInterface, PS2K, Keyboard.IBase);
     
    11601160 *
    11611161 * @returns VBox status code.
    1162  * @param   pInterface      Pointer to the keyboard port interface (KBDState::Keyboard.IPort).
     1162 * @param   pThis           The PS2 keyboard instance data.
    11631163 * @param   u32Usage        USB HID usage code with key
    11641164 *                          press/release flag.
    11651165 */
    1166 static DECLCALLBACK(int) PS2KPutEvent(PPDMIKEYBOARDPORT pInterface, uint32_t u32Usage)
    1167 {
    1168     PPS2K           pThis = RT_FROM_MEMBER(pInterface, PS2K, Keyboard.IPort);
     1166static int ps2kPutEventWorker(PPS2K pThis, uint32_t u32Usage)
     1167{
    11691168    uint8_t         u8HidCode;
    11701169    bool            fKeyDown;
     
    11961195    if (fHaveEvent)
    11971196    {
    1198         rc = PDMCritSectEnter(&pThis->KbdCritSect, VERR_SEM_BUSY);
     1197        rc = PDMCritSectEnter(pThis->pCritSectR3, VERR_SEM_BUSY);
    11991198        AssertReleaseRC(rc);
    12001199
    1201         rc = PS2KProcessKeyEvent(pThis, u8HidCode, fKeyDown);
    1202 
    1203         PDMCritSectLeave(&pThis->KbdCritSect);
     1200        rc = psk2ProcessKeyEvent(pThis, u8HidCode, fKeyDown);
     1201
     1202        PDMCritSectLeave(pThis->pCritSectR3);
    12041203    }
    12051204
     
    12071206}
    12081207
    1209 static DECLCALLBACK(int) PS2KPutEventWrapper(PPDMIKEYBOARDPORT pInterface, uint8_t u8KeyCode)
     1208static DECLCALLBACK(int) ps2kPutEventWrapper(PPDMIKEYBOARDPORT pInterface, uint8_t u8KeyCode)
    12101209{
    12111210    PPS2K       pThis = RT_FROM_MEMBER(pInterface, PS2K, Keyboard.IPort);
     
    12191218        /* Stupid Korean key hack: convert a lone break key into a press/release sequence. */
    12201219        if (u32Usage == 0x80000090 || u32Usage == 0x80000091)
    1221             PS2KPutEvent(pInterface, u32Usage & ~0x80000000);
    1222 
    1223         PS2KPutEvent(pInterface, u32Usage);
     1220            ps2kPutEventWorker(pThis, u32Usage & ~0x80000000);
     1221
     1222        ps2kPutEventWorker(pThis, u32Usage);
    12241223    }
    12251224
     
    12381237 *
    12391238 * @returns VBox status code.
     1239 * @param   pThis       The PS/2 keyboard instance data.
    12401240 * @param   pDevIns     The device instance.
    12411241 * @param   iLUN        The logical unit which is being detached.
    12421242 * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    12431243 */
    1244 int PS2KAttach(PPDMDEVINS pDevIns, PPS2K pThis, unsigned iLUN, uint32_t fFlags)
     1244int PS2KAttach(PPS2K pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    12451245{
    12461246    int         rc;
     
    12751275}
    12761276
    1277 void PS2KSaveState(PSSMHANDLE pSSM, PPS2K pThis)
     1277void PS2KSaveState(PPS2K pThis, PSSMHANDLE pSSM)
    12781278{
    12791279    uint32_t    cPressed = 0;
     
    12941294
    12951295    /* Save the command and keystroke queues. */
    1296     PS2SaveQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
    1297     PS2SaveQueue(pSSM, (GeneriQ *)&pThis->keyQ);
     1296    ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
     1297    ps2kSaveQueue(pSSM, (GeneriQ *)&pThis->keyQ);
    12981298
    12991299    /* Save the command delay timer. Note that the typematic repeat
     
    13201320}
    13211321
    1322 int PS2KLoadState(PSSMHANDLE pSSM, PPS2K pThis, uint32_t uVersion)
     1322int PS2KLoadState(PPS2K pThis, PSSMHANDLE pSSM, uint32_t uVersion)
    13231323{
    13241324    uint8_t     u8;
     
    13421342    SSMR3GetBool(pSSM, &pThis->fScanning);
    13431343
    1344     do {
    1345         /* Load the command and keystroke queues. */
    1346         rc = PS2LoadQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
    1347         if (RT_FAILURE(rc)) break;
    1348         rc = PS2LoadQueue(pSSM, (GeneriQ *)&pThis->keyQ);
    1349         if (RT_FAILURE(rc)) break;
    1350 
    1351         /* Load the command delay timer, just in case. */
    1352         rc = TMR3TimerLoad(pThis->CTX_SUFF(pKbdDelayTimer), pSSM);
    1353         if (RT_FAILURE(rc)) break;
    1354 
    1355         /* Fake key up events for keys that were held down at the time the state was saved. */
    1356         rc = SSMR3GetU32(pSSM, &cPressed);
    1357         if (RT_FAILURE(rc)) break;
    1358 
    1359         while (cPressed--)
    1360         {
    1361             rc = SSMR3GetU8(pSSM, &u8);
    1362             if (RT_FAILURE(rc)) break;
    1363             PS2KProcessKeyEvent(pThis, u8, false /* key up */);
    1364         }
    1365         if (RT_FAILURE(rc)) break;
    1366 
    1367         /* Load typematic settings for Scan Set 3. */
    1368         rc = SSMR3GetU32(pSSM, &cbTMSSize);
    1369         if (RT_FAILURE(rc)) break;
    1370 
    1371         while (cbTMSSize--)
    1372         {
    1373             rc = SSMR3GetU8(pSSM, &u8);
    1374             if (RT_FAILURE(rc)) break;
    1375         }
    1376     } while (0);
     1344    /* Load the command and keystroke queues. */
     1345    rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->cmdQ);
     1346    AssertRCReturn(rc, rc);
     1347    rc = ps2kLoadQueue(pSSM, (GeneriQ *)&pThis->keyQ);
     1348    AssertRCReturn(rc, rc);
     1349
     1350    /* Load the command delay timer, just in case. */
     1351    rc = TMR3TimerLoad(pThis->CTX_SUFF(pKbdDelayTimer), pSSM);
     1352    AssertRCReturn(rc, rc);
     1353
     1354    /* Fake key up events for keys that were held down at the time the state was saved. */
     1355    rc = SSMR3GetU32(pSSM, &cPressed);
     1356    AssertRCReturn(rc, rc);
     1357
     1358    while (cPressed--)
     1359    {
     1360        rc = SSMR3GetU8(pSSM, &u8);
     1361        AssertRCReturn(rc, rc);
     1362        psk2ProcessKeyEvent(pThis, u8, false /* key up */);
     1363    }
     1364
     1365    /* Load typematic settings for Scan Set 3. */
     1366    rc = SSMR3GetU32(pSSM, &cbTMSSize);
     1367    AssertRCReturn(rc, rc);
     1368
     1369    while (cbTMSSize--)
     1370    {
     1371        rc = SSMR3GetU8(pSSM, &u8);
     1372        AssertRCReturn(rc, rc);
     1373    }
    13771374
    13781375    return rc;
     
    13921389    /* Clear queues and any pressed keys. */
    13931390    memset(pThis->abDepressedKeys, 0, sizeof(pThis->abDepressedKeys));
    1394     PS2ClearQueue((GeneriQ *)&pThis->cmdQ);
    1395     PS2KSetDefaults(pThis);     /* Also clears keystroke queue. */
     1391    ps2kClearQueue((GeneriQ *)&pThis->cmdQ);
     1392    ps2kSetDefaults(pThis);     /* Also clears keystroke queue. */
    13961393
    13971394    /* Activate the PS/2 keyboard by default. */
     
    14001397}
    14011398
    1402 void PS2KRelocate(PPS2K pThis, RTGCINTPTR offDelta)
     1399void PS2KRelocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
    14031400{
    14041401    LogFlowFunc(("Relocating PS2K\n"));
     
    14081405}
    14091406
    1410 int PS2KConstruct(PPDMDEVINS pDevIns, PPS2K pThis, void *pParent, int iInstance)
     1407int PS2KConstruct(PPS2K pThis, PPDMDEVINS pDevIns, void *pParent, int iInstance)
    14111408{
    14121409    int     rc;
     
    14201417    pThis->cmdQ.cSize = KBD_CMD_QUEUE_SIZE;
    14211418
    1422     pThis->Keyboard.IBase.pfnQueryInterface = PS2KQueryInterface;
    1423     pThis->Keyboard.IPort.pfnPutEvent       = PS2KPutEventWrapper;
     1419    pThis->Keyboard.IBase.pfnQueryInterface = ps2kQueryInterface;
     1420    pThis->Keyboard.IPort.pfnPutEvent       = ps2kPutEventWrapper;
    14241421
    14251422    /*
    1426      * Initialize the critical section.
     1423     * Initialize the critical section pointer(s).
    14271424     */
    1428     rc = PDMDevHlpCritSectInit(pDevIns, &pThis->KbdCritSect, RT_SRC_POS, "PS2K#%u", iInstance);
    1429     if (RT_FAILURE(rc))
    1430         return rc;
     1425    pThis->pCritSectR3 = pDevIns->pCritSectRoR3;
    14311426
    14321427    /*
     
    14341429     */
    14351430    PTMTIMER pTimer;
    1436     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_REAL, PS2KTypematicTimer, pThis,
     1431    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_REAL, ps2kTypematicTimer, pThis,
    14371432                                TMTIMER_FLAGS_NO_CRIT_SECT, "PS2K Typematic Timer", &pTimer);
    1438     if (RT_FAILURE (rc))
     1433    if (RT_FAILURE(rc))
    14391434        return rc;
    14401435
     
    14461441     * Create the command delay timer.
    14471442     */
    1448     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, PS2KDelayTimer, pThis,
     1443    rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kDelayTimer, pThis,
    14491444                                TMTIMER_FLAGS_NO_CRIT_SECT, "PS2K Delay Timer", &pTimer);
    1450     if (RT_FAILURE (rc))
     1445    if (RT_FAILURE(rc))
    14511446        return rc;
    14521447
     
    14581453     * Register debugger info callbacks.
    14591454     */
    1460     PDMDevHlpDBGFInfoRegister(pDevIns, "ps2k", "Display PS/2 keyboard state.", PS2KInfoState);
     1455    PDMDevHlpDBGFInfoRegister(pDevIns, "ps2k", "Display PS/2 keyboard state.", ps2kInfoState);
    14611456
    14621457    return rc;
     
    14651460#endif
    14661461
    1467 //@todo: The following should live with the KBC implementation.
     1462///@todo The following should live with the KBC implementation.
    14681463
    14691464/* Table used by the keyboard controller to optionally translate the incoming
  • trunk/src/VBox/Devices/testcase/tstDeviceStructSize.cpp

    r44804 r44806  
    296296    CHECK_MEMBER_ALIGNMENT(IOAPIC, StatMMIOReadGC, 8);
    297297#endif
    298     CHECK_MEMBER_ALIGNMENT(KBDState, CritSect, 8);
    299     CHECK_MEMBER_ALIGNMENT(PS2K, KbdCritSect, 8);
    300298    CHECK_MEMBER_ALIGNMENT(LSILOGISCSI, ReplyPostQueueCritSect, 8);
    301299    CHECK_MEMBER_ALIGNMENT(LSILOGISCSI, ReplyFreeQueueCritSect, 8);
  • trunk/src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp

    r44804 r44806  
    392392    GEN_CHECK_OFF(KBDState, pDevInsR0);
    393393    GEN_CHECK_OFF(KBDState, pDevInsRC);
    394     GEN_CHECK_OFF(KBDState, CritSect);
    395394    GEN_CHECK_SIZE(KbdKeyQ);
    396395    GEN_CHECK_OFF(KbdCmdQ, rpos);
     
    414413    GEN_CHECK_OFF(PS2K, pKbdTypematicTimerR3);
    415414    GEN_CHECK_OFF(PS2K, pKbdTypematicTimerR0);
     415    GEN_CHECK_OFF(PS2K, pCritSectR3);
    416416    GEN_CHECK_OFF(PS2K, Keyboard.IBase);
    417417    GEN_CHECK_OFF(PS2K, Keyboard.IPort);
Note: See TracChangeset for help on using the changeset viewer.

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