VirtualBox

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

Last change on this file since 12559 was 12324, checked in by vboxsync, 16 years ago

PDMThread: New API PDMR3ThreadSleep. Fixed a per thread event sem leak.

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