VirtualBox

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

Last change on this file since 44000 was 43441, checked in by vboxsync, 12 years ago

ICH9: Fix PCI bridge initialization

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

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