VirtualBox

Changeset 82208 in vbox


Ignore:
Timestamp:
Nov 25, 2019 11:41:15 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135022
Message:

DevPS2: Converted the generic queue stuff into some a lot more paranoid (I hope), requiring no ugly casting. bugref:9218

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

Legend:

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

    r82206 r82208  
    718718 * Clear a queue.
    719719 *
    720  * @param   pQ                  Pointer to the queue.
    721  */
    722 void PS2CmnClearQueue(GeneriQ *pQ)
    723 {
    724     LogFlowFunc(("Clearing queue %p\n", pQ));
    725     pQ->wpos  = pQ->rpos;
    726     pQ->cUsed = 0;
     720 * @param   pQHdr       The queue header.
     721 * @param   cElements   The queue size.
     722 */
     723void PS2CmnClearQueue(PPS2QHDR pQHdr, size_t cElements)
     724{
     725    Assert(cElements > 0);
     726    LogFlowFunc(("Clearing queue %p\n", pQHdr));
     727    pQHdr->wpos  = pQHdr->rpos = pQHdr->rpos % cElements;
     728    pQHdr->cUsed = 0;
    727729}
    728730
     
    731733 * Add a byte to a queue.
    732734 *
    733  * @param   pQ                  Pointer to the queue.
    734  * @param   val                 The byte to store.
    735  */
    736 void PS2CmnInsertQueue(GeneriQ *pQ, uint8_t val)
    737 {
    738     /* Check if queue is full. */
    739     if (pQ->cUsed >= pQ->cSize)
    740     {
    741         LogRelFlowFunc(("queue %p full (%d entries)\n", pQ, pQ->cUsed));
    742         return;
    743     }
    744     /* Insert data and update circular buffer write position. */
    745     pQ->abQueue[pQ->wpos] = val;
    746     if (++pQ->wpos == pQ->cSize)
    747         pQ->wpos = 0;   /* Roll over. */
    748     ++pQ->cUsed;
    749     LogRelFlowFunc(("inserted 0x%02X into queue %p\n", val, pQ));
     735 * @param   pQHdr       The queue header.
     736 * @param   cElements   The queue size.
     737 * @param   abElements  The queue element array.
     738 * @param   bValue      The byte to store.
     739 */
     740void PS2CmnInsertQueue(PPS2QHDR pQHdr, size_t cElements, uint8_t *pbElements, uint8_t bValue)
     741{
     742    Assert(cElements > 0);
     743
     744    /* Check that the queue is not full. */
     745    uint32_t cUsed = pQHdr->cUsed;
     746    if (cUsed < cElements)
     747    {
     748        /* Insert data and update circular buffer write position. */
     749        uint32_t wpos = pQHdr->wpos % cElements;
     750        pbElements[wpos] = bValue;
     751
     752        wpos += 1;
     753        if (wpos < cElements)
     754            pQHdr->wpos = wpos;
     755        else
     756            pQHdr->wpos = 0; /* Roll over. */
     757        pQHdr->cUsed = cUsed + 1;
     758
     759        LogRelFlowFunc(("inserted %#04x into queue %p\n", bValue, pQHdr));
     760    }
     761    else
     762    {
     763        Assert(cUsed == cElements);
     764        LogRelFlowFunc(("queue %p full (%zu entries)\n", pQHdr, cElements));
     765    }
    750766}
    751767
     
    753769 * Retrieve a byte from a queue.
    754770 *
    755  * @param   pQ                  Pointer to the queue.
    756  * @param   pVal                Pointer to storage for the byte.
     771 * @param   pQHdr       The queue header.
     772 * @param   cElements   The queue size.
     773 * @param   abElements  The queue element array.
     774 * @param   pbValue     Where to return the byte on success.
    757775 *
    758776 * @retval  VINF_TRY_AGAIN if queue is empty,
    759777 * @retval  VINF_SUCCESS if a byte was read.
    760778 */
    761 int PS2CmnRemoveQueue(GeneriQ *pQ, uint8_t *pVal)
     779int PS2CmnRemoveQueue(PPS2QHDR pQHdr, size_t cElements, uint8_t const *pbElements, uint8_t *pbValue)
    762780{
    763781    int rc;
    764782
    765     Assert(pVal);
    766     if (pQ->cUsed)
    767     {
    768         *pVal = pQ->abQueue[pQ->rpos];
    769         if (++pQ->rpos == pQ->cSize)
    770             pQ->rpos = 0;   /* Roll over. */
    771         --pQ->cUsed;
    772         LogFlowFunc(("removed 0x%02X from queue %p\n", *pVal, pQ));
     783    Assert(cElements > 0);
     784    Assert(pbValue);
     785
     786    uint32_t cUsed = (uint32_t)RT_MIN(pQHdr->cUsed, cElements);
     787    if (cUsed > 0)
     788    {
     789        uint32_t rpos = pQHdr->rpos % cElements;
     790        *pbValue = pbElements[rpos];
     791
     792        rpos += 1;
     793        if (rpos < cElements)
     794            pQHdr->rpos = rpos;
     795        else
     796            pQHdr->rpos = 0;   /* Roll over. */
     797        pQHdr->cUsed = cUsed - 1;
     798
     799        LogFlowFunc(("removed 0x%02X from queue %p\n", *pbValue, pQHdr));
    773800        rc = VINF_SUCCESS;
    774801    }
    775802    else
    776803    {
    777         LogFlowFunc(("queue %p empty\n", pQ));
     804        LogFlowFunc(("queue %p empty\n", pQHdr));
    778805        rc = VINF_TRY_AGAIN;
    779806    }
     
    786813 * Save a queue state.
    787814 *
    788  * @param   pHlp                The device helpers.
    789  * @param   pSSM                SSM handle to write the state to.
    790  * @param   pQ                  Pointer to the queue.
    791  */
    792 void PS2CmnR3SaveQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, GeneriQ *pQ)
    793 {
    794     uint32_t    cItems = pQ->cUsed;
    795     uint32_t    i;
     815 * @param   pHlp        The device helpers.
     816 * @param   pSSM        SSM handle to write the state to.
     817 * @param   pQHdr       The queue header.
     818 * @param   cElements   The queue size.
     819 * @param   abElements  The queue element array.
     820 */
     821void PS2CmnR3SaveQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, PPS2QHDR pQHdr, size_t cElements, uint8_t const *pbElements)
     822{
     823    uint32_t cItems = (uint32_t)RT_MIN(pQHdr->cUsed, cElements);
    796824
    797825    /* Only save the number of items. Note that the read/write
     
    800828    pHlp->pfnSSMPutU32(pSSM, cItems);
    801829
    802     LogFlow(("Storing %d items from queue %p\n", cItems, pQ));
     830    LogFlow(("Storing %u items from queue %p\n", cItems, pQHdr));
    803831
    804832    /* Save queue data - only the bytes actually used (typically zero). */
    805     for (i = pQ->rpos % pQ->cSize; cItems-- > 0; i = (i + 1) % pQ->cSize)
    806         pHlp->pfnSSMPutU8(pSSM, pQ->abQueue[i]);
     833    for (uint32_t i = pQHdr->rpos % cElements; cItems-- > 0; i = (i + 1) % cElements)
     834        pHlp->pfnSSMPutU8(pSSM, pbElements[i]);
    807835}
    808836
     
    810838 * Load a queue state.
    811839 *
    812  * @param   pHlp                The device helpers.
    813  * @param   pSSM                SSM handle to read the state from.
    814  * @param   pQ                  Pointer to the queue.
     840 * @param   pHlp        The device helpers.
     841 * @param   pSSM        SSM handle to read the state from.
     842 * @param   pQHdr       The queue header.
     843 * @param   cElements   The queue size.
     844 * @param   abElements  The queue element array.
    815845 *
    816846 * @returns VBox status/error code.
    817847 */
    818 int PS2CmnR3LoadQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, GeneriQ *pQ)
    819 {
    820     int         rc;
    821 
     848int PS2CmnR3LoadQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, PPS2QHDR pQHdr, size_t cElements, uint8_t *pbElements)
     849{
    822850    /* On load, always put the read pointer at zero. */
    823     rc = pHlp->pfnSSMGetU32(pSSM, &pQ->cUsed);
    824     AssertRCReturn(rc, rc);
    825 
    826     LogFlow(("Loading %d items to queue %p\n", pQ->cUsed, pQ));
    827 
    828     AssertMsgReturn(pQ->cUsed <= pQ->cSize, ("Saved size=%u, actual=%u\n", pQ->cUsed, pQ->cSize),
     851    uint32_t cUsed;
     852    int rc = pHlp->pfnSSMGetU32(pSSM, &cUsed);
     853    AssertRCReturn(rc, rc);
     854
     855    LogFlow(("Loading %u items to queue %p\n", cUsed, pQHdr));
     856
     857    AssertMsgReturn(cUsed <= cElements, ("Saved size=%u, actual=%zu\n", cUsed, cElements),
    829858                    VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
    830859
    831860    /* Recalculate queue positions and load data in one go. */
    832     pQ->rpos = 0;
    833     pQ->wpos = pQ->cUsed;
    834     return pHlp->pfnSSMGetMem(pSSM, pQ->abQueue, pQ->cUsed);
     861    pQHdr->rpos  = 0;
     862    pQHdr->wpos  = cUsed;
     863    pQHdr->cUsed = cUsed;
     864    return pHlp->pfnSSMGetMem(pSSM, pbElements, cUsed);
    835865}
    836866
     
    10011031    PKBDSTATER3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PKBDSTATER3);
    10021032    int         rc;
     1033    RT_NOREF(iInstance);
     1034
    10031035    Assert(iInstance == 0);
    10041036
     
    10121044     * Initialize the sub-components.
    10131045     */
    1014     rc = PS2KR3Construct(pDevIns, &pThis->Kbd, &pThisCC->Kbd, iInstance, pCfg);
    1015     AssertRCReturn(rc, rc);
    1016 
    1017     rc = PS2MR3Construct(pDevIns, &pThis->Aux, &pThisCC->Aux, iInstance);
     1046    rc = PS2KR3Construct(pDevIns, &pThis->Kbd, &pThisCC->Kbd, pCfg);
     1047    AssertRCReturn(rc, rc);
     1048
     1049    rc = PS2MR3Construct(pDevIns, &pThis->Aux, &pThisCC->Aux);
    10181050    AssertRCReturn(rc, rc);
    10191051
  • trunk/src/VBox/Devices/Input/DevPS2.h

    r82206 r82208  
    2929typedef struct KBDSTATE *PKBDSTATE;
    3030
     31
     32/** @name PS/2 Input Queue Primitive
     33 * @{ */
     34typedef struct PS2QHDR
     35{
     36    uint32_t volatile   rpos;
     37    uint32_t volatile   wpos;
     38    uint32_t volatile   cUsed;
     39} PS2QHDR;
     40/** Pointer to a queue header. */
     41typedef PS2QHDR *PPS2QHDR;
     42
    3143/** Define a simple PS/2 input device queue. */
    32 #define DEF_PS2Q_TYPE(name, size)   \
    33      typedef struct {               \
    34         uint32_t    rpos;           \
    35         uint32_t    wpos;           \
    36         uint32_t    cUsed;          \
    37         uint32_t    cSize;          \
     44#define DEF_PS2Q_TYPE(name, size) \
     45     typedef struct { \
     46        PS2QHDR     Hdr; \
    3847        uint8_t     abQueue[size];  \
    3948     } name
    4049
    41 DEF_PS2Q_TYPE(GeneriQ, 1);
    42 void PS2CmnClearQueue(GeneriQ *pQ);
    43 void PS2CmnInsertQueue(GeneriQ *pQ, uint8_t val);
    44 int  PS2CmnRemoveQueue(GeneriQ *pQ, uint8_t *pVal);
    45 void PS2CmnR3SaveQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, GeneriQ *pQ);
    46 int  PS2CmnR3LoadQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, GeneriQ *pQ);
     50void PS2CmnClearQueue(PPS2QHDR pQHdr, size_t cElements);
     51void PS2CmnInsertQueue(PPS2QHDR pQHdr, size_t cElements, uint8_t *pbElements, uint8_t bValue);
     52int  PS2CmnRemoveQueue(PPS2QHDR pQHdr, size_t cElements, uint8_t const *pbElements, uint8_t *pbValue);
     53void PS2CmnR3SaveQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, PPS2QHDR pQHdr, size_t cElements, uint8_t const *pbElements);
     54int  PS2CmnR3LoadQueue(PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM, PPS2QHDR pQHdr, size_t cElements, uint8_t *pbElements);
     55
     56#define PS2Q_CLEAR(a_pQueue) \
     57    PS2CmnClearQueue(&(a_pQueue)->Hdr, RT_ELEMENTS((a_pQueue)->abQueue))
     58#define PS2Q_INSERT(a_pQueue, a_bValue) \
     59    PS2CmnInsertQueue(&(a_pQueue)->Hdr, RT_ELEMENTS((a_pQueue)->abQueue), (a_pQueue)->abQueue, (a_bValue))
     60#define PS2Q_REMOVE(a_pQueue, a_pbValue) \
     61    PS2CmnRemoveQueue(&(a_pQueue)->Hdr, RT_ELEMENTS((a_pQueue)->abQueue), (a_pQueue)->abQueue, (a_pbValue))
     62#define PS2Q_SAVE(a_pHlp, a_pSSM, a_pQueue) \
     63    PS2CmnR3SaveQueue((a_pHlp), (a_pSSM), &(a_pQueue)->Hdr, RT_ELEMENTS((a_pQueue)->abQueue), (a_pQueue)->abQueue)
     64#define PS2Q_LOAD(a_pHlp, a_pSSM, a_pQueue) \
     65    PS2CmnR3LoadQueue((a_pHlp), (a_pSSM), &(a_pQueue)->Hdr, RT_ELEMENTS((a_pQueue)->abQueue), (a_pQueue)->abQueue)
     66#define PS2Q_SIZE(a_pQueue)     RT_ELEMENTS((a_pQueue)->abQueue)
     67#define PS2Q_COUNT(a_pQueue)    ((a_pQueue)->Hdr.cUsed)
     68#define PS2Q_RD_POS(a_pQueue)   ((a_pQueue)->Hdr.rpos)
     69#define PS2Q_WR_POS(a_pQueue)   ((a_pQueue)->Hdr.wpos)
     70/** @} */
    4771
    4872
     
    173197int  PS2KByteFromKbd(PPDMDEVINS pDevIns, PPS2K pThis, uint8_t *pVal);
    174198
    175 int  PS2KR3Construct(PPDMDEVINS pDevIns, PPS2K pThis, PPS2KR3 pThisCC, unsigned iInstance, PCFGMNODE pCfg);
     199int  PS2KR3Construct(PPDMDEVINS pDevIns, PPS2K pThis, PPS2KR3 pThisCC, PCFGMNODE pCfg);
    176200int  PS2KR3Attach(PPDMDEVINS pDevIns, PPS2KR3 pThisCC, unsigned iLUN, uint32_t fFlags);
    177201void PS2KR3Reset(PPDMDEVINS pDevIns, PPS2K pThis, PPS2KR3 pThisCC);
     
    317341int  PS2MByteFromAux(PPS2M pThis, uint8_t *pVal);
    318342
    319 int  PS2MR3Construct(PPDMDEVINS pDevIns, PPS2M pThis, PPS2MR3 pThisCC, unsigned iInstance);
     343int  PS2MR3Construct(PPDMDEVINS pDevIns, PPS2M pThis, PPS2MR3 pThisCC);
    320344int  PS2MR3Attach(PPDMDEVINS pDevIns, PPS2MR3 pThisCC, unsigned iLUN, uint32_t fFlags);
    321345void PS2MR3Reset(PPS2M pThis);
  • trunk/src/VBox/Devices/Input/DevPS2K.cpp

    r82206 r82208  
    380380 * Add a null-terminated byte sequence to a queue if there is enough room.
    381381 *
    382  * @param   pQ                  Pointer to the queue.
    383  * @param   pStr                Pointer to the bytes to store.
    384  * @param   uReserve            Number of bytes that must still remain
    385  *                              available in queue.
    386  * @return  int                 VBox status/error code.
    387  */
    388 static int ps2kR3InsertStrQueue(GeneriQ *pQ, const uint8_t *pStr, uint32_t uReserve)
    389 {
    390     uint32_t    cbStr;
    391     unsigned    i;
    392 
    393     cbStr = (uint32_t)strlen((const char *)pStr);
    394 
     382 * @param   pQueue      Pointer to the queue.
     383 * @param   pStr        Pointer to the bytes to store.
     384 * @param   cbReserve   Number of bytes that must still remain available in
     385 *                      queue.
     386 * @return  VBox status/error code.
     387 */
     388static int ps2kR3InsertStrQueue(KbdKeyQ *pQueue, const uint8_t *pStr, uint32_t cbReserve)
     389{
    395390    /* Check if queue has enough room. */
    396     if (pQ->cUsed + uReserve + cbStr >= pQ->cSize)
    397     {
    398         LogRelFlowFunc(("queue %p full (%u entries, want room for %u), cannot insert %u entries\n",
    399                         pQ, pQ->cUsed, uReserve, cbStr));
     391    size_t const cbStr = (uint32_t)strlen((const char *)pStr);
     392    uint32_t     cUsed = RT_MIN(pQueue->Hdr.cUsed, RT_ELEMENTS(pQueue->abQueue));
     393    if (cUsed + cbReserve + cbStr >= RT_ELEMENTS(pQueue->abQueue))
     394    {
     395        LogRelFlowFunc(("queue %p (KbdKeyQ) full (%u entries, want room for %u), cannot insert %zu entries\n",
     396                        pQueue, cUsed, cbReserve, cbStr));
    400397        return VERR_BUFFER_OVERFLOW;
    401398    }
    402399
    403400    /* Insert byte sequence and update circular buffer write position. */
    404     for (i = 0; i < cbStr; ++i) {
    405         pQ->abQueue[pQ->wpos] = pStr[i];
    406         if (++pQ->wpos == pQ->cSize)
    407             pQ->wpos = 0;   /* Roll over. */
    408     }
    409     pQ->cUsed += cbStr;
    410     LogRelFlowFunc(("inserted %u bytes into queue %p\n", cbStr, pQ));
     401    uint32_t wpos = pQueue->Hdr.wpos % RT_ELEMENTS(pQueue->abQueue);
     402    for (size_t i = 0; i < cbStr; i++)
     403    {
     404        pQueue->abQueue[wpos] = pStr[i];
     405        wpos += 1;
     406        if (wpos < RT_ELEMENTS(pQueue->abQueue))
     407        { /* likely */ }
     408        else
     409            wpos = 0; /* Roll over. */
     410    }
     411
     412    pQueue->Hdr.wpos  = wpos;
     413    pQueue->Hdr.cUsed = cUsed + (uint32_t)cbStr;
     414
     415    LogRelFlowFunc(("inserted %u bytes into queue %p (KbdKeyQ)\n", cbStr, pQueue));
    411416    return VINF_SUCCESS;
    412417}
     
    430435
    431436    pThisCC->Keyboard.pDrv->pfnLedStatusChange(pThisCC->Keyboard.pDrv, enmLeds);
    432 }
    433 
    434 /**
    435  * Query the number of items currently in a queue.
    436  *
    437  * @param   pQ                  Pointer to the queue.
    438  *
    439  * @return  uint32_t            Number of items in queue.
    440  */
    441 static uint32_t ps2R3kInQueue(GeneriQ *pQ)
    442 {
    443     return pQ->cUsed;
    444437}
    445438
     
    481474{
    482475    LogFlowFunc(("Set keyboard defaults\n"));
    483     PS2CmnClearQueue((GeneriQ *)&pThis->keyQ);
     476    PS2Q_CLEAR(&pThis->keyQ);
    484477    /* Set default Scan Set 3 typematic values. */
    485478    /* Set default typematic rate/delay. */
     
    509502    {
    510503        case KCMD_ECHO:
    511             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ECHO);
     504            PS2Q_INSERT(&pThis->cmdQ, KRSP_ECHO);
    512505            pThis->u8CurrCmd = 0;
    513506            break;
    514507        case KCMD_READ_ID:
    515             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    516             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID1);
    517             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ID2);
     508            PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
     509            PS2Q_INSERT(&pThis->cmdQ, KRSP_ID1);
     510            PS2Q_INSERT(&pThis->cmdQ, KRSP_ID2);
    518511            pThis->u8CurrCmd = 0;
    519512            break;
    520513        case KCMD_ENABLE:
    521514            pThis->fScanning = true;
    522             PS2CmnClearQueue((GeneriQ *)&pThis->keyQ);
     515            PS2Q_CLEAR(&pThis->keyQ);
    523516            ps2kStopTypematicRepeat(pDevIns, pThis);
    524             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     517            PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    525518            pThis->u8CurrCmd = 0;
    526519            break;
     
    528521            pThis->fScanning = false;
    529522            ps2kSetDefaults(pDevIns, pThis); /* Also clears buffer/typematic state. */
    530             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     523            PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    531524            pThis->u8CurrCmd = 0;
    532525            break;
    533526        case KCMD_SET_DEFAULT:
    534527            ps2kSetDefaults(pDevIns, pThis);
    535             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     528            PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    536529            pThis->u8CurrCmd = 0;
    537530            break;
     
    541534        case KCMD_ALL_TMB:
    542535            /// @todo Set the key types here.
    543             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     536            PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    544537            pThis->u8CurrCmd = 0;
    545538            break;
     
    551544            ps2kSetDefaults(pDevIns, pThis);
    552545            /// @todo reset more?
    553             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     546            PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    554547            pThis->u8CurrCmd = cmd;
    555548            /* Delay BAT completion; the test may take hundreds of ms. */
     
    563556        case KCMD_TYPE_MK_BRK:
    564557        case KCMD_TYPE_MAKE:
    565             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     558            PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    566559            pThis->u8CurrCmd = cmd;
    567560            break;
     
    578571                        ps2kR3NotifyLedsState(pThisCC, cmd);
    579572                        pThis->fNumLockOn = !!(cmd & 0x02); /* Sync internal Num Lock state. */
    580                         PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     573                        PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    581574                        pThis->u8LEDs = cmd;
    582575                        pThis->u8CurrCmd = 0;
     
    585578                    break;
    586579                case KCMD_SCANSET:
    587                     PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     580                    PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    588581                    if (cmd == 0)
    589                         PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8ScanSet);
     582                        PS2Q_INSERT(&pThis->cmdQ, pThis->u8ScanSet);
    590583                    else if (cmd < 4)
    591584                    {
     
    598591                case KCMD_RATE_DELAY:
    599592                    ps2kSetupTypematic(pThis, cmd);
    600                     PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
     593                    PS2Q_INSERT(&pThis->cmdQ, KRSP_ACK);
    601594                    pThis->u8CurrCmd = 0;
    602595                    break;
     
    611604        case KCMD_INVALID_1:
    612605        case KCMD_INVALID_2:
    613             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_RESEND);
     606            PS2Q_INSERT(&pThis->cmdQ, KRSP_RESEND);
    614607            pThis->u8CurrCmd = 0;
    615608            break;
     
    640633     * the command queue is empty.
    641634     */
    642     rc = PS2CmnRemoveQueue((GeneriQ *)&pThis->cmdQ, pb);
     635    rc = PS2Q_REMOVE(&pThis->cmdQ, pb);
    643636    if (rc != VINF_SUCCESS && !pThis->u8CurrCmd && pThis->fScanning)
    644637        if (!pThis->fThrottleActive)
    645638        {
    646             rc = PS2CmnRemoveQueue((GeneriQ *)&pThis->keyQ, pb);
     639            rc = PS2Q_REMOVE(&pThis->keyQ, pb);
    647640            if (pThis->fThrottleEnabled)
    648641            {
     
    800793            /* Feed the bytes to the queue if there is room. */
    801794            /// @todo Send overrun code if sequence won't fit?
    802             ps2kR3InsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
     795            ps2kR3InsertStrQueue(&pThis->keyQ, abCodes, 0);
    803796        }
    804797        else if (!(pKeyDef->keyFlags & (KF_NB | KF_PB)))
     
    855848            /* Feed the bytes to the queue if there is room. */
    856849            /// @todo Send overrun code if sequence won't fit?
    857             ps2kR3InsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
     850            ps2kR3InsertStrQueue(&pThis->keyQ, abCodes, 0);
    858851        }
    859852    }
     
    880873        /* Feed the bytes to the queue if there is room. */
    881874        /// @todo Send overrun code if sequence won't fit?
    882         ps2kR3InsertStrQueue((GeneriQ *)&pThis->keyQ, abCodes, 0);
     875        ps2kR3InsertStrQueue(&pThis->keyQ, abCodes, 0);
    883876    }
    884877
     
    948941     */
    949942    pThis->fThrottleActive = false;
    950     uHaveData = ps2R3kInQueue((GeneriQ *)&pThis->keyQ);
     943    uHaveData = PS2Q_COUNT(&pThis->keyQ);
    951944    LogFlowFunc(("Have%s bytes\n", uHaveData ? "" : " no"));
    952945    if (uHaveData)
     
    998991
    999992    AssertMsg(pThis->u8CurrCmd == KCMD_RESET, ("u8CurrCmd=%02x\n", pThis->u8CurrCmd));
    1000     PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_BAT_OK);
     993    PS2Q_INSERT(&pThis->cmdQ, KRSP_BAT_OK);
    1001994    pThis->fScanning = true;    /* BAT completion enables scanning! */
    1002995    pThis->u8CurrCmd = 0;
     
    10461039                    pThis->uTypematicDelay, pThis->uTypematicRepeat);
    10471040    pHlp->pfnPrintf(pHlp, "Command queue: %d items (%d max)\n",
    1048                     pThis->cmdQ.cUsed, pThis->cmdQ.cSize);
     1041                    PS2Q_COUNT(&pThis->cmdQ), PS2Q_SIZE(&pThis->cmdQ));
    10491042    pHlp->pfnPrintf(pHlp, "Input queue  : %d items (%d max)\n",
    1050                     pThis->keyQ.cUsed, pThis->keyQ.cSize);
     1043                    PS2Q_COUNT(&pThis->keyQ), PS2Q_SIZE(&pThis->keyQ));
    10511044    if (pThis->enmTypematicState != KBD_TMS_IDLE)
    10521045        pHlp->pfnPrintf(pHlp, "Active typematic key %08X (%s)\n", pThis->u32TypematicKey,
     
    12241217
    12251218    /* Save the command and keystroke queues. */
    1226     PS2CmnR3SaveQueue(pHlp, pSSM, (GeneriQ *)&pThis->cmdQ);
    1227     PS2CmnR3SaveQueue(pHlp, pSSM, (GeneriQ *)&pThis->keyQ);
     1219    PS2Q_SAVE(pHlp, pSSM, &pThis->cmdQ);
     1220    PS2Q_SAVE(pHlp, pSSM, &pThis->keyQ);
    12281221
    12291222    /* Save the command delay timer. Note that the typematic repeat
     
    12761269
    12771270    /* Load the command and keystroke queues. */
    1278     rc = PS2CmnR3LoadQueue(pHlp, pSSM, (GeneriQ *)&pThis->cmdQ);
     1271    rc = PS2Q_LOAD(pHlp, pSSM, &pThis->cmdQ);
    12791272    AssertRCReturn(rc, rc);
    1280     rc = PS2CmnR3LoadQueue(pHlp, pSSM, (GeneriQ *)&pThis->keyQ);
     1273    rc = PS2Q_LOAD(pHlp, pSSM, &pThis->keyQ);
    12811274    AssertRCReturn(rc, rc);
    12821275
     
    13401333    /* Clear queues and any pressed keys. */
    13411334    memset(pThis->abDepressedKeys, 0, sizeof(pThis->abDepressedKeys));
    1342     PS2CmnClearQueue((GeneriQ *)&pThis->cmdQ);
     1335    PS2Q_CLEAR(&pThis->cmdQ);
    13431336    ps2kSetDefaults(pDevIns, pThis);     /* Also clears keystroke queue. */
    13441337
     
    13481341}
    13491342
    1350 int PS2KR3Construct(PPDMDEVINS pDevIns, PPS2K pThis, PPS2KR3 pThisCC, unsigned iInstance, PCFGMNODE pCfg)
    1351 {
     1343int PS2KR3Construct(PPDMDEVINS pDevIns, PPS2K pThis, PPS2KR3 pThisCC, PCFGMNODE pCfg)
     1344{
     1345    LogFlowFunc(("\n"));
    13521346    PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
    1353     RT_NOREF(pDevIns, iInstance);
    1354     LogFlowFunc(("iInstance=%u\n", iInstance));
    1355 
    1356     pThisCC->pDevIns = pDevIns;
    1357 
     1347
     1348    /*
     1349     * Read configuration.
     1350     */
    13581351    bool fThrottleEnabled;
    13591352    int rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "KbdThrottleEnabled", &fThrottleEnabled, true);
     
    13631356    pThis->fThrottleEnabled = fThrottleEnabled;
    13641357
    1365     /* Initialize the queues. */
    1366     pThis->keyQ.cSize = KBD_KEY_QUEUE_SIZE;
    1367     pThis->cmdQ.cSize = KBD_CMD_QUEUE_SIZE;
    1368 
     1358    /*
     1359     * Initialize state.
     1360     */
     1361    pThisCC->pDevIns                          = pDevIns;
    13691362    pThisCC->Keyboard.IBase.pfnQueryInterface = ps2kR3QueryInterface;
    13701363    pThisCC->Keyboard.IPort.pfnPutEventHid    = ps2kR3KeyboardPort_PutEventHid;
     
    13741367     */
    13751368    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3ThrottleTimer, pThis,
    1376                                 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Throttle Timer", &pThis->hThrottleTimer);
     1369                              TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Throttle Timer", &pThis->hThrottleTimer);
    13771370    AssertRCReturn(rc, rc);
    13781371
  • trunk/src/VBox/Devices/Input/DevPS2M.cpp

    r82206 r82208  
    219219static void ps2mR3Reset(PPS2M pThis, PPS2MR3 pThisCC)
    220220{
    221     PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_BAT_OK);
    222     PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, 0);
     221    PS2Q_INSERT(&pThis->cmdQ, ARSP_BAT_OK);
     222    PS2Q_INSERT(&pThis->cmdQ, 0);
    223223    pThis->enmMode   = AUX_MODE_STD;
    224224    pThis->u8CurrCmd = 0;
     
    250250
    251251    /* Event queue, eccumulators, and button status bits are cleared. */
    252     PS2CmnClearQueue((GeneriQ *)&pThis->evtQ);
     252    PS2Q_CLEAR(&pThis->evtQ);
    253253    pThis->iAccumX = pThis->iAccumY = pThis->iAccumZ = pThis->iAccumW = pThis->fAccumB = 0;
    254254}
     
    306306#define PS2M_IMEX_BTN_MASK  (RT_BIT(3) | RT_BIT(4))
    307307
    308 /* Report accumulated movement and button presses, then clear the accumulators. */
    309 static void ps2mReportAccumulatedEvents(PPS2M pThis, GeneriQ *pQueue, bool fAccumBtns)
     308/** Report accumulated movement and button presses, then clear the accumulators. */
     309static void ps2mReportAccumulatedEvents(PPS2M pThis, PPS2QHDR pQHdr, size_t cQElements, uint8_t *pbQElements, bool fAccumBtns)
    310310{
    311311    uint32_t    fBtnState = fAccumBtns ? pThis->fAccumB : pThis->fCurrB;
     
    326326
    327327    /* Send the standard 3-byte packet (always the same). */
    328     PS2CmnInsertQueue(pQueue, val);
    329     PS2CmnInsertQueue(pQueue, dX);
    330     PS2CmnInsertQueue(pQueue, dY);
     328    PS2CmnInsertQueue(pQHdr, cQElements, pbQElements, val);
     329    PS2CmnInsertQueue(pQHdr, cQElements, pbQElements, dX);
     330    PS2CmnInsertQueue(pQHdr, cQElements, pbQElements, dY);
    331331
    332332    /* Add fourth byte if an extended protocol is in use. */
     
    339339        {
    340340            /* NB: Only uses 4-bit dZ range, despite using a full byte. */
    341             PS2CmnInsertQueue(pQueue, dZ);
     341            PS2CmnInsertQueue(pQHdr, cQElements, pbQElements, dZ);
    342342            pThis->iAccumZ -= dZ;
    343343        }
     
    348348           val |= dZ & 0x0f;
    349349           pThis->iAccumZ -= dZ;
    350            PS2CmnInsertQueue(pQueue, val);
     350           PS2CmnInsertQueue(pQHdr, cQElements, pbQElements, val);
    351351        }
    352352        else
     
    380380               val = (fBtnState & PS2M_IMEX_BTN_MASK) << 1;
    381381            }
    382             PS2CmnInsertQueue(pQueue, val);
     382            PS2CmnInsertQueue(pQHdr, cQElements, pbQElements, val);
    383383        }
    384384    }
     
    431431
    432432    /* If there's anything left in the command response queue, trash it. */
    433     PS2CmnClearQueue((GeneriQ *)&pThis->cmdQ);
     433    PS2Q_CLEAR(&pThis->cmdQ);
    434434
    435435    if (pThis->enmMode == AUX_MODE_WRAP)
     
    440440        else
    441441        {
    442             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, cmd);
     442            PS2Q_INSERT(&pThis->cmdQ, cmd);
    443443            return VINF_SUCCESS;
    444444        }
     
    455455        case ACMD_SET_SCALE_11:
    456456            pThis->u8State &= ~AUX_STATE_SCALING;
    457             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     457            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    458458            pThis->u8CurrCmd = 0;
    459459            break;
    460460        case ACMD_SET_SCALE_21:
    461461            pThis->u8State |= AUX_STATE_SCALING;
    462             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     462            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    463463            pThis->u8CurrCmd = 0;
    464464            break;
     
    466466            /* Report current status, sample rate, and resolution. */
    467467            u8Val  = (pThis->u8State & AUX_STATE_EXTERNAL) | (pThis->fCurrB & PS2M_STD_BTN_MASK);
    468             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    469             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val);
    470             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8Resolution);
    471             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, pThis->u8SampleRate);
     468            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
     469            PS2Q_INSERT(&pThis->cmdQ, u8Val);
     470            PS2Q_INSERT(&pThis->cmdQ, pThis->u8Resolution);
     471            PS2Q_INSERT(&pThis->cmdQ, pThis->u8SampleRate);
    472472            pThis->u8CurrCmd = 0;
    473473            break;
    474474        case ACMD_SET_STREAM:
    475475            pThis->u8State &= ~AUX_STATE_REMOTE;
    476             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     476            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    477477            pThis->u8CurrCmd = 0;
    478478            break;
    479479        case ACMD_READ_REMOTE:
    480             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    481             ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->cmdQ, false);
     480            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
     481            ps2mReportAccumulatedEvents(pThis, &pThis->cmdQ.Hdr, RT_ELEMENTS(pThis->cmdQ.abQueue), pThis->cmdQ.abQueue, false);
    482482            pThis->u8CurrCmd = 0;
    483483            break;
     
    485485            pThis->enmMode = AUX_MODE_STD;
    486486            /* NB: Stream mode reporting remains disabled! */
    487             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     487            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    488488            pThis->u8CurrCmd = 0;
    489489            break;
     
    491491            pThis->enmMode = AUX_MODE_WRAP;
    492492            pThis->u8State &= ~AUX_STATE_ENABLED;
    493             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     493            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    494494            pThis->u8CurrCmd = 0;
    495495            break;
    496496        case ACMD_SET_REMOTE:
    497497            pThis->u8State |= AUX_STATE_REMOTE;
    498             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     498            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    499499            pThis->u8CurrCmd = 0;
    500500            break;
    501501        case ACMD_READ_ID:
    502             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     502            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    503503            /* ImEx + horizontal is protocol 4, just like plain ImEx. */
    504504            u8Val = pThis->enmProtocol == PS2M_PROTO_IMEX_HORZ ? PS2M_PROTO_IMEX : pThis->enmProtocol;
    505             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val);
     505            PS2Q_INSERT(&pThis->cmdQ, u8Val);
    506506            pThis->u8CurrCmd = 0;
    507507            break;
     
    513513            AssertLogRelMsgFailed(("Invalid ACMD_ENABLE outside R3!\n"));
    514514#endif
    515             PS2CmnClearQueue((GeneriQ *)&pThis->evtQ);
    516             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     515            PS2Q_CLEAR(&pThis->evtQ);
     516            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    517517            pThis->u8CurrCmd = 0;
    518518            break;
    519519        case ACMD_DISABLE:
    520520            pThis->u8State &= ~AUX_STATE_ENABLED;
    521             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     521            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    522522            pThis->u8CurrCmd = 0;
    523523            break;
    524524        case ACMD_SET_DEFAULT:
    525525            ps2mSetDefaults(pThis);
    526             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     526            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    527527            pThis->u8CurrCmd = 0;
    528528            break;
     
    535535            pThis->u8CurrCmd = cmd;
    536536            pThis->enmMode   = AUX_MODE_RESET;
    537             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     537            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    538538            if (pThis->fDelayReset)
    539539                /* Slightly delay reset completion; it might take hundreds of ms. */
     
    549549        case ACMD_SET_RES:
    550550        case ACMD_SET_SAMP_RATE:
    551             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     551            PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    552552            pThis->u8CurrCmd = cmd;
    553553            break;
     
    561561                        pThis->u8Resolution = cmd;
    562562                        pThis->u8State &= ~AUX_STATE_RES_ERR;
    563                         PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     563                        PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    564564                        pThis->u8CurrCmd = 0;
    565565                    }
     
    570570                        {
    571571                            pThis->u8State &= ~AUX_STATE_RES_ERR;
    572                             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
     572                            PS2Q_INSERT(&pThis->cmdQ, ARSP_ERROR);
    573573                            pThis->u8CurrCmd = 0;
    574574                        }
     
    576576                        {
    577577                            pThis->u8State |= AUX_STATE_RES_ERR;
    578                             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
     578                            PS2Q_INSERT(&pThis->cmdQ, ARSP_RESEND);
    579579                            /* NB: Current command remains unchanged. */
    580580                        }
     
    587587                        ps2mSetRate(pThis, cmd);
    588588                        ps2mRateProtocolKnock(pThis, cmd);
    589                         PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
     589                        PS2Q_INSERT(&pThis->cmdQ, ARSP_ACK);
    590590                        pThis->u8CurrCmd = 0;
    591591                    }
     
    596596                        {
    597597                            pThis->u8State &= ~AUX_STATE_RATE_ERR;
    598                             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR);
     598                            PS2Q_INSERT(&pThis->cmdQ, ARSP_ERROR);
    599599                            pThis->u8CurrCmd = 0;
    600600                        }
     
    602602                        {
    603603                            pThis->u8State |= AUX_STATE_RATE_ERR;
    604                             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
     604                            PS2Q_INSERT(&pThis->cmdQ, ARSP_RESEND);
    605605                            /* NB: Current command remains unchanged. */
    606606                        }
     
    626626        case ACMD_INVALID_10:
    627627            Log(("Unsupported command 0x%02X!\n", cmd));
    628             PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND);
     628            PS2Q_INSERT(&pThis->cmdQ, ARSP_RESEND);
    629629            pThis->u8CurrCmd = 0;
    630630            break;
     
    654654     */
    655655    /// @todo Probably should flush/not fill queue if stream mode reporting disabled?!
    656     rc = PS2CmnRemoveQueue((GeneriQ *)&pThis->cmdQ, pb);
     656    rc = PS2Q_REMOVE(&pThis->cmdQ, pb);
    657657    if (rc != VINF_SUCCESS && !pThis->u8CurrCmd && (pThis->u8State & AUX_STATE_ENABLED))
    658         rc = PS2CmnRemoveQueue((GeneriQ *)&pThis->evtQ, pb);
     658        rc = PS2Q_REMOVE(&pThis->evtQ, pb);
    659659
    660660    LogFlowFunc(("mouse sends 0x%02x (%svalid data)\n", *pb, rc == VINF_SUCCESS ? "" : "not "));
     
    693693    {
    694694        /* Report accumulated data, poke the KBC, and start the timer. */
    695         ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
     695        ps2mReportAccumulatedEvents(pThis, &pThis->evtQ.Hdr, RT_ELEMENTS(pThis->evtQ.abQueue), pThis->evtQ.abQueue, true);
    696696        KBCUpdateInterrupts(pDevIns);
    697697        PDMDevHlpTimerSetMillies(pDevIns, pThis->hThrottleTimer, pThis->uThrottleDelay);
     
    755755                    pThis->u8SampleRate, 1 << pThis->u8Resolution);
    756756    pHlp->pfnPrintf(pHlp, "Command queue: %d items (%d max)\n",
    757                     pThis->cmdQ.cUsed, pThis->cmdQ.cSize);
     757                    PS2Q_COUNT(&pThis->cmdQ), PS2Q_SIZE(&pThis->cmdQ));
    758758    pHlp->pfnPrintf(pHlp, "Event queue  : %d items (%d max)\n",
    759                     pThis->evtQ.cUsed, pThis->evtQ.cSize);
     759                    PS2Q_COUNT(&pThis->evtQ), PS2Q_SIZE(&pThis->evtQ));
    760760}
    761761
     
    804804    if (!pThis->fThrottleActive && ps2mR3HaveEvents(pThis))
    805805    {
    806         ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
     806        ps2mReportAccumulatedEvents(pThis, &pThis->evtQ.Hdr, RT_ELEMENTS(pThis->evtQ.abQueue), pThis->evtQ.abQueue, true);
    807807        KBCUpdateInterrupts(pDevIns);
    808808        pThis->fThrottleActive = true;
     
    936936
    937937    /* Save the command and event queues. */
    938     PS2CmnR3SaveQueue(pHlp, pSSM, (GeneriQ *)&pThis->cmdQ);
    939     PS2CmnR3SaveQueue(pHlp, pSSM, (GeneriQ *)&pThis->evtQ);
     938    PS2Q_SAVE(pHlp, pSSM, &pThis->cmdQ);
     939    PS2Q_SAVE(pHlp, pSSM, &pThis->evtQ);
    940940
    941941    /* Save the command delay timer. Note that the rate throttling
     
    967967
    968968    /* Load the command and event queues. */
    969     rc = PS2CmnR3LoadQueue(pHlp, pSSM, (GeneriQ *)&pThis->cmdQ);
     969    rc = PS2Q_LOAD(pHlp, pSSM, &pThis->cmdQ);
    970970    AssertRCReturn(rc, rc);
    971     rc = PS2CmnR3LoadQueue(pHlp, pSSM, (GeneriQ *)&pThis->evtQ);
     971    rc = PS2Q_LOAD(pHlp, pSSM, &pThis->evtQ);
    972972    AssertRCReturn(rc, rc);
    973973
     
    10061006
    10071007    /* Clear the queues. */
    1008     PS2CmnClearQueue((GeneriQ *)&pThis->cmdQ);
     1008    PS2Q_CLEAR(&pThis->cmdQ);
    10091009    ps2mSetDefaults(pThis);     /* Also clears event queue. */
    10101010}
    10111011
    1012 int PS2MR3Construct(PPDMDEVINS pDevIns, PPS2M pThis, PPS2MR3 pThisCC, unsigned iInstance)
    1013 {
    1014     RT_NOREF(iInstance);
    1015 
    1016     LogFlowFunc(("iInstance=%u\n", iInstance));
    1017 
     1012int PS2MR3Construct(PPDMDEVINS pDevIns, PPS2M pThis, PPS2MR3 pThisCC)
     1013{
     1014    LogFlowFunc(("\n"));
    10181015#ifdef RT_STRICT
    10191016    ps2mR3TestAccumulation();
    10201017#endif
    10211018
    1022     pThisCC->pDevIns = pDevIns;
    1023 
    1024     /* Initialize the queues. */
    1025     pThis->evtQ.cSize = AUX_EVT_QUEUE_SIZE;
    1026     pThis->cmdQ.cSize = AUX_CMD_QUEUE_SIZE;
    1027 
     1019    /*
     1020     * Initialize the state.
     1021     */
     1022    pThisCC->pDevIns                           = pDevIns;
    10281023    pThisCC->Mouse.IBase.pfnQueryInterface     = ps2mR3QueryInterface;
    10291024    pThisCC->Mouse.IPort.pfnPutEvent           = ps2mR3MousePort_PutEvent;
     
    10771072
    10781073    RT_ZERO(This);
    1079     This.evtQ.cSize = AUX_EVT_QUEUE_SIZE;
    10801074    This.u8State = AUX_STATE_ENABLED;
    10811075    This.fThrottleActive = true;
     
    10851079    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 1);
    10861080    if (ps2mR3HaveEvents(&This))
    1087         ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
     1081        ps2mReportAccumulatedEvents(&This, &This.evtQ.Hdr, RT_ELEMENTS(This.evtQ.abQueue), This.evtQ.abQueue, true);
    10881082    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 0);
    10891083    if (ps2mR3HaveEvents(&This))
    1090         ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
     1084        ps2mReportAccumulatedEvents(&This, &This.evtQ.Hdr, RT_ELEMENTS(This.evtQ.abQueue), This.evtQ.abQueue, true);
    10911085    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 1);
    10921086    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 0);
    10931087    if (ps2mR3HaveEvents(&This))
    1094         ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
     1088        ps2mReportAccumulatedEvents(&This, &This.evtQ.Hdr, RT_ELEMENTS(This.evtQ.abQueue), This.evtQ.abQueue, true);
    10951089    if (ps2mR3HaveEvents(&This))
    1096         ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
     1090        ps2mReportAccumulatedEvents(&This, &This.evtQ.Hdr, RT_ELEMENTS(This.evtQ.abQueue), This.evtQ.abQueue, true);
    10971091    for (i = 0; i < 12; ++i)
    10981092    {
     
    11091103    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 1);
    11101104    if (ps2mR3HaveEvents(&This))
    1111         ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
     1105        ps2mReportAccumulatedEvents(&This, &This.evtQ.Hdr, RT_ELEMENTS(This.evtQ.abQueue), This.evtQ.abQueue, true);
    11121106    if (ps2mR3HaveEvents(&This))
    1113         ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
     1107        ps2mReportAccumulatedEvents(&This, &This.evtQ.Hdr, RT_ELEMENTS(This.evtQ.abQueue), This.evtQ.abQueue, true);
    11141108    for (i = 0; i < 3; ++i)
    11151109    {
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