1 | /* $Id: VBoxPciInternal.h 36484 2011-03-31 16:09:17Z 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 | //# ifdef DEBUG_nike
|
---|
30 | # define VBOX_WITH_IOMMU
|
---|
31 | //# endif
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #ifdef VBOX_WITH_IOMMU
|
---|
35 | #include <linux/errno.h>
|
---|
36 | #include <linux/iommu.h>
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | RT_C_DECLS_BEGIN
|
---|
42 |
|
---|
43 | /* Forward declaration. */
|
---|
44 | typedef struct VBOXRAWPCIGLOBALS *PVBOXRAWPCIGLOBALS;
|
---|
45 | typedef struct VBOXRAWPCIDRVVM *PVBOXRAWPCIDRVVM;
|
---|
46 | typedef struct VBOXRAWPCIINS *PVBOXRAWPCIINS;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * The per-instance data of the VBox raw PCI interface.
|
---|
50 | *
|
---|
51 | * This is data associated with a host PCI card attached to the VM.
|
---|
52 | *
|
---|
53 | */
|
---|
54 | typedef struct VBOXRAWPCIINS
|
---|
55 | {
|
---|
56 | /** Pointer to the globals. */
|
---|
57 | PVBOXRAWPCIGLOBALS pGlobals;
|
---|
58 |
|
---|
59 | /** Mutex protecting device access. */
|
---|
60 | RTSEMFASTMUTEX hFastMtx;
|
---|
61 | /** The spinlock protecting the state variables and device access. */
|
---|
62 | RTSPINLOCK hSpinlock;
|
---|
63 | /** Pointer to the next device in the list. */
|
---|
64 | PVBOXRAWPCIINS pNext;
|
---|
65 | /** Reference count. */
|
---|
66 | uint32_t volatile cRefs;
|
---|
67 |
|
---|
68 | /* Host PCI address of this device. */
|
---|
69 | uint32_t HostPciAddress;
|
---|
70 |
|
---|
71 | #ifdef RT_OS_LINUX
|
---|
72 | struct pci_dev * pPciDev;
|
---|
73 | #endif
|
---|
74 | bool fMsiUsed;
|
---|
75 | bool fMsixUsed;
|
---|
76 | bool fIommuUsed;
|
---|
77 | bool fPad0;
|
---|
78 |
|
---|
79 | /** Temporary: host IRQ we were given. Assumes single IRQ devices. */
|
---|
80 | int32_t iHostIrq;
|
---|
81 |
|
---|
82 | /** Port, given to the outside world. */
|
---|
83 | RAWPCIDEVPORT DevPort;
|
---|
84 |
|
---|
85 | uint32_t cHandlersCount;
|
---|
86 | PFNRAWPCIISR pfnIrqHandler;
|
---|
87 | void *pIrqContext;
|
---|
88 |
|
---|
89 | PRAWPCIPERVM pVmCtx;
|
---|
90 | } VBOXRAWPCIINS;
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Per-VM data of the VBox PCI driver. Pointed to by pGVM->rawpci.s.pDriverData.
|
---|
94 | *
|
---|
95 | */
|
---|
96 | typedef struct VBOXRAWPCIDRVVM
|
---|
97 | {
|
---|
98 | /** Mutex protecting state changes. */
|
---|
99 | RTSEMFASTMUTEX hFastMtx;
|
---|
100 |
|
---|
101 | #ifdef RT_OS_LINUX
|
---|
102 | # ifdef VBOX_WITH_IOMMU
|
---|
103 | /* IOMMU domain. */
|
---|
104 | struct iommu_domain* pIommuDomain;
|
---|
105 | # endif
|
---|
106 | #endif
|
---|
107 | /* Back pointer to pGVM->rawpci.s. */
|
---|
108 | PRAWPCIPERVM pPerVmData;
|
---|
109 | } VBOXRAWPCIDRVVM;
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * The global data of the VBox PCI driver.
|
---|
113 | *
|
---|
114 | * This contains the bit required for communicating with support driver, VBoxDrv
|
---|
115 | * (start out as SupDrv).
|
---|
116 | */
|
---|
117 | typedef struct VBOXRAWPCIGLOBALS
|
---|
118 | {
|
---|
119 | /** Mutex protecting the list of instances and state changes. */
|
---|
120 | RTSEMFASTMUTEX hFastMtx;
|
---|
121 |
|
---|
122 | /** Pointer to a list of instance data. */
|
---|
123 | PVBOXRAWPCIINS pInstanceHead;
|
---|
124 |
|
---|
125 | /** The raw PCI interface factory. */
|
---|
126 | RAWPCIFACTORY RawPciFactory;
|
---|
127 | /** The SUPDRV component factory registration. */
|
---|
128 | SUPDRVFACTORY SupDrvFactory;
|
---|
129 | /** The number of current factory references. */
|
---|
130 | int32_t volatile cFactoryRefs;
|
---|
131 | /** Whether the IDC connection is open or not.
|
---|
132 | * This is only for cleaning up correctly after the separate IDC init on Windows. */
|
---|
133 | bool fIDCOpen;
|
---|
134 | /** The SUPDRV IDC handle (opaque struct). */
|
---|
135 | SUPDRVIDCHANDLE SupDrvIDC;
|
---|
136 | #ifdef RT_OS_LINUX
|
---|
137 | struct module * pciStubModule;
|
---|
138 | #endif
|
---|
139 | } VBOXRAWPCIGLOBALS;
|
---|
140 |
|
---|
141 | DECLHIDDEN(int) vboxPciInit(PVBOXRAWPCIGLOBALS pGlobals);
|
---|
142 | DECLHIDDEN(void) vboxPciShutdown(PVBOXRAWPCIGLOBALS pGlobals);
|
---|
143 |
|
---|
144 | DECLHIDDEN(int) vboxPciOsInitVm(PVBOXRAWPCIDRVVM pThis, PVM pVM, PRAWPCIPERVM pVmData);
|
---|
145 | DECLHIDDEN(void) vboxPciOsDeinitVm(PVBOXRAWPCIDRVVM pThis, PVM pVM);
|
---|
146 |
|
---|
147 | DECLHIDDEN(int) vboxPciOsDevInit (PVBOXRAWPCIINS pIns, uint32_t fFlags);
|
---|
148 | DECLHIDDEN(int) vboxPciOsDevDeinit(PVBOXRAWPCIINS pIns, uint32_t fFlags);
|
---|
149 | DECLHIDDEN(int) vboxPciOsDevDestroy(PVBOXRAWPCIINS pIns);
|
---|
150 |
|
---|
151 | DECLHIDDEN(int) vboxPciOsDevGetRegionInfo(PVBOXRAWPCIINS pIns,
|
---|
152 | int32_t iRegion,
|
---|
153 | RTHCPHYS *pRegionStart,
|
---|
154 | uint64_t *pu64RegionSize,
|
---|
155 | bool *pfPresent,
|
---|
156 | uint32_t *pfFlags);
|
---|
157 | DECLHIDDEN(int) vboxPciOsDevMapRegion(PVBOXRAWPCIINS pIns,
|
---|
158 | int32_t iRegion,
|
---|
159 | RTHCPHYS pRegionStart,
|
---|
160 | uint64_t u64RegionSize,
|
---|
161 | uint32_t fFlags,
|
---|
162 | RTR0PTR *pRegionBase);
|
---|
163 | DECLHIDDEN(int) vboxPciOsDevUnmapRegion(PVBOXRAWPCIINS pIns,
|
---|
164 | int32_t iRegion,
|
---|
165 | RTHCPHYS RegionStart,
|
---|
166 | uint64_t u64RegionSize,
|
---|
167 | RTR0PTR RegionBase);
|
---|
168 |
|
---|
169 | DECLHIDDEN(int) vboxPciOsDevPciCfgWrite(PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
|
---|
170 | DECLHIDDEN(int) vboxPciOsDevPciCfgRead (PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
|
---|
171 |
|
---|
172 | DECLHIDDEN(int) vboxPciOsDevRegisterIrqHandler (PVBOXRAWPCIINS pIns, PFNRAWPCIISR pfnHandler, void* pIrqContext, int32_t *piHostIrq);
|
---|
173 | DECLHIDDEN(int) vboxPciOsDevUnregisterIrqHandler(PVBOXRAWPCIINS pIns, int32_t iHostIrq);
|
---|
174 |
|
---|
175 | DECLHIDDEN(int) vboxPciOsDevPowerStateChange(PVBOXRAWPCIINS pIns, PCIRAWPOWERSTATE aState);
|
---|
176 |
|
---|
177 | #define VBOX_DRV_VMDATA(pIns) ((PVBOXRAWPCIDRVVM)(pIns->pVmCtx ? pIns->pVmCtx->pDriverData : NULL))
|
---|
178 |
|
---|
179 | RT_C_DECLS_END
|
---|
180 |
|
---|
181 | #endif
|
---|