VirtualBox

Changeset 82195 in vbox


Ignore:
Timestamp:
Nov 25, 2019 7:12:32 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135009
Message:

DevPS2: Converted timers. bugref:9218

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

Legend:

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

    r82191 r82195  
    217217
    218218
    219 /* update irq and KBD_STAT_[MOUSE_]OBF */
    220 static void kbd_update_irq(KBDState *s)
     219/** update irq and KBD_STAT_[MOUSE_]OBF */
     220static void kbd_update_irq(PPDMDEVINS pDevIns, KBDState *s)
    221221{
    222222    int irq12_level, irq1_level;
     
    233233        s->status &= ~KBD_STAT_MOUSE_OBF;
    234234        /* Keyboard data has priority if both kbd and aux data is available. */
    235         if (!(s->mode & KBD_MODE_DISABLE_KBD) && PS2KByteFromKbd(&s->Kbd, &val) == VINF_SUCCESS)
     235        if (!(s->mode & KBD_MODE_DISABLE_KBD) && PS2KByteFromKbd(pDevIns, &s->Kbd, &val) == VINF_SUCCESS)
    236236        {
    237237            bool    fHaveData = true;
     
    248248                 * and we keep going until the state changes or there's no more data.
    249249                 */
    250                 while (s->xlat_state == XS_BREAK && PS2KByteFromKbd(&s->Kbd, &val) == VINF_SUCCESS)
     250                while (s->xlat_state == XS_BREAK && PS2KByteFromKbd(pDevIns, &s->Kbd, &val) == VINF_SUCCESS)
    251251                {
    252252                    s->xlat_state = kbcXlateAT2PC(s->xlat_state, val, &xlated_val);
     
    286286}
    287287
    288 void KBCUpdateInterrupts(void *pKbc)
    289 {
    290     KBDState    *s = (KBDState *)pKbc;
    291     kbd_update_irq(s);
    292 }
    293 
    294 static void kbc_dbb_out(void *opaque, uint8_t val)
    295 {
    296     KBDState *s = (KBDState*)opaque;
    297 
     288void KBCUpdateInterrupts(PPDMDEVINS pDevIns)
     289{
     290    PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
     291    kbd_update_irq(pDevIns, pThis);
     292}
     293
     294static void kbc_dbb_out(PKBDSTATE s, uint8_t val)
     295{
    298296    s->dbbout = val;
    299297    /* Set the OBF and raise IRQ. */
     
    303301}
    304302
    305 static void kbc_dbb_out_aux(void *opaque, uint8_t val)
    306 {
    307     KBDState *s = (KBDState*)opaque;
    308 
     303static void kbc_dbb_out_aux(PKBDSTATE s, uint8_t val)
     304{
    309305    s->dbbout = val;
    310306    /* Set the aux OBF and raise IRQ. */
     
    314310}
    315311
    316 static uint32_t kbd_read_status(void *opaque, uint32_t addr)
    317 {
    318     KBDState *s = (KBDState*)opaque;
     312static uint32_t kbd_read_status(PKBDSTATE s, uint32_t addr)
     313{
    319314    int val = s->status;
    320315    NOREF(addr);
     
    326321}
    327322
    328 static int kbd_write_command(void *opaque, uint32_t addr, uint32_t val)
     323static int kbd_write_command(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t addr, uint32_t val)
    329324{
    330325    int rc = VINF_SUCCESS;
    331     KBDState *s = (KBDState*)opaque;
    332326    NOREF(addr);
    333327
     
    352346        s->mode &= ~KBD_MODE_DISABLE_MOUSE;
    353347        /* Check for queued input. */
    354         kbd_update_irq(s);
     348        kbd_update_irq(pDevIns, s);
    355349        break;
    356350    case KBD_CCMD_TEST_MOUSE:
     
    381375        s->mode &= ~KBD_MODE_DISABLE_KBD;
    382376        /* Check for queued input. */
    383         kbd_update_irq(s);
     377        kbd_update_irq(pDevIns, s);
    384378        break;
    385379    case KBD_CCMD_READ_INPORT:
     
    453447}
    454448
    455 static uint32_t kbd_read_data(void *opaque, uint32_t addr)
    456 {
    457     KBDState *s = (KBDState*)opaque;
     449static uint32_t kbd_read_data(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t addr)
     450{
    458451    uint32_t val;
    459452    NOREF(addr);
     
    471464
    472465    /* Check if more data is available. */
    473     kbd_update_irq(s);
     466    kbd_update_irq(pDevIns, s);
    474467#ifdef DEBUG_KBD
    475468    Log(("kbd: read data=0x%02x\n", val));
     
    480473PS2K *KBDGetPS2KFromDevIns(PPDMDEVINS pDevIns)
    481474{
    482     KBDState *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     475    KBDState *pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    483476    return &pThis->Kbd;
    484477}
     
    486479PS2M *KBDGetPS2MFromDevIns(PPDMDEVINS pDevIns)
    487480{
    488     KBDState *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
     481    KBDState *pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    489482    return &pThis->Aux;
    490483}
    491484
    492 static int kbd_write_data(void *opaque, uint32_t addr, uint32_t val)
     485static int kbd_write_data(PPDMDEVINS pDevIns, PKBDSTATE s, uint32_t addr, uint32_t val)
    493486{
    494487    int rc = VINF_SUCCESS;
    495     KBDState *s = (KBDState*)opaque;
    496488    NOREF(addr);
    497489
     
    504496        /* Automatically enables keyboard interface. */
    505497        s->mode &= ~KBD_MODE_DISABLE_KBD;
    506         rc = PS2KByteToKbd(&s->Kbd, val);
     498        rc = PS2KByteToKbd(pDevIns, &s->Kbd, val);
    507499        if (rc == VINF_SUCCESS)
    508             kbd_update_irq(s);
     500            kbd_update_irq(pDevIns, s);
    509501        break;
    510502    case KBD_CCMD_WRITE_MODE:
    511503        s->mode = val;
    512504        s->translate = (s->mode & KBD_MODE_KCC) == KBD_MODE_KCC;
    513         kbd_update_irq(s);
     505        kbd_update_irq(pDevIns, s);
    514506        break;
    515507    case KBD_CCMD_WRITE_OBUF:
     
    539531        /* Automatically enables aux interface. */
    540532        s->mode &= ~KBD_MODE_DISABLE_MOUSE;
    541         rc = PS2MByteToAux(&s->Aux, val);
     533        rc = PS2MByteToAux(pDevIns, &s->Aux, val);
    542534        if (rc == VINF_SUCCESS)
    543             kbd_update_irq(s);
     535            kbd_update_irq(pDevIns, s);
    544536        break;
    545537    default:
     
    706698        RT_FALL_THRU();
    707699    case 1:
    708         *pu32 = fluff | kbd_read_data(pThis, Port);
     700        *pu32 = fluff | kbd_read_data(pDevIns, pThis, Port);
    709701        Log2(("kbdIOPortDataRead: Port=%#x cb=%d *pu32=%#x\n", Port, cb, *pu32));
    710702        return VINF_SUCCESS;
     
    732724    if (cb == 1 || cb == 2)
    733725    {
    734         KBDState *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
    735         rc = kbd_write_data(pThis, Port, (uint8_t)u32);
     726        PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
     727        rc = kbd_write_data(pDevIns, pThis, Port, (uint8_t)u32);
    736728        Log2(("kbdIOPortDataWrite: Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
    737729    }
     
    792784    if (cb == 1 || cb == 2)
    793785    {
    794         KBDState *pThis = PDMDEVINS_2_DATA(pDevIns, KBDState *);
    795         rc = kbd_write_command(pThis, Port, (uint8_t)u32);
     786        KBDState *pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
     787        rc = kbd_write_command(pDevIns, pThis, Port, (uint8_t)u32);
    796788        Log2(("kbdIOPortCommandWrite: Port=%#x cb=%d u32=%#x rc=%Rrc\n", Port, cb, u32, rc));
    797789    }
     
    975967{
    976968    PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    977     return PS2KR3LoadDone(&pThis->Kbd, pSSM);
     969    RT_NOREF(pSSM);
     970    return PS2KR3LoadDone(pDevIns, &pThis->Kbd);
    978971}
    979972
     
    994987    pThis->translate = 0;
    995988
    996     PS2KR3Reset(&pThis->Kbd);
     989    PS2KR3Reset(pDevIns, &pThis->Kbd);
    997990    PS2MR3Reset(&pThis->Aux);
    998991}
     
    10711064    NOREF(pDevIns); NOREF(iLUN); NOREF(fFlags);
    10721065#endif
    1073 }
    1074 
    1075 
    1076 /**
    1077  * @interface_method_impl{PDMDEVREGR3,pfnRelocate}
    1078  */
    1079 static DECLCALLBACK(void) kbdR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    1080 {
    1081     PKBDSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PKBDSTATE);
    1082     pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    1083     PS2KR3Relocate(&pThis->Kbd, offDelta, pDevIns);
    1084     PS2MR3Relocate(&pThis->Aux, offDelta, pDevIns);
    10851066}
    10861067
     
    11931174    /* .pfnConstruct = */           kbdR3Construct,
    11941175    /* .pfnDestruct = */            NULL,
    1195     /* .pfnRelocate = */            kbdR3Relocate,
     1176    /* .pfnRelocate = */            NULL,
    11961177    /* .pfnMemSetup = */            NULL,
    11971178    /* .pfnPowerOn = */             NULL,
  • trunk/src/VBox/Devices/Input/DevPS2.h

    r82191 r82195  
    108108    /** Selected typematic delay/rate. */
    109109    uint8_t             u8TypematicCfg;
     110    uint8_t             bAlignment1;
    110111    /** Usage code of current typematic key, if any. */
    111112    uint32_t            u32TypematicKey;
     
    119120    uint8_t             abDepressedKeys[VBOX_USB_USAGE_ARRAY_SIZE];
    120121    /** Typematic delay in milliseconds. */
    121     unsigned            uTypematicDelay;
     122    uint32_t            uTypematicDelay;
    122123    /** Typematic repeat period in milliseconds. */
    123     unsigned            uTypematicRepeat;
     124    uint32_t            uTypematicRepeat;
    124125    /** Set if the throttle delay is currently active. */
    125126    bool                fThrottleActive;
    126127    /** Set if the input rate should be throttled. */
    127128    bool                fThrottleEnabled;
    128 
    129     uint8_t             Alignment0[2];
    130 
    131     /** Command delay timer - RC Ptr. */
    132     PTMTIMERRC          pKbdDelayTimerRC;
    133     /** Typematic timer - RC Ptr. */
    134     PTMTIMERRC          pKbdTypematicTimerRC;
    135     /** Input throttle timer - RC Ptr. */
    136     PTMTIMERRC          pThrottleTimerRC;
     129    uint8_t             abAlignment2[2];
     130
     131    /** Command delay timer - R3 Ptr. */
     132    TMTIMERHANDLE       hKbdDelayTimer;
     133    /** Typematic timer - R3 Ptr. */
     134    TMTIMERHANDLE       hKbdTypematicTimer;
     135    /** Input throttle timer. */
     136    TMTIMERHANDLE       hThrottleTimer;
    137137
    138138    /** The device critical section protecting everything - R3 Ptr */
    139139    R3PTRTYPE(PPDMCRITSECT) pCritSectR3;
    140 
    141     /** Command delay timer - R3 Ptr. */
    142     PTMTIMERR3          pKbdDelayTimerR3;
    143     /** Typematic timer - R3 Ptr. */
    144     PTMTIMERR3          pKbdTypematicTimerR3;
    145     /** Input throttle timer - R3 Ptr. */
    146     PTMTIMERR3          pThrottleTimerR3;
    147 
    148     /** Command delay timer - R0 Ptr. */
    149     PTMTIMERR0          pKbdDelayTimerR0;
    150     /** Typematic timer - R0 Ptr. */
    151     PTMTIMERR0          pKbdTypematicTimerR0;
    152     /** Input throttle timer - R0 Ptr. */
    153     PTMTIMERR0          pThrottleTimerR0;
     140    /** The device instance.
     141     * @note Only for getting our bearings in interface methods. */
     142    PPDMDEVINSR3        pDevIns;
    154143
    155144    /**
     
    176165
    177166
    178 int  PS2KByteToKbd(PPS2K pThis, uint8_t cmd);
    179 int  PS2KByteFromKbd(PPS2K pThis, uint8_t *pVal);
     167int  PS2KByteToKbd(PPDMDEVINS pDevIns, PPS2K pThis, uint8_t cmd);
     168int  PS2KByteFromKbd(PPDMDEVINS pDevIns, PPS2K pThis, uint8_t *pVal);
    180169
    181170int  PS2KR3Construct(PPS2K pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance, PCFGMNODE pCfg);
    182171int  PS2KR3Attach(PPS2K pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
    183 void PS2KR3Reset(PPS2K pThis);
    184 void PS2KR3Relocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
     172void PS2KR3Reset(PPDMDEVINS pDevIns, PPS2K pThis);
    185173void PS2KR3SaveState(PPDMDEVINS pDevIns, PPS2K pThis, PSSMHANDLE pSSM);
    186174int  PS2KR3LoadState(PPDMDEVINS pDevIns, PPS2K pThis, PSSMHANDLE pSSM, uint32_t uVersion);
    187 int  PS2KR3LoadDone(PPS2K pThis, PSSMHANDLE pSSM);
     175int  PS2KR3LoadDone(PPDMDEVINS pDevIns, PPS2K pThis);
    188176
    189177PS2K *KBDGetPS2KFromDevIns(PPDMDEVINS pDevIns);
     
    289277    /** The device critical section protecting everything - R3 Ptr */
    290278    R3PTRTYPE(PPDMCRITSECT) pCritSectR3;
    291     /** Command delay timer - R3 Ptr. */
    292     PTMTIMERR3          pDelayTimerR3;
    293     /** Interrupt throttling timer - R3 Ptr. */
    294     PTMTIMERR3          pThrottleTimerR3;
    295     RTR3PTR             Alignment1;
    296 
    297     /** Command delay timer - RC Ptr. */
    298     PTMTIMERRC          pDelayTimerRC;
    299     /** Interrupt throttling timer - RC Ptr. */
    300     PTMTIMERRC          pThrottleTimerRC;
    301 
    302     /** Command delay timer - R0 Ptr. */
    303     PTMTIMERR0          pDelayTimerR0;
    304     /** Interrupt throttling timer - R0 Ptr. */
    305     PTMTIMERR0          pThrottleTimerR0;
     279    /** The device instance.
     280     * @note Only for getting our bearings in interface methods. */
     281    PPDMDEVINSR3        pDevIns;
     282
     283    /** Command delay timer. */
     284    TMTIMERHANDLE       hDelayTimer;
     285    /** Interrupt throttling timer. */
     286    TMTIMERHANDLE       hThrottleTimer;
    306287
    307288    /**
     
    327308typedef PS2M *PPS2M;
    328309
    329 int  PS2MByteToAux(PPS2M pThis, uint8_t cmd);
     310int  PS2MByteToAux(PPDMDEVINS pDevIns, PPS2M pThis, uint8_t cmd);
    330311int  PS2MByteFromAux(PPS2M pThis, uint8_t *pVal);
    331312
     
    333314int  PS2MR3Attach(PPS2M pThis, PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
    334315void PS2MR3Reset(PPS2M pThis);
    335 void PS2MR3Relocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns);
    336316void PS2MR3SaveState(PPDMDEVINS pDevIns, PPS2M pThis, PSSMHANDLE pSSM);
    337317int  PS2MR3LoadState(PPDMDEVINS pDevIns, PPS2M pThis, PSSMHANDLE pSSM, uint32_t uVersion);
     
    374354
    375355/* Shared keyboard/aux internal interface. */
    376 void KBCUpdateInterrupts(void *pKbc);
     356void KBCUpdateInterrupts(PPDMDEVINS pDevIns);
    377357
    378358/** @}  */
  • trunk/src/VBox/Devices/Input/DevPS2K.cpp

    r82191 r82195  
    449449
    450450/** Clears the currently active typematic key, if any. */
    451 static void ps2kStopTypematicRepeat(PPS2K pThis)
     451static void ps2kStopTypematicRepeat(PPDMDEVINS pDevIns, PPS2K pThis)
    452452{
    453453    if (pThis->u32TypematicKey)
     
    456456        pThis->enmTypematicState = KBD_TMS_IDLE;
    457457        pThis->u32TypematicKey = 0;
    458         TMTimerStop(pThis->CTX_SUFF(pKbdTypematicTimer));
     458        PDMDevHlpTimerStop(pDevIns, pThis->hKbdTypematicTimer);
    459459    }
    460460}
     
    480480}
    481481
    482 static void ps2kSetDefaults(PPS2K pThis)
     482static void ps2kSetDefaults(PPDMDEVINS pDevIns, PPS2K pThis)
    483483{
    484484    LogFlowFunc(("Set keyboard defaults\n"));
     
    488488    ps2kSetupTypematic(pThis, KBD_DFL_RATE_DELAY);
    489489    /* Clear last typematic key?? */
    490     ps2kStopTypematicRepeat(pThis);
     490    ps2kStopTypematicRepeat(pDevIns, pThis);
    491491}
    492492
     
    494494 * Receive and process a byte sent by the keyboard controller.
    495495 *
    496  * @param   pThis               The PS/2 keyboard instance data.
    497  * @param   cmd                 The command (or data) byte.
    498  */
    499 int PS2KByteToKbd(PPS2K pThis, uint8_t cmd)
     496 * @param   pDevIns The device instance.
     497 * @param   pThis   The PS/2 keyboard instance data.
     498 * @param   cmd     The command (or data) byte.
     499 */
     500int PS2KByteToKbd(PPDMDEVINS pDevIns, PPS2K pThis, uint8_t cmd)
    500501{
    501502    bool    fHandled = true;
     
    522523            pThis->fScanning = true;
    523524            PS2CmnClearQueue((GeneriQ *)&pThis->keyQ);
    524             ps2kStopTypematicRepeat(pThis);
     525            ps2kStopTypematicRepeat(pDevIns, pThis);
    525526            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    526527            pThis->u8CurrCmd = 0;
     
    528529        case KCMD_DFLT_DISABLE:
    529530            pThis->fScanning = false;
    530             ps2kSetDefaults(pThis); /* Also clears buffer/typematic state. */
     531            ps2kSetDefaults(pDevIns, pThis); /* Also clears buffer/typematic state. */
    531532            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    532533            pThis->u8CurrCmd = 0;
    533534            break;
    534535        case KCMD_SET_DEFAULT:
    535             ps2kSetDefaults(pThis);
     536            ps2kSetDefaults(pDevIns, pThis);
    536537            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    537538            pThis->u8CurrCmd = 0;
     
    550551        case KCMD_RESET:
    551552            pThis->u8ScanSet = 2;
    552             ps2kSetDefaults(pThis);
     553            ps2kSetDefaults(pDevIns, pThis);
    553554            /// @todo reset more?
    554555            PS2CmnInsertQueue((GeneriQ *)&pThis->cmdQ, KRSP_ACK);
    555556            pThis->u8CurrCmd = cmd;
    556557            /* Delay BAT completion; the test may take hundreds of ms. */
    557             TMTimerSetMillies(pThis->CTX_SUFF(pKbdDelayTimer), 2);
     558            PDMDevHlpTimerSetMillies(pDevIns, pThis->hKbdDelayTimer, 2);
    558559            break;
    559560        /* The following commands need a parameter. */
     
    616617    }
    617618    LogFlowFunc(("Active cmd now 0x%02X; updating interrupts\n", pThis->u8CurrCmd));
    618 //    KBCUpdateInterrupts(pThis->pParent);
     619//    KBCUpdateInterrupts(pDevIns);
    619620    return VINF_SUCCESS;
    620621}
     
    624625 *
    625626 * @returns VINF_SUCCESS or VINF_TRY_AGAIN.
    626  * @param   pThis               The PS/2 keyboard instance data.
    627  * @param   pb                  Where to return the byte we've read.
     627 * @param   pDevIns The device instance.
     628 * @param   pThis   The PS/2 keyboard instance data.
     629 * @param   pb      Where to return the byte we've read.
    628630 * @remarks Caller must have entered the device critical section.
    629631 */
    630 int PS2KByteFromKbd(PPS2K pThis, uint8_t *pb)
     632int PS2KByteFromKbd(PPDMDEVINS pDevIns, PPS2K pThis, uint8_t *pb)
    631633{
    632634    int         rc;
     
    644646        {
    645647            rc = PS2CmnRemoveQueue((GeneriQ *)&pThis->keyQ, pb);
    646             if (pThis->fThrottleEnabled) {
     648            if (pThis->fThrottleEnabled)
     649            {
    647650                pThis->fThrottleActive = true;
    648                 TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), KBD_THROTTLE_DELAY);
     651                PDMDevHlpTimerSetMillies(pDevIns, pThis->hThrottleTimer, KBD_THROTTLE_DELAY);
    649652            }
    650653        }
     
    656659#ifdef IN_RING3
    657660
    658 static int ps2kR3ProcessKeyEvent(PPS2K pThis, uint32_t u32HidCode, bool fKeyDown)
     661static int ps2kR3ProcessKeyEvent(PPDMDEVINS pDevIns, PPS2K pThis, uint32_t u32HidCode, bool fKeyDown)
    659662{
    660663    key_def const   *pKeyDef;
     
    890893                pThis->enmTypematicState = KBD_TMS_DELAY;
    891894                pThis->u32TypematicKey   = u32HidCode;
    892                 TMTimerSetMillies(pThis->CTX_SUFF(pKbdTypematicTimer), pThis->uTypematicDelay);
     895                PDMDevHlpTimerSetMillies(pDevIns, pThis->hKbdTypematicTimer, pThis->uTypematicDelay);
    893896                Log(("Typematic delay %u ms, key %08X\n", pThis->uTypematicDelay, u32HidCode));
    894897            }
     
    906909                pThis->enmTypematicState = KBD_TMS_IDLE;
    907910                /* For good measure, we cancel the timer, too. */
    908                 TMTimerStop(pThis->CTX_SUFF(pKbdTypematicTimer));
     911                PDMDevHlpTimerStop(pDevIns, pThis->hKbdTypematicTimer);
    909912                Log(("Typematic action cleared for key %08X\n", u32HidCode));
    910913            }
     
    913916
    914917    /* Poke the KBC to update its state. */
    915     KBCUpdateInterrupts(pThis->pParent);
     918    KBCUpdateInterrupts(pDevIns);
    916919
    917920    return VINF_SUCCESS;
     
    949952    LogFlowFunc(("Have%s bytes\n", uHaveData ? "" : " no"));
    950953    if (uHaveData)
    951         KBCUpdateInterrupts(pThis->pParent);
     954        KBCUpdateInterrupts(pDevIns);
    952955
    953956    PDMCritSectLeave(pThis->pCritSectR3);
     
    976979        if (pThis->enmTypematicState == KBD_TMS_REPEAT)
    977980        {
    978             ps2kR3ProcessKeyEvent(pThis, pThis->u32TypematicKey, true /* Key down */ );
    979             TMTimerSetMillies(pThis->CTX_SUFF(pKbdTypematicTimer), pThis->uTypematicRepeat);
     981            ps2kR3ProcessKeyEvent(pDevIns, pThis, pThis->u32TypematicKey, true /* Key down */ );
     982            PDMDevHlpTimerSetMillies(pDevIns, pThis->hKbdTypematicTimer, pThis->uTypematicRepeat);
    980983        }
    981984    }
     
    10021005    /// @todo Might want a PS2KCompleteCommand() to push last response, clear command, and kick the KBC...
    10031006    /* Give the KBC a kick. */
    1004     KBCUpdateInterrupts(pThis->pParent);
     1007    KBCUpdateInterrupts(pDevIns);
    10051008}
    10061009
     
    10091012 * or resuming a suspended host.
    10101013 */
    1011 static void ps2kR3ReleaseKeys(PPS2K pThis)
     1014static void ps2kR3ReleaseKeys(PPDMDEVINS pDevIns, PPS2K pThis)
    10121015{
    10131016    LogFlowFunc(("Releasing keys...\n"));
     
    10161019        if (pThis->abDepressedKeys[uKey])
    10171020        {
    1018             ps2kR3ProcessKeyEvent(pThis, RT_MAKE_U32(USB_HID_KB_PAGE, uKey), false /* key up */);
     1021            ps2kR3ProcessKeyEvent(pDevIns, pThis, RT_MAKE_U32(USB_HID_KB_PAGE, uKey), false /* key up */);
    10191022            pThis->abDepressedKeys[uKey] = 0;
    10201023        }
     
    10711074 *
    10721075 * @returns VBox status code.
    1073  * @param   pThis           The PS2 keyboard instance data.
    1074  * @param   u32Usage        USB HID usage code with key
    1075  *                         press/release flag.
    1076  */
    1077 static int ps2kR3PutEventWorker(PPS2K pThis, uint32_t u32Usage)
     1076 * @param   pDevIns     The device instance.
     1077 * @param   pThis       The PS2 keyboard instance data.
     1078 * @param   u32Usage    USB HID usage code with key press/release flag.
     1079 */
     1080static int ps2kR3PutEventWorker(PPDMDEVINS pDevIns, PPS2K pThis, uint32_t u32Usage)
    10781081{
    10791082    uint32_t        u32HidCode;
     
    11161119        AssertReleaseRC(rc);
    11171120
    1118         rc = ps2kR3ProcessKeyEvent(pThis, u32HidCode, fKeyDown);
     1121        rc = ps2kR3ProcessKeyEvent(pDevIns, pThis, u32HidCode, fKeyDown);
    11191122
    11201123        PDMCritSectLeave(pThis->pCritSectR3);
     
    11311134{
    11321135    PPS2K       pThis = RT_FROM_MEMBER(pInterface, PS2K, Keyboard.IPort);
     1136    PPDMDEVINS  pDevIns = pThis->pDevIns;
    11331137    int         rc;
    11341138
     
    11411145     * key is allowed to use this scancode.
    11421146     */
    1143     if (RT_UNLIKELY(u32UsageCode == KRSP_BAT_FAIL))
    1144     {
    1145         ps2kR3ReleaseKeys(pThis);
    1146     }
     1147    if (RT_LIKELY(u32UsageCode != KRSP_BAT_FAIL))
     1148        ps2kR3PutEventWorker(pDevIns, pThis, u32UsageCode);
    11471149    else
    1148     {
    1149         ps2kR3PutEventWorker(pThis, u32UsageCode);
    1150     }
     1150        ps2kR3ReleaseKeys(pDevIns, pThis);
    11511151
    11521152    PDMCritSectLeave(pThis->pCritSectR3);
     
    12301230     * timer is *not* saved.
    12311231     */
    1232     TMR3TimerSave(pThis->CTX_SUFF(pKbdDelayTimer), pSSM);
     1232    PDMDevHlpTimerSave(pDevIns, pThis->hKbdDelayTimer, pSSM);
    12331233
    12341234    /* Save any pressed keys. This is necessary to avoid "stuck"
     
    12821282
    12831283    /* Load the command delay timer, just in case. */
    1284     rc = TMR3TimerLoad(pThis->CTX_SUFF(pKbdDelayTimer), pSSM);
     1284    rc = PDMDevHlpTimerLoad(pDevIns, pThis->hKbdDelayTimer, pSSM);
    12851285    AssertRCReturn(rc, rc);
    12861286
     
    13161316}
    13171317
    1318 int PS2KR3LoadDone(PPS2K pThis, PSSMHANDLE pSSM)
    1319 {
    1320     RT_NOREF(pSSM);
    1321 
     1318int PS2KR3LoadDone(PPDMDEVINS pDevIns, PPS2K pThis)
     1319{
    13221320    /* This *must* be done after the inital load because it may trigger
    13231321     * interrupts and change the interrupt controller state.
    13241322     */
    1325     ps2kR3ReleaseKeys(pThis);
     1323    ps2kR3ReleaseKeys(pDevIns, pThis);
    13261324    ps2kR3NotifyLedsState(pThis, pThis->u8LEDs);
    13271325    return VINF_SUCCESS;
    13281326}
    13291327
    1330 void PS2KR3Reset(PPS2K pThis)
     1328void PS2KR3Reset(PPDMDEVINS pDevIns, PPS2K pThis)
    13311329{
    13321330    LogFlowFunc(("Resetting PS2K\n"));
     
    13431341    memset(pThis->abDepressedKeys, 0, sizeof(pThis->abDepressedKeys));
    13441342    PS2CmnClearQueue((GeneriQ *)&pThis->cmdQ);
    1345     ps2kSetDefaults(pThis);     /* Also clears keystroke queue. */
     1343    ps2kSetDefaults(pDevIns, pThis);     /* Also clears keystroke queue. */
    13461344
    13471345    /* Activate the PS/2 keyboard by default. */
     
    13501348}
    13511349
    1352 void PS2KR3Relocate(PPS2K pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
    1353 {
    1354     RT_NOREF(pDevIns);
    1355     LogFlowFunc(("Relocating PS2K\n"));
    1356     pThis->pKbdDelayTimerRC     = TMTimerRCPtr(pThis->pKbdDelayTimerR3);
    1357     pThis->pKbdTypematicTimerRC = TMTimerRCPtr(pThis->pKbdTypematicTimerR3);
    1358     pThis->pThrottleTimerRC     = TMTimerRCPtr(pThis->pThrottleTimerR3);
    1359     NOREF(offDelta);
    1360 }
    1361 
    13621350int PS2KR3Construct(PPS2K pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance, PCFGMNODE pCfg)
    13631351{
     
    13671355
    13681356    pThis->pParent = pParent;
     1357    pThis->pDevIns = pDevIns;
    13691358
    13701359    bool fThrottleEnabled;
     
    13901379     * Create the input rate throttling timer.
    13911380     */
    1392     PTMTIMER pTimer;
    1393     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3ThrottleTimer, pThis,
    1394                                 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Throttle Timer", &pTimer);
     1381    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3ThrottleTimer, pThis,
     1382                                TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Throttle Timer", &pThis->hThrottleTimer);
    13951383    AssertRCReturn(rc, rc);
    1396 
    1397     pThis->pThrottleTimerR3 = pTimer;
    1398     pThis->pThrottleTimerR0 = TMTimerR0Ptr(pTimer);
    1399     pThis->pThrottleTimerRC = TMTimerRCPtr(pTimer);
    14001384
    14011385    /*
    14021386     * Create the typematic delay/repeat timer.
    14031387     */
    1404     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3TypematicTimer, pThis,
    1405                                 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Typematic Timer", &pTimer);
     1388    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3TypematicTimer, pThis,
     1389                              TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Typematic Timer", &pThis->hKbdTypematicTimer);
    14061390    AssertRCReturn(rc, rc);
    1407 
    1408     pThis->pKbdTypematicTimerR3 = pTimer;
    1409     pThis->pKbdTypematicTimerR0 = TMTimerR0Ptr(pTimer);
    1410     pThis->pKbdTypematicTimerRC = TMTimerRCPtr(pTimer);
    14111391
    14121392    /*
    14131393     * Create the command delay timer.
    14141394     */
    1415     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3DelayTimer, pThis,
    1416                                 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Delay Timer", &pTimer);
     1395    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2kR3DelayTimer, pThis,
     1396                              TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2K Delay Timer", &pThis->hKbdDelayTimer);
    14171397    AssertRCReturn(rc, rc);
    1418 
    1419     pThis->pKbdDelayTimerR3 = pTimer;
    1420     pThis->pKbdDelayTimerR0 = TMTimerR0Ptr(pTimer);
    1421     pThis->pKbdDelayTimerRC = TMTimerRCPtr(pTimer);
    14221398
    14231399    /*
  • trunk/src/VBox/Devices/Input/DevPS2M.cpp

    r82191 r82195  
    415415 * Receive and process a byte sent by the keyboard controller.
    416416 *
    417  * @param   pThis               The PS/2 auxiliary device instance data.
    418  * @param   cmd                 The command (or data) byte.
    419  */
    420 int PS2MByteToAux(PPS2M pThis, uint8_t cmd)
     417 * @param   pDevIns The device instance.
     418 * @param   pThis   The PS/2 auxiliary device instance data.
     419 * @param   cmd     The command (or data) byte.
     420 */
     421int PS2MByteToAux(PPDMDEVINS pDevIns, PPS2M pThis, uint8_t cmd)
    421422{
    422423    uint8_t u8Val;
     
    537538            if (pThis->fDelayReset)
    538539                /* Slightly delay reset completion; it might take hundreds of ms. */
    539                 TMTimerSetMillies(pThis->CTX_SUFF(pDelayTimer), 1);
     540                PDMDevHlpTimerSetMillies(pDevIns, pThis->hDelayTimer, 1);
    540541            else
    541542#ifdef IN_RING3
     
    693694        /* Report accumulated data, poke the KBC, and start the timer. */
    694695        ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
    695         KBCUpdateInterrupts(pThis->pParent);
    696         TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
     696        KBCUpdateInterrupts(pDevIns);
     697        PDMDevHlpTimerSetMillies(pDevIns, pThis->hThrottleTimer, pThis->uThrottleDelay);
    697698    }
    698699    else
     
    721722    /// @todo Might want a PS2MCompleteCommand() to push last response, clear command, and kick the KBC...
    722723    /* Give the KBC a kick. */
    723     KBCUpdateInterrupts(pThis->pParent);
     724    KBCUpdateInterrupts(pDevIns);
    724725}
    725726
     
    777778 *
    778779 * @returns VBox status code.
    779  * @param   pThis           The PS/2 auxiliary device instance data.
    780  * @param   dx              X direction movement delta.
    781  * @param   dy              Y direction movement delta.
    782  * @param   dz              Z (vertical scroll) movement delta.
    783  * @param   dw              W (horizontal scroll) movement delta.
    784  * @param   fButtons        Depressed button mask.
    785  */
    786 static int ps2mR3PutEventWorker(PPS2M pThis, int32_t dx, int32_t dy, int32_t dz, int32_t dw, uint32_t fButtons)
     780 * @param   pDevIns     The device instance.
     781 * @param   pThis       The PS/2 auxiliary device instance data.
     782 * @param   dx          X direction movement delta.
     783 * @param   dy          Y direction movement delta.
     784 * @param   dz          Z (vertical scroll) movement delta.
     785 * @param   dw          W (horizontal scroll) movement delta.
     786 * @param   fButtons    Depressed button mask.
     787 */
     788static int ps2mR3PutEventWorker(PPDMDEVINS pDevIns, PPS2M pThis, int32_t dx, int32_t dy, int32_t dz, int32_t dw, uint32_t fButtons)
    787789{
    788790    /* Update internal accumulators and button state. Ignore any buttons beyond 5. */
     
    814816    {
    815817        ps2mReportAccumulatedEvents(pThis, (GeneriQ *)&pThis->evtQ, true);
    816         KBCUpdateInterrupts(pThis->pParent);
     818        KBCUpdateInterrupts(pDevIns);
    817819        pThis->fThrottleActive = true;
    818         TMTimerSetMillies(pThis->CTX_SUFF(pThrottleTimer), pThis->uThrottleDelay);
     820        PDMDevHlpTimerSetMillies(pDevIns, pThis->hThrottleTimer, pThis->uThrottleDelay);
    819821    }
    820822
     
    831833{
    832834    PPS2M       pThis = RT_FROM_MEMBER(pInterface, PS2M, Mouse.IPort);
    833     int rc = PDMCritSectEnter(pThis->pCritSectR3, VERR_SEM_BUSY);
     835    PPDMDEVINS  pDevIns = pThis->pDevIns;
     836    int rc = PDMDevHlpCritSectEnter(pDevIns, pDevIns->pCritSectRoR3, VERR_SEM_BUSY);
    834837    AssertReleaseRC(rc);
    835838
    836839    LogRelFlowFunc(("dX=%d dY=%d dZ=%d dW=%d buttons=%02X\n", dx, dy, dz, dw, fButtons));
    837840    /* NB: The PS/2 Y axis direction is inverted relative to ours. */
    838     ps2mR3PutEventWorker(pThis, dx, -dy, dz, dw, fButtons);
    839 
    840     PDMCritSectLeave(pThis->pCritSectR3);
     841    ps2mR3PutEventWorker(pDevIns, pThis, dx, -dy, dz, dw, fButtons);
     842
     843    PDMDevHlpCritSectLeave(pDevIns, pDevIns->pCritSectRoR3);
    841844    return VINF_SUCCESS;
    842845}
     
    933936     * timer is *not* saved.
    934937     */
    935     TMR3TimerSave(pThis->CTX_SUFF(pDelayTimer), pSSM);
     938    PDMDevHlpTimerSave(pDevIns, pThis->hDelayTimer, pSSM);
    936939}
    937940
     
    964967
    965968    /* Load the command delay timer, just in case. */
    966     rc = TMR3TimerLoad(pThis->CTX_SUFF(pDelayTimer), pSSM);
     969    rc = PDMDevHlpTimerLoad(pDevIns, pThis->hDelayTimer, pSSM);
    967970    AssertRCReturn(rc, rc);
    968971
     
    10011004}
    10021005
    1003 void PS2MR3Relocate(PPS2M pThis, RTGCINTPTR offDelta, PPDMDEVINS pDevIns)
    1004 {
    1005     RT_NOREF(pDevIns, offDelta);
    1006     LogFlowFunc(("Relocating PS2M\n"));
    1007     pThis->pDelayTimerRC    = TMTimerRCPtr(pThis->pDelayTimerR3);
    1008     pThis->pThrottleTimerRC = TMTimerRCPtr(pThis->pThrottleTimerR3);
    1009 }
    1010 
    10111006int PS2MR3Construct(PPS2M pThis, PPDMDEVINS pDevIns, PKBDSTATE pParent, unsigned iInstance)
    10121007{
     
    10201015
    10211016    pThis->pParent = pParent;
     1017    pThis->pDevIns = pDevIns;
    10221018
    10231019    /* Initialize the queues. */
     
    10381034     * Create the input rate throttling timer. Does not use virtual time!
    10391035     */
    1040     PTMTIMER pTimer;
    1041     int rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_REAL, ps2mR3ThrottleTimer, pThis,
    1042                                     TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Throttle Timer", &pTimer);
     1036    int rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_REAL, ps2mR3ThrottleTimer, pThis,
     1037                                  TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Throttle Timer", &pThis->hThrottleTimer);
    10431038    AssertRCReturn(rc, rc);
    1044 
    1045     pThis->pThrottleTimerR3 = pTimer;
    1046     pThis->pThrottleTimerR0 = TMTimerR0Ptr(pTimer);
    1047     pThis->pThrottleTimerRC = TMTimerRCPtr(pTimer);
    10481039
    10491040    /*
    10501041     * Create the command delay timer.
    10511042     */
    1052     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2mR3DelayTimer, pThis,
    1053                                 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Delay Timer", &pTimer);
     1043    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, ps2mR3DelayTimer, pThis,
     1044                              TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "PS2M Delay Timer", &pThis->hDelayTimer);
    10541045    AssertRCReturn(rc, rc);
    1055 
    1056     pThis->pDelayTimerR3 = pTimer;
    1057     pThis->pDelayTimerR0 = TMTimerR0Ptr(pTimer);
    1058     pThis->pDelayTimerRC = TMTimerRCPtr(pTimer);
    10591046
    10601047    /*
     
    10961083     * a release-press-release all within a single 10ms interval.  Simulate
    10971084     * this to check that it is handled right. */
    1098     ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
     1085    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 1);
    10991086    if (ps2mR3HaveEvents(&This))
    11001087        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    1101     ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 0);
     1088    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 0);
    11021089    if (ps2mR3HaveEvents(&This))
    11031090        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
    1104     ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
    1105     ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 0);
     1091    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 1);
     1092    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 0);
    11061093    if (ps2mR3HaveEvents(&This))
    11071094        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
     
    11201107    /* Button hold down during mouse drags was broken at some point during
    11211108     * testing fixes for the previous issue.  Test that that works. */
    1122     ps2mR3PutEventWorker(&This, 0, 0, 0, 0, 1);
     1109    ps2mR3PutEventWorker(NULL, &This, 0, 0, 0, 0, 1);
    11231110    if (ps2mR3HaveEvents(&This))
    11241111        ps2mReportAccumulatedEvents(&This, (GeneriQ *)&This.evtQ, true);
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