VirtualBox

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

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