VirtualBox

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

Last change on this file since 81921 was 81921, checked in by vboxsync, 5 years ago

DevPcBios: Converted and split up I/O port handlers. bugref:9218

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

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