VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxPci/VBoxPciInternal.h@ 78395

Last change on this file since 78395 was 76568, checked in by vboxsync, 6 years ago

HostDrivers: Use VBOX_INCLUDED_SRC_ as header guard prefix with scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: VBoxPciInternal.h 76568 2019-01-01 04:34:11Z vboxsync $ */
2/** @file
3 * VBoxPci - PCI driver (Host), Internal Header.
4 */
5
6/*
7 * Copyright (C) 2011-2019 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 LINUX_VERSION_CODE >= KERNEL_VERSION(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
51RT_C_DECLS_BEGIN
52
53/* Forward declaration. */
54typedef struct VBOXRAWPCIGLOBALS *PVBOXRAWPCIGLOBALS;
55typedef struct VBOXRAWPCIDRVVM *PVBOXRAWPCIDRVVM;
56typedef struct VBOXRAWPCIINS *PVBOXRAWPCIINS;
57
58typedef struct VBOXRAWPCIISRDESC
59{
60 /** Handler function. */
61 PFNRAWPCIISR pfnIrqHandler;
62 /** Handler context. */
63 void *pIrqContext;
64 /** Host IRQ. */
65 int32_t iHostIrq;
66} VBOXRAWPCIISRDESC;
67typedef 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 */
75typedef 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 */
117typedef 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 */
138typedef 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
163DECLHIDDEN(int) vboxPciInit(PVBOXRAWPCIGLOBALS pGlobals);
164DECLHIDDEN(void) vboxPciShutdown(PVBOXRAWPCIGLOBALS pGlobals);
165
166DECLHIDDEN(int) vboxPciOsInitVm(PVBOXRAWPCIDRVVM pThis, PVM pVM, PRAWPCIPERVM pVmData);
167DECLHIDDEN(void) vboxPciOsDeinitVm(PVBOXRAWPCIDRVVM pThis, PVM pVM);
168
169DECLHIDDEN(int) vboxPciOsDevInit (PVBOXRAWPCIINS pIns, uint32_t fFlags);
170DECLHIDDEN(int) vboxPciOsDevDeinit(PVBOXRAWPCIINS pIns, uint32_t fFlags);
171DECLHIDDEN(int) vboxPciOsDevDestroy(PVBOXRAWPCIINS pIns);
172
173DECLHIDDEN(int) vboxPciOsDevGetRegionInfo(PVBOXRAWPCIINS pIns,
174 int32_t iRegion,
175 RTHCPHYS *pRegionStart,
176 uint64_t *pu64RegionSize,
177 bool *pfPresent,
178 uint32_t *pfFlags);
179DECLHIDDEN(int) vboxPciOsDevMapRegion(PVBOXRAWPCIINS pIns,
180 int32_t iRegion,
181 RTHCPHYS pRegionStart,
182 uint64_t u64RegionSize,
183 uint32_t fFlags,
184 RTR0PTR *pRegionBase);
185DECLHIDDEN(int) vboxPciOsDevUnmapRegion(PVBOXRAWPCIINS pIns,
186 int32_t iRegion,
187 RTHCPHYS RegionStart,
188 uint64_t u64RegionSize,
189 RTR0PTR RegionBase);
190
191DECLHIDDEN(int) vboxPciOsDevPciCfgWrite(PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
192DECLHIDDEN(int) vboxPciOsDevPciCfgRead (PVBOXRAWPCIINS pIns, uint32_t Register, PCIRAWMEMLOC *pValue);
193
194DECLHIDDEN(int) vboxPciOsDevRegisterIrqHandler (PVBOXRAWPCIINS pIns, PFNRAWPCIISR pfnHandler, void* pIrqContext, int32_t *piHostIrq);
195DECLHIDDEN(int) vboxPciOsDevUnregisterIrqHandler(PVBOXRAWPCIINS pIns, int32_t iHostIrq);
196
197DECLHIDDEN(int) vboxPciOsDevPowerStateChange(PVBOXRAWPCIINS pIns, PCIRAWPOWERSTATE aState);
198
199#define VBOX_DRV_VMDATA(pIns) ((PVBOXRAWPCIDRVVM)(pIns->pVmCtx ? pIns->pVmCtx->pDriverData : NULL))
200
201RT_C_DECLS_END
202
203#endif /* !VBOX_INCLUDED_SRC_VBoxPci_VBoxPciInternal_h */
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