summaryrefslogtreecommitdiff
path: root/src/VBox/Devices
diff options
context:
space:
mode:
authorvboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2016-10-25 14:12:19 +0000
committervboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2016-10-25 14:12:19 +0000
commit3a119d0c807a762c083a429c7334786eb9aa5b9d (patch)
tree9a0152960b1849ada3b8a87cf6f058c63c34561e /src/VBox/Devices
parent33c90f5905aa8d0b066c152d7951fb4b52334bb6 (diff)
downloadVirtualBox-svn-3a119d0c807a762c083a429c7334786eb9aa5b9d.tar.gz
DevPCI: Moved ICH9PCIBUS to a common header (DevPciInternal.h) and use that for both PCI bus implementations.
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@64414 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/Devices')
-rw-r--r--src/VBox/Devices/Bus/DevPCI.cpp192
-rw-r--r--src/VBox/Devices/Bus/DevPciIch9.cpp179
-rw-r--r--src/VBox/Devices/Bus/DevPciInternal.h72
-rw-r--r--src/VBox/Devices/Bus/DevPciMerge1.cpp.h8
-rw-r--r--src/VBox/Devices/testcase/tstDeviceStructSize.cpp3
-rw-r--r--src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp61
6 files changed, 257 insertions, 258 deletions
diff --git a/src/VBox/Devices/Bus/DevPCI.cpp b/src/VBox/Devices/Bus/DevPCI.cpp
index e9eeeb3d4ac..7c62e2cd162 100644
--- a/src/VBox/Devices/Bus/DevPCI.cpp
+++ b/src/VBox/Devices/Bus/DevPCI.cpp
@@ -1,6 +1,15 @@
/* $Id$ */
/** @file
* DevPCI - PCI BUS Device.
+ *
+ * @remarks New code is currently added to DevPciMerge1.cpp.h, the goal is
+ * to end up with a large common code base for the two PCI bus
+ * implementations. The merge file will soon be compiled separately
+ * and not included, so it shall not be used as a template with
+ * \#ifdefs for different PCI bus configs, but rather use config
+ * flags in the structures to select paths & feature sets.
+ *
+ * When moving code, always prefer the ICH9 version, not this!
*/
/*
@@ -55,11 +64,16 @@
#include "PciInline.h"
#include "VBoxDD.h"
+#include "DevPciInternal.h"
/*********************************************************************************************************************************
* Structures and Typedefs *
*********************************************************************************************************************************/
+typedef DEVPCIBUS PCIBUS;
+typedef PDEVPCIBUS PPCIBUS;
+
+
/**
* PIIX3 ISA Bridge state.
*/
@@ -69,53 +83,6 @@ typedef struct PIIX3State
PDMPCIDEV dev;
} PIIX3State, PIIX3, *PPIIX3;
-/**
- * PCI Bus instance.
- */
-typedef struct PCIBus
-{
- /** Bus number. */
- int32_t iBus;
- /** Start device number. */
- uint32_t iDevSearch;
- /** Number of bridges attached to the bus. */
- uint32_t cBridges;
-
- uint32_t Alignment0;
-
- union
- {
- /** Array of PCI devices. */
- R3PTRTYPE(PPDMPCIDEV) apDevices[256];
- /** @deprecated */
- R3PTRTYPE(PPDMPCIDEV) devices[256];
- };
- /** Array of bridges attached to the bus. */
- R3PTRTYPE(PPDMPCIDEV *) papBridgesR3;
-
- /** R3 pointer to the device instance. */
- PPDMDEVINSR3 pDevInsR3;
- /** Pointer to the PCI R3 helpers. */
- PCPDMPCIHLPR3 pPciHlpR3;
-
- /** R0 pointer to the device instance. */
- PPDMDEVINSR0 pDevInsR0;
- /** Pointer to the PCI R0 helpers. */
- PCPDMPCIHLPR0 pPciHlpR0;
-
- /** RC pointer to the device instance. */
- PPDMDEVINSRC pDevInsRC;
- /** Pointer to the PCI RC helpers. */
- PCPDMPCIHLPRC pPciHlpRC;
-
- /** The PCI device for the PCI bridge. */
- PDMPCIDEV PciDev;
-
-} PCIBUS;
-/** Pointer to a PCIBUS instance. */
-typedef PCIBUS *PPCIBUS;
-typedef PCIBUS PCIBus;
-
/** @def PCI_IRQ_PINS
* Number of pins for interrupts (PIRQ#0...PIRQ#3)
*/
@@ -132,30 +99,30 @@ typedef PCIBUS PCIBus;
typedef struct PCIGLOBALS
{
/** Irq levels for the four PCI Irqs.
- * These count how many devices asserted
- * the IRQ line. If greater 0 an IRQ is sent to the guest.
- * If it drops to 0 the IRQ is deasserted.
+ * These count how many devices asserted the IRQ line. If greater 0 an IRQ is
+ * sent to the guest. If it drops to 0 the IRQ is deasserted.
*/
volatile uint32_t pci_irq_levels[PCI_IRQ_PINS];
-#if 1 /* Will be moved into the BIOS soon. */
+#if 1 /* Will be moved into the BIOS "soon". */
/** The next I/O port address which the PCI BIOS will use. */
- uint32_t pci_bios_io_addr;
+ uint32_t uPciBiosIo;
/** The next MMIO address which the PCI BIOS will use. */
- uint32_t pci_bios_mem_addr;
+ uint32_t uPciBiosMmio;
/** Actual bus number. */
uint8_t uBus;
+ uint8_t uAlignment0[2];
#endif
/** I/O APIC usage flag */
bool fUseIoApic;
/** I/O APIC irq levels */
- volatile uint32_t pci_apic_irq_levels[PCI_APIC_IRQ_PINS];
+ volatile uint32_t uaPciApicIrqLevels[PCI_APIC_IRQ_PINS];
/** ACPI IRQ level */
uint32_t acpi_irq_level;
/** ACPI PIC IRQ */
int acpi_irq;
- /** Config register. */
+ /** Value latched in Configuration Address Port (0CF8h) */
uint32_t uConfigReg;
/** R3 pointer to the device instance. */
@@ -172,7 +139,7 @@ typedef struct PCIGLOBALS
/** ISA bridge state. */
PIIX3 PIIX3State;
/** PCI bus which is attached to the host-to-PCI bridge. */
- PCIBUS PciBus;
+ DEVPCIBUS PciBus;
} PCIGLOBALS;
/** Pointer to per VM data. */
@@ -187,7 +154,7 @@ typedef PCIGLOBALS *PPCIGLOBALS;
#define PCIBUS_2_DEVINS(pPciBus) ((pPciBus)->CTX_SUFF(pDevIns))
/** Converts a PCI bus device instance pointer to a PCIGLOBALS pointer. */
#define DEVINS_2_PCIGLOBALS(pDevIns) ((PPCIGLOBALS)(PDMINS_2_DATA(pDevIns, PPCIGLOBALS)))
-/** Converts a PCI bus device instance pointer to a PCIBUS pointer. */
+/** Converts a PCI bus device instance pointer to a DEVPCIBUS pointer. */
#define DEVINS_2_PCIBUS(pDevIns) ((PPCIBUS)(&PDMINS_2_DATA(pDevIns, PPCIGLOBALS)->PciBus))
/** Converts a pointer to a PCI bus instance to a PCIGLOBALS pointer.
@@ -528,7 +495,7 @@ static int pci_data_write(PPCIGLOBALS pGlobals, uint32_t addr, uint32_t val, int
}
else
{
- R3PTRTYPE(PDMPCIDEV *) pci_dev = pGlobals->PciBus.devices[iDevice];
+ R3PTRTYPE(PDMPCIDEV *) pci_dev = pGlobals->PciBus.apDevices[iDevice];
if (pci_dev)
{
#ifdef IN_RING3
@@ -575,7 +542,7 @@ static int pci_data_read(PPCIGLOBALS pGlobals, uint32_t addr, int len, uint32_t
}
else
{
- R3PTRTYPE(PDMPCIDEV *) pci_dev = pGlobals->PciBus.devices[iDevice];
+ R3PTRTYPE(PDMPCIDEV *) pci_dev = pGlobals->PciBus.apDevices[iDevice];
if (pci_dev)
{
#ifdef IN_RING3
@@ -611,7 +578,7 @@ static inline int pci_slot_get_apic_pirq(uint8_t uDevFn, int irq_num)
static inline int get_pci_irq_apic_level(PPCIGLOBALS pGlobals, int irq_num)
{
- return (pGlobals->pci_apic_irq_levels[irq_num] != 0);
+ return (pGlobals->uaPciApicIrqLevels[irq_num] != 0);
}
static void apic_set_irq(PPCIBUS pBus, uint8_t uDevFn, PDMPCIDEV *pPciDev, int irq_num1, int iLevel, int acpi_irq, uint32_t uTagSrc)
@@ -625,9 +592,9 @@ static void apic_set_irq(PPCIBUS pBus, uint8_t uDevFn, PDMPCIDEV *pPciDev, int i
int irq_num = pci_slot_get_apic_pirq(uDevFn, irq_num1);
if ((iLevel & PDM_IRQ_LEVEL_HIGH) == PDM_IRQ_LEVEL_HIGH)
- ASMAtomicIncU32(&pGlobals->pci_apic_irq_levels[irq_num]);
+ ASMAtomicIncU32(&pGlobals->uaPciApicIrqLevels[irq_num]);
else if ((iLevel & PDM_IRQ_LEVEL_HIGH) == PDM_IRQ_LEVEL_LOW)
- ASMAtomicDecU32(&pGlobals->pci_apic_irq_levels[irq_num]);
+ ASMAtomicDecU32(&pGlobals->uaPciApicIrqLevels[irq_num]);
apic_irq = irq_num + 0x10;
apic_level = get_pci_irq_apic_level(pGlobals, irq_num);
@@ -636,7 +603,7 @@ static void apic_set_irq(PPCIBUS pBus, uint8_t uDevFn, PDMPCIDEV *pPciDev, int i
pBus->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), apic_irq, apic_level, uTagSrc);
if ((iLevel & PDM_IRQ_LEVEL_FLIP_FLOP) == PDM_IRQ_LEVEL_FLIP_FLOP) {
- ASMAtomicDecU32(&pGlobals->pci_apic_irq_levels[irq_num]);
+ ASMAtomicDecU32(&pGlobals->uaPciApicIrqLevels[irq_num]);
pPciDev->Int.s.uIrqPinState = PDM_IRQ_LEVEL_LOW;
apic_level = get_pci_irq_apic_level(pGlobals, irq_num);
Log3(("apic_set_irq: %s: irq_num1=%d level=%d apic_irq=%d apic_level=%d irq_num1=%d (flop)\n",
@@ -997,20 +964,20 @@ static void pci_bios_init_device(PPCIGLOBALS pGlobals, uint8_t uBus, uint8_t uDe
* This does not change anything really as the access to the device is not going
* through the bridge but we want to be compliant to the spec.
*/
- if ((pGlobals->pci_bios_io_addr % 4096) != 0)
- pGlobals->pci_bios_io_addr = RT_ALIGN_32(pGlobals->pci_bios_io_addr, 4*1024);
- Log(("%s: Aligned I/O start address. New address %#x\n", __FUNCTION__, pGlobals->pci_bios_io_addr));
- pci_config_writeb(pGlobals, uBus, uDevFn, VBOX_PCI_IO_BASE, (pGlobals->pci_bios_io_addr >> 8) & 0xf0);
+ if ((pGlobals->uPciBiosIo % 4096) != 0)
+ pGlobals->uPciBiosIo = RT_ALIGN_32(pGlobals->uPciBiosIo, 4*1024);
+ Log(("%s: Aligned I/O start address. New address %#x\n", __FUNCTION__, pGlobals->uPciBiosIo));
+ pci_config_writeb(pGlobals, uBus, uDevFn, VBOX_PCI_IO_BASE, (pGlobals->uPciBiosIo >> 8) & 0xf0);
/* The MMIO range for the bridge must be aligned to a 1MB boundary. */
- if ((pGlobals->pci_bios_mem_addr % (1024 * 1024)) != 0)
- pGlobals->pci_bios_mem_addr = RT_ALIGN_32(pGlobals->pci_bios_mem_addr, 1024*1024);
- Log(("%s: Aligned MMIO start address. New address %#x\n", __FUNCTION__, pGlobals->pci_bios_mem_addr));
- pci_config_writew(pGlobals, uBus, uDevFn, VBOX_PCI_MEMORY_BASE, (pGlobals->pci_bios_mem_addr >> 16) & UINT32_C(0xffff0));
+ if ((pGlobals->uPciBiosMmio % (1024 * 1024)) != 0)
+ pGlobals->uPciBiosMmio = RT_ALIGN_32(pGlobals->uPciBiosMmio, 1024*1024);
+ Log(("%s: Aligned MMIO start address. New address %#x\n", __FUNCTION__, pGlobals->uPciBiosMmio));
+ pci_config_writew(pGlobals, uBus, uDevFn, VBOX_PCI_MEMORY_BASE, (pGlobals->uPciBiosMmio >> 16) & UINT32_C(0xffff0));
/* Save values to compare later to. */
- uint32_t u32IoAddressBase = pGlobals->pci_bios_io_addr;
- uint32_t u32MMIOAddressBase = pGlobals->pci_bios_mem_addr;
+ uint32_t u32IoAddressBase = pGlobals->uPciBiosIo;
+ uint32_t u32MMIOAddressBase = pGlobals->uPciBiosMmio;
/* Init devices behind the bridge and possibly other bridges as well. */
for (int iDev = 0; iDev <= 255; iDev++)
@@ -1025,20 +992,20 @@ static void pci_bios_init_device(PPCIGLOBALS pGlobals, uint8_t uBus, uint8_t uDe
* The result with a real bridge is that no I/O transactions are passed to the secondary
* interface. Again this doesn't really matter here but we want to be compliant to the spec.
*/
- if ((u32IoAddressBase != pGlobals->pci_bios_io_addr) && ((pGlobals->pci_bios_io_addr % 4096) != 0))
+ if ((u32IoAddressBase != pGlobals->uPciBiosIo) && ((pGlobals->uPciBiosIo % 4096) != 0))
{
/* The upper boundary must be one byte less than a 4KB boundary. */
- pGlobals->pci_bios_io_addr = RT_ALIGN_32(pGlobals->pci_bios_io_addr, 4*1024);
+ pGlobals->uPciBiosIo = RT_ALIGN_32(pGlobals->uPciBiosIo, 4*1024);
}
- pci_config_writeb(pGlobals, uBus, uDevFn, VBOX_PCI_IO_LIMIT, ((pGlobals->pci_bios_io_addr >> 8) & 0xf0) - 1);
+ pci_config_writeb(pGlobals, uBus, uDevFn, VBOX_PCI_IO_LIMIT, ((pGlobals->uPciBiosIo >> 8) & 0xf0) - 1);
/* Same with the MMIO limit register but with 1MB boundary here. */
- if ((u32MMIOAddressBase != pGlobals->pci_bios_mem_addr) && ((pGlobals->pci_bios_mem_addr % (1024 * 1024)) != 0))
+ if ((u32MMIOAddressBase != pGlobals->uPciBiosMmio) && ((pGlobals->uPciBiosMmio % (1024 * 1024)) != 0))
{
/* The upper boundary must be one byte less than a 1MB boundary. */
- pGlobals->pci_bios_mem_addr = RT_ALIGN_32(pGlobals->pci_bios_mem_addr, 1024*1024);
+ pGlobals->uPciBiosMmio = RT_ALIGN_32(pGlobals->uPciBiosMmio, 1024*1024);
}
- pci_config_writew(pGlobals, uBus, uDevFn, VBOX_PCI_MEMORY_LIMIT, ((pGlobals->pci_bios_mem_addr >> 16) & UINT32_C(0xfff0)) - 1);
+ pci_config_writew(pGlobals, uBus, uDevFn, VBOX_PCI_MEMORY_LIMIT, ((pGlobals->uPciBiosMmio >> 16) & UINT32_C(0xfff0)) - 1);
/*
* Set the prefetch base and limit registers. We currently have no device with a prefetchable region
@@ -1092,9 +1059,9 @@ static void pci_bios_init_device(PPCIGLOBALS pGlobals, uint8_t uBus, uint8_t uDe
if (u32Size)
{
if (fIsPio)
- paddr = &pGlobals->pci_bios_io_addr;
+ paddr = &pGlobals->uPciBiosIo;
else
- paddr = &pGlobals->pci_bios_mem_addr;
+ paddr = &pGlobals->uPciBiosMmio;
uint32_t uNew = *paddr;
uNew = (uNew + u32Size - 1) & ~(u32Size - 1);
if (fIsPio)
@@ -1248,7 +1215,6 @@ PDMBOTHCBDECL(int) pciIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT
* completely merge these files! File #1 contains code we write, where
* as a possible file #2 contains external code if there's any left.
*/
-typedef PPCIBUS PPCIMERGEDBUS;
# define pciR3UnmergedConfigReadDev pci_default_read_config
# define pciR3UnmergedConfigWriteDev pci_default_write_config
# include "DevPciMerge1.cpp.h"
@@ -1268,9 +1234,9 @@ static int pciR3CommonSaveExec(PPCIBUS pBus, PSSMHANDLE pSSM)
/*
* Iterate thru all the devices.
*/
- for (uint32_t i = 0; i < RT_ELEMENTS(pBus->devices); i++)
+ for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
{
- PPDMPCIDEV pDev = pBus->devices[i];
+ PPDMPCIDEV pDev = pBus->apDevices[i];
if (pDev)
{
SSMR3PutU32(pSSM, i);
@@ -1305,7 +1271,7 @@ static DECLCALLBACK(int) pciR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
for (i = 0; i < PCI_IRQ_PINS; i++)
SSMR3PutU32(pSSM, pThis->pci_irq_levels[i]);
for (i = 0; i < PCI_APIC_IRQ_PINS; i++)
- SSMR3PutU32(pSSM, pThis->pci_apic_irq_levels[i]);
+ SSMR3PutU32(pSSM, pThis->uaPciApicIrqLevels[i]);
SSMR3PutU32(pSSM, pThis->acpi_irq_level);
SSMR3PutS32(pSSM, pThis->acpi_irq);
@@ -1510,9 +1476,9 @@ static DECLCALLBACK(int) pciR3CommonLoadExec(PPCIBUS pBus, PSSMHANDLE pSSM, uint
* The register value is restored afterwards so we can do proper
* LogRels in pciR3CommonRestoreConfig.
*/
- for (i = 0; i < RT_ELEMENTS(pBus->devices); i++)
+ for (i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
{
- PPDMPCIDEV pDev = pBus->devices[i];
+ PPDMPCIDEV pDev = pBus->apDevices[i];
if (pDev)
{
uint16_t u16 = PCIDevGetCommand(pDev);
@@ -1536,7 +1502,7 @@ static DECLCALLBACK(int) pciR3CommonLoadExec(PPCIBUS pBus, PSSMHANDLE pSSM, uint
return rc;
if (u32 == (uint32_t)~0)
break;
- if ( u32 >= RT_ELEMENTS(pBus->devices)
+ if ( u32 >= RT_ELEMENTS(pBus->apDevices)
|| u32 < i)
{
AssertMsgFailed(("u32=%#x i=%#x\n", u32, i));
@@ -1546,13 +1512,13 @@ static DECLCALLBACK(int) pciR3CommonLoadExec(PPCIBUS pBus, PSSMHANDLE pSSM, uint
/* skip forward to the device checking that no new devices are present. */
for (; i < u32; i++)
{
- if (pBus->devices[i])
+ if (pBus->apDevices[i])
{
- LogRel(("PCI: New device in slot %#x, %s (vendor=%#06x device=%#06x)\n", i, pBus->devices[i]->pszNameR3,
- PCIDevGetVendorId(pBus->devices[i]), PCIDevGetDeviceId(pBus->devices[i])));
+ LogRel(("PCI: New device in slot %#x, %s (vendor=%#06x device=%#06x)\n", i, pBus->apDevices[i]->pszNameR3,
+ PCIDevGetVendorId(pBus->apDevices[i]), PCIDevGetDeviceId(pBus->apDevices[i])));
if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("New device in slot %#x, %s (vendor=%#06x device=%#06x)"),
- i, pBus->devices[i]->pszNameR3, PCIDevGetVendorId(pBus->devices[i]), PCIDevGetDeviceId(pBus->devices[i]));
+ i, pBus->apDevices[i]->pszNameR3, PCIDevGetVendorId(pBus->apDevices[i]), PCIDevGetDeviceId(pBus->apDevices[i]));
}
}
@@ -1575,7 +1541,7 @@ static DECLCALLBACK(int) pciR3CommonLoadExec(PPCIBUS pBus, PSSMHANDLE pSSM, uint
}
/* check that it's still around. */
- pDev = pBus->devices[i];
+ pDev = pBus->apDevices[i];
if (!pDev)
{
LogRel(("PCI: Device in slot %#x has been removed! vendor=%#06x device=%#06x\n", i,
@@ -1632,7 +1598,7 @@ static DECLCALLBACK(int) pciR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint
for (uint8_t i = 0; i < PCI_IRQ_PINS; i++)
SSMR3GetU32(pSSM, (uint32_t *)&pThis->pci_irq_levels[i]);
for (uint8_t i = 0; i < PCI_APIC_IRQ_PINS; i++)
- SSMR3GetU32(pSSM, (uint32_t *)&pThis->pci_apic_irq_levels[i]);
+ SSMR3GetU32(pSSM, (uint32_t *)&pThis->uaPciApicIrqLevels[i]);
SSMR3GetU32(pSSM, &pThis->acpi_irq_level);
SSMR3GetS32(pSSM, &pThis->acpi_irq);
@@ -1735,8 +1701,8 @@ static DECLCALLBACK(int) pciR3FakePCIBIOS(PPDMDEVINS pDevIns)
/*
* Set the start addresses.
*/
- pGlobals->pci_bios_io_addr = 0xd000;
- pGlobals->pci_bios_mem_addr = UINT32_C(0xf0000000);
+ pGlobals->uPciBiosIo = 0xd000;
+ pGlobals->uPciBiosMmio = UINT32_C(0xf0000000);
pGlobals->uBus = 0;
/*
@@ -1813,7 +1779,7 @@ static DECLCALLBACK(void) pciR3IrqInfo(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, c
pHlp->pfnPrintf(pHlp, "PCI I/O APIC IRQ levels:\n");
for (int i = 0; i < PCI_APIC_IRQ_PINS; ++i)
{
- pHlp->pfnPrintf(pHlp, " IRQ%02d: %u\n", 0x10 + i, pGlobals->pci_apic_irq_levels[i]);
+ pHlp->pfnPrintf(pHlp, " IRQ%02d: %u\n", 0x10 + i, pGlobals->uaPciApicIrqLevels[i]);
}
}
@@ -1840,9 +1806,9 @@ static void pciR3PrintIndent(PCDBGFINFOHLP pHlp, int iIndent)
*/
static void pciR3BusInfo(PPCIBUS pBus, PCDBGFINFOHLP pHlp, int iIndent, bool fRegisters)
{
- for (uint32_t iDev = 0; iDev < RT_ELEMENTS(pBus->devices); iDev++)
+ for (uint32_t iDev = 0; iDev < RT_ELEMENTS(pBus->apDevices); iDev++)
{
- PPDMPCIDEV pPciDev = pBus->devices[iDev];
+ PPDMPCIDEV pPciDev = pBus->apDevices[iDev];
if (pPciDev != NULL)
{
pciR3PrintIndent(pHlp, iIndent);
@@ -1977,10 +1943,10 @@ static DECLCALLBACK(void) pciR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
pBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
/* Relocate RC pointers for the attached pci devices. */
- for (uint32_t i = 0; i < RT_ELEMENTS(pBus->devices); i++)
+ for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
{
- if (pBus->devices[i])
- pBus->devices[i]->Int.s.pBusRC += offDelta;
+ if (pBus->apDevices[i])
+ pBus->apDevices[i]->Int.s.pBusRC += offDelta;
}
}
@@ -2035,11 +2001,11 @@ static DECLCALLBACK(int) pciR3Construct(PPDMDEVINS pDevIns, int iInstance, PCF
* Init data and register the PCI bus.
*/
PPCIGLOBALS pGlobals = PDMINS_2_DATA(pDevIns, PPCIGLOBALS);
- pGlobals->pci_bios_io_addr = 0xc000;
- pGlobals->pci_bios_mem_addr = 0xf0000000;
+ pGlobals->uPciBiosIo = 0xc000;
+ pGlobals->uPciBiosMmio = 0xf0000000;
memset((void *)&pGlobals->pci_irq_levels, 0, sizeof(pGlobals->pci_irq_levels));
pGlobals->fUseIoApic = fUseIoApic;
- memset((void *)&pGlobals->pci_apic_irq_levels, 0, sizeof(pGlobals->pci_apic_irq_levels));
+ memset((void *)&pGlobals->uaPciApicIrqLevels, 0, sizeof(pGlobals->uaPciApicIrqLevels));
pGlobals->pDevInsR3 = pDevIns;
pGlobals->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
@@ -2049,7 +2015,7 @@ static DECLCALLBACK(int) pciR3Construct(PPDMDEVINS pDevIns, int iInstance, PCF
pGlobals->PciBus.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
pGlobals->PciBus.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
pGlobals->PciBus.papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV)
- * RT_ELEMENTS(pGlobals->PciBus.devices));
+ * RT_ELEMENTS(pGlobals->PciBus.apDevices));
PDMPCIBUSREG PciBusReg;
PPCIBUS pBus = &pGlobals->PciBus;
@@ -2267,7 +2233,7 @@ static DECLCALLBACK(void) pcibridgeR3ConfigWrite(PPDMDEVINSR3 pDevIns, uint8_t i
else
{
/* This is the target bus, pass the write to the device. */
- PPDMPCIDEV pPciDev = pBus->devices[iDevice];
+ PPDMPCIDEV pPciDev = pBus->apDevices[iDevice];
if (pPciDev)
{
Log(("%s: %s: addr=%02x val=%08x len=%d\n", __FUNCTION__, pPciDev->pszNameR3, u32Address, u32Value, cb));
@@ -2300,7 +2266,7 @@ static DECLCALLBACK(uint32_t) pcibridgeR3ConfigRead(PPDMDEVINSR3 pDevIns, uint8_
else
{
/* This is the target bus, pass the read to the device. */
- PPDMPCIDEV pPciDev = pBus->devices[iDevice];
+ PPDMPCIDEV pPciDev = pBus->apDevices[iDevice];
if (pPciDev)
{
u32Value = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, cb);
@@ -2357,10 +2323,10 @@ static DECLCALLBACK(void) pcibridgeR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR off
pBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
/* Relocate RC pointers for the attached pci devices. */
- for (uint32_t i = 0; i < RT_ELEMENTS(pBus->devices); i++)
+ for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
{
- if (pBus->devices[i])
- pBus->devices[i]->Int.s.pBusRC += offDelta;
+ if (pBus->apDevices[i])
+ pBus->apDevices[i]->Int.s.pBusRC += offDelta;
}
}
@@ -2400,7 +2366,7 @@ static DECLCALLBACK(int) pcibridgeR3Construct(PPDMDEVINS pDevIns, int iInstanc
pBus->pDevInsR3 = pDevIns;
pBus->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
pBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
- pBus->papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV) * RT_ELEMENTS(pBus->devices));
+ pBus->papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV) * RT_ELEMENTS(pBus->apDevices));
PDMPCIBUSREG PciBusReg;
PciBusReg.u32Version = PDM_PCIBUSREG_VERSION;
@@ -2503,7 +2469,7 @@ const PDMDEVREG g_DevicePCIBridge =
/* cMaxInstances */
~0U,
/* cbInstance */
- sizeof(PCIBUS),
+ sizeof(DEVPCIBUS),
/* pfnConstruct */
pcibridgeR3Construct,
/* pfnDestruct */
diff --git a/src/VBox/Devices/Bus/DevPciIch9.cpp b/src/VBox/Devices/Bus/DevPciIch9.cpp
index 98dc895e5a1..a199ee3e33a 100644
--- a/src/VBox/Devices/Bus/DevPciIch9.cpp
+++ b/src/VBox/Devices/Bus/DevPciIch9.cpp
@@ -2,8 +2,14 @@
/** @file
* DevPCI - ICH9 southbridge PCI bus emulation device.
*
- * @note bird: I've cleaned up DevPCI.cpp to some extent, this file has not
- * be cleaned up and because of pending code merge.
+ * @remarks New code is currently added to DevPciMerge1.cpp.h, the goal is
+ * to end up with a large common code base for the two PCI bus
+ * implementations. The merge file will soon be compiled separately
+ * and not included, so it shall not be used as a template with
+ * \#ifdefs for different PCI bus configs, but rather use config
+ * flags in the structures to select paths & feature sets.
+ *
+ * When moving code, always prefer the ICH9 version (this file)!
*/
/*
@@ -23,7 +29,6 @@
* Header Files *
*********************************************************************************************************************************/
#define LOG_GROUP LOG_GROUP_DEV_PCI
-#define PCIBus ICH9PCIBus /**< HACK ALERT! Real ugly type hack! */
#define PDMPCIDEV_INCLUDE_PRIVATE /* Hack to get pdmpcidevint.h included at the right point. */
#include <VBox/vmm/pdmpcidev.h>
@@ -40,49 +45,14 @@
#include "PciInline.h"
#include "VBoxDD.h"
#include "MsiCommon.h"
+#include "DevPciInternal.h"
/*********************************************************************************************************************************
* Structures and Typedefs *
*********************************************************************************************************************************/
-/**
- * PCI Bus instance.
- */
-typedef struct ICH9PCIBus
-{
- /** Bus number. */
- int32_t iBus;
- /** Number of bridges attached to the bus. */
- uint32_t cBridges;
-
- /** Array of PCI devices. We assume 32 slots, each with 8 functions. */
- R3PTRTYPE(PPDMPCIDEV) apDevices[256];
- /** Array of bridges attached to the bus. */
- R3PTRTYPE(PPDMPCIDEV *) papBridgesR3;
-
- /** R3 pointer to the device instance. */
- PPDMDEVINSR3 pDevInsR3;
- /** Pointer to the PCI R3 helpers. */
- PCPDMPCIHLPR3 pPciHlpR3;
-
- /** R0 pointer to the device instance. */
- PPDMDEVINSR0 pDevInsR0;
- /** Pointer to the PCI R0 helpers. */
- PCPDMPCIHLPR0 pPciHlpR0;
-
- /** RC pointer to the device instance. */
- PPDMDEVINSRC pDevInsRC;
- /** Pointer to the PCI RC helpers. */
- PCPDMPCIHLPRC pPciHlpRC;
-
- /** The PCI device for the PCI bridge. */
- PDMPCIDEV aPciDev;
-
- /** Start device number - always zero (only for DevPCI source compat). */
- uint32_t iDevSearch;
- /** Size alignemnt padding. */
- uint32_t u32Alignment;
-} ICH9PCIBUS, *PICH9PCIBUS;
+typedef DEVPCIBUS ICH9PCIBUS;
+typedef PDEVPCIBUS PICH9PCIBUS;
/** @def PCI_APIC_IRQ_PINS
@@ -108,7 +78,7 @@ typedef struct
/** I/O APIC irq levels */
volatile uint32_t uaPciApicIrqLevels[PCI_APIC_IRQ_PINS];
-#if 1 /* Will be moved into the BIOS soon. */
+#if 1 /* Will be moved into the BIOS "soon". */
/** The next I/O port address which the PCI BIOS will use. */
uint32_t uPciBiosIo;
/** The next MMIO address which the PCI BIOS will use. */
@@ -125,7 +95,7 @@ typedef struct
uint64_t u64PciConfigMMioLength;
/** PCI bus which is attached to the host-to-PCI bridge. */
- ICH9PCIBUS aPciBus;
+ DEVPCIBUS PciBus;
} ICH9PCIGLOBALS, *PICH9PCIGLOBALS;
@@ -158,9 +128,9 @@ typedef struct
/** Converts a device instance pointer to a ICH9PCIGLOBALS pointer. */
#define DEVINS_2_PCIGLOBALS(pDevIns) ((PICH9PCIGLOBALS)(PDMINS_2_DATA(pDevIns, PICH9PCIGLOBALS)))
/** Converts a device instance pointer to a PCIBUS pointer. */
-#define DEVINS_2_PCIBUS(pDevIns) ((PICH9PCIBUS)(&PDMINS_2_DATA(pDevIns, PICH9PCIGLOBALS)->aPciBus))
+#define DEVINS_2_PCIBUS(pDevIns) ((PICH9PCIBUS)(&PDMINS_2_DATA(pDevIns, PICH9PCIGLOBALS)->PciBus))
/** Converts a pointer to a PCI root bus instance to a PCIGLOBALS pointer. */
-#define PCIROOTBUS_2_PCIGLOBALS(pPciBus) ( (PICH9PCIGLOBALS)((uintptr_t)(pPciBus) - RT_OFFSETOF(ICH9PCIGLOBALS, aPciBus)) )
+#define PCIROOTBUS_2_PCIGLOBALS(pPciBus) ( (PICH9PCIGLOBALS)((uintptr_t)(pPciBus) - RT_OFFSETOF(ICH9PCIGLOBALS, PciBus)) )
/** @def PCI_LOCK
* Acquires the PDM lock. This is a NOP if locking is disabled. */
@@ -227,12 +197,12 @@ PDMBOTHCBDECL(void) ich9pcibridgeSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
/* Walk the chain until we reach the host bus. */
do
{
- uDevFnBridge = pBus->aPciDev.uDevFn;
+ uDevFnBridge = pBus->PciDev.uDevFn;
iIrqPinBridge = ((pPciDevBus->uDevFn >> 3) + iIrqPinBridge) & 3;
/* Get the parent. */
- pBus = pBus->aPciDev.Int.s.CTX_SUFF(pBus);
- pPciDevBus = &pBus->aPciDev;
+ pBus = pBus->PciDev.Int.s.CTX_SUFF(pBus);
+ pPciDevBus = &pBus->PciDev;
} while (pBus->iBus != 0);
AssertMsgReturnVoid(pBus->iBus == 0, ("This is not the host pci bus iBus=%d\n", pBus->iBus));
@@ -326,10 +296,10 @@ static int ich9pciDataWriteAddr(PICH9PCIGLOBALS pGlobals, PciAddress* pAddr,
if (pAddr->iBus != 0) /* forward to subordinate bus */
{
- if (pGlobals->aPciBus.cBridges)
+ if (pGlobals->PciBus.cBridges)
{
#ifdef IN_RING3 /** @todo do lookup in R0/RC too! */
- PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(&pGlobals->aPciBus, pAddr->iBus);
+ PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(&pGlobals->PciBus, pAddr->iBus);
if (pBridgeDevice)
{
AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigWrite);
@@ -343,7 +313,7 @@ static int ich9pciDataWriteAddr(PICH9PCIGLOBALS pGlobals, PciAddress* pAddr,
}
else /* forward to directly connected device */
{
- R3PTRTYPE(PDMPCIDEV *) pPciDev = pGlobals->aPciBus.apDevices[pAddr->iDeviceFunc];
+ R3PTRTYPE(PDMPCIDEV *) pPciDev = pGlobals->PciBus.apDevices[pAddr->iDeviceFunc];
if (pPciDev)
{
#ifdef IN_RING3
@@ -439,10 +409,10 @@ static int ich9pciDataReadAddr(PICH9PCIGLOBALS pGlobals, PciAddress* pPciAddr, i
if (pPciAddr->iBus != 0) /* forward to subordinate bus */
{
- if (pGlobals->aPciBus.cBridges)
+ if (pGlobals->PciBus.cBridges)
{
#ifdef IN_RING3 /** @todo do lookup in R0/RC too! */
- PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(&pGlobals->aPciBus, pPciAddr->iBus);
+ PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(&pGlobals->PciBus, pPciAddr->iBus);
if (pBridgeDevice)
{
AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigRead);
@@ -460,7 +430,7 @@ static int ich9pciDataReadAddr(PICH9PCIGLOBALS pGlobals, PciAddress* pPciAddr, i
}
else /* forward to directly connected device */
{
- R3PTRTYPE(PDMPCIDEV *) pPciDev = pGlobals->aPciBus.apDevices[pPciAddr->iDeviceFunc];
+ R3PTRTYPE(PDMPCIDEV *) pPciDev = pGlobals->PciBus.apDevices[pPciAddr->iDeviceFunc];
if (pPciDev)
{
#ifdef IN_RING3
@@ -630,20 +600,20 @@ static void ich9pciSetIrqInternal(PICH9PCIGLOBALS pGlobals, uint8_t uDevFn, PPDM
{
Assert(!MsixIsEnabled(pPciDev)); /* Not allowed -- see note above. */
LogFlowFunc(("PCI Dev %p : MSI\n", pPciDev));
- PPDMDEVINS pDevIns = pGlobals->aPciBus.CTX_SUFF(pDevIns);
- MsiNotify(pDevIns, pGlobals->aPciBus.CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc);
+ PPDMDEVINS pDevIns = pGlobals->PciBus.CTX_SUFF(pDevIns);
+ MsiNotify(pDevIns, pGlobals->PciBus.CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc);
return;
}
if (MsixIsEnabled(pPciDev))
{
LogFlowFunc(("PCI Dev %p : MSI-X\n", pPciDev));
- PPDMDEVINS pDevIns = pGlobals->aPciBus.CTX_SUFF(pDevIns);
- MsixNotify(pDevIns, pGlobals->aPciBus.CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc);
+ PPDMDEVINS pDevIns = pGlobals->PciBus.CTX_SUFF(pDevIns);
+ MsixNotify(pDevIns, pGlobals->PciBus.CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc);
return;
}
- PICH9PCIBUS pBus = &pGlobals->aPciBus;
+ PICH9PCIBUS pBus = &pGlobals->PciBus;
const bool fIsAcpiDevice = PCIDevGetDeviceId(pPciDev) == 0x7113;
LogFlowFunc(("PCI Dev %p : IRQ\n", pPciDev));
@@ -783,7 +753,6 @@ PDMBOTHCBDECL(int) ich9pciMcfgMMIORead (PPDMDEVINS pDevIns, void *pvUser, RTGCPH
* completely merge these files! File #1 contains code we write, where
* as a possible file #2 contains external code if there's any left.
*/
-typedef PICH9PCIBUS PPCIMERGEDBUS;
# define pciR3UnmergedConfigReadDev ich9pciConfigReadDev
# define pciR3UnmergedConfigWriteDev ich9pciConfigWriteDev
# include "DevPciMerge1.cpp.h"
@@ -1120,7 +1089,7 @@ static DECLCALLBACK(int) ich9pciR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
SSMR3PutU32(pSSM, UINT32_MAX); /* separator */
- return ich9pciR3CommonSaveExec(&pThis->aPciBus, pSSM);
+ return ich9pciR3CommonSaveExec(&pThis->PciBus, pSSM);
}
@@ -1138,7 +1107,7 @@ static DECLCALLBACK(void) ich9pcibridgeConfigWrite(PPDMDEVINSR3 pDevIns, uint8_t
LogFlowFunc((": pDevIns=%p iBus=%d iDevice=%d u32Address=%u u32Value=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, u32Value, cb));
/* If the current bus is not the target bus search for the bus which contains the device. */
- if (iBus != PCIDevGetByte(&pBus->aPciDev, VBOX_PCI_SECONDARY_BUS))
+ if (iBus != PCIDevGetByte(&pBus->PciDev, VBOX_PCI_SECONDARY_BUS))
{
PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(pBus, iBus);
if (pBridgeDevice)
@@ -1168,7 +1137,7 @@ static DECLCALLBACK(uint32_t) ich9pcibridgeConfigRead(PPDMDEVINSR3 pDevIns, uint
LogFlowFunc((": pDevIns=%p iBus=%d iDevice=%d u32Address=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, cb));
/* If the current bus is not the target bus search for the bus which contains the device. */
- if (iBus != PCIDevGetByte(&pBus->aPciDev, VBOX_PCI_SECONDARY_BUS))
+ if (iBus != PCIDevGetByte(&pBus->PciDev, VBOX_PCI_SECONDARY_BUS))
{
PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(pBus, iBus);
if (pBridgeDevice)
@@ -1515,7 +1484,7 @@ static DECLCALLBACK(int) ich9pciR3CommonLoadExec(PICH9PCIBUS pBus, PSSMHANDLE pS
static DECLCALLBACK(int) ich9pciR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
{
PICH9PCIGLOBALS pThis = PDMINS_2_DATA(pDevIns, PICH9PCIGLOBALS);
- PICH9PCIBUS pBus = &pThis->aPciBus;
+ PICH9PCIBUS pBus = &pThis->PciBus;
uint32_t u32;
int rc;
@@ -1854,7 +1823,7 @@ static void ich9pciBiosInitDevice(PICH9PCIGLOBALS pGlobals, uint8_t uBus, uint8_
if (uBus != 0)
{
/* Find bus this device attached to. */
- PICH9PCIBUS pBus = &pGlobals->aPciBus;
+ PICH9PCIBUS pBus = &pGlobals->PciBus;
while (1)
{
PPDMPCIDEV pBridge = ich9pciFindBridge(pBus, uBus);
@@ -1877,8 +1846,8 @@ static void ich9pciBiosInitDevice(PICH9PCIGLOBALS pGlobals, uint8_t uBus, uint8_
while (pBus->iBus != 0)
{
/* Get the pin the device would assert on the bridge. */
- iPin = ((pBus->aPciDev.uDevFn >> 3) + iPin) & 3;
- pBus = pBus->aPciDev.Int.s.pBusR3;
+ iPin = ((pBus->PciDev.uDevFn >> 3) + iPin) & 3;
+ pBus = pBus->PciDev.Int.s.pBusR3;
};
}
@@ -1901,7 +1870,7 @@ static void ich9pciBiosInitDevice(PICH9PCIGLOBALS pGlobals, uint8_t uBus, uint8_
static void ich9pciInitBridgeTopology(PICH9PCIGLOBALS pGlobals, PICH9PCIBUS pBus, unsigned uBusPrimary,
unsigned uBusSecondary)
{
- PPDMPCIDEV pBridgeDev = &pBus->aPciDev;
+ PPDMPCIDEV pBridgeDev = &pBus->PciDev;
/* Set only if we are not on the root bus, it has no primary bus attached. */
if (uBusSecondary != 0)
@@ -1955,7 +1924,7 @@ static DECLCALLBACK(int) ich9pciFakePCIBIOS(PPDMDEVINS pDevIns)
/*
* Assign bridge topology, for further routing to work.
*/
- PICH9PCIBUS pBus = &pGlobals->aPciBus;
+ PICH9PCIBUS pBus = &pGlobals->PciBus;
ich9pciInitBridgeTopology(pGlobals, pBus, 0, 0);
/*
@@ -2430,7 +2399,7 @@ static DECLCALLBACK(int) ich9pciConstruct(PPDMDEVINS pDevIns, int iInstance, PCF
* Init data.
*/
PICH9PCIGLOBALS pGlobals = PDMINS_2_DATA(pDevIns, PICH9PCIGLOBALS);
- PICH9PCIBUS pBus = &pGlobals->aPciBus;
+ PICH9PCIBUS pBus = &pGlobals->PciBus;
/* Zero out everything */
memset(pGlobals, 0, sizeof(*pGlobals));
/* And fill values */
@@ -2450,10 +2419,10 @@ static DECLCALLBACK(int) ich9pciConstruct(PPDMDEVINS pDevIns, int iInstance, PCF
pGlobals->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
pGlobals->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
- pGlobals->aPciBus.pDevInsR3 = pDevIns;
- pGlobals->aPciBus.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
- pGlobals->aPciBus.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
- pGlobals->aPciBus.papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV) * RT_ELEMENTS(pGlobals->aPciBus.apDevices));
+ pGlobals->PciBus.pDevInsR3 = pDevIns;
+ pGlobals->PciBus.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
+ pGlobals->PciBus.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
+ pGlobals->PciBus.papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV) * RT_ELEMENTS(pGlobals->PciBus.apDevices));
/*
* Register bus
@@ -2490,18 +2459,18 @@ static DECLCALLBACK(int) ich9pciConstruct(PPDMDEVINS pDevIns, int iInstance, PCF
*/
#if 0
/* Host bridge device */
- PCIDevSetVendorId( &pBus->aPciDev, 0x8086); /* Intel */
- PCIDevSetDeviceId( &pBus->aPciDev, 0x29e0); /* Desktop */
- PCIDevSetRevisionId(&pBus->aPciDev, 0x01); /* rev. 01 */
- PCIDevSetClassBase( &pBus->aPciDev, 0x06); /* bridge */
- PCIDevSetClassSub( &pBus->aPciDev, 0x00); /* Host/PCI bridge */
- PCIDevSetClassProg( &pBus->aPciDev, 0x00); /* Host/PCI bridge */
- PCIDevSetHeaderType(&pBus->aPciDev, 0x00); /* bridge */
- PCIDevSetWord(&pBus->aPciDev, VBOX_PCI_SEC_STATUS, 0x0280); /* secondary status */
-
- pBus->aPciDev.pDevIns = pDevIns;
+ PCIDevSetVendorId( &pBus->PciDev, 0x8086); /* Intel */
+ PCIDevSetDeviceId( &pBus->PciDev, 0x29e0); /* Desktop */
+ PCIDevSetRevisionId(&pBus->PciDev, 0x01); /* rev. 01 */
+ PCIDevSetClassBase( &pBus->PciDev, 0x06); /* bridge */
+ PCIDevSetClassSub( &pBus->PciDev, 0x00); /* Host/PCI bridge */
+ PCIDevSetClassProg( &pBus->PciDev, 0x00); /* Host/PCI bridge */
+ PCIDevSetHeaderType(&pBus->PciDev, 0x00); /* bridge */
+ PCIDevSetWord(&pBus->PciDev, VBOX_PCI_SEC_STATUS, 0x0280); /* secondary status */
+
+ pBus->PciDev.pDevIns = pDevIns;
/* We register Host<->PCI controller on the bus */
- ich9pciRegisterInternal(pBus, 0, &pBus->aPciDev, "dram");
+ ich9pciRegisterInternal(pBus, 0, &pBus->PciDev, "dram");
#endif
/*
@@ -2629,7 +2598,7 @@ static void ich9pciResetDevice(PPDMPCIDEV pDev)
static DECLCALLBACK(void) ich9pciReset(PPDMDEVINS pDevIns)
{
PICH9PCIGLOBALS pGlobals = PDMINS_2_DATA(pDevIns, PICH9PCIGLOBALS);
- PICH9PCIBUS pBus = &pGlobals->aPciBus;
+ PICH9PCIBUS pBus = &pGlobals->PciBus;
/* PCI-specific reset for each device. */
for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
@@ -2663,7 +2632,7 @@ static void ich9pciRelocateDevice(PPDMPCIDEV pDev, RTGCINTPTR offDelta)
static DECLCALLBACK(void) ich9pciRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
{
PICH9PCIGLOBALS pGlobals = PDMINS_2_DATA(pDevIns, PICH9PCIGLOBALS);
- PICH9PCIBUS pBus = &pGlobals->aPciBus;
+ PICH9PCIBUS pBus = &pGlobals->PciBus;
pGlobals->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns);
@@ -2743,32 +2712,32 @@ static DECLCALLBACK(int) ich9pcibridgeConstruct(PPDMDEVINS pDevIns,
/*
* Fill in PCI configs and add them to the bus.
*/
- PCIDevSetVendorId( &pBus->aPciDev, 0x8086); /* Intel */
- PCIDevSetDeviceId( &pBus->aPciDev, 0x2448); /* 82801 Mobile PCI bridge. */
- PCIDevSetRevisionId(&pBus->aPciDev, 0xf2);
- PCIDevSetClassSub( &pBus->aPciDev, 0x04); /* pci2pci */
- PCIDevSetClassBase( &pBus->aPciDev, 0x06); /* PCI_bridge */
- PCIDevSetClassProg( &pBus->aPciDev, 0x01); /* Supports subtractive decoding. */
- PCIDevSetHeaderType(&pBus->aPciDev, 0x01); /* Single function device which adheres to the PCI-to-PCI bridge spec. */
- PCIDevSetCommand( &pBus->aPciDev, 0x00);
- PCIDevSetStatus( &pBus->aPciDev, 0x20); /* 66MHz Capable. */
- PCIDevSetInterruptLine(&pBus->aPciDev, 0x00); /* This device does not assert interrupts. */
+ PCIDevSetVendorId( &pBus->PciDev, 0x8086); /* Intel */
+ PCIDevSetDeviceId( &pBus->PciDev, 0x2448); /* 82801 Mobile PCI bridge. */
+ PCIDevSetRevisionId(&pBus->PciDev, 0xf2);
+ PCIDevSetClassSub( &pBus->PciDev, 0x04); /* pci2pci */
+ PCIDevSetClassBase( &pBus->PciDev, 0x06); /* PCI_bridge */
+ PCIDevSetClassProg( &pBus->PciDev, 0x01); /* Supports subtractive decoding. */
+ PCIDevSetHeaderType(&pBus->PciDev, 0x01); /* Single function device which adheres to the PCI-to-PCI bridge spec. */
+ PCIDevSetCommand( &pBus->PciDev, 0x00);
+ PCIDevSetStatus( &pBus->PciDev, 0x20); /* 66MHz Capable. */
+ PCIDevSetInterruptLine(&pBus->PciDev, 0x00); /* This device does not assert interrupts. */
/*
* This device does not generate interrupts. Interrupt delivery from
* devices attached to the bus is unaffected.
*/
- PCIDevSetInterruptPin (&pBus->aPciDev, 0x00);
+ PCIDevSetInterruptPin (&pBus->PciDev, 0x00);
/*
* Register this PCI bridge. The called function will take care on which bus we will get registered.
*/
- rc = PDMDevHlpPCIRegisterEx(pDevIns, &pBus->aPciDev, PDMPCIDEVREG_CFG_PRIMARY, PDMPCIDEVREG_F_PCI_BRIDGE,
+ rc = PDMDevHlpPCIRegisterEx(pDevIns, &pBus->PciDev, PDMPCIDEVREG_CFG_PRIMARY, PDMPCIDEVREG_F_PCI_BRIDGE,
PDMPCIDEVREG_DEV_NO_FIRST_UNUSED, PDMPCIDEVREG_FUN_NO_FIRST_UNUSED, "ich9pcibridge");
if (RT_FAILURE(rc))
return rc;
- pBus->aPciDev.Int.s.pfnBridgeConfigRead = ich9pcibridgeConfigRead;
- pBus->aPciDev.Int.s.pfnBridgeConfigWrite = ich9pcibridgeConfigWrite;
+ pBus->PciDev.Int.s.pfnBridgeConfigRead = ich9pcibridgeConfigRead;
+ pBus->PciDev.Int.s.pfnBridgeConfigWrite = ich9pcibridgeConfigWrite;
/*
* The iBus property doesn't really represent the bus number
@@ -2805,9 +2774,9 @@ static void ich9pcibridgeReset(PPDMDEVINS pDevIns)
PICH9PCIBUS pBus = PDMINS_2_DATA(pDevIns, PICH9PCIBUS);
/* Reset config space to default values. */
- PCIDevSetByte(&pBus->aPciDev, VBOX_PCI_PRIMARY_BUS, 0);
- PCIDevSetByte(&pBus->aPciDev, VBOX_PCI_SECONDARY_BUS, 0);
- PCIDevSetByte(&pBus->aPciDev, VBOX_PCI_SUBORDINATE_BUS, 0);
+ PCIDevSetByte(&pBus->PciDev, VBOX_PCI_PRIMARY_BUS, 0);
+ PCIDevSetByte(&pBus->PciDev, VBOX_PCI_SECONDARY_BUS, 0);
+ PCIDevSetByte(&pBus->PciDev, VBOX_PCI_SUBORDINATE_BUS, 0);
/* PCI-specific reset for each device. */
for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
@@ -2909,7 +2878,7 @@ const PDMDEVREG g_DevicePciIch9Bridge =
/* cMaxInstances */
~0U,
/* cbInstance */
- sizeof(ICH9PCIBUS),
+ sizeof(DEVPCIBUS),
/* pfnConstruct */
ich9pcibridgeConstruct,
/* pfnDestruct */
diff --git a/src/VBox/Devices/Bus/DevPciInternal.h b/src/VBox/Devices/Bus/DevPciInternal.h
new file mode 100644
index 00000000000..59b2822e1b6
--- /dev/null
+++ b/src/VBox/Devices/Bus/DevPciInternal.h
@@ -0,0 +1,72 @@
+/* $Id$ */
+/** @file
+ * DevPCI - Common Internal Header.
+ */
+
+/*
+ * Copyright (C) 2010-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+#ifndef ___Bus_DevPciInternal_h___
+#define ___Bus_DevPciInternal_h___
+
+#ifndef PDMPCIDEV_INCLUDE_PRIVATE
+# define PDMPCIDEV_INCLUDE_PRIVATE /* Hack to get pdmpcidevint.h included at the right point. */
+#endif
+#include <VBox/vmm/pdmdev.h>
+
+
+/**
+ * PCI bus instance (common to both).
+ */
+typedef struct DEVPCIBUS
+{
+ /** Bus number. */
+ int32_t iBus;
+ /** Number of bridges attached to the bus. */
+ uint32_t cBridges;
+ /** Start device number - always zero (only for DevPCI source compat). */
+ uint32_t iDevSearch;
+ /** Size alignemnt padding. */
+ uint32_t u32Alignment0;
+
+ /** R3 pointer to the device instance. */
+ PPDMDEVINSR3 pDevInsR3;
+ /** Pointer to the PCI R3 helpers. */
+ PCPDMPCIHLPR3 pPciHlpR3;
+
+ /** R0 pointer to the device instance. */
+ PPDMDEVINSR0 pDevInsR0;
+ /** Pointer to the PCI R0 helpers. */
+ PCPDMPCIHLPR0 pPciHlpR0;
+
+ /** RC pointer to the device instance. */
+ PPDMDEVINSRC pDevInsRC;
+ /** Pointer to the PCI RC helpers. */
+ PCPDMPCIHLPRC pPciHlpRC;
+
+ /** Array of bridges attached to the bus. */
+ R3PTRTYPE(PPDMPCIDEV *) papBridgesR3;
+#if HC_ARCH_BITS == 32
+ uint32_t au32Alignment1[5]; /**< Cache line align apDevices. */
+#endif
+ /** Array of PCI devices. We assume 32 slots, each with 8 functions. */
+ R3PTRTYPE(PPDMPCIDEV) apDevices[256];
+
+ /** The PCI device for the PCI bridge. */
+ PDMPCIDEV PciDev;
+} DEVPCIBUS;
+/** Pointer to a PCI bus instance. */
+typedef DEVPCIBUS *PDEVPCIBUS;
+
+
+#endif
+
diff --git a/src/VBox/Devices/Bus/DevPciMerge1.cpp.h b/src/VBox/Devices/Bus/DevPciMerge1.cpp.h
index 91169b588f0..a20e106890b 100644
--- a/src/VBox/Devices/Bus/DevPciMerge1.cpp.h
+++ b/src/VBox/Devices/Bus/DevPciMerge1.cpp.h
@@ -27,7 +27,7 @@
* @param pBus The bus to register with.
* @remarks Caller enters the PDM critical section.
*/
-static uint8_t pciR3MergedFindUnusedDeviceNo(PPCIMERGEDBUS pBus)
+static uint8_t pciR3MergedFindUnusedDeviceNo(PDEVPCIBUS pBus)
{
for (uint8_t uPciDevNo = pBus->iDevSearch >> VBOX_PCI_DEVFN_DEV_SHIFT; uPciDevNo < VBOX_PCI_MAX_DEVICES; uPciDevNo++)
if ( !pBus->apDevices[VBOX_PCI_DEVFN_MAKE(uPciDevNo, 0)]
@@ -63,7 +63,7 @@ static uint8_t pciR3MergedFindUnusedDeviceNo(PPCIMERGEDBUS pBus)
*
* @remarks Caller enters the PDM critical section.
*/
-static int pciR3MergedRegisterDeviceOnBus(PPCIMERGEDBUS pBus, PPDMPCIDEV pPciDev, uint32_t fFlags,
+static int pciR3MergedRegisterDeviceOnBus(PDEVPCIBUS pBus, PPDMPCIDEV pPciDev, uint32_t fFlags,
uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName,
PFNPCICONFIGREAD pfnConfigRead, PFNPCICONFIGWRITE pfnConfigWrite)
{
@@ -220,7 +220,7 @@ static int pciR3MergedRegisterDeviceOnBus(PPCIMERGEDBUS pBus, PPDMPCIDEV pPciDev
static DECLCALLBACK(int) pciR3MergedRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t fFlags,
uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName)
{
- PPCIMERGEDBUS pBus = DEVINS_2_PCIBUS(pDevIns);
+ PDEVPCIBUS pBus = DEVINS_2_PCIBUS(pDevIns);
return pciR3MergedRegisterDeviceOnBus(pBus, pPciDev, fFlags, uPciDevNo, uPciFunNo, pszName,
pciR3UnmergedConfigReadDev, pciR3UnmergedConfigWriteDev);
}
@@ -232,7 +232,7 @@ static DECLCALLBACK(int) pciR3MergedRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPci
static DECLCALLBACK(int) pcibridgeR3MergedRegisterDevice(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t fFlags,
uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName)
{
- PPCIMERGEDBUS pBus = PDMINS_2_DATA(pDevIns, PPCIMERGEDBUS);
+ PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
return pciR3MergedRegisterDeviceOnBus(pBus, pPciDev, fFlags, uPciDevNo, uPciFunNo, pszName,
pciR3UnmergedConfigReadDev, pciR3UnmergedConfigWriteDev);
}
diff --git a/src/VBox/Devices/testcase/tstDeviceStructSize.cpp b/src/VBox/Devices/testcase/tstDeviceStructSize.cpp
index 4719b0e4367..916c56b0f83 100644
--- a/src/VBox/Devices/testcase/tstDeviceStructSize.cpp
+++ b/src/VBox/Devices/testcase/tstDeviceStructSize.cpp
@@ -360,8 +360,7 @@ int main()
CHECK_MEMBER_ALIGNMENT(OHCI, StatCanceledIsocUrbs, 8);
# endif
#endif
- CHECK_MEMBER_ALIGNMENT(PCIBUS, devices, 16);
- CHECK_MEMBER_ALIGNMENT(PCIBUS, devices, 16);
+ CHECK_MEMBER_ALIGNMENT(DEVPCIBUS, apDevices, 64);
CHECK_MEMBER_ALIGNMENT(PCIGLOBALS, pci_irq_levels, 16);
CHECK_MEMBER_ALIGNMENT(PCNETSTATE, u64LastPoll, 8);
CHECK_MEMBER_ALIGNMENT(PCNETSTATE, CritSect, 8);
diff --git a/src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp b/src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp
index 136d6228420..2e160964748 100644
--- a/src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp
+++ b/src/VBox/Devices/testcase/tstDeviceStructSizeRC.cpp
@@ -36,6 +36,8 @@
#define VBOX_DEVICE_STRUCT_TESTCASE
#define VBOX_WITH_HGCM /* grumble */
#undef LOG_GROUP
+#include "../Bus/DevPciInternal.h"
+#undef LOG_GROUP
#include "../Bus/DevPCI.cpp" /* must be first! */
#undef LOG_GROUP
#include "../Bus/DevPciIch9.cpp"
@@ -146,10 +148,10 @@ int main()
GEN_CHECK_OFF(PDMDEVINS, pvInstanceDataRC);
GEN_CHECK_OFF(PDMDEVINS, achInstanceData);
- /* DevPCI.cpp */
+ /* PDMPCIDEV */
GEN_CHECK_SIZE(PDMPCIDEV);
GEN_CHECK_SIZE(PDMPCIDEVINT);
- GEN_CHECK_SIZE(PCIIOREGION);
+ GEN_CHECK_SIZE(PCIIOREGION); /** @todo fix name of PCIIOREGION */
GEN_CHECK_OFF(PDMPCIDEV, abConfig);
GEN_CHECK_OFF(PDMPCIDEV, uDevFn);
GEN_CHECK_OFF(PDMPCIDEV, pszNameR3);
@@ -172,29 +174,33 @@ int main()
GEN_CHECK_OFF(PDMPCIDEV, Int.s.pfnBridgeConfigRead);
GEN_CHECK_OFF(PDMPCIDEV, Int.s.pfnBridgeConfigWrite);
GEN_CHECK_PADDING(PDMPCIDEV, Int, 8);
+
+ /* DevPciInternal.h */
+ GEN_CHECK_SIZE(DEVPCIBUS);
+ GEN_CHECK_OFF(DEVPCIBUS, iBus);
+ GEN_CHECK_OFF(DEVPCIBUS, iDevSearch);
+ GEN_CHECK_OFF(DEVPCIBUS, cBridges);
+ GEN_CHECK_OFF(DEVPCIBUS, apDevices);
+ GEN_CHECK_OFF(DEVPCIBUS, apDevices[1]);
+ GEN_CHECK_OFF(DEVPCIBUS, pDevInsR3);
+ GEN_CHECK_OFF(DEVPCIBUS, pPciHlpR3);
+ GEN_CHECK_OFF(DEVPCIBUS, papBridgesR3);
+ GEN_CHECK_OFF(DEVPCIBUS, pDevInsR0);
+ GEN_CHECK_OFF(DEVPCIBUS, pPciHlpR0);
+ GEN_CHECK_OFF(DEVPCIBUS, pDevInsRC);
+ GEN_CHECK_OFF(DEVPCIBUS, pPciHlpRC);
+ GEN_CHECK_OFF(DEVPCIBUS, PciDev);
+
+ /* DevPCI.cpp */
GEN_CHECK_SIZE(PIIX3State);
- GEN_CHECK_SIZE(PCIBUS);
- GEN_CHECK_OFF(PCIBUS, iBus);
- GEN_CHECK_OFF(PCIBUS, iDevSearch);
- GEN_CHECK_OFF(PCIBUS, cBridges);
- GEN_CHECK_OFF(PCIBUS, devices);
- GEN_CHECK_OFF(PCIBUS, devices[1]);
- GEN_CHECK_OFF(PCIBUS, pDevInsR3);
- GEN_CHECK_OFF(PCIBUS, pPciHlpR3);
- GEN_CHECK_OFF(PCIBUS, papBridgesR3);
- GEN_CHECK_OFF(PCIBUS, pDevInsR0);
- GEN_CHECK_OFF(PCIBUS, pPciHlpR0);
- GEN_CHECK_OFF(PCIBUS, pDevInsRC);
- GEN_CHECK_OFF(PCIBUS, pPciHlpRC);
- GEN_CHECK_OFF(PCIBUS, PciDev);
GEN_CHECK_SIZE(PCIGLOBALS);
- GEN_CHECK_OFF(PCIGLOBALS, pci_bios_io_addr);
- GEN_CHECK_OFF(PCIGLOBALS, pci_bios_mem_addr);
+ GEN_CHECK_OFF(PCIGLOBALS, uPciBiosIo);
+ GEN_CHECK_OFF(PCIGLOBALS, uPciBiosMmio);
GEN_CHECK_OFF(PCIGLOBALS, pci_irq_levels);
GEN_CHECK_OFF(PCIGLOBALS, pci_irq_levels[1]);
GEN_CHECK_OFF(PCIGLOBALS, fUseIoApic);
- GEN_CHECK_OFF(PCIGLOBALS, pci_apic_irq_levels);
- GEN_CHECK_OFF(PCIGLOBALS, pci_apic_irq_levels[1]);
+ GEN_CHECK_OFF(PCIGLOBALS, uaPciApicIrqLevels);
+ GEN_CHECK_OFF(PCIGLOBALS, uaPciApicIrqLevels[1]);
GEN_CHECK_OFF(PCIGLOBALS, acpi_irq_level);
GEN_CHECK_OFF(PCIGLOBALS, acpi_irq);
GEN_CHECK_OFF(PCIGLOBALS, uConfigReg);
@@ -205,19 +211,6 @@ int main()
GEN_CHECK_OFF(PCIGLOBALS, PciBus);
/* DevPciIch9.cpp */
- GEN_CHECK_SIZE(ICH9PCIBUS);
- GEN_CHECK_OFF(ICH9PCIBUS, iBus);
- GEN_CHECK_OFF(ICH9PCIBUS, cBridges);
- GEN_CHECK_OFF(ICH9PCIBUS, apDevices);
- GEN_CHECK_OFF(ICH9PCIBUS, apDevices[1]);
- GEN_CHECK_OFF(ICH9PCIBUS, pDevInsR3);
- GEN_CHECK_OFF(ICH9PCIBUS, pPciHlpR3);
- GEN_CHECK_OFF(ICH9PCIBUS, papBridgesR3);
- GEN_CHECK_OFF(ICH9PCIBUS, pDevInsR0);
- GEN_CHECK_OFF(ICH9PCIBUS, pPciHlpR0);
- GEN_CHECK_OFF(ICH9PCIBUS, pDevInsRC);
- GEN_CHECK_OFF(ICH9PCIBUS, pPciHlpRC);
- GEN_CHECK_OFF(ICH9PCIBUS, aPciDev);
GEN_CHECK_SIZE(ICH9PCIGLOBALS);
GEN_CHECK_OFF(ICH9PCIGLOBALS, pDevInsR3);
GEN_CHECK_OFF(ICH9PCIGLOBALS, pDevInsR0);
@@ -231,7 +224,7 @@ int main()
GEN_CHECK_OFF(ICH9PCIGLOBALS, uBus);
GEN_CHECK_OFF(ICH9PCIGLOBALS, u64PciConfigMMioAddress);
GEN_CHECK_OFF(ICH9PCIGLOBALS, u64PciConfigMMioLength);
- GEN_CHECK_OFF(ICH9PCIGLOBALS, aPciBus);
+ GEN_CHECK_OFF(ICH9PCIGLOBALS, PciBus);
/* EFI/DevSMC.cpp */
GEN_CHECK_SIZE(DEVSMC);