VirtualBox

Changeset 44795 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Feb 21, 2013 7:49:18 PM (12 years ago)
Author:
vboxsync
Message:

DevPCI.cpp: Some cleanups.

File:
1 edited

Legend:

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

    r44508 r44795  
    179179/** Converts a bus instance pointer to a device instance pointer. */
    180180#define PCIBUS_2_DEVINS(pPciBus)        ((pPciBus)->CTX_SUFF(pDevIns))
    181 /** Converts a device instance pointer to a PCIGLOBALS pointer. */
     181/** Converts a PCI bus device instance pointer to a PCIGLOBALS pointer. */
    182182#define DEVINS_2_PCIGLOBALS(pDevIns)    ((PPCIGLOBALS)(PDMINS_2_DATA(pDevIns, PPCIGLOBALS)))
    183 /** Converts a device instance pointer to a PCIBUS pointer. */
     183/** Converts a PCI bus device instance pointer to a PCIBUS pointer. */
    184184#define DEVINS_2_PCIBUS(pDevIns)        ((PPCIBUS)(&PDMINS_2_DATA(pDevIns, PPCIGLOBALS)->PciBus))
    185185
     
    187187 *  @note This works only if the bus number is 0!!!
    188188 */
    189 #define PCIBUS_2_PCIGLOBALS(pPciBus)    ( (PPCIGLOBALS)((uintptr_t)(pPciBus) - RT_OFFSETOF(PCIGLOBALS, PciBus)) )
     189#define PCIBUS_2_PCIGLOBALS(pPciBus)    RT_FROM_MEMBER(pPciBus, PCIGLOBALS, PciBus)
    190190
    191191/** @def PCI_LOCK
     
    743743}
    744744
    745 /**
    746  * Set the IRQ for a PCI device on the host bus.
    747  *
    748  * @param   pDevIns         Device instance of the PCI Bus.
    749  * @param   pPciDev         The PCI device structure.
    750  * @param   iIrq            IRQ number to set.
    751  * @param   iLevel          IRQ level.
    752  * @param   uTagSrc         The IRQ tag and source ID (for tracing).
     745
     746/**
     747 * @interface_method_impl{PDMPCIBUSREG,pfnSetIrq}
    753748 */
    754749PDMBOTHCBDECL(void) pciSetIrq(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel, uint32_t uTagSrc)
     
    11251120#endif /* IN_RING3 */
    11261121
    1127 /* -=-=-=-=-=- wrappers -=-=-=-=-=- */
    1128 
    1129 /**
    1130  * Port I/O Handler for PCI address OUT operations.
    1131  *
    1132  * @returns VBox status code.
    1133  *
    1134  * @param   pDevIns     The device instance.
    1135  * @param   pvUser      User argument - ignored.
    1136  * @param   uPort       Port number used for the IN operation.
    1137  * @param   u32         The value to output.
    1138  * @param   cb          The value size in bytes.
     1122
     1123/* -=-=-=-=-=- I/O ports -=-=-=-=-=- */
     1124
     1125/**
     1126 * @callback_method_impl{FNIOMIOPORTOUT, PCI address}
    11391127 */
    11401128PDMBOTHCBDECL(int) pciIOPortAddressWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
     
    11561144
    11571145/**
    1158  * Port I/O Handler for PCI address IN operations.
    1159  *
    1160  * @returns VBox status code.
    1161  *
    1162  * @param   pDevIns     The device instance.
    1163  * @param   pvUser      User argument - ignored.
    1164  * @param   uPort       Port number used for the IN operation.
    1165  * @param   pu32        Where to store the result.
    1166  * @param   cb          Number of bytes read.
     1146 * @callback_method_impl{FNIOMIOPORTIN, PCI address}
    11671147 */
    11681148PDMBOTHCBDECL(int) pciIOPortAddressRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
     
    11861166
    11871167/**
    1188  * Port I/O Handler for PCI data OUT operations.
    1189  *
    1190  * @returns VBox status code.
    1191  *
    1192  * @param   pDevIns     The device instance.
    1193  * @param   pvUser      User argument - ignored.
    1194  * @param   uPort       Port number used for the IN operation.
    1195  * @param   u32         The value to output.
    1196  * @param   cb          The value size in bytes.
     1168 * @callback_method_impl{FNIOMIOPORTOUT, PCI data}
    11971169 */
    11981170PDMBOTHCBDECL(int) pciIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
     
    12141186
    12151187/**
    1216  * Port I/O Handler for PCI data IN operations.
    1217  *
    1218  * @returns VBox status code.
    1219  *
    1220  * @param   pDevIns     The device instance.
    1221  * @param   pvUser      User argument - ignored.
    1222  * @param   uPort       Port number used for the IN operation.
    1223  * @param   pu32        Where to store the result.
    1224  * @param   cb          Number of bytes read.
     1188 * @callback_method_impl{FNIOMIOPORTIN, PCI data}
    12251189 */
    12261190PDMBOTHCBDECL(int) pciIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
     
    12411205#ifdef IN_RING3
    12421206
     1207/* -=-=-=-=-=- Saved state -=-=-=-=-=- */
     1208
    12431209/**
    12441210 * Common worker for pciR3SaveExec and pcibridgeR3SaveExec.
     
    12711237
    12721238/**
    1273  * Saves a state of the PCI device.
    1274  *
    1275  * @returns VBox status code.
    1276  * @param   pDevIns     The device instance.
    1277  * @param   pPciDev     Pointer to PCI device.
    1278  * @param   pSSM  The handle to save the state to.
     1239 * @callback_method_impl{FNSSMDEVSAVEEXEC}
    12791240 */
    12801241static DECLCALLBACK(int) pciR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     
    15931554
    15941555/**
    1595  * Loads a saved PCI device state.
    1596  *
    1597  * @returns VBox status code.
    1598  * @param   pDevIns     The device instance.
    1599  * @param   pSSM        The handle to the saved state.
    1600  * @param   uVersion    The data unit version number.
    1601  * @param   uPass       The data pass.
     1556 * @callback_method_impl{FNSSMDEVLOADEXEC}
    16021557 */
    16031558static DECLCALLBACK(int) pciR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
     
    16481603
    16491604
    1650 /* -=-=-=-=-=- real code -=-=-=-=-=- */
     1605/* -=-=-=-=-=- PCI Bus Interface Methods (PDMPCIBUSREG) -=-=-=-=-=- */
    16511606
    16521607/**
     
    17911746
    17921747/**
    1793  * Registers the device with the default PCI bus.
    1794  *
    1795  * @returns VBox status code.
    1796  * @param   pDevIns         Device instance of the PCI Bus.
    1797  * @param   pPciDev         The PCI device structure.
    1798  *                          Any PCI enabled device must keep this in it's instance data!
    1799  *                          Fill in the PCI data config before registration, please.
    1800  * @param   pszName         Pointer to device name (permanent, readonly). For debugging, not unique.
    1801  * @param   iDev            The PCI device number. Use a negative value for auto assigning one.
     1748 * @interface_method_impl{PDMPCIBUSREG,pfnRegister}
    18021749 */
    18031750static DECLCALLBACK(int) pciR3Register(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev)
     
    18241771
    18251772
     1773/**
     1774 * @interface_method_impl{PDMPCIBUSREG,pfnIORegionRegisterR3}
     1775 */
    18261776static DECLCALLBACK(int) pciR3CommonIORegionRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion,
    18271777                                                     PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
     
    18661816
    18671817/**
    1868  * @copydoc PDMPCIBUSREG::pfnSetConfigCallbacksR3
    1869  */
    1870 static DECLCALLBACK(void) pciR3CommonSetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
    1871                                                         PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
     1818 * @interface_method_impl{PDMPCIBUSREG,pfnSetConfigCallbacksR3}
     1819 */
     1820static DECLCALLBACK(void)
     1821pciR3CommonSetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
     1822                              PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
    18721823{
    18731824    NOREF(pDevIns);
     
    18841835
    18851836/**
    1886  * Called to perform the job of the bios.
    1887  *
    1888  * @returns VBox status.
    1889  * @param   pDevIns     Device instance of the first bus.
     1837 * @interface_method_impl{PDMPCIBUSREG,pfnFakePCIBIOSR3}
    18901838 */
    18911839static DECLCALLBACK(int) pciR3FakePCIBIOS(PPDMDEVINS pDevIns)
     
    19421890}
    19431891
    1944 /**
    1945  * Info handler, device version.
    1946  *
    1947  * @param   pDevIns     Device instance which registered the info.
    1948  * @param   pHlp        Callback functions for doing output.
    1949  * @param   pszArgs     Argument string. Optional and specific to the handler.
     1892
     1893/* -=-=-=-=-=- Debug Info Handlers -=-=-=-=-=- */
     1894
     1895/**
     1896 * @callback_method_impl{FNDBGFHANDLERDEV}
    19501897 */
    19511898static DECLCALLBACK(void) pciR3IrqInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
    19521899{
    19531900    PPCIGLOBALS pGlobals = PDMINS_2_DATA(pDevIns, PPCIGLOBALS);
    1954     uint16_t    router;
    1955     uint8_t     irq_map;
    1956     int         i;
    19571901    NOREF(pszArgs);
    19581902
    1959     router = pGlobals->PIIX3State.dev.devfn;
     1903    uint16_t router = pGlobals->PIIX3State.dev.devfn;
    19601904    pHlp->pfnPrintf(pHlp, "PCI interrupt router at: %02X:%02X:%X\n",
    19611905                    router >> 8, (router >> 3) & 0x1f, router & 0x7);
    19621906
    1963     for (i = 0; i < 4; ++i)
    1964     {
    1965         irq_map = pci_config_readb(pGlobals, 0, router, 0x60 + i);
     1907    for (int i = 0; i < 4; ++i)
     1908    {
     1909        uint8_t irq_map = pci_config_readb(pGlobals, 0, router, 0x60 + i);
    19661910        if (irq_map & 0x80)
    19671911            pHlp->pfnPrintf(pHlp, "PIRQ%c disabled\n", 'A' + i);
     
    19711915}
    19721916
     1917/**
     1918 * Outputs indent.
     1919 *
     1920 * @param   pHlp        Output helpers.
     1921 * @param   iIndent     Indentation level.
     1922 */
    19731923static void pciR3PrintIndent(PCDBGFINFOHLP pHlp, int iIndent)
    19741924{
     
    19771927}
    19781928
     1929/**
     1930 * Recursive worker for pciR3Info.
     1931 *
     1932 * @param   pBus        The bus to display.
     1933 * @param   pHlp        Output helpers.
     1934 * @param   iIndent     Indentation level.
     1935 * @param   fRegisters  Whether to also display the PCI configuration registers
     1936 *                      of each device on the bus.
     1937 */
    19791938static void pciR3BusInfo(PPCIBUS pBus, PCDBGFINFOHLP pHlp, int iIndent, bool fRegisters)
    19801939{
     
    20812040}
    20822041
    2083 /**
    2084  * Info handler, device version.
    2085  *
    2086  * @param   pDevIns     Device instance which registered the info.
    2087  * @param   pHlp        Callback functions for doing output.
    2088  * @param   pszArgs     Argument string. Optional and specific to the handler.
     2042
     2043/**
     2044 * @callback_method_impl{FNDBGFHANDLERDEV}
    20892045 */
    20902046static DECLCALLBACK(void) pciR3Info(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
     
    21002056}
    21012057
    2102 /**
    2103  * @copydoc FNPDMDEVRELOCATE
     2058
     2059/* -=-=-=-=-=- PDMDEVREG  -=-=-=-=-=- */
     2060
     2061/**
     2062 * @interface_method_impl{PDMDEVREG,pfnRelocate}
    21042063 */
    21052064static DECLCALLBACK(void) pciR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
     
    21222081
    21232082/**
    2124  * @copydoc FNPDMDEVRESET
     2083 * @interface_method_impl{PDMDEVREG,pfnReset}
    21252084 */
    21262085static DECLCALLBACK(void) pciR3Reset(PPDMDEVINS pDevIns)
     
    21282087    pciR3FakePCIBIOS(pDevIns);
    21292088}
     2089
    21302090
    21312091/**
     
    23432303
    23442304
    2345 /**
    2346  * Set the IRQ for a PCI device on a secondary bus.
    2347  *
    2348  * @param   pDevIns         Device instance of the PCI Bus.
    2349  * @param   pPciDev         The PCI device structure.
    2350  * @param   iIrq            IRQ number to set.
    2351  * @param   iLevel          IRQ level.
    2352  * @param   uTagSrc         The IRQ tag and source ID (for tracing).
     2305
     2306/* -=-=-=-=-=- The PCI bridge specific bits -=-=-=-=-=- */
     2307
     2308/**
     2309 * @interface_method_impl{PDMPCIBUSREG,pfnSetIrq}
    23532310 */
    23542311PDMBOTHCBDECL(void) pcibridgeSetIrq(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel, uint32_t uTagSrc)
     
    23902347    PPCIBUS pBus = PDMINS_2_DATA(pDevIns, PPCIBUS);
    23912348
    2392     LogFlowFunc((": pDevIns=%p iBus=%d iDevice=%d u32Address=%u u32Value=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, u32Value, cb));
     2349    LogFlowFunc(("pDevIns=%p iBus=%d iDevice=%d u32Address=%u u32Value=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, u32Value, cb));
    23932350
    23942351    /* If the current bus is not the target bus search for the bus which contains the device. */
     
    24142371}
    24152372
     2373
    24162374/**
    24172375 * @callback_method_impl{FNPCIBRIDGECONFIGREAD}
     
    24222380    uint32_t u32Value = 0xffffffff; /* Return value in case there is no device. */
    24232381
    2424     LogFlowFunc((": pDevIns=%p iBus=%d iDevice=%d u32Address=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, cb));
     2382    LogFlowFunc(("pDevIns=%p iBus=%d iDevice=%d u32Address=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, cb));
    24252383
    24262384    /* If the current bus is not the target bus search for the bus which contains the device. */
     
    24502408
    24512409/**
    2452  * @copydoc FNSSMDEVSAVEEXEC
     2410 * @callback_method_impl{FNSSMDEVSAVEEXEC}
    24532411 */
    24542412static DECLCALLBACK(int) pcibridgeR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     
    24602418
    24612419/**
    2462  * @copydoc FNSSMDEVLOADEXEC
     2420 * @callback_method_impl{FNSSMDEVLOADEXEC}
    24632421 */
    24642422static DECLCALLBACK(int) pcibridgeR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
     
    24722430
    24732431/**
    2474  * Registers the device with the default PCI bus.
    2475  *
    2476  * @returns VBox status code.
    2477  * @param   pDevIns         Device instance of the PCI Bus.
    2478  * @param   pPciDev         The PCI device structure.
    2479  *                          Any PCI enabled device must keep this in it's instance data!
    2480  *                          Fill in the PCI data config before registration, please.
    2481  * @param   pszName         Pointer to device name (permanent, readonly). For debugging, not unique.
    2482  * @param   iDev            The PCI device number. Use a negative value for auto assigning one.
     2432 * @interface_method_impl{PDMPCIBUSREG,pfnRegister}
    24832433 */
    24842434static DECLCALLBACK(int) pcibridgeR3RegisterDevice(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev)
     
    25052455
    25062456/**
    2507  * @copydoc FNPDMDEVRESET
     2457 * @interface_method_impl{PDMDEVREG, pfnReset}
    25082458 */
    25092459static DECLCALLBACK(void) pcibridgeR3Reset(PPDMDEVINS pDevIns)
     
    25192469
    25202470/**
    2521  * @copydoc FNPDMDEVRELOCATE
     2471 * @interface_method_impl{PDMDEVREG, pfnRelocate}
    25222472 */
    25232473static DECLCALLBACK(void) pcibridgeR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
     
    26122562     * devices attached to the bus is unaffected.
    26132563     */
    2614     PCIDevSetInterruptPin (&pBus->PciDev, 0x00);
     2564    PCIDevSetInterruptPin(&pBus->PciDev, 0x00);
    26152565
    26162566    pBus->PciDev.pDevIns                    = pDevIns;
     
    26242574     * Register this PCI bridge. The called function will take care on which bus we will get registered.
    26252575     */
    2626     rc = PDMDevHlpPCIRegister (pDevIns, &pBus->PciDev);
     2576    rc = PDMDevHlpPCIRegister(pDevIns, &pBus->PciDev);
    26272577    if (RT_FAILURE(rc))
    26282578        return rc;
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