VirtualBox

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

Last change on this file since 12998 was 12985, checked in by vboxsync, 16 years ago

PDMQueue: pQueueFlushR3 isn't necessary.

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