VirtualBox

source: vbox/trunk/include/VBox/rawpci.h@ 36153

Last change on this file since 36153 was 36153, checked in by vboxsync, 14 years ago

PCI: more raw and 64-bit BARs coding

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette