VirtualBox

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

Last change on this file since 10507 was 10492, checked in by vboxsync, 16 years ago

Added PDMApicHasPendingIrq.

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