VirtualBox

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

Last change on this file since 48521 was 45965, checked in by vboxsync, 12 years ago

VMM: Facility for getting the highest-priority pending interrupt from the APIC device.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 53.7 KB
Line 
1/* $Id: PDMInternal.h 45965 2013-05-09 15:32:14Z vboxsync $ */
2/** @file
3 * PDM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___PDMInternal_h
19#define ___PDMInternal_h
20
21#include <VBox/types.h>
22#include <VBox/param.h>
23#include <VBox/vmm/cfgm.h>
24#include <VBox/vmm/stam.h>
25#include <VBox/vusb.h>
26#include <VBox/vmm/pdmasynccompletion.h>
27#ifdef VBOX_WITH_NETSHAPER
28# include <VBox/vmm/pdmnetshaper.h>
29#endif
30#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
31# include <VBox/vmm/pdmasynccompletion.h>
32#endif
33#include <VBox/vmm/pdmblkcache.h>
34#include <VBox/vmm/pdmcommon.h>
35#include <VBox/sup.h>
36#include <iprt/assert.h>
37#include <iprt/critsect.h>
38#ifdef IN_RING3
39# include <iprt/thread.h>
40#endif
41
42RT_C_DECLS_BEGIN
43
44
45/** @defgroup grp_pdm_int Internal
46 * @ingroup grp_pdm
47 * @internal
48 * @{
49 */
50
51/** @def PDM_WITH_R3R0_CRIT_SECT
52 * Enables or disabled ring-3/ring-0 critical sections. */
53#if defined(DOXYGEN_RUNNING) || 1
54# define PDM_WITH_R3R0_CRIT_SECT
55#endif
56
57/** @def PDMCRITSECT_STRICT
58 * Enables/disables PDM critsect strictness like deadlock detection. */
59#if (defined(RT_LOCK_STRICT) && defined(IN_RING3) && !defined(IEM_VERIFICATION_MODE) && !defined(PDMCRITSECT_STRICT)) \
60 || defined(DOXYGEN_RUNNING)
61# define PDMCRITSECT_STRICT
62#endif
63
64/** @def PDMCRITSECT_STRICT
65 * Enables/disables PDM read/write critsect strictness like deadlock
66 * detection. */
67#if (defined(RT_LOCK_STRICT) && defined(IN_RING3) && !defined(IEM_VERIFICATION_MODE) && !defined(PDMCRITSECTRW_STRICT)) \
68 || defined(DOXYGEN_RUNNING)
69# define PDMCRITSECTRW_STRICT
70#endif
71
72
73/*******************************************************************************
74* Structures and Typedefs *
75*******************************************************************************/
76
77/** Pointer to a PDM Device. */
78typedef struct PDMDEV *PPDMDEV;
79/** Pointer to a pointer to a PDM Device. */
80typedef PPDMDEV *PPPDMDEV;
81
82/** Pointer to a PDM USB Device. */
83typedef struct PDMUSB *PPDMUSB;
84/** Pointer to a pointer to a PDM USB Device. */
85typedef PPDMUSB *PPPDMUSB;
86
87/** Pointer to a PDM Driver. */
88typedef struct PDMDRV *PPDMDRV;
89/** Pointer to a pointer to a PDM Driver. */
90typedef PPDMDRV *PPPDMDRV;
91
92/** Pointer to a PDM Logical Unit. */
93typedef struct PDMLUN *PPDMLUN;
94/** Pointer to a pointer to a PDM Logical Unit. */
95typedef PPDMLUN *PPPDMLUN;
96
97/** Pointer to a PDM PCI Bus instance. */
98typedef struct PDMPCIBUS *PPDMPCIBUS;
99/** Pointer to a DMAC instance. */
100typedef struct PDMDMAC *PPDMDMAC;
101/** Pointer to a RTC instance. */
102typedef struct PDMRTC *PPDMRTC;
103
104/** Pointer to an USB HUB registration record. */
105typedef struct PDMUSBHUB *PPDMUSBHUB;
106
107/**
108 * Supported asynchronous completion endpoint classes.
109 */
110typedef enum PDMASYNCCOMPLETIONEPCLASSTYPE
111{
112 /** File class. */
113 PDMASYNCCOMPLETIONEPCLASSTYPE_FILE = 0,
114 /** Number of supported classes. */
115 PDMASYNCCOMPLETIONEPCLASSTYPE_MAX,
116 /** 32bit hack. */
117 PDMASYNCCOMPLETIONEPCLASSTYPE_32BIT_HACK = 0x7fffffff
118} PDMASYNCCOMPLETIONEPCLASSTYPE;
119
120/**
121 * Private device instance data.
122 */
123typedef struct PDMDEVINSINT
124{
125 /** Pointer to the next instance (HC Ptr).
126 * (Head is pointed to by PDM::pDevInstances.) */
127 R3PTRTYPE(PPDMDEVINS) pNextR3;
128 /** Pointer to the next per device instance (HC Ptr).
129 * (Head is pointed to by PDMDEV::pInstances.) */
130 R3PTRTYPE(PPDMDEVINS) pPerDeviceNextR3;
131 /** Pointer to device structure - HC Ptr. */
132 R3PTRTYPE(PPDMDEV) pDevR3;
133 /** Pointer to the list of logical units associated with the device. (FIFO) */
134 R3PTRTYPE(PPDMLUN) pLunsR3;
135 /** Pointer to the asynchronous notification callback set while in
136 * FNPDMDEVSUSPEND or FNPDMDEVPOWEROFF. */
137 R3PTRTYPE(PFNPDMDEVASYNCNOTIFY) pfnAsyncNotify;
138 /** Configuration handle to the instance node. */
139 R3PTRTYPE(PCFGMNODE) pCfgHandle;
140
141 /** R3 pointer to the VM this instance was created for. */
142 PVMR3 pVMR3;
143 /** R3 pointer to associated PCI device structure. */
144 R3PTRTYPE(struct PCIDevice *) pPciDeviceR3;
145 /** R3 pointer to associated PCI bus structure. */
146 R3PTRTYPE(PPDMPCIBUS) pPciBusR3;
147
148 /** R0 pointer to the VM this instance was created for. */
149 PVMR0 pVMR0;
150 /** R0 pointer to associated PCI device structure. */
151 R0PTRTYPE(struct PCIDevice *) pPciDeviceR0;
152 /** R0 pointer to associated PCI bus structure. */
153 R0PTRTYPE(PPDMPCIBUS) pPciBusR0;
154
155 /** RC pointer to the VM this instance was created for. */
156 PVMRC pVMRC;
157 /** RC pointer to associated PCI device structure. */
158 RCPTRTYPE(struct PCIDevice *) pPciDeviceRC;
159 /** RC pointer to associated PCI bus structure. */
160 RCPTRTYPE(PPDMPCIBUS) pPciBusRC;
161
162 /** Flags, see PDMDEVINSINT_FLAGS_XXX. */
163 uint32_t fIntFlags;
164 /** The last IRQ tag (for tracing it thru clearing). */
165 uint32_t uLastIrqTag;
166 /** Size padding. */
167 uint32_t u32Padding;
168} PDMDEVINSINT;
169
170/** @name PDMDEVINSINT::fIntFlags
171 * @{ */
172/** Used by pdmR3Load to mark device instances it found in the saved state. */
173#define PDMDEVINSINT_FLAGS_FOUND RT_BIT_32(0)
174/** Indicates that the device hasn't been powered on or resumed.
175 * This is used by PDMR3PowerOn, PDMR3Resume, PDMR3Suspend and PDMR3PowerOff
176 * to make sure each device gets exactly one notification for each of those
177 * events. PDMR3Resume and PDMR3PowerOn also makes use of it to bail out on
178 * a failure (already resumed/powered-on devices are suspended). */
179#define PDMDEVINSINT_FLAGS_SUSPENDED RT_BIT_32(1)
180/** Indicates that the device has been reset already. Used by PDMR3Reset. */
181#define PDMDEVINSINT_FLAGS_RESET RT_BIT_32(2)
182/** @} */
183
184
185/**
186 * Private USB device instance data.
187 */
188typedef struct PDMUSBINSINT
189{
190 /** The UUID of this instance. */
191 RTUUID Uuid;
192 /** Pointer to the next instance.
193 * (Head is pointed to by PDM::pUsbInstances.) */
194 R3PTRTYPE(PPDMUSBINS) pNext;
195 /** Pointer to the next per USB device instance.
196 * (Head is pointed to by PDMUSB::pInstances.) */
197 R3PTRTYPE(PPDMUSBINS) pPerDeviceNext;
198
199 /** Pointer to device structure. */
200 R3PTRTYPE(PPDMUSB) pUsbDev;
201
202 /** Pointer to the VM this instance was created for. */
203 PVMR3 pVM;
204 /** Pointer to the list of logical units associated with the device. (FIFO) */
205 R3PTRTYPE(PPDMLUN) pLuns;
206 /** The per instance device configuration. */
207 R3PTRTYPE(PCFGMNODE) pCfg;
208 /** Same as pCfg if the configuration should be deleted when detaching the device. */
209 R3PTRTYPE(PCFGMNODE) pCfgDelete;
210 /** The global device configuration. */
211 R3PTRTYPE(PCFGMNODE) pCfgGlobal;
212
213 /** Pointer to the USB hub this device is attached to.
214 * This is NULL if the device isn't connected to any HUB. */
215 R3PTRTYPE(PPDMUSBHUB) pHub;
216 /** The port number that we're connected to. */
217 uint32_t iPort;
218 /** Indicates that the USB device hasn't been powered on or resumed.
219 * See PDMDEVINSINT_FLAGS_SUSPENDED. */
220 bool fVMSuspended;
221 /** Indicates that the USB device has been reset. */
222 bool fVMReset;
223 /** Pointer to the asynchronous notification callback set while in
224 * FNPDMDEVSUSPEND or FNPDMDEVPOWEROFF. */
225 R3PTRTYPE(PFNPDMUSBASYNCNOTIFY) pfnAsyncNotify;
226} PDMUSBINSINT;
227
228
229/**
230 * Private driver instance data.
231 */
232typedef struct PDMDRVINSINT
233{
234 /** Pointer to the driver instance above.
235 * This is NULL for the topmost drive. */
236 R3PTRTYPE(PPDMDRVINS) pUp;
237 /** Pointer to the driver instance below.
238 * This is NULL for the bottommost driver. */
239 R3PTRTYPE(PPDMDRVINS) pDown;
240 /** Pointer to the logical unit this driver chained on. */
241 R3PTRTYPE(PPDMLUN) pLun;
242 /** Pointer to driver structure from which this was instantiated. */
243 R3PTRTYPE(PPDMDRV) pDrv;
244 /** Pointer to the VM this instance was created for, ring-3 context. */
245 PVMR3 pVMR3;
246 /** Pointer to the VM this instance was created for, ring-0 context. */
247 PVMR0 pVMR0;
248 /** Pointer to the VM this instance was created for, raw-mode context. */
249 PVMRC pVMRC;
250 /** Flag indicating that the driver is being detached and destroyed.
251 * (Helps detect potential recursive detaching.) */
252 bool fDetaching;
253 /** Indicates that the driver hasn't been powered on or resumed.
254 * See PDMDEVINSINT_FLAGS_SUSPENDED. */
255 bool fVMSuspended;
256 /** Indicates that the driver has been reset already. */
257 bool fVMReset;
258 /** Set if allocated on the hyper heap, false if on the ring-3 heap. */
259 bool fHyperHeap;
260 /** Pointer to the asynchronous notification callback set while in
261 * PDMUSBREG::pfnVMSuspend or PDMUSBREG::pfnVMPowerOff. */
262 R3PTRTYPE(PFNPDMDRVASYNCNOTIFY) pfnAsyncNotify;
263 /** Configuration handle to the instance node. */
264 R3PTRTYPE(PCFGMNODE) pCfgHandle;
265 /** Pointer to the ring-0 request handler function. */
266 PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0;
267} PDMDRVINSINT;
268
269
270/**
271 * Private critical section data.
272 */
273typedef struct PDMCRITSECTINT
274{
275 /** The critical section core which is shared with IPRT.
276 * @note The semaphore is a SUPSEMEVENT. */
277 RTCRITSECT Core;
278 /** Pointer to the next critical section.
279 * This chain is used for relocating pVMRC and device cleanup. */
280 R3PTRTYPE(struct PDMCRITSECTINT *) pNext;
281 /** Owner identifier.
282 * This is pDevIns if the owner is a device. Similarly for a driver or service.
283 * PDMR3CritSectInit() sets this to point to the critsect itself. */
284 RTR3PTR pvKey;
285 /** Pointer to the VM - R3Ptr. */
286 PVMR3 pVMR3;
287 /** Pointer to the VM - R0Ptr. */
288 PVMR0 pVMR0;
289 /** Pointer to the VM - GCPtr. */
290 PVMRC pVMRC;
291 /** Set if this critical section is the automatically created default
292 * section of a device.. */
293 bool fAutomaticDefaultCritsect;
294 /** Set if the critical section is used by a timer or similar.
295 * See PDMR3DevGetCritSect. */
296 bool fUsedByTimerOrSimilar;
297 /** Alignment padding. */
298 bool afPadding[2];
299 /** Event semaphore that is scheduled to be signaled upon leaving the
300 * critical section. This is Ring-3 only of course. */
301 RTSEMEVENT EventToSignal;
302 /** The lock name. */
303 R3PTRTYPE(const char *) pszName;
304 /** R0/RC lock contention. */
305 STAMCOUNTER StatContentionRZLock;
306 /** R0/RC unlock contention. */
307 STAMCOUNTER StatContentionRZUnlock;
308 /** R3 lock contention. */
309 STAMCOUNTER StatContentionR3;
310 /** Profiling the time the section is locked. */
311 STAMPROFILEADV StatLocked;
312} PDMCRITSECTINT;
313AssertCompileMemberAlignment(PDMCRITSECTINT, StatContentionRZLock, 8);
314/** Pointer to private critical section data. */
315typedef PDMCRITSECTINT *PPDMCRITSECTINT;
316
317/** Indicates that the critical section is queued for unlock.
318 * PDMCritSectIsOwner and PDMCritSectIsOwned optimizations. */
319#define PDMCRITSECT_FLAGS_PENDING_UNLOCK RT_BIT_32(17)
320
321
322/**
323 * Private critical section data.
324 */
325typedef struct PDMCRITSECTRWINT
326{
327 /** The read/write critical section core which is shared with IPRT.
328 * @note The semaphores are SUPSEMEVENT and SUPSEMEVENTMULTI. */
329 RTCRITSECTRW Core;
330
331 /** Pointer to the next critical section.
332 * This chain is used for relocating pVMRC and device cleanup. */
333 R3PTRTYPE(struct PDMCRITSECTRWINT *) pNext;
334 /** Owner identifier.
335 * This is pDevIns if the owner is a device. Similarly for a driver or service.
336 * PDMR3CritSectInit() sets this to point to the critsect itself. */
337 RTR3PTR pvKey;
338 /** Pointer to the VM - R3Ptr. */
339 PVMR3 pVMR3;
340 /** Pointer to the VM - R0Ptr. */
341 PVMR0 pVMR0;
342 /** Pointer to the VM - GCPtr. */
343 PVMRC pVMRC;
344#if HC_ARCH_BITS == 64
345 /** Alignment padding. */
346 RTRCPTR RCPtrPadding;
347#endif
348 /** The lock name. */
349 R3PTRTYPE(const char *) pszName;
350 /** R0/RC write lock contention. */
351 STAMCOUNTER StatContentionRZEnterExcl;
352 /** R0/RC write unlock contention. */
353 STAMCOUNTER StatContentionRZLeaveExcl;
354 /** R0/RC read lock contention. */
355 STAMCOUNTER StatContentionRZEnterShared;
356 /** R0/RC read unlock contention. */
357 STAMCOUNTER StatContentionRZLeaveShared;
358 /** R0/RC writes. */
359 STAMCOUNTER StatRZEnterExcl;
360 /** R0/RC reads. */
361 STAMCOUNTER StatRZEnterShared;
362 /** R3 write lock contention. */
363 STAMCOUNTER StatContentionR3EnterExcl;
364 /** R3 read lock contention. */
365 STAMCOUNTER StatContentionR3EnterShared;
366 /** R3 writes. */
367 STAMCOUNTER StatR3EnterExcl;
368 /** R3 reads. */
369 STAMCOUNTER StatR3EnterShared;
370 /** Profiling the time the section is write locked. */
371 STAMPROFILEADV StatWriteLocked;
372} PDMCRITSECTRWINT;
373AssertCompileMemberAlignment(PDMCRITSECTRWINT, StatContentionRZEnterExcl, 8);
374AssertCompileMemberAlignment(PDMCRITSECTRWINT, Core.u64State, 8);
375/** Pointer to private critical section data. */
376typedef PDMCRITSECTRWINT *PPDMCRITSECTRWINT;
377
378
379
380/**
381 * The usual device/driver/internal/external stuff.
382 */
383typedef enum
384{
385 /** The usual invalid entry. */
386 PDMTHREADTYPE_INVALID = 0,
387 /** Device type. */
388 PDMTHREADTYPE_DEVICE,
389 /** USB Device type. */
390 PDMTHREADTYPE_USB,
391 /** Driver type. */
392 PDMTHREADTYPE_DRIVER,
393 /** Internal type. */
394 PDMTHREADTYPE_INTERNAL,
395 /** External type. */
396 PDMTHREADTYPE_EXTERNAL,
397 /** The usual 32-bit hack. */
398 PDMTHREADTYPE_32BIT_HACK = 0x7fffffff
399} PDMTHREADTYPE;
400
401
402/**
403 * The internal structure for the thread.
404 */
405typedef struct PDMTHREADINT
406{
407 /** The VM pointer. */
408 PVMR3 pVM;
409 /** The event semaphore the thread blocks on when not running. */
410 RTSEMEVENTMULTI BlockEvent;
411 /** The event semaphore the thread sleeps on while running. */
412 RTSEMEVENTMULTI SleepEvent;
413 /** Pointer to the next thread. */
414 R3PTRTYPE(struct PDMTHREAD *) pNext;
415 /** The thread type. */
416 PDMTHREADTYPE enmType;
417} PDMTHREADINT;
418
419
420
421/* Must be included after PDMDEVINSINT is defined. */
422#define PDMDEVINSINT_DECLARED
423#define PDMUSBINSINT_DECLARED
424#define PDMDRVINSINT_DECLARED
425#define PDMCRITSECTINT_DECLARED
426#define PDMCRITSECTRWINT_DECLARED
427#define PDMTHREADINT_DECLARED
428#ifdef ___VBox_pdm_h
429# error "Invalid header PDM order. Include PDMInternal.h before VBox/vmm/pdm.h!"
430#endif
431RT_C_DECLS_END
432#include <VBox/vmm/pdm.h>
433RT_C_DECLS_BEGIN
434
435/**
436 * PDM Logical Unit.
437 *
438 * This typically the representation of a physical port on a
439 * device, like for instance the PS/2 keyboard port on the
440 * keyboard controller device. The LUNs are chained on the
441 * device the belong to (PDMDEVINSINT::pLunsR3).
442 */
443typedef struct PDMLUN
444{
445 /** The LUN - The Logical Unit Number. */
446 RTUINT iLun;
447 /** Pointer to the next LUN. */
448 PPDMLUN pNext;
449 /** Pointer to the top driver in the driver chain. */
450 PPDMDRVINS pTop;
451 /** Pointer to the bottom driver in the driver chain. */
452 PPDMDRVINS pBottom;
453 /** Pointer to the device instance which the LUN belongs to.
454 * Either this is set or pUsbIns is set. Both is never set at the same time. */
455 PPDMDEVINS pDevIns;
456 /** Pointer to the USB device instance which the LUN belongs to. */
457 PPDMUSBINS pUsbIns;
458 /** Pointer to the device base interface. */
459 PPDMIBASE pBase;
460 /** Description of this LUN. */
461 const char *pszDesc;
462} PDMLUN;
463
464
465/**
466 * PDM Device.
467 */
468typedef struct PDMDEV
469{
470 /** Pointer to the next device (R3 Ptr). */
471 R3PTRTYPE(PPDMDEV) pNext;
472 /** Device name length. (search optimization) */
473 RTUINT cchName;
474 /** Registration structure. */
475 R3PTRTYPE(const struct PDMDEVREG *) pReg;
476 /** Number of instances. */
477 uint32_t cInstances;
478 /** Pointer to chain of instances (R3 Ptr). */
479 PPDMDEVINSR3 pInstances;
480 /** The search path for raw-mode context modules (';' as separator). */
481 char *pszRCSearchPath;
482 /** The search path for ring-0 context modules (';' as separator). */
483 char *pszR0SearchPath;
484} PDMDEV;
485
486
487/**
488 * PDM USB Device.
489 */
490typedef struct PDMUSB
491{
492 /** Pointer to the next device (R3 Ptr). */
493 R3PTRTYPE(PPDMUSB) pNext;
494 /** Device name length. (search optimization) */
495 RTUINT cchName;
496 /** Registration structure. */
497 R3PTRTYPE(const struct PDMUSBREG *) pReg;
498 /** Next instance number. */
499 uint32_t iNextInstance;
500 /** Pointer to chain of instances (R3 Ptr). */
501 R3PTRTYPE(PPDMUSBINS) pInstances;
502} PDMUSB;
503
504
505/**
506 * PDM Driver.
507 */
508typedef struct PDMDRV
509{
510 /** Pointer to the next device. */
511 PPDMDRV pNext;
512 /** Registration structure. */
513 const struct PDMDRVREG * pReg;
514 /** Current number of instances. */
515 uint32_t cInstances;
516 /** The next instance number. */
517 uint32_t iNextInstance;
518 /** The search path for raw-mode context modules (';' as separator). */
519 char *pszRCSearchPath;
520 /** The search path for ring-0 context modules (';' as separator). */
521 char *pszR0SearchPath;
522} PDMDRV;
523
524
525/**
526 * PDM registered PIC device.
527 */
528typedef struct PDMPIC
529{
530 /** Pointer to the PIC device instance - R3. */
531 PPDMDEVINSR3 pDevInsR3;
532 /** @copydoc PDMPICREG::pfnSetIrqR3 */
533 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
534 /** @copydoc PDMPICREG::pfnGetInterruptR3 */
535 DECLR3CALLBACKMEMBER(int, pfnGetInterruptR3,(PPDMDEVINS pDevIns, uint32_t *puTagSrc));
536
537 /** Pointer to the PIC device instance - R0. */
538 PPDMDEVINSR0 pDevInsR0;
539 /** @copydoc PDMPICREG::pfnSetIrqR3 */
540 DECLR0CALLBACKMEMBER(void, pfnSetIrqR0,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
541 /** @copydoc PDMPICREG::pfnGetInterruptR3 */
542 DECLR0CALLBACKMEMBER(int, pfnGetInterruptR0,(PPDMDEVINS pDevIns, uint32_t *puTagSrc));
543
544 /** Pointer to the PIC device instance - RC. */
545 PPDMDEVINSRC pDevInsRC;
546 /** @copydoc PDMPICREG::pfnSetIrqR3 */
547 DECLRCCALLBACKMEMBER(void, pfnSetIrqRC,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
548 /** @copydoc PDMPICREG::pfnGetInterruptR3 */
549 DECLRCCALLBACKMEMBER(int, pfnGetInterruptRC,(PPDMDEVINS pDevIns, uint32_t *puTagSrc));
550 /** Alignment padding. */
551 RTRCPTR RCPtrPadding;
552} PDMPIC;
553
554
555/**
556 * PDM registered APIC device.
557 */
558typedef struct PDMAPIC
559{
560 /** Pointer to the APIC device instance - R3 Ptr. */
561 PPDMDEVINSR3 pDevInsR3;
562 /** @copydoc PDMAPICREG::pfnGetInterruptR3 */
563 DECLR3CALLBACKMEMBER(int, pfnGetInterruptR3,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t *puTagSrc));
564 /** @copydoc PDMAPICREG::pfnHasPendingIrqR3 */
565 DECLR3CALLBACKMEMBER(bool, pfnHasPendingIrqR3,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint8_t *pu8PendingIrq));
566 /** @copydoc PDMAPICREG::pfnSetBaseR3 */
567 DECLR3CALLBACKMEMBER(void, pfnSetBaseR3,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint64_t u64Base));
568 /** @copydoc PDMAPICREG::pfnGetBaseR3 */
569 DECLR3CALLBACKMEMBER(uint64_t, pfnGetBaseR3,(PPDMDEVINS pDevIns, VMCPUID idCpu));
570 /** @copydoc PDMAPICREG::pfnSetTPRR3 */
571 DECLR3CALLBACKMEMBER(void, pfnSetTPRR3,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint8_t u8TPR));
572 /** @copydoc PDMAPICREG::pfnGetTPRR3 */
573 DECLR3CALLBACKMEMBER(uint8_t, pfnGetTPRR3,(PPDMDEVINS pDevIns, VMCPUID idCpu));
574 /** @copydoc PDMAPICREG::pfnWriteMSRR3 */
575 DECLR3CALLBACKMEMBER(int, pfnWriteMSRR3, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t u64Value));
576 /** @copydoc PDMAPICREG::pfnReadMSRR3 */
577 DECLR3CALLBACKMEMBER(int, pfnReadMSRR3, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t *pu64Value));
578 /** @copydoc PDMAPICREG::pfnBusDeliverR3 */
579 DECLR3CALLBACKMEMBER(int, pfnBusDeliverR3,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
580 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
581 /** @copydoc PDMAPICREG::pfnLocalInterruptR3 */
582 DECLR3CALLBACKMEMBER(int, pfnLocalInterruptR3,(PPDMDEVINS pDevIns, uint8_t u8Pin, uint8_t u8Level));
583
584 /** Pointer to the APIC device instance - R0 Ptr. */
585 PPDMDEVINSR0 pDevInsR0;
586 /** @copydoc PDMAPICREG::pfnGetInterruptR3 */
587 DECLR0CALLBACKMEMBER(int, pfnGetInterruptR0,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t *puTagSrc));
588 /** @copydoc PDMAPICREG::pfnHasPendingIrqR3 */
589 DECLR0CALLBACKMEMBER(bool, pfnHasPendingIrqR0,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint8_t *pu8PendingIrq));
590 /** @copydoc PDMAPICREG::pfnSetBaseR3 */
591 DECLR0CALLBACKMEMBER(void, pfnSetBaseR0,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint64_t u64Base));
592 /** @copydoc PDMAPICREG::pfnGetBaseR3 */
593 DECLR0CALLBACKMEMBER(uint64_t, pfnGetBaseR0,(PPDMDEVINS pDevIns, VMCPUID idCpu));
594 /** @copydoc PDMAPICREG::pfnSetTPRR3 */
595 DECLR0CALLBACKMEMBER(void, pfnSetTPRR0,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint8_t u8TPR));
596 /** @copydoc PDMAPICREG::pfnGetTPRR3 */
597 DECLR0CALLBACKMEMBER(uint8_t, pfnGetTPRR0,(PPDMDEVINS pDevIns, VMCPUID idCpu));
598 /** @copydoc PDMAPICREG::pfnWriteMSRR3 */
599 DECLR0CALLBACKMEMBER(uint32_t, pfnWriteMSRR0, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t u64Value));
600 /** @copydoc PDMAPICREG::pfnReadMSRR3 */
601 DECLR0CALLBACKMEMBER(uint32_t, pfnReadMSRR0, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t *pu64Value));
602 /** @copydoc PDMAPICREG::pfnBusDeliverR3 */
603 DECLR0CALLBACKMEMBER(int, pfnBusDeliverR0,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
604 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
605 /** @copydoc PDMAPICREG::pfnLocalInterruptR3 */
606 DECLR0CALLBACKMEMBER(int, pfnLocalInterruptR0,(PPDMDEVINS pDevIns, uint8_t u8Pin, uint8_t u8Level));
607
608 /** Pointer to the APIC device instance - RC Ptr. */
609 PPDMDEVINSRC pDevInsRC;
610 /** @copydoc PDMAPICREG::pfnGetInterruptR3 */
611 DECLRCCALLBACKMEMBER(int, pfnGetInterruptRC,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t *puTagSrc));
612 /** @copydoc PDMAPICREG::pfnHasPendingIrqR3 */
613 DECLRCCALLBACKMEMBER(bool, pfnHasPendingIrqRC,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint8_t *pu8PendingIrq));
614 /** @copydoc PDMAPICREG::pfnSetBaseR3 */
615 DECLRCCALLBACKMEMBER(void, pfnSetBaseRC,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint64_t u64Base));
616 /** @copydoc PDMAPICREG::pfnGetBaseR3 */
617 DECLRCCALLBACKMEMBER(uint64_t, pfnGetBaseRC,(PPDMDEVINS pDevIns, VMCPUID idCpu));
618 /** @copydoc PDMAPICREG::pfnSetTPRR3 */
619 DECLRCCALLBACKMEMBER(void, pfnSetTPRRC,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint8_t u8TPR));
620 /** @copydoc PDMAPICREG::pfnGetTPRR3 */
621 DECLRCCALLBACKMEMBER(uint8_t, pfnGetTPRRC,(PPDMDEVINS pDevIns, VMCPUID idCpu));
622 /** @copydoc PDMAPICREG::pfnWriteMSRR3 */
623 DECLRCCALLBACKMEMBER(uint32_t, pfnWriteMSRRC, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t u64Value));
624 /** @copydoc PDMAPICREG::pfnReadMSRR3 */
625 DECLRCCALLBACKMEMBER(uint32_t, pfnReadMSRRC, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t *pu64Value));
626 /** @copydoc PDMAPICREG::pfnBusDeliverR3 */
627 DECLRCCALLBACKMEMBER(int, pfnBusDeliverRC,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
628 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
629 /** @copydoc PDMAPICREG::pfnLocalInterruptR3 */
630 DECLRCCALLBACKMEMBER(int, pfnLocalInterruptRC,(PPDMDEVINS pDevIns, uint8_t u8Pin, uint8_t u8Level));
631 RTRCPTR RCPtrAlignment;
632
633} PDMAPIC;
634
635
636/**
637 * PDM registered I/O APIC device.
638 */
639typedef struct PDMIOAPIC
640{
641 /** Pointer to the APIC device instance - R3 Ptr. */
642 PPDMDEVINSR3 pDevInsR3;
643 /** @copydoc PDMIOAPICREG::pfnSetIrqR3 */
644 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
645 /** @copydoc PDMIOAPICREG::pfnSendMsiR3 */
646 DECLR3CALLBACKMEMBER(void, pfnSendMsiR3,(PPDMDEVINS pDevIns, RTGCPHYS GCAddr, uint32_t uValue, uint32_t uTagSrc));
647
648 /** Pointer to the PIC device instance - R0. */
649 PPDMDEVINSR0 pDevInsR0;
650 /** @copydoc PDMIOAPICREG::pfnSetIrqR3 */
651 DECLR0CALLBACKMEMBER(void, pfnSetIrqR0,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
652 /** @copydoc PDMIOAPICREG::pfnSendMsiR3 */
653 DECLR0CALLBACKMEMBER(void, pfnSendMsiR0,(PPDMDEVINS pDevIns, RTGCPHYS GCAddr, uint32_t uValue, uint32_t uTagSrc));
654
655 /** Pointer to the APIC device instance - RC Ptr. */
656 PPDMDEVINSRC pDevInsRC;
657 /** @copydoc PDMIOAPICREG::pfnSetIrqR3 */
658 DECLRCCALLBACKMEMBER(void, pfnSetIrqRC,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
659 /** @copydoc PDMIOAPICREG::pfnSendMsiR3 */
660 DECLRCCALLBACKMEMBER(void, pfnSendMsiRC,(PPDMDEVINS pDevIns, RTGCPHYS GCAddr, uint32_t uValue, uint32_t uTagSrc));
661
662 uint8_t Alignment[4];
663} PDMIOAPIC;
664
665/** Maximum number of PCI busses for a VM. */
666#define PDM_PCI_BUSSES_MAX 8
667
668/**
669 * PDM PCI Bus instance.
670 */
671typedef struct PDMPCIBUS
672{
673 /** PCI bus number. */
674 RTUINT iBus;
675 RTUINT uPadding0; /**< Alignment padding.*/
676
677 /** Pointer to PCI Bus device instance. */
678 PPDMDEVINSR3 pDevInsR3;
679 /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
680 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
681 /** @copydoc PDMPCIBUSREG::pfnRegisterR3 */
682 DECLR3CALLBACKMEMBER(int, pfnRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev));
683 /** @copydoc PDMPCIBUSREG::pfnPCIRegisterMsiR3 */
684 DECLR3CALLBACKMEMBER(int, pfnRegisterMsiR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PPDMMSIREG pMsiReg));
685 /** @copydoc PDMPCIBUSREG::pfnIORegionRegisterR3 */
686 DECLR3CALLBACKMEMBER(int, pfnIORegionRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion,
687 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
688 /** @copydoc PDMPCIBUSREG::pfnSetConfigCallbacksR3 */
689 DECLR3CALLBACKMEMBER(void, pfnSetConfigCallbacksR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead,
690 PPFNPCICONFIGREAD ppfnReadOld, PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
691 /** @copydoc PDMPCIBUSREG::pfnFakePCIBIOSR3 */
692 DECLR3CALLBACKMEMBER(int, pfnFakePCIBIOSR3,(PPDMDEVINS pDevIns));
693
694 /** Pointer to the PIC device instance - R0. */
695 R0PTRTYPE(PPDMDEVINS) pDevInsR0;
696 /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
697 DECLR0CALLBACKMEMBER(void, pfnSetIrqR0,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
698
699 /** Pointer to PCI Bus device instance. */
700 PPDMDEVINSRC pDevInsRC;
701 /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
702 DECLRCCALLBACKMEMBER(void, pfnSetIrqRC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
703} PDMPCIBUS;
704
705
706#ifdef IN_RING3
707/**
708 * PDM registered DMAC (DMA Controller) device.
709 */
710typedef struct PDMDMAC
711{
712 /** Pointer to the DMAC device instance. */
713 PPDMDEVINSR3 pDevIns;
714 /** Copy of the registration structure. */
715 PDMDMACREG Reg;
716} PDMDMAC;
717
718
719/**
720 * PDM registered RTC (Real Time Clock) device.
721 */
722typedef struct PDMRTC
723{
724 /** Pointer to the RTC device instance. */
725 PPDMDEVINSR3 pDevIns;
726 /** Copy of the registration structure. */
727 PDMRTCREG Reg;
728} PDMRTC;
729
730#endif /* IN_RING3 */
731
732/**
733 * Module type.
734 */
735typedef enum PDMMODTYPE
736{
737 /** Raw-mode (RC) context module. */
738 PDMMOD_TYPE_RC,
739 /** Ring-0 (host) context module. */
740 PDMMOD_TYPE_R0,
741 /** Ring-3 (host) context module. */
742 PDMMOD_TYPE_R3
743} PDMMODTYPE;
744
745
746/** The module name length including the terminator. */
747#define PDMMOD_NAME_LEN 32
748
749/**
750 * Loaded module instance.
751 */
752typedef struct PDMMOD
753{
754 /** Module name. This is used for referring to
755 * the module internally, sort of like a handle. */
756 char szName[PDMMOD_NAME_LEN];
757 /** Module type. */
758 PDMMODTYPE eType;
759 /** Loader module handle. Not used for R0 modules. */
760 RTLDRMOD hLdrMod;
761 /** Loaded address.
762 * This is the 'handle' for R0 modules. */
763 RTUINTPTR ImageBase;
764 /** Old loaded address.
765 * This is used during relocation of GC modules. Not used for R0 modules. */
766 RTUINTPTR OldImageBase;
767 /** Where the R3 HC bits are stored.
768 * This can be equal to ImageBase but doesn't have to. Not used for R0 modules. */
769 void *pvBits;
770
771 /** Pointer to next module. */
772 struct PDMMOD *pNext;
773 /** Module filename. */
774 char szFilename[1];
775} PDMMOD;
776/** Pointer to loaded module instance. */
777typedef PDMMOD *PPDMMOD;
778
779
780
781/** Extra space in the free array. */
782#define PDMQUEUE_FREE_SLACK 16
783
784/**
785 * Queue type.
786 */
787typedef enum PDMQUEUETYPE
788{
789 /** Device consumer. */
790 PDMQUEUETYPE_DEV = 1,
791 /** Driver consumer. */
792 PDMQUEUETYPE_DRV,
793 /** Internal consumer. */
794 PDMQUEUETYPE_INTERNAL,
795 /** External consumer. */
796 PDMQUEUETYPE_EXTERNAL
797} PDMQUEUETYPE;
798
799/** Pointer to a PDM Queue. */
800typedef struct PDMQUEUE *PPDMQUEUE;
801
802/**
803 * PDM Queue.
804 */
805typedef struct PDMQUEUE
806{
807 /** Pointer to the next queue in the list. */
808 R3PTRTYPE(PPDMQUEUE) pNext;
809 /** Type specific data. */
810 union
811 {
812 /** PDMQUEUETYPE_DEV */
813 struct
814 {
815 /** Pointer to consumer function. */
816 R3PTRTYPE(PFNPDMQUEUEDEV) pfnCallback;
817 /** Pointer to the device instance owning the queue. */
818 R3PTRTYPE(PPDMDEVINS) pDevIns;
819 } Dev;
820 /** PDMQUEUETYPE_DRV */
821 struct
822 {
823 /** Pointer to consumer function. */
824 R3PTRTYPE(PFNPDMQUEUEDRV) pfnCallback;
825 /** Pointer to the driver instance owning the queue. */
826 R3PTRTYPE(PPDMDRVINS) pDrvIns;
827 } Drv;
828 /** PDMQUEUETYPE_INTERNAL */
829 struct
830 {
831 /** Pointer to consumer function. */
832 R3PTRTYPE(PFNPDMQUEUEINT) pfnCallback;
833 } Int;
834 /** PDMQUEUETYPE_EXTERNAL */
835 struct
836 {
837 /** Pointer to consumer function. */
838 R3PTRTYPE(PFNPDMQUEUEEXT) pfnCallback;
839 /** Pointer to user argument. */
840 R3PTRTYPE(void *) pvUser;
841 } Ext;
842 } u;
843 /** Queue type. */
844 PDMQUEUETYPE enmType;
845 /** The interval between checking the queue for events.
846 * The realtime timer below is used to do the waiting.
847 * If 0, the queue will use the VM_FF_PDM_QUEUE forced action. */
848 uint32_t cMilliesInterval;
849 /** Interval timer. Only used if cMilliesInterval is non-zero. */
850 PTMTIMERR3 pTimer;
851 /** Pointer to the VM - R3. */
852 PVMR3 pVMR3;
853 /** LIFO of pending items - R3. */
854 R3PTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingR3;
855 /** Pointer to the VM - R0. */
856 PVMR0 pVMR0;
857 /** LIFO of pending items - R0. */
858 R0PTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingR0;
859 /** Pointer to the GC VM and indicator for GC enabled queue.
860 * If this is NULL, the queue cannot be used in GC.
861 */
862 PVMRC pVMRC;
863 /** LIFO of pending items - GC. */
864 RCPTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingRC;
865
866 /** Item size (bytes). */
867 uint32_t cbItem;
868 /** Number of items in the queue. */
869 uint32_t cItems;
870 /** Index to the free head (where we insert). */
871 uint32_t volatile iFreeHead;
872 /** Index to the free tail (where we remove). */
873 uint32_t volatile iFreeTail;
874
875 /** Unique queue name. */
876 R3PTRTYPE(const char *) pszName;
877#if HC_ARCH_BITS == 32
878 RTR3PTR Alignment1;
879#endif
880 /** Stat: Times PDMQueueAlloc fails. */
881 STAMCOUNTER StatAllocFailures;
882 /** Stat: PDMQueueInsert calls. */
883 STAMCOUNTER StatInsert;
884 /** Stat: Queue flushes. */
885 STAMCOUNTER StatFlush;
886 /** Stat: Queue flushes with pending items left over. */
887 STAMCOUNTER StatFlushLeftovers;
888#ifdef VBOX_WITH_STATISTICS
889 /** State: Profiling the flushing. */
890 STAMPROFILE StatFlushPrf;
891 /** State: Pending items. */
892 uint32_t volatile cStatPending;
893 uint32_t volatile cAlignment;
894#endif
895
896 /** Array of pointers to free items. Variable size. */
897 struct PDMQUEUEFREEITEM
898 {
899 /** Pointer to the free item - HC Ptr. */
900 R3PTRTYPE(PPDMQUEUEITEMCORE) volatile pItemR3;
901 /** Pointer to the free item - HC Ptr. */
902 R0PTRTYPE(PPDMQUEUEITEMCORE) volatile pItemR0;
903 /** Pointer to the free item - GC Ptr. */
904 RCPTRTYPE(PPDMQUEUEITEMCORE) volatile pItemRC;
905#if HC_ARCH_BITS == 64
906 RTRCPTR Alignment0;
907#endif
908 } aFreeItems[1];
909} PDMQUEUE;
910
911/** @name PDM::fQueueFlushing
912 * @{ */
913/** Used to make sure only one EMT will flush the queues.
914 * Set when an EMT is flushing queues, clear otherwise. */
915#define PDM_QUEUE_FLUSH_FLAG_ACTIVE_BIT 0
916/** Indicating there are queues with items pending.
917 * This is make sure we don't miss inserts happening during flushing. The FF
918 * cannot be used for this since it has to be cleared immediately to prevent
919 * other EMTs from spinning. */
920#define PDM_QUEUE_FLUSH_FLAG_PENDING_BIT 1
921/** }@ */
922
923
924/**
925 * Queue device helper task operation.
926 */
927typedef enum PDMDEVHLPTASKOP
928{
929 /** The usual invalid 0 entry. */
930 PDMDEVHLPTASKOP_INVALID = 0,
931 /** ISASetIrq */
932 PDMDEVHLPTASKOP_ISA_SET_IRQ,
933 /** PCISetIrq */
934 PDMDEVHLPTASKOP_PCI_SET_IRQ,
935 /** PCISetIrq */
936 PDMDEVHLPTASKOP_IOAPIC_SET_IRQ,
937 /** The usual 32-bit hack. */
938 PDMDEVHLPTASKOP_32BIT_HACK = 0x7fffffff
939} PDMDEVHLPTASKOP;
940
941/**
942 * Queued Device Helper Task.
943 */
944typedef struct PDMDEVHLPTASK
945{
946 /** The queue item core (don't touch). */
947 PDMQUEUEITEMCORE Core;
948 /** Pointer to the device instance (R3 Ptr). */
949 PPDMDEVINSR3 pDevInsR3;
950 /** This operation to perform. */
951 PDMDEVHLPTASKOP enmOp;
952#if HC_ARCH_BITS == 64
953 uint32_t Alignment0;
954#endif
955 /** Parameters to the operation. */
956 union PDMDEVHLPTASKPARAMS
957 {
958 /**
959 * PDMDEVHLPTASKOP_ISA_SET_IRQ and PDMDEVHLPTASKOP_PCI_SET_IRQ.
960 */
961 struct PDMDEVHLPTASKSETIRQ
962 {
963 /** The IRQ */
964 int iIrq;
965 /** The new level. */
966 int iLevel;
967 /** The IRQ tag and source. */
968 uint32_t uTagSrc;
969 } SetIRQ;
970
971 /** Expanding the structure.. */
972 uint64_t au64[2];
973 } u;
974} PDMDEVHLPTASK;
975/** Pointer to a queued Device Helper Task. */
976typedef PDMDEVHLPTASK *PPDMDEVHLPTASK;
977/** Pointer to a const queued Device Helper Task. */
978typedef const PDMDEVHLPTASK *PCPDMDEVHLPTASK;
979
980
981
982/**
983 * An USB hub registration record.
984 */
985typedef struct PDMUSBHUB
986{
987 /** The USB versions this hub support.
988 * Note that 1.1 hubs can take on 2.0 devices. */
989 uint32_t fVersions;
990 /** The number of ports on the hub. */
991 uint32_t cPorts;
992 /** The number of available ports (0..cPorts). */
993 uint32_t cAvailablePorts;
994 /** The driver instance of the hub. */
995 PPDMDRVINS pDrvIns;
996 /** Copy of the to the registration structure. */
997 PDMUSBHUBREG Reg;
998
999 /** Pointer to the next hub in the list. */
1000 struct PDMUSBHUB *pNext;
1001} PDMUSBHUB;
1002
1003/** Pointer to a const USB HUB registration record. */
1004typedef const PDMUSBHUB *PCPDMUSBHUB;
1005
1006/** Pointer to a PDM Async I/O template. */
1007typedef struct PDMASYNCCOMPLETIONTEMPLATE *PPDMASYNCCOMPLETIONTEMPLATE;
1008
1009/** Pointer to the main PDM Async completion endpoint class. */
1010typedef struct PDMASYNCCOMPLETIONEPCLASS *PPDMASYNCCOMPLETIONEPCLASS;
1011
1012/** Pointer to the global block cache structure. */
1013typedef struct PDMBLKCACHEGLOBAL *PPDMBLKCACHEGLOBAL;
1014
1015/**
1016 * PDM VMCPU Instance data.
1017 * Changes to this must checked against the padding of the pdm union in VMCPU!
1018 */
1019typedef struct PDMCPU
1020{
1021 /** The number of entries in the apQueuedCritSectsLeaves table that's currently
1022 * in use. */
1023 uint32_t cQueuedCritSectLeaves;
1024 uint32_t uPadding0; /**< Alignment padding.*/
1025 /** Critical sections queued in RC/R0 because of contention preventing leave to
1026 * complete. (R3 Ptrs)
1027 * We will return to Ring-3 ASAP, so this queue doesn't have to be very long. */
1028 R3PTRTYPE(PPDMCRITSECT) apQueuedCritSectLeaves[8];
1029
1030 /** The number of entries in the apQueuedCritSectRwExclLeaves table that's
1031 * currently in use. */
1032 uint32_t cQueuedCritSectRwExclLeaves;
1033 uint32_t uPadding1; /**< Alignment padding.*/
1034 /** Read/write critical sections queued in RC/R0 because of contention
1035 * preventing exclusive leave to complete. (R3 Ptrs)
1036 * We will return to Ring-3 ASAP, so this queue doesn't have to be very long. */
1037 R3PTRTYPE(PPDMCRITSECTRW) apQueuedCritSectRwExclLeaves[8];
1038
1039 /** The number of entries in the apQueuedCritSectsRwShrdLeaves table that's
1040 * currently in use. */
1041 uint32_t cQueuedCritSectRwShrdLeaves;
1042 uint32_t uPadding2; /**< Alignment padding.*/
1043 /** Read/write critical sections queued in RC/R0 because of contention
1044 * preventing shared leave to complete. (R3 Ptrs)
1045 * We will return to Ring-3 ASAP, so this queue doesn't have to be very long. */
1046 R3PTRTYPE(PPDMCRITSECTRW) apQueuedCritSectRwShrdLeaves[8];
1047} PDMCPU;
1048
1049
1050/**
1051 * PDM VM Instance data.
1052 * Changes to this must checked against the padding of the cfgm union in VM!
1053 */
1054typedef struct PDM
1055{
1056 /** The PDM lock.
1057 * This is used to protect everything that deals with interrupts, i.e.
1058 * the PIC, APIC, IOAPIC and PCI devices plus some PDM functions. */
1059 PDMCRITSECT CritSect;
1060 /** The NOP critical section.
1061 * This is a dummy critical section that will not do any thread
1062 * serialization but instead let all threads enter immediately and
1063 * concurrently. */
1064 PDMCRITSECT NopCritSect;
1065
1066 /** List of registered devices. (FIFO) */
1067 R3PTRTYPE(PPDMDEV) pDevs;
1068 /** List of devices instances. (FIFO) */
1069 R3PTRTYPE(PPDMDEVINS) pDevInstances;
1070 /** List of registered USB devices. (FIFO) */
1071 R3PTRTYPE(PPDMUSB) pUsbDevs;
1072 /** List of USB devices instances. (FIFO) */
1073 R3PTRTYPE(PPDMUSBINS) pUsbInstances;
1074 /** List of registered drivers. (FIFO) */
1075 R3PTRTYPE(PPDMDRV) pDrvs;
1076 /** PCI Buses. */
1077 PDMPCIBUS aPciBuses[PDM_PCI_BUSSES_MAX];
1078 /** The register PIC device. */
1079 PDMPIC Pic;
1080 /** The registered APIC device. */
1081 PDMAPIC Apic;
1082 /** The registered I/O APIC device. */
1083 PDMIOAPIC IoApic;
1084 /** The registered DMAC device. */
1085 R3PTRTYPE(PPDMDMAC) pDmac;
1086 /** The registered RTC device. */
1087 R3PTRTYPE(PPDMRTC) pRtc;
1088 /** The registered USB HUBs. (FIFO) */
1089 R3PTRTYPE(PPDMUSBHUB) pUsbHubs;
1090
1091 /** Queue in which devhlp tasks are queued for R3 execution - R3 Ptr. */
1092 R3PTRTYPE(PPDMQUEUE) pDevHlpQueueR3;
1093 /** Queue in which devhlp tasks are queued for R3 execution - R0 Ptr. */
1094 R0PTRTYPE(PPDMQUEUE) pDevHlpQueueR0;
1095 /** Queue in which devhlp tasks are queued for R3 execution - RC Ptr. */
1096 RCPTRTYPE(PPDMQUEUE) pDevHlpQueueRC;
1097 /** Pointer to the queue which should be manually flushed - RC Ptr.
1098 * Only touched by EMT. */
1099 RCPTRTYPE(struct PDMQUEUE *) pQueueFlushRC;
1100 /** Pointer to the queue which should be manually flushed - R0 Ptr.
1101 * Only touched by EMT. */
1102 R0PTRTYPE(struct PDMQUEUE *) pQueueFlushR0;
1103 /** Bitmask controlling the queue flushing.
1104 * See PDM_QUEUE_FLUSH_FLAG_ACTIVE and PDM_QUEUE_FLUSH_FLAG_PENDING. */
1105 uint32_t volatile fQueueFlushing;
1106
1107 /** The current IRQ tag (tracing purposes). */
1108 uint32_t volatile uIrqTag;
1109
1110 /** The tracing ID of the next device instance.
1111 *
1112 * @remarks We keep the device tracing ID seperate from the rest as these are
1113 * then more likely to end up with the same ID from one run to
1114 * another, making analysis somewhat easier. Drivers and USB devices
1115 * are more volatile and can be changed at runtime, thus these are much
1116 * less likely to remain stable, so just heap them all together. */
1117 uint32_t idTracingDev;
1118 /** The tracing ID of the next driver instance, USB device instance or other
1119 * PDM entity requiring an ID. */
1120 uint32_t idTracingOther;
1121
1122 /** @name VMM device heap
1123 * @{ */
1124 /** Pointer to the heap base (MMIO2 ring-3 mapping). NULL if not registered. */
1125 RTR3PTR pvVMMDevHeap;
1126 /** The heap size. */
1127 uint32_t cbVMMDevHeap;
1128 /** Free space. */
1129 uint32_t cbVMMDevHeapLeft;
1130 /** The current mapping. NIL_RTGCPHYS if not mapped or registered. */
1131 RTGCPHYS GCPhysVMMDevHeap;
1132 /** @} */
1133
1134 /** Number of times a critical section leave request needed to be queued for ring-3 execution. */
1135 STAMCOUNTER StatQueuedCritSectLeaves;
1136} PDM;
1137AssertCompileMemberAlignment(PDM, GCPhysVMMDevHeap, sizeof(RTGCPHYS));
1138AssertCompileMemberAlignment(PDM, CritSect, 8);
1139AssertCompileMemberAlignment(PDM, StatQueuedCritSectLeaves, 8);
1140/** Pointer to PDM VM instance data. */
1141typedef PDM *PPDM;
1142
1143
1144
1145/**
1146 * PDM data kept in the UVM.
1147 */
1148typedef struct PDMUSERPERVM
1149{
1150 /** @todo move more stuff over here. */
1151
1152 /** Linked list of timer driven PDM queues.
1153 * Currently serialized by PDM::CritSect. */
1154 R3PTRTYPE(struct PDMQUEUE *) pQueuesTimer;
1155 /** Linked list of force action driven PDM queues.
1156 * Currently serialized by PDM::CritSect. */
1157 R3PTRTYPE(struct PDMQUEUE *) pQueuesForced;
1158
1159 /** Lock protecting the lists below it. */
1160 RTCRITSECT ListCritSect;
1161 /** Pointer to list of loaded modules. */
1162 PPDMMOD pModules;
1163 /** List of initialized critical sections. (LIFO) */
1164 R3PTRTYPE(PPDMCRITSECTINT) pCritSects;
1165 /** List of initialized read/write critical sections. (LIFO) */
1166 R3PTRTYPE(PPDMCRITSECTRWINT) pRwCritSects;
1167 /** Head of the PDM Thread list. (singly linked) */
1168 R3PTRTYPE(PPDMTHREAD) pThreads;
1169 /** Tail of the PDM Thread list. (singly linked) */
1170 R3PTRTYPE(PPDMTHREAD) pThreadsTail;
1171
1172 /** @name PDM Async Completion
1173 * @{ */
1174 /** Pointer to the array of supported endpoint classes. */
1175 PPDMASYNCCOMPLETIONEPCLASS apAsyncCompletionEndpointClass[PDMASYNCCOMPLETIONEPCLASSTYPE_MAX];
1176 /** Head of the templates. Singly linked, protected by ListCritSect. */
1177 R3PTRTYPE(PPDMASYNCCOMPLETIONTEMPLATE) pAsyncCompletionTemplates;
1178 /** @} */
1179
1180 /** Global block cache data. */
1181 R3PTRTYPE(PPDMBLKCACHEGLOBAL) pBlkCacheGlobal;
1182#ifdef VBOX_WITH_NETSHAPER
1183 /** Pointer to network shaper instance. */
1184 R3PTRTYPE(PPDMNETSHAPER) pNetShaper;
1185#endif /* VBOX_WITH_NETSHAPER */
1186
1187} PDMUSERPERVM;
1188/** Pointer to the PDM data kept in the UVM. */
1189typedef PDMUSERPERVM *PPDMUSERPERVM;
1190
1191
1192
1193/*******************************************************************************
1194* Global Variables *
1195*******************************************************************************/
1196#ifdef IN_RING3
1197extern const PDMDRVHLPR3 g_pdmR3DrvHlp;
1198extern const PDMDEVHLPR3 g_pdmR3DevHlpTrusted;
1199extern const PDMDEVHLPR3 g_pdmR3DevHlpUnTrusted;
1200extern const PDMPICHLPR3 g_pdmR3DevPicHlp;
1201extern const PDMAPICHLPR3 g_pdmR3DevApicHlp;
1202extern const PDMIOAPICHLPR3 g_pdmR3DevIoApicHlp;
1203extern const PDMPCIHLPR3 g_pdmR3DevPciHlp;
1204extern const PDMDMACHLP g_pdmR3DevDmacHlp;
1205extern const PDMRTCHLP g_pdmR3DevRtcHlp;
1206extern const PDMHPETHLPR3 g_pdmR3DevHpetHlp;
1207extern const PDMPCIRAWHLPR3 g_pdmR3DevPciRawHlp;
1208#endif
1209
1210
1211/*******************************************************************************
1212* Defined Constants And Macros *
1213*******************************************************************************/
1214/** @def PDMDEV_ASSERT_DEVINS
1215 * Asserts the validity of the device instance.
1216 */
1217#ifdef VBOX_STRICT
1218# define PDMDEV_ASSERT_DEVINS(pDevIns) \
1219 do { \
1220 AssertPtr(pDevIns); \
1221 Assert(pDevIns->u32Version == PDM_DEVINS_VERSION); \
1222 Assert(pDevIns->CTX_SUFF(pvInstanceData) == (void *)&pDevIns->achInstanceData[0]); \
1223 } while (0)
1224#else
1225# define PDMDEV_ASSERT_DEVINS(pDevIns) do { } while (0)
1226#endif
1227
1228/** @def PDMDRV_ASSERT_DRVINS
1229 * Asserts the validity of the driver instance.
1230 */
1231#ifdef VBOX_STRICT
1232# define PDMDRV_ASSERT_DRVINS(pDrvIns) \
1233 do { \
1234 AssertPtr(pDrvIns); \
1235 Assert(pDrvIns->u32Version == PDM_DRVINS_VERSION); \
1236 Assert(pDrvIns->CTX_SUFF(pvInstanceData) == (void *)&pDrvIns->achInstanceData[0]); \
1237 } while (0)
1238#else
1239# define PDMDRV_ASSERT_DRVINS(pDrvIns) do { } while (0)
1240#endif
1241
1242
1243/*******************************************************************************
1244* Internal Functions *
1245*******************************************************************************/
1246#ifdef IN_RING3
1247bool pdmR3IsValidName(const char *pszName);
1248
1249int pdmR3CritSectBothInitStats(PVM pVM);
1250void pdmR3CritSectBothRelocate(PVM pVM);
1251int pdmR3CritSectBothDeleteDevice(PVM pVM, PPDMDEVINS pDevIns);
1252int pdmR3CritSectBothDeleteDriver(PVM pVM, PPDMDRVINS pDrvIns);
1253int pdmR3CritSectInitDevice( PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
1254 const char *pszNameFmt, va_list va);
1255int pdmR3CritSectInitDeviceAuto( PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
1256 const char *pszNameFmt, ...);
1257int pdmR3CritSectInitDriver( PVM pVM, PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
1258 const char *pszNameFmt, ...);
1259int pdmR3CritSectRwInitDevice( PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL,
1260 const char *pszNameFmt, va_list va);
1261int pdmR3CritSectRwInitDeviceAuto( PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL,
1262 const char *pszNameFmt, ...);
1263int pdmR3CritSectRwInitDriver( PVM pVM, PPDMDRVINS pDrvIns, PPDMCRITSECTRW pCritSect, RT_SRC_POS_DECL,
1264 const char *pszNameFmt, ...);
1265
1266int pdmR3DevInit(PVM pVM);
1267PPDMDEV pdmR3DevLookup(PVM pVM, const char *pszName);
1268int pdmR3DevFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMLUN *ppLun);
1269DECLCALLBACK(bool) pdmR3DevHlpQueueConsumer(PVM pVM, PPDMQUEUEITEMCORE pItem);
1270
1271int pdmR3UsbLoadModules(PVM pVM);
1272int pdmR3UsbInstantiateDevices(PVM pVM);
1273PPDMUSB pdmR3UsbLookup(PVM pVM, const char *pszName);
1274int pdmR3UsbFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMLUN *ppLun);
1275int pdmR3UsbRegisterHub(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp);
1276int pdmR3UsbVMInitComplete(PVM pVM);
1277
1278int pdmR3DrvInit(PVM pVM);
1279int pdmR3DrvInstantiate(PVM pVM, PCFGMNODE pNode, PPDMIBASE pBaseInterface, PPDMDRVINS pDrvAbove,
1280 PPDMLUN pLun, PPDMIBASE *ppBaseInterface);
1281int pdmR3DrvDetach(PPDMDRVINS pDrvIns, uint32_t fFlags);
1282void pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns, uint32_t fFlags);
1283PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName);
1284
1285int pdmR3LdrInitU(PUVM pUVM);
1286void pdmR3LdrTermU(PUVM pUVM);
1287char *pdmR3FileR3(const char *pszFile, bool fShared);
1288int pdmR3LoadR3U(PUVM pUVM, const char *pszFilename, const char *pszName);
1289
1290void pdmR3QueueRelocate(PVM pVM, RTGCINTPTR offDelta);
1291
1292int pdmR3ThreadCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
1293 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
1294int pdmR3ThreadCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
1295 PFNPDMTHREADWAKEUPUSB pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
1296int pdmR3ThreadCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
1297 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
1298int pdmR3ThreadDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
1299int pdmR3ThreadDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
1300int pdmR3ThreadDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
1301void pdmR3ThreadDestroyAll(PVM pVM);
1302int pdmR3ThreadResumeAll(PVM pVM);
1303int pdmR3ThreadSuspendAll(PVM pVM);
1304
1305#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1306int pdmR3AsyncCompletionInit(PVM pVM);
1307int pdmR3AsyncCompletionTerm(PVM pVM);
1308void pdmR3AsyncCompletionResume(PVM pVM);
1309int pdmR3AsyncCompletionTemplateCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDEV pfnCompleted, const char *pszDesc);
1310int pdmR3AsyncCompletionTemplateCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
1311 PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser, const char *pszDesc);
1312int pdmR3AsyncCompletionTemplateCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEUSB pfnCompleted, const char *pszDesc);
1313int pdmR3AsyncCompletionTemplateDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
1314int pdmR3AsyncCompletionTemplateDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
1315int pdmR3AsyncCompletionTemplateDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
1316#endif
1317
1318#ifdef VBOX_WITH_NETSHAPER
1319int pdmR3NetShaperInit(PVM pVM);
1320int pdmR3NetShaperTerm(PVM pVM);
1321#endif
1322
1323int pdmR3BlkCacheInit(PVM pVM);
1324void pdmR3BlkCacheTerm(PVM pVM);
1325int pdmR3BlkCacheResume(PVM pVM);
1326
1327#endif /* IN_RING3 */
1328
1329void pdmLock(PVM pVM);
1330int pdmLockEx(PVM pVM, int rc);
1331void pdmUnlock(PVM pVM);
1332
1333#if defined(IN_RING3) || defined(IN_RING0)
1334void pdmCritSectRwLeaveSharedQueued(PPDMCRITSECTRW pThis);
1335void pdmCritSectRwLeaveExclQueued(PPDMCRITSECTRW pThis);
1336#endif
1337
1338/** @} */
1339
1340RT_C_DECLS_END
1341
1342#endif
1343
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