VirtualBox

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

Last change on this file since 68470 was 68470, checked in by vboxsync, 8 years ago

PDM: add new PDM device helper for sending a MSI directly (from all contexts, as all contexts support such interrupt delivery)

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