1 | /** @file
|
---|
2 | * PDM - Pluggable Device Manager, raw PCI Devices. (VMM)
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2010-2011 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_rawpci_h
|
---|
27 | #define ___VBox_rawpci_h
|
---|
28 |
|
---|
29 | #include <iprt/types.h>
|
---|
30 |
|
---|
31 |
|
---|
32 | RT_C_DECLS_BEGIN
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Handle for the raw PCI device.
|
---|
36 | */
|
---|
37 | typedef RTR0PTR PCIRAWDEVHANDLE;
|
---|
38 |
|
---|
39 |
|
---|
40 | /** Parameters buffer for PCIRAWR0_DO_OPEN_DEVICE call */
|
---|
41 | typedef struct
|
---|
42 | {
|
---|
43 | /* in */
|
---|
44 | uint32_t PciAddress;
|
---|
45 | uint32_t fFlags;
|
---|
46 | /* out */
|
---|
47 | PCIRAWDEVHANDLE Device;
|
---|
48 | } PCIRAWREQOPENDEVICE;
|
---|
49 |
|
---|
50 | /** Parameters buffer for PCIRAWR0_DO_CLOSE_DEVICE call */
|
---|
51 | typedef struct
|
---|
52 | {
|
---|
53 | /* in */
|
---|
54 | uint32_t fFlags;
|
---|
55 | } PCIRAWREQCLOSEDEVICE;
|
---|
56 |
|
---|
57 |
|
---|
58 | /** Parameters buffer for PCIRAWR0_DO_GET_REGION_INFO call */
|
---|
59 | typedef struct
|
---|
60 | {
|
---|
61 | /* in */
|
---|
62 | int32_t iRegion;
|
---|
63 | /* out */
|
---|
64 | RTGCPHYS RegionStart;
|
---|
65 | uint64_t u64RegionSize;
|
---|
66 | bool fPresent;
|
---|
67 | bool fMmio;
|
---|
68 | } PCIRAWREQGETREGIONINFO;
|
---|
69 |
|
---|
70 | /** Parameters buffer for PCIRAWR0_DO_MAP_REGION call. */
|
---|
71 | typedef struct
|
---|
72 | {
|
---|
73 | /* in */
|
---|
74 | RTGCPHYS StartAddress;
|
---|
75 | uint64_t iRegionSize;
|
---|
76 | uint32_t fFlags;
|
---|
77 | /* out */
|
---|
78 | RTR3PTR pvAddressR3;
|
---|
79 | RTR0PTR pvAddressR0;
|
---|
80 | } PCIRAWREQMAPREGION;
|
---|
81 |
|
---|
82 | /** Parameters buffer for PCIRAWR0_DO_UNMAP_REGION call. */
|
---|
83 | typedef struct
|
---|
84 | {
|
---|
85 | /* in */
|
---|
86 | RTR3PTR pvAddressR3;
|
---|
87 | RTR0PTR pvAddressR0;
|
---|
88 | } PCIRAWREQUNMAPREGION;
|
---|
89 |
|
---|
90 | /** Parameters buffer for PCIRAWR0_DO_PIO_WRITE call. */
|
---|
91 | typedef struct
|
---|
92 | {
|
---|
93 | /* in */
|
---|
94 | uint16_t iPort;
|
---|
95 | uint16_t cb;
|
---|
96 | uint32_t iValue;
|
---|
97 | } PCIRAWREQPIOWRITE;
|
---|
98 |
|
---|
99 | /** Parameters buffer for PCIRAWR0_DO_PIO_READ call. */
|
---|
100 | typedef struct
|
---|
101 | {
|
---|
102 | /* in */
|
---|
103 | uint16_t iPort;
|
---|
104 | uint16_t cb;
|
---|
105 | /* out */
|
---|
106 | uint32_t iValue;
|
---|
107 | } PCIRAWREQPIOREAD;
|
---|
108 |
|
---|
109 | /** Memory operand. */
|
---|
110 | typedef struct
|
---|
111 | {
|
---|
112 | union
|
---|
113 | {
|
---|
114 | uint8_t u8;
|
---|
115 | uint16_t u16;
|
---|
116 | uint32_t u32;
|
---|
117 | uint64_t u64;
|
---|
118 | } u;
|
---|
119 | uint8_t cb;
|
---|
120 | } PCIRAWMEMLOC;
|
---|
121 |
|
---|
122 | /** Parameters buffer for PCIRAWR0_DO_MMIO_WRITE call. */
|
---|
123 | typedef struct
|
---|
124 | {
|
---|
125 | /* in */
|
---|
126 | RTGCPHYS Address;
|
---|
127 | PCIRAWMEMLOC Value;
|
---|
128 | } PCIRAWREQMMIOWRITE;
|
---|
129 |
|
---|
130 | /** Parameters buffer for PCIRAWR0_DO_MMIO_READ call. */
|
---|
131 | typedef struct
|
---|
132 | {
|
---|
133 | /* in */
|
---|
134 | RTGCPHYS Address;
|
---|
135 | /* inout (Value.cb is in) */
|
---|
136 | PCIRAWMEMLOC Value;
|
---|
137 | } PCIRAWREQMMIOREAD;
|
---|
138 |
|
---|
139 | /* Parameters buffer for PCIRAWR0_DO_PCICFG_WRITE call. */
|
---|
140 | typedef struct
|
---|
141 | {
|
---|
142 | /* in */
|
---|
143 | uint32_t iOffset;
|
---|
144 | PCIRAWMEMLOC Value;
|
---|
145 | } PCIRAWREQPCICFGWRITE;
|
---|
146 |
|
---|
147 | /** Parameters buffer for PCIRAWR0_DO_PCICFG_READ call. */
|
---|
148 | typedef struct
|
---|
149 | {
|
---|
150 | /* in */
|
---|
151 | uint32_t iOffset;
|
---|
152 | /* inout (Value.cb is in) */
|
---|
153 | PCIRAWMEMLOC Value;
|
---|
154 | } PCIRAWREQPCICFGREAD;
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Request buffer use for communication with the driver.
|
---|
158 | */
|
---|
159 | typedef struct PCIRAWSENDREQ
|
---|
160 | {
|
---|
161 | /** The request header. */
|
---|
162 | SUPVMMR0REQHDR Hdr;
|
---|
163 | /** Alternative to passing the taking the session from the VM handle.
|
---|
164 | * Either use this member or use the VM handle, don't do both.
|
---|
165 | */
|
---|
166 | PSUPDRVSESSION pSession;
|
---|
167 | /** Request type. */
|
---|
168 | int32_t iRequest;
|
---|
169 | /** Host device request targetted to. */
|
---|
170 | PCIRAWDEVHANDLE TargetDevice;
|
---|
171 | /** Call parameters. */
|
---|
172 | union
|
---|
173 | {
|
---|
174 | PCIRAWREQOPENDEVICE aOpenDevice;
|
---|
175 | PCIRAWREQCLOSEDEVICE aCloseDevice;
|
---|
176 | PCIRAWREQGETREGIONINFO aGetRegionInfo;
|
---|
177 | PCIRAWREQMAPREGION aMapRegion;
|
---|
178 | PCIRAWREQUNMAPREGION aUnmapRegion;
|
---|
179 | PCIRAWREQPIOWRITE aPioWrite;
|
---|
180 | PCIRAWREQPIOREAD aPioRead;
|
---|
181 | PCIRAWREQMMIOWRITE aMmioWrite;
|
---|
182 | PCIRAWREQMMIOREAD aMmioRead;
|
---|
183 | PCIRAWREQPCICFGWRITE aPciCfgWrite;
|
---|
184 | PCIRAWREQPCICFGREAD aPciCfgRead;
|
---|
185 | } u;
|
---|
186 | } PCIRAWSENDREQ;
|
---|
187 | typedef PCIRAWSENDREQ *PPCIRAWSENDREQ;
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Operations performed by the driver.
|
---|
191 | */
|
---|
192 | typedef enum PCIRAWR0OPERATION
|
---|
193 | {
|
---|
194 | /* Open device. */
|
---|
195 | PCIRAWR0_DO_OPEN_DEVICE,
|
---|
196 | /* Close device. */
|
---|
197 | PCIRAWR0_DO_CLOSE_DEVICE,
|
---|
198 | /* Get PCI region info. */
|
---|
199 | PCIRAWR0_DO_GET_REGION_INFO,
|
---|
200 | /* Map PCI region into VM address space. */
|
---|
201 | PCIRAWR0_DO_MAP_REGION,
|
---|
202 | /* Unmap PCI region from VM address space. */
|
---|
203 | PCIRAWR0_DO_UNMAP_REGION,
|
---|
204 | /* Perform PIO write. */
|
---|
205 | PCIRAWR0_DO_PIO_WRITE,
|
---|
206 | /* Perform PIO read. */
|
---|
207 | PCIRAWR0_DO_PIO_READ,
|
---|
208 | /* Perform MMIO write. */
|
---|
209 | PCIRAWR0_DO_MMIO_WRITE,
|
---|
210 | /* Perform MMIO read. */
|
---|
211 | PCIRAWR0_DO_MMIO_READ,
|
---|
212 | /* Perform PCI config write. */
|
---|
213 | PCIRAWR0_DO_PCICFG_WRITE,
|
---|
214 | /* Perform PCI config read. */
|
---|
215 | PCIRAWR0_DO_PCICFG_READ,
|
---|
216 | /** The usual 32-bit type blow up. */
|
---|
217 | PCIRAWR0_DO_32BIT_HACK = 0x7fffffff
|
---|
218 | } PCIRAWR0OPERATION;
|
---|
219 |
|
---|
220 | /** Forward declarations. */
|
---|
221 | typedef struct RAWPCIFACTORY *PRAWPCIFACTORY;
|
---|
222 | typedef struct RAWPCIDEVPORT *PRAWPCIDEVPORT;
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * This is the port on the device interface, i.e. the driver side which the
|
---|
226 | * host device is connected to.
|
---|
227 | *
|
---|
228 | * This is only used for the in-kernel PCI device connections.
|
---|
229 | */
|
---|
230 | typedef struct RAWPCIDEVPORT
|
---|
231 | {
|
---|
232 | /** Structure version number. (RAWPCIDEVPORT_VERSION) */
|
---|
233 | uint32_t u32Version;
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Retain the object.
|
---|
237 | *
|
---|
238 | * It will normally be called while owning the internal semaphore.
|
---|
239 | *
|
---|
240 | * @param pPort Pointer to this structure.
|
---|
241 | */
|
---|
242 | DECLR0CALLBACKMEMBER(void, pfnRetain,(PRAWPCIDEVPORT pPort));
|
---|
243 |
|
---|
244 | /**
|
---|
245 | * Releases the object.
|
---|
246 | *
|
---|
247 | * This must be called for every pfnRetain call.
|
---|
248 | *
|
---|
249 | *
|
---|
250 | * @param pPort Pointer to this structure.
|
---|
251 | */
|
---|
252 | DECLR0CALLBACKMEMBER(void, pfnRelease,(PRAWPCIDEVPORT pPort));
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * Init device.
|
---|
256 | *
|
---|
257 | * @param pPort Pointer to this structure.
|
---|
258 | * @param fFlags Initialization flags.
|
---|
259 | */
|
---|
260 | DECLR0CALLBACKMEMBER(int, pfnInit,(PRAWPCIDEVPORT pPort,
|
---|
261 | uint32_t fFlags));
|
---|
262 |
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Deinit device.
|
---|
266 | *
|
---|
267 | * @param pPort Pointer to this structure.
|
---|
268 | * @param fFlags Initialization flags.
|
---|
269 | */
|
---|
270 | DECLR0CALLBACKMEMBER(int, pfnDeinit,(PRAWPCIDEVPORT pPort,
|
---|
271 | uint32_t fFlags));
|
---|
272 |
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Get PCI region info.
|
---|
276 | *
|
---|
277 | * @param pPort Pointer to this structure.
|
---|
278 | */
|
---|
279 | DECLR0CALLBACKMEMBER(int, pfnGetRegionInfo,(PRAWPCIDEVPORT pPort,
|
---|
280 | int32_t iRegion,
|
---|
281 | RTHCPHYS *pRegionStart,
|
---|
282 | uint64_t *pu64RegionSize,
|
---|
283 | bool *pfPresent,
|
---|
284 | bool *pfMmio));
|
---|
285 |
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * Map PCI region.
|
---|
289 | *
|
---|
290 | * @param pPort Pointer to this structure.
|
---|
291 | */
|
---|
292 | DECLR0CALLBACKMEMBER(int, pfnMapRegion,(PRAWPCIDEVPORT pPort,
|
---|
293 | int32_t iRegion,
|
---|
294 | RTHCPHYS pRegionStart,
|
---|
295 | uint64_t u64RegionSize,
|
---|
296 | RTR0PTR *pRegionBase));
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * Read device PCI register.
|
---|
300 | *
|
---|
301 | * @param pPort Pointer to this structure.
|
---|
302 | * @param fFlags Initialization flags.
|
---|
303 | */
|
---|
304 | DECLR0CALLBACKMEMBER(int, pfnPciCfgRead,(PRAWPCIDEVPORT pPort,
|
---|
305 | uint32_t Register,
|
---|
306 | PCIRAWMEMLOC *pValue));
|
---|
307 |
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Write device PCI register.
|
---|
311 | *
|
---|
312 | * @param pPort Pointer to this structure.
|
---|
313 | * @param fFlags Initialization flags.
|
---|
314 | */
|
---|
315 | DECLR0CALLBACKMEMBER(int, pfnPciCfgWrite,(PRAWPCIDEVPORT pPort,
|
---|
316 | uint32_t Register,
|
---|
317 | PCIRAWMEMLOC *pValue));
|
---|
318 |
|
---|
319 | /** Structure version number. (RAWPCIDEVPORT_VERSION) */
|
---|
320 | uint32_t u32VersionEnd;
|
---|
321 | } RAWPCIDEVPORT;
|
---|
322 | /** Version number for the RAWPCIDEVPORT::u32Version and RAWPCIIFPORT::u32VersionEnd fields. */
|
---|
323 | #define RAWPCIDEVPORT_VERSION UINT32_C(0xAFBDCC01)
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * The component factory interface for create a raw PCI interfaces.
|
---|
327 | */
|
---|
328 | typedef struct RAWPCIFACTORY
|
---|
329 | {
|
---|
330 | /**
|
---|
331 | * Release this factory.
|
---|
332 | *
|
---|
333 | * SUPR0ComponentQueryFactory (SUPDRVFACTORY::pfnQueryFactoryInterface to be precise)
|
---|
334 | * will retain a reference to the factory and the caller has to call this method to
|
---|
335 | * release it once the pfnCreateAndConnect call(s) has been done.
|
---|
336 | *
|
---|
337 | * @param pIfFactory Pointer to this structure.
|
---|
338 | */
|
---|
339 | DECLR0CALLBACKMEMBER(void, pfnRelease,(PRAWPCIFACTORY pFactory));
|
---|
340 |
|
---|
341 | /**
|
---|
342 | * Create an instance for the specfied host PCI card and connects it
|
---|
343 | * to the driver.
|
---|
344 | *
|
---|
345 | *
|
---|
346 | * @returns VBox status code.
|
---|
347 | *
|
---|
348 | * @param pIfFactory Pointer to this structure.
|
---|
349 | * @param u32HostAddress Address of PCI device on the host.
|
---|
350 | * @param fFlags Creation flags.
|
---|
351 | * @param ppDevPort Where to store the pointer to the device port
|
---|
352 | * on success.
|
---|
353 | *
|
---|
354 | */
|
---|
355 | DECLR0CALLBACKMEMBER(int, pfnCreateAndConnect,(PRAWPCIFACTORY pFactory,
|
---|
356 | uint32_t u32HostAddress,
|
---|
357 | uint32_t fFlags,
|
---|
358 | PRAWPCIDEVPORT *ppDevPort));
|
---|
359 |
|
---|
360 |
|
---|
361 | } RAWPCIFACTORY;
|
---|
362 |
|
---|
363 | #define RAWPCIFACTORY_UUID_STR "c0268f49-e1e4-402b-b7e0-eb8d09659a9b"
|
---|
364 |
|
---|
365 | RT_C_DECLS_END
|
---|
366 |
|
---|
367 | #endif
|
---|