VirtualBox

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

Last change on this file since 81950 was 81950, checked in by vboxsync, 6 years ago

pdmdev.h: Doxygen comment. bugref:9218

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 336.9 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Devices.
3 */
4
5/*
6 * Copyright (C) 2006-2019 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_INCLUDED_vmm_pdmdev_h
27#define VBOX_INCLUDED_vmm_pdmdev_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/vmm/pdmcritsect.h>
33#include <VBox/vmm/pdmqueue.h>
34#include <VBox/vmm/pdmtask.h>
35#ifdef IN_RING3
36# include <VBox/vmm/pdmthread.h>
37#endif
38#include <VBox/vmm/pdmifs.h>
39#include <VBox/vmm/pdmins.h>
40#include <VBox/vmm/pdmcommon.h>
41#include <VBox/vmm/pdmpcidev.h>
42#include <VBox/vmm/iom.h>
43#include <VBox/vmm/tm.h>
44#include <VBox/vmm/ssm.h>
45#include <VBox/vmm/cfgm.h>
46#include <VBox/vmm/dbgf.h>
47#include <VBox/err.h> /* VINF_EM_DBG_STOP, also 120+ source files expecting this. */
48#include <iprt/stdarg.h>
49#include <iprt/list.h>
50
51
52RT_C_DECLS_BEGIN
53
54/** @defgroup grp_pdm_device The PDM Devices API
55 * @ingroup grp_pdm
56 * @{
57 */
58
59/**
60 * Construct a device instance for a VM.
61 *
62 * @returns VBox status.
63 * @param pDevIns The device instance data. If the registration structure
64 * is needed, it can be accessed thru pDevIns->pReg.
65 * @param iInstance Instance number. Use this to figure out which registers
66 * and such to use. The instance number is also found in
67 * pDevIns->iInstance, but since it's likely to be
68 * frequently used PDM passes it as parameter.
69 * @param pCfg Configuration node handle for the driver. This is
70 * expected to be in high demand in the constructor and is
71 * therefore passed as an argument. When using it at other
72 * times, it can be found in pDevIns->pCfg.
73 */
74typedef DECLCALLBACK(int) FNPDMDEVCONSTRUCT(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg);
75/** Pointer to a FNPDMDEVCONSTRUCT() function. */
76typedef FNPDMDEVCONSTRUCT *PFNPDMDEVCONSTRUCT;
77
78/**
79 * Destruct a device instance.
80 *
81 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
82 * resources can be freed correctly.
83 *
84 * @returns VBox status.
85 * @param pDevIns The device instance data.
86 *
87 * @remarks The device critical section is not entered. The routine may delete
88 * the critical section, so the caller cannot exit it.
89 */
90typedef DECLCALLBACK(int) FNPDMDEVDESTRUCT(PPDMDEVINS pDevIns);
91/** Pointer to a FNPDMDEVDESTRUCT() function. */
92typedef FNPDMDEVDESTRUCT *PFNPDMDEVDESTRUCT;
93
94/**
95 * Device relocation callback.
96 *
97 * This is called when the instance data has been relocated in raw-mode context
98 * (RC). It is also called when the RC hypervisor selects changes. The device
99 * must fixup all necessary pointers and re-query all interfaces to other RC
100 * devices and drivers.
101 *
102 * Before the RC code is executed the first time, this function will be called
103 * with a 0 delta so RC pointer calculations can be one in one place.
104 *
105 * @param pDevIns Pointer to the device instance.
106 * @param offDelta The relocation delta relative to the old location.
107 *
108 * @remarks A relocation CANNOT fail.
109 *
110 * @remarks The device critical section is not entered. The relocations should
111 * not normally require any locking.
112 */
113typedef DECLCALLBACK(void) FNPDMDEVRELOCATE(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
114/** Pointer to a FNPDMDEVRELOCATE() function. */
115typedef FNPDMDEVRELOCATE *PFNPDMDEVRELOCATE;
116
117/**
118 * Power On notification.
119 *
120 * @returns VBox status.
121 * @param pDevIns The device instance data.
122 *
123 * @remarks Caller enters the device critical section.
124 */
125typedef DECLCALLBACK(void) FNPDMDEVPOWERON(PPDMDEVINS pDevIns);
126/** Pointer to a FNPDMDEVPOWERON() function. */
127typedef FNPDMDEVPOWERON *PFNPDMDEVPOWERON;
128
129/**
130 * Reset notification.
131 *
132 * @returns VBox status.
133 * @param pDevIns The device instance data.
134 *
135 * @remarks Caller enters the device critical section.
136 */
137typedef DECLCALLBACK(void) FNPDMDEVRESET(PPDMDEVINS pDevIns);
138/** Pointer to a FNPDMDEVRESET() function. */
139typedef FNPDMDEVRESET *PFNPDMDEVRESET;
140
141/**
142 * Soft reset notification.
143 *
144 * This is mainly for emulating the 286 style protected mode exits, in which
145 * most devices should remain in their current state.
146 *
147 * @returns VBox status.
148 * @param pDevIns The device instance data.
149 * @param fFlags PDMVMRESET_F_XXX (only bits relevant to soft resets).
150 *
151 * @remarks Caller enters the device critical section.
152 */
153typedef DECLCALLBACK(void) FNPDMDEVSOFTRESET(PPDMDEVINS pDevIns, uint32_t fFlags);
154/** Pointer to a FNPDMDEVSOFTRESET() function. */
155typedef FNPDMDEVSOFTRESET *PFNPDMDEVSOFTRESET;
156
157/** @name PDMVMRESET_F_XXX - VM reset flags.
158 * These flags are used both for FNPDMDEVSOFTRESET and for hardware signalling
159 * reset via PDMDevHlpVMReset.
160 * @{ */
161/** Unknown reason. */
162#define PDMVMRESET_F_UNKNOWN UINT32_C(0x00000000)
163/** GIM triggered reset. */
164#define PDMVMRESET_F_GIM UINT32_C(0x00000001)
165/** The last source always causing hard resets. */
166#define PDMVMRESET_F_LAST_ALWAYS_HARD PDMVMRESET_F_GIM
167/** ACPI triggered reset. */
168#define PDMVMRESET_F_ACPI UINT32_C(0x0000000c)
169/** PS/2 system port A (92h) reset. */
170#define PDMVMRESET_F_PORT_A UINT32_C(0x0000000d)
171/** Keyboard reset. */
172#define PDMVMRESET_F_KBD UINT32_C(0x0000000e)
173/** Tripple fault. */
174#define PDMVMRESET_F_TRIPLE_FAULT UINT32_C(0x0000000f)
175/** Reset source mask. */
176#define PDMVMRESET_F_SRC_MASK UINT32_C(0x0000000f)
177/** @} */
178
179/**
180 * Suspend notification.
181 *
182 * @returns VBox status.
183 * @param pDevIns The device instance data.
184 * @thread EMT(0)
185 *
186 * @remarks Caller enters the device critical section.
187 */
188typedef DECLCALLBACK(void) FNPDMDEVSUSPEND(PPDMDEVINS pDevIns);
189/** Pointer to a FNPDMDEVSUSPEND() function. */
190typedef FNPDMDEVSUSPEND *PFNPDMDEVSUSPEND;
191
192/**
193 * Resume notification.
194 *
195 * @returns VBox status.
196 * @param pDevIns The device instance data.
197 *
198 * @remarks Caller enters the device critical section.
199 */
200typedef DECLCALLBACK(void) FNPDMDEVRESUME(PPDMDEVINS pDevIns);
201/** Pointer to a FNPDMDEVRESUME() function. */
202typedef FNPDMDEVRESUME *PFNPDMDEVRESUME;
203
204/**
205 * Power Off notification.
206 *
207 * This is always called when VMR3PowerOff is called.
208 * There will be no callback when hot plugging devices.
209 *
210 * @param pDevIns The device instance data.
211 * @thread EMT(0)
212 *
213 * @remarks Caller enters the device critical section.
214 */
215typedef DECLCALLBACK(void) FNPDMDEVPOWEROFF(PPDMDEVINS pDevIns);
216/** Pointer to a FNPDMDEVPOWEROFF() function. */
217typedef FNPDMDEVPOWEROFF *PFNPDMDEVPOWEROFF;
218
219/**
220 * Attach command.
221 *
222 * This is called to let the device attach to a driver for a specified LUN
223 * at runtime. This is not called during VM construction, the device
224 * constructor has to attach to all the available drivers.
225 *
226 * This is like plugging in the keyboard or mouse after turning on the PC.
227 *
228 * @returns VBox status code.
229 * @param pDevIns The device instance.
230 * @param iLUN The logical unit which is being attached.
231 * @param fFlags Flags, combination of the PDM_TACH_FLAGS_* \#defines.
232 *
233 * @remarks Caller enters the device critical section.
234 */
235typedef DECLCALLBACK(int) FNPDMDEVATTACH(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
236/** Pointer to a FNPDMDEVATTACH() function. */
237typedef FNPDMDEVATTACH *PFNPDMDEVATTACH;
238
239/**
240 * Detach notification.
241 *
242 * This is called when a driver is detaching itself from a LUN of the device.
243 * The device should adjust its state to reflect this.
244 *
245 * This is like unplugging the network cable to use it for the laptop or
246 * something while the PC is still running.
247 *
248 * @param pDevIns The device instance.
249 * @param iLUN The logical unit which is being detached.
250 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
251 *
252 * @remarks Caller enters the device critical section.
253 */
254typedef DECLCALLBACK(void) FNPDMDEVDETACH(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags);
255/** Pointer to a FNPDMDEVDETACH() function. */
256typedef FNPDMDEVDETACH *PFNPDMDEVDETACH;
257
258/**
259 * Query the base interface of a logical unit.
260 *
261 * @returns VBOX status code.
262 * @param pDevIns The device instance.
263 * @param iLUN The logicial unit to query.
264 * @param ppBase Where to store the pointer to the base interface of the LUN.
265 *
266 * @remarks The device critical section is not entered.
267 */
268typedef DECLCALLBACK(int) FNPDMDEVQUERYINTERFACE(PPDMDEVINS pDevIns, unsigned iLUN, PPDMIBASE *ppBase);
269/** Pointer to a FNPDMDEVQUERYINTERFACE() function. */
270typedef FNPDMDEVQUERYINTERFACE *PFNPDMDEVQUERYINTERFACE;
271
272/**
273 * Init complete notification (after ring-0 & RC init since 5.1).
274 *
275 * This can be done to do communication with other devices and other
276 * initialization which requires everything to be in place.
277 *
278 * @returns VBOX status code.
279 * @param pDevIns The device instance.
280 *
281 * @remarks Caller enters the device critical section.
282 */
283typedef DECLCALLBACK(int) FNPDMDEVINITCOMPLETE(PPDMDEVINS pDevIns);
284/** Pointer to a FNPDMDEVINITCOMPLETE() function. */
285typedef FNPDMDEVINITCOMPLETE *PFNPDMDEVINITCOMPLETE;
286
287
288/**
289 * The context of a pfnMemSetup call.
290 */
291typedef enum PDMDEVMEMSETUPCTX
292{
293 /** Invalid zero value. */
294 PDMDEVMEMSETUPCTX_INVALID = 0,
295 /** After construction. */
296 PDMDEVMEMSETUPCTX_AFTER_CONSTRUCTION,
297 /** After reset. */
298 PDMDEVMEMSETUPCTX_AFTER_RESET,
299 /** Type size hack. */
300 PDMDEVMEMSETUPCTX_32BIT_HACK = 0x7fffffff
301} PDMDEVMEMSETUPCTX;
302
303
304/**
305 * PDM Device Registration Structure.
306 *
307 * This structure is used when registering a device from VBoxInitDevices() in HC
308 * Ring-3. PDM will continue use till the VM is terminated.
309 *
310 * @note The first part is the same in every context.
311 */
312typedef struct PDMDEVREGR3
313{
314 /** Structure version. PDM_DEVREGR3_VERSION defines the current version. */
315 uint32_t u32Version;
316 /** Reserved, must be zero. */
317 uint32_t uReserved0;
318 /** Device name, must match the ring-3 one. */
319 char szName[32];
320 /** Flags, combination of the PDM_DEVREG_FLAGS_* \#defines. */
321 uint32_t fFlags;
322 /** Device class(es), combination of the PDM_DEVREG_CLASS_* \#defines. */
323 uint32_t fClass;
324 /** Maximum number of instances (per VM). */
325 uint32_t cMaxInstances;
326 /** The shared data structure version number. */
327 uint32_t uSharedVersion;
328 /** Size of the instance data. */
329 uint32_t cbInstanceShared;
330 /** Size of the ring-0 instance data. */
331 uint32_t cbInstanceCC;
332 /** Size of the raw-mode instance data. */
333 uint32_t cbInstanceRC;
334 /** Max number of PCI devices. */
335 uint16_t cMaxPciDevices;
336 /** Max number of MSI-X vectors in any of the PCI devices. */
337 uint16_t cMaxMsixVectors;
338 /** The description of the device. The UTF-8 string pointed to shall, like this structure,
339 * remain unchanged from registration till VM destruction. */
340 const char *pszDescription;
341
342 /** Name of the raw-mode context module (no path).
343 * Only evalutated if PDM_DEVREG_FLAGS_RC is set. */
344 const char *pszRCMod;
345 /** Name of the ring-0 module (no path).
346 * Only evalutated if PDM_DEVREG_FLAGS_R0 is set. */
347 const char *pszR0Mod;
348
349 /** Construct instance - required. */
350 PFNPDMDEVCONSTRUCT pfnConstruct;
351 /** Destruct instance - optional.
352 * Critical section NOT entered (will be destroyed). */
353 PFNPDMDEVDESTRUCT pfnDestruct;
354 /** Relocation command - optional.
355 * Critical section NOT entered. */
356 PFNPDMDEVRELOCATE pfnRelocate;
357 /**
358 * Memory setup callback.
359 *
360 * @param pDevIns The device instance data.
361 * @param enmCtx Indicates the context of the call.
362 * @remarks The critical section is entered prior to calling this method.
363 */
364 DECLR3CALLBACKMEMBER(void, pfnMemSetup, (PPDMDEVINS pDevIns, PDMDEVMEMSETUPCTX enmCtx));
365 /** Power on notification - optional.
366 * Critical section is entered. */
367 PFNPDMDEVPOWERON pfnPowerOn;
368 /** Reset notification - optional.
369 * Critical section is entered. */
370 PFNPDMDEVRESET pfnReset;
371 /** Suspend notification - optional.
372 * Critical section is entered. */
373 PFNPDMDEVSUSPEND pfnSuspend;
374 /** Resume notification - optional.
375 * Critical section is entered. */
376 PFNPDMDEVRESUME pfnResume;
377 /** Attach command - optional.
378 * Critical section is entered. */
379 PFNPDMDEVATTACH pfnAttach;
380 /** Detach notification - optional.
381 * Critical section is entered. */
382 PFNPDMDEVDETACH pfnDetach;
383 /** Query a LUN base interface - optional.
384 * Critical section is NOT entered. */
385 PFNPDMDEVQUERYINTERFACE pfnQueryInterface;
386 /** Init complete notification - optional.
387 * Critical section is entered. */
388 PFNPDMDEVINITCOMPLETE pfnInitComplete;
389 /** Power off notification - optional.
390 * Critical section is entered. */
391 PFNPDMDEVPOWEROFF pfnPowerOff;
392 /** Software system reset notification - optional.
393 * Critical section is entered. */
394 PFNPDMDEVSOFTRESET pfnSoftReset;
395
396 /** @name Reserved for future extensions, must be zero.
397 * @{ */
398 DECLR3CALLBACKMEMBER(int, pfnReserved0, (PPDMDEVINS pDevIns));
399 DECLR3CALLBACKMEMBER(int, pfnReserved1, (PPDMDEVINS pDevIns));
400 DECLR3CALLBACKMEMBER(int, pfnReserved2, (PPDMDEVINS pDevIns));
401 DECLR3CALLBACKMEMBER(int, pfnReserved3, (PPDMDEVINS pDevIns));
402 DECLR3CALLBACKMEMBER(int, pfnReserved4, (PPDMDEVINS pDevIns));
403 DECLR3CALLBACKMEMBER(int, pfnReserved5, (PPDMDEVINS pDevIns));
404 DECLR3CALLBACKMEMBER(int, pfnReserved6, (PPDMDEVINS pDevIns));
405 DECLR3CALLBACKMEMBER(int, pfnReserved7, (PPDMDEVINS pDevIns));
406 /** @} */
407
408 /** Initialization safty marker. */
409 uint32_t u32VersionEnd;
410} PDMDEVREGR3;
411/** Pointer to a PDM Device Structure. */
412typedef PDMDEVREGR3 *PPDMDEVREGR3;
413/** Const pointer to a PDM Device Structure. */
414typedef PDMDEVREGR3 const *PCPDMDEVREGR3;
415/** Current DEVREGR3 version number. */
416#define PDM_DEVREGR3_VERSION PDM_VERSION_MAKE(0xffff, 4, 0)
417
418
419/** PDM Device Flags.
420 * @{ */
421/** This flag is used to indicate that the device has a R0 component. */
422#define PDM_DEVREG_FLAGS_R0 UINT32_C(0x00000001)
423/** Requires the ring-0 component, ignore configuration values. */
424#define PDM_DEVREG_FLAGS_REQUIRE_R0 UINT32_C(0x00000002)
425/** Requires the ring-0 component, ignore configuration values. */
426#define PDM_DEVREG_FLAGS_OPT_IN_R0 UINT32_C(0x00000004)
427
428/** This flag is used to indicate that the device has a RC component. */
429#define PDM_DEVREG_FLAGS_RC UINT32_C(0x00000010)
430/** Requires the raw-mode component, ignore configuration values. */
431#define PDM_DEVREG_FLAGS_REQUIRE_RC UINT32_C(0x00000020)
432/** Requires the raw-mode component, ignore configuration values. */
433#define PDM_DEVREG_FLAGS_OPT_IN_RC UINT32_C(0x00000040)
434
435/** Convenience: PDM_DEVREG_FLAGS_R0 + PDM_DEVREG_FLAGS_RC */
436#define PDM_DEVREG_FLAGS_RZ (PDM_DEVREG_FLAGS_R0 | PDM_DEVREG_FLAGS_RC)
437
438/** @def PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT
439 * The bit count for the current host.
440 * @note Superfluous, but still around for hysterical raisins. */
441#if HC_ARCH_BITS == 32
442# define PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT UINT32_C(0x00000100)
443#elif HC_ARCH_BITS == 64
444# define PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT UINT32_C(0x00000200)
445#else
446# error Unsupported HC_ARCH_BITS value.
447#endif
448/** The host bit count mask. */
449#define PDM_DEVREG_FLAGS_HOST_BITS_MASK UINT32_C(0x00000300)
450
451/** The device support only 32-bit guests. */
452#define PDM_DEVREG_FLAGS_GUEST_BITS_32 UINT32_C(0x00001000)
453/** The device support only 64-bit guests. */
454#define PDM_DEVREG_FLAGS_GUEST_BITS_64 UINT32_C(0x00002000)
455/** The device support both 32-bit & 64-bit guests. */
456#define PDM_DEVREG_FLAGS_GUEST_BITS_32_64 UINT32_C(0x00003000)
457/** @def PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT
458 * The guest bit count for the current compilation. */
459#if GC_ARCH_BITS == 32
460# define PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT PDM_DEVREG_FLAGS_GUEST_BITS_32
461#elif GC_ARCH_BITS == 64
462# define PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT PDM_DEVREG_FLAGS_GUEST_BITS_32_64
463#else
464# error Unsupported GC_ARCH_BITS value.
465#endif
466/** The guest bit count mask. */
467#define PDM_DEVREG_FLAGS_GUEST_BITS_MASK UINT32_C(0x00003000)
468
469/** A convenience. */
470#define PDM_DEVREG_FLAGS_DEFAULT_BITS (PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT | PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT)
471
472/** Indicates that the device needs to be notified before the drivers when suspending. */
473#define PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION UINT32_C(0x00010000)
474/** Indicates that the device needs to be notified before the drivers when powering off. */
475#define PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION UINT32_C(0x00020000)
476/** Indicates that the device needs to be notified before the drivers when resetting. */
477#define PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION UINT32_C(0x00040000)
478
479/** This flag is used to indicate that the device has been converted to the
480 * new device style. */
481#define PDM_DEVREG_FLAGS_NEW_STYLE UINT32_C(0x80000000)
482
483/** @} */
484
485
486/** PDM Device Classes.
487 * The order is important, lower bit earlier instantiation.
488 * @{ */
489/** Architecture device. */
490#define PDM_DEVREG_CLASS_ARCH RT_BIT(0)
491/** Architecture BIOS device. */
492#define PDM_DEVREG_CLASS_ARCH_BIOS RT_BIT(1)
493/** PCI bus brigde. */
494#define PDM_DEVREG_CLASS_BUS_PCI RT_BIT(2)
495/** ISA bus brigde. */
496#define PDM_DEVREG_CLASS_BUS_ISA RT_BIT(3)
497/** Input device (mouse, keyboard, joystick, HID, ...). */
498#define PDM_DEVREG_CLASS_INPUT RT_BIT(4)
499/** Interrupt controller (PIC). */
500#define PDM_DEVREG_CLASS_PIC RT_BIT(5)
501/** Interval controoler (PIT). */
502#define PDM_DEVREG_CLASS_PIT RT_BIT(6)
503/** RTC/CMOS. */
504#define PDM_DEVREG_CLASS_RTC RT_BIT(7)
505/** DMA controller. */
506#define PDM_DEVREG_CLASS_DMA RT_BIT(8)
507/** VMM Device. */
508#define PDM_DEVREG_CLASS_VMM_DEV RT_BIT(9)
509/** Graphics device, like VGA. */
510#define PDM_DEVREG_CLASS_GRAPHICS RT_BIT(10)
511/** Storage controller device. */
512#define PDM_DEVREG_CLASS_STORAGE RT_BIT(11)
513/** Network interface controller. */
514#define PDM_DEVREG_CLASS_NETWORK RT_BIT(12)
515/** Audio. */
516#define PDM_DEVREG_CLASS_AUDIO RT_BIT(13)
517/** USB HIC. */
518#define PDM_DEVREG_CLASS_BUS_USB RT_BIT(14)
519/** ACPI. */
520#define PDM_DEVREG_CLASS_ACPI RT_BIT(15)
521/** Serial controller device. */
522#define PDM_DEVREG_CLASS_SERIAL RT_BIT(16)
523/** Parallel controller device */
524#define PDM_DEVREG_CLASS_PARALLEL RT_BIT(17)
525/** Host PCI pass-through device */
526#define PDM_DEVREG_CLASS_HOST_DEV RT_BIT(18)
527/** Misc devices (always last). */
528#define PDM_DEVREG_CLASS_MISC RT_BIT(31)
529/** @} */
530
531
532/**
533 * PDM Device Registration Structure, ring-0.
534 *
535 * This structure is used when registering a device from VBoxInitDevices() in HC
536 * Ring-0. PDM will continue use till the VM is terminated.
537 */
538typedef struct PDMDEVREGR0
539{
540 /** Structure version. PDM_DEVREGR0_VERSION defines the current version. */
541 uint32_t u32Version;
542 /** Reserved, must be zero. */
543 uint32_t uReserved0;
544 /** Device name, must match the ring-3 one. */
545 char szName[32];
546 /** Flags, combination of the PDM_DEVREG_FLAGS_* \#defines. */
547 uint32_t fFlags;
548 /** Device class(es), combination of the PDM_DEVREG_CLASS_* \#defines. */
549 uint32_t fClass;
550 /** Maximum number of instances (per VM). */
551 uint32_t cMaxInstances;
552 /** The shared data structure version number. */
553 uint32_t uSharedVersion;
554 /** Size of the instance data. */
555 uint32_t cbInstanceShared;
556 /** Size of the ring-0 instance data. */
557 uint32_t cbInstanceCC;
558 /** Size of the raw-mode instance data. */
559 uint32_t cbInstanceRC;
560 /** Max number of PCI devices. */
561 uint16_t cMaxPciDevices;
562 /** Max number of MSI-X vectors in any of the PCI devices. */
563 uint16_t cMaxMsixVectors;
564 /** The description of the device. The UTF-8 string pointed to shall, like this structure,
565 * remain unchanged from registration till VM destruction. */
566 const char *pszDescription;
567
568 /**
569 * Early construction callback (optional).
570 *
571 * This is called right after the device instance structure has been allocated
572 * and before the ring-3 constructor gets called.
573 *
574 * @returns VBox status code.
575 * @param pDevIns The device instance data.
576 * @note The destructure is always called, regardless of the return status.
577 */
578 DECLR0CALLBACKMEMBER(int, pfnEarlyConstruct, (PPDMDEVINS pDevIns));
579
580 /**
581 * Regular construction callback (optional).
582 *
583 * This is called after (or during) the ring-3 constructor.
584 *
585 * @returns VBox status code.
586 * @param pDevIns The device instance data.
587 * @note The destructure is always called, regardless of the return status.
588 */
589 DECLR0CALLBACKMEMBER(int, pfnConstruct, (PPDMDEVINS pDevIns));
590
591 /**
592 * Destructor (optional).
593 *
594 * This is called after the ring-3 destruction. This is not called if ring-3
595 * fails to trigger it (e.g. process is killed or crashes).
596 *
597 * @param pDevIns The device instance data.
598 */
599 DECLR0CALLBACKMEMBER(void, pfnDestruct, (PPDMDEVINS pDevIns));
600
601 /**
602 * Final destructor (optional).
603 *
604 * This is called right before the memory is freed, which happens when the
605 * VM/GVM object is destroyed. This is always called.
606 *
607 * @param pDevIns The device instance data.
608 */
609 DECLR0CALLBACKMEMBER(void, pfnFinalDestruct, (PPDMDEVINS pDevIns));
610
611 /**
612 * Generic request handler (optional).
613 *
614 * @param pDevIns The device instance data.
615 * @param uReq Device specific request.
616 * @param uArg Request argument.
617 */
618 DECLR0CALLBACKMEMBER(int, pfnRequest, (PPDMDEVINS pDevIns, uint32_t uReq, uint64_t uArg));
619
620 /** @name Reserved for future extensions, must be zero.
621 * @{ */
622 DECLR0CALLBACKMEMBER(int, pfnReserved0, (PPDMDEVINS pDevIns));
623 DECLR0CALLBACKMEMBER(int, pfnReserved1, (PPDMDEVINS pDevIns));
624 DECLR0CALLBACKMEMBER(int, pfnReserved2, (PPDMDEVINS pDevIns));
625 DECLR0CALLBACKMEMBER(int, pfnReserved3, (PPDMDEVINS pDevIns));
626 DECLR0CALLBACKMEMBER(int, pfnReserved4, (PPDMDEVINS pDevIns));
627 DECLR0CALLBACKMEMBER(int, pfnReserved5, (PPDMDEVINS pDevIns));
628 DECLR0CALLBACKMEMBER(int, pfnReserved6, (PPDMDEVINS pDevIns));
629 DECLR0CALLBACKMEMBER(int, pfnReserved7, (PPDMDEVINS pDevIns));
630 /** @} */
631
632 /** Initialization safty marker. */
633 uint32_t u32VersionEnd;
634} PDMDEVREGR0;
635/** Pointer to a ring-0 PDM device registration structure. */
636typedef PDMDEVREGR0 *PPDMDEVREGR0;
637/** Pointer to a const ring-0 PDM device registration structure. */
638typedef PDMDEVREGR0 const *PCPDMDEVREGR0;
639/** Current DEVREGR0 version number. */
640#define PDM_DEVREGR0_VERSION PDM_VERSION_MAKE(0xff80, 1, 0)
641
642
643/**
644 * PDM Device Registration Structure, raw-mode
645 *
646 * At the moment, this structure is mostly here to match the other two contexts.
647 */
648typedef struct PDMDEVREGRC
649{
650 /** Structure version. PDM_DEVREGRC_VERSION defines the current version. */
651 uint32_t u32Version;
652 /** Reserved, must be zero. */
653 uint32_t uReserved0;
654 /** Device name, must match the ring-3 one. */
655 char szName[32];
656 /** Flags, combination of the PDM_DEVREG_FLAGS_* \#defines. */
657 uint32_t fFlags;
658 /** Device class(es), combination of the PDM_DEVREG_CLASS_* \#defines. */
659 uint32_t fClass;
660 /** Maximum number of instances (per VM). */
661 uint32_t cMaxInstances;
662 /** The shared data structure version number. */
663 uint32_t uSharedVersion;
664 /** Size of the instance data. */
665 uint32_t cbInstanceShared;
666 /** Size of the ring-0 instance data. */
667 uint32_t cbInstanceCC;
668 /** Size of the raw-mode instance data. */
669 uint32_t cbInstanceRC;
670 /** Max number of PCI devices. */
671 uint16_t cMaxPciDevices;
672 /** Max number of MSI-X vectors in any of the PCI devices. */
673 uint16_t cMaxMsixVectors;
674 /** The description of the device. The UTF-8 string pointed to shall, like this structure,
675 * remain unchanged from registration till VM destruction. */
676 const char *pszDescription;
677
678 /**
679 * Constructor callback.
680 *
681 * This is called much later than both the ring-0 and ring-3 constructors, since
682 * raw-mode v2 require a working VMM to run actual code.
683 *
684 * @returns VBox status code.
685 * @param pDevIns The device instance data.
686 * @note The destructure is always called, regardless of the return status.
687 */
688 DECLRGCALLBACKMEMBER(int, pfnConstruct, (PPDMDEVINS pDevIns));
689
690 /** @name Reserved for future extensions, must be zero.
691 * @{ */
692 DECLRCCALLBACKMEMBER(int, pfnReserved0, (PPDMDEVINS pDevIns));
693 DECLRCCALLBACKMEMBER(int, pfnReserved1, (PPDMDEVINS pDevIns));
694 DECLRCCALLBACKMEMBER(int, pfnReserved2, (PPDMDEVINS pDevIns));
695 DECLRCCALLBACKMEMBER(int, pfnReserved3, (PPDMDEVINS pDevIns));
696 DECLRCCALLBACKMEMBER(int, pfnReserved4, (PPDMDEVINS pDevIns));
697 DECLRCCALLBACKMEMBER(int, pfnReserved5, (PPDMDEVINS pDevIns));
698 DECLRCCALLBACKMEMBER(int, pfnReserved6, (PPDMDEVINS pDevIns));
699 DECLRCCALLBACKMEMBER(int, pfnReserved7, (PPDMDEVINS pDevIns));
700 /** @} */
701
702 /** Initialization safty marker. */
703 uint32_t u32VersionEnd;
704} PDMDEVREGRC;
705/** Pointer to a raw-mode PDM device registration structure. */
706typedef PDMDEVREGRC *PPDMDEVREGRC;
707/** Pointer to a const raw-mode PDM device registration structure. */
708typedef PDMDEVREGRC const *PCPDMDEVREGRC;
709/** Current DEVREGRC version number. */
710#define PDM_DEVREGRC_VERSION PDM_VERSION_MAKE(0xff81, 1, 0)
711
712
713
714/** @def PDM_DEVREG_VERSION
715 * Current DEVREG version number. */
716/** @typedef PDMDEVREGR3
717 * A current context PDM device registration structure. */
718/** @typedef PPDMDEVREGR3
719 * Pointer to a current context PDM device registration structure. */
720/** @typedef PCPDMDEVREGR3
721 * Pointer to a const current context PDM device registration structure. */
722#if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
723# define PDM_DEVREG_VERSION PDM_DEVREGR3_VERSION
724typedef PDMDEVREGR3 PDMDEVREG;
725typedef PPDMDEVREGR3 PPDMDEVREG;
726typedef PCPDMDEVREGR3 PCPDMDEVREG;
727#elif defined(IN_RING0)
728# define PDM_DEVREG_VERSION PDM_DEVREGR0_VERSION
729typedef PDMDEVREGR0 PDMDEVREG;
730typedef PPDMDEVREGR0 PPDMDEVREG;
731typedef PCPDMDEVREGR0 PCPDMDEVREG;
732#elif defined(IN_RC)
733# define PDM_DEVREG_VERSION PDM_DEVREGRC_VERSION
734typedef PDMDEVREGRC PDMDEVREG;
735typedef PPDMDEVREGRC PPDMDEVREG;
736typedef PCPDMDEVREGRC PCPDMDEVREG;
737#else
738# error "Not IN_RING3, IN_RING0 or IN_RC"
739#endif
740
741
742/**
743 * Device registrations for ring-0 modules.
744 *
745 * This structure is used directly and must therefore reside in persistent
746 * memory (i.e. the data section).
747 */
748typedef struct PDMDEVMODREGR0
749{
750 /** The structure version (PDM_DEVMODREGR0_VERSION). */
751 uint32_t u32Version;
752 /** Number of devices in the array papDevRegs points to. */
753 uint32_t cDevRegs;
754 /** Pointer to device registration structures. */
755 PCPDMDEVREGR0 *papDevRegs;
756 /** The ring-0 module handle - PDM internal, fingers off. */
757 void *hMod;
758 /** List entry - PDM internal, fingers off. */
759 RTLISTNODE ListEntry;
760} PDMDEVMODREGR0;
761/** Pointer to device registriations for a ring-0 module. */
762typedef PDMDEVMODREGR0 *PPDMDEVMODREGR0;
763/** Current PDMDEVMODREGR0 version number. */
764#define PDM_DEVMODREGR0_VERSION PDM_VERSION_MAKE(0xff85, 1, 0)
765
766
767/** @name IRQ Level for use with the *SetIrq APIs.
768 * @{
769 */
770/** Assert the IRQ (can assume value 1). */
771#define PDM_IRQ_LEVEL_HIGH RT_BIT(0)
772/** Deassert the IRQ (can assume value 0). */
773#define PDM_IRQ_LEVEL_LOW 0
774/** flip-flop - deassert and then assert the IRQ again immediately. */
775#define PDM_IRQ_LEVEL_FLIP_FLOP (RT_BIT(1) | PDM_IRQ_LEVEL_HIGH)
776/** @} */
777
778/**
779 * Registration record for MSI/MSI-X emulation.
780 */
781typedef struct PDMMSIREG
782{
783 /** Number of MSI interrupt vectors, 0 if MSI not supported */
784 uint16_t cMsiVectors;
785 /** Offset of MSI capability */
786 uint8_t iMsiCapOffset;
787 /** Offset of next capability to MSI */
788 uint8_t iMsiNextOffset;
789 /** If we support 64-bit MSI addressing */
790 bool fMsi64bit;
791 /** If we do not support per-vector masking */
792 bool fMsiNoMasking;
793
794 /** Number of MSI-X interrupt vectors, 0 if MSI-X not supported */
795 uint16_t cMsixVectors;
796 /** Offset of MSI-X capability */
797 uint8_t iMsixCapOffset;
798 /** Offset of next capability to MSI-X */
799 uint8_t iMsixNextOffset;
800 /** Value of PCI BAR (base addresss register) assigned by device for MSI-X page access */
801 uint8_t iMsixBar;
802} PDMMSIREG;
803typedef PDMMSIREG *PPDMMSIREG;
804
805/**
806 * PCI Bus registration structure.
807 * All the callbacks, except the PCIBIOS hack, are working on PCI devices.
808 */
809typedef struct PDMPCIBUSREGR3
810{
811 /** Structure version number. PDM_PCIBUSREGR3_VERSION defines the current version. */
812 uint32_t u32Version;
813
814 /**
815 * Registers the device with the default PCI bus.
816 *
817 * @returns VBox status code.
818 * @param pDevIns Device instance of the PCI Bus.
819 * @param pPciDev The PCI device structure.
820 * @param fFlags Reserved for future use, PDMPCIDEVREG_F_MBZ.
821 * @param uPciDevNo PDMPCIDEVREG_DEV_NO_FIRST_UNUSED, or a specific
822 * device number (0-31).
823 * @param uPciFunNo PDMPCIDEVREG_FUN_NO_FIRST_UNUSED, or a specific
824 * function number (0-7).
825 * @param pszName Device name (static but not unique).
826 *
827 * @remarks Caller enters the PDM critical section.
828 */
829 DECLR3CALLBACKMEMBER(int, pfnRegisterR3,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t fFlags,
830 uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName));
831
832 /**
833 * Initialize MSI or MSI-X emulation support in a PCI device.
834 *
835 * This cannot handle all corner cases of the MSI/MSI-X spec, but for the
836 * vast majority of device emulation it covers everything necessary. It's
837 * fully automatic, taking care of all BAR and config space requirements,
838 * and interrupt delivery is done using PDMDevHlpPCISetIrq and friends.
839 * When MSI/MSI-X is enabled then the iIrq parameter is redefined to take
840 * the vector number (otherwise it has the usual INTA-D meaning for PCI).
841 *
842 * A device not using this can still offer MSI/MSI-X. In this case it's
843 * completely up to the device (in the MSI-X case) to create/register the
844 * necessary MMIO BAR, handle all config space/BAR updating and take care
845 * of delivering the interrupts appropriately.
846 *
847 * @returns VBox status code.
848 * @param pDevIns Device instance of the PCI Bus.
849 * @param pPciDev The PCI device structure.
850 * @param pMsiReg MSI emulation registration structure
851 * @remarks Caller enters the PDM critical section.
852 */
853 DECLR3CALLBACKMEMBER(int, pfnRegisterMsiR3,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, PPDMMSIREG pMsiReg));
854
855 /**
856 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
857 *
858 * @returns VBox status code.
859 * @param pDevIns Device instance of the PCI Bus.
860 * @param pPciDev The PCI device structure.
861 * @param iRegion The region number.
862 * @param cbRegion Size of the region.
863 * @param enmType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or
864 * PCI_ADDRESS_SPACE_MEM_PREFETCH, optionally with
865 * PCI_ADDRESS_SPACE_BAR64 or'ed in.
866 * @param fFlags PDMPCIDEV_IORGN_F_XXX.
867 * @param hHandle An I/O port, MMIO or MMIO2 handle according to
868 * @a fFlags, UINT64_MAX if no handle is passed
869 * (old style).
870 * @param pfnMapUnmap Callback for doing the mapping. Optional if a handle
871 * is given.
872 * @remarks Caller enters the PDM critical section.
873 */
874 DECLR3CALLBACKMEMBER(int, pfnIORegionRegisterR3,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
875 RTGCPHYS cbRegion, PCIADDRESSSPACE enmType, uint32_t fFlags,
876 uint64_t hHandle, PFNPCIIOREGIONMAP pfnMapUnmap));
877
878 /**
879 * Register PCI configuration space read/write intercept callbacks.
880 *
881 * @param pDevIns Device instance of the PCI Bus.
882 * @param pPciDev The PCI device structure.
883 * @param pfnRead Pointer to the user defined PCI config read function.
884 * @param pfnWrite Pointer to the user defined PCI config write function.
885 * to call default PCI config write function. Can be NULL.
886 * @remarks Caller enters the PDM critical section.
887 * @thread EMT
888 */
889 DECLR3CALLBACKMEMBER(void, pfnInterceptConfigAccesses,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
890 PFNPCICONFIGREAD pfnRead, PFNPCICONFIGWRITE pfnWrite));
891
892 /**
893 * Perform a PCI configuration space write, bypassing interception.
894 *
895 * This is for devices that make use of PDMDevHlpPCIInterceptConfigAccesses().
896 *
897 * @returns Strict VBox status code (mainly DBGFSTOP).
898 * @param pDevIns Device instance of the PCI Bus.
899 * @param pPciDev The PCI device which config space is being read.
900 * @param uAddress The config space address.
901 * @param cb The size of the read: 1, 2 or 4 bytes.
902 * @param u32Value The value to write.
903 * @note The caller (PDM) does not enter the PDM critsect, but it is possible
904 * that the (root) bus will have done that already.
905 */
906 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnConfigWrite,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
907 uint32_t uAddress, unsigned cb, uint32_t u32Value));
908
909 /**
910 * Perform a PCI configuration space read, bypassing interception.
911 *
912 * This is for devices that make use of PDMDevHlpPCIInterceptConfigAccesses().
913 *
914 * @returns Strict VBox status code (mainly DBGFSTOP).
915 * @param pDevIns Device instance of the PCI Bus.
916 * @param pPciDev The PCI device which config space is being read.
917 * @param uAddress The config space address.
918 * @param cb The size of the read: 1, 2 or 4 bytes.
919 * @param pu32Value Where to return the value.
920 * @note The caller (PDM) does not enter the PDM critsect, but it is possible
921 * that the (root) bus will have done that already.
922 */
923 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnConfigRead,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
924 uint32_t uAddress, unsigned cb, uint32_t *pu32Value));
925
926 /**
927 * Set the IRQ for a PCI device.
928 *
929 * @param pDevIns Device instance of the PCI Bus.
930 * @param pPciDev The PCI device structure.
931 * @param iIrq IRQ number to set.
932 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
933 * @param uTagSrc The IRQ tag and source (for tracing).
934 * @remarks Caller enters the PDM critical section.
935 */
936 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
937
938 /** Marks the end of the structure with PDM_PCIBUSREGR3_VERSION. */
939 uint32_t u32EndVersion;
940} PDMPCIBUSREGR3;
941/** Pointer to a PCI bus registration structure. */
942typedef PDMPCIBUSREGR3 *PPDMPCIBUSREGR3;
943/** Current PDMPCIBUSREGR3 version number. */
944#define PDM_PCIBUSREGR3_VERSION PDM_VERSION_MAKE(0xff86, 2, 0)
945
946/**
947 * PCI Bus registration structure for ring-0.
948 */
949typedef struct PDMPCIBUSREGR0
950{
951 /** Structure version number. PDM_PCIBUSREGR0_VERSION defines the current version. */
952 uint32_t u32Version;
953 /** The PCI bus number (from ring-3 registration). */
954 uint32_t iBus;
955 /**
956 * Set the IRQ for a PCI device.
957 *
958 * @param pDevIns Device instance of the PCI Bus.
959 * @param pPciDev The PCI device structure.
960 * @param iIrq IRQ number to set.
961 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
962 * @param uTagSrc The IRQ tag and source (for tracing).
963 * @remarks Caller enters the PDM critical section.
964 */
965 DECLR0CALLBACKMEMBER(void, pfnSetIrq,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
966 /** Marks the end of the structure with PDM_PCIBUSREGR0_VERSION. */
967 uint32_t u32EndVersion;
968} PDMPCIBUSREGR0;
969/** Pointer to a PCI bus ring-0 registration structure. */
970typedef PDMPCIBUSREGR0 *PPDMPCIBUSREGR0;
971/** Current PDMPCIBUSREGR0 version number. */
972#define PDM_PCIBUSREGR0_VERSION PDM_VERSION_MAKE(0xff87, 1, 0)
973
974/**
975 * PCI Bus registration structure for raw-mode.
976 */
977typedef struct PDMPCIBUSREGRC
978{
979 /** Structure version number. PDM_PCIBUSREGRC_VERSION defines the current version. */
980 uint32_t u32Version;
981 /** The PCI bus number (from ring-3 registration). */
982 uint32_t iBus;
983 /**
984 * Set the IRQ for a PCI device.
985 *
986 * @param pDevIns Device instance of the PCI Bus.
987 * @param pPciDev The PCI device structure.
988 * @param iIrq IRQ number to set.
989 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
990 * @param uTagSrc The IRQ tag and source (for tracing).
991 * @remarks Caller enters the PDM critical section.
992 */
993 DECLRCCALLBACKMEMBER(void, pfnSetIrq,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel, uint32_t uTagSrc));
994 /** Marks the end of the structure with PDM_PCIBUSREGRC_VERSION. */
995 uint32_t u32EndVersion;
996} PDMPCIBUSREGRC;
997/** Pointer to a PCI bus raw-mode registration structure. */
998typedef PDMPCIBUSREGRC *PPDMPCIBUSREGRC;
999/** Current PDMPCIBUSREGRC version number. */
1000#define PDM_PCIBUSREGRC_VERSION PDM_VERSION_MAKE(0xff88, 1, 0)
1001
1002/** PCI bus registration structure for the current context. */
1003typedef CTX_SUFF(PDMPCIBUSREG) PDMPCIBUSREGCC;
1004/** Pointer to a PCI bus registration structure for the current context. */
1005typedef CTX_SUFF(PPDMPCIBUSREG) PPDMPCIBUSREGCC;
1006/** PCI bus registration structure version for the current context. */
1007#define PDM_PCIBUSREGCC_VERSION CTX_MID(PDM_PCIBUSREG,_VERSION)
1008
1009
1010/**
1011 * PCI Bus RC helpers.
1012 */
1013typedef struct PDMPCIHLPRC
1014{
1015 /** Structure version. PDM_PCIHLPRC_VERSION defines the current version. */
1016 uint32_t u32Version;
1017
1018 /**
1019 * Set an ISA IRQ.
1020 *
1021 * @param pDevIns PCI device instance.
1022 * @param iIrq IRQ number to set.
1023 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1024 * @param uTagSrc The IRQ tag and source (for tracing).
1025 * @thread EMT only.
1026 */
1027 DECLRCCALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
1028
1029 /**
1030 * Set an I/O-APIC IRQ.
1031 *
1032 * @param pDevIns PCI device instance.
1033 * @param iIrq IRQ number to set.
1034 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1035 * @param uTagSrc The IRQ tag and source (for tracing).
1036 * @thread EMT only.
1037 */
1038 DECLRCCALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
1039
1040 /**
1041 * Send an MSI.
1042 *
1043 * @param pDevIns PCI device instance.
1044 * @param GCPhys Physical address MSI request was written.
1045 * @param uValue Value written.
1046 * @param uTagSrc The IRQ tag and source (for tracing).
1047 * @thread EMT only.
1048 */
1049 DECLRCCALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc));
1050
1051
1052 /**
1053 * Acquires the PDM lock.
1054 *
1055 * @returns VINF_SUCCESS on success.
1056 * @returns rc if we failed to acquire the lock.
1057 * @param pDevIns The PCI device instance.
1058 * @param rc What to return if we fail to acquire the lock.
1059 */
1060 DECLRCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1061
1062 /**
1063 * Releases the PDM lock.
1064 *
1065 * @param pDevIns The PCI device instance.
1066 */
1067 DECLRCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1068
1069 /**
1070 * Gets a bus by it's PDM ordinal (typically the parent bus).
1071 *
1072 * @returns Pointer to the device instance of the bus.
1073 * @param pDevIns The PCI bus device instance.
1074 * @param idxPdmBus The PDM ordinal value of the bus to get.
1075 */
1076 DECLRCCALLBACKMEMBER(PPDMDEVINS, pfnGetBusByNo,(PPDMDEVINS pDevIns, uint32_t idxPdmBus));
1077
1078 /** Just a safety precaution. */
1079 uint32_t u32TheEnd;
1080} PDMPCIHLPRC;
1081/** Pointer to PCI helpers. */
1082typedef RCPTRTYPE(PDMPCIHLPRC *) PPDMPCIHLPRC;
1083/** Pointer to const PCI helpers. */
1084typedef RCPTRTYPE(const PDMPCIHLPRC *) PCPDMPCIHLPRC;
1085
1086/** Current PDMPCIHLPRC version number. */
1087#define PDM_PCIHLPRC_VERSION PDM_VERSION_MAKE(0xfffd, 3, 0)
1088
1089
1090/**
1091 * PCI Bus R0 helpers.
1092 */
1093typedef struct PDMPCIHLPR0
1094{
1095 /** Structure version. PDM_PCIHLPR0_VERSION defines the current version. */
1096 uint32_t u32Version;
1097
1098 /**
1099 * Set an ISA IRQ.
1100 *
1101 * @param pDevIns PCI device instance.
1102 * @param iIrq IRQ number to set.
1103 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1104 * @param uTagSrc The IRQ tag and source (for tracing).
1105 * @thread EMT only.
1106 */
1107 DECLR0CALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
1108
1109 /**
1110 * Set an I/O-APIC IRQ.
1111 *
1112 * @param pDevIns PCI device instance.
1113 * @param iIrq IRQ number to set.
1114 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1115 * @param uTagSrc The IRQ tag and source (for tracing).
1116 * @thread EMT only.
1117 */
1118 DECLR0CALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
1119
1120 /**
1121 * Send an MSI.
1122 *
1123 * @param pDevIns PCI device instance.
1124 * @param GCPhys Physical address MSI request was written.
1125 * @param uValue Value written.
1126 * @param uTagSrc The IRQ tag and source (for tracing).
1127 * @thread EMT only.
1128 */
1129 DECLR0CALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc));
1130
1131 /**
1132 * Acquires the PDM lock.
1133 *
1134 * @returns VINF_SUCCESS on success.
1135 * @returns rc if we failed to acquire the lock.
1136 * @param pDevIns The PCI device instance.
1137 * @param rc What to return if we fail to acquire the lock.
1138 */
1139 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1140
1141 /**
1142 * Releases the PDM lock.
1143 *
1144 * @param pDevIns The PCI device instance.
1145 */
1146 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1147
1148 /**
1149 * Gets a bus by it's PDM ordinal (typically the parent bus).
1150 *
1151 * @returns Pointer to the device instance of the bus.
1152 * @param pDevIns The PCI bus device instance.
1153 * @param idxPdmBus The PDM ordinal value of the bus to get.
1154 */
1155 DECLR0CALLBACKMEMBER(PPDMDEVINS, pfnGetBusByNo,(PPDMDEVINS pDevIns, uint32_t idxPdmBus));
1156
1157 /** Just a safety precaution. */
1158 uint32_t u32TheEnd;
1159} PDMPCIHLPR0;
1160/** Pointer to PCI helpers. */
1161typedef R0PTRTYPE(PDMPCIHLPR0 *) PPDMPCIHLPR0;
1162/** Pointer to const PCI helpers. */
1163typedef R0PTRTYPE(const PDMPCIHLPR0 *) PCPDMPCIHLPR0;
1164
1165/** Current PDMPCIHLPR0 version number. */
1166#define PDM_PCIHLPR0_VERSION PDM_VERSION_MAKE(0xfffc, 4, 0)
1167
1168/**
1169 * PCI device helpers.
1170 */
1171typedef struct PDMPCIHLPR3
1172{
1173 /** Structure version. PDM_PCIHLPR3_VERSION defines the current version. */
1174 uint32_t u32Version;
1175
1176 /**
1177 * Set an ISA IRQ.
1178 *
1179 * @param pDevIns The PCI device instance.
1180 * @param iIrq IRQ number to set.
1181 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1182 * @param uTagSrc The IRQ tag and source (for tracing).
1183 */
1184 DECLR3CALLBACKMEMBER(void, pfnIsaSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
1185
1186 /**
1187 * Set an I/O-APIC IRQ.
1188 *
1189 * @param pDevIns The PCI device instance.
1190 * @param iIrq IRQ number to set.
1191 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1192 * @param uTagSrc The IRQ tag and source (for tracing).
1193 */
1194 DECLR3CALLBACKMEMBER(void, pfnIoApicSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
1195
1196 /**
1197 * Send an MSI.
1198 *
1199 * @param pDevIns PCI device instance.
1200 * @param GCPhys Physical address MSI request was written.
1201 * @param uValue Value written.
1202 * @param uTagSrc The IRQ tag and source (for tracing).
1203 */
1204 DECLR3CALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc));
1205
1206 /**
1207 * Checks if the given address is an MMIO2 or pre-registered MMIO base address.
1208 *
1209 * @returns true/false accordingly.
1210 * @param pDevIns The PCI device instance.
1211 * @param pOwner The owner of the memory, optional.
1212 * @param GCPhys The address to check.
1213 * @sa PGMR3PhysMMIOExIsBase
1214 */
1215 DECLR3CALLBACKMEMBER(bool, pfnIsMMIOExBase,(PPDMDEVINS pDevIns, PPDMDEVINS pOwner, RTGCPHYS GCPhys));
1216
1217 /**
1218 * Acquires the PDM lock.
1219 *
1220 * @returns VINF_SUCCESS on success.
1221 * @returns Fatal error on failure.
1222 * @param pDevIns The PCI device instance.
1223 * @param rc Dummy for making the interface identical to the RC and R0 versions.
1224 */
1225 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1226
1227 /**
1228 * Releases the PDM lock.
1229 *
1230 * @param pDevIns The PCI device instance.
1231 */
1232 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1233
1234 /**
1235 * Gets a bus by it's PDM ordinal (typically the parent bus).
1236 *
1237 * @returns Pointer to the device instance of the bus.
1238 * @param pDevIns The PCI bus device instance.
1239 * @param idxPdmBus The PDM ordinal value of the bus to get.
1240 */
1241 DECLR3CALLBACKMEMBER(PPDMDEVINS, pfnGetBusByNo,(PPDMDEVINS pDevIns, uint32_t idxPdmBus));
1242
1243 /** Just a safety precaution. */
1244 uint32_t u32TheEnd;
1245} PDMPCIHLPR3;
1246/** Pointer to PCI helpers. */
1247typedef R3PTRTYPE(PDMPCIHLPR3 *) PPDMPCIHLPR3;
1248/** Pointer to const PCI helpers. */
1249typedef R3PTRTYPE(const PDMPCIHLPR3 *) PCPDMPCIHLPR3;
1250
1251/** Current PDMPCIHLPR3 version number. */
1252#define PDM_PCIHLPR3_VERSION PDM_VERSION_MAKE(0xfffb, 4, 0)
1253
1254
1255/**
1256 * Programmable Interrupt Controller registration structure (all contexts).
1257 */
1258typedef struct PDMPICREG
1259{
1260 /** Structure version number. PDM_PICREG_VERSION defines the current version. */
1261 uint32_t u32Version;
1262
1263 /**
1264 * Set the an IRQ.
1265 *
1266 * @param pDevIns Device instance of the PIC.
1267 * @param iIrq IRQ number to set.
1268 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1269 * @param uTagSrc The IRQ tag and source (for tracing).
1270 * @remarks Caller enters the PDM critical section.
1271 */
1272 DECLCALLBACKMEMBER(void, pfnSetIrq)(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc);
1273
1274 /**
1275 * Get a pending interrupt.
1276 *
1277 * @returns Pending interrupt number.
1278 * @param pDevIns Device instance of the PIC.
1279 * @param puTagSrc Where to return the IRQ tag and source.
1280 * @remarks Caller enters the PDM critical section.
1281 */
1282 DECLCALLBACKMEMBER(int, pfnGetInterrupt)(PPDMDEVINS pDevIns, uint32_t *puTagSrc);
1283
1284 /** Just a safety precaution. */
1285 uint32_t u32TheEnd;
1286} PDMPICREG;
1287/** Pointer to a PIC registration structure. */
1288typedef PDMPICREG *PPDMPICREG;
1289
1290/** Current PDMPICREG version number. */
1291#define PDM_PICREG_VERSION PDM_VERSION_MAKE(0xfffa, 3, 0)
1292
1293/**
1294 * PIC helpers, same in all contexts.
1295 */
1296typedef struct PDMPICHLP
1297{
1298 /** Structure version. PDM_PICHLP_VERSION defines the current version. */
1299 uint32_t u32Version;
1300
1301 /**
1302 * Set the interrupt force action flag.
1303 *
1304 * @param pDevIns Device instance of the PIC.
1305 */
1306 DECLCALLBACKMEMBER(void, pfnSetInterruptFF)(PPDMDEVINS pDevIns);
1307
1308 /**
1309 * Clear the interrupt force action flag.
1310 *
1311 * @param pDevIns Device instance of the PIC.
1312 */
1313 DECLCALLBACKMEMBER(void, pfnClearInterruptFF)(PPDMDEVINS pDevIns);
1314
1315 /**
1316 * Acquires the PDM lock.
1317 *
1318 * @returns VINF_SUCCESS on success.
1319 * @returns rc if we failed to acquire the lock.
1320 * @param pDevIns The PIC device instance.
1321 * @param rc What to return if we fail to acquire the lock.
1322 */
1323 DECLCALLBACKMEMBER(int, pfnLock)(PPDMDEVINS pDevIns, int rc);
1324
1325 /**
1326 * Releases the PDM lock.
1327 *
1328 * @param pDevIns The PIC device instance.
1329 */
1330 DECLCALLBACKMEMBER(void, pfnUnlock)(PPDMDEVINS pDevIns);
1331
1332 /** Just a safety precaution. */
1333 uint32_t u32TheEnd;
1334} PDMPICHLP;
1335/** Pointer to PIC helpers. */
1336typedef PDMPICHLP *PPDMPICHLP;
1337/** Pointer to const PIC helpers. */
1338typedef const PDMPICHLP *PCPDMPICHLP;
1339
1340/** Current PDMPICHLP version number. */
1341#define PDM_PICHLP_VERSION PDM_VERSION_MAKE(0xfff9, 3, 0)
1342
1343
1344/**
1345 * Firmware registration structure.
1346 */
1347typedef struct PDMFWREG
1348{
1349 /** Struct version+magic number (PDM_FWREG_VERSION). */
1350 uint32_t u32Version;
1351
1352 /**
1353 * Checks whether this is a hard or soft reset.
1354 *
1355 * The current definition of soft reset is what the PC BIOS does when CMOS[0xF]
1356 * is 5, 9 or 0xA.
1357 *
1358 * @returns true if hard reset, false if soft.
1359 * @param pDevIns Device instance of the firmware.
1360 * @param fFlags PDMRESET_F_XXX passed to the PDMDevHlpVMReset API.
1361 */
1362 DECLR3CALLBACKMEMBER(bool, pfnIsHardReset,(PPDMDEVINS pDevIns, uint32_t fFlags));
1363
1364 /** Just a safety precaution. */
1365 uint32_t u32TheEnd;
1366} PDMFWREG;
1367/** Pointer to a FW registration structure. */
1368typedef PDMFWREG *PPDMFWREG;
1369/** Pointer to a const FW registration structure. */
1370typedef PDMFWREG const *PCPDMFWREG;
1371
1372/** Current PDMFWREG version number. */
1373#define PDM_FWREG_VERSION PDM_VERSION_MAKE(0xffdd, 1, 0)
1374
1375/**
1376 * Firmware R3 helpers.
1377 */
1378typedef struct PDMFWHLPR3
1379{
1380 /** Structure version. PDM_FWHLP_VERSION defines the current version. */
1381 uint32_t u32Version;
1382
1383 /** Just a safety precaution. */
1384 uint32_t u32TheEnd;
1385} PDMFWHLPR3;
1386
1387/** Pointer to FW R3 helpers. */
1388typedef R3PTRTYPE(PDMFWHLPR3 *) PPDMFWHLPR3;
1389/** Pointer to const FW R3 helpers. */
1390typedef R3PTRTYPE(const PDMFWHLPR3 *) PCPDMFWHLPR3;
1391
1392/** Current PDMFWHLPR3 version number. */
1393#define PDM_FWHLPR3_VERSION PDM_VERSION_MAKE(0xffdb, 1, 0)
1394
1395
1396/**
1397 * APIC mode argument for apicR3SetCpuIdFeatureLevel.
1398 *
1399 * Also used in saved-states, CFGM don't change existing values.
1400 */
1401typedef enum PDMAPICMODE
1402{
1403 /** Invalid 0 entry. */
1404 PDMAPICMODE_INVALID = 0,
1405 /** No APIC. */
1406 PDMAPICMODE_NONE,
1407 /** Standard APIC (X86_CPUID_FEATURE_EDX_APIC). */
1408 PDMAPICMODE_APIC,
1409 /** Intel X2APIC (X86_CPUID_FEATURE_ECX_X2APIC). */
1410 PDMAPICMODE_X2APIC,
1411 /** The usual 32-bit paranoia. */
1412 PDMAPICMODE_32BIT_HACK = 0x7fffffff
1413} PDMAPICMODE;
1414
1415/**
1416 * APIC irq argument for pfnSetInterruptFF and pfnClearInterruptFF.
1417 */
1418typedef enum PDMAPICIRQ
1419{
1420 /** Invalid 0 entry. */
1421 PDMAPICIRQ_INVALID = 0,
1422 /** Normal hardware interrupt. */
1423 PDMAPICIRQ_HARDWARE,
1424 /** NMI. */
1425 PDMAPICIRQ_NMI,
1426 /** SMI. */
1427 PDMAPICIRQ_SMI,
1428 /** ExtINT (HW interrupt via PIC). */
1429 PDMAPICIRQ_EXTINT,
1430 /** Interrupt arrived, needs to be updated to the IRR. */
1431 PDMAPICIRQ_UPDATE_PENDING,
1432 /** The usual 32-bit paranoia. */
1433 PDMAPICIRQ_32BIT_HACK = 0x7fffffff
1434} PDMAPICIRQ;
1435
1436
1437/**
1438 * I/O APIC registration structure (all contexts).
1439 */
1440typedef struct PDMIOAPICREG
1441{
1442 /** Struct version+magic number (PDM_IOAPICREG_VERSION). */
1443 uint32_t u32Version;
1444
1445 /**
1446 * Set an IRQ.
1447 *
1448 * @param pDevIns Device instance of the I/O APIC.
1449 * @param iIrq IRQ number to set.
1450 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1451 * @param uTagSrc The IRQ tag and source (for tracing).
1452 *
1453 * @remarks Caller enters the PDM critical section
1454 * Actually, as per 2018-07-21 this isn't true (bird).
1455 */
1456 DECLCALLBACKMEMBER(void, pfnSetIrq)(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc);
1457
1458 /**
1459 * Send a MSI.
1460 *
1461 * @param pDevIns Device instance of the I/O APIC.
1462 * @param GCPhys Request address.
1463 * @param uValue Request value.
1464 * @param uTagSrc The IRQ tag and source (for tracing).
1465 *
1466 * @remarks Caller enters the PDM critical section
1467 * Actually, as per 2018-07-21 this isn't true (bird).
1468 */
1469 DECLCALLBACKMEMBER(void, pfnSendMsi)(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc);
1470
1471 /**
1472 * Set the EOI for an interrupt vector.
1473 *
1474 * @returns Strict VBox status code - only the following informational status codes:
1475 * @retval VINF_IOM_R3_MMIO_WRITE if the I/O APIC lock is contenteded and we're in R0 or RC.
1476 * @retval VINF_SUCCESS
1477 *
1478 * @param pDevIns Device instance of the I/O APIC.
1479 * @param u8Vector The vector.
1480 *
1481 * @remarks Caller enters the PDM critical section
1482 * Actually, as per 2018-07-21 this isn't true (bird).
1483 */
1484 DECLCALLBACKMEMBER(VBOXSTRICTRC, pfnSetEoi)(PPDMDEVINS pDevIns, uint8_t u8Vector);
1485
1486 /** Just a safety precaution. */
1487 uint32_t u32TheEnd;
1488} PDMIOAPICREG;
1489/** Pointer to an APIC registration structure. */
1490typedef PDMIOAPICREG *PPDMIOAPICREG;
1491
1492/** Current PDMAPICREG version number. */
1493#define PDM_IOAPICREG_VERSION PDM_VERSION_MAKE(0xfff2, 6, 0)
1494
1495
1496/**
1497 * IOAPIC helpers, same in all contexts.
1498 */
1499typedef struct PDMIOAPICHLP
1500{
1501 /** Structure version. PDM_IOAPICHLP_VERSION defines the current version. */
1502 uint32_t u32Version;
1503
1504 /**
1505 * Private interface between the IOAPIC and APIC.
1506 *
1507 * @returns status code.
1508 * @param pDevIns Device instance of the IOAPIC.
1509 * @param u8Dest See APIC implementation.
1510 * @param u8DestMode See APIC implementation.
1511 * @param u8DeliveryMode See APIC implementation.
1512 * @param uVector See APIC implementation.
1513 * @param u8Polarity See APIC implementation.
1514 * @param u8TriggerMode See APIC implementation.
1515 * @param uTagSrc The IRQ tag and source (for tracing).
1516 *
1517 * @sa APICBusDeliver()
1518 */
1519 DECLCALLBACKMEMBER(int, pfnApicBusDeliver)(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1520 uint8_t uVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc);
1521
1522 /**
1523 * Acquires the PDM lock.
1524 *
1525 * @returns VINF_SUCCESS on success.
1526 * @returns rc if we failed to acquire the lock.
1527 * @param pDevIns The IOAPIC device instance.
1528 * @param rc What to return if we fail to acquire the lock.
1529 */
1530 DECLCALLBACKMEMBER(int, pfnLock)(PPDMDEVINS pDevIns, int rc);
1531
1532 /**
1533 * Releases the PDM lock.
1534 *
1535 * @param pDevIns The IOAPIC device instance.
1536 */
1537 DECLCALLBACKMEMBER(void, pfnUnlock)(PPDMDEVINS pDevIns);
1538
1539 /** Just a safety precaution. */
1540 uint32_t u32TheEnd;
1541} PDMIOAPICHLP;
1542/** Pointer to IOAPIC helpers. */
1543typedef PDMIOAPICHLP * PPDMIOAPICHLP;
1544/** Pointer to const IOAPIC helpers. */
1545typedef const PDMIOAPICHLP * PCPDMIOAPICHLP;
1546
1547/** Current PDMIOAPICHLP version number. */
1548#define PDM_IOAPICHLP_VERSION PDM_VERSION_MAKE(0xfff0, 2, 0)
1549
1550
1551/**
1552 * HPET registration structure.
1553 */
1554typedef struct PDMHPETREG
1555{
1556 /** Struct version+magic number (PDM_HPETREG_VERSION). */
1557 uint32_t u32Version;
1558
1559} PDMHPETREG;
1560/** Pointer to an HPET registration structure. */
1561typedef PDMHPETREG *PPDMHPETREG;
1562
1563/** Current PDMHPETREG version number. */
1564#define PDM_HPETREG_VERSION PDM_VERSION_MAKE(0xffe2, 1, 0)
1565
1566/**
1567 * HPET RC helpers.
1568 *
1569 * @remarks Keep this around in case HPET will need PDM interaction in again RC
1570 * at some later point.
1571 */
1572typedef struct PDMHPETHLPRC
1573{
1574 /** Structure version. PDM_HPETHLPRC_VERSION defines the current version. */
1575 uint32_t u32Version;
1576
1577 /** Just a safety precaution. */
1578 uint32_t u32TheEnd;
1579} PDMHPETHLPRC;
1580
1581/** Pointer to HPET RC helpers. */
1582typedef RCPTRTYPE(PDMHPETHLPRC *) PPDMHPETHLPRC;
1583/** Pointer to const HPET RC helpers. */
1584typedef RCPTRTYPE(const PDMHPETHLPRC *) PCPDMHPETHLPRC;
1585
1586/** Current PDMHPETHLPRC version number. */
1587#define PDM_HPETHLPRC_VERSION PDM_VERSION_MAKE(0xffee, 2, 0)
1588
1589
1590/**
1591 * HPET R0 helpers.
1592 *
1593 * @remarks Keep this around in case HPET will need PDM interaction in again R0
1594 * at some later point.
1595 */
1596typedef struct PDMHPETHLPR0
1597{
1598 /** Structure version. PDM_HPETHLPR0_VERSION defines the current version. */
1599 uint32_t u32Version;
1600
1601 /** Just a safety precaution. */
1602 uint32_t u32TheEnd;
1603} PDMHPETHLPR0;
1604
1605/** Pointer to HPET R0 helpers. */
1606typedef R0PTRTYPE(PDMHPETHLPR0 *) PPDMHPETHLPR0;
1607/** Pointer to const HPET R0 helpers. */
1608typedef R0PTRTYPE(const PDMHPETHLPR0 *) PCPDMHPETHLPR0;
1609
1610/** Current PDMHPETHLPR0 version number. */
1611#define PDM_HPETHLPR0_VERSION PDM_VERSION_MAKE(0xffed, 2, 0)
1612
1613/**
1614 * HPET R3 helpers.
1615 */
1616typedef struct PDMHPETHLPR3
1617{
1618 /** Structure version. PDM_HPETHLP_VERSION defines the current version. */
1619 uint32_t u32Version;
1620
1621 /**
1622 * Gets the address of the RC HPET helpers.
1623 *
1624 * This should be called at both construction and relocation time
1625 * to obtain the correct address of the RC helpers.
1626 *
1627 * @returns RC pointer to the HPET helpers.
1628 * @param pDevIns Device instance of the HPET.
1629 */
1630 DECLR3CALLBACKMEMBER(PCPDMHPETHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1631
1632 /**
1633 * Gets the address of the R0 HPET helpers.
1634 *
1635 * This should be called at both construction and relocation time
1636 * to obtain the correct address of the R0 helpers.
1637 *
1638 * @returns R0 pointer to the HPET helpers.
1639 * @param pDevIns Device instance of the HPET.
1640 */
1641 DECLR3CALLBACKMEMBER(PCPDMHPETHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1642
1643 /**
1644 * Set legacy mode on PIT and RTC.
1645 *
1646 * @returns VINF_SUCCESS on success.
1647 * @returns rc if we failed to set legacy mode.
1648 * @param pDevIns Device instance of the HPET.
1649 * @param fActivated Whether legacy mode is activated or deactivated.
1650 */
1651 DECLR3CALLBACKMEMBER(int, pfnSetLegacyMode,(PPDMDEVINS pDevIns, bool fActivated));
1652
1653
1654 /**
1655 * Set IRQ, bypassing ISA bus override rules.
1656 *
1657 * @returns VINF_SUCCESS on success.
1658 * @returns rc if we failed to set legacy mode.
1659 * @param pDevIns Device instance of the HPET.
1660 * @param iIrq IRQ number to set.
1661 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1662 */
1663 DECLR3CALLBACKMEMBER(int, pfnSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
1664
1665 /** Just a safety precaution. */
1666 uint32_t u32TheEnd;
1667} PDMHPETHLPR3;
1668
1669/** Pointer to HPET R3 helpers. */
1670typedef R3PTRTYPE(PDMHPETHLPR3 *) PPDMHPETHLPR3;
1671/** Pointer to const HPET R3 helpers. */
1672typedef R3PTRTYPE(const PDMHPETHLPR3 *) PCPDMHPETHLPR3;
1673
1674/** Current PDMHPETHLPR3 version number. */
1675#define PDM_HPETHLPR3_VERSION PDM_VERSION_MAKE(0xffec, 2, 0)
1676
1677
1678/**
1679 * Raw PCI device registration structure.
1680 */
1681typedef struct PDMPCIRAWREG
1682{
1683 /** Struct version+magic number (PDM_PCIRAWREG_VERSION). */
1684 uint32_t u32Version;
1685 /** Just a safety precaution. */
1686 uint32_t u32TheEnd;
1687} PDMPCIRAWREG;
1688/** Pointer to a raw PCI registration structure. */
1689typedef PDMPCIRAWREG *PPDMPCIRAWREG;
1690
1691/** Current PDMPCIRAWREG version number. */
1692#define PDM_PCIRAWREG_VERSION PDM_VERSION_MAKE(0xffe1, 1, 0)
1693
1694/**
1695 * Raw PCI device raw-mode context helpers.
1696 */
1697typedef struct PDMPCIRAWHLPRC
1698{
1699 /** Structure version and magic number (PDM_PCIRAWHLPRC_VERSION). */
1700 uint32_t u32Version;
1701 /** Just a safety precaution. */
1702 uint32_t u32TheEnd;
1703} PDMPCIRAWHLPRC;
1704/** Pointer to a raw PCI deviec raw-mode context helper structure. */
1705typedef RCPTRTYPE(PDMPCIRAWHLPRC *) PPDMPCIRAWHLPRC;
1706/** Pointer to a const raw PCI deviec raw-mode context helper structure. */
1707typedef RCPTRTYPE(const PDMPCIRAWHLPRC *) PCPDMPCIRAWHLPRC;
1708
1709/** Current PDMPCIRAWHLPRC version number. */
1710#define PDM_PCIRAWHLPRC_VERSION PDM_VERSION_MAKE(0xffe0, 1, 0)
1711
1712/**
1713 * Raw PCI device ring-0 context helpers.
1714 */
1715typedef struct PDMPCIRAWHLPR0
1716{
1717 /** Structure version and magic number (PDM_PCIRAWHLPR0_VERSION). */
1718 uint32_t u32Version;
1719 /** Just a safety precaution. */
1720 uint32_t u32TheEnd;
1721} PDMPCIRAWHLPR0;
1722/** Pointer to a raw PCI deviec ring-0 context helper structure. */
1723typedef R0PTRTYPE(PDMPCIRAWHLPR0 *) PPDMPCIRAWHLPR0;
1724/** Pointer to a const raw PCI deviec ring-0 context helper structure. */
1725typedef R0PTRTYPE(const PDMPCIRAWHLPR0 *) PCPDMPCIRAWHLPR0;
1726
1727/** Current PDMPCIRAWHLPR0 version number. */
1728#define PDM_PCIRAWHLPR0_VERSION PDM_VERSION_MAKE(0xffdf, 1, 0)
1729
1730
1731/**
1732 * Raw PCI device ring-3 context helpers.
1733 */
1734typedef struct PDMPCIRAWHLPR3
1735{
1736 /** Undefined structure version and magic number. */
1737 uint32_t u32Version;
1738
1739 /**
1740 * Gets the address of the RC raw PCI device helpers.
1741 *
1742 * This should be called at both construction and relocation time to obtain
1743 * the correct address of the RC helpers.
1744 *
1745 * @returns RC pointer to the raw PCI device helpers.
1746 * @param pDevIns Device instance of the raw PCI device.
1747 */
1748 DECLR3CALLBACKMEMBER(PCPDMPCIRAWHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1749
1750 /**
1751 * Gets the address of the R0 raw PCI device helpers.
1752 *
1753 * This should be called at both construction and relocation time to obtain
1754 * the correct address of the R0 helpers.
1755 *
1756 * @returns R0 pointer to the raw PCI device helpers.
1757 * @param pDevIns Device instance of the raw PCI device.
1758 */
1759 DECLR3CALLBACKMEMBER(PCPDMPCIRAWHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1760
1761 /** Just a safety precaution. */
1762 uint32_t u32TheEnd;
1763} PDMPCIRAWHLPR3;
1764/** Pointer to raw PCI R3 helpers. */
1765typedef R3PTRTYPE(PDMPCIRAWHLPR3 *) PPDMPCIRAWHLPR3;
1766/** Pointer to const raw PCI R3 helpers. */
1767typedef R3PTRTYPE(const PDMPCIRAWHLPR3 *) PCPDMPCIRAWHLPR3;
1768
1769/** Current PDMPCIRAWHLPR3 version number. */
1770#define PDM_PCIRAWHLPR3_VERSION PDM_VERSION_MAKE(0xffde, 1, 0)
1771
1772
1773#ifdef IN_RING3
1774
1775/**
1776 * DMA Transfer Handler.
1777 *
1778 * @returns Number of bytes transferred.
1779 * @param pDevIns Device instance of the DMA.
1780 * @param pvUser User pointer.
1781 * @param uChannel Channel number.
1782 * @param off DMA position.
1783 * @param cb Block size.
1784 * @remarks The device lock is not taken, however, the DMA device lock is held.
1785 */
1786typedef DECLCALLBACK(uint32_t) FNDMATRANSFERHANDLER(PPDMDEVINS pDevIns, void *pvUser, unsigned uChannel, uint32_t off, uint32_t cb);
1787/** Pointer to a FNDMATRANSFERHANDLER(). */
1788typedef FNDMATRANSFERHANDLER *PFNDMATRANSFERHANDLER;
1789
1790/**
1791 * DMA Controller registration structure.
1792 */
1793typedef struct PDMDMAREG
1794{
1795 /** Structure version number. PDM_DMACREG_VERSION defines the current version. */
1796 uint32_t u32Version;
1797
1798 /**
1799 * Execute pending transfers.
1800 *
1801 * @returns A more work indiciator. I.e. 'true' if there is more to be done, and 'false' if all is done.
1802 * @param pDevIns Device instance of the DMAC.
1803 * @remarks No locks held, called on EMT(0) as a form of serialization.
1804 */
1805 DECLR3CALLBACKMEMBER(bool, pfnRun,(PPDMDEVINS pDevIns));
1806
1807 /**
1808 * Register transfer function for DMA channel.
1809 *
1810 * @param pDevIns Device instance of the DMAC.
1811 * @param uChannel Channel number.
1812 * @param pfnTransferHandler Device specific transfer function.
1813 * @param pvUser User pointer to be passed to the callback.
1814 * @remarks No locks held, called on an EMT.
1815 */
1816 DECLR3CALLBACKMEMBER(void, pfnRegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
1817
1818 /**
1819 * Read memory
1820 *
1821 * @returns Number of bytes read.
1822 * @param pDevIns Device instance of the DMAC.
1823 * @param uChannel Channel number.
1824 * @param pvBuffer Pointer to target buffer.
1825 * @param off DMA position.
1826 * @param cbBlock Block size.
1827 * @remarks No locks held, called on an EMT.
1828 */
1829 DECLR3CALLBACKMEMBER(uint32_t, pfnReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock));
1830
1831 /**
1832 * Write memory
1833 *
1834 * @returns Number of bytes written.
1835 * @param pDevIns Device instance of the DMAC.
1836 * @param uChannel Channel number.
1837 * @param pvBuffer Memory to write.
1838 * @param off DMA position.
1839 * @param cbBlock Block size.
1840 * @remarks No locks held, called on an EMT.
1841 */
1842 DECLR3CALLBACKMEMBER(uint32_t, pfnWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock));
1843
1844 /**
1845 * Set the DREQ line.
1846 *
1847 * @param pDevIns Device instance of the DMAC.
1848 * @param uChannel Channel number.
1849 * @param uLevel Level of the line.
1850 * @remarks No locks held, called on an EMT.
1851 */
1852 DECLR3CALLBACKMEMBER(void, pfnSetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
1853
1854 /**
1855 * Get channel mode
1856 *
1857 * @returns Channel mode.
1858 * @param pDevIns Device instance of the DMAC.
1859 * @param uChannel Channel number.
1860 * @remarks No locks held, called on an EMT.
1861 */
1862 DECLR3CALLBACKMEMBER(uint8_t, pfnGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
1863
1864} PDMDMACREG;
1865/** Pointer to a DMAC registration structure. */
1866typedef PDMDMACREG *PPDMDMACREG;
1867
1868/** Current PDMDMACREG version number. */
1869#define PDM_DMACREG_VERSION PDM_VERSION_MAKE(0xffeb, 1, 0)
1870
1871
1872/**
1873 * DMA Controller device helpers.
1874 */
1875typedef struct PDMDMACHLP
1876{
1877 /** Structure version. PDM_DMACHLP_VERSION defines the current version. */
1878 uint32_t u32Version;
1879
1880 /* to-be-defined */
1881
1882} PDMDMACHLP;
1883/** Pointer to DMAC helpers. */
1884typedef PDMDMACHLP *PPDMDMACHLP;
1885/** Pointer to const DMAC helpers. */
1886typedef const PDMDMACHLP *PCPDMDMACHLP;
1887
1888/** Current PDMDMACHLP version number. */
1889#define PDM_DMACHLP_VERSION PDM_VERSION_MAKE(0xffea, 1, 0)
1890
1891#endif /* IN_RING3 */
1892
1893
1894
1895/**
1896 * RTC registration structure.
1897 */
1898typedef struct PDMRTCREG
1899{
1900 /** Structure version number. PDM_RTCREG_VERSION defines the current version. */
1901 uint32_t u32Version;
1902 uint32_t u32Alignment; /**< structure size alignment. */
1903
1904 /**
1905 * Write to a CMOS register and update the checksum if necessary.
1906 *
1907 * @returns VBox status code.
1908 * @param pDevIns Device instance of the RTC.
1909 * @param iReg The CMOS register index.
1910 * @param u8Value The CMOS register value.
1911 * @remarks Caller enters the device critical section.
1912 */
1913 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
1914
1915 /**
1916 * Read a CMOS register.
1917 *
1918 * @returns VBox status code.
1919 * @param pDevIns Device instance of the RTC.
1920 * @param iReg The CMOS register index.
1921 * @param pu8Value Where to store the CMOS register value.
1922 * @remarks Caller enters the device critical section.
1923 */
1924 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
1925
1926} PDMRTCREG;
1927/** Pointer to a RTC registration structure. */
1928typedef PDMRTCREG *PPDMRTCREG;
1929/** Pointer to a const RTC registration structure. */
1930typedef const PDMRTCREG *PCPDMRTCREG;
1931
1932/** Current PDMRTCREG version number. */
1933#define PDM_RTCREG_VERSION PDM_VERSION_MAKE(0xffe9, 2, 0)
1934
1935
1936/**
1937 * RTC device helpers.
1938 */
1939typedef struct PDMRTCHLP
1940{
1941 /** Structure version. PDM_RTCHLP_VERSION defines the current version. */
1942 uint32_t u32Version;
1943
1944 /* to-be-defined */
1945
1946} PDMRTCHLP;
1947/** Pointer to RTC helpers. */
1948typedef PDMRTCHLP *PPDMRTCHLP;
1949/** Pointer to const RTC helpers. */
1950typedef const PDMRTCHLP *PCPDMRTCHLP;
1951
1952/** Current PDMRTCHLP version number. */
1953#define PDM_RTCHLP_VERSION PDM_VERSION_MAKE(0xffe8, 1, 0)
1954
1955
1956
1957/** @name Flags for PCI I/O region registration
1958 * @{ */
1959/** No handle is passed. */
1960#define PDMPCIDEV_IORGN_F_NO_HANDLE UINT32_C(0x00000000)
1961/** An I/O port handle is passed. */
1962#define PDMPCIDEV_IORGN_F_IOPORT_HANDLE UINT32_C(0x00000001)
1963/** An MMIO range handle is passed. */
1964#define PDMPCIDEV_IORGN_F_MMIO_HANDLE UINT32_C(0x00000002)
1965/** An MMIO2 handle is passed. */
1966#define PDMPCIDEV_IORGN_F_MMIO2_HANDLE UINT32_C(0x00000003)
1967/** Handle type mask. */
1968#define PDMPCIDEV_IORGN_F_HANDLE_MASK UINT32_C(0x00000003)
1969/** New-style (mostly wrt callbacks). */
1970#define PDMPCIDEV_IORGN_F_NEW_STYLE UINT32_C(0x00000004)
1971/** Mask of valid flags. */
1972#define PDMPCIDEV_IORGN_F_VALID_MASK UINT32_C(0x00000007)
1973/** @} */
1974
1975
1976#ifdef IN_RING3
1977
1978/** @name Special values for PDMDEVHLPR3::pfnPCIRegister parameters.
1979 * @{ */
1980/** Same device number (and bus) as the previous PCI device registered with the PDM device.
1981 * This is handy when registering multiple PCI device functions and the device
1982 * number is left up to the PCI bus. In order to facilitate one PDM device
1983 * instance for each PCI function, this searches earlier PDM device
1984 * instances as well. */
1985# define PDMPCIDEVREG_DEV_NO_SAME_AS_PREV UINT8_C(0xfd)
1986/** Use the first unused device number (all functions must be unused). */
1987# define PDMPCIDEVREG_DEV_NO_FIRST_UNUSED UINT8_C(0xfe)
1988/** Use the first unused device function. */
1989# define PDMPCIDEVREG_FUN_NO_FIRST_UNUSED UINT8_C(0xff)
1990
1991/** The device and function numbers are not mandatory, just suggestions. */
1992# define PDMPCIDEVREG_F_NOT_MANDATORY_NO RT_BIT_32(0)
1993/** Registering a PCI bridge device. */
1994# define PDMPCIDEVREG_F_PCI_BRIDGE RT_BIT_32(1)
1995/** Valid flag mask. */
1996# define PDMPCIDEVREG_F_VALID_MASK UINT32_C(0x00000003)
1997/** @} */
1998
1999/** Current PDMDEVHLPR3 version number. */
2000#define PDM_DEVHLPR3_VERSION PDM_VERSION_MAKE_PP(0xffe7, 36, 0)
2001
2002/**
2003 * PDM Device API.
2004 */
2005typedef struct PDMDEVHLPR3
2006{
2007 /** Structure version. PDM_DEVHLPR3_VERSION defines the current version. */
2008 uint32_t u32Version;
2009
2010 /** @name I/O ports
2011 * @{ */
2012 /**
2013 * Creates a range of I/O ports for a device.
2014 *
2015 * The I/O port range must be mapped in a separately call. Any ring-0 and
2016 * raw-mode context callback handlers needs to be set up in the respective
2017 * contexts.
2018 *
2019 * @returns VBox status.
2020 * @param pDevIns The device instance to register the ports with.
2021 * @param cPorts Number of ports to register.
2022 * @param fFlags IOM_IOPORT_F_XXX.
2023 * @param pPciDev The PCI device the range is associated with, if
2024 * applicable.
2025 * @param iPciRegion The PCI device region in the high 16-bit word and
2026 * sub-region in the low 16-bit word. UINT32_MAX if NA.
2027 * @param pfnOut Pointer to function which is gonna handle OUT
2028 * operations. Optional.
2029 * @param pfnIn Pointer to function which is gonna handle IN operations.
2030 * Optional.
2031 * @param pfnOutStr Pointer to function which is gonna handle string OUT
2032 * operations. Optional.
2033 * @param pfnInStr Pointer to function which is gonna handle string IN
2034 * operations. Optional.
2035 * @param pvUser User argument to pass to the callbacks.
2036 * @param pszDesc Pointer to description string. This must not be freed.
2037 * @param paExtDescs Extended per-port descriptions, optional. Partial range
2038 * coverage is allowed. This must not be freed.
2039 * @param phIoPorts Where to return the I/O port range handle.
2040 *
2041 * @remarks Caller enters the device critical section prior to invoking the
2042 * registered callback methods.
2043 *
2044 * @sa PDMDevHlpIoPortSetUpContext, PDMDevHlpIoPortMap,
2045 * PDMDevHlpIoPortUnmap.
2046 */
2047 DECLR3CALLBACKMEMBER(int, pfnIoPortCreateEx,(PPDMDEVINS pDevIns, RTIOPORT cPorts, uint32_t fFlags, PPDMPCIDEV pPciDev,
2048 uint32_t iPciRegion, PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
2049 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr, RTR3PTR pvUser,
2050 const char *pszDesc, PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts));
2051
2052 /**
2053 * Maps an I/O port range.
2054 *
2055 * @returns VBox status.
2056 * @param pDevIns The device instance to register the ports with.
2057 * @param hIoPorts The I/O port range handle.
2058 * @param Port Where to map the range.
2059 * @sa PDMDevHlpIoPortUnmap, PDMDevHlpIoPortSetUpContext,
2060 * PDMDevHlpIoPortCreate, PDMDevHlpIoPortCreateEx.
2061 */
2062 DECLR3CALLBACKMEMBER(int, pfnIoPortMap,(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts, RTIOPORT Port));
2063
2064 /**
2065 * Unmaps an I/O port range.
2066 *
2067 * @returns VBox status.
2068 * @param pDevIns The device instance to register the ports with.
2069 * @param hIoPorts The I/O port range handle.
2070 * @sa PDMDevHlpIoPortMap, PDMDevHlpIoPortSetUpContext,
2071 * PDMDevHlpIoPortCreate, PDMDevHlpIoPortCreateEx.
2072 */
2073 DECLR3CALLBACKMEMBER(int, pfnIoPortUnmap,(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts));
2074
2075 /**
2076 * Gets the mapping address of the I/O port range @a hIoPorts.
2077 *
2078 * @returns Mapping address (0..65535) or UINT32_MAX if not mapped (or invalid
2079 * parameters).
2080 * @param pDevIns The device instance to register the ports with.
2081 * @param hIoPorts The I/O port range handle.
2082 */
2083 DECLR3CALLBACKMEMBER(uint32_t, pfnIoPortGetMappingAddress,(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts));
2084 /** @} */
2085
2086 /**
2087 * Register a number of I/O ports with a device.
2088 *
2089 * These callbacks are of course for the host context (HC).
2090 * Register HC handlers before guest context (GC) handlers! There must be a
2091 * HC handler for every GC handler!
2092 *
2093 * @returns VBox status.
2094 * @param pDevIns The device instance to register the ports with.
2095 * @param Port First port number in the range.
2096 * @param cPorts Number of ports to register.
2097 * @param pvUser User argument.
2098 * @param pfnOut Pointer to function which is gonna handle OUT operations.
2099 * @param pfnIn Pointer to function which is gonna handle IN operations.
2100 * @param pfnOutStr Pointer to function which is gonna handle string OUT operations.
2101 * @param pfnInStr Pointer to function which is gonna handle string IN operations.
2102 * @param pszDesc Pointer to description string. This must not be freed.
2103 * @remarks Caller enters the device critical section prior to invoking the
2104 * registered callback methods.
2105 * @deprecated
2106 */
2107 DECLR3CALLBACKMEMBER(int, pfnIOPortRegister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser,
2108 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
2109 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc));
2110
2111 /**
2112 * Register a number of I/O ports with a device for RC.
2113 *
2114 * These callbacks are for the raw-mode context (RC). Register ring-3 context
2115 * (R3) handlers before raw-mode context handlers! There must be a R3 handler
2116 * for every RC handler!
2117 *
2118 * @returns VBox status.
2119 * @param pDevIns The device instance to register the ports with
2120 * and which RC module to resolve the names
2121 * against.
2122 * @param Port First port number in the range.
2123 * @param cPorts Number of ports to register.
2124 * @param pvUser User argument.
2125 * @param pszOut Name of the RC function which is gonna handle OUT operations.
2126 * @param pszIn Name of the RC function which is gonna handle IN operations.
2127 * @param pszOutStr Name of the RC function which is gonna handle string OUT operations.
2128 * @param pszInStr Name of the RC function which is gonna handle string IN operations.
2129 * @param pszDesc Pointer to description string. This must not be freed.
2130 * @remarks Caller enters the device critical section prior to invoking the
2131 * registered callback methods.
2132 * @deprecated
2133 */
2134 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterRC,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
2135 const char *pszOut, const char *pszIn,
2136 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
2137
2138 /**
2139 * Register a number of I/O ports with a device.
2140 *
2141 * These callbacks are of course for the ring-0 host context (R0).
2142 * Register R3 (HC) handlers before R0 (R0) handlers! There must be a R3 (HC) handler for every R0 handler!
2143 *
2144 * @returns VBox status.
2145 * @param pDevIns The device instance to register the ports with.
2146 * @param Port First port number in the range.
2147 * @param cPorts Number of ports to register.
2148 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
2149 * @param pszOut Name of the R0 function which is gonna handle OUT operations.
2150 * @param pszIn Name of the R0 function which is gonna handle IN operations.
2151 * @param pszOutStr Name of the R0 function which is gonna handle string OUT operations.
2152 * @param pszInStr Name of the R0 function which is gonna handle string IN operations.
2153 * @param pszDesc Pointer to description string. This must not be freed.
2154 * @remarks Caller enters the device critical section prior to invoking the
2155 * registered callback methods.
2156 * @deprecated
2157 */
2158 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterR0,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
2159 const char *pszOut, const char *pszIn,
2160 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
2161
2162 /**
2163 * Deregister I/O ports.
2164 *
2165 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
2166 *
2167 * @returns VBox status.
2168 * @param pDevIns The device instance owning the ports.
2169 * @param Port First port number in the range.
2170 * @param cPorts Number of ports to deregister.
2171 */
2172 DECLR3CALLBACKMEMBER(int, pfnIOPortDeregister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts));
2173
2174 /** @name MMIO
2175 * @{ */
2176 /**
2177 * Creates a memory mapped I/O (MMIO) region for a device.
2178 *
2179 * The MMIO region must be mapped in a separately call. Any ring-0 and
2180 * raw-mode context callback handlers needs to be set up in the respective
2181 * contexts.
2182 *
2183 * @returns VBox status.
2184 * @param pDevIns The device instance to register the ports with.
2185 * @param cbRegion The size of the region in bytes.
2186 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
2187 * @param pPciDev The PCI device the range is associated with, if
2188 * applicable.
2189 * @param iPciRegion The PCI device region in the high 16-bit word and
2190 * sub-region in the low 16-bit word. UINT32_MAX if NA.
2191 * @param pfnWrite Pointer to function which is gonna handle Write
2192 * operations.
2193 * @param pfnRead Pointer to function which is gonna handle Read
2194 * operations.
2195 * @param pfnFill Pointer to function which is gonna handle Fill/memset
2196 * operations. (optional)
2197 * @param pvUser User argument to pass to the callbacks.
2198 * @param pszDesc Pointer to description string. This must not be freed.
2199 * @param phRegion Where to return the MMIO region handle.
2200 *
2201 * @remarks Caller enters the device critical section prior to invoking the
2202 * registered callback methods.
2203 *
2204 * @sa PDMDevHlpMmioSetUpContext, PDMDevHlpMmioMap, PDMDevHlpMmioUnmap.
2205 */
2206 DECLR3CALLBACKMEMBER(int, pfnMmioCreateEx,(PPDMDEVINS pDevIns, RTGCPHYS cbRegion,
2207 uint32_t fFlags, PPDMPCIDEV pPciDev, uint32_t iPciRegion,
2208 PFNIOMMMIONEWWRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill,
2209 void *pvUser, const char *pszDesc, PIOMMMIOHANDLE phRegion));
2210
2211 /**
2212 * Maps a memory mapped I/O (MMIO) region (into the guest physical address space).
2213 *
2214 * @returns VBox status.
2215 * @param pDevIns The device instance the region is associated with.
2216 * @param hRegion The MMIO region handle.
2217 * @param GCPhys Where to map the region.
2218 * @note An MMIO range may overlap with base memory if a lot of RAM is
2219 * configured for the VM, in which case we'll drop the base memory
2220 * pages. Presently we will make no attempt to preserve anything that
2221 * happens to be present in the base memory that is replaced, this is
2222 * technically incorrect but it's just not worth the effort to do
2223 * right, at least not at this point.
2224 * @sa PDMDevHlpMmioUnmap, PDMDevHlpMmioCreate, PDMDevHlpMmioCreateEx,
2225 * PDMDevHlpMmioSetUpContext
2226 */
2227 DECLR3CALLBACKMEMBER(int, pfnMmioMap,(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, RTGCPHYS GCPhys));
2228
2229 /**
2230 * Unmaps a memory mapped I/O (MMIO) region.
2231 *
2232 * @returns VBox status.
2233 * @param pDevIns The device instance the region is associated with.
2234 * @param hRegion The MMIO region handle.
2235 * @sa PDMDevHlpMmioMap, PDMDevHlpMmioCreate, PDMDevHlpMmioCreateEx,
2236 * PDMDevHlpMmioSetUpContext
2237 */
2238 DECLR3CALLBACKMEMBER(int, pfnMmioUnmap,(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion));
2239
2240 /**
2241 * Reduces the length of a MMIO range.
2242 *
2243 * This is for implementations of PDMPCIDEV::pfnRegionLoadChangeHookR3 and will
2244 * only work during saved state restore. It will not call the PCI bus code, as
2245 * that is expected to restore the saved resource configuration.
2246 *
2247 * It just adjusts the mapping length of the region so that when pfnMmioMap is
2248 * called it will only map @a cbRegion bytes and not the value set during
2249 * registration.
2250 *
2251 * @return VBox status code.
2252 * @param pDevIns The device owning the range.
2253 * @param hRegion The MMIO region handle.
2254 * @param cbRegion The new size, must be smaller.
2255 */
2256 DECLR3CALLBACKMEMBER(int, pfnMmioReduce,(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, RTGCPHYS cbRegion));
2257
2258 /**
2259 * Gets the mapping address of the MMIO region @a hRegion.
2260 *
2261 * @returns Mapping address, NIL_RTGCPHYS if not mapped (or invalid parameters).
2262 * @param pDevIns The device instance to register the ports with.
2263 * @param hRegion The MMIO region handle.
2264 */
2265 DECLR3CALLBACKMEMBER(RTGCPHYS, pfnMmioGetMappingAddress,(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion));
2266 /** @} */
2267
2268 /**
2269 * Register a Memory Mapped I/O (MMIO) region.
2270 *
2271 * These callbacks are of course for the ring-3 context (R3). Register HC
2272 * handlers before raw-mode context (RC) and ring-0 context (R0) handlers! There
2273 * must be a R3 handler for every RC and R0 handler!
2274 *
2275 * @returns VBox status.
2276 * @param pDevIns The device instance to register the MMIO with.
2277 * @param GCPhysStart First physical address in the range.
2278 * @param cbRange The size of the range (in bytes).
2279 * @param pvUser User argument.
2280 * @param pfnWrite Pointer to function which is gonna handle Write operations.
2281 * @param pfnRead Pointer to function which is gonna handle Read operations.
2282 * @param pfnFill Pointer to function which is gonna handle Fill/memset operations. (optional)
2283 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
2284 * @param pszDesc Pointer to description string. This must not be freed.
2285 * @remarks Caller enters the device critical section prior to invoking the
2286 * registered callback methods.
2287 * @deprecated
2288 */
2289 DECLR3CALLBACKMEMBER(int, pfnMMIORegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTHCPTR pvUser,
2290 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
2291 uint32_t fFlags, const char *pszDesc));
2292
2293 /**
2294 * Register a Memory Mapped I/O (MMIO) region for RC.
2295 *
2296 * These callbacks are for the raw-mode context (RC). Register ring-3 context
2297 * (R3) handlers before guest context handlers! There must be a R3 handler for
2298 * every RC handler!
2299 *
2300 * @returns VBox status.
2301 * @param pDevIns The device instance to register the MMIO with.
2302 * @param GCPhysStart First physical address in the range.
2303 * @param cbRange The size of the range (in bytes).
2304 * @param pvUser User argument.
2305 * @param pszWrite Name of the RC function which is gonna handle Write operations.
2306 * @param pszRead Name of the RC function which is gonna handle Read operations.
2307 * @param pszFill Name of the RC function which is gonna handle Fill/memset operations. (optional)
2308 * @remarks Caller enters the device critical section prior to invoking the
2309 * registered callback methods.
2310 * @deprecated
2311 */
2312 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterRC,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTRCPTR pvUser,
2313 const char *pszWrite, const char *pszRead, const char *pszFill));
2314
2315 /**
2316 * Register a Memory Mapped I/O (MMIO) region for R0.
2317 *
2318 * These callbacks are for the ring-0 host context (R0). Register ring-3
2319 * constext (R3) handlers before R0 handlers! There must be a R3 handler for
2320 * every R0 handler!
2321 *
2322 * @returns VBox status.
2323 * @param pDevIns The device instance to register the MMIO with.
2324 * @param GCPhysStart First physical address in the range.
2325 * @param cbRange The size of the range (in bytes).
2326 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
2327 * @param pszWrite Name of the RC function which is gonna handle Write operations.
2328 * @param pszRead Name of the RC function which is gonna handle Read operations.
2329 * @param pszFill Name of the RC function which is gonna handle Fill/memset operations. (optional)
2330 * @remarks Caller enters the device critical section prior to invoking the
2331 * registered callback methods.
2332 * @deprecated
2333 */
2334 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterR0,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTR0PTR pvUser,
2335 const char *pszWrite, const char *pszRead, const char *pszFill));
2336
2337 /**
2338 * Deregister a Memory Mapped I/O (MMIO) region.
2339 *
2340 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
2341 *
2342 * @returns VBox status.
2343 * @param pDevIns The device instance owning the MMIO region(s).
2344 * @param GCPhysStart First physical address in the range.
2345 * @param cbRange The size of the range (in bytes).
2346 * @deprecated
2347 */
2348 DECLR3CALLBACKMEMBER(int, pfnMMIODeregister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange));
2349
2350 /** @name MMIO2
2351 * @{ */
2352 /**
2353 * Creates a MMIO2 region.
2354 *
2355 * As mentioned elsewhere, MMIO2 is just RAM spelled differently. It's RAM
2356 * associated with a device. It is also non-shared memory with a permanent
2357 * ring-3 mapping and page backing (presently).
2358 *
2359 * @returns VBox status.
2360 * @param pDevIns The device instance.
2361 * @param pPciDev The PCI device the region is associated with, or
2362 * NULL if no PCI device association.
2363 * @param iPciRegion The region number. Use the PCI region number as
2364 * this must be known to the PCI bus device too. If
2365 * it's not associated with the PCI device, then
2366 * any number up to UINT8_MAX is fine.
2367 * @param cbRegion The size (in bytes) of the region.
2368 * @param fFlags Reserved for future use, must be zero.
2369 * @param pszDesc Pointer to description string. This must not be
2370 * freed.
2371 * @param ppvMapping Where to store the address of the ring-3 mapping
2372 * of the memory.
2373 * @param phRegion Where to return the MMIO2 region handle.
2374 *
2375 * @thread EMT(0)
2376 */
2377 DECLR3CALLBACKMEMBER(int, pfnMmio2Create,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iPciRegion, RTGCPHYS cbRegion,
2378 uint32_t fFlags, const char *pszDesc, void **ppvMapping, PPGMMMIO2HANDLE phRegion));
2379
2380 /**
2381 * Destroys a MMIO2 region, unmapping it and freeing the memory.
2382 *
2383 * Any physical access handlers registered for the region must be deregistered
2384 * before calling this function.
2385 *
2386 * @returns VBox status code.
2387 * @param pDevIns The device instance.
2388 * @param hRegion The MMIO2 region handle.
2389 * @thread EMT.
2390 */
2391 DECLR3CALLBACKMEMBER(int, pfnMmio2Destroy,(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion));
2392
2393 /**
2394 * Maps a MMIO2 region (into the guest physical address space).
2395 *
2396 * @returns VBox status.
2397 * @param pDevIns The device instance the region is associated with.
2398 * @param hRegion The MMIO2 region handle.
2399 * @param GCPhys Where to map the region.
2400 * @note A MMIO2 region overlap with base memory if a lot of RAM is
2401 * configured for the VM, in which case we'll drop the base memory
2402 * pages. Presently we will make no attempt to preserve anything that
2403 * happens to be present in the base memory that is replaced, this is
2404 * technically incorrect but it's just not worth the effort to do
2405 * right, at least not at this point.
2406 * @sa PDMDevHlpMmio2Unmap, PDMDevHlpMmio2Create, PDMDevHlpMmio2SetUpContext
2407 */
2408 DECLR3CALLBACKMEMBER(int, pfnMmio2Map,(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, RTGCPHYS GCPhys));
2409
2410 /**
2411 * Unmaps a MMIO2 region.
2412 *
2413 * @returns VBox status.
2414 * @param pDevIns The device instance the region is associated with.
2415 * @param hRegion The MMIO2 region handle.
2416 * @sa PDMDevHlpMmio2Map, PDMDevHlpMmio2Create, PDMDevHlpMmio2SetUpContext
2417 */
2418 DECLR3CALLBACKMEMBER(int, pfnMmio2Unmap,(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion));
2419
2420 /**
2421 * Reduces the length of a MMIO range.
2422 *
2423 * This is for implementations of PDMPCIDEV::pfnRegionLoadChangeHookR3 and will
2424 * only work during saved state restore. It will not call the PCI bus code, as
2425 * that is expected to restore the saved resource configuration.
2426 *
2427 * It just adjusts the mapping length of the region so that when pfnMmioMap is
2428 * called it will only map @a cbRegion bytes and not the value set during
2429 * registration.
2430 *
2431 * @return VBox status code.
2432 * @param pDevIns The device owning the range.
2433 * @param hRegion The MMIO2 region handle.
2434 * @param cbRegion The new size, must be smaller.
2435 */
2436 DECLR3CALLBACKMEMBER(int, pfnMmio2Reduce,(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, RTGCPHYS cbRegion));
2437
2438 /**
2439 * Gets the mapping address of the MMIO region @a hRegion.
2440 *
2441 * @returns Mapping address, NIL_RTGCPHYS if not mapped (or invalid parameters).
2442 * @param pDevIns The device instance to register the ports with.
2443 * @param hRegion The MMIO2 region handle.
2444 */
2445 DECLR3CALLBACKMEMBER(RTGCPHYS, pfnMmio2GetMappingAddress,(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion));
2446
2447 /**
2448 * Changes the number of an MMIO2 or pre-registered MMIO region.
2449 *
2450 * This should only be used to deal with saved state problems, so there is no
2451 * convenience inline wrapper for this method.
2452 *
2453 * @returns VBox status code.
2454 * @param pDevIns The device instance.
2455 * @param hRegion The MMIO2 region handle.
2456 * @param iNewRegion The new region index.
2457 *
2458 * @sa @bugref{9359}
2459 */
2460 DECLR3CALLBACKMEMBER(int, pfnMmio2ChangeRegionNo,(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, uint32_t iNewRegion));
2461 /** @} */
2462
2463 /**
2464 * Allocate and register a MMIO2 region.
2465 *
2466 * As mentioned elsewhere, MMIO2 is just RAM spelled differently. It's RAM
2467 * associated with a device. It is also non-shared memory with a permanent
2468 * ring-3 mapping and page backing (presently).
2469 *
2470 * @returns VBox status.
2471 * @param pDevIns The device instance.
2472 * @param pPciDev The PCI device the region is associated with, or
2473 * NULL if no PCI device association.
2474 * @param iRegion The region number. Use the PCI region number as
2475 * this must be known to the PCI bus device too. If
2476 * it's not associated with the PCI device, then
2477 * any number up to UINT8_MAX is fine.
2478 * @param cb The size (in bytes) of the region.
2479 * @param fFlags Reserved for future use, must be zero.
2480 * @param ppv Where to store the address of the ring-3 mapping
2481 * of the memory.
2482 * @param pszDesc Pointer to description string. This must not be
2483 * freed.
2484 * @thread EMT.
2485 * @deprecated
2486 */
2487 DECLR3CALLBACKMEMBER(int, pfnMMIO2Register,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS cb,
2488 uint32_t fFlags, void **ppv, const char *pszDesc));
2489
2490 /**
2491 * Deregisters and frees a MMIO or MMIO2 region.
2492 *
2493 * Any physical (and virtual) access handlers registered for the region must
2494 * be deregistered before calling this function (MMIO2 only).
2495 *
2496 * @returns VBox status code.
2497 * @param pDevIns The device instance.
2498 * @param pPciDev The PCI device the region is associated with, or
2499 * NULL if not associated with any.
2500 * @param iRegion The region number used during registration.
2501 * @thread EMT.
2502 * @deprecated
2503 */
2504 DECLR3CALLBACKMEMBER(int, pfnMMIOExDeregister,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion));
2505
2506 /**
2507 * Maps a MMIO or MMIO2 region into the physical memory space.
2508 *
2509 * A MMIO2 range or a pre-registered MMIO range may overlap with base memory if
2510 * a lot of RAM is configured for the VM, in which case we'll drop the base
2511 * memory pages. Presently we will make no attempt to preserve anything that
2512 * happens to be present in the base memory that is replaced, this is of course
2513 * incorrect but it's too much effort.
2514 *
2515 * @returns VBox status code.
2516 * @param pDevIns The device instance.
2517 * @param pPciDev The PCI device the region is associated with, or
2518 * NULL if not associated with any.
2519 * @param iRegion The region number used during registration.
2520 * @param GCPhys The physical address to map it at.
2521 * @thread EMT.
2522 * @deprecated for MMIO
2523 */
2524 DECLR3CALLBACKMEMBER(int, pfnMMIOExMap,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS GCPhys));
2525
2526 /**
2527 * Unmaps a MMIO or MMIO2 region previously mapped using pfnMMIOExMap.
2528 *
2529 * @returns VBox status code.
2530 * @param pDevIns The device instance.
2531 * @param pPciDev The PCI device the region is associated with, or
2532 * NULL if not associated with any.
2533 * @param iRegion The region number used during registration.
2534 * @param GCPhys The physical address it's currently mapped at.
2535 * @thread EMT.
2536 * @deprecated for MMIO
2537 */
2538 DECLR3CALLBACKMEMBER(int, pfnMMIOExUnmap,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS GCPhys));
2539
2540 /**
2541 * Reduces the length of a MMIO2 or pre-registered MMIO range.
2542 *
2543 * This is for implementations of PDMPCIDEV::pfnRegionLoadChangeHookR3 and will
2544 * only work during saved state restore. It will not call the PCI bus code, as
2545 * that is expected to restore the saved resource configuration.
2546 *
2547 * It just adjusts the mapping length of the region so that when pfnMMIOExMap is
2548 * called it will only map @a cbRegion bytes and not the value set during
2549 * registration.
2550 *
2551 * @return VBox status code.
2552 * @param pDevIns The device owning the range.
2553 * @param pPciDev The PCI device the region is associated with, or
2554 * NULL if not associated with any.
2555 * @param iRegion The region.
2556 * @param cbRegion The new size, must be smaller.
2557 */
2558 DECLR3CALLBACKMEMBER(int, pfnMMIOExReduce,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS cbRegion));
2559
2560 /**
2561 * Maps a portion of an MMIO2 region into the hypervisor region.
2562 *
2563 * Callers of this API must never deregister the MMIO2 region before the
2564 * VM is powered off.
2565 *
2566 * @return VBox status code.
2567 * @param pDevIns The device owning the MMIO2 memory.
2568 * @param pPciDev The PCI device the region is associated with, or
2569 * NULL if not associated with any.
2570 * @param iRegion The region.
2571 * @param off The offset into the region. Will be rounded down
2572 * to closest page boundary.
2573 * @param cb The number of bytes to map. Will be rounded up
2574 * to the closest page boundary.
2575 * @param pszDesc Mapping description.
2576 * @param pRCPtr Where to store the RC address.
2577 */
2578 DECLR3CALLBACKMEMBER(int, pfnMMHyperMapMMIO2,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS off,
2579 RTGCPHYS cb, const char *pszDesc, PRTRCPTR pRCPtr));
2580
2581 /**
2582 * Maps a portion of an MMIO2 region into kernel space (host).
2583 *
2584 * The kernel mapping will become invalid when the MMIO2 memory is deregistered
2585 * or the VM is terminated.
2586 *
2587 * @return VBox status code.
2588 * @param pDevIns The device owning the MMIO2 memory.
2589 * @param pPciDev The PCI device the region is associated with, or
2590 * NULL if not associated with any.
2591 * @param iRegion The region.
2592 * @param off The offset into the region. Must be page
2593 * aligned.
2594 * @param cb The number of bytes to map. Must be page
2595 * aligned.
2596 * @param pszDesc Mapping description.
2597 * @param pR0Ptr Where to store the R0 address.
2598 */
2599 DECLR3CALLBACKMEMBER(int, pfnMMIO2MapKernel,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS off,
2600 RTGCPHYS cb, const char *pszDesc, PRTR0PTR pR0Ptr));
2601
2602 /**
2603 * Register a ROM (BIOS) region.
2604 *
2605 * It goes without saying that this is read-only memory. The memory region must be
2606 * in unassigned memory. I.e. from the top of the address space or on the PC in
2607 * the 0xa0000-0xfffff range.
2608 *
2609 * @returns VBox status.
2610 * @param pDevIns The device instance owning the ROM region.
2611 * @param GCPhysStart First physical address in the range.
2612 * Must be page aligned!
2613 * @param cbRange The size of the range (in bytes).
2614 * Must be page aligned!
2615 * @param pvBinary Pointer to the binary data backing the ROM image.
2616 * @param cbBinary The size of the binary pointer. This must
2617 * be equal or smaller than @a cbRange.
2618 * @param fFlags Shadow ROM flags, PGMPHYS_ROM_FLAGS_* in pgm.h.
2619 * @param pszDesc Pointer to description string. This must not be freed.
2620 *
2621 * @remark There is no way to remove the rom, automatically on device cleanup or
2622 * manually from the device yet. At present I doubt we need such features...
2623 */
2624 DECLR3CALLBACKMEMBER(int, pfnROMRegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
2625 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc));
2626
2627 /**
2628 * Changes the protection of shadowed ROM mapping.
2629 *
2630 * This is intented for use by the system BIOS, chipset or device in question to
2631 * change the protection of shadowed ROM code after init and on reset.
2632 *
2633 * @param pDevIns The device instance.
2634 * @param GCPhysStart Where the mapping starts.
2635 * @param cbRange The size of the mapping.
2636 * @param enmProt The new protection type.
2637 */
2638 DECLR3CALLBACKMEMBER(int, pfnROMProtectShadow,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt));
2639
2640 /**
2641 * Register a save state data unit.
2642 *
2643 * @returns VBox status.
2644 * @param pDevIns The device instance.
2645 * @param uVersion Data layout version number.
2646 * @param cbGuess The approximate amount of data in the unit.
2647 * Only for progress indicators.
2648 * @param pszBefore Name of data unit which we should be put in
2649 * front of. Optional (NULL).
2650 *
2651 * @param pfnLivePrep Prepare live save callback, optional.
2652 * @param pfnLiveExec Execute live save callback, optional.
2653 * @param pfnLiveVote Vote live save callback, optional.
2654 *
2655 * @param pfnSavePrep Prepare save callback, optional.
2656 * @param pfnSaveExec Execute save callback, optional.
2657 * @param pfnSaveDone Done save callback, optional.
2658 *
2659 * @param pfnLoadPrep Prepare load callback, optional.
2660 * @param pfnLoadExec Execute load callback, optional.
2661 * @param pfnLoadDone Done load callback, optional.
2662 * @remarks Caller enters the device critical section prior to invoking the
2663 * registered callback methods.
2664 */
2665 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
2666 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
2667 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
2668 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone));
2669
2670 /** @name Exported SSM Functions
2671 * @{ */
2672 DECLR3CALLBACKMEMBER(int, pfnSSMPutStruct,(PSSMHANDLE pSSM, const void *pvStruct, PCSSMFIELD paFields));
2673 DECLR3CALLBACKMEMBER(int, pfnSSMPutStructEx,(PSSMHANDLE pSSM, const void *pvStruct, size_t cbStruct, uint32_t fFlags, PCSSMFIELD paFields, void *pvUser));
2674 DECLR3CALLBACKMEMBER(int, pfnSSMPutBool,(PSSMHANDLE pSSM, bool fBool));
2675 DECLR3CALLBACKMEMBER(int, pfnSSMPutU8,(PSSMHANDLE pSSM, uint8_t u8));
2676 DECLR3CALLBACKMEMBER(int, pfnSSMPutS8,(PSSMHANDLE pSSM, int8_t i8));
2677 DECLR3CALLBACKMEMBER(int, pfnSSMPutU16,(PSSMHANDLE pSSM, uint16_t u16));
2678 DECLR3CALLBACKMEMBER(int, pfnSSMPutS16,(PSSMHANDLE pSSM, int16_t i16));
2679 DECLR3CALLBACKMEMBER(int, pfnSSMPutU32,(PSSMHANDLE pSSM, uint32_t u32));
2680 DECLR3CALLBACKMEMBER(int, pfnSSMPutS32,(PSSMHANDLE pSSM, int32_t i32));
2681 DECLR3CALLBACKMEMBER(int, pfnSSMPutU64,(PSSMHANDLE pSSM, uint64_t u64));
2682 DECLR3CALLBACKMEMBER(int, pfnSSMPutS64,(PSSMHANDLE pSSM, int64_t i64));
2683 DECLR3CALLBACKMEMBER(int, pfnSSMPutU128,(PSSMHANDLE pSSM, uint128_t u128));
2684 DECLR3CALLBACKMEMBER(int, pfnSSMPutS128,(PSSMHANDLE pSSM, int128_t i128));
2685 DECLR3CALLBACKMEMBER(int, pfnSSMPutUInt,(PSSMHANDLE pSSM, RTUINT u));
2686 DECLR3CALLBACKMEMBER(int, pfnSSMPutSInt,(PSSMHANDLE pSSM, RTINT i));
2687 DECLR3CALLBACKMEMBER(int, pfnSSMPutGCUInt,(PSSMHANDLE pSSM, RTGCUINT u));
2688 DECLR3CALLBACKMEMBER(int, pfnSSMPutGCUIntReg,(PSSMHANDLE pSSM, RTGCUINTREG u));
2689 DECLR3CALLBACKMEMBER(int, pfnSSMPutGCPhys32,(PSSMHANDLE pSSM, RTGCPHYS32 GCPhys));
2690 DECLR3CALLBACKMEMBER(int, pfnSSMPutGCPhys64,(PSSMHANDLE pSSM, RTGCPHYS64 GCPhys));
2691 DECLR3CALLBACKMEMBER(int, pfnSSMPutGCPhys,(PSSMHANDLE pSSM, RTGCPHYS GCPhys));
2692 DECLR3CALLBACKMEMBER(int, pfnSSMPutGCPtr,(PSSMHANDLE pSSM, RTGCPTR GCPtr));
2693 DECLR3CALLBACKMEMBER(int, pfnSSMPutGCUIntPtr,(PSSMHANDLE pSSM, RTGCUINTPTR GCPtr));
2694 DECLR3CALLBACKMEMBER(int, pfnSSMPutRCPtr,(PSSMHANDLE pSSM, RTRCPTR RCPtr));
2695 DECLR3CALLBACKMEMBER(int, pfnSSMPutIOPort,(PSSMHANDLE pSSM, RTIOPORT IOPort));
2696 DECLR3CALLBACKMEMBER(int, pfnSSMPutSel,(PSSMHANDLE pSSM, RTSEL Sel));
2697 DECLR3CALLBACKMEMBER(int, pfnSSMPutMem,(PSSMHANDLE pSSM, const void *pv, size_t cb));
2698 DECLR3CALLBACKMEMBER(int, pfnSSMPutStrZ,(PSSMHANDLE pSSM, const char *psz));
2699 DECLR3CALLBACKMEMBER(int, pfnSSMGetStruct,(PSSMHANDLE pSSM, void *pvStruct, PCSSMFIELD paFields));
2700 DECLR3CALLBACKMEMBER(int, pfnSSMGetStructEx,(PSSMHANDLE pSSM, void *pvStruct, size_t cbStruct, uint32_t fFlags, PCSSMFIELD paFields, void *pvUser));
2701 DECLR3CALLBACKMEMBER(int, pfnSSMGetBool,(PSSMHANDLE pSSM, bool *pfBool));
2702 DECLR3CALLBACKMEMBER(int, pfnSSMGetBoolV,(PSSMHANDLE pSSM, bool volatile *pfBool));
2703 DECLR3CALLBACKMEMBER(int, pfnSSMGetU8,(PSSMHANDLE pSSM, uint8_t *pu8));
2704 DECLR3CALLBACKMEMBER(int, pfnSSMGetU8V,(PSSMHANDLE pSSM, uint8_t volatile *pu8));
2705 DECLR3CALLBACKMEMBER(int, pfnSSMGetS8,(PSSMHANDLE pSSM, int8_t *pi8));
2706 DECLR3CALLBACKMEMBER(int, pfnSSMGetS8V,(PSSMHANDLE pSSM, int8_t volatile *pi8));
2707 DECLR3CALLBACKMEMBER(int, pfnSSMGetU16,(PSSMHANDLE pSSM, uint16_t *pu16));
2708 DECLR3CALLBACKMEMBER(int, pfnSSMGetU16V,(PSSMHANDLE pSSM, uint16_t volatile *pu16));
2709 DECLR3CALLBACKMEMBER(int, pfnSSMGetS16,(PSSMHANDLE pSSM, int16_t *pi16));
2710 DECLR3CALLBACKMEMBER(int, pfnSSMGetS16V,(PSSMHANDLE pSSM, int16_t volatile *pi16));
2711 DECLR3CALLBACKMEMBER(int, pfnSSMGetU32,(PSSMHANDLE pSSM, uint32_t *pu32));
2712 DECLR3CALLBACKMEMBER(int, pfnSSMGetU32V,(PSSMHANDLE pSSM, uint32_t volatile *pu32));
2713 DECLR3CALLBACKMEMBER(int, pfnSSMGetS32,(PSSMHANDLE pSSM, int32_t *pi32));
2714 DECLR3CALLBACKMEMBER(int, pfnSSMGetS32V,(PSSMHANDLE pSSM, int32_t volatile *pi32));
2715 DECLR3CALLBACKMEMBER(int, pfnSSMGetU64,(PSSMHANDLE pSSM, uint64_t *pu64));
2716 DECLR3CALLBACKMEMBER(int, pfnSSMGetU64V,(PSSMHANDLE pSSM, uint64_t volatile *pu64));
2717 DECLR3CALLBACKMEMBER(int, pfnSSMGetS64,(PSSMHANDLE pSSM, int64_t *pi64));
2718 DECLR3CALLBACKMEMBER(int, pfnSSMGetS64V,(PSSMHANDLE pSSM, int64_t volatile *pi64));
2719 DECLR3CALLBACKMEMBER(int, pfnSSMGetU128,(PSSMHANDLE pSSM, uint128_t *pu128));
2720 DECLR3CALLBACKMEMBER(int, pfnSSMGetU128V,(PSSMHANDLE pSSM, uint128_t volatile *pu128));
2721 DECLR3CALLBACKMEMBER(int, pfnSSMGetS128,(PSSMHANDLE pSSM, int128_t *pi128));
2722 DECLR3CALLBACKMEMBER(int, pfnSSMGetS128V,(PSSMHANDLE pSSM, int128_t volatile *pi128));
2723 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCPhys32,(PSSMHANDLE pSSM, PRTGCPHYS32 pGCPhys));
2724 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCPhys32V,(PSSMHANDLE pSSM, RTGCPHYS32 volatile *pGCPhys));
2725 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCPhys64,(PSSMHANDLE pSSM, PRTGCPHYS64 pGCPhys));
2726 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCPhys64V,(PSSMHANDLE pSSM, RTGCPHYS64 volatile *pGCPhys));
2727 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCPhys,(PSSMHANDLE pSSM, PRTGCPHYS pGCPhys));
2728 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCPhysV,(PSSMHANDLE pSSM, RTGCPHYS volatile *pGCPhys));
2729 DECLR3CALLBACKMEMBER(int, pfnSSMGetUInt,(PSSMHANDLE pSSM, PRTUINT pu));
2730 DECLR3CALLBACKMEMBER(int, pfnSSMGetSInt,(PSSMHANDLE pSSM, PRTINT pi));
2731 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCUInt,(PSSMHANDLE pSSM, PRTGCUINT pu));
2732 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCUIntReg,(PSSMHANDLE pSSM, PRTGCUINTREG pu));
2733 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCPtr,(PSSMHANDLE pSSM, PRTGCPTR pGCPtr));
2734 DECLR3CALLBACKMEMBER(int, pfnSSMGetGCUIntPtr,(PSSMHANDLE pSSM, PRTGCUINTPTR pGCPtr));
2735 DECLR3CALLBACKMEMBER(int, pfnSSMGetRCPtr,(PSSMHANDLE pSSM, PRTRCPTR pRCPtr));
2736 DECLR3CALLBACKMEMBER(int, pfnSSMGetIOPort,(PSSMHANDLE pSSM, PRTIOPORT pIOPort));
2737 DECLR3CALLBACKMEMBER(int, pfnSSMGetSel,(PSSMHANDLE pSSM, PRTSEL pSel));
2738 DECLR3CALLBACKMEMBER(int, pfnSSMGetMem,(PSSMHANDLE pSSM, void *pv, size_t cb));
2739 DECLR3CALLBACKMEMBER(int, pfnSSMGetStrZ,(PSSMHANDLE pSSM, char *psz, size_t cbMax));
2740 DECLR3CALLBACKMEMBER(int, pfnSSMGetStrZEx,(PSSMHANDLE pSSM, char *psz, size_t cbMax, size_t *pcbStr));
2741 DECLR3CALLBACKMEMBER(int, pfnSSMSkip,(PSSMHANDLE pSSM, size_t cb));
2742 DECLR3CALLBACKMEMBER(int, pfnSSMSkipToEndOfUnit,(PSSMHANDLE pSSM));
2743 DECLR3CALLBACKMEMBER(int, pfnSSMSetLoadError,(PSSMHANDLE pSSM, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(6, 7));
2744 DECLR3CALLBACKMEMBER(int, pfnSSMSetLoadErrorV,(PSSMHANDLE pSSM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(6, 0));
2745 DECLR3CALLBACKMEMBER(int, pfnSSMSetCfgError,(PSSMHANDLE pSSM, RT_SRC_POS_DECL, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(5, 6));
2746 DECLR3CALLBACKMEMBER(int, pfnSSMSetCfgErrorV,(PSSMHANDLE pSSM, RT_SRC_POS_DECL, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(5, 0));
2747 DECLR3CALLBACKMEMBER(int, pfnSSMHandleGetStatus,(PSSMHANDLE pSSM));
2748 DECLR3CALLBACKMEMBER(SSMAFTER, pfnSSMHandleGetAfter,(PSSMHANDLE pSSM));
2749 DECLR3CALLBACKMEMBER(bool, pfnSSMHandleIsLiveSave,(PSSMHANDLE pSSM));
2750 DECLR3CALLBACKMEMBER(uint32_t, pfnSSMHandleMaxDowntime,(PSSMHANDLE pSSM));
2751 DECLR3CALLBACKMEMBER(uint32_t, pfnSSMHandleHostBits,(PSSMHANDLE pSSM));
2752 DECLR3CALLBACKMEMBER(uint32_t, pfnSSMHandleRevision,(PSSMHANDLE pSSM));
2753 DECLR3CALLBACKMEMBER(uint32_t, pfnSSMHandleVersion,(PSSMHANDLE pSSM));
2754 /** @} */
2755
2756 /**
2757 * Creates a timer.
2758 *
2759 * @returns VBox status.
2760 * @param pDevIns The device instance.
2761 * @param enmClock The clock to use on this timer.
2762 * @param pfnCallback Callback function.
2763 * @param pvUser User argument for the callback.
2764 * @param fFlags Flags, see TMTIMER_FLAGS_*.
2765 * @param pszDesc Pointer to description string which must stay around
2766 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
2767 * @param ppTimer Where to store the timer on success.
2768 * @remarks Caller enters the device critical section prior to invoking the
2769 * callback.
2770 */
2771 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback,
2772 void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer));
2773
2774 /**
2775 * Creates a timer w/ a cross context handle.
2776 *
2777 * @returns VBox status.
2778 * @param pDevIns The device instance.
2779 * @param enmClock The clock to use on this timer.
2780 * @param pfnCallback Callback function.
2781 * @param pvUser User argument for the callback.
2782 * @param fFlags Flags, see TMTIMER_FLAGS_*.
2783 * @param pszDesc Pointer to description string which must stay around
2784 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
2785 * @param phTimer Where to store the timer handle on success.
2786 * @remarks Caller enters the device critical section prior to invoking the
2787 * callback.
2788 */
2789 DECLR3CALLBACKMEMBER(int, pfnTimerCreate,(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback,
2790 void *pvUser, uint32_t fFlags, const char *pszDesc, PTMTIMERHANDLE phTimer));
2791
2792 /**
2793 * Translates a timer handle to a pointer.
2794 *
2795 * @returns The time address.
2796 * @param pDevIns The device instance.
2797 * @param hTimer The timer handle.
2798 */
2799 DECLR3CALLBACKMEMBER(PTMTIMERR3, pfnTimerToPtr,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2800
2801 /** @name Timer handle method wrappers
2802 * @{ */
2803 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerFromMicro,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMicroSecs));
2804 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerFromMilli,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMilliSecs));
2805 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerFromNano,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cNanoSecs));
2806 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerGet,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2807 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerGetFreq,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2808 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerGetNano,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2809 DECLR3CALLBACKMEMBER(bool, pfnTimerIsActive,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2810 DECLR3CALLBACKMEMBER(bool, pfnTimerIsLockOwner,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2811 DECLR3CALLBACKMEMBER(int, pfnTimerLock,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, int rcBusy));
2812 DECLR3CALLBACKMEMBER(int, pfnTimerSet,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t uExpire));
2813 DECLR3CALLBACKMEMBER(int, pfnTimerSetFrequencyHint,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint32_t uHz));
2814 DECLR3CALLBACKMEMBER(int, pfnTimerSetMicro,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext));
2815 DECLR3CALLBACKMEMBER(int, pfnTimerSetMillies,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMilliesToNext));
2816 DECLR3CALLBACKMEMBER(int, pfnTimerSetNano,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cNanosToNext));
2817 DECLR3CALLBACKMEMBER(int, pfnTimerSetRelative,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now));
2818 DECLR3CALLBACKMEMBER(int, pfnTimerStop,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2819 DECLR3CALLBACKMEMBER(void, pfnTimerUnlock,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2820 DECLR3CALLBACKMEMBER(int, pfnTimerSetCritSect,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect));
2821 DECLR3CALLBACKMEMBER(int, pfnTimerSave,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM));
2822 DECLR3CALLBACKMEMBER(int, pfnTimerLoad,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM));
2823 DECLR3CALLBACKMEMBER(int, pfnTimerDestroy,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
2824 /** @sa TMR3TimerSkip */
2825 DECLR3CALLBACKMEMBER(int, pfnTimerSkipLoad,(PSSMHANDLE pSSM, bool *pfActive));
2826 /** @} */
2827
2828 /**
2829 * Get the real world UTC time adjusted for VM lag, user offset and warpdrive.
2830 *
2831 * @returns pTime.
2832 * @param pDevIns The device instance.
2833 * @param pTime Where to store the time.
2834 */
2835 DECLR3CALLBACKMEMBER(PRTTIMESPEC, pfnTMUtcNow,(PPDMDEVINS pDevIns, PRTTIMESPEC pTime));
2836
2837 /** @name Exported CFGM Functions.
2838 * @{ */
2839 DECLR3CALLBACKMEMBER(bool, pfnCFGMExists,( PCFGMNODE pNode, const char *pszName));
2840 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryType,( PCFGMNODE pNode, const char *pszName, PCFGMVALUETYPE penmType));
2841 DECLR3CALLBACKMEMBER(int, pfnCFGMQuerySize,( PCFGMNODE pNode, const char *pszName, size_t *pcb));
2842 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryInteger,( PCFGMNODE pNode, const char *pszName, uint64_t *pu64));
2843 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryIntegerDef,( PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def));
2844 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryString,( PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString));
2845 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryStringDef,( PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef));
2846 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryBytes,( PCFGMNODE pNode, const char *pszName, void *pvData, size_t cbData));
2847 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryU64,( PCFGMNODE pNode, const char *pszName, uint64_t *pu64));
2848 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryU64Def,( PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def));
2849 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryS64,( PCFGMNODE pNode, const char *pszName, int64_t *pi64));
2850 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryS64Def,( PCFGMNODE pNode, const char *pszName, int64_t *pi64, int64_t i64Def));
2851 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryU32,( PCFGMNODE pNode, const char *pszName, uint32_t *pu32));
2852 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryU32Def,( PCFGMNODE pNode, const char *pszName, uint32_t *pu32, uint32_t u32Def));
2853 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryS32,( PCFGMNODE pNode, const char *pszName, int32_t *pi32));
2854 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryS32Def,( PCFGMNODE pNode, const char *pszName, int32_t *pi32, int32_t i32Def));
2855 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryU16,( PCFGMNODE pNode, const char *pszName, uint16_t *pu16));
2856 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryU16Def,( PCFGMNODE pNode, const char *pszName, uint16_t *pu16, uint16_t u16Def));
2857 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryS16,( PCFGMNODE pNode, const char *pszName, int16_t *pi16));
2858 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryS16Def,( PCFGMNODE pNode, const char *pszName, int16_t *pi16, int16_t i16Def));
2859 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryU8,( PCFGMNODE pNode, const char *pszName, uint8_t *pu8));
2860 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryU8Def,( PCFGMNODE pNode, const char *pszName, uint8_t *pu8, uint8_t u8Def));
2861 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryS8,( PCFGMNODE pNode, const char *pszName, int8_t *pi8));
2862 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryS8Def,( PCFGMNODE pNode, const char *pszName, int8_t *pi8, int8_t i8Def));
2863 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryBool,( PCFGMNODE pNode, const char *pszName, bool *pf));
2864 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryBoolDef,( PCFGMNODE pNode, const char *pszName, bool *pf, bool fDef));
2865 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryPort,( PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort));
2866 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryPortDef,( PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort, RTIOPORT PortDef));
2867 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryUInt,( PCFGMNODE pNode, const char *pszName, unsigned int *pu));
2868 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryUIntDef,( PCFGMNODE pNode, const char *pszName, unsigned int *pu, unsigned int uDef));
2869 DECLR3CALLBACKMEMBER(int, pfnCFGMQuerySInt,( PCFGMNODE pNode, const char *pszName, signed int *pi));
2870 DECLR3CALLBACKMEMBER(int, pfnCFGMQuerySIntDef,( PCFGMNODE pNode, const char *pszName, signed int *pi, signed int iDef));
2871 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryPtr,( PCFGMNODE pNode, const char *pszName, void **ppv));
2872 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryPtrDef,( PCFGMNODE pNode, const char *pszName, void **ppv, void *pvDef));
2873 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryGCPtr,( PCFGMNODE pNode, const char *pszName, PRTGCPTR pGCPtr));
2874 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryGCPtrDef,( PCFGMNODE pNode, const char *pszName, PRTGCPTR pGCPtr, RTGCPTR GCPtrDef));
2875 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryGCPtrU,( PCFGMNODE pNode, const char *pszName, PRTGCUINTPTR pGCPtr));
2876 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryGCPtrUDef,( PCFGMNODE pNode, const char *pszName, PRTGCUINTPTR pGCPtr, RTGCUINTPTR GCPtrDef));
2877 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryGCPtrS,( PCFGMNODE pNode, const char *pszName, PRTGCINTPTR pGCPtr));
2878 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryGCPtrSDef,( PCFGMNODE pNode, const char *pszName, PRTGCINTPTR pGCPtr, RTGCINTPTR GCPtrDef));
2879 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryStringAlloc,( PCFGMNODE pNode, const char *pszName, char **ppszString));
2880 DECLR3CALLBACKMEMBER(int, pfnCFGMQueryStringAllocDef,(PCFGMNODE pNode, const char *pszName, char **ppszString, const char *pszDef));
2881 DECLR3CALLBACKMEMBER(PCFGMNODE, pfnCFGMGetParent,(PCFGMNODE pNode));
2882 DECLR3CALLBACKMEMBER(PCFGMNODE, pfnCFGMGetChild,(PCFGMNODE pNode, const char *pszPath));
2883 DECLR3CALLBACKMEMBER(PCFGMNODE, pfnCFGMGetChildF,(PCFGMNODE pNode, const char *pszPathFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3));
2884 DECLR3CALLBACKMEMBER(PCFGMNODE, pfnCFGMGetChildFV,(PCFGMNODE pNode, const char *pszPathFormat, va_list Args) RT_IPRT_FORMAT_ATTR(3, 0));
2885 DECLR3CALLBACKMEMBER(PCFGMNODE, pfnCFGMGetFirstChild,(PCFGMNODE pNode));
2886 DECLR3CALLBACKMEMBER(PCFGMNODE, pfnCFGMGetNextChild,(PCFGMNODE pCur));
2887 DECLR3CALLBACKMEMBER(int, pfnCFGMGetName,(PCFGMNODE pCur, char *pszName, size_t cchName));
2888 DECLR3CALLBACKMEMBER(size_t, pfnCFGMGetNameLen,(PCFGMNODE pCur));
2889 DECLR3CALLBACKMEMBER(bool, pfnCFGMAreChildrenValid,(PCFGMNODE pNode, const char *pszzValid));
2890 DECLR3CALLBACKMEMBER(PCFGMLEAF, pfnCFGMGetFirstValue,(PCFGMNODE pCur));
2891 DECLR3CALLBACKMEMBER(PCFGMLEAF, pfnCFGMGetNextValue,(PCFGMLEAF pCur));
2892 DECLR3CALLBACKMEMBER(int, pfnCFGMGetValueName,(PCFGMLEAF pCur, char *pszName, size_t cchName));
2893 DECLR3CALLBACKMEMBER(size_t, pfnCFGMGetValueNameLen,(PCFGMLEAF pCur));
2894 DECLR3CALLBACKMEMBER(CFGMVALUETYPE, pfnCFGMGetValueType,(PCFGMLEAF pCur));
2895 DECLR3CALLBACKMEMBER(bool, pfnCFGMAreValuesValid,(PCFGMNODE pNode, const char *pszzValid));
2896 DECLR3CALLBACKMEMBER(int, pfnCFGMValidateConfig,(PCFGMNODE pNode, const char *pszNode,
2897 const char *pszValidValues, const char *pszValidNodes,
2898 const char *pszWho, uint32_t uInstance));
2899 /** @} */
2900
2901 /**
2902 * Read physical memory.
2903 *
2904 * @returns VINF_SUCCESS (for now).
2905 * @param pDevIns The device instance.
2906 * @param GCPhys Physical address start reading from.
2907 * @param pvBuf Where to put the read bits.
2908 * @param cbRead How many bytes to read.
2909 * @thread Any thread, but the call may involve the emulation thread.
2910 */
2911 DECLR3CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
2912
2913 /**
2914 * Write to physical memory.
2915 *
2916 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
2917 * @param pDevIns The device instance.
2918 * @param GCPhys Physical address to write to.
2919 * @param pvBuf What to write.
2920 * @param cbWrite How many bytes to write.
2921 * @thread Any thread, but the call may involve the emulation thread.
2922 */
2923 DECLR3CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
2924
2925 /**
2926 * Requests the mapping of a guest page into ring-3.
2927 *
2928 * When you're done with the page, call pfnPhysReleasePageMappingLock() ASAP to
2929 * release it.
2930 *
2931 * This API will assume your intention is to write to the page, and will
2932 * therefore replace shared and zero pages. If you do not intend to modify the
2933 * page, use the pfnPhysGCPhys2CCPtrReadOnly() API.
2934 *
2935 * @returns VBox status code.
2936 * @retval VINF_SUCCESS on success.
2937 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
2938 * backing or if the page has any active access handlers. The caller
2939 * must fall back on using PGMR3PhysWriteExternal.
2940 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
2941 *
2942 * @param pDevIns The device instance.
2943 * @param GCPhys The guest physical address of the page that
2944 * should be mapped.
2945 * @param fFlags Flags reserved for future use, MBZ.
2946 * @param ppv Where to store the address corresponding to
2947 * GCPhys.
2948 * @param pLock Where to store the lock information that
2949 * pfnPhysReleasePageMappingLock needs.
2950 *
2951 * @remark Avoid calling this API from within critical sections (other than the
2952 * PGM one) because of the deadlock risk when we have to delegating the
2953 * task to an EMT.
2954 * @thread Any.
2955 */
2956 DECLR3CALLBACKMEMBER(int, pfnPhysGCPhys2CCPtr,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv,
2957 PPGMPAGEMAPLOCK pLock));
2958
2959 /**
2960 * Requests the mapping of a guest page into ring-3, external threads.
2961 *
2962 * When you're done with the page, call pfnPhysReleasePageMappingLock() ASAP to
2963 * release it.
2964 *
2965 * @returns VBox status code.
2966 * @retval VINF_SUCCESS on success.
2967 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical
2968 * backing or if the page as an active ALL access handler. The caller
2969 * must fall back on using PGMPhysRead.
2970 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
2971 *
2972 * @param pDevIns The device instance.
2973 * @param GCPhys The guest physical address of the page that
2974 * should be mapped.
2975 * @param fFlags Flags reserved for future use, MBZ.
2976 * @param ppv Where to store the address corresponding to
2977 * GCPhys.
2978 * @param pLock Where to store the lock information that
2979 * pfnPhysReleasePageMappingLock needs.
2980 *
2981 * @remark Avoid calling this API from within critical sections.
2982 * @thread Any.
2983 */
2984 DECLR3CALLBACKMEMBER(int, pfnPhysGCPhys2CCPtrReadOnly,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags,
2985 void const **ppv, PPGMPAGEMAPLOCK pLock));
2986
2987 /**
2988 * Release the mapping of a guest page.
2989 *
2990 * This is the counter part of pfnPhysGCPhys2CCPtr and
2991 * pfnPhysGCPhys2CCPtrReadOnly.
2992 *
2993 * @param pDevIns The device instance.
2994 * @param pLock The lock structure initialized by the mapping
2995 * function.
2996 */
2997 DECLR3CALLBACKMEMBER(void, pfnPhysReleasePageMappingLock,(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock));
2998
2999 /**
3000 * Read guest physical memory by virtual address.
3001 *
3002 * @param pDevIns The device instance.
3003 * @param pvDst Where to put the read bits.
3004 * @param GCVirtSrc Guest virtual address to start reading from.
3005 * @param cb How many bytes to read.
3006 * @thread The emulation thread.
3007 */
3008 DECLR3CALLBACKMEMBER(int, pfnPhysReadGCVirt,(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb));
3009
3010 /**
3011 * Write to guest physical memory by virtual address.
3012 *
3013 * @param pDevIns The device instance.
3014 * @param GCVirtDst Guest virtual address to write to.
3015 * @param pvSrc What to write.
3016 * @param cb How many bytes to write.
3017 * @thread The emulation thread.
3018 */
3019 DECLR3CALLBACKMEMBER(int, pfnPhysWriteGCVirt,(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb));
3020
3021 /**
3022 * Convert a guest virtual address to a guest physical address.
3023 *
3024 * @returns VBox status code.
3025 * @param pDevIns The device instance.
3026 * @param GCPtr Guest virtual address.
3027 * @param pGCPhys Where to store the GC physical address
3028 * corresponding to GCPtr.
3029 * @thread The emulation thread.
3030 * @remark Careful with page boundaries.
3031 */
3032 DECLR3CALLBACKMEMBER(int, pfnPhysGCPtr2GCPhys, (PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys));
3033
3034 /**
3035 * Allocate memory which is associated with current VM instance
3036 * and automatically freed on it's destruction.
3037 *
3038 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
3039 * @param pDevIns The device instance.
3040 * @param cb Number of bytes to allocate.
3041 */
3042 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMDEVINS pDevIns, size_t cb));
3043
3044 /**
3045 * Allocate memory which is associated with current VM instance
3046 * and automatically freed on it's destruction. The memory is ZEROed.
3047 *
3048 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
3049 * @param pDevIns The device instance.
3050 * @param cb Number of bytes to allocate.
3051 */
3052 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMDEVINS pDevIns, size_t cb));
3053
3054 /**
3055 * Free memory allocated with pfnMMHeapAlloc() and pfnMMHeapAllocZ().
3056 *
3057 * @param pDevIns The device instance.
3058 * @param pv Pointer to the memory to free.
3059 */
3060 DECLR3CALLBACKMEMBER(void, pfnMMHeapFree,(PPDMDEVINS pDevIns, void *pv));
3061
3062 /**
3063 * Gets the VM state.
3064 *
3065 * @returns VM state.
3066 * @param pDevIns The device instance.
3067 * @thread Any thread (just keep in mind that it's volatile info).
3068 */
3069 DECLR3CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
3070
3071 /**
3072 * Checks if the VM was teleported and hasn't been fully resumed yet.
3073 *
3074 * @returns true / false.
3075 * @param pDevIns The device instance.
3076 * @thread Any thread.
3077 */
3078 DECLR3CALLBACKMEMBER(bool, pfnVMTeleportedAndNotFullyResumedYet,(PPDMDEVINS pDevIns));
3079
3080 /**
3081 * Set the VM error message
3082 *
3083 * @returns rc.
3084 * @param pDevIns The device instance.
3085 * @param rc VBox status code.
3086 * @param SRC_POS Use RT_SRC_POS.
3087 * @param pszFormat Error message format string.
3088 * @param ... Error message arguments.
3089 */
3090 DECLR3CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
3091 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(6, 7));
3092
3093 /**
3094 * Set the VM error message
3095 *
3096 * @returns rc.
3097 * @param pDevIns The device instance.
3098 * @param rc VBox status code.
3099 * @param SRC_POS Use RT_SRC_POS.
3100 * @param pszFormat Error message format string.
3101 * @param va Error message arguments.
3102 */
3103 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
3104 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(6, 0));
3105
3106 /**
3107 * Set the VM runtime error message
3108 *
3109 * @returns VBox status code.
3110 * @param pDevIns The device instance.
3111 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3112 * @param pszErrorId Error ID string.
3113 * @param pszFormat Error message format string.
3114 * @param ... Error message arguments.
3115 */
3116 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
3117 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5));
3118
3119 /**
3120 * Set the VM runtime error message
3121 *
3122 * @returns VBox status code.
3123 * @param pDevIns The device instance.
3124 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3125 * @param pszErrorId Error ID string.
3126 * @param pszFormat Error message format string.
3127 * @param va Error message arguments.
3128 */
3129 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
3130 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0));
3131
3132 /**
3133 * Stops the VM and enters the debugger to look at the guest state.
3134 *
3135 * Use the PDMDeviceDBGFStop() inline function with the RT_SRC_POS macro instead of
3136 * invoking this function directly.
3137 *
3138 * @returns VBox status code which must be passed up to the VMM.
3139 * @param pDevIns The device instance.
3140 * @param pszFile Filename of the assertion location.
3141 * @param iLine The linenumber of the assertion location.
3142 * @param pszFunction Function of the assertion location.
3143 * @param pszFormat Message. (optional)
3144 * @param args Message parameters.
3145 */
3146 DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction,
3147 const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR(5, 0));
3148
3149 /**
3150 * Register a info handler with DBGF.
3151 *
3152 * @returns VBox status code.
3153 * @param pDevIns The device instance.
3154 * @param pszName The identifier of the info.
3155 * @param pszDesc The description of the info and any arguments
3156 * the handler may take.
3157 * @param pfnHandler The handler function to be called to display the
3158 * info.
3159 */
3160 DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegister,(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler));
3161
3162 /**
3163 * Register a info handler with DBGF, argv style.
3164 *
3165 * @returns VBox status code.
3166 * @param pDevIns The device instance.
3167 * @param pszName The identifier of the info.
3168 * @param pszDesc The description of the info and any arguments
3169 * the handler may take.
3170 * @param pfnHandler The handler function to be called to display the
3171 * info.
3172 */
3173 DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegisterArgv,(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVDEV pfnHandler));
3174
3175 /**
3176 * Registers a set of registers for a device.
3177 *
3178 * The @a pvUser argument of the getter and setter callbacks will be
3179 * @a pDevIns. The register names will be prefixed by the device name followed
3180 * immediately by the instance number.
3181 *
3182 * @returns VBox status code.
3183 * @param pDevIns The device instance.
3184 * @param paRegisters The register descriptors.
3185 *
3186 * @remarks The device critical section is NOT entered prior to working the
3187 * callbacks registered via this helper!
3188 */
3189 DECLR3CALLBACKMEMBER(int, pfnDBGFRegRegister,(PPDMDEVINS pDevIns, PCDBGFREGDESC paRegisters));
3190
3191 /**
3192 * Gets the trace buffer handle.
3193 *
3194 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
3195 * really inteded for direct usage, thus no inline wrapper function.
3196 *
3197 * @returns Trace buffer handle or NIL_RTTRACEBUF.
3198 * @param pDevIns The device instance.
3199 */
3200 DECLR3CALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
3201
3202 /**
3203 * Registers a statistics sample.
3204 *
3205 * @param pDevIns Device instance of the DMA.
3206 * @param pvSample Pointer to the sample.
3207 * @param enmType Sample type. This indicates what pvSample is
3208 * pointing at.
3209 * @param pszName Sample name, unix path style. If this does not
3210 * start with a '/', the default prefix will be
3211 * prepended, otherwise it will be used as-is.
3212 * @param enmUnit Sample unit.
3213 * @param pszDesc Sample description.
3214 */
3215 DECLR3CALLBACKMEMBER(void, pfnSTAMRegister,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc));
3216
3217 /**
3218 * Same as pfnSTAMRegister except that the name is specified in a
3219 * RTStrPrintfV like fashion.
3220 *
3221 * @returns VBox status.
3222 * @param pDevIns Device instance of the DMA.
3223 * @param pvSample Pointer to the sample.
3224 * @param enmType Sample type. This indicates what pvSample is
3225 * pointing at.
3226 * @param enmVisibility Visibility type specifying whether unused
3227 * statistics should be visible or not.
3228 * @param enmUnit Sample unit.
3229 * @param pszDesc Sample description.
3230 * @param pszName Sample name format string, unix path style. If
3231 * this does not start with a '/', the default
3232 * prefix will be prepended, otherwise it will be
3233 * used as-is.
3234 * @param args Arguments to the format string.
3235 */
3236 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType,
3237 STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc,
3238 const char *pszName, va_list args) RT_IPRT_FORMAT_ATTR(7, 0));
3239
3240 /**
3241 * Registers a PCI device with the default PCI bus.
3242 *
3243 * If a PDM device has more than one PCI device, they must be registered in the
3244 * order of PDMDEVINSR3::apPciDevs.
3245 *
3246 * @returns VBox status code.
3247 * @param pDevIns The device instance.
3248 * @param pPciDev The PCI device structure.
3249 * This must be kept in the instance data.
3250 * The PCI configuration must be initialized before registration.
3251 * @param fFlags Reserved for future use, PDMPCIDEVREG_F_MBZ.
3252 * @param uPciDevNo PDMPCIDEVREG_DEV_NO_FIRST_UNUSED,
3253 * PDMPCIDEVREG_DEV_NO_SAME_AS_PREV, or a specific
3254 * device number (0-31). This will be ignored if
3255 * the CFGM configuration contains a PCIDeviceNo
3256 * value.
3257 * @param uPciFunNo PDMPCIDEVREG_FUN_NO_FIRST_UNUSED, or a specific
3258 * function number (0-7). This will be ignored if
3259 * the CFGM configuration contains a PCIFunctionNo
3260 * value.
3261 * @param pszName Device name, if NULL PDMDEVREG::szName is used.
3262 * The pointer is saved, so don't free or changed.
3263 * @note The PCI device configuration is now implicit from the apPciDevs
3264 * index, meaning that the zero'th entry is the primary one and
3265 * subsequent uses CFGM subkeys "PciDev1", "PciDev2" and so on.
3266 */
3267 DECLR3CALLBACKMEMBER(int, pfnPCIRegister,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t fFlags,
3268 uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName));
3269
3270 /**
3271 * Initialize MSI or MSI-X emulation support for the given PCI device.
3272 *
3273 * @see PDMPCIBUSREG::pfnRegisterMsiR3 for details.
3274 *
3275 * @returns VBox status code.
3276 * @param pDevIns The device instance.
3277 * @param pPciDev The PCI device. NULL is an alias for the first
3278 * one registered.
3279 * @param pMsiReg MSI emulation registration structure.
3280 */
3281 DECLR3CALLBACKMEMBER(int, pfnPCIRegisterMsi,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, PPDMMSIREG pMsiReg));
3282
3283 /**
3284 * Registers a I/O region (memory mapped or I/O ports) for a PCI device.
3285 *
3286 * @returns VBox status code.
3287 * @param pDevIns The device instance.
3288 * @param pPciDev The PCI device structure. If NULL the default
3289 * PCI device for this device instance is used.
3290 * @param iRegion The region number.
3291 * @param cbRegion Size of the region.
3292 * @param enmType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
3293 * @param fFlags PDMPCIDEV_IORGN_F_XXX.
3294 * @param hHandle An I/O port, MMIO or MMIO2 handle according to
3295 * @a fFlags, UINT64_MAX if no handle is passed
3296 * (old style).
3297 * @param pfnMapUnmap Callback for doing the mapping, optional when a
3298 * handle is specified. The callback will be
3299 * invoked holding only the PDM lock. The device
3300 * lock will _not_ be taken (due to lock order).
3301 */
3302 DECLR3CALLBACKMEMBER(int, pfnPCIIORegionRegister,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
3303 RTGCPHYS cbRegion, PCIADDRESSSPACE enmType, uint32_t fFlags,
3304 uint64_t hHandle, PFNPCIIOREGIONMAP pfnMapUnmap));
3305
3306 /**
3307 * Register PCI configuration space read/write callbacks.
3308 *
3309 * @returns VBox status code.
3310 * @param pDevIns The device instance.
3311 * @param pPciDev The PCI device structure. If NULL the default
3312 * PCI device for this device instance is used.
3313 * @param pfnRead Pointer to the user defined PCI config read function.
3314 * to call default PCI config read function. Can be NULL.
3315 * @param pfnWrite Pointer to the user defined PCI config write function.
3316 * @remarks The callbacks will be invoked holding the PDM lock. The device lock
3317 * is NOT take because that is very likely be a lock order violation.
3318 * @thread EMT(0)
3319 * @note Only callable during VM creation.
3320 * @sa PDMDevHlpPCIConfigRead, PDMDevHlpPCIConfigWrite
3321 */
3322 DECLR3CALLBACKMEMBER(int, pfnPCIInterceptConfigAccesses,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
3323 PFNPCICONFIGREAD pfnRead, PFNPCICONFIGWRITE pfnWrite));
3324
3325 /**
3326 * Perform a PCI configuration space write.
3327 *
3328 * This is for devices that make use of PDMDevHlpPCIInterceptConfigAccesses().
3329 *
3330 * @returns Strict VBox status code (mainly DBGFSTOP).
3331 * @param pDevIns The device instance.
3332 * @param pPciDev The PCI device which config space is being read.
3333 * @param uAddress The config space address.
3334 * @param cb The size of the read: 1, 2 or 4 bytes.
3335 * @param u32Value The value to write.
3336 */
3337 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnPCIConfigWrite,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
3338 uint32_t uAddress, unsigned cb, uint32_t u32Value));
3339
3340 /**
3341 * Perform a PCI configuration space read.
3342 *
3343 * This is for devices that make use of PDMDevHlpPCIInterceptConfigAccesses().
3344 *
3345 * @returns Strict VBox status code (mainly DBGFSTOP).
3346 * @param pDevIns The device instance.
3347 * @param pPciDev The PCI device which config space is being read.
3348 * @param uAddress The config space address.
3349 * @param cb The size of the read: 1, 2 or 4 bytes.
3350 * @param pu32Value Where to return the value.
3351 */
3352 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnPCIConfigRead,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
3353 uint32_t uAddress, unsigned cb, uint32_t *pu32Value));
3354
3355 /**
3356 * Bus master physical memory read.
3357 *
3358 * @returns VINF_SUCCESS or VERR_PGM_PCI_PHYS_READ_BM_DISABLED, later maybe
3359 * VERR_EM_MEMORY. The informational status shall NOT be propagated!
3360 * @param pDevIns The device instance.
3361 * @param pPciDev The PCI device structure. If NULL the default
3362 * PCI device for this device instance is used.
3363 * @param GCPhys Physical address start reading from.
3364 * @param pvBuf Where to put the read bits.
3365 * @param cbRead How many bytes to read.
3366 * @thread Any thread, but the call may involve the emulation thread.
3367 */
3368 DECLR3CALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3369
3370 /**
3371 * Bus master physical memory write.
3372 *
3373 * @returns VINF_SUCCESS or VERR_PGM_PCI_PHYS_WRITE_BM_DISABLED, later maybe
3374 * VERR_EM_MEMORY. The informational status shall NOT be propagated!
3375 * @param pDevIns The device instance.
3376 * @param pPciDev The PCI device structure. If NULL the default
3377 * PCI device for this device instance is used.
3378 * @param GCPhys Physical address to write to.
3379 * @param pvBuf What to write.
3380 * @param cbWrite How many bytes to write.
3381 * @thread Any thread, but the call may involve the emulation thread.
3382 */
3383 DECLR3CALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3384
3385 /**
3386 * Sets the IRQ for the given PCI device.
3387 *
3388 * @param pDevIns The device instance.
3389 * @param pPciDev The PCI device structure. If NULL the default
3390 * PCI device for this device instance is used.
3391 * @param iIrq IRQ number to set.
3392 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3393 * @thread Any thread, but will involve the emulation thread.
3394 */
3395 DECLR3CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel));
3396
3397 /**
3398 * Sets the IRQ for the given PCI device, but doesn't wait for EMT to process
3399 * the request when not called from EMT.
3400 *
3401 * @param pDevIns The device instance.
3402 * @param pPciDev The PCI device structure. If NULL the default
3403 * PCI device for this device instance is used.
3404 * @param iIrq IRQ number to set.
3405 * @param iLevel IRQ level.
3406 * @thread Any thread, but will involve the emulation thread.
3407 */
3408 DECLR3CALLBACKMEMBER(void, pfnPCISetIrqNoWait,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel));
3409
3410 /**
3411 * Set ISA IRQ for a device.
3412 *
3413 * @param pDevIns The device instance.
3414 * @param iIrq IRQ number to set.
3415 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3416 * @thread Any thread, but will involve the emulation thread.
3417 */
3418 DECLR3CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3419
3420 /**
3421 * Set the ISA IRQ for a device, but don't wait for EMT to process
3422 * the request when not called from EMT.
3423 *
3424 * @param pDevIns The device instance.
3425 * @param iIrq IRQ number to set.
3426 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3427 * @thread Any thread, but will involve the emulation thread.
3428 */
3429 DECLR3CALLBACKMEMBER(void, pfnISASetIrqNoWait,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3430
3431 /**
3432 * Send an MSI straight to the I/O APIC.
3433 *
3434 * @param pDevIns PCI device instance.
3435 * @param GCPhys Physical address MSI request was written.
3436 * @param uValue Value written.
3437 * @thread Any thread, but will involve the emulation thread.
3438 */
3439 DECLR3CALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue));
3440
3441 /**
3442 * Attaches a driver (chain) to the device.
3443 *
3444 * The first call for a LUN this will serve as a registration of the LUN. The pBaseInterface and
3445 * the pszDesc string will be registered with that LUN and kept around for PDMR3QueryDeviceLun().
3446 *
3447 * @returns VBox status code.
3448 * @param pDevIns The device instance.
3449 * @param iLun The logical unit to attach.
3450 * @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
3451 * @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
3452 * @param pszDesc Pointer to a string describing the LUN. This string must remain valid
3453 * for the live of the device instance.
3454 */
3455 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface,
3456 PPDMIBASE *ppBaseInterface, const char *pszDesc));
3457
3458 /**
3459 * Detaches an attached driver (chain) from the device again.
3460 *
3461 * @returns VBox status code.
3462 * @param pDevIns The device instance.
3463 * @param pDrvIns The driver instance to detach.
3464 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
3465 */
3466 DECLR3CALLBACKMEMBER(int, pfnDriverDetach,(PPDMDEVINS pDevIns, PPDMDRVINS pDrvIns, uint32_t fFlags));
3467
3468 /** @name Exported PDM Queue Functions
3469 * @{ */
3470 /**
3471 * Create a queue.
3472 *
3473 * @returns VBox status code.
3474 * @param pDevIns The device instance.
3475 * @param cbItem The size of a queue item.
3476 * @param cItems The number of items in the queue.
3477 * @param cMilliesInterval The number of milliseconds between polling the queue.
3478 * If 0 then the emulation thread will be notified whenever an item arrives.
3479 * @param pfnCallback The consumer function.
3480 * @param fRZEnabled Set if the queue should work in RC and R0.
3481 * @param pszName The queue base name. The instance number will be
3482 * appended automatically.
3483 * @param ppQueue Where to store the queue pointer on success.
3484 * @thread The emulation thread.
3485 * @remarks The device critical section will NOT be entered before calling the
3486 * callback. No locks will be held, but for now it's safe to assume
3487 * that only one EMT will do queue callbacks at any one time.
3488 */
3489 DECLR3CALLBACKMEMBER(int, pfnQueueCreatePtr,(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
3490 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName,
3491 PPDMQUEUE *ppQueue));
3492
3493 /**
3494 * Create a queue.
3495 *
3496 * @returns VBox status code.
3497 * @param pDevIns The device instance.
3498 * @param cbItem The size of a queue item.
3499 * @param cItems The number of items in the queue.
3500 * @param cMilliesInterval The number of milliseconds between polling the queue.
3501 * If 0 then the emulation thread will be notified whenever an item arrives.
3502 * @param pfnCallback The consumer function.
3503 * @param fRZEnabled Set if the queue should work in RC and R0.
3504 * @param pszName The queue base name. The instance number will be
3505 * appended automatically.
3506 * @param phQueue Where to store the queue handle on success.
3507 * @thread EMT(0)
3508 * @remarks The device critical section will NOT be entered before calling the
3509 * callback. No locks will be held, but for now it's safe to assume
3510 * that only one EMT will do queue callbacks at any one time.
3511 */
3512 DECLR3CALLBACKMEMBER(int, pfnQueueCreate,(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
3513 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName,
3514 PDMQUEUEHANDLE *phQueue));
3515
3516 DECLR3CALLBACKMEMBER(PPDMQUEUE, pfnQueueToPtr,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue));
3517 DECLR3CALLBACKMEMBER(PPDMQUEUEITEMCORE, pfnQueueAlloc,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue));
3518 DECLR3CALLBACKMEMBER(void, pfnQueueInsert,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue, PPDMQUEUEITEMCORE pItem));
3519 DECLR3CALLBACKMEMBER(void, pfnQueueInsertEx,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue, PPDMQUEUEITEMCORE pItem, uint64_t cNanoMaxDelay));
3520 DECLR3CALLBACKMEMBER(bool, pfnQueueFlushIfNecessary,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue));
3521 /** @} */
3522
3523 /** @name PDM Task
3524 * @{ */
3525 /**
3526 * Create an asynchronous ring-3 task.
3527 *
3528 * @returns VBox status code.
3529 * @param pDevIns The device instance.
3530 * @param fFlags PDMTASK_F_XXX
3531 * @param pszName The function name or similar. Used for statistics,
3532 * so no slashes.
3533 * @param pfnCallback The task function.
3534 * @param pvUser User argument for the task function.
3535 * @param phTask Where to return the task handle.
3536 * @thread EMT(0)
3537 */
3538 DECLR3CALLBACKMEMBER(int, pfnTaskCreate,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszName,
3539 PFNPDMTASKDEV pfnCallback, void *pvUser, PDMTASKHANDLE *phTask));
3540 /**
3541 * Triggers the running the given task.
3542 *
3543 * @returns VBox status code.
3544 * @retval VINF_ALREADY_POSTED is the task is already pending.
3545 * @param pDevIns The device instance.
3546 * @param hTask The task to trigger.
3547 * @thread Any thread.
3548 */
3549 DECLR3CALLBACKMEMBER(int, pfnTaskTrigger,(PPDMDEVINS pDevIns, PDMTASKHANDLE hTask));
3550 /** @} */
3551
3552 /** @name SUP Event Semaphore Wrappers (single release / auto reset)
3553 * These semaphores can be signalled from ring-0.
3554 * @{ */
3555 /** @sa SUPSemEventCreate */
3556 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventCreate,(PPDMDEVINS pDevIns, PSUPSEMEVENT phEvent));
3557 /** @sa SUPSemEventClose */
3558 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventClose,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent));
3559 /** @sa SUPSemEventSignal */
3560 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventSignal,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent));
3561 /** @sa SUPSemEventWaitNoResume */
3562 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventWaitNoResume,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint32_t cMillies));
3563 /** @sa SUPSemEventWaitNsAbsIntr */
3564 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventWaitNsAbsIntr,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint64_t uNsTimeout));
3565 /** @sa SUPSemEventWaitNsRelIntr */
3566 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventWaitNsRelIntr,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint64_t cNsTimeout));
3567 /** @sa SUPSemEventGetResolution */
3568 DECLR3CALLBACKMEMBER(uint32_t, pfnSUPSemEventGetResolution,(PPDMDEVINS pDevIns));
3569 /** @} */
3570
3571 /** @name SUP Multi Event Semaphore Wrappers (multiple release / manual reset)
3572 * These semaphores can be signalled from ring-0.
3573 * @{ */
3574 /** @sa SUPSemEventMultiCreate */
3575 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventMultiCreate,(PPDMDEVINS pDevIns, PSUPSEMEVENTMULTI phEventMulti));
3576 /** @sa SUPSemEventMultiClose */
3577 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventMultiClose,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti));
3578 /** @sa SUPSemEventMultiSignal */
3579 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventMultiSignal,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti));
3580 /** @sa SUPSemEventMultiReset */
3581 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventMultiReset,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti));
3582 /** @sa SUPSemEventMultiWaitNoResume */
3583 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventMultiWaitNoResume,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies));
3584 /** @sa SUPSemEventMultiWaitNsAbsIntr */
3585 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventMultiWaitNsAbsIntr,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout));
3586 /** @sa SUPSemEventMultiWaitNsRelIntr */
3587 DECLR3CALLBACKMEMBER(int, pfnSUPSemEventMultiWaitNsRelIntr,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout));
3588 /** @sa SUPSemEventMultiGetResolution */
3589 DECLR3CALLBACKMEMBER(uint32_t, pfnSUPSemEventMultiGetResolution,(PPDMDEVINS pDevIns));
3590 /** @} */
3591
3592 /**
3593 * Initializes a PDM critical section.
3594 *
3595 * The PDM critical sections are derived from the IPRT critical sections, but
3596 * works in RC and R0 as well.
3597 *
3598 * @returns VBox status code.
3599 * @param pDevIns The device instance.
3600 * @param pCritSect Pointer to the critical section.
3601 * @param SRC_POS Use RT_SRC_POS.
3602 * @param pszNameFmt Format string for naming the critical section.
3603 * For statistics and lock validation.
3604 * @param va Arguments for the format string.
3605 */
3606 DECLR3CALLBACKMEMBER(int, pfnCritSectInit,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
3607 const char *pszNameFmt, va_list va) RT_IPRT_FORMAT_ATTR(6, 0));
3608
3609 /**
3610 * Gets the NOP critical section.
3611 *
3612 * @returns The ring-3 address of the NOP critical section.
3613 * @param pDevIns The device instance.
3614 */
3615 DECLR3CALLBACKMEMBER(PPDMCRITSECT, pfnCritSectGetNop,(PPDMDEVINS pDevIns));
3616
3617 /**
3618 * Gets the NOP critical section.
3619 *
3620 * @returns The ring-0 address of the NOP critical section.
3621 * @param pDevIns The device instance.
3622 * @deprecated
3623 */
3624 DECLR3CALLBACKMEMBER(R0PTRTYPE(PPDMCRITSECT), pfnCritSectGetNopR0,(PPDMDEVINS pDevIns));
3625
3626 /**
3627 * Gets the NOP critical section.
3628 *
3629 * @returns The raw-mode context address of the NOP critical section.
3630 * @param pDevIns The device instance.
3631 * @deprecated
3632 */
3633 DECLR3CALLBACKMEMBER(RCPTRTYPE(PPDMCRITSECT), pfnCritSectGetNopRC,(PPDMDEVINS pDevIns));
3634
3635 /**
3636 * Changes the device level critical section from the automatically created
3637 * default to one desired by the device constructor.
3638 *
3639 * For ring-0 and raw-mode capable devices, the call must be repeated in each of
3640 * the additional contexts.
3641 *
3642 * @returns VBox status code.
3643 * @param pDevIns The device instance.
3644 * @param pCritSect The critical section to use. NULL is not
3645 * valid, instead use the NOP critical
3646 * section.
3647 */
3648 DECLR3CALLBACKMEMBER(int, pfnSetDeviceCritSect,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
3649
3650 /** @name Exported PDM Critical Section Functions
3651 * @{ */
3652 DECLR3CALLBACKMEMBER(bool, pfnCritSectYield,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
3653 DECLR3CALLBACKMEMBER(int, pfnCritSectEnter,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy));
3654 DECLR3CALLBACKMEMBER(int, pfnCritSectEnterDebug,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy, RTHCUINTPTR uId, RT_SRC_POS_DECL));
3655 DECLR3CALLBACKMEMBER(int, pfnCritSectTryEnter,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
3656 DECLR3CALLBACKMEMBER(int, pfnCritSectTryEnterDebug,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RTHCUINTPTR uId, RT_SRC_POS_DECL));
3657 DECLR3CALLBACKMEMBER(int, pfnCritSectLeave,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
3658 DECLR3CALLBACKMEMBER(bool, pfnCritSectIsOwner,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
3659 DECLR3CALLBACKMEMBER(bool, pfnCritSectIsInitialized,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
3660 DECLR3CALLBACKMEMBER(bool, pfnCritSectHasWaiters,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
3661 DECLR3CALLBACKMEMBER(uint32_t, pfnCritSectGetRecursion,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
3662 DECLR3CALLBACKMEMBER(int, pfnCritSectScheduleExitEvent,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, SUPSEMEVENT hEventToSignal));
3663 DECLR3CALLBACKMEMBER(int, pfnCritSectDelete,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
3664 /** @} */
3665
3666 /**
3667 * Creates a PDM thread.
3668 *
3669 * This differs from the RTThreadCreate() API in that PDM takes care of suspending,
3670 * resuming, and destroying the thread as the VM state changes.
3671 *
3672 * @returns VBox status code.
3673 * @param pDevIns The device instance.
3674 * @param ppThread Where to store the thread 'handle'.
3675 * @param pvUser The user argument to the thread function.
3676 * @param pfnThread The thread function.
3677 * @param pfnWakeup The wakup callback. This is called on the EMT
3678 * thread when a state change is pending.
3679 * @param cbStack See RTThreadCreate.
3680 * @param enmType See RTThreadCreate.
3681 * @param pszName See RTThreadCreate.
3682 * @remarks The device critical section will NOT be entered prior to invoking
3683 * the function pointers.
3684 */
3685 DECLR3CALLBACKMEMBER(int, pfnThreadCreate,(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
3686 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName));
3687
3688 /** @name Exported PDM Thread Functions
3689 * @{ */
3690 DECLR3CALLBACKMEMBER(int, pfnThreadDestroy,(PPDMTHREAD pThread, int *pRcThread));
3691 DECLR3CALLBACKMEMBER(int, pfnThreadIAmSuspending,(PPDMTHREAD pThread));
3692 DECLR3CALLBACKMEMBER(int, pfnThreadIAmRunning,(PPDMTHREAD pThread));
3693 DECLR3CALLBACKMEMBER(int, pfnThreadSleep,(PPDMTHREAD pThread, RTMSINTERVAL cMillies));
3694 DECLR3CALLBACKMEMBER(int, pfnThreadSuspend,(PPDMTHREAD pThread));
3695 DECLR3CALLBACKMEMBER(int, pfnThreadResume,(PPDMTHREAD pThread));
3696 /** @} */
3697
3698 /**
3699 * Set up asynchronous handling of a suspend, reset or power off notification.
3700 *
3701 * This shall only be called when getting the notification. It must be called
3702 * for each one.
3703 *
3704 * @returns VBox status code.
3705 * @param pDevIns The device instance.
3706 * @param pfnAsyncNotify The callback.
3707 * @thread EMT(0)
3708 * @remarks The caller will enter the device critical section prior to invoking
3709 * the callback.
3710 */
3711 DECLR3CALLBACKMEMBER(int, pfnSetAsyncNotification, (PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify));
3712
3713 /**
3714 * Notify EMT(0) that the device has completed the asynchronous notification
3715 * handling.
3716 *
3717 * This can be called at any time, spurious calls will simply be ignored.
3718 *
3719 * @param pDevIns The device instance.
3720 * @thread Any
3721 */
3722 DECLR3CALLBACKMEMBER(void, pfnAsyncNotificationCompleted, (PPDMDEVINS pDevIns));
3723
3724 /**
3725 * Register the RTC device.
3726 *
3727 * @returns VBox status code.
3728 * @param pDevIns The device instance.
3729 * @param pRtcReg Pointer to a RTC registration structure.
3730 * @param ppRtcHlp Where to store the pointer to the helper
3731 * functions.
3732 */
3733 DECLR3CALLBACKMEMBER(int, pfnRTCRegister,(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp));
3734
3735 /**
3736 * Register a PCI Bus.
3737 *
3738 * @returns VBox status code, but the positive values 0..31 are used to indicate
3739 * bus number rather than informational status codes.
3740 * @param pDevIns The device instance.
3741 * @param pPciBusReg Pointer to PCI bus registration structure.
3742 * @param ppPciHlp Where to store the pointer to the PCI Bus
3743 * helpers.
3744 * @param piBus Where to return the PDM bus number. Optional.
3745 */
3746 DECLR3CALLBACKMEMBER(int, pfnPCIBusRegister,(PPDMDEVINS pDevIns, PPDMPCIBUSREGR3 pPciBusReg,
3747 PCPDMPCIHLPR3 *ppPciHlp, uint32_t *piBus));
3748
3749 /**
3750 * Register the PIC device.
3751 *
3752 * @returns VBox status code.
3753 * @param pDevIns The device instance.
3754 * @param pPicReg Pointer to a PIC registration structure.
3755 * @param ppPicHlp Where to store the pointer to the ring-3 PIC
3756 * helpers.
3757 * @sa PDMDevHlpPICSetUpContext
3758 */
3759 DECLR3CALLBACKMEMBER(int, pfnPICRegister,(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLP *ppPicHlp));
3760
3761 /**
3762 * Register the APIC device.
3763 *
3764 * @returns VBox status code.
3765 * @param pDevIns The device instance.
3766 */
3767 DECLR3CALLBACKMEMBER(int, pfnAPICRegister,(PPDMDEVINS pDevIns));
3768
3769 /**
3770 * Register the I/O APIC device.
3771 *
3772 * @returns VBox status code.
3773 * @param pDevIns The device instance.
3774 * @param pIoApicReg Pointer to a I/O APIC registration structure.
3775 * @param ppIoApicHlp Where to store the pointer to the IOAPIC
3776 * helpers.
3777 */
3778 DECLR3CALLBACKMEMBER(int, pfnIoApicRegister,(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLP *ppIoApicHlp));
3779
3780 /**
3781 * Register the HPET device.
3782 *
3783 * @returns VBox status code.
3784 * @param pDevIns The device instance.
3785 * @param pHpetReg Pointer to a HPET registration structure.
3786 * @param ppHpetHlpR3 Where to store the pointer to the HPET
3787 * helpers.
3788 */
3789 DECLR3CALLBACKMEMBER(int, pfnHPETRegister,(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3));
3790
3791 /**
3792 * Register a raw PCI device.
3793 *
3794 * @returns VBox status code.
3795 * @param pDevIns The device instance.
3796 * @param pPciRawReg Pointer to a raw PCI registration structure.
3797 * @param ppPciRawHlpR3 Where to store the pointer to the raw PCI
3798 * device helpers.
3799 */
3800 DECLR3CALLBACKMEMBER(int, pfnPciRawRegister,(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3));
3801
3802 /**
3803 * Register the DMA device.
3804 *
3805 * @returns VBox status code.
3806 * @param pDevIns The device instance.
3807 * @param pDmacReg Pointer to a DMAC registration structure.
3808 * @param ppDmacHlp Where to store the pointer to the DMA helpers.
3809 */
3810 DECLR3CALLBACKMEMBER(int, pfnDMACRegister,(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp));
3811
3812 /**
3813 * Register transfer function for DMA channel.
3814 *
3815 * @returns VBox status code.
3816 * @param pDevIns The device instance.
3817 * @param uChannel Channel number.
3818 * @param pfnTransferHandler Device specific transfer callback function.
3819 * @param pvUser User pointer to pass to the callback.
3820 * @thread EMT
3821 */
3822 DECLR3CALLBACKMEMBER(int, pfnDMARegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
3823
3824 /**
3825 * Read memory.
3826 *
3827 * @returns VBox status code.
3828 * @param pDevIns The device instance.
3829 * @param uChannel Channel number.
3830 * @param pvBuffer Pointer to target buffer.
3831 * @param off DMA position.
3832 * @param cbBlock Block size.
3833 * @param pcbRead Where to store the number of bytes which was
3834 * read. optional.
3835 * @thread EMT
3836 */
3837 DECLR3CALLBACKMEMBER(int, pfnDMAReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead));
3838
3839 /**
3840 * Write memory.
3841 *
3842 * @returns VBox status code.
3843 * @param pDevIns The device instance.
3844 * @param uChannel Channel number.
3845 * @param pvBuffer Memory to write.
3846 * @param off DMA position.
3847 * @param cbBlock Block size.
3848 * @param pcbWritten Where to store the number of bytes which was
3849 * written. optional.
3850 * @thread EMT
3851 */
3852 DECLR3CALLBACKMEMBER(int, pfnDMAWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten));
3853
3854 /**
3855 * Set the DREQ line.
3856 *
3857 * @returns VBox status code.
3858 * @param pDevIns Device instance.
3859 * @param uChannel Channel number.
3860 * @param uLevel Level of the line.
3861 * @thread EMT
3862 */
3863 DECLR3CALLBACKMEMBER(int, pfnDMASetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
3864
3865 /**
3866 * Get channel mode.
3867 *
3868 * @returns Channel mode. See specs.
3869 * @param pDevIns The device instance.
3870 * @param uChannel Channel number.
3871 * @thread EMT
3872 */
3873 DECLR3CALLBACKMEMBER(uint8_t, pfnDMAGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
3874
3875 /**
3876 * Schedule DMA execution.
3877 *
3878 * @param pDevIns The device instance.
3879 * @thread Any thread.
3880 */
3881 DECLR3CALLBACKMEMBER(void, pfnDMASchedule,(PPDMDEVINS pDevIns));
3882
3883 /**
3884 * Write CMOS value and update the checksum(s).
3885 *
3886 * @returns VBox status code.
3887 * @param pDevIns The device instance.
3888 * @param iReg The CMOS register index.
3889 * @param u8Value The CMOS register value.
3890 * @thread EMT
3891 */
3892 DECLR3CALLBACKMEMBER(int, pfnCMOSWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
3893
3894 /**
3895 * Read CMOS value.
3896 *
3897 * @returns VBox status code.
3898 * @param pDevIns The device instance.
3899 * @param iReg The CMOS register index.
3900 * @param pu8Value Where to store the CMOS register value.
3901 * @thread EMT
3902 */
3903 DECLR3CALLBACKMEMBER(int, pfnCMOSRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
3904
3905 /**
3906 * Assert that the current thread is the emulation thread.
3907 *
3908 * @returns True if correct.
3909 * @returns False if wrong.
3910 * @param pDevIns The device instance.
3911 * @param pszFile Filename of the assertion location.
3912 * @param iLine The linenumber of the assertion location.
3913 * @param pszFunction Function of the assertion location.
3914 */
3915 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
3916
3917 /**
3918 * Assert that the current thread is NOT the emulation thread.
3919 *
3920 * @returns True if correct.
3921 * @returns False if wrong.
3922 * @param pDevIns The device instance.
3923 * @param pszFile Filename of the assertion location.
3924 * @param iLine The linenumber of the assertion location.
3925 * @param pszFunction Function of the assertion location.
3926 */
3927 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDEVINS pDevIns, const char *pszFile, unsigned iLine, const char *pszFunction));
3928
3929 /**
3930 * Resolves the symbol for a raw-mode context interface.
3931 *
3932 * @returns VBox status code.
3933 * @param pDevIns The device instance.
3934 * @param pvInterface The interface structure.
3935 * @param cbInterface The size of the interface structure.
3936 * @param pszSymPrefix What to prefix the symbols in the list with
3937 * before resolving them. This must start with
3938 * 'dev' and contain the driver name.
3939 * @param pszSymList List of symbols corresponding to the interface.
3940 * There is generally a there is generally a define
3941 * holding this list associated with the interface
3942 * definition (INTERFACE_SYM_LIST). For more
3943 * details see PDMR3LdrGetInterfaceSymbols.
3944 * @thread EMT
3945 */
3946 DECLR3CALLBACKMEMBER(int, pfnLdrGetRCInterfaceSymbols,(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
3947 const char *pszSymPrefix, const char *pszSymList));
3948
3949 /**
3950 * Resolves the symbol for a ring-0 context interface.
3951 *
3952 * @returns VBox status code.
3953 * @param pDevIns The device instance.
3954 * @param pvInterface The interface structure.
3955 * @param cbInterface The size of the interface structure.
3956 * @param pszSymPrefix What to prefix the symbols in the list with
3957 * before resolving them. This must start with
3958 * 'dev' and contain the driver name.
3959 * @param pszSymList List of symbols corresponding to the interface.
3960 * There is generally a there is generally a define
3961 * holding this list associated with the interface
3962 * definition (INTERFACE_SYM_LIST). For more
3963 * details see PDMR3LdrGetInterfaceSymbols.
3964 * @thread EMT
3965 */
3966 DECLR3CALLBACKMEMBER(int, pfnLdrGetR0InterfaceSymbols,(PPDMDEVINS pDevIns, void *pvInterface, size_t cbInterface,
3967 const char *pszSymPrefix, const char *pszSymList));
3968
3969 /**
3970 * Calls the PDMDEVREGR0::pfnRequest callback (in ring-0 context).
3971 *
3972 * @returns VBox status code.
3973 * @retval VERR_INVALID_FUNCTION if the callback member is NULL.
3974 * @retval VERR_ACCESS_DENIED if the device isn't ring-0 capable.
3975 *
3976 * @param pDevIns The device instance.
3977 * @param uOperation The operation to perform.
3978 * @param u64Arg 64-bit integer argument.
3979 * @thread EMT
3980 */
3981 DECLR3CALLBACKMEMBER(int, pfnCallR0,(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg));
3982
3983 /**
3984 * Gets the reason for the most recent VM suspend.
3985 *
3986 * @returns The suspend reason. VMSUSPENDREASON_INVALID is returned if no
3987 * suspend has been made or if the pDevIns is invalid.
3988 * @param pDevIns The device instance.
3989 */
3990 DECLR3CALLBACKMEMBER(VMSUSPENDREASON, pfnVMGetSuspendReason,(PPDMDEVINS pDevIns));
3991
3992 /**
3993 * Gets the reason for the most recent VM resume.
3994 *
3995 * @returns The resume reason. VMRESUMEREASON_INVALID is returned if no
3996 * resume has been made or if the pDevIns is invalid.
3997 * @param pDevIns The device instance.
3998 */
3999 DECLR3CALLBACKMEMBER(VMRESUMEREASON, pfnVMGetResumeReason,(PPDMDEVINS pDevIns));
4000
4001 /**
4002 * Requests the mapping of multiple guest page into ring-3.
4003 *
4004 * When you're done with the pages, call pfnPhysBulkReleasePageMappingLocks()
4005 * ASAP to release them.
4006 *
4007 * This API will assume your intention is to write to the pages, and will
4008 * therefore replace shared and zero pages. If you do not intend to modify the
4009 * pages, use the pfnPhysBulkGCPhys2CCPtrReadOnly() API.
4010 *
4011 * @returns VBox status code.
4012 * @retval VINF_SUCCESS on success.
4013 * @retval VERR_PGM_PHYS_PAGE_RESERVED if any of the pages has no physical
4014 * backing or if any of the pages the page has any active access
4015 * handlers. The caller must fall back on using PGMR3PhysWriteExternal.
4016 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if @a paGCPhysPages contains
4017 * an invalid physical address.
4018 *
4019 * @param pDevIns The device instance.
4020 * @param cPages Number of pages to lock.
4021 * @param paGCPhysPages The guest physical address of the pages that
4022 * should be mapped (@a cPages entries).
4023 * @param fFlags Flags reserved for future use, MBZ.
4024 * @param papvPages Where to store the ring-3 mapping addresses
4025 * corresponding to @a paGCPhysPages.
4026 * @param paLocks Where to store the locking information that
4027 * pfnPhysBulkReleasePageMappingLock needs (@a cPages
4028 * in length).
4029 *
4030 * @remark Avoid calling this API from within critical sections (other than the
4031 * PGM one) because of the deadlock risk when we have to delegating the
4032 * task to an EMT.
4033 * @thread Any.
4034 * @since 6.0.6
4035 */
4036 DECLR3CALLBACKMEMBER(int, pfnPhysBulkGCPhys2CCPtr,(PPDMDEVINS pDevIns, uint32_t cPages, PCRTGCPHYS paGCPhysPages,
4037 uint32_t fFlags, void **papvPages, PPGMPAGEMAPLOCK paLocks));
4038
4039 /**
4040 * Requests the mapping of multiple guest page into ring-3, for reading only.
4041 *
4042 * When you're done with the pages, call pfnPhysBulkReleasePageMappingLocks()
4043 * ASAP to release them.
4044 *
4045 * @returns VBox status code.
4046 * @retval VINF_SUCCESS on success.
4047 * @retval VERR_PGM_PHYS_PAGE_RESERVED if any of the pages has no physical
4048 * backing or if any of the pages the page has an active ALL access
4049 * handler. The caller must fall back on using PGMR3PhysWriteExternal.
4050 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if @a paGCPhysPages contains
4051 * an invalid physical address.
4052 *
4053 * @param pDevIns The device instance.
4054 * @param cPages Number of pages to lock.
4055 * @param paGCPhysPages The guest physical address of the pages that
4056 * should be mapped (@a cPages entries).
4057 * @param fFlags Flags reserved for future use, MBZ.
4058 * @param papvPages Where to store the ring-3 mapping addresses
4059 * corresponding to @a paGCPhysPages.
4060 * @param paLocks Where to store the lock information that
4061 * pfnPhysReleasePageMappingLock needs (@a cPages
4062 * in length).
4063 *
4064 * @remark Avoid calling this API from within critical sections.
4065 * @thread Any.
4066 * @since 6.0.6
4067 */
4068 DECLR3CALLBACKMEMBER(int, pfnPhysBulkGCPhys2CCPtrReadOnly,(PPDMDEVINS pDevIns, uint32_t cPages, PCRTGCPHYS paGCPhysPages,
4069 uint32_t fFlags, void const **papvPages, PPGMPAGEMAPLOCK paLocks));
4070
4071 /**
4072 * Release the mappings of multiple guest pages.
4073 *
4074 * This is the counter part of pfnPhysBulkGCPhys2CCPtr and
4075 * pfnPhysBulkGCPhys2CCPtrReadOnly.
4076 *
4077 * @param pDevIns The device instance.
4078 * @param cPages Number of pages to unlock.
4079 * @param paLocks The lock structures initialized by the mapping
4080 * function (@a cPages in length).
4081 * @thread Any.
4082 * @since 6.0.6
4083 */
4084 DECLR3CALLBACKMEMBER(void, pfnPhysBulkReleasePageMappingLocks,(PPDMDEVINS pDevIns, uint32_t cPages, PPGMPAGEMAPLOCK paLocks));
4085
4086 /**
4087 * Changes the number of an MMIO2 or pre-registered MMIO region.
4088 *
4089 * This should only be used to deal with saved state problems, so there is no
4090 * convenience inline wrapper for this method.
4091 *
4092 * @returns VBox status code.
4093 * @param pDevIns The device instance.
4094 * @param pPciDev The PCI device the region is associated with, or
4095 * NULL if not associated with any.
4096 * @param iRegion The region.
4097 * @param iNewRegion The new region index.
4098 *
4099 * @sa @bugref{9359}
4100 */
4101 DECLR3CALLBACKMEMBER(int, pfnMMIOExChangeRegionNo,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
4102 uint32_t iNewRegion));
4103
4104 /** Space reserved for future members.
4105 * @{ */
4106 DECLR3CALLBACKMEMBER(void, pfnReserved1,(void));
4107 DECLR3CALLBACKMEMBER(void, pfnReserved2,(void));
4108 DECLR3CALLBACKMEMBER(void, pfnReserved3,(void));
4109 DECLR3CALLBACKMEMBER(void, pfnReserved4,(void));
4110 DECLR3CALLBACKMEMBER(void, pfnReserved5,(void));
4111 DECLR3CALLBACKMEMBER(void, pfnReserved6,(void));
4112 DECLR3CALLBACKMEMBER(void, pfnReserved7,(void));
4113 DECLR3CALLBACKMEMBER(void, pfnReserved8,(void));
4114 DECLR3CALLBACKMEMBER(void, pfnReserved9,(void));
4115 DECLR3CALLBACKMEMBER(void, pfnReserved10,(void));
4116 /** @} */
4117
4118
4119 /** API available to trusted devices only.
4120 *
4121 * These APIs are providing unrestricted access to the guest and the VM,
4122 * or they are interacting intimately with PDM.
4123 *
4124 * @{
4125 */
4126
4127 /**
4128 * Gets the user mode VM handle. Restricted API.
4129 *
4130 * @returns User mode VM Handle.
4131 * @param pDevIns The device instance.
4132 */
4133 DECLR3CALLBACKMEMBER(PUVM, pfnGetUVM,(PPDMDEVINS pDevIns));
4134
4135 /**
4136 * Gets the global VM handle. Restricted API.
4137 *
4138 * @returns VM Handle.
4139 * @param pDevIns The device instance.
4140 */
4141 DECLR3CALLBACKMEMBER(PVMCC, pfnGetVM,(PPDMDEVINS pDevIns));
4142
4143 /**
4144 * Gets the VMCPU handle. Restricted API.
4145 *
4146 * @returns VMCPU Handle.
4147 * @param pDevIns The device instance.
4148 */
4149 DECLR3CALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
4150
4151 /**
4152 * The the VM CPU ID of the current thread (restricted API).
4153 *
4154 * @returns The VMCPUID of the calling thread, NIL_VMCPUID if not EMT.
4155 * @param pDevIns The device instance.
4156 */
4157 DECLR3CALLBACKMEMBER(VMCPUID, pfnGetCurrentCpuId,(PPDMDEVINS pDevIns));
4158
4159 /**
4160 * Registers the VMM device heap or notifies about mapping/unmapping.
4161 *
4162 * This interface serves three purposes:
4163 *
4164 * -# Register the VMM device heap during device construction
4165 * for the HM to use.
4166 * -# Notify PDM/HM that it's mapped into guest address
4167 * space (i.e. usable).
4168 * -# Notify PDM/HM that it is being unmapped from the guest
4169 * address space (i.e. not usable).
4170 *
4171 * @returns VBox status code.
4172 * @param pDevIns The device instance.
4173 * @param GCPhys The physical address if mapped, NIL_RTGCPHYS if
4174 * not mapped.
4175 * @param pvHeap Ring 3 heap pointer.
4176 * @param cbHeap Size of the heap.
4177 * @thread EMT.
4178 */
4179 DECLR3CALLBACKMEMBER(int, pfnRegisterVMMDevHeap,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbHeap));
4180
4181 /**
4182 * Registers the firmware (BIOS, EFI) device with PDM.
4183 *
4184 * The firmware provides a callback table and gets a special PDM helper table.
4185 * There can only be one firmware device for a VM.
4186 *
4187 * @returns VBox status code.
4188 * @param pDevIns The device instance.
4189 * @param pFwReg Firmware registration structure.
4190 * @param ppFwHlp Where to return the firmware helper structure.
4191 * @remarks Only valid during device construction.
4192 * @thread EMT(0)
4193 */
4194 DECLR3CALLBACKMEMBER(int, pfnFirmwareRegister,(PPDMDEVINS pDevIns, PCPDMFWREG pFwReg, PCPDMFWHLPR3 *ppFwHlp));
4195
4196 /**
4197 * Resets the VM.
4198 *
4199 * @returns The appropriate VBox status code to pass around on reset.
4200 * @param pDevIns The device instance.
4201 * @param fFlags PDMVMRESET_F_XXX flags.
4202 * @thread The emulation thread.
4203 */
4204 DECLR3CALLBACKMEMBER(int, pfnVMReset,(PPDMDEVINS pDevIns, uint32_t fFlags));
4205
4206 /**
4207 * Suspends the VM.
4208 *
4209 * @returns The appropriate VBox status code to pass around on suspend.
4210 * @param pDevIns The device instance.
4211 * @thread The emulation thread.
4212 */
4213 DECLR3CALLBACKMEMBER(int, pfnVMSuspend,(PPDMDEVINS pDevIns));
4214
4215 /**
4216 * Suspends, saves and powers off the VM.
4217 *
4218 * @returns The appropriate VBox status code to pass around.
4219 * @param pDevIns The device instance.
4220 * @thread An emulation thread.
4221 */
4222 DECLR3CALLBACKMEMBER(int, pfnVMSuspendSaveAndPowerOff,(PPDMDEVINS pDevIns));
4223
4224 /**
4225 * Power off the VM.
4226 *
4227 * @returns The appropriate VBox status code to pass around on power off.
4228 * @param pDevIns The device instance.
4229 * @thread The emulation thread.
4230 */
4231 DECLR3CALLBACKMEMBER(int, pfnVMPowerOff,(PPDMDEVINS pDevIns));
4232
4233 /**
4234 * Checks if the Gate A20 is enabled or not.
4235 *
4236 * @returns true if A20 is enabled.
4237 * @returns false if A20 is disabled.
4238 * @param pDevIns The device instance.
4239 * @thread The emulation thread.
4240 */
4241 DECLR3CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
4242
4243 /**
4244 * Enables or disables the Gate A20.
4245 *
4246 * @param pDevIns The device instance.
4247 * @param fEnable Set this flag to enable the Gate A20; clear it
4248 * to disable.
4249 * @thread The emulation thread.
4250 */
4251 DECLR3CALLBACKMEMBER(void, pfnA20Set,(PPDMDEVINS pDevIns, bool fEnable));
4252
4253 /**
4254 * Get the specified CPUID leaf for the virtual CPU associated with the calling
4255 * thread.
4256 *
4257 * @param pDevIns The device instance.
4258 * @param iLeaf The CPUID leaf to get.
4259 * @param pEax Where to store the EAX value.
4260 * @param pEbx Where to store the EBX value.
4261 * @param pEcx Where to store the ECX value.
4262 * @param pEdx Where to store the EDX value.
4263 * @thread EMT.
4264 */
4265 DECLR3CALLBACKMEMBER(void, pfnGetCpuId,(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx));
4266
4267 /**
4268 * Get the current virtual clock time in a VM. The clock frequency must be
4269 * queried separately.
4270 *
4271 * @returns Current clock time.
4272 * @param pDevIns The device instance.
4273 */
4274 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
4275
4276 /**
4277 * Get the frequency of the virtual clock.
4278 *
4279 * @returns The clock frequency (not variable at run-time).
4280 * @param pDevIns The device instance.
4281 */
4282 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
4283
4284 /**
4285 * Get the current virtual clock time in a VM, in nanoseconds.
4286 *
4287 * @returns Current clock time (in ns).
4288 * @param pDevIns The device instance.
4289 */
4290 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
4291
4292 /**
4293 * Gets the support driver session.
4294 *
4295 * This is intended for working with the semaphore API.
4296 *
4297 * @returns Support driver session handle.
4298 * @param pDevIns The device instance.
4299 */
4300 DECLR3CALLBACKMEMBER(PSUPDRVSESSION, pfnGetSupDrvSession,(PPDMDEVINS pDevIns));
4301
4302 /**
4303 * Queries a generic object from the VMM user.
4304 *
4305 * @returns Pointer to the object if found, NULL if not.
4306 * @param pDevIns The device instance.
4307 * @param pUuid The UUID of what's being queried. The UUIDs and
4308 * the usage conventions are defined by the user.
4309 *
4310 * @note It is strictly forbidden to call this internally in VBox! This
4311 * interface is exclusively for hacks in externally developed devices.
4312 */
4313 DECLR3CALLBACKMEMBER(void *, pfnQueryGenericUserObject,(PPDMDEVINS pDevIns, PCRTUUID pUuid));
4314
4315 /** @} */
4316
4317 /** Just a safety precaution. (PDM_DEVHLPR3_VERSION) */
4318 uint32_t u32TheEnd;
4319} PDMDEVHLPR3;
4320#endif /* !IN_RING3 || DOXYGEN_RUNNING */
4321/** Pointer to the R3 PDM Device API. */
4322typedef R3PTRTYPE(struct PDMDEVHLPR3 *) PPDMDEVHLPR3;
4323/** Pointer to the R3 PDM Device API, const variant. */
4324typedef R3PTRTYPE(const struct PDMDEVHLPR3 *) PCPDMDEVHLPR3;
4325
4326
4327/**
4328 * PDM Device API - RC Variant.
4329 */
4330typedef struct PDMDEVHLPRC
4331{
4332 /** Structure version. PDM_DEVHLPRC_VERSION defines the current version. */
4333 uint32_t u32Version;
4334
4335 /**
4336 * Sets up raw-mode context callback handlers for an I/O port range.
4337 *
4338 * The range must have been registered in ring-3 first using
4339 * PDMDevHlpIoPortCreate() or PDMDevHlpIoPortCreateEx().
4340 *
4341 * @returns VBox status.
4342 * @param pDevIns The device instance to register the ports with.
4343 * @param hIoPorts The I/O port range handle.
4344 * @param pfnOut Pointer to function which is gonna handle OUT
4345 * operations. Optional.
4346 * @param pfnIn Pointer to function which is gonna handle IN operations.
4347 * Optional.
4348 * @param pfnOutStr Pointer to function which is gonna handle string OUT
4349 * operations. Optional.
4350 * @param pfnInStr Pointer to function which is gonna handle string IN
4351 * operations. Optional.
4352 * @param pvUser User argument to pass to the callbacks.
4353 *
4354 * @remarks Caller enters the device critical section prior to invoking the
4355 * registered callback methods.
4356 *
4357 * @sa PDMDevHlpIoPortCreate, PDMDevHlpIoPortCreateEx, PDMDevHlpIoPortMap,
4358 * PDMDevHlpIoPortUnmap.
4359 */
4360 DECLRCCALLBACKMEMBER(int, pfnIoPortSetUpContextEx,(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts,
4361 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
4362 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr,
4363 void *pvUser));
4364
4365 /**
4366 * Sets up raw-mode context callback handlers for an MMIO region.
4367 *
4368 * The region must have been registered in ring-3 first using
4369 * PDMDevHlpMmioCreate() or PDMDevHlpMmioCreateEx().
4370 *
4371 * @returns VBox status.
4372 * @param pDevIns The device instance to register the ports with.
4373 * @param hRegion The MMIO region handle.
4374 * @param pfnWrite Pointer to function which is gonna handle Write
4375 * operations.
4376 * @param pfnRead Pointer to function which is gonna handle Read
4377 * operations.
4378 * @param pfnFill Pointer to function which is gonna handle Fill/memset
4379 * operations. (optional)
4380 * @param pvUser User argument to pass to the callbacks.
4381 *
4382 * @remarks Caller enters the device critical section prior to invoking the
4383 * registered callback methods.
4384 *
4385 * @sa PDMDevHlpMmioCreate, PDMDevHlpMmioCreateEx, PDMDevHlpMmioMap,
4386 * PDMDevHlpMmioUnmap.
4387 */
4388 DECLRCCALLBACKMEMBER(int, pfnMmioSetUpContextEx,(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, PFNIOMMMIONEWWRITE pfnWrite,
4389 PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill, void *pvUser));
4390
4391 /**
4392 * Sets up a raw-mode mapping for an MMIO2 region.
4393 *
4394 * The region must have been created in ring-3 first using
4395 * PDMDevHlpMmio2Create().
4396 *
4397 * @returns VBox status.
4398 * @param pDevIns The device instance to register the ports with.
4399 * @param hRegion The MMIO2 region handle.
4400 * @param offSub Start of what to map into raw-mode. Must be page aligned.
4401 * @param cbSub Number of bytes to map into raw-mode. Must be page
4402 * aligned. Zero is an alias for everything.
4403 * @param ppvMapping Where to return the mapping corresponding to @a offSub.
4404 * @thread EMT(0)
4405 * @note Only available at VM creation time.
4406 *
4407 * @sa PDMDevHlpMmio2Create().
4408 */
4409 DECLRCCALLBACKMEMBER(int, pfnMmio2SetUpContext,(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion,
4410 size_t offSub, size_t cbSub, void **ppvMapping));
4411
4412 /**
4413 * Bus master physical memory read from the given PCI device.
4414 *
4415 * @returns VINF_SUCCESS or VERR_PGM_PCI_PHYS_READ_BM_DISABLED, later maybe
4416 * VERR_EM_MEMORY. The informational status shall NOT be propagated!
4417 * @param pDevIns The device instance.
4418 * @param pPciDev The PCI device structure. If NULL the default
4419 * PCI device for this device instance is used.
4420 * @param GCPhys Physical address start reading from.
4421 * @param pvBuf Where to put the read bits.
4422 * @param cbRead How many bytes to read.
4423 * @thread Any thread, but the call may involve the emulation thread.
4424 */
4425 DECLRCCALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys,
4426 void *pvBuf, size_t cbRead));
4427
4428 /**
4429 * Bus master physical memory write from the given PCI device.
4430 *
4431 * @returns VINF_SUCCESS or VERR_PGM_PCI_PHYS_WRITE_BM_DISABLED, later maybe
4432 * VERR_EM_MEMORY. The informational status shall NOT be propagated!
4433 * @param pDevIns The device instance.
4434 * @param pPciDev The PCI device structure. If NULL the default
4435 * PCI device for this device instance is used.
4436 * @param GCPhys Physical address to write to.
4437 * @param pvBuf What to write.
4438 * @param cbWrite How many bytes to write.
4439 * @thread Any thread, but the call may involve the emulation thread.
4440 */
4441 DECLRCCALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys,
4442 const void *pvBuf, size_t cbWrite));
4443
4444 /**
4445 * Set the IRQ for the given PCI device.
4446 *
4447 * @param pDevIns Device instance.
4448 * @param pPciDev The PCI device structure. If NULL the default
4449 * PCI device for this device instance is used.
4450 * @param iIrq IRQ number to set.
4451 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
4452 * @thread Any thread, but will involve the emulation thread.
4453 */
4454 DECLRCCALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel));
4455
4456 /**
4457 * Set ISA IRQ for a device.
4458 *
4459 * @param pDevIns Device instance.
4460 * @param iIrq IRQ number to set.
4461 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
4462 * @thread Any thread, but will involve the emulation thread.
4463 */
4464 DECLRCCALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
4465
4466 /**
4467 * Send an MSI straight to the I/O APIC.
4468 *
4469 * @param pDevIns PCI device instance.
4470 * @param GCPhys Physical address MSI request was written.
4471 * @param uValue Value written.
4472 * @thread Any thread, but will involve the emulation thread.
4473 */
4474 DECLRCCALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue));
4475
4476 /**
4477 * Read physical memory.
4478 *
4479 * @returns VINF_SUCCESS (for now).
4480 * @param pDevIns Device instance.
4481 * @param GCPhys Physical address start reading from.
4482 * @param pvBuf Where to put the read bits.
4483 * @param cbRead How many bytes to read.
4484 */
4485 DECLRCCALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
4486
4487 /**
4488 * Write to physical memory.
4489 *
4490 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
4491 * @param pDevIns Device instance.
4492 * @param GCPhys Physical address to write to.
4493 * @param pvBuf What to write.
4494 * @param cbWrite How many bytes to write.
4495 */
4496 DECLRCCALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
4497
4498 /**
4499 * Checks if the Gate A20 is enabled or not.
4500 *
4501 * @returns true if A20 is enabled.
4502 * @returns false if A20 is disabled.
4503 * @param pDevIns Device instance.
4504 * @thread The emulation thread.
4505 */
4506 DECLRCCALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
4507
4508 /**
4509 * Gets the VM state.
4510 *
4511 * @returns VM state.
4512 * @param pDevIns The device instance.
4513 * @thread Any thread (just keep in mind that it's volatile info).
4514 */
4515 DECLRCCALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
4516
4517 /**
4518 * Set the VM error message
4519 *
4520 * @returns rc.
4521 * @param pDevIns Driver instance.
4522 * @param rc VBox status code.
4523 * @param SRC_POS Use RT_SRC_POS.
4524 * @param pszFormat Error message format string.
4525 * @param ... Error message arguments.
4526 */
4527 DECLRCCALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
4528 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(6, 7));
4529
4530 /**
4531 * Set the VM error message
4532 *
4533 * @returns rc.
4534 * @param pDevIns Driver instance.
4535 * @param rc VBox status code.
4536 * @param SRC_POS Use RT_SRC_POS.
4537 * @param pszFormat Error message format string.
4538 * @param va Error message arguments.
4539 */
4540 DECLRCCALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
4541 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(6, 0));
4542
4543 /**
4544 * Set the VM runtime error message
4545 *
4546 * @returns VBox status code.
4547 * @param pDevIns Device instance.
4548 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
4549 * @param pszErrorId Error ID string.
4550 * @param pszFormat Error message format string.
4551 * @param ... Error message arguments.
4552 */
4553 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4554 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5));
4555
4556 /**
4557 * Set the VM runtime error message
4558 *
4559 * @returns VBox status code.
4560 * @param pDevIns Device instance.
4561 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
4562 * @param pszErrorId Error ID string.
4563 * @param pszFormat Error message format string.
4564 * @param va Error message arguments.
4565 */
4566 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4567 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0));
4568
4569 /**
4570 * Gets the VM handle. Restricted API.
4571 *
4572 * @returns VM Handle.
4573 * @param pDevIns Device instance.
4574 */
4575 DECLRCCALLBACKMEMBER(PVMCC, pfnGetVM,(PPDMDEVINS pDevIns));
4576
4577 /**
4578 * Gets the VMCPU handle. Restricted API.
4579 *
4580 * @returns VMCPU Handle.
4581 * @param pDevIns The device instance.
4582 */
4583 DECLRCCALLBACKMEMBER(PVMCPUCC, pfnGetVMCPU,(PPDMDEVINS pDevIns));
4584
4585 /**
4586 * The the VM CPU ID of the current thread (restricted API).
4587 *
4588 * @returns The VMCPUID of the calling thread, NIL_VMCPUID if not EMT.
4589 * @param pDevIns The device instance.
4590 */
4591 DECLRCCALLBACKMEMBER(VMCPUID, pfnGetCurrentCpuId,(PPDMDEVINS pDevIns));
4592
4593 /**
4594 * Get the current virtual clock time in a VM. The clock frequency must be
4595 * queried separately.
4596 *
4597 * @returns Current clock time.
4598 * @param pDevIns The device instance.
4599 */
4600 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
4601
4602 /**
4603 * Get the frequency of the virtual clock.
4604 *
4605 * @returns The clock frequency (not variable at run-time).
4606 * @param pDevIns The device instance.
4607 */
4608 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
4609
4610 /**
4611 * Get the current virtual clock time in a VM, in nanoseconds.
4612 *
4613 * @returns Current clock time (in ns).
4614 * @param pDevIns The device instance.
4615 */
4616 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
4617
4618 /**
4619 * Gets the NOP critical section.
4620 *
4621 * @returns The ring-3 address of the NOP critical section.
4622 * @param pDevIns The device instance.
4623 */
4624 DECLRCCALLBACKMEMBER(PPDMCRITSECT, pfnCritSectGetNop,(PPDMDEVINS pDevIns));
4625
4626 /**
4627 * Changes the device level critical section from the automatically created
4628 * default to one desired by the device constructor.
4629 *
4630 * Must first be done in ring-3.
4631 *
4632 * @returns VBox status code.
4633 * @param pDevIns The device instance.
4634 * @param pCritSect The critical section to use. NULL is not
4635 * valid, instead use the NOP critical
4636 * section.
4637 */
4638 DECLRCCALLBACKMEMBER(int, pfnSetDeviceCritSect,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
4639
4640 /** @name Exported PDM Critical Section Functions
4641 * @{ */
4642 DECLRCCALLBACKMEMBER(int, pfnCritSectEnter,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy));
4643 DECLRCCALLBACKMEMBER(int, pfnCritSectEnterDebug,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy, RTHCUINTPTR uId, RT_SRC_POS_DECL));
4644 DECLRCCALLBACKMEMBER(int, pfnCritSectTryEnter,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
4645 DECLRCCALLBACKMEMBER(int, pfnCritSectTryEnterDebug,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RTHCUINTPTR uId, RT_SRC_POS_DECL));
4646 DECLRCCALLBACKMEMBER(int, pfnCritSectLeave,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
4647 DECLRCCALLBACKMEMBER(bool, pfnCritSectIsOwner,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
4648 DECLRCCALLBACKMEMBER(bool, pfnCritSectIsInitialized,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
4649 DECLRCCALLBACKMEMBER(bool, pfnCritSectHasWaiters,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
4650 DECLRCCALLBACKMEMBER(uint32_t, pfnCritSectGetRecursion,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
4651 /** @} */
4652
4653 /**
4654 * Gets the trace buffer handle.
4655 *
4656 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
4657 * really inteded for direct usage, thus no inline wrapper function.
4658 *
4659 * @returns Trace buffer handle or NIL_RTTRACEBUF.
4660 * @param pDevIns The device instance.
4661 */
4662 DECLRCCALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
4663
4664 /**
4665 * Sets up the PCI bus for the raw-mode context.
4666 *
4667 * This must be called after ring-3 has registered the PCI bus using
4668 * PDMDevHlpPCIBusRegister().
4669 *
4670 * @returns VBox status code.
4671 * @param pDevIns The device instance.
4672 * @param pPciBusReg The PCI bus registration information for raw-mode,
4673 * considered volatile.
4674 * @param ppPciHlp Where to return the raw-mode PCI bus helpers.
4675 */
4676 DECLRCCALLBACKMEMBER(int, pfnPCIBusSetUpContext,(PPDMDEVINS pDevIns, PPDMPCIBUSREGRC pPciBusReg, PCPDMPCIHLPRC *ppPciHlp));
4677
4678 /**
4679 * Sets up the PIC for the ring-0 context.
4680 *
4681 * This must be called after ring-3 has registered the PIC using
4682 * PDMDevHlpPICRegister().
4683 *
4684 * @returns VBox status code.
4685 * @param pDevIns The device instance.
4686 * @param pPicReg The PIC registration information for ring-0,
4687 * considered volatile and copied.
4688 * @param ppPicHlp Where to return the ring-0 PIC helpers.
4689 */
4690 DECLR0CALLBACKMEMBER(int, pfnPICSetUpContext,(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLP *ppPicHlp));
4691
4692 /**
4693 * Sets up the IOAPIC for the ring-0 context.
4694 *
4695 * This must be called after ring-3 has registered the PIC using
4696 * PDMDevHlpIoApicRegister().
4697 *
4698 * @returns VBox status code.
4699 * @param pDevIns The device instance.
4700 * @param pIoApicReg The PIC registration information for ring-0,
4701 * considered volatile and copied.
4702 * @param ppIoApicHlp Where to return the ring-0 IOAPIC helpers.
4703 */
4704 DECLR0CALLBACKMEMBER(int, pfnIoApicSetUpContext,(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLP *ppIoApicHlp));
4705
4706 /** Space reserved for future members.
4707 * @{ */
4708 DECLRCCALLBACKMEMBER(void, pfnReserved1,(void));
4709 DECLRCCALLBACKMEMBER(void, pfnReserved2,(void));
4710 DECLRCCALLBACKMEMBER(void, pfnReserved3,(void));
4711 DECLRCCALLBACKMEMBER(void, pfnReserved4,(void));
4712 DECLRCCALLBACKMEMBER(void, pfnReserved5,(void));
4713 DECLRCCALLBACKMEMBER(void, pfnReserved6,(void));
4714 DECLRCCALLBACKMEMBER(void, pfnReserved7,(void));
4715 DECLRCCALLBACKMEMBER(void, pfnReserved8,(void));
4716 DECLRCCALLBACKMEMBER(void, pfnReserved9,(void));
4717 DECLRCCALLBACKMEMBER(void, pfnReserved10,(void));
4718 /** @} */
4719
4720 /** Just a safety precaution. */
4721 uint32_t u32TheEnd;
4722} PDMDEVHLPRC;
4723/** Pointer PDM Device RC API. */
4724typedef RGPTRTYPE(struct PDMDEVHLPRC *) PPDMDEVHLPRC;
4725/** Pointer PDM Device RC API. */
4726typedef RGPTRTYPE(const struct PDMDEVHLPRC *) PCPDMDEVHLPRC;
4727
4728/** Current PDMDEVHLP version number. */
4729#define PDM_DEVHLPRC_VERSION PDM_VERSION_MAKE(0xffe6, 12, 0)
4730
4731
4732/**
4733 * PDM Device API - R0 Variant.
4734 */
4735typedef struct PDMDEVHLPR0
4736{
4737 /** Structure version. PDM_DEVHLPR0_VERSION defines the current version. */
4738 uint32_t u32Version;
4739
4740 /**
4741 * Sets up ring-0 callback handlers for an I/O port range.
4742 *
4743 * The range must have been created in ring-3 first using
4744 * PDMDevHlpIoPortCreate() or PDMDevHlpIoPortCreateEx().
4745 *
4746 * @returns VBox status.
4747 * @param pDevIns The device instance to register the ports with.
4748 * @param hIoPorts The I/O port range handle.
4749 * @param pfnOut Pointer to function which is gonna handle OUT
4750 * operations. Optional.
4751 * @param pfnIn Pointer to function which is gonna handle IN operations.
4752 * Optional.
4753 * @param pfnOutStr Pointer to function which is gonna handle string OUT
4754 * operations. Optional.
4755 * @param pfnInStr Pointer to function which is gonna handle string IN
4756 * operations. Optional.
4757 * @param pvUser User argument to pass to the callbacks.
4758 *
4759 * @remarks Caller enters the device critical section prior to invoking the
4760 * registered callback methods.
4761 *
4762 * @sa PDMDevHlpIoPortCreate(), PDMDevHlpIoPortCreateEx(),
4763 * PDMDevHlpIoPortMap(), PDMDevHlpIoPortUnmap().
4764 */
4765 DECLR0CALLBACKMEMBER(int, pfnIoPortSetUpContextEx,(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts,
4766 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
4767 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr,
4768 void *pvUser));
4769
4770 /**
4771 * Sets up ring-0 callback handlers for an MMIO region.
4772 *
4773 * The region must have been created in ring-3 first using
4774 * PDMDevHlpMmioCreate(), PDMDevHlpMmioCreateEx(), PDMDevHlpMmioCreateAndMap(),
4775 * PDMDevHlpMmioCreateExAndMap() or PDMDevHlpPCIIORegionCreateMmio().
4776 *
4777 * @returns VBox status.
4778 * @param pDevIns The device instance to register the ports with.
4779 * @param hRegion The MMIO region handle.
4780 * @param pfnWrite Pointer to function which is gonna handle Write
4781 * operations.
4782 * @param pfnRead Pointer to function which is gonna handle Read
4783 * operations.
4784 * @param pfnFill Pointer to function which is gonna handle Fill/memset
4785 * operations. (optional)
4786 * @param pvUser User argument to pass to the callbacks.
4787 *
4788 * @remarks Caller enters the device critical section prior to invoking the
4789 * registered callback methods.
4790 *
4791 * @sa PDMDevHlpMmioCreate(), PDMDevHlpMmioCreateEx(), PDMDevHlpMmioMap(),
4792 * PDMDevHlpMmioUnmap().
4793 */
4794 DECLR0CALLBACKMEMBER(int, pfnMmioSetUpContextEx,(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, PFNIOMMMIONEWWRITE pfnWrite,
4795 PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill, void *pvUser));
4796
4797 /**
4798 * Sets up a ring-0 mapping for an MMIO2 region.
4799 *
4800 * The region must have been created in ring-3 first using
4801 * PDMDevHlpMmio2Create().
4802 *
4803 * @returns VBox status.
4804 * @param pDevIns The device instance to register the ports with.
4805 * @param hRegion The MMIO2 region handle.
4806 * @param offSub Start of what to map into ring-0. Must be page aligned.
4807 * @param cbSub Number of bytes to map into ring-0. Must be page
4808 * aligned. Zero is an alias for everything.
4809 * @param ppvMapping Where to return the mapping corresponding to @a offSub.
4810 *
4811 * @thread EMT(0)
4812 * @note Only available at VM creation time.
4813 *
4814 * @sa PDMDevHlpMmio2Create().
4815 */
4816 DECLR0CALLBACKMEMBER(int, pfnMmio2SetUpContext,(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, size_t offSub, size_t cbSub,
4817 void **ppvMapping));
4818
4819 /**
4820 * Bus master physical memory read from the given PCI device.
4821 *
4822 * @returns VINF_SUCCESS or VERR_PDM_NOT_PCI_BUS_MASTER, later maybe
4823 * VERR_EM_MEMORY.
4824 * @param pDevIns The device instance.
4825 * @param pPciDev The PCI device structure. If NULL the default
4826 * PCI device for this device instance is used.
4827 * @param GCPhys Physical address start reading from.
4828 * @param pvBuf Where to put the read bits.
4829 * @param cbRead How many bytes to read.
4830 * @thread Any thread, but the call may involve the emulation thread.
4831 */
4832 DECLR0CALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys,
4833 void *pvBuf, size_t cbRead));
4834
4835 /**
4836 * Bus master physical memory write from the given PCI device.
4837 *
4838 * @returns VINF_SUCCESS or VERR_PDM_NOT_PCI_BUS_MASTER, later maybe
4839 * VERR_EM_MEMORY.
4840 * @param pDevIns The device instance.
4841 * @param pPciDev The PCI device structure. If NULL the default
4842 * PCI device for this device instance is used.
4843 * @param GCPhys Physical address to write to.
4844 * @param pvBuf What to write.
4845 * @param cbWrite How many bytes to write.
4846 * @thread Any thread, but the call may involve the emulation thread.
4847 */
4848 DECLR0CALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys,
4849 const void *pvBuf, size_t cbWrite));
4850
4851 /**
4852 * Set the IRQ for the given PCI device.
4853 *
4854 * @param pDevIns Device instance.
4855 * @param pPciDev The PCI device structure. If NULL the default
4856 * PCI device for this device instance is used.
4857 * @param iIrq IRQ number to set.
4858 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
4859 * @thread Any thread, but will involve the emulation thread.
4860 */
4861 DECLR0CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel));
4862
4863 /**
4864 * Set ISA IRQ for a device.
4865 *
4866 * @param pDevIns Device instance.
4867 * @param iIrq IRQ number to set.
4868 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
4869 * @thread Any thread, but will involve the emulation thread.
4870 */
4871 DECLR0CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
4872
4873 /**
4874 * Send an MSI straight to the I/O APIC.
4875 *
4876 * @param pDevIns PCI device instance.
4877 * @param GCPhys Physical address MSI request was written.
4878 * @param uValue Value written.
4879 * @thread Any thread, but will involve the emulation thread.
4880 */
4881 DECLR0CALLBACKMEMBER(void, pfnIoApicSendMsi,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue));
4882
4883 /**
4884 * Read physical memory.
4885 *
4886 * @returns VINF_SUCCESS (for now).
4887 * @param pDevIns Device instance.
4888 * @param GCPhys Physical address start reading from.
4889 * @param pvBuf Where to put the read bits.
4890 * @param cbRead How many bytes to read.
4891 */
4892 DECLR0CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
4893
4894 /**
4895 * Write to physical memory.
4896 *
4897 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
4898 * @param pDevIns Device instance.
4899 * @param GCPhys Physical address to write to.
4900 * @param pvBuf What to write.
4901 * @param cbWrite How many bytes to write.
4902 */
4903 DECLR0CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
4904
4905 /**
4906 * Checks if the Gate A20 is enabled or not.
4907 *
4908 * @returns true if A20 is enabled.
4909 * @returns false if A20 is disabled.
4910 * @param pDevIns Device instance.
4911 * @thread The emulation thread.
4912 */
4913 DECLR0CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
4914
4915 /**
4916 * Gets the VM state.
4917 *
4918 * @returns VM state.
4919 * @param pDevIns The device instance.
4920 * @thread Any thread (just keep in mind that it's volatile info).
4921 */
4922 DECLR0CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
4923
4924 /**
4925 * Set the VM error message
4926 *
4927 * @returns rc.
4928 * @param pDevIns Driver instance.
4929 * @param rc VBox status code.
4930 * @param SRC_POS Use RT_SRC_POS.
4931 * @param pszFormat Error message format string.
4932 * @param ... Error message arguments.
4933 */
4934 DECLR0CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
4935 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(6, 7));
4936
4937 /**
4938 * Set the VM error message
4939 *
4940 * @returns rc.
4941 * @param pDevIns Driver instance.
4942 * @param rc VBox status code.
4943 * @param SRC_POS Use RT_SRC_POS.
4944 * @param pszFormat Error message format string.
4945 * @param va Error message arguments.
4946 */
4947 DECLR0CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
4948 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(6, 0));
4949
4950 /**
4951 * Set the VM runtime error message
4952 *
4953 * @returns VBox status code.
4954 * @param pDevIns Device instance.
4955 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
4956 * @param pszErrorId Error ID string.
4957 * @param pszFormat Error message format string.
4958 * @param ... Error message arguments.
4959 */
4960 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4961 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5));
4962
4963 /**
4964 * Set the VM runtime error message
4965 *
4966 * @returns VBox status code.
4967 * @param pDevIns Device instance.
4968 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
4969 * @param pszErrorId Error ID string.
4970 * @param pszFormat Error message format string.
4971 * @param va Error message arguments.
4972 */
4973 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4974 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0));
4975
4976 /**
4977 * Gets the VM handle. Restricted API.
4978 *
4979 * @returns VM Handle.
4980 * @param pDevIns Device instance.
4981 */
4982 DECLR0CALLBACKMEMBER(PVMCC, pfnGetVM,(PPDMDEVINS pDevIns));
4983
4984 /**
4985 * Gets the VMCPU handle. Restricted API.
4986 *
4987 * @returns VMCPU Handle.
4988 * @param pDevIns The device instance.
4989 */
4990 DECLR0CALLBACKMEMBER(PVMCPUCC, pfnGetVMCPU,(PPDMDEVINS pDevIns));
4991
4992 /**
4993 * The the VM CPU ID of the current thread (restricted API).
4994 *
4995 * @returns The VMCPUID of the calling thread, NIL_VMCPUID if not EMT.
4996 * @param pDevIns The device instance.
4997 */
4998 DECLR0CALLBACKMEMBER(VMCPUID, pfnGetCurrentCpuId,(PPDMDEVINS pDevIns));
4999
5000 /**
5001 * Translates a timer handle to a pointer.
5002 *
5003 * @returns The time address.
5004 * @param pDevIns The device instance.
5005 * @param hTimer The timer handle.
5006 */
5007 DECLR0CALLBACKMEMBER(PTMTIMERR0, pfnTimerToPtr,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
5008
5009 /** @name Timer handle method wrappers
5010 * @{ */
5011 DECLR0CALLBACKMEMBER(uint64_t, pfnTimerFromMicro,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMicroSecs));
5012 DECLR0CALLBACKMEMBER(uint64_t, pfnTimerFromMilli,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMilliSecs));
5013 DECLR0CALLBACKMEMBER(uint64_t, pfnTimerFromNano,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cNanoSecs));
5014 DECLR0CALLBACKMEMBER(uint64_t, pfnTimerGet,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
5015 DECLR0CALLBACKMEMBER(uint64_t, pfnTimerGetFreq,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
5016 DECLR0CALLBACKMEMBER(uint64_t, pfnTimerGetNano,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
5017 DECLR0CALLBACKMEMBER(bool, pfnTimerIsActive,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
5018 DECLR0CALLBACKMEMBER(bool, pfnTimerIsLockOwner,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
5019 DECLR0CALLBACKMEMBER(int, pfnTimerLock,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, int rcBusy));
5020 DECLR0CALLBACKMEMBER(int, pfnTimerSet,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t uExpire));
5021 DECLR0CALLBACKMEMBER(int, pfnTimerSetFrequencyHint,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint32_t uHz));
5022 DECLR0CALLBACKMEMBER(int, pfnTimerSetMicro,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext));
5023 DECLR0CALLBACKMEMBER(int, pfnTimerSetMillies,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMilliesToNext));
5024 DECLR0CALLBACKMEMBER(int, pfnTimerSetNano,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cNanosToNext));
5025 DECLR0CALLBACKMEMBER(int, pfnTimerSetRelative,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now));
5026 DECLR0CALLBACKMEMBER(int, pfnTimerStop,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
5027 DECLR0CALLBACKMEMBER(void, pfnTimerUnlock,(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer));
5028 /** @} */
5029
5030 /**
5031 * Get the current virtual clock time in a VM. The clock frequency must be
5032 * queried separately.
5033 *
5034 * @returns Current clock time.
5035 * @param pDevIns The device instance.
5036 */
5037 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
5038
5039 /**
5040 * Get the frequency of the virtual clock.
5041 *
5042 * @returns The clock frequency (not variable at run-time).
5043 * @param pDevIns The device instance.
5044 */
5045 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
5046
5047 /**
5048 * Get the current virtual clock time in a VM, in nanoseconds.
5049 *
5050 * @returns Current clock time (in ns).
5051 * @param pDevIns The device instance.
5052 */
5053 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
5054
5055 /** @name Exported PDM Queue Functions
5056 * @{ */
5057 DECLR0CALLBACKMEMBER(PPDMQUEUE, pfnQueueToPtr,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue));
5058 DECLR0CALLBACKMEMBER(PPDMQUEUEITEMCORE, pfnQueueAlloc,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue));
5059 DECLR0CALLBACKMEMBER(void, pfnQueueInsert,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue, PPDMQUEUEITEMCORE pItem));
5060 DECLR0CALLBACKMEMBER(void, pfnQueueInsertEx,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue, PPDMQUEUEITEMCORE pItem, uint64_t cNanoMaxDelay));
5061 DECLR0CALLBACKMEMBER(bool, pfnQueueFlushIfNecessary,(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue));
5062 /** @} */
5063
5064 /** @name PDM Task
5065 * @{ */
5066 /**
5067 * Triggers the running the given task.
5068 *
5069 * @returns VBox status code.
5070 * @retval VINF_ALREADY_POSTED is the task is already pending.
5071 * @param pDevIns The device instance.
5072 * @param hTask The task to trigger.
5073 * @thread Any thread.
5074 */
5075 DECLR0CALLBACKMEMBER(int, pfnTaskTrigger,(PPDMDEVINS pDevIns, PDMTASKHANDLE hTask));
5076 /** @} */
5077
5078 /** @name SUP Event Semaphore Wrappers (single release / auto reset)
5079 * These semaphores can be signalled from ring-0.
5080 * @{ */
5081 /** @sa SUPSemEventSignal */
5082 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventSignal,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent));
5083 /** @sa SUPSemEventWaitNoResume */
5084 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventWaitNoResume,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint32_t cMillies));
5085 /** @sa SUPSemEventWaitNsAbsIntr */
5086 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventWaitNsAbsIntr,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint64_t uNsTimeout));
5087 /** @sa SUPSemEventWaitNsRelIntr */
5088 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventWaitNsRelIntr,(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint64_t cNsTimeout));
5089 /** @sa SUPSemEventGetResolution */
5090 DECLR0CALLBACKMEMBER(uint32_t, pfnSUPSemEventGetResolution,(PPDMDEVINS pDevIns));
5091 /** @} */
5092
5093 /** @name SUP Multi Event Semaphore Wrappers (multiple release / manual reset)
5094 * These semaphores can be signalled from ring-0.
5095 * @{ */
5096 /** @sa SUPSemEventMultiSignal */
5097 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventMultiSignal,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti));
5098 /** @sa SUPSemEventMultiReset */
5099 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventMultiReset,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti));
5100 /** @sa SUPSemEventMultiWaitNoResume */
5101 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventMultiWaitNoResume,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies));
5102 /** @sa SUPSemEventMultiWaitNsAbsIntr */
5103 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventMultiWaitNsAbsIntr,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout));
5104 /** @sa SUPSemEventMultiWaitNsRelIntr */
5105 DECLR0CALLBACKMEMBER(int, pfnSUPSemEventMultiWaitNsRelIntr,(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout));
5106 /** @sa SUPSemEventMultiGetResolution */
5107 DECLR0CALLBACKMEMBER(uint32_t, pfnSUPSemEventMultiGetResolution,(PPDMDEVINS pDevIns));
5108 /** @} */
5109
5110 /**
5111 * Gets the NOP critical section.
5112 *
5113 * @returns The ring-3 address of the NOP critical section.
5114 * @param pDevIns The device instance.
5115 */
5116 DECLR0CALLBACKMEMBER(PPDMCRITSECT, pfnCritSectGetNop,(PPDMDEVINS pDevIns));
5117
5118 /**
5119 * Changes the device level critical section from the automatically created
5120 * default to one desired by the device constructor.
5121 *
5122 * Must first be done in ring-3.
5123 *
5124 * @returns VBox status code.
5125 * @param pDevIns The device instance.
5126 * @param pCritSect The critical section to use. NULL is not
5127 * valid, instead use the NOP critical
5128 * section.
5129 */
5130 DECLR0CALLBACKMEMBER(int, pfnSetDeviceCritSect,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
5131
5132 /** @name Exported PDM Critical Section Functions
5133 * @{ */
5134 DECLR0CALLBACKMEMBER(int, pfnCritSectEnter,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy));
5135 DECLR0CALLBACKMEMBER(int, pfnCritSectEnterDebug,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy, RTHCUINTPTR uId, RT_SRC_POS_DECL));
5136 DECLR0CALLBACKMEMBER(int, pfnCritSectTryEnter,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
5137 DECLR0CALLBACKMEMBER(int, pfnCritSectTryEnterDebug,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RTHCUINTPTR uId, RT_SRC_POS_DECL));
5138 DECLR0CALLBACKMEMBER(int, pfnCritSectLeave,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect));
5139 DECLR0CALLBACKMEMBER(bool, pfnCritSectIsOwner,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
5140 DECLR0CALLBACKMEMBER(bool, pfnCritSectIsInitialized,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
5141 DECLR0CALLBACKMEMBER(bool, pfnCritSectHasWaiters,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
5142 DECLR0CALLBACKMEMBER(uint32_t, pfnCritSectGetRecursion,(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect));
5143 DECLR0CALLBACKMEMBER(int, pfnCritSectScheduleExitEvent,(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, SUPSEMEVENT hEventToSignal));
5144 /** @} */
5145
5146 /**
5147 * Gets the trace buffer handle.
5148 *
5149 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
5150 * really inteded for direct usage, thus no inline wrapper function.
5151 *
5152 * @returns Trace buffer handle or NIL_RTTRACEBUF.
5153 * @param pDevIns The device instance.
5154 */
5155 DECLR0CALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
5156
5157 /**
5158 * Sets up the PCI bus for the ring-0 context.
5159 *
5160 * This must be called after ring-3 has registered the PCI bus using
5161 * PDMDevHlpPCIBusRegister().
5162 *
5163 * @returns VBox status code.
5164 * @param pDevIns The device instance.
5165 * @param pPciBusReg The PCI bus registration information for ring-0,
5166 * considered volatile and copied.
5167 * @param ppPciHlp Where to return the ring-0 PCI bus helpers.
5168 */
5169 DECLR0CALLBACKMEMBER(int, pfnPCIBusSetUpContext,(PPDMDEVINS pDevIns, PPDMPCIBUSREGR0 pPciBusReg, PCPDMPCIHLPR0 *ppPciHlp));
5170
5171 /**
5172 * Sets up the PIC for the ring-0 context.
5173 *
5174 * This must be called after ring-3 has registered the PIC using
5175 * PDMDevHlpPICRegister().
5176 *
5177 * @returns VBox status code.
5178 * @param pDevIns The device instance.
5179 * @param pPicReg The PIC registration information for ring-0,
5180 * considered volatile and copied.
5181 * @param ppPicHlp Where to return the ring-0 PIC helpers.
5182 */
5183 DECLR0CALLBACKMEMBER(int, pfnPICSetUpContext,(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLP *ppPicHlp));
5184
5185 /**
5186 * Sets up the IOAPIC for the ring-0 context.
5187 *
5188 * This must be called after ring-3 has registered the PIC using
5189 * PDMDevHlpIoApicRegister().
5190 *
5191 * @returns VBox status code.
5192 * @param pDevIns The device instance.
5193 * @param pIoApicReg The PIC registration information for ring-0,
5194 * considered volatile and copied.
5195 * @param ppIoApicHlp Where to return the ring-0 IOAPIC helpers.
5196 */
5197 DECLR0CALLBACKMEMBER(int, pfnIoApicSetUpContext,(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLP *ppIoApicHlp));
5198
5199 /** Space reserved for future members.
5200 * @{ */
5201 DECLR0CALLBACKMEMBER(void, pfnReserved1,(void));
5202 DECLR0CALLBACKMEMBER(void, pfnReserved2,(void));
5203 DECLR0CALLBACKMEMBER(void, pfnReserved3,(void));
5204 DECLR0CALLBACKMEMBER(void, pfnReserved4,(void));
5205 DECLR0CALLBACKMEMBER(void, pfnReserved5,(void));
5206 DECLR0CALLBACKMEMBER(void, pfnReserved6,(void));
5207 DECLR0CALLBACKMEMBER(void, pfnReserved7,(void));
5208 DECLR0CALLBACKMEMBER(void, pfnReserved8,(void));
5209 DECLR0CALLBACKMEMBER(void, pfnReserved9,(void));
5210 DECLR0CALLBACKMEMBER(void, pfnReserved10,(void));
5211 /** @} */
5212
5213 /** Just a safety precaution. */
5214 uint32_t u32TheEnd;
5215} PDMDEVHLPR0;
5216/** Pointer PDM Device R0 API. */
5217typedef R0PTRTYPE(struct PDMDEVHLPR0 *) PPDMDEVHLPR0;
5218/** Pointer PDM Device GC API. */
5219typedef R0PTRTYPE(const struct PDMDEVHLPR0 *) PCPDMDEVHLPR0;
5220
5221/** Current PDMDEVHLP version number. */
5222#define PDM_DEVHLPR0_VERSION PDM_VERSION_MAKE(0xffe5, 13, 0)
5223
5224
5225/**
5226 * PDM Device Instance.
5227 */
5228typedef struct PDMDEVINSR3
5229{
5230 /** Structure version. PDM_DEVINSR3_VERSION defines the current version. */
5231 uint32_t u32Version;
5232 /** Device instance number. */
5233 uint32_t iInstance;
5234 /** Size of the ring-3, raw-mode and shared bits. */
5235 uint32_t cbRing3;
5236 /** Set if ring-0 context is enabled. */
5237 bool fR0Enabled;
5238 /** Set if raw-mode context is enabled. */
5239 bool fRCEnabled;
5240 /** Alignment padding. */
5241 bool afReserved[2];
5242 /** Pointer the HC PDM Device API. */
5243 PCPDMDEVHLPR3 pHlpR3;
5244 /** Pointer to the shared device instance data. */
5245 RTR3PTR pvInstanceDataR3;
5246 /** Pointer to the device instance data for ring-3. */
5247 RTR3PTR pvInstanceDataForR3;
5248 /** The critical section for the device.
5249 *
5250 * TM and IOM will enter this critical section before calling into the device
5251 * code. PDM will when doing power on, power off, reset, suspend and resume
5252 * notifications. SSM will currently not, but this will be changed later on.
5253 *
5254 * The device gets a critical section automatically assigned to it before
5255 * the constructor is called. If the constructor wishes to use a different
5256 * critical section, it calls PDMDevHlpSetDeviceCritSect() to change it
5257 * very early on.
5258 */
5259 R3PTRTYPE(PPDMCRITSECT) pCritSectRoR3;
5260 /** Pointer to device registration structure. */
5261 R3PTRTYPE(PCPDMDEVREG) pReg;
5262 /** Configuration handle. */
5263 R3PTRTYPE(PCFGMNODE) pCfg;
5264 /** The base interface of the device.
5265 *
5266 * The device constructor initializes this if it has any
5267 * device level interfaces to export. To obtain this interface
5268 * call PDMR3QueryDevice(). */
5269 PDMIBASE IBase;
5270
5271 /** Tracing indicator. */
5272 uint32_t fTracing;
5273 /** The tracing ID of this device. */
5274 uint32_t idTracing;
5275
5276 /** Ring-3 pointer to the raw-mode device instance. */
5277 R3PTRTYPE(struct PDMDEVINSRC *) pDevInsForRCR3;
5278 /** Raw-mode address of the raw-mode device instance. */
5279 RTRGPTR pDevInsForRC;
5280 /** Ring-3 pointer to the raw-mode instance data. */
5281 RTR3PTR pvInstanceDataForRCR3;
5282
5283 /** PCI device structure size. */
5284 uint32_t cbPciDev;
5285 /** Number of PCI devices in apPciDevs. */
5286 uint32_t cPciDevs;
5287 /** Pointer to the PCI devices for this device.
5288 * (Allocated after the shared instance data.)
5289 * @note If we want to extend this beyond 8 sub-functions/devices, those 1 or
5290 * two devices ever needing it can use cbPciDev and do the address
5291 * calculations that for entries 8+. */
5292 R3PTRTYPE(struct PDMPCIDEV *) apPciDevs[8];
5293
5294 /** Temporarily. */
5295 R0PTRTYPE(struct PDMDEVINSR0 *) pDevInsR0RemoveMe;
5296 /** Temporarily. */
5297 RTR0PTR pvInstanceDataR0;
5298 /** Temporarily. */
5299 RTRCPTR pvInstanceDataRC;
5300 /** Align the internal data more naturally. */
5301 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 13 : 11];
5302
5303 /** Internal data. */
5304 union
5305 {
5306#ifdef PDMDEVINSINT_DECLARED
5307 PDMDEVINSINTR3 s;
5308#endif
5309 uint8_t padding[HC_ARCH_BITS == 32 ? 0x30 : 0x50];
5310 } Internal;
5311
5312 /** Device instance data for ring-3. The size of this area is defined
5313 * in the PDMDEVREG::cbInstanceR3 field. */
5314 char achInstanceData[8];
5315} PDMDEVINSR3;
5316
5317/** Current PDMDEVINSR3 version number. */
5318#define PDM_DEVINSR3_VERSION PDM_VERSION_MAKE(0xff82, 4, 0)
5319
5320/** Converts a pointer to the PDMDEVINSR3::IBase to a pointer to PDMDEVINS. */
5321#define PDMIBASE_2_PDMDEV(pInterface) ( (PPDMDEVINS)((char *)(pInterface) - RT_UOFFSETOF(PDMDEVINS, IBase)) )
5322
5323
5324/**
5325 * PDM ring-0 device instance.
5326 */
5327typedef struct PDMDEVINSR0
5328{
5329 /** Structure version. PDM_DEVINSR0_VERSION defines the current version. */
5330 uint32_t u32Version;
5331 /** Device instance number. */
5332 uint32_t iInstance;
5333
5334 /** Pointer the HC PDM Device API. */
5335 PCPDMDEVHLPR0 pHlpR0;
5336 /** Pointer to the shared device instance data. */
5337 RTR0PTR pvInstanceDataR0;
5338 /** Pointer to the device instance data for ring-0. */
5339 RTR0PTR pvInstanceDataForR0;
5340 /** The critical section for the device.
5341 *
5342 * TM and IOM will enter this critical section before calling into the device
5343 * code. PDM will when doing power on, power off, reset, suspend and resume
5344 * notifications. SSM will currently not, but this will be changed later on.
5345 *
5346 * The device gets a critical section automatically assigned to it before
5347 * the constructor is called. If the constructor wishes to use a different
5348 * critical section, it calls PDMDevHlpSetDeviceCritSect() to change it
5349 * very early on.
5350 */
5351 R0PTRTYPE(PPDMCRITSECT) pCritSectRoR0;
5352 /** Pointer to the ring-0 device registration structure. */
5353 R0PTRTYPE(PCPDMDEVREGR0) pReg;
5354 /** Ring-3 address of the ring-3 device instance. */
5355 R3PTRTYPE(struct PDMDEVINSR3 *) pDevInsForR3;
5356 /** Ring-0 pointer to the ring-3 device instance. */
5357 R0PTRTYPE(struct PDMDEVINSR3 *) pDevInsForR3R0;
5358 /** Ring-0 pointer to the ring-3 instance data. */
5359 RTR0PTR pvInstanceDataForR3R0;
5360 /** Raw-mode address of the raw-mode device instance. */
5361 RGPTRTYPE(struct PDMDEVINSRC *) pDevInsForRC;
5362 /** Ring-0 pointer to the raw-mode device instance. */
5363 R0PTRTYPE(struct PDMDEVINSRC *) pDevInsForRCR0;
5364 /** Ring-0 pointer to the raw-mode instance data. */
5365 RTR0PTR pvInstanceDataForRCR0;
5366
5367 /** PCI device structure size. */
5368 uint32_t cbPciDev;
5369 /** Number of PCI devices in apPciDevs. */
5370 uint32_t cPciDevs;
5371 /** Pointer to the PCI devices for this device.
5372 * (Allocated after the shared instance data.)
5373 * @note If we want to extend this beyond 8 sub-functions/devices, those 1 or
5374 * two devices ever needing it can use cbPciDev and do the address
5375 * calculations that for entries 8+. */
5376 R0PTRTYPE(struct PDMPCIDEV *) apPciDevs[8];
5377
5378 /** Align the internal data more naturally. */
5379 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 3 : 2 + 4];
5380
5381 /** Internal data. */
5382 union
5383 {
5384#ifdef PDMDEVINSINT_DECLARED
5385 PDMDEVINSINTR0 s;
5386#endif
5387 uint8_t padding[HC_ARCH_BITS == 32 ? 0x20 : 0x40];
5388 } Internal;
5389
5390 /** Device instance data for ring-0. The size of this area is defined
5391 * in the PDMDEVREG::cbInstanceR0 field. */
5392 char achInstanceData[8];
5393} PDMDEVINSR0;
5394
5395/** Current PDMDEVINSR0 version number. */
5396#define PDM_DEVINSR0_VERSION PDM_VERSION_MAKE(0xff83, 4, 0)
5397
5398
5399/**
5400 * PDM raw-mode device instance.
5401 */
5402typedef struct PDMDEVINSRC
5403{
5404 /** Structure version. PDM_DEVINSRC_VERSION defines the current version. */
5405 uint32_t u32Version;
5406 /** Device instance number. */
5407 uint32_t iInstance;
5408
5409 /** Pointer the HC PDM Device API. */
5410 PCPDMDEVHLPRC pHlpRC;
5411 /** Pointer to the shared device instance data. */
5412 RTRGPTR pvInstanceDataRC;
5413 /** Pointer to the device instance data for raw-mode. */
5414 RTRGPTR pvInstanceDataForRC;
5415 /** The critical section for the device.
5416 *
5417 * TM and IOM will enter this critical section before calling into the device
5418 * code. PDM will when doing power on, power off, reset, suspend and resume
5419 * notifications. SSM will currently not, but this will be changed later on.
5420 *
5421 * The device gets a critical section automatically assigned to it before
5422 * the constructor is called. If the constructor wishes to use a different
5423 * critical section, it calls PDMDevHlpSetDeviceCritSect() to change it
5424 * very early on.
5425 */
5426 RGPTRTYPE(PPDMCRITSECT) pCritSectRoRC;
5427 /** Pointer to the raw-mode device registration structure. */
5428 RGPTRTYPE(PCPDMDEVREGRC) pReg;
5429
5430 /** PCI device structure size. */
5431 uint32_t cbPciDev;
5432 /** Number of PCI devices in apPciDevs. */
5433 uint32_t cPciDevs;
5434 /** Pointer to the PCI devices for this device.
5435 * (Allocated after the shared instance data.) */
5436 RGPTRTYPE(struct PDMPCIDEV *) apPciDevs[8];
5437
5438 /** Align the internal data more naturally. */
5439 uint32_t au32Padding[14];
5440
5441 /** Internal data. */
5442 union
5443 {
5444#ifdef PDMDEVINSINT_DECLARED
5445 PDMDEVINSINTRC s;
5446#endif
5447 uint8_t padding[0x10];
5448 } Internal;
5449
5450 /** Device instance data for ring-0. The size of this area is defined
5451 * in the PDMDEVREG::cbInstanceR0 field. */
5452 char achInstanceData[8];
5453} PDMDEVINSRC;
5454
5455/** Current PDMDEVINSR0 version number. */
5456#define PDM_DEVINSRC_VERSION PDM_VERSION_MAKE(0xff84, 4, 0)
5457
5458
5459/** @def PDM_DEVINS_VERSION
5460 * Current PDMDEVINS version number. */
5461/** @typedef PDMDEVINS
5462 * The device instance structure for the current context. */
5463#ifdef IN_RING3
5464# define PDM_DEVINS_VERSION PDM_DEVINSR3_VERSION
5465typedef PDMDEVINSR3 PDMDEVINS;
5466#elif defined(IN_RING0)
5467# define PDM_DEVINS_VERSION PDM_DEVINSR0_VERSION
5468typedef PDMDEVINSR0 PDMDEVINS;
5469#elif defined(IN_RC)
5470# define PDM_DEVINS_VERSION PDM_DEVINSRC_VERSION
5471typedef PDMDEVINSRC PDMDEVINS;
5472#else
5473# error "Missing context defines: IN_RING0, IN_RING3, IN_RC"
5474#endif
5475
5476/**
5477 * Get the pointer to an PCI device.
5478 * @note Returns NULL if @a a_idxPciDev is out of bounds.
5479 */
5480#define PDMDEV_GET_PPCIDEV(a_pDevIns, a_idxPciDev) \
5481 ( (uintptr_t)(a_idxPciDev) < RT_ELEMENTS((a_pDevIns)->apPciDevs) ? (a_pDevIns)->apPciDevs[(uintptr_t)(a_idxPciDev)] \
5482 : PDMDEV_CALC_PPCIDEV(a_pDevIns, a_idxPciDev) )
5483
5484/**
5485 * Calc the pointer to of a given PCI device.
5486 * @note Returns NULL if @a a_idxPciDev is out of bounds.
5487 */
5488#define PDMDEV_CALC_PPCIDEV(a_pDevIns, a_idxPciDev) \
5489 ( (uintptr_t)(a_idxPciDev) < (a_pDevIns)->cPciDevs \
5490 ? (PPDMPCIDEV)((uint8_t *)((a_pDevIns)->apPciDevs[0]) + (a_pDevIns->cbPciDev) * (uintptr_t)(a_idxPciDev)) \
5491 : (PPDMPCIDEV)NULL )
5492
5493
5494/**
5495 * Checks the structure versions of the device instance and device helpers,
5496 * returning if they are incompatible.
5497 *
5498 * This is for use in the constructor.
5499 *
5500 * @param pDevIns The device instance pointer.
5501 */
5502#define PDMDEV_CHECK_VERSIONS_RETURN(pDevIns) \
5503 do \
5504 { \
5505 PPDMDEVINS pDevInsTypeCheck = (pDevIns); NOREF(pDevInsTypeCheck); \
5506 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->u32Version, PDM_DEVINS_VERSION), \
5507 ("DevIns=%#x mine=%#x\n", (pDevIns)->u32Version, PDM_DEVINS_VERSION), \
5508 VERR_PDM_DEVINS_VERSION_MISMATCH); \
5509 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->CTX_SUFF(pHlp)->u32Version, CTX_MID(PDM_DEVHLP,_VERSION)), \
5510 ("DevHlp=%#x mine=%#x\n", (pDevIns)->CTX_SUFF(pHlp)->u32Version, CTX_MID(PDM_DEVHLP,_VERSION)), \
5511 VERR_PDM_DEVHLP_VERSION_MISMATCH); \
5512 } while (0)
5513
5514/**
5515 * Quietly checks the structure versions of the device instance and device
5516 * helpers, returning if they are incompatible.
5517 *
5518 * This is for use in the destructor.
5519 *
5520 * @param pDevIns The device instance pointer.
5521 */
5522#define PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns) \
5523 do \
5524 { \
5525 PPDMDEVINS pDevInsTypeCheck = (pDevIns); NOREF(pDevInsTypeCheck); \
5526 if (RT_LIKELY(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->u32Version, PDM_DEVINS_VERSION) )) \
5527 { /* likely */ } else return VERR_PDM_DEVINS_VERSION_MISMATCH; \
5528 if (RT_LIKELY(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->CTX_SUFF(pHlp)->u32Version, CTX_MID(PDM_DEVHLP,_VERSION)) )) \
5529 { /* likely */ } else return VERR_PDM_DEVHLP_VERSION_MISMATCH; \
5530 } while (0)
5531
5532/**
5533 * Wrapper around CFGMR3ValidateConfig for the root config for use in the
5534 * constructor - returns on failure.
5535 *
5536 * This should be invoked after having initialized the instance data
5537 * sufficiently for the correct operation of the destructor. The destructor is
5538 * always called!
5539 *
5540 * @param pDevIns Pointer to the PDM device instance.
5541 * @param pszValidValues Patterns describing the valid value names. See
5542 * RTStrSimplePatternMultiMatch for details on the
5543 * pattern syntax.
5544 * @param pszValidNodes Patterns describing the valid node (key) names.
5545 * Pass empty string if no valid nodes.
5546 */
5547#define PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, pszValidValues, pszValidNodes) \
5548 do \
5549 { \
5550 int rcValCfg = pDevIns->pHlpR3->pfnCFGMValidateConfig((pDevIns)->pCfg, "/", pszValidValues, pszValidNodes, \
5551 (pDevIns)->pReg->szName, (pDevIns)->iInstance); \
5552 if (RT_SUCCESS(rcValCfg)) \
5553 { /* likely */ } else return rcValCfg; \
5554 } while (0)
5555
5556/** @def PDMDEV_ASSERT_EMT
5557 * Assert that the current thread is the emulation thread.
5558 */
5559#ifdef VBOX_STRICT
5560# define PDMDEV_ASSERT_EMT(pDevIns) pDevIns->pHlpR3->pfnAssertEMT(pDevIns, __FILE__, __LINE__, __FUNCTION__)
5561#else
5562# define PDMDEV_ASSERT_EMT(pDevIns) do { } while (0)
5563#endif
5564
5565/** @def PDMDEV_ASSERT_OTHER
5566 * Assert that the current thread is NOT the emulation thread.
5567 */
5568#ifdef VBOX_STRICT
5569# define PDMDEV_ASSERT_OTHER(pDevIns) pDevIns->pHlpR3->pfnAssertOther(pDevIns, __FILE__, __LINE__, __FUNCTION__)
5570#else
5571# define PDMDEV_ASSERT_OTHER(pDevIns) do { } while (0)
5572#endif
5573
5574/** @def PDMDEV_ASSERT_VMLOCK_OWNER
5575 * Assert that the current thread is owner of the VM lock.
5576 */
5577#ifdef VBOX_STRICT
5578# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) pDevIns->pHlpR3->pfnAssertVMLock(pDevIns, __FILE__, __LINE__, __FUNCTION__)
5579#else
5580# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) do { } while (0)
5581#endif
5582
5583/** @def PDMDEV_SET_ERROR
5584 * Set the VM error. See PDMDevHlpVMSetError() for printf like message formatting.
5585 */
5586#define PDMDEV_SET_ERROR(pDevIns, rc, pszError) \
5587 PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, "%s", pszError)
5588
5589/** @def PDMDEV_SET_RUNTIME_ERROR
5590 * Set the VM runtime error. See PDMDevHlpVMSetRuntimeError() for printf like message formatting.
5591 */
5592#define PDMDEV_SET_RUNTIME_ERROR(pDevIns, fFlags, pszErrorId, pszError) \
5593 PDMDevHlpVMSetRuntimeError(pDevIns, fFlags, pszErrorId, "%s", pszError)
5594
5595/** @def PDMDEVINS_2_RCPTR
5596 * Converts a PDM Device instance pointer a RC PDM Device instance pointer.
5597 */
5598#ifdef IN_RC
5599# define PDMDEVINS_2_RCPTR(pDevIns) (pDevIns)
5600#else
5601# define PDMDEVINS_2_RCPTR(pDevIns) ( (pDevIns)->pDevInsForRC )
5602#endif
5603
5604/** @def PDMDEVINS_2_R3PTR
5605 * Converts a PDM Device instance pointer a R3 PDM Device instance pointer.
5606 */
5607#ifdef IN_RING3
5608# define PDMDEVINS_2_R3PTR(pDevIns) (pDevIns)
5609#else
5610# define PDMDEVINS_2_R3PTR(pDevIns) ( (pDevIns)->pDevInsForR3 )
5611#endif
5612
5613/** @def PDMDEVINS_2_R0PTR
5614 * Converts a PDM Device instance pointer a R0 PDM Device instance pointer.
5615 */
5616#ifdef IN_RING0
5617# define PDMDEVINS_2_R0PTR(pDevIns) (pDevIns)
5618#else
5619# define PDMDEVINS_2_R0PTR(pDevIns) ( (pDevIns)->pDevInsR0RemoveMe )
5620#endif
5621
5622/** @def PDMDEVINS_DATA_2_R0_REMOVE_ME
5623 * Converts a PDM device instance data pointer to a ring-0 one.
5624 * @deprecated
5625 */
5626#ifdef IN_RING0
5627# define PDMDEVINS_DATA_2_R0_REMOVE_ME(pDevIns, pvCC) (pvCC)
5628#else
5629# define PDMDEVINS_DATA_2_R0_REMOVE_ME(pDevIns, pvCC) ( (pDevIns)->pvInstanceDataR0 + (uintptr_t)(pvCC) - (uintptr_t)(pDevIns)->CTX_SUFF(pvInstanceData) )
5630#endif
5631
5632
5633/** @def PDMDEVINS_2_DATA
5634 * This is a safer edition of PDMINS_2_DATA that checks that the size of the
5635 * target type is same as PDMDEVREG::cbInstanceShared in strict builds.
5636 *
5637 * @note Do no use this macro in common code working on a core structure which
5638 * device specific code has expanded.
5639 */
5640#if defined(VBOX_STRICT) && defined(RT_COMPILER_SUPPORTS_LAMBDA)
5641# define PDMDEVINS_2_DATA(a_pDevIns, a_PtrType) \
5642 ([](PPDMDEVINS a_pLambdaDevIns) -> a_PtrType \
5643 { \
5644 a_PtrType pLambdaRet = (a_PtrType)(a_pLambdaDevIns)->CTX_SUFF(pvInstanceData); \
5645 Assert(sizeof(*pLambdaRet) == a_pLambdaDevIns->pReg->cbInstanceShared); \
5646 return pLambdaRet; \
5647 }(a_pDevIns))
5648#else
5649# define PDMDEVINS_2_DATA(a_pDevIns, a_PtrType) ( (a_PtrType)(a_pDevIns)->CTX_SUFF(pvInstanceData) )
5650#endif
5651
5652/** @def PDMDEVINS_2_DATA_CC
5653 * This is a safer edition of PDMINS_2_DATA_CC that checks that the size of the
5654 * target type is same as PDMDEVREG::cbInstanceCC in strict builds.
5655 *
5656 * @note Do no use this macro in common code working on a core structure which
5657 * device specific code has expanded.
5658 */
5659#if defined(VBOX_STRICT) && defined(RT_COMPILER_SUPPORTS_LAMBDA)
5660# define PDMDEVINS_2_DATA_CC(a_pDevIns, a_PtrType) \
5661 ([](PPDMDEVINS a_pLambdaDevIns) -> a_PtrType \
5662 { \
5663 a_PtrType pLambdaRet = (a_PtrType)&(a_pLambdaDevIns)->achInstanceData[0]; \
5664 Assert(sizeof(*pLambdaRet) == a_pLambdaDevIns->pReg->cbInstanceCC); \
5665 return pLambdaRet; \
5666 }(a_pDevIns))
5667#else
5668# define PDMDEVINS_2_DATA_CC(a_pDevIns, a_PtrType) ( (a_PtrType)(void *)&(a_pDevIns)->achInstanceData[0] )
5669#endif
5670
5671
5672#ifdef IN_RING3
5673
5674/**
5675 * @copydoc PDMDEVHLPR3::pfnIOPortRegister
5676 */
5677DECLINLINE(int) PDMDevHlpIOPortRegister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser,
5678 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
5679 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc)
5680{
5681 return pDevIns->pHlpR3->pfnIOPortRegister(pDevIns, Port, cPorts, pvUser, pfnOut, pfnIn, pfnOutStr, pfnInStr, pszDesc);
5682}
5683
5684/**
5685 * @copydoc PDMDEVHLPR3::pfnIOPortRegisterRC
5686 */
5687DECLINLINE(int) PDMDevHlpIOPortRegisterRC(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
5688 const char *pszOut, const char *pszIn, const char *pszOutStr,
5689 const char *pszInStr, const char *pszDesc)
5690{
5691 return pDevIns->pHlpR3->pfnIOPortRegisterRC(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
5692}
5693
5694/**
5695 * @copydoc PDMDEVHLPR3::pfnIOPortRegisterR0
5696 */
5697DECLINLINE(int) PDMDevHlpIOPortRegisterR0(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
5698 const char *pszOut, const char *pszIn, const char *pszOutStr,
5699 const char *pszInStr, const char *pszDesc)
5700{
5701 return pDevIns->pHlpR3->pfnIOPortRegisterR0(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
5702}
5703
5704/**
5705 * @copydoc PDMDEVHLPR3::pfnIOPortDeregister
5706 */
5707DECLINLINE(int) PDMDevHlpIOPortDeregister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts)
5708{
5709 return pDevIns->pHlpR3->pfnIOPortDeregister(pDevIns, Port, cPorts);
5710}
5711
5712/**
5713 * Combines PDMDevHlpIoPortCreate() & PDMDevHlpIoPortMap().
5714 */
5715DECLINLINE(int) PDMDevHlpIoPortCreateAndMap(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, PFNIOMIOPORTNEWOUT pfnOut,
5716 PFNIOMIOPORTNEWIN pfnIn, const char *pszDesc, PCIOMIOPORTDESC paExtDescs,
5717 PIOMIOPORTHANDLE phIoPorts)
5718{
5719 int rc = pDevIns->pHlpR3->pfnIoPortCreateEx(pDevIns, cPorts, 0, NULL, UINT32_MAX,
5720 pfnOut, pfnIn, NULL, NULL, NULL, pszDesc, paExtDescs, phIoPorts);
5721 if (RT_SUCCESS(rc))
5722 rc = pDevIns->pHlpR3->pfnIoPortMap(pDevIns, *phIoPorts, Port);
5723 return rc;
5724}
5725
5726/**
5727 * Combines PDMDevHlpIoPortCreate() & PDMDevHlpIoPortMap(), but with pvUser.
5728 */
5729DECLINLINE(int) PDMDevHlpIoPortCreateUAndMap(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, PFNIOMIOPORTNEWOUT pfnOut,
5730 PFNIOMIOPORTNEWIN pfnIn, void *pvUser,
5731 const char *pszDesc, PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts)
5732{
5733 int rc = pDevIns->pHlpR3->pfnIoPortCreateEx(pDevIns, cPorts, 0, NULL, UINT32_MAX,
5734 pfnOut, pfnIn, NULL, NULL, pvUser, pszDesc, paExtDescs, phIoPorts);
5735 if (RT_SUCCESS(rc))
5736 rc = pDevIns->pHlpR3->pfnIoPortMap(pDevIns, *phIoPorts, Port);
5737 return rc;
5738}
5739
5740/**
5741 * Combines PDMDevHlpIoPortCreate() & PDMDevHlpIoPortMap(), but with flags.
5742 */
5743DECLINLINE(int) PDMDevHlpIoPortCreateFlagsAndMap(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, uint32_t fFlags,
5744 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
5745 const char *pszDesc, PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts)
5746{
5747 int rc = pDevIns->pHlpR3->pfnIoPortCreateEx(pDevIns, cPorts, fFlags, NULL, UINT32_MAX,
5748 pfnOut, pfnIn, NULL, NULL, NULL, pszDesc, paExtDescs, phIoPorts);
5749 if (RT_SUCCESS(rc))
5750 rc = pDevIns->pHlpR3->pfnIoPortMap(pDevIns, *phIoPorts, Port);
5751 return rc;
5752}
5753
5754/**
5755 * Combines PDMDevHlpIoPortCreateEx() & PDMDevHlpIoPortMap().
5756 */
5757DECLINLINE(int) PDMDevHlpIoPortCreateExAndMap(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, uint32_t fFlags,
5758 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
5759 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr, void *pvUser,
5760 const char *pszDesc, PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts)
5761{
5762 int rc = pDevIns->pHlpR3->pfnIoPortCreateEx(pDevIns, cPorts, fFlags, NULL, UINT32_MAX,
5763 pfnOut, pfnIn, pfnOutStr, pfnInStr, pvUser, pszDesc, paExtDescs, phIoPorts);
5764 if (RT_SUCCESS(rc))
5765 rc = pDevIns->pHlpR3->pfnIoPortMap(pDevIns, *phIoPorts, Port);
5766 return rc;
5767}
5768
5769/**
5770 * @sa PDMDevHlpIoPortCreateEx
5771 */
5772DECLINLINE(int) PDMDevHlpIoPortCreate(PPDMDEVINS pDevIns, RTIOPORT cPorts, PPDMPCIDEV pPciDev, uint32_t iPciRegion,
5773 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn, void *pvUser, const char *pszDesc,
5774 PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts)
5775{
5776 return pDevIns->pHlpR3->pfnIoPortCreateEx(pDevIns, cPorts, 0, pPciDev, iPciRegion,
5777 pfnOut, pfnIn, NULL, NULL, pvUser, pszDesc, paExtDescs, phIoPorts);
5778}
5779
5780
5781/**
5782 * @sa PDMDevHlpIoPortCreateEx
5783 */
5784DECLINLINE(int) PDMDevHlpIoPortCreateIsa(PPDMDEVINS pDevIns, RTIOPORT cPorts, PFNIOMIOPORTNEWOUT pfnOut,
5785 PFNIOMIOPORTNEWIN pfnIn, void *pvUser, const char *pszDesc,
5786 PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts)
5787{
5788 return pDevIns->pHlpR3->pfnIoPortCreateEx(pDevIns, cPorts, 0, NULL, UINT32_MAX,
5789 pfnOut, pfnIn, NULL, NULL, pvUser, pszDesc, paExtDescs, phIoPorts);
5790}
5791
5792/**
5793 * @copydoc PDMDEVHLPR3::pfnIoPortCreateEx
5794 */
5795DECLINLINE(int) PDMDevHlpIoPortCreateEx(PPDMDEVINS pDevIns, RTIOPORT cPorts, uint32_t fFlags, PPDMPCIDEV pPciDev,
5796 uint32_t iPciRegion, PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
5797 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr, void *pvUser,
5798 const char *pszDesc, PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts)
5799{
5800 return pDevIns->pHlpR3->pfnIoPortCreateEx(pDevIns, cPorts, fFlags, pPciDev, iPciRegion,
5801 pfnOut, pfnIn, pfnOutStr, pfnInStr, pvUser, pszDesc, paExtDescs, phIoPorts);
5802}
5803
5804/**
5805 * @copydoc PDMDEVHLPR3::pfnIoPortMap
5806 */
5807DECLINLINE(int) PDMDevHlpIoPortMap(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts, RTIOPORT Port)
5808{
5809 return pDevIns->pHlpR3->pfnIoPortMap(pDevIns, hIoPorts, Port);
5810}
5811
5812/**
5813 * @copydoc PDMDEVHLPR3::pfnIoPortUnmap
5814 */
5815DECLINLINE(int) PDMDevHlpIoPortUnmap(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts)
5816{
5817 return pDevIns->pHlpR3->pfnIoPortUnmap(pDevIns, hIoPorts);
5818}
5819
5820/**
5821 * @copydoc PDMDEVHLPR3::pfnIoPortGetMappingAddress
5822 */
5823DECLINLINE(uint32_t) PDMDevHlpIoPortGetMappingAddress(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts)
5824{
5825 return pDevIns->pHlpR3->pfnIoPortGetMappingAddress(pDevIns, hIoPorts);
5826}
5827
5828
5829#endif /* IN_RING3 */
5830#if !defined(IN_RING3) || defined(DOXYGEN_RUNNING)
5831
5832/**
5833 * @sa PDMDevHlpIoPortSetUpContextEx
5834 */
5835DECLINLINE(int) PDMDevHlpIoPortSetUpContext(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts,
5836 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn, void *pvUser)
5837{
5838 return pDevIns->CTX_SUFF(pHlp)->pfnIoPortSetUpContextEx(pDevIns, hIoPorts, pfnOut, pfnIn, NULL, NULL, pvUser);
5839}
5840
5841/**
5842 * @copydoc PDMDEVHLPR0::pfnIoPortSetUpContextEx
5843 */
5844DECLINLINE(int) PDMDevHlpIoPortSetUpContextEx(PPDMDEVINS pDevIns, IOMIOPORTHANDLE hIoPorts,
5845 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn,
5846 PFNIOMIOPORTNEWOUTSTRING pfnOutStr, PFNIOMIOPORTNEWINSTRING pfnInStr, void *pvUser)
5847{
5848 return pDevIns->CTX_SUFF(pHlp)->pfnIoPortSetUpContextEx(pDevIns, hIoPorts, pfnOut, pfnIn, pfnOutStr, pfnInStr, pvUser);
5849}
5850
5851#endif /* !IN_RING3 || DOXYGEN_RUNNING */
5852#ifdef IN_RING3
5853
5854/**
5855 * @sa PDMDevHlpMmioCreateEx
5856 */
5857DECLINLINE(int) PDMDevHlpMmioCreate(PPDMDEVINS pDevIns, RTGCPHYS cbRegion, PPDMPCIDEV pPciDev, uint32_t iPciRegion,
5858 PFNIOMMMIONEWWRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead, void *pvUser,
5859 uint32_t fFlags, const char *pszDesc, PIOMMMIOHANDLE phRegion)
5860{
5861 return pDevIns->pHlpR3->pfnMmioCreateEx(pDevIns, cbRegion, fFlags, pPciDev, iPciRegion,
5862 pfnWrite, pfnRead, NULL, pvUser, pszDesc, phRegion);
5863}
5864
5865/**
5866 * @copydoc PDMDEVHLPR3::pfnMmioCreateEx
5867 */
5868DECLINLINE(int) PDMDevHlpMmioCreateEx(PPDMDEVINS pDevIns, RTGCPHYS cbRegion,
5869 uint32_t fFlags, PPDMPCIDEV pPciDev, uint32_t iPciRegion,
5870 PFNIOMMMIONEWWRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill,
5871 void *pvUser, const char *pszDesc, PIOMMMIOHANDLE phRegion)
5872{
5873 return pDevIns->pHlpR3->pfnMmioCreateEx(pDevIns, cbRegion, fFlags, pPciDev, iPciRegion,
5874 pfnWrite, pfnRead, pfnFill, pvUser, pszDesc, phRegion);
5875}
5876
5877/**
5878 * @sa PDMDevHlpMmioCreate and PDMDevHlpMmioMap
5879 */
5880DECLINLINE(int) PDMDevHlpMmioCreateAndMap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPHYS cbRegion,
5881 PFNIOMMMIONEWWRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead,
5882 uint32_t fFlags, const char *pszDesc, PIOMMMIOHANDLE phRegion)
5883{
5884 int rc = pDevIns->pHlpR3->pfnMmioCreateEx(pDevIns, cbRegion, fFlags, NULL /*pPciDev*/, UINT32_MAX /*iPciRegion*/,
5885 pfnWrite, pfnRead, NULL /*pfnFill*/, NULL /*pvUser*/, pszDesc, phRegion);
5886 if (RT_SUCCESS(rc))
5887 rc = pDevIns->pHlpR3->pfnMmioMap(pDevIns, *phRegion, GCPhys);
5888 return rc;
5889}
5890
5891/**
5892 * @sa PDMDevHlpMmioCreateEx and PDMDevHlpMmioMap
5893 */
5894DECLINLINE(int) PDMDevHlpMmioCreateExAndMap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPHYS cbRegion, uint32_t fFlags,
5895 PPDMPCIDEV pPciDev, uint32_t iPciRegion, PFNIOMMMIONEWWRITE pfnWrite,
5896 PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill, void *pvUser,
5897 const char *pszDesc, PIOMMMIOHANDLE phRegion)
5898{
5899 int rc = pDevIns->pHlpR3->pfnMmioCreateEx(pDevIns, cbRegion, fFlags, pPciDev, iPciRegion,
5900 pfnWrite, pfnRead, pfnFill, pvUser, pszDesc, phRegion);
5901 if (RT_SUCCESS(rc))
5902 rc = pDevIns->pHlpR3->pfnMmioMap(pDevIns, *phRegion, GCPhys);
5903 return rc;
5904}
5905
5906/**
5907 * @copydoc PDMDEVHLPR3::pfnMmioMap
5908 */
5909DECLINLINE(int) PDMDevHlpMmioMap(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, RTGCPHYS GCPhys)
5910{
5911 return pDevIns->pHlpR3->pfnMmioMap(pDevIns, hRegion, GCPhys);
5912}
5913
5914/**
5915 * @copydoc PDMDEVHLPR3::pfnMmioUnmap
5916 */
5917DECLINLINE(int) PDMDevHlpMmioUnmap(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion)
5918{
5919 return pDevIns->pHlpR3->pfnMmioUnmap(pDevIns, hRegion);
5920}
5921
5922/**
5923 * @copydoc PDMDEVHLPR3::pfnMmioReduce
5924 */
5925DECLINLINE(int) PDMDevHlpMmioReduce(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, RTGCPHYS cbRegion)
5926{
5927 return pDevIns->pHlpR3->pfnMmioReduce(pDevIns, hRegion, cbRegion);
5928}
5929
5930/**
5931 * @copydoc PDMDEVHLPR3::pfnMmioGetMappingAddress
5932 */
5933DECLINLINE(RTGCPHYS) PDMDevHlpMmioGetMappingAddress(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion)
5934{
5935 return pDevIns->pHlpR3->pfnMmioGetMappingAddress(pDevIns, hRegion);
5936}
5937
5938#endif /* IN_RING3 */
5939#if !defined(IN_RING3) || defined(DOXYGEN_RUNNING)
5940
5941/**
5942 * @sa PDMDevHlpMmioSetUpContextEx
5943 */
5944DECLINLINE(int) PDMDevHlpMmioSetUpContext(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion,
5945 PFNIOMMMIONEWWRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead, void *pvUser)
5946{
5947 return pDevIns->CTX_SUFF(pHlp)->pfnMmioSetUpContextEx(pDevIns, hRegion, pfnWrite, pfnRead, NULL, pvUser);
5948}
5949
5950/**
5951 * @copydoc PDMDEVHLPR0::pfnMmioSetUpContextEx
5952 */
5953DECLINLINE(int) PDMDevHlpMmioSetUpContextEx(PPDMDEVINS pDevIns, IOMMMIOHANDLE hRegion, PFNIOMMMIONEWWRITE pfnWrite,
5954 PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill, void *pvUser)
5955{
5956 return pDevIns->CTX_SUFF(pHlp)->pfnMmioSetUpContextEx(pDevIns, hRegion, pfnWrite, pfnRead, pfnFill, pvUser);
5957}
5958
5959#endif /* !IN_RING3 || DOXYGEN_RUNNING */
5960#ifdef IN_RING3
5961
5962/**
5963 * Register a Memory Mapped I/O (MMIO) region.
5964 *
5965 * These callbacks are of course for the ring-3 context (R3). Register HC
5966 * handlers before raw-mode context (RC) and ring-0 context (R0) handlers! There
5967 * must be a R3 handler for every RC and R0 handler!
5968 *
5969 * @returns VBox status.
5970 * @param pDevIns The device instance to register the MMIO with.
5971 * @param GCPhysStart First physical address in the range.
5972 * @param cbRange The size of the range (in bytes).
5973 * @param pvUser User argument.
5974 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
5975 * @param pfnWrite Pointer to function which is gonna handle Write operations.
5976 * @param pfnRead Pointer to function which is gonna handle Read operations.
5977 * @param pszDesc Pointer to description string. This must not be freed.
5978 */
5979DECLINLINE(int) PDMDevHlpMMIORegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTHCPTR pvUser,
5980 uint32_t fFlags, PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, const char *pszDesc)
5981{
5982 return pDevIns->pHlpR3->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, NULL /*pfnFill*/,
5983 fFlags, pszDesc);
5984}
5985
5986/**
5987 * Register a Memory Mapped I/O (MMIO) region for RC.
5988 *
5989 * These callbacks are for the raw-mode context (RC). Register ring-3 context
5990 * (R3) handlers before guest context handlers! There must be a R3 handler for
5991 * every RC handler!
5992 *
5993 * @returns VBox status.
5994 * @param pDevIns The device instance to register the MMIO with.
5995 * @param GCPhysStart First physical address in the range.
5996 * @param cbRange The size of the range (in bytes).
5997 * @param pvUser User argument.
5998 * @param pszWrite Name of the RC function which is gonna handle Write operations.
5999 * @param pszRead Name of the RC function which is gonna handle Read operations.
6000 */
6001DECLINLINE(int) PDMDevHlpMMIORegisterRC(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTRCPTR pvUser,
6002 const char *pszWrite, const char *pszRead)
6003{
6004 return pDevIns->pHlpR3->pfnMMIORegisterRC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, NULL /*pszFill*/);
6005}
6006
6007/**
6008 * Register a Memory Mapped I/O (MMIO) region for R0.
6009 *
6010 * These callbacks are for the ring-0 host context (R0). Register ring-3
6011 * constext (R3) handlers before R0 handlers! There must be a R3 handler for
6012 * every R0 handler!
6013 *
6014 * @returns VBox status.
6015 * @param pDevIns The device instance to register the MMIO with.
6016 * @param GCPhysStart First physical address in the range.
6017 * @param cbRange The size of the range (in bytes).
6018 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
6019 * @param pszWrite Name of the RC function which is gonna handle Write operations.
6020 * @param pszRead Name of the RC function which is gonna handle Read operations.
6021 * @remarks Caller enters the device critical section prior to invoking the
6022 * registered callback methods.
6023 */
6024DECLINLINE(int) PDMDevHlpMMIORegisterR0(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTR0PTR pvUser,
6025 const char *pszWrite, const char *pszRead)
6026{
6027 return pDevIns->pHlpR3->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, NULL /*pszFill*/);
6028}
6029
6030/**
6031 * @copydoc PDMDEVHLPR3::pfnMMIORegister
6032 */
6033DECLINLINE(int) PDMDevHlpMMIORegisterEx(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTHCPTR pvUser,
6034 uint32_t fFlags, PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead,
6035 PFNIOMMMIOFILL pfnFill, const char *pszDesc)
6036{
6037 return pDevIns->pHlpR3->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, pfnFill,
6038 fFlags, pszDesc);
6039}
6040
6041/**
6042 * @copydoc PDMDEVHLPR3::pfnMMIORegisterRC
6043 */
6044DECLINLINE(int) PDMDevHlpMMIORegisterRCEx(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTRCPTR pvUser,
6045 const char *pszWrite, const char *pszRead, const char *pszFill)
6046{
6047 return pDevIns->pHlpR3->pfnMMIORegisterRC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill);
6048}
6049
6050/**
6051 * @copydoc PDMDEVHLPR3::pfnMMIORegisterR0
6052 */
6053DECLINLINE(int) PDMDevHlpMMIORegisterR0Ex(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTR0PTR pvUser,
6054 const char *pszWrite, const char *pszRead, const char *pszFill)
6055{
6056 return pDevIns->pHlpR3->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill);
6057}
6058
6059/**
6060 * @copydoc PDMDEVHLPR3::pfnMMIODeregister
6061 */
6062DECLINLINE(int) PDMDevHlpMMIODeregister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange)
6063{
6064 return pDevIns->pHlpR3->pfnMMIODeregister(pDevIns, GCPhysStart, cbRange);
6065}
6066
6067/**
6068 * @copydoc PDMDEVHLPR3::pfnMmio2Create
6069 */
6070DECLINLINE(int) PDMDevHlpMmio2Create(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iPciRegion, RTGCPHYS cbRegion,
6071 uint32_t fFlags, const char *pszDesc, void **ppvMapping, PPGMMMIO2HANDLE phRegion)
6072{
6073 return pDevIns->pHlpR3->pfnMmio2Create(pDevIns, pPciDev, iPciRegion, cbRegion, fFlags, pszDesc, ppvMapping, phRegion);
6074}
6075
6076/**
6077 * @copydoc PDMDEVHLPR3::pfnMmio2Map
6078 */
6079DECLINLINE(int) PDMDevHlpMmio2Map(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, RTGCPHYS GCPhys)
6080{
6081 return pDevIns->pHlpR3->pfnMmio2Map(pDevIns, hRegion, GCPhys);
6082}
6083
6084/**
6085 * @copydoc PDMDEVHLPR3::pfnMmio2Unmap
6086 */
6087DECLINLINE(int) PDMDevHlpMmio2Unmap(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion)
6088{
6089 return pDevIns->pHlpR3->pfnMmio2Unmap(pDevIns, hRegion);
6090}
6091
6092/**
6093 * @copydoc PDMDEVHLPR3::pfnMmio2Reduce
6094 */
6095DECLINLINE(int) PDMDevHlpMmio2Reduce(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion, RTGCPHYS cbRegion)
6096{
6097 return pDevIns->pHlpR3->pfnMmio2Reduce(pDevIns, hRegion, cbRegion);
6098}
6099
6100/**
6101 * @copydoc PDMDEVHLPR3::pfnMmio2GetMappingAddress
6102 */
6103DECLINLINE(RTGCPHYS) PDMDevHlpMmio2GetMappingAddress(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion)
6104{
6105 return pDevIns->pHlpR3->pfnMmio2GetMappingAddress(pDevIns, hRegion);
6106}
6107
6108#endif /* IN_RING3 */
6109#if !defined(IN_RING3) || defined(DOXYGEN_RUNNING)
6110
6111/**
6112 * @copydoc PDMDEVHLPR0::pfnMmio2SetUpContext
6113 */
6114DECLINLINE(int) PDMDevHlpMmio2SetUpContext(PPDMDEVINS pDevIns, PGMMMIO2HANDLE hRegion,
6115 size_t offSub, size_t cbSub, void **ppvMapping)
6116{
6117 return pDevIns->CTX_SUFF(pHlp)->pfnMmio2SetUpContext(pDevIns, hRegion, offSub, cbSub, ppvMapping);
6118}
6119
6120#endif /* !IN_RING3 || DOXYGEN_RUNNING */
6121#ifdef IN_RING3
6122
6123/**
6124 * @copydoc PDMDEVHLPR3::pfnMMIO2Register
6125 */
6126DECLINLINE(int) PDMDevHlpMMIO2Register(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS cb,
6127 uint32_t fFlags, void **ppv, const char *pszDesc)
6128{
6129 return pDevIns->pHlpR3->pfnMMIO2Register(pDevIns, pPciDev, iRegion, cb, fFlags, ppv, pszDesc);
6130}
6131
6132/**
6133 * @copydoc PDMDEVHLPR3::pfnMMIOExDeregister
6134 * @param pPciDev The PCI device the region is associated with, use
6135 * NULL to indicate it is not associated with a device.
6136 */
6137DECLINLINE(int) PDMDevHlpMMIOExDeregister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion)
6138{
6139 return pDevIns->pHlpR3->pfnMMIOExDeregister(pDevIns, pPciDev, iRegion);
6140}
6141
6142/**
6143 * @copydoc PDMDEVHLPR3::pfnMMIOExMap
6144 * @param pPciDev The PCI device the region is associated with, use
6145 * NULL to indicate it is not associated with a device.
6146 */
6147DECLINLINE(int) PDMDevHlpMMIOExMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS GCPhys)
6148{
6149 return pDevIns->pHlpR3->pfnMMIOExMap(pDevIns, pPciDev, iRegion, GCPhys);
6150}
6151
6152/**
6153 * @copydoc PDMDEVHLPR3::pfnMMIOExUnmap
6154 * @param pPciDev The PCI device the region is associated with, use
6155 * NULL to indicate it is not associated with a device.
6156 */
6157DECLINLINE(int) PDMDevHlpMMIOExUnmap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS GCPhys)
6158{
6159 return pDevIns->pHlpR3->pfnMMIOExUnmap(pDevIns, pPciDev, iRegion, GCPhys);
6160}
6161
6162/**
6163 * @copydoc PDMDEVHLPR3::pfnMMIOExReduce
6164 */
6165DECLINLINE(int) PDMDevHlpMMIOExReduce(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS cbRegion)
6166{
6167 return pDevIns->pHlpR3->pfnMMIOExReduce(pDevIns, pPciDev, iRegion, cbRegion);
6168}
6169
6170#ifdef VBOX_WITH_RAW_MODE_KEEP
6171/**
6172 * @copydoc PDMDEVHLPR3::pfnMMHyperMapMMIO2
6173 */
6174DECLINLINE(int) PDMDevHlpMMHyperMapMMIO2(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
6175 const char *pszDesc, PRTRCPTR pRCPtr)
6176{
6177 return pDevIns->pHlpR3->pfnMMHyperMapMMIO2(pDevIns, pPciDev, iRegion, off, cb, pszDesc, pRCPtr);
6178}
6179#endif
6180
6181/**
6182 * @copydoc PDMDEVHLPR3::pfnMMIO2MapKernel
6183 */
6184DECLINLINE(int) PDMDevHlpMMIO2MapKernel(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
6185 const char *pszDesc, PRTR0PTR pR0Ptr)
6186{
6187 return pDevIns->pHlpR3->pfnMMIO2MapKernel(pDevIns, pPciDev, iRegion, off, cb, pszDesc, pR0Ptr);
6188}
6189
6190/**
6191 * @copydoc PDMDEVHLPR3::pfnROMRegister
6192 */
6193DECLINLINE(int) PDMDevHlpROMRegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
6194 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc)
6195{
6196 return pDevIns->pHlpR3->pfnROMRegister(pDevIns, GCPhysStart, cbRange, pvBinary, cbBinary, fFlags, pszDesc);
6197}
6198
6199/**
6200 * @copydoc PDMDEVHLPR3::pfnROMProtectShadow
6201 */
6202DECLINLINE(int) PDMDevHlpROMProtectShadow(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt)
6203{
6204 return pDevIns->pHlpR3->pfnROMProtectShadow(pDevIns, GCPhysStart, cbRange, enmProt);
6205}
6206
6207/**
6208 * Register a save state data unit.
6209 *
6210 * @returns VBox status.
6211 * @param pDevIns The device instance.
6212 * @param uVersion Data layout version number.
6213 * @param cbGuess The approximate amount of data in the unit.
6214 * Only for progress indicators.
6215 * @param pfnSaveExec Execute save callback, optional.
6216 * @param pfnLoadExec Execute load callback, optional.
6217 */
6218DECLINLINE(int) PDMDevHlpSSMRegister(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess,
6219 PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVLOADEXEC pfnLoadExec)
6220{
6221 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, NULL /*pszBefore*/,
6222 NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveDone*/,
6223 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
6224 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
6225}
6226
6227/**
6228 * Register a save state data unit with a live save callback as well.
6229 *
6230 * @returns VBox status.
6231 * @param pDevIns The device instance.
6232 * @param uVersion Data layout version number.
6233 * @param cbGuess The approximate amount of data in the unit.
6234 * Only for progress indicators.
6235 * @param pfnLiveExec Execute live callback, optional.
6236 * @param pfnSaveExec Execute save callback, optional.
6237 * @param pfnLoadExec Execute load callback, optional.
6238 */
6239DECLINLINE(int) PDMDevHlpSSMRegister3(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess,
6240 PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVLOADEXEC pfnLoadExec)
6241{
6242 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, NULL /*pszBefore*/,
6243 NULL /*pfnLivePrep*/, pfnLiveExec, NULL /*pfnLiveDone*/,
6244 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
6245 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
6246}
6247
6248/**
6249 * @copydoc PDMDEVHLPR3::pfnSSMRegister
6250 */
6251DECLINLINE(int) PDMDevHlpSSMRegisterEx(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
6252 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
6253 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
6254 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone)
6255{
6256 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, pszBefore,
6257 pfnLivePrep, pfnLiveExec, pfnLiveVote,
6258 pfnSavePrep, pfnSaveExec, pfnSaveDone,
6259 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
6260}
6261
6262/**
6263 * @copydoc PDMDEVHLPR3::pfnTMTimerCreate
6264 */
6265DECLINLINE(int) PDMDevHlpTMTimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser,
6266 uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
6267{
6268 return pDevIns->pHlpR3->pfnTMTimerCreate(pDevIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
6269}
6270
6271/**
6272 * @copydoc PDMDEVHLPR3::pfnTimerCreate
6273 */
6274DECLINLINE(int) PDMDevHlpTimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser,
6275 uint32_t fFlags, const char *pszDesc, PTMTIMERHANDLE phTimer)
6276{
6277 return pDevIns->pHlpR3->pfnTimerCreate(pDevIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, phTimer);
6278}
6279
6280#endif /* IN_RING3 */
6281
6282/**
6283 * @copydoc PDMDEVHLPR3::pfnTimerToPtr
6284 */
6285DECLINLINE(PTMTIMER) PDMDevHlpTimerToPtr(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6286{
6287 return pDevIns->CTX_SUFF(pHlp)->pfnTimerToPtr(pDevIns, hTimer);
6288}
6289
6290/**
6291 * @copydoc PDMDEVHLPR3::pfnTimerFromMicro
6292 */
6293DECLINLINE(uint64_t) PDMDevHlpTimerFromMicro(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMicroSecs)
6294{
6295 return pDevIns->CTX_SUFF(pHlp)->pfnTimerFromMicro(pDevIns, hTimer, cMicroSecs);
6296}
6297
6298/**
6299 * @copydoc PDMDEVHLPR3::pfnTimerFromMilli
6300 */
6301DECLINLINE(uint64_t) PDMDevHlpTimerFromMilli(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMilliSecs)
6302{
6303 return pDevIns->CTX_SUFF(pHlp)->pfnTimerFromMilli(pDevIns, hTimer, cMilliSecs);
6304}
6305
6306/**
6307 * @copydoc PDMDEVHLPR3::pfnTimerFromNano
6308 */
6309DECLINLINE(uint64_t) PDMDevHlpTimerFromNano(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cNanoSecs)
6310{
6311 return pDevIns->CTX_SUFF(pHlp)->pfnTimerFromNano(pDevIns, hTimer, cNanoSecs);
6312}
6313
6314/**
6315 * @copydoc PDMDEVHLPR3::pfnTimerGet
6316 */
6317DECLINLINE(uint64_t) PDMDevHlpTimerGet(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6318{
6319 return pDevIns->CTX_SUFF(pHlp)->pfnTimerGet(pDevIns, hTimer);
6320}
6321
6322/**
6323 * @copydoc PDMDEVHLPR3::pfnTimerGetFreq
6324 */
6325DECLINLINE(uint64_t) PDMDevHlpTimerGetFreq(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6326{
6327 return pDevIns->CTX_SUFF(pHlp)->pfnTimerGetFreq(pDevIns, hTimer);
6328}
6329
6330/**
6331 * @copydoc PDMDEVHLPR3::pfnTimerGetNano
6332 */
6333DECLINLINE(uint64_t) PDMDevHlpTimerGetNano(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6334{
6335 return pDevIns->CTX_SUFF(pHlp)->pfnTimerGetNano(pDevIns, hTimer);
6336}
6337
6338/**
6339 * @copydoc PDMDEVHLPR3::pfnTimerIsActive
6340 */
6341DECLINLINE(bool) PDMDevHlpTimerIsActive(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6342{
6343 return pDevIns->CTX_SUFF(pHlp)->pfnTimerIsActive(pDevIns, hTimer);
6344}
6345
6346/**
6347 * @copydoc PDMDEVHLPR3::pfnTimerIsLockOwner
6348 */
6349DECLINLINE(bool) PDMDevHlpTimerIsLockOwner(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6350{
6351 return pDevIns->CTX_SUFF(pHlp)->pfnTimerIsLockOwner(pDevIns, hTimer);
6352}
6353
6354/**
6355 * @copydoc PDMDEVHLPR3::pfnTimerLock
6356 */
6357DECLINLINE(int) PDMDevHlpTimerLock(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, int rcBusy)
6358{
6359 return pDevIns->CTX_SUFF(pHlp)->pfnTimerLock(pDevIns, hTimer, rcBusy);
6360}
6361
6362/**
6363 * @copydoc PDMDEVHLPR3::pfnTimerSet
6364 */
6365DECLINLINE(int) PDMDevHlpTimerSet(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t uExpire)
6366{
6367 return pDevIns->CTX_SUFF(pHlp)->pfnTimerSet(pDevIns, hTimer, uExpire);
6368}
6369
6370/**
6371 * @copydoc PDMDEVHLPR3::pfnTimerSetFrequencyHint
6372 */
6373DECLINLINE(int) PDMDevHlpTimerSetFrequencyHint(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint32_t uHz)
6374{
6375 return pDevIns->CTX_SUFF(pHlp)->pfnTimerSetFrequencyHint(pDevIns, hTimer, uHz);
6376}
6377
6378/**
6379 * @copydoc PDMDEVHLPR3::pfnTimerSetMicro
6380 */
6381DECLINLINE(int) PDMDevHlpTimerSetMicro(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext)
6382{
6383 return pDevIns->CTX_SUFF(pHlp)->pfnTimerSetMicro(pDevIns, hTimer, cMicrosToNext);
6384}
6385
6386/**
6387 * @copydoc PDMDEVHLPR3::pfnTimerSetMillies
6388 */
6389DECLINLINE(int) PDMDevHlpTimerSetMillies(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cMilliesToNext)
6390{
6391 return pDevIns->CTX_SUFF(pHlp)->pfnTimerSetMillies(pDevIns, hTimer, cMilliesToNext);
6392}
6393
6394/**
6395 * @copydoc PDMDEVHLPR3::pfnTimerSetNano
6396 */
6397DECLINLINE(int) PDMDevHlpTimerSetNano(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cNanosToNext)
6398{
6399 return pDevIns->CTX_SUFF(pHlp)->pfnTimerSetNano(pDevIns, hTimer, cNanosToNext);
6400}
6401
6402/**
6403 * @copydoc PDMDEVHLPR3::pfnTimerSetRelative
6404 */
6405DECLINLINE(int) PDMDevHlpTimerSetRelative(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now)
6406{
6407 return pDevIns->CTX_SUFF(pHlp)->pfnTimerSetRelative(pDevIns, hTimer, cTicksToNext, pu64Now);
6408}
6409
6410/**
6411 * @copydoc PDMDEVHLPR3::pfnTimerStop
6412 */
6413DECLINLINE(int) PDMDevHlpTimerStop(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6414{
6415 return pDevIns->CTX_SUFF(pHlp)->pfnTimerStop(pDevIns, hTimer);
6416}
6417
6418/**
6419 * @copydoc PDMDEVHLPR3::pfnTimerUnlock
6420 */
6421DECLINLINE(void) PDMDevHlpTimerUnlock(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6422{
6423 pDevIns->CTX_SUFF(pHlp)->pfnTimerUnlock(pDevIns, hTimer);
6424}
6425
6426#ifdef IN_RING3
6427
6428/**
6429 * @copydoc PDMDEVHLPR3::pfnTimerSetCritSect
6430 */
6431DECLINLINE(int) PDMDevHlpTimerSetCritSect(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect)
6432{
6433 return pDevIns->pHlpR3->pfnTimerSetCritSect(pDevIns, hTimer, pCritSect);
6434}
6435
6436/**
6437 * @copydoc PDMDEVHLPR3::pfnTimerSave
6438 */
6439DECLINLINE(int) PDMDevHlpTimerSave(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM)
6440{
6441 return pDevIns->pHlpR3->pfnTimerSave(pDevIns, hTimer, pSSM);
6442}
6443
6444/**
6445 * @copydoc PDMDEVHLPR3::pfnTimerLoad
6446 */
6447DECLINLINE(int) PDMDevHlpTimerLoad(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM)
6448{
6449 return pDevIns->pHlpR3->pfnTimerLoad(pDevIns, hTimer, pSSM);
6450}
6451
6452/**
6453 * @copydoc PDMDEVHLPR3::pfnTimerDestroy
6454 */
6455DECLINLINE(int) PDMDevHlpTimerDestroy(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer)
6456{
6457 return pDevIns->pHlpR3->pfnTimerDestroy(pDevIns, hTimer);
6458}
6459
6460/**
6461 * @copydoc PDMDEVHLPR3::pfnTMUtcNow
6462 */
6463DECLINLINE(PRTTIMESPEC) PDMDevHlpTMUtcNow(PPDMDEVINS pDevIns, PRTTIMESPEC pTime)
6464{
6465 return pDevIns->pHlpR3->pfnTMUtcNow(pDevIns, pTime);
6466}
6467
6468#endif
6469
6470/**
6471 * @copydoc PDMDEVHLPR3::pfnPhysRead
6472 */
6473DECLINLINE(int) PDMDevHlpPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
6474{
6475 return pDevIns->CTX_SUFF(pHlp)->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
6476}
6477
6478/**
6479 * @copydoc PDMDEVHLPR3::pfnPhysWrite
6480 */
6481DECLINLINE(int) PDMDevHlpPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
6482{
6483 return pDevIns->CTX_SUFF(pHlp)->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
6484}
6485
6486#ifdef IN_RING3
6487
6488/**
6489 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtr
6490 */
6491DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
6492{
6493 return pDevIns->CTX_SUFF(pHlp)->pfnPhysGCPhys2CCPtr(pDevIns, GCPhys, fFlags, ppv, pLock);
6494}
6495
6496/**
6497 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtrReadOnly
6498 */
6499DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv,
6500 PPGMPAGEMAPLOCK pLock)
6501{
6502 return pDevIns->CTX_SUFF(pHlp)->pfnPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhys, fFlags, ppv, pLock);
6503}
6504
6505/**
6506 * @copydoc PDMDEVHLPR3::pfnPhysReleasePageMappingLock
6507 */
6508DECLINLINE(void) PDMDevHlpPhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
6509{
6510 pDevIns->CTX_SUFF(pHlp)->pfnPhysReleasePageMappingLock(pDevIns, pLock);
6511}
6512
6513/**
6514 * @copydoc PDMDEVHLPR3::pfnPhysBulkGCPhys2CCPtr
6515 */
6516DECLINLINE(int) PDMDevHlpPhysBulkGCPhys2CCPtr(PPDMDEVINS pDevIns, uint32_t cPages, PCRTGCPHYS paGCPhysPages,
6517 uint32_t fFlags, void **papvPages, PPGMPAGEMAPLOCK paLocks)
6518{
6519 return pDevIns->CTX_SUFF(pHlp)->pfnPhysBulkGCPhys2CCPtr(pDevIns, cPages, paGCPhysPages, fFlags, papvPages, paLocks);
6520}
6521
6522/**
6523 * @copydoc PDMDEVHLPR3::pfnPhysBulkGCPhys2CCPtrReadOnly
6524 */
6525DECLINLINE(int) PDMDevHlpPhysBulkGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, uint32_t cPages, PCRTGCPHYS paGCPhysPages,
6526 uint32_t fFlags, void const **papvPages, PPGMPAGEMAPLOCK paLocks)
6527{
6528 return pDevIns->CTX_SUFF(pHlp)->pfnPhysBulkGCPhys2CCPtrReadOnly(pDevIns, cPages, paGCPhysPages, fFlags, papvPages, paLocks);
6529}
6530
6531/**
6532 * @copydoc PDMDEVHLPR3::pfnPhysBulkReleasePageMappingLocks
6533 */
6534DECLINLINE(void) PDMDevHlpPhysBulkReleasePageMappingLocks(PPDMDEVINS pDevIns, uint32_t cPages, PPGMPAGEMAPLOCK paLocks)
6535{
6536 pDevIns->CTX_SUFF(pHlp)->pfnPhysBulkReleasePageMappingLocks(pDevIns, cPages, paLocks);
6537}
6538
6539/**
6540 * @copydoc PDMDEVHLPR3::pfnPhysReadGCVirt
6541 */
6542DECLINLINE(int) PDMDevHlpPhysReadGCVirt(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb)
6543{
6544 return pDevIns->pHlpR3->pfnPhysReadGCVirt(pDevIns, pvDst, GCVirtSrc, cb);
6545}
6546
6547/**
6548 * @copydoc PDMDEVHLPR3::pfnPhysWriteGCVirt
6549 */
6550DECLINLINE(int) PDMDevHlpPhysWriteGCVirt(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb)
6551{
6552 return pDevIns->pHlpR3->pfnPhysWriteGCVirt(pDevIns, GCVirtDst, pvSrc, cb);
6553}
6554
6555/**
6556 * @copydoc PDMDEVHLPR3::pfnPhysGCPtr2GCPhys
6557 */
6558DECLINLINE(int) PDMDevHlpPhysGCPtr2GCPhys(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys)
6559{
6560 return pDevIns->pHlpR3->pfnPhysGCPtr2GCPhys(pDevIns, GCPtr, pGCPhys);
6561}
6562
6563/**
6564 * @copydoc PDMDEVHLPR3::pfnMMHeapAlloc
6565 */
6566DECLINLINE(void *) PDMDevHlpMMHeapAlloc(PPDMDEVINS pDevIns, size_t cb)
6567{
6568 return pDevIns->pHlpR3->pfnMMHeapAlloc(pDevIns, cb);
6569}
6570
6571/**
6572 * @copydoc PDMDEVHLPR3::pfnMMHeapAllocZ
6573 */
6574DECLINLINE(void *) PDMDevHlpMMHeapAllocZ(PPDMDEVINS pDevIns, size_t cb)
6575{
6576 return pDevIns->pHlpR3->pfnMMHeapAllocZ(pDevIns, cb);
6577}
6578
6579/**
6580 * @copydoc PDMDEVHLPR3::pfnMMHeapFree
6581 */
6582DECLINLINE(void) PDMDevHlpMMHeapFree(PPDMDEVINS pDevIns, void *pv)
6583{
6584 pDevIns->pHlpR3->pfnMMHeapFree(pDevIns, pv);
6585}
6586#endif /* IN_RING3 */
6587
6588/**
6589 * @copydoc PDMDEVHLPR3::pfnVMState
6590 */
6591DECLINLINE(VMSTATE) PDMDevHlpVMState(PPDMDEVINS pDevIns)
6592{
6593 return pDevIns->CTX_SUFF(pHlp)->pfnVMState(pDevIns);
6594}
6595
6596#ifdef IN_RING3
6597/**
6598 * @copydoc PDMDEVHLPR3::pfnVMTeleportedAndNotFullyResumedYet
6599 */
6600DECLINLINE(bool) PDMDevHlpVMTeleportedAndNotFullyResumedYet(PPDMDEVINS pDevIns)
6601{
6602 return pDevIns->pHlpR3->pfnVMTeleportedAndNotFullyResumedYet(pDevIns);
6603}
6604#endif /* IN_RING3 */
6605
6606/**
6607 * @copydoc PDMDEVHLPR3::pfnVMSetError
6608 */
6609DECLINLINE(int) RT_IPRT_FORMAT_ATTR(6, 7) PDMDevHlpVMSetError(PPDMDEVINS pDevIns, const int rc, RT_SRC_POS_DECL,
6610 const char *pszFormat, ...)
6611{
6612 va_list va;
6613 va_start(va, pszFormat);
6614 pDevIns->CTX_SUFF(pHlp)->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
6615 va_end(va);
6616 return rc;
6617}
6618
6619/**
6620 * @copydoc PDMDEVHLPR3::pfnVMSetRuntimeError
6621 */
6622DECLINLINE(int) RT_IPRT_FORMAT_ATTR(4, 5) PDMDevHlpVMSetRuntimeError(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
6623 const char *pszFormat, ...)
6624{
6625 va_list va;
6626 int rc;
6627 va_start(va, pszFormat);
6628 rc = pDevIns->CTX_SUFF(pHlp)->pfnVMSetRuntimeErrorV(pDevIns, fFlags, pszErrorId, pszFormat, va);
6629 va_end(va);
6630 return rc;
6631}
6632
6633/**
6634 * VBOX_STRICT wrapper for pHlp->pfnDBGFStopV.
6635 *
6636 * @returns VBox status code which must be passed up to the VMM. This will be
6637 * VINF_SUCCESS in non-strict builds.
6638 * @param pDevIns The device instance.
6639 * @param SRC_POS Use RT_SRC_POS.
6640 * @param pszFormat Message. (optional)
6641 * @param ... Message parameters.
6642 */
6643DECLINLINE(int) RT_IPRT_FORMAT_ATTR(5, 6) PDMDevHlpDBGFStop(PPDMDEVINS pDevIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
6644{
6645#ifdef VBOX_STRICT
6646# ifdef IN_RING3
6647 int rc;
6648 va_list args;
6649 va_start(args, pszFormat);
6650 rc = pDevIns->pHlpR3->pfnDBGFStopV(pDevIns, RT_SRC_POS_ARGS, pszFormat, args);
6651 va_end(args);
6652 return rc;
6653# else
6654 NOREF(pDevIns);
6655 NOREF(pszFile);
6656 NOREF(iLine);
6657 NOREF(pszFunction);
6658 NOREF(pszFormat);
6659 return VINF_EM_DBG_STOP;
6660# endif
6661#else
6662 NOREF(pDevIns);
6663 NOREF(pszFile);
6664 NOREF(iLine);
6665 NOREF(pszFunction);
6666 NOREF(pszFormat);
6667 return VINF_SUCCESS;
6668#endif
6669}
6670
6671#ifdef IN_RING3
6672
6673/**
6674 * @copydoc PDMDEVHLPR3::pfnDBGFInfoRegister
6675 */
6676DECLINLINE(int) PDMDevHlpDBGFInfoRegister(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler)
6677{
6678 return pDevIns->pHlpR3->pfnDBGFInfoRegister(pDevIns, pszName, pszDesc, pfnHandler);
6679}
6680
6681/**
6682 * @copydoc PDMDEVHLPR3::pfnDBGFInfoRegisterArgv
6683 */
6684DECLINLINE(int) PDMDevHlpDBGFInfoRegisterArgv(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVDEV pfnHandler)
6685{
6686 return pDevIns->pHlpR3->pfnDBGFInfoRegisterArgv(pDevIns, pszName, pszDesc, pfnHandler);
6687}
6688
6689/**
6690 * @copydoc PDMDEVHLPR3::pfnDBGFRegRegister
6691 */
6692DECLINLINE(int) PDMDevHlpDBGFRegRegister(PPDMDEVINS pDevIns, PCDBGFREGDESC paRegisters)
6693{
6694 return pDevIns->pHlpR3->pfnDBGFRegRegister(pDevIns, paRegisters);
6695}
6696
6697/**
6698 * @copydoc PDMDEVHLPR3::pfnSTAMRegister
6699 */
6700DECLINLINE(void) PDMDevHlpSTAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
6701{
6702 pDevIns->pHlpR3->pfnSTAMRegister(pDevIns, pvSample, enmType, pszName, enmUnit, pszDesc);
6703}
6704
6705/**
6706 * Same as pfnSTAMRegister except that the name is specified in a
6707 * RTStrPrintf like fashion.
6708 *
6709 * @returns VBox status.
6710 * @param pDevIns Device instance of the DMA.
6711 * @param pvSample Pointer to the sample.
6712 * @param enmType Sample type. This indicates what pvSample is
6713 * pointing at.
6714 * @param enmVisibility Visibility type specifying whether unused
6715 * statistics should be visible or not.
6716 * @param enmUnit Sample unit.
6717 * @param pszDesc Sample description.
6718 * @param pszName Sample name format string, unix path style. If
6719 * this does not start with a '/', the default
6720 * prefix will be prepended, otherwise it will be
6721 * used as-is.
6722 * @param ... Arguments to the format string.
6723 */
6724DECLINLINE(void) RT_IPRT_FORMAT_ATTR(7, 8) PDMDevHlpSTAMRegisterF(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType,
6725 STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
6726 const char *pszDesc, const char *pszName, ...)
6727{
6728 va_list va;
6729 va_start(va, pszName);
6730 pDevIns->pHlpR3->pfnSTAMRegisterV(pDevIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
6731 va_end(va);
6732}
6733
6734/**
6735 * Registers the device with the default PCI bus.
6736 *
6737 * @returns VBox status code.
6738 * @param pDevIns The device instance.
6739 * @param pPciDev The PCI device structure.
6740 * This must be kept in the instance data.
6741 * The PCI configuration must be initialized before registration.
6742 */
6743DECLINLINE(int) PDMDevHlpPCIRegister(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev)
6744{
6745 return pDevIns->pHlpR3->pfnPCIRegister(pDevIns, pPciDev, 0 /*fFlags*/,
6746 PDMPCIDEVREG_DEV_NO_FIRST_UNUSED, PDMPCIDEVREG_FUN_NO_FIRST_UNUSED, NULL);
6747}
6748
6749/**
6750 * @copydoc PDMDEVHLPR3::pfnPCIRegister
6751 */
6752DECLINLINE(int) PDMDevHlpPCIRegisterEx(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t fFlags,
6753 uint8_t uPciDevNo, uint8_t uPciFunNo, const char *pszName)
6754{
6755 return pDevIns->pHlpR3->pfnPCIRegister(pDevIns, pPciDev, fFlags, uPciDevNo, uPciFunNo, pszName);
6756}
6757
6758/**
6759 * Initialize MSI emulation support for the first PCI device.
6760 *
6761 * @returns VBox status code.
6762 * @param pDevIns The device instance.
6763 * @param pMsiReg MSI emulation registration structure.
6764 */
6765DECLINLINE(int) PDMDevHlpPCIRegisterMsi(PPDMDEVINS pDevIns, PPDMMSIREG pMsiReg)
6766{
6767 return pDevIns->pHlpR3->pfnPCIRegisterMsi(pDevIns, NULL, pMsiReg);
6768}
6769
6770/**
6771 * @copydoc PDMDEVHLPR3::pfnPCIRegisterMsi
6772 */
6773DECLINLINE(int) PDMDevHlpPCIRegisterMsiEx(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, PPDMMSIREG pMsiReg)
6774{
6775 return pDevIns->pHlpR3->pfnPCIRegisterMsi(pDevIns, pPciDev, pMsiReg);
6776}
6777
6778/**
6779 * Registers a I/O region (memory mapped or I/O ports) for the default PCI
6780 * device.
6781 *
6782 * @returns VBox status code.
6783 * @param pDevIns The device instance.
6784 * @param iRegion The region number.
6785 * @param cbRegion Size of the region.
6786 * @param enmType PCI_ADDRESS_SPACE_MEM, PCI_ADDRESS_SPACE_IO or PCI_ADDRESS_SPACE_MEM_PREFETCH.
6787 * @param pfnMapUnmap Callback for doing the mapping.
6788 * @remarks The callback will be invoked holding the PDM lock. The device lock
6789 * is NOT take because that is very likely be a lock order violation.
6790 * @remarks Old callback style, won't get unmap calls.
6791 */
6792DECLINLINE(int) PDMDevHlpPCIIORegionRegister(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cbRegion,
6793 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnMapUnmap)
6794{
6795 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, NULL, iRegion, cbRegion, enmType,
6796 PDMPCIDEV_IORGN_F_NO_HANDLE, UINT64_MAX, pfnMapUnmap);
6797}
6798
6799/**
6800 * @sa PDMDEVHLPR3::pfnPCIIORegionRegister
6801 * @remarks Old callback style, won't get unmap calls.
6802 */
6803DECLINLINE(int) PDMDevHlpPCIIORegionRegisterEx(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion, RTGCPHYS cbRegion,
6804 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnMapUnmap)
6805{
6806 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, pPciDev, iRegion, cbRegion, enmType,
6807 PDMPCIDEV_IORGN_F_NO_HANDLE, UINT64_MAX, pfnMapUnmap);
6808}
6809
6810/**
6811 * Registers a I/O port region for the default PCI device.
6812 *
6813 * @returns VBox status code.
6814 * @param pDevIns The device instance.
6815 * @param iRegion The region number.
6816 * @param cbRegion Size of the region.
6817 * @param hIoPorts Handle to the I/O port region.
6818 */
6819DECLINLINE(int) PDMDevHlpPCIIORegionRegisterIo(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cbRegion, IOMIOPORTHANDLE hIoPorts)
6820{
6821 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, NULL, iRegion, cbRegion, PCI_ADDRESS_SPACE_IO,
6822 PDMPCIDEV_IORGN_F_IOPORT_HANDLE | PDMPCIDEV_IORGN_F_NEW_STYLE, hIoPorts, NULL);
6823}
6824
6825/**
6826 * Registers a I/O port region for the default PCI device, custom map/unmap.
6827 *
6828 * @returns VBox status code.
6829 * @param pDevIns The device instance.
6830 * @param iRegion The region number.
6831 * @param cbRegion Size of the region.
6832 * @param pfnMapUnmap Callback for doing the mapping, optional. The
6833 * callback will be invoked holding only the PDM lock.
6834 * The device lock will _not_ be taken (due to lock
6835 * order).
6836 */
6837DECLINLINE(int) PDMDevHlpPCIIORegionRegisterIoCustom(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cbRegion,
6838 PFNPCIIOREGIONMAP pfnMapUnmap)
6839{
6840 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, NULL, iRegion, cbRegion, PCI_ADDRESS_SPACE_IO,
6841 PDMPCIDEV_IORGN_F_NO_HANDLE | PDMPCIDEV_IORGN_F_NEW_STYLE,
6842 UINT64_MAX, pfnMapUnmap);
6843}
6844
6845/**
6846 * Combines PDMDevHlpIoPortCreate and PDMDevHlpPCIIORegionRegisterIo, creating
6847 * and registering an I/O port region for the default PCI device.
6848 *
6849 * @returns VBox status code.
6850 * @param pDevIns The device instance to register the ports with.
6851 * @param cPorts The count of I/O ports in the region (the size).
6852 * @param iPciRegion The PCI device region.
6853 * @param pfnOut Pointer to function which is gonna handle OUT
6854 * operations. Optional.
6855 * @param pfnIn Pointer to function which is gonna handle IN operations.
6856 * Optional.
6857 * @param pvUser User argument to pass to the callbacks.
6858 * @param pszDesc Pointer to description string. This must not be freed.
6859 * @param paExtDescs Extended per-port descriptions, optional. Partial range
6860 * coverage is allowed. This must not be freed.
6861 * @param phIoPorts Where to return the I/O port range handle.
6862 *
6863 */
6864DECLINLINE(int) PDMDevHlpPCIIORegionCreateIo(PPDMDEVINS pDevIns, uint32_t iPciRegion, RTIOPORT cPorts,
6865 PFNIOMIOPORTNEWOUT pfnOut, PFNIOMIOPORTNEWIN pfnIn, void *pvUser,
6866 const char *pszDesc, PCIOMIOPORTDESC paExtDescs, PIOMIOPORTHANDLE phIoPorts)
6867
6868{
6869 int rc = pDevIns->pHlpR3->pfnIoPortCreateEx(pDevIns, cPorts, 0 /*fFlags*/, pDevIns->apPciDevs[0], iPciRegion << 16,
6870 pfnOut, pfnIn, NULL, NULL, pvUser, pszDesc, paExtDescs, phIoPorts);
6871 if (RT_SUCCESS(rc))
6872 rc = pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, pDevIns->apPciDevs[0], iPciRegion, cPorts, PCI_ADDRESS_SPACE_IO,
6873 PDMPCIDEV_IORGN_F_IOPORT_HANDLE | PDMPCIDEV_IORGN_F_NEW_STYLE,
6874 *phIoPorts, NULL /*pfnMapUnmap*/);
6875 return rc;
6876}
6877
6878/**
6879 * Registers an MMIO region for the default PCI device.
6880 *
6881 * @returns VBox status code.
6882 * @param pDevIns The device instance.
6883 * @param iRegion The region number.
6884 * @param cbRegion Size of the region.
6885 * @param enmType PCI_ADDRESS_SPACE_MEM or
6886 * PCI_ADDRESS_SPACE_MEM_PREFETCH, optionally or-ing in
6887 * PCI_ADDRESS_SPACE_BAR64 or PCI_ADDRESS_SPACE_BAR32.
6888 * @param hMmioRegion Handle to the MMIO region.
6889 * @param pfnMapUnmap Callback for doing the mapping, optional. The
6890 * callback will be invoked holding only the PDM lock.
6891 * The device lock will _not_ be taken (due to lock
6892 * order).
6893 */
6894DECLINLINE(int) PDMDevHlpPCIIORegionRegisterMmio(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cbRegion, PCIADDRESSSPACE enmType,
6895 IOMMMIOHANDLE hMmioRegion, PFNPCIIOREGIONMAP pfnMapUnmap)
6896{
6897 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, NULL, iRegion, cbRegion, enmType,
6898 PDMPCIDEV_IORGN_F_MMIO_HANDLE | PDMPCIDEV_IORGN_F_NEW_STYLE,
6899 hMmioRegion, pfnMapUnmap);
6900}
6901
6902/**
6903 * Registers an MMIO region for the default PCI device, extended version.
6904 *
6905 * @returns VBox status code.
6906 * @param pDevIns The device instance.
6907 * @param pPciDev The PCI device structure.
6908 * @param iRegion The region number.
6909 * @param cbRegion Size of the region.
6910 * @param enmType PCI_ADDRESS_SPACE_MEM or
6911 * PCI_ADDRESS_SPACE_MEM_PREFETCH, optionally or-ing in
6912 * PCI_ADDRESS_SPACE_BAR64 or PCI_ADDRESS_SPACE_BAR32.
6913 * @param hMmioRegion Handle to the MMIO region.
6914 * @param pfnMapUnmap Callback for doing the mapping, optional. The
6915 * callback will be invoked holding only the PDM lock.
6916 * The device lock will _not_ be taken (due to lock
6917 * order).
6918 */
6919DECLINLINE(int) PDMDevHlpPCIIORegionRegisterMmioEx(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
6920 RTGCPHYS cbRegion, PCIADDRESSSPACE enmType, IOMMMIOHANDLE hMmioRegion,
6921 PFNPCIIOREGIONMAP pfnMapUnmap)
6922{
6923 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, pPciDev, iRegion, cbRegion, enmType,
6924 PDMPCIDEV_IORGN_F_MMIO_HANDLE | PDMPCIDEV_IORGN_F_NEW_STYLE,
6925 hMmioRegion, pfnMapUnmap);
6926}
6927
6928/**
6929 * Combines PDMDevHlpMmioCreate and PDMDevHlpPCIIORegionRegisterMmio, creating
6930 * and registering an MMIO region for the default PCI device.
6931 *
6932 * @returns VBox status code.
6933 * @param pDevIns The device instance to register the ports with.
6934 * @param cbRegion The size of the region in bytes.
6935 * @param iPciRegion The PCI device region.
6936 * @param enmType PCI_ADDRESS_SPACE_MEM or
6937 * PCI_ADDRESS_SPACE_MEM_PREFETCH, optionally or-ing in
6938 * PCI_ADDRESS_SPACE_BAR64 or PCI_ADDRESS_SPACE_BAR32.
6939 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
6940 * @param pfnWrite Pointer to function which is gonna handle Write
6941 * operations.
6942 * @param pfnRead Pointer to function which is gonna handle Read
6943 * operations.
6944 * @param pvUser User argument to pass to the callbacks.
6945 * @param pszDesc Pointer to description string. This must not be freed.
6946 * @param phRegion Where to return the MMIO region handle.
6947 *
6948 */
6949DECLINLINE(int) PDMDevHlpPCIIORegionCreateMmio(PPDMDEVINS pDevIns, uint32_t iPciRegion, RTGCPHYS cbRegion, PCIADDRESSSPACE enmType,
6950 PFNIOMMMIONEWWRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead, void *pvUser,
6951 uint32_t fFlags, const char *pszDesc, PIOMMMIOHANDLE phRegion)
6952
6953{
6954 int rc = pDevIns->pHlpR3->pfnMmioCreateEx(pDevIns, cbRegion, fFlags, pDevIns->apPciDevs[0], iPciRegion << 16,
6955 pfnWrite, pfnRead, NULL /*pfnFill*/, pvUser, pszDesc, phRegion);
6956 if (RT_SUCCESS(rc))
6957 rc = pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, pDevIns->apPciDevs[0], iPciRegion, cbRegion, enmType,
6958 PDMPCIDEV_IORGN_F_MMIO_HANDLE | PDMPCIDEV_IORGN_F_NEW_STYLE,
6959 *phRegion, NULL /*pfnMapUnmap*/);
6960 return rc;
6961}
6962
6963
6964/**
6965 * Registers an MMIO2 region for the default PCI device.
6966 *
6967 * @returns VBox status code.
6968 * @param pDevIns The device instance.
6969 * @param iRegion The region number.
6970 * @param cbRegion Size of the region.
6971 * @param enmType PCI_ADDRESS_SPACE_MEM or
6972 * PCI_ADDRESS_SPACE_MEM_PREFETCH, optionally or-ing in
6973 * PCI_ADDRESS_SPACE_BAR64 or PCI_ADDRESS_SPACE_BAR32.
6974 * @param hMmio2Region Handle to the MMIO2 region.
6975 */
6976DECLINLINE(int) PDMDevHlpPCIIORegionRegisterMmio2(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cbRegion,
6977 PCIADDRESSSPACE enmType, PGMMMIO2HANDLE hMmio2Region)
6978{
6979 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, NULL, iRegion, cbRegion, enmType,
6980 PDMPCIDEV_IORGN_F_MMIO2_HANDLE | PDMPCIDEV_IORGN_F_NEW_STYLE,
6981 hMmio2Region, NULL);
6982}
6983
6984/**
6985 * Combines PDMDevHlpMmio2Create and PDMDevHlpPCIIORegionRegisterMmio2, creating
6986 * and registering an MMIO2 region for the default PCI device, extended edition.
6987 *
6988 * @returns VBox status code.
6989 * @param pDevIns The device instance to register the ports with.
6990 * @param cbRegion The size of the region in bytes.
6991 * @param iPciRegion The PCI device region.
6992 * @param enmType PCI_ADDRESS_SPACE_MEM or
6993 * PCI_ADDRESS_SPACE_MEM_PREFETCH, optionally or-ing in
6994 * PCI_ADDRESS_SPACE_BAR64 or PCI_ADDRESS_SPACE_BAR32.
6995 * @param pszDesc Pointer to description string. This must not be freed.
6996 * @param ppvMapping Where to store the address of the ring-3 mapping of
6997 * the memory.
6998 * @param phRegion Where to return the MMIO2 region handle.
6999 *
7000 */
7001DECLINLINE(int) PDMDevHlpPCIIORegionCreateMmio2(PPDMDEVINS pDevIns, uint32_t iPciRegion, RTGCPHYS cbRegion,
7002 PCIADDRESSSPACE enmType, const char *pszDesc,
7003 void **ppvMapping, PPGMMMIO2HANDLE phRegion)
7004
7005{
7006 int rc = pDevIns->pHlpR3->pfnMmio2Create(pDevIns, pDevIns->apPciDevs[0], iPciRegion << 16, cbRegion, 0 /*fFlags*/,
7007 pszDesc, ppvMapping, phRegion);
7008 if (RT_SUCCESS(rc))
7009 rc = pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, pDevIns->apPciDevs[0], iPciRegion, cbRegion, enmType,
7010 PDMPCIDEV_IORGN_F_MMIO2_HANDLE, *phRegion, NULL /*pfnCallback*/);
7011 return rc;
7012}
7013
7014/**
7015 * Combines PDMDevHlpMmio2Create and PDMDevHlpPCIIORegionRegisterMmio2, creating
7016 * and registering an MMIO2 region for the default PCI device.
7017 *
7018 * @returns VBox status code.
7019 * @param pDevIns The device instance to register the ports with.
7020 * @param cbRegion The size of the region in bytes.
7021 * @param iPciRegion The PCI device region.
7022 * @param enmType PCI_ADDRESS_SPACE_MEM or
7023 * PCI_ADDRESS_SPACE_MEM_PREFETCH, optionally or-ing in
7024 * PCI_ADDRESS_SPACE_BAR64 or PCI_ADDRESS_SPACE_BAR32.
7025 * @param fMmio2Flags To be defined, must be zero.
7026 * @param pfnMapUnmap Callback for doing the mapping, optional. The
7027 * callback will be invoked holding only the PDM lock.
7028 * The device lock will _not_ be taken (due to lock
7029 * order).
7030 * @param pszDesc Pointer to description string. This must not be freed.
7031 * @param ppvMapping Where to store the address of the ring-3 mapping of
7032 * the memory.
7033 * @param phRegion Where to return the MMIO2 region handle.
7034 *
7035 */
7036DECLINLINE(int) PDMDevHlpPCIIORegionCreateMmio2Ex(PPDMDEVINS pDevIns, uint32_t iPciRegion, RTGCPHYS cbRegion,
7037 PCIADDRESSSPACE enmType, uint32_t fMmio2Flags, PFNPCIIOREGIONMAP pfnMapUnmap,
7038 const char *pszDesc, void **ppvMapping, PPGMMMIO2HANDLE phRegion)
7039
7040{
7041 int rc = pDevIns->pHlpR3->pfnMmio2Create(pDevIns, pDevIns->apPciDevs[0], iPciRegion << 16, cbRegion, fMmio2Flags,
7042 pszDesc, ppvMapping, phRegion);
7043 if (RT_SUCCESS(rc))
7044 rc = pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, pDevIns->apPciDevs[0], iPciRegion, cbRegion, enmType,
7045 PDMPCIDEV_IORGN_F_MMIO2_HANDLE, *phRegion, pfnMapUnmap);
7046 return rc;
7047}
7048
7049/**
7050 * @copydoc PDMDEVHLPR3::pfnPCIInterceptConfigAccesses
7051 */
7052DECLINLINE(int) PDMDevHlpPCIInterceptConfigAccesses(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev,
7053 PFNPCICONFIGREAD pfnRead, PFNPCICONFIGWRITE pfnWrite)
7054{
7055 return pDevIns->pHlpR3->pfnPCIInterceptConfigAccesses(pDevIns, pPciDev, pfnRead, pfnWrite);
7056}
7057
7058/**
7059 * @copydoc PDMDEVHLPR3::pfnPCIConfigRead
7060 */
7061DECLINLINE(VBOXSTRICTRC) PDMDevHlpPCIConfigRead(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress,
7062 unsigned cb, uint32_t *pu32Value)
7063{
7064 return pDevIns->pHlpR3->pfnPCIConfigRead(pDevIns, pPciDev, uAddress, cb, pu32Value);
7065}
7066
7067/**
7068 * @copydoc PDMDEVHLPR3::pfnPCIConfigWrite
7069 */
7070DECLINLINE(VBOXSTRICTRC) PDMDevHlpPCIConfigWrite(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t uAddress,
7071 unsigned cb, uint32_t u32Value)
7072{
7073 return pDevIns->pHlpR3->pfnPCIConfigWrite(pDevIns, pPciDev, uAddress, cb, u32Value);
7074}
7075
7076#endif /* IN_RING3 */
7077
7078/**
7079 * Bus master physical memory read from the default PCI device.
7080 *
7081 * @returns VINF_SUCCESS or VERR_PGM_PCI_PHYS_READ_BM_DISABLED, later maybe
7082 * VERR_EM_MEMORY. The informational status shall NOT be propagated!
7083 * @param pDevIns The device instance.
7084 * @param GCPhys Physical address start reading from.
7085 * @param pvBuf Where to put the read bits.
7086 * @param cbRead How many bytes to read.
7087 * @thread Any thread, but the call may involve the emulation thread.
7088 */
7089DECLINLINE(int) PDMDevHlpPCIPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
7090{
7091 return pDevIns->CTX_SUFF(pHlp)->pfnPCIPhysRead(pDevIns, NULL, GCPhys, pvBuf, cbRead);
7092}
7093
7094/**
7095 * @copydoc PDMDEVHLPR3::pfnPCIPhysRead
7096 */
7097DECLINLINE(int) PDMDevHlpPCIPhysReadEx(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
7098{
7099 return pDevIns->CTX_SUFF(pHlp)->pfnPCIPhysRead(pDevIns, pPciDev, GCPhys, pvBuf, cbRead);
7100}
7101
7102/**
7103 * Bus master physical memory write from the default PCI device.
7104 *
7105 * @returns VINF_SUCCESS or VERR_PGM_PCI_PHYS_WRITE_BM_DISABLED, later maybe
7106 * VERR_EM_MEMORY. The informational status shall NOT be propagated!
7107 * @param pDevIns The device instance.
7108 * @param GCPhys Physical address to write to.
7109 * @param pvBuf What to write.
7110 * @param cbWrite How many bytes to write.
7111 * @thread Any thread, but the call may involve the emulation thread.
7112 */
7113DECLINLINE(int) PDMDevHlpPCIPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
7114{
7115 return pDevIns->CTX_SUFF(pHlp)->pfnPCIPhysWrite(pDevIns, NULL, GCPhys, pvBuf, cbWrite);
7116}
7117
7118/**
7119 * @copydoc PDMDEVHLPR3::pfnPCIPhysWrite
7120 */
7121DECLINLINE(int) PDMDevHlpPCIPhysWriteEx(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
7122{
7123 return pDevIns->CTX_SUFF(pHlp)->pfnPCIPhysWrite(pDevIns, pPciDev, GCPhys, pvBuf, cbWrite);
7124}
7125
7126/**
7127 * Sets the IRQ for the default PCI device.
7128 *
7129 * @param pDevIns The device instance.
7130 * @param iIrq IRQ number to set.
7131 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
7132 * @thread Any thread, but will involve the emulation thread.
7133 */
7134DECLINLINE(void) PDMDevHlpPCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
7135{
7136 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, NULL, iIrq, iLevel);
7137}
7138
7139/**
7140 * @copydoc PDMDEVHLPR3::pfnPCISetIrq
7141 */
7142DECLINLINE(void) PDMDevHlpPCISetIrqEx(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel)
7143{
7144 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, pPciDev, iIrq, iLevel);
7145}
7146
7147/**
7148 * Sets the IRQ for the given PCI device, but doesn't wait for EMT to process
7149 * the request when not called from EMT.
7150 *
7151 * @param pDevIns The device instance.
7152 * @param iIrq IRQ number to set.
7153 * @param iLevel IRQ level.
7154 * @thread Any thread, but will involve the emulation thread.
7155 */
7156DECLINLINE(void) PDMDevHlpPCISetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
7157{
7158 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, NULL, iIrq, iLevel);
7159}
7160
7161/**
7162 * @copydoc PDMDEVHLPR3::pfnPCISetIrqNoWait
7163 */
7164DECLINLINE(void) PDMDevHlpPCISetIrqNoWaitEx(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, int iIrq, int iLevel)
7165{
7166 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, pPciDev, iIrq, iLevel);
7167}
7168
7169/**
7170 * @copydoc PDMDEVHLPR3::pfnISASetIrq
7171 */
7172DECLINLINE(void) PDMDevHlpISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
7173{
7174 pDevIns->CTX_SUFF(pHlp)->pfnISASetIrq(pDevIns, iIrq, iLevel);
7175}
7176
7177/**
7178 * @copydoc PDMDEVHLPR3::pfnISASetIrqNoWait
7179 */
7180DECLINLINE(void) PDMDevHlpISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
7181{
7182 pDevIns->CTX_SUFF(pHlp)->pfnISASetIrq(pDevIns, iIrq, iLevel);
7183}
7184
7185/**
7186 * @copydoc PDMDEVHLPR3::pfnIoApicSendMsi
7187 */
7188DECLINLINE(void) PDMDevHlpIoApicSendMsi(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue)
7189{
7190 pDevIns->CTX_SUFF(pHlp)->pfnIoApicSendMsi(pDevIns, GCPhys, uValue);
7191}
7192
7193#ifdef IN_RING3
7194
7195/**
7196 * @copydoc PDMDEVHLPR3::pfnDriverAttach
7197 */
7198DECLINLINE(int) PDMDevHlpDriverAttach(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
7199{
7200 return pDevIns->pHlpR3->pfnDriverAttach(pDevIns, iLun, pBaseInterface, ppBaseInterface, pszDesc);
7201}
7202
7203/**
7204 * @copydoc PDMDEVHLPR3::pfnDriverDetach
7205 */
7206DECLINLINE(int) PDMDevHlpDriverDetach(PPDMDEVINS pDevIns, PPDMDRVINS pDrvIns, uint32_t fFlags)
7207{
7208 return pDevIns->pHlpR3->pfnDriverDetach(pDevIns, pDrvIns, fFlags);
7209}
7210
7211/**
7212 * @copydoc PDMDEVHLPR3::pfnQueueCreatePtr
7213 */
7214DECLINLINE(int) PDMDevHlpQueueCreate(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
7215 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName, PPDMQUEUE *ppQueue)
7216{
7217 return pDevIns->pHlpR3->pfnQueueCreatePtr(pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, ppQueue);
7218}
7219
7220/**
7221 * @copydoc PDMDEVHLPR3::pfnQueueCreate
7222 */
7223DECLINLINE(int) PDMDevHlpQueueCreateNew(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
7224 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName, PDMQUEUEHANDLE *phQueue)
7225{
7226 return pDevIns->pHlpR3->pfnQueueCreate(pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, phQueue);
7227}
7228
7229#endif /* IN_RING3 */
7230
7231/**
7232 * @copydoc PDMDEVHLPR3::pfnQueueAlloc
7233 */
7234DECLINLINE(PPDMQUEUEITEMCORE) PDMDevHlpQueueAlloc(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue)
7235{
7236 return pDevIns->CTX_SUFF(pHlp)->pfnQueueAlloc(pDevIns, hQueue);
7237}
7238
7239/**
7240 * @copydoc PDMDEVHLPR3::pfnQueueInsert
7241 */
7242DECLINLINE(void) PDMDevHlpQueueInsert(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue, PPDMQUEUEITEMCORE pItem)
7243{
7244 pDevIns->CTX_SUFF(pHlp)->pfnQueueInsert(pDevIns, hQueue, pItem);
7245}
7246
7247/**
7248 * @copydoc PDMDEVHLPR3::pfnQueueInsertEx
7249 */
7250DECLINLINE(void) PDMDevHlpQueueInsertEx(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue, PPDMQUEUEITEMCORE pItem, uint64_t cNanoMaxDelay)
7251{
7252 pDevIns->CTX_SUFF(pHlp)->pfnQueueInsertEx(pDevIns, hQueue, pItem, cNanoMaxDelay);
7253}
7254
7255/**
7256 * @copydoc PDMDEVHLPR3::pfnQueueFlushIfNecessary
7257 */
7258DECLINLINE(bool) PDMDevHlpQueueFlushIfNecessary(PPDMDEVINS pDevIns, PDMQUEUEHANDLE hQueue)
7259{
7260 return pDevIns->CTX_SUFF(pHlp)->pfnQueueFlushIfNecessary(pDevIns, hQueue);
7261}
7262
7263#ifdef IN_RING3
7264/**
7265 * @copydoc PDMDEVHLPR3::pfnTaskCreate
7266 */
7267DECLINLINE(int) PDMDevHlpTaskCreate(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszName,
7268 PFNPDMTASKDEV pfnCallback, void *pvUser, PDMTASKHANDLE *phTask)
7269{
7270 return pDevIns->pHlpR3->pfnTaskCreate(pDevIns, fFlags, pszName, pfnCallback, pvUser, phTask);
7271}
7272#endif
7273
7274/**
7275 * @copydoc PDMDEVHLPR3::pfnTaskTrigger
7276 */
7277DECLINLINE(int) PDMDevHlpTaskTrigger(PPDMDEVINS pDevIns, PDMTASKHANDLE hTask)
7278{
7279 return pDevIns->CTX_SUFF(pHlp)->pfnTaskTrigger(pDevIns, hTask);
7280}
7281
7282#ifdef IN_RING3
7283
7284/**
7285 * @copydoc PDMDEVHLPR3::pfnSUPSemEventCreate
7286 */
7287DECLINLINE(int) PDMDevHlpSUPSemEventCreate(PPDMDEVINS pDevIns, PSUPSEMEVENT phEvent)
7288{
7289 return pDevIns->pHlpR3->pfnSUPSemEventCreate(pDevIns, phEvent);
7290}
7291
7292/**
7293 * @copydoc PDMDEVHLPR3::pfnSUPSemEventClose
7294 */
7295DECLINLINE(int) PDMDevHlpSUPSemEventClose(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent)
7296{
7297 return pDevIns->pHlpR3->pfnSUPSemEventClose(pDevIns, hEvent);
7298}
7299
7300#endif /* IN_RING3 */
7301
7302/**
7303 * @copydoc PDMDEVHLPR3::pfnSUPSemEventSignal
7304 */
7305DECLINLINE(int) PDMDevHlpSUPSemEventSignal(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent)
7306{
7307 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventSignal(pDevIns, hEvent);
7308}
7309
7310/**
7311 * @copydoc PDMDEVHLPR3::pfnSUPSemEventWaitNoResume
7312 */
7313DECLINLINE(int) PDMDevHlpSUPSemEventWaitNoResume(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint32_t cMillies)
7314{
7315 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventWaitNoResume(pDevIns, hEvent, cMillies);
7316}
7317
7318/**
7319 * @copydoc PDMDEVHLPR3::pfnSUPSemEventWaitNsAbsIntr
7320 */
7321DECLINLINE(int) PDMDevHlpSUPSemEventWaitNsAbsIntr(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint64_t uNsTimeout)
7322{
7323 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventWaitNsAbsIntr(pDevIns, hEvent, uNsTimeout);
7324}
7325
7326/**
7327 * @copydoc PDMDEVHLPR3::pfnSUPSemEventWaitNsRelIntr
7328 */
7329DECLINLINE(int) PDMDevHlpSUPSemEventWaitNsRelIntr(PPDMDEVINS pDevIns, SUPSEMEVENT hEvent, uint64_t cNsTimeout)
7330{
7331 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventWaitNsRelIntr(pDevIns, hEvent, cNsTimeout);
7332}
7333
7334/**
7335 * @copydoc PDMDEVHLPR3::pfnSUPSemEventGetResolution
7336 */
7337DECLINLINE(uint32_t) PDMDevHlpSUPSemEventGetResolution(PPDMDEVINS pDevIns)
7338{
7339 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventGetResolution(pDevIns);
7340}
7341
7342#ifdef IN_RING3
7343
7344/**
7345 * @copydoc PDMDEVHLPR3::pfnSUPSemEventMultiCreate
7346 */
7347DECLINLINE(int) PDMDevHlpSUPSemEventMultiCreate(PPDMDEVINS pDevIns, PSUPSEMEVENTMULTI phEventMulti)
7348{
7349 return pDevIns->pHlpR3->pfnSUPSemEventMultiCreate(pDevIns, phEventMulti);
7350}
7351
7352/**
7353 * @copydoc PDMDEVHLPR3::pfnSUPSemEventMultiClose
7354 */
7355DECLINLINE(int) PDMDevHlpSUPSemEventMultiClose(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti)
7356{
7357 return pDevIns->pHlpR3->pfnSUPSemEventMultiClose(pDevIns, hEventMulti);
7358}
7359
7360#endif /* IN_RING3 */
7361
7362/**
7363 * @copydoc PDMDEVHLPR3::pfnSUPSemEventMultiSignal
7364 */
7365DECLINLINE(int) PDMDevHlpSUPSemEventMultiSignal(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti)
7366{
7367 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventMultiSignal(pDevIns, hEventMulti);
7368}
7369
7370/**
7371 * @copydoc PDMDEVHLPR3::pfnSUPSemEventMultiReset
7372 */
7373DECLINLINE(int) PDMDevHlpSUPSemEventMultiReset(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti)
7374{
7375 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventMultiReset(pDevIns, hEventMulti);
7376}
7377
7378/**
7379 * @copydoc PDMDEVHLPR3::pfnSUPSemEventMultiWaitNoResume
7380 */
7381DECLINLINE(int) PDMDevHlpSUPSemEventMultiWaitNoResume(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies)
7382{
7383 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventMultiWaitNsRelIntr(pDevIns, hEventMulti, cMillies);
7384}
7385
7386/**
7387 * @copydoc PDMDEVHLPR3::pfnSUPSemEventMultiWaitNsAbsIntr
7388 */
7389DECLINLINE(int) PDMDevHlpSUPSemEventMultiWaitNsAbsIntr(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout)
7390{
7391 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventMultiWaitNsAbsIntr(pDevIns, hEventMulti, uNsTimeout);
7392}
7393
7394/**
7395 * @copydoc PDMDEVHLPR3::pfnSUPSemEventMultiWaitNsRelIntr
7396 */
7397DECLINLINE(int) PDMDevHlpSUPSemEventMultiWaitNsRelIntr(PPDMDEVINS pDevIns, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout)
7398{
7399 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventMultiWaitNsRelIntr(pDevIns, hEventMulti, cNsTimeout);
7400}
7401
7402/**
7403 * @copydoc PDMDEVHLPR3::pfnSUPSemEventMultiGetResolution
7404 */
7405DECLINLINE(uint32_t) PDMDevHlpSUPSemEventMultiGetResolution(PPDMDEVINS pDevIns)
7406{
7407 return pDevIns->CTX_SUFF(pHlp)->pfnSUPSemEventMultiGetResolution(pDevIns);
7408}
7409
7410#ifdef IN_RING3
7411
7412/**
7413 * Initializes a PDM critical section.
7414 *
7415 * The PDM critical sections are derived from the IPRT critical sections, but
7416 * works in RC and R0 as well.
7417 *
7418 * @returns VBox status code.
7419 * @param pDevIns The device instance.
7420 * @param pCritSect Pointer to the critical section.
7421 * @param SRC_POS Use RT_SRC_POS.
7422 * @param pszNameFmt Format string for naming the critical section.
7423 * For statistics and lock validation.
7424 * @param ... Arguments for the format string.
7425 */
7426DECLINLINE(int) RT_IPRT_FORMAT_ATTR(6, 7) PDMDevHlpCritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
7427 const char *pszNameFmt, ...)
7428{
7429 int rc;
7430 va_list va;
7431 va_start(va, pszNameFmt);
7432 rc = pDevIns->pHlpR3->pfnCritSectInit(pDevIns, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
7433 va_end(va);
7434 return rc;
7435}
7436
7437#endif /* IN_RING3 */
7438
7439/**
7440 * @copydoc PDMDEVHLPR3::pfnCritSectGetNop
7441 */
7442DECLINLINE(PPDMCRITSECT) PDMDevHlpCritSectGetNop(PPDMDEVINS pDevIns)
7443{
7444 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectGetNop(pDevIns);
7445}
7446
7447#ifdef IN_RING3
7448
7449/**
7450 * @copydoc PDMDEVHLPR3::pfnCritSectGetNopR0
7451 */
7452DECLINLINE(R0PTRTYPE(PPDMCRITSECT)) PDMDevHlpCritSectGetNopR0(PPDMDEVINS pDevIns)
7453{
7454 return pDevIns->pHlpR3->pfnCritSectGetNopR0(pDevIns);
7455}
7456
7457/**
7458 * @copydoc PDMDEVHLPR3::pfnCritSectGetNopRC
7459 */
7460DECLINLINE(RCPTRTYPE(PPDMCRITSECT)) PDMDevHlpCritSectGetNopRC(PPDMDEVINS pDevIns)
7461{
7462 return pDevIns->pHlpR3->pfnCritSectGetNopRC(pDevIns);
7463}
7464
7465#endif /* IN_RING3 */
7466
7467/**
7468 * @copydoc PDMDEVHLPR3::pfnSetDeviceCritSect
7469 */
7470DECLINLINE(int) PDMDevHlpSetDeviceCritSect(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
7471{
7472 return pDevIns->CTX_SUFF(pHlp)->pfnSetDeviceCritSect(pDevIns, pCritSect);
7473}
7474
7475/**
7476 * @copydoc PDMCritSectEnter
7477 * @param pDevIns The device instance.
7478 */
7479DECLINLINE(int) PDMDevHlpCritSectEnter(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy)
7480{
7481 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectEnter(pDevIns, pCritSect, rcBusy);
7482}
7483
7484/**
7485 * @copydoc PDMCritSectEnterDebug
7486 * @param pDevIns The device instance.
7487 */
7488DECLINLINE(int) PDMDevHlpCritSectEnterDebug(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, int rcBusy, RTHCUINTPTR uId, RT_SRC_POS_DECL)
7489{
7490 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectEnterDebug(pDevIns, pCritSect, rcBusy, uId, RT_SRC_POS_ARGS);
7491}
7492
7493/**
7494 * @copydoc PDMCritSectTryEnter
7495 * @param pDevIns The device instance.
7496 */
7497DECLINLINE(int) PDMDevHlpCritSectTryEnter(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
7498{
7499 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectTryEnter(pDevIns, pCritSect);
7500}
7501
7502/**
7503 * @copydoc PDMCritSectTryEnterDebug
7504 * @param pDevIns The device instance.
7505 */
7506DECLINLINE(int) PDMDevHlpCritSectTryEnterDebug(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RTHCUINTPTR uId, RT_SRC_POS_DECL)
7507{
7508 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectTryEnterDebug(pDevIns, pCritSect, uId, RT_SRC_POS_ARGS);
7509}
7510
7511/**
7512 * @copydoc PDMCritSectLeave
7513 * @param pDevIns The device instance.
7514 */
7515DECLINLINE(int) PDMDevHlpCritSectLeave(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
7516{
7517 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectLeave(pDevIns, pCritSect);
7518}
7519
7520/**
7521 * @copydoc PDMCritSectIsOwner
7522 * @param pDevIns The device instance.
7523 */
7524DECLINLINE(bool) PDMDevHlpCritSectIsOwner(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect)
7525{
7526 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectIsOwner(pDevIns, pCritSect);
7527}
7528
7529/**
7530 * @copydoc PDMCritSectIsInitialized
7531 * @param pDevIns The device instance.
7532 */
7533DECLINLINE(bool) PDMDevHlpCritSectIsInitialized(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect)
7534{
7535 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectIsInitialized(pDevIns, pCritSect);
7536}
7537
7538/**
7539 * @copydoc PDMCritSectHasWaiters
7540 * @param pDevIns The device instance.
7541 */
7542DECLINLINE(bool) PDMDevHlpCritSectHasWaiters(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect)
7543{
7544 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectHasWaiters(pDevIns, pCritSect);
7545}
7546
7547/**
7548 * @copydoc PDMCritSectGetRecursion
7549 * @param pDevIns The device instance.
7550 */
7551DECLINLINE(uint32_t) PDMDevHlpCritSectGetRecursion(PPDMDEVINS pDevIns, PCPDMCRITSECT pCritSect)
7552{
7553 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectGetRecursion(pDevIns, pCritSect);
7554}
7555
7556#if defined(IN_RING3) || defined(IN_RING0)
7557/**
7558 * @copydoc PDMHCCritSectScheduleExitEvent
7559 * @param pDevIns The device instance.
7560 */
7561DECLINLINE(int) PDMDevHlpCritSectScheduleExitEvent(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, SUPSEMEVENT hEventToSignal)
7562{
7563 return pDevIns->CTX_SUFF(pHlp)->pfnCritSectScheduleExitEvent(pDevIns, pCritSect, hEventToSignal);
7564}
7565#endif
7566
7567/* Strict build: Remap the two enter calls to the debug versions. */
7568#ifdef VBOX_STRICT
7569# ifdef IPRT_INCLUDED_asm_h
7570# define PDMDevHlpCritSectEnter(pDevIns, pCritSect, rcBusy) PDMDevHlpCritSectEnterDebug((pDevIns), (pCritSect), (rcBusy), (uintptr_t)ASMReturnAddress(), RT_SRC_POS)
7571# define PDMDevHlpCritSectTryEnter(pDevIns, pCritSect) PDMDevHlpCritSectTryEnterDebug((pDevIns), (pCritSect), (uintptr_t)ASMReturnAddress(), RT_SRC_POS)
7572# else
7573# define PDMDevHlpCritSectEnter(pDevIns, pCritSect, rcBusy) PDMDevHlpCritSectEnterDebug((pDevIns), (pCritSect), (rcBusy), 0, RT_SRC_POS)
7574# define PDMDevHlpCritSectTryEnter(pDevIns, pCritSect) PDMDevHlpCritSectTryEnterDebug((pDevIns), (pCritSect), 0, RT_SRC_POS)
7575# endif
7576#endif
7577
7578#if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
7579
7580/**
7581 * @copydoc PDMR3CritSectDelete
7582 * @param pDevIns The device instance.
7583 */
7584DECLINLINE(int) PDMDevHlpCritSectDelete(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
7585{
7586 return pDevIns->pHlpR3->pfnCritSectDelete(pDevIns, pCritSect);
7587}
7588
7589/**
7590 * @copydoc PDMDEVHLPR3::pfnThreadCreate
7591 */
7592DECLINLINE(int) PDMDevHlpThreadCreate(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
7593 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
7594{
7595 return pDevIns->pHlpR3->pfnThreadCreate(pDevIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
7596}
7597
7598/**
7599 * @copydoc PDMR3ThreadDestroy
7600 * @param pDevIns The device instance.
7601 */
7602DECLINLINE(int) PDMDevHlpThreadDestroy(PPDMDEVINS pDevIns, PPDMTHREAD pThread, int *pRcThread)
7603{
7604 return pDevIns->pHlpR3->pfnThreadDestroy(pThread, pRcThread);
7605}
7606
7607/**
7608 * @copydoc PDMR3ThreadIAmSuspending
7609 * @param pDevIns The device instance.
7610 */
7611DECLINLINE(int) PDMDevHlpThreadIAmSuspending(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
7612{
7613 return pDevIns->pHlpR3->pfnThreadIAmSuspending(pThread);
7614}
7615
7616/**
7617 * @copydoc PDMR3ThreadIAmRunning
7618 * @param pDevIns The device instance.
7619 */
7620DECLINLINE(int) PDMDevHlpThreadIAmRunning(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
7621{
7622 return pDevIns->pHlpR3->pfnThreadIAmRunning(pThread);
7623}
7624
7625/**
7626 * @copydoc PDMR3ThreadSleep
7627 * @param pDevIns The device instance.
7628 */
7629DECLINLINE(int) PDMDevHlpThreadSleep(PPDMDEVINS pDevIns, PPDMTHREAD pThread, RTMSINTERVAL cMillies)
7630{
7631 return pDevIns->pHlpR3->pfnThreadSleep(pThread, cMillies);
7632}
7633
7634/**
7635 * @copydoc PDMR3ThreadSuspend
7636 * @param pDevIns The device instance.
7637 */
7638DECLINLINE(int) PDMDevHlpThreadSuspend(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
7639{
7640 return pDevIns->pHlpR3->pfnThreadSuspend(pThread);
7641}
7642
7643/**
7644 * @copydoc PDMR3ThreadResume
7645 * @param pDevIns The device instance.
7646 */
7647DECLINLINE(int) PDMDevHlpThreadResume(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
7648{
7649 return pDevIns->pHlpR3->pfnThreadResume(pThread);
7650}
7651
7652/**
7653 * @copydoc PDMDEVHLPR3::pfnSetAsyncNotification
7654 */
7655DECLINLINE(int) PDMDevHlpSetAsyncNotification(PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify)
7656{
7657 return pDevIns->pHlpR3->pfnSetAsyncNotification(pDevIns, pfnAsyncNotify);
7658}
7659
7660/**
7661 * @copydoc PDMDEVHLPR3::pfnAsyncNotificationCompleted
7662 */
7663DECLINLINE(void) PDMDevHlpAsyncNotificationCompleted(PPDMDEVINS pDevIns)
7664{
7665 pDevIns->pHlpR3->pfnAsyncNotificationCompleted(pDevIns);
7666}
7667
7668/**
7669 * @copydoc PDMDEVHLPR3::pfnA20Set
7670 */
7671DECLINLINE(void) PDMDevHlpA20Set(PPDMDEVINS pDevIns, bool fEnable)
7672{
7673 pDevIns->pHlpR3->pfnA20Set(pDevIns, fEnable);
7674}
7675
7676/**
7677 * @copydoc PDMDEVHLPR3::pfnRTCRegister
7678 */
7679DECLINLINE(int) PDMDevHlpRTCRegister(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp)
7680{
7681 return pDevIns->pHlpR3->pfnRTCRegister(pDevIns, pRtcReg, ppRtcHlp);
7682}
7683
7684/**
7685 * @copydoc PDMDEVHLPR3::pfnPCIBusRegister
7686 */
7687DECLINLINE(int) PDMDevHlpPCIBusRegister(PPDMDEVINS pDevIns, PPDMPCIBUSREGR3 pPciBusReg, PCPDMPCIHLPR3 *ppPciHlp, uint32_t *piBus)
7688{
7689 return pDevIns->pHlpR3->pfnPCIBusRegister(pDevIns, pPciBusReg, ppPciHlp, piBus);
7690}
7691
7692/**
7693 * @copydoc PDMDEVHLPR3::pfnPICRegister
7694 */
7695DECLINLINE(int) PDMDevHlpPICRegister(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLP *ppPicHlp)
7696{
7697 return pDevIns->pHlpR3->pfnPICRegister(pDevIns, pPicReg, ppPicHlp);
7698}
7699
7700/**
7701 * @copydoc PDMDEVHLPR3::pfnAPICRegister
7702 */
7703DECLINLINE(int) PDMDevHlpAPICRegister(PPDMDEVINS pDevIns)
7704{
7705 return pDevIns->pHlpR3->pfnAPICRegister(pDevIns);
7706}
7707
7708/**
7709 * @copydoc PDMDEVHLPR3::pfnIoApicRegister
7710 */
7711DECLINLINE(int) PDMDevHlpIoApicRegister(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLP *ppIoApicHlp)
7712{
7713 return pDevIns->pHlpR3->pfnIoApicRegister(pDevIns, pIoApicReg, ppIoApicHlp);
7714}
7715
7716/**
7717 * @copydoc PDMDEVHLPR3::pfnHPETRegister
7718 */
7719DECLINLINE(int) PDMDevHlpHPETRegister(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3)
7720{
7721 return pDevIns->pHlpR3->pfnHPETRegister(pDevIns, pHpetReg, ppHpetHlpR3);
7722}
7723
7724/**
7725 * @copydoc PDMDEVHLPR3::pfnPciRawRegister
7726 */
7727DECLINLINE(int) PDMDevHlpPciRawRegister(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3)
7728{
7729 return pDevIns->pHlpR3->pfnPciRawRegister(pDevIns, pPciRawReg, ppPciRawHlpR3);
7730}
7731
7732/**
7733 * @copydoc PDMDEVHLPR3::pfnDMACRegister
7734 */
7735DECLINLINE(int) PDMDevHlpDMACRegister(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp)
7736{
7737 return pDevIns->pHlpR3->pfnDMACRegister(pDevIns, pDmacReg, ppDmacHlp);
7738}
7739
7740/**
7741 * @copydoc PDMDEVHLPR3::pfnDMARegister
7742 */
7743DECLINLINE(int) PDMDevHlpDMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
7744{
7745 return pDevIns->pHlpR3->pfnDMARegister(pDevIns, uChannel, pfnTransferHandler, pvUser);
7746}
7747
7748/**
7749 * @copydoc PDMDEVHLPR3::pfnDMAReadMemory
7750 */
7751DECLINLINE(int) PDMDevHlpDMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
7752{
7753 return pDevIns->pHlpR3->pfnDMAReadMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbRead);
7754}
7755
7756/**
7757 * @copydoc PDMDEVHLPR3::pfnDMAWriteMemory
7758 */
7759DECLINLINE(int) PDMDevHlpDMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
7760{
7761 return pDevIns->pHlpR3->pfnDMAWriteMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbWritten);
7762}
7763
7764/**
7765 * @copydoc PDMDEVHLPR3::pfnDMASetDREQ
7766 */
7767DECLINLINE(int) PDMDevHlpDMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
7768{
7769 return pDevIns->pHlpR3->pfnDMASetDREQ(pDevIns, uChannel, uLevel);
7770}
7771
7772/**
7773 * @copydoc PDMDEVHLPR3::pfnDMAGetChannelMode
7774 */
7775DECLINLINE(uint8_t) PDMDevHlpDMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
7776{
7777 return pDevIns->pHlpR3->pfnDMAGetChannelMode(pDevIns, uChannel);
7778}
7779
7780/**
7781 * @copydoc PDMDEVHLPR3::pfnDMASchedule
7782 */
7783DECLINLINE(void) PDMDevHlpDMASchedule(PPDMDEVINS pDevIns)
7784{
7785 pDevIns->pHlpR3->pfnDMASchedule(pDevIns);
7786}
7787
7788/**
7789 * @copydoc PDMDEVHLPR3::pfnCMOSWrite
7790 */
7791DECLINLINE(int) PDMDevHlpCMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
7792{
7793 return pDevIns->pHlpR3->pfnCMOSWrite(pDevIns, iReg, u8Value);
7794}
7795
7796/**
7797 * @copydoc PDMDEVHLPR3::pfnCMOSRead
7798 */
7799DECLINLINE(int) PDMDevHlpCMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
7800{
7801 return pDevIns->pHlpR3->pfnCMOSRead(pDevIns, iReg, pu8Value);
7802}
7803
7804/**
7805 * @copydoc PDMDEVHLPR3::pfnCallR0
7806 */
7807DECLINLINE(int) PDMDevHlpCallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
7808{
7809 return pDevIns->pHlpR3->pfnCallR0(pDevIns, uOperation, u64Arg);
7810}
7811
7812/**
7813 * @copydoc PDMDEVHLPR3::pfnVMGetSuspendReason
7814 */
7815DECLINLINE(VMSUSPENDREASON) PDMDevHlpVMGetSuspendReason(PPDMDEVINS pDevIns)
7816{
7817 return pDevIns->pHlpR3->pfnVMGetSuspendReason(pDevIns);
7818}
7819
7820/**
7821 * @copydoc PDMDEVHLPR3::pfnVMGetResumeReason
7822 */
7823DECLINLINE(VMRESUMEREASON) PDMDevHlpVMGetResumeReason(PPDMDEVINS pDevIns)
7824{
7825 return pDevIns->pHlpR3->pfnVMGetResumeReason(pDevIns);
7826}
7827
7828/**
7829 * @copydoc PDMDEVHLPR3::pfnGetUVM
7830 */
7831DECLINLINE(PUVM) PDMDevHlpGetUVM(PPDMDEVINS pDevIns)
7832{
7833 return pDevIns->CTX_SUFF(pHlp)->pfnGetUVM(pDevIns);
7834}
7835
7836#endif /* IN_RING3 || DOXYGEN_RUNNING */
7837
7838#if !defined(IN_RING3) || defined(DOXYGEN_RUNNING)
7839
7840/**
7841 * @copydoc PDMDEVHLPR0::pfnPCIBusSetUpContext
7842 */
7843DECLINLINE(int) PDMDevHlpPCIBusSetUpContext(PPDMDEVINS pDevIns, CTX_SUFF(PPDMPCIBUSREG) pPciBusReg, CTX_SUFF(PCPDMPCIHLP) *ppPciHlp)
7844{
7845 return pDevIns->CTX_SUFF(pHlp)->pfnPCIBusSetUpContext(pDevIns, pPciBusReg, ppPciHlp);
7846}
7847
7848/**
7849 * @copydoc PDMDEVHLPR0::pfnPICSetUpContext
7850 */
7851DECLINLINE(int) PDMDevHlpPICSetUpContext(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLP *ppPicHlp)
7852{
7853 return pDevIns->CTX_SUFF(pHlp)->pfnPICSetUpContext(pDevIns, pPicReg, ppPicHlp);
7854}
7855
7856/**
7857 * @copydoc PDMDEVHLPR0::pfnIoApicSetUpContext
7858 */
7859DECLINLINE(int) PDMDevHlpIoApicSetUpContext(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLP *ppIoApicHlp)
7860{
7861 return pDevIns->CTX_SUFF(pHlp)->pfnIoApicSetUpContext(pDevIns, pIoApicReg, ppIoApicHlp);
7862}
7863
7864#endif /* !IN_RING3 || DOXYGEN_RUNNING */
7865
7866/**
7867 * @copydoc PDMDEVHLPR3::pfnGetVM
7868 */
7869DECLINLINE(PVMCC) PDMDevHlpGetVM(PPDMDEVINS pDevIns)
7870{
7871 return pDevIns->CTX_SUFF(pHlp)->pfnGetVM(pDevIns);
7872}
7873
7874/**
7875 * @copydoc PDMDEVHLPR3::pfnGetVMCPU
7876 */
7877DECLINLINE(PVMCPUCC) PDMDevHlpGetVMCPU(PPDMDEVINS pDevIns)
7878{
7879 return pDevIns->CTX_SUFF(pHlp)->pfnGetVMCPU(pDevIns);
7880}
7881
7882/**
7883 * @copydoc PDMDEVHLPR3::pfnGetCurrentCpuId
7884 */
7885DECLINLINE(VMCPUID) PDMDevHlpGetCurrentCpuId(PPDMDEVINS pDevIns)
7886{
7887 return pDevIns->CTX_SUFF(pHlp)->pfnGetCurrentCpuId(pDevIns);
7888}
7889
7890/**
7891 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGet
7892 */
7893DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGet(PPDMDEVINS pDevIns)
7894{
7895 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGet(pDevIns);
7896}
7897
7898/**
7899 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGetFreq
7900 */
7901DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGetFreq(PPDMDEVINS pDevIns)
7902{
7903 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGetFreq(pDevIns);
7904}
7905
7906/**
7907 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGetFreq
7908 */
7909DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGetNano(PPDMDEVINS pDevIns)
7910{
7911 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGetNano(pDevIns);
7912}
7913
7914#ifdef IN_RING3
7915
7916/**
7917 * @copydoc PDMDEVHLPR3::pfnRegisterVMMDevHeap
7918 */
7919DECLINLINE(int) PDMDevHlpRegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbHeap)
7920{
7921 return pDevIns->pHlpR3->pfnRegisterVMMDevHeap(pDevIns, GCPhys, pvHeap, cbHeap);
7922}
7923
7924/**
7925 * @copydoc PDMDEVHLPR3::pfnFirmwareRegister
7926 */
7927DECLINLINE(int) PDMDevHlpFirmwareRegister(PPDMDEVINS pDevIns, PCPDMFWREG pFwReg, PCPDMFWHLPR3 *ppFwHlp)
7928{
7929 return pDevIns->pHlpR3->pfnFirmwareRegister(pDevIns, pFwReg, ppFwHlp);
7930}
7931
7932/**
7933 * @copydoc PDMDEVHLPR3::pfnVMReset
7934 */
7935DECLINLINE(int) PDMDevHlpVMReset(PPDMDEVINS pDevIns, uint32_t fFlags)
7936{
7937 return pDevIns->pHlpR3->pfnVMReset(pDevIns, fFlags);
7938}
7939
7940/**
7941 * @copydoc PDMDEVHLPR3::pfnVMSuspend
7942 */
7943DECLINLINE(int) PDMDevHlpVMSuspend(PPDMDEVINS pDevIns)
7944{
7945 return pDevIns->pHlpR3->pfnVMSuspend(pDevIns);
7946}
7947
7948/**
7949 * @copydoc PDMDEVHLPR3::pfnVMSuspendSaveAndPowerOff
7950 */
7951DECLINLINE(int) PDMDevHlpVMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
7952{
7953 return pDevIns->pHlpR3->pfnVMSuspendSaveAndPowerOff(pDevIns);
7954}
7955
7956/**
7957 * @copydoc PDMDEVHLPR3::pfnVMPowerOff
7958 */
7959DECLINLINE(int) PDMDevHlpVMPowerOff(PPDMDEVINS pDevIns)
7960{
7961 return pDevIns->pHlpR3->pfnVMPowerOff(pDevIns);
7962}
7963
7964#endif /* IN_RING3 */
7965
7966/**
7967 * @copydoc PDMDEVHLPR3::pfnA20IsEnabled
7968 */
7969DECLINLINE(bool) PDMDevHlpA20IsEnabled(PPDMDEVINS pDevIns)
7970{
7971 return pDevIns->CTX_SUFF(pHlp)->pfnA20IsEnabled(pDevIns);
7972}
7973
7974#ifdef IN_RING3
7975
7976/**
7977 * @copydoc PDMDEVHLPR3::pfnGetCpuId
7978 */
7979DECLINLINE(void) PDMDevHlpGetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
7980{
7981 pDevIns->pHlpR3->pfnGetCpuId(pDevIns, iLeaf, pEax, pEbx, pEcx, pEdx);
7982}
7983
7984/**
7985 * @copydoc PDMDEVHLPR3::pfnGetSupDrvSession
7986 */
7987DECLINLINE(PSUPDRVSESSION) PDMDevHlpGetSupDrvSession(PPDMDEVINS pDevIns)
7988{
7989 return pDevIns->pHlpR3->pfnGetSupDrvSession(pDevIns);
7990}
7991
7992/**
7993 * @copydoc PDMDEVHLPR3::pfnQueryGenericUserObject
7994 */
7995DECLINLINE(void *) PDMDevHlpQueryGenericUserObject(PPDMDEVINS pDevIns, PCRTUUID pUuid)
7996{
7997 return pDevIns->pHlpR3->pfnQueryGenericUserObject(pDevIns, pUuid);
7998}
7999
8000/** Wrapper around SSMR3GetU32 for simplifying getting enum values saved as uint32_t. */
8001# define PDMDEVHLP_SSM_GET_ENUM32_RET(a_pHlp, a_pSSM, a_enmDst, a_EnumType) \
8002 do { \
8003 uint32_t u32GetEnumTmp = 0; \
8004 int rcGetEnum32Tmp = (a_pHlp)->pfnSSMGetU32((a_pSSM), &u32GetEnumTmp); \
8005 AssertRCReturn(rcGetEnum32Tmp, rcGetEnum32Tmp); \
8006 (a_enmDst) = (a_EnumType)u32GetEnumTmp; \
8007 AssertCompile(sizeof(a_EnumType) == sizeof(u32GetEnumTmp)); \
8008 } while (0)
8009
8010/** Wrapper around SSMR3GetU8 for simplifying getting enum values saved as uint8_t. */
8011# define PDMDEVHLP_SSM_GET_ENUM8_RET(a_pHlp, a_pSSM, a_enmDst, a_EnumType) \
8012 do { \
8013 uint8_t bGetEnumTmp = 0; \
8014 int rcGetEnum32Tmp = (a_pHlp)->pfnSSMGetU8((a_pSSM), &bGetEnumTmp); \
8015 AssertRCReturn(rcGetEnum32Tmp, rcGetEnum32Tmp); \
8016 (a_enmDst) = (a_EnumType)bGetEnumTmp; \
8017 } while (0)
8018
8019#endif /* IN_RING3 */
8020
8021/** Pointer to callbacks provided to the VBoxDeviceRegister() call. */
8022typedef struct PDMDEVREGCB *PPDMDEVREGCB;
8023
8024/**
8025 * Callbacks for VBoxDeviceRegister().
8026 */
8027typedef struct PDMDEVREGCB
8028{
8029 /** Interface version.
8030 * This is set to PDM_DEVREG_CB_VERSION. */
8031 uint32_t u32Version;
8032
8033 /**
8034 * Registers a device with the current VM instance.
8035 *
8036 * @returns VBox status code.
8037 * @param pCallbacks Pointer to the callback table.
8038 * @param pReg Pointer to the device registration record.
8039 * This data must be permanent and readonly.
8040 */
8041 DECLR3CALLBACKMEMBER(int, pfnRegister,(PPDMDEVREGCB pCallbacks, PCPDMDEVREG pReg));
8042} PDMDEVREGCB;
8043
8044/** Current version of the PDMDEVREGCB structure. */
8045#define PDM_DEVREG_CB_VERSION PDM_VERSION_MAKE(0xffe3, 1, 0)
8046
8047
8048/**
8049 * The VBoxDevicesRegister callback function.
8050 *
8051 * PDM will invoke this function after loading a device module and letting
8052 * the module decide which devices to register and how to handle conflicts.
8053 *
8054 * @returns VBox status code.
8055 * @param pCallbacks Pointer to the callback table.
8056 * @param u32Version VBox version number.
8057 */
8058typedef DECLCALLBACK(int) FNPDMVBOXDEVICESREGISTER(PPDMDEVREGCB pCallbacks, uint32_t u32Version);
8059
8060/** @} */
8061
8062RT_C_DECLS_END
8063
8064#endif /* !VBOX_INCLUDED_vmm_pdmdev_h */
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