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