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