VirtualBox

source: vbox/trunk/src/VBox/VMM/include/PDMInternal.h@ 99208

Last change on this file since 99208 was 98570, checked in by vboxsync, 21 months ago

VMM/PDMQueue: Use the ListCritSect to relax ring-3 queue creation and destruction restrictions, to avoid annoying assertions (audio driver destruction). bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 76.2 KB
Line 
1/* $Id: PDMInternal.h 98570 2023-02-14 21:33:06Z vboxsync $ */
2/** @file
3 * PDM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-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 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef VMM_INCLUDED_SRC_include_PDMInternal_h
29#define VMM_INCLUDED_SRC_include_PDMInternal_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <VBox/types.h>
35#include <VBox/param.h>
36#include <VBox/vmm/cfgm.h>
37#include <VBox/vmm/stam.h>
38#include <VBox/vusb.h>
39#include <VBox/vmm/iom.h>
40#include <VBox/vmm/pdmasynccompletion.h>
41#ifdef VBOX_WITH_NETSHAPER
42# include <VBox/vmm/pdmnetshaper.h>
43#endif
44#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
45# include <VBox/vmm/pdmasynccompletion.h>
46#endif
47#include <VBox/vmm/pdmblkcache.h>
48#include <VBox/vmm/pdmcommon.h>
49#include <VBox/vmm/pdmtask.h>
50#include <VBox/sup.h>
51#include <VBox/msi.h>
52#include <iprt/assert.h>
53#include <iprt/critsect.h>
54#ifdef IN_RING3
55# include <iprt/thread.h>
56#endif
57
58RT_C_DECLS_BEGIN
59
60
61/** @defgroup grp_pdm_int Internal
62 * @ingroup grp_pdm
63 * @internal
64 * @{
65 */
66
67/** @def PDM_WITH_R3R0_CRIT_SECT
68 * Enables or disabled ring-3/ring-0 critical sections. */
69#if defined(DOXYGEN_RUNNING) || 1
70# define PDM_WITH_R3R0_CRIT_SECT
71#endif
72
73/** @def PDMCRITSECT_STRICT
74 * Enables/disables PDM critsect strictness like deadlock detection. */
75#if (defined(RT_LOCK_STRICT) && defined(IN_RING3) && !defined(PDMCRITSECT_STRICT)) \
76 || defined(DOXYGEN_RUNNING)
77# define PDMCRITSECT_STRICT
78#endif
79
80/** @def PDMCRITSECT_STRICT
81 * Enables/disables PDM read/write critsect strictness like deadlock
82 * detection. */
83#if (defined(RT_LOCK_STRICT) && defined(IN_RING3) && !defined(PDMCRITSECTRW_STRICT)) \
84 || defined(DOXYGEN_RUNNING)
85# define PDMCRITSECTRW_STRICT
86#endif
87
88/** The maximum device instance (total) size, ring-0/raw-mode capable devices. */
89#define PDM_MAX_DEVICE_INSTANCE_SIZE _4M
90/** The maximum device instance (total) size, ring-3 only devices. */
91#define PDM_MAX_DEVICE_INSTANCE_SIZE_R3 _8M
92/** The maximum size for the DBGF tracing tracking structure allocated for each device. */
93#define PDM_MAX_DEVICE_DBGF_TRACING_TRACK HOST_PAGE_SIZE
94
95
96
97/*******************************************************************************
98* Structures and Typedefs *
99*******************************************************************************/
100
101/** Pointer to a PDM Device. */
102typedef struct PDMDEV *PPDMDEV;
103/** Pointer to a pointer to a PDM Device. */
104typedef PPDMDEV *PPPDMDEV;
105
106/** Pointer to a PDM USB Device. */
107typedef struct PDMUSB *PPDMUSB;
108/** Pointer to a pointer to a PDM USB Device. */
109typedef PPDMUSB *PPPDMUSB;
110
111/** Pointer to a PDM Driver. */
112typedef struct PDMDRV *PPDMDRV;
113/** Pointer to a pointer to a PDM Driver. */
114typedef PPDMDRV *PPPDMDRV;
115
116/** Pointer to a PDM Logical Unit. */
117typedef struct PDMLUN *PPDMLUN;
118/** Pointer to a pointer to a PDM Logical Unit. */
119typedef PPDMLUN *PPPDMLUN;
120
121/** Pointer to a DMAC instance. */
122typedef struct PDMDMAC *PPDMDMAC;
123/** Pointer to a RTC instance. */
124typedef struct PDMRTC *PPDMRTC;
125
126/** Pointer to an USB HUB registration record. */
127typedef struct PDMUSBHUB *PPDMUSBHUB;
128
129/**
130 * Supported asynchronous completion endpoint classes.
131 */
132typedef enum PDMASYNCCOMPLETIONEPCLASSTYPE
133{
134 /** File class. */
135 PDMASYNCCOMPLETIONEPCLASSTYPE_FILE = 0,
136 /** Number of supported classes. */
137 PDMASYNCCOMPLETIONEPCLASSTYPE_MAX,
138 /** 32bit hack. */
139 PDMASYNCCOMPLETIONEPCLASSTYPE_32BIT_HACK = 0x7fffffff
140} PDMASYNCCOMPLETIONEPCLASSTYPE;
141
142
143/**
144 * MMIO/IO port registration tracking structure for DBGF tracing.
145 */
146typedef struct PDMDEVINSDBGFTRACK
147{
148 /** Flag whether this tracks a IO port or MMIO registration. */
149 bool fMmio;
150 /** Opaque user data passed during registration. */
151 void *pvUser;
152 /** Type dependent data. */
153 union
154 {
155 /** I/O port registration. */
156 struct
157 {
158 /** IOM I/O port handle. */
159 IOMIOPORTHANDLE hIoPorts;
160 /** Original OUT handler of the device. */
161 PFNIOMIOPORTNEWOUT pfnOut;
162 /** Original IN handler of the device. */
163 PFNIOMIOPORTNEWIN pfnIn;
164 /** Original string OUT handler of the device. */
165 PFNIOMIOPORTNEWOUTSTRING pfnOutStr;
166 /** Original string IN handler of the device. */
167 PFNIOMIOPORTNEWINSTRING pfnInStr;
168 } IoPort;
169 /** MMIO registration. */
170 struct
171 {
172 /** IOM MMIO region handle. */
173 IOMMMIOHANDLE hMmioRegion;
174 /** Original MMIO write handler of the device. */
175 PFNIOMMMIONEWWRITE pfnWrite;
176 /** Original MMIO read handler of the device. */
177 PFNIOMMMIONEWREAD pfnRead;
178 /** Original MMIO fill handler of the device. */
179 PFNIOMMMIONEWFILL pfnFill;
180 } Mmio;
181 } u;
182} PDMDEVINSDBGFTRACK;
183/** Pointer to a MMIO/IO port registration tracking structure. */
184typedef PDMDEVINSDBGFTRACK *PPDMDEVINSDBGFTRACK;
185/** Pointer to a const MMIO/IO port registration tracking structure. */
186typedef const PDMDEVINSDBGFTRACK *PCPDMDEVINSDBGFTRACK;
187
188
189/**
190 * Private device instance data, ring-3.
191 */
192typedef struct PDMDEVINSINTR3
193{
194 /** Pointer to the next instance.
195 * (Head is pointed to by PDM::pDevInstances.) */
196 R3PTRTYPE(PPDMDEVINS) pNextR3;
197 /** Pointer to the next per device instance.
198 * (Head is pointed to by PDMDEV::pInstances.) */
199 R3PTRTYPE(PPDMDEVINS) pPerDeviceNextR3;
200 /** Pointer to device structure. */
201 R3PTRTYPE(PPDMDEV) pDevR3;
202 /** Pointer to the list of logical units associated with the device. (FIFO) */
203 R3PTRTYPE(PPDMLUN) pLunsR3;
204 /** Pointer to the asynchronous notification callback set while in
205 * FNPDMDEVSUSPEND or FNPDMDEVPOWEROFF. */
206 R3PTRTYPE(PFNPDMDEVASYNCNOTIFY) pfnAsyncNotify;
207 /** Configuration handle to the instance node. */
208 R3PTRTYPE(PCFGMNODE) pCfgHandle;
209
210 /** R3 pointer to the VM this instance was created for. */
211 PVMR3 pVMR3;
212 /** DBGF trace event source handle if tracing is configured. */
213 DBGFTRACEREVTSRC hDbgfTraceEvtSrc;
214 /** Pointer to the base of the page containing the DBGF tracing tracking structures. */
215 PPDMDEVINSDBGFTRACK paDbgfTraceTrack;
216 /** Index of the next entry to use for tracking. */
217 uint32_t idxDbgfTraceTrackNext;
218 /** Maximum number of records fitting into the single page. */
219 uint32_t cDbgfTraceTrackMax;
220
221 /** Flags, see PDMDEVINSINT_FLAGS_XXX. */
222 uint32_t fIntFlags;
223 /** The last IRQ tag (for tracing it thru clearing). */
224 uint32_t uLastIrqTag;
225 /** The ring-0 device index (for making ring-0 calls). */
226 uint32_t idxR0Device;
227} PDMDEVINSINTR3;
228
229
230/**
231 * Private device instance data, ring-0.
232 */
233typedef struct PDMDEVINSINTR0
234{
235 /** Pointer to the VM this instance was created for. */
236 R0PTRTYPE(PGVM) pGVM;
237 /** Pointer to device structure. */
238 R0PTRTYPE(struct PDMDEVREGR0 const *) pRegR0;
239 /** The ring-0 module reference. */
240 RTR0PTR hMod;
241 /** Pointer to the ring-0 mapping of the ring-3 internal data (for uLastIrqTag). */
242 R0PTRTYPE(PDMDEVINSINTR3 *) pIntR3R0;
243 /** Pointer to the ring-0 mapping of the ring-3 instance (for idTracing). */
244 R0PTRTYPE(struct PDMDEVINSR3 *) pInsR3R0;
245 /** DBGF trace event source handle if tracing is configured. */
246 DBGFTRACEREVTSRC hDbgfTraceEvtSrc;
247 /** The device instance memory. */
248 RTR0MEMOBJ hMemObj;
249 /** The ring-3 mapping object. */
250 RTR0MEMOBJ hMapObj;
251 /** The page memory object for tracking MMIO and I/O port registrations when tracing is configured. */
252 RTR0MEMOBJ hDbgfTraceObj;
253 /** Pointer to the base of the page containing the DBGF tracing tracking structures. */
254 PPDMDEVINSDBGFTRACK paDbgfTraceTrack;
255 /** Index of the next entry to use for tracking. */
256 uint32_t idxDbgfTraceTrackNext;
257 /** Maximum number of records fitting into the single page. */
258 uint32_t cDbgfTraceTrackMax;
259 /** Index into PDMR0PERVM::apDevInstances. */
260 uint32_t idxR0Device;
261} PDMDEVINSINTR0;
262
263
264/**
265 * Private device instance data, raw-mode
266 */
267typedef struct PDMDEVINSINTRC
268{
269 /** Pointer to the VM this instance was created for. */
270 RGPTRTYPE(PVM) pVMRC;
271} PDMDEVINSINTRC;
272
273
274/**
275 * Private device instance data.
276 */
277typedef struct PDMDEVINSINT
278{
279 /** Pointer to the next instance (HC Ptr).
280 * (Head is pointed to by PDM::pDevInstances.) */
281 R3PTRTYPE(PPDMDEVINS) pNextR3;
282 /** Pointer to the next per device instance (HC Ptr).
283 * (Head is pointed to by PDMDEV::pInstances.) */
284 R3PTRTYPE(PPDMDEVINS) pPerDeviceNextR3;
285 /** Pointer to device structure - HC Ptr. */
286 R3PTRTYPE(PPDMDEV) pDevR3;
287 /** Pointer to the list of logical units associated with the device. (FIFO) */
288 R3PTRTYPE(PPDMLUN) pLunsR3;
289 /** Pointer to the asynchronous notification callback set while in
290 * FNPDMDEVSUSPEND or FNPDMDEVPOWEROFF. */
291 R3PTRTYPE(PFNPDMDEVASYNCNOTIFY) pfnAsyncNotify;
292 /** Configuration handle to the instance node. */
293 R3PTRTYPE(PCFGMNODE) pCfgHandle;
294
295 /** R3 pointer to the VM this instance was created for. */
296 PVMR3 pVMR3;
297
298 /** R0 pointer to the VM this instance was created for. */
299 R0PTRTYPE(PVMCC) pVMR0;
300
301 /** RC pointer to the VM this instance was created for. */
302 PVMRC pVMRC;
303
304 /** Flags, see PDMDEVINSINT_FLAGS_XXX. */
305 uint32_t fIntFlags;
306 /** The last IRQ tag (for tracing it thru clearing). */
307 uint32_t uLastIrqTag;
308} PDMDEVINSINT;
309
310/** @name PDMDEVINSINT::fIntFlags
311 * @{ */
312/** Used by pdmR3Load to mark device instances it found in the saved state. */
313#define PDMDEVINSINT_FLAGS_FOUND RT_BIT_32(0)
314/** Indicates that the device hasn't been powered on or resumed.
315 * This is used by PDMR3PowerOn, PDMR3Resume, PDMR3Suspend and PDMR3PowerOff
316 * to make sure each device gets exactly one notification for each of those
317 * events. PDMR3Resume and PDMR3PowerOn also makes use of it to bail out on
318 * a failure (already resumed/powered-on devices are suspended).
319 * PDMR3PowerOff resets this flag once before going through the devices to make sure
320 * every device gets the power off notification even if it was suspended before with
321 * PDMR3Suspend.
322 */
323#define PDMDEVINSINT_FLAGS_SUSPENDED RT_BIT_32(1)
324/** Indicates that the device has been reset already. Used by PDMR3Reset. */
325#define PDMDEVINSINT_FLAGS_RESET RT_BIT_32(2)
326#define PDMDEVINSINT_FLAGS_R0_ENABLED RT_BIT_32(3)
327#define PDMDEVINSINT_FLAGS_RC_ENABLED RT_BIT_32(4)
328/** Set if we've called the ring-0 constructor. */
329#define PDMDEVINSINT_FLAGS_R0_CONTRUCT RT_BIT_32(5)
330/** Set if using non-default critical section. */
331#define PDMDEVINSINT_FLAGS_CHANGED_CRITSECT RT_BIT_32(6)
332/** @} */
333
334
335/**
336 * Private USB device instance data.
337 */
338typedef struct PDMUSBINSINT
339{
340 /** The UUID of this instance. */
341 RTUUID Uuid;
342 /** Pointer to the next instance.
343 * (Head is pointed to by PDM::pUsbInstances.) */
344 R3PTRTYPE(PPDMUSBINS) pNext;
345 /** Pointer to the next per USB device instance.
346 * (Head is pointed to by PDMUSB::pInstances.) */
347 R3PTRTYPE(PPDMUSBINS) pPerDeviceNext;
348
349 /** Pointer to device structure. */
350 R3PTRTYPE(PPDMUSB) pUsbDev;
351
352 /** Pointer to the VM this instance was created for. */
353 PVMR3 pVM;
354 /** Pointer to the list of logical units associated with the device. (FIFO) */
355 R3PTRTYPE(PPDMLUN) pLuns;
356 /** The per instance device configuration. */
357 R3PTRTYPE(PCFGMNODE) pCfg;
358 /** Same as pCfg if the configuration should be deleted when detaching the device. */
359 R3PTRTYPE(PCFGMNODE) pCfgDelete;
360 /** The global device configuration. */
361 R3PTRTYPE(PCFGMNODE) pCfgGlobal;
362
363 /** Pointer to the USB hub this device is attached to.
364 * This is NULL if the device isn't connected to any HUB. */
365 R3PTRTYPE(PPDMUSBHUB) pHub;
366 /** The port number that we're connected to. */
367 uint32_t iPort;
368 /** Indicates that the USB device hasn't been powered on or resumed.
369 * See PDMDEVINSINT_FLAGS_SUSPENDED.
370 * @note Runtime attached USB devices gets a pfnHotPlugged callback rather than
371 * a pfnVMResume one. */
372 bool fVMSuspended;
373 /** Indicates that the USB device has been reset. */
374 bool fVMReset;
375 /** Pointer to the asynchronous notification callback set while in
376 * FNPDMDEVSUSPEND or FNPDMDEVPOWEROFF. */
377 R3PTRTYPE(PFNPDMUSBASYNCNOTIFY) pfnAsyncNotify;
378} PDMUSBINSINT;
379
380
381/**
382 * Private driver instance data.
383 */
384typedef struct PDMDRVINSINT
385{
386 /** Pointer to the driver instance above.
387 * This is NULL for the topmost drive. */
388 R3PTRTYPE(PPDMDRVINS) pUp;
389 /** Pointer to the driver instance below.
390 * This is NULL for the bottommost driver. */
391 R3PTRTYPE(PPDMDRVINS) pDown;
392 /** Pointer to the logical unit this driver chained on. */
393 R3PTRTYPE(PPDMLUN) pLun;
394 /** Pointer to driver structure from which this was instantiated. */
395 R3PTRTYPE(PPDMDRV) pDrv;
396 /** Pointer to the VM this instance was created for, ring-3 context. */
397 PVMR3 pVMR3;
398 /** Pointer to the VM this instance was created for, ring-0 context. */
399 R0PTRTYPE(PVMCC) pVMR0;
400 /** Pointer to the VM this instance was created for, raw-mode context. */
401 PVMRC pVMRC;
402 /** Flag indicating that the driver is being detached and destroyed.
403 * (Helps detect potential recursive detaching.) */
404 bool fDetaching;
405 /** Indicates that the driver hasn't been powered on or resumed.
406 * See PDMDEVINSINT_FLAGS_SUSPENDED. */
407 bool fVMSuspended;
408 /** Indicates that the driver has been reset already. */
409 bool fVMReset;
410 /** Set if allocated on the hyper heap, false if on the ring-3 heap. */
411 bool fHyperHeap;
412 /** Pointer to the asynchronous notification callback set while in
413 * PDMUSBREG::pfnVMSuspend or PDMUSBREG::pfnVMPowerOff. */
414 R3PTRTYPE(PFNPDMDRVASYNCNOTIFY) pfnAsyncNotify;
415 /** Configuration handle to the instance node. */
416 R3PTRTYPE(PCFGMNODE) pCfgHandle;
417 /** Pointer to the ring-0 request handler function. */
418 PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0;
419} PDMDRVINSINT;
420
421
422/**
423 * Private critical section data.
424 */
425typedef struct PDMCRITSECTINT
426{
427 /** The critical section core which is shared with IPRT.
428 * @note The semaphore is a SUPSEMEVENT. */
429 RTCRITSECT Core;
430 /** Pointer to the next critical section.
431 * This chain is used for device cleanup and the dbgf info item. */
432 R3PTRTYPE(struct PDMCRITSECTINT *) pNext;
433 /** Owner identifier.
434 * This is pDevIns if the owner is a device. Similarly for a driver or service.
435 * PDMR3CritSectInit() sets this to point to the critsect itself. */
436 RTR3PTR pvKey;
437 /** Set if this critical section is the automatically created default
438 * section of a device. */
439 bool fAutomaticDefaultCritsect;
440 /** Set if the critical section is used by a timer or similar.
441 * See PDMR3DevGetCritSect. */
442 bool fUsedByTimerOrSimilar;
443 /** Alignment padding. */
444 bool afPadding[2+4];
445 /** Support driver event semaphore that is scheduled to be signaled upon leaving
446 * the critical section. This is only for Ring-3 and Ring-0. */
447 SUPSEMEVENT volatile hEventToSignal;
448 /** The lock name. */
449 R3PTRTYPE(const char *) pszName;
450 /** The ring-3 pointer to this critical section, for leave queueing. */
451 R3PTRTYPE(PPDMCRITSECT) pSelfR3;
452 /** R0/RC lock contention. */
453 STAMCOUNTER StatContentionRZLock;
454 /** R0/RC lock contention: returning rcBusy or VERR_SEM_BUSY (try). */
455 STAMCOUNTER StatContentionRZLockBusy;
456 /** R0/RC lock contention: Profiling waiting time. */
457 STAMPROFILE StatContentionRZWait;
458 /** R0/RC unlock contention. */
459 STAMCOUNTER StatContentionRZUnlock;
460 /** R3 lock contention. */
461 STAMCOUNTER StatContentionR3;
462 /** R3 lock contention: Profiling waiting time. */
463 STAMPROFILE StatContentionR3Wait;
464 /** Profiling the time the section is locked. */
465 STAMPROFILEADV StatLocked;
466} PDMCRITSECTINT;
467AssertCompileMemberAlignment(PDMCRITSECTINT, StatContentionRZLock, 8);
468/** Pointer to private critical section data. */
469typedef PDMCRITSECTINT *PPDMCRITSECTINT;
470
471/** Special magic value set when we failed to abort entering in ring-0 due to a
472 * timeout, interruption or pending thread termination. */
473#define PDMCRITSECT_MAGIC_FAILED_ABORT UINT32_C(0x0bad0326)
474/** Special magic value set if we detected data/state corruption. */
475#define PDMCRITSECT_MAGIC_CORRUPTED UINT32_C(0x0bad2603)
476
477/** Indicates that the critical section is queued for unlock.
478 * PDMCritSectIsOwner and PDMCritSectIsOwned optimizations. */
479#define PDMCRITSECT_FLAGS_PENDING_UNLOCK RT_BIT_32(17)
480
481
482/**
483 * Private critical section data.
484 */
485typedef struct PDMCRITSECTRWINT
486{
487 /** The read/write critical section core which is shared with IPRT.
488 * @note The semaphores are SUPSEMEVENT and SUPSEMEVENTMULTI. */
489 RTCRITSECTRW Core;
490
491 /** Pointer to the next critical section.
492 * This chain is used for device cleanup and the dbgf info item. */
493 R3PTRTYPE(struct PDMCRITSECTRWINT *) pNext;
494 /** Self pointer. */
495 R3PTRTYPE(PPDMCRITSECTRW) pSelfR3;
496 /** Owner identifier.
497 * This is pDevIns if the owner is a device. Similarly for a driver or service.
498 * PDMR3CritSectRwInit() sets this to point to the critsect itself. */
499 RTR3PTR pvKey;
500 /** The lock name. */
501 R3PTRTYPE(const char *) pszName;
502
503 /** R0/RC write lock contention. */
504 STAMCOUNTER StatContentionRZEnterExcl;
505 /** R0/RC write unlock contention. */
506 STAMCOUNTER StatContentionRZLeaveExcl;
507 /** R0/RC read lock contention. */
508 STAMCOUNTER StatContentionRZEnterShared;
509 /** R0/RC read unlock contention. */
510 STAMCOUNTER StatContentionRZLeaveShared;
511 /** R0/RC writes. */
512 STAMCOUNTER StatRZEnterExcl;
513 /** R0/RC reads. */
514 STAMCOUNTER StatRZEnterShared;
515 /** R3 write lock contention. */
516 STAMCOUNTER StatContentionR3EnterExcl;
517 /** R3 write unlock contention. */
518 STAMCOUNTER StatContentionR3LeaveExcl;
519 /** R3 read lock contention. */
520 STAMCOUNTER StatContentionR3EnterShared;
521 /** R3 writes. */
522 STAMCOUNTER StatR3EnterExcl;
523 /** R3 reads. */
524 STAMCOUNTER StatR3EnterShared;
525 /** Profiling the time the section is write locked. */
526 STAMPROFILEADV StatWriteLocked;
527} PDMCRITSECTRWINT;
528AssertCompileMemberAlignment(PDMCRITSECTRWINT, StatContentionRZEnterExcl, 8);
529AssertCompileMemberAlignment(PDMCRITSECTRWINT, Core.u, 16);
530AssertCompileMemberAlignment(PDMCRITSECTRWINT, Core.u.s.u64State, 8);
531/** Pointer to private critical section data. */
532typedef PDMCRITSECTRWINT *PPDMCRITSECTRWINT;
533
534/** Special magic value we set the structure has become corrupted. */
535#define PDMCRITSECTRW_MAGIC_CORRUPT UINT32_C(0x0bad0620)
536
537
538/**
539 * The usual device/driver/internal/external stuff.
540 */
541typedef enum
542{
543 /** The usual invalid entry. */
544 PDMTHREADTYPE_INVALID = 0,
545 /** Device type. */
546 PDMTHREADTYPE_DEVICE,
547 /** USB Device type. */
548 PDMTHREADTYPE_USB,
549 /** Driver type. */
550 PDMTHREADTYPE_DRIVER,
551 /** Internal type. */
552 PDMTHREADTYPE_INTERNAL,
553 /** External type. */
554 PDMTHREADTYPE_EXTERNAL,
555 /** The usual 32-bit hack. */
556 PDMTHREADTYPE_32BIT_HACK = 0x7fffffff
557} PDMTHREADTYPE;
558
559
560/**
561 * The internal structure for the thread.
562 */
563typedef struct PDMTHREADINT
564{
565 /** The VM pointer. */
566 PVMR3 pVM;
567 /** The event semaphore the thread blocks on when not running. */
568 RTSEMEVENTMULTI BlockEvent;
569 /** The event semaphore the thread sleeps on while running. */
570 RTSEMEVENTMULTI SleepEvent;
571 /** Pointer to the next thread. */
572 R3PTRTYPE(struct PDMTHREAD *) pNext;
573 /** The thread type. */
574 PDMTHREADTYPE enmType;
575} PDMTHREADINT;
576
577
578
579/* Must be included after PDMDEVINSINT is defined. */
580#define PDMDEVINSINT_DECLARED
581#define PDMUSBINSINT_DECLARED
582#define PDMDRVINSINT_DECLARED
583#define PDMCRITSECTINT_DECLARED
584#define PDMCRITSECTRWINT_DECLARED
585#define PDMTHREADINT_DECLARED
586#ifdef ___VBox_pdm_h
587# error "Invalid header PDM order. Include PDMInternal.h before VBox/vmm/pdm.h!"
588#endif
589RT_C_DECLS_END
590#include <VBox/vmm/pdm.h>
591RT_C_DECLS_BEGIN
592
593/**
594 * PDM Logical Unit.
595 *
596 * This typically the representation of a physical port on a
597 * device, like for instance the PS/2 keyboard port on the
598 * keyboard controller device. The LUNs are chained on the
599 * device they belong to (PDMDEVINSINT::pLunsR3).
600 */
601typedef struct PDMLUN
602{
603 /** The LUN - The Logical Unit Number. */
604 RTUINT iLun;
605 /** Pointer to the next LUN. */
606 PPDMLUN pNext;
607 /** Pointer to the top driver in the driver chain. */
608 PPDMDRVINS pTop;
609 /** Pointer to the bottom driver in the driver chain. */
610 PPDMDRVINS pBottom;
611 /** Pointer to the device instance which the LUN belongs to.
612 * Either this is set or pUsbIns is set. Both is never set at the same time. */
613 PPDMDEVINS pDevIns;
614 /** Pointer to the USB device instance which the LUN belongs to. */
615 PPDMUSBINS pUsbIns;
616 /** Pointer to the device base interface. */
617 PPDMIBASE pBase;
618 /** Description of this LUN. */
619 const char *pszDesc;
620} PDMLUN;
621
622
623/**
624 * PDM Device, ring-3.
625 */
626typedef struct PDMDEV
627{
628 /** Pointer to the next device (R3 Ptr). */
629 R3PTRTYPE(PPDMDEV) pNext;
630 /** Device name length. (search optimization) */
631 uint32_t cchName;
632 /** Registration structure. */
633 R3PTRTYPE(const struct PDMDEVREGR3 *) pReg;
634 /** Number of instances. */
635 uint32_t cInstances;
636 /** Pointer to chain of instances (R3 Ptr). */
637 PPDMDEVINSR3 pInstances;
638 /** The search path for raw-mode context modules (';' as separator). */
639 char *pszRCSearchPath;
640 /** The search path for ring-0 context modules (';' as separator). */
641 char *pszR0SearchPath;
642} PDMDEV;
643
644
645#if 0
646/**
647 * PDM Device, ring-0.
648 */
649typedef struct PDMDEVR0
650{
651 /** Pointer to the next device. */
652 R0PTRTYPE(PPDMDEVR0) pNext;
653 /** Device name length. (search optimization) */
654 uint32_t cchName;
655 /** Registration structure. */
656 R3PTRTYPE(const struct PDMDEVREGR0 *) pReg;
657 /** Number of instances. */
658 uint32_t cInstances;
659 /** Pointer to chain of instances. */
660 PPDMDEVINSR0 pInstances;
661} PDMDEVR0;
662#endif
663
664
665/**
666 * PDM USB Device.
667 */
668typedef struct PDMUSB
669{
670 /** Pointer to the next device (R3 Ptr). */
671 R3PTRTYPE(PPDMUSB) pNext;
672 /** Device name length. (search optimization) */
673 RTUINT cchName;
674 /** Registration structure. */
675 R3PTRTYPE(const struct PDMUSBREG *) pReg;
676 /** Next instance number. */
677 uint32_t iNextInstance;
678 /** Pointer to chain of instances (R3 Ptr). */
679 R3PTRTYPE(PPDMUSBINS) pInstances;
680} PDMUSB;
681
682
683/**
684 * PDM Driver.
685 */
686typedef struct PDMDRV
687{
688 /** Pointer to the next device. */
689 PPDMDRV pNext;
690 /** Registration structure. */
691 const struct PDMDRVREG * pReg;
692 /** Current number of instances. */
693 uint32_t cInstances;
694 /** The next instance number. */
695 uint32_t iNextInstance;
696 /** The search path for raw-mode context modules (';' as separator). */
697 char *pszRCSearchPath;
698 /** The search path for ring-0 context modules (';' as separator). */
699 char *pszR0SearchPath;
700} PDMDRV;
701
702
703/**
704 * PDM IOMMU, shared ring-3.
705 */
706typedef struct PDMIOMMUR3
707{
708 /** IOMMU index. */
709 uint32_t idxIommu;
710 uint32_t uPadding0; /**< Alignment padding.*/
711
712 /** Pointer to the IOMMU device instance - R3. */
713 PPDMDEVINSR3 pDevInsR3;
714 /** @copydoc PDMIOMMUREGR3::pfnMemAccess */
715 DECLR3CALLBACKMEMBER(int, pfnMemAccess,(PPDMDEVINS pDevIns, uint16_t idDevice, uint64_t uIova, size_t cbIova,
716 uint32_t fFlags, PRTGCPHYS pGCPhysSpa, size_t *pcbContig));
717 /** @copydoc PDMIOMMUREGR3::pfnMemBulkAccess */
718 DECLR3CALLBACKMEMBER(int, pfnMemBulkAccess,(PPDMDEVINS pDevIns, uint16_t idDevice, size_t cIovas, uint64_t const *pauIovas,
719 uint32_t fFlags, PRTGCPHYS paGCPhysSpa));
720 /** @copydoc PDMIOMMUREGR3::pfnMsiRemap */
721 DECLR3CALLBACKMEMBER(int, pfnMsiRemap,(PPDMDEVINS pDevIns, uint16_t idDevice, PCMSIMSG pMsiIn, PMSIMSG pMsiOut));
722} PDMIOMMUR3;
723/** Pointer to a PDM IOMMU instance. */
724typedef PDMIOMMUR3 *PPDMIOMMUR3;
725/** Pointer to a const PDM IOMMU instance. */
726typedef const PDMIOMMUR3 *PCPDMIOMMUR3;
727
728
729/**
730 * PDM IOMMU, ring-0.
731 */
732typedef struct PDMIOMMUR0
733{
734 /** IOMMU index. */
735 uint32_t idxIommu;
736 uint32_t uPadding0; /**< Alignment padding.*/
737
738 /** Pointer to IOMMU device instance. */
739 PPDMDEVINSR0 pDevInsR0;
740 /** @copydoc PDMIOMMUREGR3::pfnMemAccess */
741 DECLR0CALLBACKMEMBER(int, pfnMemAccess,(PPDMDEVINS pDevIns, uint16_t idDevice, uint64_t uIova, size_t cbIova,
742 uint32_t fFlags, PRTGCPHYS pGCPhysSpa, size_t *pcbContig));
743 /** @copydoc PDMIOMMUREGR3::pfnMemBulkAccess */
744 DECLR0CALLBACKMEMBER(int, pfnMemBulkAccess,(PPDMDEVINS pDevIns, uint16_t idDevice, size_t cIovas, uint64_t const *pauIovas,
745 uint32_t fFlags, PRTGCPHYS paGCPhysSpa));
746 /** @copydoc PDMIOMMUREGR3::pfnMsiRemap */
747 DECLR0CALLBACKMEMBER(int, pfnMsiRemap,(PPDMDEVINS pDevIns, uint16_t idDevice, PCMSIMSG pMsiIn, PMSIMSG pMsiOut));
748} PDMIOMMUR0;
749/** Pointer to a ring-0 IOMMU data. */
750typedef PDMIOMMUR0 *PPDMIOMMUR0;
751/** Pointer to a const ring-0 IOMMU data. */
752typedef const PDMIOMMUR0 *PCPDMIOMMUR0;
753
754/** Pointer to a PDM IOMMU for the current context. */
755#ifdef IN_RING3
756typedef PPDMIOMMUR3 PPDMIOMMU;
757#else
758typedef PPDMIOMMUR0 PPDMIOMMU;
759#endif
760
761
762/**
763 * PDM registered PIC device.
764 */
765typedef struct PDMPIC
766{
767 /** Pointer to the PIC device instance - R3. */
768 PPDMDEVINSR3 pDevInsR3;
769 /** @copydoc PDMPICREG::pfnSetIrq */
770 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
771 /** @copydoc PDMPICREG::pfnGetInterrupt */
772 DECLR3CALLBACKMEMBER(int, pfnGetInterruptR3,(PPDMDEVINS pDevIns, uint32_t *puTagSrc));
773
774 /** Pointer to the PIC device instance - R0. */
775 PPDMDEVINSR0 pDevInsR0;
776 /** @copydoc PDMPICREG::pfnSetIrq */
777 DECLR0CALLBACKMEMBER(void, pfnSetIrqR0,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
778 /** @copydoc PDMPICREG::pfnGetInterrupt */
779 DECLR0CALLBACKMEMBER(int, pfnGetInterruptR0,(PPDMDEVINS pDevIns, uint32_t *puTagSrc));
780
781 /** Pointer to the PIC device instance - RC. */
782 PPDMDEVINSRC pDevInsRC;
783 /** @copydoc PDMPICREG::pfnSetIrq */
784 DECLRCCALLBACKMEMBER(void, pfnSetIrqRC,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
785 /** @copydoc PDMPICREG::pfnGetInterrupt */
786 DECLRCCALLBACKMEMBER(int, pfnGetInterruptRC,(PPDMDEVINS pDevIns, uint32_t *puTagSrc));
787 /** Alignment padding. */
788 RTRCPTR RCPtrPadding;
789} PDMPIC;
790
791
792/**
793 * PDM registered APIC device.
794 */
795typedef struct PDMAPIC
796{
797 /** Pointer to the APIC device instance - R3 Ptr. */
798 PPDMDEVINSR3 pDevInsR3;
799 /** Pointer to the APIC device instance - R0 Ptr. */
800 PPDMDEVINSR0 pDevInsR0;
801 /** Pointer to the APIC device instance - RC Ptr. */
802 PPDMDEVINSRC pDevInsRC;
803 uint8_t Alignment[4];
804} PDMAPIC;
805
806
807/**
808 * PDM registered I/O APIC device.
809 */
810typedef struct PDMIOAPIC
811{
812 /** Pointer to the I/O APIC device instance - R3 Ptr. */
813 PPDMDEVINSR3 pDevInsR3;
814 /** @copydoc PDMIOAPICREG::pfnSetIrq */
815 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, PCIBDF uBusDevFn, int iIrq, int iLevel, uint32_t uTagSrc));
816 /** @copydoc PDMIOAPICREG::pfnSendMsi */
817 DECLR3CALLBACKMEMBER(void, pfnSendMsiR3,(PPDMDEVINS pDevIns, PCIBDF uBusDevFn, PCMSIMSG pMsi, uint32_t uTagSrc));
818 /** @copydoc PDMIOAPICREG::pfnSetEoi */
819 DECLR3CALLBACKMEMBER(void, pfnSetEoiR3,(PPDMDEVINS pDevIns, uint8_t u8Vector));
820
821 /** Pointer to the I/O APIC device instance - R0. */
822 PPDMDEVINSR0 pDevInsR0;
823 /** @copydoc PDMIOAPICREG::pfnSetIrq */
824 DECLR0CALLBACKMEMBER(void, pfnSetIrqR0,(PPDMDEVINS pDevIns, PCIBDF uBusDevFn, int iIrq, int iLevel, uint32_t uTagSrc));
825 /** @copydoc PDMIOAPICREG::pfnSendMsi */
826 DECLR0CALLBACKMEMBER(void, pfnSendMsiR0,(PPDMDEVINS pDevIns, PCIBDF uBusDevFn, PCMSIMSG pMsi, uint32_t uTagSrc));
827 /** @copydoc PDMIOAPICREG::pfnSetEoi */
828 DECLR0CALLBACKMEMBER(void, pfnSetEoiR0,(PPDMDEVINS pDevIns, uint8_t u8Vector));
829
830 /** Pointer to the I/O APIC device instance - RC Ptr. */
831 PPDMDEVINSRC pDevInsRC;
832 /** @copydoc PDMIOAPICREG::pfnSetIrq */
833 DECLRCCALLBACKMEMBER(void, pfnSetIrqRC,(PPDMDEVINS pDevIns, PCIBDF uBusDevFn, int iIrq, int iLevel, uint32_t uTagSrc));
834 /** @copydoc PDMIOAPICREG::pfnSendMsi */
835 DECLRCCALLBACKMEMBER(void, pfnSendMsiRC,(PPDMDEVINS pDevIns, PCIBDF uBusDevFn, PCMSIMSG pMsi, uint32_t uTagSrc));
836 /** @copydoc PDMIOAPICREG::pfnSendMsi */
837 DECLRCCALLBACKMEMBER(void, pfnSetEoiRC,(PPDMDEVINS pDevIns, uint8_t u8Vector));
838} PDMIOAPIC;
839/** Pointer to a PDM IOAPIC instance. */
840typedef PDMIOAPIC *PPDMIOAPIC;
841/** Pointer to a const PDM IOAPIC instance. */
842typedef PDMIOAPIC const *PCPDMIOAPIC;
843
844/** Maximum number of PCI busses for a VM. */
845#define PDM_PCI_BUSSES_MAX 8
846/** Maximum number of IOMMUs (at most one per PCI bus). */
847#define PDM_IOMMUS_MAX PDM_PCI_BUSSES_MAX
848
849
850#ifdef IN_RING3
851/**
852 * PDM registered firmware device.
853 */
854typedef struct PDMFW
855{
856 /** Pointer to the firmware device instance. */
857 PPDMDEVINSR3 pDevIns;
858 /** Copy of the registration structure. */
859 PDMFWREG Reg;
860} PDMFW;
861/** Pointer to a firmware instance. */
862typedef PDMFW *PPDMFW;
863#endif
864
865
866/**
867 * PDM PCI bus instance.
868 */
869typedef struct PDMPCIBUS
870{
871 /** PCI bus number. */
872 uint32_t iBus;
873 uint32_t uPadding0; /**< Alignment padding.*/
874
875 /** Pointer to PCI bus device instance. */
876 PPDMDEVINSR3 pDevInsR3;
877 /** @copydoc PDMPCIBUSREGR3::pfnSetIrqR3 */
878 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
879
880 /** @copydoc PDMPCIBUSREGR3::pfnRegisterR3 */
881 DECLR3CALLBACKMEMBER(int, pfnRegister,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t fFlags,
882 uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName));
883 /** @copydoc PDMPCIBUSREGR3::pfnRegisterMsiR3 */
884 DECLR3CALLBACKMEMBER(int, pfnRegisterMsi,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, PPDMMSIREG pMsiReg));
885 /** @copydoc PDMPCIBUSREGR3::pfnIORegionRegisterR3 */
886 DECLR3CALLBACKMEMBER(int, pfnIORegionRegister,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
887 RTGCPHYS cbRegion, PCIADDRESSSPACE enmType, uint32_t fFlags,
888 uint64_t hHandle, PFNPCIIOREGIONMAP pfnCallback));
889 /** @copydoc PDMPCIBUSREGR3::pfnInterceptConfigAccesses */
890 DECLR3CALLBACKMEMBER(void, pfnInterceptConfigAccesses,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
891 PFNPCICONFIGREAD pfnRead, PFNPCICONFIGWRITE pfnWrite));
892 /** @copydoc PDMPCIBUSREGR3::pfnConfigWrite */
893 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnConfigWrite,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
894 uint32_t uAddress, unsigned cb, uint32_t u32Value));
895 /** @copydoc PDMPCIBUSREGR3::pfnConfigRead */
896 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnConfigRead,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
897 uint32_t uAddress, unsigned cb, uint32_t *pu32Value));
898} PDMPCIBUS;
899/** Pointer to a PDM PCI Bus instance. */
900typedef PDMPCIBUS *PPDMPCIBUS;
901/** Pointer to a const PDM PCI Bus instance. */
902typedef const PDMPCIBUS *PCPDMPCIBUS;
903
904
905/**
906 * Ring-0 PDM PCI bus instance data.
907 */
908typedef struct PDMPCIBUSR0
909{
910 /** PCI bus number. */
911 uint32_t iBus;
912 uint32_t uPadding0; /**< Alignment padding.*/
913 /** Pointer to PCI bus device instance. */
914 PPDMDEVINSR0 pDevInsR0;
915 /** @copydoc PDMPCIBUSREGR0::pfnSetIrq */
916 DECLR0CALLBACKMEMBER(void, pfnSetIrqR0,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
917} PDMPCIBUSR0;
918/** Pointer to the ring-0 PCI bus data. */
919typedef PDMPCIBUSR0 *PPDMPCIBUSR0;
920/** Pointer to the const ring-0 PCI bus data. */
921typedef const PDMPCIBUSR0 *PCPDMPCIBUSR0;
922
923
924#ifdef IN_RING3
925/**
926 * PDM registered DMAC (DMA Controller) device.
927 */
928typedef struct PDMDMAC
929{
930 /** Pointer to the DMAC device instance. */
931 PPDMDEVINSR3 pDevIns;
932 /** Copy of the registration structure. */
933 PDMDMACREG Reg;
934} PDMDMAC;
935
936
937/**
938 * PDM registered RTC (Real Time Clock) device.
939 */
940typedef struct PDMRTC
941{
942 /** Pointer to the RTC device instance. */
943 PPDMDEVINSR3 pDevIns;
944 /** Copy of the registration structure. */
945 PDMRTCREG Reg;
946} PDMRTC;
947
948#endif /* IN_RING3 */
949
950/**
951 * Module type.
952 */
953typedef enum PDMMODTYPE
954{
955 /** Raw-mode (RC) context module. */
956 PDMMOD_TYPE_RC,
957 /** Ring-0 (host) context module. */
958 PDMMOD_TYPE_R0,
959 /** Ring-3 (host) context module. */
960 PDMMOD_TYPE_R3
961} PDMMODTYPE;
962
963
964/** The module name length including the terminator. */
965#define PDMMOD_NAME_LEN 32
966
967/**
968 * Loaded module instance.
969 */
970typedef struct PDMMOD
971{
972 /** Module name. This is used for referring to
973 * the module internally, sort of like a handle. */
974 char szName[PDMMOD_NAME_LEN];
975 /** Module type. */
976 PDMMODTYPE eType;
977 /** Loader module handle. Not used for R0 modules. */
978 RTLDRMOD hLdrMod;
979 /** Loaded address.
980 * This is the 'handle' for R0 modules. */
981 RTUINTPTR ImageBase;
982 /** Old loaded address.
983 * This is used during relocation of GC modules. Not used for R0 modules. */
984 RTUINTPTR OldImageBase;
985 /** Where the R3 HC bits are stored.
986 * This can be equal to ImageBase but doesn't have to. Not used for R0 modules. */
987 void *pvBits;
988
989 /** Pointer to next module. */
990 struct PDMMOD *pNext;
991 /** Module filename. */
992 char szFilename[1];
993} PDMMOD;
994/** Pointer to loaded module instance. */
995typedef PDMMOD *PPDMMOD;
996
997
998
999/** Max number of items in a queue. */
1000#define PDMQUEUE_MAX_ITEMS _16K
1001/** Max item size. */
1002#define PDMQUEUE_MAX_ITEM_SIZE _1M
1003/** Max total queue item size for ring-0 capable queues. */
1004#define PDMQUEUE_MAX_TOTAL_SIZE_R0 _8M
1005/** Max total queue item size for ring-3 only queues. */
1006#define PDMQUEUE_MAX_TOTAL_SIZE_R3 _32M
1007
1008/**
1009 * Queue type.
1010 */
1011typedef enum PDMQUEUETYPE
1012{
1013 /** Device consumer. */
1014 PDMQUEUETYPE_DEV = 1,
1015 /** Driver consumer. */
1016 PDMQUEUETYPE_DRV,
1017 /** Internal consumer. */
1018 PDMQUEUETYPE_INTERNAL,
1019 /** External consumer. */
1020 PDMQUEUETYPE_EXTERNAL
1021} PDMQUEUETYPE;
1022
1023/**
1024 * PDM Queue.
1025 */
1026typedef struct PDMQUEUE
1027{
1028 /** Magic value (PDMQUEUE_MAGIC). */
1029 uint32_t u32Magic;
1030 /** Item size (bytes). */
1031 uint32_t cbItem;
1032 /** Number of items in the queue. */
1033 uint32_t cItems;
1034 /** Offset of the the queue items relative to the PDMQUEUE structure. */
1035 uint32_t offItems;
1036
1037 /** Interval timer. Only used if cMilliesInterval is non-zero. */
1038 TMTIMERHANDLE hTimer;
1039 /** The interval between checking the queue for events.
1040 * The realtime timer below is used to do the waiting.
1041 * If 0, the queue will use the VM_FF_PDM_QUEUE forced action. */
1042 uint32_t cMilliesInterval;
1043
1044 /** This is VINF_SUCCESS if the queue is okay, error status if not. */
1045 int32_t rcOkay;
1046 uint32_t u32Padding;
1047
1048 /** Queue type. */
1049 PDMQUEUETYPE enmType;
1050 /** Type specific data. */
1051 union
1052 {
1053 /** PDMQUEUETYPE_DEV */
1054 struct
1055 {
1056 /** Pointer to consumer function. */
1057 R3PTRTYPE(PFNPDMQUEUEDEV) pfnCallback;
1058 /** Pointer to the device instance owning the queue. */
1059 R3PTRTYPE(PPDMDEVINS) pDevIns;
1060 } Dev;
1061 /** PDMQUEUETYPE_DRV */
1062 struct
1063 {
1064 /** Pointer to consumer function. */
1065 R3PTRTYPE(PFNPDMQUEUEDRV) pfnCallback;
1066 /** Pointer to the driver instance owning the queue. */
1067 R3PTRTYPE(PPDMDRVINS) pDrvIns;
1068 } Drv;
1069 /** PDMQUEUETYPE_INTERNAL */
1070 struct
1071 {
1072 /** Pointer to consumer function. */
1073 R3PTRTYPE(PFNPDMQUEUEINT) pfnCallback;
1074 } Int;
1075 /** PDMQUEUETYPE_EXTERNAL */
1076 struct
1077 {
1078 /** Pointer to consumer function. */
1079 R3PTRTYPE(PFNPDMQUEUEEXT) pfnCallback;
1080 /** Pointer to user argument. */
1081 R3PTRTYPE(void *) pvUser;
1082 } Ext;
1083 struct
1084 {
1085 /** Generic callback pointer. */
1086 RTR3PTR pfnCallback;
1087 /** Generic owner pointer. */
1088 RTR3PTR pvOwner;
1089 } Gen;
1090 } u;
1091
1092 /** Unique queue name. */
1093 char szName[40];
1094
1095 /** LIFO of pending items (item index), UINT32_MAX if empty. */
1096 uint32_t volatile iPending;
1097
1098 /** State: Pending items. */
1099 uint32_t volatile cStatPending;
1100 /** Stat: Times PDMQueueAlloc fails. */
1101 STAMCOUNTER StatAllocFailures;
1102 /** Stat: PDMQueueInsert calls. */
1103 STAMCOUNTER StatInsert;
1104 /** Stat: Queue flushes. */
1105 STAMCOUNTER StatFlush;
1106 /** Stat: Queue flushes with pending items left over. */
1107 STAMCOUNTER StatFlushLeftovers;
1108 /** State: Profiling the flushing. */
1109 STAMPROFILE StatFlushPrf;
1110 uint64_t au64Padding[3];
1111
1112 /** Allocation bitmap: Set bits means free, clear means allocated. */
1113 RT_FLEXIBLE_ARRAY_EXTENSION
1114 uint64_t bmAlloc[RT_FLEXIBLE_ARRAY];
1115 /* The items follows after the end of the bitmap */
1116} PDMQUEUE;
1117AssertCompileMemberAlignment(PDMQUEUE, bmAlloc, 64);
1118/** Pointer to a PDM Queue. */
1119typedef struct PDMQUEUE *PPDMQUEUE;
1120
1121/** Magic value PDMQUEUE::u32Magic (Bud Powell). */
1122#define PDMQUEUE_MAGIC UINT32_C(0x19240927)
1123/** Magic value PDMQUEUE::u32Magic after destroy. */
1124#define PDMQUEUE_MAGIC_DEAD UINT32_C(0x19660731)
1125
1126/** @name PDM::fQueueFlushing
1127 * @{ */
1128/** Used to make sure only one EMT will flush the queues.
1129 * Set when an EMT is flushing queues, clear otherwise. */
1130#define PDM_QUEUE_FLUSH_FLAG_ACTIVE_BIT 0
1131/** Indicating there are queues with items pending.
1132 * This is make sure we don't miss inserts happening during flushing. The FF
1133 * cannot be used for this since it has to be cleared immediately to prevent
1134 * other EMTs from spinning. */
1135#define PDM_QUEUE_FLUSH_FLAG_PENDING_BIT 1
1136/** @} */
1137
1138/**
1139 * Ring-0 queue
1140 *
1141 * @author bird (2022-02-04)
1142 */
1143typedef struct PDMQUEUER0
1144{
1145 /** Pointer to the shared queue data. */
1146 R0PTRTYPE(PPDMQUEUE) pQueue;
1147 /** The memory allocation. */
1148 RTR0MEMOBJ hMemObj;
1149 /** The ring-3 mapping object. */
1150 RTR0MEMOBJ hMapObj;
1151 /** The owner pointer. This is NULL if not allocated. */
1152 RTR0PTR pvOwner;
1153 /** Queue item size. */
1154 uint32_t cbItem;
1155 /** Number of queue items. */
1156 uint32_t cItems;
1157 /** Offset of the the queue items relative to the PDMQUEUE structure. */
1158 uint32_t offItems;
1159 uint32_t u32Reserved;
1160} PDMQUEUER0;
1161
1162
1163/** @name PDM task structures.
1164 * @{ */
1165
1166/**
1167 * A asynchronous user mode task.
1168 */
1169typedef struct PDMTASK
1170{
1171 /** Task owner type. */
1172 PDMTASKTYPE volatile enmType;
1173 /** Queue flags. */
1174 uint32_t volatile fFlags;
1175 /** User argument for the callback. */
1176 R3PTRTYPE(void *) volatile pvUser;
1177 /** The callback (will be cast according to enmType before callout). */
1178 R3PTRTYPE(PFNRT) volatile pfnCallback;
1179 /** The owner identifier. */
1180 R3PTRTYPE(void *) volatile pvOwner;
1181 /** Task name. */
1182 R3PTRTYPE(const char *) pszName;
1183 /** Number of times already triggered when PDMTaskTrigger was called. */
1184 uint32_t volatile cAlreadyTrigged;
1185 /** Number of runs. */
1186 uint32_t cRuns;
1187} PDMTASK;
1188/** Pointer to a PDM task. */
1189typedef PDMTASK *PPDMTASK;
1190
1191/**
1192 * A task set.
1193 *
1194 * This is served by one task executor thread.
1195 */
1196typedef struct PDMTASKSET
1197{
1198 /** Magic value (PDMTASKSET_MAGIC). */
1199 uint32_t u32Magic;
1200 /** Set if this task set works for ring-0 and raw-mode. */
1201 bool fRZEnabled;
1202 /** Number of allocated taks. */
1203 uint8_t volatile cAllocated;
1204 /** Base handle value for this set. */
1205 uint16_t uHandleBase;
1206 /** The task executor thread. */
1207 R3PTRTYPE(RTTHREAD) hThread;
1208 /** Event semaphore for waking up the thread when fRZEnabled is set. */
1209 SUPSEMEVENT hEventR0;
1210 /** Event semaphore for waking up the thread when fRZEnabled is clear. */
1211 R3PTRTYPE(RTSEMEVENT) hEventR3;
1212 /** The VM pointer. */
1213 PVM pVM;
1214 /** Padding so fTriggered is in its own cacheline. */
1215 uint64_t au64Padding2[3];
1216
1217 /** Bitmask of triggered tasks. */
1218 uint64_t volatile fTriggered;
1219 /** Shutdown thread indicator. */
1220 bool volatile fShutdown;
1221 /** Padding. */
1222 bool volatile afPadding3[3];
1223 /** Task currently running, UINT32_MAX if idle. */
1224 uint32_t volatile idxRunning;
1225 /** Padding so fTriggered and fShutdown are in their own cacheline. */
1226 uint64_t volatile au64Padding3[6];
1227
1228 /** The individual tasks. (Unallocated tasks have NULL pvOwner.) */
1229 PDMTASK aTasks[64];
1230} PDMTASKSET;
1231AssertCompileMemberAlignment(PDMTASKSET, fTriggered, 64);
1232AssertCompileMemberAlignment(PDMTASKSET, aTasks, 64);
1233/** Magic value for PDMTASKSET::u32Magic (Quincy Delight Jones Jr.). */
1234#define PDMTASKSET_MAGIC UINT32_C(0x19330314)
1235/** Pointer to a task set. */
1236typedef PDMTASKSET *PPDMTASKSET;
1237
1238/** @} */
1239
1240
1241/** @name PDM Network Shaper
1242 * @{ */
1243
1244/**
1245 * Bandwidth group.
1246 */
1247typedef struct PDMNSBWGROUP
1248{
1249 /** Critical section protecting all members below. */
1250 PDMCRITSECT Lock;
1251 /** List of filters in this group (PDMNSFILTER). */
1252 RTLISTANCHORR3 FilterList;
1253 /** Reference counter - How many filters are associated with this group. */
1254 volatile uint32_t cRefs;
1255 uint32_t uPadding1;
1256 /** The group name. */
1257 char szName[PDM_NET_SHAPER_MAX_NAME_LEN + 1];
1258 /** Maximum number of bytes filters are allowed to transfer. */
1259 volatile uint64_t cbPerSecMax;
1260 /** Number of bytes we are allowed to transfer in one burst. */
1261 volatile uint32_t cbBucket;
1262 /** Number of bytes we were allowed to transfer at the last update. */
1263 volatile uint32_t cbTokensLast;
1264 /** Timestamp of the last update */
1265 volatile uint64_t tsUpdatedLast;
1266 /** Number of times a filter was choked. */
1267 volatile uint64_t cTotalChokings;
1268 /** Pad the structure to a multiple of 64 bytes. */
1269 uint64_t au64Padding[1];
1270} PDMNSBWGROUP;
1271AssertCompileSizeAlignment(PDMNSBWGROUP, 64);
1272/** Pointer to a bandwidth group. */
1273typedef PDMNSBWGROUP *PPDMNSBWGROUP;
1274
1275/** @} */
1276
1277
1278/**
1279 * Queue device helper task operation.
1280 */
1281typedef enum PDMDEVHLPTASKOP
1282{
1283 /** The usual invalid 0 entry. */
1284 PDMDEVHLPTASKOP_INVALID = 0,
1285 /** IsaSetIrq, IoApicSetIrq */
1286 PDMDEVHLPTASKOP_ISA_SET_IRQ,
1287 /** PciSetIrq */
1288 PDMDEVHLPTASKOP_PCI_SET_IRQ,
1289 /** PciSetIrq */
1290 PDMDEVHLPTASKOP_IOAPIC_SET_IRQ,
1291 /** IoApicSendMsi */
1292 PDMDEVHLPTASKOP_IOAPIC_SEND_MSI,
1293 /** IoApicSettEoi */
1294 PDMDEVHLPTASKOP_IOAPIC_SET_EOI,
1295 /** The usual 32-bit hack. */
1296 PDMDEVHLPTASKOP_32BIT_HACK = 0x7fffffff
1297} PDMDEVHLPTASKOP;
1298
1299/**
1300 * Queued Device Helper Task.
1301 */
1302typedef struct PDMDEVHLPTASK
1303{
1304 /** The queue item core (don't touch). */
1305 PDMQUEUEITEMCORE Core;
1306 /** Pointer to the device instance (R3 Ptr). */
1307 PPDMDEVINSR3 pDevInsR3;
1308 /** This operation to perform. */
1309 PDMDEVHLPTASKOP enmOp;
1310#if HC_ARCH_BITS == 64
1311 uint32_t Alignment0;
1312#endif
1313 /** Parameters to the operation. */
1314 union PDMDEVHLPTASKPARAMS
1315 {
1316 /**
1317 * PDMDEVHLPTASKOP_ISA_SET_IRQ and PDMDEVHLPTASKOP_IOAPIC_SET_IRQ.
1318 */
1319 struct PDMDEVHLPTASKISASETIRQ
1320 {
1321 /** The bus:device:function of the device initiating the IRQ. Can be NIL_PCIBDF. */
1322 PCIBDF uBusDevFn;
1323 /** The IRQ */
1324 int iIrq;
1325 /** The new level. */
1326 int iLevel;
1327 /** The IRQ tag and source. */
1328 uint32_t uTagSrc;
1329 } IsaSetIrq, IoApicSetIrq;
1330
1331 /**
1332 * PDMDEVHLPTASKOP_PCI_SET_IRQ
1333 */
1334 struct PDMDEVHLPTASKPCISETIRQ
1335 {
1336 /** Index of the PCI device (into PDMDEVINSR3::apPciDevs). */
1337 uint32_t idxPciDev;
1338 /** The IRQ */
1339 int32_t iIrq;
1340 /** The new level. */
1341 int32_t iLevel;
1342 /** The IRQ tag and source. */
1343 uint32_t uTagSrc;
1344 } PciSetIrq;
1345
1346 /**
1347 * PDMDEVHLPTASKOP_IOAPIC_SEND_MSI
1348 */
1349 struct PDMDEVHLPTASKIOAPICSENDMSI
1350 {
1351 /** The bus:device:function of the device sending the MSI. */
1352 PCIBDF uBusDevFn;
1353 /** The MSI. */
1354 MSIMSG Msi;
1355 /** The IRQ tag and source. */
1356 uint32_t uTagSrc;
1357 } IoApicSendMsi;
1358
1359 /**
1360 * PDMDEVHLPTASKOP_IOAPIC_SET_EOI
1361 */
1362 struct PDMDEVHLPTASKIOAPICSETEOI
1363 {
1364 /** The vector corresponding to the EOI. */
1365 uint8_t uVector;
1366 } IoApicSetEoi;
1367
1368 /** Expanding the structure. */
1369 uint64_t au64[3];
1370 } u;
1371} PDMDEVHLPTASK;
1372/** Pointer to a queued Device Helper Task. */
1373typedef PDMDEVHLPTASK *PPDMDEVHLPTASK;
1374/** Pointer to a const queued Device Helper Task. */
1375typedef const PDMDEVHLPTASK *PCPDMDEVHLPTASK;
1376
1377
1378
1379/**
1380 * An USB hub registration record.
1381 */
1382typedef struct PDMUSBHUB
1383{
1384 /** The USB versions this hub support.
1385 * Note that 1.1 hubs can take on 2.0 devices. */
1386 uint32_t fVersions;
1387 /** The number of ports on the hub. */
1388 uint32_t cPorts;
1389 /** The number of available ports (0..cPorts). */
1390 uint32_t cAvailablePorts;
1391 /** The driver instance of the hub. */
1392 PPDMDRVINS pDrvIns;
1393 /** Copy of the to the registration structure. */
1394 PDMUSBHUBREG Reg;
1395
1396 /** Pointer to the next hub in the list. */
1397 struct PDMUSBHUB *pNext;
1398} PDMUSBHUB;
1399
1400/** Pointer to a const USB HUB registration record. */
1401typedef const PDMUSBHUB *PCPDMUSBHUB;
1402
1403/** Pointer to a PDM Async I/O template. */
1404typedef struct PDMASYNCCOMPLETIONTEMPLATE *PPDMASYNCCOMPLETIONTEMPLATE;
1405
1406/** Pointer to the main PDM Async completion endpoint class. */
1407typedef struct PDMASYNCCOMPLETIONEPCLASS *PPDMASYNCCOMPLETIONEPCLASS;
1408
1409/** Pointer to the global block cache structure. */
1410typedef struct PDMBLKCACHEGLOBAL *PPDMBLKCACHEGLOBAL;
1411
1412/**
1413 * PDM VMCPU Instance data.
1414 * Changes to this must checked against the padding of the pdm union in VMCPU!
1415 */
1416typedef struct PDMCPU
1417{
1418 /** The number of entries in the apQueuedCritSectsLeaves table that's currently
1419 * in use. */
1420 uint32_t cQueuedCritSectLeaves;
1421 uint32_t uPadding0; /**< Alignment padding.*/
1422 /** Critical sections queued in RC/R0 because of contention preventing leave to
1423 * complete. (R3 Ptrs)
1424 * We will return to Ring-3 ASAP, so this queue doesn't have to be very long. */
1425 R3PTRTYPE(PPDMCRITSECT) apQueuedCritSectLeaves[8];
1426
1427 /** The number of entries in the apQueuedCritSectRwExclLeaves table that's
1428 * currently in use. */
1429 uint32_t cQueuedCritSectRwExclLeaves;
1430 uint32_t uPadding1; /**< Alignment padding.*/
1431 /** Read/write critical sections queued in RC/R0 because of contention
1432 * preventing exclusive leave to complete. (R3 Ptrs)
1433 * We will return to Ring-3 ASAP, so this queue doesn't have to be very long. */
1434 R3PTRTYPE(PPDMCRITSECTRW) apQueuedCritSectRwExclLeaves[8];
1435
1436 /** The number of entries in the apQueuedCritSectsRwShrdLeaves table that's
1437 * currently in use. */
1438 uint32_t cQueuedCritSectRwShrdLeaves;
1439 uint32_t uPadding2; /**< Alignment padding.*/
1440 /** Read/write critical sections queued in RC/R0 because of contention
1441 * preventing shared leave to complete. (R3 Ptrs)
1442 * We will return to Ring-3 ASAP, so this queue doesn't have to be very long. */
1443 R3PTRTYPE(PPDMCRITSECTRW) apQueuedCritSectRwShrdLeaves[8];
1444} PDMCPU;
1445
1446
1447/** Max number of ring-0 device instances. */
1448#define PDM_MAX_RING0_DEVICE_INSTANCES 190
1449
1450
1451/**
1452 * PDM VM Instance data.
1453 * Changes to this must checked against the padding of the cfgm union in VM!
1454 */
1455typedef struct PDM
1456{
1457 /** The PDM lock.
1458 * This is used to protect everything that deals with interrupts, i.e.
1459 * the PIC, APIC, IOAPIC and PCI devices plus some PDM functions. */
1460 PDMCRITSECT CritSect;
1461 /** The NOP critical section.
1462 * This is a dummy critical section that will not do any thread
1463 * serialization but instead let all threads enter immediately and
1464 * concurrently. */
1465 PDMCRITSECT NopCritSect;
1466
1467 /** The ring-0 capable task sets (max 128). */
1468 PDMTASKSET aTaskSets[2];
1469 /** Pointer to task sets (max 512). */
1470 R3PTRTYPE(PPDMTASKSET) apTaskSets[8];
1471
1472 /** PCI Buses. */
1473 PDMPCIBUS aPciBuses[PDM_PCI_BUSSES_MAX];
1474 /** IOMMU devices. */
1475 PDMIOMMUR3 aIommus[PDM_IOMMUS_MAX];
1476 /** The register PIC device. */
1477 PDMPIC Pic;
1478 /** The registered APIC device. */
1479 PDMAPIC Apic;
1480 /** The registered I/O APIC device. */
1481 PDMIOAPIC IoApic;
1482 /** The registered HPET device. */
1483 PPDMDEVINSR3 pHpet;
1484
1485 /** List of registered devices. (FIFO) */
1486 R3PTRTYPE(PPDMDEV) pDevs;
1487 /** List of devices instances. (FIFO) */
1488 PPDMDEVINSR3 pDevInstances;
1489 /** This runs parallel to PDMR0PERVM::apDevInstances and is used with
1490 * physical access handlers to get the ring-3 device instance for passing down
1491 * as uUser. */
1492 PPDMDEVINSR3 apDevRing0Instances[PDM_MAX_RING0_DEVICE_INSTANCES];
1493
1494 /** List of registered USB devices. (FIFO) */
1495 R3PTRTYPE(PPDMUSB) pUsbDevs;
1496 /** List of USB devices instances. (FIFO) */
1497 R3PTRTYPE(PPDMUSBINS) pUsbInstances;
1498 /** List of registered drivers. (FIFO) */
1499 R3PTRTYPE(PPDMDRV) pDrvs;
1500 /** The registered firmware device (can be NULL). */
1501 R3PTRTYPE(PPDMFW) pFirmware;
1502 /** The registered DMAC device. */
1503 R3PTRTYPE(PPDMDMAC) pDmac;
1504 /** The registered RTC device. */
1505 R3PTRTYPE(PPDMRTC) pRtc;
1506 /** The registered USB HUBs. (FIFO) */
1507 R3PTRTYPE(PPDMUSBHUB) pUsbHubs;
1508
1509 /** @name Queues
1510 * @{ */
1511 /** Number of ring-0 capable queues in apQueues. */
1512 uint32_t cRing0Queues;
1513 uint32_t u32Padding1;
1514 /** Array of ring-0 capable queues running in parallel to PDMR0PERVM::aQueues. */
1515 R3PTRTYPE(PPDMQUEUE) apRing0Queues[16];
1516
1517 /** Number of ring-3 only queues.
1518 * PDMUSERPERVM::ListCritSect protects this and the next two members. */
1519 uint32_t cRing3Queues;
1520 /** The allocation size of the ring-3 queue handle table. */
1521 uint32_t cRing3QueuesAlloc;
1522 /** Handle table for the ring-3 only queues. */
1523 R3PTRTYPE(PPDMQUEUE *) papRing3Queues;
1524
1525 /** Queue in which devhlp tasks are queued for R3 execution. */
1526 PDMQUEUEHANDLE hDevHlpQueue;
1527 /** Bitmask controlling the queue flushing.
1528 * See PDM_QUEUE_FLUSH_FLAG_ACTIVE and PDM_QUEUE_FLUSH_FLAG_PENDING. */
1529 uint32_t volatile fQueueFlushing;
1530 /** @} */
1531
1532 /** The current IRQ tag (tracing purposes). */
1533 uint32_t volatile uIrqTag;
1534
1535 /** Pending reset flags (PDMVMRESET_F_XXX). */
1536 uint32_t volatile fResetFlags;
1537
1538 /** Set by pdmR3LoadExec for use in assertions. */
1539 bool fStateLoaded;
1540 /** Alignment padding. */
1541 bool afPadding1[3];
1542
1543 /** The tracing ID of the next device instance.
1544 *
1545 * @remarks We keep the device tracing ID seperate from the rest as these are
1546 * then more likely to end up with the same ID from one run to
1547 * another, making analysis somewhat easier. Drivers and USB devices
1548 * are more volatile and can be changed at runtime, thus these are much
1549 * less likely to remain stable, so just heap them all together. */
1550 uint32_t idTracingDev;
1551 /** The tracing ID of the next driver instance, USB device instance or other
1552 * PDM entity requiring an ID. */
1553 uint32_t idTracingOther;
1554
1555 /** @name VMM device heap
1556 * @{ */
1557 /** The heap size. */
1558 uint32_t cbVMMDevHeap;
1559 /** Free space. */
1560 uint32_t cbVMMDevHeapLeft;
1561 /** Pointer to the heap base (MMIO2 ring-3 mapping). NULL if not registered. */
1562 RTR3PTR pvVMMDevHeap;
1563 /** Ring-3 mapping/unmapping notification callback for the user. */
1564 PFNPDMVMMDEVHEAPNOTIFY pfnVMMDevHeapNotify;
1565 /** The current mapping. NIL_RTGCPHYS if not mapped or registered. */
1566 RTGCPHYS GCPhysVMMDevHeap;
1567 /** @} */
1568
1569 /** @name Network Shaper
1570 * @{ */
1571 /** Thread that processes choked filter drivers after
1572 * the a PDM_NETSHAPER_MAX_LATENCY period has elapsed. */
1573 PPDMTHREAD pNsUnchokeThread;
1574 /** Semaphore that the TX thread waits on. */
1575 RTSEMEVENT hNsUnchokeEvt;
1576 /** Timer handle for waking up pNsUnchokeThread. */
1577 TMTIMERHANDLE hNsUnchokeTimer;
1578 /** Indicates whether the unchoke timer has been armed already or not. */
1579 bool volatile fNsUnchokeTimerArmed;
1580 /** Align aNsGroups on a cacheline. */
1581 bool afPadding2[19+16];
1582 /** Number of network shaper groups.
1583 * @note Marked volatile to prevent re-reading after validation. */
1584 uint32_t volatile cNsGroups;
1585 /** The network shaper groups. */
1586 PDMNSBWGROUP aNsGroups[PDM_NET_SHAPER_MAX_GROUPS];
1587 /** Critical section protecting attaching, detaching and unchoking.
1588 * This helps making sure pNsTxThread can do unchoking w/o needing to lock the
1589 * individual groups and cause unnecessary contention. */
1590 RTCRITSECT NsLock;
1591 /** @} */
1592
1593 /** Number of times a critical section leave request needed to be queued for ring-3 execution. */
1594 STAMCOUNTER StatQueuedCritSectLeaves;
1595 /** Number of times we've successfully aborted a wait in ring-0. */
1596 STAMCOUNTER StatAbortedCritSectEnters;
1597 /** Number of times we've got the critical section ownership while trying to
1598 * abort a wait due to VERR_INTERRUPTED. */
1599 STAMCOUNTER StatCritSectEntersWhileAborting;
1600 STAMCOUNTER StatCritSectVerrTimeout;
1601 STAMCOUNTER StatCritSectVerrInterrupted;
1602 STAMCOUNTER StatCritSectNonInterruptibleWaits;
1603
1604 STAMCOUNTER StatCritSectRwExclVerrTimeout;
1605 STAMCOUNTER StatCritSectRwExclVerrInterrupted;
1606 STAMCOUNTER StatCritSectRwExclNonInterruptibleWaits;
1607
1608 STAMCOUNTER StatCritSectRwEnterSharedWhileAborting;
1609 STAMCOUNTER StatCritSectRwSharedVerrTimeout;
1610 STAMCOUNTER StatCritSectRwSharedVerrInterrupted;
1611 STAMCOUNTER StatCritSectRwSharedNonInterruptibleWaits;
1612} PDM;
1613AssertCompileMemberAlignment(PDM, CritSect, 8);
1614AssertCompileMemberAlignment(PDM, aTaskSets, 64);
1615AssertCompileMemberAlignment(PDM, aNsGroups, 8);
1616AssertCompileMemberAlignment(PDM, aNsGroups, 16);
1617AssertCompileMemberAlignment(PDM, aNsGroups, 32);
1618AssertCompileMemberAlignment(PDM, aNsGroups, 64);
1619AssertCompileMemberAlignment(PDM, StatQueuedCritSectLeaves, 8);
1620AssertCompileMemberAlignment(PDM, GCPhysVMMDevHeap, sizeof(RTGCPHYS));
1621/** Pointer to PDM VM instance data. */
1622typedef PDM *PPDM;
1623
1624
1625/**
1626 * PDM data kept in the ring-0 GVM.
1627 */
1628typedef struct PDMR0PERVM
1629{
1630 /** PCI Buses, ring-0 data. */
1631 PDMPCIBUSR0 aPciBuses[PDM_PCI_BUSSES_MAX];
1632 /** IOMMUs, ring-0 data. */
1633 PDMIOMMUR0 aIommus[PDM_IOMMUS_MAX];
1634 /** Number of valid ring-0 device instances (apDevInstances). */
1635 uint32_t cDevInstances;
1636 uint32_t u32Padding1;
1637 /** Pointer to ring-0 device instances. */
1638 R0PTRTYPE(struct PDMDEVINSR0 *) apDevInstances[PDM_MAX_RING0_DEVICE_INSTANCES];
1639 /** Number of valid ring-0 queue instances (aQueues). */
1640 uint32_t cQueues;
1641 uint32_t u32Padding2;
1642 /** Array of ring-0 queues. */
1643 PDMQUEUER0 aQueues[16];
1644} PDMR0PERVM;
1645
1646
1647/**
1648 * PDM data kept in the UVM.
1649 */
1650typedef struct PDMUSERPERVM
1651{
1652 /** @todo move more stuff over here. */
1653
1654 /** Lock protecting the lists below it and the queue list. */
1655 RTCRITSECT ListCritSect;
1656 /** Pointer to list of loaded modules. */
1657 PPDMMOD pModules;
1658 /** List of initialized critical sections. (LIFO) */
1659 R3PTRTYPE(PPDMCRITSECTINT) pCritSects;
1660 /** List of initialized read/write critical sections. (LIFO) */
1661 R3PTRTYPE(PPDMCRITSECTRWINT) pRwCritSects;
1662 /** Head of the PDM Thread list. (singly linked) */
1663 R3PTRTYPE(PPDMTHREAD) pThreads;
1664 /** Tail of the PDM Thread list. (singly linked) */
1665 R3PTRTYPE(PPDMTHREAD) pThreadsTail;
1666
1667 /** @name PDM Async Completion
1668 * @{ */
1669 /** Pointer to the array of supported endpoint classes. */
1670 PPDMASYNCCOMPLETIONEPCLASS apAsyncCompletionEndpointClass[PDMASYNCCOMPLETIONEPCLASSTYPE_MAX];
1671 /** Head of the templates. Singly linked, protected by ListCritSect. */
1672 R3PTRTYPE(PPDMASYNCCOMPLETIONTEMPLATE) pAsyncCompletionTemplates;
1673 /** @} */
1674
1675 /** Global block cache data. */
1676 R3PTRTYPE(PPDMBLKCACHEGLOBAL) pBlkCacheGlobal;
1677} PDMUSERPERVM;
1678/** Pointer to the PDM data kept in the UVM. */
1679typedef PDMUSERPERVM *PPDMUSERPERVM;
1680
1681
1682
1683/*******************************************************************************
1684* Global Variables *
1685*******************************************************************************/
1686#ifdef IN_RING3
1687extern const PDMDRVHLPR3 g_pdmR3DrvHlp;
1688extern const PDMDEVHLPR3 g_pdmR3DevHlpTrusted;
1689# ifdef VBOX_WITH_DBGF_TRACING
1690extern const PDMDEVHLPR3 g_pdmR3DevHlpTracing;
1691# endif
1692extern const PDMDEVHLPR3 g_pdmR3DevHlpUnTrusted;
1693extern const PDMPICHLP g_pdmR3DevPicHlp;
1694extern const PDMIOAPICHLP g_pdmR3DevIoApicHlp;
1695extern const PDMFWHLPR3 g_pdmR3DevFirmwareHlp;
1696extern const PDMPCIHLPR3 g_pdmR3DevPciHlp;
1697extern const PDMIOMMUHLPR3 g_pdmR3DevIommuHlp;
1698extern const PDMDMACHLP g_pdmR3DevDmacHlp;
1699extern const PDMRTCHLP g_pdmR3DevRtcHlp;
1700extern const PDMHPETHLPR3 g_pdmR3DevHpetHlp;
1701extern const PDMPCIRAWHLPR3 g_pdmR3DevPciRawHlp;
1702#endif
1703
1704
1705/*******************************************************************************
1706* Defined Constants And Macros *
1707*******************************************************************************/
1708/** @def PDMDEV_ASSERT_DEVINS
1709 * Asserts the validity of the device instance.
1710 */
1711#ifdef VBOX_STRICT
1712# define PDMDEV_ASSERT_DEVINS(pDevIns) \
1713 do { \
1714 AssertPtr(pDevIns); \
1715 Assert(pDevIns->u32Version == PDM_DEVINS_VERSION); \
1716 Assert(pDevIns->CTX_SUFF(pvInstanceDataFor) == (void *)&pDevIns->achInstanceData[0]); \
1717 } while (0)
1718#else
1719# define PDMDEV_ASSERT_DEVINS(pDevIns) do { } while (0)
1720#endif
1721
1722/** @def PDMDRV_ASSERT_DRVINS
1723 * Asserts the validity of the driver instance.
1724 */
1725#ifdef VBOX_STRICT
1726# define PDMDRV_ASSERT_DRVINS(pDrvIns) \
1727 do { \
1728 AssertPtr(pDrvIns); \
1729 Assert(pDrvIns->u32Version == PDM_DRVINS_VERSION); \
1730 Assert(pDrvIns->CTX_SUFF(pvInstanceData) == (void *)&pDrvIns->achInstanceData[0]); \
1731 } while (0)
1732#else
1733# define PDMDRV_ASSERT_DRVINS(pDrvIns) do { } while (0)
1734#endif
1735
1736
1737/*******************************************************************************
1738* Internal Functions *
1739*******************************************************************************/
1740#ifdef IN_RING3
1741bool pdmR3IsValidName(const char *pszName);
1742
1743int pdmR3CritSectBothInitStatsAndInfo(PVM pVM);
1744int pdmR3CritSectBothDeleteDevice(PVM pVM, PPDMDEVINS pDevIns);
1745int pdmR3CritSectBothDeleteDriver(PVM pVM, PPDMDRVINS pDrvIns);
1746int pdmR3CritSectInitDevice( PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
1747 const char *pszNameFmt, va_list va);
1748int pdmR3CritSectInitDeviceAuto( PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
1749 const char *pszNameFmt, ...);
1750int pdmR3CritSectInitDriver( PVM pVM, PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
1751 const char *pszNameFmt, ...);
1752int pdmR3CritSectRwInitDevice( PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL,
1753 const char *pszNameFmt, va_list va);
1754int pdmR3CritSectRwInitDeviceAuto( PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL,
1755 const char *pszNameFmt, ...);
1756int pdmR3CritSectRwInitDriver( PVM pVM, PPDMDRVINS pDrvIns, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL,
1757 const char *pszNameFmt, ...);
1758
1759int pdmR3DevInit(PVM pVM);
1760int pdmR3DevInitComplete(PVM pVM);
1761PPDMDEV pdmR3DevLookup(PVM pVM, const char *pszName);
1762int pdmR3DevFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMLUN *ppLun);
1763DECLCALLBACK(bool) pdmR3DevHlpQueueConsumer(PVM pVM, PPDMQUEUEITEMCORE pItem);
1764
1765int pdmR3UsbLoadModules(PVM pVM);
1766int pdmR3UsbInstantiateDevices(PVM pVM);
1767PPDMUSB pdmR3UsbLookup(PVM pVM, const char *pszName);
1768int pdmR3UsbRegisterHub(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp);
1769int pdmR3UsbVMInitComplete(PVM pVM);
1770
1771int pdmR3DrvInit(PVM pVM);
1772int pdmR3DrvInstantiate(PVM pVM, PCFGMNODE pNode, PPDMIBASE pBaseInterface, PPDMDRVINS pDrvAbove,
1773 PPDMLUN pLun, PPDMIBASE *ppBaseInterface);
1774int pdmR3DrvDetach(PPDMDRVINS pDrvIns, uint32_t fFlags);
1775void pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns, uint32_t fFlags);
1776PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName);
1777
1778int pdmR3LdrInitU(PUVM pUVM);
1779void pdmR3LdrTermU(PUVM pUVM, bool fFinal);
1780char *pdmR3FileR3(const char *pszFile, bool fShared);
1781int pdmR3LoadR3U(PUVM pUVM, const char *pszFilename, const char *pszName);
1782#endif /* IN_RING3 */
1783
1784void pdmQueueInit(PPDMQUEUE pQueue, uint32_t cbBitmap, uint32_t cbItem, uint32_t cItems,
1785 const char *pszName, PDMQUEUETYPE enmType, RTR3PTR pfnCallback, RTR3PTR pvOwner);
1786
1787#ifdef IN_RING3
1788int pdmR3TaskInit(PVM pVM);
1789void pdmR3TaskTerm(PVM pVM);
1790
1791int pdmR3ThreadCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
1792 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
1793int pdmR3ThreadCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
1794 PFNPDMTHREADWAKEUPUSB pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
1795int pdmR3ThreadCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
1796 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
1797int pdmR3ThreadDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
1798int pdmR3ThreadDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
1799int pdmR3ThreadDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
1800void pdmR3ThreadDestroyAll(PVM pVM);
1801int pdmR3ThreadResumeAll(PVM pVM);
1802int pdmR3ThreadSuspendAll(PVM pVM);
1803
1804# ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1805int pdmR3AsyncCompletionInit(PVM pVM);
1806int pdmR3AsyncCompletionTerm(PVM pVM);
1807void pdmR3AsyncCompletionResume(PVM pVM);
1808int pdmR3AsyncCompletionTemplateCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDEV pfnCompleted, const char *pszDesc);
1809int pdmR3AsyncCompletionTemplateCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
1810 PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser, const char *pszDesc);
1811int pdmR3AsyncCompletionTemplateCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEUSB pfnCompleted, const char *pszDesc);
1812int pdmR3AsyncCompletionTemplateDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
1813int pdmR3AsyncCompletionTemplateDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
1814int pdmR3AsyncCompletionTemplateDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
1815# endif
1816
1817# ifdef VBOX_WITH_NETSHAPER
1818int pdmR3NetShaperInit(PVM pVM);
1819void pdmR3NetShaperTerm(PVM pVM);
1820# endif
1821
1822int pdmR3BlkCacheInit(PVM pVM);
1823void pdmR3BlkCacheTerm(PVM pVM);
1824int pdmR3BlkCacheResume(PVM pVM);
1825
1826DECLHIDDEN(void) pdmR3QueueTerm(PVM pVM);
1827#endif /* IN_RING3 */
1828
1829void pdmLock(PVMCC pVM);
1830int pdmLockEx(PVMCC pVM, int rcBusy);
1831void pdmUnlock(PVMCC pVM);
1832bool pdmLockIsOwner(PVMCC pVM);
1833
1834#if defined(VBOX_WITH_IOMMU_AMD) || defined(VBOX_WITH_IOMMU_INTEL)
1835bool pdmIommuIsPresent(PPDMDEVINS pDevIns);
1836int pdmIommuMsiRemap(PPDMDEVINS pDevIns, uint16_t idDevice, PCMSIMSG pMsiIn, PMSIMSG pMsiOut);
1837int pdmIommuMemAccessRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags);
1838int pdmIommuMemAccessWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags);
1839# ifdef IN_RING3
1840int pdmR3IommuMemAccessReadCCPtr(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv, PPGMPAGEMAPLOCK pLock);
1841int pdmR3IommuMemAccessWriteCCPtr(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock);
1842int pdmR3IommuMemAccessBulkReadCCPtr(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t cPages, PCRTGCPHYS paGCPhysPages, uint32_t fFlags, const void **papvPages, PPGMPAGEMAPLOCK paLocks);
1843int pdmR3IommuMemAccessBulkWriteCCPtr(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t cPages, PCRTGCPHYS paGCPhysPages, uint32_t fFlags, void **papvPages, PPGMPAGEMAPLOCK paLocks);
1844# endif
1845#endif
1846
1847#if defined(IN_RING3) || defined(IN_RING0)
1848void pdmCritSectRwLeaveSharedQueued(PVMCC pVM, PPDMCRITSECTRW pThis);
1849void pdmCritSectRwLeaveExclQueued(PVMCC pVM, PPDMCRITSECTRW pThis);
1850#endif
1851
1852#ifdef IN_RING0
1853DECLHIDDEN(bool) pdmR0IsaSetIrq(PGVM pGVM, int iIrq, int iLevel, uint32_t uTagSrc);
1854DECLHIDDEN(void) pdmR0QueueDestroy(PGVM pGVM, uint32_t iQueue);
1855
1856#endif
1857
1858#ifdef VBOX_WITH_DBGF_TRACING
1859# ifdef IN_RING3
1860DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_IoPortCreateEx(PPDMDEVINS pDevIns, RTIOPORT cPorts, uint32_t fFlags, PPDMPCIDEV pPciDev,
1861 uint32_t iPciRegion, PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
1862 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr, RTR3PTR pvUser,
1863 const char *pszDesc, PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts);
1864DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_IoPortMap(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts, RTIOPORT Port);
1865DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_IoPortUnmap(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts);
1866DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_MmioCreateEx(PPDMDEVINS pDevIns, RTGCPHYS cbRegion,
1867 uint32_t fFlags, PPDMPCIDEV pPciDev, uint32_t iPciRegion,
1868 PFNIOMMMIONEWWRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill,
1869 void *pvUser, const char *pszDesc, PIOMMMIOHANDLE phRegion);
1870DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_MmioMap(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, RTGCPHYS GCPhys);
1871DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_MmioUnmap(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion);
1872DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags);
1873DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags);
1874DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_PCIPhysRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags);
1875DECL_HIDDEN_CALLBACK(int) pdmR3DevHlpTracing_PCIPhysWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags);
1876DECL_HIDDEN_CALLBACK(void) pdmR3DevHlpTracing_PCISetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel);
1877DECL_HIDDEN_CALLBACK(void) pdmR3DevHlpTracing_PCISetIrqNoWait(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel);
1878DECL_HIDDEN_CALLBACK(void) pdmR3DevHlpTracing_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
1879DECL_HIDDEN_CALLBACK(void) pdmR3DevHlpTracing_ISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel);
1880# elif defined(IN_RING0)
1881DECL_HIDDEN_CALLBACK(int) pdmR0DevHlpTracing_IoPortSetUpContextEx(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts,
1882 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
1883 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr,
1884 void *pvUser);
1885DECL_HIDDEN_CALLBACK(int) pdmR0DevHlpTracing_MmioSetUpContextEx(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, PFNIOMMMIONEWWRITE pfnWrite,
1886 PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill, void *pvUser);
1887DECL_HIDDEN_CALLBACK(int) pdmR0DevHlpTracing_PhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags);
1888DECL_HIDDEN_CALLBACK(int) pdmR0DevHlpTracing_PhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags);
1889DECL_HIDDEN_CALLBACK(int) pdmR0DevHlpTracing_PCIPhysRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead, uint32_t fFlags);
1890DECL_HIDDEN_CALLBACK(int) pdmR0DevHlpTracing_PCIPhysWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite, uint32_t fFlags);
1891DECL_HIDDEN_CALLBACK(void) pdmR0DevHlpTracing_PCISetIrq(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel);
1892DECL_HIDDEN_CALLBACK(void) pdmR0DevHlpTracing_PCISetIrqNoWait(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel);
1893DECL_HIDDEN_CALLBACK(void) pdmR0DevHlpTracing_ISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel);
1894DECL_HIDDEN_CALLBACK(void) pdmR0DevHlpTracing_ISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel);
1895# else
1896# error "Invalid environment selected"
1897# endif
1898#endif
1899
1900
1901/** @} */
1902
1903RT_C_DECLS_END
1904
1905#endif /* !VMM_INCLUDED_SRC_include_PDMInternal_h */
1906
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