VirtualBox

source: vbox/trunk/include/VBox/pdmdev.h@ 8155

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

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 135.0 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Devices.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_pdmdev_h
31#define ___VBox_pdmdev_h
32
33#include <VBox/pdmqueue.h>
34#include <VBox/pdmcritsect.h>
35#include <VBox/pdmthread.h>
36#include <VBox/pdmifs.h>
37#include <VBox/pdmins.h>
38#include <VBox/iom.h>
39#include <VBox/tm.h>
40#include <VBox/ssm.h>
41#include <VBox/cfgm.h>
42#include <VBox/dbgf.h>
43#include <VBox/mm.h>
44#include <VBox/err.h>
45#include <VBox/pci.h>
46#include <iprt/stdarg.h>
47
48__BEGIN_DECLS
49
50/** @defgroup grp_pdm_device Devices
51 * @ingroup grp_pdm
52 * @{
53 */
54
55/**
56 * Construct a device instance for a VM.
57 *
58 * @returns VBox status.
59 * @param pDevIns The device instance data.
60 * If the registration structure is needed, pDevIns->pDevReg points to it.
61 * @param iInstance Instance number. Use this to figure out which registers and such to use.
62 * The instance number is also found in pDevIns->iInstance, but since it's
63 * likely to be freqently used PDM passes it as parameter.
64 * @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
65 * of the device instance. It's also found in pDevIns->pCfgHandle, but since it's
66 * primary usage will in this function it's passed as a parameter.
67 */
68typedef DECLCALLBACK(int) FNPDMDEVCONSTRUCT(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfgHandle);
69/** Pointer to a FNPDMDEVCONSTRUCT() function. */
70typedef FNPDMDEVCONSTRUCT *PFNPDMDEVCONSTRUCT;
71
72/**
73 * Destruct a device instance.
74 *
75 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
76 * resources can be freed correctly.
77 *
78 * @returns VBox status.
79 * @param pDevIns The device instance data.
80 */
81typedef DECLCALLBACK(int) FNPDMDEVDESTRUCT(PPDMDEVINS pDevIns);
82/** Pointer to a FNPDMDEVDESTRUCT() function. */
83typedef FNPDMDEVDESTRUCT *PFNPDMDEVDESTRUCT;
84
85/**
86 * Device relocation callback.
87 *
88 * When this callback is called the device instance data, and if the
89 * device have a GC component, is being relocated, or/and the selectors
90 * have been changed. The device must use the chance to perform the
91 * necessary pointer relocations and data updates.
92 *
93 * Before the GC code is executed the first time, this function will be
94 * called with a 0 delta so GC pointer calculations can be one in one place.
95 *
96 * @param pDevIns Pointer to the device instance.
97 * @param offDelta The relocation delta relative to the old location.
98 *
99 * @remark A relocation CANNOT fail.
100 */
101typedef DECLCALLBACK(void) FNPDMDEVRELOCATE(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
102/** Pointer to a FNPDMDEVRELOCATE() function. */
103typedef FNPDMDEVRELOCATE *PFNPDMDEVRELOCATE;
104
105
106/**
107 * Device I/O Control interface.
108 *
109 * This is used by external components, such as the COM interface, to
110 * communicate with devices using a class wide interface or a device
111 * specific interface.
112 *
113 * @returns VBox status code.
114 * @param pDevIns Pointer to the device instance.
115 * @param uFunction Function to perform.
116 * @param pvIn Pointer to input data.
117 * @param cbIn Size of input data.
118 * @param pvOut Pointer to output data.
119 * @param cbOut Size of output data.
120 * @param pcbOut Where to store the actual size of the output data.
121 */
122typedef DECLCALLBACK(int) FNPDMDEVIOCTL(PPDMDEVINS pDevIns, RTUINT uFunction,
123 void *pvIn, RTUINT cbIn,
124 void *pvOut, RTUINT cbOut, PRTUINT pcbOut);
125/** Pointer to a FNPDMDEVIOCTL() function. */
126typedef FNPDMDEVIOCTL *PFNPDMDEVIOCTL;
127
128/**
129 * Power On notification.
130 *
131 * @returns VBox status.
132 * @param pDevIns The device instance data.
133 */
134typedef DECLCALLBACK(void) FNPDMDEVPOWERON(PPDMDEVINS pDevIns);
135/** Pointer to a FNPDMDEVPOWERON() function. */
136typedef FNPDMDEVPOWERON *PFNPDMDEVPOWERON;
137
138/**
139 * Reset notification.
140 *
141 * @returns VBox status.
142 * @param pDevIns The device instance data.
143 */
144typedef DECLCALLBACK(void) FNPDMDEVRESET(PPDMDEVINS pDevIns);
145/** Pointer to a FNPDMDEVRESET() function. */
146typedef FNPDMDEVRESET *PFNPDMDEVRESET;
147
148/**
149 * Suspend notification.
150 *
151 * @returns VBox status.
152 * @param pDevIns The device instance data.
153 */
154typedef DECLCALLBACK(void) FNPDMDEVSUSPEND(PPDMDEVINS pDevIns);
155/** Pointer to a FNPDMDEVSUSPEND() function. */
156typedef FNPDMDEVSUSPEND *PFNPDMDEVSUSPEND;
157
158/**
159 * Resume notification.
160 *
161 * @returns VBox status.
162 * @param pDevIns The device instance data.
163 */
164typedef DECLCALLBACK(void) FNPDMDEVRESUME(PPDMDEVINS pDevIns);
165/** Pointer to a FNPDMDEVRESUME() function. */
166typedef FNPDMDEVRESUME *PFNPDMDEVRESUME;
167
168/**
169 * Power Off notification.
170 *
171 * @param pDevIns The device instance data.
172 */
173typedef DECLCALLBACK(void) FNPDMDEVPOWEROFF(PPDMDEVINS pDevIns);
174/** Pointer to a FNPDMDEVPOWEROFF() function. */
175typedef FNPDMDEVPOWEROFF *PFNPDMDEVPOWEROFF;
176
177/**
178 * Attach command.
179 *
180 * This is called to let the device attach to a driver for a specified LUN
181 * at runtime. This is not called during VM construction, the device
182 * constructor have to attach to all the available drivers.
183 *
184 * This is like plugging in the keyboard or mouse after turning on the PC.
185 *
186 * @returns VBox status code.
187 * @param pDevIns The device instance.
188 * @param iLUN The logical unit which is being detached.
189 */
190typedef DECLCALLBACK(int) FNPDMDEVATTACH(PPDMDEVINS pDevIns, unsigned iLUN);
191/** Pointer to a FNPDMDEVATTACH() function. */
192typedef FNPDMDEVATTACH *PFNPDMDEVATTACH;
193
194/**
195 * Detach notification.
196 *
197 * This is called when a driver is detaching itself from a LUN of the device.
198 * The device should adjust it's state to reflect this.
199 *
200 * This is like unplugging the network cable to use it for the laptop or
201 * something while the PC is still running.
202 *
203 * @param pDevIns The device instance.
204 * @param iLUN The logical unit which is being detached.
205 */
206typedef DECLCALLBACK(void) FNPDMDEVDETACH(PPDMDEVINS pDevIns, unsigned iLUN);
207/** Pointer to a FNPDMDEVDETACH() function. */
208typedef FNPDMDEVDETACH *PFNPDMDEVDETACH;
209
210/**
211 * Query the base interface of a logical unit.
212 *
213 * @returns VBOX status code.
214 * @param pDevIns The device instance.
215 * @param iLUN The logicial unit to query.
216 * @param ppBase Where to store the pointer to the base interface of the LUN.
217 */
218typedef DECLCALLBACK(int) FNPDMDEVQUERYINTERFACE(PPDMDEVINS pDevIns, unsigned iLUN, PPDMIBASE *ppBase);
219/** Pointer to a FNPDMDEVQUERYINTERFACE() function. */
220typedef FNPDMDEVQUERYINTERFACE *PFNPDMDEVQUERYINTERFACE;
221
222/**
223 * Init complete notification.
224 * This can be done to do communication with other devices and other
225 * initialization which requires everything to be in place.
226 *
227 * @returns VBOX status code.
228 * @param pDevIns The device instance.
229 */
230typedef DECLCALLBACK(int) FNPDMDEVINITCOMPLETE(PPDMDEVINS pDevIns);
231/** Pointer to a FNPDMDEVINITCOMPLETE() function. */
232typedef FNPDMDEVINITCOMPLETE *PFNPDMDEVINITCOMPLETE;
233
234
235
236/** PDM Device Registration Structure,
237 * This structure is used when registering a device from
238 * VBoxInitDevices() in HC Ring-3. PDM will continue use till
239 * the VM is terminated.
240 */
241typedef struct PDMDEVREG
242{
243 /** Structure version. PDM_DEVREG_VERSION defines the current version. */
244 uint32_t u32Version;
245 /** Device name. */
246 char szDeviceName[32];
247 /** Name of guest context module (no path).
248 * Only evalutated if PDM_DEVREG_FLAGS_GC is set. */
249 char szGCMod[32];
250 /** Name of guest context module (no path).
251 * Only evalutated if PDM_DEVREG_FLAGS_GC is set. */
252 char szR0Mod[32];
253 /** The description of the device. The UTF-8 string pointed to shall, like this structure,
254 * remain unchanged from registration till VM destruction. */
255 const char *pszDescription;
256
257 /** Flags, combination of the PDM_DEVREG_FLAGS_* \#defines. */
258 RTUINT fFlags;
259 /** Device class(es), combination of the PDM_DEVREG_CLASS_* \#defines. */
260 RTUINT fClass;
261 /** Maximum number of instances (per VM). */
262 RTUINT cMaxInstances;
263 /** Size of the instance data. */
264 RTUINT cbInstance;
265
266 /** Construct instance - required. */
267 PFNPDMDEVCONSTRUCT pfnConstruct;
268 /** Destruct instance - optional. */
269 PFNPDMDEVDESTRUCT pfnDestruct;
270 /** Relocation command - optional. */
271 PFNPDMDEVRELOCATE pfnRelocate;
272 /** I/O Control interface - optional. */
273 PFNPDMDEVIOCTL pfnIOCtl;
274 /** Power on notification - optional. */
275 PFNPDMDEVPOWERON pfnPowerOn;
276 /** Reset notification - optional. */
277 PFNPDMDEVRESET pfnReset;
278 /** Suspend notification - optional. */
279 PFNPDMDEVSUSPEND pfnSuspend;
280 /** Resume notification - optional. */
281 PFNPDMDEVRESUME pfnResume;
282 /** Attach command - optional. */
283 PFNPDMDEVATTACH pfnAttach;
284 /** Detach notification - optional. */
285 PFNPDMDEVDETACH pfnDetach;
286 /** Query a LUN base interface - optional. */
287 PFNPDMDEVQUERYINTERFACE pfnQueryInterface;
288 /** Init complete notification - optional. */
289 PFNPDMDEVINITCOMPLETE pfnInitComplete;
290 /** Power off notification - optional. */
291 PFNPDMDEVPOWEROFF pfnPowerOff;
292} PDMDEVREG;
293/** Pointer to a PDM Device Structure. */
294typedef PDMDEVREG *PPDMDEVREG;
295/** Const pointer to a PDM Device Structure. */
296typedef PDMDEVREG const *PCPDMDEVREG;
297
298/** Current DEVREG version number. */
299#define PDM_DEVREG_VERSION 0xc0010000
300
301/** PDM Device Flags.
302 * @{ */
303/** This flag is used to indicate that the device has a GC component. */
304#define PDM_DEVREG_FLAGS_GC 0x00000001
305/** This flag is used to indicate that the device has a R0 component. */
306#define PDM_DEVREG_FLAGS_R0 0x00010000
307
308/** @def PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT
309 * The bit count for the current host. */
310#if HC_ARCH_BITS == 32
311# define PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT 0x00000002
312#elif HC_ARCH_BITS == 64
313# define PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT 0x00000004
314#else
315# error Unsupported HC_ARCH_BITS value.
316#endif
317/** The host bit count mask. */
318#define PDM_DEVREG_FLAGS_HOST_BITS_MASK 0x00000006
319
320/** The device support only 32-bit guests. */
321#define PDM_DEVREG_FLAGS_GUEST_BITS_32 0x00000008
322/** The device support only 64-bit guests. */
323#define PDM_DEVREG_FLAGS_GUEST_BITS_64 0x00000010
324/** The device support both 32-bit & 64-bit guests. */
325#define PDM_DEVREG_FLAGS_GUEST_BITS_32_64 0x00000018
326/** @def PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT
327 * The guest bit count for the current compilation. */
328#if GC_ARCH_BITS == 32
329# define PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT PDM_DEVREG_FLAGS_GUEST_BITS_32
330#elif GC_ARCH_BITS == 64
331# define PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT PDM_DEVREG_FLAGS_GUEST_BITS_64
332#else
333# error Unsupported GC_ARCH_BITS value.
334#endif
335/** The guest bit count mask. */
336#define PDM_DEVREG_FLAGS_GUEST_BITS_MASK 0x00000018
337
338/** Indicates that the devices support PAE36 on a 32-bit guest. */
339#define PDM_DEVREG_FLAGS_PAE36 0x00000020
340/** @} */
341
342
343/** PDM Device Classes.
344 * The order is important, lower bit earlier instantiation.
345 * @{ */
346/** Architecture device. */
347#define PDM_DEVREG_CLASS_ARCH RT_BIT(0)
348/** Architecture BIOS device. */
349#define PDM_DEVREG_CLASS_ARCH_BIOS RT_BIT(1)
350/** PCI bus brigde. */
351#define PDM_DEVREG_CLASS_BUS_PCI RT_BIT(2)
352/** ISA bus brigde. */
353#define PDM_DEVREG_CLASS_BUS_ISA RT_BIT(3)
354/** Input device (mouse, keyboard, joystick,..). */
355#define PDM_DEVREG_CLASS_INPUT RT_BIT(4)
356/** Interrupt controller (PIC). */
357#define PDM_DEVREG_CLASS_PIC RT_BIT(5)
358/** Interval controoler (PIT). */
359#define PDM_DEVREG_CLASS_PIT RT_BIT(6)
360/** RTC/CMOS. */
361#define PDM_DEVREG_CLASS_RTC RT_BIT(7)
362/** DMA controller. */
363#define PDM_DEVREG_CLASS_DMA RT_BIT(8)
364/** VMM Device. */
365#define PDM_DEVREG_CLASS_VMM_DEV RT_BIT(9)
366/** Graphics device, like VGA. */
367#define PDM_DEVREG_CLASS_GRAPHICS RT_BIT(10)
368/** Storage controller device. */
369#define PDM_DEVREG_CLASS_STORAGE RT_BIT(11)
370/** Network interface controller. */
371#define PDM_DEVREG_CLASS_NETWORK RT_BIT(12)
372/** Audio. */
373#define PDM_DEVREG_CLASS_AUDIO RT_BIT(13)
374/** USB HIC. */
375#define PDM_DEVREG_CLASS_BUS_USB RT_BIT(14)
376/** ACPI. */
377#define PDM_DEVREG_CLASS_ACPI RT_BIT(15)
378/** Serial controller device. */
379#define PDM_DEVREG_CLASS_SERIAL RT_BIT(16)
380/** Parallel controller device */
381#define PDM_DEVREG_CLASS_PARALLEL RT_BIT(17)
382/** Misc devices (always last). */
383#define PDM_DEVREG_CLASS_MISC RT_BIT(31)
384/** @} */
385
386
387/** @name IRQ Level for use with the *SetIrq APIs.
388 * @{
389 */
390/** Assert the IRQ (can assume value 1). */
391#define PDM_IRQ_LEVEL_HIGH RT_BIT(0)
392/** Deassert the IRQ (can assume value 0). */
393#define PDM_IRQ_LEVEL_LOW 0
394/** flip-flop - assert and then deassert it again immediately. */
395#define PDM_IRQ_LEVEL_FLIP_FLOP (RT_BIT(1) | PDM_IRQ_LEVEL_HIGH)
396/** @} */
397
398
399/**
400 * PCI Bus registration structure.
401 * All the callbacks, except the PCIBIOS hack, are working on PCI devices.
402 */
403typedef struct PDMPCIBUSREG
404{
405 /** Structure version number. PDM_PCIBUSREG_VERSION defines the current version. */
406 uint32_t u32Version;
407
408 /**
409 * Registers the device with the default PCI bus.
410 *
411 * @returns VBox status code.
412 * @param pDevIns Device instance of the PCI Bus.
413 * @param pPciDev The PCI device structure.
414 * Any PCI enabled device must keep this in it's instance data!
415 * Fill in the PCI data config before registration, please.
416 * @param pszName Pointer to device name (permanent, readonly). For debugging, not unique.
417 * @param iDev The device number ((dev << 3) | function) the device should have on the bus.
418 * If negative, the pci bus device will assign one.
419 */
420 DECLR3CALLBACKMEMBER(int, pfnRegisterHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev));
421
422 /**
423 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
424 *
425 * @returns VBox status code.
426 * @param pDevIns Device instance of the PCI Bus.
427 * @param pPciDev The PCI device structure.
428 * @param iRegion The region number.
429 * @param cbRegion Size of the region.
430 * @param iType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
431 * @param pfnCallback Callback for doing the mapping.
432 */
433 DECLR3CALLBACKMEMBER(int, pfnIORegionRegisterHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
434
435 /**
436 * Register PCI configuration space read/write callbacks.
437 *
438 * @param pDevIns Device instance of the PCI Bus.
439 * @param pPciDev The PCI device structure.
440 * @param pfnRead Pointer to the user defined PCI config read function.
441 * @param ppfnReadOld Pointer to function pointer which will receive the old (default)
442 * PCI config read function. This way, user can decide when (and if)
443 * to call default PCI config read function. Can be NULL.
444 * @param pfnWrite Pointer to the user defined PCI config write function.
445 * @param pfnWriteOld Pointer to function pointer which will receive the old (default)
446 * PCI config write function. This way, user can decide when (and if)
447 * to call default PCI config write function. Can be NULL.
448 * @thread EMT
449 */
450 DECLR3CALLBACKMEMBER(void, pfnSetConfigCallbacksHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
451 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
452
453 /**
454 * Set the IRQ for a PCI device.
455 *
456 * @param pDevIns Device instance of the PCI Bus.
457 * @param pPciDev The PCI device structure.
458 * @param iIrq IRQ number to set.
459 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
460 */
461 DECLR3CALLBACKMEMBER(void, pfnSetIrqHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel));
462
463 /**
464 * Saves a state of the PCI device.
465 *
466 * @returns VBox status code.
467 * @param pDevIns Device instance of the PCI Bus.
468 * @param pPciDev Pointer to PCI device.
469 * @param pSSMHandle The handle to save the state to.
470 */
471 DECLR3CALLBACKMEMBER(int, pfnSaveExecHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
472
473 /**
474 * Loads a saved PCI device state.
475 *
476 * @returns VBox status code.
477 * @param pDevIns Device instance of the PCI Bus.
478 * @param pPciDev Pointer to PCI device.
479 * @param pSSMHandle The handle to the saved state.
480 */
481 DECLR3CALLBACKMEMBER(int, pfnLoadExecHC,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSMHandle));
482
483 /**
484 * Called to perform the job of the bios.
485 * This is only called for the first PCI Bus - it is expected to
486 * service all the PCI buses.
487 *
488 * @returns VBox status.
489 * @param pDevIns Device instance of the first bus.
490 */
491 DECLR3CALLBACKMEMBER(int, pfnFakePCIBIOSHC,(PPDMDEVINS pDevIns));
492
493 /** The name of the SetIrq GC entry point. */
494 const char *pszSetIrqGC;
495
496 /** The name of the SetIrq R0 entry point. */
497 const char *pszSetIrqR0;
498
499} PDMPCIBUSREG;
500/** Pointer to a PCI bus registration structure. */
501typedef PDMPCIBUSREG *PPDMPCIBUSREG;
502
503/** Current PDMPCIBUSREG version number. */
504#define PDM_PCIBUSREG_VERSION 0xd0020000
505
506/**
507 * PCI Bus GC helpers.
508 */
509typedef struct PDMPCIHLPGC
510{
511 /** Structure version. PDM_PCIHLPGC_VERSION defines the current version. */
512 uint32_t u32Version;
513
514 /**
515 * Set an ISA IRQ.
516 *
517 * @param pDevIns PCI device instance.
518 * @param iIrq IRQ number to set.
519 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
520 * @thread EMT only.
521 */
522 DECLGCCALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
523
524 /**
525 * Set an I/O-APIC IRQ.
526 *
527 * @param pDevIns PCI device instance.
528 * @param iIrq IRQ number to set.
529 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
530 * @thread EMT only.
531 */
532 DECLGCCALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
533
534#ifdef VBOX_WITH_PDM_LOCK
535 /**
536 * Acquires the PDM lock.
537 *
538 * @returns VINF_SUCCESS on success.
539 * @returns rc if we failed to acquire the lock.
540 * @param pDevIns The PCI device instance.
541 * @param rc What to return if we fail to acquire the lock.
542 */
543 DECLGCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
544
545 /**
546 * Releases the PDM lock.
547 *
548 * @param pDevIns The PCI device instance.
549 */
550 DECLGCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
551#endif
552 /** Just a safety precaution. */
553 uint32_t u32TheEnd;
554} PDMPCIHLPGC;
555/** Pointer to PCI helpers. */
556typedef GCPTRTYPE(PDMPCIHLPGC *) PPDMPCIHLPGC;
557/** Pointer to const PCI helpers. */
558typedef GCPTRTYPE(const PDMPCIHLPGC *) PCPDMPCIHLPGC;
559
560/** Current PDMPCIHLPR3 version number. */
561#define PDM_PCIHLPGC_VERSION 0xe1010000
562
563
564/**
565 * PCI Bus R0 helpers.
566 */
567typedef struct PDMPCIHLPR0
568{
569 /** Structure version. PDM_PCIHLPR0_VERSION defines the current version. */
570 uint32_t u32Version;
571
572 /**
573 * Set an ISA IRQ.
574 *
575 * @param pDevIns PCI device instance.
576 * @param iIrq IRQ number to set.
577 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
578 * @thread EMT only.
579 */
580 DECLR0CALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
581
582 /**
583 * Set an I/O-APIC IRQ.
584 *
585 * @param pDevIns PCI device instance.
586 * @param iIrq IRQ number to set.
587 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
588 * @thread EMT only.
589 */
590 DECLR0CALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
591
592#ifdef VBOX_WITH_PDM_LOCK
593 /**
594 * Acquires the PDM lock.
595 *
596 * @returns VINF_SUCCESS on success.
597 * @returns rc if we failed to acquire the lock.
598 * @param pDevIns The PCI device instance.
599 * @param rc What to return if we fail to acquire the lock.
600 */
601 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
602
603 /**
604 * Releases the PDM lock.
605 *
606 * @param pDevIns The PCI device instance.
607 */
608 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
609#endif
610
611 /** Just a safety precaution. */
612 uint32_t u32TheEnd;
613} PDMPCIHLPR0;
614/** Pointer to PCI helpers. */
615typedef R0PTRTYPE(PDMPCIHLPR0 *) PPDMPCIHLPR0;
616/** Pointer to const PCI helpers. */
617typedef R0PTRTYPE(const PDMPCIHLPR0 *) PCPDMPCIHLPR0;
618
619/** Current PDMPCIHLPR0 version number. */
620#define PDM_PCIHLPR0_VERSION 0xe1010000
621
622/**
623 * PCI device helpers.
624 */
625typedef struct PDMPCIHLPR3
626{
627 /** Structure version. PDM_PCIHLPR3_VERSION defines the current version. */
628 uint32_t u32Version;
629
630 /**
631 * Set an ISA IRQ.
632 *
633 * @param pDevIns The PCI device instance.
634 * @param iIrq IRQ number to set.
635 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
636 * @thread EMT only.
637 */
638 DECLR3CALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
639
640 /**
641 * Set an I/O-APIC IRQ.
642 *
643 * @param pDevIns The PCI device instance.
644 * @param iIrq IRQ number to set.
645 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
646 * @thread EMT only.
647 */
648 DECLR3CALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
649
650 /**
651 * Checks if the given address is an MMIO2 base address or not.
652 *
653 * @returns true/false accordingly.
654 * @param pDevIns The PCI device instance.
655 * @param pOwner The owner of the memory, optional.
656 * @param GCPhys The address to check.
657 */
658 DECLR3CALLBACKMEMBER(bool, pfnIsMMIO2Base,(PPDMDEVINS pDevIns, PPDMDEVINS pOwner, RTGCPHYS GCPhys));
659
660 /**
661 * Gets the address of the GC PCI Bus helpers.
662 *
663 * This should be called at both construction and relocation time
664 * to obtain the correct address of the GC helpers.
665 *
666 * @returns GC pointer to the PCI Bus helpers.
667 * @param pDevIns Device instance of the PCI Bus.
668 * @thread EMT only.
669 */
670 DECLR3CALLBACKMEMBER(PCPDMPCIHLPGC, pfnGetGCHelpers,(PPDMDEVINS pDevIns));
671
672 /**
673 * Gets the address of the R0 PCI Bus helpers.
674 *
675 * This should be called at both construction and relocation time
676 * to obtain the correct address of the GC helpers.
677 *
678 * @returns R0 pointer to the PCI Bus helpers.
679 * @param pDevIns Device instance of the PCI Bus.
680 * @thread EMT only.
681 */
682 DECLR3CALLBACKMEMBER(PCPDMPCIHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
683
684#ifdef VBOX_WITH_PDM_LOCK
685 /**
686 * Acquires the PDM lock.
687 *
688 * @returns VINF_SUCCESS on success.
689 * @returns Fatal error on failure.
690 * @param pDevIns The PCI device instance.
691 * @param rc Dummy for making the interface identical to the GC and R0 versions.
692 */
693 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
694
695 /**
696 * Releases the PDM lock.
697 *
698 * @param pDevIns The PCI device instance.
699 */
700 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
701#endif
702
703 /** Just a safety precaution. */
704 uint32_t u32TheEnd;
705} PDMPCIHLPR3;
706/** Pointer to PCI helpers. */
707typedef R3PTRTYPE(PDMPCIHLPR3 *) PPDMPCIHLPR3;
708/** Pointer to const PCI helpers. */
709typedef R3PTRTYPE(const PDMPCIHLPR3 *) PCPDMPCIHLPR3;
710
711/** Current PDMPCIHLPR3 version number. */
712#define PDM_PCIHLPR3_VERSION 0xf1020000
713
714
715/**
716 * Programmable Interrupt Controller registration structure.
717 */
718typedef struct PDMPICREG
719{
720 /** Structure version number. PDM_PICREG_VERSION defines the current version. */
721 uint32_t u32Version;
722
723 /**
724 * Set the an IRQ.
725 *
726 * @param pDevIns Device instance of the PIC.
727 * @param iIrq IRQ number to set.
728 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
729 */
730 DECLR3CALLBACKMEMBER(void, pfnSetIrqHC,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
731
732 /**
733 * Get a pending interrupt.
734 *
735 * @returns Pending interrupt number.
736 * @param pDevIns Device instance of the PIC.
737 */
738 DECLR3CALLBACKMEMBER(int, pfnGetInterruptHC,(PPDMDEVINS pDevIns));
739
740 /** The name of the GC SetIrq entry point. */
741 const char *pszSetIrqGC;
742 /** The name of the GC GetInterrupt entry point. */
743 const char *pszGetInterruptGC;
744
745 /** The name of the R0 SetIrq entry point. */
746 const char *pszSetIrqR0;
747 /** The name of the R0 GetInterrupt entry point. */
748 const char *pszGetInterruptR0;
749} PDMPICREG;
750/** Pointer to a PIC registration structure. */
751typedef PDMPICREG *PPDMPICREG;
752
753/** Current PDMPICREG version number. */
754#define PDM_PICREG_VERSION 0xe0020000
755
756/**
757 * PIC GC helpers.
758 */
759typedef struct PDMPICHLPGC
760{
761 /** Structure version. PDM_PICHLPGC_VERSION defines the current version. */
762 uint32_t u32Version;
763
764 /**
765 * Set the interrupt force action flag.
766 *
767 * @param pDevIns Device instance of the PIC.
768 */
769 DECLGCCALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
770
771 /**
772 * Clear the interrupt force action flag.
773 *
774 * @param pDevIns Device instance of the PIC.
775 */
776 DECLGCCALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
777
778#ifdef VBOX_WITH_PDM_LOCK
779 /**
780 * Acquires the PDM lock.
781 *
782 * @returns VINF_SUCCESS on success.
783 * @returns rc if we failed to acquire the lock.
784 * @param pDevIns The PIC device instance.
785 * @param rc What to return if we fail to acquire the lock.
786 */
787 DECLGCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
788
789 /**
790 * Releases the PDM lock.
791 *
792 * @param pDevIns The PIC device instance.
793 */
794 DECLGCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
795#endif
796 /** Just a safety precaution. */
797 uint32_t u32TheEnd;
798} PDMPICHLPGC;
799
800/** Pointer to PIC GC helpers. */
801typedef GCPTRTYPE(PDMPICHLPGC *) PPDMPICHLPGC;
802/** Pointer to const PIC GC helpers. */
803typedef GCPTRTYPE(const PDMPICHLPGC *) PCPDMPICHLPGC;
804
805/** Current PDMPICHLPGC version number. */
806#define PDM_PICHLPGC_VERSION 0xfc010000
807
808
809/**
810 * PIC R0 helpers.
811 */
812typedef struct PDMPICHLPR0
813{
814 /** Structure version. PDM_PICHLPR0_VERSION defines the current version. */
815 uint32_t u32Version;
816
817 /**
818 * Set the interrupt force action flag.
819 *
820 * @param pDevIns Device instance of the PIC.
821 */
822 DECLR0CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
823
824 /**
825 * Clear the interrupt force action flag.
826 *
827 * @param pDevIns Device instance of the PIC.
828 */
829 DECLR0CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
830
831#ifdef VBOX_WITH_PDM_LOCK
832 /**
833 * Acquires the PDM lock.
834 *
835 * @returns VINF_SUCCESS on success.
836 * @returns rc if we failed to acquire the lock.
837 * @param pDevIns The PIC device instance.
838 * @param rc What to return if we fail to acquire the lock.
839 */
840 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
841
842 /**
843 * Releases the PDM lock.
844 *
845 * @param pDevIns The PCI device instance.
846 */
847 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
848#endif
849
850 /** Just a safety precaution. */
851 uint32_t u32TheEnd;
852} PDMPICHLPR0;
853
854/** Pointer to PIC R0 helpers. */
855typedef R0PTRTYPE(PDMPICHLPR0 *) PPDMPICHLPR0;
856/** Pointer to const PIC R0 helpers. */
857typedef R0PTRTYPE(const PDMPICHLPR0 *) PCPDMPICHLPR0;
858
859/** Current PDMPICHLPR0 version number. */
860#define PDM_PICHLPR0_VERSION 0xfc010000
861
862/**
863 * PIC HC helpers.
864 */
865typedef struct PDMPICHLPR3
866{
867 /** Structure version. PDM_PICHLP_VERSION defines the current version. */
868 uint32_t u32Version;
869
870 /**
871 * Set the interrupt force action flag.
872 *
873 * @param pDevIns Device instance of the PIC.
874 */
875 DECLR3CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
876
877 /**
878 * Clear the interrupt force action flag.
879 *
880 * @param pDevIns Device instance of the PIC.
881 */
882 DECLR3CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
883
884#ifdef VBOX_WITH_PDM_LOCK
885 /**
886 * Acquires the PDM lock.
887 *
888 * @returns VINF_SUCCESS on success.
889 * @returns Fatal error on failure.
890 * @param pDevIns The PIC device instance.
891 * @param rc Dummy for making the interface identical to the GC and R0 versions.
892 */
893 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
894
895 /**
896 * Releases the PDM lock.
897 *
898 * @param pDevIns The PIC device instance.
899 */
900 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
901#endif
902
903 /**
904 * Gets the address of the GC PIC helpers.
905 *
906 * This should be called at both construction and relocation time
907 * to obtain the correct address of the GC helpers.
908 *
909 * @returns GC pointer to the PIC helpers.
910 * @param pDevIns Device instance of the PIC.
911 */
912 DECLR3CALLBACKMEMBER(PCPDMPICHLPGC, pfnGetGCHelpers,(PPDMDEVINS pDevIns));
913
914 /**
915 * Gets the address of the R0 PIC helpers.
916 *
917 * This should be called at both construction and relocation time
918 * to obtain the correct address of the GC helpers.
919 *
920 * @returns R0 pointer to the PIC helpers.
921 * @param pDevIns Device instance of the PIC.
922 */
923 DECLR3CALLBACKMEMBER(PCPDMPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
924
925 /** Just a safety precaution. */
926 uint32_t u32TheEnd;
927} PDMPICHLPR3;
928
929/** Pointer to PIC HC helpers. */
930typedef R3PTRTYPE(PDMPICHLPR3 *) PPDMPICHLPR3;
931/** Pointer to const PIC HC helpers. */
932typedef R3PTRTYPE(const PDMPICHLPR3 *) PCPDMPICHLPR3;
933
934/** Current PDMPICHLPR3 version number. */
935#define PDM_PICHLPR3_VERSION 0xf0010000
936
937
938
939/**
940 * Advanced Programmable Interrupt Controller registration structure.
941 */
942typedef struct PDMAPICREG
943{
944 /** Structure version number. PDM_APICREG_VERSION defines the current version. */
945 uint32_t u32Version;
946
947 /**
948 * Get a pending interrupt.
949 *
950 * @returns Pending interrupt number.
951 * @param pDevIns Device instance of the APIC.
952 */
953 DECLR3CALLBACKMEMBER(int, pfnGetInterruptHC,(PPDMDEVINS pDevIns));
954
955 /**
956 * Set the APIC base.
957 *
958 * @param pDevIns Device instance of the APIC.
959 * @param u64Base The new base.
960 */
961 DECLR3CALLBACKMEMBER(void, pfnSetBaseHC,(PPDMDEVINS pDevIns, uint64_t u64Base));
962
963 /**
964 * Get the APIC base.
965 *
966 * @returns Current base.
967 * @param pDevIns Device instance of the APIC.
968 */
969 DECLR3CALLBACKMEMBER(uint64_t, pfnGetBaseHC,(PPDMDEVINS pDevIns));
970
971 /**
972 * Set the TPR (task priority register?).
973 *
974 * @param pDevIns Device instance of the APIC.
975 * @param u8TPR The new TPR.
976 */
977 DECLR3CALLBACKMEMBER(void, pfnSetTPRHC,(PPDMDEVINS pDevIns, uint8_t u8TPR));
978
979 /**
980 * Get the TPR (task priority register?).
981 *
982 * @returns The current TPR.
983 * @param pDevIns Device instance of the APIC.
984 */
985 DECLR3CALLBACKMEMBER(uint8_t, pfnGetTPRHC,(PPDMDEVINS pDevIns));
986
987 /**
988 * Private interface between the IOAPIC and APIC.
989 *
990 * This is a low-level, APIC/IOAPIC implementation specific interface
991 * which is registered with PDM only because it makes life so much
992 * simpler right now (GC bits). This is a bad bad hack! The correct
993 * way of doing this would involve some way of querying GC interfaces
994 * and relocating them. Perhaps doing some kind of device init in GC...
995 *
996 * @returns The current TPR.
997 * @param pDevIns Device instance of the APIC.
998 * @param u8Dest See APIC implementation.
999 * @param u8DestMode See APIC implementation.
1000 * @param u8DeliveryMode See APIC implementation.
1001 * @param iVector See APIC implementation.
1002 * @param u8Polarity See APIC implementation.
1003 * @param u8TriggerMode See APIC implementation.
1004 */
1005 DECLR3CALLBACKMEMBER(void, pfnBusDeliverHC,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1006 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
1007
1008 /** The name of the GC GetInterrupt entry point. */
1009 const char *pszGetInterruptGC;
1010 /** The name of the GC SetBase entry point. */
1011 const char *pszSetBaseGC;
1012 /** The name of the GC GetBase entry point. */
1013 const char *pszGetBaseGC;
1014 /** The name of the GC SetTPR entry point. */
1015 const char *pszSetTPRGC;
1016 /** The name of the GC GetTPR entry point. */
1017 const char *pszGetTPRGC;
1018 /** The name of the GC BusDeliver entry point. */
1019 const char *pszBusDeliverGC;
1020
1021 /** The name of the R0 GetInterrupt entry point. */
1022 const char *pszGetInterruptR0;
1023 /** The name of the R0 SetBase entry point. */
1024 const char *pszSetBaseR0;
1025 /** The name of the R0 GetBase entry point. */
1026 const char *pszGetBaseR0;
1027 /** The name of the R0 SetTPR entry point. */
1028 const char *pszSetTPRR0;
1029 /** The name of the R0 GetTPR entry point. */
1030 const char *pszGetTPRR0;
1031 /** The name of the R0 BusDeliver entry point. */
1032 const char *pszBusDeliverR0;
1033
1034} PDMAPICREG;
1035/** Pointer to an APIC registration structure. */
1036typedef PDMAPICREG *PPDMAPICREG;
1037
1038/** Current PDMAPICREG version number. */
1039#define PDM_APICREG_VERSION 0x70010000
1040
1041
1042/**
1043 * APIC GC helpers.
1044 */
1045typedef struct PDMAPICHLPGC
1046{
1047 /** Structure version. PDM_APICHLPGC_VERSION defines the current version. */
1048 uint32_t u32Version;
1049
1050 /**
1051 * Set the interrupt force action flag.
1052 *
1053 * @param pDevIns Device instance of the APIC.
1054 */
1055 DECLGCCALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
1056
1057 /**
1058 * Clear the interrupt force action flag.
1059 *
1060 * @param pDevIns Device instance of the APIC.
1061 */
1062 DECLGCCALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
1063
1064 /**
1065 * Sets or clears the APIC bit in the CPUID feature masks.
1066 *
1067 * @param pDevIns Device instance of the APIC.
1068 * @param fEnabled If true the bit is set, else cleared.
1069 */
1070 DECLGCCALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, bool fEnabled));
1071
1072#ifdef VBOX_WITH_PDM_LOCK
1073 /**
1074 * Acquires the PDM lock.
1075 *
1076 * @returns VINF_SUCCESS on success.
1077 * @returns rc if we failed to acquire the lock.
1078 * @param pDevIns The APIC device instance.
1079 * @param rc What to return if we fail to acquire the lock.
1080 */
1081 DECLGCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1082
1083 /**
1084 * Releases the PDM lock.
1085 *
1086 * @param pDevIns The APIC device instance.
1087 */
1088 DECLGCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1089#endif
1090 /** Just a safety precaution. */
1091 uint32_t u32TheEnd;
1092} PDMAPICHLPGC;
1093/** Pointer to APIC GC helpers. */
1094typedef GCPTRTYPE(PDMAPICHLPGC *) PPDMAPICHLPGC;
1095/** Pointer to const APIC helpers. */
1096typedef GCPTRTYPE(const PDMAPICHLPGC *) PCPDMAPICHLPGC;
1097
1098/** Current PDMAPICHLPGC version number. */
1099#define PDM_APICHLPGC_VERSION 0x60010000
1100
1101
1102/**
1103 * APIC R0 helpers.
1104 */
1105typedef struct PDMAPICHLPR0
1106{
1107 /** Structure version. PDM_APICHLPR0_VERSION defines the current version. */
1108 uint32_t u32Version;
1109
1110 /**
1111 * Set the interrupt force action flag.
1112 *
1113 * @param pDevIns Device instance of the APIC.
1114 */
1115 DECLR0CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
1116
1117 /**
1118 * Clear the interrupt force action flag.
1119 *
1120 * @param pDevIns Device instance of the APIC.
1121 */
1122 DECLR0CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
1123
1124 /**
1125 * Sets or clears the APIC bit in the CPUID feature masks.
1126 *
1127 * @param pDevIns Device instance of the APIC.
1128 * @param fEnabled If true the bit is set, else cleared.
1129 */
1130 DECLR0CALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, bool fEnabled));
1131
1132#ifdef VBOX_WITH_PDM_LOCK
1133 /**
1134 * Acquires the PDM lock.
1135 *
1136 * @returns VINF_SUCCESS on success.
1137 * @returns rc if we failed to acquire the lock.
1138 * @param pDevIns The APIC device instance.
1139 * @param rc What to return if we fail to acquire the lock.
1140 */
1141 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1142
1143 /**
1144 * Releases the PDM lock.
1145 *
1146 * @param pDevIns The APIC device instance.
1147 */
1148 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1149#endif
1150
1151 /** Just a safety precaution. */
1152 uint32_t u32TheEnd;
1153} PDMAPICHLPR0;
1154/** Pointer to APIC GC helpers. */
1155typedef GCPTRTYPE(PDMAPICHLPR0 *) PPDMAPICHLPR0;
1156/** Pointer to const APIC helpers. */
1157typedef R0PTRTYPE(const PDMAPICHLPR0 *) PCPDMAPICHLPR0;
1158
1159/** Current PDMAPICHLPR0 version number. */
1160#define PDM_APICHLPR0_VERSION 0x60010000
1161
1162/**
1163 * APIC HC helpers.
1164 */
1165typedef struct PDMAPICHLPR3
1166{
1167 /** Structure version. PDM_APICHLPR3_VERSION defines the current version. */
1168 uint32_t u32Version;
1169
1170 /**
1171 * Set the interrupt force action flag.
1172 *
1173 * @param pDevIns Device instance of the APIC.
1174 */
1175 DECLR3CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
1176
1177 /**
1178 * Clear the interrupt force action flag.
1179 *
1180 * @param pDevIns Device instance of the APIC.
1181 */
1182 DECLR3CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
1183
1184 /**
1185 * Sets or clears the APIC bit in the CPUID feature masks.
1186 *
1187 * @param pDevIns Device instance of the APIC.
1188 * @param fEnabled If true the bit is set, else cleared.
1189 */
1190 DECLR3CALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, bool fEnabled));
1191
1192#ifdef VBOX_WITH_PDM_LOCK
1193 /**
1194 * Acquires the PDM lock.
1195 *
1196 * @returns VINF_SUCCESS on success.
1197 * @returns Fatal error on failure.
1198 * @param pDevIns The APIC device instance.
1199 * @param rc Dummy for making the interface identical to the GC and R0 versions.
1200 */
1201 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1202
1203 /**
1204 * Releases the PDM lock.
1205 *
1206 * @param pDevIns The APIC device instance.
1207 */
1208 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1209#endif
1210
1211 /**
1212 * Gets the address of the GC APIC helpers.
1213 *
1214 * This should be called at both construction and relocation time
1215 * to obtain the correct address of the GC helpers.
1216 *
1217 * @returns GC pointer to the APIC helpers.
1218 * @param pDevIns Device instance of the APIC.
1219 */
1220 DECLR3CALLBACKMEMBER(PCPDMAPICHLPGC, pfnGetGCHelpers,(PPDMDEVINS pDevIns));
1221
1222 /**
1223 * Gets the address of the R0 APIC helpers.
1224 *
1225 * This should be called at both construction and relocation time
1226 * to obtain the correct address of the R0 helpers.
1227 *
1228 * @returns R0 pointer to the APIC helpers.
1229 * @param pDevIns Device instance of the APIC.
1230 */
1231 DECLR3CALLBACKMEMBER(PCPDMAPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1232
1233 /** Just a safety precaution. */
1234 uint32_t u32TheEnd;
1235} PDMAPICHLPR3;
1236/** Pointer to APIC helpers. */
1237typedef R3PTRTYPE(PDMAPICHLPR3 *) PPDMAPICHLPR3;
1238/** Pointer to const APIC helpers. */
1239typedef R3PTRTYPE(const PDMAPICHLPR3 *) PCPDMAPICHLPR3;
1240
1241/** Current PDMAPICHLP version number. */
1242#define PDM_APICHLPR3_VERSION 0xfd010000
1243
1244
1245/**
1246 * I/O APIC registration structure.
1247 */
1248typedef struct PDMIOAPICREG
1249{
1250 /** Struct version+magic number (PDM_IOAPICREG_VERSION). */
1251 uint32_t u32Version;
1252
1253 /**
1254 * Set the an IRQ.
1255 *
1256 * @param pDevIns Device instance of the I/O APIC.
1257 * @param iIrq IRQ number to set.
1258 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1259 */
1260 DECLR3CALLBACKMEMBER(void, pfnSetIrqHC,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
1261
1262 /** The name of the GC SetIrq entry point. */
1263 const char *pszSetIrqGC;
1264
1265 /** The name of the R0 SetIrq entry point. */
1266 const char *pszSetIrqR0;
1267} PDMIOAPICREG;
1268/** Pointer to an APIC registration structure. */
1269typedef PDMIOAPICREG *PPDMIOAPICREG;
1270
1271/** Current PDMAPICREG version number. */
1272#define PDM_IOAPICREG_VERSION 0x50010000
1273
1274
1275/**
1276 * IOAPIC GC helpers.
1277 */
1278typedef struct PDMIOAPICHLPGC
1279{
1280 /** Structure version. PDM_IOAPICHLPGC_VERSION defines the current version. */
1281 uint32_t u32Version;
1282
1283 /**
1284 * Private interface between the IOAPIC and APIC.
1285 *
1286 * See comments about this hack on PDMAPICREG::pfnBusDeliverHC.
1287 *
1288 * @returns The current TPR.
1289 * @param pDevIns Device instance of the IOAPIC.
1290 * @param u8Dest See APIC implementation.
1291 * @param u8DestMode See APIC implementation.
1292 * @param u8DeliveryMode See APIC implementation.
1293 * @param iVector See APIC implementation.
1294 * @param u8Polarity See APIC implementation.
1295 * @param u8TriggerMode See APIC implementation.
1296 */
1297 DECLGCCALLBACKMEMBER(void, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1298 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
1299
1300#ifdef VBOX_WITH_PDM_LOCK
1301 /**
1302 * Acquires the PDM lock.
1303 *
1304 * @returns VINF_SUCCESS on success.
1305 * @returns rc if we failed to acquire the lock.
1306 * @param pDevIns The IOAPIC device instance.
1307 * @param rc What to return if we fail to acquire the lock.
1308 */
1309 DECLGCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1310
1311 /**
1312 * Releases the PDM lock.
1313 *
1314 * @param pDevIns The IOAPIC device instance.
1315 */
1316 DECLGCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1317#endif
1318
1319 /** Just a safety precaution. */
1320 uint32_t u32TheEnd;
1321} PDMIOAPICHLPGC;
1322/** Pointer to IOAPIC GC helpers. */
1323typedef GCPTRTYPE(PDMAPICHLPGC *)PPDMIOAPICHLPGC;
1324/** Pointer to const IOAPIC helpers. */
1325typedef GCPTRTYPE(const PDMIOAPICHLPGC *) PCPDMIOAPICHLPGC;
1326
1327/** Current PDMIOAPICHLPGC version number. */
1328#define PDM_IOAPICHLPGC_VERSION 0xfe010000
1329
1330
1331/**
1332 * IOAPIC R0 helpers.
1333 */
1334typedef struct PDMIOAPICHLPR0
1335{
1336 /** Structure version. PDM_IOAPICHLPR0_VERSION defines the current version. */
1337 uint32_t u32Version;
1338
1339 /**
1340 * Private interface between the IOAPIC and APIC.
1341 *
1342 * See comments about this hack on PDMAPICREG::pfnBusDeliverHC.
1343 *
1344 * @returns The current TPR.
1345 * @param pDevIns Device instance of the IOAPIC.
1346 * @param u8Dest See APIC implementation.
1347 * @param u8DestMode See APIC implementation.
1348 * @param u8DeliveryMode See APIC implementation.
1349 * @param iVector See APIC implementation.
1350 * @param u8Polarity See APIC implementation.
1351 * @param u8TriggerMode See APIC implementation.
1352 */
1353 DECLR0CALLBACKMEMBER(void, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1354 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
1355
1356#ifdef VBOX_WITH_PDM_LOCK
1357 /**
1358 * Acquires the PDM lock.
1359 *
1360 * @returns VINF_SUCCESS on success.
1361 * @returns rc if we failed to acquire the lock.
1362 * @param pDevIns The IOAPIC device instance.
1363 * @param rc What to return if we fail to acquire the lock.
1364 */
1365 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1366
1367 /**
1368 * Releases the PDM lock.
1369 *
1370 * @param pDevIns The IOAPIC device instance.
1371 */
1372 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1373#endif
1374
1375 /** Just a safety precaution. */
1376 uint32_t u32TheEnd;
1377} PDMIOAPICHLPR0;
1378/** Pointer to IOAPIC R0 helpers. */
1379typedef R0PTRTYPE(PDMAPICHLPGC *) PPDMIOAPICHLPR0;
1380/** Pointer to const IOAPIC helpers. */
1381typedef R0PTRTYPE(const PDMIOAPICHLPR0 *) PCPDMIOAPICHLPR0;
1382
1383/** Current PDMIOAPICHLPR0 version number. */
1384#define PDM_IOAPICHLPR0_VERSION 0xfe010000
1385
1386/**
1387 * IOAPIC HC helpers.
1388 */
1389typedef struct PDMIOAPICHLPR3
1390{
1391 /** Structure version. PDM_IOAPICHLPR3_VERSION defines the current version. */
1392 uint32_t u32Version;
1393
1394 /**
1395 * Private interface between the IOAPIC and APIC.
1396 *
1397 * See comments about this hack on PDMAPICREG::pfnBusDeliverHC.
1398 *
1399 * @returns The current TPR.
1400 * @param pDevIns Device instance of the IOAPIC.
1401 * @param u8Dest See APIC implementation.
1402 * @param u8DestMode See APIC implementation.
1403 * @param u8DeliveryMode See APIC implementation.
1404 * @param iVector See APIC implementation.
1405 * @param u8Polarity See APIC implementation.
1406 * @param u8TriggerMode See APIC implementation.
1407 */
1408 DECLR3CALLBACKMEMBER(void, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1409 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode));
1410
1411#ifdef VBOX_WITH_PDM_LOCK
1412 /**
1413 * Acquires the PDM lock.
1414 *
1415 * @returns VINF_SUCCESS on success.
1416 * @returns Fatal error on failure.
1417 * @param pDevIns The IOAPIC device instance.
1418 * @param rc Dummy for making the interface identical to the GC and R0 versions.
1419 */
1420 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1421
1422 /**
1423 * Releases the PDM lock.
1424 *
1425 * @param pDevIns The IOAPIC device instance.
1426 */
1427 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1428#endif
1429
1430 /**
1431 * Gets the address of the GC IOAPIC helpers.
1432 *
1433 * This should be called at both construction and relocation time
1434 * to obtain the correct address of the GC helpers.
1435 *
1436 * @returns GC pointer to the IOAPIC helpers.
1437 * @param pDevIns Device instance of the IOAPIC.
1438 */
1439 DECLR3CALLBACKMEMBER(PCPDMIOAPICHLPGC, pfnGetGCHelpers,(PPDMDEVINS pDevIns));
1440
1441 /**
1442 * Gets the address of the R0 IOAPIC helpers.
1443 *
1444 * This should be called at both construction and relocation time
1445 * to obtain the correct address of the R0 helpers.
1446 *
1447 * @returns R0 pointer to the IOAPIC helpers.
1448 * @param pDevIns Device instance of the IOAPIC.
1449 */
1450 DECLR3CALLBACKMEMBER(PCPDMIOAPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1451
1452 /** Just a safety precaution. */
1453 uint32_t u32TheEnd;
1454} PDMIOAPICHLPR3;
1455/** Pointer to IOAPIC HC helpers. */
1456typedef R3PTRTYPE(PDMIOAPICHLPR3 *) PPDMIOAPICHLPR3;
1457/** Pointer to const IOAPIC helpers. */
1458typedef R3PTRTYPE(const PDMIOAPICHLPR3 *) PCPDMIOAPICHLPR3;
1459
1460/** Current PDMIOAPICHLPR3 version number. */
1461#define PDM_IOAPICHLPR3_VERSION 0xff010000
1462
1463
1464
1465#ifdef IN_RING3
1466
1467/**
1468 * DMA Transfer Handler.
1469 *
1470 * @returns Number of bytes transferred.
1471 * @param pDevIns Device instance of the DMA.
1472 * @param pvUser User pointer.
1473 * @param uChannel Channel number.
1474 * @param off DMA position.
1475 * @param cb Block size.
1476 */
1477typedef DECLCALLBACK(uint32_t) FNDMATRANSFERHANDLER(PPDMDEVINS pDevIns, void *pvUser, unsigned uChannel, uint32_t off, uint32_t cb);
1478/** Pointer to a FNDMATRANSFERHANDLER(). */
1479typedef FNDMATRANSFERHANDLER *PFNDMATRANSFERHANDLER;
1480
1481/**
1482 * DMA Controller registration structure.
1483 */
1484typedef struct PDMDMAREG
1485{
1486 /** Structure version number. PDM_DMACREG_VERSION defines the current version. */
1487 uint32_t u32Version;
1488
1489 /**
1490 * Execute pending transfers.
1491 *
1492 * @returns A more work indiciator. I.e. 'true' if there is more to be done, and 'false' if all is done.
1493 * @param pDevIns Device instance of the DMAC.
1494 */
1495 DECLR3CALLBACKMEMBER(bool, pfnRun,(PPDMDEVINS pDevIns));
1496
1497 /**
1498 * Register transfer function for DMA channel.
1499 *
1500 * @param pDevIns Device instance of the DMAC.
1501 * @param uChannel Channel number.
1502 * @param pfnTransferHandler Device specific transfer function.
1503 * @param pvUSer User pointer to be passed to the callback.
1504 */
1505 DECLR3CALLBACKMEMBER(void, pfnRegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
1506
1507 /**
1508 * Read memory
1509 *
1510 * @returns Number of bytes read.
1511 * @param pDevIns Device instance of the DMAC.
1512 * @param pvBuffer Pointer to target buffer.
1513 * @param off DMA position.
1514 * @param cbBlock Block size.
1515 */
1516 DECLR3CALLBACKMEMBER(uint32_t, pfnReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock));
1517
1518 /**
1519 * Write memory
1520 *
1521 * @returns Number of bytes written.
1522 * @param pDevIns Device instance of the DMAC.
1523 * @param pvBuffer Memory to write.
1524 * @param off DMA position.
1525 * @param cbBlock Block size.
1526 */
1527 DECLR3CALLBACKMEMBER(uint32_t, pfnWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock));
1528
1529 /**
1530 * Set the DREQ line.
1531 *
1532 * @param pDevIns Device instance of the DMAC.
1533 * @param uChannel Channel number.
1534 * @param uLevel Level of the line.
1535 */
1536 DECLR3CALLBACKMEMBER(void, pfnSetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
1537
1538 /**
1539 * Get channel mode
1540 *
1541 * @returns Channel mode.
1542 * @param pDevIns Device instance of the DMAC.
1543 * @param uChannel Channel number.
1544 */
1545 DECLR3CALLBACKMEMBER(uint8_t, pfnGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
1546
1547} PDMDMACREG;
1548/** Pointer to a DMAC registration structure. */
1549typedef PDMDMACREG *PPDMDMACREG;
1550
1551/** Current PDMDMACREG version number. */
1552#define PDM_DMACREG_VERSION 0xf5010000
1553
1554
1555/**
1556 * DMA Controller device helpers.
1557 */
1558typedef struct PDMDMACHLP
1559{
1560 /** Structure version. PDM_DMACHLP_VERSION defines the current version. */
1561 uint32_t u32Version;
1562
1563 /* to-be-defined */
1564
1565} PDMDMACHLP;
1566/** Pointer to DMAC helpers. */
1567typedef PDMDMACHLP *PPDMDMACHLP;
1568/** Pointer to const DMAC helpers. */
1569typedef const PDMDMACHLP *PCPDMDMACHLP;
1570
1571/** Current PDMDMACHLP version number. */
1572#define PDM_DMACHLP_VERSION 0xf6010000
1573
1574#endif /* IN_RING3 */
1575
1576
1577
1578/**
1579 * RTC registration structure.
1580 */
1581typedef struct PDMRTCREG
1582{
1583 /** Structure version number. PDM_RTCREG_VERSION defines the current version. */
1584 uint32_t u32Version;
1585 uint32_t u32Alignment; /**< structure size alignment. */
1586
1587 /**
1588 * Write to a CMOS register and update the checksum if necessary.
1589 *
1590 * @returns VBox status code.
1591 * @param pDevIns Device instance of the RTC.
1592 * @param iReg The CMOS register index.
1593 * @param u8Value The CMOS register value.
1594 */
1595 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
1596
1597 /**
1598 * Read a CMOS register.
1599 *
1600 * @returns VBox status code.
1601 * @param pDevIns Device instance of the RTC.
1602 * @param iReg The CMOS register index.
1603 * @param pu8Value Where to store the CMOS register value.
1604 */
1605 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
1606
1607} PDMRTCREG;
1608/** Pointer to a RTC registration structure. */
1609typedef PDMRTCREG *PPDMRTCREG;
1610/** Pointer to a const RTC registration structure. */
1611typedef const PDMRTCREG *PCPDMRTCREG;
1612
1613/** Current PDMRTCREG version number. */
1614#define PDM_RTCREG_VERSION 0xfa010000
1615
1616
1617/**
1618 * RTC device helpers.
1619 */
1620typedef struct PDMRTCHLP
1621{
1622 /** Structure version. PDM_RTCHLP_VERSION defines the current version. */
1623 uint32_t u32Version;
1624
1625 /* to-be-defined */
1626
1627} PDMRTCHLP;
1628/** Pointer to RTC helpers. */
1629typedef PDMRTCHLP *PPDMRTCHLP;
1630/** Pointer to const RTC helpers. */
1631typedef const PDMRTCHLP *PCPDMRTCHLP;
1632
1633/** Current PDMRTCHLP version number. */
1634#define PDM_RTCHLP_VERSION 0xf6010000
1635
1636
1637
1638#ifdef IN_RING3
1639
1640/**
1641 * PDM Device API.
1642 */
1643typedef struct PDMDEVHLP
1644{
1645 /** Structure version. PDM_DEVHLP_VERSION defines the current version. */
1646 uint32_t u32Version;
1647
1648 /**
1649 * Register a number of I/O ports with a device.
1650 *
1651 * These callbacks are of course for the host context (HC).
1652 * Register HC handlers before guest context (GC) handlers! There must be a
1653 * HC handler for every GC handler!
1654 *
1655 * @returns VBox status.
1656 * @param pDevIns The device instance to register the ports with.
1657 * @param Port First port number in the range.
1658 * @param cPorts Number of ports to register.
1659 * @param pvUser User argument.
1660 * @param pfnOut Pointer to function which is gonna handle OUT operations.
1661 * @param pfnIn Pointer to function which is gonna handle IN operations.
1662 * @param pfnOutStr Pointer to function which is gonna handle string OUT operations.
1663 * @param pfnInStr Pointer to function which is gonna handle string IN operations.
1664 * @param pszDesc Pointer to description string. This must not be freed.
1665 */
1666 DECLR3CALLBACKMEMBER(int, pfnIOPortRegister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTHCPTR pvUser,
1667 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
1668 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc));
1669
1670 /**
1671 * Register a number of I/O ports with a device for GC.
1672 *
1673 * These callbacks are for the host context (GC).
1674 * Register host context (HC) handlers before guest context handlers! There must be a
1675 * HC handler for every GC handler!
1676 *
1677 * @returns VBox status.
1678 * @param pDevIns The device instance to register the ports with and which GC module
1679 * to resolve the names against.
1680 * @param Port First port number in the range.
1681 * @param cPorts Number of ports to register.
1682 * @param pvUser User argument.
1683 * @param pszOut Name of the GC function which is gonna handle OUT operations.
1684 * @param pszIn Name of the GC function which is gonna handle IN operations.
1685 * @param pszOutStr Name of the GC function which is gonna handle string OUT operations.
1686 * @param pszInStr Name of the GC function which is gonna handle string IN operations.
1687 * @param pszDesc Pointer to description string. This must not be freed.
1688 */
1689 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterGC,(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTGCPTR pvUser,
1690 const char *pszOut, const char *pszIn,
1691 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
1692
1693 /**
1694 * Register a number of I/O ports with a device.
1695 *
1696 * These callbacks are of course for the ring-0 host context (R0).
1697 * Register R3 (HC) handlers before R0 (R0) handlers! There must be a R3 (HC) handler for every R0 handler!
1698 *
1699 * @returns VBox status.
1700 * @param pDevIns The device instance to register the ports with.
1701 * @param Port First port number in the range.
1702 * @param cPorts Number of ports to register.
1703 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
1704 * @param pszOut Name of the R0 function which is gonna handle OUT operations.
1705 * @param pszIn Name of the R0 function which is gonna handle IN operations.
1706 * @param pszOutStr Name of the R0 function which is gonna handle string OUT operations.
1707 * @param pszInStr Name of the R0 function which is gonna handle string IN operations.
1708 * @param pszDesc Pointer to description string. This must not be freed.
1709 */
1710 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterR0,(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTR0PTR pvUser,
1711 const char *pszOut, const char *pszIn,
1712 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
1713
1714 /**
1715 * Deregister I/O ports.
1716 *
1717 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
1718 *
1719 * @returns VBox status.
1720 * @param pDevIns The device instance owning the ports.
1721 * @param Port First port number in the range.
1722 * @param cPorts Number of ports to deregister.
1723 */
1724 DECLR3CALLBACKMEMBER(int, pfnIOPortDeregister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts));
1725
1726 /**
1727 * Register a Memory Mapped I/O (MMIO) region.
1728 *
1729 * These callbacks are of course for the host context (HC).
1730 * Register HC handlers before guest context (GC) handlers! There must be a
1731 * HC handler for every GC handler!
1732 *
1733 * @returns VBox status.
1734 * @param pDevIns The device instance to register the MMIO with.
1735 * @param GCPhysStart First physical address in the range.
1736 * @param cbRange The size of the range (in bytes).
1737 * @param pvUser User argument.
1738 * @param pfnWrite Pointer to function which is gonna handle Write operations.
1739 * @param pfnRead Pointer to function which is gonna handle Read operations.
1740 * @param pfnFill Pointer to function which is gonna handle Fill/memset operations. (optional)
1741 * @param pszDesc Pointer to description string. This must not be freed.
1742 */
1743 DECLR3CALLBACKMEMBER(int, pfnMMIORegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
1744 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
1745 const char *pszDesc));
1746
1747 /**
1748 * Register a Memory Mapped I/O (MMIO) region for GC.
1749 *
1750 * These callbacks are for the guest context (GC).
1751 * Register host context (HC) handlers before guest context handlers! There must be a
1752 * HC handler for every GC handler!
1753 *
1754 * @returns VBox status.
1755 * @param pDevIns The device instance to register the MMIO with.
1756 * @param GCPhysStart First physical address in the range.
1757 * @param cbRange The size of the range (in bytes).
1758 * @param pvUser User argument.
1759 * @param pszWrite Name of the GC function which is gonna handle Write operations.
1760 * @param pszRead Name of the GC function which is gonna handle Read operations.
1761 * @param pszFill Name of the GC function which is gonna handle Fill/memset operations. (optional)
1762 * @param pszDesc Obsolete. NULL is fine.
1763 * @todo Remove pszDesc in the next major revision of PDMDEVHLP.
1764 */
1765 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterGC,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
1766 const char *pszWrite, const char *pszRead, const char *pszFill,
1767 const char *pszDesc));
1768
1769 /**
1770 * Register a Memory Mapped I/O (MMIO) region for R0.
1771 *
1772 * These callbacks are for the ring-0 host context (R0).
1773 * Register R3 (HC) handlers before R0 handlers! There must be a R3 handler for every R0 handler!
1774 *
1775 * @returns VBox status.
1776 * @param pDevIns The device instance to register the MMIO with.
1777 * @param GCPhysStart First physical address in the range.
1778 * @param cbRange The size of the range (in bytes).
1779 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
1780 * @param pszWrite Name of the GC function which is gonna handle Write operations.
1781 * @param pszRead Name of the GC function which is gonna handle Read operations.
1782 * @param pszFill Name of the GC function which is gonna handle Fill/memset operations. (optional)
1783 * @param pszDesc Obsolete. NULL is fine.
1784 * @todo Remove pszDesc in the next major revision of PDMDEVHLP.
1785 */
1786 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterR0,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTR0PTR pvUser,
1787 const char *pszWrite, const char *pszRead, const char *pszFill,
1788 const char *pszDesc));
1789
1790 /**
1791 * Deregister a Memory Mapped I/O (MMIO) region.
1792 *
1793 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
1794 *
1795 * @returns VBox status.
1796 * @param pDevIns The device instance owning the MMIO region(s).
1797 * @param GCPhysStart First physical address in the range.
1798 * @param cbRange The size of the range (in bytes).
1799 */
1800 DECLR3CALLBACKMEMBER(int, pfnMMIODeregister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange));
1801
1802 /**
1803 * Register a ROM (BIOS) region.
1804 *
1805 * It goes without saying that this is read-only memory. The memory region must be
1806 * in unassigned memory. I.e. from the top of the address space or on the PC in
1807 * the 0xa0000-0xfffff range.
1808 *
1809 * @returns VBox status.
1810 * @param pDevIns The device instance owning the ROM region.
1811 * @param GCPhysStart First physical address in the range.
1812 * Must be page aligned!
1813 * @param cbRange The size of the range (in bytes).
1814 * Must be page aligned!
1815 * @param pvBinary Pointer to the binary data backing the ROM image.
1816 * This must be cbRange bytes big.
1817 * It will be copied and doesn't have to stick around if fShadow is clear.
1818 * @param fShadow Whether to emulate ROM shadowing. This involves leaving
1819 * the ROM writable for a while during the POST and refreshing
1820 * it at reset. When this flag is set, the memory pointed to by
1821 * pvBinary has to stick around for the lifespan of the VM.
1822 * @param pszDesc Pointer to description string. This must not be freed.
1823 *
1824 * @remark There is no way to remove the rom, automatically on device cleanup or
1825 * manually from the device yet. At present I doubt we need such features...
1826 */
1827 DECLR3CALLBACKMEMBER(int, pfnROMRegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, const void *pvBinary, bool fShadow, const char *pszDesc));
1828
1829 /**
1830 * Register a save state data unit.
1831 *
1832 * @returns VBox status.
1833 * @param pDevIns Device instance.
1834 * @param pszName Data unit name.
1835 * @param u32Instance The instance identifier of the data unit.
1836 * This must together with the name be unique.
1837 * @param u32Version Data layout version number.
1838 * @param cbGuess The approximate amount of data in the unit.
1839 * Only for progress indicators.
1840 * @param pfnSavePrep Prepare save callback, optional.
1841 * @param pfnSaveExec Execute save callback, optional.
1842 * @param pfnSaveDone Done save callback, optional.
1843 * @param pfnLoadPrep Prepare load callback, optional.
1844 * @param pfnLoadExec Execute load callback, optional.
1845 * @param pfnLoadDone Done load callback, optional.
1846 */
1847 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMDEVINS pDevIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
1848 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
1849 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone));
1850
1851 /**
1852 * Creates a timer.
1853 *
1854 * @returns VBox status.
1855 * @param pDevIns Device instance.
1856 * @param enmClock The clock to use on this timer.
1857 * @param pfnCallback Callback function.
1858 * @param pszDesc Pointer to description string which must stay around
1859 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
1860 * @param ppTimer Where to store the timer on success.
1861 */
1862 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer));
1863
1864 /**
1865 * Creates an external timer.
1866 *
1867 * @returns timer pointer
1868 * @param pDevIns Device instance.
1869 * @param enmClock The clock to use on this timer.
1870 * @param pfnCallback Callback function.
1871 * @param pvUser User pointer
1872 * @param pszDesc Pointer to description string which must stay around
1873 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
1874 */
1875 DECLR3CALLBACKMEMBER(PTMTIMERR3, pfnTMTimerCreateExternal,(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMEREXT pfnCallback, void *pvUser, const char *pszDesc));
1876
1877 /**
1878 * Registers the device with the default PCI bus.
1879 *
1880 * @returns VBox status code.
1881 * @param pDevIns Device instance.
1882 * @param pPciDev The PCI device structure.
1883 * Any PCI enabled device must keep this in it's instance data!
1884 * Fill in the PCI data config before registration, please.
1885 * @remark This is the simple interface, a Ex interface will be created if
1886 * more features are needed later.
1887 */
1888 DECLR3CALLBACKMEMBER(int, pfnPCIRegister,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev));
1889
1890 /**
1891 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
1892 *
1893 * @returns VBox status code.
1894 * @param pDevIns Device instance.
1895 * @param iRegion The region number.
1896 * @param cbRegion Size of the region.
1897 * @param enmType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
1898 * @param pfnCallback Callback for doing the mapping.
1899 */
1900 DECLR3CALLBACKMEMBER(int, pfnPCIIORegionRegister,(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
1901
1902 /**
1903 * Register PCI configuration space read/write callbacks.
1904 *
1905 * @param pDevIns Device instance.
1906 * @param pPciDev The PCI device structure.
1907 * If NULL the default PCI device for this device instance is used.
1908 * @param pfnRead Pointer to the user defined PCI config read function.
1909 * @param ppfnReadOld Pointer to function pointer which will receive the old (default)
1910 * PCI config read function. This way, user can decide when (and if)
1911 * to call default PCI config read function. Can be NULL.
1912 * @param pfnWrite Pointer to the user defined PCI config write function.
1913 * @param pfnWriteOld Pointer to function pointer which will receive the old (default)
1914 * PCI config write function. This way, user can decide when (and if)
1915 * to call default PCI config write function. Can be NULL.
1916 * @thread EMT
1917 */
1918 DECLR3CALLBACKMEMBER(void, pfnPCISetConfigCallbacks,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
1919 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
1920
1921 /**
1922 * Set the IRQ for a PCI device.
1923 *
1924 * @param pDevIns Device instance.
1925 * @param iIrq IRQ number to set.
1926 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1927 * @thread Any thread, but will involve the emulation thread.
1928 */
1929 DECLR3CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
1930
1931 /**
1932 * Set the IRQ for a PCI device, but don't wait for EMT to process
1933 * the request when not called from EMT.
1934 *
1935 * @param pDevIns Device instance.
1936 * @param iIrq IRQ number to set.
1937 * @param iLevel IRQ level.
1938 * @thread Any thread, but will involve the emulation thread.
1939 */
1940 DECLR3CALLBACKMEMBER(void, pfnPCISetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
1941
1942 /**
1943 * Set ISA IRQ for a device.
1944 *
1945 * @param pDevIns Device instance.
1946 * @param iIrq IRQ number to set.
1947 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1948 * @thread Any thread, but will involve the emulation thread.
1949 */
1950 DECLR3CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
1951
1952 /**
1953 * Set the ISA IRQ for a device, but don't wait for EMT to process
1954 * the request when not called from EMT.
1955 *
1956 * @param pDevIns Device instance.
1957 * @param iIrq IRQ number to set.
1958 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1959 * @thread Any thread, but will involve the emulation thread.
1960 */
1961 DECLR3CALLBACKMEMBER(void, pfnISASetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
1962
1963 /**
1964 * Attaches a driver (chain) to the device.
1965 *
1966 * The first call for a LUN this will serve as a registartion of the LUN. The pBaseInterface and
1967 * the pszDesc string will be registered with that LUN and kept around for PDMR3QueryDeviceLun().
1968 *
1969 * @returns VBox status code.
1970 * @param pDevIns Device instance.
1971 * @param iLun The logical unit to attach.
1972 * @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
1973 * @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
1974 * @param pszDesc Pointer to a string describing the LUN. This string must remain valid
1975 * for the live of the device instance.
1976 */
1977 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMDEVINS pDevIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc));
1978
1979 /**
1980 * Allocate memory which is associated with current VM instance
1981 * and automatically freed on it's destruction.
1982 *
1983 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
1984 * @param pDevIns Device instance.
1985 * @param cb Number of bytes to allocate.
1986 */
1987 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMDEVINS pDevIns, size_t cb));
1988
1989 /**
1990 * Allocate memory which is associated with current VM instance
1991 * and automatically freed on it's destruction. The memory is ZEROed.
1992 *
1993 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
1994 * @param pDevIns Device instance.
1995 * @param cb Number of bytes to allocate.
1996 */
1997 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMDEVINS pDevIns, size_t cb));
1998
1999 /**
2000 * Free memory allocated with pfnMMHeapAlloc() and pfnMMHeapAllocZ().
2001 *
2002 * @param pDevIns Device instance.
2003 * @param pv Pointer to the memory to free.
2004 */
2005 DECLR3CALLBACKMEMBER(void, pfnMMHeapFree,(PPDMDEVINS pDevIns, void *pv));
2006
2007 /**
2008 * Set the VM error message
2009 *
2010 * @returns rc.
2011 * @param pDevIns Device instance.
2012 * @param rc VBox status code.
2013 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2014 * @param pszFormat Error message format string.
2015 * @param ... Error message arguments.
2016 */
2017 DECLR3CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
2018
2019 /**
2020 * Set the VM error message
2021 *
2022 * @returns rc.
2023 * @param pDevIns Device instance.
2024 * @param rc VBox status code.
2025 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2026 * @param pszFormat Error message format string.
2027 * @param va Error message arguments.
2028 */
2029 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
2030
2031 /**
2032 * Set the VM runtime error message
2033 *
2034 * @returns VBox status code.
2035 * @param pDevIns Device instance.
2036 * @param fFatal Whether it is a fatal error or not.
2037 * @param pszErrorID Error ID string.
2038 * @param pszFormat Error message format string.
2039 * @param ... Error message arguments.
2040 */
2041 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...));
2042
2043 /**
2044 * Set the VM runtime error message
2045 *
2046 * @returns VBox status code.
2047 * @param pDevIns Device instance.
2048 * @param fFatal Whether it is a fatal error or not.
2049 * @param pszErrorID Error ID string.
2050 * @param pszFormat Error message format string.
2051 * @param va Error message arguments.
2052 */
2053 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
2054
2055 /**
2056 * Assert that the current thread is the emulation thread.
2057 *
2058 * @returns True if correct.
2059 * @returns False if wrong.
2060 * @param pDevIns Device instance.
2061 * @param pszFile Filename of the assertion location.
2062 * @param iLine The linenumber of the assertion location.
2063 * @param pszFunction Function of the assertion location.
2064 */
2065 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
2066
2067 /**
2068 * Assert that the current thread is NOT the emulation thread.
2069 *
2070 * @returns True if correct.
2071 * @returns False if wrong.
2072 * @param pDevIns Device instance.
2073 * @param pszFile Filename of the assertion location.
2074 * @param iLine The linenumber of the assertion location.
2075 * @param pszFunction Function of the assertion location.
2076 */
2077 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
2078
2079 /**
2080 * Stops the VM and enters the debugger to look at the guest state.
2081 *
2082 * Use the PDMDeviceDBGFStop() inline function with the RT_SRC_POS macro instead of
2083 * invoking this function directly.
2084 *
2085 * @returns VBox status code which must be passed up to the VMM.
2086 * @param pDevIns Device instance.
2087 * @param pszFile Filename of the assertion location.
2088 * @param iLine The linenumber of the assertion location.
2089 * @param pszFunction Function of the assertion location.
2090 * @param pszFormat Message. (optional)
2091 * @param args Message parameters.
2092 */
2093 DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list args));
2094
2095 /**
2096 * Register a info handler with DBGF,
2097 *
2098 * @returns VBox status code.
2099 * @param pDevIns Device instance.
2100 * @param pszName The identifier of the info.
2101 * @param pszDesc The description of the info and any arguments the handler may take.
2102 * @param pfnHandler The handler function to be called to display the info.
2103 */
2104 DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegister,(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler));
2105
2106 /**
2107 * Registers a statistics sample if statistics are enabled.
2108 *
2109 * @param pDevIns Device instance of the DMA.
2110 * @param pvSample Pointer to the sample.
2111 * @param enmType Sample type. This indicates what pvSample is pointing at.
2112 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
2113 * Further nesting is possible.
2114 * @param enmUnit Sample unit.
2115 * @param pszDesc Sample description.
2116 */
2117 DECLR3CALLBACKMEMBER(void, pfnSTAMRegister,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc));
2118
2119 /**
2120 * Same as pfnSTAMRegister except that the name is specified in a
2121 * RTStrPrintf like fashion.
2122 *
2123 * @returns VBox status.
2124 * @param pDevIns Device instance of the DMA.
2125 * @param pvSample Pointer to the sample.
2126 * @param enmType Sample type. This indicates what pvSample is pointing at.
2127 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
2128 * @param enmUnit Sample unit.
2129 * @param pszDesc Sample description.
2130 * @param pszName The sample name format string.
2131 * @param ... Arguments to the format string.
2132 */
2133 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterF,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
2134 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...));
2135
2136 /**
2137 * Same as pfnSTAMRegister except that the name is specified in a
2138 * RTStrPrintfV like fashion.
2139 *
2140 * @returns VBox status.
2141 * @param pDevIns Device instance of the DMA.
2142 * @param pvSample Pointer to the sample.
2143 * @param enmType Sample type. This indicates what pvSample is pointing at.
2144 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
2145 * @param enmUnit Sample unit.
2146 * @param pszDesc Sample description.
2147 * @param pszName The sample name format string.
2148 * @param args Arguments to the format string.
2149 */
2150 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
2151 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args));
2152
2153 /**
2154 * Register the RTC device.
2155 *
2156 * @returns VBox status code.
2157 * @param pDevIns Device instance.
2158 * @param pRtcReg Pointer to a RTC registration structure.
2159 * @param ppRtcHlp Where to store the pointer to the helper functions.
2160 */
2161 DECLR3CALLBACKMEMBER(int, pfnRTCRegister,(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp));
2162
2163 /**
2164 * Create a queue.
2165 *
2166 * @returns VBox status code.
2167 * @param pDevIns The device instance.
2168 * @param cbItem The size of a queue item.
2169 * @param cItems The number of items in the queue.
2170 * @param cMilliesInterval The number of milliseconds between polling the queue.
2171 * If 0 then the emulation thread will be notified whenever an item arrives.
2172 * @param pfnCallback The consumer function.
2173 * @param fGCEnabled Set if the queue should work in GC too.
2174 * @param ppQueue Where to store the queue handle on success.
2175 * @thread The emulation thread.
2176 */
2177 DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMDEVINS pDevIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
2178 PFNPDMQUEUEDEV pfnCallback, bool fGCEnabled, PPDMQUEUE *ppQueue));
2179
2180 /**
2181 * Initializes a PDM critical section.
2182 *
2183 * The PDM critical sections are derived from the IPRT critical sections, but
2184 * works in GC as well.
2185 *
2186 * @returns VBox status code.
2187 * @param pDevIns Device instance.
2188 * @param pCritSect Pointer to the critical section.
2189 * @param pszName The name of the critical section (for statistics).
2190 */
2191 DECLR3CALLBACKMEMBER(int, pfnCritSectInit,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, const char *pszName));
2192
2193 /**
2194 * Get the real world UTC time adjusted for VM lag, user offset and warpdrive.
2195 *
2196 * @returns pTime.
2197 * @param pDevIns Device instance.
2198 * @param pTime Where to store the time.
2199 */
2200 DECLR3CALLBACKMEMBER(PRTTIMESPEC, pfnUTCNow,(PPDMDEVINS pDevIns, PRTTIMESPEC pTime));
2201
2202 /**
2203 * Creates a PDM thread.
2204 *
2205 * This differs from the RTThreadCreate() API in that PDM takes care of suspending,
2206 * resuming, and destroying the thread as the VM state changes.
2207 *
2208 * @returns VBox status code.
2209 * @param pDevIns The device instance.
2210 * @param ppThread Where to store the thread 'handle'.
2211 * @param pvUser The user argument to the thread function.
2212 * @param pfnThread The thread function.
2213 * @param pfnWakeup The wakup callback. This is called on the EMT thread when
2214 * a state change is pending.
2215 * @param cbStack See RTThreadCreate.
2216 * @param enmType See RTThreadCreate.
2217 * @param pszName See RTThreadCreate.
2218 */
2219 DECLR3CALLBACKMEMBER(int, pfnPDMThreadCreate,(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
2220 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName));
2221
2222 /**
2223 * Convert a guest virtual address to a guest physical address.
2224 *
2225 * @returns VBox status code.
2226 * @param pDevIns Device instance.
2227 * @param GCPtr Guest virtual address.
2228 * @param pGCPhys Where to store the GC physical address corresponding to GCPtr.
2229 * @thread The emulation thread.
2230 * @remark Careful with page boundraries.
2231 */
2232 DECLR3CALLBACKMEMBER(int, pfnPhysGCPtr2GCPhys, (PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys));
2233
2234 /**
2235 * Gets the VM state.
2236 *
2237 * @returns VM state.
2238 * @param pDevIns The device instance.
2239 * @thread Any thread (just keep in mind that it's volatile info).
2240 */
2241 DECLR3CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
2242
2243 /** Space reserved for future members.
2244 * @{ */
2245 DECLR3CALLBACKMEMBER(void, pfnReserved4,(void));
2246 DECLR3CALLBACKMEMBER(void, pfnReserved5,(void));
2247 DECLR3CALLBACKMEMBER(void, pfnReserved6,(void));
2248 DECLR3CALLBACKMEMBER(void, pfnReserved7,(void));
2249 DECLR3CALLBACKMEMBER(void, pfnReserved8,(void));
2250 DECLR3CALLBACKMEMBER(void, pfnReserved9,(void));
2251 DECLR3CALLBACKMEMBER(void, pfnReserved10,(void));
2252 /** @} */
2253
2254
2255 /** API available to trusted devices only.
2256 *
2257 * These APIs are providing unrestricted access to the guest and the VM,
2258 * or they are interacting intimately with PDM.
2259 *
2260 * @{
2261 */
2262 /**
2263 * Gets the VM handle. Restricted API.
2264 *
2265 * @returns VM Handle.
2266 * @param pDevIns Device instance.
2267 */
2268 DECLR3CALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
2269
2270 /**
2271 * Register the PCI Bus.
2272 *
2273 * @returns VBox status code.
2274 * @param pDevIns Device instance.
2275 * @param pPciBusReg Pointer to PCI bus registration structure.
2276 * @param ppPciHlpR3 Where to store the pointer to the PCI Bus helpers.
2277 */
2278 DECLR3CALLBACKMEMBER(int, pfnPCIBusRegister,(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3));
2279
2280 /**
2281 * Register the PIC device.
2282 *
2283 * @returns VBox status code.
2284 * @param pDevIns Device instance.
2285 * @param pPicReg Pointer to a PIC registration structure.
2286 * @param ppPicHlpR3 Where to store the pointer to the PIC HC helpers.
2287 */
2288 DECLR3CALLBACKMEMBER(int, pfnPICRegister,(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3));
2289
2290 /**
2291 * Register the APIC device.
2292 *
2293 * @returns VBox status code.
2294 * @param pDevIns Device instance.
2295 * @param pApicReg Pointer to a APIC registration structure.
2296 * @param ppApicHlpR3 Where to store the pointer to the APIC helpers.
2297 */
2298 DECLR3CALLBACKMEMBER(int, pfnAPICRegister,(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3));
2299
2300 /**
2301 * Register the I/O APIC device.
2302 *
2303 * @returns VBox status code.
2304 * @param pDevIns Device instance.
2305 * @param pIoApicReg Pointer to a I/O APIC registration structure.
2306 * @param ppIoApicHlpR3 Where to store the pointer to the IOAPIC helpers.
2307 */
2308 DECLR3CALLBACKMEMBER(int, pfnIOAPICRegister,(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3));
2309
2310 /**
2311 * Register the DMA device.
2312 *
2313 * @returns VBox status code.
2314 * @param pDevIns Device instance.
2315 * @param pDmacReg Pointer to a DMAC registration structure.
2316 * @param ppDmacHlp Where to store the pointer to the DMA helpers.
2317 */
2318 DECLR3CALLBACKMEMBER(int, pfnDMACRegister,(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp));
2319
2320 /**
2321 * Read physical memory.
2322 *
2323 * @param pDevIns Device instance.
2324 * @param GCPhys Physical address start reading from.
2325 * @param pvBuf Where to put the read bits.
2326 * @param cbRead How many bytes to read.
2327 * @thread Any thread, but the call may involve the emulation thread.
2328 */
2329 DECLR3CALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
2330
2331 /**
2332 * Write to physical memory.
2333 *
2334 * @param pDevIns Device instance.
2335 * @param GCPhys Physical address to write to.
2336 * @param pvBuf What to write.
2337 * @param cbWrite How many bytes to write.
2338 * @thread Any thread, but the call may involve the emulation thread.
2339 */
2340 DECLR3CALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
2341
2342 /**
2343 * Read guest physical memory by virtual address.
2344 *
2345 * @param pDevIns Device instance.
2346 * @param pvDst Where to put the read bits.
2347 * @param GCVirtSrc Guest virtual address to start reading from.
2348 * @param cb How many bytes to read.
2349 * @thread The emulation thread.
2350 */
2351 DECLR3CALLBACKMEMBER(int, pfnPhysReadGCVirt,(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb));
2352
2353 /**
2354 * Write to guest physical memory by virtual address.
2355 *
2356 * @param pDevIns Device instance.
2357 * @param GCVirtDst Guest virtual address to write to.
2358 * @param pvSrc What to write.
2359 * @param cb How many bytes to write.
2360 * @thread The emulation thread.
2361 */
2362 DECLR3CALLBACKMEMBER(int, pfnPhysWriteGCVirt,(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb));
2363
2364 /**
2365 * Reserve physical address space for ROM and MMIO ranges.
2366 *
2367 * @returns VBox status code.
2368 * @param pDevIns Device instance.
2369 * @param GCPhys Start physical address.
2370 * @param cbRange The size of the range.
2371 * @param pszDesc Description string.
2372 * @thread The emulation thread.
2373 */
2374 DECLR3CALLBACKMEMBER(int, pfnPhysReserve,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc));
2375
2376 /**
2377 * Convert a guest physical address to a host virtual address. (OBSOLETE)
2378 *
2379 * @returns VBox status code.
2380 * @param pDevIns Device instance.
2381 * @param GCPhys Start physical address.
2382 * @param cbRange The size of the range. Use 0 if you don't care about the range.
2383 * @param ppvHC Where to store the HC pointer corresponding to GCPhys.
2384 * @thread The emulation thread.
2385 *
2386 * @remark Careful with page boundraries.
2387 * @remark Do not use the mapping after you return to the caller! (it could get invalidated/changed)
2388 */
2389 DECLR3CALLBACKMEMBER(int, pfnObsoletePhys2HCVirt,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR ppvHC));
2390
2391 /**
2392 * Convert a guest virtual address to a host virtual address. (OBSOLETE)
2393 *
2394 * @returns VBox status code.
2395 * @param pDevIns Device instance.
2396 * @param GCPtr Guest virtual address.
2397 * @param pHCPtr Where to store the HC pointer corresponding to GCPtr.
2398 * @thread The emulation thread.
2399 *
2400 * @remark Careful with page boundraries.
2401 * @remark Do not use the mapping after you return to the caller! (it could get invalidated/changed)
2402 */
2403 DECLR3CALLBACKMEMBER(int, pfnObsoletePhysGCPtr2HCPtr,(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTHCPTR pHCPtr));
2404
2405 /**
2406 * Checks if the Gate A20 is enabled or not.
2407 *
2408 * @returns true if A20 is enabled.
2409 * @returns false if A20 is disabled.
2410 * @param pDevIns Device instance.
2411 * @thread The emulation thread.
2412 */
2413 DECLR3CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
2414
2415 /**
2416 * Enables or disables the Gate A20.
2417 *
2418 * @param pDevIns Device instance.
2419 * @param fEnable Set this flag to enable the Gate A20; clear it to disable.
2420 * @thread The emulation thread.
2421 */
2422 DECLR3CALLBACKMEMBER(void, pfnA20Set,(PPDMDEVINS pDevIns, bool fEnable));
2423
2424 /**
2425 * Resets the VM.
2426 *
2427 * @returns The appropriate VBox status code to pass around on reset.
2428 * @param pDevIns Device instance.
2429 * @thread The emulation thread.
2430 */
2431 DECLR3CALLBACKMEMBER(int, pfnVMReset,(PPDMDEVINS pDevIns));
2432
2433 /**
2434 * Suspends the VM.
2435 *
2436 * @returns The appropriate VBox status code to pass around on suspend.
2437 * @param pDevIns Device instance.
2438 * @thread The emulation thread.
2439 */
2440 DECLR3CALLBACKMEMBER(int, pfnVMSuspend,(PPDMDEVINS pDevIns));
2441
2442 /**
2443 * Power off the VM.
2444 *
2445 * @returns The appropriate VBox status code to pass around on power off.
2446 * @param pDevIns Device instance.
2447 * @thread The emulation thread.
2448 */
2449 DECLR3CALLBACKMEMBER(int, pfnVMPowerOff,(PPDMDEVINS pDevIns));
2450
2451 /**
2452 * Acquire global VM lock
2453 *
2454 * @returns VBox status code
2455 * @param pDevIns Device instance.
2456 */
2457 DECLR3CALLBACKMEMBER(int , pfnLockVM,(PPDMDEVINS pDevIns));
2458
2459 /**
2460 * Release global VM lock
2461 *
2462 * @returns VBox status code
2463 * @param pDevIns Device instance.
2464 */
2465 DECLR3CALLBACKMEMBER(int, pfnUnlockVM,(PPDMDEVINS pDevIns));
2466
2467 /**
2468 * Check that the current thread owns the global VM lock.
2469 *
2470 * @returns boolean
2471 * @param pDevIns Device instance.
2472 * @param pszFile Filename of the assertion location.
2473 * @param iLine Linenumber of the assertion location.
2474 * @param pszFunction Function of the assertion location.
2475 */
2476 DECLR3CALLBACKMEMBER(bool, pfnAssertVMLock,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
2477
2478 /**
2479 * Register transfer function for DMA channel.
2480 *
2481 * @returns VBox status code.
2482 * @param pDevIns Device instance.
2483 * @param uChannel Channel number.
2484 * @param pfnTransferHandler Device specific transfer callback function.
2485 * @param pvUser User pointer to pass to the callback.
2486 * @thread EMT
2487 */
2488 DECLR3CALLBACKMEMBER(int, pfnDMARegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
2489
2490 /**
2491 * Read memory.
2492 *
2493 * @returns VBox status code.
2494 * @param pDevIns Device instance.
2495 * @param uChannel Channel number.
2496 * @param pvBuffer Pointer to target buffer.
2497 * @param off DMA position.
2498 * @param cbBlock Block size.
2499 * @param pcbRead Where to store the number of bytes which was read. optional.
2500 * @thread EMT
2501 */
2502 DECLR3CALLBACKMEMBER(int, pfnDMAReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead));
2503
2504 /**
2505 * Write memory.
2506 *
2507 * @returns VBox status code.
2508 * @param pDevIns Device instance.
2509 * @param uChannel Channel number.
2510 * @param pvBuffer Memory to write.
2511 * @param off DMA position.
2512 * @param cbBlock Block size.
2513 * @param pcbWritten Where to store the number of bytes which was written. optional.
2514 * @thread EMT
2515 */
2516 DECLR3CALLBACKMEMBER(int, pfnDMAWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten));
2517
2518 /**
2519 * Set the DREQ line.
2520 *
2521 * @returns VBox status code.
2522 * @param pDevIns Device instance.
2523 * @param uChannel Channel number.
2524 * @param uLevel Level of the line.
2525 * @thread EMT
2526 */
2527 DECLR3CALLBACKMEMBER(int, pfnDMASetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
2528
2529 /**
2530 * Get channel mode.
2531 *
2532 * @returns Channel mode. See specs.
2533 * @param pDevIns Device instance.
2534 * @param uChannel Channel number.
2535 * @thread EMT
2536 */
2537 DECLR3CALLBACKMEMBER(uint8_t, pfnDMAGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
2538
2539 /**
2540 * Schedule DMA execution.
2541 *
2542 * @param pDevIns Device instance.
2543 * @thread Any thread.
2544 */
2545 DECLR3CALLBACKMEMBER(void, pfnDMASchedule,(PPDMDEVINS pDevIns));
2546
2547 /**
2548 * Write CMOS value and update the checksum(s).
2549 *
2550 * @returns VBox status code.
2551 * @param pDevIns Device instance.
2552 * @param iReg The CMOS register index.
2553 * @param u8Value The CMOS register value.
2554 * @thread EMT
2555 */
2556 DECLR3CALLBACKMEMBER(int, pfnCMOSWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
2557
2558 /**
2559 * Read CMOS value.
2560 *
2561 * @returns VBox status code.
2562 * @param pDevIns Device instance.
2563 * @param iReg The CMOS register index.
2564 * @param pu8Value Where to store the CMOS register value.
2565 * @thread EMT
2566 */
2567 DECLR3CALLBACKMEMBER(int, pfnCMOSRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
2568
2569 /**
2570 * Query CPUID.
2571 *
2572 * @param pDevIns Device instance.
2573 * @param iLeaf The CPUID leaf to get.
2574 * @param pEax Where to store the EAX value.
2575 * @param pEbx Where to store the EBX value.
2576 * @param pEcx Where to store the ECX value.
2577 * @param pEdx Where to store the EDX value.
2578 */
2579 DECLR3CALLBACKMEMBER(void, pfnGetCpuId,(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx));
2580
2581 /**
2582 * Write protects a shadow ROM mapping.
2583 *
2584 * This is intented for use by the system BIOS or by the device that
2585 * employs a shadow ROM BIOS, so that the shadow ROM mapping can be
2586 * write protected once the POST is over.
2587 *
2588 * @param pDevIns Device instance.
2589 * @param GCPhysStart Where the shadow ROM mapping starts.
2590 * @param cbRange The size of the shadow ROM mapping.
2591 */
2592 DECLR3CALLBACKMEMBER(int, pfnROMProtectShadow,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange));
2593
2594 /**
2595 * Allocate and register a MMIO2 region.
2596 *
2597 * As mentioned elsewhere, MMIO2 is just RAM spelled differently. It's
2598 * RAM associated with a device. It is also non-shared memory with a
2599 * permanent ring-3 mapping and page backing (presently).
2600 *
2601 * @returns VBox status.
2602 * @param pDevIns The device instance.
2603 * @param iRegion The region number. Use the PCI region number as
2604 * this must be known to the PCI bus device too. If it's not associated
2605 * with the PCI device, then any number up to UINT8_MAX is fine.
2606 * @param cb The size (in bytes) of the region.
2607 * @param fFlags Reserved for future use, must be zero.
2608 * @param ppv Where to store the address of the ring-3 mapping of the memory.
2609 * @param pszDesc Pointer to description string. This must not be freed.
2610 * @thread EMT.
2611 */
2612 DECLR3CALLBACKMEMBER(int, pfnMMIO2Register,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc));
2613
2614 /**
2615 * Deregisters and frees a MMIO2 region.
2616 *
2617 * Any physical (and virtual) access handlers registered for the region must
2618 * be deregistered before calling this function.
2619 *
2620 * @returns VBox status code.
2621 * @param pDevIns The device instance.
2622 * @param iRegion The region number used during registration.
2623 * @thread EMT.
2624 */
2625 DECLR3CALLBACKMEMBER(int, pfnMMIO2Deregister,(PPDMDEVINS pDevIns, uint32_t iRegion));
2626
2627 /**
2628 * Maps a MMIO2 region into the physical memory space.
2629 *
2630 * A MMIO2 range may overlap with base memory if a lot of RAM
2631 * is configured for the VM, in which case we'll drop the base
2632 * memory pages. Presently we will make no attempt to preserve
2633 * anything that happens to be present in the base memory that
2634 * is replaced, this is of course incorrectly but it's too much
2635 * effort.
2636 *
2637 * @returns VBox status code.
2638 * @param pDevIns The device instance.
2639 * @param iRegion The region number used during registration.
2640 * @param GCPhys The physical address to map it at.
2641 * @thread EMT.
2642 */
2643 DECLR3CALLBACKMEMBER(int, pfnMMIO2Map,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys));
2644
2645 /**
2646 * Unmaps a MMIO2 region previously mapped using pfnMMIO2Map.
2647 *
2648 * @returns VBox status code.
2649 * @param pDevIns The device instance.
2650 * @param iRegion The region number used during registration.
2651 * @param GCPhys The physical address it's currently mapped at.
2652 * @thread EMT.
2653 */
2654 DECLR3CALLBACKMEMBER(int, pfnMMIO2Unmap,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys));
2655
2656 /**
2657 * Maps a portion of an MMIO2 region into the hypervisor region.
2658 *
2659 * Callers of this API must never deregister the MMIO2 region before the
2660 * VM is powered off.
2661 *
2662 * @return VBox status code.
2663 * @param pDevIns The device owning the MMIO2 memory.
2664 * @param iRegion The region.
2665 * @param off The offset into the region. Will be rounded down to closest page boundrary.
2666 * @param cb The number of bytes to map. Will be rounded up to the closest page boundrary.
2667 * @param pszDesc Mapping description.
2668 * @param pGCPtr Where to store the GC address.
2669 */
2670 DECLR3CALLBACKMEMBER(int, pfnMMHyperMapMMIO2,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
2671 const char *pszDesc, PRTGCPTR pGCPtr));
2672
2673 /** @} */
2674
2675 /** Just a safety precaution. (PDM_DEVHLP_VERSION) */
2676 uint32_t u32TheEnd;
2677} PDMDEVHLP;
2678#endif /* !IN_RING3 */
2679/** Pointer PDM Device API. */
2680typedef R3PTRTYPE(struct PDMDEVHLP *) PPDMDEVHLP;
2681/** Pointer PDM Device API. */
2682typedef R3PTRTYPE(const struct PDMDEVHLP *) PCPDMDEVHLP;
2683
2684/** Current PDMDEVHLP version number. */
2685#define PDM_DEVHLP_VERSION 0xf2050002
2686
2687
2688/**
2689 * PDM Device API - GC Variant.
2690 */
2691typedef struct PDMDEVHLPGC
2692{
2693 /** Structure version. PDM_DEVHLPGC_VERSION defines the current version. */
2694 uint32_t u32Version;
2695
2696 /**
2697 * Set the IRQ for a PCI device.
2698 *
2699 * @param pDevIns Device instance.
2700 * @param iIrq IRQ number to set.
2701 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2702 * @thread Any thread, but will involve the emulation thread.
2703 */
2704 DECLGCCALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2705
2706 /**
2707 * Set ISA IRQ for a device.
2708 *
2709 * @param pDevIns Device instance.
2710 * @param iIrq IRQ number to set.
2711 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2712 * @thread Any thread, but will involve the emulation thread.
2713 */
2714 DECLGCCALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2715
2716 /**
2717 * Read physical memory.
2718 *
2719 * @param pDevIns Device instance.
2720 * @param GCPhys Physical address start reading from.
2721 * @param pvBuf Where to put the read bits.
2722 * @param cbRead How many bytes to read.
2723 */
2724 DECLGCCALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
2725
2726 /**
2727 * Write to physical memory.
2728 *
2729 * @param pDevIns Device instance.
2730 * @param GCPhys Physical address to write to.
2731 * @param pvBuf What to write.
2732 * @param cbWrite How many bytes to write.
2733 */
2734 DECLGCCALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
2735
2736 /**
2737 * Checks if the Gate A20 is enabled or not.
2738 *
2739 * @returns true if A20 is enabled.
2740 * @returns false if A20 is disabled.
2741 * @param pDevIns Device instance.
2742 * @thread The emulation thread.
2743 */
2744 DECLGCCALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
2745
2746 /**
2747 * Set the VM error message
2748 *
2749 * @returns rc.
2750 * @param pDrvIns Driver instance.
2751 * @param rc VBox status code.
2752 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2753 * @param pszFormat Error message format string.
2754 * @param ... Error message arguments.
2755 */
2756 DECLGCCALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
2757
2758 /**
2759 * Set the VM error message
2760 *
2761 * @returns rc.
2762 * @param pDrvIns Driver instance.
2763 * @param rc VBox status code.
2764 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2765 * @param pszFormat Error message format string.
2766 * @param va Error message arguments.
2767 */
2768 DECLGCCALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
2769
2770 /**
2771 * Set the VM runtime error message
2772 *
2773 * @returns VBox status code.
2774 * @param pDevIns Device instance.
2775 * @param fFatal Whether it is a fatal error or not.
2776 * @param pszErrorID Error ID string.
2777 * @param pszFormat Error message format string.
2778 * @param ... Error message arguments.
2779 */
2780 DECLGCCALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...));
2781
2782 /**
2783 * Set the VM runtime error message
2784 *
2785 * @returns VBox status code.
2786 * @param pDevIns Device instance.
2787 * @param fFatal Whether it is a fatal error or not.
2788 * @param pszErrorID Error ID string.
2789 * @param pszFormat Error message format string.
2790 * @param va Error message arguments.
2791 */
2792 DECLGCCALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
2793
2794 /**
2795 * Set parameters for pending MMIO patch operation
2796 *
2797 * @returns VBox status code.
2798 * @param pDevIns Device instance.
2799 * @param GCPhys MMIO physical address
2800 * @param pCachedData GC pointer to cached data
2801 */
2802 DECLGCCALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
2803
2804 /** Just a safety precaution. */
2805 uint32_t u32TheEnd;
2806} PDMDEVHLPGC;
2807/** Pointer PDM Device GC API. */
2808typedef GCPTRTYPE(struct PDMDEVHLPGC *) PPDMDEVHLPGC;
2809/** Pointer PDM Device GC API. */
2810typedef GCPTRTYPE(const struct PDMDEVHLPGC *) PCPDMDEVHLPGC;
2811
2812/** Current PDMDEVHLP version number. */
2813#define PDM_DEVHLPGC_VERSION 0xfb010000
2814
2815
2816/**
2817 * PDM Device API - R0 Variant.
2818 */
2819typedef struct PDMDEVHLPR0
2820{
2821 /** Structure version. PDM_DEVHLPR0_VERSION defines the current version. */
2822 uint32_t u32Version;
2823
2824 /**
2825 * Set the IRQ for a PCI device.
2826 *
2827 * @param pDevIns Device instance.
2828 * @param iIrq IRQ number to set.
2829 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2830 * @thread Any thread, but will involve the emulation thread.
2831 */
2832 DECLR0CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2833
2834 /**
2835 * Set ISA IRQ for a device.
2836 *
2837 * @param pDevIns Device instance.
2838 * @param iIrq IRQ number to set.
2839 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2840 * @thread Any thread, but will involve the emulation thread.
2841 */
2842 DECLR0CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2843
2844 /**
2845 * Read physical memory.
2846 *
2847 * @param pDevIns Device instance.
2848 * @param GCPhys Physical address start reading from.
2849 * @param pvBuf Where to put the read bits.
2850 * @param cbRead How many bytes to read.
2851 */
2852 DECLR0CALLBACKMEMBER(void, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
2853
2854 /**
2855 * Write to physical memory.
2856 *
2857 * @param pDevIns Device instance.
2858 * @param GCPhys Physical address to write to.
2859 * @param pvBuf What to write.
2860 * @param cbWrite How many bytes to write.
2861 */
2862 DECLR0CALLBACKMEMBER(void, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
2863
2864 /**
2865 * Checks if the Gate A20 is enabled or not.
2866 *
2867 * @returns true if A20 is enabled.
2868 * @returns false if A20 is disabled.
2869 * @param pDevIns Device instance.
2870 * @thread The emulation thread.
2871 */
2872 DECLR0CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
2873
2874 /**
2875 * Set the VM error message
2876 *
2877 * @returns rc.
2878 * @param pDrvIns Driver instance.
2879 * @param rc VBox status code.
2880 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2881 * @param pszFormat Error message format string.
2882 * @param ... Error message arguments.
2883 */
2884 DECLR0CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
2885
2886 /**
2887 * Set the VM error message
2888 *
2889 * @returns rc.
2890 * @param pDrvIns Driver instance.
2891 * @param rc VBox status code.
2892 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2893 * @param pszFormat Error message format string.
2894 * @param va Error message arguments.
2895 */
2896 DECLR0CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
2897
2898 /**
2899 * Set the VM runtime error message
2900 *
2901 * @returns VBox status code.
2902 * @param pDevIns Device instance.
2903 * @param fFatal Whether it is a fatal error or not.
2904 * @param pszErrorID Error ID string.
2905 * @param pszFormat Error message format string.
2906 * @param ... Error message arguments.
2907 */
2908 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...));
2909
2910 /**
2911 * Set the VM runtime error message
2912 *
2913 * @returns VBox status code.
2914 * @param pDevIns Device instance.
2915 * @param fFatal Whether it is a fatal error or not.
2916 * @param pszErrorID Error ID string.
2917 * @param pszFormat Error message format string.
2918 * @param va Error message arguments.
2919 */
2920 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
2921
2922 /**
2923 * Set parameters for pending MMIO patch operation
2924 *
2925 * @returns rc.
2926 * @param pDevIns Device instance.
2927 * @param GCPhys MMIO physical address
2928 * @param pCachedData GC pointer to cached data
2929 */
2930 DECLR0CALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
2931
2932 /** Just a safety precaution. */
2933 uint32_t u32TheEnd;
2934} PDMDEVHLPR0;
2935/** Pointer PDM Device R0 API. */
2936typedef R0PTRTYPE(struct PDMDEVHLPR0 *) PPDMDEVHLPR0;
2937/** Pointer PDM Device GC API. */
2938typedef R0PTRTYPE(const struct PDMDEVHLPR0 *) PCPDMDEVHLPR0;
2939
2940/** Current PDMDEVHLP version number. */
2941#define PDM_DEVHLPR0_VERSION 0xfb010000
2942
2943
2944
2945/**
2946 * PDM Device Instance.
2947 */
2948typedef struct PDMDEVINS
2949{
2950 /** Structure version. PDM_DEVINS_VERSION defines the current version. */
2951 uint32_t u32Version;
2952 /** Device instance number. */
2953 RTUINT iInstance;
2954 /** The base interface of the device.
2955 * The device constructor initializes this if it has any
2956 * device level interfaces to export. To obtain this interface
2957 * call PDMR3QueryDevice(). */
2958 PDMIBASE IBase;
2959
2960 /** Internal data. */
2961 union
2962 {
2963#ifdef PDMDEVINSINT_DECLARED
2964 PDMDEVINSINT s;
2965#endif
2966 uint8_t padding[HC_ARCH_BITS == 32 ? 48 : 96];
2967 } Internal;
2968
2969 /** Pointer the HC PDM Device API. */
2970 R3PTRTYPE(PCPDMDEVHLP) pDevHlp;
2971 /** Pointer the R0 PDM Device API. */
2972 R0PTRTYPE(PCPDMDEVHLPR0) pDevHlpR0;
2973 /** Pointer to device registration structure. */
2974 R3PTRTYPE(PCPDMDEVREG) pDevReg;
2975 /** Configuration handle. */
2976 R3PTRTYPE(PCFGMNODE) pCfgHandle;
2977 /** Pointer to device instance data. */
2978 R3PTRTYPE(void *) pvInstanceDataR3;
2979 /** Pointer to device instance data. */
2980 R0PTRTYPE(void *) pvInstanceDataR0;
2981 /** Pointer the GC PDM Device API. */
2982 GCPTRTYPE(PCPDMDEVHLPGC) pDevHlpGC;
2983 /** Pointer to device instance data. */
2984 GCPTRTYPE(void *) pvInstanceDataGC;
2985 /* padding to make achInstanceData aligned at 32 byte boundrary. */
2986 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 1 : 6];
2987 /** Device instance data. The size of this area is defined
2988 * in the PDMDEVREG::cbInstanceData field. */
2989 char achInstanceData[8];
2990} PDMDEVINS;
2991
2992/** Current DEVREG version number. */
2993#define PDM_DEVINS_VERSION 0xf3010000
2994
2995/** Converts a pointer to the PDMDEVINS::IBase to a pointer to PDMDEVINS. */
2996#define PDMIBASE_2_PDMDEV(pInterface) ( (PPDMDEVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDEVINS, IBase)) )
2997
2998
2999/** @def PDMDEV_ASSERT_EMT
3000 * Assert that the current thread is the emulation thread.
3001 */
3002#ifdef VBOX_STRICT
3003# define PDMDEV_ASSERT_EMT(pDevIns) pDevIns->pDevHlp->pfnAssertEMT(pDevIns, __FILE__, __LINE__, __FUNCTION__)
3004#else
3005# define PDMDEV_ASSERT_EMT(pDevIns) do { } while (0)
3006#endif
3007
3008/** @def PDMDEV_ASSERT_OTHER
3009 * Assert that the current thread is NOT the emulation thread.
3010 */
3011#ifdef VBOX_STRICT
3012# define PDMDEV_ASSERT_OTHER(pDevIns) pDevIns->pDevHlp->pfnAssertOther(pDevIns, __FILE__, __LINE__, __FUNCTION__)
3013#else
3014# define PDMDEV_ASSERT_OTHER(pDevIns) do { } while (0)
3015#endif
3016
3017/** @def PDMDEV_ASSERT_VMLOCK_OWNER
3018 * Assert that the current thread is owner of the VM lock.
3019 */
3020#ifdef VBOX_STRICT
3021# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) pDevIns->pDevHlp->pfnAssertVMLock(pDevIns, __FILE__, __LINE__, __FUNCTION__)
3022#else
3023# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) do { } while (0)
3024#endif
3025
3026/** @def PDMDEV_SET_ERROR
3027 * Set the VM error. See PDMDevHlpVMSetError() for printf like message formatting.
3028 */
3029#define PDMDEV_SET_ERROR(pDevIns, rc, pszError) \
3030 PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, "%s", pszError)
3031
3032/** @def PDMDEV_SET_RUNTIME_ERROR
3033 * Set the VM runtime error. See PDMDevHlpVMSetRuntimeError() for printf like message formatting.
3034 */
3035#define PDMDEV_SET_RUNTIME_ERROR(pDevIns, fFatal, pszErrorID, pszError) \
3036 PDMDevHlpVMSetRuntimeError(pDevIns, fFatal, pszErrorID, "%s", pszError)
3037
3038/** @def PDMDEVINS_2_GCPTR
3039 * Converts a PDM Device instance pointer a GC PDM Device instance pointer.
3040 */
3041#define PDMDEVINS_2_GCPTR(pDevIns) ( (GCPTRTYPE(PPDMDEVINS))((RTGCUINTPTR)(pDevIns)->pvInstanceDataGC - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
3042
3043/** @def PDMDEVINS_2_R3PTR
3044 * Converts a PDM Device instance pointer a HC PDM Device instance pointer.
3045 */
3046#define PDMDEVINS_2_R3PTR(pDevIns) ( (R3PTRTYPE(PPDMDEVINS))((RTHCUINTPTR)(pDevIns)->pvInstanceDataR3 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
3047
3048/** @def PDMDEVINS_2_R0PTR
3049 * Converts a PDM Device instance pointer a R0 PDM Device instance pointer.
3050 */
3051#define PDMDEVINS_2_R0PTR(pDevIns) ( (R0PTRTYPE(PPDMDEVINS))((RTR0UINTPTR)(pDevIns)->pvInstanceDataR0 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
3052
3053
3054/**
3055 * VBOX_STRICT wrapper for pDevHlp->pfnDBGFStopV.
3056 *
3057 * @returns VBox status code which must be passed up to the VMM.
3058 * @param pDevIns Device instance.
3059 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3060 * @param pszFormat Message. (optional)
3061 * @param ... Message parameters.
3062 */
3063DECLINLINE(int) PDMDeviceDBGFStop(PPDMDEVINS pDevIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
3064{
3065#ifdef VBOX_STRICT
3066# ifdef IN_RING3
3067 int rc;
3068 va_list args;
3069 va_start(args, pszFormat);
3070 rc = pDevIns->pDevHlp->pfnDBGFStopV(pDevIns, RT_SRC_POS_ARGS, pszFormat, args);
3071 va_end(args);
3072 return rc;
3073# else
3074 return VINF_EM_DBG_STOP;
3075# endif
3076#else
3077 return VINF_SUCCESS;
3078#endif
3079}
3080
3081
3082#ifdef IN_RING3
3083/**
3084 * @copydoc PDMDEVHLP::pfnIOPortRegister
3085 */
3086DECLINLINE(int) PDMDevHlpIOPortRegister(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTHCPTR pvUser,
3087 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
3088 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc)
3089{
3090 return pDevIns->pDevHlp->pfnIOPortRegister(pDevIns, Port, cPorts, pvUser, pfnOut, pfnIn, pfnOutStr, pfnInStr, pszDesc);
3091}
3092
3093/**
3094 * @copydoc PDMDEVHLP::pfnIOPortRegisterGC
3095 */
3096DECLINLINE(int) PDMDevHlpIOPortRegisterGC(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTGCPTR pvUser,
3097 const char *pszOut, const char *pszIn, const char *pszOutStr,
3098 const char *pszInStr, const char *pszDesc)
3099{
3100 return pDevIns->pDevHlp->pfnIOPortRegisterGC(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
3101}
3102
3103/**
3104 * @copydoc PDMDEVHLP::pfnIOPortRegisterR0
3105 */
3106DECLINLINE(int) PDMDevHlpIOPortRegisterR0(PPDMDEVINS pDevIns, RTIOPORT Port, RTUINT cPorts, RTR0PTR pvUser,
3107 const char *pszOut, const char *pszIn, const char *pszOutStr,
3108 const char *pszInStr, const char *pszDesc)
3109{
3110 return pDevIns->pDevHlp->pfnIOPortRegisterR0(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
3111}
3112
3113/**
3114 * @copydoc PDMDEVHLP::pfnMMIORegister
3115 */
3116DECLINLINE(int) PDMDevHlpMMIORegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTHCPTR pvUser,
3117 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
3118 const char *pszDesc)
3119{
3120 return pDevIns->pDevHlp->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, pfnFill, pszDesc);
3121}
3122
3123/**
3124 * @copydoc PDMDEVHLP::pfnMMIORegisterGC
3125 */
3126DECLINLINE(int) PDMDevHlpMMIORegisterGC(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTGCPTR pvUser,
3127 const char *pszWrite, const char *pszRead, const char *pszFill)
3128{
3129 return pDevIns->pDevHlp->pfnMMIORegisterGC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill, NULL);
3130}
3131
3132/**
3133 * @copydoc PDMDEVHLP::pfnMMIORegisterR0
3134 */
3135DECLINLINE(int) PDMDevHlpMMIORegisterR0(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, RTR0PTR pvUser,
3136 const char *pszWrite, const char *pszRead, const char *pszFill)
3137{
3138 return pDevIns->pDevHlp->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill, NULL);
3139}
3140
3141/**
3142 * @copydoc PDMDEVHLP::pfnROMRegister
3143 */
3144DECLINLINE(int) PDMDevHlpROMRegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange, const void *pvBinary, bool fShadow, const char *pszDesc)
3145{
3146 return pDevIns->pDevHlp->pfnROMRegister(pDevIns, GCPhysStart, cbRange, pvBinary, fShadow, pszDesc);
3147}
3148/**
3149 * @copydoc PDMDEVHLP::pfnROMProtectShadow
3150 */
3151DECLINLINE(int) PDMDevHlpROMProtectShadow(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTUINT cbRange)
3152{
3153 return pDevIns->pDevHlp->pfnROMProtectShadow(pDevIns, GCPhysStart, cbRange);
3154}
3155
3156/**
3157 * @copydoc PDMDEVHLP::pfnMMIO2Register
3158 */
3159DECLINLINE(int) PDMDevHlpMMIO2Register(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc)
3160{
3161 return pDevIns->pDevHlp->pfnMMIO2Register(pDevIns, iRegion, cb, fFlags, ppv, pszDesc);
3162}
3163
3164/**
3165 * @copydoc PDMDEVHLP::pfnMMIO2Deregister
3166 */
3167DECLINLINE(int) PDMDevHlpMMIO2Deregister(PPDMDEVINS pDevIns, uint32_t iRegion)
3168{
3169 return pDevIns->pDevHlp->pfnMMIO2Deregister(pDevIns, iRegion);
3170}
3171
3172/**
3173 * @copydoc PDMDEVHLP::pfnMMIO2Map
3174 */
3175DECLINLINE(int) PDMDevHlpMMIO2Map(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
3176{
3177 return pDevIns->pDevHlp->pfnMMIO2Map(pDevIns, iRegion, GCPhys);
3178}
3179
3180/**
3181 * @copydoc PDMDEVHLP::pfnMMIO2Unmap
3182 */
3183DECLINLINE(int) PDMDevHlpMMIO2Unmap(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
3184{
3185 return pDevIns->pDevHlp->pfnMMIO2Unmap(pDevIns, iRegion, GCPhys);
3186}
3187
3188/**
3189 * @copydoc PDMDEVHLP::pfnMMHyperMapMMIO2
3190 */
3191DECLINLINE(int) PDMDevHlpMMHyperMapMMIO2(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
3192 const char *pszDesc, PRTGCPTR pGCPtr)
3193{
3194 return pDevIns->pDevHlp->pfnMMHyperMapMMIO2(pDevIns, iRegion, off, cb, pszDesc, pGCPtr);
3195}
3196
3197/**
3198 * @copydoc PDMDEVHLP::pfnSSMRegister
3199 */
3200DECLINLINE(int) PDMDevHlpSSMRegister(PPDMDEVINS pDevIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
3201 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
3202 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone)
3203{
3204 return pDevIns->pDevHlp->pfnSSMRegister(pDevIns, pszName, u32Instance, u32Version, cbGuess,
3205 pfnSavePrep, pfnSaveExec, pfnSaveDone,
3206 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
3207}
3208
3209/**
3210 * @copydoc PDMDEVHLP::pfnTMTimerCreate
3211 */
3212DECLINLINE(int) PDMDevHlpTMTimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer)
3213{
3214 return pDevIns->pDevHlp->pfnTMTimerCreate(pDevIns, enmClock, pfnCallback, pszDesc, ppTimer);
3215}
3216
3217/**
3218 * @copydoc PDMDEVHLP::pfnPCIRegister
3219 */
3220DECLINLINE(int) PDMDevHlpPCIRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev)
3221{
3222 return pDevIns->pDevHlp->pfnPCIRegister(pDevIns, pPciDev);
3223}
3224
3225/**
3226 * @copydoc PDMDEVHLP::pfnPCIIORegionRegister
3227 */
3228DECLINLINE(int) PDMDevHlpPCIIORegionRegister(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
3229{
3230 return pDevIns->pDevHlp->pfnPCIIORegionRegister(pDevIns, iRegion, cbRegion, enmType, pfnCallback);
3231}
3232
3233/**
3234 * @copydoc PDMDEVHLP::pfnPCISetConfigCallbacks
3235 */
3236DECLINLINE(void) PDMDevHlpPCISetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
3237 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
3238{
3239 pDevIns->pDevHlp->pfnPCISetConfigCallbacks(pDevIns, pPciDev, pfnRead, ppfnReadOld, pfnWrite, ppfnWriteOld);
3240}
3241
3242/**
3243 * @copydoc PDMDEVHLP::pfnDriverAttach
3244 */
3245DECLINLINE(int) PDMDevHlpDriverAttach(PPDMDEVINS pDevIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
3246{
3247 return pDevIns->pDevHlp->pfnDriverAttach(pDevIns, iLun, pBaseInterface, ppBaseInterface, pszDesc);
3248}
3249
3250/**
3251 * @copydoc PDMDEVHLP::pfnMMHeapAlloc
3252 */
3253DECLINLINE(void *) PDMDevHlpMMHeapAlloc(PPDMDEVINS pDevIns, size_t cb)
3254{
3255 return pDevIns->pDevHlp->pfnMMHeapAlloc(pDevIns, cb);
3256}
3257
3258/**
3259 * @copydoc PDMDEVHLP::pfnMMHeapAllocZ
3260 */
3261DECLINLINE(void *) PDMDevHlpMMHeapAllocZ(PPDMDEVINS pDevIns, size_t cb)
3262{
3263 return pDevIns->pDevHlp->pfnMMHeapAllocZ(pDevIns, cb);
3264}
3265
3266/**
3267 * @copydoc PDMDEVHLP::pfnMMHeapFree
3268 */
3269DECLINLINE(void) PDMDevHlpMMHeapFree(PPDMDEVINS pDevIns, void *pv)
3270{
3271 pDevIns->pDevHlp->pfnMMHeapFree(pDevIns, pv);
3272}
3273
3274/**
3275 * @copydoc PDMDEVHLP::pfnDBGFInfoRegister
3276 */
3277DECLINLINE(int) PDMDevHlpDBGFInfoRegister(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler)
3278{
3279 return pDevIns->pDevHlp->pfnDBGFInfoRegister(pDevIns, pszName, pszDesc, pfnHandler);
3280}
3281
3282/**
3283 * @copydoc PDMDEVHLP::pfnSTAMRegister
3284 */
3285DECLINLINE(void) PDMDevHlpSTAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
3286{
3287 pDevIns->pDevHlp->pfnSTAMRegister(pDevIns, pvSample, enmType, pszName, enmUnit, pszDesc);
3288}
3289
3290/**
3291 * @copydoc PDMDEVHLP::pfnSTAMRegisterF
3292 */
3293DECLINLINE(void) PDMDevHlpSTAMRegisterF(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
3294 const char *pszDesc, const char *pszName, ...)
3295{
3296 va_list va;
3297 va_start(va, pszName);
3298 pDevIns->pDevHlp->pfnSTAMRegisterV(pDevIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
3299 va_end(va);
3300}
3301
3302/**
3303 * @copydoc PDMDEVHLP::pfnPDMQueueCreate
3304 */
3305DECLINLINE(int) PDMDevHlpPDMQueueCreate(PPDMDEVINS pDevIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
3306 PFNPDMQUEUEDEV pfnCallback, bool fGCEnabled, PPDMQUEUE *ppQueue)
3307{
3308 return pDevIns->pDevHlp->pfnPDMQueueCreate(pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fGCEnabled, ppQueue);
3309}
3310
3311/**
3312 * @copydoc PDMDEVHLP::pfnCritSectInit
3313 */
3314DECLINLINE(int) PDMDevHlpCritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, const char *pszName)
3315{
3316 return pDevIns->pDevHlp->pfnCritSectInit(pDevIns, pCritSect, pszName);
3317}
3318
3319/**
3320 * @copydoc PDMDEVHLP::pfnUTCNow
3321 */
3322DECLINLINE(PRTTIMESPEC) PDMDevHlpUTCNow(PPDMDEVINS pDevIns, PRTTIMESPEC pTime)
3323{
3324 return pDevIns->pDevHlp->pfnUTCNow(pDevIns, pTime);
3325}
3326
3327/**
3328 * @copydoc PDMDEVHLP::pfnGetVM
3329 */
3330DECLINLINE(PVM) PDMDevHlpGetVM(PPDMDEVINS pDevIns)
3331{
3332 return pDevIns->pDevHlp->pfnGetVM(pDevIns);
3333}
3334
3335/**
3336 * @copydoc PDMDEVHLP::pfnPhysReadGCVirt
3337 */
3338DECLINLINE(int) PDMDevHlpPhysReadGCVirt(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb)
3339{
3340 return pDevIns->pDevHlp->pfnPhysReadGCVirt(pDevIns, pvDst, GCVirtSrc, cb);
3341}
3342
3343/**
3344 * @copydoc PDMDEVHLP::pfnPhysWriteGCVirt
3345 */
3346DECLINLINE(int) PDMDevHlpPhysWriteGCVirt(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb)
3347{
3348 return pDevIns->pDevHlp->pfnPhysWriteGCVirt(pDevIns, GCVirtDst, pvSrc, cb);
3349}
3350
3351/**
3352 * @copydoc PDMDEVHLP::pfnPhysReserve
3353 */
3354DECLINLINE(int) PDMDevHlpPhysReserve(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc)
3355{
3356 return pDevIns->pDevHlp->pfnPhysReserve(pDevIns, GCPhys, cbRange, pszDesc);
3357}
3358
3359/**
3360 * @copydoc PDMDEVHLP::pfnPhysGCPtr2GCPhys
3361 */
3362DECLINLINE(int) PDMDevHlpPhysGCPtr2GCPhys(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys)
3363{
3364 return pDevIns->pDevHlp->pfnPhysGCPtr2GCPhys(pDevIns, GCPtr, pGCPhys);
3365}
3366
3367/**
3368 * @copydoc PDMDEVHLP::pfnVMState
3369 */
3370DECLINLINE(VMSTATE) PDMDevHlpVMState(PPDMDEVINS pDevIns)
3371{
3372 return pDevIns->pDevHlp->pfnVMState(pDevIns);
3373}
3374
3375/**
3376 * @copydoc PDMDEVHLP::pfnA20Set
3377 */
3378DECLINLINE(void) PDMDevHlpA20Set(PPDMDEVINS pDevIns, bool fEnable)
3379{
3380 pDevIns->pDevHlp->pfnA20Set(pDevIns, fEnable);
3381}
3382
3383/**
3384 * @copydoc PDMDEVHLP::pfnVMReset
3385 */
3386DECLINLINE(int) PDMDevHlpVMReset(PPDMDEVINS pDevIns)
3387{
3388 return pDevIns->pDevHlp->pfnVMReset(pDevIns);
3389}
3390
3391/**
3392 * @copydoc PDMDEVHLP::pfnVMSuspend
3393 */
3394DECLINLINE(int) PDMDevHlpVMSuspend(PPDMDEVINS pDevIns)
3395{
3396 return pDevIns->pDevHlp->pfnVMSuspend(pDevIns);
3397}
3398
3399/**
3400 * @copydoc PDMDEVHLP::pfnVMPowerOff
3401 */
3402DECLINLINE(int) PDMDevHlpVMPowerOff(PPDMDEVINS pDevIns)
3403{
3404 return pDevIns->pDevHlp->pfnVMPowerOff(pDevIns);
3405}
3406
3407/**
3408 * @copydoc PDMDEVHLP::pfnDMARegister
3409 */
3410DECLINLINE(int) PDMDevHlpDMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
3411{
3412 return pDevIns->pDevHlp->pfnDMARegister(pDevIns, uChannel, pfnTransferHandler, pvUser);
3413}
3414
3415/**
3416 * @copydoc PDMDEVHLP::pfnDMAReadMemory
3417 */
3418DECLINLINE(int) PDMDevHlpDMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
3419{
3420 return pDevIns->pDevHlp->pfnDMAReadMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbRead);
3421}
3422
3423/**
3424 * @copydoc PDMDEVHLP::pfnDMAWriteMemory
3425 */
3426DECLINLINE(int) PDMDevHlpDMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
3427{
3428 return pDevIns->pDevHlp->pfnDMAWriteMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbWritten);
3429}
3430
3431/**
3432 * @copydoc PDMDEVHLP::pfnDMASetDREQ
3433 */
3434DECLINLINE(int) PDMDevHlpDMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
3435{
3436 return pDevIns->pDevHlp->pfnDMASetDREQ(pDevIns, uChannel, uLevel);
3437}
3438
3439/**
3440 * @copydoc PDMDEVHLP::pfnDMAGetChannelMode
3441 */
3442DECLINLINE(uint8_t) PDMDevHlpDMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
3443{
3444 return pDevIns->pDevHlp->pfnDMAGetChannelMode(pDevIns, uChannel);
3445}
3446
3447/**
3448 * @copydoc PDMDEVHLP::pfnDMASchedule
3449 */
3450DECLINLINE(void) PDMDevHlpDMASchedule(PPDMDEVINS pDevIns)
3451{
3452 pDevIns->pDevHlp->pfnDMASchedule(pDevIns);
3453}
3454
3455/**
3456 * @copydoc PDMDEVHLP::pfnCMOSWrite
3457 */
3458DECLINLINE(int) PDMDevHlpCMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
3459{
3460 return pDevIns->pDevHlp->pfnCMOSWrite(pDevIns, iReg, u8Value);
3461}
3462
3463/**
3464 * @copydoc PDMDEVHLP::pfnCMOSRead
3465 */
3466DECLINLINE(int) PDMDevHlpCMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
3467{
3468 return pDevIns->pDevHlp->pfnCMOSRead(pDevIns, iReg, pu8Value);
3469}
3470
3471/**
3472 * @copydoc PDMDEVHLP::pfnGetCpuId
3473 */
3474DECLINLINE(void) PDMDevHlpGetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
3475{
3476 pDevIns->pDevHlp->pfnGetCpuId(pDevIns, iLeaf, pEax, pEbx, pEcx, pEdx);
3477}
3478
3479/**
3480 * @copydoc PDMDEVHLP::pfnPDMThreadCreate
3481 */
3482DECLINLINE(int) PDMDevHlpPDMThreadCreate(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
3483 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
3484{
3485 return pDevIns->pDevHlp->pfnPDMThreadCreate(pDevIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
3486}
3487#endif /* IN_RING3 */
3488
3489
3490/**
3491 * @copydoc PDMDEVHLP::pfnPCISetIrq
3492 */
3493DECLINLINE(void) PDMDevHlpPCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
3494{
3495#ifdef IN_GC
3496 pDevIns->pDevHlpGC->pfnPCISetIrq(pDevIns, iIrq, iLevel);
3497#elif defined(IN_RING0)
3498 pDevIns->pDevHlpR0->pfnPCISetIrq(pDevIns, iIrq, iLevel);
3499#else
3500 pDevIns->pDevHlp->pfnPCISetIrq(pDevIns, iIrq, iLevel);
3501#endif
3502}
3503
3504/**
3505 * @copydoc PDMDEVHLP::pfnPCISetIrqNoWait
3506 */
3507DECLINLINE(void) PDMDevHlpPCISetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
3508{
3509#ifdef IN_GC
3510 pDevIns->pDevHlpGC->pfnPCISetIrq(pDevIns, iIrq, iLevel);
3511#elif defined(IN_RING0)
3512 pDevIns->pDevHlpR0->pfnPCISetIrq(pDevIns, iIrq, iLevel);
3513#else
3514 pDevIns->pDevHlp->pfnPCISetIrqNoWait(pDevIns, iIrq, iLevel);
3515#endif
3516}
3517
3518/**
3519 * @copydoc PDMDEVHLP::pfnISASetIrq
3520 */
3521DECLINLINE(void) PDMDevHlpISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
3522{
3523#ifdef IN_GC
3524 pDevIns->pDevHlpGC->pfnISASetIrq(pDevIns, iIrq, iLevel);
3525#elif defined(IN_RING0)
3526 pDevIns->pDevHlpR0->pfnISASetIrq(pDevIns, iIrq, iLevel);
3527#else
3528 pDevIns->pDevHlp->pfnISASetIrq(pDevIns, iIrq, iLevel);
3529#endif
3530}
3531
3532/**
3533 * @copydoc PDMDEVHLP::pfnISASetIrqNoWait
3534 */
3535DECLINLINE(void) PDMDevHlpISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
3536{
3537#ifdef IN_GC
3538 pDevIns->pDevHlpGC->pfnISASetIrq(pDevIns, iIrq, iLevel);
3539#elif defined(IN_RING0)
3540 pDevIns->pDevHlpR0->pfnISASetIrq(pDevIns, iIrq, iLevel);
3541#else
3542 pDevIns->pDevHlp->pfnISASetIrqNoWait(pDevIns, iIrq, iLevel);
3543#endif
3544}
3545
3546/**
3547 * @copydoc PDMDEVHLP::pfnPhysRead
3548 */
3549DECLINLINE(void) PDMDevHlpPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
3550{
3551#ifdef IN_GC
3552 pDevIns->pDevHlpGC->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
3553#elif defined(IN_RING0)
3554 pDevIns->pDevHlpR0->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
3555#else
3556 pDevIns->pDevHlp->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
3557#endif
3558}
3559
3560/**
3561 * @copydoc PDMDEVHLP::pfnPhysWrite
3562 */
3563DECLINLINE(void) PDMDevHlpPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
3564{
3565#ifdef IN_GC
3566 pDevIns->pDevHlpGC->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
3567#elif defined(IN_RING0)
3568 pDevIns->pDevHlpR0->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
3569#else
3570 pDevIns->pDevHlp->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
3571#endif
3572}
3573
3574/**
3575 * @copydoc PDMDEVHLP::pfnA20IsEnabled
3576 */
3577DECLINLINE(bool) PDMDevHlpA20IsEnabled(PPDMDEVINS pDevIns)
3578{
3579#ifdef IN_GC
3580 return pDevIns->pDevHlpGC->pfnA20IsEnabled(pDevIns);
3581#elif defined(IN_RING0)
3582 return pDevIns->pDevHlpR0->pfnA20IsEnabled(pDevIns);
3583#else
3584 return pDevIns->pDevHlp->pfnA20IsEnabled(pDevIns);
3585#endif
3586}
3587
3588/**
3589 * @copydoc PDMDEVHLP::pfnVMSetError
3590 */
3591DECLINLINE(int) PDMDevHlpVMSetError(PPDMDEVINS pDevIns, const int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
3592{
3593 va_list va;
3594 va_start(va, pszFormat);
3595#ifdef IN_GC
3596 pDevIns->pDevHlpGC->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
3597#elif defined(IN_RING0)
3598 pDevIns->pDevHlpR0->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
3599#else
3600 pDevIns->pDevHlp->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
3601#endif
3602 va_end(va);
3603 return rc;
3604}
3605
3606/**
3607 * @copydoc PDMDEVHLP::pfnVMSetRuntimeError
3608 */
3609DECLINLINE(int) PDMDevHlpVMSetRuntimeError(PPDMDEVINS pDevIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...)
3610{
3611 va_list va;
3612 int rc;
3613 va_start(va, pszFormat);
3614#ifdef IN_GC
3615 rc = pDevIns->pDevHlpGC->pfnVMSetRuntimeErrorV(pDevIns, fFatal, pszErrorID, pszFormat, va);
3616#elif defined(IN_RING0)
3617 rc = pDevIns->pDevHlpR0->pfnVMSetRuntimeErrorV(pDevIns, fFatal, pszErrorID, pszFormat, va);
3618#else
3619 rc = pDevIns->pDevHlp->pfnVMSetRuntimeErrorV(pDevIns, fFatal, pszErrorID, pszFormat, va);
3620#endif
3621 va_end(va);
3622 return rc;
3623}
3624
3625
3626
3627/** Pointer to callbacks provided to the VBoxDeviceRegister() call. */
3628typedef struct PDMDEVREGCB *PPDMDEVREGCB;
3629
3630/**
3631 * Callbacks for VBoxDeviceRegister().
3632 */
3633typedef struct PDMDEVREGCB
3634{
3635 /** Interface version.
3636 * This is set to PDM_DEVREG_CB_VERSION. */
3637 uint32_t u32Version;
3638
3639 /**
3640 * Registers a device with the current VM instance.
3641 *
3642 * @returns VBox status code.
3643 * @param pCallbacks Pointer to the callback table.
3644 * @param pDevReg Pointer to the device registration record.
3645 * This data must be permanent and readonly.
3646 */
3647 DECLR3CALLBACKMEMBER(int, pfnRegister,(PPDMDEVREGCB pCallbacks, PCPDMDEVREG pDevReg));
3648
3649 /**
3650 * Allocate memory which is associated with current VM instance
3651 * and automatically freed on it's destruction.
3652 *
3653 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
3654 * @param pCallbacks Pointer to the callback table.
3655 * @param cb Number of bytes to allocate.
3656 */
3657 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMDEVREGCB pCallbacks, size_t cb));
3658} PDMDEVREGCB;
3659
3660/** Current version of the PDMDEVREGCB structure. */
3661#define PDM_DEVREG_CB_VERSION 0xf4010000
3662
3663
3664/**
3665 * The VBoxDevicesRegister callback function.
3666 *
3667 * PDM will invoke this function after loading a device module and letting
3668 * the module decide which devices to register and how to handle conflicts.
3669 *
3670 * @returns VBox status code.
3671 * @param pCallbacks Pointer to the callback table.
3672 * @param u32Version VBox version number.
3673 */
3674typedef DECLCALLBACK(int) FNPDMVBOXDEVICESREGISTER(PPDMDEVREGCB pCallbacks, uint32_t u32Version);
3675
3676/** @} */
3677
3678__END_DECLS
3679
3680#endif
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use