1 | /** @file
|
---|
2 | * PCI - The PCI Controller And Devices.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | *
|
---|
25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___VBox_pci_h
|
---|
31 | #define ___VBox_pci_h
|
---|
32 |
|
---|
33 | #include <VBox/cdefs.h>
|
---|
34 | #include <VBox/types.h>
|
---|
35 |
|
---|
36 | /** @defgroup grp_pci PCI - The PCI Controller.
|
---|
37 | * @{
|
---|
38 | */
|
---|
39 |
|
---|
40 | /** Pointer to a PCI device. */
|
---|
41 | typedef struct PCIDevice *PPCIDEVICE;
|
---|
42 |
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * PCI configuration word 4 (command) and word 6 (status).
|
---|
46 | */
|
---|
47 | typedef enum PCICONFIGCOMMAND
|
---|
48 | {
|
---|
49 | /** Supports/uses memory accesses. */
|
---|
50 | PCI_COMMAND_IOACCESS = 0x0001,
|
---|
51 | PCI_COMMAND_MEMACCESS = 0x0002,
|
---|
52 | PCI_COMMAND_BUSMASTER = 0x0004
|
---|
53 | } PCICONFIGCOMMAND;
|
---|
54 |
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * PCI Address space specification.
|
---|
58 | * This is used when registering a I/O region.
|
---|
59 | */
|
---|
60 | /** Note: There are all sorts of dirty dependencies on the values in the
|
---|
61 | * pci device. Be careful when changing this.
|
---|
62 | * @todo we should introduce 32 & 64 bits physical address types
|
---|
63 | */
|
---|
64 | typedef enum PCIADDRESSSPACE
|
---|
65 | {
|
---|
66 | /** Memory. */
|
---|
67 | PCI_ADDRESS_SPACE_MEM = 0x00,
|
---|
68 | /** I/O space. */
|
---|
69 | PCI_ADDRESS_SPACE_IO = 0x01,
|
---|
70 | /** Prefetch memory. */
|
---|
71 | PCI_ADDRESS_SPACE_MEM_PREFETCH = 0x08
|
---|
72 | } PCIADDRESSSPACE;
|
---|
73 |
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Callback function for mapping an PCI I/O region.
|
---|
77 | *
|
---|
78 | * @return VBox status code.
|
---|
79 | * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
|
---|
80 | * @param iRegion The region number.
|
---|
81 | * @param GCPhysAddress Physical address of the region. If enmType is PCI_ADDRESS_SPACE_IO, this
|
---|
82 | * is an I/O port, otherwise it's a physical address.
|
---|
83 | *
|
---|
84 | * NIL_RTGCPHYS indicates that a MMIO2 mapping is about to be unmapped and
|
---|
85 | * that the device deregister access handlers for it and update its internal
|
---|
86 | * state to reflect this.
|
---|
87 | *
|
---|
88 | * @param enmType One of the PCI_ADDRESS_SPACE_* values.
|
---|
89 | *
|
---|
90 | * @remarks The address is *NOT* relative to pci_mem_base.
|
---|
91 | */
|
---|
92 | typedef DECLCALLBACK(int) FNPCIIOREGIONMAP(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType);
|
---|
93 | /** Pointer to a FNPCIIOREGIONMAP() function. */
|
---|
94 | typedef FNPCIIOREGIONMAP *PFNPCIIOREGIONMAP;
|
---|
95 |
|
---|
96 |
|
---|
97 | /** @name PCI Configuration Space Registers
|
---|
98 | * @{ */
|
---|
99 | #define VBOX_PCI_VENDOR_ID 0x00 /**< 16-bit RO */
|
---|
100 | #define VBOX_PCI_DEVICE_ID 0x02 /**< 16-bit RO */
|
---|
101 | #define VBOX_PCI_COMMAND 0x04 /**< 16-bit RW */
|
---|
102 | #define VBOX_PCI_STATUS 0x06 /**< 16-bit RW */
|
---|
103 | #define VBOX_PCI_REVISION_ID 0x08 /**< 8-bit RO */
|
---|
104 | #define VBOX_PCI_CLASS_PROG 0x09 /**< 8-bit RO */
|
---|
105 | #define VBOX_PCI_CLASS_DEVICE 0x0a /**< 8-bit ?? */
|
---|
106 | #define VBOX_PCI_CACHE_LINE_SIZE 0x0c /**< 8-bit ?? */
|
---|
107 | #define VBOX_PCI_LATENCY_TIMER 0x0d /**< 8-bit ?? */
|
---|
108 | #define VBOX_PCI_HEADER_TYPE 0x0e /**< 8-bit ?? */
|
---|
109 | #define VBOX_PCI_BIST 0x0f /**< 8-bit ?? */
|
---|
110 | #define VBOX_PCI_BASE_ADDRESS_0 0x10 /**< 32-bit RW */
|
---|
111 | #define VBOX_PCI_BASE_ADDRESS_1 0x14 /**< 32-bit RW */
|
---|
112 | #define VBOX_PCI_BASE_ADDRESS_2 0x18 /**< 32-bit RW */
|
---|
113 | #define VBOX_PCI_PRIMARY_BUS 0x18 /**< 8-bit ?? - bridge - primary bus number. */
|
---|
114 | #define VBOX_PCI_SECONDARY_BUS 0x19 /**< 8-bit ?? - bridge - secondary bus number. */
|
---|
115 | #define VBOX_PCI_SUBORDINATE_BUS 0x1a /**< 8-bit ?? - bridge - highest subordinate bus number. (behind the bridge) */
|
---|
116 | #define VBOX_PCI_SEC_LATENCY_TIMER 0x1b /**< 8-bit ?? - bridge - secondary latency timer. */
|
---|
117 | #define VBOX_PCI_BASE_ADDRESS_3 0x1c /**< 32-bit RW */
|
---|
118 | #define VBOX_PCI_IO_BASE 0x1c /**< 8-bit ?? - bridge - I/O range base. */
|
---|
119 | #define VBOX_PCI_IO_LIMIT 0x1d /**< 8-bit ?? - bridge - I/O range limit. */
|
---|
120 | #define VBOX_PCI_SEC_STATUS 0x1e /**< 16-bit ?? - bridge - secondary status register. */
|
---|
121 | #define VBOX_PCI_BASE_ADDRESS_4 0x20 /**< 32-bit RW */
|
---|
122 | #define VBOX_PCI_MEMORY_BASE 0x20 /**< 16-bit ?? - bridge - memory range base. */
|
---|
123 | #define VBOX_PCI_MEMORY_LIMIT 0x22 /**< 16-bit ?? - bridge - memory range limit. */
|
---|
124 | #define VBOX_PCI_BASE_ADDRESS_5 0x24 /**< 32-bit RW */
|
---|
125 | #define VBOX_PCI_PREF_MEMORY_BASE 0x24 /**< 16-bit ?? - bridge - Prefetchable memory range base. */
|
---|
126 | #define VBOX_PCI_PREF_MEMORY_LIMIT 0x26 /**< 16-bit ?? - bridge - Prefetchable memory range limit. */
|
---|
127 | #define VBOX_PCI_CARDBUS_CIS 0x28 /**< 32-bit ?? */
|
---|
128 | #define VBOX_PCI_PREF_BASE_UPPER32 0x28 /**< 32-bit ?? - bridge - Prefetchable memory range high base.*/
|
---|
129 | #define VBOX_PCI_PREF_LIMIT_UPPER32 0x2c /**< 32-bit ?? - bridge - Prefetchable memory range high limit. */
|
---|
130 | #define VBOX_PCI_SUBSYSTEM_VENDOR_ID 0x2c /**< 16-bit ?? */
|
---|
131 | #define VBOX_PCI_SUBSYSTEM_ID 0x2e /**< 16-bit ?? */
|
---|
132 | #define VBOX_PCI_ROM_ADDRESS 0x30 /**< 32-bit ?? */
|
---|
133 | #define VBOX_PCI_IO_BASE_UPPER16 0x30 /**< 16-bit ?? - bridge - memory range high base. */
|
---|
134 | #define VBOX_PCI_IO_LIMIT_UPPER16 0x32 /**< 16-bit ?? - bridge - memory range high limit. */
|
---|
135 | #define VBOX_PCI_CAPABILITY_LIST 0x34 /**< 8-bit? ?? */
|
---|
136 | #define VBOX_PCI_ROM_ADDRESS_BR 0x38 /**< 32-bit ?? - bridge */
|
---|
137 | #define VBOX_PCI_INTERRUPT_LINE 0x3c /**< 8-bit RW - Interrupt line. */
|
---|
138 | #define VBOX_PCI_INTERRUPT_PIN 0x3d /**< 8-bit RO - Interrupt pin. */
|
---|
139 | #define VBOX_PCI_MIN_GNT 0x3e /**< 8-bit ?? */
|
---|
140 | #define VBOX_PCI_BRIDGE_CONTROL 0x3e /**< 8-bit? ?? - bridge */
|
---|
141 | #define VBOX_PCI_MAX_LAT 0x3f /**< 8-bit ?? */
|
---|
142 | /** @} */
|
---|
143 |
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Callback function for reading from the PCI configuration space.
|
---|
147 | *
|
---|
148 | * @returns The register value.
|
---|
149 | * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
|
---|
150 | * @param Address The configuration space register address. [0..255]
|
---|
151 | * @param cb The register size. [1,2,4]
|
---|
152 | */
|
---|
153 | typedef DECLCALLBACK(uint32_t) FNPCICONFIGREAD(PPCIDEVICE pPciDev, uint32_t Address, unsigned cb);
|
---|
154 | /** Pointer to a FNPCICONFIGREAD() function. */
|
---|
155 | typedef FNPCICONFIGREAD *PFNPCICONFIGREAD;
|
---|
156 | /** Pointer to a PFNPCICONFIGREAD. */
|
---|
157 | typedef PFNPCICONFIGREAD *PPFNPCICONFIGREAD;
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Callback function for writing to the PCI configuration space.
|
---|
161 | *
|
---|
162 | * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
|
---|
163 | * @param Address The configuration space register address. [0..255]
|
---|
164 | * @param u32Value The value that's being written. The number of bits actually used from
|
---|
165 | * this value is determined by the cb parameter.
|
---|
166 | * @param cb The register size. [1,2,4]
|
---|
167 | */
|
---|
168 | typedef DECLCALLBACK(void) FNPCICONFIGWRITE(PPCIDEVICE pPciDev, uint32_t Address, uint32_t u32Value, unsigned cb);
|
---|
169 | /** Pointer to a FNPCICONFIGWRITE() function. */
|
---|
170 | typedef FNPCICONFIGWRITE *PFNPCICONFIGWRITE;
|
---|
171 | /** Pointer to a PFNPCICONFIGWRITE. */
|
---|
172 | typedef PFNPCICONFIGWRITE *PPFNPCICONFIGWRITE;
|
---|
173 |
|
---|
174 | /** Fixed I/O region number for ROM. */
|
---|
175 | #define PCI_ROM_SLOT 6
|
---|
176 | /** Max number of I/O regions. */
|
---|
177 | #define PCI_NUM_REGIONS 7
|
---|
178 |
|
---|
179 | /*
|
---|
180 | * Hack to include the PCIDEVICEINT structure at the right place
|
---|
181 | * to avoid duplications of FNPCIIOREGIONMAP and PCI_NUM_REGIONS.
|
---|
182 | */
|
---|
183 | #ifdef PCI_INCLUDE_PRIVATE
|
---|
184 | # include "PCIInternal.h"
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * PCI Device structure.
|
---|
189 | */
|
---|
190 | typedef struct PCIDevice
|
---|
191 | {
|
---|
192 | /** PCI config space. */
|
---|
193 | uint8_t config[256];
|
---|
194 |
|
---|
195 | /** Internal data. */
|
---|
196 | union
|
---|
197 | {
|
---|
198 | #ifdef __PCIDEVICEINT_DECLARED__
|
---|
199 | PCIDEVICEINT s;
|
---|
200 | #endif
|
---|
201 | char padding[224];
|
---|
202 | } Int;
|
---|
203 |
|
---|
204 | /** Read only data.
|
---|
205 | * @{
|
---|
206 | */
|
---|
207 | /** PCI device number on the pci bus. */
|
---|
208 | int32_t devfn;
|
---|
209 | uint32_t Alignment0; /**< Alignment. */
|
---|
210 | /** Device name. */
|
---|
211 | R3PTRTYPE(const char *) name;
|
---|
212 | /** Pointer to the device instance which registered the device. */
|
---|
213 | PPDMDEVINSR3 pDevIns;
|
---|
214 | /** @} */
|
---|
215 | } PCIDEVICE;
|
---|
216 |
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * Sets the vendor id config register.
|
---|
220 | * @param pPciDev The PCI device.
|
---|
221 | * @param u16VendorId The vendor id.
|
---|
222 | */
|
---|
223 | DECLINLINE(void) PCIDevSetVendorId(PPCIDEVICE pPciDev, uint16_t u16VendorId)
|
---|
224 | {
|
---|
225 | u16VendorId = RT_H2LE_U16(u16VendorId);
|
---|
226 | pPciDev->config[VBOX_PCI_VENDOR_ID] = u16VendorId & 0xff;
|
---|
227 | pPciDev->config[VBOX_PCI_VENDOR_ID + 1] = u16VendorId >> 8;
|
---|
228 | }
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Gets the vendor id config register.
|
---|
232 | * @returns the vendor id.
|
---|
233 | * @param pPciDev The PCI device.
|
---|
234 | */
|
---|
235 | DECLINLINE(uint16_t) PCIDevGetVendorId(PPCIDEVICE pPciDev)
|
---|
236 | {
|
---|
237 | return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_VENDOR_ID], pPciDev->config[VBOX_PCI_VENDOR_ID + 1]));
|
---|
238 | }
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Sets the device id config register.
|
---|
242 | * @param pPciDev The PCI device.
|
---|
243 | * @param u16DeviceId The device id.
|
---|
244 | */
|
---|
245 | DECLINLINE(void) PCIDevSetDeviceId(PPCIDEVICE pPciDev, uint16_t u16DeviceId)
|
---|
246 | {
|
---|
247 | u16DeviceId = RT_H2LE_U16(u16DeviceId);
|
---|
248 | pPciDev->config[VBOX_PCI_DEVICE_ID] = u16DeviceId & 0xff;
|
---|
249 | pPciDev->config[VBOX_PCI_DEVICE_ID + 1] = u16DeviceId >> 8;
|
---|
250 | }
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Gets the device id config register.
|
---|
254 | * @returns the device id.
|
---|
255 | * @param pPciDev The PCI device.
|
---|
256 | */
|
---|
257 | DECLINLINE(uint16_t) PCIDevGetDeviceId(PPCIDEVICE pPciDev)
|
---|
258 | {
|
---|
259 | return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_DEVICE_ID], pPciDev->config[VBOX_PCI_DEVICE_ID + 1]));
|
---|
260 | }
|
---|
261 |
|
---|
262 | /**
|
---|
263 | * Gets the sub-system vendor id config register.
|
---|
264 | * @returns the sub-system vendor id.
|
---|
265 | * @param pPciDev The PCI device.
|
---|
266 | */
|
---|
267 | DECLINLINE(uint16_t) PCIDevGetSubSystemVendorId(PPCIDEVICE pPciDev)
|
---|
268 | {
|
---|
269 | return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID], pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID + 1]));
|
---|
270 | }
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * Gets the sub-system id config register.
|
---|
274 | * @returns the sub-system id.
|
---|
275 | * @param pPciDev The PCI device.
|
---|
276 | */
|
---|
277 | DECLINLINE(uint16_t) PCIDevGetSubSystemId(PPCIDEVICE pPciDev)
|
---|
278 | {
|
---|
279 | return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_SUBSYSTEM_ID], pPciDev->config[VBOX_PCI_SUBSYSTEM_ID + 1]));
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 | /** @} */
|
---|
284 |
|
---|
285 | #endif
|
---|