VirtualBox

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

Last change on this file since 13373 was 13189, checked in by vboxsync, 16 years ago

PCI: Add support for PCI-to-PCI bridges

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 37.8 KB
Line 
1/* $Id: PDMInternal.h 13189 2008-10-11 12:36:11Z 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/** Maximum number of PCI busses for a VM. */
487#define PDM_PCI_BUSSES_MAX 8
488
489/**
490 * PDM PCI Bus instance.
491 */
492typedef struct PDMPCIBUS
493{
494 /** PCI bus number. */
495 RTUINT iBus;
496 RTUINT uPadding0; /**< Alignment padding.*/
497
498 /** Pointer to PCI Bus device instance. */
499 PPDMDEVINSR3 pDevInsR3;
500 /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
501 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
502 /** @copydoc PDMPCIBUSREG::pfnRegisterR3 */
503 DECLR3CALLBACKMEMBER(int, pfnRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev));
504 /** @copydoc PDMPCIBUSREG::pfnIORegionRegisterR3 */
505 DECLR3CALLBACKMEMBER(int, pfnIORegionRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion,
506 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
507 /** @copydoc PDMPCIBUSREG::pfnSetConfigCallbacksR3 */
508 DECLR3CALLBACKMEMBER(void, pfnSetConfigCallbacksR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead,
509 PPFNPCICONFIGREAD ppfnReadOld, PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
510 /** @copydoc PDMPCIBUSREG::pfnSaveExecR3 */
511 DECLR3CALLBACKMEMBER(int, pfnSaveExecR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
512 /** @copydoc PDMPCIBUSREG::pfnLoadExecR3 */
513 DECLR3CALLBACKMEMBER(int, pfnLoadExecR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
514 /** @copydoc PDMPCIBUSREG::pfnFakePCIBIOSR3 */
515 DECLR3CALLBACKMEMBER(int, pfnFakePCIBIOSR3,(PPDMDEVINS pDevIns));
516
517 /** Pointer to the PIC device instance - R0. */
518 R0PTRTYPE(PPDMDEVINS) pDevInsR0;
519 /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
520 DECLR0CALLBACKMEMBER(void, pfnSetIrqR0,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
521
522 /** Pointer to PCI Bus device instance. */
523 PPDMDEVINSRC pDevInsRC;
524 /** @copydoc PDMPCIBUSREG::pfnSetIrqR3 */
525 DECLRCCALLBACKMEMBER(void, pfnSetIrqRC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
526} PDMPCIBUS;
527
528
529#ifdef IN_RING3
530/**
531 * PDM registered DMAC (DMA Controller) device.
532 */
533typedef struct PDMDMAC
534{
535 /** Pointer to the DMAC device instance. */
536 PPDMDEVINSR3 pDevIns;
537 /** Copy of the registration structure. */
538 PDMDMACREG Reg;
539} PDMDMAC;
540
541
542/**
543 * PDM registered RTC (Real Time Clock) device.
544 */
545typedef struct PDMRTC
546{
547 /** Pointer to the RTC device instance. */
548 PPDMDEVINSR3 pDevIns;
549 /** Copy of the registration structure. */
550 PDMRTCREG Reg;
551} PDMRTC;
552
553#endif /* IN_RING3 */
554
555/**
556 * Module type.
557 */
558typedef enum PDMMODTYPE
559{
560 /** Raw-mode (RC) context module. */
561 PDMMOD_TYPE_RC,
562 /** Ring-0 (host) context module. */
563 PDMMOD_TYPE_R0,
564 /** Ring-3 (host) context module. */
565 PDMMOD_TYPE_R3
566} PDMMODTYPE;
567
568
569/** The module name length including the terminator. */
570#define PDMMOD_NAME_LEN 32
571
572/**
573 * Loaded module instance.
574 */
575typedef struct PDMMOD
576{
577 /** Module name. This is used for refering to
578 * the module internally, sort of like a handle. */
579 char szName[PDMMOD_NAME_LEN];
580 /** Module type. */
581 PDMMODTYPE eType;
582 /** Loader module handle. Not used for R0 modules. */
583 RTLDRMOD hLdrMod;
584 /** Loaded address.
585 * This is the 'handle' for R0 modules. */
586 RTUINTPTR ImageBase;
587 /** Old loaded address.
588 * This is used during relocation of GC modules. Not used for R0 modules. */
589 RTUINTPTR OldImageBase;
590 /** Where the R3 HC bits are stored.
591 * This can be equal to ImageBase but doesn't have to. Not used for R0 modules. */
592 void *pvBits;
593
594 /** Pointer to next module. */
595 struct PDMMOD *pNext;
596 /** Module filename. */
597 char szFilename[1];
598} PDMMOD;
599/** Pointer to loaded module instance. */
600typedef PDMMOD *PPDMMOD;
601
602
603
604/** Extra space in the free array. */
605#define PDMQUEUE_FREE_SLACK 16
606
607/**
608 * Queue type.
609 */
610typedef enum PDMQUEUETYPE
611{
612 /** Device consumer. */
613 PDMQUEUETYPE_DEV = 1,
614 /** Driver consumer. */
615 PDMQUEUETYPE_DRV,
616 /** Internal consumer. */
617 PDMQUEUETYPE_INTERNAL,
618 /** External consumer. */
619 PDMQUEUETYPE_EXTERNAL
620} PDMQUEUETYPE;
621
622/** Pointer to a PDM Queue. */
623typedef struct PDMQUEUE *PPDMQUEUE;
624
625/**
626 * PDM Queue.
627 */
628typedef struct PDMQUEUE
629{
630 /** Pointer to the next queue in the list. */
631 R3PTRTYPE(PPDMQUEUE) pNext;
632 /** Type specific data. */
633 union
634 {
635 /** PDMQUEUETYPE_DEV */
636 struct
637 {
638 /** Pointer to consumer function. */
639 R3PTRTYPE(PFNPDMQUEUEDEV) pfnCallback;
640 /** Pointer to the device instance owning the queue. */
641 R3PTRTYPE(PPDMDEVINS) pDevIns;
642 } Dev;
643 /** PDMQUEUETYPE_DRV */
644 struct
645 {
646 /** Pointer to consumer function. */
647 R3PTRTYPE(PFNPDMQUEUEDRV) pfnCallback;
648 /** Pointer to the driver instance owning the queue. */
649 R3PTRTYPE(PPDMDRVINS) pDrvIns;
650 } Drv;
651 /** PDMQUEUETYPE_INTERNAL */
652 struct
653 {
654 /** Pointer to consumer function. */
655 R3PTRTYPE(PFNPDMQUEUEINT) pfnCallback;
656 } Int;
657 /** PDMQUEUETYPE_EXTERNAL */
658 struct
659 {
660 /** Pointer to consumer function. */
661 R3PTRTYPE(PFNPDMQUEUEEXT) pfnCallback;
662 /** Pointer to user argument. */
663 R3PTRTYPE(void *) pvUser;
664 } Ext;
665 } u;
666 /** Queue type. */
667 PDMQUEUETYPE enmType;
668 /** The interval between checking the queue for events.
669 * The realtime timer below is used to do the waiting.
670 * If 0, the queue will use the VM_FF_PDM_QUEUE forced action. */
671 uint32_t cMilliesInterval;
672 /** Interval timer. Only used if cMilliesInterval is non-zero. */
673 PTMTIMERR3 pTimer;
674 /** Pointer to the VM - R3. */
675 PVMR3 pVMR3;
676 /** LIFO of pending items - R3. */
677 R3PTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingR3;
678 /** Pointer to the VM - R0. */
679 PVMR0 pVMR0;
680 /** LIFO of pending items - R0. */
681 R0PTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingR0;
682 /** Pointer to the GC VM and indicator for GC enabled queue.
683 * If this is NULL, the queue cannot be used in GC.
684 */
685 PVMRC pVMRC;
686 /** LIFO of pending items - GC. */
687 RCPTRTYPE(PPDMQUEUEITEMCORE) volatile pPendingRC;
688 /** Item size (bytes). */
689 RTUINT cbItem;
690 /** Number of items in the queue. */
691 RTUINT cItems;
692 /** Index to the free head (where we insert). */
693 uint32_t volatile iFreeHead;
694 /** Index to the free tail (where we remove). */
695 uint32_t volatile iFreeTail;
696
697 /** Array of pointers to free items. Variable size. */
698 struct PDMQUEUEFREEITEM
699 {
700 /** Pointer to the free item - HC Ptr. */
701 R3PTRTYPE(PPDMQUEUEITEMCORE) volatile pItemR3;
702 /** Pointer to the free item - HC Ptr. */
703 R0PTRTYPE(PPDMQUEUEITEMCORE) volatile pItemR0;
704 /** Pointer to the free item - GC Ptr. */
705 RCPTRTYPE(PPDMQUEUEITEMCORE) volatile pItemRC;
706#if HC_ARCH_BITS == 64
707 RTRCPTR Alignment0;
708#endif
709 } aFreeItems[1];
710} PDMQUEUE;
711
712
713/**
714 * Queue device helper task operation.
715 */
716typedef enum PDMDEVHLPTASKOP
717{
718 /** The usual invalid 0 entry. */
719 PDMDEVHLPTASKOP_INVALID = 0,
720 /** ISASetIrq */
721 PDMDEVHLPTASKOP_ISA_SET_IRQ,
722 /** PCISetIrq */
723 PDMDEVHLPTASKOP_PCI_SET_IRQ,
724 /** PCISetIrq */
725 PDMDEVHLPTASKOP_IOAPIC_SET_IRQ,
726 /** The usual 32-bit hack. */
727 PDMDEVHLPTASKOP_32BIT_HACK = 0x7fffffff
728} PDMDEVHLPTASKOP;
729
730/**
731 * Queued Device Helper Task.
732 */
733typedef struct PDMDEVHLPTASK
734{
735 /** The queue item core (don't touch). */
736 PDMQUEUEITEMCORE Core;
737 /** Pointer to the device instance (R3 Ptr). */
738 PPDMDEVINSR3 pDevInsR3;
739 /** This operation to perform. */
740 PDMDEVHLPTASKOP enmOp;
741#if HC_ARCH_BITS == 64
742 uint32_t Alignment0;
743#endif
744 /** Parameters to the operation. */
745 union PDMDEVHLPTASKPARAMS
746 {
747 /**
748 * PDMDEVHLPTASKOP_ISA_SET_IRQ and PDMDEVHLPTASKOP_PCI_SET_IRQ.
749 */
750 struct PDMDEVHLPTASKSETIRQ
751 {
752 /** The IRQ */
753 int iIrq;
754 /** The new level. */
755 int iLevel;
756 } SetIRQ;
757 } u;
758} PDMDEVHLPTASK;
759/** Pointer to a queued Device Helper Task. */
760typedef PDMDEVHLPTASK *PPDMDEVHLPTASK;
761/** Pointer to a const queued Device Helper Task. */
762typedef const PDMDEVHLPTASK *PCPDMDEVHLPTASK;
763
764
765
766/**
767 * An USB hub registration record.
768 */
769typedef struct PDMUSBHUB
770{
771 /** The USB versions this hub support.
772 * Note that 1.1 hubs can take on 2.0 devices. */
773 uint32_t fVersions;
774 /** The number of ports on the hub. */
775 uint32_t cPorts;
776 /** The number of available ports (0..cPorts). */
777 uint32_t cAvailablePorts;
778 /** The driver instance of the hub. */
779 PPDMDRVINS pDrvIns;
780 /** Copy of the to the registration structure. */
781 PDMUSBHUBREG Reg;
782
783 /** Pointer to the next hub in the list. */
784 struct PDMUSBHUB *pNext;
785} PDMUSBHUB;
786
787/** Pointer to a const USB HUB registration record. */
788typedef const PDMUSBHUB *PCPDMUSBHUB;
789
790/** Pointer to a PDM Async I/O template. */
791typedef struct PDMASYNCCOMPLETIONTEMPLATE *PPDMASYNCCOMPLETIONTEMPLATE;
792
793/** Pointer to the main PDM Async completion structure. */
794typedef struct PDMASYNCCOMPLETIONMANAGER *PPDMASYNCCOMPLETIONMANAGER;
795
796/**
797 * Converts a PDM pointer into a VM pointer.
798 * @returns Pointer to the VM structure the PDM is part of.
799 * @param pPDM Pointer to PDM instance data.
800 */
801#define PDM2VM(pPDM) ( (PVM)((char*)pPDM - pPDM->offVM) )
802
803
804/**
805 * PDM VM Instance data.
806 * Changes to this must checked against the padding of the cfgm union in VM!
807 */
808typedef struct PDM
809{
810 /** Offset to the VM structure.
811 * See PDM2VM(). */
812 RTUINT offVM;
813 RTUINT uPadding0; /**< Alignment padding.*/
814
815 /** List of registered devices. (FIFO) */
816 R3PTRTYPE(PPDMDEV) pDevs;
817 /** List of devices instances. (FIFO) */
818 R3PTRTYPE(PPDMDEVINS) pDevInstances;
819 /** List of registered USB devices. (FIFO) */
820 R3PTRTYPE(PPDMUSB) pUsbDevs;
821 /** List of USB devices instances. (FIFO) */
822 R3PTRTYPE(PPDMUSBINS) pUsbInstances;
823 /** List of registered drivers. (FIFO) */
824 R3PTRTYPE(PPDMDRV) pDrvs;
825 /** List of initialized critical sections. (LIFO) */
826 R3PTRTYPE(PPDMCRITSECTINT) pCritSects;
827 /** PCI Buses. */
828 PDMPCIBUS aPciBuses[PDM_PCI_BUSSES_MAX];
829 /** The register PIC device. */
830 PDMPIC Pic;
831 /** The registerd APIC device. */
832 PDMAPIC Apic;
833 /** The registerd I/O APIC device. */
834 PDMIOAPIC IoApic;
835 /** The registered DMAC device. */
836 R3PTRTYPE(PPDMDMAC) pDmac;
837 /** The registered RTC device. */
838 R3PTRTYPE(PPDMRTC) pRtc;
839 /** The registered USB HUBs. (FIFO) */
840 R3PTRTYPE(PPDMUSBHUB) pUsbHubs;
841
842 /** Queue in which devhlp tasks are queued for R3 execution - R3 Ptr. */
843 R3PTRTYPE(PPDMQUEUE) pDevHlpQueueR3;
844 /** Queue in which devhlp tasks are queued for R3 execution - R0 Ptr. */
845 R0PTRTYPE(PPDMQUEUE) pDevHlpQueueR0;
846 /** Queue in which devhlp tasks are queued for R3 execution - RC Ptr. */
847 RCPTRTYPE(PPDMQUEUE) pDevHlpQueueRC;
848
849 /** The number of entries in the apQueuedCritSectsLeaves table that's currnetly in use. */
850 RTUINT cQueuedCritSectLeaves;
851 /** Critical sections queued in RC/R0 because of contention preventing leave to complete. (R3 Ptrs)
852 * We will return to Ring-3 ASAP, so this queue doesn't have to be very long. */
853 R3PTRTYPE(PPDMCRITSECT) apQueuedCritSectsLeaves[8];
854
855 /** Linked list of timer driven PDM queues. */
856 R3PTRTYPE(struct PDMQUEUE *) pQueuesTimer;
857 /** Linked list of force action driven PDM queues. */
858 R3PTRTYPE(struct PDMQUEUE *) pQueuesForced;
859 /** Pointer to the queue which should be manually flushed - R0 Ptr.
860 * Only touched by EMT. */
861 R0PTRTYPE(struct PDMQUEUE *) pQueueFlushR0;
862 /** Pointer to the queue which should be manually flushed - RC Ptr.
863 * Only touched by EMT. */
864 RCPTRTYPE(struct PDMQUEUE *) pQueueFlushRC;
865#if HC_ARCH_BITS == 64
866 RTRCPTR padding0;
867#endif
868
869 /** Head of the PDM Thread list. (singly linked) */
870 R3PTRTYPE(PPDMTHREAD) pThreads;
871 /** Tail of the PDM Thread list. (singly linked) */
872 R3PTRTYPE(PPDMTHREAD) pThreadsTail;
873
874 /** Head of the asychronous tasks managers. (singly linked) */
875 R3PTRTYPE(PPDMASYNCCOMPLETIONMANAGER) pAsyncCompletionManagerHead;
876 /** Head of the templates. (singly linked) */
877 R3PTRTYPE(PPDMASYNCCOMPLETIONTEMPLATE) pAsyncCompletionTemplates;
878
879 /** @name VMM device heap
880 * @{ */
881 /** Pointer to the heap base (MMIO2 ring-3 mapping). NULL if not registered. */
882 RTR3PTR pvVMMDevHeap;
883 /** The heap size. */
884 RTUINT cbVMMDevHeap;
885 /** Free space. */
886 RTUINT cbVMMDevHeapLeft;
887 /** The current mapping. NIL_RTGCPHYS if not mapped or registered. */
888 RTGCPHYS GCPhysVMMDevHeap;
889 /** @} */
890
891 /** TEMPORARY HACKS FOR NETWORK POLLING.
892 * @todo fix NAT and kill this!
893 * @{ */
894 RTUINT cPollers;
895#if HC_ARCH_BITS == 64
896 RTUINT padding1;
897#endif
898 R3PTRTYPE(PFNPDMDRVPOLLER) apfnPollers[16];
899 R3PTRTYPE(PPDMDRVINS) aDrvInsPollers[16];
900 PTMTIMERR3 pTimerPollers;
901 /** @} */
902
903 /** The PDM lock.
904 * This is used to protect everything that deals with interrupts, i.e.
905 * the PIC, APIC, IOAPIC and PCI devices pluss some PDM functions. */
906 PDMCRITSECT CritSect;
907
908 /** Number of times a critical section leave requesed needed to be queued for ring-3 execution. */
909 STAMCOUNTER StatQueuedCritSectLeaves;
910} PDM;
911/** Pointer to PDM VM instance data. */
912typedef PDM *PPDM;
913
914
915/**
916 * PDM data kept in the UVM.
917 */
918typedef struct PDMUSERPERVM
919{
920 /** Pointer to list of loaded modules. */
921 PPDMMOD pModules;
922 /** @todo move more stuff over here. */
923} PDMUSERPERVM;
924/** Pointer to the PDM data kept in the UVM. */
925typedef PDMUSERPERVM *PPDMUSERPERVM;
926
927
928
929/*******************************************************************************
930* Global Variables *
931*******************************************************************************/
932#ifdef IN_RING3
933extern const PDMDRVHLP g_pdmR3DrvHlp;
934extern const PDMDEVHLPR3 g_pdmR3DevHlpTrusted;
935extern const PDMDEVHLPR3 g_pdmR3DevHlpUnTrusted;
936extern const PDMPICHLPR3 g_pdmR3DevPicHlp;
937extern const PDMAPICHLPR3 g_pdmR3DevApicHlp;
938extern const PDMIOAPICHLPR3 g_pdmR3DevIoApicHlp;
939extern const PDMPCIHLPR3 g_pdmR3DevPciHlp;
940extern const PDMDMACHLP g_pdmR3DevDmacHlp;
941extern const PDMRTCHLP g_pdmR3DevRtcHlp;
942#endif
943
944
945/*******************************************************************************
946* Defined Constants And Macros *
947*******************************************************************************/
948/** @def PDMDEV_ASSERT_DEVINS
949 * Asserts the validity of the device instance.
950 */
951#ifdef VBOX_STRICT
952# define PDMDEV_ASSERT_DEVINS(pDevIns) \
953 do { \
954 AssertPtr(pDevIns); \
955 Assert(pDevIns->u32Version == PDM_DEVINS_VERSION); \
956 Assert(pDevIns->CTX_SUFF(pvInstanceData) == (void *)&pDevIns->achInstanceData[0]); \
957 } while (0)
958#else
959# define PDMDEV_ASSERT_DEVINS(pDevIns) do { } while (0)
960#endif
961
962
963/*******************************************************************************
964* Internal Functions *
965*******************************************************************************/
966#ifdef IN_RING3
967int pdmR3CritSectInit(PVM pVM);
968int pdmR3CritSectTerm(PVM pVM);
969void pdmR3CritSectRelocate(PVM pVM);
970int pdmR3CritSectInitDevice(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, const char *pszName);
971int pdmR3CritSectDeleteDevice(PVM pVM, PPDMDEVINS pDevIns);
972
973int pdmR3DevInit(PVM pVM);
974PPDMDEV pdmR3DevLookup(PVM pVM, const char *pszName);
975int pdmR3DevFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMLUN *ppLun);
976DECLCALLBACK(bool) pdmR3DevHlpQueueConsumer(PVM pVM, PPDMQUEUEITEMCORE pItem);
977
978int pdmR3UsbLoadModules(PVM pVM);
979int pdmR3UsbInstantiateDevices(PVM pVM);
980PPDMUSB pdmR3UsbLookup(PVM pVM, const char *pszName);
981int pdmR3UsbFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMLUN *ppLun);
982int pdmR3UsbRegisterHub(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp);
983int pdmR3UsbVMInitComplete(PVM pVM);
984
985int pdmR3DrvInit(PVM pVM);
986int pdmR3DrvDetach(PPDMDRVINS pDrvIns);
987void pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns);
988PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName);
989
990int pdmR3LdrInitU(PUVM pUVM);
991void pdmR3LdrTermU(PUVM pUVM);
992char * pdmR3FileR3(const char *pszFile, bool fShared = false);
993int pdmR3LoadR3U(PUVM pUVM, const char *pszFilename, const char *pszName);
994
995void pdmR3QueueRelocate(PVM pVM, RTGCINTPTR offDelta);
996
997int pdmR3ThreadCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
998 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
999int pdmR3ThreadCreateUsb(PVM pVM, PPDMDRVINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
1000 PFNPDMTHREADWAKEUPUSB pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
1001int pdmR3ThreadCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
1002 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName);
1003int pdmR3ThreadDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
1004int pdmR3ThreadDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
1005int pdmR3ThreadDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
1006void pdmR3ThreadDestroyAll(PVM pVM);
1007int pdmR3ThreadResumeAll(PVM pVM);
1008int pdmR3ThreadSuspendAll(PVM pVM);
1009
1010#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1011int pdmR3AsyncCompletionInit(PVM pVM);
1012int pdmR3AsyncCompletionTerm(PVM pVM);
1013#endif
1014
1015#endif /* IN_RING3 */
1016
1017void pdmLock(PVM pVM);
1018int pdmLockEx(PVM pVM, int rc);
1019void pdmUnlock(PVM pVM);
1020
1021/** @} */
1022
1023__END_DECLS
1024
1025#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