VirtualBox

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

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

pdmdev.h: Doc update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 195.7 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 * @remarks The device lock is not taken, however, the DMA device lock is held.
2004 */
2005typedef DECLCALLBACK(uint32_t) FNDMATRANSFERHANDLER(PPDMDEVINS pDevIns, void *pvUser, unsigned uChannel, uint32_t off, uint32_t cb);
2006/** Pointer to a FNDMATRANSFERHANDLER(). */
2007typedef FNDMATRANSFERHANDLER *PFNDMATRANSFERHANDLER;
2008
2009/**
2010 * DMA Controller registration structure.
2011 */
2012typedef struct PDMDMAREG
2013{
2014 /** Structure version number. PDM_DMACREG_VERSION defines the current version. */
2015 uint32_t u32Version;
2016
2017 /**
2018 * Execute pending transfers.
2019 *
2020 * @returns A more work indiciator. I.e. 'true' if there is more to be done, and 'false' if all is done.
2021 * @param pDevIns Device instance of the DMAC.
2022 * @remarks No locks held, called on EMT(0) as a form of serialization.
2023 */
2024 DECLR3CALLBACKMEMBER(bool, pfnRun,(PPDMDEVINS pDevIns));
2025
2026 /**
2027 * Register transfer function for DMA channel.
2028 *
2029 * @param pDevIns Device instance of the DMAC.
2030 * @param uChannel Channel number.
2031 * @param pfnTransferHandler Device specific transfer function.
2032 * @param pvUSer User pointer to be passed to the callback.
2033 * @remarks No locks held, called on an EMT.
2034 */
2035 DECLR3CALLBACKMEMBER(void, pfnRegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
2036
2037 /**
2038 * Read memory
2039 *
2040 * @returns Number of bytes read.
2041 * @param pDevIns Device instance of the DMAC.
2042 * @param pvBuffer Pointer to target buffer.
2043 * @param off DMA position.
2044 * @param cbBlock Block size.
2045 * @remarks No locks held, called on an EMT.
2046 */
2047 DECLR3CALLBACKMEMBER(uint32_t, pfnReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock));
2048
2049 /**
2050 * Write memory
2051 *
2052 * @returns Number of bytes written.
2053 * @param pDevIns Device instance of the DMAC.
2054 * @param pvBuffer Memory to write.
2055 * @param off DMA position.
2056 * @param cbBlock Block size.
2057 * @remarks No locks held, called on an EMT.
2058 */
2059 DECLR3CALLBACKMEMBER(uint32_t, pfnWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock));
2060
2061 /**
2062 * Set the DREQ line.
2063 *
2064 * @param pDevIns Device instance of the DMAC.
2065 * @param uChannel Channel number.
2066 * @param uLevel Level of the line.
2067 * @remarks No locks held, called on an EMT.
2068 */
2069 DECLR3CALLBACKMEMBER(void, pfnSetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
2070
2071 /**
2072 * Get channel mode
2073 *
2074 * @returns Channel mode.
2075 * @param pDevIns Device instance of the DMAC.
2076 * @param uChannel Channel number.
2077 * @remarks No locks held, called on an EMT.
2078 */
2079 DECLR3CALLBACKMEMBER(uint8_t, pfnGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
2080
2081} PDMDMACREG;
2082/** Pointer to a DMAC registration structure. */
2083typedef PDMDMACREG *PPDMDMACREG;
2084
2085/** Current PDMDMACREG version number. */
2086#define PDM_DMACREG_VERSION PDM_VERSION_MAKE(0xffeb, 1, 0)
2087
2088
2089/**
2090 * DMA Controller device helpers.
2091 */
2092typedef struct PDMDMACHLP
2093{
2094 /** Structure version. PDM_DMACHLP_VERSION defines the current version. */
2095 uint32_t u32Version;
2096
2097 /* to-be-defined */
2098
2099} PDMDMACHLP;
2100/** Pointer to DMAC helpers. */
2101typedef PDMDMACHLP *PPDMDMACHLP;
2102/** Pointer to const DMAC helpers. */
2103typedef const PDMDMACHLP *PCPDMDMACHLP;
2104
2105/** Current PDMDMACHLP version number. */
2106#define PDM_DMACHLP_VERSION PDM_VERSION_MAKE(0xffea, 1, 0)
2107
2108#endif /* IN_RING3 */
2109
2110
2111
2112/**
2113 * RTC registration structure.
2114 */
2115typedef struct PDMRTCREG
2116{
2117 /** Structure version number. PDM_RTCREG_VERSION defines the current version. */
2118 uint32_t u32Version;
2119 uint32_t u32Alignment; /**< structure size alignment. */
2120
2121 /**
2122 * Write to a CMOS register and update the checksum if necessary.
2123 *
2124 * @returns VBox status code.
2125 * @param pDevIns Device instance of the RTC.
2126 * @param iReg The CMOS register index.
2127 * @param u8Value The CMOS register value.
2128 * @remarks Caller enters the device critical section.
2129 */
2130 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
2131
2132 /**
2133 * Read a CMOS register.
2134 *
2135 * @returns VBox status code.
2136 * @param pDevIns Device instance of the RTC.
2137 * @param iReg The CMOS register index.
2138 * @param pu8Value Where to store the CMOS register value.
2139 * @remarks Caller enters the device critical section.
2140 */
2141 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
2142
2143} PDMRTCREG;
2144/** Pointer to a RTC registration structure. */
2145typedef PDMRTCREG *PPDMRTCREG;
2146/** Pointer to a const RTC registration structure. */
2147typedef const PDMRTCREG *PCPDMRTCREG;
2148
2149/** Current PDMRTCREG version number. */
2150#define PDM_RTCREG_VERSION PDM_VERSION_MAKE(0xffe9, 2, 0)
2151
2152
2153/**
2154 * RTC device helpers.
2155 */
2156typedef struct PDMRTCHLP
2157{
2158 /** Structure version. PDM_RTCHLP_VERSION defines the current version. */
2159 uint32_t u32Version;
2160
2161 /* to-be-defined */
2162
2163} PDMRTCHLP;
2164/** Pointer to RTC helpers. */
2165typedef PDMRTCHLP *PPDMRTCHLP;
2166/** Pointer to const RTC helpers. */
2167typedef const PDMRTCHLP *PCPDMRTCHLP;
2168
2169/** Current PDMRTCHLP version number. */
2170#define PDM_RTCHLP_VERSION PDM_VERSION_MAKE(0xffe8, 1, 0)
2171
2172
2173
2174#ifdef IN_RING3
2175
2176/**
2177 * PDM Device API.
2178 */
2179typedef struct PDMDEVHLPR3
2180{
2181 /** Structure version. PDM_DEVHLPR3_VERSION defines the current version. */
2182 uint32_t u32Version;
2183
2184 /**
2185 * Register a number of I/O ports with a device.
2186 *
2187 * These callbacks are of course for the host context (HC).
2188 * Register HC handlers before guest context (GC) handlers! There must be a
2189 * HC handler for every GC handler!
2190 *
2191 * @returns VBox status.
2192 * @param pDevIns The device instance to register the ports with.
2193 * @param Port First port number in the range.
2194 * @param cPorts Number of ports to register.
2195 * @param pvUser User argument.
2196 * @param pfnOut Pointer to function which is gonna handle OUT operations.
2197 * @param pfnIn Pointer to function which is gonna handle IN operations.
2198 * @param pfnOutStr Pointer to function which is gonna handle string OUT operations.
2199 * @param pfnInStr Pointer to function which is gonna handle string IN operations.
2200 * @param pszDesc Pointer to description string. This must not be freed.
2201 * @remarks Caller enters the device critical section prior to invoking the
2202 * registered callback methods.
2203 */
2204 DECLR3CALLBACKMEMBER(int, pfnIOPortRegister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser,
2205 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
2206 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc));
2207
2208 /**
2209 * Register a number of I/O ports with a device for RC.
2210 *
2211 * These callbacks are for the raw-mode context (RC). Register ring-3 context
2212 * (R3) handlers before raw-mode context handlers! There must be a R3 handler
2213 * for every RC handler!
2214 *
2215 * @returns VBox status.
2216 * @param pDevIns The device instance to register the ports with
2217 * and which RC module to resolve the names
2218 * against.
2219 * @param Port First port number in the range.
2220 * @param cPorts Number of ports to register.
2221 * @param pvUser User argument.
2222 * @param pszOut Name of the RC function which is gonna handle OUT operations.
2223 * @param pszIn Name of the RC function which is gonna handle IN operations.
2224 * @param pszOutStr Name of the RC function which is gonna handle string OUT operations.
2225 * @param pszInStr Name of the RC function which is gonna handle string IN operations.
2226 * @param pszDesc Pointer to description string. This must not be freed.
2227 * @remarks Caller enters the device critical section prior to invoking the
2228 * registered callback methods.
2229 */
2230 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterRC,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
2231 const char *pszOut, const char *pszIn,
2232 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
2233
2234 /**
2235 * Register a number of I/O ports with a device.
2236 *
2237 * These callbacks are of course for the ring-0 host context (R0).
2238 * Register R3 (HC) handlers before R0 (R0) handlers! There must be a R3 (HC) handler for every R0 handler!
2239 *
2240 * @returns VBox status.
2241 * @param pDevIns The device instance to register the ports with.
2242 * @param Port First port number in the range.
2243 * @param cPorts Number of ports to register.
2244 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
2245 * @param pszOut Name of the R0 function which is gonna handle OUT operations.
2246 * @param pszIn Name of the R0 function which is gonna handle IN operations.
2247 * @param pszOutStr Name of the R0 function which is gonna handle string OUT operations.
2248 * @param pszInStr Name of the R0 function which is gonna handle string IN operations.
2249 * @param pszDesc Pointer to description string. This must not be freed.
2250 * @remarks Caller enters the device critical section prior to invoking the
2251 * registered callback methods.
2252 */
2253 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterR0,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
2254 const char *pszOut, const char *pszIn,
2255 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
2256
2257 /**
2258 * Deregister I/O ports.
2259 *
2260 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
2261 *
2262 * @returns VBox status.
2263 * @param pDevIns The device instance owning the ports.
2264 * @param Port First port number in the range.
2265 * @param cPorts Number of ports to deregister.
2266 */
2267 DECLR3CALLBACKMEMBER(int, pfnIOPortDeregister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts));
2268
2269 /**
2270 * Register a Memory Mapped I/O (MMIO) region.
2271 *
2272 * These callbacks are of course for the ring-3 context (R3). Register HC
2273 * handlers before raw-mode context (RC) and ring-0 context (R0) handlers! There
2274 * must be a R3 handler for every RC and R0 handler!
2275 *
2276 * @returns VBox status.
2277 * @param pDevIns The device instance to register the MMIO with.
2278 * @param GCPhysStart First physical address in the range.
2279 * @param cbRange The size of the range (in bytes).
2280 * @param pvUser User argument.
2281 * @param pfnWrite Pointer to function which is gonna handle Write operations.
2282 * @param pfnRead Pointer to function which is gonna handle Read operations.
2283 * @param pfnFill Pointer to function which is gonna handle Fill/memset operations. (optional)
2284 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
2285 * @param pszDesc Pointer to description string. This must not be freed.
2286 * @remarks Caller enters the device critical section prior to invoking the
2287 * registered callback methods.
2288 */
2289 DECLR3CALLBACKMEMBER(int, pfnMMIORegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTHCPTR pvUser,
2290 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
2291 uint32_t fFlags, const char *pszDesc));
2292
2293 /**
2294 * Register a Memory Mapped I/O (MMIO) region for GC.
2295 *
2296 * These callbacks are for the raw-mode context (RC). Register ring-3 context
2297 * (R3) handlers before guest context handlers! There must be a R3 handler for
2298 * every RC handler!
2299 *
2300 * @returns VBox status.
2301 * @param pDevIns The device instance to register the MMIO with.
2302 * @param GCPhysStart First physical address in the range.
2303 * @param cbRange The size of the range (in bytes).
2304 * @param pvUser User argument.
2305 * @param pszWrite Name of the RC function which is gonna handle Write operations.
2306 * @param pszRead Name of the RC function which is gonna handle Read operations.
2307 * @param pszFill Name of the RC function which is gonna handle Fill/memset operations. (optional)
2308 * @remarks Caller enters the device critical section prior to invoking the
2309 * registered callback methods.
2310 */
2311 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterRC,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTRCPTR pvUser,
2312 const char *pszWrite, const char *pszRead, const char *pszFill));
2313
2314 /**
2315 * Register a Memory Mapped I/O (MMIO) region for R0.
2316 *
2317 * These callbacks are for the ring-0 host context (R0). Register ring-3
2318 * constext (R3) handlers before R0 handlers! There must be a R3 handler for
2319 * every R0 handler!
2320 *
2321 * @returns VBox status.
2322 * @param pDevIns The device instance to register the MMIO with.
2323 * @param GCPhysStart First physical address in the range.
2324 * @param cbRange The size of the range (in bytes).
2325 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
2326 * @param pszWrite Name of the RC function which is gonna handle Write operations.
2327 * @param pszRead Name of the RC function which is gonna handle Read operations.
2328 * @param pszFill Name of the RC function which is gonna handle Fill/memset operations. (optional)
2329 * @param pszDesc Obsolete. NULL is fine.
2330 * @remarks Caller enters the device critical section prior to invoking the
2331 * registered callback methods.
2332 */
2333 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterR0,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTR0PTR pvUser,
2334 const char *pszWrite, const char *pszRead, const char *pszFill));
2335
2336 /**
2337 * Deregister a Memory Mapped I/O (MMIO) region.
2338 *
2339 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
2340 *
2341 * @returns VBox status.
2342 * @param pDevIns The device instance owning the MMIO region(s).
2343 * @param GCPhysStart First physical address in the range.
2344 * @param cbRange The size of the range (in bytes).
2345 */
2346 DECLR3CALLBACKMEMBER(int, pfnMMIODeregister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange));
2347
2348 /**
2349 * Allocate and register a MMIO2 region.
2350 *
2351 * As mentioned elsewhere, MMIO2 is just RAM spelled differently. It's
2352 * RAM associated with a device. It is also non-shared memory with a
2353 * permanent ring-3 mapping and page backing (presently).
2354 *
2355 * @returns VBox status.
2356 * @param pDevIns The device instance.
2357 * @param iRegion The region number. Use the PCI region number as
2358 * this must be known to the PCI bus device too. If
2359 * it's not associated with the PCI device, then
2360 * any number up to UINT8_MAX is fine.
2361 * @param cb The size (in bytes) of the region.
2362 * @param fFlags Reserved for future use, must be zero.
2363 * @param ppv Where to store the address of the ring-3 mapping
2364 * of the memory.
2365 * @param pszDesc Pointer to description string. This must not be
2366 * freed.
2367 * @thread EMT.
2368 */
2369 DECLR3CALLBACKMEMBER(int, pfnMMIO2Register,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc));
2370
2371 /**
2372 * Deregisters and frees a MMIO2 region.
2373 *
2374 * Any physical (and virtual) access handlers registered for the region must
2375 * be deregistered before calling this function.
2376 *
2377 * @returns VBox status code.
2378 * @param pDevIns The device instance.
2379 * @param iRegion The region number used during registration.
2380 * @thread EMT.
2381 */
2382 DECLR3CALLBACKMEMBER(int, pfnMMIO2Deregister,(PPDMDEVINS pDevIns, uint32_t iRegion));
2383
2384 /**
2385 * Maps a MMIO2 region into the physical memory space.
2386 *
2387 * A MMIO2 range may overlap with base memory if a lot of RAM
2388 * is configured for the VM, in which case we'll drop the base
2389 * memory pages. Presently we will make no attempt to preserve
2390 * anything that happens to be present in the base memory that
2391 * is replaced, this is of course incorrectly but it's too much
2392 * effort.
2393 *
2394 * @returns VBox status code.
2395 * @param pDevIns The device instance.
2396 * @param iRegion The region number used during registration.
2397 * @param GCPhys The physical address to map it at.
2398 * @thread EMT.
2399 */
2400 DECLR3CALLBACKMEMBER(int, pfnMMIO2Map,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys));
2401
2402 /**
2403 * Unmaps a MMIO2 region previously mapped using pfnMMIO2Map.
2404 *
2405 * @returns VBox status code.
2406 * @param pDevIns The device instance.
2407 * @param iRegion The region number used during registration.
2408 * @param GCPhys The physical address it's currently mapped at.
2409 * @thread EMT.
2410 */
2411 DECLR3CALLBACKMEMBER(int, pfnMMIO2Unmap,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys));
2412
2413 /**
2414 * Maps a portion of an MMIO2 region into the hypervisor region.
2415 *
2416 * Callers of this API must never deregister the MMIO2 region before the
2417 * VM is powered off.
2418 *
2419 * @return VBox status code.
2420 * @param pDevIns The device owning the MMIO2 memory.
2421 * @param iRegion The region.
2422 * @param off The offset into the region. Will be rounded down
2423 * to closest page boundary.
2424 * @param cb The number of bytes to map. Will be rounded up
2425 * to the closest page boundary.
2426 * @param pszDesc Mapping description.
2427 * @param pRCPtr Where to store the RC address.
2428 */
2429 DECLR3CALLBACKMEMBER(int, pfnMMHyperMapMMIO2,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
2430 const char *pszDesc, PRTRCPTR pRCPtr));
2431
2432 /**
2433 * Maps a portion of an MMIO2 region into kernel space (host).
2434 *
2435 * The kernel mapping will become invalid when the MMIO2 memory is deregistered
2436 * or the VM is terminated.
2437 *
2438 * @return VBox status code.
2439 * @param pDevIns The device owning the MMIO2 memory.
2440 * @param iRegion The region.
2441 * @param off The offset into the region. Must be page
2442 * aligned.
2443 * @param cb The number of bytes to map. Must be page
2444 * aligned.
2445 * @param pszDesc Mapping description.
2446 * @param pR0Ptr Where to store the R0 address.
2447 */
2448 DECLR3CALLBACKMEMBER(int, pfnMMIO2MapKernel,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
2449 const char *pszDesc, PRTR0PTR pR0Ptr));
2450
2451 /**
2452 * Register a ROM (BIOS) region.
2453 *
2454 * It goes without saying that this is read-only memory. The memory region must be
2455 * in unassigned memory. I.e. from the top of the address space or on the PC in
2456 * the 0xa0000-0xfffff range.
2457 *
2458 * @returns VBox status.
2459 * @param pDevIns The device instance owning the ROM region.
2460 * @param GCPhysStart First physical address in the range.
2461 * Must be page aligned!
2462 * @param cbRange The size of the range (in bytes).
2463 * Must be page aligned!
2464 * @param pvBinary Pointer to the binary data backing the ROM image.
2465 * @param cbBinary The size of the binary pointer. This must
2466 * be equal or smaller than @a cbRange.
2467 * @param fFlags Shadow ROM flags, PGMPHYS_ROM_FLAGS_* in pgm.h.
2468 * @param pszDesc Pointer to description string. This must not be freed.
2469 *
2470 * @remark There is no way to remove the rom, automatically on device cleanup or
2471 * manually from the device yet. At present I doubt we need such features...
2472 */
2473 DECLR3CALLBACKMEMBER(int, pfnROMRegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
2474 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc));
2475
2476 /**
2477 * Changes the protection of shadowed ROM mapping.
2478 *
2479 * This is intented for use by the system BIOS, chipset or device in question to
2480 * change the protection of shadowed ROM code after init and on reset.
2481 *
2482 * @param pDevIns The device instance.
2483 * @param GCPhysStart Where the mapping starts.
2484 * @param cbRange The size of the mapping.
2485 * @param enmProt The new protection type.
2486 */
2487 DECLR3CALLBACKMEMBER(int, pfnROMProtectShadow,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt));
2488
2489 /**
2490 * Register a save state data unit.
2491 *
2492 * @returns VBox status.
2493 * @param pDevIns The device instance.
2494 * @param pszName Data unit name.
2495 * @param uInstance The instance identifier of the data unit.
2496 * This must together with the name be unique.
2497 * @param uVersion Data layout version number.
2498 * @param cbGuess The approximate amount of data in the unit.
2499 * Only for progress indicators.
2500 * @param pszBefore Name of data unit which we should be put in
2501 * front of. Optional (NULL).
2502 *
2503 * @param pfnLivePrep Prepare live save callback, optional.
2504 * @param pfnLiveExec Execute live save callback, optional.
2505 * @param pfnLiveVote Vote live save callback, optional.
2506 *
2507 * @param pfnSavePrep Prepare save callback, optional.
2508 * @param pfnSaveExec Execute save callback, optional.
2509 * @param pfnSaveDone Done save callback, optional.
2510 *
2511 * @param pfnLoadPrep Prepare load callback, optional.
2512 * @param pfnLoadExec Execute load callback, optional.
2513 * @param pfnLoadDone Done load callback, optional.
2514 * @remarks Caller enters the device critical section prior to invoking the
2515 * registered callback methods.
2516 */
2517 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
2518 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
2519 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
2520 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone));
2521
2522 /**
2523 * Creates a timer.
2524 *
2525 * @returns VBox status.
2526 * @param pDevIns The device instance.
2527 * @param enmClock The clock to use on this timer.
2528 * @param pfnCallback Callback function.
2529 * @param pvUser User argument for the callback.
2530 * @param fFlags Flags, see TMTIMER_FLAGS_*.
2531 * @param pszDesc Pointer to description string which must stay around
2532 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
2533 * @param ppTimer Where to store the timer on success.
2534 * @remarks Caller enters the device critical section prior to invoking the
2535 * callback.
2536 */
2537 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer));
2538
2539 /**
2540 * Get the real world UTC time adjusted for VM lag, user offset and warpdrive.
2541 *
2542 * @returns pTime.
2543 * @param pDevIns The device instance.
2544 * @param pTime Where to store the time.
2545 */
2546 DECLR3CALLBACKMEMBER(PRTTIMESPEC, pfnTMUtcNow,(PPDMDEVINS pDevIns, PRTTIMESPEC pTime));
2547
2548 /**
2549 * Read physical memory.
2550 *
2551 * @returns VINF_SUCCESS (for now).
2552 * @param pDevIns The device instance.
2553 * @param GCPhys Physical address start reading from.
2554 * @param pvBuf Where to put the read bits.
2555 * @param cbRead How many bytes to read.
2556 * @thread Any thread, but the call may involve the emulation thread.
2557 */
2558 DECLR3CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
2559
2560 /**
2561 * Write to physical memory.
2562 *
2563 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
2564 * @param pDevIns The device instance.
2565 * @param GCPhys Physical address to write to.
2566 * @param pvBuf What to write.
2567 * @param cbWrite How many bytes to write.
2568 * @thread Any thread, but the call may involve the emulation thread.
2569 */
2570 DECLR3CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
2571
2572 /**
2573 * Requests the mapping of a guest page into ring-3.
2574 *
2575 * When you're done with the page, call pfnPhysReleasePageMappingLock() ASAP to
2576 * release it.
2577 *
2578 * This API will assume your intention is to write to the page, and will
2579 * therefore replace shared and zero pages. If you do not intend to modify the
2580 * page, use the pfnPhysGCPhys2CCPtrReadOnly() API.
2581 *
2582 * @returns VBox status code.
2583 * @retval VINF_SUCCESS on success.
2584 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
2585 * backing or if the page has any active access handlers. The caller
2586 * must fall back on using PGMR3PhysWriteExternal.
2587 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
2588 *
2589 * @param pVM The VM handle.
2590 * @param GCPhys The guest physical address of the page that
2591 * should be mapped.
2592 * @param fFlags Flags reserved for future use, MBZ.
2593 * @param ppv Where to store the address corresponding to
2594 * GCPhys.
2595 * @param pLock Where to store the lock information that
2596 * pfnPhysReleasePageMappingLock needs.
2597 *
2598 * @remark Avoid calling this API from within critical sections (other than the
2599 * PGM one) because of the deadlock risk when we have to delegating the
2600 * task to an EMT.
2601 * @thread Any.
2602 */
2603 DECLR3CALLBACKMEMBER(int, pfnPhysGCPhys2CCPtr,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock));
2604
2605 /**
2606 * Requests the mapping of a guest page into ring-3, external threads.
2607 *
2608 * When you're done with the page, call pfnPhysReleasePageMappingLock() ASAP to
2609 * release it.
2610 *
2611 * @returns VBox status code.
2612 * @retval VINF_SUCCESS on success.
2613 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
2614 * backing or if the page as an active ALL access handler. The caller
2615 * must fall back on using PGMPhysRead.
2616 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
2617 *
2618 * @param pDevIns The device instance.
2619 * @param GCPhys The guest physical address of the page that
2620 * should be mapped.
2621 * @param fFlags Flags reserved for future use, MBZ.
2622 * @param ppv Where to store the address corresponding to
2623 * GCPhys.
2624 * @param pLock Where to store the lock information that
2625 * pfnPhysReleasePageMappingLock needs.
2626 *
2627 * @remark Avoid calling this API from within critical sections.
2628 * @thread Any.
2629 */
2630 DECLR3CALLBACKMEMBER(int, pfnPhysGCPhys2CCPtrReadOnly,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv, PPGMPAGEMAPLOCK pLock));
2631
2632 /**
2633 * Release the mapping of a guest page.
2634 *
2635 * This is the counter part of pfnPhysGCPhys2CCPtr and
2636 * pfnPhysGCPhys2CCPtrReadOnly.
2637 *
2638 * @param pDevIns The device instance.
2639 * @param pLock The lock structure initialized by the mapping
2640 * function.
2641 */
2642 DECLR3CALLBACKMEMBER(void, pfnPhysReleasePageMappingLock,(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock));
2643
2644 /**
2645 * Read guest physical memory by virtual address.
2646 *
2647 * @param pDevIns The device instance.
2648 * @param pvDst Where to put the read bits.
2649 * @param GCVirtSrc Guest virtual address to start reading from.
2650 * @param cb How many bytes to read.
2651 * @thread The emulation thread.
2652 */
2653 DECLR3CALLBACKMEMBER(int, pfnPhysReadGCVirt,(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb));
2654
2655 /**
2656 * Write to guest physical memory by virtual address.
2657 *
2658 * @param pDevIns The device instance.
2659 * @param GCVirtDst Guest virtual address to write to.
2660 * @param pvSrc What to write.
2661 * @param cb How many bytes to write.
2662 * @thread The emulation thread.
2663 */
2664 DECLR3CALLBACKMEMBER(int, pfnPhysWriteGCVirt,(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb));
2665
2666 /**
2667 * Convert a guest virtual address to a guest physical address.
2668 *
2669 * @returns VBox status code.
2670 * @param pDevIns The device instance.
2671 * @param GCPtr Guest virtual address.
2672 * @param pGCPhys Where to store the GC physical address
2673 * corresponding to GCPtr.
2674 * @thread The emulation thread.
2675 * @remark Careful with page boundaries.
2676 */
2677 DECLR3CALLBACKMEMBER(int, pfnPhysGCPtr2GCPhys, (PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys));
2678
2679 /**
2680 * Allocate memory which is associated with current VM instance
2681 * and automatically freed on it's destruction.
2682 *
2683 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
2684 * @param pDevIns The device instance.
2685 * @param cb Number of bytes to allocate.
2686 */
2687 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMDEVINS pDevIns, size_t cb));
2688
2689 /**
2690 * Allocate memory which is associated with current VM instance
2691 * and automatically freed on it's destruction. The memory is ZEROed.
2692 *
2693 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
2694 * @param pDevIns The device instance.
2695 * @param cb Number of bytes to allocate.
2696 */
2697 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMDEVINS pDevIns, size_t cb));
2698
2699 /**
2700 * Free memory allocated with pfnMMHeapAlloc() and pfnMMHeapAllocZ().
2701 *
2702 * @param pDevIns The device instance.
2703 * @param pv Pointer to the memory to free.
2704 */
2705 DECLR3CALLBACKMEMBER(void, pfnMMHeapFree,(PPDMDEVINS pDevIns, void *pv));
2706
2707 /**
2708 * Gets the VM state.
2709 *
2710 * @returns VM state.
2711 * @param pDevIns The device instance.
2712 * @thread Any thread (just keep in mind that it's volatile info).
2713 */
2714 DECLR3CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
2715
2716 /**
2717 * Checks if the VM was teleported and hasn't been fully resumed yet.
2718 *
2719 * @returns true / false.
2720 * @param pDevIns The device instance.
2721 * @thread Any thread.
2722 */
2723 DECLR3CALLBACKMEMBER(bool, pfnVMTeleportedAndNotFullyResumedYet,(PPDMDEVINS pDevIns));
2724
2725 /**
2726 * Set the VM error message
2727 *
2728 * @returns rc.
2729 * @param pDevIns The device instance.
2730 * @param rc VBox status code.
2731 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2732 * @param pszFormat Error message format string.
2733 * @param ... Error message arguments.
2734 */
2735 DECLR3CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
2736
2737 /**
2738 * Set the VM error message
2739 *
2740 * @returns rc.
2741 * @param pDevIns The device instance.
2742 * @param rc VBox status code.
2743 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
2744 * @param pszFormat Error message format string.
2745 * @param va Error message arguments.
2746 */
2747 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
2748
2749 /**
2750 * Set the VM runtime error message
2751 *
2752 * @returns VBox status code.
2753 * @param pDevIns The device instance.
2754 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
2755 * @param pszErrorId Error ID string.
2756 * @param pszFormat Error message format string.
2757 * @param ... Error message arguments.
2758 */
2759 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
2760
2761 /**
2762 * Set the VM runtime error message
2763 *
2764 * @returns VBox status code.
2765 * @param pDevIns The device instance.
2766 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
2767 * @param pszErrorId Error ID string.
2768 * @param pszFormat Error message format string.
2769 * @param va Error message arguments.
2770 */
2771 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
2772
2773 /**
2774 * Stops the VM and enters the debugger to look at the guest state.
2775 *
2776 * Use the PDMDeviceDBGFStop() inline function with the RT_SRC_POS macro instead of
2777 * invoking this function directly.
2778 *
2779 * @returns VBox status code which must be passed up to the VMM.
2780 * @param pDevIns The device instance.
2781 * @param pszFile Filename of the assertion location.
2782 * @param iLine The linenumber of the assertion location.
2783 * @param pszFunction Function of the assertion location.
2784 * @param pszFormat Message. (optional)
2785 * @param args Message parameters.
2786 */
2787 DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list args));
2788
2789 /**
2790 * Register a info handler with DBGF,
2791 *
2792 * @returns VBox status code.
2793 * @param pDevIns The device instance.
2794 * @param pszName The identifier of the info.
2795 * @param pszDesc The description of the info and any arguments
2796 * the handler may take.
2797 * @param pfnHandler The handler function to be called to display the
2798 * info.
2799 */
2800 DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegister,(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler));
2801
2802 /**
2803 * Gets the trace buffer handle.
2804 *
2805 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
2806 * really inteded for direct usage, thus no inline wrapper function.
2807 *
2808 * @returns Trace buffer handle or NIL_RTTRACEBUF.
2809 * @param pDevIns The device instance.
2810 */
2811 DECLR3CALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
2812
2813 /**
2814 * Registers a statistics sample if statistics are enabled.
2815 *
2816 * @param pDevIns Device instance of the DMA.
2817 * @param pvSample Pointer to the sample.
2818 * @param enmType Sample type. This indicates what pvSample is
2819 * pointing at.
2820 * @param pszName Sample name. The name is on this form
2821 * "/<component>/<sample>". Further nesting is
2822 * possible.
2823 * @param enmUnit Sample unit.
2824 * @param pszDesc Sample description.
2825 */
2826 DECLR3CALLBACKMEMBER(void, pfnSTAMRegister,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc));
2827
2828 /**
2829 * Same as pfnSTAMRegister except that the name is specified in a
2830 * RTStrPrintf like fashion.
2831 *
2832 * @returns VBox status.
2833 * @param pDevIns Device instance of the DMA.
2834 * @param pvSample Pointer to the sample.
2835 * @param enmType Sample type. This indicates what pvSample is
2836 * pointing at.
2837 * @param enmVisibility Visibility type specifying whether unused
2838 * statistics should be visible or not.
2839 * @param enmUnit Sample unit.
2840 * @param pszDesc Sample description.
2841 * @param pszName The sample name format string.
2842 * @param ... Arguments to the format string.
2843 */
2844 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterF,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
2845 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...));
2846
2847 /**
2848 * Same as pfnSTAMRegister except that the name is specified in a
2849 * RTStrPrintfV like fashion.
2850 *
2851 * @returns VBox status.
2852 * @param pDevIns Device instance of the DMA.
2853 * @param pvSample Pointer to the sample.
2854 * @param enmType Sample type. This indicates what pvSample is
2855 * pointing at.
2856 * @param enmVisibility Visibility type specifying whether unused
2857 * statistics should be visible or not.
2858 * @param enmUnit Sample unit.
2859 * @param pszDesc Sample description.
2860 * @param pszName The sample name format string.
2861 * @param args Arguments to the format string.
2862 */
2863 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
2864 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args));
2865
2866 /**
2867 * Reads data via bus mastering, if enabled. If no bus mastering is available,
2868 * this function does nothing and returns VINF_PGM_PCI_PHYS_READ_BM_DISABLED.
2869 *
2870 * @return IPRT status code.
2871 */
2872 DECLR3CALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
2873
2874 /**
2875 * Writes data via bus mastering, if enabled. If no bus mastering is available,
2876 * this function does nothing and returns VINF_PGM_PCI_PHYS_WRITE_BM_DISABLED.
2877 *
2878 * @return IPRT status code.
2879 */
2880 DECLR3CALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
2881
2882 /**
2883 * Registers the device with the default PCI bus.
2884 *
2885 * @returns VBox status code.
2886 * @param pDevIns The device instance.
2887 * @param pPciDev The PCI device structure.
2888 * Any PCI enabled device must keep this in it's instance data!
2889 * Fill in the PCI data config before registration, please.
2890 * @remark This is the simple interface, a Ex interface will be created if
2891 * more features are needed later.
2892 */
2893 DECLR3CALLBACKMEMBER(int, pfnPCIRegister,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev));
2894
2895 /**
2896 * Initialize MSI support in a PCI device.
2897 *
2898 * @returns VBox status code.
2899 * @param pDevIns The device instance.
2900 * @param pMsiReg MSI registartion structure.
2901 */
2902 DECLR3CALLBACKMEMBER(int, pfnPCIRegisterMsi,(PPDMDEVINS pDevIns, PPDMMSIREG pMsiReg));
2903
2904 /**
2905 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
2906 *
2907 * @returns VBox status code.
2908 * @param pDevIns The device instance.
2909 * @param iRegion The region number.
2910 * @param cbRegion Size of the region.
2911 * @param enmType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
2912 * @param pfnCallback Callback for doing the mapping.
2913 * @remarks The callback will be invoked holding the PDM lock. The device lock
2914 * is NOT take because that is very likely be a lock order violation.
2915 */
2916 DECLR3CALLBACKMEMBER(int, pfnPCIIORegionRegister,(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion,
2917 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback));
2918
2919 /**
2920 * Register PCI configuration space read/write callbacks.
2921 *
2922 * @param pDevIns The device instance.
2923 * @param pPciDev The PCI device structure.
2924 * If NULL the default PCI device for this device instance is used.
2925 * @param pfnRead Pointer to the user defined PCI config read function.
2926 * @param ppfnReadOld Pointer to function pointer which will receive the old (default)
2927 * PCI config read function. This way, user can decide when (and if)
2928 * to call default PCI config read function. Can be NULL.
2929 * @param pfnWrite Pointer to the user defined PCI config write function.
2930 * @param pfnWriteOld Pointer to function pointer which will receive the old (default)
2931 * PCI config write function. This way, user can decide when (and if)
2932 * to call default PCI config write function. Can be NULL.
2933 * @remarks The callbacks will be invoked holding the PDM lock. The device lock
2934 * is NOT take because that is very likely be a lock order violation.
2935 * @thread EMT
2936 */
2937 DECLR3CALLBACKMEMBER(void, pfnPCISetConfigCallbacks,(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
2938 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld));
2939
2940 /**
2941 * Set the IRQ for a PCI device.
2942 *
2943 * @param pDevIns The device instance.
2944 * @param iIrq IRQ number to set.
2945 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2946 * @thread Any thread, but will involve the emulation thread.
2947 */
2948 DECLR3CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2949
2950 /**
2951 * Set the IRQ for a PCI device, but don't wait for EMT to process
2952 * the request when not called from EMT.
2953 *
2954 * @param pDevIns The device instance.
2955 * @param iIrq IRQ number to set.
2956 * @param iLevel IRQ level.
2957 * @thread Any thread, but will involve the emulation thread.
2958 */
2959 DECLR3CALLBACKMEMBER(void, pfnPCISetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2960
2961 /**
2962 * Set ISA IRQ for a device.
2963 *
2964 * @param pDevIns The device instance.
2965 * @param iIrq IRQ number to set.
2966 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2967 * @thread Any thread, but will involve the emulation thread.
2968 */
2969 DECLR3CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2970
2971 /**
2972 * Set the ISA IRQ for a device, but don't wait for EMT to process
2973 * the request when not called from EMT.
2974 *
2975 * @param pDevIns The device instance.
2976 * @param iIrq IRQ number to set.
2977 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2978 * @thread Any thread, but will involve the emulation thread.
2979 */
2980 DECLR3CALLBACKMEMBER(void, pfnISASetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2981
2982 /**
2983 * Attaches a driver (chain) to the device.
2984 *
2985 * The first call for a LUN this will serve as a registartion of the LUN. The pBaseInterface and
2986 * the pszDesc string will be registered with that LUN and kept around for PDMR3QueryDeviceLun().
2987 *
2988 * @returns VBox status code.
2989 * @param pDevIns The device instance.
2990 * @param iLun The logical unit to attach.
2991 * @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
2992 * @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
2993 * @param pszDesc Pointer to a string describing the LUN. This string must remain valid
2994 * for the live of the device instance.
2995 */
2996 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface,
2997 PPDMIBASE *ppBaseInterface, const char *pszDesc));
2998
2999 /**
3000 * Create a queue.
3001 *
3002 * @returns VBox status code.
3003 * @param pDevIns The device instance.
3004 * @param cbItem The size of a queue item.
3005 * @param cItems The number of items in the queue.
3006 * @param cMilliesInterval The number of milliseconds between polling the queue.
3007 * If 0 then the emulation thread will be notified whenever an item arrives.
3008 * @param pfnCallback The consumer function.
3009 * @param fRZEnabled Set if the queue should work in RC and R0.
3010 * @param pszName The queue base name. The instance number will be
3011 * appended automatically.
3012 * @param ppQueue Where to store the queue handle on success.
3013 * @thread The emulation thread.
3014 * @remarks The device critical section will NOT be entered before calling the
3015 * callback. No locks will be held, but for now it's safe to assume
3016 * that only one EMT will do queue callbacks at any one time.
3017 */
3018 DECLR3CALLBACKMEMBER(int, pfnQueueCreate,(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
3019 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName, PPDMQUEUE *ppQueue));
3020
3021 /**
3022 * Initializes a PDM critical section.
3023 *
3024 * The PDM critical sections are derived from the IPRT critical sections, but
3025 * works in RC and R0 as well.
3026 *
3027 * @returns VBox status code.
3028 * @param pDevIns The device instance.
3029 * @param pCritSect Pointer to the critical section.
3030 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3031 * @param pszNameFmt Format string for naming the critical section.
3032 * For statistics and lock validation.
3033 * @param va Arguments for the format string.
3034 */
3035 DECLR3CALLBACKMEMBER(int, pfnCritSectInit,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
3036 const char *pszNameFmt, va_list va));
3037
3038 /**
3039 * Gets the NOP critical section.
3040 *
3041 * @returns The ring-3 address of the NOP critical section.
3042 * @param pDevIns The device instance.
3043 */
3044 DECLR3CALLBACKMEMBER(PPDMCRITSECT, pfnCritSectGetNop,(PPDMDEVINS pDevIns));
3045
3046 /**
3047 * Gets the NOP critical section.
3048 *
3049 * @returns The ring-0 address of the NOP critical section.
3050 * @param pDevIns The device instance.
3051 */
3052 DECLR3CALLBACKMEMBER(R0PTRTYPE(PPDMCRITSECT), pfnCritSectGetNopR0,(PPDMDEVINS pDevIns));
3053
3054 /**
3055 * Gets the NOP critical section.
3056 *
3057 * @returns The raw-mode context address of the NOP critical section.
3058 * @param pDevIns The device instance.
3059 */
3060 DECLR3CALLBACKMEMBER(RCPTRTYPE(PPDMCRITSECT), pfnCritSectGetNopRC,(PPDMDEVINS pDevIns));
3061
3062 /**
3063 * Changes the device level critical section from the automatically created
3064 * default to one desired by the device constructor.
3065 *
3066 * @returns VBox status code.
3067 * @param pDevIns The device instance.
3068 * @param pCritSect The critical section to use. NULL is not
3069 * valid, instead use the NOP critical
3070 * section.
3071 */
3072 DECLR3CALLBACKMEMBER(int, pfnSetDeviceCritSect,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
3073
3074 /**
3075 * Creates a PDM thread.
3076 *
3077 * This differs from the RTThreadCreate() API in that PDM takes care of suspending,
3078 * resuming, and destroying the thread as the VM state changes.
3079 *
3080 * @returns VBox status code.
3081 * @param pDevIns The device instance.
3082 * @param ppThread Where to store the thread 'handle'.
3083 * @param pvUser The user argument to the thread function.
3084 * @param pfnThread The thread function.
3085 * @param pfnWakeup The wakup callback. This is called on the EMT
3086 * thread when a state change is pending.
3087 * @param cbStack See RTThreadCreate.
3088 * @param enmType See RTThreadCreate.
3089 * @param pszName See RTThreadCreate.
3090 * @remarks The device critical section will NOT be entered prior to invoking
3091 * the function pointers.
3092 */
3093 DECLR3CALLBACKMEMBER(int, pfnThreadCreate,(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
3094 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName));
3095
3096 /**
3097 * Set up asynchronous handling of a suspend, reset or power off notification.
3098 *
3099 * This shall only be called when getting the notification. It must be called
3100 * for each one.
3101 *
3102 * @returns VBox status code.
3103 * @param pDevIns The device instance.
3104 * @param pfnAsyncNotify The callback.
3105 * @thread EMT(0)
3106 * @remarks The caller will enter the device critical section prior to invoking
3107 * the callback.
3108 */
3109 DECLR3CALLBACKMEMBER(int, pfnSetAsyncNotification, (PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify));
3110
3111 /**
3112 * Notify EMT(0) that the device has completed the asynchronous notification
3113 * handling.
3114 *
3115 * This can be called at any time, spurious calls will simply be ignored.
3116 *
3117 * @param pDevIns The device instance.
3118 * @thread Any
3119 */
3120 DECLR3CALLBACKMEMBER(void, pfnAsyncNotificationCompleted, (PPDMDEVINS pDevIns));
3121
3122 /**
3123 * Register the RTC device.
3124 *
3125 * @returns VBox status code.
3126 * @param pDevIns The device instance.
3127 * @param pRtcReg Pointer to a RTC registration structure.
3128 * @param ppRtcHlp Where to store the pointer to the helper
3129 * functions.
3130 */
3131 DECLR3CALLBACKMEMBER(int, pfnRTCRegister,(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp));
3132
3133 /**
3134 * Register the PCI Bus.
3135 *
3136 * @returns VBox status code.
3137 * @param pDevIns The device instance.
3138 * @param pPciBusReg Pointer to PCI bus registration structure.
3139 * @param ppPciHlpR3 Where to store the pointer to the PCI Bus
3140 * helpers.
3141 */
3142 DECLR3CALLBACKMEMBER(int, pfnPCIBusRegister,(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3));
3143
3144 /**
3145 * Register the PIC device.
3146 *
3147 * @returns VBox status code.
3148 * @param pDevIns The device instance.
3149 * @param pPicReg Pointer to a PIC registration structure.
3150 * @param ppPicHlpR3 Where to store the pointer to the PIC HC
3151 * helpers.
3152 */
3153 DECLR3CALLBACKMEMBER(int, pfnPICRegister,(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3));
3154
3155 /**
3156 * Register the APIC device.
3157 *
3158 * @returns VBox status code.
3159 * @param pDevIns The device instance.
3160 * @param pApicReg Pointer to a APIC registration structure.
3161 * @param ppApicHlpR3 Where to store the pointer to the APIC helpers.
3162 */
3163 DECLR3CALLBACKMEMBER(int, pfnAPICRegister,(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3));
3164
3165 /**
3166 * Register the I/O APIC device.
3167 *
3168 * @returns VBox status code.
3169 * @param pDevIns The device instance.
3170 * @param pIoApicReg Pointer to a I/O APIC registration structure.
3171 * @param ppIoApicHlpR3 Where to store the pointer to the IOAPIC
3172 * helpers.
3173 */
3174 DECLR3CALLBACKMEMBER(int, pfnIOAPICRegister,(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3));
3175
3176 /**
3177 * Register the HPET device.
3178 *
3179 * @returns VBox status code.
3180 * @param pDevIns The device instance.
3181 * @param pHpetReg Pointer to a HPET registration structure.
3182 * @param ppHpetHlpR3 Where to store the pointer to the HPET
3183 * helpers.
3184 */
3185 DECLR3CALLBACKMEMBER(int, pfnHPETRegister,(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3));
3186
3187 /**
3188 * Register a raw PCI device.
3189 *
3190 * @returns VBox status code.
3191 * @param pDevIns The device instance.
3192 * @param pHpetReg Pointer to a raw PCI registration structure.
3193 * @param ppPciRawHlpR3 Where to store the pointer to the raw PCI
3194 * device helpers.
3195 */
3196 DECLR3CALLBACKMEMBER(int, pfnPciRawRegister,(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3));
3197
3198 /**
3199 * Register the DMA device.
3200 *
3201 * @returns VBox status code.
3202 * @param pDevIns The device instance.
3203 * @param pDmacReg Pointer to a DMAC registration structure.
3204 * @param ppDmacHlp Where to store the pointer to the DMA helpers.
3205 */
3206 DECLR3CALLBACKMEMBER(int, pfnDMACRegister,(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp));
3207
3208 /**
3209 * Register transfer function for DMA channel.
3210 *
3211 * @returns VBox status code.
3212 * @param pDevIns The device instance.
3213 * @param uChannel Channel number.
3214 * @param pfnTransferHandler Device specific transfer callback function.
3215 * @param pvUser User pointer to pass to the callback.
3216 * @thread EMT
3217 */
3218 DECLR3CALLBACKMEMBER(int, pfnDMARegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
3219
3220 /**
3221 * Read memory.
3222 *
3223 * @returns VBox status code.
3224 * @param pDevIns The device instance.
3225 * @param uChannel Channel number.
3226 * @param pvBuffer Pointer to target buffer.
3227 * @param off DMA position.
3228 * @param cbBlock Block size.
3229 * @param pcbRead Where to store the number of bytes which was
3230 * read. optional.
3231 * @thread EMT
3232 */
3233 DECLR3CALLBACKMEMBER(int, pfnDMAReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead));
3234
3235 /**
3236 * Write memory.
3237 *
3238 * @returns VBox status code.
3239 * @param pDevIns The device instance.
3240 * @param uChannel Channel number.
3241 * @param pvBuffer Memory to write.
3242 * @param off DMA position.
3243 * @param cbBlock Block size.
3244 * @param pcbWritten Where to store the number of bytes which was
3245 * written. optional.
3246 * @thread EMT
3247 */
3248 DECLR3CALLBACKMEMBER(int, pfnDMAWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten));
3249
3250 /**
3251 * Set the DREQ line.
3252 *
3253 * @returns VBox status code.
3254 * @param pDevIns Device instance.
3255 * @param uChannel Channel number.
3256 * @param uLevel Level of the line.
3257 * @thread EMT
3258 */
3259 DECLR3CALLBACKMEMBER(int, pfnDMASetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
3260
3261 /**
3262 * Get channel mode.
3263 *
3264 * @returns Channel mode. See specs.
3265 * @param pDevIns The device instance.
3266 * @param uChannel Channel number.
3267 * @thread EMT
3268 */
3269 DECLR3CALLBACKMEMBER(uint8_t, pfnDMAGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
3270
3271 /**
3272 * Schedule DMA execution.
3273 *
3274 * @param pDevIns The device instance.
3275 * @thread Any thread.
3276 */
3277 DECLR3CALLBACKMEMBER(void, pfnDMASchedule,(PPDMDEVINS pDevIns));
3278
3279 /**
3280 * Write CMOS value and update the checksum(s).
3281 *
3282 * @returns VBox status code.
3283 * @param pDevIns The device instance.
3284 * @param iReg The CMOS register index.
3285 * @param u8Value The CMOS register value.
3286 * @thread EMT
3287 */
3288 DECLR3CALLBACKMEMBER(int, pfnCMOSWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
3289
3290 /**
3291 * Read CMOS value.
3292 *
3293 * @returns VBox status code.
3294 * @param pDevIns The device instance.
3295 * @param iReg The CMOS register index.
3296 * @param pu8Value Where to store the CMOS register value.
3297 * @thread EMT
3298 */
3299 DECLR3CALLBACKMEMBER(int, pfnCMOSRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
3300
3301 /**
3302 * Assert that the current thread is the emulation thread.
3303 *
3304 * @returns True if correct.
3305 * @returns False if wrong.
3306 * @param pDevIns The device instance.
3307 * @param pszFile Filename of the assertion location.
3308 * @param iLine The linenumber of the assertion location.
3309 * @param pszFunction Function of the assertion location.
3310 */
3311 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
3312
3313 /**
3314 * Assert that the current thread is NOT the emulation thread.
3315 *
3316 * @returns True if correct.
3317 * @returns False if wrong.
3318 * @param pDevIns The device instance.
3319 * @param pszFile Filename of the assertion location.
3320 * @param iLine The linenumber of the assertion location.
3321 * @param pszFunction Function of the assertion location.
3322 */
3323 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
3324
3325 /**
3326 * Resolves the symbol for a raw-mode context interface.
3327 *
3328 * @returns VBox status code.
3329 * @param pDevIns The device instance.
3330 * @param pvInterface The interface structure.
3331 * @param cbInterface The size of the interface structure.
3332 * @param pszSymPrefix What to prefix the symbols in the list with
3333 * before resolving them. This must start with
3334 * 'dev' and contain the driver name.
3335 * @param pszSymList List of symbols corresponding to the interface.
3336 * There is generally a there is generally a define
3337 * holding this list associated with the interface
3338 * definition (INTERFACE_SYM_LIST). For more
3339 * details see PDMR3LdrGetInterfaceSymbols.
3340 * @thread EMT
3341 */
3342 DECLR3CALLBACKMEMBER(int, pfnLdrGetRCInterfaceSymbols,(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
3343 const char *pszSymPrefix, const char *pszSymList));
3344
3345 /**
3346 * Resolves the symbol for a ring-0 context interface.
3347 *
3348 * @returns VBox status code.
3349 * @param pDevIns The device instance.
3350 * @param pvInterface The interface structure.
3351 * @param cbInterface The size of the interface structure.
3352 * @param pszSymPrefix What to prefix the symbols in the list with
3353 * before resolving them. This must start with
3354 * 'dev' and contain the driver name.
3355 * @param pszSymList List of symbols corresponding to the interface.
3356 * There is generally a there is generally a define
3357 * holding this list associated with the interface
3358 * definition (INTERFACE_SYM_LIST). For more
3359 * details see PDMR3LdrGetInterfaceSymbols.
3360 * @thread EMT
3361 */
3362 DECLR3CALLBACKMEMBER(int, pfnLdrGetR0InterfaceSymbols,(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
3363 const char *pszSymPrefix, const char *pszSymList));
3364
3365 /**
3366 * Call the ring-0 request handler routine of the device.
3367 *
3368 * For this to work, the device must be ring-0 enabled and export a request
3369 * handler function. The name of the function must be the device name in
3370 * the PDMDRVREG struct prefixed with 'drvR0' and suffixed with
3371 * 'ReqHandler'. The device name will be captialized. It shall take the
3372 * exact same arguments as this function and be declared using
3373 * PDMBOTHCBDECL. See FNPDMDEVREQHANDLERR0.
3374 *
3375 * Unlike PDMDrvHlpCallR0, this is current unsuitable for more than a call
3376 * or two as the handler address will be resolved on each invocation. This
3377 * is the reason for the EMT only restriction as well.
3378 *
3379 * @returns VBox status code.
3380 * @retval VERR_SYMBOL_NOT_FOUND if the device doesn't export the required
3381 * handler function.
3382 * @retval VERR_ACCESS_DENIED if the device isn't ring-0 capable.
3383 *
3384 * @param pDevIns The device instance.
3385 * @param uOperation The operation to perform.
3386 * @param u64Arg 64-bit integer argument.
3387 * @thread EMT
3388 */
3389 DECLR3CALLBACKMEMBER(int, pfnCallR0,(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg));
3390
3391 /** Space reserved for future members.
3392 * @{ */
3393 DECLR3CALLBACKMEMBER(void, pfnReserved1,(void));
3394 DECLR3CALLBACKMEMBER(void, pfnReserved2,(void));
3395 DECLR3CALLBACKMEMBER(void, pfnReserved3,(void));
3396 DECLR3CALLBACKMEMBER(void, pfnReserved4,(void));
3397 DECLR3CALLBACKMEMBER(void, pfnReserved5,(void));
3398 DECLR3CALLBACKMEMBER(void, pfnReserved6,(void));
3399 DECLR3CALLBACKMEMBER(void, pfnReserved7,(void));
3400 DECLR3CALLBACKMEMBER(void, pfnReserved8,(void));
3401 DECLR3CALLBACKMEMBER(void, pfnReserved9,(void));
3402 /*DECLR3CALLBACKMEMBER(void, pfnReserved10,(void));*/
3403 /** @} */
3404
3405
3406 /** API available to trusted devices only.
3407 *
3408 * These APIs are providing unrestricted access to the guest and the VM,
3409 * or they are interacting intimately with PDM.
3410 *
3411 * @{
3412 */
3413
3414 /**
3415 * Gets the user mode VM handle. Restricted API.
3416 *
3417 * @returns User mode VM Handle.
3418 * @param pDevIns The device instance.
3419 */
3420 DECLR3CALLBACKMEMBER(PUVM, pfnGetUVM,(PPDMDEVINS pDevIns));
3421
3422 /**
3423 * Gets the global VM handle. Restricted API.
3424 *
3425 * @returns VM Handle.
3426 * @param pDevIns The device instance.
3427 */
3428 DECLR3CALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
3429
3430 /**
3431 * Gets the VMCPU handle. Restricted API.
3432 *
3433 * @returns VMCPU Handle.
3434 * @param pDevIns The device instance.
3435 */
3436 DECLR3CALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
3437
3438 /**
3439 * Registers the VMM device heap
3440 *
3441 * @returns VBox status code.
3442 * @param pDevIns The device instance.
3443 * @param GCPhys The physical address.
3444 * @param pvHeap Ring 3 heap pointer.
3445 * @param cbSize Size of the heap.
3446 * @thread EMT.
3447 */
3448 DECLR3CALLBACKMEMBER(int, pfnRegisterVMMDevHeap,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize));
3449
3450 /**
3451 * Unregisters the VMM device heap
3452 *
3453 * @returns VBox status code.
3454 * @param pDevIns The device instance.
3455 * @param GCPhys The physical address.
3456 * @thread EMT.
3457 */
3458 DECLR3CALLBACKMEMBER(int, pfnUnregisterVMMDevHeap,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys));
3459
3460 /**
3461 * Resets the VM.
3462 *
3463 * @returns The appropriate VBox status code to pass around on reset.
3464 * @param pDevIns The device instance.
3465 * @thread The emulation thread.
3466 */
3467 DECLR3CALLBACKMEMBER(int, pfnVMReset,(PPDMDEVINS pDevIns));
3468
3469 /**
3470 * Suspends the VM.
3471 *
3472 * @returns The appropriate VBox status code to pass around on suspend.
3473 * @param pDevIns The device instance.
3474 * @thread The emulation thread.
3475 */
3476 DECLR3CALLBACKMEMBER(int, pfnVMSuspend,(PPDMDEVINS pDevIns));
3477
3478 /**
3479 * Suspends, saves and powers off the VM.
3480 *
3481 * @returns The appropriate VBox status code to pass around.
3482 * @param pDevIns The device instance.
3483 * @thread An emulation thread.
3484 */
3485 DECLR3CALLBACKMEMBER(int, pfnVMSuspendSaveAndPowerOff,(PPDMDEVINS pDevIns));
3486
3487 /**
3488 * Power off the VM.
3489 *
3490 * @returns The appropriate VBox status code to pass around on power off.
3491 * @param pDevIns The device instance.
3492 * @thread The emulation thread.
3493 */
3494 DECLR3CALLBACKMEMBER(int, pfnVMPowerOff,(PPDMDEVINS pDevIns));
3495
3496 /**
3497 * Checks if the Gate A20 is enabled or not.
3498 *
3499 * @returns true if A20 is enabled.
3500 * @returns false if A20 is disabled.
3501 * @param pDevIns The device instance.
3502 * @thread The emulation thread.
3503 */
3504 DECLR3CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
3505
3506 /**
3507 * Enables or disables the Gate A20.
3508 *
3509 * @param pDevIns The device instance.
3510 * @param fEnable Set this flag to enable the Gate A20; clear it
3511 * to disable.
3512 * @thread The emulation thread.
3513 */
3514 DECLR3CALLBACKMEMBER(void, pfnA20Set,(PPDMDEVINS pDevIns, bool fEnable));
3515
3516 /**
3517 * Get the specified CPUID leaf for the virtual CPU associated with the calling
3518 * thread.
3519 *
3520 * @param pDevIns The device instance.
3521 * @param iLeaf The CPUID leaf to get.
3522 * @param pEax Where to store the EAX value.
3523 * @param pEbx Where to store the EBX value.
3524 * @param pEcx Where to store the ECX value.
3525 * @param pEdx Where to store the EDX value.
3526 * @thread EMT.
3527 */
3528 DECLR3CALLBACKMEMBER(void, pfnGetCpuId,(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx));
3529
3530 /**
3531 * Get the current virtual clock time in a VM. The clock frequency must be
3532 * queried separately.
3533 *
3534 * @returns Current clock time.
3535 * @param pDevIns The device instance.
3536 */
3537 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
3538
3539 /**
3540 * Get the frequency of the virtual clock.
3541 *
3542 * @returns The clock frequency (not variable at run-time).
3543 * @param pDevIns The device instance.
3544 */
3545 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
3546
3547 /**
3548 * Get the current virtual clock time in a VM, in nanoseconds.
3549 *
3550 * @returns Current clock time (in ns).
3551 * @param pDevIns The device instance.
3552 */
3553 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
3554
3555 /** @} */
3556
3557 /** Just a safety precaution. (PDM_DEVHLPR3_VERSION) */
3558 uint32_t u32TheEnd;
3559} PDMDEVHLPR3;
3560#endif /* !IN_RING3 */
3561/** Pointer to the R3 PDM Device API. */
3562typedef R3PTRTYPE(struct PDMDEVHLPR3 *) PPDMDEVHLPR3;
3563/** Pointer to the R3 PDM Device API, const variant. */
3564typedef R3PTRTYPE(const struct PDMDEVHLPR3 *) PCPDMDEVHLPR3;
3565
3566/** Current PDMDEVHLPR3 version number. */
3567#define PDM_DEVHLPR3_VERSION PDM_VERSION_MAKE(0xffe7, 9, 0)
3568
3569
3570/**
3571 * PDM Device API - RC Variant.
3572 */
3573typedef struct PDMDEVHLPRC
3574{
3575 /** Structure version. PDM_DEVHLPRC_VERSION defines the current version. */
3576 uint32_t u32Version;
3577
3578 /**
3579 * Reads data via bus mastering, if enabled. If no bus mastering is available,
3580 * this function does nothing and returns VINF_PGM_PCI_PHYS_READ_BM_DISABLED.
3581 *
3582 * @return IPRT status code.
3583 */
3584 DECLRCCALLBACKMEMBER(int, pfnPCIDevPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3585
3586 /**
3587 * Writes data via bus mastering, if enabled. If no bus mastering is available,
3588 * this function does nothing and returns VINF_PGM_PCI_PHYS_WRITE_BM_DISABLED.
3589 *
3590 * @return IPRT status code.
3591 */
3592 DECLRCCALLBACKMEMBER(int, pfnPCIDevPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3593
3594 /**
3595 * Set the IRQ for a PCI device.
3596 *
3597 * @param pDevIns Device instance.
3598 * @param iIrq IRQ number to set.
3599 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3600 * @thread Any thread, but will involve the emulation thread.
3601 */
3602 DECLRCCALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3603
3604 /**
3605 * Set ISA IRQ for a device.
3606 *
3607 * @param pDevIns Device instance.
3608 * @param iIrq IRQ number to set.
3609 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3610 * @thread Any thread, but will involve the emulation thread.
3611 */
3612 DECLRCCALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3613
3614 /**
3615 * Read physical memory.
3616 *
3617 * @returns VINF_SUCCESS (for now).
3618 * @param pDevIns Device instance.
3619 * @param GCPhys Physical address start reading from.
3620 * @param pvBuf Where to put the read bits.
3621 * @param cbRead How many bytes to read.
3622 */
3623 DECLRCCALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3624
3625 /**
3626 * Write to physical memory.
3627 *
3628 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
3629 * @param pDevIns Device instance.
3630 * @param GCPhys Physical address to write to.
3631 * @param pvBuf What to write.
3632 * @param cbWrite How many bytes to write.
3633 */
3634 DECLRCCALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3635
3636 /**
3637 * Checks if the Gate A20 is enabled or not.
3638 *
3639 * @returns true if A20 is enabled.
3640 * @returns false if A20 is disabled.
3641 * @param pDevIns Device instance.
3642 * @thread The emulation thread.
3643 */
3644 DECLRCCALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
3645
3646 /**
3647 * Gets the VM state.
3648 *
3649 * @returns VM state.
3650 * @param pDevIns The device instance.
3651 * @thread Any thread (just keep in mind that it's volatile info).
3652 */
3653 DECLRCCALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
3654
3655 /**
3656 * Set the VM error message
3657 *
3658 * @returns rc.
3659 * @param pDrvIns Driver instance.
3660 * @param rc VBox status code.
3661 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3662 * @param pszFormat Error message format string.
3663 * @param ... Error message arguments.
3664 */
3665 DECLRCCALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
3666
3667 /**
3668 * Set the VM error message
3669 *
3670 * @returns rc.
3671 * @param pDrvIns Driver instance.
3672 * @param rc VBox status code.
3673 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3674 * @param pszFormat Error message format string.
3675 * @param va Error message arguments.
3676 */
3677 DECLRCCALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
3678
3679 /**
3680 * Set the VM runtime error message
3681 *
3682 * @returns VBox status code.
3683 * @param pDevIns Device instance.
3684 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3685 * @param pszErrorId Error ID string.
3686 * @param pszFormat Error message format string.
3687 * @param ... Error message arguments.
3688 */
3689 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
3690
3691 /**
3692 * Set the VM runtime error message
3693 *
3694 * @returns VBox status code.
3695 * @param pDevIns Device instance.
3696 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3697 * @param pszErrorId Error ID string.
3698 * @param pszFormat Error message format string.
3699 * @param va Error message arguments.
3700 */
3701 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
3702
3703 /**
3704 * Set parameters for pending MMIO patch operation
3705 *
3706 * @returns VBox status code.
3707 * @param pDevIns Device instance.
3708 * @param GCPhys MMIO physical address
3709 * @param pCachedData GC pointer to cached data
3710 */
3711 DECLRCCALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
3712
3713 /**
3714 * Gets the VM handle. Restricted API.
3715 *
3716 * @returns VM Handle.
3717 * @param pDevIns Device instance.
3718 */
3719 DECLRCCALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
3720
3721 /**
3722 * Gets the VMCPU handle. Restricted API.
3723 *
3724 * @returns VMCPU Handle.
3725 * @param pDevIns The device instance.
3726 */
3727 DECLRCCALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
3728
3729 /**
3730 * Get the current virtual clock time in a VM. The clock frequency must be
3731 * queried separately.
3732 *
3733 * @returns Current clock time.
3734 * @param pDevIns The device instance.
3735 */
3736 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
3737
3738 /**
3739 * Get the frequency of the virtual clock.
3740 *
3741 * @returns The clock frequency (not variable at run-time).
3742 * @param pDevIns The device instance.
3743 */
3744 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
3745
3746 /**
3747 * Get the current virtual clock time in a VM, in nanoseconds.
3748 *
3749 * @returns Current clock time (in ns).
3750 * @param pDevIns The device instance.
3751 */
3752 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
3753
3754 /**
3755 * Gets the trace buffer handle.
3756 *
3757 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
3758 * really inteded for direct usage, thus no inline wrapper function.
3759 *
3760 * @returns Trace buffer handle or NIL_RTTRACEBUF.
3761 * @param pDevIns The device instance.
3762 */
3763 DECLRCCALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
3764
3765 /** Just a safety precaution. */
3766 uint32_t u32TheEnd;
3767} PDMDEVHLPRC;
3768/** Pointer PDM Device RC API. */
3769typedef RCPTRTYPE(struct PDMDEVHLPRC *) PPDMDEVHLPRC;
3770/** Pointer PDM Device RC API. */
3771typedef RCPTRTYPE(const struct PDMDEVHLPRC *) PCPDMDEVHLPRC;
3772
3773/** Current PDMDEVHLP version number. */
3774#define PDM_DEVHLPRC_VERSION PDM_VERSION_MAKE(0xffe6, 3, 0)
3775
3776
3777/**
3778 * PDM Device API - R0 Variant.
3779 */
3780typedef struct PDMDEVHLPR0
3781{
3782 /** Structure version. PDM_DEVHLPR0_VERSION defines the current version. */
3783 uint32_t u32Version;
3784
3785 /**
3786 * Reads data via bus mastering, if enabled. If no bus mastering is available,
3787 * this function does nothing and returns VINF_PGM_PCI_PHYS_READ_BM_DISABLED.
3788 *
3789 * @return IPRT status code.
3790 */
3791 DECLR0CALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3792
3793 /**
3794 * Writes data via bus mastering, if enabled. If no bus mastering is available,
3795 * this function does nothing and returns VINF_PGM_PCI_PHYS_WRITE_BM_DISABLED.
3796 *
3797 * @return IPRT status code.
3798 */
3799 DECLR0CALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3800
3801 /**
3802 * Set the IRQ for a PCI device.
3803 *
3804 * @param pDevIns Device instance.
3805 * @param iIrq IRQ number to set.
3806 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3807 * @thread Any thread, but will involve the emulation thread.
3808 */
3809 DECLR0CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3810
3811 /**
3812 * Set ISA IRQ for a device.
3813 *
3814 * @param pDevIns Device instance.
3815 * @param iIrq IRQ number to set.
3816 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3817 * @thread Any thread, but will involve the emulation thread.
3818 */
3819 DECLR0CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3820
3821 /**
3822 * Read physical memory.
3823 *
3824 * @returns VINF_SUCCESS (for now).
3825 * @param pDevIns Device instance.
3826 * @param GCPhys Physical address start reading from.
3827 * @param pvBuf Where to put the read bits.
3828 * @param cbRead How many bytes to read.
3829 */
3830 DECLR0CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3831
3832 /**
3833 * Write to physical memory.
3834 *
3835 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
3836 * @param pDevIns Device instance.
3837 * @param GCPhys Physical address to write to.
3838 * @param pvBuf What to write.
3839 * @param cbWrite How many bytes to write.
3840 */
3841 DECLR0CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3842
3843 /**
3844 * Checks if the Gate A20 is enabled or not.
3845 *
3846 * @returns true if A20 is enabled.
3847 * @returns false if A20 is disabled.
3848 * @param pDevIns Device instance.
3849 * @thread The emulation thread.
3850 */
3851 DECLR0CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
3852
3853 /**
3854 * Gets the VM state.
3855 *
3856 * @returns VM state.
3857 * @param pDevIns The device instance.
3858 * @thread Any thread (just keep in mind that it's volatile info).
3859 */
3860 DECLR0CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
3861
3862 /**
3863 * Set the VM error message
3864 *
3865 * @returns rc.
3866 * @param pDrvIns Driver instance.
3867 * @param rc VBox status code.
3868 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3869 * @param pszFormat Error message format string.
3870 * @param ... Error message arguments.
3871 */
3872 DECLR0CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
3873
3874 /**
3875 * Set the VM error message
3876 *
3877 * @returns rc.
3878 * @param pDrvIns Driver instance.
3879 * @param rc VBox status code.
3880 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
3881 * @param pszFormat Error message format string.
3882 * @param va Error message arguments.
3883 */
3884 DECLR0CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
3885
3886 /**
3887 * Set the VM runtime error message
3888 *
3889 * @returns VBox status code.
3890 * @param pDevIns Device instance.
3891 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3892 * @param pszErrorId Error ID string.
3893 * @param pszFormat Error message format string.
3894 * @param ... Error message arguments.
3895 */
3896 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
3897
3898 /**
3899 * Set the VM runtime error message
3900 *
3901 * @returns VBox status code.
3902 * @param pDevIns Device instance.
3903 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3904 * @param pszErrorId Error ID string.
3905 * @param pszFormat Error message format string.
3906 * @param va Error message arguments.
3907 */
3908 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
3909
3910 /**
3911 * Set parameters for pending MMIO patch operation
3912 *
3913 * @returns rc.
3914 * @param pDevIns Device instance.
3915 * @param GCPhys MMIO physical address
3916 * @param pCachedData GC pointer to cached data
3917 */
3918 DECLR0CALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
3919
3920 /**
3921 * Gets the VM handle. Restricted API.
3922 *
3923 * @returns VM Handle.
3924 * @param pDevIns Device instance.
3925 */
3926 DECLR0CALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
3927
3928 /**
3929 * Checks if our current CPU state allows for IO block emulation fallback to the recompiler
3930 *
3931 * @returns true = yes, false = no
3932 * @param pDevIns Device instance.
3933 */
3934 DECLR0CALLBACKMEMBER(bool, pfnCanEmulateIoBlock,(PPDMDEVINS pDevIns));
3935
3936 /**
3937 * Gets the VMCPU handle. Restricted API.
3938 *
3939 * @returns VMCPU Handle.
3940 * @param pDevIns The device instance.
3941 */
3942 DECLR0CALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
3943
3944 /**
3945 * Get the current virtual clock time in a VM. The clock frequency must be
3946 * queried separately.
3947 *
3948 * @returns Current clock time.
3949 * @param pDevIns The device instance.
3950 */
3951 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
3952
3953 /**
3954 * Get the frequency of the virtual clock.
3955 *
3956 * @returns The clock frequency (not variable at run-time).
3957 * @param pDevIns The device instance.
3958 */
3959 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
3960
3961 /**
3962 * Get the current virtual clock time in a VM, in nanoseconds.
3963 *
3964 * @returns Current clock time (in ns).
3965 * @param pDevIns The device instance.
3966 */
3967 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
3968
3969 /**
3970 * Gets the trace buffer handle.
3971 *
3972 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
3973 * really inteded for direct usage, thus no inline wrapper function.
3974 *
3975 * @returns Trace buffer handle or NIL_RTTRACEBUF.
3976 * @param pDevIns The device instance.
3977 */
3978 DECLR0CALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
3979
3980 /** Just a safety precaution. */
3981 uint32_t u32TheEnd;
3982} PDMDEVHLPR0;
3983/** Pointer PDM Device R0 API. */
3984typedef R0PTRTYPE(struct PDMDEVHLPR0 *) PPDMDEVHLPR0;
3985/** Pointer PDM Device GC API. */
3986typedef R0PTRTYPE(const struct PDMDEVHLPR0 *) PCPDMDEVHLPR0;
3987
3988/** Current PDMDEVHLP version number. */
3989#define PDM_DEVHLPR0_VERSION PDM_VERSION_MAKE(0xffe5, 3, 0)
3990
3991
3992
3993/**
3994 * PDM Device Instance.
3995 */
3996typedef struct PDMDEVINS
3997{
3998 /** Structure version. PDM_DEVINS_VERSION defines the current version. */
3999 uint32_t u32Version;
4000 /** Device instance number. */
4001 uint32_t iInstance;
4002
4003 /** Pointer the GC PDM Device API. */
4004 PCPDMDEVHLPRC pHlpRC;
4005 /** Pointer to device instance data. */
4006 RTRCPTR pvInstanceDataRC;
4007 /** The critical section for the device, see pCritSectXR3. */
4008 RCPTRTYPE(PPDMCRITSECT) pCritSectRoRC;
4009 /** Alignment padding. */
4010 RTRCPTR pAlignmentRC;
4011
4012 /** Pointer the R0 PDM Device API. */
4013 PCPDMDEVHLPR0 pHlpR0;
4014 /** Pointer to device instance data (R0). */
4015 RTR0PTR pvInstanceDataR0;
4016 /** The critical section for the device, see pCritSectXR3. */
4017 R0PTRTYPE(PPDMCRITSECT) pCritSectRoR0;
4018
4019 /** Pointer the HC PDM Device API. */
4020 PCPDMDEVHLPR3 pHlpR3;
4021 /** Pointer to device instance data. */
4022 RTR3PTR pvInstanceDataR3;
4023 /** The critical section for the device.
4024 *
4025 * TM and IOM will enter this critical section before calling into the device
4026 * code. PDM will when doing power on, power off, reset, suspend and resume
4027 * notifications. SSM will currently not, but this will be changed later on.
4028 *
4029 * The device gets a critical section automatically assigned to it before
4030 * the constructor is called. If the constructor wishes to use a different
4031 * critical section, it calls PDMDevHlpSetDeviceCritSect() to change it
4032 * very early on.
4033 */
4034 R3PTRTYPE(PPDMCRITSECT) pCritSectRoR3;
4035
4036 /** Pointer to device registration structure. */
4037 R3PTRTYPE(PCPDMDEVREG) pReg;
4038 /** Configuration handle. */
4039 R3PTRTYPE(PCFGMNODE) pCfg;
4040
4041 /** The base interface of the device.
4042 *
4043 * The device constructor initializes this if it has any
4044 * device level interfaces to export. To obtain this interface
4045 * call PDMR3QueryDevice(). */
4046 PDMIBASE IBase;
4047
4048 /** Tracing indicator. */
4049 uint32_t fTracing;
4050 /** The tracing ID of this device. */
4051 uint32_t idTracing;
4052#if HC_ARCH_BITS == 32
4053 /** Align the internal data more naturally. */
4054 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 13 : 0];
4055#endif
4056
4057 /** Internal data. */
4058 union
4059 {
4060#ifdef PDMDEVINSINT_DECLARED
4061 PDMDEVINSINT s;
4062#endif
4063 uint8_t padding[HC_ARCH_BITS == 32 ? 72 : 112 + 0x28];
4064 } Internal;
4065
4066 /** Device instance data. The size of this area is defined
4067 * in the PDMDEVREG::cbInstanceData field. */
4068 char achInstanceData[8];
4069} PDMDEVINS;
4070
4071/** Current PDMDEVINS version number. */
4072#define PDM_DEVINS_VERSION PDM_VERSION_MAKE(0xffe4, 3, 0)
4073
4074/** Converts a pointer to the PDMDEVINS::IBase to a pointer to PDMDEVINS. */
4075#define PDMIBASE_2_PDMDEV(pInterface) ( (PPDMDEVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDEVINS, IBase)) )
4076
4077/**
4078 * Checks the structure versions of the device instance and device helpers,
4079 * returning if they are incompatible.
4080 *
4081 * This is for use in the constructor.
4082 *
4083 * @param pDevIns The device instance pointer.
4084 */
4085#define PDMDEV_CHECK_VERSIONS_RETURN(pDevIns) \
4086 do \
4087 { \
4088 PPDMDEVINS pDevInsTypeCheck = (pDevIns); NOREF(pDevInsTypeCheck); \
4089 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->u32Version, PDM_DEVINS_VERSION), \
4090 ("DevIns=%#x mine=%#x\n", (pDevIns)->u32Version, PDM_DEVINS_VERSION), \
4091 VERR_PDM_DEVINS_VERSION_MISMATCH); \
4092 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION), \
4093 ("DevHlp=%#x mine=%#x\n", (pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION), \
4094 VERR_PDM_DEVHLPR3_VERSION_MISMATCH); \
4095 } while (0)
4096
4097/**
4098 * Quietly checks the structure versions of the device instance and device
4099 * helpers, returning if they are incompatible.
4100 *
4101 * This is for use in the destructor.
4102 *
4103 * @param pDevIns The device instance pointer.
4104 */
4105#define PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns) \
4106 do \
4107 { \
4108 PPDMDEVINS pDevInsTypeCheck = (pDevIns); NOREF(pDevInsTypeCheck); \
4109 if (RT_UNLIKELY(!PDM_VERSION_ARE_COMPATIBLE((pDevIns)->u32Version, PDM_DEVINS_VERSION) )) \
4110 return VERR_PDM_DEVINS_VERSION_MISMATCH; \
4111 if (RT_UNLIKELY(!PDM_VERSION_ARE_COMPATIBLE((pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION) )) \
4112 return VERR_PDM_DEVHLPR3_VERSION_MISMATCH; \
4113 } while (0)
4114
4115/**
4116 * Wrapper around CFGMR3ValidateConfig for the root config for use in the
4117 * constructor - returns on failure.
4118 *
4119 * This should be invoked after having initialized the instance data
4120 * sufficiently for the correct operation of the destructor. The destructor is
4121 * always called!
4122 *
4123 * @param pDevIns Pointer to the PDM device instance.
4124 * @param pszValidValues Patterns describing the valid value names. See
4125 * RTStrSimplePatternMultiMatch for details on the
4126 * pattern syntax.
4127 * @param pszValidNodes Patterns describing the valid node (key) names.
4128 * Pass empty string if no valid nodes.
4129 */
4130#define PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, pszValidValues, pszValidNodes) \
4131 do \
4132 { \
4133 int rcValCfg = CFGMR3ValidateConfig((pDevIns)->pCfg, "/", pszValidValues, pszValidNodes, \
4134 (pDevIns)->pReg->szName, (pDevIns)->iInstance); \
4135 if (RT_FAILURE(rcValCfg)) \
4136 return rcValCfg; \
4137 } while (0)
4138
4139/** @def PDMDEV_ASSERT_EMT
4140 * Assert that the current thread is the emulation thread.
4141 */
4142#ifdef VBOX_STRICT
4143# define PDMDEV_ASSERT_EMT(pDevIns) pDevIns->pHlpR3->pfnAssertEMT(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4144#else
4145# define PDMDEV_ASSERT_EMT(pDevIns) do { } while (0)
4146#endif
4147
4148/** @def PDMDEV_ASSERT_OTHER
4149 * Assert that the current thread is NOT the emulation thread.
4150 */
4151#ifdef VBOX_STRICT
4152# define PDMDEV_ASSERT_OTHER(pDevIns) pDevIns->pHlpR3->pfnAssertOther(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4153#else
4154# define PDMDEV_ASSERT_OTHER(pDevIns) do { } while (0)
4155#endif
4156
4157/** @def PDMDEV_ASSERT_VMLOCK_OWNER
4158 * Assert that the current thread is owner of the VM lock.
4159 */
4160#ifdef VBOX_STRICT
4161# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) pDevIns->pHlpR3->pfnAssertVMLock(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4162#else
4163# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) do { } while (0)
4164#endif
4165
4166/** @def PDMDEV_SET_ERROR
4167 * Set the VM error. See PDMDevHlpVMSetError() for printf like message formatting.
4168 */
4169#define PDMDEV_SET_ERROR(pDevIns, rc, pszError) \
4170 PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, "%s", pszError)
4171
4172/** @def PDMDEV_SET_RUNTIME_ERROR
4173 * Set the VM runtime error. See PDMDevHlpVMSetRuntimeError() for printf like message formatting.
4174 */
4175#define PDMDEV_SET_RUNTIME_ERROR(pDevIns, fFlags, pszErrorId, pszError) \
4176 PDMDevHlpVMSetRuntimeError(pDevIns, fFlags, pszErrorId, "%s", pszError)
4177
4178/** @def PDMDEVINS_2_RCPTR
4179 * Converts a PDM Device instance pointer a RC PDM Device instance pointer.
4180 */
4181#define PDMDEVINS_2_RCPTR(pDevIns) ( (RCPTRTYPE(PPDMDEVINS))((RTGCUINTPTR)(pDevIns)->pvInstanceDataRC - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4182
4183/** @def PDMDEVINS_2_R3PTR
4184 * Converts a PDM Device instance pointer a R3 PDM Device instance pointer.
4185 */
4186#define PDMDEVINS_2_R3PTR(pDevIns) ( (R3PTRTYPE(PPDMDEVINS))((RTHCUINTPTR)(pDevIns)->pvInstanceDataR3 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4187
4188/** @def PDMDEVINS_2_R0PTR
4189 * Converts a PDM Device instance pointer a R0 PDM Device instance pointer.
4190 */
4191#define PDMDEVINS_2_R0PTR(pDevIns) ( (R0PTRTYPE(PPDMDEVINS))((RTR0UINTPTR)(pDevIns)->pvInstanceDataR0 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4192
4193
4194#ifdef IN_RING3
4195
4196/**
4197 * @copydoc PDMDEVHLPR3::pfnIOPortRegister
4198 */
4199DECLINLINE(int) PDMDevHlpIOPortRegister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser,
4200 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
4201 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc)
4202{
4203 return pDevIns->pHlpR3->pfnIOPortRegister(pDevIns, Port, cPorts, pvUser, pfnOut, pfnIn, pfnOutStr, pfnInStr, pszDesc);
4204}
4205
4206/**
4207 * @copydoc PDMDEVHLPR3::pfnIOPortRegisterRC
4208 */
4209DECLINLINE(int) PDMDevHlpIOPortRegisterRC(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
4210 const char *pszOut, const char *pszIn, const char *pszOutStr,
4211 const char *pszInStr, const char *pszDesc)
4212{
4213 return pDevIns->pHlpR3->pfnIOPortRegisterRC(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
4214}
4215
4216/**
4217 * @copydoc PDMDEVHLPR3::pfnIOPortRegisterR0
4218 */
4219DECLINLINE(int) PDMDevHlpIOPortRegisterR0(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
4220 const char *pszOut, const char *pszIn, const char *pszOutStr,
4221 const char *pszInStr, const char *pszDesc)
4222{
4223 return pDevIns->pHlpR3->pfnIOPortRegisterR0(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
4224}
4225
4226/**
4227 * @copydoc PDMDEVHLPR3::pfnIOPortDeregister
4228 */
4229DECLINLINE(int) PDMDevHlpIOPortDeregister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts)
4230{
4231 return pDevIns->pHlpR3->pfnIOPortDeregister(pDevIns, Port, cPorts);
4232}
4233
4234/**
4235 * Register a Memory Mapped I/O (MMIO) region.
4236 *
4237 * These callbacks are of course for the ring-3 context (R3). Register HC
4238 * handlers before raw-mode context (RC) and ring-0 context (R0) handlers! There
4239 * must be a R3 handler for every RC and R0 handler!
4240 *
4241 * @returns VBox status.
4242 * @param pDevIns The device instance to register the MMIO with.
4243 * @param GCPhysStart First physical address in the range.
4244 * @param cbRange The size of the range (in bytes).
4245 * @param pvUser User argument.
4246 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
4247 * @param pfnWrite Pointer to function which is gonna handle Write operations.
4248 * @param pfnRead Pointer to function which is gonna handle Read operations.
4249 * @param pszDesc Pointer to description string. This must not be freed.
4250 */
4251DECLINLINE(int) PDMDevHlpMMIORegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTHCPTR pvUser,
4252 uint32_t fFlags, PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, const char *pszDesc)
4253{
4254 return pDevIns->pHlpR3->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, NULL /*pfnFill*/,
4255 fFlags, pszDesc);
4256}
4257
4258/**
4259 * Register a Memory Mapped I/O (MMIO) region for GC.
4260 *
4261 * These callbacks are for the raw-mode context (RC). Register ring-3 context
4262 * (R3) handlers before guest context handlers! There must be a R3 handler for
4263 * every RC handler!
4264 *
4265 * @returns VBox status.
4266 * @param pDevIns The device instance to register the MMIO with.
4267 * @param GCPhysStart First physical address in the range.
4268 * @param cbRange The size of the range (in bytes).
4269 * @param pvUser User argument.
4270 * @param pszWrite Name of the RC function which is gonna handle Write operations.
4271 * @param pszRead Name of the RC function which is gonna handle Read operations.
4272 */
4273DECLINLINE(int) PDMDevHlpMMIORegisterRC(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTRCPTR pvUser,
4274 const char *pszWrite, const char *pszRead)
4275{
4276 return pDevIns->pHlpR3->pfnMMIORegisterRC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, NULL /*pszFill*/);
4277}
4278
4279/**
4280 * @copydoc PDMDEVHLPR3::pfnMMIORegisterR0
4281 */
4282DECLINLINE(int) PDMDevHlpMMIORegisterR0(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTR0PTR pvUser,
4283 const char *pszWrite, const char *pszRead)
4284{
4285 return pDevIns->pHlpR3->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, NULL /*pszFill*/);
4286}
4287
4288/**
4289 * @copydoc PDMDEVHLPR3::pfnMMIORegister
4290 */
4291DECLINLINE(int) PDMDevHlpMMIORegisterEx(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTHCPTR pvUser,
4292 uint32_t fFlags, PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead,
4293 PFNIOMMMIOFILL pfnFill, const char *pszDesc)
4294{
4295 return pDevIns->pHlpR3->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, pfnFill,
4296 fFlags, pszDesc);
4297}
4298
4299/**
4300 * @copydoc PDMDEVHLPR3::pfnMMIORegisterRC
4301 */
4302DECLINLINE(int) PDMDevHlpMMIORegisterRCEx(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTRCPTR pvUser,
4303 const char *pszWrite, const char *pszRead, const char *pszFill)
4304{
4305 return pDevIns->pHlpR3->pfnMMIORegisterRC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill);
4306}
4307
4308/**
4309 * @copydoc PDMDEVHLPR3::pfnMMIORegisterR0
4310 */
4311DECLINLINE(int) PDMDevHlpMMIORegisterR0Ex(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, RTR0PTR pvUser,
4312 const char *pszWrite, const char *pszRead, const char *pszFill)
4313{
4314 return pDevIns->pHlpR3->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill);
4315}
4316
4317/**
4318 * @copydoc PDMDEVHLPR3::pfnMMIODeregister
4319 */
4320DECLINLINE(int) PDMDevHlpMMIODeregister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange)
4321{
4322 return pDevIns->pHlpR3->pfnMMIODeregister(pDevIns, GCPhysStart, cbRange);
4323}
4324
4325/**
4326 * @copydoc PDMDEVHLPR3::pfnMMIO2Register
4327 */
4328DECLINLINE(int) PDMDevHlpMMIO2Register(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc)
4329{
4330 return pDevIns->pHlpR3->pfnMMIO2Register(pDevIns, iRegion, cb, fFlags, ppv, pszDesc);
4331}
4332
4333/**
4334 * @copydoc PDMDEVHLPR3::pfnMMIO2Deregister
4335 */
4336DECLINLINE(int) PDMDevHlpMMIO2Deregister(PPDMDEVINS pDevIns, uint32_t iRegion)
4337{
4338 return pDevIns->pHlpR3->pfnMMIO2Deregister(pDevIns, iRegion);
4339}
4340
4341/**
4342 * @copydoc PDMDEVHLPR3::pfnMMIO2Map
4343 */
4344DECLINLINE(int) PDMDevHlpMMIO2Map(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
4345{
4346 return pDevIns->pHlpR3->pfnMMIO2Map(pDevIns, iRegion, GCPhys);
4347}
4348
4349/**
4350 * @copydoc PDMDEVHLPR3::pfnMMIO2Unmap
4351 */
4352DECLINLINE(int) PDMDevHlpMMIO2Unmap(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
4353{
4354 return pDevIns->pHlpR3->pfnMMIO2Unmap(pDevIns, iRegion, GCPhys);
4355}
4356
4357/**
4358 * @copydoc PDMDEVHLPR3::pfnMMHyperMapMMIO2
4359 */
4360DECLINLINE(int) PDMDevHlpMMHyperMapMMIO2(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
4361 const char *pszDesc, PRTRCPTR pRCPtr)
4362{
4363 return pDevIns->pHlpR3->pfnMMHyperMapMMIO2(pDevIns, iRegion, off, cb, pszDesc, pRCPtr);
4364}
4365
4366/**
4367 * @copydoc PDMDEVHLPR3::pfnMMIO2MapKernel
4368 */
4369DECLINLINE(int) PDMDevHlpMMIO2MapKernel(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
4370 const char *pszDesc, PRTR0PTR pR0Ptr)
4371{
4372 return pDevIns->pHlpR3->pfnMMIO2MapKernel(pDevIns, iRegion, off, cb, pszDesc, pR0Ptr);
4373}
4374
4375/**
4376 * @copydoc PDMDEVHLPR3::pfnROMRegister
4377 */
4378DECLINLINE(int) PDMDevHlpROMRegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
4379 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc)
4380{
4381 return pDevIns->pHlpR3->pfnROMRegister(pDevIns, GCPhysStart, cbRange, pvBinary, cbBinary, fFlags, pszDesc);
4382}
4383
4384/**
4385 * @copydoc PDMDEVHLPR3::pfnROMProtectShadow
4386 */
4387DECLINLINE(int) PDMDevHlpROMProtectShadow(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt)
4388{
4389 return pDevIns->pHlpR3->pfnROMProtectShadow(pDevIns, GCPhysStart, cbRange, enmProt);
4390}
4391
4392/**
4393 * Register a save state data unit.
4394 *
4395 * @returns VBox status.
4396 * @param pDevIns The device instance.
4397 * @param uVersion Data layout version number.
4398 * @param cbGuess The approximate amount of data in the unit.
4399 * Only for progress indicators.
4400 * @param pfnSaveExec Execute save callback, optional.
4401 * @param pfnLoadExec Execute load callback, optional.
4402 */
4403DECLINLINE(int) PDMDevHlpSSMRegister(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess,
4404 PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVLOADEXEC pfnLoadExec)
4405{
4406 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, NULL /*pszBefore*/,
4407 NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveDone*/,
4408 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
4409 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
4410}
4411
4412/**
4413 * Register a save state data unit with a live save callback as well.
4414 *
4415 * @returns VBox status.
4416 * @param pDevIns The device instance.
4417 * @param uVersion Data layout version number.
4418 * @param cbGuess The approximate amount of data in the unit.
4419 * Only for progress indicators.
4420 * @param pfnLiveExec Execute live callback, optional.
4421 * @param pfnSaveExec Execute save callback, optional.
4422 * @param pfnLoadExec Execute load callback, optional.
4423 */
4424DECLINLINE(int) PDMDevHlpSSMRegister3(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess,
4425 FNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVLOADEXEC pfnLoadExec)
4426{
4427 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, NULL /*pszBefore*/,
4428 NULL /*pfnLivePrep*/, pfnLiveExec, NULL /*pfnLiveDone*/,
4429 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
4430 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
4431}
4432
4433/**
4434 * @copydoc PDMDEVHLPR3::pfnSSMRegister
4435 */
4436DECLINLINE(int) PDMDevHlpSSMRegisterEx(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
4437 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
4438 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
4439 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone)
4440{
4441 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, pszBefore,
4442 pfnLivePrep, pfnLiveExec, pfnLiveVote,
4443 pfnSavePrep, pfnSaveExec, pfnSaveDone,
4444 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
4445}
4446
4447/**
4448 * @copydoc PDMDEVHLPR3::pfnTMTimerCreate
4449 */
4450DECLINLINE(int) PDMDevHlpTMTimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser, uint32_t fFlags,
4451 const char *pszDesc, PPTMTIMERR3 ppTimer)
4452{
4453 return pDevIns->pHlpR3->pfnTMTimerCreate(pDevIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
4454}
4455
4456/**
4457 * @copydoc PDMDEVHLPR3::pfnTMUtcNow
4458 */
4459DECLINLINE(PRTTIMESPEC) PDMDevHlpTMUtcNow(PPDMDEVINS pDevIns, PRTTIMESPEC pTime)
4460{
4461 return pDevIns->pHlpR3->pfnTMUtcNow(pDevIns, pTime);
4462}
4463
4464#endif /* IN_RING3 */
4465
4466/**
4467 * @copydoc PDMDEVHLPR3::pfnPhysRead
4468 */
4469DECLINLINE(int) PDMDevHlpPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
4470{
4471 return pDevIns->CTX_SUFF(pHlp)->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
4472}
4473
4474/**
4475 * @copydoc PDMDEVHLPR3::pfnPhysWrite
4476 */
4477DECLINLINE(int) PDMDevHlpPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
4478{
4479 return pDevIns->CTX_SUFF(pHlp)->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
4480}
4481
4482#ifdef IN_RING3
4483
4484/**
4485 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtr
4486 */
4487DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
4488{
4489 return pDevIns->CTX_SUFF(pHlp)->pfnPhysGCPhys2CCPtr(pDevIns, GCPhys, fFlags, ppv, pLock);
4490}
4491
4492/**
4493 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtrReadOnly
4494 */
4495DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv, PPGMPAGEMAPLOCK pLock)
4496{
4497 return pDevIns->CTX_SUFF(pHlp)->pfnPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhys, fFlags, ppv, pLock);
4498}
4499
4500/**
4501 * @copydoc PDMDEVHLPR3::pfnPhysReleasePageMappingLock
4502 */
4503DECLINLINE(void) PDMDevHlpPhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
4504{
4505 pDevIns->CTX_SUFF(pHlp)->pfnPhysReleasePageMappingLock(pDevIns, pLock);
4506}
4507
4508/**
4509 * @copydoc PDMDEVHLPR3::pfnPhysReadGCVirt
4510 */
4511DECLINLINE(int) PDMDevHlpPhysReadGCVirt(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb)
4512{
4513 return pDevIns->pHlpR3->pfnPhysReadGCVirt(pDevIns, pvDst, GCVirtSrc, cb);
4514}
4515
4516/**
4517 * @copydoc PDMDEVHLPR3::pfnPhysWriteGCVirt
4518 */
4519DECLINLINE(int) PDMDevHlpPhysWriteGCVirt(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb)
4520{
4521 return pDevIns->pHlpR3->pfnPhysWriteGCVirt(pDevIns, GCVirtDst, pvSrc, cb);
4522}
4523
4524/**
4525 * @copydoc PDMDEVHLPR3::pfnPhysGCPtr2GCPhys
4526 */
4527DECLINLINE(int) PDMDevHlpPhysGCPtr2GCPhys(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys)
4528{
4529 return pDevIns->pHlpR3->pfnPhysGCPtr2GCPhys(pDevIns, GCPtr, pGCPhys);
4530}
4531
4532/**
4533 * @copydoc PDMDEVHLPR3::pfnMMHeapAlloc
4534 */
4535DECLINLINE(void *) PDMDevHlpMMHeapAlloc(PPDMDEVINS pDevIns, size_t cb)
4536{
4537 return pDevIns->pHlpR3->pfnMMHeapAlloc(pDevIns, cb);
4538}
4539
4540/**
4541 * @copydoc PDMDEVHLPR3::pfnMMHeapAllocZ
4542 */
4543DECLINLINE(void *) PDMDevHlpMMHeapAllocZ(PPDMDEVINS pDevIns, size_t cb)
4544{
4545 return pDevIns->pHlpR3->pfnMMHeapAllocZ(pDevIns, cb);
4546}
4547
4548/**
4549 * @copydoc PDMDEVHLPR3::pfnMMHeapFree
4550 */
4551DECLINLINE(void) PDMDevHlpMMHeapFree(PPDMDEVINS pDevIns, void *pv)
4552{
4553 pDevIns->pHlpR3->pfnMMHeapFree(pDevIns, pv);
4554}
4555#endif /* IN_RING3 */
4556
4557/**
4558 * @copydoc PDMDEVHLPR3::pfnVMState
4559 */
4560DECLINLINE(VMSTATE) PDMDevHlpVMState(PPDMDEVINS pDevIns)
4561{
4562 return pDevIns->CTX_SUFF(pHlp)->pfnVMState(pDevIns);
4563}
4564
4565#ifdef IN_RING3
4566/**
4567 * @copydoc PDMDEVHLPR3::pfnVMTeleportedAndNotFullyResumedYet
4568 */
4569DECLINLINE(bool) PDMDevHlpVMTeleportedAndNotFullyResumedYet(PPDMDEVINS pDevIns)
4570{
4571 return pDevIns->pHlpR3->pfnVMTeleportedAndNotFullyResumedYet(pDevIns);
4572}
4573#endif /* IN_RING3 */
4574
4575/**
4576 * @copydoc PDMDEVHLPR3::pfnVMSetError
4577 */
4578DECLINLINE(int) PDMDevHlpVMSetError(PPDMDEVINS pDevIns, const int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
4579{
4580 va_list va;
4581 va_start(va, pszFormat);
4582 pDevIns->CTX_SUFF(pHlp)->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
4583 va_end(va);
4584 return rc;
4585}
4586
4587/**
4588 * @copydoc PDMDEVHLPR3::pfnVMSetRuntimeError
4589 */
4590DECLINLINE(int) PDMDevHlpVMSetRuntimeError(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
4591{
4592 va_list va;
4593 int rc;
4594 va_start(va, pszFormat);
4595 rc = pDevIns->CTX_SUFF(pHlp)->pfnVMSetRuntimeErrorV(pDevIns, fFlags, pszErrorId, pszFormat, va);
4596 va_end(va);
4597 return rc;
4598}
4599
4600/**
4601 * VBOX_STRICT wrapper for pHlp->pfnDBGFStopV.
4602 *
4603 * @returns VBox status code which must be passed up to the VMM. This will be
4604 * VINF_SUCCESS in non-strict builds.
4605 * @param pDevIns The device instance.
4606 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
4607 * @param pszFormat Message. (optional)
4608 * @param ... Message parameters.
4609 */
4610DECLINLINE(int) PDMDevHlpDBGFStop(PPDMDEVINS pDevIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
4611{
4612#ifdef VBOX_STRICT
4613# ifdef IN_RING3
4614 int rc;
4615 va_list args;
4616 va_start(args, pszFormat);
4617 rc = pDevIns->pHlpR3->pfnDBGFStopV(pDevIns, RT_SRC_POS_ARGS, pszFormat, args);
4618 va_end(args);
4619 return rc;
4620# else
4621 NOREF(pDevIns);
4622 NOREF(pszFile);
4623 NOREF(iLine);
4624 NOREF(pszFunction);
4625 NOREF(pszFormat);
4626 return VINF_EM_DBG_STOP;
4627# endif
4628#else
4629 NOREF(pDevIns);
4630 NOREF(pszFile);
4631 NOREF(iLine);
4632 NOREF(pszFunction);
4633 NOREF(pszFormat);
4634 return VINF_SUCCESS;
4635#endif
4636}
4637
4638#ifdef IN_RING3
4639
4640/**
4641 * @copydoc PDMDEVHLPR3::pfnDBGFInfoRegister
4642 */
4643DECLINLINE(int) PDMDevHlpDBGFInfoRegister(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler)
4644{
4645 return pDevIns->pHlpR3->pfnDBGFInfoRegister(pDevIns, pszName, pszDesc, pfnHandler);
4646}
4647
4648/**
4649 * @copydoc PDMDEVHLPR3::pfnSTAMRegister
4650 */
4651DECLINLINE(void) PDMDevHlpSTAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
4652{
4653 pDevIns->pHlpR3->pfnSTAMRegister(pDevIns, pvSample, enmType, pszName, enmUnit, pszDesc);
4654}
4655
4656/**
4657 * @copydoc PDMDEVHLPR3::pfnSTAMRegisterF
4658 */
4659DECLINLINE(void) PDMDevHlpSTAMRegisterF(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
4660 const char *pszDesc, const char *pszName, ...)
4661{
4662 va_list va;
4663 va_start(va, pszName);
4664 pDevIns->pHlpR3->pfnSTAMRegisterV(pDevIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
4665 va_end(va);
4666}
4667
4668/**
4669 * @copydoc PDMDEVHLPR3::pfnPCIRegister
4670 */
4671DECLINLINE(int) PDMDevHlpPCIRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev)
4672{
4673 return pDevIns->pHlpR3->pfnPCIRegister(pDevIns, pPciDev);
4674}
4675
4676/**
4677 * @copydoc PDMDEVHLPR3::pfnPCIIORegionRegister
4678 */
4679DECLINLINE(int) PDMDevHlpPCIIORegionRegister(PPDMDEVINS pDevIns, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
4680{
4681 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, iRegion, cbRegion, enmType, pfnCallback);
4682}
4683
4684/**
4685 * @copydoc PDMDEVHLPR3::pfnPCIRegisterMsi
4686 */
4687DECLINLINE(int) PDMDevHlpPCIRegisterMsi(PPDMDEVINS pDevIns, PPDMMSIREG pMsiReg)
4688{
4689 return pDevIns->pHlpR3->pfnPCIRegisterMsi(pDevIns, pMsiReg);
4690}
4691
4692/**
4693 * @copydoc PDMDEVHLPR3::pfnPCISetConfigCallbacks
4694 */
4695DECLINLINE(void) PDMDevHlpPCISetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
4696 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
4697{
4698 pDevIns->pHlpR3->pfnPCISetConfigCallbacks(pDevIns, pPciDev, pfnRead, ppfnReadOld, pfnWrite, ppfnWriteOld);
4699}
4700
4701/**
4702 * Reads data via bus mastering, if enabled. If no bus mastering is available,
4703 * this function does nothing and returns VINF_PGM_PCI_PHYS_READ_BM_DISABLED.
4704 *
4705 * @return IPRT status code.
4706 */
4707DECLINLINE(int) PDMDevHlpPCIDevPhysRead(PPCIDEVICE pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
4708{
4709 AssertPtrReturn(pPciDev, VERR_INVALID_POINTER);
4710 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
4711 AssertReturn(cbRead, VERR_INVALID_PARAMETER);
4712
4713 if (!PCIDevIsBusmaster(pPciDev))
4714 {
4715#ifdef DEBUG
4716 Log2(("%s: %RU16:%RU16: No bus master (anymore), skipping read %p (%z)\n", __FUNCTION__,
4717 PCIDevGetVendorId(pPciDev), PCIDevGetDeviceId(pPciDev), pvBuf, cbRead));
4718#endif
4719 return VINF_PDM_PCI_PHYS_READ_BM_DISABLED;
4720 }
4721
4722 return PDMDevHlpPhysRead(pPciDev->pDevIns, GCPhys, pvBuf, cbRead);
4723}
4724
4725/**
4726 * Writes data via bus mastering, if enabled. If no bus mastering is available,
4727 * this function does nothing and returns VINF_PGM_PCI_PHYS_WRITE_BM_DISABLED.
4728 *
4729 * @return IPRT status code.
4730 */
4731DECLINLINE(int) PDMDevHlpPCIDevPhysWrite(PPCIDEVICE pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
4732{
4733 AssertPtrReturn(pPciDev, VERR_INVALID_POINTER);
4734 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
4735 AssertReturn(cbWrite, VERR_INVALID_PARAMETER);
4736
4737 if (!PCIDevIsBusmaster(pPciDev))
4738 {
4739#ifdef DEBUG
4740 Log2(("%s: %RU16:%RU16: No bus master (anymore), skipping write %p (%z)\n", __FUNCTION__,
4741 PCIDevGetVendorId(pPciDev), PCIDevGetDeviceId(pPciDev), pvBuf, cbWrite));
4742#endif
4743 return VINF_PDM_PCI_PHYS_WRITE_BM_DISABLED;
4744 }
4745
4746 return PDMDevHlpPhysWrite(pPciDev->pDevIns, GCPhys, pvBuf, cbWrite);
4747}
4748
4749#endif /* IN_RING3 */
4750
4751/**
4752 * @copydoc PDMDEVHLPR3::pfnPCISetIrq
4753 */
4754DECLINLINE(void) PDMDevHlpPCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
4755{
4756 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, iIrq, iLevel);
4757}
4758
4759/**
4760 * @copydoc PDMDEVHLPR3::pfnPCISetIrqNoWait
4761 */
4762DECLINLINE(void) PDMDevHlpPCISetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
4763{
4764 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, iIrq, iLevel);
4765}
4766
4767/**
4768 * @copydoc PDMDEVHLPR3::pfnISASetIrq
4769 */
4770DECLINLINE(void) PDMDevHlpISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
4771{
4772 pDevIns->CTX_SUFF(pHlp)->pfnISASetIrq(pDevIns, iIrq, iLevel);
4773}
4774
4775/**
4776 * @copydoc PDMDEVHLPR3::pfnISASetIrqNoWait
4777 */
4778DECLINLINE(void) PDMDevHlpISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
4779{
4780 pDevIns->CTX_SUFF(pHlp)->pfnISASetIrq(pDevIns, iIrq, iLevel);
4781}
4782
4783#ifdef IN_RING3
4784
4785/**
4786 * @copydoc PDMDEVHLPR3::pfnDriverAttach
4787 */
4788DECLINLINE(int) PDMDevHlpDriverAttach(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
4789{
4790 return pDevIns->pHlpR3->pfnDriverAttach(pDevIns, iLun, pBaseInterface, ppBaseInterface, pszDesc);
4791}
4792
4793/**
4794 * @copydoc PDMDEVHLPR3::pfnQueueCreate
4795 */
4796DECLINLINE(int) PDMDevHlpQueueCreate(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
4797 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName, PPDMQUEUE *ppQueue)
4798{
4799 return pDevIns->pHlpR3->pfnQueueCreate(pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, ppQueue);
4800}
4801
4802/**
4803 * Initializes a PDM critical section.
4804 *
4805 * The PDM critical sections are derived from the IPRT critical sections, but
4806 * works in RC and R0 as well.
4807 *
4808 * @returns VBox status code.
4809 * @param pDevIns The device instance.
4810 * @param pCritSect Pointer to the critical section.
4811 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
4812 * @param pszNameFmt Format string for naming the critical section.
4813 * For statistics and lock validation.
4814 * @param ... Arguments for the format string.
4815 */
4816DECLINLINE(int) PDMDevHlpCritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL, const char *pszNameFmt, ...)
4817{
4818 int rc;
4819 va_list va;
4820 va_start(va, pszNameFmt);
4821 rc = pDevIns->pHlpR3->pfnCritSectInit(pDevIns, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
4822 va_end(va);
4823 return rc;
4824}
4825
4826/**
4827 * @copydoc PDMDEVHLPR3::pfnCritSectGetNop
4828 */
4829DECLINLINE(PPDMCRITSECT) PDMDevHlpCritSectGetNop(PPDMDEVINS pDevIns)
4830{
4831 return pDevIns->pHlpR3->pfnCritSectGetNop(pDevIns);
4832}
4833
4834/**
4835 * @copydoc PDMDEVHLPR3::pfnCritSectGetNopR0
4836 */
4837DECLINLINE(R0PTRTYPE(PPDMCRITSECT)) PDMDevHlpCritSectGetNopR0(PPDMDEVINS pDevIns)
4838{
4839 return pDevIns->pHlpR3->pfnCritSectGetNopR0(pDevIns);
4840}
4841
4842/**
4843 * @copydoc PDMDEVHLPR3::pfnCritSectGetNopRC
4844 */
4845DECLINLINE(RCPTRTYPE(PPDMCRITSECT)) PDMDevHlpCritSectGetNopRC(PPDMDEVINS pDevIns)
4846{
4847 return pDevIns->pHlpR3->pfnCritSectGetNopRC(pDevIns);
4848}
4849
4850/**
4851 * @copydoc PDMDEVHLPR3::pfnSetDeviceCritSect
4852 */
4853DECLINLINE(int) PDMDevHlpSetDeviceCritSect(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
4854{
4855 return pDevIns->pHlpR3->pfnSetDeviceCritSect(pDevIns, pCritSect);
4856}
4857
4858/**
4859 * @copydoc PDMDEVHLPR3::pfnThreadCreate
4860 */
4861DECLINLINE(int) PDMDevHlpThreadCreate(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
4862 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
4863{
4864 return pDevIns->pHlpR3->pfnThreadCreate(pDevIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
4865}
4866
4867/**
4868 * @copydoc PDMDEVHLPR3::pfnSetAsyncNotification
4869 */
4870DECLINLINE(int) PDMDevHlpSetAsyncNotification(PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify)
4871{
4872 return pDevIns->pHlpR3->pfnSetAsyncNotification(pDevIns, pfnAsyncNotify);
4873}
4874
4875/**
4876 * @copydoc PDMDEVHLPR3::pfnAsyncNotificationCompleted
4877 */
4878DECLINLINE(void) PDMDevHlpAsyncNotificationCompleted(PPDMDEVINS pDevIns)
4879{
4880 pDevIns->pHlpR3->pfnAsyncNotificationCompleted(pDevIns);
4881}
4882
4883/**
4884 * @copydoc PDMDEVHLPR3::pfnA20Set
4885 */
4886DECLINLINE(void) PDMDevHlpA20Set(PPDMDEVINS pDevIns, bool fEnable)
4887{
4888 pDevIns->pHlpR3->pfnA20Set(pDevIns, fEnable);
4889}
4890
4891/**
4892 * @copydoc PDMDEVHLPR3::pfnRTCRegister
4893 */
4894DECLINLINE(int) PDMDevHlpRTCRegister(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp)
4895{
4896 return pDevIns->pHlpR3->pfnRTCRegister(pDevIns, pRtcReg, ppRtcHlp);
4897}
4898
4899/**
4900 * @copydoc PDMDEVHLPR3::pfnPCIBusRegister
4901 */
4902DECLINLINE(int) PDMDevHlpPCIBusRegister(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3)
4903{
4904 return pDevIns->pHlpR3->pfnPCIBusRegister(pDevIns, pPciBusReg, ppPciHlpR3);
4905}
4906
4907/**
4908 * @copydoc PDMDEVHLPR3::pfnPICRegister
4909 */
4910DECLINLINE(int) PDMDevHlpPICRegister(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3)
4911{
4912 return pDevIns->pHlpR3->pfnPICRegister(pDevIns, pPicReg, ppPicHlpR3);
4913}
4914
4915/**
4916 * @copydoc PDMDEVHLPR3::pfnAPICRegister
4917 */
4918DECLINLINE(int) PDMDevHlpAPICRegister(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3)
4919{
4920 return pDevIns->pHlpR3->pfnAPICRegister(pDevIns, pApicReg, ppApicHlpR3);
4921}
4922
4923/**
4924 * @copydoc PDMDEVHLPR3::pfn
4925 */
4926DECLINLINE(int) PDMDevHlpIOAPICRegister(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3)
4927{
4928 return pDevIns->pHlpR3->pfnIOAPICRegister(pDevIns, pIoApicReg, ppIoApicHlpR3);
4929}
4930
4931/**
4932 * @copydoc PDMDEVHLPR3::pfnHPETRegister
4933 */
4934DECLINLINE(int) PDMDevHlpHPETRegister(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3)
4935{
4936 return pDevIns->pHlpR3->pfnHPETRegister(pDevIns, pHpetReg, ppHpetHlpR3);
4937}
4938
4939/**
4940 * @copydoc PDMDEVHLPR3::pfnPciRawRegister
4941 */
4942DECLINLINE(int) PDMDevHlpPciRawRegister(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3)
4943{
4944 return pDevIns->pHlpR3->pfnPciRawRegister(pDevIns, pPciRawReg, ppPciRawHlpR3);
4945}
4946
4947/**
4948 * @copydoc PDMDEVHLPR3::pfnDMACRegister
4949 */
4950DECLINLINE(int) PDMDevHlpDMACRegister(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp)
4951{
4952 return pDevIns->pHlpR3->pfnDMACRegister(pDevIns, pDmacReg, ppDmacHlp);
4953}
4954
4955/**
4956 * @copydoc PDMDEVHLPR3::pfnDMARegister
4957 */
4958DECLINLINE(int) PDMDevHlpDMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
4959{
4960 return pDevIns->pHlpR3->pfnDMARegister(pDevIns, uChannel, pfnTransferHandler, pvUser);
4961}
4962
4963/**
4964 * @copydoc PDMDEVHLPR3::pfnDMAReadMemory
4965 */
4966DECLINLINE(int) PDMDevHlpDMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
4967{
4968 return pDevIns->pHlpR3->pfnDMAReadMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbRead);
4969}
4970
4971/**
4972 * @copydoc PDMDEVHLPR3::pfnDMAWriteMemory
4973 */
4974DECLINLINE(int) PDMDevHlpDMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
4975{
4976 return pDevIns->pHlpR3->pfnDMAWriteMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbWritten);
4977}
4978
4979/**
4980 * @copydoc PDMDEVHLPR3::pfnDMASetDREQ
4981 */
4982DECLINLINE(int) PDMDevHlpDMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
4983{
4984 return pDevIns->pHlpR3->pfnDMASetDREQ(pDevIns, uChannel, uLevel);
4985}
4986
4987/**
4988 * @copydoc PDMDEVHLPR3::pfnDMAGetChannelMode
4989 */
4990DECLINLINE(uint8_t) PDMDevHlpDMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
4991{
4992 return pDevIns->pHlpR3->pfnDMAGetChannelMode(pDevIns, uChannel);
4993}
4994
4995/**
4996 * @copydoc PDMDEVHLPR3::pfnDMASchedule
4997 */
4998DECLINLINE(void) PDMDevHlpDMASchedule(PPDMDEVINS pDevIns)
4999{
5000 pDevIns->pHlpR3->pfnDMASchedule(pDevIns);
5001}
5002
5003/**
5004 * @copydoc PDMDEVHLPR3::pfnCMOSWrite
5005 */
5006DECLINLINE(int) PDMDevHlpCMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
5007{
5008 return pDevIns->pHlpR3->pfnCMOSWrite(pDevIns, iReg, u8Value);
5009}
5010
5011/**
5012 * @copydoc PDMDEVHLPR3::pfnCMOSRead
5013 */
5014DECLINLINE(int) PDMDevHlpCMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
5015{
5016 return pDevIns->pHlpR3->pfnCMOSRead(pDevIns, iReg, pu8Value);
5017}
5018
5019/**
5020 * @copydoc PDMDEVHLP::pfnCallR0
5021 */
5022DECLINLINE(int) PDMDevHlpCallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
5023{
5024 return pDevIns->pHlpR3->pfnCallR0(pDevIns, uOperation, u64Arg);
5025}
5026
5027/**
5028 * @copydoc PDMDEVHLPR3::pfnGetUVM
5029 */
5030DECLINLINE(PUVM) PDMDevHlpGetUVM(PPDMDEVINS pDevIns)
5031{
5032 return pDevIns->CTX_SUFF(pHlp)->pfnGetUVM(pDevIns);
5033}
5034
5035#endif /* IN_RING3 */
5036
5037/**
5038 * @copydoc PDMDEVHLPR3::pfnGetVM
5039 */
5040DECLINLINE(PVM) PDMDevHlpGetVM(PPDMDEVINS pDevIns)
5041{
5042 return pDevIns->CTX_SUFF(pHlp)->pfnGetVM(pDevIns);
5043}
5044
5045/**
5046 * @copydoc PDMDEVHLPR3::pfnGetVMCPU
5047 */
5048DECLINLINE(PVMCPU) PDMDevHlpGetVMCPU(PPDMDEVINS pDevIns)
5049{
5050 return pDevIns->CTX_SUFF(pHlp)->pfnGetVMCPU(pDevIns);
5051}
5052
5053/**
5054 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGet
5055 */
5056DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGet(PPDMDEVINS pDevIns)
5057{
5058 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGet(pDevIns);
5059}
5060
5061/**
5062 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGetFreq
5063 */
5064DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGetFreq(PPDMDEVINS pDevIns)
5065{
5066 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGetFreq(pDevIns);
5067}
5068
5069/**
5070 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGetFreq
5071 */
5072DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGetNano(PPDMDEVINS pDevIns)
5073{
5074 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGetNano(pDevIns);
5075}
5076
5077#ifdef IN_RING3
5078
5079/**
5080 * @copydoc PDMDEVHLPR3::pfnRegisterVMMDevHeap
5081 */
5082DECLINLINE(int) PDMDevHlpRegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbSize)
5083{
5084 return pDevIns->pHlpR3->pfnRegisterVMMDevHeap(pDevIns, GCPhys, pvHeap, cbSize);
5085}
5086
5087/**
5088 * @copydoc PDMDEVHLPR3::pfnUnregisterVMMDevHeap
5089 */
5090DECLINLINE(int) PDMDevHlpUnregisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys)
5091{
5092 return pDevIns->pHlpR3->pfnUnregisterVMMDevHeap(pDevIns, GCPhys);
5093}
5094
5095/**
5096 * @copydoc PDMDEVHLPR3::pfnVMReset
5097 */
5098DECLINLINE(int) PDMDevHlpVMReset(PPDMDEVINS pDevIns)
5099{
5100 return pDevIns->pHlpR3->pfnVMReset(pDevIns);
5101}
5102
5103/**
5104 * @copydoc PDMDEVHLPR3::pfnVMSuspend
5105 */
5106DECLINLINE(int) PDMDevHlpVMSuspend(PPDMDEVINS pDevIns)
5107{
5108 return pDevIns->pHlpR3->pfnVMSuspend(pDevIns);
5109}
5110
5111/**
5112 * @copydoc PDMDEVHLPR3::pfnVMSuspendSaveAndPowerOff
5113 */
5114DECLINLINE(int) PDMDevHlpVMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
5115{
5116 return pDevIns->pHlpR3->pfnVMSuspendSaveAndPowerOff(pDevIns);
5117}
5118
5119/**
5120 * @copydoc PDMDEVHLPR3::pfnVMPowerOff
5121 */
5122DECLINLINE(int) PDMDevHlpVMPowerOff(PPDMDEVINS pDevIns)
5123{
5124 return pDevIns->pHlpR3->pfnVMPowerOff(pDevIns);
5125}
5126
5127#endif /* IN_RING3 */
5128
5129/**
5130 * @copydoc PDMDEVHLPR3::pfnA20IsEnabled
5131 */
5132DECLINLINE(bool) PDMDevHlpA20IsEnabled(PPDMDEVINS pDevIns)
5133{
5134 return pDevIns->CTX_SUFF(pHlp)->pfnA20IsEnabled(pDevIns);
5135}
5136
5137#ifdef IN_RING3
5138
5139/**
5140 * @copydoc PDMDEVHLPR3::pfnGetCpuId
5141 */
5142DECLINLINE(void) PDMDevHlpGetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
5143{
5144 pDevIns->pHlpR3->pfnGetCpuId(pDevIns, iLeaf, pEax, pEbx, pEcx, pEdx);
5145}
5146
5147#endif /* IN_RING3 */
5148#ifdef IN_RING0
5149
5150/**
5151 * @copydoc PDMDEVHLPR0::pfnCanEmulateIoBlock
5152 */
5153DECLINLINE(bool) PDMDevHlpCanEmulateIoBlock(PPDMDEVINS pDevIns)
5154{
5155 return pDevIns->CTX_SUFF(pHlp)->pfnCanEmulateIoBlock(pDevIns);
5156}
5157
5158#endif /* IN_RING0 */
5159
5160
5161
5162
5163/** Pointer to callbacks provided to the VBoxDeviceRegister() call. */
5164typedef struct PDMDEVREGCB *PPDMDEVREGCB;
5165
5166/**
5167 * Callbacks for VBoxDeviceRegister().
5168 */
5169typedef struct PDMDEVREGCB
5170{
5171 /** Interface version.
5172 * This is set to PDM_DEVREG_CB_VERSION. */
5173 uint32_t u32Version;
5174
5175 /**
5176 * Registers a device with the current VM instance.
5177 *
5178 * @returns VBox status code.
5179 * @param pCallbacks Pointer to the callback table.
5180 * @param pReg Pointer to the device registration record.
5181 * This data must be permanent and readonly.
5182 */
5183 DECLR3CALLBACKMEMBER(int, pfnRegister,(PPDMDEVREGCB pCallbacks, PCPDMDEVREG pReg));
5184} PDMDEVREGCB;
5185
5186/** Current version of the PDMDEVREGCB structure. */
5187#define PDM_DEVREG_CB_VERSION PDM_VERSION_MAKE(0xffe3, 1, 0)
5188
5189
5190/**
5191 * The VBoxDevicesRegister callback function.
5192 *
5193 * PDM will invoke this function after loading a device module and letting
5194 * the module decide which devices to register and how to handle conflicts.
5195 *
5196 * @returns VBox status code.
5197 * @param pCallbacks Pointer to the callback table.
5198 * @param u32Version VBox version number.
5199 */
5200typedef DECLCALLBACK(int) FNPDMVBOXDEVICESREGISTER(PPDMDEVREGCB pCallbacks, uint32_t u32Version);
5201
5202/** @} */
5203
5204RT_C_DECLS_END
5205
5206#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