VirtualBox

source: vbox/trunk/src/VBox/Devices/Bus/DevPciIch9.cpp@ 64700

Last change on this file since 64700 was 64700, checked in by vboxsync, 8 years ago

ich9pciBiosInitBridgeTopology: Missed VBOX_PCI_SUBORDINATE_BUS, now it works.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 111.7 KB
Line 
1/* $Id: DevPciIch9.cpp 64700 2016-11-17 18:32:18Z vboxsync $ */
2/** @file
3 * DevPCI - ICH9 southbridge PCI bus emulation device.
4 *
5 * @remarks We'll be slowly promoting the code in this file to common PCI bus
6 * code. Function without 'static' and using 'devpci' as prefix is
7 * also used by DevPCI.cpp and have a prototype in DevPciInternal.h.
8 *
9 * For the time being the DevPciMerge1.cpp.h file will remain separate,
10 * due to 5.1. We can merge it into this one later in the dev cycle.
11 */
12
13/*
14 * Copyright (C) 2010-2016 Oracle Corporation
15 *
16 * This file is part of VirtualBox Open Source Edition (OSE), as
17 * available from http://www.virtualbox.org. This file is free software;
18 * you can redistribute it and/or modify it under the terms of the GNU
19 * General Public License (GPL) as published by the Free Software
20 * Foundation, in version 2 as it comes in the "COPYING" file of the
21 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
22 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
23 */
24
25
26/*********************************************************************************************************************************
27* Header Files *
28*********************************************************************************************************************************/
29#define LOG_GROUP LOG_GROUP_DEV_PCI
30#define PDMPCIDEV_INCLUDE_PRIVATE /* Hack to get pdmpcidevint.h included at the right point. */
31#include <VBox/vmm/pdmpcidev.h>
32
33#include <VBox/msi.h>
34#include <VBox/vmm/pdmdev.h>
35#include <VBox/vmm/mm.h>
36#include <iprt/asm.h>
37#include <iprt/assert.h>
38#include <iprt/string.h>
39#ifdef IN_RING3
40# include <iprt/mem.h>
41#endif
42
43#include "PciInline.h"
44#include "VBoxDD.h"
45#include "MsiCommon.h"
46#include "DevPciInternal.h"
47
48
49/*********************************************************************************************************************************
50* Structures and Typedefs *
51*********************************************************************************************************************************/
52/**
53 * PCI configuration space address.
54 */
55typedef struct
56{
57 uint8_t iBus;
58 uint8_t iDeviceFunc;
59 uint16_t iRegister;
60} PciAddress;
61
62
63/*********************************************************************************************************************************
64* Defined Constants And Macros *
65*********************************************************************************************************************************/
66/** @def VBOX_ICH9PCI_SAVED_STATE_VERSION
67 * Saved state version of the ICH9 PCI bus device.
68 */
69#define VBOX_ICH9PCI_SAVED_STATE_VERSION_NOMSI 1
70#define VBOX_ICH9PCI_SAVED_STATE_VERSION_MSI 2
71#define VBOX_ICH9PCI_SAVED_STATE_VERSION_CURRENT VBOX_ICH9PCI_SAVED_STATE_VERSION_MSI
72
73/** Invalid PCI region mapping address. */
74#define INVALID_PCI_ADDRESS UINT32_MAX
75
76
77/*********************************************************************************************************************************
78* Internal Functions *
79*********************************************************************************************************************************/
80/* Prototypes */
81static void ich9pciSetIrqInternal(PDEVPCIROOT pPciRoot, uint8_t uDevFn, PPDMPCIDEV pPciDev,
82 int iIrq, int iLevel, uint32_t uTagSrc);
83#ifdef IN_RING3
84static void ich9pcibridgeReset(PPDMDEVINS pDevIns);
85DECLINLINE(PPDMPCIDEV) ich9pciFindBridge(PDEVPCIBUS pBus, uint8_t iBus);
86static void ich9pciBiosInitDevice(PDEVPCIROOT pPciRoot, uint8_t uBus, uint8_t uDevFn);
87#endif
88
89
90// See 7.2.2. PCI Express Enhanced Configuration Mechanism for details of address
91// mapping, we take n=6 approach
92DECLINLINE(void) ich9pciPhysToPciAddr(PDEVPCIROOT pPciRoot, RTGCPHYS GCPhysAddr, PciAddress* pPciAddr)
93{
94 NOREF(pPciRoot);
95 pPciAddr->iBus = (GCPhysAddr >> 20) & ((1<<6) - 1);
96 pPciAddr->iDeviceFunc = (GCPhysAddr >> 12) & ((1<<(5+3)) - 1); // 5 bits - device, 3 bits - function
97 pPciAddr->iRegister = (GCPhysAddr >> 0) & ((1<<(6+4+2)) - 1); // 6 bits - register, 4 bits - extended register, 2 bits -Byte Enable
98}
99
100DECLINLINE(void) ich9pciStateToPciAddr(PDEVPCIROOT pPciRoot, RTGCPHYS addr, PciAddress* pPciAddr)
101{
102 pPciAddr->iBus = (pPciRoot->uConfigReg >> 16) & 0xff;
103 pPciAddr->iDeviceFunc = (pPciRoot->uConfigReg >> 8) & 0xff;
104 pPciAddr->iRegister = (pPciRoot->uConfigReg & 0xfc) | (addr & 3);
105}
106
107PDMBOTHCBDECL(void) ich9pciSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc)
108{
109 LogFlowFunc(("invoked by %p/%d: iIrq=%d iLevel=%d uTagSrc=%#x\n", pDevIns, pDevIns->iInstance, iIrq, iLevel, uTagSrc));
110 ich9pciSetIrqInternal(PDMINS_2_DATA(pDevIns, PDEVPCIROOT), pPciDev->uDevFn, pPciDev, iIrq, iLevel, uTagSrc);
111}
112
113PDMBOTHCBDECL(void) ich9pcibridgeSetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc)
114{
115 /*
116 * The PCI-to-PCI bridge specification defines how the interrupt pins
117 * are routed from the secondary to the primary bus (see chapter 9).
118 * iIrq gives the interrupt pin the pci device asserted.
119 * We change iIrq here according to the spec and call the SetIrq function
120 * of our parent passing the device which asserted the interrupt instead of the device of the bridge.
121 */
122 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
123 PPDMPCIDEV pPciDevBus = pPciDev;
124 int iIrqPinBridge = iIrq;
125 uint8_t uDevFnBridge = 0;
126
127 /* Walk the chain until we reach the host bus. */
128 do
129 {
130 uDevFnBridge = pBus->PciDev.uDevFn;
131 iIrqPinBridge = ((pPciDevBus->uDevFn >> 3) + iIrqPinBridge) & 3;
132
133 /* Get the parent. */
134 pBus = pBus->PciDev.Int.s.CTX_SUFF(pBus);
135 pPciDevBus = &pBus->PciDev;
136 } while (pBus->iBus != 0);
137
138 AssertMsgReturnVoid(pBus->iBus == 0, ("This is not the host pci bus iBus=%d\n", pBus->iBus));
139 ich9pciSetIrqInternal(DEVPCIBUS_2_DEVPCIROOT(pBus), uDevFnBridge, pPciDev, iIrqPinBridge, iLevel, uTagSrc);
140}
141
142
143/**
144 * Port I/O Handler for PCI address OUT operations.
145 *
146 * Emulates writes to Configuration Address Port at 0CF8h for
147 * Configuration Mechanism #1.
148 *
149 * @returns VBox status code.
150 *
151 * @param pDevIns ICH9 device instance.
152 * @param pvUser User argument - ignored.
153 * @param uPort Port number used for the OUT operation.
154 * @param u32 The value to output.
155 * @param cb The value size in bytes.
156 */
157PDMBOTHCBDECL(int) ich9pciIOPortAddressWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
158{
159 LogFlow(("ich9pciIOPortAddressWrite: Port=%#x u32=%#x cb=%d\n", Port, u32, cb));
160 RT_NOREF2(Port, pvUser);
161 if (cb == 4)
162 {
163 PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
164
165 /*
166 * bits [1:0] are hard-wired, read-only and must return zeroes
167 * when read.
168 */
169 u32 &= ~3;
170
171 PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
172 pThis->uConfigReg = u32;
173 PCI_UNLOCK(pDevIns);
174 }
175
176 return VINF_SUCCESS;
177}
178
179
180/**
181 * Port I/O Handler for PCI address IN operations.
182 *
183 * Emulates reads from Configuration Address Port at 0CF8h for
184 * Configuration Mechanism #1.
185 *
186 * @returns VBox status code.
187 *
188 * @param pDevIns ICH9 device instance.
189 * @param pvUser User argument - ignored.
190 * @param uPort Port number used for the IN operation.
191 * @param pu32 Where to store the result.
192 * @param cb Number of bytes read.
193 */
194PDMBOTHCBDECL(int) ich9pciIOPortAddressRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
195{
196 RT_NOREF2(Port, pvUser);
197 if (cb == 4)
198 {
199 PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
200
201 PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_READ);
202 *pu32 = pThis->uConfigReg;
203 PCI_UNLOCK(pDevIns);
204
205 LogFlow(("ich9pciIOPortAddressRead: Port=%#x cb=%d -> %#x\n", Port, cb, *pu32));
206 return VINF_SUCCESS;
207 }
208
209 Log(("ich9pciIOPortAddressRead: Port=%#x cb=%d VERR_IOM_IOPORT_UNUSED\n", Port, cb));
210 return VERR_IOM_IOPORT_UNUSED;
211}
212
213
214/*
215 * Perform configuration space write.
216 */
217static int ich9pciDataWriteAddr(PDEVPCIROOT pPciRoot, PciAddress* pAddr,
218 uint32_t val, int cb, int rcReschedule)
219{
220 int rc = VINF_SUCCESS;
221#ifdef IN_RING3
222 NOREF(rcReschedule);
223#else
224 RT_NOREF2(val, cb);
225#endif
226
227 if (pAddr->iBus != 0) /* forward to subordinate bus */
228 {
229 if (pPciRoot->PciBus.cBridges)
230 {
231#ifdef IN_RING3 /** @todo do lookup in R0/RC too! */
232 PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(&pPciRoot->PciBus, pAddr->iBus);
233 if (pBridgeDevice)
234 {
235 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigWrite);
236 pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), pAddr->iBus, pAddr->iDeviceFunc,
237 pAddr->iRegister, val, cb);
238 }
239#else
240 rc = rcReschedule;
241#endif
242 }
243 }
244 else /* forward to directly connected device */
245 {
246 R3PTRTYPE(PDMPCIDEV *) pPciDev = pPciRoot->PciBus.apDevices[pAddr->iDeviceFunc];
247 if (pPciDev)
248 {
249#ifdef IN_RING3
250 pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, pAddr->iRegister, val, cb);
251#else
252 rc = rcReschedule;
253#endif
254 }
255 }
256
257 Log2(("ich9pciDataWriteAddr: %02x:%02x:%02x reg %x(%d) %x %Rrc\n",
258 pAddr->iBus, pAddr->iDeviceFunc >> 3, pAddr->iDeviceFunc & 0x7, pAddr->iRegister,
259 cb, val, rc));
260 return rc;
261}
262
263
264/*
265 * Decode value latched in Configuration Address Port and perform
266 * requsted write to the target configuration space register.
267 *
268 * XXX: This code should be probably moved to its only caller
269 * (ich9pciIOPortDataWrite) to avoid prolifiration of confusingly
270 * similarly named functions.
271 */
272static int ich9pciDataWrite(PDEVPCIROOT pPciRoot, uint32_t addr, uint32_t val, int len)
273{
274 LogFlow(("ich9pciDataWrite: config=%08x val=%08x len=%d\n", pPciRoot->uConfigReg, val, len));
275
276 /* Configuration space mapping enabled? */
277 if (!(pPciRoot->uConfigReg & (1 << 31)))
278 return VINF_SUCCESS;
279
280 /* Decode target device and configuration space register */
281 PciAddress aPciAddr;
282 ich9pciStateToPciAddr(pPciRoot, addr, &aPciAddr);
283
284 /* Perform configuration space write */
285 return ich9pciDataWriteAddr(pPciRoot, &aPciAddr, val, len, VINF_IOM_R3_IOPORT_WRITE);
286}
287
288
289/**
290 * Port I/O Handler for PCI data OUT operations.
291 *
292 * Emulates writes to Configuration Data Port at 0CFCh for
293 * Configuration Mechanism #1.
294 *
295 * @returns VBox status code.
296 *
297 * @param pDevIns ICH9 device instance.
298 * @param pvUser User argument - ignored.
299 * @param uPort Port number used for the OUT operation.
300 * @param u32 The value to output.
301 * @param cb The value size in bytes.
302 */
303PDMBOTHCBDECL(int) ich9pciIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
304{
305 LogFlow(("ich9pciIOPortDataWrite: Port=%#x u32=%#x cb=%d\n", Port, u32, cb));
306 NOREF(pvUser);
307 int rc = VINF_SUCCESS;
308 if (!(Port % cb))
309 {
310 PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
311
312 PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_WRITE);
313 rc = ich9pciDataWrite(pThis, Port, u32, cb);
314 PCI_UNLOCK(pDevIns);
315 }
316 else
317 AssertMsgFailed(("Unaligned write to port %#x u32=%#x cb=%d\n", Port, u32, cb));
318 return rc;
319}
320
321
322static void ich9pciNoMem(void* ptr, int cb)
323{
324 for (int i = 0; i < cb; i++)
325 ((uint8_t*)ptr)[i] = 0xff;
326}
327
328
329/*
330 * Perform configuration space read.
331 */
332static int ich9pciDataReadAddr(PDEVPCIROOT pPciRoot, PciAddress* pPciAddr, int cb,
333 uint32_t *pu32, int rcReschedule)
334{
335 int rc = VINF_SUCCESS;
336#ifdef IN_RING3
337 NOREF(rcReschedule);
338#endif
339
340 if (pPciAddr->iBus != 0) /* forward to subordinate bus */
341 {
342 if (pPciRoot->PciBus.cBridges)
343 {
344#ifdef IN_RING3 /** @todo do lookup in R0/RC too! */
345 PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(&pPciRoot->PciBus, pPciAddr->iBus);
346 if (pBridgeDevice)
347 {
348 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigRead);
349 *pu32 = pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), pPciAddr->iBus,
350 pPciAddr->iDeviceFunc, pPciAddr->iRegister, cb);
351 }
352 else
353 ich9pciNoMem(pu32, cb);
354#else
355 rc = rcReschedule;
356#endif
357 }
358 else
359 ich9pciNoMem(pu32, cb);
360 }
361 else /* forward to directly connected device */
362 {
363 R3PTRTYPE(PDMPCIDEV *) pPciDev = pPciRoot->PciBus.apDevices[pPciAddr->iDeviceFunc];
364 if (pPciDev)
365 {
366#ifdef IN_RING3
367 *pu32 = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, pPciAddr->iRegister, cb);
368#else
369 rc = rcReschedule;
370#endif
371 }
372 else
373 ich9pciNoMem(pu32, cb);
374 }
375
376 Log3(("ich9pciDataReadAddr: %02x:%02x:%02x reg %x(%d) gave %x %Rrc\n",
377 pPciAddr->iBus, pPciAddr->iDeviceFunc >> 3, pPciAddr->iDeviceFunc & 0x7, pPciAddr->iRegister,
378 cb, *pu32, rc));
379 return rc;
380}
381
382
383/*
384 * Decode value latched in Configuration Address Port and perform
385 * requsted read from the target configuration space register.
386 *
387 * XXX: This code should be probably moved to its only caller
388 * (ich9pciIOPortDataRead) to avoid prolifiration of confusingly
389 * similarly named functions.
390 */
391static int ich9pciDataRead(PDEVPCIROOT pPciRoot, uint32_t addr, int cb, uint32_t *pu32)
392{
393 LogFlow(("ich9pciDataRead: config=%x cb=%d\n", pPciRoot->uConfigReg, cb));
394
395 *pu32 = 0xffffffff;
396
397 /* Configuration space mapping enabled? */
398 if (!(pPciRoot->uConfigReg & (1 << 31)))
399 return VINF_SUCCESS;
400
401 /* Decode target device and configuration space register */
402 PciAddress aPciAddr;
403 ich9pciStateToPciAddr(pPciRoot, addr, &aPciAddr);
404
405 /* Perform configuration space read */
406 return ich9pciDataReadAddr(pPciRoot, &aPciAddr, cb, pu32, VINF_IOM_R3_IOPORT_READ);
407}
408
409
410/**
411 * Port I/O Handler for PCI data IN operations.
412 *
413 * Emulates reads from Configuration Data Port at 0CFCh for
414 * Configuration Mechanism #1.
415 *
416 * @returns VBox status code.
417 *
418 * @param pDevIns ICH9 device instance.
419 * @param pvUser User argument - ignored.
420 * @param uPort Port number used for the IN operation.
421 * @param pu32 Where to store the result.
422 * @param cb Number of bytes read.
423 */
424PDMBOTHCBDECL(int) ich9pciIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
425{
426 NOREF(pvUser);
427 if (!(Port % cb))
428 {
429 PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
430
431 PCI_LOCK(pDevIns, VINF_IOM_R3_IOPORT_READ);
432 int rc = ich9pciDataRead(pThis, Port, cb, pu32);
433 PCI_UNLOCK(pDevIns);
434
435 LogFlow(("ich9pciIOPortDataRead: Port=%#x cb=%#x -> %#x (%Rrc)\n", Port, cb, *pu32, rc));
436 return rc;
437 }
438 AssertMsgFailed(("Unaligned read from port %#x cb=%d\n", Port, cb));
439 return VERR_IOM_IOPORT_UNUSED;
440}
441
442
443/* Compute mapping of PCI slot and IRQ number to APIC interrupt line */
444DECLINLINE(int) ich9pciSlot2ApicIrq(uint8_t uSlot, int irq_num)
445{
446 return (irq_num + uSlot) & 7;
447}
448
449#ifdef IN_RING3
450
451/* return the global irq number corresponding to a given device irq
452 pin. We could also use the bus number to have a more precise
453 mapping. This is the implementation note described in the PCI spec chapter 2.2.6 */
454DECLINLINE(int) ich9pciSlotGetPirq(uint8_t uBus, uint8_t uDevFn, int iIrqNum)
455{
456 NOREF(uBus);
457 int iSlotAddend = (uDevFn >> 3) - 1;
458 return (iIrqNum + iSlotAddend) & 3;
459}
460
461/* irqs corresponding to PCI irqs A-D, must match pci_irq_list in rombios.c */
462static const uint8_t aPciIrqs[4] = { 11, 10, 9, 5 };
463
464#endif /* IN_RING3 */
465
466/* Add one more level up request on APIC input line */
467DECLINLINE(void) ich9pciApicLevelUp(PDEVPCIROOT pPciRoot, int irq_num)
468{
469 ASMAtomicIncU32(&pPciRoot->auPciApicIrqLevels[irq_num]);
470}
471
472/* Remove one level up request on APIC input line */
473DECLINLINE(void) ich9pciApicLevelDown(PDEVPCIROOT pPciRoot, int irq_num)
474{
475 ASMAtomicDecU32(&pPciRoot->auPciApicIrqLevels[irq_num]);
476}
477
478static void ich9pciApicSetIrq(PDEVPCIBUS pBus, uint8_t uDevFn, PDMPCIDEV *pPciDev, int irq_num1, int iLevel,
479 uint32_t uTagSrc, int iForcedIrq)
480{
481 /* This is only allowed to be called with a pointer to the root bus. */
482 AssertMsg(pBus->iBus == 0, ("iBus=%u\n", pBus->iBus));
483
484 if (iForcedIrq == -1)
485 {
486 int apic_irq, apic_level;
487 PDEVPCIROOT pPciRoot = DEVPCIBUS_2_DEVPCIROOT(pBus);
488 int irq_num = ich9pciSlot2ApicIrq(uDevFn >> 3, irq_num1);
489
490 if ((iLevel & PDM_IRQ_LEVEL_HIGH) == PDM_IRQ_LEVEL_HIGH)
491 ich9pciApicLevelUp(pPciRoot, irq_num);
492 else if ((iLevel & PDM_IRQ_LEVEL_HIGH) == PDM_IRQ_LEVEL_LOW)
493 ich9pciApicLevelDown(pPciRoot, irq_num);
494
495 apic_irq = irq_num + 0x10;
496 apic_level = pPciRoot->auPciApicIrqLevels[irq_num] != 0;
497 Log3(("ich9pciApicSetIrq: %s: irq_num1=%d level=%d apic_irq=%d apic_level=%d irq_num1=%d uTagSrc=%#x\n",
498 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, apic_irq, apic_level, irq_num, uTagSrc));
499 pBus->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), apic_irq, apic_level, uTagSrc);
500
501 if ((iLevel & PDM_IRQ_LEVEL_FLIP_FLOP) == PDM_IRQ_LEVEL_FLIP_FLOP)
502 {
503 /*
504 * we raised it few lines above, as PDM_IRQ_LEVEL_FLIP_FLOP has
505 * PDM_IRQ_LEVEL_HIGH bit set
506 */
507 ich9pciApicLevelDown(pPciRoot, irq_num);
508 pPciDev->Int.s.uIrqPinState = PDM_IRQ_LEVEL_LOW;
509 apic_level = pPciRoot->auPciApicIrqLevels[irq_num] != 0;
510 Log3(("ich9pciApicSetIrq: %s: irq_num1=%d level=%d apic_irq=%d apic_level=%d irq_num1=%d uTagSrc=%#x (flop)\n",
511 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, apic_irq, apic_level, irq_num, uTagSrc));
512 pBus->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), apic_irq, apic_level, uTagSrc);
513 }
514 } else {
515 Log3(("ich9pciApicSetIrq: (forced) %s: irq_num1=%d level=%d acpi_irq=%d uTagSrc=%#x\n",
516 R3STRING(pPciDev->pszNameR3), irq_num1, iLevel, iForcedIrq, uTagSrc));
517 pBus->CTX_SUFF(pPciHlp)->pfnIoApicSetIrq(pBus->CTX_SUFF(pDevIns), iForcedIrq, iLevel, uTagSrc);
518 }
519}
520
521static void ich9pciSetIrqInternal(PDEVPCIROOT pPciRoot, uint8_t uDevFn, PPDMPCIDEV pPciDev,
522 int iIrq, int iLevel, uint32_t uTagSrc)
523{
524 /* If MSI or MSI-X is enabled, PCI INTx# signals are disabled regardless of the PCI command
525 * register interrupt bit state.
526 * PCI 3.0 (section 6.8) forbids MSI and MSI-X to be enabled at the same time and makes
527 * that undefined behavior. We check for MSI first, then MSI-X.
528 */
529 if (MsiIsEnabled(pPciDev))
530 {
531 Assert(!MsixIsEnabled(pPciDev)); /* Not allowed -- see note above. */
532 LogFlowFunc(("PCI Dev %p : MSI\n", pPciDev));
533 PPDMDEVINS pDevIns = pPciRoot->PciBus.CTX_SUFF(pDevIns);
534 MsiNotify(pDevIns, pPciRoot->PciBus.CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc);
535 return;
536 }
537
538 if (MsixIsEnabled(pPciDev))
539 {
540 LogFlowFunc(("PCI Dev %p : MSI-X\n", pPciDev));
541 PPDMDEVINS pDevIns = pPciRoot->PciBus.CTX_SUFF(pDevIns);
542 MsixNotify(pDevIns, pPciRoot->PciBus.CTX_SUFF(pPciHlp), pPciDev, iIrq, iLevel, uTagSrc);
543 return;
544 }
545
546 PDEVPCIBUS pBus = &pPciRoot->PciBus;
547 const bool fIsAcpiDevice = PCIDevGetDeviceId(pPciDev) == 0x7113;
548
549 LogFlowFunc(("PCI Dev %p : IRQ\n", pPciDev));
550 /* Check if the state changed. */
551 if (pPciDev->Int.s.uIrqPinState != iLevel)
552 {
553 pPciDev->Int.s.uIrqPinState = (iLevel & PDM_IRQ_LEVEL_HIGH);
554
555 /* Send interrupt to I/O APIC only now. */
556 if (fIsAcpiDevice)
557 /*
558 * ACPI needs special treatment since SCI is hardwired and
559 * should not be affected by PCI IRQ routing tables at the
560 * same time SCI IRQ is shared in PCI sense hence this
561 * kludge (i.e. we fetch the hardwired value from ACPIs
562 * PCI device configuration space).
563 */
564 ich9pciApicSetIrq(pBus, uDevFn, pPciDev, -1, iLevel, uTagSrc, PCIDevGetInterruptLine(pPciDev));
565 else
566 ich9pciApicSetIrq(pBus, uDevFn, pPciDev, iIrq, iLevel, uTagSrc, -1);
567 }
568}
569
570
571/**
572 * Memory mapped I/O Handler for write operations.
573 *
574 * Emulates writes to configuration space.
575 *
576 * @returns VBox status code.
577 *
578 * @param pDevIns The device instance.
579 * @param pvUser User argument.
580 * @param GCPhysAddr Physical address (in GC) where the read starts.
581 * @param pv Where to fetch the result.
582 * @param cb Number of bytes to write.
583 * @remarks Caller enters the device critical section.
584 */
585PDMBOTHCBDECL(int) ich9pciMcfgMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
586{
587 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
588 uint32_t u32 = 0;
589 NOREF(pvUser);
590
591 Log2(("ich9pciMcfgMMIOWrite: %RGp(%d) \n", GCPhysAddr, cb));
592
593 PCI_LOCK(pDevIns, VINF_IOM_R3_MMIO_WRITE);
594
595 /* Decode target device and configuration space register */
596 PciAddress aDest;
597 ich9pciPhysToPciAddr(pPciRoot, GCPhysAddr, &aDest);
598
599 switch (cb)
600 {
601 case 1:
602 u32 = *(uint8_t*)pv;
603 break;
604 case 2:
605 u32 = *(uint16_t*)pv;
606 break;
607 case 4:
608 u32 = *(uint32_t*)pv;
609 break;
610 default:
611 Assert(false);
612 break;
613 }
614
615 /* Perform configuration space write */
616 int rc = ich9pciDataWriteAddr(pPciRoot, &aDest, u32, cb, VINF_IOM_R3_MMIO_WRITE);
617 PCI_UNLOCK(pDevIns);
618
619 return rc;
620}
621
622
623/**
624 * Memory mapped I/O Handler for read operations.
625 *
626 * Emulates reads from configuration space.
627 *
628 * @returns VBox status code.
629 *
630 * @param pDevIns The device instance.
631 * @param pvUser User argument.
632 * @param GCPhysAddr Physical address (in GC) where the read starts.
633 * @param pv Where to store the result.
634 * @param cb Number of bytes read.
635 * @remarks Caller enters the device critical section.
636 */
637PDMBOTHCBDECL(int) ich9pciMcfgMMIORead (PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
638{
639 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
640 uint32_t rv;
641 NOREF(pvUser);
642
643 LogFlow(("ich9pciMcfgMMIORead: %RGp(%d) \n", GCPhysAddr, cb));
644
645 PCI_LOCK(pDevIns, VINF_IOM_R3_MMIO_READ);
646
647 /* Decode target device and configuration space register */
648 PciAddress aDest;
649 ich9pciPhysToPciAddr(pPciRoot, GCPhysAddr, &aDest);
650
651 /* Perform configuration space read */
652 int rc = ich9pciDataReadAddr(pPciRoot, &aDest, cb, &rv, VINF_IOM_R3_MMIO_READ);
653
654 if (RT_SUCCESS(rc))
655 {
656 switch (cb)
657 {
658 case 1:
659 *(uint8_t*)pv = (uint8_t)rv;
660 break;
661 case 2:
662 *(uint16_t*)pv = (uint16_t)rv;
663 break;
664 case 4:
665 *(uint32_t*)pv = (uint32_t)rv;
666 break;
667 default:
668 Assert(false);
669 break;
670 }
671 }
672 PCI_UNLOCK(pDevIns);
673
674 return rc;
675}
676
677#ifdef IN_RING3
678
679/*
680 * Include code we share with the other PCI bus implementation.
681 *
682 * Note! No #ifdefs, use instant data booleans/flags/whatever. Goal is to
683 * completely merge these files! File #1 contains code we write, where
684 * as a possible file #2 contains external code if there's any left.
685 */
686# include "DevPciMerge1.cpp.h"
687
688
689DECLINLINE(PPDMPCIDEV) ich9pciFindBridge(PDEVPCIBUS pBus, uint8_t iBus)
690{
691 /* Search for a fitting bridge. */
692 for (uint32_t iBridge = 0; iBridge < pBus->cBridges; iBridge++)
693 {
694 /*
695 * Examine secondary and subordinate bus number.
696 * If the target bus is in the range we pass the request on to the bridge.
697 */
698 PPDMPCIDEV pBridge = pBus->papBridgesR3[iBridge];
699 AssertMsg(pBridge && pciDevIsPci2PciBridge(pBridge),
700 ("Device is not a PCI bridge but on the list of PCI bridges\n"));
701 uint32_t uSecondary = PDMPciDevGetByte(pBridge, VBOX_PCI_SECONDARY_BUS);
702 uint32_t uSubordinate = PDMPciDevGetByte(pBridge, VBOX_PCI_SUBORDINATE_BUS);
703 Log3(("ich9pciFindBridge on bus %p, bridge %d: %d in %d..%d\n", pBus, iBridge, iBus, uSecondary, uSubordinate));
704 if (iBus >= uSecondary && iBus <= uSubordinate)
705 return pBridge;
706 }
707
708 /* Nothing found. */
709 return NULL;
710}
711
712static uint32_t ich9pciGetCfg(PPDMPCIDEV pPciDev, int32_t iRegister, int cb)
713{
714 return pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, iRegister, cb);
715}
716
717static uint8_t ich9pciGetByte(PPDMPCIDEV pPciDev, int32_t iRegister)
718{
719 return (uint8_t)ich9pciGetCfg(pPciDev, iRegister, 1);
720}
721
722static uint16_t ich9pciGetWord(PPDMPCIDEV pPciDev, int32_t iRegister)
723{
724 return (uint16_t)ich9pciGetCfg(pPciDev, iRegister, 2);
725}
726
727static uint32_t ich9pciGetDWord(PPDMPCIDEV pPciDev, int32_t iRegister)
728{
729 return (uint32_t)ich9pciGetCfg(pPciDev, iRegister, 4);
730}
731
732DECLINLINE(uint32_t) ich9pciGetRegionReg(int iRegion)
733{
734 return iRegion == VBOX_PCI_ROM_SLOT
735 ? VBOX_PCI_ROM_ADDRESS : (VBOX_PCI_BASE_ADDRESS_0 + iRegion * 4);
736}
737
738
739/* -=-=-=-=-=- PCI Bus Interface Methods (PDMPCIBUSREG) -=-=-=-=-=- */
740
741
742static DECLCALLBACK(int) ich9pciRegisterMsi(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, PPDMMSIREG pMsiReg)
743{
744 NOREF(pDevIns);
745 int rc;
746
747 rc = MsiInit(pPciDev, pMsiReg);
748 if (RT_FAILURE(rc))
749 return rc;
750
751 rc = MsixInit(pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pPciHlp), pPciDev, pMsiReg);
752 if (RT_FAILURE(rc))
753 return rc;
754
755 return VINF_SUCCESS;
756}
757
758
759/**
760 * @interface_method_impl{PDMPCIBUSREG,pfnIORegionRegisterR3}
761 */
762DECLCALLBACK(int) devpciR3CommonIORegionRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iRegion, RTGCPHYS cbRegion,
763 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
764{
765 NOREF(pDevIns);
766
767 /*
768 * Validate.
769 */
770 AssertMsgReturn( enmType == (PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR32)
771 || enmType == (PCI_ADDRESS_SPACE_MEM_PREFETCH | PCI_ADDRESS_SPACE_BAR32)
772 || enmType == (PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64)
773 || enmType == (PCI_ADDRESS_SPACE_MEM_PREFETCH | PCI_ADDRESS_SPACE_BAR64)
774 || enmType == PCI_ADDRESS_SPACE_IO
775 ,
776 ("Invalid enmType=%#x? Or was this a bitmask after all...\n", enmType),
777 VERR_INVALID_PARAMETER);
778 AssertMsgReturn((unsigned)iRegion < VBOX_PCI_NUM_REGIONS,
779 ("Invalid iRegion=%d VBOX_PCI_NUM_REGIONS=%d\n", iRegion, VBOX_PCI_NUM_REGIONS),
780 VERR_INVALID_PARAMETER);
781 int iLastSet = ASMBitLastSetU64(cbRegion);
782 AssertMsgReturn( iLastSet != 0
783 && RT_BIT_64(iLastSet - 1) == cbRegion,
784 ("Invalid cbRegion=%RGp iLastSet=%#x (not a power of 2 or 0)\n", cbRegion, iLastSet),
785 VERR_INVALID_PARAMETER);
786
787 Log(("devpciR3CommonIORegionRegister: %s region %d size %RGp type %x\n",
788 pPciDev->pszNameR3, iRegion, cbRegion, enmType));
789
790 /* Make sure that we haven't marked this region as continuation of 64-bit region. */
791 Assert(pPciDev->Int.s.aIORegions[iRegion].type != 0xff);
792
793 /*
794 * Register the I/O region.
795 */
796 PPCIIOREGION pRegion = &pPciDev->Int.s.aIORegions[iRegion];
797 pRegion->addr = INVALID_PCI_ADDRESS;
798 pRegion->size = cbRegion;
799 pRegion->type = enmType;
800 pRegion->map_func = pfnCallback;
801
802 if ((enmType & PCI_ADDRESS_SPACE_BAR64) != 0)
803 {
804 /* VBOX_PCI_BASE_ADDRESS_5 and VBOX_PCI_ROM_ADDRESS are excluded. */
805 AssertMsgReturn(iRegion < VBOX_PCI_NUM_REGIONS - 2,
806 ("Region %d cannot be 64-bit\n", iRegion),
807 VERR_INVALID_PARAMETER);
808 /* Mark next region as continuation of this one. */
809 pPciDev->Int.s.aIORegions[iRegion + 1].type = 0xff;
810 }
811
812 /* Set type in the PCI config space. */
813 AssertCompile(PCI_ADDRESS_SPACE_MEM == 0);
814 AssertCompile(PCI_ADDRESS_SPACE_IO == 1);
815 AssertCompile(PCI_ADDRESS_SPACE_BAR64 == RT_BIT_32(2));
816 AssertCompile(PCI_ADDRESS_SPACE_MEM_PREFETCH == RT_BIT_32(3));
817 uint32_t u32Value = (uint32_t)enmType & (PCI_ADDRESS_SPACE_IO | PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_MEM_PREFETCH);
818 PCIDevSetDWord(pPciDev, ich9pciGetRegionReg(iRegion), u32Value);
819
820 return VINF_SUCCESS;
821}
822
823
824/**
825 * @interface_method_impl{PDMPCIBUSREG,pfnSetConfigCallbacksR3}
826 */
827DECLCALLBACK(void) devpciR3CommonSetConfigCallbacks(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
828 PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
829 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
830{
831 NOREF(pDevIns);
832
833 if (ppfnReadOld)
834 *ppfnReadOld = pPciDev->Int.s.pfnConfigRead;
835 pPciDev->Int.s.pfnConfigRead = pfnRead;
836
837 if (ppfnWriteOld)
838 *ppfnWriteOld = pPciDev->Int.s.pfnConfigWrite;
839 pPciDev->Int.s.pfnConfigWrite = pfnWrite;
840}
841
842
843static int ich9pciR3CommonSaveExec(PDEVPCIBUS pBus, PSSMHANDLE pSSM)
844{
845 /*
846 * Iterate thru all the devices.
847 */
848 for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
849 {
850 PPDMPCIDEV pDev = pBus->apDevices[i];
851 if (pDev)
852 {
853 /* Device position */
854 SSMR3PutU32(pSSM, i);
855 /* PCI config registers */
856 SSMR3PutMem(pSSM, pDev->abConfig, sizeof(pDev->abConfig));
857
858 /* Device flags */
859 int rc = SSMR3PutU32(pSSM, pDev->Int.s.fFlags);
860 if (RT_FAILURE(rc))
861 return rc;
862
863 /* IRQ pin state */
864 rc = SSMR3PutS32(pSSM, pDev->Int.s.uIrqPinState);
865 if (RT_FAILURE(rc))
866 return rc;
867
868 /* MSI info */
869 rc = SSMR3PutU8(pSSM, pDev->Int.s.u8MsiCapOffset);
870 if (RT_FAILURE(rc))
871 return rc;
872 rc = SSMR3PutU8(pSSM, pDev->Int.s.u8MsiCapSize);
873 if (RT_FAILURE(rc))
874 return rc;
875
876 /* MSI-X info */
877 rc = SSMR3PutU8(pSSM, pDev->Int.s.u8MsixCapOffset);
878 if (RT_FAILURE(rc))
879 return rc;
880 rc = SSMR3PutU8(pSSM, pDev->Int.s.u8MsixCapSize);
881 if (RT_FAILURE(rc))
882 return rc;
883 /* Save MSI-X page state */
884 if (pDev->Int.s.u8MsixCapOffset != 0)
885 {
886 Assert(pDev->Int.s.pMsixPageR3 != NULL);
887 SSMR3PutMem(pSSM, pDev->Int.s.pMsixPageR3, 0x1000);
888 if (RT_FAILURE(rc))
889 return rc;
890 }
891 }
892 }
893 return SSMR3PutU32(pSSM, UINT32_MAX); /* terminator */
894}
895
896static DECLCALLBACK(int) ich9pciR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
897{
898 PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
899
900 /*
901 * Bus state data.
902 */
903 SSMR3PutU32(pSSM, pThis->uConfigReg);
904
905 /*
906 * Save IRQ states.
907 */
908 for (unsigned i = 0; i < RT_ELEMENTS(pThis->auPciApicIrqLevels); i++)
909 SSMR3PutU32(pSSM, pThis->auPciApicIrqLevels[i]);
910
911 SSMR3PutU32(pSSM, UINT32_MAX); /* separator */
912
913 return ich9pciR3CommonSaveExec(&pThis->PciBus, pSSM);
914}
915
916
917static DECLCALLBACK(int) ich9pcibridgeR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
918{
919 PDEVPCIBUS pThis = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
920 return ich9pciR3CommonSaveExec(pThis, pSSM);
921}
922
923
924static DECLCALLBACK(void) ich9pcibridgeConfigWrite(PPDMDEVINSR3 pDevIns, uint8_t iBus, uint8_t iDevice, uint32_t u32Address, uint32_t u32Value, unsigned cb)
925{
926 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
927
928 LogFlowFunc((": pDevIns=%p iBus=%d iDevice=%d u32Address=%u u32Value=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, u32Value, cb));
929
930 /* If the current bus is not the target bus search for the bus which contains the device. */
931 if (iBus != PDMPciDevGetByte(&pBus->PciDev, VBOX_PCI_SECONDARY_BUS))
932 {
933 PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(pBus, iBus);
934 if (pBridgeDevice)
935 {
936 AssertPtr(pBridgeDevice->Int.s.pfnBridgeConfigWrite);
937 pBridgeDevice->Int.s.pfnBridgeConfigWrite(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), iBus, iDevice,
938 u32Address, u32Value, cb);
939 }
940 }
941 else
942 {
943 /* This is the target bus, pass the write to the device. */
944 PPDMPCIDEV pPciDev = pBus->apDevices[iDevice];
945 if (pPciDev)
946 {
947 Log(("%s: %s: addr=%02x val=%08x len=%d\n", __FUNCTION__, pPciDev->pszNameR3, u32Address, u32Value, cb));
948 pPciDev->Int.s.pfnConfigWrite(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, u32Value, cb);
949 }
950 }
951}
952
953static DECLCALLBACK(uint32_t) ich9pcibridgeConfigRead(PPDMDEVINSR3 pDevIns, uint8_t iBus, uint8_t iDevice, uint32_t u32Address, unsigned cb)
954{
955 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
956 uint32_t u32Value;
957
958 LogFlowFunc((": pDevIns=%p iBus=%d iDevice=%d u32Address=%u cb=%d\n", pDevIns, iBus, iDevice, u32Address, cb));
959
960 /* If the current bus is not the target bus search for the bus which contains the device. */
961 if (iBus != PDMPciDevGetByte(&pBus->PciDev, VBOX_PCI_SECONDARY_BUS))
962 {
963 PPDMPCIDEV pBridgeDevice = ich9pciFindBridge(pBus, iBus);
964 if (pBridgeDevice)
965 {
966 AssertPtr( pBridgeDevice->Int.s.pfnBridgeConfigRead);
967 u32Value = pBridgeDevice->Int.s.pfnBridgeConfigRead(pBridgeDevice->Int.s.CTX_SUFF(pDevIns), iBus, iDevice,
968 u32Address, cb);
969 }
970 else
971 ich9pciNoMem(&u32Value, 4);
972 }
973 else
974 {
975 /* This is the target bus, pass the read to the device. */
976 PPDMPCIDEV pPciDev = pBus->apDevices[iDevice];
977 if (pPciDev)
978 {
979 u32Value = pPciDev->Int.s.pfnConfigRead(pPciDev->Int.s.CTX_SUFF(pDevIns), pPciDev, u32Address, cb);
980 Log(("%s: %s: u32Address=%02x u32Value=%08x cb=%d\n", __FUNCTION__, pPciDev->pszNameR3, u32Address, u32Value, cb));
981 }
982 else
983 ich9pciNoMem(&u32Value, 4);
984 }
985
986 return u32Value;
987}
988
989
990
991/* -=-=-=-=-=- Saved State -=-=-=-=-=- */
992
993
994/**
995 * Common routine for restoring the config registers of a PCI device.
996 *
997 * @param pDev The PCI device.
998 * @param pbSrcConfig The configuration register values to be loaded.
999 * @param fIsBridge Whether this is a bridge device or not.
1000 */
1001void devpciR3CommonRestoreConfig(PPDMPCIDEV pDev, uint8_t const *pbSrcConfig, bool fIsBridge)
1002{
1003 /*
1004 * This table defines the fields for normal devices and bridge devices, and
1005 * the order in which they need to be restored.
1006 */
1007 static const struct PciField
1008 {
1009 uint8_t off;
1010 uint8_t cb;
1011 uint8_t fWritable;
1012 uint8_t fBridge;
1013 const char *pszName;
1014 } s_aFields[] =
1015 {
1016 /* off,cb,fW,fB, pszName */
1017 { 0x00, 2, 0, 3, "VENDOR_ID" },
1018 { 0x02, 2, 0, 3, "DEVICE_ID" },
1019 { 0x06, 2, 1, 3, "STATUS" },
1020 { 0x08, 1, 0, 3, "REVISION_ID" },
1021 { 0x09, 1, 0, 3, "CLASS_PROG" },
1022 { 0x0a, 1, 0, 3, "CLASS_SUB" },
1023 { 0x0b, 1, 0, 3, "CLASS_BASE" },
1024 { 0x0c, 1, 1, 3, "CACHE_LINE_SIZE" },
1025 { 0x0d, 1, 1, 3, "LATENCY_TIMER" },
1026 { 0x0e, 1, 0, 3, "HEADER_TYPE" },
1027 { 0x0f, 1, 1, 3, "BIST" },
1028 { 0x10, 4, 1, 3, "BASE_ADDRESS_0" },
1029 { 0x14, 4, 1, 3, "BASE_ADDRESS_1" },
1030 { 0x18, 4, 1, 1, "BASE_ADDRESS_2" },
1031 { 0x18, 1, 1, 2, "PRIMARY_BUS" }, // fWritable = ??
1032 { 0x19, 1, 1, 2, "SECONDARY_BUS" }, // fWritable = ??
1033 { 0x1a, 1, 1, 2, "SUBORDINATE_BUS" }, // fWritable = ??
1034 { 0x1b, 1, 1, 2, "SEC_LATENCY_TIMER" }, // fWritable = ??
1035 { 0x1c, 4, 1, 1, "BASE_ADDRESS_3" },
1036 { 0x1c, 1, 1, 2, "IO_BASE" }, // fWritable = ??
1037 { 0x1d, 1, 1, 2, "IO_LIMIT" }, // fWritable = ??
1038 { 0x1e, 2, 1, 2, "SEC_STATUS" }, // fWritable = ??
1039 { 0x20, 4, 1, 1, "BASE_ADDRESS_4" },
1040 { 0x20, 2, 1, 2, "MEMORY_BASE" }, // fWritable = ??
1041 { 0x22, 2, 1, 2, "MEMORY_LIMIT" }, // fWritable = ??
1042 { 0x24, 4, 1, 1, "BASE_ADDRESS_5" },
1043 { 0x24, 2, 1, 2, "PREF_MEMORY_BASE" }, // fWritable = ??
1044 { 0x26, 2, 1, 2, "PREF_MEMORY_LIMIT" }, // fWritable = ??
1045 { 0x28, 4, 1, 1, "CARDBUS_CIS" }, // fWritable = ??
1046 { 0x28, 4, 1, 2, "PREF_BASE_UPPER32" }, // fWritable = ??
1047 { 0x2c, 2, 0, 1, "SUBSYSTEM_VENDOR_ID" },// fWritable = !?
1048 { 0x2c, 4, 1, 2, "PREF_LIMIT_UPPER32" },// fWritable = ??
1049 { 0x2e, 2, 0, 1, "SUBSYSTEM_ID" }, // fWritable = !?
1050 { 0x30, 4, 1, 1, "ROM_ADDRESS" }, // fWritable = ?!
1051 { 0x30, 2, 1, 2, "IO_BASE_UPPER16" }, // fWritable = ?!
1052 { 0x32, 2, 1, 2, "IO_LIMIT_UPPER16" }, // fWritable = ?!
1053 { 0x34, 4, 0, 3, "CAPABILITY_LIST" }, // fWritable = !? cb=!?
1054 { 0x38, 4, 1, 1, "RESERVED_38" }, // ???
1055 { 0x38, 4, 1, 2, "ROM_ADDRESS_BR" }, // fWritable = !? cb=!? fBridge=!?
1056 { 0x3c, 1, 1, 3, "INTERRUPT_LINE" }, // fBridge=??
1057 { 0x3d, 1, 0, 3, "INTERRUPT_PIN" }, // fBridge=??
1058 { 0x3e, 1, 0, 1, "MIN_GNT" },
1059 { 0x3e, 2, 1, 2, "BRIDGE_CONTROL" }, // fWritable = !?
1060 { 0x3f, 1, 0, 1, "MAX_LAT" },
1061 /* The COMMAND register must come last as it requires the *ADDRESS*
1062 registers to be restored before we pretent to change it from 0 to
1063 whatever value the guest assigned it. */
1064 { 0x04, 2, 1, 3, "COMMAND" },
1065 };
1066
1067#ifdef RT_STRICT
1068 /* Check that we've got full register coverage. */
1069 uint32_t bmDevice[0x40 / 32];
1070 uint32_t bmBridge[0x40 / 32];
1071 RT_ZERO(bmDevice);
1072 RT_ZERO(bmBridge);
1073 for (uint32_t i = 0; i < RT_ELEMENTS(s_aFields); i++)
1074 {
1075 uint8_t off = s_aFields[i].off;
1076 uint8_t cb = s_aFields[i].cb;
1077 uint8_t f = s_aFields[i].fBridge;
1078 while (cb-- > 0)
1079 {
1080 if (f & 1) AssertMsg(!ASMBitTest(bmDevice, off), ("%#x\n", off));
1081 if (f & 2) AssertMsg(!ASMBitTest(bmBridge, off), ("%#x\n", off));
1082 if (f & 1) ASMBitSet(bmDevice, off);
1083 if (f & 2) ASMBitSet(bmBridge, off);
1084 off++;
1085 }
1086 }
1087 for (uint32_t off = 0; off < 0x40; off++)
1088 {
1089 AssertMsg(ASMBitTest(bmDevice, off), ("%#x\n", off));
1090 AssertMsg(ASMBitTest(bmBridge, off), ("%#x\n", off));
1091 }
1092#endif
1093
1094 /*
1095 * Loop thru the fields covering the 64 bytes of standard registers.
1096 */
1097 uint8_t const fBridge = fIsBridge ? 2 : 1;
1098 Assert(!pciDevIsPassthrough(pDev));
1099 uint8_t *pbDstConfig = &pDev->abConfig[0];
1100
1101 for (uint32_t i = 0; i < RT_ELEMENTS(s_aFields); i++)
1102 if (s_aFields[i].fBridge & fBridge)
1103 {
1104 uint8_t const off = s_aFields[i].off;
1105 uint8_t const cb = s_aFields[i].cb;
1106 uint32_t u32Src;
1107 uint32_t u32Dst;
1108 switch (cb)
1109 {
1110 case 1:
1111 u32Src = pbSrcConfig[off];
1112 u32Dst = pbDstConfig[off];
1113 break;
1114 case 2:
1115 u32Src = *(uint16_t const *)&pbSrcConfig[off];
1116 u32Dst = *(uint16_t const *)&pbDstConfig[off];
1117 break;
1118 case 4:
1119 u32Src = *(uint32_t const *)&pbSrcConfig[off];
1120 u32Dst = *(uint32_t const *)&pbDstConfig[off];
1121 break;
1122 default:
1123 AssertFailed();
1124 continue;
1125 }
1126
1127 if ( u32Src != u32Dst
1128 || off == VBOX_PCI_COMMAND)
1129 {
1130 if (u32Src != u32Dst)
1131 {
1132 if (!s_aFields[i].fWritable)
1133 LogRel(("PCI: %8s/%u: %2u-bit field %s: %x -> %x - !READ ONLY!\n",
1134 pDev->pszNameR3, pDev->Int.s.CTX_SUFF(pDevIns)->iInstance, cb*8, s_aFields[i].pszName, u32Dst, u32Src));
1135 else
1136 LogRel(("PCI: %8s/%u: %2u-bit field %s: %x -> %x\n",
1137 pDev->pszNameR3, pDev->Int.s.CTX_SUFF(pDevIns)->iInstance, cb*8, s_aFields[i].pszName, u32Dst, u32Src));
1138 }
1139 if (off == VBOX_PCI_COMMAND)
1140 PCIDevSetCommand(pDev, 0); /* For remapping, see ich9pciR3CommonLoadExec. */
1141 pDev->Int.s.pfnConfigWrite(pDev->Int.s.CTX_SUFF(pDevIns), pDev, off, u32Src, cb);
1142 }
1143 }
1144
1145 /*
1146 * The device dependent registers.
1147 *
1148 * We will not use ConfigWrite here as we have no clue about the size
1149 * of the registers, so the device is responsible for correctly
1150 * restoring functionality governed by these registers.
1151 */
1152 for (uint32_t off = 0x40; off < sizeof(pDev->abConfig); off++)
1153 if (pbDstConfig[off] != pbSrcConfig[off])
1154 {
1155 LogRel(("PCI: %8s/%u: register %02x: %02x -> %02x\n",
1156 pDev->pszNameR3, pDev->Int.s.CTX_SUFF(pDevIns)->iInstance, off, pbDstConfig[off], pbSrcConfig[off])); /** @todo make this Log() later. */
1157 pbDstConfig[off] = pbSrcConfig[off];
1158 }
1159}
1160
1161/**
1162 * Common worker for ich9pciR3LoadExec and ich9pcibridgeR3LoadExec.
1163 *
1164 * @returns VBox status code.
1165 * @param pBus The bus which data is being loaded.
1166 * @param pSSM The saved state handle.
1167 * @param uVersion The data version.
1168 * @param uPass The pass.
1169 */
1170static DECLCALLBACK(int) ich9pciR3CommonLoadExec(PDEVPCIBUS pBus, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
1171{
1172 uint32_t u32;
1173 uint32_t i;
1174 int rc;
1175
1176 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
1177 if (uVersion != VBOX_ICH9PCI_SAVED_STATE_VERSION_CURRENT)
1178 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1179
1180 /*
1181 * Iterate thru all the devices and write 0 to the COMMAND register so
1182 * that all the memory is unmapped before we start restoring the saved
1183 * mapping locations.
1184 *
1185 * The register value is restored afterwards so we can do proper
1186 * LogRels in devpciR3CommonRestoreConfig.
1187 */
1188 for (i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
1189 {
1190 PPDMPCIDEV pDev = pBus->apDevices[i];
1191 if (pDev)
1192 {
1193 uint16_t u16 = PCIDevGetCommand(pDev);
1194 pDev->Int.s.pfnConfigWrite(pDev->Int.s.CTX_SUFF(pDevIns), pDev, VBOX_PCI_COMMAND, 0, 2);
1195 PCIDevSetCommand(pDev, u16);
1196 Assert(PCIDevGetCommand(pDev) == u16);
1197 }
1198 }
1199
1200 void *pvMsixPage = RTMemTmpAllocZ(0x1000);
1201 AssertReturn(pvMsixPage, VERR_NO_TMP_MEMORY);
1202
1203 /*
1204 * Iterate all the devices.
1205 */
1206 for (i = 0;; i++)
1207 {
1208 PPDMPCIDEV pDev;
1209 PDMPCIDEV DevTmp;
1210
1211 /* index / terminator */
1212 rc = SSMR3GetU32(pSSM, &u32);
1213 if (RT_FAILURE(rc))
1214 break;
1215 if (u32 == (uint32_t)~0)
1216 break;
1217 AssertMsgBreak(u32 < RT_ELEMENTS(pBus->apDevices) && u32 >= i, ("u32=%#x i=%#x\n", u32, i));
1218
1219 /* skip forward to the device checking that no new devices are present. */
1220 for (; i < u32; i++)
1221 {
1222 pDev = pBus->apDevices[i];
1223 if (pDev)
1224 {
1225 LogRel(("PCI: New device in slot %#x, %s (vendor=%#06x device=%#06x)\n", i, pDev->pszNameR3,
1226 PCIDevGetVendorId(pDev), PCIDevGetDeviceId(pDev)));
1227 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
1228 {
1229 rc = SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("New device in slot %#x, %s (vendor=%#06x device=%#06x)"),
1230 i, pDev->pszNameR3, PCIDevGetVendorId(pDev), PCIDevGetDeviceId(pDev));
1231 break;
1232 }
1233 }
1234 }
1235 if (RT_FAILURE(rc))
1236 break;
1237
1238 /* get the data */
1239 DevTmp.Int.s.fFlags = 0;
1240 DevTmp.Int.s.u8MsiCapOffset = 0;
1241 DevTmp.Int.s.u8MsiCapSize = 0;
1242 DevTmp.Int.s.u8MsixCapOffset = 0;
1243 DevTmp.Int.s.u8MsixCapSize = 0;
1244 DevTmp.Int.s.uIrqPinState = ~0; /* Invalid value in case we have an older saved state to force a state change in pciSetIrq. */
1245 SSMR3GetMem(pSSM, DevTmp.abConfig, sizeof(DevTmp.abConfig));
1246
1247 SSMR3GetU32(pSSM, &DevTmp.Int.s.fFlags);
1248 SSMR3GetS32(pSSM, &DevTmp.Int.s.uIrqPinState);
1249 SSMR3GetU8(pSSM, &DevTmp.Int.s.u8MsiCapOffset);
1250 SSMR3GetU8(pSSM, &DevTmp.Int.s.u8MsiCapSize);
1251 SSMR3GetU8(pSSM, &DevTmp.Int.s.u8MsixCapOffset);
1252 rc = SSMR3GetU8(pSSM, &DevTmp.Int.s.u8MsixCapSize);
1253 if (RT_FAILURE(rc))
1254 break;
1255
1256 /* Load MSI-X page state */
1257 if (DevTmp.Int.s.u8MsixCapOffset != 0)
1258 {
1259 Assert(pvMsixPage != NULL);
1260 rc = SSMR3GetMem(pSSM, pvMsixPage, 0x1000);
1261 if (RT_FAILURE(rc))
1262 break;
1263 }
1264
1265 /* check that it's still around. */
1266 pDev = pBus->apDevices[i];
1267 if (!pDev)
1268 {
1269 LogRel(("PCI: Device in slot %#x has been removed! vendor=%#06x device=%#06x\n", i,
1270 PCIDevGetVendorId(&DevTmp), PCIDevGetDeviceId(&DevTmp)));
1271 if (SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT)
1272 {
1273 rc = SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device in slot %#x has been removed! vendor=%#06x device=%#06x"),
1274 i, PCIDevGetVendorId(&DevTmp), PCIDevGetDeviceId(&DevTmp));
1275 break;
1276 }
1277 continue;
1278 }
1279
1280 /* match the vendor id assuming that this will never be changed. */
1281 if (PCIDevGetVendorId(&DevTmp) != PCIDevGetVendorId(pDev))
1282 {
1283 rc = SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device in slot %#x (%s) vendor id mismatch! saved=%.4Rhxs current=%.4Rhxs"),
1284 i, pDev->pszNameR3, PCIDevGetVendorId(&DevTmp), PCIDevGetVendorId(pDev));
1285 break;
1286 }
1287
1288 /* commit the loaded device config. */
1289 Assert(!pciDevIsPassthrough(pDev));
1290 devpciR3CommonRestoreConfig(pDev, &DevTmp.abConfig[0], false ); /** @todo fix bridge fun! */
1291
1292 pDev->Int.s.uIrqPinState = DevTmp.Int.s.uIrqPinState;
1293 pDev->Int.s.u8MsiCapOffset = DevTmp.Int.s.u8MsiCapOffset;
1294 pDev->Int.s.u8MsiCapSize = DevTmp.Int.s.u8MsiCapSize;
1295 pDev->Int.s.u8MsixCapOffset = DevTmp.Int.s.u8MsixCapOffset;
1296 pDev->Int.s.u8MsixCapSize = DevTmp.Int.s.u8MsixCapSize;
1297 if (DevTmp.Int.s.u8MsixCapSize != 0)
1298 {
1299 Assert(pDev->Int.s.pMsixPageR3 != NULL);
1300 memcpy(pDev->Int.s.pMsixPageR3, pvMsixPage, 0x1000);
1301 }
1302 }
1303
1304 RTMemTmpFree(pvMsixPage);
1305
1306 return rc;
1307}
1308
1309static DECLCALLBACK(int) ich9pciR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
1310{
1311 PDEVPCIROOT pThis = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
1312 PDEVPCIBUS pBus = &pThis->PciBus;
1313 uint32_t u32;
1314 int rc;
1315
1316 /* We ignore this version as there's no saved state with it anyway */
1317 if (uVersion == VBOX_ICH9PCI_SAVED_STATE_VERSION_NOMSI)
1318 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1319 if (uVersion > VBOX_ICH9PCI_SAVED_STATE_VERSION_MSI)
1320 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1321
1322 /*
1323 * Bus state data.
1324 */
1325 SSMR3GetU32(pSSM, &pThis->uConfigReg);
1326
1327 /*
1328 * Load IRQ states.
1329 */
1330 for (unsigned i = 0; i < RT_ELEMENTS(pThis->auPciApicIrqLevels); i++)
1331 SSMR3GetU32(pSSM, (uint32_t*)&pThis->auPciApicIrqLevels[i]);
1332
1333 /* separator */
1334 rc = SSMR3GetU32(pSSM, &u32);
1335 if (RT_FAILURE(rc))
1336 return rc;
1337 if (u32 != (uint32_t)~0)
1338 AssertMsgFailedReturn(("u32=%#x\n", u32), rc);
1339
1340 return ich9pciR3CommonLoadExec(pBus, pSSM, uVersion, uPass);
1341}
1342
1343static DECLCALLBACK(int) ich9pcibridgeR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
1344{
1345 PDEVPCIBUS pThis = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
1346 if (uVersion > VBOX_ICH9PCI_SAVED_STATE_VERSION_MSI)
1347 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
1348 return ich9pciR3CommonLoadExec(pThis, pSSM, uVersion, uPass);
1349}
1350
1351
1352
1353/* -=-=-=-=-=- Fake PCI BIOS Init -=-=-=-=-=- */
1354
1355
1356/*
1357 * Perform imeediate read of configuration space register.
1358 * Cannot be rescheduled, as already in R3.
1359 */
1360static uint32_t ich9pciBiosInitReadConfig(PDEVPCIROOT pPciRoot, uint8_t uBus, uint8_t uDevFn, uint32_t addr, uint32_t len)
1361{
1362 PciAddress aPciAddr;
1363 aPciAddr.iBus = uBus;
1364 aPciAddr.iDeviceFunc = uDevFn;
1365 aPciAddr.iRegister = addr;
1366
1367 uint32_t u32Val = 0;
1368 int rc = ich9pciDataReadAddr(pPciRoot, &aPciAddr, len, &u32Val, VERR_INTERNAL_ERROR);
1369 AssertRC(rc);
1370
1371 return u32Val;
1372}
1373
1374
1375/*
1376 * Perform imeediate write to configuration space register.
1377 * Cannot be rescheduled, as already in R3.
1378 */
1379static void ich9pciBiosInitWriteConfig(PDEVPCIROOT pPciRoot, uint8_t uBus, uint8_t uDevFn, uint32_t addr, uint32_t val, uint32_t len)
1380{
1381 PciAddress aPciAddr;
1382 aPciAddr.iBus = uBus;
1383 aPciAddr.iDeviceFunc = uDevFn;
1384 aPciAddr.iRegister = addr;
1385
1386 int rc = ich9pciDataWriteAddr(pPciRoot, &aPciAddr, val, len, VERR_INTERNAL_ERROR);
1387 AssertRC(rc);
1388}
1389
1390
1391static void ich9pciBiosInitSetRegionAddress(PDEVPCIROOT pPciRoot, uint8_t uBus, uint8_t uDevFn, int iRegion, uint64_t addr)
1392{
1393 uint32_t uReg = ich9pciGetRegionReg(iRegion);
1394
1395 /* Read memory type first. */
1396 uint8_t uResourceType = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, uReg, 1);
1397 bool f64Bit = (uResourceType & ((uint8_t)(PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_IO)))
1398 == PCI_ADDRESS_SPACE_BAR64;
1399
1400 Log(("Set region address: %02x:%02x.%d region %d address=%RX64%s\n",
1401 uBus, uDevFn >> 3, uDevFn & 7, iRegion, addr, f64Bit ? " (64-bit)" : ""));
1402
1403 /* Write address of the device. */
1404 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, uReg, (uint32_t)addr, 4);
1405 if (f64Bit)
1406 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, uReg + 4, (uint32_t)(addr >> 32), 4);
1407}
1408
1409
1410static void ich9pciBiosInitBridge(PDEVPCIROOT pPciRoot, uint8_t uBus, uint8_t uDevFn)
1411{
1412 Log(("BIOS init bridge: %02x::%02x.%d\n", uBus, uDevFn >> 3, uDevFn & 7));
1413
1414 /*
1415 * The I/O range for the bridge must be aligned to a 4KB boundary.
1416 * This does not change anything really as the access to the device is not going
1417 * through the bridge but we want to be compliant to the spec.
1418 */
1419 if ((pPciRoot->uPciBiosIo % 4096) != 0)
1420 {
1421 pPciRoot->uPciBiosIo = RT_ALIGN_32(pPciRoot->uPciBiosIo, 4*1024);
1422 Log(("%s: Aligned I/O start address. New address %#x\n", __FUNCTION__, pPciRoot->uPciBiosIo));
1423 }
1424 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_IO_BASE, (pPciRoot->uPciBiosIo >> 8) & 0xf0, 1);
1425
1426 /* The MMIO range for the bridge must be aligned to a 1MB boundary. */
1427 if ((pPciRoot->uPciBiosMmio % (1024 * 1024)) != 0)
1428 {
1429 pPciRoot->uPciBiosMmio = RT_ALIGN_32(pPciRoot->uPciBiosMmio, 1024*1024);
1430 Log(("%s: Aligned MMIO start address. New address %#x\n", __FUNCTION__, pPciRoot->uPciBiosMmio));
1431 }
1432 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_MEMORY_BASE, (pPciRoot->uPciBiosMmio >> 16) & UINT32_C(0xffff0), 2);
1433
1434 /* Save values to compare later to. */
1435 uint32_t u32IoAddressBase = pPciRoot->uPciBiosIo;
1436 uint32_t u32MMIOAddressBase = pPciRoot->uPciBiosMmio;
1437 uint8_t uBridgeBus = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_SECONDARY_BUS, 1);
1438
1439 /* Init devices behind the bridge and possibly other bridges as well. */
1440 for (int iDev = 0; iDev <= 255; iDev++)
1441 ich9pciBiosInitDevice(pPciRoot, uBridgeBus, iDev);
1442
1443 /*
1444 * Set I/O limit register. If there is no device with I/O space behind the bridge
1445 * we set a lower value than in the base register.
1446 * The result with a real bridge is that no I/O transactions are passed to the secondary
1447 * interface. Again this doesn't really matter here but we want to be compliant to the spec.
1448 */
1449 if ((u32IoAddressBase != pPciRoot->uPciBiosIo) && ((pPciRoot->uPciBiosIo % 4096) != 0))
1450 {
1451 /* The upper boundary must be one byte less than a 4KB boundary. */
1452 pPciRoot->uPciBiosIo = RT_ALIGN_32(pPciRoot->uPciBiosIo, 4*1024);
1453 }
1454
1455 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_IO_LIMIT, ((pPciRoot->uPciBiosIo >> 8) & 0xf0) - 1, 1);
1456
1457 /* Same with the MMIO limit register but with 1MB boundary here. */
1458 if ((u32MMIOAddressBase != pPciRoot->uPciBiosMmio) && ((pPciRoot->uPciBiosMmio % (1024 * 1024)) != 0))
1459 {
1460 /* The upper boundary must be one byte less than a 1MB boundary. */
1461 pPciRoot->uPciBiosMmio = RT_ALIGN_32(pPciRoot->uPciBiosMmio, 1024*1024);
1462 }
1463 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_MEMORY_LIMIT, ((pPciRoot->uPciBiosMmio >> 16) & UINT32_C(0xfff0)) - 1, 2);
1464
1465 /*
1466 * Set the prefetch base and limit registers. We currently have no device with a prefetchable region
1467 * which may be behind a bridge. That's why it is unconditionally disabled here atm by writing a higher value into
1468 * the base register than in the limit register.
1469 */
1470 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_PREF_MEMORY_BASE, 0xfff0, 2);
1471 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_PREF_MEMORY_LIMIT, 0x0, 2);
1472 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_PREF_BASE_UPPER32, 0x00, 4);
1473 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_PREF_LIMIT_UPPER32, 0x00, 4);
1474}
1475
1476static void ich9pciBiosInitDevice(PDEVPCIROOT pPciRoot, uint8_t uBus, uint8_t uDevFn)
1477{
1478 uint16_t uDevClass, uVendor, uDevice;
1479 uint8_t uCmd;
1480
1481 uDevClass = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_CLASS_DEVICE, 2);
1482 uVendor = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_VENDOR_ID, 2);
1483 uDevice = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_DEVICE_ID, 2);
1484
1485 /* If device is present */
1486 if (uVendor == 0xffff)
1487 return;
1488
1489 Log(("BIOS init device: %02x:%02x.%d\n", uBus, uDevFn >> 3, uDevFn & 7));
1490
1491 switch (uDevClass)
1492 {
1493 case 0x0101:
1494 /* IDE controller */
1495 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, 0x40, 0x8000, 2); /* enable IDE0 */
1496 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, 0x42, 0x8000, 2); /* enable IDE1 */
1497 goto default_map;
1498 break;
1499 case 0x0300:
1500 /* VGA controller */
1501
1502 /* NB: Default Bochs VGA LFB address is 0xE0000000. Old guest
1503 * software may break if the framebuffer isn't mapped there.
1504 */
1505
1506 /*
1507 * Legacy VGA I/O ports are implicitly decoded by a VGA class device. But
1508 * only the framebuffer (i.e., a memory region) is explicitly registered via
1509 * ich9pciSetRegionAddress, so don't forget to enable I/O decoding.
1510 */
1511 uCmd = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_COMMAND, 1);
1512 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_COMMAND,
1513 uCmd | PCI_COMMAND_IOACCESS,
1514 1);
1515 goto default_map;
1516 break;
1517 case 0x0604:
1518 /* PCI-to-PCI bridge. */
1519 ich9pciBiosInitBridge(pPciRoot, uBus, uDevFn);
1520 break;
1521 default:
1522 default_map:
1523 {
1524 /* default memory mappings */
1525 bool fActiveMemRegion = false;
1526 bool fActiveIORegion = false;
1527 /*
1528 * We ignore ROM region here.
1529 */
1530 for (int iRegion = 0; iRegion < VBOX_PCI_NUM_REGIONS - 1; iRegion++)
1531 {
1532 uint32_t u32Address = ich9pciGetRegionReg(iRegion);
1533
1534 /* Calculate size - we write all 1s into the BAR, and then evaluate which bits
1535 are cleared. */
1536 uint8_t u8ResourceType = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, u32Address, 1);
1537
1538 bool f64Bit = (u8ResourceType & ((uint8_t)(PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_IO)))
1539 == PCI_ADDRESS_SPACE_BAR64;
1540 bool fIsPio = ((u8ResourceType & PCI_COMMAND_IOACCESS) == PCI_COMMAND_IOACCESS);
1541 uint64_t cbRegSize64 = 0;
1542
1543 if (f64Bit)
1544 {
1545 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, u32Address, UINT32_C(0xffffffff), 4);
1546 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, u32Address+4, UINT32_C(0xffffffff), 4);
1547 cbRegSize64 = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, u32Address, 4);
1548 cbRegSize64 |= ((uint64_t)ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, u32Address+4, 4) << 32);
1549 cbRegSize64 &= ~UINT64_C(0x0f);
1550 cbRegSize64 = (~cbRegSize64) + 1;
1551
1552 /* No 64-bit PIO regions possible. */
1553#ifndef DEBUG_bird /* EFI triggers this for DevAHCI. */
1554 AssertMsg((u8ResourceType & PCI_COMMAND_IOACCESS) == 0, ("type=%#x rgn=%d\n", u8ResourceType, iRegion));
1555#endif
1556 }
1557 else
1558 {
1559 uint32_t cbRegSize32;
1560 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, u32Address, UINT32_C(0xffffffff), 4);
1561 cbRegSize32 = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, u32Address, 4);
1562
1563 /* Clear resource information depending on resource type. */
1564 if (fIsPio) /* PIO */
1565 cbRegSize32 &= ~UINT32_C(0x01);
1566 else /* MMIO */
1567 cbRegSize32 &= ~UINT32_C(0x0f);
1568
1569 /*
1570 * Invert all bits and add 1 to get size of the region.
1571 * (From PCI implementation note)
1572 */
1573 if (fIsPio && (cbRegSize32 & UINT32_C(0xffff0000)) == 0)
1574 cbRegSize32 = (~(cbRegSize32 | UINT32_C(0xffff0000))) + 1;
1575 else
1576 cbRegSize32 = (~cbRegSize32) + 1;
1577
1578 cbRegSize64 = cbRegSize32;
1579 }
1580 Log2(("%s: Size of region %u for device %d on bus %d is %lld\n", __FUNCTION__, iRegion, uDevFn, uBus, cbRegSize64));
1581
1582 if (cbRegSize64)
1583 {
1584 /* Try 32-bit base first. */
1585 uint32_t* paddr = fIsPio ? &pPciRoot->uPciBiosIo : &pPciRoot->uPciBiosMmio;
1586 uint64_t uNew = *paddr;
1587 /* Align starting address to region size. */
1588 uNew = (uNew + cbRegSize64 - 1) & ~(cbRegSize64 - 1);
1589 if (fIsPio)
1590 uNew &= UINT32_C(0xffff);
1591 /* Unconditionally exclude I/O-APIC/HPET/ROM. Pessimistic, but better than causing a mess. */
1592 if ( !uNew
1593 || (uNew <= UINT32_C(0xffffffff) && uNew + cbRegSize64 - 1 >= UINT32_C(0xfec00000))
1594 || uNew >= _4G)
1595 {
1596 if (f64Bit)
1597 {
1598 /* Map a 64-bit region above 4GB. */
1599 Assert(!fIsPio);
1600 uNew = pPciRoot->uPciBiosMmio64;
1601 /* Align starting address to region size. */
1602 uNew = (uNew + cbRegSize64 - 1) & ~(cbRegSize64 - 1);
1603 LogFunc(("Start address of 64-bit MMIO region %u/%u is %#llx\n", iRegion, iRegion + 1, uNew));
1604 ich9pciBiosInitSetRegionAddress(pPciRoot, uBus, uDevFn, iRegion, uNew);
1605 fActiveMemRegion = true;
1606 pPciRoot->uPciBiosMmio64 = uNew + cbRegSize64;
1607 Log2Func(("New 64-bit address is %#llx\n", pPciRoot->uPciBiosMmio64));
1608 }
1609 else
1610 {
1611 LogRel(("PCI: no space left for BAR%u of device %u/%u/%u (vendor=%#06x device=%#06x)\n",
1612 iRegion, uBus, uDevFn >> 3, uDevFn & 7, uVendor, uDevice)); /** @todo make this a VM start failure later. */
1613 /* Undo the mapping mess caused by the size probing. */
1614 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, u32Address, UINT32_C(0), 4);
1615 }
1616 }
1617 else
1618 {
1619 LogFunc(("Start address of %s region %u is %#x\n", (fIsPio ? "I/O" : "MMIO"), iRegion, uNew));
1620 ich9pciBiosInitSetRegionAddress(pPciRoot, uBus, uDevFn, iRegion, uNew);
1621 if (fIsPio)
1622 fActiveIORegion = true;
1623 else
1624 fActiveMemRegion = true;
1625 *paddr = uNew + cbRegSize64;
1626 Log2Func(("New 32-bit address is %#x\n", *paddr));
1627 }
1628
1629 if (f64Bit)
1630 iRegion++; /* skip next region */
1631 }
1632 }
1633
1634 /* Update the command word appropriately. */
1635 uCmd = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_COMMAND, 2);
1636 if (fActiveMemRegion)
1637 uCmd |= PCI_COMMAND_MEMACCESS; /* Enable MMIO access. */
1638 if (fActiveIORegion)
1639 uCmd |= PCI_COMMAND_IOACCESS; /* Enable I/O space access. */
1640 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_COMMAND, uCmd, 2);
1641 break;
1642 }
1643 }
1644
1645 /* map the interrupt */
1646 uint32_t iPin = ich9pciBiosInitReadConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_INTERRUPT_PIN, 1);
1647 if (iPin != 0)
1648 {
1649 iPin--;
1650
1651 if (uBus != 0)
1652 {
1653 /* Find bus this device attached to. */
1654 PDEVPCIBUS pBus = &pPciRoot->PciBus;
1655 while (1)
1656 {
1657 PPDMPCIDEV pBridge = ich9pciFindBridge(pBus, uBus);
1658 if (!pBridge)
1659 {
1660 Assert(false);
1661 break;
1662 }
1663 if (uBus == PDMPciDevGetByte(pBridge, VBOX_PCI_SECONDARY_BUS))
1664 {
1665 /* OK, found bus this device attached to. */
1666 break;
1667 }
1668 pBus = PDMINS_2_DATA(pBridge->Int.s.CTX_SUFF(pDevIns), PDEVPCIBUS);
1669 }
1670
1671 /* We need to go up to the host bus to see which irq pin this
1672 * device will use there. See logic in ich9pcibridgeSetIrq().
1673 */
1674 while (pBus->iBus != 0)
1675 {
1676 /* Get the pin the device would assert on the bridge. */
1677 iPin = ((pBus->PciDev.uDevFn >> 3) + iPin) & 3;
1678 pBus = pBus->PciDev.Int.s.pBusR3;
1679 };
1680 }
1681
1682 int iIrq = aPciIrqs[ich9pciSlotGetPirq(uBus, uDevFn, iPin)];
1683 Log(("Using pin %d and IRQ %d for device %02x:%02x.%d\n",
1684 iPin, iIrq, uBus, uDevFn>>3, uDevFn&7));
1685 ich9pciBiosInitWriteConfig(pPciRoot, uBus, uDevFn, VBOX_PCI_INTERRUPT_LINE, iIrq, 1);
1686 }
1687}
1688
1689/**
1690 * Initializes bridges registers used for routing.
1691 *
1692 * @returns Max subordinate bus number.
1693 * @param pPciRoot Global device instance data used to generate unique bus numbers.
1694 * @param pBus The PCI bus to initialize.
1695 * @param uBusPrimary The primary bus number the bus is connected to.
1696 * @param uBusSecondary The secondary bus number, i.e. the bus number behind the bridge.
1697 */
1698static uint8_t ich9pciBiosInitBridgeTopology(PDEVPCIROOT pPciRoot, PDEVPCIBUS pBus, unsigned uBusPrimary, unsigned uBusSecondary)
1699{
1700 PPDMPCIDEV pBridgeDev = &pBus->PciDev;
1701
1702 /* Set only if we are not on the root bus, it has no primary bus attached. */
1703 if (uBusSecondary != 0)
1704 {
1705 PCIDevSetByte(pBridgeDev, VBOX_PCI_PRIMARY_BUS, uBusPrimary);
1706 PCIDevSetByte(pBridgeDev, VBOX_PCI_SECONDARY_BUS, uBusSecondary);
1707 }
1708
1709 uint8_t uMaxSubNum = 0;
1710 for (uint32_t iBridge = 0; iBridge < pBus->cBridges; iBridge++)
1711 {
1712 PPDMPCIDEV pBridge = pBus->papBridgesR3[iBridge];
1713 AssertMsg(pBridge && pciDevIsPci2PciBridge(pBridge),
1714 ("Device is not a PCI bridge but on the list of PCI bridges\n"));
1715 PDEVPCIBUS pChildBus = PDMINS_2_DATA(pBridge->Int.s.CTX_SUFF(pDevIns), PDEVPCIBUS);
1716 uint8_t uMaxChildSubBus = ich9pciBiosInitBridgeTopology(pPciRoot, pChildBus, uBusSecondary, pChildBus->iBus);
1717 uMaxSubNum = RT_MAX(uMaxSubNum, RT_MAX(uMaxChildSubBus, pChildBus->iBus));
1718 }
1719 PCIDevSetByte(pBridgeDev, VBOX_PCI_SUBORDINATE_BUS, uMaxSubNum);
1720 Log2(("ich9pciBiosInitBridgeTopology: for bus %p: primary=%d secondary=%d subordinate=%d\n",
1721 pBus,
1722 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_PRIMARY_BUS),
1723 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_SECONDARY_BUS),
1724 PDMPciDevGetByte(pBridgeDev, VBOX_PCI_SUBORDINATE_BUS)
1725 ));
1726
1727 return uMaxSubNum;
1728}
1729
1730
1731/**
1732 * @interface_method_impl{PDMPCIBUSREG,pfnFakePCIBIOSR3}
1733 */
1734static DECLCALLBACK(int) ich9pciFakePCIBIOS(PPDMDEVINS pDevIns)
1735{
1736 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
1737 PVM pVM = PDMDevHlpGetVM(pDevIns);
1738 uint32_t const cbBelow4GB = MMR3PhysGetRamSizeBelow4GB(pVM);
1739 uint64_t const cbAbove4GB = MMR3PhysGetRamSizeAbove4GB(pVM);
1740
1741 /*
1742 * Set the start addresses.
1743 */
1744 pPciRoot->uPciBiosBus = 0;
1745 pPciRoot->uPciBiosIo = 0xd000;
1746 pPciRoot->uPciBiosMmio = cbBelow4GB;
1747 pPciRoot->uPciBiosMmio64 = cbAbove4GB + _4G;
1748
1749 /* NB: Assume that if PCI controller MMIO range is enabled, it is at the bottom of the memory hole. */
1750 if (pPciRoot->u64PciConfigMMioAddress)
1751 {
1752 AssertRelease(pPciRoot->u64PciConfigMMioAddress >= cbBelow4GB);
1753 pPciRoot->uPciBiosMmio = pPciRoot->u64PciConfigMMioAddress + pPciRoot->u64PciConfigMMioLength;
1754 }
1755 Log(("cbBelow4GB: %#RX32, uPciBiosMmio: %#RX64, cbAbove4GB: %#RX64, uPciBiosMmio64=%#RX64\n",
1756 cbBelow4GB, pPciRoot->uPciBiosMmio, cbAbove4GB, pPciRoot->uPciBiosMmio64));
1757
1758 /*
1759 * Assign bridge topology, for further routing to work.
1760 */
1761 PDEVPCIBUS pBus = &pPciRoot->PciBus;
1762 AssertLogRel(pBus->iBus == 0);
1763 ich9pciBiosInitBridgeTopology(pPciRoot, pBus, 0, pBus->iBus);
1764
1765 /*
1766 * Init the devices.
1767 */
1768 for (uint32_t i = 0; i < 256; i++)
1769 ich9pciBiosInitDevice(pPciRoot, 0, i);
1770
1771 return VINF_SUCCESS;
1772}
1773
1774
1775/* -=-=-=-=-=- PCI Config Space -=-=-=-=-=- */
1776
1777
1778/**
1779 * @callback_method_impl{PFNPCICONFIGREAD, Default config space read callback.}
1780 */
1781DECLCALLBACK(uint32_t) devpciR3CommonDefaultConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb)
1782{
1783 NOREF(pDevIns);
1784
1785 uint32_t uValue;
1786 if (uAddress + cb <= 256)
1787 {
1788 switch (cb)
1789 {
1790 case 1:
1791 uValue = PDMPciDevGetByte(pPciDev, uAddress);
1792 break;
1793 case 2:
1794 uValue = PDMPciDevGetWord(pPciDev, uAddress);
1795 break;
1796 case 4:
1797 uValue = PDMPciDevGetDWord(pPciDev, uAddress);
1798 break;
1799 default:
1800 AssertFailed();
1801 uValue = 0;
1802 break;
1803 }
1804
1805#ifdef LOG_ENABLED
1806 if ( pciDevIsMsiCapable(pPciDev)
1807 && uAddress - (uint32_t)pPciDev->Int.s.u8MsiCapOffset < (uint32_t)pPciDev->Int.s.u8MsiCapSize )
1808 Log2(("devpciR3CommonDefaultConfigRead: MSI CAP: %#x LB %u -> %#x\n", uAddress - (uint32_t)pPciDev->Int.s.u8MsiCapOffset, cb, uValue));
1809 else if ( pciDevIsMsixCapable(pPciDev)
1810 && uAddress - (uint32_t)pPciDev->Int.s.u8MsixCapOffset < (uint32_t)pPciDev->Int.s.u8MsixCapSize)
1811 Log2(("devpciR3CommonDefaultConfigRead: MSI-X CAP: %#x LB %u -> %#x\n", uAddress - (uint32_t)pPciDev->Int.s.u8MsiCapOffset, cb, uValue));
1812#endif
1813 }
1814 else
1815 {
1816 if (uAddress + cb < 4096)
1817 LogRel(("PCI: %8s/%u: Read from extended register %d fallen back to generic code\n",
1818 pPciDev->pszNameR3, pPciDev->Int.s.CTX_SUFF(pDevIns)->iInstance, uAddress));
1819 else
1820 AssertFailed();
1821 uValue = 0;
1822 }
1823 return uValue;
1824}
1825
1826
1827/**
1828 * Worker for ich9pciResetDevice and devpciR3UpdateMappings that unmaps a region.
1829 *
1830 * @returns VBox status code.
1831 * @param pDev The PCI device.
1832 * @param iRegion The region to unmap.
1833 */
1834static int ich9pciUnmapRegion(PPDMPCIDEV pDev, int iRegion)
1835{
1836 PCIIORegion *pRegion = &pDev->Int.s.aIORegions[iRegion];
1837 AssertReturn(pRegion->size != 0, VINF_SUCCESS);
1838
1839 int rc;
1840 if (pRegion->addr == INVALID_PCI_ADDRESS)
1841 rc = VINF_SUCCESS;
1842 else
1843 {
1844 if (pRegion->type & PCI_ADDRESS_SPACE_IO)
1845 {
1846 /* Port IO */
1847 rc = PDMDevHlpIOPortDeregister(pDev->Int.s.pDevInsR3, pRegion->addr, pRegion->size);
1848 AssertRC(rc);
1849 }
1850 else
1851 {
1852 PDEVPCIBUS pBus = pDev->Int.s.CTX_SUFF(pBus);
1853 RTGCPHYS GCPhysBase = pRegion->addr;
1854 if (pBus->pPciHlpR3->pfnIsMMIOExBase(pBus->pDevInsR3, pDev->Int.s.pDevInsR3, GCPhysBase))
1855 {
1856 /* unmap it. */
1857 rc = pRegion->map_func(pDev->Int.s.pDevInsR3, pDev, iRegion,
1858 NIL_RTGCPHYS, pRegion->size, (PCIADDRESSSPACE)(pRegion->type));
1859 AssertRC(rc);
1860 rc = PDMDevHlpMMIOExUnmap(pDev->Int.s.pDevInsR3, pDev, iRegion, GCPhysBase);
1861 }
1862 else
1863 rc = PDMDevHlpMMIODeregister(pDev->Int.s.pDevInsR3, GCPhysBase, pRegion->size);
1864 AssertRC(rc);
1865 }
1866 pRegion->addr = INVALID_PCI_ADDRESS;
1867 }
1868 return rc;
1869}
1870
1871
1872/**
1873 * Worker for devpciR3IsConfigByteWritable that update BAR and ROM mappings.
1874 *
1875 * @param pDev The PCI device to update the mappings for.
1876 */
1877static void devpciR3UpdateMappings(PPDMPCIDEV pPciDev)
1878{
1879 uint16_t const u16Cmd = ich9pciGetWord(pPciDev, VBOX_PCI_COMMAND);
1880 for (unsigned iRegion = 0; iRegion < VBOX_PCI_NUM_REGIONS; iRegion++)
1881 {
1882 PCIIORegion *pRegion = &pPciDev->Int.s.aIORegions[iRegion];
1883 uint64_t const cbRegion = pRegion->size;
1884 if (cbRegion != 0)
1885 {
1886 uint32_t const offCfgReg = ich9pciGetRegionReg(iRegion);
1887 bool const f64Bit = (pRegion->type & ((uint8_t)(PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_IO)))
1888 == PCI_ADDRESS_SPACE_BAR64;
1889 uint64_t uNew = INVALID_PCI_ADDRESS;
1890
1891 /*
1892 * Port I/O region. Check if mapped and within 1..65535 range.
1893 */
1894 if (pRegion->type & PCI_ADDRESS_SPACE_IO)
1895 {
1896 if (u16Cmd & PCI_COMMAND_IOACCESS)
1897 {
1898 uint32_t uIoBase = ich9pciGetDWord(pPciDev, offCfgReg);
1899 uIoBase &= ~(uint32_t)(cbRegion - 1);
1900
1901 uint64_t uLast = cbRegion - 1 + uIoBase;
1902 if ( uLast < _64K
1903 && uIoBase < uLast
1904 && uIoBase > 0)
1905 uNew = uIoBase;
1906 }
1907 }
1908 /*
1909 * MMIO or ROM. Check ROM enable bit and range.
1910 *
1911 * Note! We exclude the I/O-APIC/HPET/ROM area at the end of the first 4GB to
1912 * prevent the (fake) PCI BIOS and others from making a mess. Pure paranoia.
1913 */
1914 else if (u16Cmd & PCI_COMMAND_MEMACCESS)
1915 {
1916 uint64_t uMemBase = ich9pciGetDWord(pPciDev, offCfgReg);
1917 if (f64Bit)
1918 {
1919 Assert(iRegion < VBOX_PCI_ROM_SLOT);
1920 uMemBase |= (uint64_t)ich9pciGetDWord(pPciDev, offCfgReg + 4) << 32;
1921 }
1922 if ( iRegion != PCI_ROM_SLOT
1923 || (uMemBase & RT_BIT_32(0))) /* ROM enable bit. */
1924 {
1925 uMemBase &= ~(cbRegion - 1);
1926
1927 uint64_t uLast = uMemBase + cbRegion - 1;
1928 if ( uMemBase < uLast
1929 && uMemBase > 0
1930 && !( uNew <= UINT32_C(0xffffffff)
1931 && uLast >= UINT32_C(0xfec00000)) )
1932 uNew = uMemBase;
1933 }
1934 }
1935
1936 /*
1937 * Do real unmapping and/or mapping if the address change.
1938 */
1939 if (uNew != pRegion->addr)
1940 {
1941 LogRel2(("PCI: config dev %u/%u (%s) BAR%i: %#RX64 -> %#RX64 (LB %RX64 (%RU64))\n",
1942 pPciDev->uDevFn >> VBOX_PCI_DEVFN_DEV_SHIFT, pPciDev->uDevFn & VBOX_PCI_DEVFN_FUN_MASK,
1943 pPciDev->pszNameR3, iRegion, pRegion->addr, uNew, cbRegion, cbRegion));
1944
1945 ich9pciUnmapRegion(pPciDev, iRegion);
1946 pRegion->addr = uNew;
1947 if (uNew != INVALID_PCI_ADDRESS)
1948 {
1949 int rc = pRegion->map_func(pPciDev->Int.s.pDevInsR3, pPciDev, iRegion, uNew, cbRegion,
1950 (PCIADDRESSSPACE)(pRegion->type));
1951 AssertRC(rc);
1952 }
1953 }
1954
1955 if (f64Bit)
1956 iRegion++;
1957 }
1958 /* else: size == 0: unused region */
1959 }
1960}
1961
1962
1963/**
1964 * Worker for devpciR3CommonDefaultConfigWrite that write a byte to a BAR.
1965 *
1966 * @param pPciDev The PCI device.
1967 * @param iRegion The region.
1968 * @param off The BAR offset.
1969 * @param bVal The byte to write.
1970 */
1971DECLINLINE(void) devpciR3WriteBarByte(PPDMPCIDEV pPciDev, uint32_t iRegion, uint32_t off, uint8_t bVal)
1972{
1973 PCIIORegion *pRegion = &pPciDev->Int.s.aIORegions[iRegion];
1974 Log3(("devpciR3WriteBarByte: region=%d off=%d val=%#x size=%#llx\n", iRegion, off, bVal, pRegion->size));
1975 Assert(off <= 3);
1976
1977 /* Check if we're writing to upper part of 64-bit BAR. */
1978 if (pRegion->type == 0xff)
1979 {
1980 AssertLogRelReturnVoid(iRegion > 0 && iRegion < VBOX_PCI_ROM_SLOT);
1981 pRegion--;
1982 iRegion--;
1983 off += 4;
1984 Assert(pRegion->type & PCI_ADDRESS_SPACE_BAR64);
1985 }
1986
1987 /* Ignore zero sized regions (they don't exist). */
1988 if (pRegion->size != 0)
1989 {
1990 uint32_t uAddr = ich9pciGetRegionReg(iRegion) + off;
1991 Assert((pRegion->size & (pRegion->size - 1)) == 0); /* Region size must be power of two. */
1992 uint8_t bMask = ( (pRegion->size - 1) >> (off * 8) ) & 0xff;
1993 if (off == 0)
1994 bMask |= (pRegion->type & PCI_ADDRESS_SPACE_IO)
1995 ? (1 << 2) - 1 /* 2 lowest bits for IO region */ :
1996 (1 << 4) - 1 /* 4 lowest bits for memory region, also ROM enable bit for ROM region */;
1997
1998 uint8_t bOld = PDMPciDevGetByte(pPciDev, uAddr) & bMask;
1999 bVal = (bOld & bMask) | (bVal & ~bMask);
2000
2001 Log3(("devpciR3WriteBarByte: %x changed to %x\n", bOld, bVal));
2002
2003 PCIDevSetByte(pPciDev, uAddr, bVal);
2004 }
2005}
2006
2007
2008/**
2009 * Checks if the given configuration byte is writable.
2010 *
2011 * @returns true if writable, false if not
2012 * @param uAddress The config space byte byte.
2013 * @param bHeaderType The device header byte.
2014 */
2015DECLINLINE(bool) devpciR3IsConfigByteWritable(uint32_t uAddress, uint8_t bHeaderType)
2016{
2017 switch (bHeaderType)
2018 {
2019 case 0x00: /* normal device */
2020 case 0x80: /* multi-function device */
2021 switch (uAddress)
2022 {
2023 /* Read-only registers. */
2024 case VBOX_PCI_VENDOR_ID:
2025 case VBOX_PCI_VENDOR_ID+1:
2026 case VBOX_PCI_DEVICE_ID:
2027 case VBOX_PCI_DEVICE_ID+1:
2028 case VBOX_PCI_REVISION_ID:
2029 case VBOX_PCI_CLASS_PROG:
2030 case VBOX_PCI_CLASS_SUB:
2031 case VBOX_PCI_CLASS_BASE:
2032 case VBOX_PCI_HEADER_TYPE:
2033 case VBOX_PCI_SUBSYSTEM_VENDOR_ID:
2034 case VBOX_PCI_SUBSYSTEM_VENDOR_ID+1:
2035 case VBOX_PCI_SUBSYSTEM_ID:
2036 case VBOX_PCI_SUBSYSTEM_ID+1:
2037 case VBOX_PCI_ROM_ADDRESS:
2038 case VBOX_PCI_ROM_ADDRESS+1:
2039 case VBOX_PCI_ROM_ADDRESS+2:
2040 case VBOX_PCI_ROM_ADDRESS+3:
2041 case VBOX_PCI_CAPABILITY_LIST:
2042 case VBOX_PCI_INTERRUPT_PIN:
2043 return false;
2044 /* Other registers can be written. */
2045 default:
2046 return true;
2047 }
2048 break;
2049 case 0x01: /* PCI-PCI bridge */
2050 switch (uAddress)
2051 {
2052 /* Read-only registers. */
2053 case VBOX_PCI_VENDOR_ID:
2054 case VBOX_PCI_VENDOR_ID+1:
2055 case VBOX_PCI_DEVICE_ID:
2056 case VBOX_PCI_DEVICE_ID+1:
2057 case VBOX_PCI_REVISION_ID:
2058 case VBOX_PCI_CLASS_PROG:
2059 case VBOX_PCI_CLASS_SUB:
2060 case VBOX_PCI_CLASS_BASE:
2061 case VBOX_PCI_HEADER_TYPE:
2062 case VBOX_PCI_ROM_ADDRESS_BR:
2063 case VBOX_PCI_ROM_ADDRESS_BR+1:
2064 case VBOX_PCI_ROM_ADDRESS_BR+2:
2065 case VBOX_PCI_ROM_ADDRESS_BR+3:
2066 case VBOX_PCI_INTERRUPT_PIN:
2067 return false;
2068 /* Other registers can be written. */
2069 default:
2070 return true;
2071 }
2072 break;
2073 default:
2074 AssertMsgFailed(("Unknown header type %#x\n", bHeaderType));
2075 return false;
2076 }
2077}
2078
2079
2080/**
2081 * @callback_method_impl{PFNPCICONFIGWRITE,
2082 * Default config space write callback.}
2083 *
2084 * See paragraph 7.5 of PCI Express specification (p. 349) for
2085 * definition of registers and their writability policy.
2086 */
2087DECLCALLBACK(void) devpciR3CommonDefaultConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
2088 uint32_t uAddress, uint32_t u32Value, unsigned cb)
2089{
2090 NOREF(pDevIns);
2091 Assert(cb <= 4);
2092
2093 if (uAddress + cb <= 256)
2094 {
2095 /*
2096 * MSI and MSI-X capabilites needs to be handled separately.
2097 */
2098 if ( pciDevIsMsiCapable(pPciDev)
2099 && uAddress - (uint32_t)pPciDev->Int.s.u8MsiCapOffset < (uint32_t)pPciDev->Int.s.u8MsiCapSize)
2100 MsiPciConfigWrite(pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pDevIns),
2101 pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pPciHlp),
2102 pPciDev, uAddress, u32Value, cb);
2103 else if ( pciDevIsMsixCapable(pPciDev)
2104 && uAddress - (uint32_t)pPciDev->Int.s.u8MsixCapOffset < (uint32_t)pPciDev->Int.s.u8MsixCapSize)
2105 MsixPciConfigWrite(pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pDevIns),
2106 pPciDev->Int.s.CTX_SUFF(pBus)->CTX_SUFF(pPciHlp),
2107 pPciDev, uAddress, u32Value, cb);
2108 else
2109 {
2110 /*
2111 * Handle the writes byte-by-byte to catch all possible cases.
2112 *
2113 * Note! Real hardware may not necessarily handle non-dword writes like
2114 * we do here and even produce erratic behavior. We don't (yet)
2115 * try emulate that.
2116 */
2117 uint8_t const bHeaderType = ich9pciGetByte(pPciDev, VBOX_PCI_HEADER_TYPE);
2118 bool const fP2PBridge = bHeaderType == 0x01; /* PCI-PCI bridge */
2119 bool fUpdateMappings = false;
2120 while (cb-- > 0)
2121 {
2122 bool fWritable = devpciR3IsConfigByteWritable(uAddress, bHeaderType);
2123 uint8_t bVal = (uint8_t)u32Value;
2124 bool fRom = false;
2125 switch (uAddress)
2126 {
2127 case VBOX_PCI_COMMAND: /* Command register, bits 0-7. */
2128 if (fWritable)
2129 {
2130 PCIDevSetByte(pPciDev, uAddress, bVal);
2131 fUpdateMappings = true; /** @todo r=bird: Probably not necessary to update mappings on VBOX_PCI_COMMAND changes for bridges? */
2132 }
2133 break;
2134
2135 case VBOX_PCI_COMMAND+1: /* Command register, bits 8-15. */
2136 if (fWritable)
2137 {
2138 /* don't change reserved bits (11-15) */
2139 bVal &= ~UINT8_C(0xf8);
2140 PCIDevSetByte(pPciDev, uAddress, bVal);
2141 fUpdateMappings = true;
2142 }
2143 break;
2144
2145 case VBOX_PCI_STATUS: /* Status register, bits 0-7. */
2146 /* don't change read-only bits => actually all lower bits are read-only */
2147 bVal &= ~UINT8_C(0xff);
2148 /* status register, low part: clear bits by writing a '1' to the corresponding bit */
2149 pPciDev->abConfig[uAddress] &= ~bVal;
2150 break;
2151
2152 case VBOX_PCI_STATUS+1: /* Status register, bits 8-15. */
2153 /* don't change read-only bits */
2154 bVal &= ~UINT8_C(0x06);
2155 /* status register, high part: clear bits by writing a '1' to the corresponding bit */
2156 pPciDev->abConfig[uAddress] &= ~bVal;
2157 break;
2158
2159 case VBOX_PCI_ROM_ADDRESS: case VBOX_PCI_ROM_ADDRESS +1: case VBOX_PCI_ROM_ADDRESS +2: case VBOX_PCI_ROM_ADDRESS +3:
2160 fRom = true;
2161 case VBOX_PCI_BASE_ADDRESS_0: case VBOX_PCI_BASE_ADDRESS_0+1: case VBOX_PCI_BASE_ADDRESS_0+2: case VBOX_PCI_BASE_ADDRESS_0+3:
2162 case VBOX_PCI_BASE_ADDRESS_1: case VBOX_PCI_BASE_ADDRESS_1+1: case VBOX_PCI_BASE_ADDRESS_1+2: case VBOX_PCI_BASE_ADDRESS_1+3:
2163 case VBOX_PCI_BASE_ADDRESS_2: case VBOX_PCI_BASE_ADDRESS_2+1: case VBOX_PCI_BASE_ADDRESS_2+2: case VBOX_PCI_BASE_ADDRESS_2+3:
2164 case VBOX_PCI_BASE_ADDRESS_3: case VBOX_PCI_BASE_ADDRESS_3+1: case VBOX_PCI_BASE_ADDRESS_3+2: case VBOX_PCI_BASE_ADDRESS_3+3:
2165 case VBOX_PCI_BASE_ADDRESS_4: case VBOX_PCI_BASE_ADDRESS_4+1: case VBOX_PCI_BASE_ADDRESS_4+2: case VBOX_PCI_BASE_ADDRESS_4+3:
2166 case VBOX_PCI_BASE_ADDRESS_5: case VBOX_PCI_BASE_ADDRESS_5+1: case VBOX_PCI_BASE_ADDRESS_5+2: case VBOX_PCI_BASE_ADDRESS_5+3:
2167 /* We check that, as same PCI register numbers as BARs may mean different registers for bridges */
2168 if (!fP2PBridge)
2169 {
2170 uint32_t iRegion = fRom ? VBOX_PCI_ROM_SLOT : (uAddress - VBOX_PCI_BASE_ADDRESS_0) >> 2;
2171 devpciR3WriteBarByte(pPciDev, iRegion, uAddress & 0x3, bVal);
2172 fUpdateMappings = true;
2173 break;
2174 }
2175 /* fall thru (bridge) */
2176 default:
2177 if (fWritable)
2178 PCIDevSetByte(pPciDev, uAddress, bVal);
2179 break;
2180 }
2181 uAddress++;
2182 u32Value >>= 8;
2183 }
2184
2185 /*
2186 * Update the region mappings if anything changed related to them (command, BARs, ROM).
2187 */
2188 if (fUpdateMappings)
2189 devpciR3UpdateMappings(pPciDev);
2190 }
2191 }
2192 else if (uAddress + cb <= 4096)
2193 LogRel(("PCI: %8s/%u: Write to extended register %d fallen back to generic code\n",
2194 pPciDev->pszNameR3, pPciDev->Int.s.CTX_SUFF(pDevIns)->iInstance, uAddress));
2195 else
2196 AssertMsgFailed(("Write after end of PCI config space\n"));
2197}
2198
2199
2200/* -=-=-=-=-=- Debug Info Handlers -=-=-=-=-=- */
2201
2202/**
2203 * Indents an info line.
2204 * @param pHlp The info helper.
2205 * @param iIndentLvl The desired indentation level.
2206 */
2207static void devpciR3InfoIndent(PCDBGFINFOHLP pHlp, unsigned iIndentLvl)
2208{
2209 for (unsigned i = 0; i < iIndentLvl; i++)
2210 pHlp->pfnPrintf(pHlp, " ");
2211}
2212
2213
2214/**
2215 * Recursive worker for devpciR3InfoPci.
2216 *
2217 * @param pBus The bus to show info for.
2218 * @param pHlp The info helpers.
2219 * @param iIndentLvl The indentation level.
2220 * @param fRegisters Whether to show device registers or not.
2221 */
2222static void devpciR3InfoPciBus(PDEVPCIBUS pBus, PCDBGFINFOHLP pHlp, unsigned iIndentLvl, bool fRegisters)
2223{
2224/** @todo r=bird: Not sure if we should actually do PCI config space
2225 * callbacks from this code!! */
2226
2227 for (uint32_t iDev = 0; iDev < RT_ELEMENTS(pBus->apDevices); iDev++)
2228 {
2229 PPDMPCIDEV pPciDev = pBus->apDevices[iDev];
2230 if (pPciDev != NULL)
2231 {
2232 devpciR3InfoIndent(pHlp, iIndentLvl);
2233
2234 /*
2235 * For passthrough devices MSI/MSI-X mostly reflects the way interrupts delivered to the guest,
2236 * as host driver handles real devices interrupts.
2237 */
2238 pHlp->pfnPrintf(pHlp, "%02x:%02x:%02x %s%s: %04x-%04x %s%s%s",
2239 pBus->iBus, (iDev >> 3) & 0xff, iDev & 0x7,
2240 pPciDev->pszNameR3,
2241 pciDevIsPassthrough(pPciDev) ? " (PASSTHROUGH)" : "",
2242 ich9pciGetWord(pPciDev, VBOX_PCI_VENDOR_ID), ich9pciGetWord(pPciDev, VBOX_PCI_DEVICE_ID),
2243 pBus->fTypeIch9 ? "ICH9" : pBus->fTypePiix3 ? "PIIX3" : "?type?",
2244 pciDevIsMsiCapable(pPciDev) ? " MSI" : "",
2245 pciDevIsMsixCapable(pPciDev) ? " MSI-X" : ""
2246 );
2247 if (ich9pciGetByte(pPciDev, VBOX_PCI_INTERRUPT_PIN) != 0)
2248 {
2249 pHlp->pfnPrintf(pHlp, " IRQ%d", ich9pciGetByte(pPciDev, VBOX_PCI_INTERRUPT_LINE));
2250 pHlp->pfnPrintf(pHlp, " (INTA#->IRQ%d)", 0x10 + ich9pciSlot2ApicIrq(iDev >> 3, 0));
2251 }
2252 pHlp->pfnPrintf(pHlp, "\n");
2253
2254 if (pciDevIsMsiCapable(pPciDev) || pciDevIsMsixCapable(pPciDev))
2255 {
2256 devpciR3InfoIndent(pHlp, iIndentLvl + 2);
2257
2258 if (pciDevIsMsiCapable(pPciDev))
2259 pHlp->pfnPrintf(pHlp, "MSI:%s ", MsiIsEnabled(pPciDev) ? "on" : "off");
2260
2261 if (pciDevIsMsixCapable(pPciDev))
2262 pHlp->pfnPrintf(pHlp, "MSI-X:%s ", MsixIsEnabled(pPciDev) ? "on" : "off");
2263
2264 pHlp->pfnPrintf(pHlp, "\n");
2265 }
2266
2267 uint16_t iCmd = ich9pciGetWord(pPciDev, VBOX_PCI_COMMAND);
2268 if ((iCmd & (VBOX_PCI_COMMAND_IO | VBOX_PCI_COMMAND_MEMORY)) != 0)
2269 {
2270 for (unsigned iRegion = 0; iRegion < VBOX_PCI_NUM_REGIONS; iRegion++)
2271 {
2272 PCIIORegion const *pRegion = &pPciDev->Int.s.aIORegions[iRegion];
2273 uint64_t const cbRegion = pRegion->size;
2274
2275 if (cbRegion == 0)
2276 continue;
2277
2278 uint32_t uAddr = ich9pciGetDWord(pPciDev, ich9pciGetRegionReg(iRegion));
2279 const char * pszDesc;
2280 char szDescBuf[128];
2281
2282 bool f64Bit = (pRegion->type & ((uint8_t)(PCI_ADDRESS_SPACE_BAR64 | PCI_ADDRESS_SPACE_IO)))
2283 == PCI_ADDRESS_SPACE_BAR64;
2284 if (pRegion->type & PCI_ADDRESS_SPACE_IO)
2285 {
2286 pszDesc = "IO";
2287 uAddr &= ~0x3;
2288 }
2289 else
2290 {
2291 RTStrPrintf(szDescBuf, sizeof(szDescBuf), "MMIO%s%s",
2292 f64Bit ? "64" : "32",
2293 pRegion->type & PCI_ADDRESS_SPACE_MEM_PREFETCH ? " PREFETCH" : "");
2294 pszDesc = szDescBuf;
2295 uAddr &= ~0xf;
2296 }
2297
2298 devpciR3InfoIndent(pHlp, iIndentLvl + 2);
2299 pHlp->pfnPrintf(pHlp, "%s region #%u: ", pszDesc, iRegion);
2300 if (f64Bit)
2301 {
2302 uint32_t u32High = ich9pciGetDWord(pPciDev, ich9pciGetRegionReg(iRegion+1));
2303 uint64_t u64Addr = RT_MAKE_U64(uAddr, u32High);
2304 pHlp->pfnPrintf(pHlp, "%RX64..%RX64\n", u64Addr, u64Addr + cbRegion);
2305 iRegion++;
2306 }
2307 else
2308 pHlp->pfnPrintf(pHlp, "%x..%x\n", uAddr, uAddr + (uint32_t)cbRegion);
2309 }
2310 }
2311
2312 devpciR3InfoIndent(pHlp, iIndentLvl + 2);
2313 uint16_t iStatus = ich9pciGetWord(pPciDev, VBOX_PCI_STATUS);
2314 pHlp->pfnPrintf(pHlp, "Command: %04X, Status: %04x\n", iCmd, iStatus);
2315 devpciR3InfoIndent(pHlp, iIndentLvl + 2);
2316 pHlp->pfnPrintf(pHlp, "Bus master: %s\n", iCmd & VBOX_PCI_COMMAND_MASTER ? "Yes" : "No");
2317
2318 if (fRegisters)
2319 {
2320 devpciR3InfoIndent(pHlp, iIndentLvl + 2);
2321 pHlp->pfnPrintf(pHlp, "PCI registers:\n");
2322 for (unsigned iReg = 0; iReg < 0x100; )
2323 {
2324 unsigned iPerLine = 0x10;
2325 Assert(0x100 % iPerLine == 0);
2326 devpciR3InfoIndent(pHlp, iIndentLvl + 3);
2327
2328 while (iPerLine-- > 0)
2329 pHlp->pfnPrintf(pHlp, "%02x ", ich9pciGetByte(pPciDev, iReg++));
2330 pHlp->pfnPrintf(pHlp, "\n");
2331 }
2332 }
2333 }
2334 }
2335
2336 if (pBus->cBridges > 0)
2337 {
2338 devpciR3InfoIndent(pHlp, iIndentLvl);
2339 pHlp->pfnPrintf(pHlp, "Registered %d bridges, subordinate buses info follows\n", pBus->cBridges);
2340 for (uint32_t iBridge = 0; iBridge < pBus->cBridges; iBridge++)
2341 {
2342 PDEVPCIBUS pBusSub = PDMINS_2_DATA(pBus->papBridgesR3[iBridge]->Int.s.CTX_SUFF(pDevIns), PDEVPCIBUS);
2343 devpciR3InfoPciBus(pBusSub, pHlp, iIndentLvl + 1, fRegisters);
2344 }
2345 }
2346}
2347
2348
2349/**
2350 * @callback_method_impl{FNDBGFHANDLERDEV, 'pci'}
2351 */
2352DECLCALLBACK(void) devpciR3InfoPci(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
2353{
2354 PDEVPCIBUS pBus = DEVINS_2_DEVPCIBUS(pDevIns);
2355
2356 if (pszArgs == NULL || !*pszArgs || !strcmp(pszArgs, "basic"))
2357 devpciR3InfoPciBus(pBus, pHlp, 0 /*iIndentLvl*/, false /*fRegisters*/);
2358 else if (!strcmp(pszArgs, "verbose"))
2359 devpciR3InfoPciBus(pBus, pHlp, 0 /*iIndentLvl*/, true /*fRegisters*/);
2360 else
2361 pHlp->pfnPrintf(pHlp, "Invalid argument. Recognized arguments are 'basic', 'verbose'.\n");
2362}
2363
2364
2365/**
2366 * @callback_method_impl{FNDBGFHANDLERDEV, 'pciirq'}
2367 */
2368DECLCALLBACK(void) devpciR3InfoPciIrq(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
2369{
2370 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
2371 NOREF(pszArgs);
2372
2373 pHlp->pfnPrintf(pHlp, "PCI I/O APIC IRQ levels:\n");
2374 for (int i = 0; i < DEVPCI_APIC_IRQ_PINS; ++i)
2375 pHlp->pfnPrintf(pHlp, " IRQ%02d: %u\n", 0x10 + i, pPciRoot->auPciApicIrqLevels[i]);
2376}
2377
2378
2379
2380static DECLCALLBACK(int) ich9pciConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
2381{
2382 RT_NOREF1(iInstance);
2383 Assert(iInstance == 0);
2384 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
2385
2386 /*
2387 * Validate and read configuration.
2388 */
2389 if (!CFGMR3AreValuesValid(pCfg,
2390 "IOAPIC\0"
2391 "GCEnabled\0"
2392 "R0Enabled\0"
2393 "McfgBase\0"
2394 "McfgLength\0"
2395 ))
2396 return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
2397
2398 /* query whether we got an IOAPIC */
2399 bool fUseIoApic;
2400 int rc = CFGMR3QueryBoolDef(pCfg, "IOAPIC", &fUseIoApic, false);
2401 if (RT_FAILURE(rc))
2402 return PDMDEV_SET_ERROR(pDevIns, rc,
2403 N_("Configuration error: Failed to query boolean value \"IOAPIC\""));
2404
2405 /* check if RC code is enabled. */
2406 bool fGCEnabled;
2407 rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fGCEnabled, true);
2408 if (RT_FAILURE(rc))
2409 return PDMDEV_SET_ERROR(pDevIns, rc,
2410 N_("Configuration error: Failed to query boolean value \"GCEnabled\""));
2411 /* check if R0 code is enabled. */
2412 bool fR0Enabled;
2413 rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true);
2414 if (RT_FAILURE(rc))
2415 return PDMDEV_SET_ERROR(pDevIns, rc,
2416 N_("Configuration error: Failed to query boolean value \"R0Enabled\""));
2417
2418 Log(("PCI: fUseIoApic=%RTbool fGCEnabled=%RTbool fR0Enabled=%RTbool\n", fUseIoApic, fGCEnabled, fR0Enabled));
2419
2420 /*
2421 * Init data.
2422 */
2423 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
2424 PDEVPCIBUS pBus = &pPciRoot->PciBus;
2425 /* Zero out everything */
2426 memset(pPciRoot, 0, sizeof(*pPciRoot));
2427 /* And fill values */
2428 if (!fUseIoApic)
2429 return PDMDEV_SET_ERROR(pDevIns, rc,
2430 N_("Must use IO-APIC with ICH9 chipset"));
2431 rc = CFGMR3QueryU64Def(pCfg, "McfgBase", &pPciRoot->u64PciConfigMMioAddress, 0);
2432 if (RT_FAILURE(rc))
2433 return PDMDEV_SET_ERROR(pDevIns, rc,
2434 N_("Configuration error: Failed to read \"McfgBase\""));
2435 rc = CFGMR3QueryU64Def(pCfg, "McfgLength", &pPciRoot->u64PciConfigMMioLength, 0);
2436 if (RT_FAILURE(rc))
2437 return PDMDEV_SET_ERROR(pDevIns, rc,
2438 N_("Configuration error: Failed to read \"McfgLength\""));
2439
2440 pPciRoot->fUseIoApic = fUseIoApic;
2441 pPciRoot->pDevInsR3 = pDevIns;
2442 pPciRoot->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2443 pPciRoot->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2444
2445 pPciRoot->PciBus.fTypePiix3 = false;
2446 pPciRoot->PciBus.fTypeIch9 = true;
2447 pPciRoot->PciBus.fPureBridge = false;
2448 pPciRoot->PciBus.pDevInsR3 = pDevIns;
2449 pPciRoot->PciBus.pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2450 pPciRoot->PciBus.pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2451 pPciRoot->PciBus.papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV) * RT_ELEMENTS(pPciRoot->PciBus.apDevices));
2452 AssertLogRelReturn(pPciRoot->PciBus.papBridgesR3, VERR_NO_MEMORY);
2453
2454 /*
2455 * Register bus
2456 */
2457 PDMPCIBUSREG PciBusReg;
2458 PciBusReg.u32Version = PDM_PCIBUSREG_VERSION;
2459 PciBusReg.pfnRegisterR3 = pciR3MergedRegister;
2460 PciBusReg.pfnRegisterMsiR3 = ich9pciRegisterMsi;
2461 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister;
2462 PciBusReg.pfnSetConfigCallbacksR3 = devpciR3CommonSetConfigCallbacks;
2463 PciBusReg.pfnSetIrqR3 = ich9pciSetIrq;
2464 PciBusReg.pfnFakePCIBIOSR3 = ich9pciFakePCIBIOS;
2465 PciBusReg.pszSetIrqRC = fGCEnabled ? "ich9pciSetIrq" : NULL;
2466 PciBusReg.pszSetIrqR0 = fR0Enabled ? "ich9pciSetIrq" : NULL;
2467#if PDM_DEVHLPR3_VERSION >= PDM_VERSION_MAKE_PP(0xffe7, 20, 0)
2468 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBus->pPciHlpR3, &pBus->iBus);
2469#else
2470 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBus->pPciHlpR3);
2471 pBus->iBus = rc;
2472#endif
2473 if (RT_FAILURE(rc))
2474 return PDMDEV_SET_ERROR(pDevIns, rc,
2475 N_("Failed to register ourselves as a PCI Bus"));
2476 Assert(pBus->iBus == 0);
2477 if (pBus->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION)
2478 return PDMDevHlpVMSetError(pDevIns, VERR_VERSION_MISMATCH, RT_SRC_POS,
2479 N_("PCI helper version mismatch; got %#x expected %#x"),
2480 pBus->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION);
2481
2482 pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns);
2483 pBus->pPciHlpR0 = pBus->pPciHlpR3->pfnGetR0Helpers(pDevIns);
2484
2485 /*
2486 * Fill in PCI configs and add them to the bus.
2487 */
2488 /** @todo Disabled for now because this causes error messages with Linux guests.
2489 * The guest loads the x38_edac device which tries to map a memory region
2490 * using an address given at place 0x48 - 0x4f in the PCi config space.
2491 * This fails. because we don't register such a region.
2492 */
2493#if 0
2494 /* Host bridge device */
2495 PCIDevSetVendorId( &pBus->PciDev, 0x8086); /* Intel */
2496 PCIDevSetDeviceId( &pBus->PciDev, 0x29e0); /* Desktop */
2497 PCIDevSetRevisionId(&pBus->PciDev, 0x01); /* rev. 01 */
2498 PCIDevSetClassBase( &pBus->PciDev, 0x06); /* bridge */
2499 PCIDevSetClassSub( &pBus->PciDev, 0x00); /* Host/PCI bridge */
2500 PCIDevSetClassProg( &pBus->PciDev, 0x00); /* Host/PCI bridge */
2501 PCIDevSetHeaderType(&pBus->PciDev, 0x00); /* bridge */
2502 PCIDevSetWord(&pBus->PciDev, VBOX_PCI_SEC_STATUS, 0x0280); /* secondary status */
2503
2504 pBus->PciDev.pDevIns = pDevIns;
2505 /* We register Host<->PCI controller on the bus */
2506 ich9pciRegisterInternal(pBus, 0, &pBus->PciDev, "dram");
2507#endif
2508
2509 /*
2510 * Register I/O ports and save state.
2511 */
2512 rc = PDMDevHlpIOPortRegister(pDevIns, 0x0cf8, 1, NULL, ich9pciIOPortAddressWrite, ich9pciIOPortAddressRead, NULL, NULL, "ICH9 (PCI)");
2513 if (RT_FAILURE(rc))
2514 return rc;
2515 rc = PDMDevHlpIOPortRegister(pDevIns, 0x0cfc, 4, NULL, ich9pciIOPortDataWrite, ich9pciIOPortDataRead, NULL, NULL, "ICH9 (PCI)");
2516 if (RT_FAILURE(rc))
2517 return rc;
2518 if (fGCEnabled)
2519 {
2520 rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x0cf8, 1, NIL_RTGCPTR, "ich9pciIOPortAddressWrite", "ich9pciIOPortAddressRead", NULL, NULL, "ICH9 (PCI)");
2521 if (RT_FAILURE(rc))
2522 return rc;
2523 rc = PDMDevHlpIOPortRegisterRC(pDevIns, 0x0cfc, 4, NIL_RTGCPTR, "ich9pciIOPortDataWrite", "ich9pciIOPortDataRead", NULL, NULL, "ICH9 (PCI)");
2524 if (RT_FAILURE(rc))
2525 return rc;
2526 }
2527 if (fR0Enabled)
2528 {
2529 rc = PDMDevHlpIOPortRegisterR0(pDevIns, 0x0cf8, 1, NIL_RTR0PTR, "ich9pciIOPortAddressWrite", "ich9pciIOPortAddressRead", NULL, NULL, "ICH9 (PCI)");
2530 if (RT_FAILURE(rc))
2531 return rc;
2532 rc = PDMDevHlpIOPortRegisterR0(pDevIns, 0x0cfc, 4, NIL_RTR0PTR, "ich9pciIOPortDataWrite", "ich9pciIOPortDataRead", NULL, NULL, "ICH9 (PCI)");
2533 if (RT_FAILURE(rc))
2534 return rc;
2535 }
2536
2537 if (pPciRoot->u64PciConfigMMioAddress != 0)
2538 {
2539 rc = PDMDevHlpMMIORegister(pDevIns, pPciRoot->u64PciConfigMMioAddress, pPciRoot->u64PciConfigMMioLength, NULL /*pvUser*/,
2540 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
2541 ich9pciMcfgMMIOWrite, ich9pciMcfgMMIORead, "MCFG ranges");
2542 AssertMsgRCReturn(rc, ("rc=%Rrc %#llx/%#llx\n", rc, pPciRoot->u64PciConfigMMioAddress, pPciRoot->u64PciConfigMMioLength), rc);
2543
2544 if (fGCEnabled)
2545 {
2546 rc = PDMDevHlpMMIORegisterRC(pDevIns, pPciRoot->u64PciConfigMMioAddress, pPciRoot->u64PciConfigMMioLength,
2547 NIL_RTRCPTR /*pvUser*/, "ich9pciMcfgMMIOWrite", "ich9pciMcfgMMIORead");
2548 AssertRCReturn(rc, rc);
2549 }
2550
2551
2552 if (fR0Enabled)
2553 {
2554 rc = PDMDevHlpMMIORegisterR0(pDevIns, pPciRoot->u64PciConfigMMioAddress, pPciRoot->u64PciConfigMMioLength,
2555 NIL_RTR0PTR /*pvUser*/, "ich9pciMcfgMMIOWrite", "ich9pciMcfgMMIORead");
2556 AssertRCReturn(rc, rc);
2557 }
2558 }
2559
2560 rc = PDMDevHlpSSMRegisterEx(pDevIns, VBOX_ICH9PCI_SAVED_STATE_VERSION_CURRENT,
2561 sizeof(*pBus) + 16*128, "pgm",
2562 NULL, NULL, NULL,
2563 NULL, ich9pciR3SaveExec, NULL,
2564 NULL, ich9pciR3LoadExec, NULL);
2565 if (RT_FAILURE(rc))
2566 return rc;
2567
2568
2569 /** @todo other chipset devices shall be registered too */
2570
2571 PDMDevHlpDBGFInfoRegister(pDevIns, "pci",
2572 "Display PCI bus status. Recognizes 'basic' or 'verbose' as arguments, defaults to 'basic'.",
2573 devpciR3InfoPci);
2574 PDMDevHlpDBGFInfoRegister(pDevIns, "pciirq", "Display PCI IRQ state. (no arguments)", devpciR3InfoPciIrq);
2575
2576 return VINF_SUCCESS;
2577}
2578
2579static void ich9pciResetDevice(PPDMPCIDEV pDev)
2580{
2581 /* Clear regions */
2582 for (int iRegion = 0; iRegion < VBOX_PCI_NUM_REGIONS; iRegion++)
2583 {
2584 PCIIORegion* pRegion = &pDev->Int.s.aIORegions[iRegion];
2585 if (pRegion->size == 0)
2586 continue;
2587
2588 ich9pciUnmapRegion(pDev, iRegion);
2589 }
2590
2591 if (pciDevIsPassthrough(pDev))
2592 {
2593 // no reset handler - we can do what we need in PDM reset handler
2594 /// @todo is it correct?
2595 }
2596 else
2597 {
2598 PCIDevSetCommand(pDev,
2599 PCIDevGetCommand(pDev)
2600 &
2601 ~(VBOX_PCI_COMMAND_IO | VBOX_PCI_COMMAND_MEMORY |
2602 VBOX_PCI_COMMAND_MASTER | VBOX_PCI_COMMAND_SPECIAL |
2603 VBOX_PCI_COMMAND_PARITY | VBOX_PCI_COMMAND_SERR |
2604 VBOX_PCI_COMMAND_FAST_BACK | VBOX_PCI_COMMAND_INTX_DISABLE));
2605
2606 /* Bridge device reset handlers processed later */
2607 if (!pciDevIsPci2PciBridge(pDev))
2608 {
2609 PCIDevSetByte(pDev, VBOX_PCI_CACHE_LINE_SIZE, 0x0);
2610 PCIDevSetInterruptLine(pDev, 0x0);
2611 }
2612
2613 /* Reset MSI message control. */
2614 if (pciDevIsMsiCapable(pDev))
2615 {
2616 /* Extracted from MsiPciConfigWrite(). */
2617 pDev->abConfig[pDev->Int.s.u8MsiCapOffset + VBOX_MSI_CAP_MESSAGE_CONTROL] &= 0x8e;
2618 }
2619
2620 /* Reset MSI-X message control. */
2621 if (pciDevIsMsixCapable(pDev))
2622 {
2623 /* Extracted from MsixPciConfigWrite(); no side effects. */
2624 pDev->abConfig[pDev->Int.s.u8MsixCapOffset + VBOX_MSIX_CAP_MESSAGE_CONTROL + 1] &= 0x3f;
2625 }
2626 }
2627}
2628
2629
2630/**
2631 * @copydoc FNPDMDEVRESET
2632 */
2633static DECLCALLBACK(void) ich9pciReset(PPDMDEVINS pDevIns)
2634{
2635 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
2636 PDEVPCIBUS pBus = &pPciRoot->PciBus;
2637
2638 /* PCI-specific reset for each device. */
2639 for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
2640 {
2641 if (pBus->apDevices[i])
2642 ich9pciResetDevice(pBus->apDevices[i]);
2643 }
2644
2645 for (uint32_t iBridge = 0; iBridge < pBus->cBridges; iBridge++)
2646 {
2647 if (pBus->papBridgesR3[iBridge])
2648 ich9pcibridgeReset(pBus->papBridgesR3[iBridge]->Int.s.CTX_SUFF(pDevIns));
2649 }
2650
2651 ich9pciFakePCIBIOS(pDevIns);
2652}
2653
2654
2655/**
2656 * @interface_method_impl{PDMDEVREG,pfnRelocate}
2657 */
2658DECLCALLBACK(void) devpciR3BusRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
2659{
2660 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
2661
2662 pBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2663 pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns);
2664
2665 /* Relocate RC pointers for the attached pci devices. */
2666 for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
2667 {
2668 PPDMPCIDEV pDev = pBus->apDevices[i];
2669 if (pDev)
2670 {
2671 pDev->Int.s.pBusRC += offDelta;
2672 if (pDev->Int.s.pMsixPageRC)
2673 pDev->Int.s.pMsixPageRC += offDelta;
2674 }
2675 }
2676}
2677
2678
2679/**
2680 * @interface_method_impl{PDMDEVREG,pfnRelocate}
2681 */
2682DECLCALLBACK(void) devpciR3RootRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
2683{
2684 PDEVPCIROOT pPciRoot = PDMINS_2_DATA(pDevIns, PDEVPCIROOT);
2685 pPciRoot->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2686
2687 AssertCompileMemberOffset(DEVPCIROOT, PciBus, 0);
2688 devpciR3BusRelocate(pDevIns, offDelta);
2689}
2690
2691
2692/**
2693 * @interface_method_impl{PDMDEVREG,pfnConstruct}
2694 */
2695static DECLCALLBACK(int) ich9pcibridgeConstruct(PPDMDEVINS pDevIns,
2696 int iInstance,
2697 PCFGMNODE pCfg)
2698{
2699 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
2700
2701 /*
2702 * Validate and read configuration.
2703 */
2704 if (!CFGMR3AreValuesValid(pCfg, "GCEnabled\0" "R0Enabled\0"))
2705 return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
2706
2707 /* check if RC code is enabled. */
2708 bool fGCEnabled;
2709 int rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fGCEnabled, true);
2710 if (RT_FAILURE(rc))
2711 return PDMDEV_SET_ERROR(pDevIns, rc,
2712 N_("Configuration error: Failed to query boolean value \"GCEnabled\""));
2713
2714 /* check if R0 code is enabled. */
2715 bool fR0Enabled;
2716 rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true);
2717 if (RT_FAILURE(rc))
2718 return PDMDEV_SET_ERROR(pDevIns, rc,
2719 N_("Configuration error: Failed to query boolean value \"R0Enabled\""));
2720 Log(("PCI: fGCEnabled=%RTbool fR0Enabled=%RTbool\n", fGCEnabled, fR0Enabled));
2721
2722 /*
2723 * Init data and register the PCI bus.
2724 */
2725 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
2726 pBus->fTypePiix3 = false;
2727 pBus->fTypeIch9 = true;
2728 pBus->fPureBridge = true;
2729 pBus->pDevInsR3 = pDevIns;
2730 pBus->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
2731 pBus->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
2732 pBus->papBridgesR3 = (PPDMPCIDEV *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPDMPCIDEV) * RT_ELEMENTS(pBus->apDevices));
2733 AssertLogRelReturn(pBus->papBridgesR3, VERR_NO_MEMORY);
2734
2735 PDMPCIBUSREG PciBusReg;
2736 PciBusReg.u32Version = PDM_PCIBUSREG_VERSION;
2737 PciBusReg.pfnRegisterR3 = pcibridgeR3MergedRegisterDevice;
2738 PciBusReg.pfnRegisterMsiR3 = ich9pciRegisterMsi;
2739 PciBusReg.pfnIORegionRegisterR3 = devpciR3CommonIORegionRegister;
2740 PciBusReg.pfnSetConfigCallbacksR3 = devpciR3CommonSetConfigCallbacks;
2741 PciBusReg.pfnSetIrqR3 = ich9pcibridgeSetIrq;
2742 PciBusReg.pfnFakePCIBIOSR3 = NULL; /* Only needed for the first bus. */
2743 PciBusReg.pszSetIrqRC = fGCEnabled ? "ich9pcibridgeSetIrq" : NULL;
2744 PciBusReg.pszSetIrqR0 = fR0Enabled ? "ich9pcibridgeSetIrq" : NULL;
2745#if PDM_DEVHLPR3_VERSION >= PDM_VERSION_MAKE_PP(0xffe7, 20, 0)
2746 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBus->pPciHlpR3, &pBus->iBus);
2747#else
2748 rc = PDMDevHlpPCIBusRegister(pDevIns, &PciBusReg, &pBus->pPciHlpR3);
2749 pBus->iBus = rc;
2750#endif
2751 if (RT_FAILURE(rc))
2752 return PDMDEV_SET_ERROR(pDevIns, rc,
2753 N_("Failed to register ourselves as a PCI Bus"));
2754 Assert(pBus->iBus == (uint32_t)iInstance + 1); /* Can be removed when adding support for multiple bridge implementations. */
2755 if (pBus->pPciHlpR3->u32Version != PDM_PCIHLPR3_VERSION)
2756 return PDMDevHlpVMSetError(pDevIns, VERR_VERSION_MISMATCH, RT_SRC_POS,
2757 N_("PCI helper version mismatch; got %#x expected %#x"),
2758 pBus->pPciHlpR3->u32Version, PDM_PCIHLPR3_VERSION);
2759
2760 pBus->pPciHlpRC = pBus->pPciHlpR3->pfnGetRCHelpers(pDevIns);
2761 pBus->pPciHlpR0 = pBus->pPciHlpR3->pfnGetR0Helpers(pDevIns);
2762
2763
2764 /* Disable default device locking. */
2765 rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
2766 AssertRCReturn(rc, rc);
2767
2768 /*
2769 * Fill in PCI configs and add them to the bus.
2770 */
2771 PCIDevSetVendorId( &pBus->PciDev, 0x8086); /* Intel */
2772 PCIDevSetDeviceId( &pBus->PciDev, 0x2448); /* 82801 Mobile PCI bridge. */
2773 PCIDevSetRevisionId(&pBus->PciDev, 0xf2);
2774 PCIDevSetClassSub( &pBus->PciDev, 0x04); /* pci2pci */
2775 PCIDevSetClassBase( &pBus->PciDev, 0x06); /* PCI_bridge */
2776 PCIDevSetClassProg( &pBus->PciDev, 0x01); /* Supports subtractive decoding. */
2777 PCIDevSetHeaderType(&pBus->PciDev, 0x01); /* Single function device which adheres to the PCI-to-PCI bridge spec. */
2778 PCIDevSetCommand( &pBus->PciDev, 0x00);
2779 PCIDevSetStatus( &pBus->PciDev, 0x20); /* 66MHz Capable. */
2780 PCIDevSetInterruptLine(&pBus->PciDev, 0x00); /* This device does not assert interrupts. */
2781
2782 /*
2783 * This device does not generate interrupts. Interrupt delivery from
2784 * devices attached to the bus is unaffected.
2785 */
2786 PCIDevSetInterruptPin (&pBus->PciDev, 0x00);
2787
2788 /*
2789 * Register this PCI bridge. The called function will take care on which bus we will get registered.
2790 */
2791 rc = PDMDevHlpPCIRegisterEx(pDevIns, &pBus->PciDev, PDMPCIDEVREG_CFG_PRIMARY, PDMPCIDEVREG_F_PCI_BRIDGE,
2792 PDMPCIDEVREG_DEV_NO_FIRST_UNUSED, PDMPCIDEVREG_FUN_NO_FIRST_UNUSED, "ich9pcibridge");
2793 if (RT_FAILURE(rc))
2794 return rc;
2795 pBus->PciDev.Int.s.pfnBridgeConfigRead = ich9pcibridgeConfigRead;
2796 pBus->PciDev.Int.s.pfnBridgeConfigWrite = ich9pcibridgeConfigWrite;
2797
2798 /*
2799 * Register SSM handlers. We use the same saved state version as for the host bridge
2800 * to make changes easier.
2801 */
2802 rc = PDMDevHlpSSMRegisterEx(pDevIns, VBOX_ICH9PCI_SAVED_STATE_VERSION_CURRENT,
2803 sizeof(*pBus) + 16*128,
2804 "pgm" /* before */,
2805 NULL, NULL, NULL,
2806 NULL, ich9pcibridgeR3SaveExec, NULL,
2807 NULL, ich9pcibridgeR3LoadExec, NULL);
2808 if (RT_FAILURE(rc))
2809 return rc;
2810
2811
2812 return VINF_SUCCESS;
2813}
2814
2815/**
2816 * @copydoc FNPDMDEVRESET
2817 */
2818static void ich9pcibridgeReset(PPDMDEVINS pDevIns)
2819{
2820 PDEVPCIBUS pBus = PDMINS_2_DATA(pDevIns, PDEVPCIBUS);
2821
2822 /* Reset config space to default values. */
2823 PCIDevSetByte(&pBus->PciDev, VBOX_PCI_PRIMARY_BUS, 0);
2824 PCIDevSetByte(&pBus->PciDev, VBOX_PCI_SECONDARY_BUS, 0);
2825 PCIDevSetByte(&pBus->PciDev, VBOX_PCI_SUBORDINATE_BUS, 0);
2826
2827 /* PCI-specific reset for each device. */
2828 for (uint32_t i = 0; i < RT_ELEMENTS(pBus->apDevices); i++)
2829 {
2830 if (pBus->apDevices[i])
2831 ich9pciResetDevice(pBus->apDevices[i]);
2832 }
2833}
2834
2835
2836
2837/**
2838 * The PCI bus device registration structure.
2839 */
2840const PDMDEVREG g_DevicePciIch9 =
2841{
2842 /* u32Version */
2843 PDM_DEVREG_VERSION,
2844 /* szName */
2845 "ich9pci",
2846 /* szRCMod */
2847 "VBoxDDRC.rc",
2848 /* szR0Mod */
2849 "VBoxDDR0.r0",
2850 /* pszDescription */
2851 "ICH9 PCI bridge",
2852 /* fFlags */
2853 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
2854 /* fClass */
2855 PDM_DEVREG_CLASS_BUS_PCI | PDM_DEVREG_CLASS_BUS_ISA,
2856 /* cMaxInstances */
2857 1,
2858 /* cbInstance */
2859 sizeof(DEVPCIROOT),
2860 /* pfnConstruct */
2861 ich9pciConstruct,
2862 /* pfnDestruct */
2863 NULL,
2864 /* pfnRelocate */
2865 devpciR3RootRelocate,
2866 /* pfnMemSetup */
2867 NULL,
2868 /* pfnPowerOn */
2869 NULL,
2870 /* pfnReset */
2871 ich9pciReset,
2872 /* pfnSuspend */
2873 NULL,
2874 /* pfnResume */
2875 NULL,
2876 /* pfnAttach */
2877 NULL,
2878 /* pfnDetach */
2879 NULL,
2880 /* pfnQueryInterface */
2881 NULL,
2882 /* pfnInitComplete */
2883 NULL,
2884 /* pfnPowerOff */
2885 NULL,
2886 /* pfnSoftReset */
2887 NULL,
2888 /* u32VersionEnd */
2889 PDM_DEVREG_VERSION
2890};
2891
2892/**
2893 * The device registration structure
2894 * for the PCI-to-PCI bridge.
2895 */
2896const PDMDEVREG g_DevicePciIch9Bridge =
2897{
2898 /* u32Version */
2899 PDM_DEVREG_VERSION,
2900 /* szName */
2901 "ich9pcibridge",
2902 /* szRCMod */
2903 "VBoxDDRC.rc",
2904 /* szR0Mod */
2905 "VBoxDDR0.r0",
2906 /* pszDescription */
2907 "ICH9 PCI to PCI bridge",
2908 /* fFlags */
2909 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
2910 /* fClass */
2911 PDM_DEVREG_CLASS_BUS_PCI,
2912 /* cMaxInstances */
2913 ~0U,
2914 /* cbInstance */
2915 sizeof(DEVPCIBUS),
2916 /* pfnConstruct */
2917 ich9pcibridgeConstruct,
2918 /* pfnDestruct */
2919 NULL,
2920 /* pfnRelocate */
2921 devpciR3BusRelocate,
2922 /* pfnMemSetup */
2923 NULL,
2924 /* pfnPowerOn */
2925 NULL,
2926 /* pfnReset */
2927 NULL, /* Must be NULL, to make sure only bus driver handles reset */
2928 /* pfnSuspend */
2929 NULL,
2930 /* pfnResume */
2931 NULL,
2932 /* pfnAttach */
2933 NULL,
2934 /* pfnDetach */
2935 NULL,
2936 /* pfnQueryInterface */
2937 NULL,
2938 /* pfnInitComplete */
2939 NULL,
2940 /* pfnPowerOff */
2941 NULL,
2942 /* pfnSoftReset */
2943 NULL,
2944 /* u32VersionEnd */
2945 PDM_DEVREG_VERSION
2946};
2947
2948#endif /* IN_RING3 */
2949
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette