VirtualBox

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

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

64-bit GC alignment fixes

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