VirtualBox

Changeset 81809 in vbox


Ignore:
Timestamp:
Nov 12, 2019 3:40:09 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134600
Message:

DevBusLogic.cpp: Converting it to the new PDM device style - I/O ports. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevBusLogic.cpp

    r81808 r81809  
    2626#include <VBox/vmm/pdmstorageifs.h>
    2727#include <VBox/vmm/pdmcritsect.h>
     28#include <VBox/AssertGuest.h>
    2829#include <VBox/scsi.h>
    2930#include <iprt/asm.h>
     
    342343    /** Whether RC is enabled. */
    343344    bool                            fGCEnabled;
    344     /** Base address of the I/O ports. */
    345     RTIOPORT                        IOPortBase;
     345    bool                            afPadding[2];
    346346
    347347    /** Base address of the memory mapping. */
     
    487487#endif
    488488
     489    /** ISA compatibility I/O ports. */
     490    IOMIOPORTHANDLE                 hIoPortsIsa;
     491    /** PCI Region \#0: I/O ports. */
     492    IOMIOPORTHANDLE                 hIoPortsPci;
    489493} BUSLOGIC;
    490494/** Pointer to the shared BusLogic device emulation state. */
     
    10091013*********************************************************************************************************************************/
    10101014#ifdef IN_RING3
    1011 static int buslogicR3RegisterISARange(PBUSLOGIC pBusLogic, uint8_t uBaseCode);
     1015static int buslogicR3RegisterISARange(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, uint8_t uBaseCode);
    10121016#endif
    10131017
     
    11481152    /* Guest-initiated HBA reset does not affect ISA port I/O. */
    11491153    if (fResetIO)
    1150     {
    1151         buslogicR3RegisterISARange(pBusLogic, pBusLogic->uDefaultISABaseCode);
    1152     }
     1154        buslogicR3RegisterISARange(pBusLogic->CTX_SUFF(pDevIns), pBusLogic, pBusLogic->uDefaultISABaseCode);
    11531155    buslogicR3InitializeLocalRam(pBusLogic);
    11541156    vboxscsiInitialize(&pBusLogic->VBoxSCSI);
     
    18141816             * However, it is required for compatibility with old drivers.
    18151817             */
    1816 #ifdef IN_RING3
     1818#ifdef IN_RING3 /* We can do this from ring-0 now, but we'd like to see the LogRel, so we keep going back to ring-3 anyway. */
    18171819            Log(("ISA I/O for PCI (code %x)\n", pBusLogic->aCommandBuffer[0]));
    1818             buslogicR3RegisterISARange(pBusLogic, pBusLogic->aCommandBuffer[0]);
     1820            buslogicR3RegisterISARange(pBusLogic->CTX_SUFF(pDevIns), pBusLogic, pBusLogic->aCommandBuffer[0]);
    18191821            pBusLogic->cbReplyParametersLeft = 0;
    18201822            fSuppressIrq = true;
     
    26602662
    26612663/**
    2662  * Port I/O Handler for IN operations.
    2663  *
    2664  * @returns VBox status code.
    2665  *
    2666  * @param   pDevIns     The device instance.
    2667  * @param   pvUser      User argument.
    2668  * @param   uPort       Port number used for the IN operation.
    2669  * @param   pu32        Where to store the result.
    2670  * @param   cb          Number of bytes read.
    2671  */
    2672 PDMBOTHCBDECL(int) buslogicIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t *pu32, unsigned cb)
     2664 * @callback_method_impl{FNIOMIOPORTNEWIN}
     2665 */
     2666static DECLCALLBACK(VBOXSTRICTRC)
     2667buslogicIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
    26732668{
    26742669    PBUSLOGIC pBusLogic = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    2675     unsigned iRegister = uPort % 4;
    2676     RT_NOREF_PV(pvUser); RT_NOREF_PV(cb);
    2677 
    2678     Assert(cb == 1);
     2670    unsigned iRegister = offPort % 4;
     2671    RT_NOREF(pvUser, cb);
     2672
     2673    ASSERT_GUEST(cb == 1);
    26792674
    26802675    return buslogicRegisterRead(pBusLogic, iRegister, pu32);
     
    26822677
    26832678/**
    2684  * Port I/O Handler for OUT operations.
    2685  *
    2686  * @returns VBox status code.
    2687  *
    2688  * @param   pDevIns     The device instance.
    2689  * @param   pvUser      User argument.
    2690  * @param   uPort       Port number used for the IN operation.
    2691  * @param   u32         The value to output.
    2692  * @param   cb          The value size in bytes.
    2693  */
    2694 PDMBOTHCBDECL(int) buslogicIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t u32, unsigned cb)
     2679 * @callback_method_impl{FNIOMIOPORTNEWOUT}
     2680 */
     2681static DECLCALLBACK(VBOXSTRICTRC)
     2682buslogicIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
    26952683{
    26962684    PBUSLOGIC pBusLogic = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    2697     unsigned iRegister = uPort % 4;
    2698     uint8_t uVal = (uint8_t)u32;
    2699     RT_NOREF2(pvUser, cb);
    2700 
    2701     Assert(cb == 1);
    2702 
    2703     int rc = buslogicRegisterWrite(pDevIns, pBusLogic, iRegister, (uint8_t)uVal);
    2704 
    2705     Log2(("#%d %s: pvUser=%#p cb=%d u32=%#x uPort=%#x rc=%Rrc\n",
    2706           pDevIns->iInstance, __FUNCTION__, pvUser, cb, u32, uPort, rc));
     2685    unsigned iRegister = offPort % 4;
     2686    RT_NOREF(pvUser, cb);
     2687
     2688    ASSERT_GUEST(cb == 1);
     2689
     2690    int rc = buslogicRegisterWrite(pDevIns, pBusLogic, iRegister, (uint8_t)u32);
     2691
     2692    Log2(("#%d %s: pvUser=%#p cb=%d u32=%#x offPort=%#x rc=%Rrc\n",
     2693          pDevIns->iInstance, __FUNCTION__, pvUser, cb, u32, offPort, rc));
    27072694
    27082695    return rc;
     
    28912878 *
    28922879 * @returns nothing.
     2880 * @param   pDevIns         The device instance.
    28932881 * @param   pBusLogic       Pointer to the BusLogic device instance.
    28942882 * @param   uBaseCode       Encoded ISA I/O base; only low 3 bits are used.
    28952883 */
    2896 static int buslogicR3RegisterISARange(PBUSLOGIC pBusLogic, uint8_t uBaseCode)
     2884static int buslogicR3RegisterISARange(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, uint8_t uBaseCode)
    28972885{
    28982886    uint8_t     uCode = uBaseCode & MAX_ISA_BASE;
     
    29022890    LogFlowFunc(("ISA I/O code %02X, new base %X\n", uBaseCode, uNewBase));
    29032891
    2904     /* Check if the same port range is already registered. */
     2892    /* Check if the same port range actually changed. */
    29052893    if (uNewBase != pBusLogic->IOISABase)
    29062894    {
    2907         /* Unregister the old range, if any. */
     2895        /* Unmap the old range, if necessary. */
    29082896        if (pBusLogic->IOISABase)
    2909             rc = PDMDevHlpIOPortDeregister(pBusLogic->CTX_SUFF(pDevIns), pBusLogic->IOISABase, 4);
    2910 
     2897        {
     2898            rc = PDMDevHlpIoPortUnmap(pDevIns, pBusLogic->hIoPortsIsa);
     2899            AssertRC(rc);
     2900        }
    29112901        if (RT_SUCCESS(rc))
    29122902        {
     
    29172907            {
    29182908                /* Register the new range if requested. */
    2919                 rc = PDMDevHlpIOPortRegister(pBusLogic->CTX_SUFF(pDevIns), uNewBase, 4, NULL,
    2920                                              buslogicIOPortWrite, buslogicIOPortRead,
    2921                                              NULL, NULL,
    2922                                              "BusLogic ISA");
     2909                rc = PDMDevHlpIoPortMap(pDevIns, pBusLogic->hIoPortsIsa, uNewBase);
    29232910                if (RT_SUCCESS(rc))
    29242911                {
     
    29882975
    29892976        pThis->MMIOBase = GCPhysAddress;
    2990     }
    2991     else if (enmType == PCI_ADDRESS_SPACE_IO)
    2992     {
    2993         rc = PDMDevHlpIOPortRegister(pDevIns, (RTIOPORT)GCPhysAddress, 32,
    2994                                      NULL, buslogicIOPortWrite, buslogicIOPortRead, NULL, NULL, "BusLogic PCI");
    2995         if (RT_FAILURE(rc))
    2996             return rc;
    2997 
    2998         if (pThis->fR0Enabled)
    2999         {
    3000             rc = PDMDevHlpIOPortRegisterR0(pDevIns, (RTIOPORT)GCPhysAddress, 32,
    3001                                            0, "buslogicIOPortWrite", "buslogicIOPortRead", NULL, NULL, "BusLogic PCI");
    3002             if (RT_FAILURE(rc))
    3003                 return rc;
    3004         }
    3005 
    3006         if (pThis->fGCEnabled)
    3007         {
    3008             rc = PDMDevHlpIOPortRegisterRC(pDevIns, (RTIOPORT)GCPhysAddress, 32,
    3009                                            0, "buslogicIOPortWrite", "buslogicIOPortRead", NULL, NULL, "BusLogic PCI");
    3010             if (RT_FAILURE(rc))
    3011                 return rc;
    3012         }
    3013 
    3014         pThis->IOPortBase = (RTIOPORT)GCPhysAddress;
    30152977    }
    30162978    else
     
    35273489    PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    35283490
    3529     buslogicR3RegisterISARange(pThis, pThis->uISABaseCode);
     3491    buslogicR3RegisterISARange(pDevIns, pThis, pThis->uISABaseCode);
    35303492
    35313493    /* Kick of any requests we might need to redo. */
     
    38273789                        pThis->uIsaIrq);
    38283790    else
    3829         pHlp->pfnPrintf(pHlp, "PCI I/O=%RTiop ISA I/O=%RTiop MMIO=%RGp IRQ=%u ",
    3830                         pThis->IOPortBase, pThis->IOISABase, pThis->MMIOBase,
     3791        pHlp->pfnPrintf(pHlp, "PCI I/O=%04x ISA I/O=%RTiop MMIO=%RGp IRQ=%u ",
     3792                        PDMDevHlpIoPortGetMappingAddress(pDevIns, pThis->hIoPortsPci), pThis->IOISABase, pThis->MMIOBase,
    38313793                        PCIDevGetInterruptLine(pDevIns->apPciDevs[0]));
    38323794    pHlp->pfnPrintf(pHlp, "GC=%RTbool R0=%RTbool\n",
     
    42774239    {
    42784240        rc = PDMDevHlpPCIRegister(pDevIns, pPciDev);
    4279         if (RT_FAILURE(rc))
    4280             return rc;
    4281 
    4282         rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 32, PCI_ADDRESS_SPACE_IO, buslogicR3MmioMap);
    4283         if (RT_FAILURE(rc))
    4284             return rc;
     4241        AssertRCReturn(rc, rc);
     4242
     4243        rc = PDMDevHlpPCIIORegionCreateIo(pDevIns, 0 /*iPciRegion*/, 32 /*cPorts*/,
     4244                                          buslogicIOPortWrite, buslogicIOPortRead, NULL /*pvUser*/,
     4245                                          "BusLogic PCI", NULL /*paExtDescs*/, &pThis->hIoPortsPci);
     4246        AssertRCReturn(rc, rc);
    42854247
    42864248        rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, 32, PCI_ADDRESS_SPACE_MEM, buslogicR3MmioMap);
     
    43014263
    43024264    /* Set up the compatibility I/O range. */
    4303     rc = buslogicR3RegisterISARange(pThis, pThis->uDefaultISABaseCode);
     4265    rc = PDMDevHlpIoPortCreate(pDevIns, 4 /*cPorts*/, NULL /*pPciDev*/, UINT32_MAX /*iPciRegion*/,
     4266                               buslogicIOPortWrite, buslogicIOPortRead, NULL /*pvUser*/,
     4267                               "BusLogic ISA", NULL /*paExtDescs*/, &pThis->hIoPortsIsa);
     4268    AssertRCReturn(rc, rc);
     4269
     4270    rc = buslogicR3RegisterISARange(pDevIns, pThis, pThis->uDefaultISABaseCode);
    43044271    if (RT_FAILURE(rc))
    43054272        return PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic cannot register ISA I/O handlers"));
     
    44274394}
    44284395
    4429 #endif /* IN_RING3 */
     4396#else  /* !IN_RING3 */
     4397
     4398/**
     4399 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
     4400 */
     4401static DECLCALLBACK(int) buslogicRZConstruct(PPDMDEVINS pDevIns)
     4402{
     4403    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     4404    PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     4405
     4406    int rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortsPci, buslogicIOPortWrite, buslogicIOPortRead, NULL /*pvUser*/);
     4407    AssertRCReturn(rc, rc);
     4408
     4409    return VINF_SUCCESS;
     4410}
     4411
     4412
     4413#endif /* !IN_RING3 */
    44304414
    44314415/**
     
    44764460#elif defined(IN_RING0)
    44774461    /* .pfnEarlyConstruct = */      NULL,
    4478     /* .pfnConstruct = */           NULL,
     4462    /* .pfnConstruct = */           buslogicRZConstruct,
    44794463    /* .pfnDestruct = */            NULL,
    44804464    /* .pfnFinalDestruct = */       NULL,
     
    44894473    /* .pfnReserved7 = */           NULL,
    44904474#elif defined(IN_RC)
    4491     /* .pfnConstruct = */           NULL,
     4475    /* .pfnConstruct = */           buslogicRZConstruct,
    44924476    /* .pfnReserved0 = */           NULL,
    44934477    /* .pfnReserved1 = */           NULL,
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