1 | /* $Id: VBoxPciInternal.h 37423 2011-06-12 18:37:56Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxPci - PCI driver (Host), Internal Header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___VBoPciInternal_h___
|
---|
19 | #define ___VBoxPciInternal_h___
|
---|
20 |
|
---|
21 | #include <VBox/sup.h>
|
---|
22 | #include <VBox/rawpci.h>
|
---|
23 | #include <iprt/semaphore.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 |
|
---|
26 | #ifdef RT_OS_LINUX
|
---|
27 |
|
---|
28 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
|
---|
29 | # define VBOX_WITH_IOMMU
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #ifdef VBOX_WITH_IOMMU
|
---|
33 | #include <linux/errno.h>
|
---|
34 | #include <linux/iommu.h>
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | RT_C_DECLS_BEGIN
|
---|
40 |
|
---|
41 | /* Forward declaration. */
|
---|
42 | typedef struct VBOXRAWPCIGLOBALS *PVBOXRAWPCIGLOBALS;
|
---|
43 | typedef struct VBOXRAWPCIDRVVM *PVBOXRAWPCIDRVVM;
|
---|
44 | typedef struct VBOXRAWPCIINS *PVBOXRAWPCIINS;
|
---|
45 |
|
---|
46 | typedef struct VBOXRAWPCIISRDESC
|
---|
47 | {
|
---|
48 | /** Handler function. */
|
---|
49 | PFNRAWPCIISR pfnIrqHandler;
|
---|
50 | /** Handler context. */
|
---|
51 | void *pIrqContext;
|
---|
52 | /** Host IRQ. */
|
---|
53 | int32_t iHostIrq;
|
---|
54 | } VBOXRAWPCIISRDESC;
|
---|
55 | typedef struct VBOXRAWPCIISRDESC *PVBOXRAWPCIISRDESC;
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * The per-instance data of the VBox raw PCI interface.
|
---|
59 | *
|
---|
60 | * This is data associated with a host PCI card attached to the VM.
|
---|
61 | *
|
---|
62 | */
|
---|
63 | typedef struct VBOXRAWPCIINS
|
---|
64 | {
|
---|
65 | /** Pointer to the globals. */
|
---|
66 | PVBOXRAWPCIGLOBALS pGlobals;
|
---|
67 |
|
---|
68 | /** Mutex protecting device access. */
|
---|
69 | RTSEMFASTMUTEX hFastMtx;
|
---|
70 | /** The spinlock protecting the state variables and device access. */
|
---|
71 | RTSPINLOCK hSpinlock;
|
---|
72 | /** Pointer to the next device in the list. */
|
---|
73 | PVBOXRAWPCIINS pNext;
|
---|
74 | /** Reference count. */
|
---|
75 | uint32_t volatile cRefs;
|
---|
76 |
|
---|
77 | /* Host PCI address of this device. */
|
---|
78 | uint32_t HostPciAddress;
|
---|
79 |
|
---|
80 | #ifdef RT_OS_LINUX
|
---|
81 | struct pci_dev * pPciDev;
|
---|
82 | char szPrevDriver[64];
|
---|
83 | #endif
|
---|
84 | bool fMsiUsed;
|
---|
85 | bool fMsixUsed;
|
---|
86 | bool fIommuUsed;
|
---|
87 | bool fPad0;
|
---|
88 |
|
---|
89 | /** Port, given to the outside world. */
|
---|
90 | RAWPCIDEVPORT DevPort;
|
---|
91 |
|
---|
92 | /** IRQ handler. */
|
---|
93 | VBOXRAWPCIISRDESC IrqHandler;
|
---|
94 |
|
---|
95 | /** Pointer to per-VM context in hypervisor data. */
|
---|
96 | PRAWPCIPERVM pVmCtx;
|
---|
97 | } VBOXRAWPCIINS;
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Per-VM data of the VBox PCI driver. Pointed to by pGVM->rawpci.s.pDriverData.
|
---|
101 | *
|
---|
102 | */
|
---|
103 | typedef struct VBOXRAWPCIDRVVM
|
---|
104 | {
|
---|
105 | /** Mutex protecting state changes. */
|
---|
106 | RTSEMFASTMUTEX hFastMtx;
|
---|
107 |
|
---|
108 | #ifdef RT_OS_LINUX
|
---|
109 | # ifdef VBOX_WITH_IOMMU
|
---|
110 | /* IOMMU domain. */
|
---|
111 | struct iommu_domain* pIommuDomain;
|
---|
112 | # endif
|
---|
113 | #endif
|
---|
114 | /* Back pointer to pGVM->rawpci.s. */
|
---|
115 | PRAWPCIPERVM pPerVmData;
|
---|
116 | } VBOXRAWPCIDRVVM;
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * The global data of the VBox PCI driver.
|
---|
120 | *
|
---|
121 | * This contains the bit required for communicating with support driver, VBoxDrv
|
---|
122 | * (start out as SupDrv).
|
---|
123 | */
|
---|
124 | typedef struct VBOXRAWPCIGLOBALS
|
---|
125 | {
|
---|
126 | /** Mutex protecting the list of instances and state changes. */
|
---|
127 | RTSEMFASTMUTEX hFastMtx;
|
---|
128 |
|
---|
129 | /** Pointer to a list of instance data. */
|
---|
130 | PVBOXRAWPCIINS pInstanceHead;
|
---|
131 |
|
---|
132 | /** The raw PCI interface factory. */
|
---|
133 | RAWPCIFACTORY RawPciFactory;
|
---|
134 | /** The SUPDRV component factory registration. */
|
---|
135 | SUPDRVFACTORY SupDrvFactory;
|
---|
136 | /** The number of current factory references. */
|
---|
137 | int32_t volatile cFactoryRefs;
|
---|
138 | /** Whether the IDC connection is open or not.
|
---|
139 | * This is only for cleaning up correctly after the separate IDC init on Windows. */
|
---|
140 | bool fIDCOpen;
|
---|
141 | /** The SUPDRV IDC handle (opaque struct). */
|
---|
142 | SUPDRVIDCHANDLE SupDrvIDC;
|
---|
143 | #ifdef RT_OS_LINUX
|
---|
144 | bool fPciStubModuleAvail;
|
---|
145 | struct module * pciStubModule;
|
---|
146 | #endif
|
---|
147 | } VBOXRAWPCIGLOBALS;
|
---|
148 |
|
---|
149 | DECLHIDDEN(int) vboxPciInit(PVBOXRAWPCIGLOBALS pGlobals);
|
---|
150 | DECLHIDDEN(void) vboxPciShutdown(PVBOXRAWPCIGLOBALS pGlobals);
|
---|
151 |
|
---|
152 | DECLHIDDEN(int) vboxPciOsInitVm(PVBOXRAWPCIDRVVM pThis, PVM pVM, PRAWPCIPERVM pVmData);
|
---|
153 | DECLHIDDEN(void) vboxPciOsDeinitVm(PVBOXRAWPCIDRVVM pThis, PVM pVM);
|
---|
154 |
|
---|
155 | DECLHIDDEN(int) vboxPciOsDevInit (PVBOXRAWPCIINS pIns, uint32_t fFlags);
|
---|
156 | DECLHIDDEN(int) vboxPciOsDevDeinit(PVBOXRAWPCIINS pIns, uint32_t fFlags);
|
---|
157 | DECLHIDDEN(int) vboxPciOsDevDestroy(PVBOXRAWPCIINS pIns);
|
---|
158 |
|
---|
159 | DECLHIDDEN(int) vboxPciOsDevGetRegionInfo(PVBOXRAWPCIINS pIns,
|
---|
160 | int32_t iRegion,
|
---|
161 | RTHCPHYS *pRegionStart,
|
---|
162 | uint64_t *pu64RegionSize,
|
---|
163 | bool *pfPresent,
|
---|
164 | uint32_t *pfFlags);
|
---|
165 | DECLHIDDEN(int) vboxPciOsDevMapRegion(PVBOXRAWPCIINS pIns,
|
---|
166 | int32_t iRegion,
|
---|
167 | RTHCPHYS pRegionStart,
|
---|
168 | uint64_t u64RegionSize,
|
---|
169 | uint32_t fFlags,
|
---|
170 | RTR0PTR *pRegionBase);
|
---|
171 | DECLHIDDEN(int) vboxPciOsDevUnmapRegion(PVBOXRAWPCIINS pIns,
|
---|
172 | int32_t iRegion,
|
---|
173 | RTHCPHYS RegionStart,
|
---|
174 | uint64_t u64RegionSize,
|
---|
175 | RTR0PTR RegionBase);
|
---|
176 |
|
---|
177 | DECLHIDDEN(int) vboxPciOsDevPciCfgWrite(PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
|
---|
178 | DECLHIDDEN(int) vboxPciOsDevPciCfgRead (PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
|
---|
179 |
|
---|
180 | DECLHIDDEN(int) vboxPciOsDevRegisterIrqHandler (PVBOXRAWPCIINS pIns, PFNRAWPCIISR pfnHandler, void* pIrqContext, int32_t *piHostIrq);
|
---|
181 | DECLHIDDEN(int) vboxPciOsDevUnregisterIrqHandler(PVBOXRAWPCIINS pIns, int32_t iHostIrq);
|
---|
182 |
|
---|
183 | DECLHIDDEN(int) vboxPciOsDevPowerStateChange(PVBOXRAWPCIINS pIns, PCIRAWPOWERSTATE aState);
|
---|
184 |
|
---|
185 | #define VBOX_DRV_VMDATA(pIns) ((PVBOXRAWPCIDRVVM)(pIns->pVmCtx ? pIns->pVmCtx->pDriverData : NULL))
|
---|
186 |
|
---|
187 | RT_C_DECLS_END
|
---|
188 |
|
---|
189 | #endif
|
---|