VirtualBox

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

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

PDMUsb changes.

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