VirtualBox

source: vbox/trunk/src/VBox/Devices/Bus/DevPciInternal.h@ 76681

Last change on this file since 76681 was 76565, checked in by vboxsync, 6 years ago

Devices: Use VBOX_INCLUDED_SRC_ as header guard prefix with scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
Line 
1/* $Id: DevPciInternal.h 76565 2019-01-01 04:23:20Z vboxsync $ */
2/** @file
3 * DevPCI - Common Internal Header.
4 */
5
6/*
7 * Copyright (C) 2010-2019 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#ifndef VBOX_INCLUDED_SRC_Bus_DevPciInternal_h
19#define VBOX_INCLUDED_SRC_Bus_DevPciInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#ifndef PDMPCIDEV_INCLUDE_PRIVATE
25# define PDMPCIDEV_INCLUDE_PRIVATE /* Hack to get pdmpcidevint.h included at the right point. */
26#endif
27#include <VBox/vmm/pdmdev.h>
28
29
30/**
31 * PCI bus instance (common to both).
32 */
33typedef struct DEVPCIBUS
34{
35 /** Bus number. */
36 uint32_t iBus;
37 /** Number of bridges attached to the bus. */
38 uint32_t cBridges;
39 /** Start device number - always zero (only for DevPCI source compat). */
40 uint32_t iDevSearch;
41 /** Set if PIIX3 type. */
42 uint32_t fTypePiix3 : 1;
43 /** Set if ICH9 type. */
44 uint32_t fTypeIch9: 1;
45 /** Set if this is a pure bridge, i.e. not part of DEVPCIGLOBALS struct. */
46 uint32_t fPureBridge : 1;
47 /** Reserved for future config flags. */
48 uint32_t uReservedConfigFlags : 29;
49
50 /** R3 pointer to the device instance. */
51 PPDMDEVINSR3 pDevInsR3;
52 /** Pointer to the PCI R3 helpers. */
53 PCPDMPCIHLPR3 pPciHlpR3;
54
55 /** R0 pointer to the device instance. */
56 PPDMDEVINSR0 pDevInsR0;
57 /** Pointer to the PCI R0 helpers. */
58 PCPDMPCIHLPR0 pPciHlpR0;
59
60 /** RC pointer to the device instance. */
61 PPDMDEVINSRC pDevInsRC;
62 /** Pointer to the PCI RC helpers. */
63 PCPDMPCIHLPRC pPciHlpRC;
64
65 /** Array of bridges attached to the bus. */
66 R3PTRTYPE(PPDMPCIDEV *) papBridgesR3;
67#if HC_ARCH_BITS == 32
68 uint32_t au32Alignment1[5]; /**< Cache line align apDevices. */
69#endif
70 /** Array of PCI devices. We assume 32 slots, each with 8 functions. */
71 R3PTRTYPE(PPDMPCIDEV) apDevices[256];
72
73 /** The PCI device for the PCI bridge. */
74 PDMPCIDEV PciDev;
75} DEVPCIBUS;
76/** Pointer to a PCI bus instance. */
77typedef DEVPCIBUS *PDEVPCIBUS;
78
79
80/** @def DEVPCI_APIC_IRQ_PINS
81 * Number of pins for interrupts if the APIC is used.
82 */
83#define DEVPCI_APIC_IRQ_PINS 8
84/** @def DEVPCI_LEGACY_IRQ_PINS
85 * Number of pins for interrupts (PIRQ#0...PIRQ#3).
86 * @remarks Labling this "legacy" might be a bit off...
87 */
88#define DEVPCI_LEGACY_IRQ_PINS 4
89
90/**
91 * PIIX3 ISA bridge state.
92 */
93typedef struct PIIX3ISABRIDGE
94{
95 /** The PCI device of the bridge. */
96 PDMPCIDEV dev;
97} PIIX3ISABRIDGE;
98
99
100/**
101 * PCI Globals - This is the host-to-pci bridge and the root bus.
102 *
103 * @note Only used by the root bus, not the bridges.
104 */
105typedef struct DEVPCIROOT
106{
107 /** PCI bus which is attached to the host-to-PCI bridge.
108 * @note This must come first so we can share more code with the bridges! */
109 DEVPCIBUS PciBus;
110
111 /** R3 pointer to the device instance. */
112 PPDMDEVINSR3 pDevInsR3;
113 /** R0 pointer to the device instance. */
114 PPDMDEVINSR0 pDevInsR0;
115 /** RC pointer to the device instance. */
116 PPDMDEVINSRC pDevInsRC;
117
118 /** I/O APIC usage flag (always true of ICH9, see constructor). */
119 bool fUseIoApic;
120 /** Reserved for future config flags. */
121 bool afFutureFlags[3];
122 /** Physical address of PCI config space MMIO region. */
123 uint64_t u64PciConfigMMioAddress;
124 /** Length of PCI config space MMIO region. */
125 uint64_t u64PciConfigMMioLength;
126
127 /** I/O APIC irq levels */
128 volatile uint32_t auPciApicIrqLevels[DEVPCI_APIC_IRQ_PINS];
129 /** Value latched in Configuration Address Port (0CF8h) */
130 uint32_t uConfigReg;
131 /** Alignment padding. */
132 uint32_t u32Alignment1;
133 /** Members only used by the PIIX3 code variant. */
134 struct
135 {
136 /** ACPI IRQ level */
137 uint32_t iAcpiIrqLevel;
138 /** ACPI PIC IRQ */
139 int32_t iAcpiIrq;
140 /** Irq levels for the four PCI Irqs.
141 * These count how many devices asserted the IRQ line. If greater 0 an IRQ
142 * is sent to the guest. If it drops to 0 the IRQ is deasserted.
143 * @remarks Labling this "legacy" might be a bit off...
144 */
145 volatile uint32_t auPciLegacyIrqLevels[DEVPCI_LEGACY_IRQ_PINS];
146 /** ISA bridge state. */
147 PIIX3ISABRIDGE PIIX3State;
148 } Piix3;
149
150#if 1 /* Will be moved into the BIOS "soon". */
151 /** Current bus number - obsolete (still used by DevPCI, but merge will fix that). */
152 uint8_t uPciBiosBus;
153 uint8_t abAlignment2[7];
154 /** The next I/O port address which the PCI BIOS will use. */
155 uint32_t uPciBiosIo;
156 /** The next MMIO address which the PCI BIOS will use. */
157 uint32_t uPciBiosMmio;
158 /** The next 64-bit MMIO address which the PCI BIOS will use. */
159 uint64_t uPciBiosMmio64;
160#endif
161
162} DEVPCIROOT;
163/** Pointer to PCI device globals. */
164typedef DEVPCIROOT *PDEVPCIROOT;
165
166
167/** Converts a PCI bus device instance pointer to a DEVPCIBUS pointer. */
168#define DEVINS_2_DEVPCIBUS(pDevIns) (&PDMINS_2_DATA(pDevIns, PDEVPCIROOT)->PciBus)
169/** Converts a pointer to a PCI bus instance to a DEVPCIROOT pointer. */
170#define DEVPCIBUS_2_DEVPCIROOT(pPciBus) RT_FROM_MEMBER(pPciBus, DEVPCIROOT, PciBus)
171
172/** @def PCI_LOCK
173 * Acquires the PDM lock. This is a NOP if locking is disabled. */
174/** @def PCI_UNLOCK
175 * Releases the PDM lock. This is a NOP if locking is disabled. */
176#define PCI_LOCK(pDevIns, rc) \
177 do { \
178 int rc2 = DEVINS_2_DEVPCIBUS(pDevIns)->CTX_SUFF(pPciHlp)->pfnLock((pDevIns), rc); \
179 if (rc2 != VINF_SUCCESS) \
180 return rc2; \
181 } while (0)
182#define PCI_UNLOCK(pDevIns) \
183 DEVINS_2_DEVPCIBUS(pDevIns)->CTX_SUFF(pPciHlp)->pfnUnlock(pDevIns)
184
185
186#ifdef IN_RING3
187
188DECLCALLBACK(void) devpciR3RootRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
189DECLCALLBACK(void) devpciR3BusRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
190DECLCALLBACK(void) devpciR3InfoPci(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs);
191DECLCALLBACK(void) devpciR3InfoPciIrq(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs);
192DECLCALLBACK(int) devpciR3CommonIORegionRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iRegion, RTGCPHYS cbRegion,
193 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback);
194DECLCALLBACK(void) devpciR3CommonSetConfigCallbacks(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
195 PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
196 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld);
197DECLCALLBACK(uint32_t) devpciR3CommonDefaultConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress, unsigned cb);
198DECLCALLBACK(VBOXSTRICTRC) devpciR3CommonDefaultConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
199 uint32_t uAddress, uint32_t u32Value, unsigned cb);
200void devpciR3CommonRestoreConfig(PPDMPCIDEV pDev, uint8_t const *pbSrcConfig);
201int devpciR3CommonRestoreRegions(PSSMHANDLE pSSM, PPDMPCIDEV pPciDev, PPCIIOREGION paIoRegions, bool fNewState);
202void devpciR3ResetDevice(PPDMPCIDEV pDev);
203void devpciR3BiosInitSetRegionAddress(PDEVPCIBUS pBus, PPDMPCIDEV pPciDev, int iRegion, uint64_t addr);
204uint32_t devpciR3GetCfg(PPDMPCIDEV pPciDev, int32_t iRegister, int cb);
205void devpciR3SetCfg(PPDMPCIDEV pPciDev, int32_t iRegister, uint32_t u32, int cb);
206
207DECLINLINE(uint8_t) devpciR3GetByte(PPDMPCIDEV pPciDev, int32_t iRegister)
208{
209 return (uint8_t)devpciR3GetCfg(pPciDev, iRegister, 1);
210}
211
212DECLINLINE(uint16_t) devpciR3GetWord(PPDMPCIDEV pPciDev, int32_t iRegister)
213{
214 return (uint16_t)devpciR3GetCfg(pPciDev, iRegister, 2);
215}
216
217DECLINLINE(uint32_t) devpciR3GetDWord(PPDMPCIDEV pPciDev, int32_t iRegister)
218{
219 return (uint32_t)devpciR3GetCfg(pPciDev, iRegister, 4);
220}
221
222DECLINLINE(void) devpciR3SetByte(PPDMPCIDEV pPciDev, int32_t iRegister, uint8_t u8)
223{
224 devpciR3SetCfg(pPciDev, iRegister, u8, 1);
225}
226
227DECLINLINE(void) devpciR3SetWord(PPDMPCIDEV pPciDev, int32_t iRegister, uint16_t u16)
228{
229 devpciR3SetCfg(pPciDev, iRegister, u16, 2);
230}
231
232DECLINLINE(void) devpciR3SetDWord(PPDMPCIDEV pPciDev, int32_t iRegister, uint32_t u32)
233{
234 devpciR3SetCfg(pPciDev, iRegister, u32, 4);
235}
236
237#endif /* IN_RING3 */
238
239#endif /* !VBOX_INCLUDED_SRC_Bus_DevPciInternal_h */
240
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