VirtualBox

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

Last change on this file since 63855 was 63701, checked in by vboxsync, 9 years ago

pdmdev: remark about PDM_DEVHLPR3_VERSION in 5.0

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

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