1 | /** @file
|
---|
2 | * PCI - The PCI Controller And Devices. (DEV)
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2016 Oracle Corporation
|
---|
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 |
|
---|
26 | #ifndef ___VBox_vmm_pdmpcidev_h
|
---|
27 | #define ___VBox_vmm_pdmpcidev_h
|
---|
28 |
|
---|
29 | #include <VBox/pci.h>
|
---|
30 | #include <iprt/assert.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | /** @defgroup grp_pdm_pcidev PDM PCI Device
|
---|
34 | * @ingroup grp_pdm_device
|
---|
35 | * @{
|
---|
36 | */
|
---|
37 |
|
---|
38 | /** @deprecated. */
|
---|
39 | typedef PPDMPCIDEV PPCIDEVICE;
|
---|
40 | /** @deprecated. */
|
---|
41 | typedef struct PDMPCIDEV PCIDEVICE;
|
---|
42 | /** Legacy type name.
|
---|
43 | * @deprecated */
|
---|
44 | #define PCIDevice PDMPCIDEV
|
---|
45 |
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Callback function for reading from the PCI configuration space.
|
---|
49 | *
|
---|
50 | * @returns The register value.
|
---|
51 | * @param pDevIns Pointer to the device instance the PCI device
|
---|
52 | * belongs to.
|
---|
53 | * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
|
---|
54 | * @param Address The configuration space register address. [0..4096]
|
---|
55 | * @param cb The register size. [1,2,4]
|
---|
56 | *
|
---|
57 | * @remarks Called with the PDM lock held. The device lock is NOT take because
|
---|
58 | * that is very likely be a lock order violation.
|
---|
59 | *
|
---|
60 | * @todo add pDevIns parameter.
|
---|
61 | */
|
---|
62 | typedef DECLCALLBACK(uint32_t) FNPCICONFIGREAD(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t Address, unsigned cb);
|
---|
63 | /** Pointer to a FNPCICONFIGREAD() function. */
|
---|
64 | typedef FNPCICONFIGREAD *PFNPCICONFIGREAD;
|
---|
65 | /** Pointer to a PFNPCICONFIGREAD. */
|
---|
66 | typedef PFNPCICONFIGREAD *PPFNPCICONFIGREAD;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Callback function for writing to the PCI configuration space.
|
---|
70 | *
|
---|
71 | * @param pDevIns Pointer to the device instance the PCI device
|
---|
72 | * belongs to.
|
---|
73 | * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
|
---|
74 | * @param Address The configuration space register address. [0..4096]
|
---|
75 | * @param u32Value The value that's being written. The number of bits actually used from
|
---|
76 | * this value is determined by the cb parameter.
|
---|
77 | * @param cb The register size. [1,2,4]
|
---|
78 | *
|
---|
79 | * @remarks Called with the PDM lock held. The device lock is NOT take because
|
---|
80 | * that is very likely be a lock order violation.
|
---|
81 | *
|
---|
82 | * @todo add pDevIns parameter and fix iRegion type.
|
---|
83 | */
|
---|
84 | typedef DECLCALLBACK(void) FNPCICONFIGWRITE(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t Address, uint32_t u32Value, unsigned cb);
|
---|
85 | /** Pointer to a FNPCICONFIGWRITE() function. */
|
---|
86 | typedef FNPCICONFIGWRITE *PFNPCICONFIGWRITE;
|
---|
87 | /** Pointer to a PFNPCICONFIGWRITE. */
|
---|
88 | typedef PFNPCICONFIGWRITE *PPFNPCICONFIGWRITE;
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * Callback function for mapping an PCI I/O region.
|
---|
92 | *
|
---|
93 | * @returns VBox status code.
|
---|
94 | * @param pDevIns Pointer to the device instance the PCI device
|
---|
95 | * belongs to.
|
---|
96 | * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
|
---|
97 | * @param iRegion The region number.
|
---|
98 | * @param GCPhysAddress Physical address of the region. If enmType is PCI_ADDRESS_SPACE_IO, this
|
---|
99 | * is an I/O port, otherwise it's a physical address.
|
---|
100 | *
|
---|
101 | * NIL_RTGCPHYS indicates that a MMIO2 mapping is about to be unmapped and
|
---|
102 | * that the device deregister access handlers for it and update its internal
|
---|
103 | * state to reflect this.
|
---|
104 | *
|
---|
105 | * @param cb Size of the region in bytes.
|
---|
106 | * @param enmType One of the PCI_ADDRESS_SPACE_* values.
|
---|
107 | *
|
---|
108 | * @remarks Called with the PDM lock held. The device lock is NOT take because
|
---|
109 | * that is very likely be a lock order violation.
|
---|
110 | *
|
---|
111 | * @todo add pDevIns parameter and fix iRegion type.
|
---|
112 | */
|
---|
113 | typedef DECLCALLBACK(int) FNPCIIOREGIONMAP(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, uint32_t iRegion,
|
---|
114 | RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType);
|
---|
115 | /** Pointer to a FNPCIIOREGIONMAP() function. */
|
---|
116 | typedef FNPCIIOREGIONMAP *PFNPCIIOREGIONMAP;
|
---|
117 |
|
---|
118 |
|
---|
119 | /*
|
---|
120 | * Hack to include the PDMPCIDEVICEINT structure at the right place
|
---|
121 | * to avoid duplications of FNPCIIOREGIONMAP and such.
|
---|
122 | */
|
---|
123 | #ifdef PDMPCIDEV_INCLUDE_PRIVATE
|
---|
124 | # include "pdmpcidevint.h"
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * PDM PCI Device structure.
|
---|
129 | *
|
---|
130 | * A PCI device belongs to a PDM device. A PDM device may have zero or more PCI
|
---|
131 | * devices associated with it. The first PCI device that it registers
|
---|
132 | * automatically becomes the default PCI device and can be used implicitly
|
---|
133 | * with the device helper APIs. Subsequent PCI devices must be specified
|
---|
134 | * expeclitly to the device helper APIs when used.
|
---|
135 | */
|
---|
136 | typedef struct PDMPCIDEV
|
---|
137 | {
|
---|
138 | union
|
---|
139 | {
|
---|
140 | /** PCI config space. */
|
---|
141 | uint8_t abConfig[256];
|
---|
142 | #ifndef PDMPCIDEVICE_NO_DEPRECATED
|
---|
143 | /** @deprecated Use abConfig! */
|
---|
144 | uint8_t config[256];
|
---|
145 | #endif
|
---|
146 | };
|
---|
147 |
|
---|
148 | /** Internal data. */
|
---|
149 | union
|
---|
150 | {
|
---|
151 | #ifdef PDMPCIDEVICEINT_DECLARED
|
---|
152 | PDMPCIDEVICEINT s;
|
---|
153 | #endif
|
---|
154 | uint8_t padding[HC_ARCH_BITS == 32 ? 272 : 384];
|
---|
155 | } Int;
|
---|
156 |
|
---|
157 | /** @name Read only data.
|
---|
158 | * @{
|
---|
159 | */
|
---|
160 | union
|
---|
161 | {
|
---|
162 | /** PCI device number [11:3] and function [2:0] on the pci bus.
|
---|
163 | * @sa VBOX_PCI_DEVFN_MAKE, VBOX_PCI_DEVFN_FUN_MASK, VBOX_PCI_DEVFN_DEV_SHIFT */
|
---|
164 | uint32_t uDevFn;
|
---|
165 | #ifndef PDMPCIDEVICE_NO_DEPRECATED
|
---|
166 | /** @deprecated Use uDevFn! */
|
---|
167 | int32_t devfn;
|
---|
168 | #endif
|
---|
169 | };
|
---|
170 | uint32_t Alignment0; /**< Alignment. */
|
---|
171 |
|
---|
172 | union
|
---|
173 | {
|
---|
174 | /** Device name. */
|
---|
175 | R3PTRTYPE(const char *) pszNameR3;
|
---|
176 | #ifndef PDMPCIDEVICE_NO_DEPRECATED
|
---|
177 | /** @deprecated Use pszNameR3! */
|
---|
178 | R3PTRTYPE(const char *) name;
|
---|
179 | #endif
|
---|
180 | };
|
---|
181 | /** Pointer to the device instance which registered the device.
|
---|
182 | * @todo eliminate this one? */
|
---|
183 | PPDMDEVINSR3 pDevIns;
|
---|
184 | /** @} */
|
---|
185 | } PDMPCIDEV;
|
---|
186 | #ifdef PDMPCIDEVICEINT_DECLARED
|
---|
187 | AssertCompile(RT_SIZEOFMEMB(PDMPCIDEV, Int.s) <= RT_SIZEOFMEMB(PDMPCIDEV, Int.padding));
|
---|
188 | #endif
|
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 | /** @name PDM PCI config space accessor function.
|
---|
193 | * @{
|
---|
194 | */
|
---|
195 |
|
---|
196 | /** @todo handle extended space access. */
|
---|
197 |
|
---|
198 | DECLINLINE(void) PDMPciDevSetByte(PPDMPCIDEV pPciDev, uint32_t offReg, uint8_t u8Value)
|
---|
199 | {
|
---|
200 | Assert(offReg < sizeof(pPciDev->abConfig));
|
---|
201 | pPciDev->abConfig[offReg] = u8Value;
|
---|
202 | }
|
---|
203 |
|
---|
204 | DECLINLINE(uint8_t) PDMPciDevGetByte(PPDMPCIDEV pPciDev, uint32_t offReg)
|
---|
205 | {
|
---|
206 | Assert(offReg < sizeof(pPciDev->abConfig));
|
---|
207 | return pPciDev->abConfig[offReg];
|
---|
208 | }
|
---|
209 |
|
---|
210 | DECLINLINE(void) PDMPciDevSetWord(PPDMPCIDEV pPciDev, uint32_t offReg, uint16_t u16Value)
|
---|
211 | {
|
---|
212 | Assert(offReg <= sizeof(pPciDev->abConfig) - sizeof(uint16_t));
|
---|
213 | *(uint16_t*)&pPciDev->abConfig[offReg] = RT_H2LE_U16(u16Value);
|
---|
214 | }
|
---|
215 |
|
---|
216 | DECLINLINE(uint16_t) PDMPciDevGetWord(PPDMPCIDEV pPciDev, uint32_t offReg)
|
---|
217 | {
|
---|
218 | uint16_t u16Value;
|
---|
219 | Assert(offReg <= sizeof(pPciDev->abConfig) - sizeof(uint16_t));
|
---|
220 | u16Value = *(uint16_t*)&pPciDev->abConfig[offReg];
|
---|
221 | return RT_H2LE_U16(u16Value);
|
---|
222 | }
|
---|
223 |
|
---|
224 | DECLINLINE(void) PDMPciDevSetDWord(PPDMPCIDEV pPciDev, uint32_t offReg, uint32_t u32Value)
|
---|
225 | {
|
---|
226 | Assert(offReg <= sizeof(pPciDev->abConfig) - sizeof(uint32_t));
|
---|
227 | *(uint32_t*)&pPciDev->abConfig[offReg] = RT_H2LE_U32(u32Value);
|
---|
228 | }
|
---|
229 |
|
---|
230 | DECLINLINE(uint32_t) PDMPciDevGetDWord(PPDMPCIDEV pPciDev, uint32_t offReg)
|
---|
231 | {
|
---|
232 | uint32_t u32Value;
|
---|
233 | Assert(offReg <= sizeof(pPciDev->abConfig) - sizeof(uint32_t));
|
---|
234 | u32Value = *(uint32_t*)&pPciDev->abConfig[offReg];
|
---|
235 | return RT_H2LE_U32(u32Value);
|
---|
236 | }
|
---|
237 |
|
---|
238 | DECLINLINE(void) PDMPciDevSetQWord(PPDMPCIDEV pPciDev, uint32_t offReg, uint64_t u64Value)
|
---|
239 | {
|
---|
240 | Assert(offReg <= sizeof(pPciDev->abConfig) - sizeof(uint64_t));
|
---|
241 | *(uint64_t*)&pPciDev->abConfig[offReg] = RT_H2LE_U64(u64Value);
|
---|
242 | }
|
---|
243 |
|
---|
244 | DECLINLINE(uint64_t) PDMPciDevGetQWord(PPDMPCIDEV pPciDev, uint32_t offReg)
|
---|
245 | {
|
---|
246 | uint64_t u64Value;
|
---|
247 | Assert(offReg <= sizeof(pPciDev->abConfig) - sizeof(uint64_t));
|
---|
248 | u64Value = *(uint64_t*)&pPciDev->abConfig[offReg];
|
---|
249 | return RT_H2LE_U64(u64Value);
|
---|
250 | }
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Sets the vendor id config register.
|
---|
254 | * @param pPciDev The PCI device.
|
---|
255 | * @param u16VendorId The vendor id.
|
---|
256 | */
|
---|
257 | DECLINLINE(void) PDMPciDevSetVendorId(PPDMPCIDEV pPciDev, uint16_t u16VendorId)
|
---|
258 | {
|
---|
259 | PDMPciDevSetWord(pPciDev, VBOX_PCI_VENDOR_ID, u16VendorId);
|
---|
260 | }
|
---|
261 |
|
---|
262 | /**
|
---|
263 | * Gets the vendor id config register.
|
---|
264 | * @returns the vendor id.
|
---|
265 | * @param pPciDev The PCI device.
|
---|
266 | */
|
---|
267 | DECLINLINE(uint16_t) PDMPciDevGetVendorId(PPDMPCIDEV pPciDev)
|
---|
268 | {
|
---|
269 | return PDMPciDevGetWord(pPciDev, VBOX_PCI_VENDOR_ID);
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | /**
|
---|
274 | * Sets the device id config register.
|
---|
275 | * @param pPciDev The PCI device.
|
---|
276 | * @param u16DeviceId The device id.
|
---|
277 | */
|
---|
278 | DECLINLINE(void) PDMPciDevSetDeviceId(PPDMPCIDEV pPciDev, uint16_t u16DeviceId)
|
---|
279 | {
|
---|
280 | PDMPciDevSetWord(pPciDev, VBOX_PCI_DEVICE_ID, u16DeviceId);
|
---|
281 | }
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Gets the device id config register.
|
---|
285 | * @returns the device id.
|
---|
286 | * @param pPciDev The PCI device.
|
---|
287 | */
|
---|
288 | DECLINLINE(uint16_t) PDMPciDevGetDeviceId(PPDMPCIDEV pPciDev)
|
---|
289 | {
|
---|
290 | return PDMPciDevGetWord(pPciDev, VBOX_PCI_DEVICE_ID);
|
---|
291 | }
|
---|
292 |
|
---|
293 | /**
|
---|
294 | * Sets the command config register.
|
---|
295 | *
|
---|
296 | * @param pPciDev The PCI device.
|
---|
297 | * @param u16Command The command register value.
|
---|
298 | */
|
---|
299 | DECLINLINE(void) PDMPciDevSetCommand(PPDMPCIDEV pPciDev, uint16_t u16Command)
|
---|
300 | {
|
---|
301 | PDMPciDevSetWord(pPciDev, VBOX_PCI_COMMAND, u16Command);
|
---|
302 | }
|
---|
303 |
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Gets the command config register.
|
---|
307 | * @returns The command register value.
|
---|
308 | * @param pPciDev The PCI device.
|
---|
309 | */
|
---|
310 | DECLINLINE(uint16_t) PDMPciDevGetCommand(PPDMPCIDEV pPciDev)
|
---|
311 | {
|
---|
312 | return PDMPciDevGetWord(pPciDev, VBOX_PCI_COMMAND);
|
---|
313 | }
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * Checks if the given PCI device is a bus master.
|
---|
317 | * @returns true if the device is a bus master, false if not.
|
---|
318 | * @param pPciDev The PCI device.
|
---|
319 | */
|
---|
320 | DECLINLINE(bool) PDMPciDevIsBusmaster(PPDMPCIDEV pPciDev)
|
---|
321 | {
|
---|
322 | return (PDMPciDevGetCommand(pPciDev) & VBOX_PCI_COMMAND_MASTER) != 0;
|
---|
323 | }
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * Checks if INTx interrupts disabled in the command config register.
|
---|
327 | * @returns true if disabled.
|
---|
328 | * @param pPciDev The PCI device.
|
---|
329 | */
|
---|
330 | DECLINLINE(bool) PDMPciDevIsIntxDisabled(PPDMPCIDEV pPciDev)
|
---|
331 | {
|
---|
332 | return (PDMPciDevGetCommand(pPciDev) & VBOX_PCI_COMMAND_INTX_DISABLE) != 0;
|
---|
333 | }
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * Gets the status config register.
|
---|
337 | *
|
---|
338 | * @returns status config register.
|
---|
339 | * @param pPciDev The PCI device.
|
---|
340 | */
|
---|
341 | DECLINLINE(uint16_t) PDMPciDevGetStatus(PPDMPCIDEV pPciDev)
|
---|
342 | {
|
---|
343 | return PDMPciDevGetWord(pPciDev, VBOX_PCI_STATUS);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /**
|
---|
347 | * Sets the status config register.
|
---|
348 | *
|
---|
349 | * @param pPciDev The PCI device.
|
---|
350 | * @param u16Status The status register value.
|
---|
351 | */
|
---|
352 | DECLINLINE(void) PDMPciDevSetStatus(PPDMPCIDEV pPciDev, uint16_t u16Status)
|
---|
353 | {
|
---|
354 | PDMPciDevSetWord(pPciDev, VBOX_PCI_STATUS, u16Status);
|
---|
355 | }
|
---|
356 |
|
---|
357 |
|
---|
358 | /**
|
---|
359 | * Sets the revision id config register.
|
---|
360 | *
|
---|
361 | * @param pPciDev The PCI device.
|
---|
362 | * @param u8RevisionId The revision id.
|
---|
363 | */
|
---|
364 | DECLINLINE(void) PDMPciDevSetRevisionId(PPDMPCIDEV pPciDev, uint8_t u8RevisionId)
|
---|
365 | {
|
---|
366 | PDMPciDevSetByte(pPciDev, VBOX_PCI_REVISION_ID, u8RevisionId);
|
---|
367 | }
|
---|
368 |
|
---|
369 |
|
---|
370 | /**
|
---|
371 | * Sets the register level programming class config register.
|
---|
372 | *
|
---|
373 | * @param pPciDev The PCI device.
|
---|
374 | * @param u8ClassProg The new value.
|
---|
375 | */
|
---|
376 | DECLINLINE(void) PDMPciDevSetClassProg(PPDMPCIDEV pPciDev, uint8_t u8ClassProg)
|
---|
377 | {
|
---|
378 | PDMPciDevSetByte(pPciDev, VBOX_PCI_CLASS_PROG, u8ClassProg);
|
---|
379 | }
|
---|
380 |
|
---|
381 |
|
---|
382 | /**
|
---|
383 | * Sets the sub-class (aka device class) config register.
|
---|
384 | *
|
---|
385 | * @param pPciDev The PCI device.
|
---|
386 | * @param u8SubClass The sub-class.
|
---|
387 | */
|
---|
388 | DECLINLINE(void) PDMPciDevSetClassSub(PPDMPCIDEV pPciDev, uint8_t u8SubClass)
|
---|
389 | {
|
---|
390 | PDMPciDevSetByte(pPciDev, VBOX_PCI_CLASS_SUB, u8SubClass);
|
---|
391 | }
|
---|
392 |
|
---|
393 |
|
---|
394 | /**
|
---|
395 | * Sets the base class config register.
|
---|
396 | *
|
---|
397 | * @param pPciDev The PCI device.
|
---|
398 | * @param u8BaseClass The base class.
|
---|
399 | */
|
---|
400 | DECLINLINE(void) PDMPciDevSetClassBase(PPDMPCIDEV pPciDev, uint8_t u8BaseClass)
|
---|
401 | {
|
---|
402 | PDMPciDevSetByte(pPciDev, VBOX_PCI_CLASS_BASE, u8BaseClass);
|
---|
403 | }
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * Sets the header type config register.
|
---|
407 | *
|
---|
408 | * @param pPciDev The PCI device.
|
---|
409 | * @param u8HdrType The header type.
|
---|
410 | */
|
---|
411 | DECLINLINE(void) PDMPciDevSetHeaderType(PPDMPCIDEV pPciDev, uint8_t u8HdrType)
|
---|
412 | {
|
---|
413 | PDMPciDevSetByte(pPciDev, VBOX_PCI_HEADER_TYPE, u8HdrType);
|
---|
414 | }
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * Gets the header type config register.
|
---|
418 | *
|
---|
419 | * @param pPciDev The PCI device.
|
---|
420 | * @returns u8HdrType The header type.
|
---|
421 | */
|
---|
422 | DECLINLINE(uint8_t) PDMPciDevGetHeaderType(PPDMPCIDEV pPciDev)
|
---|
423 | {
|
---|
424 | return PDMPciDevGetByte(pPciDev, VBOX_PCI_HEADER_TYPE);
|
---|
425 | }
|
---|
426 |
|
---|
427 | /**
|
---|
428 | * Sets the BIST (built-in self-test) config register.
|
---|
429 | *
|
---|
430 | * @param pPciDev The PCI device.
|
---|
431 | * @param u8Bist The BIST value.
|
---|
432 | */
|
---|
433 | DECLINLINE(void) PDMPciDevSetBIST(PPDMPCIDEV pPciDev, uint8_t u8Bist)
|
---|
434 | {
|
---|
435 | PDMPciDevSetByte(pPciDev, VBOX_PCI_BIST, u8Bist);
|
---|
436 | }
|
---|
437 |
|
---|
438 | /**
|
---|
439 | * Gets the BIST (built-in self-test) config register.
|
---|
440 | *
|
---|
441 | * @param pPciDev The PCI device.
|
---|
442 | * @returns u8Bist The BIST.
|
---|
443 | */
|
---|
444 | DECLINLINE(uint8_t) PDMPciDevGetBIST(PPDMPCIDEV pPciDev)
|
---|
445 | {
|
---|
446 | return PDMPciDevGetByte(pPciDev, VBOX_PCI_BIST);
|
---|
447 | }
|
---|
448 |
|
---|
449 |
|
---|
450 | /**
|
---|
451 | * Sets a base address config register.
|
---|
452 | *
|
---|
453 | * @param pPciDev The PCI device.
|
---|
454 | * @param iReg Base address register number (0..5).
|
---|
455 | * @param fIOSpace Whether it's I/O (true) or memory (false) space.
|
---|
456 | * @param fPrefetchable Whether the memory is prefetachable. Must be false if fIOSpace == true.
|
---|
457 | * @param f64Bit Whether the memory can be mapped anywhere in the 64-bit address space. Otherwise restrict to 32-bit.
|
---|
458 | * @param u32Addr The address value.
|
---|
459 | */
|
---|
460 | DECLINLINE(void) PDMPciDevSetBaseAddress(PPDMPCIDEV pPciDev, uint8_t iReg, bool fIOSpace, bool fPrefetchable, bool f64Bit,
|
---|
461 | uint32_t u32Addr)
|
---|
462 | {
|
---|
463 | if (fIOSpace)
|
---|
464 | {
|
---|
465 | Assert(!(u32Addr & 0x3)); Assert(!fPrefetchable); Assert(!f64Bit);
|
---|
466 | u32Addr |= RT_BIT_32(0);
|
---|
467 | }
|
---|
468 | else
|
---|
469 | {
|
---|
470 | Assert(!(u32Addr & 0xf));
|
---|
471 | if (fPrefetchable)
|
---|
472 | u32Addr |= RT_BIT_32(3);
|
---|
473 | if (f64Bit)
|
---|
474 | u32Addr |= 0x2 << 1;
|
---|
475 | }
|
---|
476 | switch (iReg)
|
---|
477 | {
|
---|
478 | case 0: iReg = VBOX_PCI_BASE_ADDRESS_0; break;
|
---|
479 | case 1: iReg = VBOX_PCI_BASE_ADDRESS_1; break;
|
---|
480 | case 2: iReg = VBOX_PCI_BASE_ADDRESS_2; break;
|
---|
481 | case 3: iReg = VBOX_PCI_BASE_ADDRESS_3; break;
|
---|
482 | case 4: iReg = VBOX_PCI_BASE_ADDRESS_4; break;
|
---|
483 | case 5: iReg = VBOX_PCI_BASE_ADDRESS_5; break;
|
---|
484 | default: AssertFailedReturnVoid();
|
---|
485 | }
|
---|
486 |
|
---|
487 | PDMPciDevSetDWord(pPciDev, iReg, u32Addr);
|
---|
488 | }
|
---|
489 |
|
---|
490 | /**
|
---|
491 | * Please document me. I don't seem to be getting as much as calculating
|
---|
492 | * the address of some PCI region.
|
---|
493 | */
|
---|
494 | DECLINLINE(uint32_t) PDMPciDevGetRegionReg(uint32_t iRegion)
|
---|
495 | {
|
---|
496 | return iRegion == VBOX_PCI_ROM_SLOT
|
---|
497 | ? VBOX_PCI_ROM_ADDRESS : (VBOX_PCI_BASE_ADDRESS_0 + iRegion * 4);
|
---|
498 | }
|
---|
499 |
|
---|
500 | /**
|
---|
501 | * Sets the sub-system vendor id config register.
|
---|
502 | *
|
---|
503 | * @param pPciDev The PCI device.
|
---|
504 | * @param u16SubSysVendorId The sub-system vendor id.
|
---|
505 | */
|
---|
506 | DECLINLINE(void) PDMPciDevSetSubSystemVendorId(PPDMPCIDEV pPciDev, uint16_t u16SubSysVendorId)
|
---|
507 | {
|
---|
508 | PDMPciDevSetWord(pPciDev, VBOX_PCI_SUBSYSTEM_VENDOR_ID, u16SubSysVendorId);
|
---|
509 | }
|
---|
510 |
|
---|
511 | /**
|
---|
512 | * Gets the sub-system vendor id config register.
|
---|
513 | * @returns the sub-system vendor id.
|
---|
514 | * @param pPciDev The PCI device.
|
---|
515 | */
|
---|
516 | DECLINLINE(uint16_t) PDMPciDevGetSubSystemVendorId(PPDMPCIDEV pPciDev)
|
---|
517 | {
|
---|
518 | return PDMPciDevGetWord(pPciDev, VBOX_PCI_SUBSYSTEM_VENDOR_ID);
|
---|
519 | }
|
---|
520 |
|
---|
521 |
|
---|
522 | /**
|
---|
523 | * Sets the sub-system id config register.
|
---|
524 | *
|
---|
525 | * @param pPciDev The PCI device.
|
---|
526 | * @param u16SubSystemId The sub-system id.
|
---|
527 | */
|
---|
528 | DECLINLINE(void) PDMPciDevSetSubSystemId(PPDMPCIDEV pPciDev, uint16_t u16SubSystemId)
|
---|
529 | {
|
---|
530 | PDMPciDevSetWord(pPciDev, VBOX_PCI_SUBSYSTEM_ID, u16SubSystemId);
|
---|
531 | }
|
---|
532 |
|
---|
533 | /**
|
---|
534 | * Gets the sub-system id config register.
|
---|
535 | * @returns the sub-system id.
|
---|
536 | * @param pPciDev The PCI device.
|
---|
537 | */
|
---|
538 | DECLINLINE(uint16_t) PDMPciDevGetSubSystemId(PPDMPCIDEV pPciDev)
|
---|
539 | {
|
---|
540 | return PDMPciDevGetWord(pPciDev, VBOX_PCI_SUBSYSTEM_ID);
|
---|
541 | }
|
---|
542 |
|
---|
543 | /**
|
---|
544 | * Sets offset to capability list.
|
---|
545 | *
|
---|
546 | * @param pPciDev The PCI device.
|
---|
547 | * @param u8Offset The offset to capability list.
|
---|
548 | */
|
---|
549 | DECLINLINE(void) PDMPciDevSetCapabilityList(PPDMPCIDEV pPciDev, uint8_t u8Offset)
|
---|
550 | {
|
---|
551 | PDMPciDevSetByte(pPciDev, VBOX_PCI_CAPABILITY_LIST, u8Offset);
|
---|
552 | }
|
---|
553 |
|
---|
554 | /**
|
---|
555 | * Returns offset to capability list.
|
---|
556 | *
|
---|
557 | * @returns offset to capability list.
|
---|
558 | * @param pPciDev The PCI device.
|
---|
559 | */
|
---|
560 | DECLINLINE(uint8_t) PDMPciDevGetCapabilityList(PPDMPCIDEV pPciDev)
|
---|
561 | {
|
---|
562 | return PDMPciDevGetByte(pPciDev, VBOX_PCI_CAPABILITY_LIST);
|
---|
563 | }
|
---|
564 |
|
---|
565 | /**
|
---|
566 | * Sets the interrupt line config register.
|
---|
567 | *
|
---|
568 | * @param pPciDev The PCI device.
|
---|
569 | * @param u8Line The interrupt line.
|
---|
570 | */
|
---|
571 | DECLINLINE(void) PDMPciDevSetInterruptLine(PPDMPCIDEV pPciDev, uint8_t u8Line)
|
---|
572 | {
|
---|
573 | PDMPciDevSetByte(pPciDev, VBOX_PCI_INTERRUPT_LINE, u8Line);
|
---|
574 | }
|
---|
575 |
|
---|
576 | /**
|
---|
577 | * Gets the interrupt line config register.
|
---|
578 | *
|
---|
579 | * @returns The interrupt line.
|
---|
580 | * @param pPciDev The PCI device.
|
---|
581 | */
|
---|
582 | DECLINLINE(uint8_t) PDMPciDevGetInterruptLine(PPDMPCIDEV pPciDev)
|
---|
583 | {
|
---|
584 | return PDMPciDevGetByte(pPciDev, VBOX_PCI_INTERRUPT_LINE);
|
---|
585 | }
|
---|
586 |
|
---|
587 | /**
|
---|
588 | * Sets the interrupt pin config register.
|
---|
589 | *
|
---|
590 | * @param pPciDev The PCI device.
|
---|
591 | * @param u8Pin The interrupt pin.
|
---|
592 | */
|
---|
593 | DECLINLINE(void) PDMPciDevSetInterruptPin(PPDMPCIDEV pPciDev, uint8_t u8Pin)
|
---|
594 | {
|
---|
595 | PDMPciDevSetByte(pPciDev, VBOX_PCI_INTERRUPT_PIN, u8Pin);
|
---|
596 | }
|
---|
597 |
|
---|
598 | /**
|
---|
599 | * Gets the interrupt pin config register.
|
---|
600 | *
|
---|
601 | * @returns The interrupt pin.
|
---|
602 | * @param pPciDev The PCI device.
|
---|
603 | */
|
---|
604 | DECLINLINE(uint8_t) PDMPciDevGetInterruptPin(PPDMPCIDEV pPciDev)
|
---|
605 | {
|
---|
606 | return PDMPciDevGetByte(pPciDev, VBOX_PCI_INTERRUPT_PIN);
|
---|
607 | }
|
---|
608 |
|
---|
609 | /** @} */
|
---|
610 |
|
---|
611 | /** @name Aliases for old function names.
|
---|
612 | * @{
|
---|
613 | */
|
---|
614 | #if !defined(PDMPCIDEVICE_NO_DEPRECATED) || defined(DOXYGEN_RUNNING)
|
---|
615 | # define PCIDevSetByte PDMPciDevSetByte
|
---|
616 | # define PCIDevGetByte PDMPciDevGetByte
|
---|
617 | # define PCIDevSetWord PDMPciDevSetWord
|
---|
618 | # define PCIDevGetWord PDMPciDevGetWord
|
---|
619 | # define PCIDevSetDWord PDMPciDevSetDWord
|
---|
620 | # define PCIDevGetDWord PDMPciDevGetDWord
|
---|
621 | # define PCIDevSetQWord PDMPciDevSetQWord
|
---|
622 | # define PCIDevGetQWord PDMPciDevGetQWord
|
---|
623 | # define PCIDevSetVendorId PDMPciDevSetVendorId
|
---|
624 | # define PCIDevGetVendorId PDMPciDevGetVendorId
|
---|
625 | # define PCIDevSetDeviceId PDMPciDevSetDeviceId
|
---|
626 | # define PCIDevGetDeviceId PDMPciDevGetDeviceId
|
---|
627 | # define PCIDevSetCommand PDMPciDevSetCommand
|
---|
628 | # define PCIDevGetCommand PDMPciDevGetCommand
|
---|
629 | # define PCIDevIsBusmaster PDMPciDevIsBusmaster
|
---|
630 | # define PCIDevIsIntxDisabled PDMPciDevIsIntxDisabled
|
---|
631 | # define PCIDevGetStatus PDMPciDevGetStatus
|
---|
632 | # define PCIDevSetStatus PDMPciDevSetStatus
|
---|
633 | # define PCIDevSetRevisionId PDMPciDevSetRevisionId
|
---|
634 | # define PCIDevSetClassProg PDMPciDevSetClassProg
|
---|
635 | # define PCIDevSetClassSub PDMPciDevSetClassSub
|
---|
636 | # define PCIDevSetClassBase PDMPciDevSetClassBase
|
---|
637 | # define PCIDevSetHeaderType PDMPciDevSetHeaderType
|
---|
638 | # define PCIDevGetHeaderType PDMPciDevGetHeaderType
|
---|
639 | # define PCIDevSetBIST PDMPciDevSetBIST
|
---|
640 | # define PCIDevGetBIST PDMPciDevGetBIST
|
---|
641 | # define PCIDevSetBaseAddress PDMPciDevSetBaseAddress
|
---|
642 | # define PCIDevGetRegionReg PDMPciDevGetRegionReg
|
---|
643 | # define PCIDevSetSubSystemVendorId PDMPciDevSetSubSystemVendorId
|
---|
644 | # define PCIDevGetSubSystemVendorId PDMPciDevGetSubSystemVendorId
|
---|
645 | # define PCIDevSetSubSystemId PDMPciDevSetSubSystemId
|
---|
646 | # define PCIDevGetSubSystemId PDMPciDevGetSubSystemId
|
---|
647 | # define PCIDevSetCapabilityList PDMPciDevSetCapabilityList
|
---|
648 | # define PCIDevGetCapabilityList PDMPciDevGetCapabilityList
|
---|
649 | # define PCIDevSetInterruptLine PDMPciDevSetInterruptLine
|
---|
650 | # define PCIDevGetInterruptLine PDMPciDevGetInterruptLine
|
---|
651 | # define PCIDevSetInterruptPin PDMPciDevSetInterruptPin
|
---|
652 | # define PCIDevGetInterruptPin PDMPciDevGetInterruptPin
|
---|
653 | #endif
|
---|
654 | /** @} */
|
---|
655 |
|
---|
656 |
|
---|
657 | /** @} */
|
---|
658 |
|
---|
659 | #endif
|
---|