Changeset 80943 in vbox for trunk/src/VBox/Devices/Bus
- Timestamp:
- Sep 23, 2019 9:36:14 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 133523
- Location:
- trunk/src/VBox/Devices/Bus
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Bus/DevPCI.cpp
r80854 r80943 84 84 RT_C_DECLS_BEGIN 85 85 86 PDMBOTHCBDECL(void) pciSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTag); 87 PDMBOTHCBDECL(void) pcibridgeSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTag); 86 static DECLCALLBACK(void) pcibridgeSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTag); 88 87 PDMBOTHCBDECL(int) pciIOPortAddressWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb); 89 88 PDMBOTHCBDECL(int) pciIOPortAddressRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb); … … 111 110 112 111 113 static int pci_data_write(PDEVPCIROOT pGlobals, uint32_t addr, uint32_t val, int len) 114 { 115 uint8_t iBus, iDevice; 116 uint32_t config_addr; 117 118 LogFunc(("addr=%08x val=%08x len=%d\n", pGlobals->uConfigReg, val, len)); 119 120 if (!(pGlobals->uConfigReg & (1 << 31))) { 112 static int pci_data_write(PPDMDEVINS pDevIns, PDEVPCIROOT pGlobals, uint32_t addr, uint32_t u32Value, int cb) 113 { 114 LogFunc(("addr=%08x u32Value=%08x cb=%d\n", pGlobals->uConfigReg, u32Value, cb)); 115 116 if (!(pGlobals->uConfigReg & (1 << 31))) 121 117 return VINF_SUCCESS; 122 } 123 if ((pGlobals->uConfigReg & 0x3) != 0) { 118 if ((pGlobals->uConfigReg & 0x3) != 0) 124 119 return VINF_SUCCESS; 125 } 126 iBus = (pGlobals->uConfigReg >> 16) & 0xff; 127 iDevice = (pGlobals->uConfigReg >> 8) & 0xff; 128 config_addr = (pGlobals->uConfigReg & 0xfc) | (addr & 3); 120 121 uint8_t const iBus = (pGlobals->uConfigReg >> 16) & 0xff; 122 uint8_t const iDevice = (pGlobals->uConfigReg >> 8) & 0xff; 123 #ifdef IN_RING3 124 uint32_t const config_addr = (pGlobals->uConfigReg & 0xfc) | (addr & 3); 125 #endif 129 126 RT_UNTRUSTED_VALIDATED_FENCE(); /* paranoia */ 127 128 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 130 129 if (iBus != 0) 131 130 { … … 137 136 { 138 137 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigWrite); 139 pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), iBus, iDevice, config_addr, val, len); 138 rcStrict = pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), iBus, 139 iDevice, config_addr, cb, u32Value); 140 140 } 141 141 #else 142 RT_NOREF 2(val, len);143 r eturnVINF_IOM_R3_IOPORT_WRITE;142 RT_NOREF(pDevIns, addr, u32Value, cb); 143 rcStrict = VINF_IOM_R3_IOPORT_WRITE; 144 144 #endif 145 145 } … … 147 147 else 148 148 { 149 R3PTRTYPE(PDMPCIDEV *) p ci_dev = pGlobals->PciBus.apDevices[iDevice];150 if (p ci_dev)149 R3PTRTYPE(PDMPCIDEV *) pPciDev = pGlobals->PciBus.apDevices[iDevice]; 150 if (pPciDev) 151 151 { 152 152 #ifdef IN_RING3 153 LogFunc(("%s: addr=%02x val=%08x len=%d\n", pci_dev->pszNameR3, config_addr, val, len)); 154 return VBOXSTRICTRC_TODO(pci_dev->Int.s.pfnConfigWrite(pci_dev->Int.s.CTX_SUFF(pDevIns), pci_dev, config_addr, val, len)); 153 LogFunc(("%s: addr=%02x u32Value=%08x cb=%d\n", pPciDev->pszNameR3, config_addr, u32Value, cb)); 154 rcStrict = VINF_PDM_PCI_DO_DEFAULT; 155 if (pPciDev->Int.s.pfnConfigWrite) 156 rcStrict = pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, config_addr, cb, u32Value); 157 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 158 rcStrict = devpciR3CommonConfigWriteWorker(pDevIns, PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC), 159 pPciDev, config_addr, cb, u32Value); 155 160 #else 156 r eturnVINF_IOM_R3_IOPORT_WRITE;161 rcStrict = VINF_IOM_R3_IOPORT_WRITE; 157 162 #endif 158 163 } 159 164 } 160 return VINF_SUCCESS; 161 } 162 163 static int pci_data_read(PDEVPCIROOT pGlobals, uint32_t addr, int len, uint32_t *pu32) 164 { 165 uint8_t iBus, iDevice; 166 uint32_t config_addr; 167 168 *pu32 = 0xffffffff; 165 return rcStrict; 166 } 167 168 static int pci_data_read(PDEVPCIROOT pGlobals, uint32_t addr, int cb, uint32_t *pu32Value) 169 { 170 *pu32Value = UINT32_MAX; 169 171 170 172 if (!(pGlobals->uConfigReg & (1 << 31))) … … 172 174 if ((pGlobals->uConfigReg & 0x3) != 0) 173 175 return VINF_SUCCESS; 174 iBus = (pGlobals->uConfigReg >> 16) & 0xff; 175 iDevice = (pGlobals->uConfigReg >> 8) & 0xff; 176 config_addr = (pGlobals->uConfigReg & 0xfc) | (addr & 3); 176 uint8_t const iBus = (pGlobals->uConfigReg >> 16) & 0xff; 177 uint8_t const iDevice = (pGlobals->uConfigReg >> 8) & 0xff; 178 #ifdef IN_RING3 179 uint32_t const config_addr = (pGlobals->uConfigReg & 0xfc) | (addr & 3); 180 #endif 177 181 RT_UNTRUSTED_VALIDATED_FENCE(); 182 183 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 178 184 if (iBus != 0) 179 185 { … … 185 191 { 186 192 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigRead); 187 *pu32 = pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), iBus, iDevice, config_addr, len); 193 rcStrict = pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), 194 iBus, iDevice, config_addr, cb, pu32Value); 188 195 } 189 196 #else 190 NOREF(len);191 r eturnVINF_IOM_R3_IOPORT_READ;197 RT_NOREF(addr, cb); 198 rcStrict = VINF_IOM_R3_IOPORT_READ; 192 199 #endif 193 200 } … … 195 202 else 196 203 { 197 R3PTRTYPE(PDMPCIDEV *) p ci_dev = pGlobals->PciBus.apDevices[iDevice];198 if (p ci_dev)204 R3PTRTYPE(PDMPCIDEV *) pPciDev = pGlobals->PciBus.apDevices[iDevice]; 205 if (pPciDev) 199 206 { 200 207 #ifdef IN_RING3 201 *pu32 = pci_dev->Int.s.pfnConfigRead(pci_dev->Int.s.CTX_SUFF(pDevIns), pci_dev, config_addr, len); 202 LogFunc(("%s: addr=%02x val=%08x len=%d\n", pci_dev->pszNameR3, config_addr, *pu32, len)); 208 rcStrict = VINF_PDM_PCI_DO_DEFAULT; 209 if (pPciDev->Int.s.pfnConfigRead) 210 rcStrict = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, config_addr, cb, pu32Value); 211 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 212 rcStrict = devpciR3CommonConfigReadWorker(pPciDev, config_addr, cb, pu32Value); 213 LogFunc(("%s: addr=%02x val=%08x cb=%d\n", pPciDev->pszNameR3, config_addr, *pu32Value, cb)); 203 214 #else 204 NOREF( len);205 r eturnVINF_IOM_R3_IOPORT_READ;215 NOREF(cb); 216 rcStrict = VINF_IOM_R3_IOPORT_READ; 206 217 #endif 207 218 } 208 219 } 209 220 210 return VINF_SUCCESS;221 return rcStrict; 211 222 } 212 223 … … 234 245 } 235 246 236 static void apic_set_irq(PDEVPCIBUS pBus, uint8_t uDevFn, PDMPCIDEV *pPciDev, int irq_num1, int iLevel, int iAcpiIrq, uint32_t uTagSrc) 247 static void apic_set_irq(PPDMDEVINS pDevIns, PDEVPCIBUS pBus, PDEVPCIBUSCC pBusCC, 248 uint8_t uDevFn, PDMPCIDEV *pPciDev, int irq_num1, int iLevel, int iAcpiIrq, uint32_t uTagSrc) 237 249 { 238 250 /* This is only allowed to be called with a pointer to the host bus. */ … … 253 265 Log3Func(("%s: irq_num1=%d level=%d apic_irq=%d apic_level=%d irq_num1=%d\n", 254 266 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, apic_irq, apic_level, irq_num)); 255 pBus ->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), apic_irq, apic_level, uTagSrc);267 pBusCC->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pDevIns, apic_irq, apic_level, uTagSrc); 256 268 257 269 if ((iLevel & PDM_IRQ_LEVEL_FLIP_FLOP) == PDM_IRQ_LEVEL_FLIP_FLOP) { … … 261 273 Log3Func(("%s: irq_num1=%d level=%d apic_irq=%d apic_level=%d irq_num1=%d (flop)\n", 262 274 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, apic_irq, apic_level, irq_num)); 263 pBus ->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), apic_irq, apic_level, uTagSrc);275 pBusCC->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pDevIns, apic_irq, apic_level, uTagSrc); 264 276 } 265 277 } else { 266 278 Log3Func(("%s: irq_num1=%d level=%d iAcpiIrq=%d\n", 267 279 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, iAcpiIrq)); 268 pBus ->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), iAcpiIrq, iLevel, uTagSrc);280 pBusCC->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pDevIns, iAcpiIrq, iLevel, uTagSrc); 269 281 } 270 282 } … … 278 290 * Set the IRQ for a PCI device on the host bus - shared by host bus and bridge. 279 291 * 280 * @param pGlobals Device instance of the host PCI Bus. 292 * @param pPdmDev The PDM device instance for the PCI bus. 293 * @param pGlobals Device instance of the host PCI bus. 294 * @param pBusCC Context specific data for the PCI bus. 281 295 * @param uDevFn The device number on the host bus which will raise the IRQ 282 296 * @param pPciDev The PCI device structure which raised the interrupt. … … 288 302 * is needed to calculate the PIRQ value. 289 303 */ 290 static void pciSetIrqInternal(PDEVPCIROOT pGlobals, uint8_t uDevFn, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc) 304 static void pciSetIrqInternal(PPDMDEVINS pDevIns, PDEVPCIROOT pGlobals, PDEVPCIBUSCC pBusCC, 305 uint8_t uDevFn, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc) 291 306 { 292 307 PDEVPCIBUS pBus = &pGlobals->PciBus; … … 316 331 * PCI device configuration space). 317 332 */ 318 apic_set_irq(p Bus, uDevFn, pPciDev, -1, iLevel, pPciDev->abConfig[PCI_INTERRUPT_LINE], uTagSrc);333 apic_set_irq(pDevIns, pBus, pBusCC, uDevFn, pPciDev, -1, iLevel, pPciDev->abConfig[PCI_INTERRUPT_LINE], uTagSrc); 319 334 else 320 apic_set_irq(p Bus, uDevFn, pPciDev, iIrq, iLevel, -1, uTagSrc);335 apic_set_irq(pDevIns, pBus, pBusCC, uDevFn, pPciDev, iIrq, iLevel, -1, uTagSrc); 321 336 return; 322 337 } … … 368 383 Log3Func(("%s: iLevel=%d iIrq=%d pic_irq=%d pic_level=%d uTagSrc=%#x\n", 369 384 R3STRING(pPciDev->pszNameR3), iLevel, iIrq, pic_irq, pic_level, uTagSrc)); 370 pBus ->CTX_SUFF(pPciHlp)->pfnIsaSetIrq(pBus->CTX_SUFF(pDevIns), pic_irq, pic_level, uTagSrc);385 pBusCC->CTX_SUFF(pPciHlp)->pfnIsaSetIrq(pDevIns, pic_irq, pic_level, uTagSrc); 371 386 372 387 /** @todo optimize pci irq flip-flop some rainy day. */ 373 388 if ((iLevel & PDM_IRQ_LEVEL_FLIP_FLOP) == PDM_IRQ_LEVEL_FLIP_FLOP) 374 pciSetIrqInternal(p Globals, uDevFn, pPciDev, iIrq, PDM_IRQ_LEVEL_LOW, uTagSrc);389 pciSetIrqInternal(pDevIns, pGlobals, pBusCC, uDevFn, pPciDev, iIrq, PDM_IRQ_LEVEL_LOW, uTagSrc); 375 390 } 376 391 } … … 380 395 * @interface_method_impl{PDMPCIBUSREG,pfnSetIrqR3} 381 396 */ 382 PDMBOTHCBDECL(void) pciSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc) 383 { 384 pciSetIrqInternal(PDMINS_2_DATA(pDevIns, PDEVPCIROOT), pPciDev->uDevFn, pPciDev, iIrq, iLevel, uTagSrc); 397 static DECLCALLBACK(void) pciSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc) 398 { 399 PDEVPCIROOT pBus = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 400 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 401 LogFlow(("pciSetIrq: %p %u %u %#x\n", pPciDev, iIrq, iLevel, uTagSrc)); 402 pciSetIrqInternal(pDevIns, pBus, pBusCC, pPciDev->uDevFn, pPciDev, iIrq, iLevel, uTagSrc); 385 403 } 386 404 … … 454 472 static const uint8_t pci_irqs[4] = { 11, 10, 9, 11 }; /* bird: added const */ 455 473 456 static void pci_bios_init_device(PDEVPCIROOT pGlobals, PDEVPCIBUS pBus, PPDMPCIDEV pPciDev, uint8_t cBridgeDepth, uint8_t *paBridgePositions) 474 static void pci_bios_init_device(PPDMDEVINS pDevIns, PDEVPCIROOT pGlobals, PDEVPCIBUS pBus, 475 PPDMPCIDEV pPciDev, uint8_t cBridgeDepth, uint8_t *paBridgePositions) 457 476 { 458 477 uint32_t *paddr; … … 474 493 { 475 494 /* PIIX3, PIIX4 or ICH6 IDE */ 476 devpciR3SetWord(p PciDev, 0x40, 0x8011); /* enable IDE0 + fast timing */477 devpciR3SetWord(p PciDev, 0x42, 0x8011); /* enable IDE1 + fast timing */495 devpciR3SetWord(pDevIns, pPciDev, 0x40, 0x8011); /* enable IDE0 + fast timing */ 496 devpciR3SetWord(pDevIns, pPciDev, 0x42, 0x8011); /* enable IDE1 + fast timing */ 478 497 goto default_map; 479 498 } … … 481 500 { 482 501 /* IDE: we map it as in ISA mode */ 483 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, 0, 0x1f0);484 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, 1, 0x3f4);485 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, 2, 0x170);486 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, 3, 0x374);487 devpciR3SetWord(p PciDev, PCI_COMMAND,502 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, 0, 0x1f0); 503 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, 1, 0x3f4); 504 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, 2, 0x170); 505 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, 3, 0x374); 506 devpciR3SetWord(pDevIns, pPciDev, PCI_COMMAND, 488 507 devpciR3GetWord(pPciDev, PCI_COMMAND) 489 508 | PCI_COMMAND_IOACCESS); … … 495 514 goto default_map; 496 515 /* VGA: map frame buffer to default Bochs VBE address */ 497 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, 0, 0xe0000000);516 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, 0, 0xe0000000); 498 517 /* 499 518 * Legacy VGA I/O ports are implicitly decoded by a VGA class device. But … … 501 520 * devpciR3BiosInitSetRegionAddress, so don't forget to enable I/O decoding. 502 521 */ 503 devpciR3SetWord(p PciDev, PCI_COMMAND,522 devpciR3SetWord(pDevIns, pPciDev, PCI_COMMAND, 504 523 devpciR3GetWord(pPciDev, PCI_COMMAND) 505 524 | PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS); … … 516 535 { 517 536 /* MPIC & MPIC2 */ 518 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, 0, 0x80800000 + 0x00040000);519 devpciR3SetWord(p PciDev, PCI_COMMAND,537 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, 0, 0x80800000 + 0x00040000); 538 devpciR3SetWord(pDevIns, pPciDev, PCI_COMMAND, 520 539 devpciR3GetWord(pPciDev, PCI_COMMAND) 521 540 | PCI_COMMAND_MEMACCESS); … … 528 547 { 529 548 /* macio bridge */ 530 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, 0, 0x80800000);531 devpciR3SetWord(p PciDev, PCI_COMMAND,549 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, 0, 0x80800000); 550 devpciR3SetWord(pDevIns, pPciDev, PCI_COMMAND, 532 551 devpciR3GetWord(pPciDev, PCI_COMMAND) 533 552 | PCI_COMMAND_MEMACCESS); … … 537 556 { 538 557 /* Init PCI-to-PCI bridge. */ 539 devpciR3SetByte(p PciDev, VBOX_PCI_PRIMARY_BUS, pBus->iBus);558 devpciR3SetByte(pDevIns, pPciDev, VBOX_PCI_PRIMARY_BUS, pBus->iBus); 540 559 541 560 AssertMsg(pGlobals->uPciBiosBus < 255, ("Too many bridges on the bus\n")); 542 561 pGlobals->uPciBiosBus++; 543 devpciR3SetByte(p PciDev, VBOX_PCI_SECONDARY_BUS, pGlobals->uPciBiosBus);544 devpciR3SetByte(p PciDev, VBOX_PCI_SUBORDINATE_BUS, 0xff); /* Temporary until we know how many other bridges are behind this one. */562 devpciR3SetByte(pDevIns, pPciDev, VBOX_PCI_SECONDARY_BUS, pGlobals->uPciBiosBus); 563 devpciR3SetByte(pDevIns, pPciDev, VBOX_PCI_SUBORDINATE_BUS, 0xff); /* Temporary until we know how many other bridges are behind this one. */ 545 564 546 565 /* Add position of this bridge into the array. */ … … 555 574 pGlobals->uPciBiosIo = RT_ALIGN_32(pGlobals->uPciBiosIo, _4K); 556 575 LogFunc(("Aligned I/O start address. New address %#x\n", pGlobals->uPciBiosIo)); 557 devpciR3SetByte(p PciDev, VBOX_PCI_IO_BASE, (pGlobals->uPciBiosIo >> 8) & 0xf0);576 devpciR3SetByte(pDevIns, pPciDev, VBOX_PCI_IO_BASE, (pGlobals->uPciBiosIo >> 8) & 0xf0); 558 577 559 578 /* The MMIO range for the bridge must be aligned to a 1MB boundary. */ … … 561 580 pGlobals->uPciBiosMmio = RT_ALIGN_32(pGlobals->uPciBiosMmio, _1M); 562 581 LogFunc(("Aligned MMIO start address. New address %#x\n", pGlobals->uPciBiosMmio)); 563 devpciR3SetWord(p PciDev, VBOX_PCI_MEMORY_BASE, (pGlobals->uPciBiosMmio >> 16) & UINT32_C(0xffff0));582 devpciR3SetWord(pDevIns, pPciDev, VBOX_PCI_MEMORY_BASE, (pGlobals->uPciBiosMmio >> 16) & UINT32_C(0xffff0)); 564 583 565 584 /* Save values to compare later to. */ … … 573 592 PPDMPCIDEV pChildPciDev = pChildBus->apDevices[uDevFn]; 574 593 if (pChildPciDev) 575 pci_bios_init_device(p Globals, pChildBus, pChildPciDev, cBridgeDepth + 1, paBridgePositions);594 pci_bios_init_device(pDevIns, pGlobals, pChildBus, pChildPciDev, cBridgeDepth + 1, paBridgePositions); 576 595 } 577 596 578 597 /* The number of bridges behind the this one is now available. */ 579 devpciR3SetByte(p PciDev, VBOX_PCI_SUBORDINATE_BUS, pGlobals->uPciBiosBus);598 devpciR3SetByte(pDevIns, pPciDev, VBOX_PCI_SUBORDINATE_BUS, pGlobals->uPciBiosBus); 580 599 581 600 /* … … 590 609 pGlobals->uPciBiosIo = RT_ALIGN_32(pGlobals->uPciBiosIo, _4K); 591 610 } 592 devpciR3SetByte(p PciDev, VBOX_PCI_IO_LIMIT, ((pGlobals->uPciBiosIo >> 8) & 0xf0) - 1);611 devpciR3SetByte(pDevIns, pPciDev, VBOX_PCI_IO_LIMIT, ((pGlobals->uPciBiosIo >> 8) & 0xf0) - 1); 593 612 594 613 /* Same with the MMIO limit register but with 1MB boundary here. */ … … 598 617 pGlobals->uPciBiosMmio = RT_ALIGN_32(pGlobals->uPciBiosMmio, _1M); 599 618 } 600 devpciR3SetWord(p PciDev, VBOX_PCI_MEMORY_LIMIT, ((pGlobals->uPciBiosMmio >> 16) & UINT32_C(0xfff0)) - 1);619 devpciR3SetWord(pDevIns, pPciDev, VBOX_PCI_MEMORY_LIMIT, ((pGlobals->uPciBiosMmio >> 16) & UINT32_C(0xfff0)) - 1); 601 620 602 621 /* … … 605 624 * the base register than in the limit register. 606 625 */ 607 devpciR3SetWord(p PciDev, VBOX_PCI_PREF_MEMORY_BASE, 0xfff0);608 devpciR3SetWord(p PciDev, VBOX_PCI_PREF_MEMORY_LIMIT, 0x0);609 devpciR3SetDWord(p PciDev, VBOX_PCI_PREF_BASE_UPPER32, 0x00);610 devpciR3SetDWord(p PciDev, VBOX_PCI_PREF_LIMIT_UPPER32, 0x00);626 devpciR3SetWord(pDevIns, pPciDev, VBOX_PCI_PREF_MEMORY_BASE, 0xfff0); 627 devpciR3SetWord(pDevIns, pPciDev, VBOX_PCI_PREF_MEMORY_LIMIT, 0x0); 628 devpciR3SetDWord(pDevIns, pPciDev, VBOX_PCI_PREF_BASE_UPPER32, 0x00); 629 devpciR3SetDWord(pDevIns, pPciDev, VBOX_PCI_PREF_LIMIT_UPPER32, 0x00); 611 630 break; 612 631 } … … 629 648 /* Calculate size. */ 630 649 u8RessourceType = devpciR3GetByte(pPciDev, u32Address); 631 devpciR3SetDWord(p PciDev, u32Address, UINT32_C(0xffffffff));650 devpciR3SetDWord(pDevIns, pPciDev, u32Address, UINT32_C(0xffffffff)); 632 651 u32Size = devpciR3GetDWord(pPciDev, u32Address); 633 652 bool fIsPio = ((u8RessourceType & PCI_COMMAND_IOACCESS) == PCI_COMMAND_IOACCESS); … … 665 684 i, pBus->iBus, pPciDev->uDevFn >> 3, pPciDev->uDevFn & 7, vendor_id, device_id)); /** @todo make this a VM start failure later. */ 666 685 /* Undo the mapping mess caused by the size probing. */ 667 devpciR3SetDWord(p PciDev, u32Address, UINT32_C(0));686 devpciR3SetDWord(pDevIns, pPciDev, u32Address, UINT32_C(0)); 668 687 } 669 688 else 670 689 { 671 690 LogFunc(("Start address of %s region %u is %#x\n", (fIsPio ? "I/O" : "MMIO"), i, uNew)); 672 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, i, uNew);691 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, i, uNew); 673 692 if (fIsPio) 674 693 fActiveIORegion = true; … … 682 701 683 702 /* Update the command word appropriately. */ 684 devpciR3SetWord(p PciDev, PCI_COMMAND,703 devpciR3SetWord(pDevIns, pPciDev, PCI_COMMAND, 685 704 devpciR3GetWord(pPciDev, PCI_COMMAND) 686 705 | (fActiveMemRegion ? PCI_COMMAND_MEMACCESS : 0) … … 709 728 pin = pci_slot_get_pirq(pPciDev->uDevFn, pin); 710 729 pic_irq = pci_irqs[pin]; 711 devpciR3SetByte(p PciDev, PCI_INTERRUPT_LINE, pic_irq);730 devpciR3SetByte(pDevIns, pPciDev, PCI_INTERRUPT_LINE, pic_irq); 712 731 } 713 732 } … … 750 769 elcr[irq >> 3] |= (1 << (irq & 7)); 751 770 /* Activate irq remapping in PIIX3. */ 752 devpciR3SetByte(p PIIX3, 0x60 + i, irq);771 devpciR3SetByte(pDevIns, pPIIX3, 0x60 + i, irq); 753 772 } 754 773 … … 770 789 { 771 790 PPDMPCIDEV pPciDev = pBus->apDevices[uDevFn]; 772 uint8_t aBridgePositions[256];773 774 791 if (pPciDev) 775 792 { 776 memset(aBridgePositions, 0, sizeof(aBridgePositions));777 Log2(("PCI: Initializing device %d (%#x)\n",778 uDevFn, 0x80000000 | (uDevFn << 8)));779 pci_bios_init_device(p Globals, pBus, pPciDev, 0, aBridgePositions);793 Log2(("PCI: Initializing device %d (%#x)\n", uDevFn, 0x80000000 | (uDevFn << 8))); 794 uint8_t aBridgePositions[256]; 795 RT_ZERO(aBridgePositions); 796 pci_bios_init_device(pDevIns, pGlobals, pBus, pPciDev, 0, aBridgePositions); 780 797 } 781 798 } … … 842 859 { 843 860 PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_WRITE); 844 rc = pci_data_write( PDMINS_2_DATA(pDevIns, PDEVPCIROOT), Port, u32, cb);861 rc = pci_data_write(pDevIns, PDMINS_2_DATA(pDevIns, PDEVPCIROOT), Port, u32, cb); 845 862 PCI_UNLOCK(pDevIns); 846 863 } … … 984 1001 * 985 1002 * @returns VBox status code. 1003 * @param pDevIns The device instance. 986 1004 * @param pBus The bus which data is being loaded. 987 1005 * @param pSSM The saved state handle. … … 989 1007 * @param uPass The pass. 990 1008 */ 991 static DECLCALLBACK(int) pciR3CommonLoadExec(PDEVPCIBUS pBus, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)1009 static int pciR3CommonLoadExec(PPDMDEVINS pDevIns, PDEVPCIBUS pBus, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass) 992 1010 { 993 1011 uint32_t u32; … … 1010 1028 { 1011 1029 uint16_t u16 = PCIDevGetCommand(pDev); 1012 pDev->Int.s.pfnConfigWrite(pDev->Int.s.CTX_SUFF(pDevIns), pDev, VBOX_PCI_COMMAND, 0, 2);1030 devpciR3SetCfg(pDevIns, pDev, VBOX_PCI_COMMAND, 0 /*u32Value*/, 2 /*cb*/); 1013 1031 PCIDevSetCommand(pDev, u16); 1014 1032 Assert(PCIDevGetCommand(pDev) == u16); … … 1102 1120 if (RT_FAILURE(rc)) 1103 1121 break; 1104 devpciR3CommonRestoreConfig(pDev , &DevTmp.abConfig[0]);1122 devpciR3CommonRestoreConfig(pDevIns, pDev, &DevTmp.abConfig[0]); 1105 1123 1106 1124 pDev->Int.s.uIrqPinState = DevTmp.Int.s.uIrqPinState; … … 1157 1175 * The devices. 1158 1176 */ 1159 return pciR3CommonLoadExec(p Bus, pSSM, uVersion, uPass);1177 return pciR3CommonLoadExec(pDevIns, pBus, pSSM, uVersion, uPass); 1160 1178 } 1161 1179 … … 1204 1222 1205 1223 /* -=-=-=-=-=- PDMDEVREG -=-=-=-=-=- */ 1224 1225 /** 1226 * @interface_method_impl{PDMDEVREG,pfnReset} 1227 */ 1228 static DECLCALLBACK(void) pciR3Reset(PPDMDEVINS pDevIns) 1229 { 1230 PDEVPCIROOT pGlobals = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 1231 PDEVPCIBUS pBus = &pGlobals->PciBus; 1232 1233 /* PCI-specific reset for each device. */ 1234 for (uint32_t uDevFn = 0; uDevFn < RT_ELEMENTS(pBus->apDevices); uDevFn++) 1235 { 1236 if (pBus->apDevices[uDevFn]) 1237 devpciR3ResetDevice(pDevIns, pBus->apDevices[uDevFn]); 1238 } 1239 1240 pciR3Piix3Reset(&pGlobals->Piix3.PIIX3State); 1241 } 1242 1243 1244 /** 1245 * @interface_method_impl{PDMDEVREG,pfnDestruct} 1246 */ 1247 static DECLCALLBACK(int) pciR3Destruct(PPDMDEVINS pDevIns) 1248 { 1249 PDEVPCIROOT pGlobals = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 1250 if (pGlobals->PciBus.papBridgesR3) 1251 { 1252 PDMDevHlpMMHeapFree(pDevIns, pGlobals->PciBus.papBridgesR3); 1253 pGlobals->PciBus.papBridgesR3 = NULL; 1254 } 1255 return VINF_SUCCESS; 1256 } 1206 1257 1207 1258 … … 1243 1294 Log(("PCI: fUseIoApic=%RTbool fGCEnabled=%RTbool fR0Enabled=%RTbool\n", fUseIoApic, fGCEnabled, fR0Enabled)); 1244 1295 1296 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 1297 PDEVPCIROOT pGlobals = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 1298 1245 1299 /* 1246 1300 * Init data and register the PCI bus. 1247 1301 */ 1248 PDEVPCIROOT pGlobals = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);1249 1302 pGlobals->uPciBiosIo = 0xc000; 1250 1303 pGlobals->uPciBiosMmio = 0xf0000000; … … 1253 1306 memset((void *)&pGlobals->auPciApicIrqLevels, 0, sizeof(pGlobals->auPciApicIrqLevels)); 1254 1307 1255 pGlobals->pDevInsR3 = pDevIns;1256 pGlobals->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);1257 pGlobals->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);1258 1259 1308 pGlobals->PciBus.fTypePiix3 = true; 1260 1309 pGlobals->PciBus.fTypeIch9 = false; 1261 1310 pGlobals->PciBus.fPureBridge = false; 1262 pGlobals->PciBus.pDevInsR3 = pDevIns;1263 pGlobals->PciBus.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);1264 pGlobals->PciBus.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);1265 1311 pGlobals->PciBus.papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, 1266 1312 sizeof(PPDMPCIDEV) … … 1268 1314 AssertLogRelReturn(pGlobals->PciBus.papBridgesR3, VERR_NO_MEMORY); 1269 1315 1270 1271 PDMPCIBUSREG PciBusReg;1272 P DEVPCIBUS pBus = &pGlobals->PciBus;1273 PciBusReg. u32Version = PDM_PCIBUSREG_VERSION;1274 PciBusReg.pfnRegister R3 = pciR3MergedRegister;1275 PciBusReg.pfn RegisterMsiR3 = NULL;1276 PciBusReg.pfnI ORegionRegisterR3 = devpciR3CommonIORegionRegister;1277 PciBusReg.pfn SetConfigCallbacksR3 = devpciR3CommonSetConfigCallbacks;1278 PciBusReg.pfn SetIrqR3 = pciSetIrq;1279 PciBusReg.p szSetIrqRC = fGCEnabled ? "pciSetIrq" : NULL;1280 PciBusReg. pszSetIrqR0 = fR0Enabled ? "pciSetIrq" : NULL;1281 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBus ->pPciHlpR3, &pBus->iBus);1316 PDEVPCIBUS pBus = &pGlobals->PciBus; 1317 PDMPCIBUSREGCC PciBusReg; 1318 PciBusReg.u32Version = PDM_PCIBUSREGCC_VERSION; 1319 PciBusReg.pfnRegisterR3 = pciR3MergedRegister; 1320 PciBusReg.pfnRegisterMsiR3 = NULL; 1321 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister; 1322 PciBusReg.pfnInterceptConfigAccesses = devpciR3CommonInterceptConfigAccesses; 1323 PciBusReg.pfnConfigRead = devpciR3CommonConfigRead; 1324 PciBusReg.pfnConfigWrite = devpciR3CommonConfigWrite; 1325 PciBusReg.pfnSetIrqR3 = pciSetIrq; 1326 PciBusReg.u32EndVersion = PDM_PCIBUSREGCC_VERSION; 1327 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBusCC->pPciHlpR3, &pBus->iBus); 1282 1328 if (RT_FAILURE(rc)) 1283 return PDMDEV_SET_ERROR(pDevIns, rc, 1284 N_("Failed to register ourselves as a PCI Bus")); 1329 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to register ourselves as a PCI Bus")); 1285 1330 Assert(pBus->iBus == 0); 1286 if (pBus ->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION)1331 if (pBusCC->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION) 1287 1332 return PDMDevHlpVMSetError(pDevIns, VERR_VERSION_MISMATCH, RT_SRC_POS, 1288 1333 N_("PCI helper version mismatch; got %#x expected %#x"), 1289 pBus->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION); 1290 1291 pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns); 1292 pBus->pPciHlpR0 = pBus->pPciHlpR3->pfnGetR0Helpers(pDevIns); 1334 pBusCC->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION); 1293 1335 1294 1336 /* Disable default device locking. */ … … 1351 1393 } 1352 1394 1353 rc = PDMDevHlpIOPortRegister(pDevIns, 0x0410, 1, NULL, pciR3IOPortMagicPCIWrite, pciR3IOPortMagicPCIRead, NULL, NULL, "i440FX (Fake PCI BIOS trigger)") 1354 ; 1395 rc = PDMDevHlpIOPortRegister(pDevIns, 0x0410, 1, NULL, pciR3IOPortMagicPCIWrite, pciR3IOPortMagicPCIRead, NULL, NULL, "i440FX (Fake PCI BIOS trigger)"); 1355 1396 if (RT_FAILURE(rc)) 1356 1397 return rc; … … 1374 1415 } 1375 1416 1376 1377 /** 1378 * @interface_method_impl{PDMDEVREG,pfnDestruct} 1379 */ 1380 static DECLCALLBACK(int) pciR3Destruct(PPDMDEVINS pDevIns) 1381 { 1382 PDEVPCIROOT pGlobals = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 1383 if (pGlobals->PciBus.papBridgesR3) 1384 { 1385 PDMDevHlpMMHeapFree(pDevIns, pGlobals->PciBus.papBridgesR3); 1386 pGlobals->PciBus.papBridgesR3 = NULL; 1387 } 1388 return VINF_SUCCESS; 1389 } 1390 1391 1392 /** 1393 * @interface_method_impl{PDMDEVREG,pfnReset} 1394 */ 1395 static DECLCALLBACK(void) pciR3Reset(PPDMDEVINS pDevIns) 1396 { 1397 PDEVPCIROOT pGlobals = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 1398 PDEVPCIBUS pBus = &pGlobals->PciBus; 1399 1400 /* PCI-specific reset for each device. */ 1401 for (uint32_t uDevFn = 0; uDevFn < RT_ELEMENTS(pBus->apDevices); uDevFn++) 1402 { 1403 if (pBus->apDevices[uDevFn]) 1404 devpciR3ResetDevice(pBus->apDevices[uDevFn]); 1405 } 1406 1407 pciR3Piix3Reset(&pGlobals->Piix3.PIIX3State); 1408 } 1409 1410 #endif /* IN_RING3 */ 1417 #else /* !IN_RING3 */ 1418 1419 /** 1420 * @interface_method_impl{PDMDEVREGR0,pfnConstruct} 1421 */ 1422 static DECLCALLBACK(int) pciRZRootConstruct(PPDMDEVINS pDevIns) 1423 { 1424 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 1425 PDEVPCIROOT pGlobals = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 1426 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 1427 1428 PDMPCIBUSREGCC PciBusReg; 1429 PciBusReg.u32Version = PDM_PCIBUSREGCC_VERSION; 1430 PciBusReg.iBus = pGlobals->PciBus.iBus; 1431 PciBusReg.pfnSetIrq = pciSetIrq; 1432 PciBusReg.u32EndVersion = PDM_PCIBUSREGCC_VERSION; 1433 int rc = PDMDevHlpPCIBusSetUpContext(pDevIns, &PciBusReg, &pBusCC->CTX_SUFF(pPciHlp)); 1434 AssertRC(rc); 1435 1436 return rc; 1437 } 1438 1439 #endif /* !IN_RING3 */ 1411 1440 1412 1441 /** … … 1423 1452 /* .uSharedVersion = */ 42, 1424 1453 /* .cbInstanceShared = */ sizeof(DEVPCIROOT), 1425 /* .cbInstanceCC = */ 0,1426 /* .cbInstanceRC = */ 0,1454 /* .cbInstanceCC = */ sizeof(CTX_SUFF(DEVPCIBUS)), 1455 /* .cbInstanceRC = */ sizeof(DEVPCIBUSRC), 1427 1456 /* .cMaxPciDevices = */ 2, 1428 1457 /* .cMaxMsixVectors = */ 0, … … 1455 1484 #elif defined(IN_RING0) 1456 1485 /* .pfnEarlyConstruct = */ NULL, 1457 /* .pfnConstruct = */ NULL,1486 /* .pfnConstruct = */ pciRZRootConstruct, 1458 1487 /* .pfnDestruct = */ NULL, 1459 1488 /* .pfnFinalDestruct = */ NULL, … … 1468 1497 /* .pfnReserved7 = */ NULL, 1469 1498 #elif defined(IN_RC) 1470 /* .pfnConstruct = */ NULL,1499 /* .pfnConstruct = */ pciRZRootConstruct, 1471 1500 /* .pfnReserved0 = */ NULL, 1472 1501 /* .pfnReserved1 = */ NULL, … … 1491 1520 * @interface_method_impl{PDMPCIBUSREG,pfnSetIrqR3} 1492 1521 */ 1493 PDMBOTHCBDECL(void) pcibridgeSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc) 1494 { 1522 static DECLCALLBACK(void) pcibridgeSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc) 1523 { 1524 LogFlow(("pcibridgeSetIrq: %p %u %u %#x\n", pPciDev, iIrq, iLevel, uTagSrc)); 1525 1495 1526 /* 1496 1527 * The PCI-to-PCI bridge specification defines how the interrupt pins … … 1500 1531 * of our parent passing the device which asserted the interrupt instead of the device of the bridge. 1501 1532 */ 1502 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1503 PPDMPCIDEV pPciDevBus = pPciDev; 1504 int iIrqPinBridge = iIrq; 1505 uint8_t uDevFnBridge = 0; 1533 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1534 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 1535 PPDMPCIDEV pPciDevBus = pPciDev; 1536 int iIrqPinBridge = iIrq; 1537 uint8_t uDevFnBridge = 0; 1506 1538 1507 1539 /* Walk the chain until we reach the host bus. */ … … 1517 1549 1518 1550 AssertMsg(pBus->iBus == 0, ("This is not the host pci bus iBus=%d\n", pBus->iBus)); 1519 pciSetIrqInternal( DEVPCIBUS_2_DEVPCIROOT(pBus), uDevFnBridge, pPciDev, iIrqPinBridge, iLevel, uTagSrc);1551 pciSetIrqInternal(pDevIns, DEVPCIBUS_2_DEVPCIROOT(pBus), pBusCC, uDevFnBridge, pPciDev, iIrqPinBridge, iLevel, uTagSrc); 1520 1552 } 1521 1553 … … 1525 1557 * @callback_method_impl{FNPCIBRIDGECONFIGWRITE} 1526 1558 */ 1527 static DECLCALLBACK(void) pcibridgeR3ConfigWrite(PPDMDEVINSR3 pDevIns, uint8_t iBus, uint8_t iDevice, uint32_t u32Address, uint32_t u32Value, unsigned cb) 1528 { 1529 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1530 1531 LogFlowFunc(("pDevIns=%p iBus=%d iDevice=%d u32Address=%u u32Value=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, u32Value, cb)); 1559 static DECLCALLBACK(VBOXSTRICTRC) pcibridgeR3ConfigWrite(PPDMDEVINSR3 pDevIns, uint8_t iBus, uint8_t iDevice, 1560 uint32_t u32Address, unsigned cb, uint32_t u32Value) 1561 { 1562 LogFlowFunc(("pDevIns=%p iBus=%d iDevice=%d u32Address=%u cb=%d u32Value=%u\n", pDevIns, iBus, iDevice, u32Address, cb, u32Value)); 1563 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1564 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 1532 1565 1533 1566 /* If the current bus is not the target bus search for the bus which contains the device. */ … … 1538 1571 { 1539 1572 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigWrite); 1540 pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), iBus, iDevice, u32Address, u32Value, cb); 1573 rcStrict = pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), iBus, iDevice, 1574 u32Address, cb, u32Value); 1541 1575 } 1542 1576 } … … 1548 1582 { 1549 1583 LogFunc(("%s: addr=%02x val=%08x len=%d\n", pPciDev->pszNameR3, u32Address, u32Value, cb)); 1550 /** @todo return rc */ 1551 pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, u32Value, cb); 1552 } 1553 } 1584 rcStrict = VINF_PDM_PCI_DO_DEFAULT; 1585 if (pPciDev->Int.s.pfnConfigWrite) 1586 rcStrict = pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, cb, u32Value); 1587 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 1588 rcStrict = devpciR3CommonConfigWriteWorker(pDevIns, PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC), 1589 pPciDev, u32Address, cb, u32Value); 1590 } 1591 } 1592 return rcStrict; 1554 1593 } 1555 1594 … … 1558 1597 * @callback_method_impl{FNPCIBRIDGECONFIGREAD} 1559 1598 */ 1560 static DECLCALLBACK(uint32_t) pcibridgeR3ConfigRead(PPDMDEVINSR3 pDevIns, uint8_t iBus, uint8_t iDevice, uint32_t u32Address, unsigned cb) 1561 { 1562 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1563 uint32_t u32Value = 0xffffffff; /* Return value in case there is no device. */ 1564 1599 static DECLCALLBACK(VBOXSTRICTRC) pcibridgeR3ConfigRead(PPDMDEVINSR3 pDevIns, uint8_t iBus, uint8_t iDevice, 1600 uint32_t u32Address, unsigned cb, uint32_t *pu32Value) 1601 { 1565 1602 LogFlowFunc(("pDevIns=%p iBus=%d iDevice=%d u32Address=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, cb)); 1603 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1604 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 1566 1605 1567 1606 /* If the current bus is not the target bus search for the bus which contains the device. */ … … 1571 1610 if (pBridgeDevice) 1572 1611 { 1573 AssertPtr( pBridgeDevice->Int.s.pfnBridgeConfigRead); 1574 u32Value = pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), iBus, iDevice, u32Address, cb); 1575 } 1612 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigRead); 1613 rcStrict = pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), 1614 iBus, iDevice, u32Address, cb, pu32Value); 1615 } 1616 else 1617 *pu32Value = UINT32_MAX; 1576 1618 } 1577 1619 else … … 1581 1623 if (pPciDev) 1582 1624 { 1583 u32Value = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, cb); 1584 LogFunc(("%s: u32Address=%02x u32Value=%08x cb=%d\n", pPciDev->pszNameR3, u32Address, u32Value, cb)); 1585 } 1586 } 1587 1588 return u32Value; 1625 rcStrict = VINF_PDM_PCI_DO_DEFAULT; 1626 if (pPciDev->Int.s.pfnConfigRead) 1627 rcStrict = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, cb, pu32Value); 1628 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 1629 rcStrict = devpciR3CommonConfigReadWorker(pPciDev, u32Address, cb, pu32Value); 1630 1631 LogFunc(("%s: u32Address=%02x u32Value=%08x cb=%d\n", pPciDev->pszNameR3, u32Address, *pu32Value, cb)); 1632 } 1633 else 1634 *pu32Value = UINT32_MAX; 1635 } 1636 1637 return rcStrict; 1589 1638 } 1590 1639 … … 1608 1657 if (uVersion > VBOX_PCI_SAVED_STATE_VERSION) 1609 1658 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION; 1610 return pciR3CommonLoadExec(p This, pSSM, uVersion, uPass);1659 return pciR3CommonLoadExec(pDevIns, pThis, pSSM, uVersion, uPass); 1611 1660 } 1612 1661 … … 1623 1672 pBus->PciDev.abConfig[VBOX_PCI_SECONDARY_BUS] = 0; 1624 1673 pBus->PciDev.abConfig[VBOX_PCI_SUBORDINATE_BUS] = 0; 1674 } 1675 1676 1677 /** 1678 * @interface_method_impl{PDMDEVREG,pfnDestruct} 1679 */ 1680 static DECLCALLBACK(int) pcibridgeR3Destruct(PPDMDEVINS pDevIns) 1681 { 1682 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1683 if (pBus->papBridgesR3) 1684 { 1685 PDMDevHlpMMHeapFree(pDevIns, pBus->papBridgesR3); 1686 pBus->papBridgesR3 = NULL; 1687 } 1688 return VINF_SUCCESS; 1625 1689 } 1626 1690 … … 1655 1719 Log(("PCI: fGCEnabled=%RTbool fR0Enabled=%RTbool\n", fGCEnabled, fR0Enabled)); 1656 1720 1721 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1722 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 1723 1657 1724 /* 1658 1725 * Init data and register the PCI bus. 1659 1726 */ 1660 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);1661 1727 pBus->fTypePiix3 = true; 1662 1728 pBus->fTypeIch9 = false; 1663 1729 pBus->fPureBridge = true; 1664 pBus->pDevInsR3 = pDevIns;1665 pBus->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);1666 pBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);1667 1730 pBus->papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV) * RT_ELEMENTS(pBus->apDevices)); 1668 1731 AssertLogRelReturn(pBus->papBridgesR3, VERR_NO_MEMORY); 1669 1732 1670 PDMPCIBUSREG PciBusReg; 1671 PciBusReg.u32Version = PDM_PCIBUSREG_VERSION; 1672 PciBusReg.pfnRegisterR3 = pcibridgeR3MergedRegisterDevice; 1673 PciBusReg.pfnRegisterMsiR3 = NULL; 1674 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister; 1675 PciBusReg.pfnSetConfigCallbacksR3 = devpciR3CommonSetConfigCallbacks; 1676 PciBusReg.pfnSetIrqR3 = pcibridgeSetIrq; 1677 PciBusReg.pszSetIrqRC = fGCEnabled ? "pcibridgeSetIrq" : NULL; 1678 PciBusReg.pszSetIrqR0 = fR0Enabled ? "pcibridgeSetIrq" : NULL; 1679 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBus->pPciHlpR3, &pBus->iBus); 1733 PDMPCIBUSREGCC PciBusReg; 1734 PciBusReg.u32Version = PDM_PCIBUSREGCC_VERSION; 1735 PciBusReg.pfnRegisterR3 = pcibridgeR3MergedRegisterDevice; 1736 PciBusReg.pfnRegisterMsiR3 = NULL; 1737 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister; 1738 PciBusReg.pfnInterceptConfigAccesses = devpciR3CommonInterceptConfigAccesses; 1739 PciBusReg.pfnConfigWrite = devpciR3CommonConfigWrite; 1740 PciBusReg.pfnConfigRead = devpciR3CommonConfigRead; 1741 PciBusReg.pfnSetIrqR3 = pcibridgeSetIrq; 1742 PciBusReg.u32EndVersion = PDM_PCIBUSREGCC_VERSION; 1743 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBusCC->pPciHlpR3, &pBus->iBus); 1680 1744 if (RT_FAILURE(rc)) 1681 1745 return PDMDEV_SET_ERROR(pDevIns, rc, 1682 1746 N_("Failed to register ourselves as a PCI Bus")); 1683 1747 Assert(pBus->iBus == (uint32_t)iInstance + 1); /* Can be removed when adding support for multiple bridge implementations. */ 1684 if (pBus ->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION)1748 if (pBusCC->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION) 1685 1749 return PDMDevHlpVMSetError(pDevIns, VERR_VERSION_MISMATCH, RT_SRC_POS, 1686 1750 N_("PCI helper version mismatch; got %#x expected %#x"), 1687 pBus->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION); 1688 1689 pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns); 1690 pBus->pPciHlpR0 = pBus->pPciHlpR3->pfnGetR0Helpers(pDevIns); 1751 pBusCC->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION); 1691 1752 1692 1753 /* … … 1736 1797 } 1737 1798 1738 1739 /** 1740 * @interface_method_impl{PDMDEVREG,pfnDestruct} 1741 */ 1742 static DECLCALLBACK(int) pcibridgeR3Destruct(PPDMDEVINS pDevIns) 1743 { 1744 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1745 if (pBus->papBridgesR3) 1746 { 1747 PDMDevHlpMMHeapFree(pDevIns, pBus->papBridgesR3); 1748 pBus->papBridgesR3 = NULL; 1749 } 1750 return VINF_SUCCESS; 1751 } 1752 1753 #endif /* IN_RING3 */ 1799 #else /* !IN_RING3 */ 1800 1801 /** 1802 * @interface_method_impl{PDMDEVREGR0,pfnConstruct} 1803 */ 1804 static DECLCALLBACK(int) pcibridgeRZConstruct(PPDMDEVINS pDevIns) 1805 { 1806 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 1807 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1808 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 1809 1810 PDMPCIBUSREGCC PciBusReg; 1811 PciBusReg.u32Version = PDM_PCIBUSREGCC_VERSION; 1812 PciBusReg.iBus = pBus->iBus; 1813 PciBusReg.pfnSetIrq = pcibridgeSetIrq; 1814 PciBusReg.u32EndVersion = PDM_PCIBUSREGCC_VERSION; 1815 int rc = PDMDevHlpPCIBusSetUpContext(pDevIns, &PciBusReg, &pBusCC->CTX_SUFF(pPciHlp)); 1816 AssertRC(rc); 1817 1818 return rc; 1819 } 1820 1821 #endif /* !IN_RING3 */ 1754 1822 1755 1823 /** … … 1767 1835 /* .uSharedVersion = */ 42, 1768 1836 /* .cbInstanceShared = */ sizeof(DEVPCIBUS), 1769 /* .cbInstanceCC = */ 0,1837 /* .cbInstanceCC = */ sizeof(CTX_SUFF(DEVPCIBUS)), 1770 1838 /* .cbInstanceRC = */ 0, 1771 1839 /* .cMaxPciDevices = */ 1, … … 1799 1867 #elif defined(IN_RING0) 1800 1868 /* .pfnEarlyConstruct = */ NULL, 1801 /* .pfnConstruct = */ NULL,1869 /* .pfnConstruct = */ pcibridgeRZConstruct, 1802 1870 /* .pfnDestruct = */ NULL, 1803 1871 /* .pfnFinalDestruct = */ NULL, … … 1812 1880 /* .pfnReserved7 = */ NULL, 1813 1881 #elif defined(IN_RC) 1814 /* .pfnConstruct = */ NULL,1882 /* .pfnConstruct = */ pcibridgeRZConstruct, 1815 1883 /* .pfnReserved0 = */ NULL, 1816 1884 /* .pfnReserved1 = */ NULL, -
trunk/src/VBox/Devices/Bus/DevPciIch9.cpp
r80704 r80943 93 93 *********************************************************************************************************************************/ 94 94 /* Prototypes */ 95 static void ich9pciSetIrqInternal(P DEVPCIROOT pPciRoot, uint8_t uDevFn, PPDMPCIDEV pPciDev,96 int iIrq, int iLevel, uint32_t uTagSrc);95 static void ich9pciSetIrqInternal(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUSCC pBusCC, 96 uint8_t uDevFn, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc); 97 97 #ifdef IN_RING3 98 98 static int ich9pciFakePCIBIOS(PPDMDEVINS pDevIns); 99 99 DECLINLINE(PPDMPCIDEV) ich9pciFindBridge(PDEVPCIBUS pBus, uint8_t uBus); 100 static void ich9pciBiosInitAllDevicesOnBus(P DEVPCIROOT pPciRoot, PDEVPCIBUS pBus);101 static bool ich9pciBiosInitAllDevicesPrefetchableOnBus(P DEVPCIROOT pPciRoot, PDEVPCIBUS pBus, bool fUse64Bit, bool fDryrun);100 static void ich9pciBiosInitAllDevicesOnBus(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus); 101 static bool ich9pciBiosInitAllDevicesPrefetchableOnBus(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, bool fUse64Bit, bool fDryrun); 102 102 #endif 103 103 … … 125 125 { 126 126 LogFlowFunc(("invoked by %p/%d: iIrq=%d iLevel=%d uTagSrc=%#x\n", pDevIns, pDevIns->iInstance, iIrq, iLevel, uTagSrc)); 127 ich9pciSetIrqInternal(PDMINS_2_DATA(pDevIns, PDEVPCIROOT), pPciDev->uDevFn, pPciDev, iIrq, iLevel, uTagSrc); 127 ich9pciSetIrqInternal(pDevIns, PDMINS_2_DATA(pDevIns, PDEVPCIROOT), PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC), 128 pPciDev->uDevFn, pPciDev, iIrq, iLevel, uTagSrc); 128 129 } 129 130 … … 163 164 || MsixIsEnabled(pPciDev)) 164 165 iIrqPinVector = iIrq; 165 ich9pciSetIrqInternal(DEVPCIBUS_2_DEVPCIROOT(pBus), uDevFnBridge, pPciDev, iIrqPinVector, iLevel, uTagSrc); 166 ich9pciSetIrqInternal(pDevIns, DEVPCIBUS_2_DEVPCIROOT(pBus), PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC), 167 uDevFnBridge, pPciDev, iIrqPinVector, iLevel, uTagSrc); 166 168 } 167 169 … … 292 294 * Perform configuration space write. 293 295 */ 294 static int ich9pciConfigWrite(PDEVPCIROOT pPciRoot, PciAddress* pAddr, 295 uint32_t val, int cb, int rcReschedule) 296 { 297 int rc = VINF_SUCCESS; 298 #ifdef IN_RING3 299 NOREF(rcReschedule); 300 #else 301 RT_NOREF2(val, cb); 302 #endif 303 304 if (pAddr->iBus != 0) /* forward to subordinate bus */ 296 static VBOXSTRICTRC ich9pciConfigWrite(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PciAddress const *pPciAddr, 297 uint32_t u32Value, int cb, int rcReschedule) 298 { 299 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 300 301 if (pPciAddr->iBus != 0) /* forward to subordinate bus */ 305 302 { 306 303 if (pPciRoot->PciBus.cBridges) 307 304 { 308 305 #ifdef IN_RING3 /** @todo do lookup in R0/RC too! r=klaus don't think that it can work, since the config space access callback only works in R3 */ 309 PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(&pPciRoot->PciBus, p Addr->iBus);306 PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(&pPciRoot->PciBus, pPciAddr->iBus); 310 307 if (pBridgeDevice) 311 308 { 312 309 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigWrite); 313 pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), pAddr->iBus, pAddr->iDeviceFunc,314 pAddr->iRegister, val, cb);310 rcStrict = pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), pPciAddr->iBus, 311 pPciAddr->iDeviceFunc, pPciAddr->iRegister, cb, u32Value); 315 312 } 316 313 #else 317 rc = rcReschedule;314 rcStrict = rcReschedule; 318 315 #endif 319 316 } … … 321 318 else /* forward to directly connected device */ 322 319 { 323 R3PTRTYPE(PDMPCIDEV *) pPciDev = pPciRoot->PciBus.apDevices[p Addr->iDeviceFunc];320 R3PTRTYPE(PDMPCIDEV *) pPciDev = pPciRoot->PciBus.apDevices[pPciAddr->iDeviceFunc]; 324 321 if (pPciDev) 325 322 { 326 323 #ifdef IN_RING3 327 rc = VBOXSTRICTRC_TODO(pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, 328 pAddr->iRegister, val, cb)); 324 rcStrict = VINF_PDM_PCI_DO_DEFAULT; 325 if (pPciDev->Int.s.pfnConfigWrite) 326 rcStrict = pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, 327 pPciAddr->iRegister, cb, u32Value); 328 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 329 rcStrict = devpciR3CommonConfigWriteWorker(pDevIns, PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC), 330 pPciDev, pPciAddr->iRegister, cb, u32Value); 331 RT_NOREF(rcReschedule); 329 332 #else 330 rc = rcReschedule; 333 rcStrict = rcReschedule; 334 RT_NOREF(pDevIns, u32Value, cb); 331 335 #endif 332 336 } 333 337 } 334 338 335 Log2Func(("%02x:%02x.% d reg %x(%d) %x %Rrc\n",336 p Addr->iBus, pAddr->iDeviceFunc >> 3, pAddr->iDeviceFunc & 0x7, pAddr->iRegister, cb, val, rc));337 return rc ;339 Log2Func(("%02x:%02x.%u reg %x(%u) %x %Rrc\n", pPciAddr->iBus, pPciAddr->iDeviceFunc >> 3, pPciAddr->iDeviceFunc & 0x7, 340 pPciAddr->iRegister, cb, u32Value, VBOXSTRICTRC_VAL(rcStrict))); 341 return rcStrict; 338 342 } 339 343 … … 374 378 375 379 /* Perform configuration space write */ 376 rc = ich9pciConfigWrite(p This, &aPciAddr, u32, cb, VINF_IOM_R3_IOPORT_WRITE);380 rc = ich9pciConfigWrite(pDevIns, pThis, &aPciAddr, u32, cb, VINF_IOM_R3_IOPORT_WRITE); 377 381 } while (0); 378 382 … … 388 392 * Perform configuration space read. 389 393 */ 390 static int ich9pciConfigRead(PDEVPCIROOT pPciRoot, PciAddress* pPciAddr, int cb, 391 uint32_t *pu32, int rcReschedule) 392 { 393 int rc = VINF_SUCCESS; 394 static VBOXSTRICTRC ich9pciConfigRead(PDEVPCIROOT pPciRoot, PciAddress* pPciAddr, int cb, uint32_t *pu32Value, int rcReschedule) 395 { 396 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 394 397 #ifdef IN_RING3 395 398 NOREF(rcReschedule); … … 407 410 { 408 411 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigRead); 409 *pu32= pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), pPciAddr->iBus,410 pPciAddr->iDeviceFunc, pPciAddr->iRegister, cb);412 rcStrict = pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), pPciAddr->iBus, 413 pPciAddr->iDeviceFunc, pPciAddr->iRegister, cb, pu32Value); 411 414 } 412 415 else 413 *pu32 = 0xffffffff;416 *pu32Value = UINT32_MAX; 414 417 #else 415 rc = rcReschedule;418 rcStrict = rcReschedule; 416 419 #endif 417 420 } 418 421 else 419 *pu32 = 0xffffffff;422 *pu32Value = 0xffffffff; 420 423 } 421 424 else /* forward to directly connected device */ … … 425 428 { 426 429 #ifdef IN_RING3 427 *pu32 = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, pPciAddr->iRegister, cb); 430 rcStrict = VINF_PDM_PCI_DO_DEFAULT; 431 if (pPciDev->Int.s.pfnConfigRead) 432 rcStrict = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, 433 pPciAddr->iRegister, cb, pu32Value); 434 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 435 rcStrict = devpciR3CommonConfigReadWorker(pPciDev, pPciAddr->iRegister, cb, pu32Value); 428 436 #else 429 rc = rcReschedule;437 rcStrict = rcReschedule; 430 438 #endif 431 439 } 432 440 else 433 *pu32 = 0xffffffff;434 } 435 436 Log3Func(("%02x:%02x.%d reg %x(%d) gave %x %Rrc\n", 437 pPciAddr->i Bus, pPciAddr->iDeviceFunc >> 3, pPciAddr->iDeviceFunc & 0x7, pPciAddr->iRegister, cb, *pu32, rc));438 return rc ;441 *pu32Value = UINT32_MAX; 442 } 443 444 Log3Func(("%02x:%02x.%d reg %x(%d) gave %x %Rrc\n", pPciAddr->iBus, pPciAddr->iDeviceFunc >> 3, pPciAddr->iDeviceFunc & 0x7, 445 pPciAddr->iRegister, cb, *pu32Value, VBOXSTRICTRC_VAL(rcStrict) )); 446 return rcStrict; 439 447 } 440 448 … … 457 465 { 458 466 NOREF(pvUser); 459 int rc = VINF_SUCCESS;460 467 if (!(uPort % cb)) 461 468 { … … 465 472 PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_READ); 466 473 467 do 468 { 469 /* Configuration space mapping enabled? */ 470 if (!(pThis->uConfigReg & (1 << 31))) 471 { 472 rc = VINF_SUCCESS; 473 break; 474 } 475 474 /* Configuration space mapping enabled? */ 475 int rc; 476 if (!(pThis->uConfigReg & (1 << 31))) 477 rc = VINF_SUCCESS; 478 else 479 { 476 480 /* Decode target device and configuration space register */ 477 481 PciAddress aPciAddr; … … 479 483 480 484 /* Perform configuration space read */ 481 rc = 482 } while (0);485 rc = ich9pciConfigRead(pThis, &aPciAddr, cb, pu32, VINF_IOM_R3_IOPORT_READ); 486 } 483 487 484 488 PCI_UNLOCK(pDevIns); … … 528 532 } 529 533 530 static void ich9pciApicSetIrq(P DEVPCIBUS pBus, uint8_t uDevFn, PDMPCIDEV *pPciDev, int irq_num1, int iLevel,531 uint 32_t uTagSrc, int iForcedIrq)534 static void ich9pciApicSetIrq(PPDMDEVINS pDevIns, PDEVPCIBUS pBus, PDEVPCIBUSCC pBusCC, 535 uint8_t uDevFn, PDMPCIDEV *pPciDev, int irq_num1, int iLevel, uint32_t uTagSrc, int iForcedIrq) 532 536 { 533 537 /* This is only allowed to be called with a pointer to the root bus. */ … … 549 553 Log3Func(("%s: irq_num1=%d level=%d apic_irq=%d apic_level=%d irq_num1=%d uTagSrc=%#x\n", 550 554 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, apic_irq, apic_level, irq_num, uTagSrc)); 551 pBus ->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), apic_irq, apic_level, uTagSrc);555 pBusCC->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pDevIns, apic_irq, apic_level, uTagSrc); 552 556 553 557 if ((iLevel & PDM_IRQ_LEVEL_FLIP_FLOP) == PDM_IRQ_LEVEL_FLIP_FLOP) … … 562 566 Log3Func(("%s: irq_num1=%d level=%d apic_irq=%d apic_level=%d irq_num1=%d uTagSrc=%#x (flop)\n", 563 567 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, apic_irq, apic_level, irq_num, uTagSrc)); 564 pBus ->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), apic_irq, apic_level, uTagSrc);568 pBusCC->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pDevIns, apic_irq, apic_level, uTagSrc); 565 569 } 566 570 } else { 567 571 Log3Func(("(forced) %s: irq_num1=%d level=%d acpi_irq=%d uTagSrc=%#x\n", 568 572 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, iForcedIrq, uTagSrc)); 569 pBus ->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), iForcedIrq, iLevel, uTagSrc);570 } 571 } 572 573 static void ich9pciSetIrqInternal(P DEVPCIROOT pPciRoot, uint8_t uDevFn, PPDMPCIDEV pPciDev,574 int iIrq, int iLevel, uint32_t uTagSrc)573 pBusCC->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pDevIns, iForcedIrq, iLevel, uTagSrc); 574 } 575 } 576 577 static void ich9pciSetIrqInternal(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUSCC pBusCC, 578 uint8_t uDevFn, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc) 575 579 { 576 580 /* If MSI or MSI-X is enabled, PCI INTx# signals are disabled regardless of the PCI command … … 583 587 Assert(!MsixIsEnabled(pPciDev)); /* Not allowed -- see note above. */ 584 588 LogFlowFunc(("PCI Dev %p : MSI\n", pPciDev)); 585 PPDMDEVINS pDevIns = pPciRoot->PciBus.CTX_SUFF(pDevIns); 586 MsiNotify(pDevIns, pPciRoot->PciBus.CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc); 589 MsiNotify(pDevIns, pBusCC->CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc); 587 590 return; 588 591 } … … 591 594 { 592 595 LogFlowFunc(("PCI Dev %p : MSI-X\n", pPciDev)); 593 PPDMDEVINS pDevIns = pPciRoot->PciBus.CTX_SUFF(pDevIns); 594 MsixNotify(pDevIns, pPciRoot->PciBus.CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc); 596 MsixNotify(pDevIns, pBusCC->CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc); 595 597 return; 596 598 } … … 618 620 */ 619 621 /* safe, only needs to go to the config space array */ 620 ich9pciApicSetIrq(p Bus, uDevFn, pPciDev, -1, iLevel, uTagSrc, PDMPciDevGetInterruptLine(pPciDev));622 ich9pciApicSetIrq(pDevIns, pBus, pBusCC, uDevFn, pPciDev, -1, iLevel, uTagSrc, PDMPciDevGetInterruptLine(pPciDev)); 621 623 else 622 ich9pciApicSetIrq(p Bus, uDevFn, pPciDev, iIrq, iLevel, uTagSrc, -1);624 ich9pciApicSetIrq(pDevIns, pBus, pBusCC, uDevFn, pPciDev, iIrq, iLevel, uTagSrc, -1); 623 625 } 624 626 } … … 670 672 671 673 /* Perform configuration space write */ 672 int rc = ich9pciConfigWrite(p PciRoot, &aDest, u32, cb, VINF_IOM_R3_MMIO_WRITE);674 int rc = ich9pciConfigWrite(pDevIns, pPciRoot, &aDest, u32, cb, VINF_IOM_R3_MMIO_WRITE); 673 675 PCI_UNLOCK(pDevIns); 674 676 … … 770 772 uint32_t devpciR3GetCfg(PPDMPCIDEV pPciDev, int32_t iRegister, int cb) 771 773 { 772 return pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, iRegister, cb); 774 uint32_t u32Value = UINT32_MAX; 775 VBOXSTRICTRC rcStrict = VINF_PDM_PCI_DO_DEFAULT; 776 if (pPciDev->Int.s.pfnConfigRead) 777 rcStrict = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, iRegister, cb, &u32Value); 778 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 779 rcStrict = devpciR3CommonConfigReadWorker(pPciDev, iRegister, cb, &u32Value); 780 AssertRCSuccess(rcStrict); 781 return u32Value; 773 782 } 774 783 … … 779 788 } 780 789 781 void devpciR3SetCfg(PPDMPCIDEV pPciDev, int32_t iRegister, uint32_t u32, int cb) 782 { 783 pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, iRegister, u32, cb); 790 /** 791 * Worker for devpciR3SetByte(), devpciR3SetWord() and devpciR3SetDWord(), also 792 * used during state restore. 793 */ 794 void devpciR3SetCfg(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int32_t iRegister, uint32_t u32Value, int cb) 795 { 796 Assert(cb <= 4 && cb != 3); 797 VBOXSTRICTRC rcStrict = VINF_PDM_PCI_DO_DEFAULT; 798 if (pPciDev->Int.s.pfnConfigWrite) 799 rcStrict = pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, iRegister, cb, u32Value); 800 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 801 rcStrict = devpciR3CommonConfigWriteWorker(pDevIns, PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC), 802 pPciDev, iRegister, cb, u32Value); 803 AssertRCSuccess(rcStrict); 784 804 } 785 805 … … 790 810 static DECLCALLBACK(int) ich9pciRegisterMsi(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, PPDMMSIREG pMsiReg) 791 811 { 792 NOREF(pDevIns); 793 int rc; 794 795 rc = MsiR3Init(pPciDev, pMsiReg); 796 if (RT_FAILURE(rc)) 797 return rc; 798 799 rc = MsixR3Init(pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pPciHlp), pPciDev, pMsiReg); 800 if (RT_FAILURE(rc)) 801 return rc; 802 803 return VINF_SUCCESS; 812 //PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 813 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 814 815 int rc = MsiR3Init(pPciDev, pMsiReg); 816 if (RT_SUCCESS(rc)) 817 rc = MsixR3Init(pBusCC->CTX_SUFF(pPciHlp), pPciDev, pMsiReg); 818 819 return rc; 804 820 } 805 821 … … 871 887 872 888 /** 873 * @interface_method_impl{PDMPCIBUSREG,pfnSetConfigCallbacksR3} 874 */ 875 DECLCALLBACK(void) devpciR3CommonSetConfigCallbacks(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 876 PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld, 877 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld) 889 * @interface_method_impl{PDMPCIBUSREG,pfnInterceptConfigAccesses} 890 */ 891 DECLCALLBACK(void) devpciR3CommonInterceptConfigAccesses(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 892 PFNPCICONFIGREAD pfnRead, PFNPCICONFIGWRITE pfnWrite) 878 893 { 879 894 NOREF(pDevIns); 880 895 881 if (ppfnReadOld)882 *ppfnReadOld = pPciDev->Int.s.pfnConfigRead;883 896 pPciDev->Int.s.pfnConfigRead = pfnRead; 884 885 if (ppfnWriteOld)886 *ppfnWriteOld = pPciDev->Int.s.pfnConfigWrite;887 897 pPciDev->Int.s.pfnConfigWrite = pfnWrite; 888 898 } … … 979 989 980 990 981 static DECLCALLBACK(void) ich9pcibridgeConfigWrite(PPDMDEVINSR3 pDevIns, uint8_t uBus, uint8_t uDevice, uint32_t u32Address, uint32_t u32Value, unsigned cb) 982 { 983 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 984 985 LogFlowFunc(("pDevIns=%p uBus=%d uDevice=%d u32Address=%u u32Value=%u cb=%d\n", pDevIns, uBus, uDevice, u32Address, u32Value, cb)); 991 /** 992 * @callback_method_impl{FNPCIBRIDGECONFIGWRITE} 993 */ 994 static DECLCALLBACK(VBOXSTRICTRC) ich9pcibridgeConfigWrite(PPDMDEVINSR3 pDevIns, uint8_t uBus, uint8_t uDevice, 995 uint32_t u32Address, unsigned cb, uint32_t u32Value) 996 { 997 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 998 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 999 LogFlowFunc(("pDevIns=%p uBus=%d uDevice=%d u32Address=%#x cb=%d u32Value=%#x\n", pDevIns, uBus, uDevice, u32Address, cb, u32Value)); 986 1000 987 1001 /* If the current bus is not the target bus search for the bus which contains the device. */ … … 994 1008 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigWrite); 995 1009 pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), uBus, uDevice, 996 u32Address, u32Value, cb);1010 u32Address, cb, u32Value); 997 1011 } 998 1012 } … … 1004 1018 { 1005 1019 LogFunc(("%s: addr=%02x val=%08x len=%d\n", pPciDev->pszNameR3, u32Address, u32Value, cb)); 1006 /** @todo return rc */ 1007 pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, u32Value, cb); 1008 } 1009 } 1010 } 1011 1012 static DECLCALLBACK(uint32_t) ich9pcibridgeConfigRead(PPDMDEVINSR3 pDevIns, uint8_t uBus, uint8_t uDevice, uint32_t u32Address, unsigned cb) 1013 { 1014 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1015 uint32_t u32Value; 1016 1017 LogFlowFunc(("pDevIns=%p uBus=%d uDevice=%d u32Address=%u cb=%d\n", pDevIns, uBus, uDevice, u32Address, cb)); 1020 rcStrict = VINF_PDM_PCI_DO_DEFAULT; 1021 if (pPciDev->Int.s.pfnConfigWrite) 1022 rcStrict = pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, cb, u32Value); 1023 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 1024 rcStrict = devpciR3CommonConfigWriteWorker(pDevIns, PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC), 1025 pPciDev, u32Address, cb, u32Value); 1026 } 1027 } 1028 return rcStrict; 1029 } 1030 1031 /** 1032 * @callback_method_impl{FNPCIBRIDGECONFIGREAD} 1033 */ 1034 static DECLCALLBACK(VBOXSTRICTRC) ich9pcibridgeConfigRead(PPDMDEVINSR3 pDevIns, uint8_t uBus, uint8_t uDevice, 1035 uint32_t u32Address, unsigned cb, uint32_t *pu32Value) 1036 { 1037 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1038 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 1039 LogFlowFunc(("pDevIns=%p uBus=%d uDevice=%d u32Address=%#x cb=%d\n", pDevIns, uBus, uDevice, u32Address, cb)); 1018 1040 1019 1041 /* If the current bus is not the target bus search for the bus which contains the device. */ … … 1024 1046 if (pBridgeDevice) 1025 1047 { 1026 AssertPtr( 1027 u32Value= pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), uBus, uDevice,1028 u32Address, cb );1048 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigRead); 1049 rcStrict = pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), uBus, uDevice, 1050 u32Address, cb, pu32Value); 1029 1051 } 1030 1052 else 1031 u32Value = 0xffffffff;1053 *pu32Value = UINT32_MAX; 1032 1054 } 1033 1055 else … … 1037 1059 if (pPciDev) 1038 1060 { 1039 u32Value = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, cb); 1040 LogFunc(("%s: u32Address=%02x u32Value=%08x cb=%d\n", pPciDev->pszNameR3, u32Address, u32Value, cb)); 1061 rcStrict = VINF_PDM_PCI_DO_DEFAULT; 1062 if (pPciDev->Int.s.pfnConfigRead) 1063 rcStrict = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, cb, pu32Value); 1064 if (rcStrict == VINF_PDM_PCI_DO_DEFAULT) 1065 rcStrict = devpciR3CommonConfigReadWorker(pPciDev, u32Address, cb, pu32Value); 1066 LogFunc(("%s: u32Address=%02x *pu32Value=%#010x cb=%d\n", pPciDev->pszNameR3, u32Address, *pu32Value, cb)); 1041 1067 } 1042 1068 else 1043 u32Value = 0xffffffff;1044 } 1045 1046 return u32Value;1069 *pu32Value = UINT32_MAX; 1070 } 1071 1072 return rcStrict; 1047 1073 } 1048 1074 … … 1055 1081 * Common routine for restoring the config registers of a PCI device. 1056 1082 * 1083 * @param pDevIns The device instance of the PC bus. 1057 1084 * @param pDev The PCI device. 1058 1085 * @param pbSrcConfig The configuration register values to be loaded. 1059 1086 */ 1060 void devpciR3CommonRestoreConfig(PPDM PCIDEV pDev, uint8_t const *pbSrcConfig)1087 void devpciR3CommonRestoreConfig(PPDMDEVINS pDevIns, PPDMPCIDEV pDev, uint8_t const *pbSrcConfig) 1061 1088 { 1062 1089 /* … … 1199 1226 /* safe, only needs to go to the config space array */ 1200 1227 PDMPciDevSetCommand(pDev, 0); /* For remapping, see pciR3CommonLoadExec/ich9pciR3CommonLoadExec. */ 1201 pDev->Int.s.pfnConfigWrite(pDev->Int.s.CTX_SUFF(pDevIns), pDev, off, u32Src, cb);1228 devpciR3SetCfg(pDevIns, pDev, off, u32Src, cb); 1202 1229 } 1203 1230 } … … 1312 1339 * 1313 1340 * @returns VBox status code. 1341 * @param pDevIns The device instance of the bus. 1314 1342 * @param pBus The bus which data is being loaded. 1315 1343 * @param pSSM The saved state handle. … … 1317 1345 * @param uPass The pass. 1318 1346 */ 1319 static DECLCALLBACK(int) ich9pciR3CommonLoadExec(PDEVPCIBUS pBus, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)1320 { 1321 uint32_t u32;1322 int rc;1347 static int ich9pciR3CommonLoadExec(PPDMDEVINS pDevIns, PDEVPCIBUS pBus, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass) 1348 { 1349 uint32_t u32; 1350 int rc; 1323 1351 1324 1352 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass); … … 1342 1370 /* safe, only needs to go to the config space array */ 1343 1371 uint16_t u16 = PDMPciDevGetCommand(pDev); 1344 pDev->Int.s.pfnConfigWrite(pDev->Int.s.CTX_SUFF(pDevIns), pDev, VBOX_PCI_COMMAND, 0, 2);1372 devpciR3SetCfg(pDevIns, pDev, VBOX_PCI_COMMAND, 0 /*u32Value*/, 2 /*cb*/); 1345 1373 /* safe, only needs to go to the config space array */ 1346 1374 PDMPciDevSetCommand(pDev, u16); … … 1463 1491 break; 1464 1492 Assert(!pciDevIsPassthrough(pDev)); 1465 devpciR3CommonRestoreConfig(pDev , &DevTmp.abConfig[0]);1493 devpciR3CommonRestoreConfig(pDevIns, pDev, &DevTmp.abConfig[0]); 1466 1494 1467 1495 pDev->Int.s.uIrqPinState = DevTmp.Int.s.uIrqPinState; … … 1514 1542 AssertMsgFailedReturn(("u32=%#x\n", u32), rc); 1515 1543 1516 return ich9pciR3CommonLoadExec(p Bus, pSSM, uVersion, uPass);1544 return ich9pciR3CommonLoadExec(pDevIns, pBus, pSSM, uVersion, uPass); 1517 1545 } 1518 1546 … … 1520 1548 { 1521 1549 PDEVPCIBUS pThis = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 1522 return ich9pciR3CommonLoadExec(p This, pSSM, uVersion, uPass);1550 return ich9pciR3CommonLoadExec(pDevIns, pThis, pSSM, uVersion, uPass); 1523 1551 } 1524 1552 … … 1528 1556 1529 1557 1530 void devpciR3BiosInitSetRegionAddress(P DEVPCIBUS pBus, PPDMPCIDEV pPciDev, int iRegion, uint64_t addr)1558 void devpciR3BiosInitSetRegionAddress(PPDMDEVINS pDevIns, PDEVPCIBUS pBus, PPDMPCIDEV pPciDev, int iRegion, uint64_t addr) 1531 1559 { 1532 1560 NOREF(pBus); … … 1542 1570 1543 1571 /* Write address of the device. */ 1544 devpciR3SetDWord(p PciDev, uReg, (uint32_t)addr);1572 devpciR3SetDWord(pDevIns, pPciDev, uReg, (uint32_t)addr); 1545 1573 if (f64Bit) 1546 devpciR3SetDWord(p PciDev, uReg + 4, (uint32_t)(addr >> 32));1547 } 1548 1549 1550 static void ich9pciBiosInitBridge(P DEVPCIROOT pPciRoot, PDEVPCIBUS pBus)1574 devpciR3SetDWord(pDevIns, pPciDev, uReg + 4, (uint32_t)(addr >> 32)); 1575 } 1576 1577 1578 static void ich9pciBiosInitBridge(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus) 1551 1579 { 1552 1580 PPDMPCIDEV pBridge = &pBus->PciDev; … … 1563 1591 LogFunc(("Aligned I/O start address. New address %#x\n", pPciRoot->uPciBiosIo)); 1564 1592 } 1565 devpciR3SetByte(p Bridge, VBOX_PCI_IO_BASE, (pPciRoot->uPciBiosIo >> 8) & 0xf0);1593 devpciR3SetByte(pDevIns, pBridge, VBOX_PCI_IO_BASE, (pPciRoot->uPciBiosIo >> 8) & 0xf0); 1566 1594 1567 1595 /* The MMIO range for the bridge must be aligned to a 1MB boundary. */ … … 1571 1599 LogFunc(("Aligned MMIO start address. New address %#x\n", pPciRoot->uPciBiosMmio)); 1572 1600 } 1573 devpciR3SetWord(p Bridge, VBOX_PCI_MEMORY_BASE, (pPciRoot->uPciBiosMmio >> 16) & UINT32_C(0xffff0));1601 devpciR3SetWord(pDevIns, pBridge, VBOX_PCI_MEMORY_BASE, (pPciRoot->uPciBiosMmio >> 16) & UINT32_C(0xffff0)); 1574 1602 1575 1603 /* Save values to compare later to. */ … … 1578 1606 1579 1607 /* Init all devices behind the bridge (recursing to further buses). */ 1580 ich9pciBiosInitAllDevicesOnBus(p PciRoot, pBus);1608 ich9pciBiosInitAllDevicesOnBus(pDevIns, pPciRoot, pBus); 1581 1609 1582 1610 /* … … 1588 1616 /* Need again alignment to a 4KB boundary. */ 1589 1617 pPciRoot->uPciBiosIo = RT_ALIGN_32(pPciRoot->uPciBiosIo, _4K); 1590 devpciR3SetByte(p Bridge, VBOX_PCI_IO_LIMIT, ((pPciRoot->uPciBiosIo - 1) >> 8) & 0xf0);1618 devpciR3SetByte(pDevIns, pBridge, VBOX_PCI_IO_LIMIT, ((pPciRoot->uPciBiosIo - 1) >> 8) & 0xf0); 1591 1619 } 1592 1620 else 1593 1621 { 1594 devpciR3SetByte(p Bridge, VBOX_PCI_IO_BASE, 0xf0);1595 devpciR3SetByte(p Bridge, VBOX_PCI_IO_LIMIT, 0x00);1622 devpciR3SetByte(pDevIns, pBridge, VBOX_PCI_IO_BASE, 0xf0); 1623 devpciR3SetByte(pDevIns, pBridge, VBOX_PCI_IO_LIMIT, 0x00); 1596 1624 } 1597 1625 … … 1600 1628 { 1601 1629 pPciRoot->uPciBiosMmio = RT_ALIGN_32(pPciRoot->uPciBiosMmio, _1M); 1602 devpciR3SetWord(p Bridge, VBOX_PCI_MEMORY_LIMIT, ((pPciRoot->uPciBiosMmio - 1) >> 16) & UINT32_C(0xfff0));1630 devpciR3SetWord(pDevIns, pBridge, VBOX_PCI_MEMORY_LIMIT, ((pPciRoot->uPciBiosMmio - 1) >> 16) & UINT32_C(0xfff0)); 1603 1631 } 1604 1632 else 1605 1633 { 1606 devpciR3SetWord(p Bridge, VBOX_PCI_MEMORY_BASE, 0xfff0);1607 devpciR3SetWord(p Bridge, VBOX_PCI_MEMORY_LIMIT, 0x0000);1634 devpciR3SetWord(pDevIns, pBridge, VBOX_PCI_MEMORY_BASE, 0xfff0); 1635 devpciR3SetWord(pDevIns, pBridge, VBOX_PCI_MEMORY_LIMIT, 0x0000); 1608 1636 } 1609 1637 … … 1613 1641 * the base register than in the limit register. 1614 1642 */ 1615 devpciR3SetWord(p Bridge, VBOX_PCI_PREF_MEMORY_BASE, 0xfff0);1616 devpciR3SetWord(p Bridge, VBOX_PCI_PREF_MEMORY_LIMIT, 0x0000);1617 devpciR3SetDWord(p Bridge, VBOX_PCI_PREF_BASE_UPPER32, 0x00000000);1618 devpciR3SetDWord(p Bridge, VBOX_PCI_PREF_LIMIT_UPPER32, 0x00000000);1643 devpciR3SetWord(pDevIns, pBridge, VBOX_PCI_PREF_MEMORY_BASE, 0xfff0); 1644 devpciR3SetWord(pDevIns, pBridge, VBOX_PCI_PREF_MEMORY_LIMIT, 0x0000); 1645 devpciR3SetDWord(pDevIns, pBridge, VBOX_PCI_PREF_BASE_UPPER32, 0x00000000); 1646 devpciR3SetDWord(pDevIns, pBridge, VBOX_PCI_PREF_LIMIT_UPPER32, 0x00000000); 1619 1647 } 1620 1648 … … 1635 1663 } 1636 1664 1637 static void ich9pciBiosInitDeviceBARs(P DEVPCIROOT pPciRoot, PDEVPCIBUS pBus, PPDMPCIDEV pPciDev)1665 static void ich9pciBiosInitDeviceBARs(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, PPDMPCIDEV pPciDev) 1638 1666 { 1639 1667 int cRegions = ich9pciBiosInitDeviceGetRegions(pPciDev); … … 1669 1697 if (f64Bit) 1670 1698 { 1671 devpciR3SetDWord(p PciDev, u32Address, UINT32_C(0xffffffff));1672 devpciR3SetDWord(p PciDev, u32Address+4, UINT32_C(0xffffffff));1699 devpciR3SetDWord(pDevIns, pPciDev, u32Address, UINT32_C(0xffffffff)); 1700 devpciR3SetDWord(pDevIns, pPciDev, u32Address+4, UINT32_C(0xffffffff)); 1673 1701 cbRegSize64 = RT_MAKE_U64(devpciR3GetDWord(pPciDev, u32Address), 1674 1702 devpciR3GetDWord(pPciDev, u32Address+4)); … … 1684 1712 { 1685 1713 uint32_t cbRegSize32; 1686 devpciR3SetDWord(p PciDev, u32Address, UINT32_C(0xffffffff));1714 devpciR3SetDWord(pDevIns, pPciDev, u32Address, UINT32_C(0xffffffff)); 1687 1715 cbRegSize32 = devpciR3GetDWord(pPciDev, u32Address); 1688 1716 … … 1731 1759 uNew = (uNew + cbRegSize64 - 1) & ~(cbRegSize64 - 1); 1732 1760 LogFunc(("Start address of 64-bit MMIO region %u/%u is %#llx\n", iRegion, iRegion + 1, uNew)); 1733 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, iRegion, uNew);1761 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, iRegion, uNew); 1734 1762 fActiveMemRegion = true; 1735 1763 pPciRoot->uPciBiosMmio64 = uNew + cbRegSize64; … … 1743 1771 iRegion, pBus->iBus, pPciDev->uDevFn >> 3, pPciDev->uDevFn & 7, uVendor, uDevice)); /** @todo make this a VM start failure later. */ 1744 1772 /* Undo the mapping mess caused by the size probing. */ 1745 devpciR3SetDWord(p PciDev, u32Address, UINT32_C(0));1773 devpciR3SetDWord(pDevIns, pPciDev, u32Address, UINT32_C(0)); 1746 1774 } 1747 1775 } … … 1749 1777 { 1750 1778 LogFunc(("Start address of %s region %u is %#x\n", (fIsPio ? "I/O" : "MMIO"), iRegion, uNew)); 1751 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, iRegion, uNew);1779 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, iRegion, uNew); 1752 1780 if (fIsPio) 1753 1781 fActiveIORegion = true; … … 1769 1797 if (fActiveIORegion) 1770 1798 uCmd |= VBOX_PCI_COMMAND_IO; /* Enable I/O space access. */ 1771 devpciR3SetWord(p PciDev, VBOX_PCI_COMMAND, uCmd);1772 } 1773 1774 static bool ich9pciBiosInitDevicePrefetchableBARs(P DEVPCIROOT pPciRoot, PDEVPCIBUS pBus, PPDMPCIDEV pPciDev, bool fUse64Bit, bool fDryrun)1799 devpciR3SetWord(pDevIns, pPciDev, VBOX_PCI_COMMAND, uCmd); 1800 } 1801 1802 static bool ich9pciBiosInitDevicePrefetchableBARs(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, PPDMPCIDEV pPciDev, bool fUse64Bit, bool fDryrun) 1775 1803 { 1776 1804 int cRegions = ich9pciBiosInitDeviceGetRegions(pPciDev); … … 1792 1820 if (f64Bit) 1793 1821 { 1794 devpciR3SetDWord(p PciDev, u32Address, UINT32_C(0xffffffff));1795 devpciR3SetDWord(p PciDev, u32Address+4, UINT32_C(0xffffffff));1822 devpciR3SetDWord(pDevIns, pPciDev, u32Address, UINT32_C(0xffffffff)); 1823 devpciR3SetDWord(pDevIns, pPciDev, u32Address+4, UINT32_C(0xffffffff)); 1796 1824 cbRegSize64 = RT_MAKE_U64(devpciR3GetDWord(pPciDev, u32Address), 1797 1825 devpciR3GetDWord(pPciDev, u32Address+4)); … … 1802 1830 { 1803 1831 uint32_t cbRegSize32; 1804 devpciR3SetDWord(p PciDev, u32Address, UINT32_C(0xffffffff));1832 devpciR3SetDWord(pDevIns, pPciDev, u32Address, UINT32_C(0xffffffff)); 1805 1833 cbRegSize32 = devpciR3GetDWord(pPciDev, u32Address); 1806 1834 cbRegSize32 &= ~UINT32_C(0x0f); … … 1831 1859 { 1832 1860 LogFunc(("Start address of MMIO region %u is %#x\n", iRegion, uNew)); 1833 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, iRegion, uNew);1861 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, iRegion, uNew); 1834 1862 fActiveMemRegion = true; 1835 1863 } … … 1851 1879 { 1852 1880 LogFunc(("Start address of 64-bit MMIO region %u/%u is %#llx\n", iRegion, iRegion + 1, uNew)); 1853 devpciR3BiosInitSetRegionAddress(p Bus, pPciDev, iRegion, uNew);1881 devpciR3BiosInitSetRegionAddress(pDevIns, pBus, pPciDev, iRegion, uNew); 1854 1882 fActiveMemRegion = true; 1855 1883 } … … 1867 1895 if (fActiveMemRegion) 1868 1896 uCmd |= VBOX_PCI_COMMAND_MEMORY; /* Enable MMIO access. */ 1869 devpciR3SetWord(p PciDev, VBOX_PCI_COMMAND, uCmd);1897 devpciR3SetWord(pDevIns, pPciDev, VBOX_PCI_COMMAND, uCmd); 1870 1898 } 1871 1899 else … … 1875 1903 } 1876 1904 1877 static bool ich9pciBiosInitBridgePrefetchable(P DEVPCIROOT pPciRoot, PDEVPCIBUS pBus, bool fUse64Bit, bool fDryrun)1905 static bool ich9pciBiosInitBridgePrefetchable(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, bool fUse64Bit, bool fDryrun) 1878 1906 { 1879 1907 PPDMPCIDEV pBridge = &pBus->PciDev; … … 1888 1916 1889 1917 /* Init all devices behind the bridge (recursing to further buses). */ 1890 bool fRes = ich9pciBiosInitAllDevicesPrefetchableOnBus(p PciRoot, pBus, fUse64Bit, fDryrun);1918 bool fRes = ich9pciBiosInitAllDevicesPrefetchableOnBus(pDevIns, pPciRoot, pBus, fUse64Bit, fDryrun); 1891 1919 if (fDryrun) 1892 1920 return fRes; … … 1909 1937 uLimit = RT_ALIGN_32(pPciRoot->uPciBiosMmio, _1M) - 1; 1910 1938 } 1911 devpciR3SetDWord(p Bridge, VBOX_PCI_PREF_BASE_UPPER32, uBase >> 32);1912 devpciR3SetWord(p Bridge, VBOX_PCI_PREF_MEMORY_BASE, (uint32_t)(uBase >> 16) & UINT32_C(0xfff0));1913 devpciR3SetDWord(p Bridge, VBOX_PCI_PREF_LIMIT_UPPER32, uLimit >> 32);1914 devpciR3SetWord(p Bridge, VBOX_PCI_PREF_MEMORY_LIMIT, (uint32_t)(uLimit >> 16) & UINT32_C(0xfff0));1939 devpciR3SetDWord(pDevIns, pBridge, VBOX_PCI_PREF_BASE_UPPER32, uBase >> 32); 1940 devpciR3SetWord(pDevIns, pBridge, VBOX_PCI_PREF_MEMORY_BASE, (uint32_t)(uBase >> 16) & UINT32_C(0xfff0)); 1941 devpciR3SetDWord(pDevIns, pBridge, VBOX_PCI_PREF_LIMIT_UPPER32, uLimit >> 32); 1942 devpciR3SetWord(pDevIns, pBridge, VBOX_PCI_PREF_MEMORY_LIMIT, (uint32_t)(uLimit >> 16) & UINT32_C(0xfff0)); 1915 1943 1916 1944 return false; 1917 1945 } 1918 1946 1919 static bool ich9pciBiosInitAllDevicesPrefetchableOnBus(PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, bool fUse64Bit, bool fDryrun) 1947 static bool ich9pciBiosInitAllDevicesPrefetchableOnBus(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, 1948 bool fUse64Bit, bool fDryrun) 1920 1949 { 1921 1950 /* First pass: assign resources to all devices. */ … … 1931 1960 1932 1961 /* prefetchable memory mappings */ 1933 bool fRes = ich9pciBiosInitDevicePrefetchableBARs(p PciRoot, pBus, pPciDev, fUse64Bit, fDryrun);1962 bool fRes = ich9pciBiosInitDevicePrefetchableBARs(pDevIns, pPciRoot, pBus, pPciDev, fUse64Bit, fDryrun); 1934 1963 if (fRes) 1935 1964 { … … 1947 1976 PDEVPCIBUS pChildBus = PDMINS_2_DATA(pBridge->Int.s.CTX_SUFF(pDevIns), PDEVPCIBUS); 1948 1977 1949 bool fRes = ich9pciBiosInitBridgePrefetchable(p PciRoot, pChildBus, fUse64Bit, fDryrun);1978 bool fRes = ich9pciBiosInitBridgePrefetchable(pDevIns, pPciRoot, pChildBus, fUse64Bit, fDryrun); 1950 1979 if (fRes) 1951 1980 { … … 1957 1986 } 1958 1987 1959 static void ich9pciBiosInitAllDevicesOnBus(P DEVPCIROOT pPciRoot, PDEVPCIBUS pBus)1988 static void ich9pciBiosInitAllDevicesOnBus(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus) 1960 1989 { 1961 1990 /* First pass: assign resources to all devices and map the interrupt. */ … … 1971 2000 1972 2001 /* default memory mappings */ 1973 ich9pciBiosInitDeviceBARs(p PciRoot, pBus, pPciDev);2002 ich9pciBiosInitDeviceBARs(pDevIns, pPciRoot, pBus, pPciDev); 1974 2003 uint16_t uDevClass = devpciR3GetWord(pPciDev, VBOX_PCI_CLASS_DEVICE); 1975 2004 switch (uDevClass) … … 1977 2006 case 0x0101: 1978 2007 /* IDE controller */ 1979 devpciR3SetWord(p PciDev, 0x40, 0x8000); /* enable IDE0 */1980 devpciR3SetWord(p PciDev, 0x42, 0x8000); /* enable IDE1 */2008 devpciR3SetWord(pDevIns, pPciDev, 0x40, 0x8000); /* enable IDE0 */ 2009 devpciR3SetWord(pDevIns, pPciDev, 0x42, 0x8000); /* enable IDE1 */ 1981 2010 break; 1982 2011 case 0x0300: … … 1994 2023 */ 1995 2024 uint16_t uCmd = devpciR3GetWord(pPciDev, VBOX_PCI_COMMAND); 1996 devpciR3SetWord(p PciDev, VBOX_PCI_COMMAND, uCmd | VBOX_PCI_COMMAND_IO);2025 devpciR3SetWord(pDevIns, pPciDev, VBOX_PCI_COMMAND, uCmd | VBOX_PCI_COMMAND_IO); 1997 2026 break; 1998 2027 } … … 2019 2048 Log(("Using pin %d and IRQ %d for device %02x:%02x.%d\n", 2020 2049 iPin, iIrq, pBus->iBus, uDevFn>>3, uDevFn&7)); 2021 devpciR3SetByte(p PciDev, VBOX_PCI_INTERRUPT_LINE, iIrq);2050 devpciR3SetByte(pDevIns, pPciDev, VBOX_PCI_INTERRUPT_LINE, iIrq); 2022 2051 } 2023 2052 } … … 2031 2060 PDEVPCIBUS pChildBus = PDMINS_2_DATA(pBridge->Int.s.CTX_SUFF(pDevIns), PDEVPCIBUS); 2032 2061 2033 ich9pciBiosInitBridge(p PciRoot, pChildBus);2062 ich9pciBiosInitBridge(pDevIns, pPciRoot, pChildBus); 2034 2063 } 2035 2064 … … 2049 2078 uint64_t u64MMIOAddressBase = pPciRoot->uPciBiosMmio64; 2050 2079 2051 bool fProbe = ich9pciBiosInitBridgePrefetchable(p PciRoot, pChildBus, false /* fUse64Bit */, true /* fDryrun */);2080 bool fProbe = ich9pciBiosInitBridgePrefetchable(pDevIns, pPciRoot, pChildBus, false /* fUse64Bit */, true /* fDryrun */); 2052 2081 pPciRoot->uPciBiosMmio = u32MMIOAddressBase; 2053 2082 pPciRoot->uPciBiosMmio64 = u64MMIOAddressBase; 2054 2083 if (fProbe) 2055 2084 { 2056 fProbe = ich9pciBiosInitBridgePrefetchable(p PciRoot, pChildBus, true /* fUse64Bit */, true /* fDryrun */);2085 fProbe = ich9pciBiosInitBridgePrefetchable(pDevIns, pPciRoot, pChildBus, true /* fUse64Bit */, true /* fDryrun */); 2057 2086 pPciRoot->uPciBiosMmio = u32MMIOAddressBase; 2058 2087 pPciRoot->uPciBiosMmio64 = u64MMIOAddressBase; … … 2060 2089 LogRel(("PCI: unresolvable prefetchable memory behind bridge %02x:%02x.%d\n", pChildBus->iBus, pBridge->uDevFn >> 3, pBridge->uDevFn & 7)); 2061 2090 else 2062 ich9pciBiosInitBridgePrefetchable(p PciRoot, pChildBus, true /* fUse64Bit */, false /* fDryrun */);2091 ich9pciBiosInitBridgePrefetchable(pDevIns, pPciRoot, pChildBus, true /* fUse64Bit */, false /* fDryrun */); 2063 2092 } 2064 2093 else 2065 ich9pciBiosInitBridgePrefetchable(p PciRoot, pChildBus, false /* fUse64Bit */, false /* fDryrun */);2094 ich9pciBiosInitBridgePrefetchable(pDevIns, pPciRoot, pChildBus, false /* fUse64Bit */, false /* fDryrun */); 2066 2095 } 2067 2096 } … … 2082 2111 * @param uBusPrimary The primary bus number the bus is connected to. 2083 2112 */ 2084 static uint8_t ich9pciBiosInitBridgeTopology(PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, uint32_t *pbmUsed, uint8_t uBusPrimary) 2113 static uint8_t ich9pciBiosInitBridgeTopology(PPDMDEVINS pDevIns, PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, 2114 uint32_t *pbmUsed, uint8_t uBusPrimary) 2085 2115 { 2086 2116 PPDMPCIDEV pBridgeDev = &pBus->PciDev; … … 2095 2125 if (pBus->iBus != 0) 2096 2126 { 2097 devpciR3SetByte(p BridgeDev, VBOX_PCI_PRIMARY_BUS, uBusPrimary);2098 devpciR3SetByte(p BridgeDev, VBOX_PCI_SECONDARY_BUS, pBus->iBus);2127 devpciR3SetByte(pDevIns, pBridgeDev, VBOX_PCI_PRIMARY_BUS, uBusPrimary); 2128 devpciR3SetByte(pDevIns, pBridgeDev, VBOX_PCI_SECONDARY_BUS, pBus->iBus); 2099 2129 /* Since the subordinate bus value can only be finalized once we 2100 2130 * finished recursing through everything behind the bridge, the only … … 2103 2133 * (for our own sloppy emulation it apparently doesn't matter, but 2104 2134 * this is vital for real PCI bridges/devices in passthrough mode). */ 2105 devpciR3SetByte(p BridgeDev, VBOX_PCI_SUBORDINATE_BUS, 0xff);2135 devpciR3SetByte(pDevIns, pBridgeDev, VBOX_PCI_SUBORDINATE_BUS, 0xff); 2106 2136 } 2107 2137 … … 2113 2143 ("Device is not a PCI bridge but on the list of PCI bridges\n")); 2114 2144 PDEVPCIBUS pChildBus = PDMINS_2_DATA(pBridge->Int.s.CTX_SUFF(pDevIns), PDEVPCIBUS); 2115 uint8_t uMaxChildSubBus = ich9pciBiosInitBridgeTopology(p PciRoot, pChildBus, pbmUsed, pBus->iBus);2145 uint8_t uMaxChildSubBus = ich9pciBiosInitBridgeTopology(pDevIns, pPciRoot, pChildBus, pbmUsed, pBus->iBus); 2116 2146 uMaxSubNum = RT_MAX(uMaxSubNum, uMaxChildSubBus); 2117 2147 } 2118 2148 2119 2149 if (pBus->iBus != 0) 2120 devpciR3SetByte(p BridgeDev, VBOX_PCI_SUBORDINATE_BUS, uMaxSubNum);2150 devpciR3SetByte(pDevIns, pBridgeDev, VBOX_PCI_SUBORDINATE_BUS, uMaxSubNum); 2121 2151 for (uint32_t i = pBus->iBus; i <= uMaxSubNum; i++) 2122 2152 *pbmUsed |= RT_BIT_32(i); … … 2126 2156 * but on the other hand it can't hurt either. */ 2127 2157 if (pBus->iBus != 0) 2128 devpciR3SetWord(p BridgeDev, VBOX_PCI_COMMAND,2158 devpciR3SetWord(pDevIns, pBridgeDev, VBOX_PCI_COMMAND, 2129 2159 VBOX_PCI_COMMAND_IO 2130 2160 | VBOX_PCI_COMMAND_MEMORY … … 2132 2162 2133 2163 /* safe, only needs to go to the config space array */ 2134 Log2Func(("for bus %p: primary=%d secondary=%d subordinate=%d\n", 2135 pBus, 2136 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_PRIMARY_BUS), 2137 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_SECONDARY_BUS), 2138 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_SUBORDINATE_BUS) 2139 )); 2164 Log2Func(("for bus %p: primary=%d secondary=%d subordinate=%d\n", pBus, 2165 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_PRIMARY_BUS), 2166 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_SECONDARY_BUS), 2167 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_SUBORDINATE_BUS) )); 2140 2168 2141 2169 return uMaxSubNum; … … 2184 2212 AssertLogRel(pBus->iBus == 0); 2185 2213 uint32_t bmUsed = 0; 2186 ich9pciBiosInitBridgeTopology(p PciRoot, pBus, &bmUsed, 0);2214 ich9pciBiosInitBridgeTopology(pDevIns, pPciRoot, pBus, &bmUsed, 0); 2187 2215 2188 2216 /* 2189 2217 * Init all devices on bus 0 (recursing to further buses). 2190 2218 */ 2191 ich9pciBiosInitAllDevicesOnBus(p PciRoot, pBus);2219 ich9pciBiosInitAllDevicesOnBus(pDevIns, pPciRoot, pBus); 2192 2220 2193 2221 return VINF_SUCCESS; … … 2199 2227 2200 2228 /** 2201 * @callback_method_impl{PFNPCICONFIGREAD, Default config space read callback.} 2202 */ 2203 DECLCALLBACK(uint32_t) devpciR3CommonDefaultConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb) 2204 { 2205 NOREF(pDevIns); 2206 2229 * Reads config space for a device, ignoring interceptors. 2230 */ 2231 DECLHIDDEN(VBOXSTRICTRC) devpciR3CommonConfigReadWorker(PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb, uint32_t *pu32Value) 2232 { 2207 2233 uint32_t uValue; 2208 2234 if (uAddress + cb <= 256) … … 2246 2272 uValue = 0; 2247 2273 } 2248 return uValue; 2274 2275 *pu32Value = uValue; 2276 return VINF_SUCCESS; 2277 } 2278 2279 2280 /** 2281 * @interface_method_impl{PDMPCIBUSREGR3,pfnConfigRead} 2282 */ 2283 DECLCALLBACK(VBOXSTRICTRC) devpciR3CommonConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 2284 uint32_t uAddress, unsigned cb, uint32_t *pu32Value) 2285 { 2286 RT_NOREF(pDevIns); 2287 return devpciR3CommonConfigReadWorker(pPciDev, uAddress, cb, pu32Value); 2249 2288 } 2250 2289 … … 2254 2293 * 2255 2294 * @returns VBox status code. 2295 * @param pDevIns The PCI bus device instance. 2256 2296 * @param pDev The PCI device. 2257 2297 * @param iRegion The region to unmap. 2258 2298 */ 2259 static int devpciR3UnmapRegion(PPDM PCIDEV pDev, int iRegion)2299 static int devpciR3UnmapRegion(PPDMDEVINS pDevIns, PPDMPCIDEV pDev, int iRegion) 2260 2300 { 2261 2301 PCIIORegion *pRegion = &pDev->Int.s.aIORegions[iRegion]; … … 2275 2315 else 2276 2316 { 2277 PDEVPCIBUS pBus = pDev->Int.s.CTX_SUFF(pBus);2278 RTGCPHYS GCPhysBase = pRegion->addr;2279 if (pBus ->pPciHlpR3->pfnIsMMIOExBase(pBus->pDevInsR3, pDev->Int.s.pDevInsR3, GCPhysBase))2317 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 2318 RTGCPHYS GCPhysBase = pRegion->addr; 2319 if (pBusCC->pPciHlpR3->pfnIsMMIOExBase(pDevIns, pDev->Int.s.pDevInsR3, GCPhysBase)) 2280 2320 { 2281 2321 /* unmap it. */ … … 2299 2339 * 2300 2340 * @returns VINF_SUCCESS of DBGFSTOP result. 2341 * @param pDevIns The PCI bus device instance. 2301 2342 * @param pPciDev The PCI device to update the mappings for. 2302 2343 * @param fP2PBridge Whether this is a PCI to PCI bridge or not. 2303 2344 */ 2304 static VBOXSTRICTRC devpciR3UpdateMappings(PPDM PCIDEV pPciDev, bool fP2PBridge)2345 static VBOXSTRICTRC devpciR3UpdateMappings(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, bool fP2PBridge) 2305 2346 { 2306 2347 /* safe, only needs to go to the config space array */ … … 2406 2447 pPciDev->pszNameR3, iRegion, pRegion->addr, uNew, cbRegion, cbRegion)); 2407 2448 2408 devpciR3UnmapRegion(p PciDev, iRegion);2449 devpciR3UnmapRegion(pDevIns, pPciDev, iRegion); 2409 2450 pRegion->addr = uNew; 2410 2451 if (uNew != INVALID_PCI_ADDRESS) 2411 2452 { 2412 2453 int rc = pRegion->map_func(pPciDev->Int.s.pDevInsR3, pPciDev, iRegion, uNew, cbRegion, 2413 (PCIADDRESSSPACE) (pRegion->type));2454 (PCIADDRESSSPACE)pRegion->type); 2414 2455 AssertRC(rc); 2415 2456 } … … 2546 2587 2547 2588 /** 2548 * @callback_method_impl{PFNPCICONFIGWRITE, 2549 * Default config space write callback.} 2589 * Writes config space for a device, ignoring interceptors. 2550 2590 * 2551 2591 * See paragraph 7.5 of PCI Express specification (p. 349) for 2552 2592 * definition of registers and their writability policy. 2553 2593 */ 2554 DECLCALLBACK(VBOXSTRICTRC) devpciR3CommonDefaultConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 2555 uint32_t uAddress, uint32_t u32Value, unsigned cb) 2556 { 2557 NOREF(pDevIns); 2558 Assert(cb <= 4); 2559 VBOXSTRICTRC rcRet = VINF_SUCCESS; 2594 DECLHIDDEN(VBOXSTRICTRC) devpciR3CommonConfigWriteWorker(PPDMDEVINS pDevIns, PDEVPCIBUSCC pBusCC, 2595 PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb, uint32_t u32Value) 2596 { 2597 Assert(cb <= 4 && cb != 3); 2598 VBOXSTRICTRC rcStrict = VINF_SUCCESS; 2560 2599 2561 2600 if (uAddress + cb <= 256) … … 2566 2605 if ( pciDevIsMsiCapable(pPciDev) 2567 2606 && uAddress - (uint32_t)pPciDev->Int.s.u8MsiCapOffset < (uint32_t)pPciDev->Int.s.u8MsiCapSize) 2568 MsiR3PciConfigWrite(pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pDevIns), 2569 pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pPciHlp), 2570 pPciDev, uAddress, u32Value, cb); 2607 MsiR3PciConfigWrite(pDevIns, pBusCC->CTX_SUFF(pPciHlp), pPciDev, uAddress, u32Value, cb); 2571 2608 else if ( pciDevIsMsixCapable(pPciDev) 2572 2609 && uAddress - (uint32_t)pPciDev->Int.s.u8MsixCapOffset < (uint32_t)pPciDev->Int.s.u8MsixCapSize) 2573 MsixR3PciConfigWrite(pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pDevIns), 2574 pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pPciHlp), 2575 pPciDev, uAddress, u32Value, cb); 2610 MsixR3PciConfigWrite(pDevIns, pBusCC->CTX_SUFF(pPciHlp), pPciDev, uAddress, u32Value, cb); 2576 2611 else 2577 2612 { … … 2684 2719 */ 2685 2720 if (fUpdateMappings) 2686 rc Ret = devpciR3UpdateMappings(pPciDev, fP2PBridge);2721 rcStrict = devpciR3UpdateMappings(pDevIns, pPciDev, fP2PBridge); 2687 2722 } 2688 2723 } … … 2693 2728 AssertMsgFailed(("Write after end of PCI config space\n")); 2694 2729 2695 return rcRet; 2730 return rcStrict; 2731 } 2732 2733 2734 /** 2735 * @interface_method_impl{PDMPCIBUSREGR3,pfnConfigWrite} 2736 */ 2737 DECLCALLBACK(VBOXSTRICTRC) devpciR3CommonConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 2738 uint32_t uAddress, unsigned cb, uint32_t u32Value) 2739 { 2740 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 2741 return devpciR3CommonConfigWriteWorker(pDevIns, pBusCC, pPciDev, uAddress, cb, u32Value); 2696 2742 } 2697 2743 … … 2976 3022 * @interface_method_impl{PDMDEVREG,pfnConstruct} 2977 3023 */ 2978 static DECLCALLBACK(int) ich9pci Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)3024 static DECLCALLBACK(int) ich9pciR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 2979 3025 { 2980 3026 RT_NOREF1(iInstance); … … 3019 3065 * Init data. 3020 3066 */ 3021 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 3022 PDEVPCIBUS pBus = &pPciRoot->PciBus; 3067 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 3068 PDEVPCIBUS pBus = &pPciRoot->PciBus; 3069 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 3070 3023 3071 /* Zero out everything */ 3024 memset(pPciRoot, 0, sizeof(*pPciRoot)); 3072 Assert(ASMMemIsZero(pPciRoot, sizeof(*pPciRoot))); 3073 memset(pPciRoot, 0, sizeof(*pPciRoot)); /** @todo unnecessary as instance data is always set to zero by the allocator, see assertion above. */ 3074 3025 3075 /* And fill values */ 3026 3076 if (!fUseIoApic) … … 3036 3086 N_("Configuration error: Failed to read \"McfgLength\"")); 3037 3087 3038 pPciRoot->fUseIoApic = fUseIoApic; 3039 pPciRoot->pDevInsR3 = pDevIns; 3040 pPciRoot->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns); 3041 pPciRoot->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns); 3042 3043 pPciRoot->PciBus.fTypePiix3 = false; 3044 pPciRoot->PciBus.fTypeIch9 = true; 3045 pPciRoot->PciBus.fPureBridge = false; 3046 pPciRoot->PciBus.pDevInsR3 = pDevIns; 3047 pPciRoot->PciBus.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns); 3048 pPciRoot->PciBus.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns); 3088 pBusCC->pDevInsR3 = pDevIns; 3089 pPciRoot->fUseIoApic = fUseIoApic; 3090 pPciRoot->PciBus.fTypePiix3 = false; 3091 pPciRoot->PciBus.fTypeIch9 = true; 3092 pPciRoot->PciBus.fPureBridge = false; 3049 3093 pPciRoot->PciBus.papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV) * RT_ELEMENTS(pPciRoot->PciBus.apDevices)); 3050 3094 AssertLogRelReturn(pPciRoot->PciBus.papBridgesR3, VERR_NO_MEMORY); … … 3053 3097 * Register bus 3054 3098 */ 3055 PDMPCIBUSREG PciBusReg; 3056 PciBusReg.u32Version = PDM_PCIBUSREG_VERSION; 3057 PciBusReg.pfnRegisterR3 = pciR3MergedRegister; 3058 PciBusReg.pfnRegisterMsiR3 = ich9pciRegisterMsi; 3059 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister; 3060 PciBusReg.pfnSetConfigCallbacksR3 = devpciR3CommonSetConfigCallbacks; 3061 PciBusReg.pfnSetIrqR3 = ich9pciSetIrq; 3062 PciBusReg.pszSetIrqRC = fGCEnabled ? "ich9pciSetIrq" : NULL; 3063 PciBusReg.pszSetIrqR0 = fR0Enabled ? "ich9pciSetIrq" : NULL; 3064 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBus->pPciHlpR3, &pBus->iBus); 3099 PDMPCIBUSREGCC PciBusReg; 3100 PciBusReg.u32Version = PDM_PCIBUSREGCC_VERSION; 3101 PciBusReg.pfnRegisterR3 = pciR3MergedRegister; 3102 PciBusReg.pfnRegisterMsiR3 = ich9pciRegisterMsi; 3103 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister; 3104 PciBusReg.pfnInterceptConfigAccesses = devpciR3CommonInterceptConfigAccesses; 3105 PciBusReg.pfnConfigRead = devpciR3CommonConfigRead; 3106 PciBusReg.pfnConfigWrite = devpciR3CommonConfigWrite; 3107 PciBusReg.pfnSetIrqR3 = ich9pciSetIrq; 3108 PciBusReg.u32EndVersion = PDM_PCIBUSREGCC_VERSION; 3109 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBusCC->pPciHlpR3, &pBus->iBus); 3065 3110 if (RT_FAILURE(rc)) 3066 return PDMDEV_SET_ERROR(pDevIns, rc, 3067 N_("Failed to register ourselves as a PCI Bus")); 3111 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to register ourselves as a PCI Bus")); 3068 3112 Assert(pBus->iBus == 0); 3069 if (pBus ->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION)3113 if (pBusCC->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION) 3070 3114 return PDMDevHlpVMSetError(pDevIns, VERR_VERSION_MISMATCH, RT_SRC_POS, 3071 3115 N_("PCI helper version mismatch; got %#x expected %#x"), 3072 pBus->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION); 3073 3074 pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns); 3075 pBus->pPciHlpR0 = pBus->pPciHlpR3->pfnGetR0Helpers(pDevIns); 3116 pBusCC->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION); 3076 3117 3077 3118 /* … … 3177 3218 * @interface_method_impl{PDMDEVREG,pfnDestruct} 3178 3219 */ 3179 static DECLCALLBACK(int) ich9pci Destruct(PPDMDEVINS pDevIns)3220 static DECLCALLBACK(int) ich9pciR3Destruct(PPDMDEVINS pDevIns) 3180 3221 { 3181 3222 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); … … 3189 3230 3190 3231 3191 void devpciR3ResetDevice(PPDMPCIDEV pDev) 3232 /** 3233 * @param pDevIns The PCI bus device instance. 3234 * @param pDev The PCI device to reset. 3235 */ 3236 void devpciR3ResetDevice(PPDMDEVINS pDevIns, PPDMPCIDEV pDev) 3192 3237 { 3193 3238 /* Clear regions */ … … 3200 3245 == PCI_ADDRESS_SPACE_BAR64; 3201 3246 3202 devpciR3UnmapRegion(pDev , iRegion);3247 devpciR3UnmapRegion(pDevIns, pDev, iRegion); 3203 3248 3204 3249 if (f64Bit) … … 3213 3258 else 3214 3259 { 3215 devpciR3SetWord(pDev , VBOX_PCI_COMMAND,3260 devpciR3SetWord(pDevIns, pDev, VBOX_PCI_COMMAND, 3216 3261 devpciR3GetWord(pDev, VBOX_PCI_COMMAND) 3217 3262 & ~(VBOX_PCI_COMMAND_IO | VBOX_PCI_COMMAND_MEMORY | … … 3223 3268 if (!pciDevIsPci2PciBridge(pDev)) 3224 3269 { 3225 devpciR3SetByte(pDev , VBOX_PCI_CACHE_LINE_SIZE, 0x0);3226 devpciR3SetByte(pDev , VBOX_PCI_INTERRUPT_LINE, 0x0);3270 devpciR3SetByte(pDevIns, pDev, VBOX_PCI_CACHE_LINE_SIZE, 0x0); 3271 devpciR3SetByte(pDevIns, pDev, VBOX_PCI_INTERRUPT_LINE, 0x0); 3227 3272 } 3228 3273 3229 3274 /* Reset MSI message control. */ 3230 3275 if (pciDevIsMsiCapable(pDev)) 3231 { 3232 devpciR3SetWord(pDev, pDev->Int.s.u8MsiCapOffset + VBOX_MSI_CAP_MESSAGE_CONTROL, 3276 devpciR3SetWord(pDevIns, pDev, pDev->Int.s.u8MsiCapOffset + VBOX_MSI_CAP_MESSAGE_CONTROL, 3233 3277 devpciR3GetWord(pDev, pDev->Int.s.u8MsiCapOffset + VBOX_MSI_CAP_MESSAGE_CONTROL) & 0xff8e); 3234 }3235 3278 3236 3279 /* Reset MSI-X message control. */ 3237 3280 if (pciDevIsMsixCapable(pDev)) 3238 { 3239 devpciR3SetWord(pDev, pDev->Int.s.u8MsixCapOffset + VBOX_MSIX_CAP_MESSAGE_CONTROL, 3281 devpciR3SetWord(pDevIns, pDev, pDev->Int.s.u8MsixCapOffset + VBOX_MSIX_CAP_MESSAGE_CONTROL, 3240 3282 devpciR3GetWord(pDev, pDev->Int.s.u8MsixCapOffset + VBOX_MSIX_CAP_MESSAGE_CONTROL) & 0x3fff); 3241 }3242 3283 } 3243 3284 } … … 3286 3327 { 3287 3328 if (pBus->apDevices[uDevFn]) 3288 devpciR3ResetDevice(p Bus->apDevices[uDevFn]);3329 devpciR3ResetDevice(pDevIns, pBus->apDevices[uDevFn]); 3289 3330 } 3290 3331 … … 3299 3340 if (pBus->iBus != 0) 3300 3341 { 3301 devpciR3SetByte( &pBus->PciDev, VBOX_PCI_PRIMARY_BUS, 0);3302 devpciR3SetByte( &pBus->PciDev, VBOX_PCI_SECONDARY_BUS, 0);3303 devpciR3SetByte( &pBus->PciDev, VBOX_PCI_SUBORDINATE_BUS, 0);3342 devpciR3SetByte(pDevIns, &pBus->PciDev, VBOX_PCI_PRIMARY_BUS, 0); 3343 devpciR3SetByte(pDevIns, &pBus->PciDev, VBOX_PCI_SECONDARY_BUS, 0); 3344 devpciR3SetByte(pDevIns, &pBus->PciDev, VBOX_PCI_SUBORDINATE_BUS, 0); 3304 3345 /* Not resetting the address decoders of the bridge to 0, since the 3305 3346 * PCI-to-PCI Bridge spec says that there is no default value. */ … … 3324 3365 { 3325 3366 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 3326 3327 pBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);3328 pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns);3329 3367 3330 3368 /* Relocate RC pointers for the attached pci devices. */ … … 3347 3385 DECLCALLBACK(void) devpciR3RootRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta) 3348 3386 { 3349 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);3350 pPciRoot->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);3351 3352 3387 AssertCompileMemberOffset(DEVPCIROOT, PciBus, 0); 3353 3388 devpciR3BusRelocate(pDevIns, offDelta); … … 3368 3403 } 3369 3404 3405 /** 3406 * @interface_method_impl{PDMDEVREG,pfnDestruct} 3407 */ 3408 static DECLCALLBACK(int) ich9pcibridgeR3Destruct(PPDMDEVINS pDevIns) 3409 { 3410 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 3411 if (pBus->papBridgesR3) 3412 { 3413 PDMDevHlpMMHeapFree(pDevIns, pBus->papBridgesR3); 3414 pBus->papBridgesR3 = NULL; 3415 } 3416 return VINF_SUCCESS; 3417 } 3418 3370 3419 3371 3420 /** 3372 3421 * @interface_method_impl{PDMDEVREG,pfnConstruct} 3373 3422 */ 3374 static DECLCALLBACK(int) ich9pcibridgeConstruct(PPDMDEVINS pDevIns, 3375 int iInstance, 3376 PCFGMNODE pCfg) 3423 static DECLCALLBACK(int) ich9pcibridgeR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 3377 3424 { 3378 3425 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); … … 3421 3468 * Init data and register the PCI bus. 3422 3469 */ 3423 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 3470 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 3471 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 3424 3472 pBus->fTypePiix3 = false; 3425 3473 pBus->fTypeIch9 = true; 3426 3474 pBus->fPureBridge = true; 3427 pBus->pDevInsR3 = pDevIns; 3428 pBus->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns); 3429 pBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns); 3475 pBusCC->pDevInsR3 = pDevIns; 3430 3476 /** @todo r=klaus figure out how to extend this to allow PCIe config space 3431 3477 * extension, which increases the config space from 256 bytes to 4K. */ … … 3433 3479 AssertLogRelReturn(pBus->papBridgesR3, VERR_NO_MEMORY); 3434 3480 3435 PDMPCIBUSREG PciBusReg; 3436 PciBusReg.u32Version = PDM_PCIBUSREG_VERSION; 3437 PciBusReg.pfnRegisterR3 = pcibridgeR3MergedRegisterDevice; 3438 PciBusReg.pfnRegisterMsiR3 = ich9pciRegisterMsi; 3439 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister; 3440 PciBusReg.pfnSetConfigCallbacksR3 = devpciR3CommonSetConfigCallbacks; 3441 PciBusReg.pfnSetIrqR3 = ich9pcibridgeSetIrq; 3442 PciBusReg.pszSetIrqRC = fGCEnabled ? "ich9pcibridgeSetIrq" : NULL; 3443 PciBusReg.pszSetIrqR0 = fR0Enabled ? "ich9pcibridgeSetIrq" : NULL; 3444 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBus->pPciHlpR3, &pBus->iBus); 3481 PDMPCIBUSREGCC PciBusReg; 3482 PciBusReg.u32Version = PDM_PCIBUSREGCC_VERSION; 3483 PciBusReg.pfnRegisterR3 = pcibridgeR3MergedRegisterDevice; 3484 PciBusReg.pfnRegisterMsiR3 = ich9pciRegisterMsi; 3485 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister; 3486 PciBusReg.pfnInterceptConfigAccesses = devpciR3CommonInterceptConfigAccesses; 3487 PciBusReg.pfnConfigWrite = devpciR3CommonConfigWrite; 3488 PciBusReg.pfnConfigRead = devpciR3CommonConfigRead; 3489 PciBusReg.pfnSetIrqR3 = ich9pcibridgeSetIrq; 3490 PciBusReg.u32EndVersion = PDM_PCIBUSREGCC_VERSION; 3491 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBusCC->pPciHlpR3, &pBus->iBus); 3445 3492 if (RT_FAILURE(rc)) 3446 return PDMDEV_SET_ERROR(pDevIns, rc, 3447 N_("Failed to register ourselves as a PCI Bus")); 3493 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to register ourselves as a PCI Bus")); 3448 3494 Assert(pBus->iBus == (uint32_t)iInstance + 1); /* Can be removed when adding support for multiple bridge implementations. */ 3449 if (pBus ->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION)3495 if (pBusCC->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION) 3450 3496 return PDMDevHlpVMSetError(pDevIns, VERR_VERSION_MISMATCH, RT_SRC_POS, 3451 3497 N_("PCI helper version mismatch; got %#x expected %#x"), 3452 pBus->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION); 3453 3454 pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns); 3455 pBus->pPciHlpR0 = pBus->pPciHlpR3->pfnGetR0Helpers(pDevIns); 3498 pBusCC->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION); 3499 3456 3500 LogRel(("PCI: Registered bridge instance #%u as PDM bus no %u.\n", iInstance, pBus->iBus)); 3457 3501 … … 3574 3618 } 3575 3619 3576 /** 3577 * @interface_method_impl{PDMDEVREG,pfnDestruct} 3578 */ 3579 static DECLCALLBACK(int) ich9pcibridgeDestruct(PPDMDEVINS pDevIns) 3580 { 3581 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 3582 if (pBus->papBridgesR3) 3583 { 3584 PDMDevHlpMMHeapFree(pDevIns, pBus->papBridgesR3); 3585 pBus->papBridgesR3 = NULL; 3586 } 3587 return VINF_SUCCESS; 3588 } 3589 3590 #endif /* IN_RING3 */ 3620 #else /* !IN_RING3 */ 3621 3622 /** 3623 * @interface_method_impl{PDMDEVREGR0,pfnConstruct} 3624 */ 3625 DECLCALLBACK(int) ich9pciRZConstruct(PPDMDEVINS pDevIns) 3626 { 3627 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 3628 PDEVPCIROOT pGlobals = PDMINS_2_DATA(pDevIns, PDEVPCIROOT); 3629 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 3630 3631 PDMPCIBUSREGCC PciBusReg; 3632 PciBusReg.u32Version = PDM_PCIBUSREGCC_VERSION; 3633 PciBusReg.iBus = pGlobals->PciBus.iBus; 3634 PciBusReg.pfnSetIrq = ich9pciSetIrq; 3635 PciBusReg.u32EndVersion = PDM_PCIBUSREGCC_VERSION; 3636 int rc = PDMDevHlpPCIBusSetUpContext(pDevIns, &PciBusReg, &pBusCC->CTX_SUFF(pPciHlp)); 3637 AssertRC(rc); 3638 3639 /* Disable default device locking. */ 3640 rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns)); 3641 AssertRCReturn(rc, rc); 3642 3643 return rc; 3644 } 3645 3646 3647 /** 3648 * @interface_method_impl{PDMDEVREGR0,pfnConstruct} 3649 */ 3650 DECLCALLBACK(int) ich9pcibridgeRZConstruct(PPDMDEVINS pDevIns) 3651 { 3652 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 3653 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 3654 PDEVPCIBUSCC pBusCC = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC); 3655 3656 PDMPCIBUSREGCC PciBusReg; 3657 PciBusReg.u32Version = PDM_PCIBUSREGCC_VERSION; 3658 PciBusReg.iBus = pBus->iBus; 3659 PciBusReg.pfnSetIrq = ich9pcibridgeSetIrq; 3660 PciBusReg.u32EndVersion = PDM_PCIBUSREGCC_VERSION; 3661 int rc = PDMDevHlpPCIBusSetUpContext(pDevIns, &PciBusReg, &pBusCC->CTX_SUFF(pPciHlp)); 3662 AssertRC(rc); 3663 3664 /* Disable default device locking. */ 3665 rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns)); 3666 AssertRCReturn(rc, rc); 3667 3668 return rc; 3669 } 3670 3671 #endif /* !IN_RING3 */ 3591 3672 3592 3673 /** … … 3603 3684 /* .uSharedVersion = */ 42, 3604 3685 /* .cbInstanceShared = */ sizeof(DEVPCIROOT), 3605 /* .cbInstanceCC = */ 0,3606 /* .cbInstanceRC = */ 0,3686 /* .cbInstanceCC = */ sizeof(CTX_SUFF(DEVPCIBUS)), 3687 /* .cbInstanceRC = */ sizeof(DEVPCIBUSRC), 3607 3688 /* .cMaxPciDevices = */ 1, 3608 3689 /* .cMaxMsixVectors = */ 0, … … 3611 3692 /* .pszRCMod = */ "VBoxDDRC.rc", 3612 3693 /* .pszR0Mod = */ "VBoxDDR0.r0", 3613 /* .pfnConstruct = */ ich9pci Construct,3614 /* .pfnDestruct = */ ich9pci Destruct,3694 /* .pfnConstruct = */ ich9pciR3Construct, 3695 /* .pfnDestruct = */ ich9pciR3Destruct, 3615 3696 /* .pfnRelocate = */ devpciR3RootRelocate, 3616 3697 /* .pfnMemSetup = */ NULL, … … 3635 3716 #elif defined(IN_RING0) 3636 3717 /* .pfnEarlyConstruct = */ NULL, 3637 /* .pfnConstruct = */ NULL,3718 /* .pfnConstruct = */ ich9pciRZConstruct, 3638 3719 /* .pfnDestruct = */ NULL, 3639 3720 /* .pfnFinalDestruct = */ NULL, … … 3648 3729 /* .pfnReserved7 = */ NULL, 3649 3730 #elif defined(IN_RC) 3650 /* .pfnConstruct = */ NULL,3731 /* .pfnConstruct = */ ich9pciRZConstruct, 3651 3732 /* .pfnReserved0 = */ NULL, 3652 3733 /* .pfnReserved1 = */ NULL, … … 3677 3758 /* .uSharedVersion = */ 42, 3678 3759 /* .cbInstanceShared = */ sizeof(DEVPCIBUS), 3679 /* .cbInstanceCC = */ 0,3760 /* .cbInstanceCC = */ sizeof(CTX_SUFF(DEVPCIBUS)), 3680 3761 /* .cbInstanceRC = */ 0, 3681 3762 /* .cMaxPciDevices = */ 1, … … 3685 3766 /* .pszRCMod = */ "VBoxDDRC.rc", 3686 3767 /* .pszR0Mod = */ "VBoxDDR0.r0", 3687 /* .pfnConstruct = */ ich9pcibridge Construct,3688 /* .pfnDestruct = */ ich9pcibridge Destruct,3768 /* .pfnConstruct = */ ich9pcibridgeR3Construct, 3769 /* .pfnDestruct = */ ich9pcibridgeR3Destruct, 3689 3770 /* .pfnRelocate = */ devpciR3BusRelocate, 3690 3771 /* .pfnMemSetup = */ NULL, … … 3709 3790 #elif defined(IN_RING0) 3710 3791 /* .pfnEarlyConstruct = */ NULL, 3711 /* .pfnConstruct = */ NULL,3792 /* .pfnConstruct = */ ich9pcibridgeRZConstruct, 3712 3793 /* .pfnDestruct = */ NULL, 3713 3794 /* .pfnFinalDestruct = */ NULL, … … 3722 3803 /* .pfnReserved7 = */ NULL, 3723 3804 #elif defined(IN_RC) 3724 /* .pfnConstruct = */ NULL,3805 /* .pfnConstruct = */ ich9pcibridgeRZConstruct, 3725 3806 /* .pfnReserved0 = */ NULL, 3726 3807 /* .pfnReserved1 = */ NULL, -
trunk/src/VBox/Devices/Bus/DevPciInternal.h
r76565 r80943 29 29 30 30 /** 31 * PCI bus instance (common to both).31 * PCI bus shared instance data (common to both PCI buses). 32 32 */ 33 33 typedef struct DEVPCIBUS … … 42 42 uint32_t fTypePiix3 : 1; 43 43 /** Set if ICH9 type. */ 44 uint32_t fTypeIch9 : 1;44 uint32_t fTypeIch9 : 1; 45 45 /** Set if this is a pure bridge, i.e. not part of DEVPCIGLOBALS struct. */ 46 46 uint32_t fPureBridge : 1; … … 48 48 uint32_t uReservedConfigFlags : 29; 49 49 50 /** Array of bridges attached to the bus. */ 51 R3PTRTYPE(PPDMPCIDEV *) papBridgesR3; 52 /** Cache line align apDevices. */ 53 uint32_t au32Alignment1[HC_ARCH_BITS == 32 ? 3+8 : 2+8]; 54 /** Array of PCI devices. We assume 32 slots, each with 8 functions. */ 55 R3PTRTYPE(PPDMPCIDEV) apDevices[256]; 56 57 /** The PCI device for the PCI bridge. */ 58 PDMPCIDEV PciDev; 59 } DEVPCIBUS; 60 /** Pointer to PCI bus shared instance data. */ 61 typedef DEVPCIBUS *PDEVPCIBUS; 62 63 /** 64 * PCI bus ring-3 instance data (common to both PCI buses). 65 */ 66 typedef struct DEVPCIBUSR3 67 { 50 68 /** R3 pointer to the device instance. */ 51 69 PPDMDEVINSR3 pDevInsR3; 52 70 /** Pointer to the PCI R3 helpers. */ 53 71 PCPDMPCIHLPR3 pPciHlpR3; 54 72 } DEVPCIBUSR3; 73 /** Pointer to PCI bus ring-3 instance data. */ 74 typedef DEVPCIBUSR3 *PDEVPCIBUSR3; 75 76 /** 77 * PCI bus ring-0 instance data (common to both PCI buses). 78 */ 79 typedef struct DEVPCIBUSR0 80 { 55 81 /** R0 pointer to the device instance. */ 56 82 PPDMDEVINSR0 pDevInsR0; 57 83 /** Pointer to the PCI R0 helpers. */ 58 84 PCPDMPCIHLPR0 pPciHlpR0; 59 60 /** RC pointer to the device instance. */ 85 } DEVPCIBUSR0; 86 /** Pointer to PCI bus ring-0 instance data. */ 87 typedef DEVPCIBUSR0 *PDEVPCIBUSR0; 88 89 /** 90 * PCI bus raw-mode instance data (common to both PCI buses). 91 */ 92 typedef struct DEVPCIBUSRC 93 { 94 /** R0 pointer to the device instance. */ 61 95 PPDMDEVINSRC pDevInsRC; 62 /** Pointer to the PCI RChelpers. */96 /** Pointer to the PCI raw-mode helpers. */ 63 97 PCPDMPCIHLPRC pPciHlpRC; 64 65 /** Array of bridges attached to the bus. */ 66 R3PTRTYPE(PPDMPCIDEV *) papBridgesR3; 67 #if HC_ARCH_BITS == 32 68 uint32_t au32Alignment1[5]; /**< Cache line align apDevices. */ 69 #endif 70 /** Array of PCI devices. We assume 32 slots, each with 8 functions. */ 71 R3PTRTYPE(PPDMPCIDEV) apDevices[256]; 72 73 /** The PCI device for the PCI bridge. */ 74 PDMPCIDEV PciDev; 75 } DEVPCIBUS; 76 /** Pointer to a PCI bus instance. */ 77 typedef DEVPCIBUS *PDEVPCIBUS; 98 } DEVPCIBUSRC; 99 /** Pointer to PCI bus raw-mode instance data. */ 100 typedef DEVPCIBUSRC *PDEVPCIBUSRC; 101 102 /** DEVPCIBUSR3, DEVPCIBUSR0 or DEVPCIBUSRC depending on context. */ 103 typedef CTX_SUFF(DEVPCIBUS) DEVPCIBUSCC; 104 /** PDEVPCIBUSR3, PDEVPCIBUSR0 or PDEVPCIBUSRC depending on context. */ 105 typedef CTX_SUFF(PDEVPCIBUS) PDEVPCIBUSCC; 78 106 79 107 … … 99 127 100 128 /** 101 * PCI Globals - This is the host-to-pci bridge and the root bus .129 * PCI Globals - This is the host-to-pci bridge and the root bus, shared data. 102 130 * 103 131 * @note Only used by the root bus, not the bridges. … … 109 137 DEVPCIBUS PciBus; 110 138 111 /** R3 pointer to the device instance. */112 PPDMDEVINSR3 pDevInsR3;113 /** R0 pointer to the device instance. */114 PPDMDEVINSR0 pDevInsR0;115 /** RC pointer to the device instance. */116 PPDMDEVINSRC pDevInsRC;117 118 139 /** I/O APIC usage flag (always true of ICH9, see constructor). */ 119 140 bool fUseIoApic; 120 141 /** Reserved for future config flags. */ 121 bool afFutureFlags[3 ];142 bool afFutureFlags[3+4]; 122 143 /** Physical address of PCI config space MMIO region. */ 123 144 uint64_t u64PciConfigMMioAddress; … … 163 184 /** Pointer to PCI device globals. */ 164 185 typedef DEVPCIROOT *PDEVPCIROOT; 165 166 167 186 /** Converts a PCI bus device instance pointer to a DEVPCIBUS pointer. */ 168 187 #define DEVINS_2_DEVPCIBUS(pDevIns) (&PDMINS_2_DATA(pDevIns, PDEVPCIROOT)->PciBus) … … 176 195 #define PCI_LOCK(pDevIns, rc) \ 177 196 do { \ 178 int rc2 = DEVINS_2_DEVPCIBUS(pDevIns)->CTX_SUFF(pPciHlp)->pfnLock((pDevIns), rc); \197 int rc2 = PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC)->CTX_SUFF(pPciHlp)->pfnLock((pDevIns), rc); \ 179 198 if (rc2 != VINF_SUCCESS) \ 180 199 return rc2; \ 181 200 } while (0) 182 201 #define PCI_UNLOCK(pDevIns) \ 183 DEVINS_2_DEVPCIBUS(pDevIns)->CTX_SUFF(pPciHlp)->pfnUnlock(pDevIns)202 PDMINS_2_DATA_CC(pDevIns, PDEVPCIBUSCC)->CTX_SUFF(pPciHlp)->pfnUnlock(pDevIns) 184 203 185 204 … … 192 211 DECLCALLBACK(int) devpciR3CommonIORegionRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iRegion, RTGCPHYS cbRegion, 193 212 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback); 194 DECLCALLBACK(void) devpciR3CommonSetConfigCallbacks(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 195 PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld, 196 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld); 197 DECLCALLBACK(uint32_t) devpciR3CommonDefaultConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb); 198 DECLCALLBACK(VBOXSTRICTRC) devpciR3CommonDefaultConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 199 uint32_t uAddress, uint32_t u32Value, unsigned cb); 200 void devpciR3CommonRestoreConfig(PPDMPCIDEV pDev, uint8_t const *pbSrcConfig); 213 DECLCALLBACK(void) devpciR3CommonInterceptConfigAccesses(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 214 PFNPCICONFIGREAD pfnRead, PFNPCICONFIGWRITE pfnWrite); 215 DECLCALLBACK(VBOXSTRICTRC) devpciR3CommonConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 216 uint32_t uAddress, unsigned cb, uint32_t *pu32Value); 217 DECLHIDDEN(VBOXSTRICTRC) devpciR3CommonConfigReadWorker(PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb, uint32_t *pu32Value); 218 DECLCALLBACK(VBOXSTRICTRC) devpciR3CommonConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, 219 uint32_t uAddress, unsigned cb, uint32_t u32Value); 220 DECLHIDDEN(VBOXSTRICTRC) devpciR3CommonConfigWriteWorker(PPDMDEVINS pDevIns, PDEVPCIBUSCC pBusCC, 221 PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb, uint32_t u32Value); 222 void devpciR3CommonRestoreConfig(PPDMDEVINS pDevIns, PPDMPCIDEV pDev, uint8_t const *pbSrcConfig); 201 223 int devpciR3CommonRestoreRegions(PSSMHANDLE pSSM, PPDMPCIDEV pPciDev, PPCIIOREGION paIoRegions, bool fNewState); 202 void devpciR3ResetDevice(PPDM PCIDEV pDev);203 void devpciR3BiosInitSetRegionAddress(P DEVPCIBUS pBus, PPDMPCIDEV pPciDev, int iRegion, uint64_t addr);224 void devpciR3ResetDevice(PPDMDEVINS pDevIns, PPDMPCIDEV pDev); 225 void devpciR3BiosInitSetRegionAddress(PPDMDEVINS pDevIns, PDEVPCIBUS pBus, PPDMPCIDEV pPciDev, int iRegion, uint64_t addr); 204 226 uint32_t devpciR3GetCfg(PPDMPCIDEV pPciDev, int32_t iRegister, int cb); 205 void devpciR3SetCfg(PPDM PCIDEV pPciDev, int32_t iRegister, uint32_t u32, int cb);227 void devpciR3SetCfg(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int32_t iRegister, uint32_t u32, int cb); 206 228 207 229 DECLINLINE(uint8_t) devpciR3GetByte(PPDMPCIDEV pPciDev, int32_t iRegister) … … 220 242 } 221 243 222 DECLINLINE(void) devpciR3SetByte(PPDM PCIDEV pPciDev, int32_t iRegister, uint8_t u8)223 { 224 devpciR3SetCfg(p PciDev, iRegister, u8, 1);225 } 226 227 DECLINLINE(void) devpciR3SetWord(PPDM PCIDEV pPciDev, int32_t iRegister, uint16_t u16)228 { 229 devpciR3SetCfg(p PciDev, iRegister, u16, 2);230 } 231 232 DECLINLINE(void) devpciR3SetDWord(PPDM PCIDEV pPciDev, int32_t iRegister, uint32_t u32)233 { 234 devpciR3SetCfg(p PciDev, iRegister, u32, 4);244 DECLINLINE(void) devpciR3SetByte(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int32_t iRegister, uint8_t u8) 245 { 246 devpciR3SetCfg(pDevIns, pPciDev, iRegister, u8, 1); 247 } 248 249 DECLINLINE(void) devpciR3SetWord(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int32_t iRegister, uint16_t u16) 250 { 251 devpciR3SetCfg(pDevIns, pPciDev, iRegister, u16, 2); 252 } 253 254 DECLINLINE(void) devpciR3SetDWord(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int32_t iRegister, uint32_t u32) 255 { 256 devpciR3SetCfg(pDevIns, pPciDev, iRegister, u32, 4); 235 257 } 236 258 -
trunk/src/VBox/Devices/Bus/DevPciMerge1.cpp.h
r80531 r80943 60 60 * function number (0-7). 61 61 * @param pszName Device name (static but not unique). 62 * @param pfnConfigRead The default config read method.63 * @param pfnConfigWrite The default config read method.64 62 * 65 63 * @remarks Caller enters the PDM critical section. 66 64 */ 67 65 static int pciR3MergedRegisterDeviceOnBus(PPDMDEVINS pDevIns, PDEVPCIBUS pBus, PPDMPCIDEV pPciDev, uint32_t fFlags, 68 uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName, 69 PFNPCICONFIGREAD pfnConfigRead, PFNPCICONFIGWRITE pfnConfigWrite) 66 uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName) 70 67 { 71 68 /* … … 197 194 pPciDev->Int.s.pBusR0 = PDMINS_2_DATA_R0PTR(pDevIns); 198 195 pPciDev->Int.s.pBusRC = PDMINS_2_DATA_RCPTR(pDevIns); 199 pPciDev->Int.s.pfnConfigRead = pfnConfigRead;200 pPciDev->Int.s.pfnConfigWrite = pfnConfigWrite;196 pPciDev->Int.s.pfnConfigRead = NULL; 197 pPciDev->Int.s.pfnConfigWrite = NULL; 201 198 202 199 /* Remember and mark bridges. */ … … 225 222 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 226 223 AssertCompileMemberOffset(DEVPCIROOT, PciBus, 0); 227 return pciR3MergedRegisterDeviceOnBus(pDevIns, pBus, pPciDev, fFlags, uPciDevNo, uPciFunNo, pszName, 228 devpciR3CommonDefaultConfigRead, devpciR3CommonDefaultConfigWrite); 224 return pciR3MergedRegisterDeviceOnBus(pDevIns, pBus, pPciDev, fFlags, uPciDevNo, uPciFunNo, pszName); 229 225 } 230 226 … … 237 233 { 238 234 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS); 239 return pciR3MergedRegisterDeviceOnBus(pDevIns, pBus, pPciDev, fFlags, uPciDevNo, uPciFunNo, pszName, 240 devpciR3CommonDefaultConfigRead, devpciR3CommonDefaultConfigWrite); 241 } 242 235 return pciR3MergedRegisterDeviceOnBus(pDevIns, pBus, pPciDev, fFlags, uPciDevNo, uPciFunNo, pszName); 236 } 237 -
trunk/src/VBox/Devices/Bus/MsiCommon.cpp
r76553 r80943 33 33 uint32_t idxMessageControl = pDev->Int.s.u8MsiCapOffset + VBOX_MSI_CAP_MESSAGE_CONTROL; 34 34 #ifdef IN_RING3 35 if (pciDevIsPassthrough(pDev)) 36 return pDev->Int.s.pfnConfigRead(pDev->Int.s.CTX_SUFF(pDevIns), pDev, idxMessageControl, 2); 35 if (pciDevIsPassthrough(pDev) && pDev->Int.s.pfnConfigRead) 36 { 37 uint32_t u32Value = 0; 38 VBOXSTRICTRC rcStrict = pDev->Int.s.pfnConfigRead(pDev->Int.s.CTX_SUFF(pDevIns), pDev, idxMessageControl, 2, &u32Value); 39 AssertRCSuccess(rcStrict); 40 return (uint16_t)u32Value; 41 } 37 42 #endif 38 43 return PCIDevGetWord(pDev, idxMessageControl);
Note:
See TracChangeset
for help on using the changeset viewer.