VirtualBox

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

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

Hooked up the PDMThread stuff.

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