VirtualBox

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

Last change on this file since 4787 was 4787, checked in by vboxsync, 17 years ago

Eliminated HCPTRTYPE and replaced with R3R0PTRTYPE where necessary.

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