VirtualBox

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

Last change on this file since 32963 was 32935, checked in by vboxsync, 14 years ago

PDM, VMM, PCI: reworked MSI API: now MSIs delivered via IOAPIC API, not with MMIO access, LSI logic now can work in MSI mode

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