VirtualBox

Changeset 81375 in vbox for trunk/src/VBox/Devices/Bus


Ignore:
Timestamp:
Oct 19, 2019 1:57:55 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134088
Message:

IOM,PDM,PCI: Making new MMIO code work with PCI. bugref:9218

Location:
trunk/src/VBox/Devices/Bus
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Bus/DevPciIch9.cpp

    r81136 r81375  
    10391039 * @interface_method_impl{PDMPCIBUSREGR3,pfnIORegionRegisterR3}
    10401040 */
    1041 DECLCALLBACK(int) devpciR3CommonIORegionRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iRegion, RTGCPHYS cbRegion,
    1042                                                  PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
    1043 {
    1044     NOREF(pDevIns);
     1041DECLCALLBACK(int) devpciR3CommonIORegionRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
     1042                                                 RTGCPHYS cbRegion, PCIADDRESSSPACE enmType, uint32_t fFlags,
     1043                                                 uint64_t hHandle, PFNPCIIOREGIONMAP pfnCallback)
     1044{
     1045    LogFunc(("%s: region #%u size %RGp type %x fFlags=%#x hHandle=%#RX64\n",
     1046             pPciDev->pszNameR3, iRegion, cbRegion, enmType, fFlags, hHandle));
     1047    RT_NOREF(pDevIns);
    10451048
    10461049    /*
     
    10631066                    ("Invalid cbRegion=%RGp iLastSet=%#x (not a power of 2 or 0)\n", cbRegion, iLastSet),
    10641067                    VERR_INVALID_PARAMETER);
    1065 
    1066     LogFunc(("%s region %d size %RGp type %x\n", pPciDev->pszNameR3, iRegion, cbRegion, enmType));
     1068    switch (fFlags & PDMPCIDEV_IORGN_F_HANDLE_MASK)
     1069    {
     1070        case PDMPCIDEV_IORGN_F_IOPORT_HANDLE:
     1071        case PDMPCIDEV_IORGN_F_MMIO_HANDLE:
     1072        case PDMPCIDEV_IORGN_F_MMIO2_HANDLE:
     1073            AssertReturn(hHandle != UINT64_MAX, VERR_INVALID_HANDLE);
     1074            break;
     1075        default:
     1076            AssertReturn(hHandle == UINT64_MAX, VERR_INVALID_HANDLE);
     1077    }
    10671078
    10681079    /* Make sure that we haven't marked this region as continuation of 64-bit region. */
    1069     Assert(pPciDev->Int.s.aIORegions[iRegion].type != 0xff);
     1080    AssertReturn(pPciDev->Int.s.aIORegions[iRegion].type != 0xff, VERR_NOT_AVAILABLE);
    10701081
    10711082    /*
     
    10751086    pRegion->addr        = INVALID_PCI_ADDRESS;
    10761087    pRegion->size        = cbRegion;
     1088    pRegion->fFlags      = fFlags;
     1089    pRegion->hHandle     = hHandle;
    10771090    pRegion->type        = enmType;
    1078     pRegion->map_func    = pfnCallback;
     1091    pRegion->pfnMap      = pfnCallback;
    10791092
    10801093    if ((enmType & PCI_ADDRESS_SPACE_BAR64) != 0)
     
    25242537static int devpciR3UnmapRegion(PPDMDEVINS pDevIns, PPDMPCIDEV pDev, int iRegion)
    25252538{
    2526     PCIIORegion *pRegion = &pDev->Int.s.aIORegions[iRegion];
     2539    PPCIIOREGION pRegion = &pDev->Int.s.aIORegions[iRegion];
    25272540    AssertReturn(pRegion->size != 0, VINF_SUCCESS);
    25282541
    2529     int rc;
    2530     if (pRegion->addr == INVALID_PCI_ADDRESS)
    2531         rc = VINF_SUCCESS;
    2532     else
    2533     {
    2534         if (pRegion->type & PCI_ADDRESS_SPACE_IO)
    2535         {
    2536             /* Port IO */
    2537             rc = PDMDevHlpIOPortDeregister(pDev->Int.s.pDevInsR3, pRegion->addr, pRegion->size);
    2538             AssertRC(rc);
     2542    int rc = VINF_SUCCESS;
     2543    if (pRegion->addr != INVALID_PCI_ADDRESS)
     2544    {
     2545        if (pRegion->hHandle != UINT64_MAX)
     2546        {
     2547            /*
     2548             * New style device with a IOM handle.  Do callout first (optional),
     2549             * then do the unmapping via handle.
     2550             */
     2551            if (pRegion->pfnMap)
     2552            {
     2553                rc = pRegion->pfnMap(pDev->Int.s.pDevInsR3, pDev, iRegion,
     2554                                     NIL_RTGCPHYS, pRegion->size, (PCIADDRESSSPACE)(pRegion->type));
     2555                AssertRC(rc);
     2556            }
     2557
     2558            switch (pRegion->fFlags & PDMPCIDEV_IORGN_F_HANDLE_MASK)
     2559            {
     2560                case PDMPCIDEV_IORGN_F_IOPORT_HANDLE:
     2561                    rc = PDMDevHlpIoPortUnmap(pDev->Int.s.pDevInsR3, (IOMIOPORTHANDLE)pRegion->hHandle);
     2562                    AssertRC(rc);
     2563                    break;
     2564
     2565                case PDMPCIDEV_IORGN_F_MMIO_HANDLE:
     2566                    rc = PDMDevHlpMmioUnmap(pDev->Int.s.pDevInsR3, (IOMMMIOHANDLE)pRegion->hHandle);
     2567                    AssertRC(rc);
     2568                    break;
     2569
     2570                default:
     2571                    AssertLogRelFailed();
     2572            }
    25392573        }
    25402574        else
    25412575        {
    2542             PDEVPCIBUSCC pBusCC     = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC);
    2543             RTGCPHYS     GCPhysBase = pRegion->addr;
    2544             if (pBusCC->pPciHlpR3->pfnIsMMIOExBase(pDevIns, pDev->Int.s.pDevInsR3, GCPhysBase))
     2576            /*
     2577             * Old style device, no handle here and only MMIOEx gets callouts.
     2578             */
     2579            if (pRegion->type & PCI_ADDRESS_SPACE_IO)
    25452580            {
    2546                 /* unmap it. */
    2547                 rc = pRegion->map_func(pDev->Int.s.pDevInsR3, pDev, iRegion,
    2548                                        NIL_RTGCPHYS, pRegion->size, (PCIADDRESSSPACE)(pRegion->type));
     2581                /* Port IO */
     2582                rc = PDMDevHlpIOPortDeregister(pDev->Int.s.pDevInsR3, pRegion->addr, pRegion->size);
    25492583                AssertRC(rc);
    2550                 rc = PDMDevHlpMMIOExUnmap(pDev->Int.s.pDevInsR3, pDev, iRegion, GCPhysBase);
    25512584            }
    25522585            else
    2553                 rc = PDMDevHlpMMIODeregister(pDev->Int.s.pDevInsR3, GCPhysBase, pRegion->size);
    2554             AssertRC(rc);
     2586            {
     2587                PDEVPCIBUSCC pBusCC     = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC);
     2588                RTGCPHYS     GCPhysBase = pRegion->addr;
     2589                if (pBusCC->pPciHlpR3->pfnIsMMIOExBase(pDevIns, pDev->Int.s.pDevInsR3, GCPhysBase))
     2590                {
     2591                    /* unmap it. */
     2592                    rc = pRegion->pfnMap(pDev->Int.s.pDevInsR3, pDev, iRegion,
     2593                                         NIL_RTGCPHYS, pRegion->size, (PCIADDRESSSPACE)(pRegion->type));
     2594                    AssertRC(rc);
     2595                    rc = PDMDevHlpMMIOExUnmap(pDev->Int.s.pDevInsR3, pDev, iRegion, GCPhysBase);
     2596                }
     2597                else
     2598                    rc = PDMDevHlpMMIODeregister(pDev->Int.s.pDevInsR3, GCPhysBase, pRegion->size);
     2599                AssertRC(rc);
     2600            }
    25552601        }
    25562602        pRegion->addr = INVALID_PCI_ADDRESS;
     
    25792625        if (fP2PBridge && iRegion >= 2 && iRegion <= 5)
    25802626            continue;
    2581         PCIIORegion   *pRegion  = &pPciDev->Int.s.aIORegions[iRegion];
     2627        PCIIOREGION   *pRegion  = &pPciDev->Int.s.aIORegions[iRegion];
    25822628        uint64_t const cbRegion = pRegion->size;
    25832629        if (cbRegion != 0)
     
    26622708            /*
    26632709             * Do real unmapping and/or mapping if the address change.
     2710             *
     2711             * For new style device we'll do the actual mapping, whereas old ones
     2712             * are expected to do it themselves via the callback.
    26642713             */
    26652714            Log4(("devpciR3UpdateMappings: dev %u/%u (%s): iRegion=%u addr=%#RX64 uNew=%#RX64\n",
     
    26722721                         pPciDev->pszNameR3, iRegion, pRegion->addr, uNew, cbRegion, cbRegion));
    26732722
    2674                 devpciR3UnmapRegion(pDevIns, pPciDev, iRegion);
     2723                int rc = devpciR3UnmapRegion(pDevIns, pPciDev, iRegion);
     2724                AssertLogRelRC(rc);
    26752725                pRegion->addr = uNew;
    26762726                if (uNew != INVALID_PCI_ADDRESS)
    26772727                {
    2678                     int rc = pRegion->map_func(pPciDev->Int.s.pDevInsR3, pPciDev, iRegion, uNew, cbRegion,
    2679                                                (PCIADDRESSSPACE)pRegion->type);
    2680                     AssertRC(rc);
     2728                    /* The callout is optional with new style devices: */
     2729                    int rc;
     2730                    if (pRegion->pfnMap)
     2731                    {
     2732                        rc = pRegion->pfnMap(pPciDev->Int.s.pDevInsR3, pPciDev, iRegion,
     2733                                             uNew, cbRegion, (PCIADDRESSSPACE)(pRegion->type));
     2734                        AssertLogRelRC(rc);
     2735                    }
     2736
     2737                    /* We do the mapping for new-style devices: */
     2738                    if (pRegion->hHandle != UINT64_MAX)
     2739                    {
     2740                        switch (pRegion->fFlags & PDMPCIDEV_IORGN_F_HANDLE_MASK)
     2741                        {
     2742                            case PDMPCIDEV_IORGN_F_IOPORT_HANDLE:
     2743                                rc = PDMDevHlpIoPortMap(pPciDev->Int.s.pDevInsR3, (IOMIOPORTHANDLE)pRegion->hHandle, (RTIOPORT)uNew);
     2744                                AssertLogRelRC(rc);
     2745                                break;
     2746
     2747                            case PDMPCIDEV_IORGN_F_MMIO_HANDLE:
     2748                                rc = PDMDevHlpMmioMap(pPciDev->Int.s.pDevInsR3, (IOMMMIOHANDLE)pRegion->hHandle, uNew);
     2749                                AssertLogRelRC(rc);
     2750                                break;
     2751
     2752                            default:
     2753                                AssertLogRelFailed();
     2754                        }
     2755                    }
    26812756                }
    26822757            }
     
    27022777DECLINLINE(void) devpciR3WriteBarByte(PPDMPCIDEV pPciDev, uint32_t iRegion, uint32_t off, uint8_t bVal)
    27032778{
    2704     PCIIORegion *pRegion = &pPciDev->Int.s.aIORegions[iRegion];
     2779    PCIIOREGION *pRegion = &pPciDev->Int.s.aIORegions[iRegion];
    27052780    Log3Func(("region=%d off=%d val=%#x size=%#llx\n", iRegion, off, bVal, pRegion->size));
    27062781    Assert(off <= 3);
     
    30733148            for (unsigned iRegion = 0; iRegion < VBOX_PCI_NUM_REGIONS; iRegion++)
    30743149            {
    3075                 PCIIORegion const *pRegion  = &pPciDev->Int.s.aIORegions[iRegion];
     3150                PCIIOREGION const *pRegion  = &pPciDev->Int.s.aIORegions[iRegion];
    30763151                uint64_t const     cbRegion = pRegion->size;
    30773152
     
    34313506    for (int iRegion = 0; iRegion < VBOX_PCI_NUM_REGIONS; iRegion++)
    34323507    {
    3433         PCIIORegion* pRegion = &pDev->Int.s.aIORegions[iRegion];
     3508        PCIIOREGION *pRegion = &pDev->Int.s.aIORegions[iRegion];
    34343509        if (pRegion->size == 0)
    34353510            continue;
  • trunk/src/VBox/Devices/Bus/DevPciInternal.h

    r81034 r81375  
    210210DECLCALLBACK(int)  devpcibridgeR3CommonRegisterDevice(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t fFlags,
    211211                                                      uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName);
    212 DECLCALLBACK(int)  devpciR3CommonIORegionRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iRegion, RTGCPHYS cbRegion,
    213                                                   PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback);
     212DECLCALLBACK(int)  devpciR3CommonIORegionRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
     213                                                  RTGCPHYS cbRegion, PCIADDRESSSPACE enmType, uint32_t fFlags,
     214                                                  uint64_t hHandle, PFNPCIIOREGIONMAP pfnCallback);
    214215DECLCALLBACK(void) devpciR3CommonInterceptConfigAccesses(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
    215216                                                         PFNPCICONFIGREAD pfnRead, PFNPCICONFIGWRITE pfnWrite);
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