VirtualBox

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

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

VMM(PDM,PGM,MM): MMIO2 cleanups. bugref:9218

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