VirtualBox

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

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

PCI: per-VM initialization (for IOMMU domains)

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

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