VirtualBox

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

Last change on this file since 51476 was 51377, checked in by vboxsync, 11 years ago

ICH9: A bit of logging to track MSI delivery.

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

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