VirtualBox

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

Last change on this file since 21111 was 20847, checked in by vboxsync, 15 years ago

pdmdev.h: major version (not really important, but whatever).

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette