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 | /** Parameters buffer for PCIRAWR0_DO_GET_REGION_INFO call */
|
---|
35 | typedef struct
|
---|
36 | {
|
---|
37 | /* in */
|
---|
38 | int32_t iRegion;
|
---|
39 | /* out */
|
---|
40 | RTHCPHYS RegionStart;
|
---|
41 | uint64_t u64RegionSize;
|
---|
42 | bool fPresent;
|
---|
43 | bool fMmio;
|
---|
44 | } PCIRAWREQGETREGIONINFO;
|
---|
45 |
|
---|
46 | /** Parameters buffer for PCIRAWR0_DO_MAP_REGION call. */
|
---|
47 | typedef struct
|
---|
48 | {
|
---|
49 | /* in */
|
---|
50 | RTGCPHYS StartAddress;
|
---|
51 | uint64_t iRegionSize;
|
---|
52 | uint32_t fFlags;
|
---|
53 | /* out */
|
---|
54 | RTR3PTR pvAddressR3;
|
---|
55 | RTR0PTR pvAddressR0;
|
---|
56 | } PCIRAWREQMAPREGION;
|
---|
57 |
|
---|
58 | /** Parameters buffer for PCIRAWR0_DO_UNMAP_REGION call. */
|
---|
59 | typedef struct
|
---|
60 | {
|
---|
61 | /* in */
|
---|
62 | RTR3PTR pvAddressR3;
|
---|
63 | RTR0PTR pvAddressR0;
|
---|
64 | } PCIRAWREQUNMAPREGION;
|
---|
65 |
|
---|
66 | /** Parameters buffer for PCIRAWR0_DO_PIO_WRITE call. */
|
---|
67 | typedef struct
|
---|
68 | {
|
---|
69 | /* in */
|
---|
70 | uint16_t iPort;
|
---|
71 | uint16_t cb;
|
---|
72 | uint32_t iValue;
|
---|
73 | } PCIRAWREQPIOWRITE;
|
---|
74 |
|
---|
75 | /** Parameters buffer for PCIRAWR0_DO_PIO_READ call. */
|
---|
76 | typedef struct
|
---|
77 | {
|
---|
78 | /* in */
|
---|
79 | uint16_t iPort;
|
---|
80 | uint16_t cb;
|
---|
81 | /* out */
|
---|
82 | uint32_t iValue;
|
---|
83 | } PCIRAWREQPIOREAD;
|
---|
84 |
|
---|
85 | /** Memory operand. */
|
---|
86 | typedef struct
|
---|
87 | {
|
---|
88 | union
|
---|
89 | {
|
---|
90 | uint8_t u8;
|
---|
91 | uint16_t u16;
|
---|
92 | uint32_t u32;
|
---|
93 | uint64_t u64;
|
---|
94 | } u;
|
---|
95 | uint8_t cb;
|
---|
96 | } PCIRAWMEMLOC;
|
---|
97 |
|
---|
98 | /** Parameters buffer for PCIRAWR0_DO_MMIO_WRITE call. */
|
---|
99 | typedef struct
|
---|
100 | {
|
---|
101 | /* in */
|
---|
102 | RTGCPHYS Address;
|
---|
103 | PCIRAWMEMLOC Value;
|
---|
104 | } PCIRAWREQMMIOWRITE;
|
---|
105 |
|
---|
106 | /** Parameters buffer for PCIRAWR0_DO_MMIO_READ call. */
|
---|
107 | typedef struct
|
---|
108 | {
|
---|
109 | /* in */
|
---|
110 | RTGCPHYS Address;
|
---|
111 | /* inout (Value.cb is in) */
|
---|
112 | PCIRAWMEMLOC Value;
|
---|
113 | } PCIRAWREQMMIOREAD;
|
---|
114 |
|
---|
115 | /* Parameters buffer for PCIRAWR0_DO_PCICFG_WRITE call. */
|
---|
116 | typedef struct
|
---|
117 | {
|
---|
118 | /* in */
|
---|
119 | uint32_t iOffset;
|
---|
120 | PCIRAWMEMLOC Value;
|
---|
121 | } PCIRAWREQPCICFGWRITE;
|
---|
122 |
|
---|
123 | /** Parameters buffer for PCIRAWR0_DO_PCICFG_READ call. */
|
---|
124 | typedef struct
|
---|
125 | {
|
---|
126 | /* in */
|
---|
127 | uint32_t iOffset;
|
---|
128 | /* inout (Value.cb is in) */
|
---|
129 | PCIRAWMEMLOC Value;
|
---|
130 | } PCIRAWREQPCICFGREAD;
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Handle for the raw PCI device.
|
---|
135 | */
|
---|
136 | typedef RTR0PTR PCIRAWDEVHANDLE;
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Request buffer use for communication with the driver.
|
---|
140 | */
|
---|
141 | typedef struct PCIRAWSENDREQ
|
---|
142 | {
|
---|
143 | /** The request header. */
|
---|
144 | SUPVMMR0REQHDR Hdr;
|
---|
145 | /** Alternative to passing the taking the session from the VM handle.
|
---|
146 | * Either use this member or use the VM handle, don't do both.
|
---|
147 | */
|
---|
148 | PSUPDRVSESSION pSession;
|
---|
149 | /** Request type. */
|
---|
150 | int32_t iRequest;
|
---|
151 | /** Host device request targetted to. */
|
---|
152 | PCIRAWDEVHANDLE TargetDevice;
|
---|
153 | /** Call parameters. */
|
---|
154 | union
|
---|
155 | {
|
---|
156 | PCIRAWREQGETREGIONINFO aGetRegionInfo;
|
---|
157 | PCIRAWREQMAPREGION aMapRegion;
|
---|
158 | PCIRAWREQUNMAPREGION aUnmapRegion;
|
---|
159 | PCIRAWREQPIOWRITE aPioWrite;
|
---|
160 | PCIRAWREQPIOREAD aPioRead;
|
---|
161 | PCIRAWREQMMIOWRITE aMmioWrite;
|
---|
162 | PCIRAWREQMMIOREAD aMmioRead;
|
---|
163 | PCIRAWREQPCICFGWRITE aPciCfgWrite;
|
---|
164 | PCIRAWREQPCICFGREAD aPciCfgRead;
|
---|
165 | } u;
|
---|
166 | } PCIRAWSENDREQ;
|
---|
167 | typedef PCIRAWSENDREQ *PPCIRAWSENDREQ;
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Operations performed by the driver.
|
---|
171 | */
|
---|
172 | typedef enum PCIRAWR0OPERATION
|
---|
173 | {
|
---|
174 | /* Get PCI region info. */
|
---|
175 | PCIRAWR0_DO_GET_REGION_INFO,
|
---|
176 | /* Map PCI region into VM address space. */
|
---|
177 | PCIRAWR0_DO_MAP_REGION,
|
---|
178 | /* Unmap PCI region from VM address space. */
|
---|
179 | PCIRAWR0_DO_UNMAP_REGION,
|
---|
180 | /* Perform PIO write. */
|
---|
181 | PCIRAWR0_DO_PIO_WRITE,
|
---|
182 | /* Perform PIO read. */
|
---|
183 | PCIRAWR0_DO_PIO_READ,
|
---|
184 | /* Perform MMIO write. */
|
---|
185 | PCIRAWR0_DO_MMIO_WRITE,
|
---|
186 | /* Perform MMIO read. */
|
---|
187 | PCIRAWR0_DO_MMIO_READ,
|
---|
188 | /* Perform PCI config write. */
|
---|
189 | PCIRAWR0_DO_PCICFG_WRITE,
|
---|
190 | /* Perform PCI config read. */
|
---|
191 | PCIRAWR0_DO_PCICFG_READ,
|
---|
192 | /** The usual 32-bit type blow up. */
|
---|
193 | PCIRAWR0_DO_32BIT_HACK = 0x7fffffff
|
---|
194 | } PCIRAWR0OPERATION;
|
---|
195 |
|
---|
196 | /** Forward declarations. */
|
---|
197 | typedef struct RAWPCIFACTORY *PRAWPCIFACTORY;
|
---|
198 | typedef struct RAWPCIDEVPORT *PRAWPCIDEVPORT;
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * This is the port on the device interface, i.e. the driver side which the
|
---|
202 | * host device is connected to.
|
---|
203 | *
|
---|
204 | * This is only used for the in-kernel PCI device connections.
|
---|
205 | */
|
---|
206 | typedef struct RAWPCIDEVPORT
|
---|
207 | {
|
---|
208 | /** Structure version number. (RAWPCIDEVPORT_VERSION) */
|
---|
209 | uint32_t u32Version;
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Retain the object.
|
---|
213 | *
|
---|
214 | * It will normally be called while owning the internal semaphore.
|
---|
215 | *
|
---|
216 | * @param pPort Pointer to this structure.
|
---|
217 | */
|
---|
218 | DECLR0CALLBACKMEMBER(void, pfnRetain,(PRAWPCIDEVPORT pPort));
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * Releases the object.
|
---|
222 | *
|
---|
223 | * This must be called for every pfnRetain call.
|
---|
224 | *
|
---|
225 | *
|
---|
226 | * @param pPort Pointer to this structure.
|
---|
227 | */
|
---|
228 | DECLR0CALLBACKMEMBER(void, pfnRelease,(PRAWPCIDEVPORT pPort));
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Init device.
|
---|
232 | *
|
---|
233 | * @param pPort Pointer to this structure.
|
---|
234 | * @param fFlags Initialization flags.
|
---|
235 | */
|
---|
236 | DECLR0CALLBACKMEMBER(int, pfnInit,(PRAWPCIDEVPORT pPort,
|
---|
237 | uint32_t fFlags));
|
---|
238 |
|
---|
239 |
|
---|
240 |
|
---|
241 | /** Structure version number. (RAWPCIDEVPORT_VERSION) */
|
---|
242 | uint32_t u32VersionEnd;
|
---|
243 | } RAWPCIDEVPORT;
|
---|
244 | /** Version number for the RAWPCIDEVPORT::u32Version and RAWPCIIFPORT::u32VersionEnd fields. */
|
---|
245 | #define RAWPCIDEVPORT_VERSION UINT32_C(0xAFBDCC01)
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * The component factory interface for create a raw PCI interfaces.
|
---|
249 | */
|
---|
250 | typedef struct RAWPCIFACTORY
|
---|
251 | {
|
---|
252 | /**
|
---|
253 | * Release this factory.
|
---|
254 | *
|
---|
255 | * SUPR0ComponentQueryFactory (SUPDRVFACTORY::pfnQueryFactoryInterface to be precise)
|
---|
256 | * will retain a reference to the factory and the caller has to call this method to
|
---|
257 | * release it once the pfnCreateAndConnect call(s) has been done.
|
---|
258 | *
|
---|
259 | * @param pIfFactory Pointer to this structure.
|
---|
260 | */
|
---|
261 | DECLR0CALLBACKMEMBER(void, pfnRelease,(PRAWPCIFACTORY pFactory));
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * Create an instance for the specfied host PCI card and connects it
|
---|
265 | * to the driver.
|
---|
266 | *
|
---|
267 | *
|
---|
268 | * @returns VBox status code.
|
---|
269 | *
|
---|
270 | * @param pIfFactory Pointer to this structure.
|
---|
271 | * @param u32HostAddress Address of PCI device on the host.
|
---|
272 | * @param fFlags Creation flags.
|
---|
273 | * @param ppDevPort Where to store the pointer to the device port
|
---|
274 | * on success.
|
---|
275 | *
|
---|
276 | */
|
---|
277 | DECLR0CALLBACKMEMBER(int, pfnCreateAndConnect,(PRAWPCIFACTORY pFactory,
|
---|
278 | uint32_t u32HostAddress,
|
---|
279 | uint32_t fFlags,
|
---|
280 | PRAWPCIDEVPORT *ppDevPort));
|
---|
281 |
|
---|
282 |
|
---|
283 | } RAWPCIFACTORY;
|
---|
284 |
|
---|
285 | #define RAWPCIFACTORY_UUID_STR "c0268f49-e1e4-402b-b7e0-eb8d09659a9b"
|
---|
286 |
|
---|
287 | RT_C_DECLS_END
|
---|
288 |
|
---|
289 | #endif
|
---|