VirtualBox

source: vbox/trunk/include/VBox/vmm/pdmdev.h@ 44512

Last change on this file since 44512 was 44512, checked in by vboxsync, 12 years ago

Documented locking on the remaining device callbacks.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 195.6 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Devices.
3 */
4
5/*
6 * Copyright (C) 2006-2013 Oracle Corporation
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
26#ifndef ___VBox_vmm_pdmdev_h
27#define ___VBox_vmm_pdmdev_h
28
29#include <VBox/vmm/pdmqueue.h>
30#include <VBox/vmm/pdmcritsect.h>
31#include <VBox/vmm/pdmthread.h>
32#include <VBox/vmm/pdmifs.h>
33#include <VBox/vmm/pdmins.h>
34#include <VBox/vmm/pdmcommon.h>
35#include <VBox/vmm/iom.h>
36#include <VBox/vmm/tm.h>
37#include <VBox/vmm/ssm.h>
38#include <VBox/vmm/cfgm.h>
39#include <VBox/vmm/dbgf.h>
40#include <VBox/err.h>
41#include <VBox/pci.h>
42#include <iprt/stdarg.h>
43
44
45RT_C_DECLS_BEGIN
46
47/** @defgroup grp_pdm_device The PDM Devices API
48 * @ingroup grp_pdm
49 * @{
50 */
51
52/**
53 * Construct a device instance for a VM.
54 *
55 * @returns VBox status.
56 * @param pDevIns The device instance data. If the registration structure
57 * is needed, it can be accessed thru pDevIns->pReg.
58 * @param iInstance Instance number. Use this to figure out which registers
59 * and such to use. The instance number is also found in
60 * pDevIns->iInstance, but since it's likely to be
61 * frequently used PDM passes it as parameter.
62 * @param pCfg Configuration node handle for the driver. This is
63 * expected to be in high demand in the constructor and is
64 * therefore passed as an argument. When using it at other
65 * times, it can be found in pDrvIns->pCfg.
66 */
67typedef DECLCALLBACK(int) FNPDMDEVCONSTRUCT(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg);
68/** Pointer to a FNPDMDEVCONSTRUCT() function. */
69typedef FNPDMDEVCONSTRUCT *PFNPDMDEVCONSTRUCT;
70
71/**
72 * Destruct a device instance.
73 *
74 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
75 * resources can be freed correctly.
76 *
77 * @returns VBox status.
78 * @param pDevIns The device instance data.
79 *
80 * @remarks The device critical section is not entered. The routine may delete
81 * the critical section, so the caller cannot exit it.
82 */
83typedef DECLCALLBACK(int) FNPDMDEVDESTRUCT(PPDMDEVINS pDevIns);
84/** Pointer to a FNPDMDEVDESTRUCT() function. */
85typedef FNPDMDEVDESTRUCT *PFNPDMDEVDESTRUCT;
86
87/**
88 * Device relocation callback.
89 *
90 * This is called when the instance data has been relocated in raw-mode context
91 * (RC). It is also called when the RC hypervisor selects changes. The device
92 * must fixup all necessary pointers and re-query all interfaces to other RC
93 * devices and drivers.
94 *
95 * Before the RC code is executed the first time, this function will be called
96 * with a 0 delta so RC pointer calculations can be one in one place.
97 *
98 * @param pDevIns Pointer to the device instance.
99 * @param offDelta The relocation delta relative to the old location.
100 *
101 * @remarks A relocation CANNOT fail.
102 *
103 * @remarks The device critical section is not entered. The relocations should
104 * not normally require any locking.
105 */
106typedef DECLCALLBACK(void) FNPDMDEVRELOCATE(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
107/** Pointer to a FNPDMDEVRELOCATE() function. */
108typedef FNPDMDEVRELOCATE *PFNPDMDEVRELOCATE;
109
110/**
111 * Power On notification.
112 *
113 * @returns VBox status.
114 * @param pDevIns The device instance data.
115 *
116 * @remarks Caller enters the device critical section.
117 */
118typedef DECLCALLBACK(void) FNPDMDEVPOWERON(PPDMDEVINS pDevIns);
119/** Pointer to a FNPDMDEVPOWERON() function. */
120typedef FNPDMDEVPOWERON *PFNPDMDEVPOWERON;
121
122/**
123 * Reset notification.
124 *
125 * @returns VBox status.
126 * @param pDevIns The device instance data.
127 *
128 * @remarks Caller enters the device critical section.
129 */
130typedef DECLCALLBACK(void) FNPDMDEVRESET(PPDMDEVINS pDevIns);
131/** Pointer to a FNPDMDEVRESET() function. */
132typedef FNPDMDEVRESET *PFNPDMDEVRESET;
133
134/**
135 * Suspend notification.
136 *
137 * @returns VBox status.
138 * @param pDevIns The device instance data.
139 * @thread EMT(0)
140 *
141 * @remarks Caller enters the device critical section.
142 */
143typedef DECLCALLBACK(void) FNPDMDEVSUSPEND(PPDMDEVINS pDevIns);
144/** Pointer to a FNPDMDEVSUSPEND() function. */
145typedef FNPDMDEVSUSPEND *PFNPDMDEVSUSPEND;
146
147/**
148 * Resume notification.
149 *
150 * @returns VBox status.
151 * @param pDevIns The device instance data.
152 *
153 * @remarks Caller enters the device critical section.
154 */
155typedef DECLCALLBACK(void) FNPDMDEVRESUME(PPDMDEVINS pDevIns);
156/** Pointer to a FNPDMDEVRESUME() function. */
157typedef FNPDMDEVRESUME *PFNPDMDEVRESUME;
158
159/**
160 * Power Off notification.
161 *
162 * This is only called when the VMR3PowerOff call is made on a running VM. This
163 * means that there is no notification if the VM was suspended before being
164 * powered of. There will also be no callback when hot plugging devices.
165 *
166 * @param pDevIns The device instance data.
167 * @thread EMT(0)
168 *
169 * @remarks Caller enters the device critical section.
170 */
171typedef DECLCALLBACK(void) FNPDMDEVPOWEROFF(PPDMDEVINS pDevIns);
172/** Pointer to a FNPDMDEVPOWEROFF() function. */
173typedef FNPDMDEVPOWEROFF *PFNPDMDEVPOWEROFF;
174
175/**
176 * Attach command.
177 *
178 * This is called to let the device attach to a driver for a specified LUN
179 * at runtime. This is not called during VM construction, the device
180 * constructor have to attach to all the available drivers.
181 *
182 * This is like plugging in the keyboard or mouse after turning on the PC.
183 *
184 * @returns VBox status code.
185 * @param pDevIns The device instance.
186 * @param iLUN The logical unit which is being detached.
187 * @param fFlags Flags, combination of the PDM_TACH_FLAGS_* \#defines.
188 *
189 * @remarks Caller enters the device critical section.
190 */
191typedef DECLCALLBACK(int) FNPDMDEVATTACH(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
192/** Pointer to a FNPDMDEVATTACH() function. */
193typedef FNPDMDEVATTACH *PFNPDMDEVATTACH;
194
195/**
196 * Detach notification.
197 *
198 * This is called when a driver is detaching itself from a LUN of the device.
199 * The device should adjust it's state to reflect this.
200 *
201 * This is like unplugging the network cable to use it for the laptop or
202 * something while the PC is still running.
203 *
204 * @param pDevIns The device instance.
205 * @param iLUN The logical unit which is being detached.
206 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
207 *
208 * @remarks Caller enters the device critical section.
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 *
222 * @remarks The device critical section is not entered.
223 */
224typedef DECLCALLBACK(int) FNPDMDEVQUERYINTERFACE(PPDMDEVINS pDevIns, unsigned iLUN, PPDMIBASE *ppBase);
225/** Pointer to a FNPDMDEVQUERYINTERFACE() function. */
226typedef FNPDMDEVQUERYINTERFACE *PFNPDMDEVQUERYINTERFACE;
227
228/**
229 * Init complete notification.
230 * This can be done to do communication with other devices and other
231 * initialization which requires everything to be in place.
232 *
233 * @returns VBOX status code.
234 * @param pDevIns The device instance.
235 *
236 * @remarks Caller enters the device critical section.
237 */
238typedef DECLCALLBACK(int) FNPDMDEVINITCOMPLETE(PPDMDEVINS pDevIns);
239/** Pointer to a FNPDMDEVINITCOMPLETE() function. */
240typedef FNPDMDEVINITCOMPLETE *PFNPDMDEVINITCOMPLETE;
241
242
243
244/**
245 * PDM Device Registration Structure.
246 *
247 * This structure is used when registering a device from VBoxInitDevices() in HC
248 * Ring-3. PDM will continue use till the VM is terminated.
249 */
250typedef struct PDMDEVREG
251{
252 /** Structure version. PDM_DEVREG_VERSION defines the current version. */
253 uint32_t u32Version;
254 /** Device name. */
255 char szName[32];
256 /** Name of the raw-mode context module (no path).
257 * Only evalutated if PDM_DEVREG_FLAGS_RC is set. */
258 char szRCMod[32];
259 /** Name of the ring-0 module (no path).
260 * Only evalutated if PDM_DEVREG_FLAGS_R0 is set. */
261 char szR0Mod[32];
262 /** The description of the device. The UTF-8 string pointed to shall, like this structure,
263 * remain unchanged from registration till VM destruction. */
264 const char *pszDescription;
265
266 /** Flags, combination of the PDM_DEVREG_FLAGS_* \#defines. */
267 uint32_t fFlags;
268 /** Device class(es), combination of the PDM_DEVREG_CLASS_* \#defines. */
269 uint32_t fClass;
270 /** Maximum number of instances (per VM). */
271 uint32_t cMaxInstances;
272 /** Size of the instance data. */
273 uint32_t cbInstance;
274
275 /** Construct instance - required. */
276 PFNPDMDEVCONSTRUCT pfnConstruct;
277 /** Destruct instance - optional.
278 * Critical section NOT entered (will be destroyed). */
279 PFNPDMDEVDESTRUCT pfnDestruct;
280 /** Relocation command - optional.
281 * Critical section NOT entered. */
282 PFNPDMDEVRELOCATE pfnRelocate;
283 /** Unused member. (Was pfnIOCtl.) */
284 PFNRT pfnUnused;
285 /** Power on notification - optional.
286 * Critical section is entered. */
287 PFNPDMDEVPOWERON pfnPowerOn;
288 /** Reset notification - optional.
289 * Critical section is entered. */
290 PFNPDMDEVRESET pfnReset;
291 /** Suspend notification - optional.
292 * Critical section is entered. */
293 PFNPDMDEVSUSPEND pfnSuspend;
294 /** Resume notification - optional.
295 * Critical section is entered. */
296 PFNPDMDEVRESUME pfnResume;
297 /** Attach command - optional.
298 * Critical section is entered. */
299 PFNPDMDEVATTACH pfnAttach;
300 /** Detach notification - optional.
301 * Critical section is entered. */
302 PFNPDMDEVDETACH pfnDetach;
303 /** Query a LUN base interface - optional.
304 * Critical section is NOT entered. */
305 PFNPDMDEVQUERYINTERFACE pfnQueryInterface;
306 /** Init complete notification - optional.
307 * Critical section is entered. */
308 PFNPDMDEVINITCOMPLETE pfnInitComplete;
309 /** Power off notification - optional.
310 * Critical section is entered. */
311 PFNPDMDEVPOWEROFF pfnPowerOff;
312 /** @todo */
313 PFNRT pfnSoftReset;
314 /** Initialization safty marker. */
315 uint32_t u32VersionEnd;
316} PDMDEVREG;
317/** Pointer to a PDM Device Structure. */
318typedef PDMDEVREG *PPDMDEVREG;
319/** Const pointer to a PDM Device Structure. */
320typedef PDMDEVREG const *PCPDMDEVREG;
321
322/** Current DEVREG version number. */
323#define PDM_DEVREG_VERSION PDM_VERSION_MAKE(0xffff, 1, 0)
324
325/** PDM Device Flags.
326 * @{ */
327/** This flag is used to indicate that the device has a RC component. */
328#define PDM_DEVREG_FLAGS_RC 0x00000001
329/** This flag is used to indicate that the device has a R0 component. */
330#define PDM_DEVREG_FLAGS_R0 0x00000002
331
332/** @def PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT
333 * The bit count for the current host. */
334#if HC_ARCH_BITS == 32
335# define PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT 0x00000010
336#elif HC_ARCH_BITS == 64
337# define PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT 0x00000020
338#else
339# error Unsupported HC_ARCH_BITS value.
340#endif
341/** The host bit count mask. */
342#define PDM_DEVREG_FLAGS_HOST_BITS_MASK 0x00000030
343
344/** The device support only 32-bit guests. */
345#define PDM_DEVREG_FLAGS_GUEST_BITS_32 0x00000100
346/** The device support only 64-bit guests. */
347#define PDM_DEVREG_FLAGS_GUEST_BITS_64 0x00000200
348/** The device support both 32-bit & 64-bit guests. */
349#define PDM_DEVREG_FLAGS_GUEST_BITS_32_64 0x00000300
350/** @def PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT
351 * The guest bit count for the current compilation. */
352#if GC_ARCH_BITS == 32
353# define PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT PDM_DEVREG_FLAGS_GUEST_BITS_32
354#elif GC_ARCH_BITS == 64
355# define PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT PDM_DEVREG_FLAGS_GUEST_BITS_32_64
356#else
357# error Unsupported GC_ARCH_BITS value.
358#endif
359/** The guest bit count mask. */
360#define PDM_DEVREG_FLAGS_GUEST_BITS_MASK 0x00000300
361
362/** A convenience. */
363#define PDM_DEVREG_FLAGS_DEFAULT_BITS (PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT | PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT)
364
365/** Indicates that the devices support PAE36 on a 32-bit guest. */
366#define PDM_DEVREG_FLAGS_PAE36 0x00001000
367
368/** Indicates that the device needs to be notified before the drivers when suspending. */
369#define PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION 0x00002000
370
371/** Indicates that the device needs to be notified before the drivers when powering off. */
372#define PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION 0x00004000
373
374/** Indicates that the device needs to be notified before the drivers when resetting. */
375#define PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION 0x00008000
376/** @} */
377
378
379/** PDM Device Classes.
380 * The order is important, lower bit earlier instantiation.
381 * @{ */
382/** Architecture device. */
383#define PDM_DEVREG_CLASS_ARCH RT_BIT(0)
384/** Architecture BIOS device. */
385#define PDM_DEVREG_CLASS_ARCH_BIOS RT_BIT(1)
386/** PCI bus brigde. */
387#define PDM_DEVREG_CLASS_BUS_PCI RT_BIT(2)
388/** ISA bus brigde. */
389#define PDM_DEVREG_CLASS_BUS_ISA RT_BIT(3)
390/** Input device (mouse, keyboard, joystick, HID, ...). */
391#define PDM_DEVREG_CLASS_INPUT RT_BIT(4)
392/** Interrupt controller (PIC). */
393#define PDM_DEVREG_CLASS_PIC RT_BIT(5)
394/** Interval controoler (PIT). */
395#define PDM_DEVREG_CLASS_PIT RT_BIT(6)
396/** RTC/CMOS. */
397#define PDM_DEVREG_CLASS_RTC RT_BIT(7)
398/** DMA controller. */
399#define PDM_DEVREG_CLASS_DMA RT_BIT(8)
400/** VMM Device. */
401#define PDM_DEVREG_CLASS_VMM_DEV RT_BIT(9)
402/** Graphics device, like VGA. */
403#define PDM_DEVREG_CLASS_GRAPHICS RT_BIT(10)
404/** Storage controller device. */
405#define PDM_DEVREG_CLASS_STORAGE RT_BIT(11)
406/** Network interface controller. */
407#define PDM_DEVREG_CLASS_NETWORK RT_BIT(12)
408/** Audio. */
409#define PDM_DEVREG_CLASS_AUDIO RT_BIT(13)
410/** USB HIC. */
411#define PDM_DEVREG_CLASS_BUS_USB RT_BIT(14)
412/** ACPI. */
413#define PDM_DEVREG_CLASS_ACPI RT_BIT(15)
414/** Serial controller device. */
415#define PDM_DEVREG_CLASS_SERIAL RT_BIT(16)
416/** Parallel controller device */
417#define PDM_DEVREG_CLASS_PARALLEL RT_BIT(17)
418/** Host PCI pass-through device */
419#define PDM_DEVREG_CLASS_HOST_DEV RT_BIT(18)
420/** Misc devices (always last). */
421#define PDM_DEVREG_CLASS_MISC RT_BIT(31)
422/** @} */
423
424
425/** @name IRQ Level for use with the *SetIrq APIs.
426 * @{
427 */
428/** Assert the IRQ (can assume value 1). */
429#define PDM_IRQ_LEVEL_HIGH RT_BIT(0)
430/** Deassert the IRQ (can assume value 0). */
431#define PDM_IRQ_LEVEL_LOW 0
432/** flip-flop - deassert and then assert the IRQ again immediately. */
433#define PDM_IRQ_LEVEL_FLIP_FLOP (RT_BIT(1) | PDM_IRQ_LEVEL_HIGH)
434/** @} */
435
436/**
437 * Registration record for MSI.
438 */
439typedef struct PDMMSIREG
440{
441 /** Number of MSI interrupt vectors, 0 if MSI not supported */
442 uint16_t cMsiVectors;
443 /** Offset of MSI capability */
444 uint8_t iMsiCapOffset;
445 /** Offset of next capability to MSI */
446 uint8_t iMsiNextOffset;
447 /** If we support 64-bit MSI addressing */
448 bool fMsi64bit;
449
450 /** Number of MSI-X interrupt vectors, 0 if MSI-X not supported */
451 uint16_t cMsixVectors;
452 /** Offset of MSI-X capability */
453 uint8_t iMsixCapOffset;
454 /** Offset of next capability to MSI-X */
455 uint8_t iMsixNextOffset;
456 /** Value of PCI BAR (base addresss register) assigned by device for MSI-X page access */
457 uint8_t iMsixBar;
458} PDMMSIREG;
459typedef PDMMSIREG *PPDMMSIREG;
460
461/**
462 * PCI Bus registration structure.
463 * All the callbacks, except the PCIBIOS hack, are working on PCI devices.
464 */
465typedef struct PDMPCIBUSREG
466{
467 /** Structure version number. PDM_PCIBUSREG_VERSION defines the current version. */
468 uint32_t u32Version;
469
470 /**
471 * Registers the device with the default PCI bus.
472 *
473 * @returns VBox status code.
474 * @param pDevIns Device instance of the PCI Bus.
475 * @param pPciDev The PCI device structure.
476 * Any PCI enabled device must keep this in it's instance data!
477 * Fill in the PCI data config before registration, please.
478 * @param pszName Pointer to device name (permanent, readonly). For debugging, not unique.
479 * @param iDev The device number ((dev << 3) | function) the device should have on the bus.
480 * If negative, the pci bus device will assign one.
481 * @remarks Caller enters the PDM critical section.
482 */
483 DECLR3CALLBACKMEMBER(int, pfnRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev));
484
485 /**
486 * Initialize MSI support in a PCI device.
487 *
488 * @returns VBox status code.
489 * @param pDevIns Device instance of the PCI Bus.
490 * @param pPciDev The PCI device structure.
491 * @param pMsiReg MSI registration structure
492 * @remarks Caller enters the PDM critical section.
493 */
494 DECLR3CALLBACKMEMBER(int, pfnRegisterMsiR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PPDMMSIREG pMsiReg));
495
496 /**
497 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
498 *
499 * @returns VBox status code.
500 * @param pDevIns Device instance of the PCI Bus.
501 * @param pPciDev The PCI device structure.
502 * @param iRegion The region number.
503 * @param cbRegion Size of the region.
504 * @param iType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
505 * @param pfnCallback Callback for doing the mapping.
506 * @remarks Caller enters the PDM critical section.
507 */
508 DECLR3CALLBACKMEMBER(int, pfnIORegionRegisterR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
509
510 /**
511 * Register PCI configuration space read/write callbacks.
512 *
513 * @param pDevIns Device instance of the PCI Bus.
514 * @param pPciDev The PCI device structure.
515 * @param pfnRead Pointer to the user defined PCI config read function.
516 * @param ppfnReadOld Pointer to function pointer which will receive the old (default)
517 * PCI config read function. This way, user can decide when (and if)
518 * to call default PCI config read function. Can be NULL.
519 * @param pfnWrite Pointer to the user defined PCI config write function.
520 * @param pfnWriteOld Pointer to function pointer which will receive the old (default)
521 * PCI config write function. This way, user can decide when (and if)
522 * to call default PCI config write function. Can be NULL.
523 * @remarks Caller enters the PDM critical section.
524 * @thread EMT
525 */
526 DECLR3CALLBACKMEMBER(void, pfnSetConfigCallbacksR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
527 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
528
529 /**
530 * Set the IRQ for a PCI device.
531 *
532 * @param pDevIns Device instance of the PCI Bus.
533 * @param pPciDev The PCI device structure.
534 * @param iIrq IRQ number to set.
535 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
536 * @param uTagSrc The IRQ tag and source (for tracing).
537 * @remarks Caller enters the PDM critical section.
538 */
539 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
540
541 /**
542 * Called to perform the job of the bios.
543 * This is only called for the first PCI Bus - it is expected to
544 * service all the PCI buses.
545 *
546 * @returns VBox status.
547 * @param pDevIns Device instance of the first bus.
548 * @remarks Caller enters the PDM critical section.
549 */
550 DECLR3CALLBACKMEMBER(int, pfnFakePCIBIOSR3,(PPDMDEVINS pDevIns));
551
552 /** The name of the SetIrq RC entry point. */
553 const char *pszSetIrqRC;
554
555 /** The name of the SetIrq R0 entry point. */
556 const char *pszSetIrqR0;
557
558} PDMPCIBUSREG;
559/** Pointer to a PCI bus registration structure. */
560typedef PDMPCIBUSREG *PPDMPCIBUSREG;
561
562/** Current PDMPCIBUSREG version number. */
563#define PDM_PCIBUSREG_VERSION PDM_VERSION_MAKE(0xfffe, 4, 0)
564
565/**
566 * PCI Bus RC helpers.
567 */
568typedef struct PDMPCIHLPRC
569{
570 /** Structure version. PDM_PCIHLPRC_VERSION defines the current version. */
571 uint32_t u32Version;
572
573 /**
574 * Set an ISA IRQ.
575 *
576 * @param pDevIns PCI device instance.
577 * @param iIrq IRQ number to set.
578 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
579 * @param uTagSrc The IRQ tag and source (for tracing).
580 * @thread EMT only.
581 */
582 DECLRCCALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
583
584 /**
585 * Set an I/O-APIC IRQ.
586 *
587 * @param pDevIns PCI device instance.
588 * @param iIrq IRQ number to set.
589 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
590 * @param uTagSrc The IRQ tag and source (for tracing).
591 * @thread EMT only.
592 */
593 DECLRCCALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
594
595 /**
596 * Send an MSI.
597 *
598 * @param pDevIns PCI device instance.
599 * @param GCPhys Physical address MSI request was written.
600 * @param uValue Value written.
601 * @param uTagSrc The IRQ tag and source (for tracing).
602 * @thread EMT only.
603 */
604 DECLRCCALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc));
605
606
607 /**
608 * Acquires the PDM lock.
609 *
610 * @returns VINF_SUCCESS on success.
611 * @returns rc if we failed to acquire the lock.
612 * @param pDevIns The PCI device instance.
613 * @param rc What to return if we fail to acquire the lock.
614 */
615 DECLRCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
616
617 /**
618 * Releases the PDM lock.
619 *
620 * @param pDevIns The PCI device instance.
621 */
622 DECLRCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
623
624 /** Just a safety precaution. */
625 uint32_t u32TheEnd;
626} PDMPCIHLPRC;
627/** Pointer to PCI helpers. */
628typedef RCPTRTYPE(PDMPCIHLPRC *) PPDMPCIHLPRC;
629/** Pointer to const PCI helpers. */
630typedef RCPTRTYPE(const PDMPCIHLPRC *) PCPDMPCIHLPRC;
631
632/** Current PDMPCIHLPRC version number. */
633#define PDM_PCIHLPRC_VERSION PDM_VERSION_MAKE(0xfffd, 3, 0)
634
635
636/**
637 * PCI Bus R0 helpers.
638 */
639typedef struct PDMPCIHLPR0
640{
641 /** Structure version. PDM_PCIHLPR0_VERSION defines the current version. */
642 uint32_t u32Version;
643
644 /**
645 * Set an ISA IRQ.
646 *
647 * @param pDevIns PCI device instance.
648 * @param iIrq IRQ number to set.
649 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
650 * @param uTagSrc The IRQ tag and source (for tracing).
651 * @thread EMT only.
652 */
653 DECLR0CALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
654
655 /**
656 * Set an I/O-APIC IRQ.
657 *
658 * @param pDevIns PCI device instance.
659 * @param iIrq IRQ number to set.
660 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
661 * @param uTagSrc The IRQ tag and source (for tracing).
662 * @thread EMT only.
663 */
664 DECLR0CALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
665
666 /**
667 * Send an MSI.
668 *
669 * @param pDevIns PCI device instance.
670 * @param GCPhys Physical address MSI request was written.
671 * @param uValue Value written.
672 * @param uTagSrc The IRQ tag and source (for tracing).
673 * @thread EMT only.
674 */
675 DECLR0CALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc));
676
677
678 /**
679 * Acquires the PDM lock.
680 *
681 * @returns VINF_SUCCESS on success.
682 * @returns rc if we failed to acquire the lock.
683 * @param pDevIns The PCI device instance.
684 * @param rc What to return if we fail to acquire the lock.
685 */
686 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
687
688 /**
689 * Releases the PDM lock.
690 *
691 * @param pDevIns The PCI device instance.
692 */
693 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
694
695 /** Just a safety precaution. */
696 uint32_t u32TheEnd;
697} PDMPCIHLPR0;
698/** Pointer to PCI helpers. */
699typedef R0PTRTYPE(PDMPCIHLPR0 *) PPDMPCIHLPR0;
700/** Pointer to const PCI helpers. */
701typedef R0PTRTYPE(const PDMPCIHLPR0 *) PCPDMPCIHLPR0;
702
703/** Current PDMPCIHLPR0 version number. */
704#define PDM_PCIHLPR0_VERSION PDM_VERSION_MAKE(0xfffc, 3, 0)
705
706/**
707 * PCI device helpers.
708 */
709typedef struct PDMPCIHLPR3
710{
711 /** Structure version. PDM_PCIHLPR3_VERSION defines the current version. */
712 uint32_t u32Version;
713
714 /**
715 * Set an ISA IRQ.
716 *
717 * @param pDevIns The PCI device instance.
718 * @param iIrq IRQ number to set.
719 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
720 * @param uTagSrc The IRQ tag and source (for tracing).
721 */
722 DECLR3CALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
723
724 /**
725 * Set an I/O-APIC IRQ.
726 *
727 * @param pDevIns The PCI device instance.
728 * @param iIrq IRQ number to set.
729 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
730 * @param uTagSrc The IRQ tag and source (for tracing).
731 */
732 DECLR3CALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
733
734 /**
735 * Send an MSI.
736 *
737 * @param pDevIns PCI device instance.
738 * @param GCPhys Physical address MSI request was written.
739 * @param uValue Value written.
740 * @param uTagSrc The IRQ tag and source (for tracing).
741 */
742 DECLR3CALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc));
743
744 /**
745 * Checks if the given address is an MMIO2 base address or not.
746 *
747 * @returns true/false accordingly.
748 * @param pDevIns The PCI device instance.
749 * @param pOwner The owner of the memory, optional.
750 * @param GCPhys The address to check.
751 */
752 DECLR3CALLBACKMEMBER(bool, pfnIsMMIO2Base,(PPDMDEVINS pDevIns, PPDMDEVINS pOwner, RTGCPHYS GCPhys));
753
754 /**
755 * Gets the address of the RC PCI Bus helpers.
756 *
757 * This should be called at both construction and relocation time
758 * to obtain the correct address of the RC helpers.
759 *
760 * @returns RC pointer to the PCI Bus helpers.
761 * @param pDevIns Device instance of the PCI Bus.
762 * @thread EMT only.
763 */
764 DECLR3CALLBACKMEMBER(PCPDMPCIHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
765
766 /**
767 * Gets the address of the R0 PCI Bus helpers.
768 *
769 * This should be called at both construction and relocation time
770 * to obtain the correct address of the R0 helpers.
771 *
772 * @returns R0 pointer to the PCI Bus helpers.
773 * @param pDevIns Device instance of the PCI Bus.
774 * @thread EMT only.
775 */
776 DECLR3CALLBACKMEMBER(PCPDMPCIHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
777
778 /**
779 * Acquires the PDM lock.
780 *
781 * @returns VINF_SUCCESS on success.
782 * @returns Fatal error on failure.
783 * @param pDevIns The PCI device instance.
784 * @param rc Dummy for making the interface identical to the RC and R0 versions.
785 */
786 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
787
788 /**
789 * Releases the PDM lock.
790 *
791 * @param pDevIns The PCI device instance.
792 */
793 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
794
795 /** Just a safety precaution. */
796 uint32_t u32TheEnd;
797} PDMPCIHLPR3;
798/** Pointer to PCI helpers. */
799typedef R3PTRTYPE(PDMPCIHLPR3 *) PPDMPCIHLPR3;
800/** Pointer to const PCI helpers. */
801typedef R3PTRTYPE(const PDMPCIHLPR3 *) PCPDMPCIHLPR3;
802
803/** Current PDMPCIHLPR3 version number. */
804#define PDM_PCIHLPR3_VERSION PDM_VERSION_MAKE(0xfffb, 3, 0)
805
806
807/**
808 * Programmable Interrupt Controller registration structure.
809 */
810typedef struct PDMPICREG
811{
812 /** Structure version number. PDM_PICREG_VERSION defines the current version. */
813 uint32_t u32Version;
814
815 /**
816 * Set the an IRQ.
817 *
818 * @param pDevIns Device instance of the PIC.
819 * @param iIrq IRQ number to set.
820 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
821 * @param uTagSrc The IRQ tag and source (for tracing).
822 * @remarks Caller enters the PDM critical section.
823 */
824 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
825
826 /**
827 * Get a pending interrupt.
828 *
829 * @returns Pending interrupt number.
830 * @param pDevIns Device instance of the PIC.
831 * @param puTagSrc Where to return the IRQ tag and source.
832 * @remarks Caller enters the PDM critical section.
833 */
834 DECLR3CALLBACKMEMBER(int, pfnGetInterruptR3,(PPDMDEVINS pDevIns, uint32_t *puTagSrc));
835
836 /** The name of the RC SetIrq entry point. */
837 const char *pszSetIrqRC;
838 /** The name of the RC GetInterrupt entry point. */
839 const char *pszGetInterruptRC;
840
841 /** The name of the R0 SetIrq entry point. */
842 const char *pszSetIrqR0;
843 /** The name of the R0 GetInterrupt entry point. */
844 const char *pszGetInterruptR0;
845} PDMPICREG;
846/** Pointer to a PIC registration structure. */
847typedef PDMPICREG *PPDMPICREG;
848
849/** Current PDMPICREG version number. */
850#define PDM_PICREG_VERSION PDM_VERSION_MAKE(0xfffa, 2, 0)
851
852/**
853 * PIC RC helpers.
854 */
855typedef struct PDMPICHLPRC
856{
857 /** Structure version. PDM_PICHLPRC_VERSION defines the current version. */
858 uint32_t u32Version;
859
860 /**
861 * Set the interrupt force action flag.
862 *
863 * @param pDevIns Device instance of the PIC.
864 */
865 DECLRCCALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
866
867 /**
868 * Clear the interrupt force action flag.
869 *
870 * @param pDevIns Device instance of the PIC.
871 */
872 DECLRCCALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
873
874 /**
875 * Acquires the PDM lock.
876 *
877 * @returns VINF_SUCCESS on success.
878 * @returns rc if we failed to acquire the lock.
879 * @param pDevIns The PIC device instance.
880 * @param rc What to return if we fail to acquire the lock.
881 */
882 DECLRCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
883
884 /**
885 * Releases the PDM lock.
886 *
887 * @param pDevIns The PIC device instance.
888 */
889 DECLRCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
890
891 /** Just a safety precaution. */
892 uint32_t u32TheEnd;
893} PDMPICHLPRC;
894
895/** Pointer to PIC RC helpers. */
896typedef RCPTRTYPE(PDMPICHLPRC *) PPDMPICHLPRC;
897/** Pointer to const PIC RC helpers. */
898typedef RCPTRTYPE(const PDMPICHLPRC *) PCPDMPICHLPRC;
899
900/** Current PDMPICHLPRC version number. */
901#define PDM_PICHLPRC_VERSION PDM_VERSION_MAKE(0xfff9, 2, 0)
902
903
904/**
905 * PIC R0 helpers.
906 */
907typedef struct PDMPICHLPR0
908{
909 /** Structure version. PDM_PICHLPR0_VERSION defines the current version. */
910 uint32_t u32Version;
911
912 /**
913 * Set the interrupt force action flag.
914 *
915 * @param pDevIns Device instance of the PIC.
916 */
917 DECLR0CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
918
919 /**
920 * Clear the interrupt force action flag.
921 *
922 * @param pDevIns Device instance of the PIC.
923 */
924 DECLR0CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
925
926 /**
927 * Acquires the PDM lock.
928 *
929 * @returns VINF_SUCCESS on success.
930 * @returns rc if we failed to acquire the lock.
931 * @param pDevIns The PIC device instance.
932 * @param rc What to return if we fail to acquire the lock.
933 */
934 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
935
936 /**
937 * Releases the PDM lock.
938 *
939 * @param pDevIns The PCI device instance.
940 */
941 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
942
943 /** Just a safety precaution. */
944 uint32_t u32TheEnd;
945} PDMPICHLPR0;
946
947/** Pointer to PIC R0 helpers. */
948typedef R0PTRTYPE(PDMPICHLPR0 *) PPDMPICHLPR0;
949/** Pointer to const PIC R0 helpers. */
950typedef R0PTRTYPE(const PDMPICHLPR0 *) PCPDMPICHLPR0;
951
952/** Current PDMPICHLPR0 version number. */
953#define PDM_PICHLPR0_VERSION PDM_VERSION_MAKE(0xfff8, 1, 0)
954
955/**
956 * PIC R3 helpers.
957 */
958typedef struct PDMPICHLPR3
959{
960 /** Structure version. PDM_PICHLP_VERSION defines the current version. */
961 uint32_t u32Version;
962
963 /**
964 * Set the interrupt force action flag.
965 *
966 * @param pDevIns Device instance of the PIC.
967 */
968 DECLR3CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
969
970 /**
971 * Clear the interrupt force action flag.
972 *
973 * @param pDevIns Device instance of the PIC.
974 */
975 DECLR3CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
976
977 /**
978 * Acquires the PDM lock.
979 *
980 * @returns VINF_SUCCESS on success.
981 * @returns Fatal error on failure.
982 * @param pDevIns The PIC device instance.
983 * @param rc Dummy for making the interface identical to the RC and R0 versions.
984 */
985 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
986
987 /**
988 * Releases the PDM lock.
989 *
990 * @param pDevIns The PIC device instance.
991 */
992 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
993
994 /**
995 * Gets the address of the RC PIC helpers.
996 *
997 * This should be called at both construction and relocation time
998 * to obtain the correct address of the RC helpers.
999 *
1000 * @returns RC pointer to the PIC helpers.
1001 * @param pDevIns Device instance of the PIC.
1002 */
1003 DECLR3CALLBACKMEMBER(PCPDMPICHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1004
1005 /**
1006 * Gets the address of the R0 PIC helpers.
1007 *
1008 * This should be called at both construction and relocation time
1009 * to obtain the correct address of the R0 helpers.
1010 *
1011 * @returns R0 pointer to the PIC helpers.
1012 * @param pDevIns Device instance of the PIC.
1013 */
1014 DECLR3CALLBACKMEMBER(PCPDMPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1015
1016 /** Just a safety precaution. */
1017 uint32_t u32TheEnd;
1018} PDMPICHLPR3;
1019
1020/** Pointer to PIC R3 helpers. */
1021typedef R3PTRTYPE(PDMPICHLPR3 *) PPDMPICHLPR3;
1022/** Pointer to const PIC R3 helpers. */
1023typedef R3PTRTYPE(const PDMPICHLPR3 *) PCPDMPICHLPR3;
1024
1025/** Current PDMPICHLPR3 version number. */
1026#define PDM_PICHLPR3_VERSION PDM_VERSION_MAKE(0xfff7, 1, 0)
1027
1028
1029
1030/**
1031 * Advanced Programmable Interrupt Controller registration structure.
1032 */
1033typedef struct PDMAPICREG
1034{
1035 /** Structure version number. PDM_APICREG_VERSION defines the current version. */
1036 uint32_t u32Version;
1037
1038 /**
1039 * Get a pending interrupt.
1040 *
1041 * @returns Pending interrupt number.
1042 * @param pDevIns Device instance of the APIC.
1043 * @param idCpu The VCPU Id.
1044 * @param puTagSrc Where to return the tag source.
1045 * @remarks Caller enters the PDM critical section
1046 */
1047 DECLR3CALLBACKMEMBER(int, pfnGetInterruptR3,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t *puTagSrc));
1048
1049 /**
1050 * Check if the APIC has a pending interrupt/if a TPR change would active one
1051 *
1052 * @returns Pending interrupt yes/no
1053 * @param pDevIns Device instance of the APIC.
1054 * @param idCpu The VCPU Id.
1055 * @remarks Unlike the other callbacks, the PDM lock may not always be entered
1056 * prior to calling this method.
1057 */
1058 DECLR3CALLBACKMEMBER(bool, pfnHasPendingIrqR3,(PPDMDEVINS pDevIns, VMCPUID idCpu));
1059
1060 /**
1061 * Set the APIC base.
1062 *
1063 * @param pDevIns Device instance of the APIC.
1064 * @param idCpu The VCPU Id.
1065 * @param u64Base The new base.
1066 * @remarks Caller enters the PDM critical section.
1067 */
1068 DECLR3CALLBACKMEMBER(void, pfnSetBaseR3,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint64_t u64Base));
1069
1070 /**
1071 * Get the APIC base.
1072 *
1073 * @returns Current base.
1074 * @param pDevIns Device instance of the APIC.
1075 * @param idCpu The VCPU Id.
1076 * @remarks Caller enters the PDM critical section.
1077 */
1078 DECLR3CALLBACKMEMBER(uint64_t, pfnGetBaseR3,(PPDMDEVINS pDevIns, VMCPUID idCpu));
1079
1080 /**
1081 * Set the TPR (task priority register).
1082 *
1083 * @param pDevIns Device instance of the APIC.
1084 * @param idCpu The VCPU id.
1085 * @param u8TPR The new TPR.
1086 * @remarks Caller enters the PDM critical section.
1087 */
1088 DECLR3CALLBACKMEMBER(void, pfnSetTPRR3,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint8_t u8TPR));
1089
1090 /**
1091 * Get the TPR (task priority register).
1092 *
1093 * @returns The current TPR.
1094 * @param pDevIns Device instance of the APIC.
1095 * @param idCpu VCPU id
1096 * @remarks Caller enters the PDM critical section.
1097 */
1098 DECLR3CALLBACKMEMBER(uint8_t, pfnGetTPRR3,(PPDMDEVINS pDevIns, VMCPUID idCpu));
1099
1100 /**
1101 * Write to a MSR in APIC range.
1102 *
1103 * @returns VBox status code.
1104 * @param pDevIns Device instance of the APIC.
1105 * @param idCpu Target CPU.
1106 * @param u32Reg The MSR begin written to.
1107 * @param u64Value The value to write.
1108 *
1109 * @remarks Unlike the other callbacks, the PDM lock is not taken before
1110 * calling this method.
1111 */
1112 DECLR3CALLBACKMEMBER(int, pfnWriteMSRR3, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t u64Value));
1113
1114 /**
1115 * Read from a MSR in APIC range.
1116 *
1117 * @returns VBox status code.
1118 * @param pDevIns Device instance of the APIC.
1119 * @param idCpu Target CPU.
1120 * @param u32Reg MSR to read.
1121 * @param pu64Value Where to return the read value.
1122 *
1123 * @remarks Unlike the other callbacks, the PDM lock is not taken before
1124 * calling this method.
1125 */
1126 DECLR3CALLBACKMEMBER(int, pfnReadMSRR3, (PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t u32Reg, uint64_t *pu64Value));
1127
1128 /**
1129 * Private interface between the IOAPIC and APIC.
1130 *
1131 * This is a low-level, APIC/IOAPIC implementation specific interface which
1132 * is registered with PDM only because it makes life so much simpler right
1133 * now (GC bits). This is a bad bad hack! The correct way of doing this
1134 * would involve some way of querying GC interfaces and relocating them.
1135 * Perhaps doing some kind of device init in GC...
1136 *
1137 * @returns status code.
1138 * @param pDevIns Device instance of the APIC.
1139 * @param u8Dest See APIC implementation.
1140 * @param u8DestMode See APIC implementation.
1141 * @param u8DeliveryMode See APIC implementation.
1142 * @param iVector See APIC implementation.
1143 * @param u8Polarity See APIC implementation.
1144 * @param u8TriggerMode See APIC implementation.
1145 * @param uTagSrc The IRQ tag and source (for tracing).
1146 * @remarks Caller enters the PDM critical section
1147 */
1148 DECLR3CALLBACKMEMBER(int, pfnBusDeliverR3,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1149 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
1150
1151 /**
1152 * Deliver a signal to CPU's local interrupt pins (LINT0/LINT1).
1153 *
1154 * Used for virtual wire mode when interrupts from the PIC are passed through
1155 * LAPIC.
1156 *
1157 * @returns status code.
1158 * @param pDevIns Device instance of the APIC.
1159 * @param u8Pin Local pin number (0 or 1 for current CPUs).
1160 * @param u8Level The level.
1161 * @param uTagSrc The IRQ tag and source (for tracing).
1162 * @remarks Caller enters the PDM critical section
1163 */
1164 DECLR3CALLBACKMEMBER(int, pfnLocalInterruptR3,(PPDMDEVINS pDevIns, uint8_t u8Pin, uint8_t u8Level));
1165
1166 /** The name of the RC GetInterrupt entry point. */
1167 const char *pszGetInterruptRC;
1168 /** The name of the RC HasPendingIrq entry point. */
1169 const char *pszHasPendingIrqRC;
1170 /** The name of the RC SetBase entry point. */
1171 const char *pszSetBaseRC;
1172 /** The name of the RC GetBase entry point. */
1173 const char *pszGetBaseRC;
1174 /** The name of the RC SetTPR entry point. */
1175 const char *pszSetTPRRC;
1176 /** The name of the RC GetTPR entry point. */
1177 const char *pszGetTPRRC;
1178 /** The name of the RC WriteMSR entry point. */
1179 const char *pszWriteMSRRC;
1180 /** The name of the RC ReadMSR entry point. */
1181 const char *pszReadMSRRC;
1182 /** The name of the RC BusDeliver entry point. */
1183 const char *pszBusDeliverRC;
1184 /** The name of the RC LocalInterrupt entry point. */
1185 const char *pszLocalInterruptRC;
1186
1187 /** The name of the R0 GetInterrupt entry point. */
1188 const char *pszGetInterruptR0;
1189 /** The name of the R0 HasPendingIrq entry point. */
1190 const char *pszHasPendingIrqR0;
1191 /** The name of the R0 SetBase entry point. */
1192 const char *pszSetBaseR0;
1193 /** The name of the R0 GetBase entry point. */
1194 const char *pszGetBaseR0;
1195 /** The name of the R0 SetTPR entry point. */
1196 const char *pszSetTPRR0;
1197 /** The name of the R0 GetTPR entry point. */
1198 const char *pszGetTPRR0;
1199 /** The name of the R0 WriteMSR entry point. */
1200 const char *pszWriteMSRR0;
1201 /** The name of the R0 ReadMSR entry point. */
1202 const char *pszReadMSRR0;
1203 /** The name of the R0 BusDeliver entry point. */
1204 const char *pszBusDeliverR0;
1205 /** The name of the R0 LocalInterrupt entry point. */
1206 const char *pszLocalInterruptR0;
1207
1208} PDMAPICREG;
1209/** Pointer to an APIC registration structure. */
1210typedef PDMAPICREG *PPDMAPICREG;
1211
1212/** Current PDMAPICREG version number. */
1213#define PDM_APICREG_VERSION PDM_VERSION_MAKE(0xfff6, 2, 0)
1214
1215
1216/**
1217 * APIC version argument for pfnChangeFeature.
1218 */
1219typedef enum PDMAPICVERSION
1220{
1221 /** Invalid 0 entry. */
1222 PDMAPICVERSION_INVALID = 0,
1223 /** No APIC. */
1224 PDMAPICVERSION_NONE,
1225 /** Standard APIC (X86_CPUID_FEATURE_EDX_APIC). */
1226 PDMAPICVERSION_APIC,
1227 /** Intel X2APIC (X86_CPUID_FEATURE_ECX_X2APIC). */
1228 PDMAPICVERSION_X2APIC,
1229 /** The usual 32-bit paranoia. */
1230 PDMAPICVERSION_32BIT_HACK = 0x7fffffff
1231} PDMAPICVERSION;
1232
1233/**
1234 * APIC irq argument for SetInterruptFF.
1235 */
1236typedef enum PDMAPICIRQ
1237{
1238 /** Invalid 0 entry. */
1239 PDMAPICIRQ_INVALID = 0,
1240 /** Normal hardware interrupt. */
1241 PDMAPICIRQ_HARDWARE,
1242 /** NMI. */
1243 PDMAPICIRQ_NMI,
1244 /** SMI. */
1245 PDMAPICIRQ_SMI,
1246 /** ExtINT (HW interrupt via PIC). */
1247 PDMAPICIRQ_EXTINT,
1248 /** The usual 32-bit paranoia. */
1249 PDMAPICIRQ_32BIT_HACK = 0x7fffffff
1250} PDMAPICIRQ;
1251
1252
1253/**
1254 * APIC RC helpers.
1255 */
1256typedef struct PDMAPICHLPRC
1257{
1258 /** Structure version. PDM_APICHLPRC_VERSION defines the current version. */
1259 uint32_t u32Version;
1260
1261 /**
1262 * Set the interrupt force action flag.
1263 *
1264 * @param pDevIns Device instance of the APIC.
1265 * @param enmType IRQ type.
1266 * @param idCpu Virtual CPU to set flag upon.
1267 */
1268 DECLRCCALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1269
1270 /**
1271 * Clear the interrupt force action flag.
1272 *
1273 * @param pDevIns Device instance of the APIC.
1274 * @param enmType IRQ type.
1275 * @param idCpu Virtual CPU to clear flag upon.
1276 */
1277 DECLRCCALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1278
1279 /**
1280 * Calculates an IRQ tag for a timer, IPI or similar event.
1281 *
1282 * @returns The IRQ tag.
1283 * @param pDevIns Device instance of the APIC.
1284 * @param u8Level PDM_IRQ_LEVEL_HIGH or PDM_IRQ_LEVEL_FLIP_FLOP.
1285 */
1286 DECLRCCALLBACKMEMBER(uint32_t, pfnCalcIrqTag,(PPDMDEVINS pDevIns, uint8_t u8Level));
1287
1288 /**
1289 * Modifies APIC-related bits in the CPUID feature mask.
1290 *
1291 * @param pDevIns Device instance of the APIC.
1292 * @param enmVersion Supported APIC version.
1293 */
1294 DECLRCCALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, PDMAPICVERSION enmVersion));
1295
1296 /**
1297 * Acquires the PDM lock.
1298 *
1299 * @returns VINF_SUCCESS on success.
1300 * @returns rc if we failed to acquire the lock.
1301 * @param pDevIns The APIC device instance.
1302 * @param rc What to return if we fail to acquire the lock.
1303 */
1304 DECLRCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1305
1306 /**
1307 * Releases the PDM lock.
1308 *
1309 * @param pDevIns The APIC device instance.
1310 */
1311 DECLRCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1312
1313 /**
1314 * Get the virtual CPU id corresponding to the current EMT.
1315 *
1316 * @param pDevIns The APIC device instance.
1317 */
1318 DECLRCCALLBACKMEMBER(VMCPUID, pfnGetCpuId,(PPDMDEVINS pDevIns));
1319
1320 /** Just a safety precaution. */
1321 uint32_t u32TheEnd;
1322} PDMAPICHLPRC;
1323/** Pointer to APIC GC helpers. */
1324typedef RCPTRTYPE(PDMAPICHLPRC *) PPDMAPICHLPRC;
1325/** Pointer to const APIC helpers. */
1326typedef RCPTRTYPE(const PDMAPICHLPRC *) PCPDMAPICHLPRC;
1327
1328/** Current PDMAPICHLPRC version number. */
1329#define PDM_APICHLPRC_VERSION PDM_VERSION_MAKE(0xfff5, 2, 0)
1330
1331
1332/**
1333 * APIC R0 helpers.
1334 */
1335typedef struct PDMAPICHLPR0
1336{
1337 /** Structure version. PDM_APICHLPR0_VERSION defines the current version. */
1338 uint32_t u32Version;
1339
1340 /**
1341 * Set the interrupt force action flag.
1342 *
1343 * @param pDevIns Device instance of the APIC.
1344 * @param enmType IRQ type.
1345 * @param idCpu Virtual CPU to set flag upon.
1346 */
1347 DECLR0CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1348
1349 /**
1350 * Clear the interrupt force action flag.
1351 *
1352 * @param pDevIns Device instance of the APIC.
1353 * @param enmType IRQ type.
1354 * @param idCpu Virtual CPU to clear flag upon.
1355 */
1356 DECLR0CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1357
1358 /**
1359 * Calculates an IRQ tag for a timer, IPI or similar event.
1360 *
1361 * @returns The IRQ tag.
1362 * @param pDevIns Device instance of the APIC.
1363 * @param u8Level PDM_IRQ_LEVEL_HIGH or PDM_IRQ_LEVEL_FLIP_FLOP.
1364 */
1365 DECLR0CALLBACKMEMBER(uint32_t, pfnCalcIrqTag,(PPDMDEVINS pDevIns, uint8_t u8Level));
1366
1367 /**
1368 * Modifies APIC-related bits in the CPUID feature mask.
1369 *
1370 * @param pDevIns Device instance of the APIC.
1371 * @param enmVersion Supported APIC version.
1372 */
1373 DECLR0CALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, PDMAPICVERSION enmVersion));
1374
1375 /**
1376 * Acquires the PDM lock.
1377 *
1378 * @returns VINF_SUCCESS on success.
1379 * @returns rc if we failed to acquire the lock.
1380 * @param pDevIns The APIC device instance.
1381 * @param rc What to return if we fail to acquire the lock.
1382 */
1383 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1384
1385 /**
1386 * Releases the PDM lock.
1387 *
1388 * @param pDevIns The APIC device instance.
1389 */
1390 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1391
1392 /**
1393 * Get the virtual CPU id corresponding to the current EMT.
1394 *
1395 * @param pDevIns The APIC device instance.
1396 */
1397 DECLR0CALLBACKMEMBER(VMCPUID, pfnGetCpuId,(PPDMDEVINS pDevIns));
1398
1399 /** Just a safety precaution. */
1400 uint32_t u32TheEnd;
1401} PDMAPICHLPR0;
1402/** Pointer to APIC GC helpers. */
1403typedef RCPTRTYPE(PDMAPICHLPR0 *) PPDMAPICHLPR0;
1404/** Pointer to const APIC helpers. */
1405typedef R0PTRTYPE(const PDMAPICHLPR0 *) PCPDMAPICHLPR0;
1406
1407/** Current PDMAPICHLPR0 version number. */
1408#define PDM_APICHLPR0_VERSION PDM_VERSION_MAKE(0xfff4, 2, 0)
1409
1410/**
1411 * APIC R3 helpers.
1412 */
1413typedef struct PDMAPICHLPR3
1414{
1415 /** Structure version. PDM_APICHLPR3_VERSION defines the current version. */
1416 uint32_t u32Version;
1417
1418 /**
1419 * Set the interrupt force action flag.
1420 *
1421 * @param pDevIns Device instance of the APIC.
1422 * @param enmType IRQ type.
1423 * @param idCpu Virtual CPU to set flag upon.
1424 */
1425 DECLR3CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1426
1427 /**
1428 * Clear the interrupt force action flag.
1429 *
1430 * @param pDevIns Device instance of the APIC.
1431 * @param enmType IRQ type.
1432 * @param idCpu Virtual CPU to clear flag upon.
1433 */
1434 DECLR3CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1435
1436 /**
1437 * Calculates an IRQ tag for a timer, IPI or similar event.
1438 *
1439 * @returns The IRQ tag.
1440 * @param pDevIns Device instance of the APIC.
1441 * @param u8Level PDM_IRQ_LEVEL_HIGH or PDM_IRQ_LEVEL_FLIP_FLOP.
1442 */
1443 DECLR3CALLBACKMEMBER(uint32_t, pfnCalcIrqTag,(PPDMDEVINS pDevIns, uint8_t u8Level));
1444
1445 /**
1446 * Modifies APIC-related bits in the CPUID feature mask.
1447 *
1448 * @param pDevIns Device instance of the APIC.
1449 * @param enmVersion Supported APIC version.
1450 */
1451 DECLR3CALLBACKMEMBER(void, pfnChangeFeature,(PPDMDEVINS pDevIns, PDMAPICVERSION enmVersion));
1452
1453 /**
1454 * Get the virtual CPU id corresponding to the current EMT.
1455 *
1456 * @param pDevIns The APIC device instance.
1457 */
1458 DECLR3CALLBACKMEMBER(VMCPUID, pfnGetCpuId,(PPDMDEVINS pDevIns));
1459
1460 /**
1461 * Sends SIPI to given virtual CPU.
1462 *
1463 * @param pDevIns The APIC device instance.
1464 * @param idCpu Virtual CPU to perform SIPI on
1465 * @param iVector SIPI vector
1466 */
1467 DECLR3CALLBACKMEMBER(void, pfnSendSipi,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t uVector));
1468
1469 /**
1470 * Sends init IPI to given virtual CPU, should result in reset and
1471 * halting till SIPI.
1472 *
1473 * @param pDevIns The APIC device instance.
1474 * @param idCpu Virtual CPU to perform SIPI on
1475 */
1476 DECLR3CALLBACKMEMBER(void, pfnSendInitIpi,(PPDMDEVINS pDevIns, VMCPUID idCpu));
1477
1478 /**
1479 * Gets the address of the RC APIC helpers.
1480 *
1481 * This should be called at both construction and relocation time
1482 * to obtain the correct address of the RC helpers.
1483 *
1484 * @returns GC pointer to the APIC helpers.
1485 * @param pDevIns Device instance of the APIC.
1486 */
1487 DECLR3CALLBACKMEMBER(PCPDMAPICHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1488
1489 /**
1490 * Gets the address of the R0 APIC helpers.
1491 *
1492 * This should be called at both construction and relocation time
1493 * to obtain the correct address of the R0 helpers.
1494 *
1495 * @returns R0 pointer to the APIC helpers.
1496 * @param pDevIns Device instance of the APIC.
1497 */
1498 DECLR3CALLBACKMEMBER(PCPDMAPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1499
1500 /**
1501 * Get the critical section used to synchronize the PICs, PCI and stuff.
1502 *
1503 * @returns Ring-3 pointer to the critical section.
1504 * @param pDevIns The APIC device instance.
1505 */
1506 DECLR3CALLBACKMEMBER(R3PTRTYPE(PPDMCRITSECT), pfnGetR3CritSect,(PPDMDEVINS pDevIns));
1507
1508 /**
1509 * Get the critical section used to synchronize the PICs, PCI and stuff.
1510 *
1511 * @returns Raw-mode context pointer to the critical section.
1512 * @param pDevIns The APIC device instance.
1513 */
1514 DECLR3CALLBACKMEMBER(RCPTRTYPE(PPDMCRITSECT), pfnGetRCCritSect,(PPDMDEVINS pDevIns));
1515
1516 /**
1517 * Get the critical section used to synchronize the PICs, PCI and stuff.
1518 *
1519 * @returns Ring-0 pointer to the critical section.
1520 * @param pDevIns The APIC device instance.
1521 */
1522 DECLR3CALLBACKMEMBER(R0PTRTYPE(PPDMCRITSECT), pfnGetR0CritSect,(PPDMDEVINS pDevIns));
1523
1524 /** Just a safety precaution. */
1525 uint32_t u32TheEnd;
1526} PDMAPICHLPR3;
1527/** Pointer to APIC helpers. */
1528typedef R3PTRTYPE(PDMAPICHLPR3 *) PPDMAPICHLPR3;
1529/** Pointer to const APIC helpers. */
1530typedef R3PTRTYPE(const PDMAPICHLPR3 *) PCPDMAPICHLPR3;
1531
1532/** Current PDMAPICHLP version number. */
1533#define PDM_APICHLPR3_VERSION PDM_VERSION_MAKE(0xfff3, 2, 0)
1534
1535
1536/**
1537 * I/O APIC registration structure.
1538 */
1539typedef struct PDMIOAPICREG
1540{
1541 /** Struct version+magic number (PDM_IOAPICREG_VERSION). */
1542 uint32_t u32Version;
1543
1544 /**
1545 * Set the an IRQ.
1546 *
1547 * @param pDevIns Device instance of the I/O APIC.
1548 * @param iIrq IRQ number to set.
1549 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1550 * @param uTagSrc The IRQ tag and source (for tracing).
1551 * @remarks Caller enters the PDM critical section
1552 */
1553 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
1554
1555 /** The name of the RC SetIrq entry point. */
1556 const char *pszSetIrqRC;
1557
1558 /** The name of the R0 SetIrq entry point. */
1559 const char *pszSetIrqR0;
1560
1561 /**
1562 * Send a MSI.
1563 *
1564 * @param pDevIns Device instance of the I/O APIC.
1565 * @param GCPhys Request address.
1566 * @param uValue Request value.
1567 * @param uTagSrc The IRQ tag and source (for tracing).
1568 * @remarks Caller enters the PDM critical section
1569 */
1570 DECLR3CALLBACKMEMBER(void, pfnSendMsiR3,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc));
1571
1572 /** The name of the RC SendMsi entry point. */
1573 const char *pszSendMsiRC;
1574
1575 /** The name of the R0 SendMsi entry point. */
1576 const char *pszSendMsiR0;
1577} PDMIOAPICREG;
1578/** Pointer to an APIC registration structure. */
1579typedef PDMIOAPICREG *PPDMIOAPICREG;
1580
1581/** Current PDMAPICREG version number. */
1582#define PDM_IOAPICREG_VERSION PDM_VERSION_MAKE(0xfff2, 3, 0)
1583
1584
1585/**
1586 * IOAPIC RC helpers.
1587 */
1588typedef struct PDMIOAPICHLPRC
1589{
1590 /** Structure version. PDM_IOAPICHLPRC_VERSION defines the current version. */
1591 uint32_t u32Version;
1592
1593 /**
1594 * Private interface between the IOAPIC and APIC.
1595 *
1596 * See comments about this hack on PDMAPICREG::pfnBusDeliverR3.
1597 *
1598 * @returns status code.
1599 * @param pDevIns Device instance of the IOAPIC.
1600 * @param u8Dest See APIC implementation.
1601 * @param u8DestMode See APIC implementation.
1602 * @param u8DeliveryMode See APIC implementation.
1603 * @param iVector See APIC implementation.
1604 * @param u8Polarity See APIC implementation.
1605 * @param u8TriggerMode See APIC implementation.
1606 * @param uTagSrc The IRQ tag and source (for tracing).
1607 */
1608 DECLRCCALLBACKMEMBER(int, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1609 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
1610
1611 /**
1612 * Acquires the PDM lock.
1613 *
1614 * @returns VINF_SUCCESS on success.
1615 * @returns rc if we failed to acquire the lock.
1616 * @param pDevIns The IOAPIC device instance.
1617 * @param rc What to return if we fail to acquire the lock.
1618 */
1619 DECLRCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1620
1621 /**
1622 * Releases the PDM lock.
1623 *
1624 * @param pDevIns The IOAPIC device instance.
1625 */
1626 DECLRCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1627
1628 /** Just a safety precaution. */
1629 uint32_t u32TheEnd;
1630} PDMIOAPICHLPRC;
1631/** Pointer to IOAPIC RC helpers. */
1632typedef RCPTRTYPE(PDMIOAPICHLPRC *) PPDMIOAPICHLPRC;
1633/** Pointer to const IOAPIC helpers. */
1634typedef RCPTRTYPE(const PDMIOAPICHLPRC *) PCPDMIOAPICHLPRC;
1635
1636/** Current PDMIOAPICHLPRC version number. */
1637#define PDM_IOAPICHLPRC_VERSION PDM_VERSION_MAKE(0xfff1, 2, 0)
1638
1639
1640/**
1641 * IOAPIC R0 helpers.
1642 */
1643typedef struct PDMIOAPICHLPR0
1644{
1645 /** Structure version. PDM_IOAPICHLPR0_VERSION defines the current version. */
1646 uint32_t u32Version;
1647
1648 /**
1649 * Private interface between the IOAPIC and APIC.
1650 *
1651 * See comments about this hack on PDMAPICREG::pfnBusDeliverR3.
1652 *
1653 * @returns status code.
1654 * @param pDevIns Device instance of the IOAPIC.
1655 * @param u8Dest See APIC implementation.
1656 * @param u8DestMode See APIC implementation.
1657 * @param u8DeliveryMode See APIC implementation.
1658 * @param iVector See APIC implementation.
1659 * @param u8Polarity See APIC implementation.
1660 * @param u8TriggerMode See APIC implementation.
1661 * @param uTagSrc The IRQ tag and source (for tracing).
1662 */
1663 DECLR0CALLBACKMEMBER(int, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1664 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
1665
1666 /**
1667 * Acquires the PDM lock.
1668 *
1669 * @returns VINF_SUCCESS on success.
1670 * @returns rc if we failed to acquire the lock.
1671 * @param pDevIns The IOAPIC device instance.
1672 * @param rc What to return if we fail to acquire the lock.
1673 */
1674 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1675
1676 /**
1677 * Releases the PDM lock.
1678 *
1679 * @param pDevIns The IOAPIC device instance.
1680 */
1681 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1682
1683 /** Just a safety precaution. */
1684 uint32_t u32TheEnd;
1685} PDMIOAPICHLPR0;
1686/** Pointer to IOAPIC R0 helpers. */
1687typedef R0PTRTYPE(PDMIOAPICHLPR0 *) PPDMIOAPICHLPR0;
1688/** Pointer to const IOAPIC helpers. */
1689typedef R0PTRTYPE(const PDMIOAPICHLPR0 *) PCPDMIOAPICHLPR0;
1690
1691/** Current PDMIOAPICHLPR0 version number. */
1692#define PDM_IOAPICHLPR0_VERSION PDM_VERSION_MAKE(0xfff0, 2, 0)
1693
1694/**
1695 * IOAPIC R3 helpers.
1696 */
1697typedef struct PDMIOAPICHLPR3
1698{
1699 /** Structure version. PDM_IOAPICHLPR3_VERSION defines the current version. */
1700 uint32_t u32Version;
1701
1702 /**
1703 * Private interface between the IOAPIC and APIC.
1704 *
1705 * See comments about this hack on PDMAPICREG::pfnBusDeliverR3.
1706 *
1707 * @returns status code
1708 * @param pDevIns Device instance of the IOAPIC.
1709 * @param u8Dest See APIC implementation.
1710 * @param u8DestMode See APIC implementation.
1711 * @param u8DeliveryMode See APIC implementation.
1712 * @param iVector See APIC implementation.
1713 * @param u8Polarity See APIC implementation.
1714 * @param u8TriggerMode See APIC implementation.
1715 * @param uTagSrc The IRQ tag and source (for tracing).
1716 */
1717 DECLR3CALLBACKMEMBER(int, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1718 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
1719
1720 /**
1721 * Acquires the PDM lock.
1722 *
1723 * @returns VINF_SUCCESS on success.
1724 * @returns Fatal error on failure.
1725 * @param pDevIns The IOAPIC device instance.
1726 * @param rc Dummy for making the interface identical to the GC and R0 versions.
1727 */
1728 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1729
1730 /**
1731 * Releases the PDM lock.
1732 *
1733 * @param pDevIns The IOAPIC device instance.
1734 */
1735 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1736
1737 /**
1738 * Gets the address of the RC IOAPIC helpers.
1739 *
1740 * This should be called at both construction and relocation time
1741 * to obtain the correct address of the RC helpers.
1742 *
1743 * @returns RC pointer to the IOAPIC helpers.
1744 * @param pDevIns Device instance of the IOAPIC.
1745 */
1746 DECLR3CALLBACKMEMBER(PCPDMIOAPICHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1747
1748 /**
1749 * Gets the address of the R0 IOAPIC helpers.
1750 *
1751 * This should be called at both construction and relocation time
1752 * to obtain the correct address of the R0 helpers.
1753 *
1754 * @returns R0 pointer to the IOAPIC helpers.
1755 * @param pDevIns Device instance of the IOAPIC.
1756 */
1757 DECLR3CALLBACKMEMBER(PCPDMIOAPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1758
1759 /** Just a safety precaution. */
1760 uint32_t u32TheEnd;
1761} PDMIOAPICHLPR3;
1762/** Pointer to IOAPIC R3 helpers. */
1763typedef R3PTRTYPE(PDMIOAPICHLPR3 *) PPDMIOAPICHLPR3;
1764/** Pointer to const IOAPIC helpers. */
1765typedef R3PTRTYPE(const PDMIOAPICHLPR3 *) PCPDMIOAPICHLPR3;
1766
1767/** Current PDMIOAPICHLPR3 version number. */
1768#define PDM_IOAPICHLPR3_VERSION PDM_VERSION_MAKE(0xffef, 2, 0)
1769
1770
1771/**
1772 * HPET registration structure.
1773 */
1774typedef struct PDMHPETREG
1775{
1776 /** Struct version+magic number (PDM_HPETREG_VERSION). */
1777 uint32_t u32Version;
1778
1779} PDMHPETREG;
1780/** Pointer to an HPET registration structure. */
1781typedef PDMHPETREG *PPDMHPETREG;
1782
1783/** Current PDMHPETREG version number. */
1784#define PDM_HPETREG_VERSION PDM_VERSION_MAKE(0xffe2, 1, 0)
1785
1786/**
1787 * HPET RC helpers.
1788 *
1789 * @remarks Keep this around in case HPET will need PDM interaction in again RC
1790 * at some later point.
1791 */
1792typedef struct PDMHPETHLPRC
1793{
1794 /** Structure version. PDM_HPETHLPRC_VERSION defines the current version. */
1795 uint32_t u32Version;
1796
1797 /** Just a safety precaution. */
1798 uint32_t u32TheEnd;
1799} PDMHPETHLPRC;
1800
1801/** Pointer to HPET RC helpers. */
1802typedef RCPTRTYPE(PDMHPETHLPRC *) PPDMHPETHLPRC;
1803/** Pointer to const HPET RC helpers. */
1804typedef RCPTRTYPE(const PDMHPETHLPRC *) PCPDMHPETHLPRC;
1805
1806/** Current PDMHPETHLPRC version number. */
1807#define PDM_HPETHLPRC_VERSION PDM_VERSION_MAKE(0xffee, 2, 0)
1808
1809
1810/**
1811 * HPET R0 helpers.
1812 *
1813 * @remarks Keep this around in case HPET will need PDM interaction in again R0
1814 * at some later point.
1815 */
1816typedef struct PDMHPETHLPR0
1817{
1818 /** Structure version. PDM_HPETHLPR0_VERSION defines the current version. */
1819 uint32_t u32Version;
1820
1821 /** Just a safety precaution. */
1822 uint32_t u32TheEnd;
1823} PDMHPETHLPR0;
1824
1825/** Pointer to HPET R0 helpers. */
1826typedef R0PTRTYPE(PDMHPETHLPR0 *) PPDMHPETHLPR0;
1827/** Pointer to const HPET R0 helpers. */
1828typedef R0PTRTYPE(const PDMHPETHLPR0 *) PCPDMHPETHLPR0;
1829
1830/** Current PDMHPETHLPR0 version number. */
1831#define PDM_HPETHLPR0_VERSION PDM_VERSION_MAKE(0xffed, 2, 0)
1832
1833/**
1834 * HPET R3 helpers.
1835 */
1836typedef struct PDMHPETHLPR3
1837{
1838 /** Structure version. PDM_HPETHLP_VERSION defines the current version. */
1839 uint32_t u32Version;
1840
1841 /**
1842 * Gets the address of the RC HPET helpers.
1843 *
1844 * This should be called at both construction and relocation time
1845 * to obtain the correct address of the RC helpers.
1846 *
1847 * @returns RC pointer to the HPET helpers.
1848 * @param pDevIns Device instance of the HPET.
1849 */
1850 DECLR3CALLBACKMEMBER(PCPDMHPETHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1851
1852 /**
1853 * Gets the address of the R0 HPET helpers.
1854 *
1855 * This should be called at both construction and relocation time
1856 * to obtain the correct address of the R0 helpers.
1857 *
1858 * @returns R0 pointer to the HPET helpers.
1859 * @param pDevIns Device instance of the HPET.
1860 */
1861 DECLR3CALLBACKMEMBER(PCPDMHPETHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1862
1863 /**
1864 * Set legacy mode on PIT and RTC.
1865 *
1866 * @returns VINF_SUCCESS on success.
1867 * @returns rc if we failed to set legacy mode.
1868 * @param pDevIns Device instance of the HPET.
1869 * @param fActivated Whether legacy mode is activated or deactivated.
1870 */
1871 DECLR3CALLBACKMEMBER(int, pfnSetLegacyMode,(PPDMDEVINS pDevIns, bool fActivated));
1872
1873
1874 /**
1875 * Set IRQ, bypassing ISA bus override rules.
1876 *
1877 * @returns VINF_SUCCESS on success.
1878 * @returns rc if we failed to set legacy mode.
1879 * @param pDevIns Device instance of the HPET.
1880 * @param fActivate Activate or deactivate legacy mode.
1881 */
1882 DECLR3CALLBACKMEMBER(int, pfnSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
1883
1884 /** Just a safety precaution. */
1885 uint32_t u32TheEnd;
1886} PDMHPETHLPR3;
1887
1888/** Pointer to HPET R3 helpers. */
1889typedef R3PTRTYPE(PDMHPETHLPR3 *) PPDMHPETHLPR3;
1890/** Pointer to const HPET R3 helpers. */
1891typedef R3PTRTYPE(const PDMHPETHLPR3 *) PCPDMHPETHLPR3;
1892
1893/** Current PDMHPETHLPR3 version number. */
1894#define PDM_HPETHLPR3_VERSION PDM_VERSION_MAKE(0xffec, 2, 0)
1895
1896
1897/**
1898 * Raw PCI device registration structure.
1899 */
1900typedef struct PDMPCIRAWREG
1901{
1902 /** Struct version+magic number (PDM_PCIRAWREG_VERSION). */
1903 uint32_t u32Version;
1904 /** Just a safety precaution. */
1905 uint32_t u32TheEnd;
1906} PDMPCIRAWREG;
1907/** Pointer to a raw PCI registration structure. */
1908typedef PDMPCIRAWREG *PPDMPCIRAWREG;
1909
1910/** Current PDMPCIRAWREG version number. */
1911#define PDM_PCIRAWREG_VERSION PDM_VERSION_MAKE(0xffe1, 1, 0)
1912
1913/**
1914 * Raw PCI device raw-mode context helpers.
1915 */
1916typedef struct PDMPCIRAWHLPRC
1917{
1918 /** Structure version and magic number (PDM_PCIRAWHLPRC_VERSION). */
1919 uint32_t u32Version;
1920 /** Just a safety precaution. */
1921 uint32_t u32TheEnd;
1922} PDMPCIRAWHLPRC;
1923/** Pointer to a raw PCI deviec raw-mode context helper structure. */
1924typedef RCPTRTYPE(PDMPCIRAWHLPRC *) PPDMPCIRAWHLPRC;
1925/** Pointer to a const raw PCI deviec raw-mode context helper structure. */
1926typedef RCPTRTYPE(const PDMPCIRAWHLPRC *) PCPDMPCIRAWHLPRC;
1927
1928/** Current PDMPCIRAWHLPRC version number. */
1929#define PDM_PCIRAWHLPRC_VERSION PDM_VERSION_MAKE(0xffe0, 1, 0)
1930
1931/**
1932 * Raw PCI device ring-0 context helpers.
1933 */
1934typedef struct PDMPCIRAWHLPR0
1935{
1936 /** Structure version and magic number (PDM_PCIRAWHLPR0_VERSION). */
1937 uint32_t u32Version;
1938 /** Just a safety precaution. */
1939 uint32_t u32TheEnd;
1940} PDMPCIRAWHLPR0;
1941/** Pointer to a raw PCI deviec ring-0 context helper structure. */
1942typedef R0PTRTYPE(PDMPCIRAWHLPR0 *) PPDMPCIRAWHLPR0;
1943/** Pointer to a const raw PCI deviec ring-0 context helper structure. */
1944typedef R0PTRTYPE(const PDMPCIRAWHLPR0 *) PCPDMPCIRAWHLPR0;
1945
1946/** Current PDMPCIRAWHLPR0 version number. */
1947#define PDM_PCIRAWHLPR0_VERSION PDM_VERSION_MAKE(0xffdf, 1, 0)
1948
1949
1950/**
1951 * Raw PCI device ring-3 context helpers.
1952 */
1953typedef struct PDMPCIRAWHLPR3
1954{
1955 /** Undefined structure version and magic number. */
1956 uint32_t u32Version;
1957
1958 /**
1959 * Gets the address of the RC raw PCI device helpers.
1960 *
1961 * This should be called at both construction and relocation time to obtain
1962 * the correct address of the RC helpers.
1963 *
1964 * @returns RC pointer to the raw PCI device helpers.
1965 * @param pDevIns Device instance of the raw PCI device.
1966 */
1967 DECLR3CALLBACKMEMBER(PCPDMPCIRAWHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1968
1969 /**
1970 * Gets the address of the R0 raw PCI device helpers.
1971 *
1972 * This should be called at both construction and relocation time to obtain
1973 * the correct address of the R0 helpers.
1974 *
1975 * @returns R0 pointer to the raw PCI device helpers.
1976 * @param pDevIns Device instance of the raw PCI device.
1977 */
1978 DECLR3CALLBACKMEMBER(PCPDMPCIRAWHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1979
1980 /** Just a safety precaution. */
1981 uint32_t u32TheEnd;
1982} PDMPCIRAWHLPR3;
1983/** Pointer to raw PCI R3 helpers. */
1984typedef R3PTRTYPE(PDMPCIRAWHLPR3 *) PPDMPCIRAWHLPR3;
1985/** Pointer to const raw PCI R3 helpers. */
1986typedef R3PTRTYPE(const PDMPCIRAWHLPR3 *) PCPDMPCIRAWHLPR3;
1987
1988/** Current PDMPCIRAWHLPR3 version number. */
1989#define PDM_PCIRAWHLPR3_VERSION PDM_VERSION_MAKE(0xffde, 1, 0)
1990
1991
1992#ifdef IN_RING3
1993
1994/**
1995 * DMA Transfer Handler.
1996 *
1997 * @returns Number of bytes transferred.
1998 * @param pDevIns Device instance of the DMA.
1999 * @param pvUser User pointer.
2000 * @param uChannel Channel number.
2001 * @param off DMA position.
2002 * @param cb Block size.
2003 */
2004typedef DECLCALLBACK(uint32_t) FNDMATRANSFERHANDLER(PPDMDEVINS pDevIns, void *pvUser, unsigned uChannel, uint32_t off, uint32_t cb);
2005/** Pointer to a FNDMATRANSFERHANDLER(). */
2006typedef FNDMATRANSFERHANDLER *PFNDMATRANSFERHANDLER;
2007
2008/**
2009 * DMA Controller registration structure.
2010 */
2011typedef struct PDMDMAREG
2012{
2013 /** Structure version number. PDM_DMACREG_VERSION defines the current version. */
2014 uint32_t u32Version;
2015
2016 /**
2017 * Execute pending transfers.
2018 *
2019 * @returns A more work indiciator. I.e. 'true' if there is more to be done, and 'false' if all is done.
2020 * @param pDevIns Device instance of the DMAC.
2021 * @remarks No locks held, called on EMT(0) as a form of serialization.
2022 */
2023 DECLR3CALLBACKMEMBER(bool, pfnRun,(PPDMDEVINS pDevIns));
2024
2025 /**
2026 * Register transfer function for DMA channel.
2027 *
2028 * @param pDevIns Device instance of the DMAC.
2029 * @param uChannel Channel number.
2030 * @param pfnTransferHandler Device specific transfer function.
2031 * @param pvUSer User pointer to be passed to the callback.
2032 * @remarks No locks held, called on an EMT.
2033 */
2034 DECLR3CALLBACKMEMBER(void, pfnRegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
2035
2036 /**
2037 * Read memory
2038 *
2039 * @returns Number of bytes read.
2040 * @param pDevIns Device instance of the DMAC.
2041 * @param pvBuffer Pointer to target buffer.
2042 * @param off DMA position.
2043 * @param cbBlock Block size.
2044 * @remarks No locks held, called on an EMT.
2045 */
2046 DECLR3CALLBACKMEMBER(uint32_t, pfnReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock));
2047
2048 /**
2049 * Write memory
2050 *
2051 * @returns Number of bytes written.
2052 * @param pDevIns Device instance of the DMAC.
2053 * @param pvBuffer Memory to write.
2054 * @param off DMA position.
2055 * @param cbBlock Block size.
2056 * @remarks No locks held, called on an EMT.
2057 */
2058 DECLR3CALLBACKMEMBER(uint32_t, pfnWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock));
2059
2060 /**
2061 * Set the DREQ line.
2062 *
2063 * @param pDevIns Device instance of the DMAC.
2064 * @param uChannel Channel number.
2065 * @param uLevel Level of the line.
2066 * @remarks No locks held, called on an EMT.
2067 */
2068 DECLR3CALLBACKMEMBER(void, pfnSetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
2069
2070 /**
2071 * Get channel mode
2072 *
2073 * @returns Channel mode.
2074 * @param pDevIns Device instance of the DMAC.
2075 * @param uChannel Channel number.
2076 * @remarks No locks held, called on an EMT.
2077 */
2078 DECLR3CALLBACKMEMBER(uint8_t, pfnGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
2079
2080} PDMDMACREG;
2081/** Pointer to a DMAC registration structure. */
2082typedef PDMDMACREG *PPDMDMACREG;
2083
2084/** Current PDMDMACREG version number. */
2085#define PDM_DMACREG_VERSION PDM_VERSION_MAKE(0xffeb, 1, 0)
2086
2087
2088/**
2089 * DMA Controller device helpers.
2090 */
2091typedef struct PDMDMACHLP
2092{
2093 /** Structure version. PDM_DMACHLP_VERSION defines the current version. */
2094 uint32_t u32Version;
2095
2096 /* to-be-defined */
2097
2098} PDMDMACHLP;
2099/** Pointer to DMAC helpers. */
2100typedef PDMDMACHLP *PPDMDMACHLP;
2101/** Pointer to const DMAC helpers. */
2102typedef const PDMDMACHLP *PCPDMDMACHLP;
2103
2104/** Current PDMDMACHLP version number. */
2105#define PDM_DMACHLP_VERSION PDM_VERSION_MAKE(0xffea, 1, 0)
2106
2107#endif /* IN_RING3 */
2108
2109
2110
2111/**
2112 * RTC registration structure.
2113 */
2114typedef struct PDMRTCREG
2115{
2116 /** Structure version number. PDM_RTCREG_VERSION defines the current version. */
2117 uint32_t u32Version;
2118 uint32_t u32Alignment; /**< structure size alignment. */
2119
2120 /**
2121 * Write to a CMOS register and update the checksum if necessary.
2122 *
2123 * @returns VBox status code.
2124 * @param pDevIns Device instance of the RTC.
2125 * @param iReg The CMOS register index.
2126 * @param u8Value The CMOS register value.
2127 * @remarks Caller enters the device critical section.
2128 */
2129 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
2130
2131 /**
2132 * Read a CMOS register.
2133 *
2134 * @returns VBox status code.
2135 * @param pDevIns Device instance of the RTC.
2136 * @param iReg The CMOS register index.
2137 * @param pu8Value Where to store the CMOS register value.
2138 * @remarks Caller enters the device critical section.
2139 */
2140 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
2141
2142} PDMRTCREG;
2143/** Pointer to a RTC registration structure. */
2144typedef PDMRTCREG *PPDMRTCREG;
2145/** Pointer to a const RTC registration structure. */
2146typedef const PDMRTCREG *PCPDMRTCREG;
2147
2148/** Current PDMRTCREG version number. */
2149#define PDM_RTCREG_VERSION PDM_VERSION_MAKE(0xffe9, 2, 0)
2150
2151
2152/**
2153 * RTC device helpers.
2154 */
2155typedef struct PDMRTCHLP
2156{
2157 /** Structure version. PDM_RTCHLP_VERSION defines the current version. */
2158 uint32_t u32Version;
2159
2160 /* to-be-defined */
2161
2162} PDMRTCHLP;
2163/** Pointer to RTC helpers. */
2164typedef PDMRTCHLP *PPDMRTCHLP;
2165/** Pointer to const RTC helpers. */
2166typedef const PDMRTCHLP *PCPDMRTCHLP;
2167
2168/** Current PDMRTCHLP version number. */
2169#define PDM_RTCHLP_VERSION PDM_VERSION_MAKE(0xffe8, 1, 0)
2170
2171
2172
2173#ifdef IN_RING3
2174
2175/**
2176 * PDM Device API.
2177 */
2178typedef struct PDMDEVHLPR3
2179{
2180 /** Structure version. PDM_DEVHLPR3_VERSION defines the current version. */
2181 uint32_t u32Version;
2182
2183 /**
2184 * Register a number of I/O ports with a device.
2185 *
2186 * These callbacks are of course for the host context (HC).
2187 * Register HC handlers before guest context (GC) handlers! There must be a
2188 * HC handler for every GC handler!
2189 *
2190 * @returns VBox status.
2191 * @param pDevIns The device instance to register the ports with.
2192 * @param Port First port number in the range.
2193 * @param cPorts Number of ports to register.
2194 * @param pvUser User argument.
2195 * @param pfnOut Pointer to function which is gonna handle OUT operations.
2196 * @param pfnIn Pointer to function which is gonna handle IN operations.
2197 * @param pfnOutStr Pointer to function which is gonna handle string OUT operations.
2198 * @param pfnInStr Pointer to function which is gonna handle string IN operations.
2199 * @param pszDesc Pointer to description string. This must not be freed.
2200 * @remarks Caller enters the device critical section prior to invoking the
2201 * registered callback methods.
2202 */
2203 DECLR3CALLBACKMEMBER(int, pfnIOPortRegister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser,
2204 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
2205 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc));
2206
2207 /**
2208 * Register a number of I/O ports with a device for RC.
2209 *
2210 * These callbacks are for the raw-mode context (RC). Register ring-3 context
2211 * (R3) handlers before raw-mode context handlers! There must be a R3 handler
2212 * for every RC handler!
2213 *
2214 * @returns VBox status.
2215 * @param pDevIns The device instance to register the ports with
2216 * and which RC module to resolve the names
2217 * against.
2218 * @param Port First port number in the range.
2219 * @param cPorts Number of ports to register.
2220 * @param pvUser User argument.
2221 * @param pszOut Name of the RC function which is gonna handle OUT operations.
2222 * @param pszIn Name of the RC function which is gonna handle IN operations.
2223 * @param pszOutStr Name of the RC function which is gonna handle string OUT operations.
2224 * @param pszInStr Name of the RC function which is gonna handle string IN operations.
2225 * @param pszDesc Pointer to description string. This must not be freed.
2226 * @remarks Caller enters the device critical section prior to invoking the
2227 * registered callback methods.
2228 */
2229 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterRC,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
2230 const char *pszOut, const char *pszIn,
2231 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
2232
2233 /**
2234 * Register a number of I/O ports with a device.
2235 *
2236 * These callbacks are of course for the ring-0 host context (R0).
2237 * Register R3 (HC) handlers before R0 (R0) handlers! There must be a R3 (HC) handler for every R0 handler!
2238 *
2239 * @returns VBox status.
2240 * @param pDevIns The device instance to register the ports with.
2241 * @param Port First port number in the range.
2242 * @param cPorts Number of ports to register.
2243 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
2244 * @param pszOut Name of the R0 function which is gonna handle OUT operations.
2245 * @param pszIn Name of the R0 function which is gonna handle IN operations.
2246 * @param pszOutStr Name of the R0 function which is gonna handle string OUT operations.
2247 * @param pszInStr Name of the R0 function which is gonna handle string IN operations.
2248 * @param pszDesc Pointer to description string. This must not be freed.
2249 * @remarks Caller enters the device critical section prior to invoking the
2250 * registered callback methods.
2251 */
2252 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterR0,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
2253 const char *pszOut, const char *pszIn,
2254 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
2255
2256 /**
2257 * Deregister I/O ports.
2258 *
2259 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
2260 *
2261 * @returns VBox status.
2262 * @param pDevIns The device instance owning the ports.
2263 * @param Port First port number in the range.
2264 * @param cPorts Number of ports to deregister.
2265 */
2266 DECLR3CALLBACKMEMBER(int, pfnIOPortDeregister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts));
2267
2268 /**
2269 * Register a Memory Mapped I/O (MMIO) region.
2270 *
2271 * These callbacks are of course for the ring-3 context (R3). Register HC
2272 * handlers before raw-mode context (RC) and ring-0 context (R0) handlers! There
2273 * must be a R3 handler for every RC and R0 handler!
2274 *
2275 * @returns VBox status.
2276 * @param pDevIns The device instance to register the MMIO with.
2277 * @param GCPhysStart First physical address in the range.
2278 * @param cbRange The size of the range (in bytes).
2279 * @param pvUser User argument.
2280 * @param pfnWrite Pointer to function which is gonna handle Write operations.
2281 * @param pfnRead Pointer to function which is gonna handle Read operations.
2282 * @param pfnFill Pointer to function which is gonna handle Fill/memset operations. (optional)
2283 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
2284 * @param pszDesc Pointer to description string. This must not be freed.
2285 * @remarks Caller enters the device critical section prior to invoking the
2286 * registered callback methods.
2287 */
2288 DECLR3CALLBACKMEMBER(int, pfnMMIORegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTHCPTR pvUser,
2289 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
2290 uint32_t fFlags, const char *pszDesc));
2291
2292 /**
2293 * Register a Memory Mapped I/O (MMIO) region for GC.
2294 *
2295 * These callbacks are for the raw-mode context (RC). Register ring-3 context
2296 * (R3) handlers before guest context handlers! There must be a R3 handler for
2297 * every RC handler!
2298 *
2299 * @returns VBox status.
2300 * @param pDevIns The device instance to register the MMIO with.
2301 * @param GCPhysStart First physical address in the range.
2302 * @param cbRange The size of the range (in bytes).
2303 * @param pvUser User argument.
2304 * @param pszWrite Name of the RC function which is gonna handle Write operations.
2305 * @param pszRead Name of the RC function which is gonna handle Read operations.
2306 * @param pszFill Name of the RC function which is gonna handle Fill/memset operations. (optional)
2307 * @remarks Caller enters the device critical section prior to invoking the
2308 * registered callback methods.
2309 */
2310 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterRC,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTRCPTR pvUser,
2311 const char *pszWrite, const char *pszRead, const char *pszFill));
2312
2313 /**
2314 * Register a Memory Mapped I/O (MMIO) region for R0.
2315 *
2316 * These callbacks are for the ring-0 host context (R0). Register ring-3
2317 * constext (R3) handlers before R0 handlers! There must be a R3 handler for
2318 * every R0 handler!
2319 *
2320 * @returns VBox status.
2321 * @param pDevIns The device instance to register the MMIO with.
2322 * @param GCPhysStart First physical address in the range.
2323 * @param cbRange The size of the range (in bytes).
2324 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
2325 * @param pszWrite Name of the RC function which is gonna handle Write operations.
2326 * @param pszRead Name of the RC function which is gonna handle Read operations.
2327 * @param pszFill Name of the RC function which is gonna handle Fill/memset operations. (optional)
2328 * @param pszDesc Obsolete. NULL is fine.
2329 * @remarks Caller enters the device critical section prior to invoking the
2330 * registered callback methods.
2331 */
2332 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterR0,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTR0PTR pvUser,
2333 const char *pszWrite, const char *pszRead, const char *pszFill));
2334
2335 /**
2336 * Deregister a Memory Mapped I/O (MMIO) region.
2337 *
2338 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
2339 *
2340 * @returns VBox status.
2341 * @param pDevIns The device instance owning the MMIO region(s).
2342 * @param GCPhysStart First physical address in the range.
2343 * @param cbRange The size of the range (in bytes).
2344 */
2345 DECLR3CALLBACKMEMBER(int, pfnMMIODeregister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange));
2346
2347 /**
2348 * Allocate and register a MMIO2 region.
2349 *
2350 * As mentioned elsewhere, MMIO2 is just RAM spelled differently. It's
2351 * RAM associated with a device. It is also non-shared memory with a
2352 * permanent ring-3 mapping and page backing (presently).
2353 *
2354 * @returns VBox status.
2355 * @param pDevIns The device instance.
2356 * @param iRegion The region number. Use the PCI region number as
2357 * this must be known to the PCI bus device too. If
2358 * it's not associated with the PCI device, then
2359 * any number up to UINT8_MAX is fine.
2360 * @param cb The size (in bytes) of the region.
2361 * @param fFlags Reserved for future use, must be zero.
2362 * @param ppv Where to store the address of the ring-3 mapping
2363 * of the memory.
2364 * @param pszDesc Pointer to description string. This must not be
2365 * freed.
2366 * @thread EMT.
2367 */
2368 DECLR3CALLBACKMEMBER(int, pfnMMIO2Register,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc));
2369
2370 /**
2371 * Deregisters and frees a MMIO2 region.
2372 *
2373 * Any physical (and virtual) access handlers registered for the region must
2374 * be deregistered before calling this function.
2375 *
2376 * @returns VBox status code.
2377 * @param pDevIns The device instance.
2378 * @param iRegion The region number used during registration.
2379 * @thread EMT.
2380 */
2381 DECLR3CALLBACKMEMBER(int, pfnMMIO2Deregister,(PPDMDEVINS pDevIns, uint32_t iRegion));
2382
2383 /**
2384 * Maps a MMIO2 region into the physical memory space.
2385 *
2386 * A MMIO2 range may overlap with base memory if a lot of RAM
2387 * is configured for the VM, in which case we'll drop the base
2388 * memory pages. Presently we will make no attempt to preserve
2389 * anything that happens to be present in the base memory that
2390 * is replaced, this is of course incorrectly but it's too much
2391 * effort.
2392 *
2393 * @returns VBox status code.
2394 * @param pDevIns The device instance.
2395 * @param iRegion The region number used during registration.
2396 * @param GCPhys The physical address to map it at.
2397 * @thread EMT.
2398 */
2399 DECLR3CALLBACKMEMBER(int, pfnMMIO2Map,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys));
2400
2401 /**
2402 * Unmaps a MMIO2 region previously mapped using pfnMMIO2Map.
2403 *
2404 * @returns VBox status code.
2405 * @param pDevIns The device instance.
2406 * @param iRegion The region number used during registration.
2407 * @param GCPhys The physical address it's currently mapped at.
2408 * @thread EMT.
2409 */
2410 DECLR3CALLBACKMEMBER(int, pfnMMIO2Unmap,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys));
2411
2412 /**
2413 * Maps a portion of an MMIO2 region into the hypervisor region.
2414 *
2415 * Callers of this API must never deregister the MMIO2 region before the
2416 * VM is powered off.
2417 *
2418 * @return VBox status code.
2419 * @param pDevIns The device owning the MMIO2 memory.
2420 * @param iRegion The region.
2421 * @param off The offset into the region. Will be rounded down
2422 * to closest page boundary.
2423 * @param cb The number of bytes to map. Will be rounded up
2424 * to the closest page boundary.
2425 * @param pszDesc Mapping description.
2426 * @param pRCPtr Where to store the RC address.
2427 */
2428 DECLR3CALLBACKMEMBER(int, pfnMMHyperMapMMIO2,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
2429 const char *pszDesc, PRTRCPTR pRCPtr));
2430
2431 /**
2432 * Maps a portion of an MMIO2 region into kernel space (host).
2433 *
2434 * The kernel mapping will become invalid when the MMIO2 memory is deregistered
2435 * or the VM is terminated.
2436 *
2437 * @return VBox status code.
2438 * @param pDevIns The device owning the MMIO2 memory.
2439 * @param iRegion The region.
2440 * @param off The offset into the region. Must be page
2441 * aligned.
2442 * @param cb The number of bytes to map. Must be page
2443 * aligned.
2444 * @param pszDesc Mapping description.
2445 * @param pR0Ptr Where to store the R0 address.
2446 */
2447 DECLR3CALLBACKMEMBER(int, pfnMMIO2MapKernel,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
2448 const char *pszDesc, PRTR0PTR pR0Ptr));
2449
2450 /**
2451 * Register a ROM (BIOS) region.
2452 *
2453 * It goes without saying that this is read-only memory. The memory region must be
2454 * in unassigned memory. I.e. from the top of the address space or on the PC in
2455 * the 0xa0000-0xfffff range.
2456 *
2457 * @returns VBox status.
2458 * @param pDevIns The device instance owning the ROM region.
2459 * @param GCPhysStart First physical address in the range.
2460 * Must be page aligned!
2461 * @param cbRange The size of the range (in bytes).
2462 * Must be page aligned!
2463 * @param pvBinary Pointer to the binary data backing the ROM image.
2464 * @param cbBinary The size of the binary pointer. This must
2465 * be equal or smaller than @a cbRange.
2466 * @param fFlags Shadow ROM flags, PGMPHYS_ROM_FLAGS_* in pgm.h.
2467 * @param pszDesc Pointer to description string. This must not be freed.
2468 *
2469 * @remark There is no way to remove the rom, automatically on device cleanup or
2470 * manually from the device yet. At present I doubt we need such features...
2471 */
2472 DECLR3CALLBACKMEMBER(int, pfnROMRegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
2473 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc));
2474
2475 /**
2476 * Changes the protection of shadowed ROM mapping.
2477 *
2478 * This is intented for use by the system BIOS, chipset or device in question to
2479 * change the protection of shadowed ROM code after init and on reset.
2480 *
2481 * @param pDevIns The device instance.
2482 * @param GCPhysStart Where the mapping starts.
2483 * @param cbRange The size of the mapping.
2484 * @param enmProt The new protection type.
2485 */
2486 DECLR3CALLBACKMEMBER(int, pfnROMProtectShadow,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt));
2487
2488 /**
2489 * Register a save state data unit.
2490 *
2491 * @returns VBox status.
2492 * @param pDevIns The device instance.
2493 * @param pszName Data unit name.
2494 * @param uInstance The instance identifier of the data unit.
2495 * This must together with the name be unique.
2496 * @param uVersion Data layout version number.
2497 * @param cbGuess The approximate amount of data in the unit.
2498 * Only for progress indicators.
2499 * @param pszBefore Name of data unit which we should be put in
2500 * front of. Optional (NULL).
2501 *
2502 * @param pfnLivePrep Prepare live save callback, optional.
2503 * @param pfnLiveExec Execute live save callback, optional.
2504 * @param pfnLiveVote Vote live save callback, optional.
2505 *
2506 * @param pfnSavePrep Prepare save callback, optional.
2507 * @param pfnSaveExec Execute save callback, optional.
2508 * @param pfnSaveDone Done save callback, optional.
2509 *
2510 * @param pfnLoadPrep Prepare load callback, optional.
2511 * @param pfnLoadExec Execute load callback, optional.
2512 * @param pfnLoadDone Done load callback, optional.
2513 * @remarks Caller enters the device critical section prior to invoking the
2514 * registered callback methods.
2515 */
2516 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
2517 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
2518 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
2519 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone));
2520
2521 /**
2522 * Creates a timer.
2523 *
2524 * @returns VBox status.
2525 * @param pDevIns The device instance.
2526 * @param enmClock The clock to use on this timer.
2527 * @param pfnCallback Callback function.
2528 * @param pvUser User argument for the callback.
2529 * @param fFlags Flags, see TMTIMER_FLAGS_*.
2530 * @param pszDesc Pointer to description string which must stay around
2531 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
2532 * @param ppTimer Where to store the timer on success.
2533 * @remarks Caller enters the device critical section prior to invoking the
2534 * callback.
2535 */
2536 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer));
2537
2538 /**
2539 * Get the real world UTC time adjusted for VM lag, user offset and warpdrive.
2540 *
2541 * @returns pTime.
2542 * @param pDevIns The device instance.
2543 * @param pTime Where to store the time.
2544 */
2545 DECLR3CALLBACKMEMBER(PRTTIMESPEC, pfnTMUtcNow,(PPDMDEVINS pDevIns, PRTTIMESPEC pTime));
2546
2547 /**
2548 * Read physical memory.
2549 *
2550 * @returns VINF_SUCCESS (for now).
2551 * @param pDevIns The device instance.
2552 * @param GCPhys Physical address start reading from.
2553 * @param pvBuf Where to put the read bits.
2554 * @param cbRead How many bytes to read.
2555 * @thread Any thread, but the call may involve the emulation thread.
2556 */
2557 DECLR3CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
2558
2559 /**
2560 * Write to physical memory.
2561 *
2562 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
2563 * @param pDevIns The device instance.
2564 * @param GCPhys Physical address to write to.
2565 * @param pvBuf What to write.
2566 * @param cbWrite How many bytes to write.
2567 * @thread Any thread, but the call may involve the emulation thread.
2568 */
2569 DECLR3CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
2570
2571 /**
2572 * Requests the mapping of a guest page into ring-3.
2573 *
2574 * When you're done with the page, call pfnPhysReleasePageMappingLock() ASAP to
2575 * release it.
2576 *
2577 * This API will assume your intention is to write to the page, and will
2578 * therefore replace shared and zero pages. If you do not intend to modify the
2579 * page, use the pfnPhysGCPhys2CCPtrReadOnly() API.
2580 *
2581 * @returns VBox status code.
2582 * @retval VINF_SUCCESS on success.
2583 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
2584 * backing or if the page has any active access handlers. The caller
2585 * must fall back on using PGMR3PhysWriteExternal.
2586 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
2587 *
2588 * @param pVM The VM handle.
2589 * @param GCPhys The guest physical address of the page that
2590 * should be mapped.
2591 * @param fFlags Flags reserved for future use, MBZ.
2592 * @param ppv Where to store the address corresponding to
2593 * GCPhys.
2594 * @param pLock Where to store the lock information that
2595 * pfnPhysReleasePageMappingLock needs.
2596 *
2597 * @remark Avoid calling this API from within critical sections (other than the
2598 * PGM one) because of the deadlock risk when we have to delegating the
2599 * task to an EMT.
2600 * @thread Any.
2601 */
2602 DECLR3CALLBACKMEMBER(int, pfnPhysGCPhys2CCPtr,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock));
2603
2604 /**
2605 * Requests the mapping of a guest page into ring-3, external threads.
2606 *
2607 * When you're done with the page, call pfnPhysReleasePageMappingLock() ASAP to
2608 * release it.
2609 *
2610 * @returns VBox status code.
2611 * @retval VINF_SUCCESS on success.
2612 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
2613 * backing or if the page as an active ALL access handler. The caller
2614 * must fall back on using PGMPhysRead.
2615 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
2616 *
2617 * @param pDevIns The device instance.
2618 * @param GCPhys The guest physical address of the page that
2619 * should be mapped.
2620 * @param fFlags Flags reserved for future use, MBZ.
2621 * @param ppv Where to store the address corresponding to
2622 * GCPhys.
2623 * @param pLock Where to store the lock information that
2624 * pfnPhysReleasePageMappingLock needs.
2625 *
2626 * @remark Avoid calling this API from within critical sections.
2627 * @thread Any.
2628 */
2629 DECLR3CALLBACKMEMBER(int, pfnPhysGCPhys2CCPtrReadOnly,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv, PPGMPAGEMAPLOCK pLock));
2630
2631 /**
2632 * Release the mapping of a guest page.
2633 *
2634 * This is the counter part of pfnPhysGCPhys2CCPtr and
2635 * pfnPhysGCPhys2CCPtrReadOnly.
2636 *
2637 * @param pDevIns The device instance.
2638 * @param pLock The lock structure initialized by the mapping
2639 * function.
2640 */
2641 DECLR3CALLBACKMEMBER(void, pfnPhysReleasePageMappingLock,(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock));
2642
2643 /**
2644 * Read guest physical memory by virtual address.
2645 *
2646 * @param pDevIns The device instance.
2647 * @param pvDst Where to put the read bits.
2648 * @param GCVirtSrc Guest virtual address to start reading from.
2649 * @param cb How many bytes to read.
2650 * @thread The emulation thread.
2651 */
2652 DECLR3CALLBACKMEMBER(int, pfnPhysReadGCVirt,(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb));
2653
2654 /**
2655 * Write to guest physical memory by virtual address.
2656 *
2657 * @param pDevIns The device instance.
2658 * @param GCVirtDst Guest virtual address to write to.
2659 * @param pvSrc What to write.
2660 * @param cb How many bytes to write.
2661 * @thread The emulation thread.
2662 */
2663 DECLR3CALLBACKMEMBER(int, pfnPhysWriteGCVirt,(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb));
2664
2665 /**
2666 * Convert a guest virtual address to a guest physical address.
2667 *
2668 * @returns VBox status code.
2669 * @param pDevIns The device instance.
2670 * @param GCPtr Guest virtual address.
2671 * @param pGCPhys Where to store the GC physical address
2672 * corresponding to GCPtr.
2673 * @thread The emulation thread.
2674 * @remark Careful with page boundaries.
2675 */
2676 DECLR3CALLBACKMEMBER(int, pfnPhysGCPtr2GCPhys, (PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys));
2677
2678 /**
2679 * Allocate memory which is associated with current VM instance
2680 * and automatically freed on it's destruction.
2681 *
2682 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
2683 * @param pDevIns The device instance.
2684 * @param cb Number of bytes to allocate.
2685 */
2686 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMDEVINS pDevIns, size_t cb));
2687
2688 /**
2689 * Allocate memory which is associated with current VM instance
2690 * and automatically freed on it's destruction. The memory is ZEROed.
2691 *
2692 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
2693 * @param pDevIns The device instance.
2694 * @param cb Number of bytes to allocate.
2695 */
2696 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMDEVINS pDevIns, size_t cb));
2697
2698 /**
2699 * Free memory allocated with pfnMMHeapAlloc() and pfnMMHeapAllocZ().
2700 *
2701 * @param pDevIns The device instance.
2702 * @param pv Pointer to the memory to free.
2703 */
2704 DECLR3CALLBACKMEMBER(void, pfnMMHeapFree,(PPDMDEVINS pDevIns, void *pv));
2705
2706 /**
2707 * Gets the VM state.
2708 *
2709 * @returns VM state.
2710 * @param pDevIns The device instance.
2711 * @thread Any thread (just keep in mind that it's volatile info).
2712 */
2713 DECLR3CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
2714
2715 /**
2716 * Checks if the VM was teleported and hasn't been fully resumed yet.
2717 *
2718 * @returns true / false.
2719 * @param pDevIns The device instance.
2720 * @thread Any thread.
2721 */
2722 DECLR3CALLBACKMEMBER(bool, pfnVMTeleportedAndNotFullyResumedYet,(PPDMDEVINS pDevIns));
2723
2724 /**
2725 * Set the VM error message
2726 *
2727 * @returns rc.
2728 * @param pDevIns The device instance.
2729 * @param rc VBox status code.
2730 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2731 * @param pszFormat Error message format string.
2732 * @param ... Error message arguments.
2733 */
2734 DECLR3CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
2735
2736 /**
2737 * Set the VM error message
2738 *
2739 * @returns rc.
2740 * @param pDevIns The device instance.
2741 * @param rc VBox status code.
2742 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2743 * @param pszFormat Error message format string.
2744 * @param va Error message arguments.
2745 */
2746 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
2747
2748 /**
2749 * Set the VM runtime error message
2750 *
2751 * @returns VBox status code.
2752 * @param pDevIns The device instance.
2753 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
2754 * @param pszErrorId Error ID string.
2755 * @param pszFormat Error message format string.
2756 * @param ... Error message arguments.
2757 */
2758 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
2759
2760 /**
2761 * Set the VM runtime error message
2762 *
2763 * @returns VBox status code.
2764 * @param pDevIns The device instance.
2765 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
2766 * @param pszErrorId Error ID string.
2767 * @param pszFormat Error message format string.
2768 * @param va Error message arguments.
2769 */
2770 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
2771
2772 /**
2773 * Stops the VM and enters the debugger to look at the guest state.
2774 *
2775 * Use the PDMDeviceDBGFStop() inline function with the RT_SRC_POS macro instead of
2776 * invoking this function directly.
2777 *
2778 * @returns VBox status code which must be passed up to the VMM.
2779 * @param pDevIns The device instance.
2780 * @param pszFile Filename of the assertion location.
2781 * @param iLine The linenumber of the assertion location.
2782 * @param pszFunction Function of the assertion location.
2783 * @param pszFormat Message. (optional)
2784 * @param args Message parameters.
2785 */
2786 DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list args));
2787
2788 /**
2789 * Register a info handler with DBGF,
2790 *
2791 * @returns VBox status code.
2792 * @param pDevIns The device instance.
2793 * @param pszName The identifier of the info.
2794 * @param pszDesc The description of the info and any arguments
2795 * the handler may take.
2796 * @param pfnHandler The handler function to be called to display the
2797 * info.
2798 */
2799 DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegister,(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler));
2800
2801 /**
2802 * Gets the trace buffer handle.
2803 *
2804 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
2805 * really inteded for direct usage, thus no inline wrapper function.
2806 *
2807 * @returns Trace buffer handle or NIL_RTTRACEBUF.
2808 * @param pDevIns The device instance.
2809 */
2810 DECLR3CALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
2811
2812 /**
2813 * Registers a statistics sample if statistics are enabled.
2814 *
2815 * @param pDevIns Device instance of the DMA.
2816 * @param pvSample Pointer to the sample.
2817 * @param enmType Sample type. This indicates what pvSample is
2818 * pointing at.
2819 * @param pszName Sample name. The name is on this form
2820 * "/<component>/<sample>". Further nesting is
2821 * possible.
2822 * @param enmUnit Sample unit.
2823 * @param pszDesc Sample description.
2824 */
2825 DECLR3CALLBACKMEMBER(void, pfnSTAMRegister,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc));
2826
2827 /**
2828 * Same as pfnSTAMRegister except that the name is specified in a
2829 * RTStrPrintf like fashion.
2830 *
2831 * @returns VBox status.
2832 * @param pDevIns Device instance of the DMA.
2833 * @param pvSample Pointer to the sample.
2834 * @param enmType Sample type. This indicates what pvSample is
2835 * pointing at.
2836 * @param enmVisibility Visibility type specifying whether unused
2837 * statistics should be visible or not.
2838 * @param enmUnit Sample unit.
2839 * @param pszDesc Sample description.
2840 * @param pszName The sample name format string.
2841 * @param ... Arguments to the format string.
2842 */
2843 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterF,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
2844 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...));
2845
2846 /**
2847 * Same as pfnSTAMRegister except that the name is specified in a
2848 * RTStrPrintfV like fashion.
2849 *
2850 * @returns VBox status.
2851 * @param pDevIns Device instance of the DMA.
2852 * @param pvSample Pointer to the sample.
2853 * @param enmType Sample type. This indicates what pvSample is
2854 * pointing at.
2855 * @param enmVisibility Visibility type specifying whether unused
2856 * statistics should be visible or not.
2857 * @param enmUnit Sample unit.
2858 * @param pszDesc Sample description.
2859 * @param pszName The sample name format string.
2860 * @param args Arguments to the format string.
2861 */
2862 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
2863 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args));
2864
2865 /**
2866 * Reads data via bus mastering, if enabled. If no bus mastering is available,
2867 * this function does nothing and returns VINF_PGM_PCI_PHYS_READ_BM_DISABLED.
2868 *
2869 * @return IPRT status code.
2870 */
2871 DECLR3CALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
2872
2873 /**
2874 * Writes data via bus mastering, if enabled. If no bus mastering is available,
2875 * this function does nothing and returns VINF_PGM_PCI_PHYS_WRITE_BM_DISABLED.
2876 *
2877 * @return IPRT status code.
2878 */
2879 DECLR3CALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
2880
2881 /**
2882 * Registers the device with the default PCI bus.
2883 *
2884 * @returns VBox status code.
2885 * @param pDevIns The device instance.
2886 * @param pPciDev The PCI device structure.
2887 * Any PCI enabled device must keep this in it's instance data!
2888 * Fill in the PCI data config before registration, please.
2889 * @remark This is the simple interface, a Ex interface will be created if
2890 * more features are needed later.
2891 */
2892 DECLR3CALLBACKMEMBER(int, pfnPCIRegister,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev));
2893
2894 /**
2895 * Initialize MSI support in a PCI device.
2896 *
2897 * @returns VBox status code.
2898 * @param pDevIns The device instance.
2899 * @param pMsiReg MSI registartion structure.
2900 */
2901 DECLR3CALLBACKMEMBER(int, pfnPCIRegisterMsi,(PPDMDEVINS pDevIns, PPDMMSIREG pMsiReg));
2902
2903 /**
2904 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
2905 *
2906 * @returns VBox status code.
2907 * @param pDevIns The device instance.
2908 * @param iRegion The region number.
2909 * @param cbRegion Size of the region.
2910 * @param enmType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
2911 * @param pfnCallback Callback for doing the mapping.
2912 * @remarks The callback will be invoked holding the PDM lock. The device lock
2913 * is NOT take because that is very likely be a lock order violation.
2914 */
2915 DECLR3CALLBACKMEMBER(int, pfnPCIIORegionRegister,(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion,
2916 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
2917
2918 /**
2919 * Register PCI configuration space read/write callbacks.
2920 *
2921 * @param pDevIns The device instance.
2922 * @param pPciDev The PCI device structure.
2923 * If NULL the default PCI device for this device instance is used.
2924 * @param pfnRead Pointer to the user defined PCI config read function.
2925 * @param ppfnReadOld Pointer to function pointer which will receive the old (default)
2926 * PCI config read function. This way, user can decide when (and if)
2927 * to call default PCI config read function. Can be NULL.
2928 * @param pfnWrite Pointer to the user defined PCI config write function.
2929 * @param pfnWriteOld Pointer to function pointer which will receive the old (default)
2930 * PCI config write function. This way, user can decide when (and if)
2931 * to call default PCI config write function. Can be NULL.
2932 * @remarks The callbacks will be invoked holding the PDM lock. The device lock
2933 * is NOT take because that is very likely be a lock order violation.
2934 * @thread EMT
2935 */
2936 DECLR3CALLBACKMEMBER(void, pfnPCISetConfigCallbacks,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
2937 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
2938
2939 /**
2940 * Set the IRQ for a PCI device.
2941 *
2942 * @param pDevIns The device instance.
2943 * @param iIrq IRQ number to set.
2944 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2945 * @thread Any thread, but will involve the emulation thread.
2946 */
2947 DECLR3CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2948
2949 /**
2950 * Set the IRQ for a PCI device, but don't wait for EMT to process
2951 * the request when not called from EMT.
2952 *
2953 * @param pDevIns The device instance.
2954 * @param iIrq IRQ number to set.
2955 * @param iLevel IRQ level.
2956 * @thread Any thread, but will involve the emulation thread.
2957 */
2958 DECLR3CALLBACKMEMBER(void, pfnPCISetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2959
2960 /**
2961 * Set ISA IRQ for a device.
2962 *
2963 * @param pDevIns The device instance.
2964 * @param iIrq IRQ number to set.
2965 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2966 * @thread Any thread, but will involve the emulation thread.
2967 */
2968 DECLR3CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2969
2970 /**
2971 * Set the ISA IRQ for a device, but don't wait for EMT to process
2972 * the request when not called from EMT.
2973 *
2974 * @param pDevIns The device instance.
2975 * @param iIrq IRQ number to set.
2976 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2977 * @thread Any thread, but will involve the emulation thread.
2978 */
2979 DECLR3CALLBACKMEMBER(void, pfnISASetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2980
2981 /**
2982 * Attaches a driver (chain) to the device.
2983 *
2984 * The first call for a LUN this will serve as a registartion of the LUN. The pBaseInterface and
2985 * the pszDesc string will be registered with that LUN and kept around for PDMR3QueryDeviceLun().
2986 *
2987 * @returns VBox status code.
2988 * @param pDevIns The device instance.
2989 * @param iLun The logical unit to attach.
2990 * @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
2991 * @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
2992 * @param pszDesc Pointer to a string describing the LUN. This string must remain valid
2993 * for the live of the device instance.
2994 */
2995 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface,
2996 PPDMIBASE *ppBaseInterface, const char *pszDesc));
2997
2998 /**
2999 * Create a queue.
3000 *
3001 * @returns VBox status code.
3002 * @param pDevIns The device instance.
3003 * @param cbItem The size of a queue item.
3004 * @param cItems The number of items in the queue.
3005 * @param cMilliesInterval The number of milliseconds between polling the queue.
3006 * If 0 then the emulation thread will be notified whenever an item arrives.
3007 * @param pfnCallback The consumer function.
3008 * @param fRZEnabled Set if the queue should work in RC and R0.
3009 * @param pszName The queue base name. The instance number will be
3010 * appended automatically.
3011 * @param ppQueue Where to store the queue handle on success.
3012 * @thread The emulation thread.
3013 * @remarks The device critical section will NOT be entered before calling the
3014 * callback. No locks will be held, but for now it's safe to assume
3015 * that only one EMT will do queue callbacks at any one time.
3016 */
3017 DECLR3CALLBACKMEMBER(int, pfnQueueCreate,(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
3018 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName, PPDMQUEUE *ppQueue));
3019
3020 /**
3021 * Initializes a PDM critical section.
3022 *
3023 * The PDM critical sections are derived from the IPRT critical sections, but
3024 * works in RC and R0 as well.
3025 *
3026 * @returns VBox status code.
3027 * @param pDevIns The device instance.
3028 * @param pCritSect Pointer to the critical section.
3029 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3030 * @param pszNameFmt Format string for naming the critical section.
3031 * For statistics and lock validation.
3032 * @param va Arguments for the format string.
3033 */
3034 DECLR3CALLBACKMEMBER(int, pfnCritSectInit,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
3035 const char *pszNameFmt, va_list va));
3036
3037 /**
3038 * Gets the NOP critical section.
3039 *
3040 * @returns The ring-3 address of the NOP critical section.
3041 * @param pDevIns The device instance.
3042 */
3043 DECLR3CALLBACKMEMBER(PPDMCRITSECT, pfnCritSectGetNop,(PPDMDEVINS pDevIns));
3044
3045 /**
3046 * Gets the NOP critical section.
3047 *
3048 * @returns The ring-0 address of the NOP critical section.
3049 * @param pDevIns The device instance.
3050 */
3051 DECLR3CALLBACKMEMBER(R0PTRTYPE(PPDMCRITSECT), pfnCritSectGetNopR0,(PPDMDEVINS pDevIns));
3052
3053 /**
3054 * Gets the NOP critical section.
3055 *
3056 * @returns The raw-mode context address of the NOP critical section.
3057 * @param pDevIns The device instance.
3058 */
3059 DECLR3CALLBACKMEMBER(RCPTRTYPE(PPDMCRITSECT), pfnCritSectGetNopRC,(PPDMDEVINS pDevIns));
3060
3061 /**
3062 * Changes the device level critical section from the automatically created
3063 * default to one desired by the device constructor.
3064 *
3065 * @returns VBox status code.
3066 * @param pDevIns The device instance.
3067 * @param pCritSect The critical section to use. NULL is not
3068 * valid, instead use the NOP critical
3069 * section.
3070 */
3071 DECLR3CALLBACKMEMBER(int, pfnSetDeviceCritSect,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
3072
3073 /**
3074 * Creates a PDM thread.
3075 *
3076 * This differs from the RTThreadCreate() API in that PDM takes care of suspending,
3077 * resuming, and destroying the thread as the VM state changes.
3078 *
3079 * @returns VBox status code.
3080 * @param pDevIns The device instance.
3081 * @param ppThread Where to store the thread 'handle'.
3082 * @param pvUser The user argument to the thread function.
3083 * @param pfnThread The thread function.
3084 * @param pfnWakeup The wakup callback. This is called on the EMT
3085 * thread when a state change is pending.
3086 * @param cbStack See RTThreadCreate.
3087 * @param enmType See RTThreadCreate.
3088 * @param pszName See RTThreadCreate.
3089 * @remarks The device critical section will NOT be entered prior to invoking
3090 * the function pointers.
3091 */
3092 DECLR3CALLBACKMEMBER(int, pfnThreadCreate,(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
3093 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName));
3094
3095 /**
3096 * Set up asynchronous handling of a suspend, reset or power off notification.
3097 *
3098 * This shall only be called when getting the notification. It must be called
3099 * for each one.
3100 *
3101 * @returns VBox status code.
3102 * @param pDevIns The device instance.
3103 * @param pfnAsyncNotify The callback.
3104 * @thread EMT(0)
3105 * @remarks The caller will enter the device critical section prior to invoking
3106 * the callback.
3107 */
3108 DECLR3CALLBACKMEMBER(int, pfnSetAsyncNotification, (PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify));
3109
3110 /**
3111 * Notify EMT(0) that the device has completed the asynchronous notification
3112 * handling.
3113 *
3114 * This can be called at any time, spurious calls will simply be ignored.
3115 *
3116 * @param pDevIns The device instance.
3117 * @thread Any
3118 */
3119 DECLR3CALLBACKMEMBER(void, pfnAsyncNotificationCompleted, (PPDMDEVINS pDevIns));
3120
3121 /**
3122 * Register the RTC device.
3123 *
3124 * @returns VBox status code.
3125 * @param pDevIns The device instance.
3126 * @param pRtcReg Pointer to a RTC registration structure.
3127 * @param ppRtcHlp Where to store the pointer to the helper
3128 * functions.
3129 */
3130 DECLR3CALLBACKMEMBER(int, pfnRTCRegister,(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp));
3131
3132 /**
3133 * Register the PCI Bus.
3134 *
3135 * @returns VBox status code.
3136 * @param pDevIns The device instance.
3137 * @param pPciBusReg Pointer to PCI bus registration structure.
3138 * @param ppPciHlpR3 Where to store the pointer to the PCI Bus
3139 * helpers.
3140 */
3141 DECLR3CALLBACKMEMBER(int, pfnPCIBusRegister,(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3));
3142
3143 /**
3144 * Register the PIC device.
3145 *
3146 * @returns VBox status code.
3147 * @param pDevIns The device instance.
3148 * @param pPicReg Pointer to a PIC registration structure.
3149 * @param ppPicHlpR3 Where to store the pointer to the PIC HC
3150 * helpers.
3151 */
3152 DECLR3CALLBACKMEMBER(int, pfnPICRegister,(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3));
3153
3154 /**
3155 * Register the APIC device.
3156 *
3157 * @returns VBox status code.
3158 * @param pDevIns The device instance.
3159 * @param pApicReg Pointer to a APIC registration structure.
3160 * @param ppApicHlpR3 Where to store the pointer to the APIC helpers.
3161 */
3162 DECLR3CALLBACKMEMBER(int, pfnAPICRegister,(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3));
3163
3164 /**
3165 * Register the I/O APIC device.
3166 *
3167 * @returns VBox status code.
3168 * @param pDevIns The device instance.
3169 * @param pIoApicReg Pointer to a I/O APIC registration structure.
3170 * @param ppIoApicHlpR3 Where to store the pointer to the IOAPIC
3171 * helpers.
3172 */
3173 DECLR3CALLBACKMEMBER(int, pfnIOAPICRegister,(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3));
3174
3175 /**
3176 * Register the HPET device.
3177 *
3178 * @returns VBox status code.
3179 * @param pDevIns The device instance.
3180 * @param pHpetReg Pointer to a HPET registration structure.
3181 * @param ppHpetHlpR3 Where to store the pointer to the HPET
3182 * helpers.
3183 */
3184 DECLR3CALLBACKMEMBER(int, pfnHPETRegister,(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3));
3185
3186 /**
3187 * Register a raw PCI device.
3188 *
3189 * @returns VBox status code.
3190 * @param pDevIns The device instance.
3191 * @param pHpetReg Pointer to a raw PCI registration structure.
3192 * @param ppPciRawHlpR3 Where to store the pointer to the raw PCI
3193 * device helpers.
3194 */
3195 DECLR3CALLBACKMEMBER(int, pfnPciRawRegister,(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3));
3196
3197 /**
3198 * Register the DMA device.
3199 *
3200 * @returns VBox status code.
3201 * @param pDevIns The device instance.
3202 * @param pDmacReg Pointer to a DMAC registration structure.
3203 * @param ppDmacHlp Where to store the pointer to the DMA helpers.
3204 */
3205 DECLR3CALLBACKMEMBER(int, pfnDMACRegister,(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp));
3206
3207 /**
3208 * Register transfer function for DMA channel.
3209 *
3210 * @returns VBox status code.
3211 * @param pDevIns The device instance.
3212 * @param uChannel Channel number.
3213 * @param pfnTransferHandler Device specific transfer callback function.
3214 * @param pvUser User pointer to pass to the callback.
3215 * @thread EMT
3216 */
3217 DECLR3CALLBACKMEMBER(int, pfnDMARegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
3218
3219 /**
3220 * Read memory.
3221 *
3222 * @returns VBox status code.
3223 * @param pDevIns The device instance.
3224 * @param uChannel Channel number.
3225 * @param pvBuffer Pointer to target buffer.
3226 * @param off DMA position.
3227 * @param cbBlock Block size.
3228 * @param pcbRead Where to store the number of bytes which was
3229 * read. optional.
3230 * @thread EMT
3231 */
3232 DECLR3CALLBACKMEMBER(int, pfnDMAReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead));
3233
3234 /**
3235 * Write memory.
3236 *
3237 * @returns VBox status code.
3238 * @param pDevIns The device instance.
3239 * @param uChannel Channel number.
3240 * @param pvBuffer Memory to write.
3241 * @param off DMA position.
3242 * @param cbBlock Block size.
3243 * @param pcbWritten Where to store the number of bytes which was
3244 * written. optional.
3245 * @thread EMT
3246 */
3247 DECLR3CALLBACKMEMBER(int, pfnDMAWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten));
3248
3249 /**
3250 * Set the DREQ line.
3251 *
3252 * @returns VBox status code.
3253 * @param pDevIns Device instance.
3254 * @param uChannel Channel number.
3255 * @param uLevel Level of the line.
3256 * @thread EMT
3257 */
3258 DECLR3CALLBACKMEMBER(int, pfnDMASetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
3259
3260 /**
3261 * Get channel mode.
3262 *
3263 * @returns Channel mode. See specs.
3264 * @param pDevIns The device instance.
3265 * @param uChannel Channel number.
3266 * @thread EMT
3267 */
3268 DECLR3CALLBACKMEMBER(uint8_t, pfnDMAGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
3269
3270 /**
3271 * Schedule DMA execution.
3272 *
3273 * @param pDevIns The device instance.
3274 * @thread Any thread.
3275 */
3276 DECLR3CALLBACKMEMBER(void, pfnDMASchedule,(PPDMDEVINS pDevIns));
3277
3278 /**
3279 * Write CMOS value and update the checksum(s).
3280 *
3281 * @returns VBox status code.
3282 * @param pDevIns The device instance.
3283 * @param iReg The CMOS register index.
3284 * @param u8Value The CMOS register value.
3285 * @thread EMT
3286 */
3287 DECLR3CALLBACKMEMBER(int, pfnCMOSWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
3288
3289 /**
3290 * Read CMOS value.
3291 *
3292 * @returns VBox status code.
3293 * @param pDevIns The device instance.
3294 * @param iReg The CMOS register index.
3295 * @param pu8Value Where to store the CMOS register value.
3296 * @thread EMT
3297 */
3298 DECLR3CALLBACKMEMBER(int, pfnCMOSRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
3299
3300 /**
3301 * Assert that the current thread is the emulation thread.
3302 *
3303 * @returns True if correct.
3304 * @returns False if wrong.
3305 * @param pDevIns The device instance.
3306 * @param pszFile Filename of the assertion location.
3307 * @param iLine The linenumber of the assertion location.
3308 * @param pszFunction Function of the assertion location.
3309 */
3310 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
3311
3312 /**
3313 * Assert that the current thread is NOT the emulation thread.
3314 *
3315 * @returns True if correct.
3316 * @returns False if wrong.
3317 * @param pDevIns The device instance.
3318 * @param pszFile Filename of the assertion location.
3319 * @param iLine The linenumber of the assertion location.
3320 * @param pszFunction Function of the assertion location.
3321 */
3322 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
3323
3324 /**
3325 * Resolves the symbol for a raw-mode context interface.
3326 *
3327 * @returns VBox status code.
3328 * @param pDevIns The device instance.
3329 * @param pvInterface The interface structure.
3330 * @param cbInterface The size of the interface structure.
3331 * @param pszSymPrefix What to prefix the symbols in the list with
3332 * before resolving them. This must start with
3333 * 'dev' and contain the driver name.
3334 * @param pszSymList List of symbols corresponding to the interface.
3335 * There is generally a there is generally a define
3336 * holding this list associated with the interface
3337 * definition (INTERFACE_SYM_LIST). For more
3338 * details see PDMR3LdrGetInterfaceSymbols.
3339 * @thread EMT
3340 */
3341 DECLR3CALLBACKMEMBER(int, pfnLdrGetRCInterfaceSymbols,(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
3342 const char *pszSymPrefix, const char *pszSymList));
3343
3344 /**
3345 * Resolves the symbol for a ring-0 context interface.
3346 *
3347 * @returns VBox status code.
3348 * @param pDevIns The device instance.
3349 * @param pvInterface The interface structure.
3350 * @param cbInterface The size of the interface structure.
3351 * @param pszSymPrefix What to prefix the symbols in the list with
3352 * before resolving them. This must start with
3353 * 'dev' and contain the driver name.
3354 * @param pszSymList List of symbols corresponding to the interface.
3355 * There is generally a there is generally a define
3356 * holding this list associated with the interface
3357 * definition (INTERFACE_SYM_LIST). For more
3358 * details see PDMR3LdrGetInterfaceSymbols.
3359 * @thread EMT
3360 */
3361 DECLR3CALLBACKMEMBER(int, pfnLdrGetR0InterfaceSymbols,(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
3362 const char *pszSymPrefix, const char *pszSymList));
3363
3364 /**
3365 * Call the ring-0 request handler routine of the device.
3366 *
3367 * For this to work, the device must be ring-0 enabled and export a request
3368 * handler function. The name of the function must be the device name in
3369 * the PDMDRVREG struct prefixed with 'drvR0' and suffixed with
3370 * 'ReqHandler'. The device name will be captialized. It shall take the
3371 * exact same arguments as this function and be declared using
3372 * PDMBOTHCBDECL. See FNPDMDEVREQHANDLERR0.
3373 *
3374 * Unlike PDMDrvHlpCallR0, this is current unsuitable for more than a call
3375 * or two as the handler address will be resolved on each invocation. This
3376 * is the reason for the EMT only restriction as well.
3377 *
3378 * @returns VBox status code.
3379 * @retval VERR_SYMBOL_NOT_FOUND if the device doesn't export the required
3380 * handler function.
3381 * @retval VERR_ACCESS_DENIED if the device isn't ring-0 capable.
3382 *
3383 * @param pDevIns The device instance.
3384 * @param uOperation The operation to perform.
3385 * @param u64Arg 64-bit integer argument.
3386 * @thread EMT
3387 */
3388 DECLR3CALLBACKMEMBER(int, pfnCallR0,(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg));
3389
3390 /** Space reserved for future members.
3391 * @{ */
3392 DECLR3CALLBACKMEMBER(void, pfnReserved1,(void));
3393 DECLR3CALLBACKMEMBER(void, pfnReserved2,(void));
3394 DECLR3CALLBACKMEMBER(void, pfnReserved3,(void));
3395 DECLR3CALLBACKMEMBER(void, pfnReserved4,(void));
3396 DECLR3CALLBACKMEMBER(void, pfnReserved5,(void));
3397 DECLR3CALLBACKMEMBER(void, pfnReserved6,(void));
3398 DECLR3CALLBACKMEMBER(void, pfnReserved7,(void));
3399 DECLR3CALLBACKMEMBER(void, pfnReserved8,(void));
3400 DECLR3CALLBACKMEMBER(void, pfnReserved9,(void));
3401 /*DECLR3CALLBACKMEMBER(void, pfnReserved10,(void));*/
3402 /** @} */
3403
3404
3405 /** API available to trusted devices only.
3406 *
3407 * These APIs are providing unrestricted access to the guest and the VM,
3408 * or they are interacting intimately with PDM.
3409 *
3410 * @{
3411 */
3412
3413 /**
3414 * Gets the user mode VM handle. Restricted API.
3415 *
3416 * @returns User mode VM Handle.
3417 * @param pDevIns The device instance.
3418 */
3419 DECLR3CALLBACKMEMBER(PUVM, pfnGetUVM,(PPDMDEVINS pDevIns));
3420
3421 /**
3422 * Gets the global VM handle. Restricted API.
3423 *
3424 * @returns VM Handle.
3425 * @param pDevIns The device instance.
3426 */
3427 DECLR3CALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
3428
3429 /**
3430 * Gets the VMCPU handle. Restricted API.
3431 *
3432 * @returns VMCPU Handle.
3433 * @param pDevIns The device instance.
3434 */
3435 DECLR3CALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
3436
3437 /**
3438 * Registers the VMM device heap
3439 *
3440 * @returns VBox status code.
3441 * @param pDevIns The device instance.
3442 * @param GCPhys The physical address.
3443 * @param pvHeap Ring 3 heap pointer.
3444 * @param cbSize Size of the heap.
3445 * @thread EMT.
3446 */
3447 DECLR3CALLBACKMEMBER(int, pfnRegisterVMMDevHeap,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize));
3448
3449 /**
3450 * Unregisters the VMM device heap
3451 *
3452 * @returns VBox status code.
3453 * @param pDevIns The device instance.
3454 * @param GCPhys The physical address.
3455 * @thread EMT.
3456 */
3457 DECLR3CALLBACKMEMBER(int, pfnUnregisterVMMDevHeap,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys));
3458
3459 /**
3460 * Resets the VM.
3461 *
3462 * @returns The appropriate VBox status code to pass around on reset.
3463 * @param pDevIns The device instance.
3464 * @thread The emulation thread.
3465 */
3466 DECLR3CALLBACKMEMBER(int, pfnVMReset,(PPDMDEVINS pDevIns));
3467
3468 /**
3469 * Suspends the VM.
3470 *
3471 * @returns The appropriate VBox status code to pass around on suspend.
3472 * @param pDevIns The device instance.
3473 * @thread The emulation thread.
3474 */
3475 DECLR3CALLBACKMEMBER(int, pfnVMSuspend,(PPDMDEVINS pDevIns));
3476
3477 /**
3478 * Suspends, saves and powers off the VM.
3479 *
3480 * @returns The appropriate VBox status code to pass around.
3481 * @param pDevIns The device instance.
3482 * @thread An emulation thread.
3483 */
3484 DECLR3CALLBACKMEMBER(int, pfnVMSuspendSaveAndPowerOff,(PPDMDEVINS pDevIns));
3485
3486 /**
3487 * Power off the VM.
3488 *
3489 * @returns The appropriate VBox status code to pass around on power off.
3490 * @param pDevIns The device instance.
3491 * @thread The emulation thread.
3492 */
3493 DECLR3CALLBACKMEMBER(int, pfnVMPowerOff,(PPDMDEVINS pDevIns));
3494
3495 /**
3496 * Checks if the Gate A20 is enabled or not.
3497 *
3498 * @returns true if A20 is enabled.
3499 * @returns false if A20 is disabled.
3500 * @param pDevIns The device instance.
3501 * @thread The emulation thread.
3502 */
3503 DECLR3CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
3504
3505 /**
3506 * Enables or disables the Gate A20.
3507 *
3508 * @param pDevIns The device instance.
3509 * @param fEnable Set this flag to enable the Gate A20; clear it
3510 * to disable.
3511 * @thread The emulation thread.
3512 */
3513 DECLR3CALLBACKMEMBER(void, pfnA20Set,(PPDMDEVINS pDevIns, bool fEnable));
3514
3515 /**
3516 * Get the specified CPUID leaf for the virtual CPU associated with the calling
3517 * thread.
3518 *
3519 * @param pDevIns The device instance.
3520 * @param iLeaf The CPUID leaf to get.
3521 * @param pEax Where to store the EAX value.
3522 * @param pEbx Where to store the EBX value.
3523 * @param pEcx Where to store the ECX value.
3524 * @param pEdx Where to store the EDX value.
3525 * @thread EMT.
3526 */
3527 DECLR3CALLBACKMEMBER(void, pfnGetCpuId,(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx));
3528
3529 /**
3530 * Get the current virtual clock time in a VM. The clock frequency must be
3531 * queried separately.
3532 *
3533 * @returns Current clock time.
3534 * @param pDevIns The device instance.
3535 */
3536 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
3537
3538 /**
3539 * Get the frequency of the virtual clock.
3540 *
3541 * @returns The clock frequency (not variable at run-time).
3542 * @param pDevIns The device instance.
3543 */
3544 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
3545
3546 /**
3547 * Get the current virtual clock time in a VM, in nanoseconds.
3548 *
3549 * @returns Current clock time (in ns).
3550 * @param pDevIns The device instance.
3551 */
3552 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
3553
3554 /** @} */
3555
3556 /** Just a safety precaution. (PDM_DEVHLPR3_VERSION) */
3557 uint32_t u32TheEnd;
3558} PDMDEVHLPR3;
3559#endif /* !IN_RING3 */
3560/** Pointer to the R3 PDM Device API. */
3561typedef R3PTRTYPE(struct PDMDEVHLPR3 *) PPDMDEVHLPR3;
3562/** Pointer to the R3 PDM Device API, const variant. */
3563typedef R3PTRTYPE(const struct PDMDEVHLPR3 *) PCPDMDEVHLPR3;
3564
3565/** Current PDMDEVHLPR3 version number. */
3566#define PDM_DEVHLPR3_VERSION PDM_VERSION_MAKE(0xffe7, 9, 0)
3567
3568
3569/**
3570 * PDM Device API - RC Variant.
3571 */
3572typedef struct PDMDEVHLPRC
3573{
3574 /** Structure version. PDM_DEVHLPRC_VERSION defines the current version. */
3575 uint32_t u32Version;
3576
3577 /**
3578 * Reads data via bus mastering, if enabled. If no bus mastering is available,
3579 * this function does nothing and returns VINF_PGM_PCI_PHYS_READ_BM_DISABLED.
3580 *
3581 * @return IPRT status code.
3582 */
3583 DECLRCCALLBACKMEMBER(int, pfnPCIDevPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3584
3585 /**
3586 * Writes data via bus mastering, if enabled. If no bus mastering is available,
3587 * this function does nothing and returns VINF_PGM_PCI_PHYS_WRITE_BM_DISABLED.
3588 *
3589 * @return IPRT status code.
3590 */
3591 DECLRCCALLBACKMEMBER(int, pfnPCIDevPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3592
3593 /**
3594 * Set the IRQ for a PCI device.
3595 *
3596 * @param pDevIns Device instance.
3597 * @param iIrq IRQ number to set.
3598 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3599 * @thread Any thread, but will involve the emulation thread.
3600 */
3601 DECLRCCALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3602
3603 /**
3604 * Set ISA IRQ for a device.
3605 *
3606 * @param pDevIns Device instance.
3607 * @param iIrq IRQ number to set.
3608 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3609 * @thread Any thread, but will involve the emulation thread.
3610 */
3611 DECLRCCALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3612
3613 /**
3614 * Read physical memory.
3615 *
3616 * @returns VINF_SUCCESS (for now).
3617 * @param pDevIns Device instance.
3618 * @param GCPhys Physical address start reading from.
3619 * @param pvBuf Where to put the read bits.
3620 * @param cbRead How many bytes to read.
3621 */
3622 DECLRCCALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3623
3624 /**
3625 * Write to physical memory.
3626 *
3627 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
3628 * @param pDevIns Device instance.
3629 * @param GCPhys Physical address to write to.
3630 * @param pvBuf What to write.
3631 * @param cbWrite How many bytes to write.
3632 */
3633 DECLRCCALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3634
3635 /**
3636 * Checks if the Gate A20 is enabled or not.
3637 *
3638 * @returns true if A20 is enabled.
3639 * @returns false if A20 is disabled.
3640 * @param pDevIns Device instance.
3641 * @thread The emulation thread.
3642 */
3643 DECLRCCALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
3644
3645 /**
3646 * Gets the VM state.
3647 *
3648 * @returns VM state.
3649 * @param pDevIns The device instance.
3650 * @thread Any thread (just keep in mind that it's volatile info).
3651 */
3652 DECLRCCALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
3653
3654 /**
3655 * Set the VM error message
3656 *
3657 * @returns rc.
3658 * @param pDrvIns Driver instance.
3659 * @param rc VBox status code.
3660 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3661 * @param pszFormat Error message format string.
3662 * @param ... Error message arguments.
3663 */
3664 DECLRCCALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
3665
3666 /**
3667 * Set the VM error message
3668 *
3669 * @returns rc.
3670 * @param pDrvIns Driver instance.
3671 * @param rc VBox status code.
3672 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3673 * @param pszFormat Error message format string.
3674 * @param va Error message arguments.
3675 */
3676 DECLRCCALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
3677
3678 /**
3679 * Set the VM runtime error message
3680 *
3681 * @returns VBox status code.
3682 * @param pDevIns Device instance.
3683 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3684 * @param pszErrorId Error ID string.
3685 * @param pszFormat Error message format string.
3686 * @param ... Error message arguments.
3687 */
3688 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
3689
3690 /**
3691 * Set the VM runtime error message
3692 *
3693 * @returns VBox status code.
3694 * @param pDevIns Device instance.
3695 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3696 * @param pszErrorId Error ID string.
3697 * @param pszFormat Error message format string.
3698 * @param va Error message arguments.
3699 */
3700 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
3701
3702 /**
3703 * Set parameters for pending MMIO patch operation
3704 *
3705 * @returns VBox status code.
3706 * @param pDevIns Device instance.
3707 * @param GCPhys MMIO physical address
3708 * @param pCachedData GC pointer to cached data
3709 */
3710 DECLRCCALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
3711
3712 /**
3713 * Gets the VM handle. Restricted API.
3714 *
3715 * @returns VM Handle.
3716 * @param pDevIns Device instance.
3717 */
3718 DECLRCCALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
3719
3720 /**
3721 * Gets the VMCPU handle. Restricted API.
3722 *
3723 * @returns VMCPU Handle.
3724 * @param pDevIns The device instance.
3725 */
3726 DECLRCCALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
3727
3728 /**
3729 * Get the current virtual clock time in a VM. The clock frequency must be
3730 * queried separately.
3731 *
3732 * @returns Current clock time.
3733 * @param pDevIns The device instance.
3734 */
3735 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
3736
3737 /**
3738 * Get the frequency of the virtual clock.
3739 *
3740 * @returns The clock frequency (not variable at run-time).
3741 * @param pDevIns The device instance.
3742 */
3743 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
3744
3745 /**
3746 * Get the current virtual clock time in a VM, in nanoseconds.
3747 *
3748 * @returns Current clock time (in ns).
3749 * @param pDevIns The device instance.
3750 */
3751 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
3752
3753 /**
3754 * Gets the trace buffer handle.
3755 *
3756 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
3757 * really inteded for direct usage, thus no inline wrapper function.
3758 *
3759 * @returns Trace buffer handle or NIL_RTTRACEBUF.
3760 * @param pDevIns The device instance.
3761 */
3762 DECLRCCALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
3763
3764 /** Just a safety precaution. */
3765 uint32_t u32TheEnd;
3766} PDMDEVHLPRC;
3767/** Pointer PDM Device RC API. */
3768typedef RCPTRTYPE(struct PDMDEVHLPRC *) PPDMDEVHLPRC;
3769/** Pointer PDM Device RC API. */
3770typedef RCPTRTYPE(const struct PDMDEVHLPRC *) PCPDMDEVHLPRC;
3771
3772/** Current PDMDEVHLP version number. */
3773#define PDM_DEVHLPRC_VERSION PDM_VERSION_MAKE(0xffe6, 3, 0)
3774
3775
3776/**
3777 * PDM Device API - R0 Variant.
3778 */
3779typedef struct PDMDEVHLPR0
3780{
3781 /** Structure version. PDM_DEVHLPR0_VERSION defines the current version. */
3782 uint32_t u32Version;
3783
3784 /**
3785 * Reads data via bus mastering, if enabled. If no bus mastering is available,
3786 * this function does nothing and returns VINF_PGM_PCI_PHYS_READ_BM_DISABLED.
3787 *
3788 * @return IPRT status code.
3789 */
3790 DECLR0CALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3791
3792 /**
3793 * Writes data via bus mastering, if enabled. If no bus mastering is available,
3794 * this function does nothing and returns VINF_PGM_PCI_PHYS_WRITE_BM_DISABLED.
3795 *
3796 * @return IPRT status code.
3797 */
3798 DECLR0CALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3799
3800 /**
3801 * Set the IRQ for a PCI device.
3802 *
3803 * @param pDevIns Device instance.
3804 * @param iIrq IRQ number to set.
3805 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3806 * @thread Any thread, but will involve the emulation thread.
3807 */
3808 DECLR0CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3809
3810 /**
3811 * Set ISA IRQ for a device.
3812 *
3813 * @param pDevIns Device instance.
3814 * @param iIrq IRQ number to set.
3815 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3816 * @thread Any thread, but will involve the emulation thread.
3817 */
3818 DECLR0CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3819
3820 /**
3821 * Read physical memory.
3822 *
3823 * @returns VINF_SUCCESS (for now).
3824 * @param pDevIns Device instance.
3825 * @param GCPhys Physical address start reading from.
3826 * @param pvBuf Where to put the read bits.
3827 * @param cbRead How many bytes to read.
3828 */
3829 DECLR0CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3830
3831 /**
3832 * Write to physical memory.
3833 *
3834 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
3835 * @param pDevIns Device instance.
3836 * @param GCPhys Physical address to write to.
3837 * @param pvBuf What to write.
3838 * @param cbWrite How many bytes to write.
3839 */
3840 DECLR0CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3841
3842 /**
3843 * Checks if the Gate A20 is enabled or not.
3844 *
3845 * @returns true if A20 is enabled.
3846 * @returns false if A20 is disabled.
3847 * @param pDevIns Device instance.
3848 * @thread The emulation thread.
3849 */
3850 DECLR0CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
3851
3852 /**
3853 * Gets the VM state.
3854 *
3855 * @returns VM state.
3856 * @param pDevIns The device instance.
3857 * @thread Any thread (just keep in mind that it's volatile info).
3858 */
3859 DECLR0CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
3860
3861 /**
3862 * Set the VM error message
3863 *
3864 * @returns rc.
3865 * @param pDrvIns Driver instance.
3866 * @param rc VBox status code.
3867 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3868 * @param pszFormat Error message format string.
3869 * @param ... Error message arguments.
3870 */
3871 DECLR0CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
3872
3873 /**
3874 * Set the VM error message
3875 *
3876 * @returns rc.
3877 * @param pDrvIns Driver instance.
3878 * @param rc VBox status code.
3879 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3880 * @param pszFormat Error message format string.
3881 * @param va Error message arguments.
3882 */
3883 DECLR0CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
3884
3885 /**
3886 * Set the VM runtime error message
3887 *
3888 * @returns VBox status code.
3889 * @param pDevIns Device instance.
3890 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3891 * @param pszErrorId Error ID string.
3892 * @param pszFormat Error message format string.
3893 * @param ... Error message arguments.
3894 */
3895 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
3896
3897 /**
3898 * Set the VM runtime error message
3899 *
3900 * @returns VBox status code.
3901 * @param pDevIns Device instance.
3902 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3903 * @param pszErrorId Error ID string.
3904 * @param pszFormat Error message format string.
3905 * @param va Error message arguments.
3906 */
3907 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
3908
3909 /**
3910 * Set parameters for pending MMIO patch operation
3911 *
3912 * @returns rc.
3913 * @param pDevIns Device instance.
3914 * @param GCPhys MMIO physical address
3915 * @param pCachedData GC pointer to cached data
3916 */
3917 DECLR0CALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
3918
3919 /**
3920 * Gets the VM handle. Restricted API.
3921 *
3922 * @returns VM Handle.
3923 * @param pDevIns Device instance.
3924 */
3925 DECLR0CALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
3926
3927 /**
3928 * Checks if our current CPU state allows for IO block emulation fallback to the recompiler
3929 *
3930 * @returns true = yes, false = no
3931 * @param pDevIns Device instance.
3932 */
3933 DECLR0CALLBACKMEMBER(bool, pfnCanEmulateIoBlock,(PPDMDEVINS pDevIns));
3934
3935 /**
3936 * Gets the VMCPU handle. Restricted API.
3937 *
3938 * @returns VMCPU Handle.
3939 * @param pDevIns The device instance.
3940 */
3941 DECLR0CALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
3942
3943 /**
3944 * Get the current virtual clock time in a VM. The clock frequency must be
3945 * queried separately.
3946 *
3947 * @returns Current clock time.
3948 * @param pDevIns The device instance.
3949 */
3950 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
3951
3952 /**
3953 * Get the frequency of the virtual clock.
3954 *
3955 * @returns The clock frequency (not variable at run-time).
3956 * @param pDevIns The device instance.
3957 */
3958 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
3959
3960 /**
3961 * Get the current virtual clock time in a VM, in nanoseconds.
3962 *
3963 * @returns Current clock time (in ns).
3964 * @param pDevIns The device instance.
3965 */
3966 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
3967
3968 /**
3969 * Gets the trace buffer handle.
3970 *
3971 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
3972 * really inteded for direct usage, thus no inline wrapper function.
3973 *
3974 * @returns Trace buffer handle or NIL_RTTRACEBUF.
3975 * @param pDevIns The device instance.
3976 */
3977 DECLR0CALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
3978
3979 /** Just a safety precaution. */
3980 uint32_t u32TheEnd;
3981} PDMDEVHLPR0;
3982/** Pointer PDM Device R0 API. */
3983typedef R0PTRTYPE(struct PDMDEVHLPR0 *) PPDMDEVHLPR0;
3984/** Pointer PDM Device GC API. */
3985typedef R0PTRTYPE(const struct PDMDEVHLPR0 *) PCPDMDEVHLPR0;
3986
3987/** Current PDMDEVHLP version number. */
3988#define PDM_DEVHLPR0_VERSION PDM_VERSION_MAKE(0xffe5, 3, 0)
3989
3990
3991
3992/**
3993 * PDM Device Instance.
3994 */
3995typedef struct PDMDEVINS
3996{
3997 /** Structure version. PDM_DEVINS_VERSION defines the current version. */
3998 uint32_t u32Version;
3999 /** Device instance number. */
4000 uint32_t iInstance;
4001
4002 /** Pointer the GC PDM Device API. */
4003 PCPDMDEVHLPRC pHlpRC;
4004 /** Pointer to device instance data. */
4005 RTRCPTR pvInstanceDataRC;
4006 /** The critical section for the device, see pCritSectXR3. */
4007 RCPTRTYPE(PPDMCRITSECT) pCritSectRoRC;
4008 /** Alignment padding. */
4009 RTRCPTR pAlignmentRC;
4010
4011 /** Pointer the R0 PDM Device API. */
4012 PCPDMDEVHLPR0 pHlpR0;
4013 /** Pointer to device instance data (R0). */
4014 RTR0PTR pvInstanceDataR0;
4015 /** The critical section for the device, see pCritSectXR3. */
4016 R0PTRTYPE(PPDMCRITSECT) pCritSectRoR0;
4017
4018 /** Pointer the HC PDM Device API. */
4019 PCPDMDEVHLPR3 pHlpR3;
4020 /** Pointer to device instance data. */
4021 RTR3PTR pvInstanceDataR3;
4022 /** The critical section for the device.
4023 *
4024 * TM and IOM will enter this critical section before calling into the device
4025 * code. PDM will when doing power on, power off, reset, suspend and resume
4026 * notifications. SSM will currently not, but this will be changed later on.
4027 *
4028 * The device gets a critical section automatically assigned to it before
4029 * the constructor is called. If the constructor wishes to use a different
4030 * critical section, it calls PDMDevHlpSetDeviceCritSect() to change it
4031 * very early on.
4032 */
4033 R3PTRTYPE(PPDMCRITSECT) pCritSectRoR3;
4034
4035 /** Pointer to device registration structure. */
4036 R3PTRTYPE(PCPDMDEVREG) pReg;
4037 /** Configuration handle. */
4038 R3PTRTYPE(PCFGMNODE) pCfg;
4039
4040 /** The base interface of the device.
4041 *
4042 * The device constructor initializes this if it has any
4043 * device level interfaces to export. To obtain this interface
4044 * call PDMR3QueryDevice(). */
4045 PDMIBASE IBase;
4046
4047 /** Tracing indicator. */
4048 uint32_t fTracing;
4049 /** The tracing ID of this device. */
4050 uint32_t idTracing;
4051#if HC_ARCH_BITS == 32
4052 /** Align the internal data more naturally. */
4053 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 13 : 0];
4054#endif
4055
4056 /** Internal data. */
4057 union
4058 {
4059#ifdef PDMDEVINSINT_DECLARED
4060 PDMDEVINSINT s;
4061#endif
4062 uint8_t padding[HC_ARCH_BITS == 32 ? 72 : 112 + 0x28];
4063 } Internal;
4064
4065 /** Device instance data. The size of this area is defined
4066 * in the PDMDEVREG::cbInstanceData field. */
4067 char achInstanceData[8];
4068} PDMDEVINS;
4069
4070/** Current PDMDEVINS version number. */
4071#define PDM_DEVINS_VERSION PDM_VERSION_MAKE(0xffe4, 3, 0)
4072
4073/** Converts a pointer to the PDMDEVINS::IBase to a pointer to PDMDEVINS. */
4074#define PDMIBASE_2_PDMDEV(pInterface) ( (PPDMDEVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDEVINS, IBase)) )
4075
4076/**
4077 * Checks the structure versions of the device instance and device helpers,
4078 * returning if they are incompatible.
4079 *
4080 * This is for use in the constructor.
4081 *
4082 * @param pDevIns The device instance pointer.
4083 */
4084#define PDMDEV_CHECK_VERSIONS_RETURN(pDevIns) \
4085 do \
4086 { \
4087 PPDMDEVINS pDevInsTypeCheck = (pDevIns); NOREF(pDevInsTypeCheck); \
4088 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->u32Version, PDM_DEVINS_VERSION), \
4089 ("DevIns=%#x mine=%#x\n", (pDevIns)->u32Version, PDM_DEVINS_VERSION), \
4090 VERR_PDM_DEVINS_VERSION_MISMATCH); \
4091 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION), \
4092 ("DevHlp=%#x mine=%#x\n", (pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION), \
4093 VERR_PDM_DEVHLPR3_VERSION_MISMATCH); \
4094 } while (0)
4095
4096/**
4097 * Quietly checks the structure versions of the device instance and device
4098 * helpers, returning if they are incompatible.
4099 *
4100 * This is for use in the destructor.
4101 *
4102 * @param pDevIns The device instance pointer.
4103 */
4104#define PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns) \
4105 do \
4106 { \
4107 PPDMDEVINS pDevInsTypeCheck = (pDevIns); NOREF(pDevInsTypeCheck); \
4108 if (RT_UNLIKELY(!PDM_VERSION_ARE_COMPATIBLE((pDevIns)->u32Version, PDM_DEVINS_VERSION) )) \
4109 return VERR_PDM_DEVINS_VERSION_MISMATCH; \
4110 if (RT_UNLIKELY(!PDM_VERSION_ARE_COMPATIBLE((pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION) )) \
4111 return VERR_PDM_DEVHLPR3_VERSION_MISMATCH; \
4112 } while (0)
4113
4114/**
4115 * Wrapper around CFGMR3ValidateConfig for the root config for use in the
4116 * constructor - returns on failure.
4117 *
4118 * This should be invoked after having initialized the instance data
4119 * sufficiently for the correct operation of the destructor. The destructor is
4120 * always called!
4121 *
4122 * @param pDevIns Pointer to the PDM device instance.
4123 * @param pszValidValues Patterns describing the valid value names. See
4124 * RTStrSimplePatternMultiMatch for details on the
4125 * pattern syntax.
4126 * @param pszValidNodes Patterns describing the valid node (key) names.
4127 * Pass empty string if no valid nodes.
4128 */
4129#define PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, pszValidValues, pszValidNodes) \
4130 do \
4131 { \
4132 int rcValCfg = CFGMR3ValidateConfig((pDevIns)->pCfg, "/", pszValidValues, pszValidNodes, \
4133 (pDevIns)->pReg->szName, (pDevIns)->iInstance); \
4134 if (RT_FAILURE(rcValCfg)) \
4135 return rcValCfg; \
4136 } while (0)
4137
4138/** @def PDMDEV_ASSERT_EMT
4139 * Assert that the current thread is the emulation thread.
4140 */
4141#ifdef VBOX_STRICT
4142# define PDMDEV_ASSERT_EMT(pDevIns) pDevIns->pHlpR3->pfnAssertEMT(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4143#else
4144# define PDMDEV_ASSERT_EMT(pDevIns) do { } while (0)
4145#endif
4146
4147/** @def PDMDEV_ASSERT_OTHER
4148 * Assert that the current thread is NOT the emulation thread.
4149 */
4150#ifdef VBOX_STRICT
4151# define PDMDEV_ASSERT_OTHER(pDevIns) pDevIns->pHlpR3->pfnAssertOther(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4152#else
4153# define PDMDEV_ASSERT_OTHER(pDevIns) do { } while (0)
4154#endif
4155
4156/** @def PDMDEV_ASSERT_VMLOCK_OWNER
4157 * Assert that the current thread is owner of the VM lock.
4158 */
4159#ifdef VBOX_STRICT
4160# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) pDevIns->pHlpR3->pfnAssertVMLock(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4161#else
4162# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) do { } while (0)
4163#endif
4164
4165/** @def PDMDEV_SET_ERROR
4166 * Set the VM error. See PDMDevHlpVMSetError() for printf like message formatting.
4167 */
4168#define PDMDEV_SET_ERROR(pDevIns, rc, pszError) \
4169 PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, "%s", pszError)
4170
4171/** @def PDMDEV_SET_RUNTIME_ERROR
4172 * Set the VM runtime error. See PDMDevHlpVMSetRuntimeError() for printf like message formatting.
4173 */
4174#define PDMDEV_SET_RUNTIME_ERROR(pDevIns, fFlags, pszErrorId, pszError) \
4175 PDMDevHlpVMSetRuntimeError(pDevIns, fFlags, pszErrorId, "%s", pszError)
4176
4177/** @def PDMDEVINS_2_RCPTR
4178 * Converts a PDM Device instance pointer a RC PDM Device instance pointer.
4179 */
4180#define PDMDEVINS_2_RCPTR(pDevIns) ( (RCPTRTYPE(PPDMDEVINS))((RTGCUINTPTR)(pDevIns)->pvInstanceDataRC - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4181
4182/** @def PDMDEVINS_2_R3PTR
4183 * Converts a PDM Device instance pointer a R3 PDM Device instance pointer.
4184 */
4185#define PDMDEVINS_2_R3PTR(pDevIns) ( (R3PTRTYPE(PPDMDEVINS))((RTHCUINTPTR)(pDevIns)->pvInstanceDataR3 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4186
4187/** @def PDMDEVINS_2_R0PTR
4188 * Converts a PDM Device instance pointer a R0 PDM Device instance pointer.
4189 */
4190#define PDMDEVINS_2_R0PTR(pDevIns) ( (R0PTRTYPE(PPDMDEVINS))((RTR0UINTPTR)(pDevIns)->pvInstanceDataR0 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4191
4192
4193#ifdef IN_RING3
4194
4195/**
4196 * @copydoc PDMDEVHLPR3::pfnIOPortRegister
4197 */
4198DECLINLINE(int) PDMDevHlpIOPortRegister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser,
4199 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
4200 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc)
4201{
4202 return pDevIns->pHlpR3->pfnIOPortRegister(pDevIns, Port, cPorts, pvUser, pfnOut, pfnIn, pfnOutStr, pfnInStr, pszDesc);
4203}
4204
4205/**
4206 * @copydoc PDMDEVHLPR3::pfnIOPortRegisterRC
4207 */
4208DECLINLINE(int) PDMDevHlpIOPortRegisterRC(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
4209 const char *pszOut, const char *pszIn, const char *pszOutStr,
4210 const char *pszInStr, const char *pszDesc)
4211{
4212 return pDevIns->pHlpR3->pfnIOPortRegisterRC(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
4213}
4214
4215/**
4216 * @copydoc PDMDEVHLPR3::pfnIOPortRegisterR0
4217 */
4218DECLINLINE(int) PDMDevHlpIOPortRegisterR0(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
4219 const char *pszOut, const char *pszIn, const char *pszOutStr,
4220 const char *pszInStr, const char *pszDesc)
4221{
4222 return pDevIns->pHlpR3->pfnIOPortRegisterR0(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
4223}
4224
4225/**
4226 * @copydoc PDMDEVHLPR3::pfnIOPortDeregister
4227 */
4228DECLINLINE(int) PDMDevHlpIOPortDeregister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts)
4229{
4230 return pDevIns->pHlpR3->pfnIOPortDeregister(pDevIns, Port, cPorts);
4231}
4232
4233/**
4234 * Register a Memory Mapped I/O (MMIO) region.
4235 *
4236 * These callbacks are of course for the ring-3 context (R3). Register HC
4237 * handlers before raw-mode context (RC) and ring-0 context (R0) handlers! There
4238 * must be a R3 handler for every RC and R0 handler!
4239 *
4240 * @returns VBox status.
4241 * @param pDevIns The device instance to register the MMIO with.
4242 * @param GCPhysStart First physical address in the range.
4243 * @param cbRange The size of the range (in bytes).
4244 * @param pvUser User argument.
4245 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
4246 * @param pfnWrite Pointer to function which is gonna handle Write operations.
4247 * @param pfnRead Pointer to function which is gonna handle Read operations.
4248 * @param pszDesc Pointer to description string. This must not be freed.
4249 */
4250DECLINLINE(int) PDMDevHlpMMIORegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTHCPTR pvUser,
4251 uint32_t fFlags, PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, const char *pszDesc)
4252{
4253 return pDevIns->pHlpR3->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, NULL /*pfnFill*/,
4254 fFlags, pszDesc);
4255}
4256
4257/**
4258 * Register a Memory Mapped I/O (MMIO) region for GC.
4259 *
4260 * These callbacks are for the raw-mode context (RC). Register ring-3 context
4261 * (R3) handlers before guest context handlers! There must be a R3 handler for
4262 * every RC handler!
4263 *
4264 * @returns VBox status.
4265 * @param pDevIns The device instance to register the MMIO with.
4266 * @param GCPhysStart First physical address in the range.
4267 * @param cbRange The size of the range (in bytes).
4268 * @param pvUser User argument.
4269 * @param pszWrite Name of the RC function which is gonna handle Write operations.
4270 * @param pszRead Name of the RC function which is gonna handle Read operations.
4271 */
4272DECLINLINE(int) PDMDevHlpMMIORegisterRC(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTRCPTR pvUser,
4273 const char *pszWrite, const char *pszRead)
4274{
4275 return pDevIns->pHlpR3->pfnMMIORegisterRC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, NULL /*pszFill*/);
4276}
4277
4278/**
4279 * @copydoc PDMDEVHLPR3::pfnMMIORegisterR0
4280 */
4281DECLINLINE(int) PDMDevHlpMMIORegisterR0(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTR0PTR pvUser,
4282 const char *pszWrite, const char *pszRead)
4283{
4284 return pDevIns->pHlpR3->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, NULL /*pszFill*/);
4285}
4286
4287/**
4288 * @copydoc PDMDEVHLPR3::pfnMMIORegister
4289 */
4290DECLINLINE(int) PDMDevHlpMMIORegisterEx(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTHCPTR pvUser,
4291 uint32_t fFlags, PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead,
4292 PFNIOMMMIOFILL pfnFill, const char *pszDesc)
4293{
4294 return pDevIns->pHlpR3->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, pfnFill,
4295 fFlags, pszDesc);
4296}
4297
4298/**
4299 * @copydoc PDMDEVHLPR3::pfnMMIORegisterRC
4300 */
4301DECLINLINE(int) PDMDevHlpMMIORegisterRCEx(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTRCPTR pvUser,
4302 const char *pszWrite, const char *pszRead, const char *pszFill)
4303{
4304 return pDevIns->pHlpR3->pfnMMIORegisterRC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill);
4305}
4306
4307/**
4308 * @copydoc PDMDEVHLPR3::pfnMMIORegisterR0
4309 */
4310DECLINLINE(int) PDMDevHlpMMIORegisterR0Ex(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTR0PTR pvUser,
4311 const char *pszWrite, const char *pszRead, const char *pszFill)
4312{
4313 return pDevIns->pHlpR3->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill);
4314}
4315
4316/**
4317 * @copydoc PDMDEVHLPR3::pfnMMIODeregister
4318 */
4319DECLINLINE(int) PDMDevHlpMMIODeregister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange)
4320{
4321 return pDevIns->pHlpR3->pfnMMIODeregister(pDevIns, GCPhysStart, cbRange);
4322}
4323
4324/**
4325 * @copydoc PDMDEVHLPR3::pfnMMIO2Register
4326 */
4327DECLINLINE(int) PDMDevHlpMMIO2Register(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc)
4328{
4329 return pDevIns->pHlpR3->pfnMMIO2Register(pDevIns, iRegion, cb, fFlags, ppv, pszDesc);
4330}
4331
4332/**
4333 * @copydoc PDMDEVHLPR3::pfnMMIO2Deregister
4334 */
4335DECLINLINE(int) PDMDevHlpMMIO2Deregister(PPDMDEVINS pDevIns, uint32_t iRegion)
4336{
4337 return pDevIns->pHlpR3->pfnMMIO2Deregister(pDevIns, iRegion);
4338}
4339
4340/**
4341 * @copydoc PDMDEVHLPR3::pfnMMIO2Map
4342 */
4343DECLINLINE(int) PDMDevHlpMMIO2Map(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
4344{
4345 return pDevIns->pHlpR3->pfnMMIO2Map(pDevIns, iRegion, GCPhys);
4346}
4347
4348/**
4349 * @copydoc PDMDEVHLPR3::pfnMMIO2Unmap
4350 */
4351DECLINLINE(int) PDMDevHlpMMIO2Unmap(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
4352{
4353 return pDevIns->pHlpR3->pfnMMIO2Unmap(pDevIns, iRegion, GCPhys);
4354}
4355
4356/**
4357 * @copydoc PDMDEVHLPR3::pfnMMHyperMapMMIO2
4358 */
4359DECLINLINE(int) PDMDevHlpMMHyperMapMMIO2(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
4360 const char *pszDesc, PRTRCPTR pRCPtr)
4361{
4362 return pDevIns->pHlpR3->pfnMMHyperMapMMIO2(pDevIns, iRegion, off, cb, pszDesc, pRCPtr);
4363}
4364
4365/**
4366 * @copydoc PDMDEVHLPR3::pfnMMIO2MapKernel
4367 */
4368DECLINLINE(int) PDMDevHlpMMIO2MapKernel(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
4369 const char *pszDesc, PRTR0PTR pR0Ptr)
4370{
4371 return pDevIns->pHlpR3->pfnMMIO2MapKernel(pDevIns, iRegion, off, cb, pszDesc, pR0Ptr);
4372}
4373
4374/**
4375 * @copydoc PDMDEVHLPR3::pfnROMRegister
4376 */
4377DECLINLINE(int) PDMDevHlpROMRegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
4378 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc)
4379{
4380 return pDevIns->pHlpR3->pfnROMRegister(pDevIns, GCPhysStart, cbRange, pvBinary, cbBinary, fFlags, pszDesc);
4381}
4382
4383/**
4384 * @copydoc PDMDEVHLPR3::pfnROMProtectShadow
4385 */
4386DECLINLINE(int) PDMDevHlpROMProtectShadow(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt)
4387{
4388 return pDevIns->pHlpR3->pfnROMProtectShadow(pDevIns, GCPhysStart, cbRange, enmProt);
4389}
4390
4391/**
4392 * Register a save state data unit.
4393 *
4394 * @returns VBox status.
4395 * @param pDevIns The device instance.
4396 * @param uVersion Data layout version number.
4397 * @param cbGuess The approximate amount of data in the unit.
4398 * Only for progress indicators.
4399 * @param pfnSaveExec Execute save callback, optional.
4400 * @param pfnLoadExec Execute load callback, optional.
4401 */
4402DECLINLINE(int) PDMDevHlpSSMRegister(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess,
4403 PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVLOADEXEC pfnLoadExec)
4404{
4405 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, NULL /*pszBefore*/,
4406 NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveDone*/,
4407 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
4408 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
4409}
4410
4411/**
4412 * Register a save state data unit with a live save callback as well.
4413 *
4414 * @returns VBox status.
4415 * @param pDevIns The device instance.
4416 * @param uVersion Data layout version number.
4417 * @param cbGuess The approximate amount of data in the unit.
4418 * Only for progress indicators.
4419 * @param pfnLiveExec Execute live callback, optional.
4420 * @param pfnSaveExec Execute save callback, optional.
4421 * @param pfnLoadExec Execute load callback, optional.
4422 */
4423DECLINLINE(int) PDMDevHlpSSMRegister3(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess,
4424 FNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVLOADEXEC pfnLoadExec)
4425{
4426 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, NULL /*pszBefore*/,
4427 NULL /*pfnLivePrep*/, pfnLiveExec, NULL /*pfnLiveDone*/,
4428 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
4429 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
4430}
4431
4432/**
4433 * @copydoc PDMDEVHLPR3::pfnSSMRegister
4434 */
4435DECLINLINE(int) PDMDevHlpSSMRegisterEx(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
4436 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
4437 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
4438 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone)
4439{
4440 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, pszBefore,
4441 pfnLivePrep, pfnLiveExec, pfnLiveVote,
4442 pfnSavePrep, pfnSaveExec, pfnSaveDone,
4443 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
4444}
4445
4446/**
4447 * @copydoc PDMDEVHLPR3::pfnTMTimerCreate
4448 */
4449DECLINLINE(int) PDMDevHlpTMTimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser, uint32_t fFlags,
4450 const char *pszDesc, PPTMTIMERR3 ppTimer)
4451{
4452 return pDevIns->pHlpR3->pfnTMTimerCreate(pDevIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
4453}
4454
4455/**
4456 * @copydoc PDMDEVHLPR3::pfnTMUtcNow
4457 */
4458DECLINLINE(PRTTIMESPEC) PDMDevHlpTMUtcNow(PPDMDEVINS pDevIns, PRTTIMESPEC pTime)
4459{
4460 return pDevIns->pHlpR3->pfnTMUtcNow(pDevIns, pTime);
4461}
4462
4463#endif /* IN_RING3 */
4464
4465/**
4466 * @copydoc PDMDEVHLPR3::pfnPhysRead
4467 */
4468DECLINLINE(int) PDMDevHlpPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
4469{
4470 return pDevIns->CTX_SUFF(pHlp)->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
4471}
4472
4473/**
4474 * @copydoc PDMDEVHLPR3::pfnPhysWrite
4475 */
4476DECLINLINE(int) PDMDevHlpPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
4477{
4478 return pDevIns->CTX_SUFF(pHlp)->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
4479}
4480
4481#ifdef IN_RING3
4482
4483/**
4484 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtr
4485 */
4486DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
4487{
4488 return pDevIns->CTX_SUFF(pHlp)->pfnPhysGCPhys2CCPtr(pDevIns, GCPhys, fFlags, ppv, pLock);
4489}
4490
4491/**
4492 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtrReadOnly
4493 */
4494DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv, PPGMPAGEMAPLOCK pLock)
4495{
4496 return pDevIns->CTX_SUFF(pHlp)->pfnPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhys, fFlags, ppv, pLock);
4497}
4498
4499/**
4500 * @copydoc PDMDEVHLPR3::pfnPhysReleasePageMappingLock
4501 */
4502DECLINLINE(void) PDMDevHlpPhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
4503{
4504 pDevIns->CTX_SUFF(pHlp)->pfnPhysReleasePageMappingLock(pDevIns, pLock);
4505}
4506
4507/**
4508 * @copydoc PDMDEVHLPR3::pfnPhysReadGCVirt
4509 */
4510DECLINLINE(int) PDMDevHlpPhysReadGCVirt(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb)
4511{
4512 return pDevIns->pHlpR3->pfnPhysReadGCVirt(pDevIns, pvDst, GCVirtSrc, cb);
4513}
4514
4515/**
4516 * @copydoc PDMDEVHLPR3::pfnPhysWriteGCVirt
4517 */
4518DECLINLINE(int) PDMDevHlpPhysWriteGCVirt(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb)
4519{
4520 return pDevIns->pHlpR3->pfnPhysWriteGCVirt(pDevIns, GCVirtDst, pvSrc, cb);
4521}
4522
4523/**
4524 * @copydoc PDMDEVHLPR3::pfnPhysGCPtr2GCPhys
4525 */
4526DECLINLINE(int) PDMDevHlpPhysGCPtr2GCPhys(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys)
4527{
4528 return pDevIns->pHlpR3->pfnPhysGCPtr2GCPhys(pDevIns, GCPtr, pGCPhys);
4529}
4530
4531/**
4532 * @copydoc PDMDEVHLPR3::pfnMMHeapAlloc
4533 */
4534DECLINLINE(void *) PDMDevHlpMMHeapAlloc(PPDMDEVINS pDevIns, size_t cb)
4535{
4536 return pDevIns->pHlpR3->pfnMMHeapAlloc(pDevIns, cb);
4537}
4538
4539/**
4540 * @copydoc PDMDEVHLPR3::pfnMMHeapAllocZ
4541 */
4542DECLINLINE(void *) PDMDevHlpMMHeapAllocZ(PPDMDEVINS pDevIns, size_t cb)
4543{
4544 return pDevIns->pHlpR3->pfnMMHeapAllocZ(pDevIns, cb);
4545}
4546
4547/**
4548 * @copydoc PDMDEVHLPR3::pfnMMHeapFree
4549 */
4550DECLINLINE(void) PDMDevHlpMMHeapFree(PPDMDEVINS pDevIns, void *pv)
4551{
4552 pDevIns->pHlpR3->pfnMMHeapFree(pDevIns, pv);
4553}
4554#endif /* IN_RING3 */
4555
4556/**
4557 * @copydoc PDMDEVHLPR3::pfnVMState
4558 */
4559DECLINLINE(VMSTATE) PDMDevHlpVMState(PPDMDEVINS pDevIns)
4560{
4561 return pDevIns->CTX_SUFF(pHlp)->pfnVMState(pDevIns);
4562}
4563
4564#ifdef IN_RING3
4565/**
4566 * @copydoc PDMDEVHLPR3::pfnVMTeleportedAndNotFullyResumedYet
4567 */
4568DECLINLINE(bool) PDMDevHlpVMTeleportedAndNotFullyResumedYet(PPDMDEVINS pDevIns)
4569{
4570 return pDevIns->pHlpR3->pfnVMTeleportedAndNotFullyResumedYet(pDevIns);
4571}
4572#endif /* IN_RING3 */
4573
4574/**
4575 * @copydoc PDMDEVHLPR3::pfnVMSetError
4576 */
4577DECLINLINE(int) PDMDevHlpVMSetError(PPDMDEVINS pDevIns, const int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
4578{
4579 va_list va;
4580 va_start(va, pszFormat);
4581 pDevIns->CTX_SUFF(pHlp)->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
4582 va_end(va);
4583 return rc;
4584}
4585
4586/**
4587 * @copydoc PDMDEVHLPR3::pfnVMSetRuntimeError
4588 */
4589DECLINLINE(int) PDMDevHlpVMSetRuntimeError(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
4590{
4591 va_list va;
4592 int rc;
4593 va_start(va, pszFormat);
4594 rc = pDevIns->CTX_SUFF(pHlp)->pfnVMSetRuntimeErrorV(pDevIns, fFlags, pszErrorId, pszFormat, va);
4595 va_end(va);
4596 return rc;
4597}
4598
4599/**
4600 * VBOX_STRICT wrapper for pHlp->pfnDBGFStopV.
4601 *
4602 * @returns VBox status code which must be passed up to the VMM. This will be
4603 * VINF_SUCCESS in non-strict builds.
4604 * @param pDevIns The device instance.
4605 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
4606 * @param pszFormat Message. (optional)
4607 * @param ... Message parameters.
4608 */
4609DECLINLINE(int) PDMDevHlpDBGFStop(PPDMDEVINS pDevIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
4610{
4611#ifdef VBOX_STRICT
4612# ifdef IN_RING3
4613 int rc;
4614 va_list args;
4615 va_start(args, pszFormat);
4616 rc = pDevIns->pHlpR3->pfnDBGFStopV(pDevIns, RT_SRC_POS_ARGS, pszFormat, args);
4617 va_end(args);
4618 return rc;
4619# else
4620 NOREF(pDevIns);
4621 NOREF(pszFile);
4622 NOREF(iLine);
4623 NOREF(pszFunction);
4624 NOREF(pszFormat);
4625 return VINF_EM_DBG_STOP;
4626# endif
4627#else
4628 NOREF(pDevIns);
4629 NOREF(pszFile);
4630 NOREF(iLine);
4631 NOREF(pszFunction);
4632 NOREF(pszFormat);
4633 return VINF_SUCCESS;
4634#endif
4635}
4636
4637#ifdef IN_RING3
4638
4639/**
4640 * @copydoc PDMDEVHLPR3::pfnDBGFInfoRegister
4641 */
4642DECLINLINE(int) PDMDevHlpDBGFInfoRegister(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler)
4643{
4644 return pDevIns->pHlpR3->pfnDBGFInfoRegister(pDevIns, pszName, pszDesc, pfnHandler);
4645}
4646
4647/**
4648 * @copydoc PDMDEVHLPR3::pfnSTAMRegister
4649 */
4650DECLINLINE(void) PDMDevHlpSTAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
4651{
4652 pDevIns->pHlpR3->pfnSTAMRegister(pDevIns, pvSample, enmType, pszName, enmUnit, pszDesc);
4653}
4654
4655/**
4656 * @copydoc PDMDEVHLPR3::pfnSTAMRegisterF
4657 */
4658DECLINLINE(void) PDMDevHlpSTAMRegisterF(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
4659 const char *pszDesc, const char *pszName, ...)
4660{
4661 va_list va;
4662 va_start(va, pszName);
4663 pDevIns->pHlpR3->pfnSTAMRegisterV(pDevIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
4664 va_end(va);
4665}
4666
4667/**
4668 * @copydoc PDMDEVHLPR3::pfnPCIRegister
4669 */
4670DECLINLINE(int) PDMDevHlpPCIRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev)
4671{
4672 return pDevIns->pHlpR3->pfnPCIRegister(pDevIns, pPciDev);
4673}
4674
4675/**
4676 * @copydoc PDMDEVHLPR3::pfnPCIIORegionRegister
4677 */
4678DECLINLINE(int) PDMDevHlpPCIIORegionRegister(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
4679{
4680 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, iRegion, cbRegion, enmType, pfnCallback);
4681}
4682
4683/**
4684 * @copydoc PDMDEVHLPR3::pfnPCIRegisterMsi
4685 */
4686DECLINLINE(int) PDMDevHlpPCIRegisterMsi(PPDMDEVINS pDevIns, PPDMMSIREG pMsiReg)
4687{
4688 return pDevIns->pHlpR3->pfnPCIRegisterMsi(pDevIns, pMsiReg);
4689}
4690
4691/**
4692 * @copydoc PDMDEVHLPR3::pfnPCISetConfigCallbacks
4693 */
4694DECLINLINE(void) PDMDevHlpPCISetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
4695 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
4696{
4697 pDevIns->pHlpR3->pfnPCISetConfigCallbacks(pDevIns, pPciDev, pfnRead, ppfnReadOld, pfnWrite, ppfnWriteOld);
4698}
4699
4700/**
4701 * Reads data via bus mastering, if enabled. If no bus mastering is available,
4702 * this function does nothing and returns VINF_PGM_PCI_PHYS_READ_BM_DISABLED.
4703 *
4704 * @return IPRT status code.
4705 */
4706DECLINLINE(int) PDMDevHlpPCIDevPhysRead(PPCIDEVICE pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
4707{
4708 AssertPtrReturn(pPciDev, VERR_INVALID_POINTER);
4709 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
4710 AssertReturn(cbRead, VERR_INVALID_PARAMETER);
4711
4712 if (!PCIDevIsBusmaster(pPciDev))
4713 {
4714#ifdef DEBUG
4715 Log2(("%s: %RU16:%RU16: No bus master (anymore), skipping read %p (%z)\n", __FUNCTION__,
4716 PCIDevGetVendorId(pPciDev), PCIDevGetDeviceId(pPciDev), pvBuf, cbRead));
4717#endif
4718 return VINF_PDM_PCI_PHYS_READ_BM_DISABLED;
4719 }
4720
4721 return PDMDevHlpPhysRead(pPciDev->pDevIns, GCPhys, pvBuf, cbRead);
4722}
4723
4724/**
4725 * Writes data via bus mastering, if enabled. If no bus mastering is available,
4726 * this function does nothing and returns VINF_PGM_PCI_PHYS_WRITE_BM_DISABLED.
4727 *
4728 * @return IPRT status code.
4729 */
4730DECLINLINE(int) PDMDevHlpPCIDevPhysWrite(PPCIDEVICE pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
4731{
4732 AssertPtrReturn(pPciDev, VERR_INVALID_POINTER);
4733 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
4734 AssertReturn(cbWrite, VERR_INVALID_PARAMETER);
4735
4736 if (!PCIDevIsBusmaster(pPciDev))
4737 {
4738#ifdef DEBUG
4739 Log2(("%s: %RU16:%RU16: No bus master (anymore), skipping write %p (%z)\n", __FUNCTION__,
4740 PCIDevGetVendorId(pPciDev), PCIDevGetDeviceId(pPciDev), pvBuf, cbWrite));
4741#endif
4742 return VINF_PDM_PCI_PHYS_WRITE_BM_DISABLED;
4743 }
4744
4745 return PDMDevHlpPhysWrite(pPciDev->pDevIns, GCPhys, pvBuf, cbWrite);
4746}
4747
4748#endif /* IN_RING3 */
4749
4750/**
4751 * @copydoc PDMDEVHLPR3::pfnPCISetIrq
4752 */
4753DECLINLINE(void) PDMDevHlpPCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
4754{
4755 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, iIrq, iLevel);
4756}
4757
4758/**
4759 * @copydoc PDMDEVHLPR3::pfnPCISetIrqNoWait
4760 */
4761DECLINLINE(void) PDMDevHlpPCISetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
4762{
4763 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, iIrq, iLevel);
4764}
4765
4766/**
4767 * @copydoc PDMDEVHLPR3::pfnISASetIrq
4768 */
4769DECLINLINE(void) PDMDevHlpISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
4770{
4771 pDevIns->CTX_SUFF(pHlp)->pfnISASetIrq(pDevIns, iIrq, iLevel);
4772}
4773
4774/**
4775 * @copydoc PDMDEVHLPR3::pfnISASetIrqNoWait
4776 */
4777DECLINLINE(void) PDMDevHlpISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
4778{
4779 pDevIns->CTX_SUFF(pHlp)->pfnISASetIrq(pDevIns, iIrq, iLevel);
4780}
4781
4782#ifdef IN_RING3
4783
4784/**
4785 * @copydoc PDMDEVHLPR3::pfnDriverAttach
4786 */
4787DECLINLINE(int) PDMDevHlpDriverAttach(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
4788{
4789 return pDevIns->pHlpR3->pfnDriverAttach(pDevIns, iLun, pBaseInterface, ppBaseInterface, pszDesc);
4790}
4791
4792/**
4793 * @copydoc PDMDEVHLPR3::pfnQueueCreate
4794 */
4795DECLINLINE(int) PDMDevHlpQueueCreate(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
4796 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName, PPDMQUEUE *ppQueue)
4797{
4798 return pDevIns->pHlpR3->pfnQueueCreate(pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, ppQueue);
4799}
4800
4801/**
4802 * Initializes a PDM critical section.
4803 *
4804 * The PDM critical sections are derived from the IPRT critical sections, but
4805 * works in RC and R0 as well.
4806 *
4807 * @returns VBox status code.
4808 * @param pDevIns The device instance.
4809 * @param pCritSect Pointer to the critical section.
4810 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
4811 * @param pszNameFmt Format string for naming the critical section.
4812 * For statistics and lock validation.
4813 * @param ... Arguments for the format string.
4814 */
4815DECLINLINE(int) PDMDevHlpCritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL, const char *pszNameFmt, ...)
4816{
4817 int rc;
4818 va_list va;
4819 va_start(va, pszNameFmt);
4820 rc = pDevIns->pHlpR3->pfnCritSectInit(pDevIns, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
4821 va_end(va);
4822 return rc;
4823}
4824
4825/**
4826 * @copydoc PDMDEVHLPR3::pfnCritSectGetNop
4827 */
4828DECLINLINE(PPDMCRITSECT) PDMDevHlpCritSectGetNop(PPDMDEVINS pDevIns)
4829{
4830 return pDevIns->pHlpR3->pfnCritSectGetNop(pDevIns);
4831}
4832
4833/**
4834 * @copydoc PDMDEVHLPR3::pfnCritSectGetNopR0
4835 */
4836DECLINLINE(R0PTRTYPE(PPDMCRITSECT)) PDMDevHlpCritSectGetNopR0(PPDMDEVINS pDevIns)
4837{
4838 return pDevIns->pHlpR3->pfnCritSectGetNopR0(pDevIns);
4839}
4840
4841/**
4842 * @copydoc PDMDEVHLPR3::pfnCritSectGetNopRC
4843 */
4844DECLINLINE(RCPTRTYPE(PPDMCRITSECT)) PDMDevHlpCritSectGetNopRC(PPDMDEVINS pDevIns)
4845{
4846 return pDevIns->pHlpR3->pfnCritSectGetNopRC(pDevIns);
4847}
4848
4849/**
4850 * @copydoc PDMDEVHLPR3::pfnSetDeviceCritSect
4851 */
4852DECLINLINE(int) PDMDevHlpSetDeviceCritSect(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
4853{
4854 return pDevIns->pHlpR3->pfnSetDeviceCritSect(pDevIns, pCritSect);
4855}
4856
4857/**
4858 * @copydoc PDMDEVHLPR3::pfnThreadCreate
4859 */
4860DECLINLINE(int) PDMDevHlpThreadCreate(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
4861 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
4862{
4863 return pDevIns->pHlpR3->pfnThreadCreate(pDevIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
4864}
4865
4866/**
4867 * @copydoc PDMDEVHLPR3::pfnSetAsyncNotification
4868 */
4869DECLINLINE(int) PDMDevHlpSetAsyncNotification(PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify)
4870{
4871 return pDevIns->pHlpR3->pfnSetAsyncNotification(pDevIns, pfnAsyncNotify);
4872}
4873
4874/**
4875 * @copydoc PDMDEVHLPR3::pfnAsyncNotificationCompleted
4876 */
4877DECLINLINE(void) PDMDevHlpAsyncNotificationCompleted(PPDMDEVINS pDevIns)
4878{
4879 pDevIns->pHlpR3->pfnAsyncNotificationCompleted(pDevIns);
4880}
4881
4882/**
4883 * @copydoc PDMDEVHLPR3::pfnA20Set
4884 */
4885DECLINLINE(void) PDMDevHlpA20Set(PPDMDEVINS pDevIns, bool fEnable)
4886{
4887 pDevIns->pHlpR3->pfnA20Set(pDevIns, fEnable);
4888}
4889
4890/**
4891 * @copydoc PDMDEVHLPR3::pfnRTCRegister
4892 */
4893DECLINLINE(int) PDMDevHlpRTCRegister(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp)
4894{
4895 return pDevIns->pHlpR3->pfnRTCRegister(pDevIns, pRtcReg, ppRtcHlp);
4896}
4897
4898/**
4899 * @copydoc PDMDEVHLPR3::pfnPCIBusRegister
4900 */
4901DECLINLINE(int) PDMDevHlpPCIBusRegister(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3)
4902{
4903 return pDevIns->pHlpR3->pfnPCIBusRegister(pDevIns, pPciBusReg, ppPciHlpR3);
4904}
4905
4906/**
4907 * @copydoc PDMDEVHLPR3::pfnPICRegister
4908 */
4909DECLINLINE(int) PDMDevHlpPICRegister(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3)
4910{
4911 return pDevIns->pHlpR3->pfnPICRegister(pDevIns, pPicReg, ppPicHlpR3);
4912}
4913
4914/**
4915 * @copydoc PDMDEVHLPR3::pfnAPICRegister
4916 */
4917DECLINLINE(int) PDMDevHlpAPICRegister(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3)
4918{
4919 return pDevIns->pHlpR3->pfnAPICRegister(pDevIns, pApicReg, ppApicHlpR3);
4920}
4921
4922/**
4923 * @copydoc PDMDEVHLPR3::pfn
4924 */
4925DECLINLINE(int) PDMDevHlpIOAPICRegister(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3)
4926{
4927 return pDevIns->pHlpR3->pfnIOAPICRegister(pDevIns, pIoApicReg, ppIoApicHlpR3);
4928}
4929
4930/**
4931 * @copydoc PDMDEVHLPR3::pfnHPETRegister
4932 */
4933DECLINLINE(int) PDMDevHlpHPETRegister(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3)
4934{
4935 return pDevIns->pHlpR3->pfnHPETRegister(pDevIns, pHpetReg, ppHpetHlpR3);
4936}
4937
4938/**
4939 * @copydoc PDMDEVHLPR3::pfnPciRawRegister
4940 */
4941DECLINLINE(int) PDMDevHlpPciRawRegister(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3)
4942{
4943 return pDevIns->pHlpR3->pfnPciRawRegister(pDevIns, pPciRawReg, ppPciRawHlpR3);
4944}
4945
4946/**
4947 * @copydoc PDMDEVHLPR3::pfnDMACRegister
4948 */
4949DECLINLINE(int) PDMDevHlpDMACRegister(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp)
4950{
4951 return pDevIns->pHlpR3->pfnDMACRegister(pDevIns, pDmacReg, ppDmacHlp);
4952}
4953
4954/**
4955 * @copydoc PDMDEVHLPR3::pfnDMARegister
4956 */
4957DECLINLINE(int) PDMDevHlpDMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
4958{
4959 return pDevIns->pHlpR3->pfnDMARegister(pDevIns, uChannel, pfnTransferHandler, pvUser);
4960}
4961
4962/**
4963 * @copydoc PDMDEVHLPR3::pfnDMAReadMemory
4964 */
4965DECLINLINE(int) PDMDevHlpDMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
4966{
4967 return pDevIns->pHlpR3->pfnDMAReadMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbRead);
4968}
4969
4970/**
4971 * @copydoc PDMDEVHLPR3::pfnDMAWriteMemory
4972 */
4973DECLINLINE(int) PDMDevHlpDMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
4974{
4975 return pDevIns->pHlpR3->pfnDMAWriteMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbWritten);
4976}
4977
4978/**
4979 * @copydoc PDMDEVHLPR3::pfnDMASetDREQ
4980 */
4981DECLINLINE(int) PDMDevHlpDMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
4982{
4983 return pDevIns->pHlpR3->pfnDMASetDREQ(pDevIns, uChannel, uLevel);
4984}
4985
4986/**
4987 * @copydoc PDMDEVHLPR3::pfnDMAGetChannelMode
4988 */
4989DECLINLINE(uint8_t) PDMDevHlpDMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
4990{
4991 return pDevIns->pHlpR3->pfnDMAGetChannelMode(pDevIns, uChannel);
4992}
4993
4994/**
4995 * @copydoc PDMDEVHLPR3::pfnDMASchedule
4996 */
4997DECLINLINE(void) PDMDevHlpDMASchedule(PPDMDEVINS pDevIns)
4998{
4999 pDevIns->pHlpR3->pfnDMASchedule(pDevIns);
5000}
5001
5002/**
5003 * @copydoc PDMDEVHLPR3::pfnCMOSWrite
5004 */
5005DECLINLINE(int) PDMDevHlpCMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
5006{
5007 return pDevIns->pHlpR3->pfnCMOSWrite(pDevIns, iReg, u8Value);
5008}
5009
5010/**
5011 * @copydoc PDMDEVHLPR3::pfnCMOSRead
5012 */
5013DECLINLINE(int) PDMDevHlpCMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
5014{
5015 return pDevIns->pHlpR3->pfnCMOSRead(pDevIns, iReg, pu8Value);
5016}
5017
5018/**
5019 * @copydoc PDMDEVHLP::pfnCallR0
5020 */
5021DECLINLINE(int) PDMDevHlpCallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
5022{
5023 return pDevIns->pHlpR3->pfnCallR0(pDevIns, uOperation, u64Arg);
5024}
5025
5026/**
5027 * @copydoc PDMDEVHLPR3::pfnGetUVM
5028 */
5029DECLINLINE(PUVM) PDMDevHlpGetUVM(PPDMDEVINS pDevIns)
5030{
5031 return pDevIns->CTX_SUFF(pHlp)->pfnGetUVM(pDevIns);
5032}
5033
5034#endif /* IN_RING3 */
5035
5036/**
5037 * @copydoc PDMDEVHLPR3::pfnGetVM
5038 */
5039DECLINLINE(PVM) PDMDevHlpGetVM(PPDMDEVINS pDevIns)
5040{
5041 return pDevIns->CTX_SUFF(pHlp)->pfnGetVM(pDevIns);
5042}
5043
5044/**
5045 * @copydoc PDMDEVHLPR3::pfnGetVMCPU
5046 */
5047DECLINLINE(PVMCPU) PDMDevHlpGetVMCPU(PPDMDEVINS pDevIns)
5048{
5049 return pDevIns->CTX_SUFF(pHlp)->pfnGetVMCPU(pDevIns);
5050}
5051
5052/**
5053 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGet
5054 */
5055DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGet(PPDMDEVINS pDevIns)
5056{
5057 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGet(pDevIns);
5058}
5059
5060/**
5061 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGetFreq
5062 */
5063DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGetFreq(PPDMDEVINS pDevIns)
5064{
5065 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGetFreq(pDevIns);
5066}
5067
5068/**
5069 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGetFreq
5070 */
5071DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGetNano(PPDMDEVINS pDevIns)
5072{
5073 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGetNano(pDevIns);
5074}
5075
5076#ifdef IN_RING3
5077
5078/**
5079 * @copydoc PDMDEVHLPR3::pfnRegisterVMMDevHeap
5080 */
5081DECLINLINE(int) PDMDevHlpRegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize)
5082{
5083 return pDevIns->pHlpR3->pfnRegisterVMMDevHeap(pDevIns, GCPhys, pvHeap, cbSize);
5084}
5085
5086/**
5087 * @copydoc PDMDEVHLPR3::pfnUnregisterVMMDevHeap
5088 */
5089DECLINLINE(int) PDMDevHlpUnregisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys)
5090{
5091 return pDevIns->pHlpR3->pfnUnregisterVMMDevHeap(pDevIns, GCPhys);
5092}
5093
5094/**
5095 * @copydoc PDMDEVHLPR3::pfnVMReset
5096 */
5097DECLINLINE(int) PDMDevHlpVMReset(PPDMDEVINS pDevIns)
5098{
5099 return pDevIns->pHlpR3->pfnVMReset(pDevIns);
5100}
5101
5102/**
5103 * @copydoc PDMDEVHLPR3::pfnVMSuspend
5104 */
5105DECLINLINE(int) PDMDevHlpVMSuspend(PPDMDEVINS pDevIns)
5106{
5107 return pDevIns->pHlpR3->pfnVMSuspend(pDevIns);
5108}
5109
5110/**
5111 * @copydoc PDMDEVHLPR3::pfnVMSuspendSaveAndPowerOff
5112 */
5113DECLINLINE(int) PDMDevHlpVMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
5114{
5115 return pDevIns->pHlpR3->pfnVMSuspendSaveAndPowerOff(pDevIns);
5116}
5117
5118/**
5119 * @copydoc PDMDEVHLPR3::pfnVMPowerOff
5120 */
5121DECLINLINE(int) PDMDevHlpVMPowerOff(PPDMDEVINS pDevIns)
5122{
5123 return pDevIns->pHlpR3->pfnVMPowerOff(pDevIns);
5124}
5125
5126#endif /* IN_RING3 */
5127
5128/**
5129 * @copydoc PDMDEVHLPR3::pfnA20IsEnabled
5130 */
5131DECLINLINE(bool) PDMDevHlpA20IsEnabled(PPDMDEVINS pDevIns)
5132{
5133 return pDevIns->CTX_SUFF(pHlp)->pfnA20IsEnabled(pDevIns);
5134}
5135
5136#ifdef IN_RING3
5137
5138/**
5139 * @copydoc PDMDEVHLPR3::pfnGetCpuId
5140 */
5141DECLINLINE(void) PDMDevHlpGetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
5142{
5143 pDevIns->pHlpR3->pfnGetCpuId(pDevIns, iLeaf, pEax, pEbx, pEcx, pEdx);
5144}
5145
5146#endif /* IN_RING3 */
5147#ifdef IN_RING0
5148
5149/**
5150 * @copydoc PDMDEVHLPR0::pfnCanEmulateIoBlock
5151 */
5152DECLINLINE(bool) PDMDevHlpCanEmulateIoBlock(PPDMDEVINS pDevIns)
5153{
5154 return pDevIns->CTX_SUFF(pHlp)->pfnCanEmulateIoBlock(pDevIns);
5155}
5156
5157#endif /* IN_RING0 */
5158
5159
5160
5161
5162/** Pointer to callbacks provided to the VBoxDeviceRegister() call. */
5163typedef struct PDMDEVREGCB *PPDMDEVREGCB;
5164
5165/**
5166 * Callbacks for VBoxDeviceRegister().
5167 */
5168typedef struct PDMDEVREGCB
5169{
5170 /** Interface version.
5171 * This is set to PDM_DEVREG_CB_VERSION. */
5172 uint32_t u32Version;
5173
5174 /**
5175 * Registers a device with the current VM instance.
5176 *
5177 * @returns VBox status code.
5178 * @param pCallbacks Pointer to the callback table.
5179 * @param pReg Pointer to the device registration record.
5180 * This data must be permanent and readonly.
5181 */
5182 DECLR3CALLBACKMEMBER(int, pfnRegister,(PPDMDEVREGCB pCallbacks, PCPDMDEVREG pReg));
5183} PDMDEVREGCB;
5184
5185/** Current version of the PDMDEVREGCB structure. */
5186#define PDM_DEVREG_CB_VERSION PDM_VERSION_MAKE(0xffe3, 1, 0)
5187
5188
5189/**
5190 * The VBoxDevicesRegister callback function.
5191 *
5192 * PDM will invoke this function after loading a device module and letting
5193 * the module decide which devices to register and how to handle conflicts.
5194 *
5195 * @returns VBox status code.
5196 * @param pCallbacks Pointer to the callback table.
5197 * @param u32Version VBox version number.
5198 */
5199typedef DECLCALLBACK(int) FNPDMVBOXDEVICESREGISTER(PPDMDEVREGCB pCallbacks, uint32_t u32Version);
5200
5201/** @} */
5202
5203RT_C_DECLS_END
5204
5205#endif
Note: See TracBrowser for help on using the repository browser.

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