VirtualBox

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

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

APIC,PDM: Avoid a few more return-to-ring-3 statuses now that we've got LogRel. Updated related (mostly) docs here and there. bugref:9044

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

© 2023 Oracle
ContactPrivacy policyTerms of Use