VirtualBox

Changeset 81031 in vbox for trunk/src/VBox/Devices/Samples


Ignore:
Timestamp:
Sep 26, 2019 7:26:33 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133634
Message:

PDM,Devices: Moving the PDMPCIDEV structures into the PDMDEVINS allocation. Preps for extending the config space to 4KB. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Samples/DevPlayground.cpp

    r80704 r81031  
    5151typedef struct VBOXPLAYGROUNDDEVICEFUNCTION
    5252{
    53     /** The PCI devices. */
    54     PDMPCIDEV   PciDev;
    5553    /** The function number. */
    5654    uint8_t     iFun;
     
    203201
    204202    uint8_t uNumFunctions;
     203    AssertCompile(RT_ELEMENTS(pThis->aPciFuns) <= RT_ELEMENTS(pDevIns->apPciDevs));
    205204    rc = CFGMR3QueryU8Def(pCfg, "NumFunctions", &uNumFunctions, RT_ELEMENTS(pThis->aPciFuns));
    206205    if (RT_FAILURE(rc))
     
    258257    for (uint32_t iPciFun = 0; iPciFun < uNumFunctions; iPciFun++)
    259258    {
    260         PVBOXPLAYGROUNDDEVICEFUNCTION pFun = &pThis->aPciFuns[iPciFun];
    261         RTStrPrintf(pFun->szName, sizeof(pThis->aPciFuns[iPciFun].PciDev), "playground%u", iPciFun);
     259        PPDMPCIDEV                    pPciDev = pDevIns->apPciDevs[iPciFun];
     260        PVBOXPLAYGROUNDDEVICEFUNCTION pFun    = &pThis->aPciFuns[iPciFun];
     261        RTStrPrintf(pFun->szName, sizeof(pFun->szName), "playground%u", iPciFun);
    262262        pFun->iFun = iPciFun;
    263263
    264         PCIDevSetVendorId( &pFun->PciDev, 0x80ee);
    265         PCIDevSetDeviceId( &pFun->PciDev, 0xde4e);
    266         PCIDevSetClassBase(&pFun->PciDev, 0x07);   /* communications device */
    267         PCIDevSetClassSub( &pFun->PciDev, 0x80);   /* other communications device */
    268         if (iPciFun == 0)       /* only for the primary function */
    269             PCIDevSetHeaderType(&pFun->PciDev, 0x80); /* normal, multifunction device */
    270 
    271         rc = PDMDevHlpPCIRegisterEx(pDevIns, &pFun->PciDev, iPciFun, 0 /*fFlags*/, iPciDevNo, iPciFun,
    272                                     pThis->aPciFuns[iPciFun].szName);
     264        PDMPCIDEV_ASSERT_VALID(pDevIns, pPciDev);
     265
     266        PDMPciDevSetVendorId(pPciDev,       0x80ee);
     267        PDMPciDevSetDeviceId(pPciDev,       0xde4e);
     268        PDMPciDevSetClassBase(pPciDev,      0x07);  /* communications device */
     269        PDMPciDevSetClassSub(pPciDev,       0x80);  /* other communications device */
     270        if (iPciFun == 0) /* only for the primary function */
     271            PDMPciDevSetHeaderType(pPciDev, 0x80);  /* normal, multifunction device */
     272
     273        rc = PDMDevHlpPCIRegisterEx(pDevIns, pPciDev, 0 /*fFlags*/, iPciDevNo, iPciFun, pThis->aPciFuns[iPciFun].szName);
    273274        AssertLogRelRCReturn(rc, rc);
    274275
    275276        /* First region. */
    276277        RTGCPHYS const cbFirst = iPciFun == 0 ? cbFirstBAR : iPciFun * _4K;
    277         rc = PDMDevHlpPCIIORegionRegisterEx(pDevIns, &pFun->PciDev, 0, cbFirst,
     278        rc = PDMDevHlpPCIIORegionRegisterEx(pDevIns, pPciDev, 0, cbFirst,
    278279                                            (PCIADDRESSSPACE)(  PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64
    279280                                                              | (iPciFun == 0 ? PCI_ADDRESS_SPACE_MEM_PREFETCH : 0)),
     
    283284        RTStrAPrintf(&pszRegionName, "PG-F%d-BAR0", iPciFun);
    284285        Assert(pszRegionName);
    285         rc = PDMDevHlpMMIOExPreRegister(pDevIns, &pFun->PciDev, 0, cbFirst,
     286        rc = PDMDevHlpMMIOExPreRegister(pDevIns, pPciDev, 0, cbFirst,
    286287                                        IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, pszRegionName,
    287288                                        NULL /*pvUser*/,  devPlaygroundMMIOWrite, devPlaygroundMMIORead, NULL /*pfnFill*/,
     
    292293        /* Second region. */
    293294        RTGCPHYS const cbSecond = iPciFun == 0  ? cbSecondBAR : iPciFun * _32K;
    294         rc = PDMDevHlpPCIIORegionRegisterEx(pDevIns, &pFun->PciDev, 2, cbSecond,
     295        rc = PDMDevHlpPCIIORegionRegisterEx(pDevIns, pPciDev, 2, cbSecond,
    295296                                            (PCIADDRESSSPACE)(  PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64
    296297                                                              | (iPciFun == 0 ? PCI_ADDRESS_SPACE_MEM_PREFETCH : 0)),
     
    300301        RTStrAPrintf(&pszRegionName, "PG-F%d-BAR2", iPciFun);
    301302        Assert(pszRegionName);
    302         rc = PDMDevHlpMMIOExPreRegister(pDevIns, &pFun->PciDev, 2, cbSecond,
     303        rc = PDMDevHlpMMIOExPreRegister(pDevIns, pPciDev, 2, cbSecond,
    303304                                        IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, pszRegionName,
    304305                                        NULL /*pvUser*/,  devPlaygroundMMIOWrite, devPlaygroundMMIORead, NULL /*pfnFill*/,
     
    351352    /* .cbInstanceCC = */           0,
    352353    /* .cbInstanceRC = */           0,
    353     /* .cMaxPciDevices = */         1,
     354    /* .cMaxPciDevices = */         8,
    354355    /* .cMaxMsixVectors = */        0,
    355356    /* .pszDescription = */         "VBox Playground Device.",
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