VirtualBox

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

Last change on this file since 12016 was 11261, checked in by vboxsync, 16 years ago

#1865: DevPIC.

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