VirtualBox

Ignore:
Timestamp:
Nov 17, 2019 10:38:54 AM (5 years ago)
Author:
vboxsync
Message:

DevPit-i8254: Converted the I/O ports to new style. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevPit-i8254.cpp

    r81900 r81902  
    251251    /** Critical section protecting the state. */
    252252    PDMCRITSECT             CritSect;
     253    /** The primary I/O port range (0x40-0x43). */
     254    IOMIOPORTHANDLE         hIoPorts;
     255    /** The speaker I/O port range (0x40-0x43). */
     256    IOMIOPORTHANDLE         hIoPortSpeaker;
    253257} PITSTATE;
    254258/** Pointer to the PIT device state. */
     
    643647
    644648/**
    645  * @callback_method_impl{FNIOMIOPORTIN}
    646  */
    647 PDMBOTHCBDECL(int) pitIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t *pu32, unsigned cb)
    648 {
    649     Log2(("pitIOPortRead: uPort=%#x cb=%x\n", uPort, cb));
     649 * @callback_method_impl{FNIOMIOPORTNEWIN}
     650 */
     651static DECLCALLBACK(VBOXSTRICTRC) pitIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
     652{
     653    Log2(("pitIOPortRead: offPort=%#x cb=%x\n", offPort, cb));
    650654    NOREF(pvUser);
    651     uPort &= 3;
    652     if (cb != 1 || uPort == 3)
    653     {
    654         Log(("pitIOPortRead: uPort=%#x cb=%x *pu32=unused!\n", uPort, cb));
     655    Assert(offPort < 4);
     656    if (cb != 1 || offPort == 3)
     657    {
     658        Log(("pitIOPortRead: offPort=%#x cb=%x *pu32=unused!\n", offPort, cb));
    655659        return VERR_IOM_IOPORT_UNUSED;
    656660    }
     
    658662
    659663    PPITSTATE   pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    660     PPITCHANNEL pChan = &pThis->channels[uPort];
     664    PPITCHANNEL pChan = &pThis->channels[offPort];
    661665    int ret;
    662666
     
    719723
    720724    *pu32 = ret;
    721     Log2(("pitIOPortRead: uPort=%#x cb=%x *pu32=%#04x\n", uPort, cb, *pu32));
     725    Log2(("pitIOPortRead: offPort=%#x cb=%x *pu32=%#04x\n", offPort, cb, *pu32));
    722726    return VINF_SUCCESS;
    723727}
     
    725729
    726730/**
    727  * @callback_method_impl{FNIOMIOPORTOUT}
    728  */
    729 PDMBOTHCBDECL(int) pitIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t u32, unsigned cb)
    730 {
    731     Log2(("pitIOPortWrite: uPort=%#x cb=%x u32=%#04x\n", uPort, cb, u32));
     731 * @callback_method_impl{FNIOMIOPORTNEWOUT}
     732 */
     733static DECLCALLBACK(VBOXSTRICTRC) pitIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
     734{
     735    Log2(("pitIOPortWrite: offPort=%#x cb=%x u32=%#04x\n", offPort, cb, u32));
    732736    NOREF(pvUser);
     737    Assert(offPort < 4);
     738
    733739    if (cb != 1)
    734740        return VINF_SUCCESS;
    735741
    736742    PPITSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
    737     uPort &= 3;
    738     if (uPort == 3)
     743    if (offPort == 3)
    739744    {
    740745        /*
     
    820825         */
    821826        RT_UNTRUSTED_VALIDATED_FENCE(); /* paranoia */
    822         PPITCHANNEL pChan = &pThis->channels[uPort];
     827        PPITCHANNEL pChan = &pThis->channels[offPort];
    823828        DEVPIT_LOCK_BOTH_RETURN(pDevIns, pThis, VINF_IOM_R3_IOPORT_WRITE);
    824829        switch (pChan->write_state)
     
    848853
    849854/**
    850  * @callback_method_impl{FNIOMIOPORTIN, Speaker}
    851  */
    852 PDMBOTHCBDECL(int) pitIOPortSpeakerRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t *pu32, unsigned cb)
    853 {
    854     RT_NOREF(pvUser, uPort);
     855 * @callback_method_impl{FNIOMIOPORTNEWIN, Speaker}
     856 */
     857static DECLCALLBACK(VBOXSTRICTRC)
     858pitIOPortSpeakerRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
     859{
     860    RT_NOREF(pvUser, offPort);
    855861    if (cb == 1)
    856862    {
     
    884890              | (fRefresh << 4)
    885891              | (fOut << 5);
    886         Log(("pitIOPortSpeakerRead: uPort=%#x cb=%x *pu32=%#x\n", uPort, cb, *pu32));
     892        Log(("pitIOPortSpeakerRead: offPort=%#x cb=%x *pu32=%#x\n", offPort, cb, *pu32));
    887893        return VINF_SUCCESS;
    888894    }
    889     Log(("pitIOPortSpeakerRead: uPort=%#x cb=%x *pu32=unused!\n", uPort, cb));
     895    Log(("pitIOPortSpeakerRead: offPort=%#x cb=%x *pu32=unused!\n", offPort, cb));
    890896    return VERR_IOM_IOPORT_UNUSED;
    891897}
     
    894900
    895901/**
    896  * @callback_method_impl{FNIOMIOPORTOUT, Speaker}
    897  */
    898 PDMBOTHCBDECL(int) pitIOPortSpeakerWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t u32, unsigned cb)
    899 {
    900     RT_NOREF(pvUser, uPort);
     902 * @callback_method_impl{FNIOMIOPORTNEWOUT, Speaker}
     903 */
     904static DECLCALLBACK(VBOXSTRICTRC)
     905pitR3IOPortSpeakerWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
     906{
     907    RT_NOREF(pvUser, offPort);
    901908    if (cb == 1)
    902909    {
     
    992999        DEVPIT_UNLOCK_BOTH(pDevIns, pThis);
    9931000    }
    994     Log(("pitIOPortSpeakerWrite: uPort=%#x cb=%x u32=%#x\n", uPort, cb, u32));
     1001    Log(("pitR3IOPortSpeakerWrite: offPort=%#x cb=%x u32=%#x\n", offPort, cb, u32));
    9951002    return VINF_SUCCESS;
    9961003}
     
    14281435     * Register I/O ports.
    14291436     */
    1430     rc = PDMDevHlpIOPortRegister(pDevIns, u16Base, 4, NULL, pitIOPortWrite, pitIOPortRead, NULL, NULL, "i8254 Programmable Interval Timer");
    1431     if (RT_FAILURE(rc))
    1432         return rc;
    1433     if (pDevIns->fRCEnabled)
    1434     {
    1435         rc = PDMDevHlpIOPortRegisterRC(pDevIns, u16Base, 4, 0, "pitIOPortWrite", "pitIOPortRead", NULL, NULL, "i8254 Programmable Interval Timer");
    1436         if (RT_FAILURE(rc))
    1437             return rc;
    1438     }
    1439     if (pDevIns->fR0Enabled)
    1440     {
    1441         rc = PDMDevHlpIOPortRegisterR0(pDevIns, u16Base, 4, 0, "pitIOPortWrite", "pitIOPortRead", NULL, NULL, "i8254 Programmable Interval Timer");
    1442         if (RT_FAILURE(rc))
    1443             return rc;
    1444     }
     1437    rc = PDMDevHlpIoPortCreateAndMap(pDevIns, u16Base, 4 /*cPorts*/, pitIOPortWrite, pitIOPortRead,
     1438                                     "i8254 Programmable Interval Timer", NULL /*paExtDescs*/, &pThis->hIoPorts);
     1439    AssertRCReturn(rc, rc);
    14451440
    14461441    if (fSpeaker)
    14471442    {
    1448         rc = PDMDevHlpIOPortRegister(pDevIns, 0x61, 1, NULL, pitIOPortSpeakerWrite, pitIOPortSpeakerRead, NULL, NULL, "PC Speaker");
    1449         if (RT_FAILURE(rc))
    1450             return rc;
    1451         if (pDevIns->fRCEnabled)
    1452         {
    1453             rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x61, 1, 0, NULL, "pitIOPortSpeakerRead", NULL, NULL, "PC Speaker");
    1454             if (RT_FAILURE(rc))
    1455                 return rc;
    1456         }
     1443        rc = PDMDevHlpIoPortCreateAndMap(pDevIns, 0x61, 1 /*cPorts*/, pitR3IOPortSpeakerWrite, pitIOPortSpeakerRead,
     1444                                         "PC Speaker", NULL /*paExtDescs*/, &pThis->hIoPortSpeaker);
     1445        AssertRCReturn(rc, rc);
    14571446    }
    14581447
     
    14801469}
    14811470
    1482 #endif /* IN_RING3 */
     1471#else  /* !IN_RING3 */
     1472
     1473/**
     1474 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
     1475 */
     1476static DECLCALLBACK(int) picRZConstruct(PPDMDEVINS pDevIns)
     1477{
     1478    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     1479    PPITSTATE pThis = PDMDEVINS_2_DATA(pDevIns, PPITSTATE);
     1480
     1481    int rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
     1482    AssertRCReturn(rc, rc);
     1483
     1484    rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPorts, pitIOPortWrite, pitIOPortRead, NULL /*pvUser*/);
     1485    AssertRCReturn(rc, rc);
     1486
     1487    rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortSpeaker, NULL /*pfnWrite*/, pitIOPortSpeakerRead, NULL /*pvUser*/);
     1488    AssertRCReturn(rc, rc);
     1489
     1490    return VINF_SUCCESS;
     1491}
     1492
     1493#endif /* !IN_RING3 */
    14831494
    14841495/**
     
    15271538#elif defined(IN_RING0)
    15281539    /* .pfnEarlyConstruct = */      NULL,
    1529     /* .pfnConstruct = */           NULL,
     1540    /* .pfnConstruct = */           picRZConstruct,
    15301541    /* .pfnDestruct = */            NULL,
    15311542    /* .pfnFinalDestruct = */       NULL,
     
    15401551    /* .pfnReserved7 = */           NULL,
    15411552#elif defined(IN_RC)
    1542     /* .pfnConstruct = */           NULL,
     1553    /* .pfnConstruct = */           picRZConstruct,
    15431554    /* .pfnReserved0 = */           NULL,
    15441555    /* .pfnReserved1 = */           NULL,
Note: See TracChangeset for help on using the changeset viewer.

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