1 | /** @file
|
---|
2 | * PDM - Pluggable Device Manager, raw PCI Devices. (VMM)
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2010-2017 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___VBox_vmm_pdmpci_h
|
---|
27 | #define ___VBox_vmm_pdmpci_h
|
---|
28 |
|
---|
29 | #include <VBox/types.h>
|
---|
30 | #include <VBox/rawpci.h>
|
---|
31 |
|
---|
32 | RT_C_DECLS_BEGIN
|
---|
33 |
|
---|
34 | /** @defgroup grp_pdm_pciraw The raw PCI Devices API
|
---|
35 | * @ingroup grp_pdm
|
---|
36 | * @{
|
---|
37 | */
|
---|
38 |
|
---|
39 | typedef struct PDMIPCIRAW *PPDMIPCIRAW;
|
---|
40 | typedef struct PDMIPCIRAW
|
---|
41 | {
|
---|
42 | /**
|
---|
43 | * Notify virtual device that interrupt has arrived.
|
---|
44 | * For this callback to be called, interface have to be
|
---|
45 | * registered with PDMIPCIRAWUP::pfnRegisterInterruptListener.
|
---|
46 | *
|
---|
47 | * @note no level parameter, as we can only support flip-flop.
|
---|
48 | *
|
---|
49 | * @param pInterface Pointer to this interface structure.
|
---|
50 | * @param iGuestIrq Guest interrupt number, passed earlier when registering listener.
|
---|
51 | *
|
---|
52 | * @thread Any thread.
|
---|
53 | */
|
---|
54 | DECLR3CALLBACKMEMBER(int, pfnInterruptRequest,(PPDMIPCIRAW pInterface, int32_t iGuestIrq));
|
---|
55 | } PDMIPCIRAW;
|
---|
56 |
|
---|
57 | typedef struct PDMIPCIRAWUP *PPDMIPCIRAWUP;
|
---|
58 | typedef struct PDMIPCIRAWUP
|
---|
59 | {
|
---|
60 | /**
|
---|
61 | * Host PCI MMIO access function.
|
---|
62 | */
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Request driver info about PCI region on host PCI device.
|
---|
66 | *
|
---|
67 | * @returns true, if region is present, and out parameters are correct
|
---|
68 | * @param pInterface Pointer to this interface structure.
|
---|
69 | * @param iRegion Region number.
|
---|
70 | * @param pGCPhysRegion Where to store region base address (guest).
|
---|
71 | * @param pcbRegion Where to store region size.
|
---|
72 | *
|
---|
73 | * @param pfFlags If region is MMIO or IO.
|
---|
74 | * @thread Any thread.
|
---|
75 | */
|
---|
76 | DECLR3CALLBACKMEMBER(bool, pfnGetRegionInfo, (PPDMIPCIRAWUP pInterface,
|
---|
77 | uint32_t iRegion,
|
---|
78 | RTGCPHYS *pGCPhysRegion,
|
---|
79 | uint64_t *pcbRegion,
|
---|
80 | uint32_t *pfFlags));
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Request driver to map part of host device's MMIO region to the VM process and maybe kernel.
|
---|
84 | * Shall only be issued within earlier obtained with pfnGetRegionInfo()
|
---|
85 | * host physical address ranges for the device BARs. Even if failed, device still may function
|
---|
86 | * using pfnMmio* and pfnPio* operations, just much slower.
|
---|
87 | *
|
---|
88 | * @returns status code
|
---|
89 | * @param pInterface Pointer to this interface structure.
|
---|
90 | * @param iRegion Number of the region.
|
---|
91 | * @param StartAddress Host physical address of start.
|
---|
92 | * @param cbRegion Size of the region.
|
---|
93 | * @param fFlags Flags, currently lowest significant bit set if R0 mapping requested too
|
---|
94 | * @param ppvAddressR3 Where to store mapped region address for R3 (can be 0, if cannot map into userland)
|
---|
95 | * @param ppvAddressR0 Where to store mapped region address for R0 (can be 0, if cannot map into kernel)
|
---|
96 | *
|
---|
97 | * @thread Any thread.
|
---|
98 | */
|
---|
99 | DECLR3CALLBACKMEMBER(int, pfnMapRegion, (PPDMIPCIRAWUP pInterface,
|
---|
100 | uint32_t iRegion,
|
---|
101 | RTHCPHYS StartAddress,
|
---|
102 | uint64_t cbRegion,
|
---|
103 | uint32_t fFlags,
|
---|
104 | PRTR3PTR ppvAddressR3,
|
---|
105 | PRTR0PTR ppvAddressR0));
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Request driver to unmap part of host device's MMIO region to the VM process.
|
---|
109 | * Shall only be issued with pointer earlier obtained with pfnMapRegion().
|
---|
110 | *
|
---|
111 | * @returns status code
|
---|
112 | * @param pInterface Pointer to this interface structure
|
---|
113 | * @param iRegion Number of the region.
|
---|
114 | * @param StartAddress Host physical address of start.
|
---|
115 | * @param cbRegion Size of the region.
|
---|
116 | * @param pvAddressR3 R3 address of mapped region.
|
---|
117 | * @param pvAddressR0 R0 address of mapped region.
|
---|
118 | *
|
---|
119 | * @thread Any thread.
|
---|
120 | */
|
---|
121 | DECLR3CALLBACKMEMBER(int, pfnUnmapRegion, (PPDMIPCIRAWUP pInterface,
|
---|
122 | uint32_t iRegion,
|
---|
123 | RTHCPHYS StartAddress,
|
---|
124 | uint64_t cbRegion,
|
---|
125 | RTR3PTR pvAddressR3,
|
---|
126 | RTR0PTR pvAddressR0));
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Request port IO write.
|
---|
130 | *
|
---|
131 | * @returns status code
|
---|
132 | * @param pInterface Pointer to this interface structure.
|
---|
133 | * @param uPort I/O port address.
|
---|
134 | * @param uValue Value to write.
|
---|
135 | * @param cb Access width.
|
---|
136 | *
|
---|
137 | * @thread EMT thread.
|
---|
138 | */
|
---|
139 | DECLR3CALLBACKMEMBER(int, pfnPioWrite, (PPDMIPCIRAWUP pInterface,
|
---|
140 | RTIOPORT uPort,
|
---|
141 | uint32_t uValue,
|
---|
142 | unsigned cb));
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Request port IO read.
|
---|
146 | *
|
---|
147 | * @returns status code
|
---|
148 | * @param pInterface Pointer to this interface structure.
|
---|
149 | * @param uPort I/O port address.
|
---|
150 | * @param puValue Place to store read value.
|
---|
151 | * @param cb Access width.
|
---|
152 | *
|
---|
153 | * @thread EMT thread.
|
---|
154 | */
|
---|
155 |
|
---|
156 | DECLR3CALLBACKMEMBER(int, pfnPioRead, (PPDMIPCIRAWUP pInterface,
|
---|
157 | RTIOPORT uPort,
|
---|
158 | uint32_t *puValue,
|
---|
159 | unsigned cb));
|
---|
160 |
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Request MMIO write. This callback is only called if driver wants to receive MMIO via
|
---|
164 | * pu32Flags argument of pfnPciDeviceConstructStart().
|
---|
165 | *
|
---|
166 | * @returns status code
|
---|
167 | * @param pInterface Pointer to this interface structure.
|
---|
168 | * @param Address Guest physical address.
|
---|
169 | * @todo Why is this documented as guest physical
|
---|
170 | * address and given a host ring-0 address type?
|
---|
171 | * @param pvValue Address of value to write.
|
---|
172 | * @param cb Access width.
|
---|
173 | *
|
---|
174 | * @thread EMT thread.
|
---|
175 | */
|
---|
176 | DECLR3CALLBACKMEMBER(int, pfnMmioWrite, (PPDMIPCIRAWUP pInterface,
|
---|
177 | RTR0PTR Address,
|
---|
178 | void const *pvValue,
|
---|
179 | unsigned cb));
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * Request MMIO read.
|
---|
183 | *
|
---|
184 | * @returns status code
|
---|
185 | * @param pInterface Pointer to this interface structure.
|
---|
186 | * @param Address Guest physical address.
|
---|
187 | * @todo Why is this documented as guest physical
|
---|
188 | * address and given a host ring-0 address type?
|
---|
189 | * @param pvValue Place to store read value.
|
---|
190 | * @param cb Access width.
|
---|
191 | *
|
---|
192 | * @thread EMT thread.
|
---|
193 | */
|
---|
194 |
|
---|
195 | DECLR3CALLBACKMEMBER(int, pfnMmioRead, (PPDMIPCIRAWUP pInterface,
|
---|
196 | RTR0PTR Address,
|
---|
197 | void *pvValue,
|
---|
198 | unsigned cb));
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Host PCI config space accessors.
|
---|
202 | */
|
---|
203 | /**
|
---|
204 | * Request driver to write value to host device's PCI config space.
|
---|
205 | * Host specific way (PIO or MCFG) is used to perform actual operation.
|
---|
206 | *
|
---|
207 | * @returns status code
|
---|
208 | * @param pInterface Pointer to this interface structure.
|
---|
209 | * @param offCfgSpace Offset in PCI config space.
|
---|
210 | * @param pvValue Value to write.
|
---|
211 | * @param cb Access width.
|
---|
212 | *
|
---|
213 | * @thread EMT thread.
|
---|
214 | */
|
---|
215 | DECLR3CALLBACKMEMBER(int, pfnPciCfgWrite, (PPDMIPCIRAWUP pInterface,
|
---|
216 | uint32_t offCfgSpace,
|
---|
217 | void *pvValue,
|
---|
218 | unsigned cb));
|
---|
219 | /**
|
---|
220 | * Request driver to read value from host device's PCI config space.
|
---|
221 | * Host specific way (PIO or MCFG) is used to perform actual operation.
|
---|
222 | *
|
---|
223 | * @returns status code
|
---|
224 | * @param pInterface Pointer to this interface structure.
|
---|
225 | * @param offCfgSpace Offset in PCI config space.
|
---|
226 | * @param pvValue Where to store read value.
|
---|
227 | * @param cb Access width.
|
---|
228 | *
|
---|
229 | * @thread EMT thread.
|
---|
230 | */
|
---|
231 | DECLR3CALLBACKMEMBER(int, pfnPciCfgRead, (PPDMIPCIRAWUP pInterface,
|
---|
232 | uint32_t offCfgSpace,
|
---|
233 | void *pvValue,
|
---|
234 | unsigned cb));
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Request to enable interrupt notifications. Please note that this is purely
|
---|
238 | * R3 interface, so it's up to implementor to perform necessary machinery
|
---|
239 | * for communications with host OS kernel driver. Typical implementation will start
|
---|
240 | * userland thread waiting on shared semaphore (such as using SUPSEMEVENT),
|
---|
241 | * notified by the kernel interrupt handler, and then will call
|
---|
242 | * upper port pfnInterruptRequest() based on data provided by the driver.
|
---|
243 | * This apporach is taken, as calling VBox code from an asyncronous R0
|
---|
244 | * interrupt handler when VMM may not be even running doesn't look
|
---|
245 | * like a good idea.
|
---|
246 | *
|
---|
247 | * @returns status code
|
---|
248 | * @param pInterface Pointer to this interface structure.
|
---|
249 | * @param uGuestIrq Guest IRQ to be passed to pfnInterruptRequest().
|
---|
250 | *
|
---|
251 | * @thread Any thread, pfnInterruptRequest() will be usually invoked on a dedicated thread.
|
---|
252 | */
|
---|
253 | DECLR3CALLBACKMEMBER(int, pfnEnableInterruptNotifications, (PPDMIPCIRAWUP pInterface, uint8_t uGuestIrq));
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Request to disable interrupt notifications.
|
---|
257 | *
|
---|
258 | * @returns status code
|
---|
259 | * @param pInterface Pointer to this interface structure.
|
---|
260 | *
|
---|
261 | * @thread Any thread.
|
---|
262 | */
|
---|
263 | DECLR3CALLBACKMEMBER(int, pfnDisableInterruptNotifications, (PPDMIPCIRAWUP pInterface));
|
---|
264 |
|
---|
265 | /** @name Notification APIs.
|
---|
266 | * @{
|
---|
267 | */
|
---|
268 |
|
---|
269 | /**
|
---|
270 | * Notify driver when raw PCI device construction starts.
|
---|
271 | *
|
---|
272 | * Have to be the first operation as initializes internal state and opens host
|
---|
273 | * device driver.
|
---|
274 | *
|
---|
275 | * @returns status code
|
---|
276 | * @param pInterface Pointer to this interface structure.
|
---|
277 | * @param uHostPciAddress Host PCI address of device attached.
|
---|
278 | * @param uGuestPciAddress Guest PCI address of device attached.
|
---|
279 | * @param pszDeviceName Human readable device name.
|
---|
280 | * @param fDeviceFlags Flags for the host device.
|
---|
281 | * @param pfFlags Flags for virtual device, from the upper driver.
|
---|
282 | *
|
---|
283 | * @thread Any thread.
|
---|
284 | */
|
---|
285 | DECLR3CALLBACKMEMBER(int, pfnPciDeviceConstructStart, (PPDMIPCIRAWUP pInterface,
|
---|
286 | uint32_t uHostPciAddress,
|
---|
287 | uint32_t uGuestPciAddress,
|
---|
288 | const char *pszDeviceName,
|
---|
289 | uint32_t fDeviceFlags,
|
---|
290 | uint32_t *pfFlags));
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Notify driver when raw PCI device construction completes, so that it may
|
---|
294 | * perform further actions depending on success or failure of this operation.
|
---|
295 | * Standard action is to raise global IHostPciDevicePlugEvent.
|
---|
296 | *
|
---|
297 | * @param pInterface Pointer to this interface structure.
|
---|
298 | * @param rc Result code of the operation.
|
---|
299 | *
|
---|
300 | * @thread Any thread.
|
---|
301 | */
|
---|
302 | DECLR3CALLBACKMEMBER(void, pfnPciDeviceConstructComplete, (PPDMIPCIRAWUP pInterface, int rc));
|
---|
303 |
|
---|
304 | /**
|
---|
305 | * Notify driver on finalization of raw PCI device.
|
---|
306 | *
|
---|
307 | * @param pInterface Pointer to this interface structure.
|
---|
308 | * @param fFlags Flags.
|
---|
309 | *
|
---|
310 | * @thread Any thread.
|
---|
311 | */
|
---|
312 | DECLR3CALLBACKMEMBER(int, pfnPciDeviceDestruct, (PPDMIPCIRAWUP pInterface, uint32_t fFlags));
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * Notify driver on guest power state change.
|
---|
316 | *
|
---|
317 | * @param pInterface Pointer to this interface structure.
|
---|
318 | * @param enmState New power state.
|
---|
319 | * @param pu64Param State-specific in/out parameter. For now only used during power-on to provide VM caps.
|
---|
320 | *
|
---|
321 | * @thread Any thread.
|
---|
322 | */
|
---|
323 | DECLR3CALLBACKMEMBER(int, pfnPciDevicePowerStateChange, (PPDMIPCIRAWUP pInterface,
|
---|
324 | PCIRAWPOWERSTATE enmState,
|
---|
325 | uint64_t *pu64Param));
|
---|
326 |
|
---|
327 | /**
|
---|
328 | * Notify driver about runtime error.
|
---|
329 | *
|
---|
330 | * @param pInterface Pointer to this interface structure.
|
---|
331 | * @param fFatal If error is fatal.
|
---|
332 | * @param pszErrorId Error ID.
|
---|
333 | * @param pszMessage Error message.
|
---|
334 | *
|
---|
335 | * @thread Any thread.
|
---|
336 | */
|
---|
337 | DECLR3CALLBACKMEMBER(int, pfnReportRuntimeError, (PPDMIPCIRAWUP pInterface,
|
---|
338 | bool fFatal,
|
---|
339 | const char *pszErrorId,
|
---|
340 | const char *pszMessage));
|
---|
341 | /** @} */
|
---|
342 | } PDMIPCIRAWUP;
|
---|
343 |
|
---|
344 | /**
|
---|
345 | * Init R0 PCI module.
|
---|
346 | */
|
---|
347 | PCIRAWR0DECL(int) PciRawR0Init(void);
|
---|
348 | /**
|
---|
349 | * Process request (in R0).
|
---|
350 | */
|
---|
351 | PCIRAWR0DECL(int) PciRawR0ProcessReq(PGVM pGVM, PVM pVM, PSUPDRVSESSION pSession, PPCIRAWSENDREQ pReq);
|
---|
352 | /**
|
---|
353 | * Terminate R0 PCI module.
|
---|
354 | */
|
---|
355 | PCIRAWR0DECL(void) PciRawR0Term(void);
|
---|
356 |
|
---|
357 | /**
|
---|
358 | * Per-VM R0 module init.
|
---|
359 | */
|
---|
360 | PCIRAWR0DECL(int) PciRawR0InitVM(PGVM pGVM, PVM pVM);
|
---|
361 |
|
---|
362 | /**
|
---|
363 | * Per-VM R0 module termination routine.
|
---|
364 | */
|
---|
365 | PCIRAWR0DECL(void) PciRawR0TermVM(PGVM pGVM, PVM pVM);
|
---|
366 |
|
---|
367 | /**
|
---|
368 | * Flags returned by pfnPciDeviceConstructStart(), to notify device
|
---|
369 | * how it shall handle device IO traffic.
|
---|
370 | */
|
---|
371 | typedef enum PCIRAWDEVICEFLAGS
|
---|
372 | {
|
---|
373 | /** Intercept port IO (R3 PIO always go to the driver). */
|
---|
374 | PCIRAWRFLAG_CAPTURE_PIO = (1 << 0),
|
---|
375 | /** Intercept MMIO. */
|
---|
376 | PCIRAWRFLAG_CAPTURE_MMIO = (1 << 1),
|
---|
377 | /** Allow bus mastering by physical device (requires IOMMU). */
|
---|
378 | PCIRAWRFLAG_ALLOW_BM = (1 << 2),
|
---|
379 | /** Allow R3 MMIO mapping. */
|
---|
380 | PCIRAWRFLAG_ALLOW_R3MAP = (1 << 3),
|
---|
381 |
|
---|
382 | /** The usual 32-bit type blow up. */
|
---|
383 | PCIRAWRFLAG_32BIT_HACK = 0x7fffffff
|
---|
384 | } PCIRAWDEVICEFLAGS;
|
---|
385 |
|
---|
386 | #define PDMIPCIRAWUP_IID "06daa17f-097b-4ebe-a626-15f467b1de12"
|
---|
387 | #define PDMIPCIRAW_IID "68c6e4c4-4223-47e0-9134-e3c297992543"
|
---|
388 |
|
---|
389 | /** @} */
|
---|
390 |
|
---|
391 | RT_C_DECLS_END
|
---|
392 |
|
---|
393 | #endif
|
---|