VirtualBox

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

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

PDM: Implemented making device/driver/usb-device suspend and poweroff notifications asynchronous when needed. Also prepped the way for failing poweron and resume.

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