VirtualBox

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

Last change on this file since 99196 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

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