VirtualBox

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

Last change on this file since 64310 was 64115, checked in by vboxsync, 9 years ago

PDM,IOM,PGM: Morphed the MMIO2 API into a mixed MMIO2 and pre-registered MMIO API that is able to deal with really large (<= 64GB) MMIO ranges. Limited testing, so back out at first sign of trouble.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 214.1 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 or pre-registered MMIO base address.
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 * @sa PGMR3PhysMMIOExIsBase
817 */
818 DECLR3CALLBACKMEMBER(bool, pfnIsMMIOExBase,(PPDMDEVINS pDevIns, PPDMDEVINS pOwner, RTGCPHYS GCPhys));
819
820 /**
821 * Gets the address of the RC PCI Bus helpers.
822 *
823 * This should be called at both construction and relocation time
824 * to obtain the correct address of the RC helpers.
825 *
826 * @returns RC pointer to the PCI Bus helpers.
827 * @param pDevIns Device instance of the PCI Bus.
828 * @thread EMT only.
829 */
830 DECLR3CALLBACKMEMBER(PCPDMPCIHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
831
832 /**
833 * Gets the address of the R0 PCI Bus helpers.
834 *
835 * This should be called at both construction and relocation time
836 * to obtain the correct address of the R0 helpers.
837 *
838 * @returns R0 pointer to the PCI Bus helpers.
839 * @param pDevIns Device instance of the PCI Bus.
840 * @thread EMT only.
841 */
842 DECLR3CALLBACKMEMBER(PCPDMPCIHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
843
844 /**
845 * Acquires the PDM lock.
846 *
847 * @returns VINF_SUCCESS on success.
848 * @returns Fatal error on failure.
849 * @param pDevIns The PCI device instance.
850 * @param rc Dummy for making the interface identical to the RC and R0 versions.
851 */
852 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
853
854 /**
855 * Releases the PDM lock.
856 *
857 * @param pDevIns The PCI device instance.
858 */
859 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
860
861 /** Just a safety precaution. */
862 uint32_t u32TheEnd;
863} PDMPCIHLPR3;
864/** Pointer to PCI helpers. */
865typedef R3PTRTYPE(PDMPCIHLPR3 *) PPDMPCIHLPR3;
866/** Pointer to const PCI helpers. */
867typedef R3PTRTYPE(const PDMPCIHLPR3 *) PCPDMPCIHLPR3;
868
869/** Current PDMPCIHLPR3 version number. */
870#define PDM_PCIHLPR3_VERSION PDM_VERSION_MAKE(0xfffb, 3, 1)
871
872
873/**
874 * Programmable Interrupt Controller registration structure.
875 */
876typedef struct PDMPICREG
877{
878 /** Structure version number. PDM_PICREG_VERSION defines the current version. */
879 uint32_t u32Version;
880
881 /**
882 * Set the an IRQ.
883 *
884 * @param pDevIns Device instance of the PIC.
885 * @param iIrq IRQ number to set.
886 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
887 * @param uTagSrc The IRQ tag and source (for tracing).
888 * @remarks Caller enters the PDM critical section.
889 */
890 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
891
892 /**
893 * Get a pending interrupt.
894 *
895 * @returns Pending interrupt number.
896 * @param pDevIns Device instance of the PIC.
897 * @param puTagSrc Where to return the IRQ tag and source.
898 * @remarks Caller enters the PDM critical section.
899 */
900 DECLR3CALLBACKMEMBER(int, pfnGetInterruptR3,(PPDMDEVINS pDevIns, uint32_t *puTagSrc));
901
902 /** The name of the RC SetIrq entry point. */
903 const char *pszSetIrqRC;
904 /** The name of the RC GetInterrupt entry point. */
905 const char *pszGetInterruptRC;
906
907 /** The name of the R0 SetIrq entry point. */
908 const char *pszSetIrqR0;
909 /** The name of the R0 GetInterrupt entry point. */
910 const char *pszGetInterruptR0;
911} PDMPICREG;
912/** Pointer to a PIC registration structure. */
913typedef PDMPICREG *PPDMPICREG;
914
915/** Current PDMPICREG version number. */
916#define PDM_PICREG_VERSION PDM_VERSION_MAKE(0xfffa, 2, 0)
917
918/**
919 * PIC RC helpers.
920 */
921typedef struct PDMPICHLPRC
922{
923 /** Structure version. PDM_PICHLPRC_VERSION defines the current version. */
924 uint32_t u32Version;
925
926 /**
927 * Set the interrupt force action flag.
928 *
929 * @param pDevIns Device instance of the PIC.
930 */
931 DECLRCCALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
932
933 /**
934 * Clear the interrupt force action flag.
935 *
936 * @param pDevIns Device instance of the PIC.
937 */
938 DECLRCCALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
939
940 /**
941 * Acquires the PDM lock.
942 *
943 * @returns VINF_SUCCESS on success.
944 * @returns rc if we failed to acquire the lock.
945 * @param pDevIns The PIC device instance.
946 * @param rc What to return if we fail to acquire the lock.
947 */
948 DECLRCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
949
950 /**
951 * Releases the PDM lock.
952 *
953 * @param pDevIns The PIC device instance.
954 */
955 DECLRCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
956
957 /** Just a safety precaution. */
958 uint32_t u32TheEnd;
959} PDMPICHLPRC;
960
961/** Pointer to PIC RC helpers. */
962typedef RCPTRTYPE(PDMPICHLPRC *) PPDMPICHLPRC;
963/** Pointer to const PIC RC helpers. */
964typedef RCPTRTYPE(const PDMPICHLPRC *) PCPDMPICHLPRC;
965
966/** Current PDMPICHLPRC version number. */
967#define PDM_PICHLPRC_VERSION PDM_VERSION_MAKE(0xfff9, 2, 0)
968
969
970/**
971 * PIC R0 helpers.
972 */
973typedef struct PDMPICHLPR0
974{
975 /** Structure version. PDM_PICHLPR0_VERSION defines the current version. */
976 uint32_t u32Version;
977
978 /**
979 * Set the interrupt force action flag.
980 *
981 * @param pDevIns Device instance of the PIC.
982 */
983 DECLR0CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
984
985 /**
986 * Clear the interrupt force action flag.
987 *
988 * @param pDevIns Device instance of the PIC.
989 */
990 DECLR0CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
991
992 /**
993 * Acquires the PDM lock.
994 *
995 * @returns VINF_SUCCESS on success.
996 * @returns rc if we failed to acquire the lock.
997 * @param pDevIns The PIC device instance.
998 * @param rc What to return if we fail to acquire the lock.
999 */
1000 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1001
1002 /**
1003 * Releases the PDM lock.
1004 *
1005 * @param pDevIns The PCI device instance.
1006 */
1007 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1008
1009 /** Just a safety precaution. */
1010 uint32_t u32TheEnd;
1011} PDMPICHLPR0;
1012
1013/** Pointer to PIC R0 helpers. */
1014typedef R0PTRTYPE(PDMPICHLPR0 *) PPDMPICHLPR0;
1015/** Pointer to const PIC R0 helpers. */
1016typedef R0PTRTYPE(const PDMPICHLPR0 *) PCPDMPICHLPR0;
1017
1018/** Current PDMPICHLPR0 version number. */
1019#define PDM_PICHLPR0_VERSION PDM_VERSION_MAKE(0xfff8, 1, 0)
1020
1021/**
1022 * PIC R3 helpers.
1023 */
1024typedef struct PDMPICHLPR3
1025{
1026 /** Structure version. PDM_PICHLP_VERSION defines the current version. */
1027 uint32_t u32Version;
1028
1029 /**
1030 * Set the interrupt force action flag.
1031 *
1032 * @param pDevIns Device instance of the PIC.
1033 */
1034 DECLR3CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns));
1035
1036 /**
1037 * Clear the interrupt force action flag.
1038 *
1039 * @param pDevIns Device instance of the PIC.
1040 */
1041 DECLR3CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns));
1042
1043 /**
1044 * Acquires the PDM lock.
1045 *
1046 * @returns VINF_SUCCESS on success.
1047 * @returns Fatal error on failure.
1048 * @param pDevIns The PIC device instance.
1049 * @param rc Dummy for making the interface identical to the RC and R0 versions.
1050 */
1051 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1052
1053 /**
1054 * Releases the PDM lock.
1055 *
1056 * @param pDevIns The PIC device instance.
1057 */
1058 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1059
1060 /**
1061 * Gets the address of the RC PIC helpers.
1062 *
1063 * This should be called at both construction and relocation time
1064 * to obtain the correct address of the RC helpers.
1065 *
1066 * @returns RC pointer to the PIC helpers.
1067 * @param pDevIns Device instance of the PIC.
1068 */
1069 DECLR3CALLBACKMEMBER(PCPDMPICHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1070
1071 /**
1072 * Gets the address of the R0 PIC helpers.
1073 *
1074 * This should be called at both construction and relocation time
1075 * to obtain the correct address of the R0 helpers.
1076 *
1077 * @returns R0 pointer to the PIC helpers.
1078 * @param pDevIns Device instance of the PIC.
1079 */
1080 DECLR3CALLBACKMEMBER(PCPDMPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1081
1082 /** Just a safety precaution. */
1083 uint32_t u32TheEnd;
1084} PDMPICHLPR3;
1085
1086/** Pointer to PIC R3 helpers. */
1087typedef R3PTRTYPE(PDMPICHLPR3 *) PPDMPICHLPR3;
1088/** Pointer to const PIC R3 helpers. */
1089typedef R3PTRTYPE(const PDMPICHLPR3 *) PCPDMPICHLPR3;
1090
1091/** Current PDMPICHLPR3 version number. */
1092#define PDM_PICHLPR3_VERSION PDM_VERSION_MAKE(0xfff7, 1, 0)
1093
1094
1095
1096/**
1097 * Firmware registration structure.
1098 */
1099typedef struct PDMFWREG
1100{
1101 /** Struct version+magic number (PDM_FWREG_VERSION). */
1102 uint32_t u32Version;
1103
1104 /**
1105 * Checks whether this is a hard or soft reset.
1106 *
1107 * The current definition of soft reset is what the PC BIOS does when CMOS[0xF]
1108 * is 5, 9 or 0xA.
1109 *
1110 * @returns true if hard reset, false if soft.
1111 * @param pDevIns Device instance of the firmware.
1112 * @param fFlags PDMRESET_F_XXX passed to the PDMDevHlpVMReset API.
1113 */
1114 DECLR3CALLBACKMEMBER(bool, pfnIsHardReset,(PPDMDEVINS pDevIns, uint32_t fFlags));
1115
1116 /** Just a safety precaution. */
1117 uint32_t u32TheEnd;
1118} PDMFWREG;
1119/** Pointer to a FW registration structure. */
1120typedef PDMFWREG *PPDMFWREG;
1121/** Pointer to a const FW registration structure. */
1122typedef PDMFWREG const *PCPDMFWREG;
1123
1124/** Current PDMFWREG version number. */
1125#define PDM_FWREG_VERSION PDM_VERSION_MAKE(0xffdd, 1, 0)
1126
1127/**
1128 * Firmware R3 helpers.
1129 */
1130typedef struct PDMFWHLPR3
1131{
1132 /** Structure version. PDM_FWHLP_VERSION defines the current version. */
1133 uint32_t u32Version;
1134
1135 /** Just a safety precaution. */
1136 uint32_t u32TheEnd;
1137} PDMFWHLPR3;
1138
1139/** Pointer to FW R3 helpers. */
1140typedef R3PTRTYPE(PDMFWHLPR3 *) PPDMFWHLPR3;
1141/** Pointer to const FW R3 helpers. */
1142typedef R3PTRTYPE(const PDMFWHLPR3 *) PCPDMFWHLPR3;
1143
1144/** Current PDMFWHLPR3 version number. */
1145#define PDM_FWHLPR3_VERSION PDM_VERSION_MAKE(0xffdb, 1, 0)
1146
1147
1148/**
1149 * Advanced Programmable Interrupt Controller registration structure.
1150 */
1151typedef struct PDMAPICREG
1152{
1153 /** Structure version number. PDM_APICREG_VERSION defines the current version. */
1154 uint32_t u32Version;
1155
1156 /**
1157 * Get a pending interrupt.
1158 *
1159 * @returns VBox status code.
1160 * @param pDevIns Device instance of the APIC.
1161 * @param pVCpu The cross context virtual CPU structure.
1162 * @param pu8Vector Where to store the vector.
1163 * @param pu32TagSrc Where to return the tag source (tracing
1164 * purposes).
1165 * @remarks Caller enters the PDM critical section.
1166 */
1167 DECLR3CALLBACKMEMBER(int, pfnGetInterruptR3,(PPDMDEVINS pDevIns, PVMCPU pVCpu, uint8_t *pu8Vector, uint32_t *pu32TagSrc));
1168
1169 /**
1170 * Set the APIC base.
1171 *
1172 * @param pDevIns Device instance of the APIC.
1173 * @param pVCpu The cross context virtual CPU structure.
1174 * @param u64BaseMsr The base MSR value.
1175 * @remarks Caller enters the PDM critical section (might not be the case with
1176 * the new APIC code)
1177 */
1178 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnSetBaseMsrR3,(PPDMDEVINS pDevIns, PVMCPU pVCpu, uint64_t u64BaseMsr));
1179
1180 /**
1181 * Get the APIC base.
1182 *
1183 * @returns Current base.
1184 * @param pDevIns Device instance of the APIC.
1185 * @param pVCpu The cross context virtual CPU structure.
1186 * @remarks Caller enters the PDM critical section.
1187 */
1188 DECLR3CALLBACKMEMBER(uint64_t, pfnGetBaseMsrR3,(PPDMDEVINS pDevIns, PVMCPU pVCpu));
1189
1190 /**
1191 * Set the TPR (task priority register).
1192 *
1193 * @param pDevIns Device instance of the APIC.
1194 * @param pVCpu The cross context virtual CPU structure.
1195 * @param u8Tpr The new TPR.
1196 * @remarks Caller enters the PDM critical section.
1197 */
1198 DECLR3CALLBACKMEMBER(void, pfnSetTprR3,(PPDMDEVINS pDevIns, PVMCPU pVCpu, uint8_t u8Tpr));
1199
1200 /**
1201 * Get the TPR (task priority register).
1202 *
1203 * @returns The current TPR.
1204 * @param pDevIns Device instance of the APIC.
1205 * @param pVCpu The cross context virtual CPU structure.
1206 * @param pfPending Where to store if there is an interrupt pending
1207 * (optional, can be NULL).
1208 * @param pu8PendingIntr Where to store the pending interrupt vector
1209 * (optional, can be NULL).
1210 * @remarks Caller enters the PDM critical section.
1211 */
1212 DECLR3CALLBACKMEMBER(uint8_t, pfnGetTprR3,(PPDMDEVINS pDevIns, PVMCPU pVCpu, bool *pfPending, uint8_t *pu8PendingIntr));
1213
1214 /**
1215 * Write to a MSR in APIC range.
1216 *
1217 * @returns Strict VBox status code.
1218 * @param pDevIns Device instance of the APIC.
1219 * @param pVCpu The cross context virtual CPU structure.
1220 * @param u32Reg The MSR begin written to.
1221 * @param u64Value The value to write.
1222 *
1223 * @remarks Unlike the other callbacks, the PDM lock is not taken before
1224 * calling this method.
1225 */
1226 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnWriteMsrR3,(PPDMDEVINS pDevIns, PVMCPU pVCpu, uint32_t u32Reg, uint64_t u64Value));
1227
1228 /**
1229 * Read from a MSR in APIC range.
1230 *
1231 * @returns Strict VBox status code.
1232 * @param pDevIns Device instance of the APIC.
1233 * @param pVCpu The cross context virtual CPU structure.
1234 * @param u32Reg MSR to read.
1235 * @param pu64Value Where to return the read value.
1236 *
1237 * @remarks Unlike the other callbacks, the PDM lock is not taken before
1238 * calling this method.
1239 */
1240 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnReadMsrR3,(PPDMDEVINS pDevIns, PVMCPU pVCpu, uint32_t u32Reg, uint64_t *pu64Value));
1241
1242 /**
1243 * Private interface between the IOAPIC and APIC.
1244 *
1245 * This is a low-level, APIC/IOAPIC implementation specific interface which
1246 * is registered with PDM only because it makes life so much simpler right
1247 * now (GC bits). This is a bad bad hack! The correct way of doing this
1248 * would involve some way of querying GC interfaces and relocating them.
1249 * Perhaps doing some kind of device init in GC...
1250 *
1251 * @returns VBox status code.
1252 * @param pDevIns Device instance of the APIC.
1253 * @param uDest The destination mask.
1254 * @param uDestMode The destination mode, see XAPICDESTMODE.
1255 * @param uDeliveryMode The delivery mode, see XAPICDELIVERYMODE.
1256 * @param uVector The interrupt vector.
1257 * @param uPolarity The input pin polarity.
1258 * @param uTriggerMode The trigger mode, see XAPICTRIGGERMODE.
1259 * @param uTagSrc The IRQ tag and source (for tracing).
1260 * @remarks Caller enters the PDM critical section.
1261 */
1262 DECLR3CALLBACKMEMBER(int, pfnBusDeliverR3,(PPDMDEVINS pDevIns, uint8_t uDest, uint8_t uDestMode, uint8_t uDeliveryMode,
1263 uint8_t uVector, uint8_t uPolarity, uint8_t uTriggerMode, uint32_t uTagSrc));
1264
1265 /**
1266 * Deliver a signal to CPU's local interrupt pins (LINT0/LINT1).
1267 *
1268 * Used for virtual wire mode when interrupts from the PIC are passed through
1269 * LAPIC.
1270 *
1271 * @returns Strict VBox status code.
1272 * @param pDevIns Device instance of the APIC.
1273 * @param pVCpu The cross context virtual CPU structure.
1274 * @param u8Pin Local pin number (0 or 1 for current CPUs).
1275 * @param u8Level The level.
1276 * @param rcRZ The return code if the operation cannot be
1277 * performed in the current context.
1278 * @remarks Caller enters the PDM critical section
1279 */
1280 DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnLocalInterruptR3,(PPDMDEVINS pDevIns, PVMCPU pVCpu, uint8_t u8Pin, uint8_t u8Level,
1281 int rcRZ));
1282
1283 /**
1284 * Get the APIC timer frequency (in Hz).
1285 *
1286 * @returns The frequency of the APIC timer.
1287 * @param pDevIns Device instance of the APIC.
1288 */
1289 DECLR3CALLBACKMEMBER(uint64_t, pfnGetTimerFreqR3,(PPDMDEVINS pDevIns));
1290
1291 /** The name of the RC GetInterrupt entry point. */
1292 const char *pszGetInterruptRC;
1293 /** The name of the RC SetBaseMsr entry point. */
1294 const char *pszSetBaseMsrRC;
1295 /** The name of the RC GetBaseMsr entry point. */
1296 const char *pszGetBaseMsrRC;
1297 /** The name of the RC SetTpr entry point. */
1298 const char *pszSetTprRC;
1299 /** The name of the RC GetTpr entry point. */
1300 const char *pszGetTprRC;
1301 /** The name of the RC WriteMsr entry point. */
1302 const char *pszWriteMsrRC;
1303 /** The name of the RC ReadMsr entry point. */
1304 const char *pszReadMsrRC;
1305 /** The name of the RC BusDeliver entry point. */
1306 const char *pszBusDeliverRC;
1307 /** The name of the RC LocalInterrupt entry point. */
1308 const char *pszLocalInterruptRC;
1309 /** The name of the RC GetTimerFreq entry point. */
1310 const char *pszGetTimerFreqRC;
1311
1312 /** The name of the R0 GetInterrupt entry point. */
1313 const char *pszGetInterruptR0;
1314 /** The name of the R0 SetBaseMsr entry point. */
1315 const char *pszSetBaseMsrR0;
1316 /** The name of the R0 GetBaseMsr entry point. */
1317 const char *pszGetBaseMsrR0;
1318 /** The name of the R0 SetTpr entry point. */
1319 const char *pszSetTprR0;
1320 /** The name of the R0 GetTpr entry point. */
1321 const char *pszGetTprR0;
1322 /** The name of the R0 WriteMsr entry point. */
1323 const char *pszWriteMsrR0;
1324 /** The name of the R0 ReadMsr entry point. */
1325 const char *pszReadMsrR0;
1326 /** The name of the R0 BusDeliver entry point. */
1327 const char *pszBusDeliverR0;
1328 /** The name of the R0 LocalInterrupt entry point. */
1329 const char *pszLocalInterruptR0;
1330 /** The name of the R0 GetTimerFreq entry point. */
1331 const char *pszGetTimerFreqR0;
1332} PDMAPICREG;
1333/** Pointer to an APIC registration structure. */
1334typedef PDMAPICREG *PPDMAPICREG;
1335
1336/** Current PDMAPICREG version number. */
1337#define PDM_APICREG_VERSION PDM_VERSION_MAKE(0xfff6, 4, 0)
1338
1339
1340/**
1341 * APIC mode argument for pfnChangeFeature.
1342 *
1343 * Also used in saved-states, don't change existing values.
1344 */
1345typedef enum PDMAPICMODE
1346{
1347 /** Invalid 0 entry. */
1348 PDMAPICMODE_INVALID = 0,
1349 /** No APIC. */
1350 PDMAPICMODE_NONE,
1351 /** Standard APIC (X86_CPUID_FEATURE_EDX_APIC). */
1352 PDMAPICMODE_APIC,
1353 /** Intel X2APIC (X86_CPUID_FEATURE_ECX_X2APIC). */
1354 PDMAPICMODE_X2APIC,
1355 /** The usual 32-bit paranoia. */
1356 PDMAPICMODE_32BIT_HACK = 0x7fffffff
1357} PDMAPICMODE;
1358
1359/**
1360 * APIC irq argument for pfnSetInterruptFF and pfnClearInterruptFF.
1361 */
1362typedef enum PDMAPICIRQ
1363{
1364 /** Invalid 0 entry. */
1365 PDMAPICIRQ_INVALID = 0,
1366 /** Normal hardware interrupt. */
1367 PDMAPICIRQ_HARDWARE,
1368 /** NMI. */
1369 PDMAPICIRQ_NMI,
1370 /** SMI. */
1371 PDMAPICIRQ_SMI,
1372 /** ExtINT (HW interrupt via PIC). */
1373 PDMAPICIRQ_EXTINT,
1374 /** Interrupt arrived, needs to be updated to the IRR. */
1375 PDMAPICIRQ_UPDATE_PENDING,
1376 /** The usual 32-bit paranoia. */
1377 PDMAPICIRQ_32BIT_HACK = 0x7fffffff
1378} PDMAPICIRQ;
1379
1380
1381/**
1382 * APIC RC helpers.
1383 */
1384typedef struct PDMAPICHLPRC
1385{
1386 /** Structure version. PDM_APICHLPRC_VERSION defines the current version. */
1387 uint32_t u32Version;
1388
1389 /**
1390 * Set the interrupt force action flag.
1391 *
1392 * @param pDevIns Device instance of the APIC.
1393 * @param enmType IRQ type.
1394 * @param idCpu Virtual CPU to set flag upon.
1395 */
1396 DECLRCCALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1397
1398 /**
1399 * Clear the interrupt force action flag.
1400 *
1401 * @param pDevIns Device instance of the APIC.
1402 * @param enmType IRQ type.
1403 * @param idCpu Virtual CPU to clear flag upon.
1404 */
1405 DECLRCCALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1406
1407 /**
1408 * Broadcasts an EOI for an interrupt vector to the I/O APICs.
1409 *
1410 * @returns VBox status code.
1411 * @param pDevIns The APIC device instance.
1412 * @param u8Vector The interrupt vector.
1413 */
1414 DECLRCCALLBACKMEMBER(int, pfnBusBroadcastEoi,(PPDMDEVINS pDevIns, uint8_t u8Vector));
1415
1416 /**
1417 * Calculates an IRQ tag for a timer, IPI or similar event.
1418 *
1419 * @returns The IRQ tag.
1420 * @param pDevIns Device instance of the APIC.
1421 * @param u8Level PDM_IRQ_LEVEL_HIGH or PDM_IRQ_LEVEL_FLIP_FLOP.
1422 */
1423 DECLRCCALLBACKMEMBER(uint32_t, pfnCalcIrqTag,(PPDMDEVINS pDevIns, uint8_t u8Level));
1424
1425 /**
1426 * Acquires the PDM lock.
1427 *
1428 * @returns VINF_SUCCESS on success.
1429 * @returns rc if we failed to acquire the lock.
1430 * @param pDevIns The APIC device instance.
1431 * @param rc What to return if we fail to acquire the lock.
1432 */
1433 DECLRCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1434
1435 /**
1436 * Releases the PDM lock.
1437 *
1438 * @param pDevIns The APIC device instance.
1439 */
1440 DECLRCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1441
1442 /**
1443 * Get the virtual CPU id corresponding to the current EMT.
1444 *
1445 * @param pDevIns The APIC device instance.
1446 */
1447 DECLRCCALLBACKMEMBER(VMCPUID, pfnGetCpuId,(PPDMDEVINS pDevIns));
1448
1449 /** Just a safety precaution. */
1450 uint32_t u32TheEnd;
1451} PDMAPICHLPRC;
1452/** Pointer to APIC GC helpers. */
1453typedef RCPTRTYPE(PDMAPICHLPRC *) PPDMAPICHLPRC;
1454/** Pointer to const APIC helpers. */
1455typedef RCPTRTYPE(const PDMAPICHLPRC *) PCPDMAPICHLPRC;
1456
1457/** Current PDMAPICHLPRC version number. */
1458#define PDM_APICHLPRC_VERSION PDM_VERSION_MAKE(0xfff5, 5, 0)
1459
1460
1461/**
1462 * APIC R0 helpers.
1463 */
1464typedef struct PDMAPICHLPR0
1465{
1466 /** Structure version. PDM_APICHLPR0_VERSION defines the current version. */
1467 uint32_t u32Version;
1468
1469 /**
1470 * Set the interrupt force action flag.
1471 *
1472 * @param pDevIns Device instance of the APIC.
1473 * @param enmType IRQ type.
1474 * @param idCpu Virtual CPU to set flag upon.
1475 */
1476 DECLR0CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1477
1478 /**
1479 * Clear the interrupt force action flag.
1480 *
1481 * @param pDevIns Device instance of the APIC.
1482 * @param enmType IRQ type.
1483 * @param idCpu Virtual CPU to clear flag upon.
1484 */
1485 DECLR0CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1486
1487 /**
1488 * Broadcasts an EOI for an interrupt vector to the I/O APICs.
1489 *
1490 * @returns VBox status code.
1491 * @param pDevIns The APIC device instance.
1492 * @param u8Vector The interrupt vector.
1493 */
1494 DECLR0CALLBACKMEMBER(int, pfnBusBroadcastEoi,(PPDMDEVINS pDevIns, uint8_t u8Vector));
1495
1496 /**
1497 * Calculates an IRQ tag for a timer, IPI or similar event.
1498 *
1499 * @returns The IRQ tag.
1500 * @param pDevIns Device instance of the APIC.
1501 * @param u8Level PDM_IRQ_LEVEL_HIGH or PDM_IRQ_LEVEL_FLIP_FLOP.
1502 */
1503 DECLR0CALLBACKMEMBER(uint32_t, pfnCalcIrqTag,(PPDMDEVINS pDevIns, uint8_t u8Level));
1504
1505 /**
1506 * Acquires the PDM lock.
1507 *
1508 * @returns VINF_SUCCESS on success.
1509 * @returns rc if we failed to acquire the lock.
1510 * @param pDevIns The APIC device instance.
1511 * @param rc What to return if we fail to acquire the lock.
1512 */
1513 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1514
1515 /**
1516 * Releases the PDM lock.
1517 *
1518 * @param pDevIns The APIC device instance.
1519 */
1520 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1521
1522 /**
1523 * Get the virtual CPU id corresponding to the current EMT.
1524 *
1525 * @param pDevIns The APIC device instance.
1526 */
1527 DECLR0CALLBACKMEMBER(VMCPUID, pfnGetCpuId,(PPDMDEVINS pDevIns));
1528
1529 /** Just a safety precaution. */
1530 uint32_t u32TheEnd;
1531} PDMAPICHLPR0;
1532/** Pointer to APIC GC helpers. */
1533typedef RCPTRTYPE(PDMAPICHLPR0 *) PPDMAPICHLPR0;
1534/** Pointer to const APIC helpers. */
1535typedef R0PTRTYPE(const PDMAPICHLPR0 *) PCPDMAPICHLPR0;
1536
1537/** Current PDMAPICHLPR0 version number. */
1538#define PDM_APICHLPR0_VERSION PDM_VERSION_MAKE(0xfff4, 5, 0)
1539
1540/**
1541 * APIC R3 helpers.
1542 */
1543typedef struct PDMAPICHLPR3
1544{
1545 /** Structure version. PDM_APICHLPR3_VERSION defines the current version. */
1546 uint32_t u32Version;
1547
1548 /**
1549 * Set the interrupt force action flag.
1550 *
1551 * @param pDevIns Device instance of the APIC.
1552 * @param enmType IRQ type.
1553 * @param idCpu Virtual CPU to set flag upon.
1554 */
1555 DECLR3CALLBACKMEMBER(void, pfnSetInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1556
1557 /**
1558 * Clear the interrupt force action flag.
1559 *
1560 * @param pDevIns Device instance of the APIC.
1561 * @param enmType IRQ type.
1562 * @param idCpu Virtual CPU to clear flag upon.
1563 */
1564 DECLR3CALLBACKMEMBER(void, pfnClearInterruptFF,(PPDMDEVINS pDevIns, PDMAPICIRQ enmType, VMCPUID idCpu));
1565
1566 /**
1567 * Broadcasts an EOI for an interrupt vector to the I/O APICs.
1568 *
1569 * @returns VBox status code.
1570 * @param pDevIns The APIC device instance.
1571 * @param u8Vector The interrupt vector.
1572 */
1573 DECLR3CALLBACKMEMBER(int, pfnBusBroadcastEoi,(PPDMDEVINS pDevIns, uint8_t u8Vector));
1574
1575 /**
1576 * Calculates an IRQ tag for a timer, IPI or similar event.
1577 *
1578 * @returns The IRQ tag.
1579 * @param pDevIns Device instance of the APIC.
1580 * @param u8Level PDM_IRQ_LEVEL_HIGH or PDM_IRQ_LEVEL_FLIP_FLOP.
1581 */
1582 DECLR3CALLBACKMEMBER(uint32_t, pfnCalcIrqTag,(PPDMDEVINS pDevIns, uint8_t u8Level));
1583
1584 /**
1585 * Modifies APIC-related bits in the CPUID feature mask and preps MSRs.
1586 *
1587 * @param pDevIns Device instance of the APIC.
1588 * @param enmMode Max supported APIC mode.
1589 */
1590 DECLR3CALLBACKMEMBER(void, pfnSetFeatureLevel,(PPDMDEVINS pDevIns, PDMAPICMODE enmMode));
1591
1592 /**
1593 * Get the virtual CPU id corresponding to the current EMT.
1594 *
1595 * @param pDevIns The APIC device instance.
1596 */
1597 DECLR3CALLBACKMEMBER(VMCPUID, pfnGetCpuId,(PPDMDEVINS pDevIns));
1598
1599 /**
1600 * Sends Startup IPI to given virtual CPU.
1601 *
1602 * @param pDevIns The APIC device instance.
1603 * @param idCpu Virtual CPU to perform Startup IPI on.
1604 * @param uVector Startup IPI vector.
1605 */
1606 DECLR3CALLBACKMEMBER(void, pfnSendStartupIpi,(PPDMDEVINS pDevIns, VMCPUID idCpu, uint32_t uVector));
1607
1608 /**
1609 * Sends INIT IPI to given virtual CPU, should result in reset and
1610 * halting till Startup IPI.
1611 *
1612 * @param pDevIns The APIC device instance.
1613 * @param idCpu Virtual CPU to perform INIT IPI on.
1614 */
1615 DECLR3CALLBACKMEMBER(void, pfnSendInitIpi,(PPDMDEVINS pDevIns, VMCPUID idCpu));
1616
1617 /**
1618 * Gets the address of the RC APIC helpers.
1619 *
1620 * This should be called at both construction and relocation time
1621 * to obtain the correct address of the RC helpers.
1622 *
1623 * @returns GC pointer to the APIC helpers.
1624 * @param pDevIns Device instance of the APIC.
1625 */
1626 DECLR3CALLBACKMEMBER(PCPDMAPICHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1627
1628 /**
1629 * Gets the address of the R0 APIC helpers.
1630 *
1631 * This should be called at both construction and relocation time
1632 * to obtain the correct address of the R0 helpers.
1633 *
1634 * @returns R0 pointer to the APIC helpers.
1635 * @param pDevIns Device instance of the APIC.
1636 */
1637 DECLR3CALLBACKMEMBER(PCPDMAPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1638
1639 /**
1640 * Get the critical section used to synchronize the PICs, PCI and stuff.
1641 *
1642 * @returns Ring-3 pointer to the critical section.
1643 * @param pDevIns The APIC device instance.
1644 */
1645 DECLR3CALLBACKMEMBER(R3PTRTYPE(PPDMCRITSECT), pfnGetR3CritSect,(PPDMDEVINS pDevIns));
1646
1647 /**
1648 * Get the critical section used to synchronize the PICs, PCI and stuff.
1649 *
1650 * @returns Raw-mode context pointer to the critical section.
1651 * @param pDevIns The APIC device instance.
1652 */
1653 DECLR3CALLBACKMEMBER(RCPTRTYPE(PPDMCRITSECT), pfnGetRCCritSect,(PPDMDEVINS pDevIns));
1654
1655 /**
1656 * Get the critical section used to synchronize the PICs, PCI and stuff.
1657 *
1658 * @returns Ring-0 pointer to the critical section.
1659 * @param pDevIns The APIC device instance.
1660 */
1661 DECLR3CALLBACKMEMBER(R0PTRTYPE(PPDMCRITSECT), pfnGetR0CritSect,(PPDMDEVINS pDevIns));
1662
1663 /** Just a safety precaution. */
1664 uint32_t u32TheEnd;
1665} PDMAPICHLPR3;
1666/** Pointer to APIC helpers. */
1667typedef R3PTRTYPE(PDMAPICHLPR3 *) PPDMAPICHLPR3;
1668/** Pointer to const APIC helpers. */
1669typedef R3PTRTYPE(const PDMAPICHLPR3 *) PCPDMAPICHLPR3;
1670
1671/** Current PDMAPICHLP version number. */
1672#define PDM_APICHLPR3_VERSION PDM_VERSION_MAKE(0xfff3, 4, 0)
1673
1674
1675/**
1676 * I/O APIC registration structure.
1677 */
1678typedef struct PDMIOAPICREG
1679{
1680 /** Struct version+magic number (PDM_IOAPICREG_VERSION). */
1681 uint32_t u32Version;
1682
1683 /**
1684 * Set an IRQ.
1685 *
1686 * @param pDevIns Device instance of the I/O APIC.
1687 * @param iIrq IRQ number to set.
1688 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
1689 * @param uTagSrc The IRQ tag and source (for tracing).
1690 * @remarks Caller enters the PDM critical section
1691 */
1692 DECLR3CALLBACKMEMBER(void, pfnSetIrqR3,(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc));
1693
1694 /** The name of the RC SetIrq entry point. */
1695 const char *pszSetIrqRC;
1696
1697 /** The name of the R0 SetIrq entry point. */
1698 const char *pszSetIrqR0;
1699
1700 /**
1701 * Send a MSI.
1702 *
1703 * @param pDevIns Device instance of the I/O APIC.
1704 * @param GCPhys Request address.
1705 * @param uValue Request value.
1706 * @param uTagSrc The IRQ tag and source (for tracing).
1707 * @remarks Caller enters the PDM critical section
1708 */
1709 DECLR3CALLBACKMEMBER(void, pfnSendMsiR3,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc));
1710
1711 /** The name of the RC SendMsi entry point. */
1712 const char *pszSendMsiRC;
1713
1714 /** The name of the R0 SendMsi entry point. */
1715 const char *pszSendMsiR0;
1716
1717 /**
1718 * Set the EOI for an interrupt vector.
1719 *
1720 * @returns VBox status code.
1721 * @param pDevIns Device instance of the I/O APIC.
1722 * @param u8Vector The vector.
1723 * @remarks Caller enters the PDM critical section
1724 */
1725 DECLR3CALLBACKMEMBER(int, pfnSetEoiR3,(PPDMDEVINS pDevIns, uint8_t u8Vector));
1726
1727 /** The name of the RC SetEoi entry point. */
1728 const char *pszSetEoiRC;
1729
1730 /** The name of the R0 SetEoi entry point. */
1731 const char *pszSetEoiR0;
1732} PDMIOAPICREG;
1733/** Pointer to an APIC registration structure. */
1734typedef PDMIOAPICREG *PPDMIOAPICREG;
1735
1736/** Current PDMAPICREG version number. */
1737#define PDM_IOAPICREG_VERSION PDM_VERSION_MAKE(0xfff2, 5, 0)
1738
1739
1740/**
1741 * IOAPIC RC helpers.
1742 */
1743typedef struct PDMIOAPICHLPRC
1744{
1745 /** Structure version. PDM_IOAPICHLPRC_VERSION defines the current version. */
1746 uint32_t u32Version;
1747
1748 /**
1749 * Private interface between the IOAPIC and APIC.
1750 *
1751 * See comments about this hack on PDMAPICREG::pfnBusDeliverR3.
1752 *
1753 * @returns status code.
1754 * @param pDevIns Device instance of the IOAPIC.
1755 * @param u8Dest See APIC implementation.
1756 * @param u8DestMode See APIC implementation.
1757 * @param u8DeliveryMode See APIC implementation.
1758 * @param iVector See APIC implementation.
1759 * @param u8Polarity See APIC implementation.
1760 * @param u8TriggerMode See APIC implementation.
1761 * @param uTagSrc The IRQ tag and source (for tracing).
1762 */
1763 DECLRCCALLBACKMEMBER(int, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1764 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
1765
1766 /**
1767 * Acquires the PDM lock.
1768 *
1769 * @returns VINF_SUCCESS on success.
1770 * @returns rc if we failed to acquire the lock.
1771 * @param pDevIns The IOAPIC device instance.
1772 * @param rc What to return if we fail to acquire the lock.
1773 */
1774 DECLRCCALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1775
1776 /**
1777 * Releases the PDM lock.
1778 *
1779 * @param pDevIns The IOAPIC device instance.
1780 */
1781 DECLRCCALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1782
1783 /** Just a safety precaution. */
1784 uint32_t u32TheEnd;
1785} PDMIOAPICHLPRC;
1786/** Pointer to IOAPIC RC helpers. */
1787typedef RCPTRTYPE(PDMIOAPICHLPRC *) PPDMIOAPICHLPRC;
1788/** Pointer to const IOAPIC helpers. */
1789typedef RCPTRTYPE(const PDMIOAPICHLPRC *) PCPDMIOAPICHLPRC;
1790
1791/** Current PDMIOAPICHLPRC version number. */
1792#define PDM_IOAPICHLPRC_VERSION PDM_VERSION_MAKE(0xfff1, 2, 0)
1793
1794
1795/**
1796 * IOAPIC R0 helpers.
1797 */
1798typedef struct PDMIOAPICHLPR0
1799{
1800 /** Structure version. PDM_IOAPICHLPR0_VERSION defines the current version. */
1801 uint32_t u32Version;
1802
1803 /**
1804 * Private interface between the IOAPIC and APIC.
1805 *
1806 * See comments about this hack on PDMAPICREG::pfnBusDeliverR3.
1807 *
1808 * @returns status code.
1809 * @param pDevIns Device instance of the IOAPIC.
1810 * @param u8Dest See APIC implementation.
1811 * @param u8DestMode See APIC implementation.
1812 * @param u8DeliveryMode See APIC implementation.
1813 * @param iVector See APIC implementation.
1814 * @param u8Polarity See APIC implementation.
1815 * @param u8TriggerMode See APIC implementation.
1816 * @param uTagSrc The IRQ tag and source (for tracing).
1817 */
1818 DECLR0CALLBACKMEMBER(int, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1819 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
1820
1821 /**
1822 * Acquires the PDM lock.
1823 *
1824 * @returns VINF_SUCCESS on success.
1825 * @returns rc if we failed to acquire the lock.
1826 * @param pDevIns The IOAPIC device instance.
1827 * @param rc What to return if we fail to acquire the lock.
1828 */
1829 DECLR0CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1830
1831 /**
1832 * Releases the PDM lock.
1833 *
1834 * @param pDevIns The IOAPIC device instance.
1835 */
1836 DECLR0CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1837
1838 /** Just a safety precaution. */
1839 uint32_t u32TheEnd;
1840} PDMIOAPICHLPR0;
1841/** Pointer to IOAPIC R0 helpers. */
1842typedef R0PTRTYPE(PDMIOAPICHLPR0 *) PPDMIOAPICHLPR0;
1843/** Pointer to const IOAPIC helpers. */
1844typedef R0PTRTYPE(const PDMIOAPICHLPR0 *) PCPDMIOAPICHLPR0;
1845
1846/** Current PDMIOAPICHLPR0 version number. */
1847#define PDM_IOAPICHLPR0_VERSION PDM_VERSION_MAKE(0xfff0, 2, 0)
1848
1849/**
1850 * IOAPIC R3 helpers.
1851 */
1852typedef struct PDMIOAPICHLPR3
1853{
1854 /** Structure version. PDM_IOAPICHLPR3_VERSION defines the current version. */
1855 uint32_t u32Version;
1856
1857 /**
1858 * Private interface between the IOAPIC and APIC.
1859 *
1860 * See comments about this hack on PDMAPICREG::pfnBusDeliverR3.
1861 *
1862 * @returns status code
1863 * @param pDevIns Device instance of the IOAPIC.
1864 * @param u8Dest See APIC implementation.
1865 * @param u8DestMode See APIC implementation.
1866 * @param u8DeliveryMode See APIC implementation.
1867 * @param iVector See APIC implementation.
1868 * @param u8Polarity See APIC implementation.
1869 * @param u8TriggerMode See APIC implementation.
1870 * @param uTagSrc The IRQ tag and source (for tracing).
1871 */
1872 DECLR3CALLBACKMEMBER(int, pfnApicBusDeliver,(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
1873 uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc));
1874
1875 /**
1876 * Acquires the PDM lock.
1877 *
1878 * @returns VINF_SUCCESS on success.
1879 * @returns Fatal error on failure.
1880 * @param pDevIns The IOAPIC device instance.
1881 * @param rc Dummy for making the interface identical to the GC and R0 versions.
1882 */
1883 DECLR3CALLBACKMEMBER(int, pfnLock,(PPDMDEVINS pDevIns, int rc));
1884
1885 /**
1886 * Releases the PDM lock.
1887 *
1888 * @param pDevIns The IOAPIC device instance.
1889 */
1890 DECLR3CALLBACKMEMBER(void, pfnUnlock,(PPDMDEVINS pDevIns));
1891
1892 /**
1893 * Gets the address of the RC IOAPIC helpers.
1894 *
1895 * This should be called at both construction and relocation time
1896 * to obtain the correct address of the RC helpers.
1897 *
1898 * @returns RC pointer to the IOAPIC helpers.
1899 * @param pDevIns Device instance of the IOAPIC.
1900 */
1901 DECLR3CALLBACKMEMBER(PCPDMIOAPICHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
1902
1903 /**
1904 * Gets the address of the R0 IOAPIC helpers.
1905 *
1906 * This should be called at both construction and relocation time
1907 * to obtain the correct address of the R0 helpers.
1908 *
1909 * @returns R0 pointer to the IOAPIC helpers.
1910 * @param pDevIns Device instance of the IOAPIC.
1911 */
1912 DECLR3CALLBACKMEMBER(PCPDMIOAPICHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
1913
1914 /** Just a safety precaution. */
1915 uint32_t u32TheEnd;
1916} PDMIOAPICHLPR3;
1917/** Pointer to IOAPIC R3 helpers. */
1918typedef R3PTRTYPE(PDMIOAPICHLPR3 *) PPDMIOAPICHLPR3;
1919/** Pointer to const IOAPIC helpers. */
1920typedef R3PTRTYPE(const PDMIOAPICHLPR3 *) PCPDMIOAPICHLPR3;
1921
1922/** Current PDMIOAPICHLPR3 version number. */
1923#define PDM_IOAPICHLPR3_VERSION PDM_VERSION_MAKE(0xffef, 2, 0)
1924
1925
1926/**
1927 * HPET registration structure.
1928 */
1929typedef struct PDMHPETREG
1930{
1931 /** Struct version+magic number (PDM_HPETREG_VERSION). */
1932 uint32_t u32Version;
1933
1934} PDMHPETREG;
1935/** Pointer to an HPET registration structure. */
1936typedef PDMHPETREG *PPDMHPETREG;
1937
1938/** Current PDMHPETREG version number. */
1939#define PDM_HPETREG_VERSION PDM_VERSION_MAKE(0xffe2, 1, 0)
1940
1941/**
1942 * HPET RC helpers.
1943 *
1944 * @remarks Keep this around in case HPET will need PDM interaction in again RC
1945 * at some later point.
1946 */
1947typedef struct PDMHPETHLPRC
1948{
1949 /** Structure version. PDM_HPETHLPRC_VERSION defines the current version. */
1950 uint32_t u32Version;
1951
1952 /** Just a safety precaution. */
1953 uint32_t u32TheEnd;
1954} PDMHPETHLPRC;
1955
1956/** Pointer to HPET RC helpers. */
1957typedef RCPTRTYPE(PDMHPETHLPRC *) PPDMHPETHLPRC;
1958/** Pointer to const HPET RC helpers. */
1959typedef RCPTRTYPE(const PDMHPETHLPRC *) PCPDMHPETHLPRC;
1960
1961/** Current PDMHPETHLPRC version number. */
1962#define PDM_HPETHLPRC_VERSION PDM_VERSION_MAKE(0xffee, 2, 0)
1963
1964
1965/**
1966 * HPET R0 helpers.
1967 *
1968 * @remarks Keep this around in case HPET will need PDM interaction in again R0
1969 * at some later point.
1970 */
1971typedef struct PDMHPETHLPR0
1972{
1973 /** Structure version. PDM_HPETHLPR0_VERSION defines the current version. */
1974 uint32_t u32Version;
1975
1976 /** Just a safety precaution. */
1977 uint32_t u32TheEnd;
1978} PDMHPETHLPR0;
1979
1980/** Pointer to HPET R0 helpers. */
1981typedef R0PTRTYPE(PDMHPETHLPR0 *) PPDMHPETHLPR0;
1982/** Pointer to const HPET R0 helpers. */
1983typedef R0PTRTYPE(const PDMHPETHLPR0 *) PCPDMHPETHLPR0;
1984
1985/** Current PDMHPETHLPR0 version number. */
1986#define PDM_HPETHLPR0_VERSION PDM_VERSION_MAKE(0xffed, 2, 0)
1987
1988/**
1989 * HPET R3 helpers.
1990 */
1991typedef struct PDMHPETHLPR3
1992{
1993 /** Structure version. PDM_HPETHLP_VERSION defines the current version. */
1994 uint32_t u32Version;
1995
1996 /**
1997 * Gets the address of the RC HPET helpers.
1998 *
1999 * This should be called at both construction and relocation time
2000 * to obtain the correct address of the RC helpers.
2001 *
2002 * @returns RC pointer to the HPET helpers.
2003 * @param pDevIns Device instance of the HPET.
2004 */
2005 DECLR3CALLBACKMEMBER(PCPDMHPETHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
2006
2007 /**
2008 * Gets the address of the R0 HPET helpers.
2009 *
2010 * This should be called at both construction and relocation time
2011 * to obtain the correct address of the R0 helpers.
2012 *
2013 * @returns R0 pointer to the HPET helpers.
2014 * @param pDevIns Device instance of the HPET.
2015 */
2016 DECLR3CALLBACKMEMBER(PCPDMHPETHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
2017
2018 /**
2019 * Set legacy mode on PIT and RTC.
2020 *
2021 * @returns VINF_SUCCESS on success.
2022 * @returns rc if we failed to set legacy mode.
2023 * @param pDevIns Device instance of the HPET.
2024 * @param fActivated Whether legacy mode is activated or deactivated.
2025 */
2026 DECLR3CALLBACKMEMBER(int, pfnSetLegacyMode,(PPDMDEVINS pDevIns, bool fActivated));
2027
2028
2029 /**
2030 * Set IRQ, bypassing ISA bus override rules.
2031 *
2032 * @returns VINF_SUCCESS on success.
2033 * @returns rc if we failed to set legacy mode.
2034 * @param pDevIns Device instance of the HPET.
2035 * @param iIrq IRQ number to set.
2036 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
2037 */
2038 DECLR3CALLBACKMEMBER(int, pfnSetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
2039
2040 /** Just a safety precaution. */
2041 uint32_t u32TheEnd;
2042} PDMHPETHLPR3;
2043
2044/** Pointer to HPET R3 helpers. */
2045typedef R3PTRTYPE(PDMHPETHLPR3 *) PPDMHPETHLPR3;
2046/** Pointer to const HPET R3 helpers. */
2047typedef R3PTRTYPE(const PDMHPETHLPR3 *) PCPDMHPETHLPR3;
2048
2049/** Current PDMHPETHLPR3 version number. */
2050#define PDM_HPETHLPR3_VERSION PDM_VERSION_MAKE(0xffec, 2, 0)
2051
2052
2053/**
2054 * Raw PCI device registration structure.
2055 */
2056typedef struct PDMPCIRAWREG
2057{
2058 /** Struct version+magic number (PDM_PCIRAWREG_VERSION). */
2059 uint32_t u32Version;
2060 /** Just a safety precaution. */
2061 uint32_t u32TheEnd;
2062} PDMPCIRAWREG;
2063/** Pointer to a raw PCI registration structure. */
2064typedef PDMPCIRAWREG *PPDMPCIRAWREG;
2065
2066/** Current PDMPCIRAWREG version number. */
2067#define PDM_PCIRAWREG_VERSION PDM_VERSION_MAKE(0xffe1, 1, 0)
2068
2069/**
2070 * Raw PCI device raw-mode context helpers.
2071 */
2072typedef struct PDMPCIRAWHLPRC
2073{
2074 /** Structure version and magic number (PDM_PCIRAWHLPRC_VERSION). */
2075 uint32_t u32Version;
2076 /** Just a safety precaution. */
2077 uint32_t u32TheEnd;
2078} PDMPCIRAWHLPRC;
2079/** Pointer to a raw PCI deviec raw-mode context helper structure. */
2080typedef RCPTRTYPE(PDMPCIRAWHLPRC *) PPDMPCIRAWHLPRC;
2081/** Pointer to a const raw PCI deviec raw-mode context helper structure. */
2082typedef RCPTRTYPE(const PDMPCIRAWHLPRC *) PCPDMPCIRAWHLPRC;
2083
2084/** Current PDMPCIRAWHLPRC version number. */
2085#define PDM_PCIRAWHLPRC_VERSION PDM_VERSION_MAKE(0xffe0, 1, 0)
2086
2087/**
2088 * Raw PCI device ring-0 context helpers.
2089 */
2090typedef struct PDMPCIRAWHLPR0
2091{
2092 /** Structure version and magic number (PDM_PCIRAWHLPR0_VERSION). */
2093 uint32_t u32Version;
2094 /** Just a safety precaution. */
2095 uint32_t u32TheEnd;
2096} PDMPCIRAWHLPR0;
2097/** Pointer to a raw PCI deviec ring-0 context helper structure. */
2098typedef R0PTRTYPE(PDMPCIRAWHLPR0 *) PPDMPCIRAWHLPR0;
2099/** Pointer to a const raw PCI deviec ring-0 context helper structure. */
2100typedef R0PTRTYPE(const PDMPCIRAWHLPR0 *) PCPDMPCIRAWHLPR0;
2101
2102/** Current PDMPCIRAWHLPR0 version number. */
2103#define PDM_PCIRAWHLPR0_VERSION PDM_VERSION_MAKE(0xffdf, 1, 0)
2104
2105
2106/**
2107 * Raw PCI device ring-3 context helpers.
2108 */
2109typedef struct PDMPCIRAWHLPR3
2110{
2111 /** Undefined structure version and magic number. */
2112 uint32_t u32Version;
2113
2114 /**
2115 * Gets the address of the RC raw PCI device helpers.
2116 *
2117 * This should be called at both construction and relocation time to obtain
2118 * the correct address of the RC helpers.
2119 *
2120 * @returns RC pointer to the raw PCI device helpers.
2121 * @param pDevIns Device instance of the raw PCI device.
2122 */
2123 DECLR3CALLBACKMEMBER(PCPDMPCIRAWHLPRC, pfnGetRCHelpers,(PPDMDEVINS pDevIns));
2124
2125 /**
2126 * Gets the address of the R0 raw PCI device helpers.
2127 *
2128 * This should be called at both construction and relocation time to obtain
2129 * the correct address of the R0 helpers.
2130 *
2131 * @returns R0 pointer to the raw PCI device helpers.
2132 * @param pDevIns Device instance of the raw PCI device.
2133 */
2134 DECLR3CALLBACKMEMBER(PCPDMPCIRAWHLPR0, pfnGetR0Helpers,(PPDMDEVINS pDevIns));
2135
2136 /** Just a safety precaution. */
2137 uint32_t u32TheEnd;
2138} PDMPCIRAWHLPR3;
2139/** Pointer to raw PCI R3 helpers. */
2140typedef R3PTRTYPE(PDMPCIRAWHLPR3 *) PPDMPCIRAWHLPR3;
2141/** Pointer to const raw PCI R3 helpers. */
2142typedef R3PTRTYPE(const PDMPCIRAWHLPR3 *) PCPDMPCIRAWHLPR3;
2143
2144/** Current PDMPCIRAWHLPR3 version number. */
2145#define PDM_PCIRAWHLPR3_VERSION PDM_VERSION_MAKE(0xffde, 1, 0)
2146
2147
2148#ifdef IN_RING3
2149
2150/**
2151 * DMA Transfer Handler.
2152 *
2153 * @returns Number of bytes transferred.
2154 * @param pDevIns Device instance of the DMA.
2155 * @param pvUser User pointer.
2156 * @param uChannel Channel number.
2157 * @param off DMA position.
2158 * @param cb Block size.
2159 * @remarks The device lock is not taken, however, the DMA device lock is held.
2160 */
2161typedef DECLCALLBACK(uint32_t) FNDMATRANSFERHANDLER(PPDMDEVINS pDevIns, void *pvUser, unsigned uChannel, uint32_t off, uint32_t cb);
2162/** Pointer to a FNDMATRANSFERHANDLER(). */
2163typedef FNDMATRANSFERHANDLER *PFNDMATRANSFERHANDLER;
2164
2165/**
2166 * DMA Controller registration structure.
2167 */
2168typedef struct PDMDMAREG
2169{
2170 /** Structure version number. PDM_DMACREG_VERSION defines the current version. */
2171 uint32_t u32Version;
2172
2173 /**
2174 * Execute pending transfers.
2175 *
2176 * @returns A more work indiciator. I.e. 'true' if there is more to be done, and 'false' if all is done.
2177 * @param pDevIns Device instance of the DMAC.
2178 * @remarks No locks held, called on EMT(0) as a form of serialization.
2179 */
2180 DECLR3CALLBACKMEMBER(bool, pfnRun,(PPDMDEVINS pDevIns));
2181
2182 /**
2183 * Register transfer function for DMA channel.
2184 *
2185 * @param pDevIns Device instance of the DMAC.
2186 * @param uChannel Channel number.
2187 * @param pfnTransferHandler Device specific transfer function.
2188 * @param pvUSer User pointer to be passed to the callback.
2189 * @remarks No locks held, called on an EMT.
2190 */
2191 DECLR3CALLBACKMEMBER(void, pfnRegister,(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser));
2192
2193 /**
2194 * Read memory
2195 *
2196 * @returns Number of bytes read.
2197 * @param pDevIns Device instance of the DMAC.
2198 * @param pvBuffer Pointer to target buffer.
2199 * @param off DMA position.
2200 * @param cbBlock Block size.
2201 * @remarks No locks held, called on an EMT.
2202 */
2203 DECLR3CALLBACKMEMBER(uint32_t, pfnReadMemory,(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock));
2204
2205 /**
2206 * Write memory
2207 *
2208 * @returns Number of bytes written.
2209 * @param pDevIns Device instance of the DMAC.
2210 * @param pvBuffer Memory to write.
2211 * @param off DMA position.
2212 * @param cbBlock Block size.
2213 * @remarks No locks held, called on an EMT.
2214 */
2215 DECLR3CALLBACKMEMBER(uint32_t, pfnWriteMemory,(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock));
2216
2217 /**
2218 * Set the DREQ line.
2219 *
2220 * @param pDevIns Device instance of the DMAC.
2221 * @param uChannel Channel number.
2222 * @param uLevel Level of the line.
2223 * @remarks No locks held, called on an EMT.
2224 */
2225 DECLR3CALLBACKMEMBER(void, pfnSetDREQ,(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel));
2226
2227 /**
2228 * Get channel mode
2229 *
2230 * @returns Channel mode.
2231 * @param pDevIns Device instance of the DMAC.
2232 * @param uChannel Channel number.
2233 * @remarks No locks held, called on an EMT.
2234 */
2235 DECLR3CALLBACKMEMBER(uint8_t, pfnGetChannelMode,(PPDMDEVINS pDevIns, unsigned uChannel));
2236
2237} PDMDMACREG;
2238/** Pointer to a DMAC registration structure. */
2239typedef PDMDMACREG *PPDMDMACREG;
2240
2241/** Current PDMDMACREG version number. */
2242#define PDM_DMACREG_VERSION PDM_VERSION_MAKE(0xffeb, 1, 0)
2243
2244
2245/**
2246 * DMA Controller device helpers.
2247 */
2248typedef struct PDMDMACHLP
2249{
2250 /** Structure version. PDM_DMACHLP_VERSION defines the current version. */
2251 uint32_t u32Version;
2252
2253 /* to-be-defined */
2254
2255} PDMDMACHLP;
2256/** Pointer to DMAC helpers. */
2257typedef PDMDMACHLP *PPDMDMACHLP;
2258/** Pointer to const DMAC helpers. */
2259typedef const PDMDMACHLP *PCPDMDMACHLP;
2260
2261/** Current PDMDMACHLP version number. */
2262#define PDM_DMACHLP_VERSION PDM_VERSION_MAKE(0xffea, 1, 0)
2263
2264#endif /* IN_RING3 */
2265
2266
2267
2268/**
2269 * RTC registration structure.
2270 */
2271typedef struct PDMRTCREG
2272{
2273 /** Structure version number. PDM_RTCREG_VERSION defines the current version. */
2274 uint32_t u32Version;
2275 uint32_t u32Alignment; /**< structure size alignment. */
2276
2277 /**
2278 * Write to a CMOS register and update the checksum if necessary.
2279 *
2280 * @returns VBox status code.
2281 * @param pDevIns Device instance of the RTC.
2282 * @param iReg The CMOS register index.
2283 * @param u8Value The CMOS register value.
2284 * @remarks Caller enters the device critical section.
2285 */
2286 DECLR3CALLBACKMEMBER(int, pfnWrite,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value));
2287
2288 /**
2289 * Read a CMOS register.
2290 *
2291 * @returns VBox status code.
2292 * @param pDevIns Device instance of the RTC.
2293 * @param iReg The CMOS register index.
2294 * @param pu8Value Where to store the CMOS register value.
2295 * @remarks Caller enters the device critical section.
2296 */
2297 DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value));
2298
2299} PDMRTCREG;
2300/** Pointer to a RTC registration structure. */
2301typedef PDMRTCREG *PPDMRTCREG;
2302/** Pointer to a const RTC registration structure. */
2303typedef const PDMRTCREG *PCPDMRTCREG;
2304
2305/** Current PDMRTCREG version number. */
2306#define PDM_RTCREG_VERSION PDM_VERSION_MAKE(0xffe9, 2, 0)
2307
2308
2309/**
2310 * RTC device helpers.
2311 */
2312typedef struct PDMRTCHLP
2313{
2314 /** Structure version. PDM_RTCHLP_VERSION defines the current version. */
2315 uint32_t u32Version;
2316
2317 /* to-be-defined */
2318
2319} PDMRTCHLP;
2320/** Pointer to RTC helpers. */
2321typedef PDMRTCHLP *PPDMRTCHLP;
2322/** Pointer to const RTC helpers. */
2323typedef const PDMRTCHLP *PCPDMRTCHLP;
2324
2325/** Current PDMRTCHLP version number. */
2326#define PDM_RTCHLP_VERSION PDM_VERSION_MAKE(0xffe8, 1, 0)
2327
2328
2329
2330#ifdef IN_RING3
2331
2332/**
2333 * PDM Device API.
2334 */
2335typedef struct PDMDEVHLPR3
2336{
2337 /** Structure version. PDM_DEVHLPR3_VERSION defines the current version. */
2338 uint32_t u32Version;
2339
2340 /**
2341 * Register a number of I/O ports with a device.
2342 *
2343 * These callbacks are of course for the host context (HC).
2344 * Register HC handlers before guest context (GC) handlers! There must be a
2345 * HC handler for every GC handler!
2346 *
2347 * @returns VBox status.
2348 * @param pDevIns The device instance to register the ports with.
2349 * @param Port First port number in the range.
2350 * @param cPorts Number of ports to register.
2351 * @param pvUser User argument.
2352 * @param pfnOut Pointer to function which is gonna handle OUT operations.
2353 * @param pfnIn Pointer to function which is gonna handle IN operations.
2354 * @param pfnOutStr Pointer to function which is gonna handle string OUT operations.
2355 * @param pfnInStr Pointer to function which is gonna handle string IN operations.
2356 * @param pszDesc Pointer to description string. This must not be freed.
2357 * @remarks Caller enters the device critical section prior to invoking the
2358 * registered callback methods.
2359 */
2360 DECLR3CALLBACKMEMBER(int, pfnIOPortRegister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser,
2361 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
2362 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc));
2363
2364 /**
2365 * Register a number of I/O ports with a device for RC.
2366 *
2367 * These callbacks are for the raw-mode context (RC). Register ring-3 context
2368 * (R3) handlers before raw-mode context handlers! There must be a R3 handler
2369 * for every RC handler!
2370 *
2371 * @returns VBox status.
2372 * @param pDevIns The device instance to register the ports with
2373 * and which RC module to resolve the names
2374 * against.
2375 * @param Port First port number in the range.
2376 * @param cPorts Number of ports to register.
2377 * @param pvUser User argument.
2378 * @param pszOut Name of the RC function which is gonna handle OUT operations.
2379 * @param pszIn Name of the RC function which is gonna handle IN operations.
2380 * @param pszOutStr Name of the RC function which is gonna handle string OUT operations.
2381 * @param pszInStr Name of the RC function which is gonna handle string IN operations.
2382 * @param pszDesc Pointer to description string. This must not be freed.
2383 * @remarks Caller enters the device critical section prior to invoking the
2384 * registered callback methods.
2385 */
2386 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterRC,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
2387 const char *pszOut, const char *pszIn,
2388 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
2389
2390 /**
2391 * Register a number of I/O ports with a device.
2392 *
2393 * These callbacks are of course for the ring-0 host context (R0).
2394 * Register R3 (HC) handlers before R0 (R0) handlers! There must be a R3 (HC) handler for every R0 handler!
2395 *
2396 * @returns VBox status.
2397 * @param pDevIns The device instance to register the ports with.
2398 * @param Port First port number in the range.
2399 * @param cPorts Number of ports to register.
2400 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
2401 * @param pszOut Name of the R0 function which is gonna handle OUT operations.
2402 * @param pszIn Name of the R0 function which is gonna handle IN operations.
2403 * @param pszOutStr Name of the R0 function which is gonna handle string OUT operations.
2404 * @param pszInStr Name of the R0 function which is gonna handle string IN operations.
2405 * @param pszDesc Pointer to description string. This must not be freed.
2406 * @remarks Caller enters the device critical section prior to invoking the
2407 * registered callback methods.
2408 */
2409 DECLR3CALLBACKMEMBER(int, pfnIOPortRegisterR0,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
2410 const char *pszOut, const char *pszIn,
2411 const char *pszOutStr, const char *pszInStr, const char *pszDesc));
2412
2413 /**
2414 * Deregister I/O ports.
2415 *
2416 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
2417 *
2418 * @returns VBox status.
2419 * @param pDevIns The device instance owning the ports.
2420 * @param Port First port number in the range.
2421 * @param cPorts Number of ports to deregister.
2422 */
2423 DECLR3CALLBACKMEMBER(int, pfnIOPortDeregister,(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts));
2424
2425 /**
2426 * Register a Memory Mapped I/O (MMIO) region.
2427 *
2428 * These callbacks are of course for the ring-3 context (R3). Register HC
2429 * handlers before raw-mode context (RC) and ring-0 context (R0) handlers! There
2430 * must be a R3 handler for every RC and R0 handler!
2431 *
2432 * @returns VBox status.
2433 * @param pDevIns The device instance to register the MMIO with.
2434 * @param GCPhysStart First physical address in the range.
2435 * @param cbRange The size of the range (in bytes).
2436 * @param pvUser User argument.
2437 * @param pfnWrite Pointer to function which is gonna handle Write operations.
2438 * @param pfnRead Pointer to function which is gonna handle Read operations.
2439 * @param pfnFill Pointer to function which is gonna handle Fill/memset operations. (optional)
2440 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
2441 * @param pszDesc Pointer to description string. This must not be freed.
2442 * @remarks Caller enters the device critical section prior to invoking the
2443 * registered callback methods.
2444 */
2445 DECLR3CALLBACKMEMBER(int, pfnMMIORegister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTHCPTR pvUser,
2446 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
2447 uint32_t fFlags, const char *pszDesc));
2448
2449 /**
2450 * Register a Memory Mapped I/O (MMIO) region for RC.
2451 *
2452 * These callbacks are for the raw-mode context (RC). Register ring-3 context
2453 * (R3) handlers before guest context handlers! There must be a R3 handler for
2454 * every RC handler!
2455 *
2456 * @returns VBox status.
2457 * @param pDevIns The device instance to register the MMIO with.
2458 * @param GCPhysStart First physical address in the range.
2459 * @param cbRange The size of the range (in bytes).
2460 * @param pvUser User argument.
2461 * @param pszWrite Name of the RC function which is gonna handle Write operations.
2462 * @param pszRead Name of the RC function which is gonna handle Read operations.
2463 * @param pszFill Name of the RC function which is gonna handle Fill/memset operations. (optional)
2464 * @remarks Caller enters the device critical section prior to invoking the
2465 * registered callback methods.
2466 */
2467 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterRC,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTRCPTR pvUser,
2468 const char *pszWrite, const char *pszRead, const char *pszFill));
2469
2470 /**
2471 * Register a Memory Mapped I/O (MMIO) region for R0.
2472 *
2473 * These callbacks are for the ring-0 host context (R0). Register ring-3
2474 * constext (R3) handlers before R0 handlers! There must be a R3 handler for
2475 * every R0 handler!
2476 *
2477 * @returns VBox status.
2478 * @param pDevIns The device instance to register the MMIO with.
2479 * @param GCPhysStart First physical address in the range.
2480 * @param cbRange The size of the range (in bytes).
2481 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
2482 * @param pszWrite Name of the RC function which is gonna handle Write operations.
2483 * @param pszRead Name of the RC function which is gonna handle Read operations.
2484 * @param pszFill Name of the RC function which is gonna handle Fill/memset operations. (optional)
2485 * @remarks Caller enters the device critical section prior to invoking the
2486 * registered callback methods.
2487 */
2488 DECLR3CALLBACKMEMBER(int, pfnMMIORegisterR0,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTR0PTR pvUser,
2489 const char *pszWrite, const char *pszRead, const char *pszFill));
2490
2491 /**
2492 * Deregister a Memory Mapped I/O (MMIO) region.
2493 *
2494 * This naturally affects both guest context (GC), ring-0 (R0) and ring-3 (R3/HC) handlers.
2495 *
2496 * @returns VBox status.
2497 * @param pDevIns The device instance owning the MMIO region(s).
2498 * @param GCPhysStart First physical address in the range.
2499 * @param cbRange The size of the range (in bytes).
2500 */
2501 DECLR3CALLBACKMEMBER(int, pfnMMIODeregister,(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange));
2502
2503 /**
2504 * Allocate and register a MMIO2 region.
2505 *
2506 * As mentioned elsewhere, MMIO2 is just RAM spelled differently. It's
2507 * RAM associated with a device. It is also non-shared memory with a
2508 * permanent ring-3 mapping and page backing (presently).
2509 *
2510 * @returns VBox status.
2511 * @param pDevIns The device instance.
2512 * @param iRegion The region number. Use the PCI region number as
2513 * this must be known to the PCI bus device too. If
2514 * it's not associated with the PCI device, then
2515 * any number up to UINT8_MAX is fine.
2516 * @param cb The size (in bytes) of the region.
2517 * @param fFlags Reserved for future use, must be zero.
2518 * @param ppv Where to store the address of the ring-3 mapping
2519 * of the memory.
2520 * @param pszDesc Pointer to description string. This must not be
2521 * freed.
2522 * @thread EMT.
2523 */
2524 DECLR3CALLBACKMEMBER(int, pfnMMIO2Register,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags,
2525 void **ppv, const char *pszDesc));
2526
2527 /**
2528 * Deregisters and frees a MMIO or MMIO2 region.
2529 *
2530 * Any physical (and virtual) access handlers registered for the region must
2531 * be deregistered before calling this function (MMIO2 only).
2532 *
2533 * @returns VBox status code.
2534 * @param pDevIns The device instance.
2535 * @param iRegion The region number used during registration.
2536 * @thread EMT.
2537 */
2538 DECLR3CALLBACKMEMBER(int, pfnMMIOExDeregister,(PPDMDEVINS pDevIns, uint32_t iRegion));
2539
2540 /**
2541 * Maps a MMIO or MMIO2 region into the physical memory space.
2542 *
2543 * A MMIO2 range or a pre-registered MMIO range may overlap with base memory if
2544 * a lot of RAM is configured for the VM, in which case we'll drop the base
2545 * memory pages. Presently we will make no attempt to preserve anything that
2546 * happens to be present in the base memory that is replaced, this is of course
2547 * incorrect but it's too much 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, pfnMMIOExMap,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys));
2556
2557 /**
2558 * Unmaps a MMIO or MMIO2 region previously mapped using pfnMMIOExMap.
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, pfnMMIOExUnmap,(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 * Pre-register a Memory Mapped I/O (MMIO) region.
3611 *
3612 * This API must be used for large PCI MMIO regions, as it handles these much
3613 * more efficiently and with greater flexibility when it comes to heap usage.
3614 * It is only available during device construction.
3615 *
3616 * To map and unmap the pre-registered region into and our of guest address
3617 * space, use the PDMDevHlpMMIOExMap and PDMDevHlpMMIOExUnmap helpers.
3618 *
3619 * You may call PDMDevHlpMMIOExDeregister from the destructor to free the region
3620 * for reasons of symmetry, but it will be automatically deregistered by PDM
3621 * once the destructor returns.
3622 *
3623 * @returns VBox status.
3624 * @param pDevIns The device instance to register the MMIO with.
3625 * @param iRegion The region number.
3626 * @param cbRegion The size of the range (in bytes).
3627 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
3628 * @param pszDesc Pointer to description string. This must not be freed.
3629 * @param pvUser Ring-3 user argument.
3630 * @param pfnWrite Pointer to function which is gonna handle Write operations.
3631 * @param pfnRead Pointer to function which is gonna handle Read operations.
3632 * @param pfnFill Pointer to function which is gonna handle Fill/memset operations. (optional)
3633 * @param pvUserR0 Ring-0 user argument. Optional.
3634 * @param pszWriteR0 The name of the ring-0 write handler method. Optional.
3635 * @param pszReadR0 The name of the ring-0 read handler method. Optional.
3636 * @param pszFillR0 The name of the ring-0 fill/memset handler method. Optional.
3637 * @param pvUserRC Raw-mode context user argument. Optional. If
3638 * unsigned value is 0x10000 or higher, it will be
3639 * automatically relocated with the hypervisor
3640 * guest mapping.
3641 * @param pszWriteRC The name of the raw-mode context write handler method. Optional.
3642 * @param pszReadRC The name of the raw-mode context read handler method. Optional.
3643 * @param pszFillRC The name of the raw-mode context fill/memset handler method. Optional.
3644 * @thread EMT
3645 *
3646 * @remarks Caller enters the device critical section prior to invoking the
3647 * registered callback methods.
3648 * @sa PDMDevHlpMMIOExMap, PDMDevHlpMMIOExUnmap, PDMDevHlpMMIOExDeregister,
3649 * PDMDevHlpMMIORegisterEx
3650 */
3651 DECLR3CALLBACKMEMBER(int, pfnMMIOExPreRegister,(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cbRegion,
3652 uint32_t fFlags, const char *pszDesc, RTHCPTR pvUser,
3653 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
3654 RTR0PTR pvUserR0, const char *pszWriteR0, const char *pszReadR0, const char *pszFillR0,
3655 RTRCPTR pvUserRC, const char *pszWriteRC, const char *pszReadRC, const char *pszFillRC));
3656
3657 /** Space reserved for future members.
3658 * @{ */
3659 DECLR3CALLBACKMEMBER(void, pfnReserved1,(void));
3660 DECLR3CALLBACKMEMBER(void, pfnReserved2,(void));
3661 DECLR3CALLBACKMEMBER(void, pfnReserved3,(void));
3662 DECLR3CALLBACKMEMBER(void, pfnReserved4,(void));
3663 DECLR3CALLBACKMEMBER(void, pfnReserved5,(void));
3664 DECLR3CALLBACKMEMBER(void, pfnReserved6,(void));
3665 /*DECLR3CALLBACKMEMBER(void, pfnReserved7,(void));
3666 DECLR3CALLBACKMEMBER(void, pfnReserved8,(void));
3667 DECLR3CALLBACKMEMBER(void, pfnReserved9,(void));*/
3668 /*DECLR3CALLBACKMEMBER(void, pfnReserved10,(void));*/
3669 /** @} */
3670
3671
3672 /** API available to trusted devices only.
3673 *
3674 * These APIs are providing unrestricted access to the guest and the VM,
3675 * or they are interacting intimately with PDM.
3676 *
3677 * @{
3678 */
3679
3680 /**
3681 * Gets the user mode VM handle. Restricted API.
3682 *
3683 * @returns User mode VM Handle.
3684 * @param pDevIns The device instance.
3685 */
3686 DECLR3CALLBACKMEMBER(PUVM, pfnGetUVM,(PPDMDEVINS pDevIns));
3687
3688 /**
3689 * Gets the global VM handle. Restricted API.
3690 *
3691 * @returns VM Handle.
3692 * @param pDevIns The device instance.
3693 */
3694 DECLR3CALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
3695
3696 /**
3697 * Gets the VMCPU handle. Restricted API.
3698 *
3699 * @returns VMCPU Handle.
3700 * @param pDevIns The device instance.
3701 */
3702 DECLR3CALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
3703
3704 /**
3705 * The the VM CPU ID of the current thread (restricted API).
3706 *
3707 * @returns The VMCPUID of the calling thread, NIL_CPUID if not EMT.
3708 * @param pDevIns The device instance.
3709 */
3710 DECLR3CALLBACKMEMBER(VMCPUID, pfnGetCurrentCpuId,(PPDMDEVINS pDevIns));
3711
3712 /**
3713 * Registers the VMM device heap or notifies about mapping/unmapping.
3714 *
3715 * This interface serves three purposes:
3716 *
3717 * -# Register the VMM device heap during device construction
3718 * for the HM to use.
3719 * -# Notify PDM/HM that it's mapped into guest address
3720 * space (i.e. usable).
3721 * -# Notify PDM/HM that it is being unmapped from the guest
3722 * address space (i.e. not usable).
3723 *
3724 * @returns VBox status code.
3725 * @param pDevIns The device instance.
3726 * @param GCPhys The physical address if mapped, NIL_RTGCPHYS if
3727 * not mapped.
3728 * @param pvHeap Ring 3 heap pointer.
3729 * @param cbHeap Size of the heap.
3730 * @thread EMT.
3731 */
3732 DECLR3CALLBACKMEMBER(int, pfnRegisterVMMDevHeap,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbHeap));
3733
3734 /**
3735 * Registers the firmware (BIOS, EFI) device with PDM.
3736 *
3737 * The firmware provides a callback table and gets a special PDM helper table.
3738 * There can only be one firmware device for a VM.
3739 *
3740 * @returns VBox status code.
3741 * @param pDevIns The device instance.
3742 * @param pFwReg Firmware registration structure.
3743 * @param ppFwHlp Where to return the firmware helper structure.
3744 * @remarks Only valid during device construction.
3745 * @thread EMT(0)
3746 */
3747 DECLR3CALLBACKMEMBER(int, pfnFirmwareRegister,(PPDMDEVINS pDevIns, PCPDMFWREG pFwReg, PCPDMFWHLPR3 *ppFwHlp));
3748
3749 /**
3750 * Resets the VM.
3751 *
3752 * @returns The appropriate VBox status code to pass around on reset.
3753 * @param pDevIns The device instance.
3754 * @param fFlags PDMVMRESET_F_XXX flags.
3755 * @thread The emulation thread.
3756 */
3757 DECLR3CALLBACKMEMBER(int, pfnVMReset,(PPDMDEVINS pDevIns, uint32_t fFlags));
3758
3759 /**
3760 * Suspends the VM.
3761 *
3762 * @returns The appropriate VBox status code to pass around on suspend.
3763 * @param pDevIns The device instance.
3764 * @thread The emulation thread.
3765 */
3766 DECLR3CALLBACKMEMBER(int, pfnVMSuspend,(PPDMDEVINS pDevIns));
3767
3768 /**
3769 * Suspends, saves and powers off the VM.
3770 *
3771 * @returns The appropriate VBox status code to pass around.
3772 * @param pDevIns The device instance.
3773 * @thread An emulation thread.
3774 */
3775 DECLR3CALLBACKMEMBER(int, pfnVMSuspendSaveAndPowerOff,(PPDMDEVINS pDevIns));
3776
3777 /**
3778 * Power off the VM.
3779 *
3780 * @returns The appropriate VBox status code to pass around on power off.
3781 * @param pDevIns The device instance.
3782 * @thread The emulation thread.
3783 */
3784 DECLR3CALLBACKMEMBER(int, pfnVMPowerOff,(PPDMDEVINS pDevIns));
3785
3786 /**
3787 * Checks if the Gate A20 is enabled or not.
3788 *
3789 * @returns true if A20 is enabled.
3790 * @returns false if A20 is disabled.
3791 * @param pDevIns The device instance.
3792 * @thread The emulation thread.
3793 */
3794 DECLR3CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
3795
3796 /**
3797 * Enables or disables the Gate A20.
3798 *
3799 * @param pDevIns The device instance.
3800 * @param fEnable Set this flag to enable the Gate A20; clear it
3801 * to disable.
3802 * @thread The emulation thread.
3803 */
3804 DECLR3CALLBACKMEMBER(void, pfnA20Set,(PPDMDEVINS pDevIns, bool fEnable));
3805
3806 /**
3807 * Get the specified CPUID leaf for the virtual CPU associated with the calling
3808 * thread.
3809 *
3810 * @param pDevIns The device instance.
3811 * @param iLeaf The CPUID leaf to get.
3812 * @param pEax Where to store the EAX value.
3813 * @param pEbx Where to store the EBX value.
3814 * @param pEcx Where to store the ECX value.
3815 * @param pEdx Where to store the EDX value.
3816 * @thread EMT.
3817 */
3818 DECLR3CALLBACKMEMBER(void, pfnGetCpuId,(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx));
3819
3820 /**
3821 * Get the current virtual clock time in a VM. The clock frequency must be
3822 * queried separately.
3823 *
3824 * @returns Current clock time.
3825 * @param pDevIns The device instance.
3826 */
3827 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
3828
3829 /**
3830 * Get the frequency of the virtual clock.
3831 *
3832 * @returns The clock frequency (not variable at run-time).
3833 * @param pDevIns The device instance.
3834 */
3835 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
3836
3837 /**
3838 * Get the current virtual clock time in a VM, in nanoseconds.
3839 *
3840 * @returns Current clock time (in ns).
3841 * @param pDevIns The device instance.
3842 */
3843 DECLR3CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
3844
3845 /**
3846 * Gets the support driver session.
3847 *
3848 * This is intended for working with the semaphore API.
3849 *
3850 * @returns Support driver session handle.
3851 * @param pDevIns The device instance.
3852 */
3853 DECLR3CALLBACKMEMBER(PSUPDRVSESSION, pfnGetSupDrvSession,(PPDMDEVINS pDevIns));
3854
3855 /** @} */
3856
3857 /** Just a safety precaution. (PDM_DEVHLPR3_VERSION) */
3858 uint32_t u32TheEnd;
3859} PDMDEVHLPR3;
3860#endif /* !IN_RING3 */
3861/** Pointer to the R3 PDM Device API. */
3862typedef R3PTRTYPE(struct PDMDEVHLPR3 *) PPDMDEVHLPR3;
3863/** Pointer to the R3 PDM Device API, const variant. */
3864typedef R3PTRTYPE(const struct PDMDEVHLPR3 *) PCPDMDEVHLPR3;
3865
3866/** Current PDMDEVHLPR3 version number. */
3867/* 5.0 is (18, 0) so the next version for trunk has to be (19, 0)! */
3868#define PDM_DEVHLPR3_VERSION PDM_VERSION_MAKE(0xffe7, 17, 1)
3869
3870
3871/**
3872 * PDM Device API - RC Variant.
3873 */
3874typedef struct PDMDEVHLPRC
3875{
3876 /** Structure version. PDM_DEVHLPRC_VERSION defines the current version. */
3877 uint32_t u32Version;
3878
3879 /**
3880 * Bus master physical memory read.
3881 *
3882 * @returns VINF_SUCCESS or VERR_PGM_PCI_PHYS_READ_BM_DISABLED, later maybe
3883 * VERR_EM_MEMORY. The informational status shall NOT be propagated!
3884 * @param pDevIns The device instance.
3885 * @param GCPhys Physical address start reading from.
3886 * @param pvBuf Where to put the read bits.
3887 * @param cbRead How many bytes to read.
3888 * @thread Any thread, but the call may involve the emulation thread.
3889 */
3890 DECLRCCALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3891
3892 /**
3893 * Bus master physical memory write.
3894 *
3895 * @returns VINF_SUCCESS or VERR_PGM_PCI_PHYS_WRITE_BM_DISABLED, later maybe
3896 * VERR_EM_MEMORY. The informational status shall NOT be propagated!
3897 * @param pDevIns The device instance.
3898 * @param GCPhys Physical address to write to.
3899 * @param pvBuf What to write.
3900 * @param cbWrite How many bytes to write.
3901 * @thread Any thread, but the call may involve the emulation thread.
3902 */
3903 DECLRCCALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3904
3905 /**
3906 * Set the IRQ for a PCI device.
3907 *
3908 * @param pDevIns Device instance.
3909 * @param iIrq IRQ number to set.
3910 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3911 * @thread Any thread, but will involve the emulation thread.
3912 */
3913 DECLRCCALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3914
3915 /**
3916 * Set ISA IRQ for a device.
3917 *
3918 * @param pDevIns Device instance.
3919 * @param iIrq IRQ number to set.
3920 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
3921 * @thread Any thread, but will involve the emulation thread.
3922 */
3923 DECLRCCALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
3924
3925 /**
3926 * Read physical memory.
3927 *
3928 * @returns VINF_SUCCESS (for now).
3929 * @param pDevIns Device instance.
3930 * @param GCPhys Physical address start reading from.
3931 * @param pvBuf Where to put the read bits.
3932 * @param cbRead How many bytes to read.
3933 */
3934 DECLRCCALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
3935
3936 /**
3937 * Write to physical memory.
3938 *
3939 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
3940 * @param pDevIns Device instance.
3941 * @param GCPhys Physical address to write to.
3942 * @param pvBuf What to write.
3943 * @param cbWrite How many bytes to write.
3944 */
3945 DECLRCCALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
3946
3947 /**
3948 * Checks if the Gate A20 is enabled or not.
3949 *
3950 * @returns true if A20 is enabled.
3951 * @returns false if A20 is disabled.
3952 * @param pDevIns Device instance.
3953 * @thread The emulation thread.
3954 */
3955 DECLRCCALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
3956
3957 /**
3958 * Gets the VM state.
3959 *
3960 * @returns VM state.
3961 * @param pDevIns The device instance.
3962 * @thread Any thread (just keep in mind that it's volatile info).
3963 */
3964 DECLRCCALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
3965
3966 /**
3967 * Set the VM error message
3968 *
3969 * @returns rc.
3970 * @param pDevIns Driver instance.
3971 * @param rc VBox status code.
3972 * @param SRC_POS Use RT_SRC_POS.
3973 * @param pszFormat Error message format string.
3974 * @param ... Error message arguments.
3975 */
3976 DECLRCCALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
3977 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(6, 7));
3978
3979 /**
3980 * Set the VM error message
3981 *
3982 * @returns rc.
3983 * @param pDevIns Driver instance.
3984 * @param rc VBox status code.
3985 * @param SRC_POS Use RT_SRC_POS.
3986 * @param pszFormat Error message format string.
3987 * @param va Error message arguments.
3988 */
3989 DECLRCCALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
3990 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(6, 0));
3991
3992 /**
3993 * Set the VM runtime error message
3994 *
3995 * @returns VBox status code.
3996 * @param pDevIns Device instance.
3997 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
3998 * @param pszErrorId Error ID string.
3999 * @param pszFormat Error message format string.
4000 * @param ... Error message arguments.
4001 */
4002 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4003 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5));
4004
4005 /**
4006 * Set the VM runtime error message
4007 *
4008 * @returns VBox status code.
4009 * @param pDevIns Device instance.
4010 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
4011 * @param pszErrorId Error ID string.
4012 * @param pszFormat Error message format string.
4013 * @param va Error message arguments.
4014 */
4015 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4016 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0));
4017
4018 /**
4019 * Set parameters for pending MMIO patch operation
4020 *
4021 * @returns VBox status code.
4022 * @param pDevIns Device instance.
4023 * @param GCPhys MMIO physical address
4024 * @param pCachedData GC pointer to cached data
4025 */
4026 DECLRCCALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
4027
4028 /**
4029 * Gets the VM handle. Restricted API.
4030 *
4031 * @returns VM Handle.
4032 * @param pDevIns Device instance.
4033 */
4034 DECLRCCALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
4035
4036 /**
4037 * Gets the VMCPU handle. Restricted API.
4038 *
4039 * @returns VMCPU Handle.
4040 * @param pDevIns The device instance.
4041 */
4042 DECLRCCALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
4043
4044 /**
4045 * The the VM CPU ID of the current thread (restricted API).
4046 *
4047 * @returns The VMCPUID of the calling thread, NIL_CPUID if not EMT.
4048 * @param pDevIns The device instance.
4049 */
4050 DECLRCCALLBACKMEMBER(VMCPUID, pfnGetCurrentCpuId,(PPDMDEVINS pDevIns));
4051
4052 /**
4053 * Get the current virtual clock time in a VM. The clock frequency must be
4054 * queried separately.
4055 *
4056 * @returns Current clock time.
4057 * @param pDevIns The device instance.
4058 */
4059 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
4060
4061 /**
4062 * Get the frequency of the virtual clock.
4063 *
4064 * @returns The clock frequency (not variable at run-time).
4065 * @param pDevIns The device instance.
4066 */
4067 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
4068
4069 /**
4070 * Get the current virtual clock time in a VM, in nanoseconds.
4071 *
4072 * @returns Current clock time (in ns).
4073 * @param pDevIns The device instance.
4074 */
4075 DECLRCCALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
4076
4077 /**
4078 * Gets the trace buffer handle.
4079 *
4080 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
4081 * really inteded for direct usage, thus no inline wrapper function.
4082 *
4083 * @returns Trace buffer handle or NIL_RTTRACEBUF.
4084 * @param pDevIns The device instance.
4085 */
4086 DECLRCCALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
4087
4088 /** Just a safety precaution. */
4089 uint32_t u32TheEnd;
4090} PDMDEVHLPRC;
4091/** Pointer PDM Device RC API. */
4092typedef RCPTRTYPE(struct PDMDEVHLPRC *) PPDMDEVHLPRC;
4093/** Pointer PDM Device RC API. */
4094typedef RCPTRTYPE(const struct PDMDEVHLPRC *) PCPDMDEVHLPRC;
4095
4096/** Current PDMDEVHLP version number. */
4097#define PDM_DEVHLPRC_VERSION PDM_VERSION_MAKE(0xffe6, 4, 1)
4098
4099
4100/**
4101 * PDM Device API - R0 Variant.
4102 */
4103typedef struct PDMDEVHLPR0
4104{
4105 /** Structure version. PDM_DEVHLPR0_VERSION defines the current version. */
4106 uint32_t u32Version;
4107
4108 /**
4109 * Bus master physical memory read.
4110 *
4111 * @returns VINF_SUCCESS or VERR_PDM_NOT_PCI_BUS_MASTER, later maybe
4112 * VERR_EM_MEMORY.
4113 * @param pDevIns The device instance.
4114 * @param GCPhys Physical address start reading from.
4115 * @param pvBuf Where to put the read bits.
4116 * @param cbRead How many bytes to read.
4117 * @thread Any thread, but the call may involve the emulation thread.
4118 */
4119 DECLR0CALLBACKMEMBER(int, pfnPCIPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
4120
4121 /**
4122 * Bus master physical memory write.
4123 *
4124 * @returns VINF_SUCCESS or VERR_PDM_NOT_PCI_BUS_MASTER, later maybe
4125 * VERR_EM_MEMORY.
4126 * @param pDevIns The device instance.
4127 * @param GCPhys Physical address to write to.
4128 * @param pvBuf What to write.
4129 * @param cbWrite How many bytes to write.
4130 * @thread Any thread, but the call may involve the emulation thread.
4131 */
4132 DECLR0CALLBACKMEMBER(int, pfnPCIPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
4133
4134 /**
4135 * Set the IRQ for a PCI device.
4136 *
4137 * @param pDevIns Device instance.
4138 * @param iIrq IRQ number to set.
4139 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
4140 * @thread Any thread, but will involve the emulation thread.
4141 */
4142 DECLR0CALLBACKMEMBER(void, pfnPCISetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
4143
4144 /**
4145 * Set ISA IRQ for a device.
4146 *
4147 * @param pDevIns Device instance.
4148 * @param iIrq IRQ number to set.
4149 * @param iLevel IRQ level. See the PDM_IRQ_LEVEL_* \#defines.
4150 * @thread Any thread, but will involve the emulation thread.
4151 */
4152 DECLR0CALLBACKMEMBER(void, pfnISASetIrq,(PPDMDEVINS pDevIns, int iIrq, int iLevel));
4153
4154 /**
4155 * Read physical memory.
4156 *
4157 * @returns VINF_SUCCESS (for now).
4158 * @param pDevIns Device instance.
4159 * @param GCPhys Physical address start reading from.
4160 * @param pvBuf Where to put the read bits.
4161 * @param cbRead How many bytes to read.
4162 */
4163 DECLR0CALLBACKMEMBER(int, pfnPhysRead,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead));
4164
4165 /**
4166 * Write to physical memory.
4167 *
4168 * @returns VINF_SUCCESS for now, and later maybe VERR_EM_MEMORY.
4169 * @param pDevIns Device instance.
4170 * @param GCPhys Physical address to write to.
4171 * @param pvBuf What to write.
4172 * @param cbWrite How many bytes to write.
4173 */
4174 DECLR0CALLBACKMEMBER(int, pfnPhysWrite,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite));
4175
4176 /**
4177 * Checks if the Gate A20 is enabled or not.
4178 *
4179 * @returns true if A20 is enabled.
4180 * @returns false if A20 is disabled.
4181 * @param pDevIns Device instance.
4182 * @thread The emulation thread.
4183 */
4184 DECLR0CALLBACKMEMBER(bool, pfnA20IsEnabled,(PPDMDEVINS pDevIns));
4185
4186 /**
4187 * Gets the VM state.
4188 *
4189 * @returns VM state.
4190 * @param pDevIns The device instance.
4191 * @thread Any thread (just keep in mind that it's volatile info).
4192 */
4193 DECLR0CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDEVINS pDevIns));
4194
4195 /**
4196 * Set the VM error message
4197 *
4198 * @returns rc.
4199 * @param pDevIns Driver instance.
4200 * @param rc VBox status code.
4201 * @param SRC_POS Use RT_SRC_POS.
4202 * @param pszFormat Error message format string.
4203 * @param ... Error message arguments.
4204 */
4205 DECLR0CALLBACKMEMBER(int, pfnVMSetError,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
4206 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(6, 7));
4207
4208 /**
4209 * Set the VM error message
4210 *
4211 * @returns rc.
4212 * @param pDevIns Driver instance.
4213 * @param rc VBox status code.
4214 * @param SRC_POS Use RT_SRC_POS.
4215 * @param pszFormat Error message format string.
4216 * @param va Error message arguments.
4217 */
4218 DECLR0CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDEVINS pDevIns, int rc, RT_SRC_POS_DECL,
4219 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(6, 0));
4220
4221 /**
4222 * Set the VM runtime error message
4223 *
4224 * @returns VBox status code.
4225 * @param pDevIns Device instance.
4226 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
4227 * @param pszErrorId Error ID string.
4228 * @param pszFormat Error message format string.
4229 * @param ... Error message arguments.
4230 */
4231 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4232 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5));
4233
4234 /**
4235 * Set the VM runtime error message
4236 *
4237 * @returns VBox status code.
4238 * @param pDevIns Device instance.
4239 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
4240 * @param pszErrorId Error ID string.
4241 * @param pszFormat Error message format string.
4242 * @param va Error message arguments.
4243 */
4244 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4245 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0));
4246
4247 /**
4248 * Set parameters for pending MMIO patch operation
4249 *
4250 * @returns rc.
4251 * @param pDevIns Device instance.
4252 * @param GCPhys MMIO physical address
4253 * @param pCachedData GC pointer to cached data
4254 */
4255 DECLR0CALLBACKMEMBER(int, pfnPATMSetMMIOPatchInfo,(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTGCPTR pCachedData));
4256
4257 /**
4258 * Gets the VM handle. Restricted API.
4259 *
4260 * @returns VM Handle.
4261 * @param pDevIns Device instance.
4262 */
4263 DECLR0CALLBACKMEMBER(PVM, pfnGetVM,(PPDMDEVINS pDevIns));
4264
4265 /**
4266 * Checks if our current CPU state allows for IO block emulation fallback to the recompiler
4267 *
4268 * @returns true = yes, false = no
4269 * @param pDevIns Device instance.
4270 */
4271 DECLR0CALLBACKMEMBER(bool, pfnCanEmulateIoBlock,(PPDMDEVINS pDevIns));
4272
4273 /**
4274 * Gets the VMCPU handle. Restricted API.
4275 *
4276 * @returns VMCPU Handle.
4277 * @param pDevIns The device instance.
4278 */
4279 DECLR0CALLBACKMEMBER(PVMCPU, pfnGetVMCPU,(PPDMDEVINS pDevIns));
4280
4281 /**
4282 * The the VM CPU ID of the current thread (restricted API).
4283 *
4284 * @returns The VMCPUID of the calling thread, NIL_CPUID if not EMT.
4285 * @param pDevIns The device instance.
4286 */
4287 DECLR0CALLBACKMEMBER(VMCPUID, pfnGetCurrentCpuId,(PPDMDEVINS pDevIns));
4288
4289 /**
4290 * Get the current virtual clock time in a VM. The clock frequency must be
4291 * queried separately.
4292 *
4293 * @returns Current clock time.
4294 * @param pDevIns The device instance.
4295 */
4296 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGet,(PPDMDEVINS pDevIns));
4297
4298 /**
4299 * Get the frequency of the virtual clock.
4300 *
4301 * @returns The clock frequency (not variable at run-time).
4302 * @param pDevIns The device instance.
4303 */
4304 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetFreq,(PPDMDEVINS pDevIns));
4305
4306 /**
4307 * Get the current virtual clock time in a VM, in nanoseconds.
4308 *
4309 * @returns Current clock time (in ns).
4310 * @param pDevIns The device instance.
4311 */
4312 DECLR0CALLBACKMEMBER(uint64_t, pfnTMTimeVirtGetNano,(PPDMDEVINS pDevIns));
4313
4314 /**
4315 * Gets the trace buffer handle.
4316 *
4317 * This is used by the macros found in VBox/vmm/dbgftrace.h and is not
4318 * really inteded for direct usage, thus no inline wrapper function.
4319 *
4320 * @returns Trace buffer handle or NIL_RTTRACEBUF.
4321 * @param pDevIns The device instance.
4322 */
4323 DECLR0CALLBACKMEMBER(RTTRACEBUF, pfnDBGFTraceBuf,(PPDMDEVINS pDevIns));
4324
4325 /** Just a safety precaution. */
4326 uint32_t u32TheEnd;
4327} PDMDEVHLPR0;
4328/** Pointer PDM Device R0 API. */
4329typedef R0PTRTYPE(struct PDMDEVHLPR0 *) PPDMDEVHLPR0;
4330/** Pointer PDM Device GC API. */
4331typedef R0PTRTYPE(const struct PDMDEVHLPR0 *) PCPDMDEVHLPR0;
4332
4333/** Current PDMDEVHLP version number. */
4334#define PDM_DEVHLPR0_VERSION PDM_VERSION_MAKE(0xffe5, 4, 1)
4335
4336
4337
4338/**
4339 * PDM Device Instance.
4340 */
4341typedef struct PDMDEVINS
4342{
4343 /** Structure version. PDM_DEVINS_VERSION defines the current version. */
4344 uint32_t u32Version;
4345 /** Device instance number. */
4346 uint32_t iInstance;
4347
4348 /** Pointer the GC PDM Device API. */
4349 PCPDMDEVHLPRC pHlpRC;
4350 /** Pointer to device instance data. */
4351 RTRCPTR pvInstanceDataRC;
4352 /** The critical section for the device, see pCritSectXR3. */
4353 RCPTRTYPE(PPDMCRITSECT) pCritSectRoRC;
4354 /** Alignment padding. */
4355 RTRCPTR pAlignmentRC;
4356
4357 /** Pointer the R0 PDM Device API. */
4358 PCPDMDEVHLPR0 pHlpR0;
4359 /** Pointer to device instance data (R0). */
4360 RTR0PTR pvInstanceDataR0;
4361 /** The critical section for the device, see pCritSectXR3. */
4362 R0PTRTYPE(PPDMCRITSECT) pCritSectRoR0;
4363
4364 /** Pointer the HC PDM Device API. */
4365 PCPDMDEVHLPR3 pHlpR3;
4366 /** Pointer to device instance data. */
4367 RTR3PTR pvInstanceDataR3;
4368 /** The critical section for the device.
4369 *
4370 * TM and IOM will enter this critical section before calling into the device
4371 * code. PDM will when doing power on, power off, reset, suspend and resume
4372 * notifications. SSM will currently not, but this will be changed later on.
4373 *
4374 * The device gets a critical section automatically assigned to it before
4375 * the constructor is called. If the constructor wishes to use a different
4376 * critical section, it calls PDMDevHlpSetDeviceCritSect() to change it
4377 * very early on.
4378 */
4379 R3PTRTYPE(PPDMCRITSECT) pCritSectRoR3;
4380
4381 /** Pointer to device registration structure. */
4382 R3PTRTYPE(PCPDMDEVREG) pReg;
4383 /** Configuration handle. */
4384 R3PTRTYPE(PCFGMNODE) pCfg;
4385
4386 /** The base interface of the device.
4387 *
4388 * The device constructor initializes this if it has any
4389 * device level interfaces to export. To obtain this interface
4390 * call PDMR3QueryDevice(). */
4391 PDMIBASE IBase;
4392
4393 /** Tracing indicator. */
4394 uint32_t fTracing;
4395 /** The tracing ID of this device. */
4396 uint32_t idTracing;
4397#if HC_ARCH_BITS == 32
4398 /** Align the internal data more naturally. */
4399 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 13 : 0];
4400#endif
4401
4402 /** Internal data. */
4403 union
4404 {
4405#ifdef PDMDEVINSINT_DECLARED
4406 PDMDEVINSINT s;
4407#endif
4408 uint8_t padding[HC_ARCH_BITS == 32 ? 72 : 112 + 0x28];
4409 } Internal;
4410
4411 /** Device instance data. The size of this area is defined
4412 * in the PDMDEVREG::cbInstanceData field. */
4413 char achInstanceData[8];
4414} PDMDEVINS;
4415
4416/** Current PDMDEVINS version number. */
4417#define PDM_DEVINS_VERSION PDM_VERSION_MAKE(0xffe4, 3, 0)
4418
4419/** Converts a pointer to the PDMDEVINS::IBase to a pointer to PDMDEVINS. */
4420#define PDMIBASE_2_PDMDEV(pInterface) ( (PPDMDEVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDEVINS, IBase)) )
4421
4422/**
4423 * Checks the structure versions of the device instance and device helpers,
4424 * returning if they are incompatible.
4425 *
4426 * This is for use in the constructor.
4427 *
4428 * @param pDevIns The device instance pointer.
4429 */
4430#define PDMDEV_CHECK_VERSIONS_RETURN(pDevIns) \
4431 do \
4432 { \
4433 PPDMDEVINS pDevInsTypeCheck = (pDevIns); NOREF(pDevInsTypeCheck); \
4434 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->u32Version, PDM_DEVINS_VERSION), \
4435 ("DevIns=%#x mine=%#x\n", (pDevIns)->u32Version, PDM_DEVINS_VERSION), \
4436 VERR_PDM_DEVINS_VERSION_MISMATCH); \
4437 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION), \
4438 ("DevHlp=%#x mine=%#x\n", (pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION), \
4439 VERR_PDM_DEVHLPR3_VERSION_MISMATCH); \
4440 } while (0)
4441
4442/**
4443 * Quietly checks the structure versions of the device instance and device
4444 * helpers, returning if they are incompatible.
4445 *
4446 * This is for use in the destructor.
4447 *
4448 * @param pDevIns The device instance pointer.
4449 */
4450#define PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns) \
4451 do \
4452 { \
4453 PPDMDEVINS pDevInsTypeCheck = (pDevIns); NOREF(pDevInsTypeCheck); \
4454 if (RT_LIKELY(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->u32Version, PDM_DEVINS_VERSION) )) \
4455 { /* likely */ } else return VERR_PDM_DEVINS_VERSION_MISMATCH; \
4456 if (RT_LIKELY(PDM_VERSION_ARE_COMPATIBLE((pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION) )) \
4457 { /* likely */ } else return VERR_PDM_DEVHLPR3_VERSION_MISMATCH; \
4458 } while (0)
4459
4460/**
4461 * Wrapper around CFGMR3ValidateConfig for the root config for use in the
4462 * constructor - returns on failure.
4463 *
4464 * This should be invoked after having initialized the instance data
4465 * sufficiently for the correct operation of the destructor. The destructor is
4466 * always called!
4467 *
4468 * @param pDevIns Pointer to the PDM device instance.
4469 * @param pszValidValues Patterns describing the valid value names. See
4470 * RTStrSimplePatternMultiMatch for details on the
4471 * pattern syntax.
4472 * @param pszValidNodes Patterns describing the valid node (key) names.
4473 * Pass empty string if no valid nodes.
4474 */
4475#define PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, pszValidValues, pszValidNodes) \
4476 do \
4477 { \
4478 int rcValCfg = CFGMR3ValidateConfig((pDevIns)->pCfg, "/", pszValidValues, pszValidNodes, \
4479 (pDevIns)->pReg->szName, (pDevIns)->iInstance); \
4480 if (RT_SUCCESS(rcValCfg)) \
4481 { /* likely */ } else return rcValCfg; \
4482 } while (0)
4483
4484/** @def PDMDEV_ASSERT_EMT
4485 * Assert that the current thread is the emulation thread.
4486 */
4487#ifdef VBOX_STRICT
4488# define PDMDEV_ASSERT_EMT(pDevIns) pDevIns->pHlpR3->pfnAssertEMT(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4489#else
4490# define PDMDEV_ASSERT_EMT(pDevIns) do { } while (0)
4491#endif
4492
4493/** @def PDMDEV_ASSERT_OTHER
4494 * Assert that the current thread is NOT the emulation thread.
4495 */
4496#ifdef VBOX_STRICT
4497# define PDMDEV_ASSERT_OTHER(pDevIns) pDevIns->pHlpR3->pfnAssertOther(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4498#else
4499# define PDMDEV_ASSERT_OTHER(pDevIns) do { } while (0)
4500#endif
4501
4502/** @def PDMDEV_ASSERT_VMLOCK_OWNER
4503 * Assert that the current thread is owner of the VM lock.
4504 */
4505#ifdef VBOX_STRICT
4506# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) pDevIns->pHlpR3->pfnAssertVMLock(pDevIns, __FILE__, __LINE__, __FUNCTION__)
4507#else
4508# define PDMDEV_ASSERT_VMLOCK_OWNER(pDevIns) do { } while (0)
4509#endif
4510
4511/** @def PDMDEV_SET_ERROR
4512 * Set the VM error. See PDMDevHlpVMSetError() for printf like message formatting.
4513 */
4514#define PDMDEV_SET_ERROR(pDevIns, rc, pszError) \
4515 PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, "%s", pszError)
4516
4517/** @def PDMDEV_SET_RUNTIME_ERROR
4518 * Set the VM runtime error. See PDMDevHlpVMSetRuntimeError() for printf like message formatting.
4519 */
4520#define PDMDEV_SET_RUNTIME_ERROR(pDevIns, fFlags, pszErrorId, pszError) \
4521 PDMDevHlpVMSetRuntimeError(pDevIns, fFlags, pszErrorId, "%s", pszError)
4522
4523/** @def PDMDEVINS_2_RCPTR
4524 * Converts a PDM Device instance pointer a RC PDM Device instance pointer.
4525 */
4526#define PDMDEVINS_2_RCPTR(pDevIns) ( (RCPTRTYPE(PPDMDEVINS))((RTGCUINTPTR)(pDevIns)->pvInstanceDataRC - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4527
4528/** @def PDMDEVINS_2_R3PTR
4529 * Converts a PDM Device instance pointer a R3 PDM Device instance pointer.
4530 */
4531#define PDMDEVINS_2_R3PTR(pDevIns) ( (R3PTRTYPE(PPDMDEVINS))((RTHCUINTPTR)(pDevIns)->pvInstanceDataR3 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4532
4533/** @def PDMDEVINS_2_R0PTR
4534 * Converts a PDM Device instance pointer a R0 PDM Device instance pointer.
4535 */
4536#define PDMDEVINS_2_R0PTR(pDevIns) ( (R0PTRTYPE(PPDMDEVINS))((RTR0UINTPTR)(pDevIns)->pvInstanceDataR0 - RT_OFFSETOF(PDMDEVINS, achInstanceData)) )
4537
4538
4539#ifdef IN_RING3
4540
4541/**
4542 * @copydoc PDMDEVHLPR3::pfnIOPortRegister
4543 */
4544DECLINLINE(int) PDMDevHlpIOPortRegister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTHCPTR pvUser,
4545 PFNIOMIOPORTOUT pfnOut, PFNIOMIOPORTIN pfnIn,
4546 PFNIOMIOPORTOUTSTRING pfnOutStr, PFNIOMIOPORTINSTRING pfnInStr, const char *pszDesc)
4547{
4548 return pDevIns->pHlpR3->pfnIOPortRegister(pDevIns, Port, cPorts, pvUser, pfnOut, pfnIn, pfnOutStr, pfnInStr, pszDesc);
4549}
4550
4551/**
4552 * @copydoc PDMDEVHLPR3::pfnIOPortRegisterRC
4553 */
4554DECLINLINE(int) PDMDevHlpIOPortRegisterRC(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTRCPTR pvUser,
4555 const char *pszOut, const char *pszIn, const char *pszOutStr,
4556 const char *pszInStr, const char *pszDesc)
4557{
4558 return pDevIns->pHlpR3->pfnIOPortRegisterRC(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
4559}
4560
4561/**
4562 * @copydoc PDMDEVHLPR3::pfnIOPortRegisterR0
4563 */
4564DECLINLINE(int) PDMDevHlpIOPortRegisterR0(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts, RTR0PTR pvUser,
4565 const char *pszOut, const char *pszIn, const char *pszOutStr,
4566 const char *pszInStr, const char *pszDesc)
4567{
4568 return pDevIns->pHlpR3->pfnIOPortRegisterR0(pDevIns, Port, cPorts, pvUser, pszOut, pszIn, pszOutStr, pszInStr, pszDesc);
4569}
4570
4571/**
4572 * @copydoc PDMDEVHLPR3::pfnIOPortDeregister
4573 */
4574DECLINLINE(int) PDMDevHlpIOPortDeregister(PPDMDEVINS pDevIns, RTIOPORT Port, RTIOPORT cPorts)
4575{
4576 return pDevIns->pHlpR3->pfnIOPortDeregister(pDevIns, Port, cPorts);
4577}
4578
4579/**
4580 * Register a Memory Mapped I/O (MMIO) region.
4581 *
4582 * These callbacks are of course for the ring-3 context (R3). Register HC
4583 * handlers before raw-mode context (RC) and ring-0 context (R0) handlers! There
4584 * must be a R3 handler for every RC and R0 handler!
4585 *
4586 * @returns VBox status.
4587 * @param pDevIns The device instance to register the MMIO with.
4588 * @param GCPhysStart First physical address in the range.
4589 * @param cbRange The size of the range (in bytes).
4590 * @param pvUser User argument.
4591 * @param fFlags Flags, IOMMMIO_FLAGS_XXX.
4592 * @param pfnWrite Pointer to function which is gonna handle Write operations.
4593 * @param pfnRead Pointer to function which is gonna handle Read operations.
4594 * @param pszDesc Pointer to description string. This must not be freed.
4595 */
4596DECLINLINE(int) PDMDevHlpMMIORegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTHCPTR pvUser,
4597 uint32_t fFlags, PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, const char *pszDesc)
4598{
4599 return pDevIns->pHlpR3->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, NULL /*pfnFill*/,
4600 fFlags, pszDesc);
4601}
4602
4603/**
4604 * Register a Memory Mapped I/O (MMIO) region for RC.
4605 *
4606 * These callbacks are for the raw-mode context (RC). Register ring-3 context
4607 * (R3) handlers before guest context handlers! There must be a R3 handler for
4608 * every RC handler!
4609 *
4610 * @returns VBox status.
4611 * @param pDevIns The device instance to register the MMIO with.
4612 * @param GCPhysStart First physical address in the range.
4613 * @param cbRange The size of the range (in bytes).
4614 * @param pvUser User argument.
4615 * @param pszWrite Name of the RC function which is gonna handle Write operations.
4616 * @param pszRead Name of the RC function which is gonna handle Read operations.
4617 */
4618DECLINLINE(int) PDMDevHlpMMIORegisterRC(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTRCPTR pvUser,
4619 const char *pszWrite, const char *pszRead)
4620{
4621 return pDevIns->pHlpR3->pfnMMIORegisterRC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, NULL /*pszFill*/);
4622}
4623
4624/**
4625 * Register a Memory Mapped I/O (MMIO) region for R0.
4626 *
4627 * These callbacks are for the ring-0 host context (R0). Register ring-3
4628 * constext (R3) handlers before R0 handlers! There must be a R3 handler for
4629 * every R0 handler!
4630 *
4631 * @returns VBox status.
4632 * @param pDevIns The device instance to register the MMIO with.
4633 * @param GCPhysStart First physical address in the range.
4634 * @param cbRange The size of the range (in bytes).
4635 * @param pvUser User argument. (if pointer, then it must be in locked memory!)
4636 * @param pszWrite Name of the RC function which is gonna handle Write operations.
4637 * @param pszRead Name of the RC function which is gonna handle Read operations.
4638 * @remarks Caller enters the device critical section prior to invoking the
4639 * registered callback methods.
4640 */
4641DECLINLINE(int) PDMDevHlpMMIORegisterR0(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTR0PTR pvUser,
4642 const char *pszWrite, const char *pszRead)
4643{
4644 return pDevIns->pHlpR3->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, NULL /*pszFill*/);
4645}
4646
4647/**
4648 * @copydoc PDMDEVHLPR3::pfnMMIORegister
4649 */
4650DECLINLINE(int) PDMDevHlpMMIORegisterEx(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTHCPTR pvUser,
4651 uint32_t fFlags, PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead,
4652 PFNIOMMMIOFILL pfnFill, const char *pszDesc)
4653{
4654 return pDevIns->pHlpR3->pfnMMIORegister(pDevIns, GCPhysStart, cbRange, pvUser, pfnWrite, pfnRead, pfnFill,
4655 fFlags, pszDesc);
4656}
4657
4658/**
4659 * @copydoc PDMDEVHLPR3::pfnMMIORegisterRC
4660 */
4661DECLINLINE(int) PDMDevHlpMMIORegisterRCEx(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTRCPTR pvUser,
4662 const char *pszWrite, const char *pszRead, const char *pszFill)
4663{
4664 return pDevIns->pHlpR3->pfnMMIORegisterRC(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill);
4665}
4666
4667/**
4668 * @copydoc PDMDEVHLPR3::pfnMMIORegisterR0
4669 */
4670DECLINLINE(int) PDMDevHlpMMIORegisterR0Ex(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange, RTR0PTR pvUser,
4671 const char *pszWrite, const char *pszRead, const char *pszFill)
4672{
4673 return pDevIns->pHlpR3->pfnMMIORegisterR0(pDevIns, GCPhysStart, cbRange, pvUser, pszWrite, pszRead, pszFill);
4674}
4675
4676/**
4677 * @copydoc PDMDEVHLPR3::pfnMMIODeregister
4678 */
4679DECLINLINE(int) PDMDevHlpMMIODeregister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, RTGCPHYS cbRange)
4680{
4681 return pDevIns->pHlpR3->pfnMMIODeregister(pDevIns, GCPhysStart, cbRange);
4682}
4683
4684/**
4685 * @copydoc PDMDEVHLPR3::pfnMMIO2Register
4686 */
4687DECLINLINE(int) PDMDevHlpMMIO2Register(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cb, uint32_t fFlags, void **ppv, const char *pszDesc)
4688{
4689 return pDevIns->pHlpR3->pfnMMIO2Register(pDevIns, iRegion, cb, fFlags, ppv, pszDesc);
4690}
4691
4692/**
4693 * @copydoc PDMDEVHLPR3::pfnMMIOExPreRegister
4694 */
4695DECLINLINE(int) PDMDevHlpMMIOExPreRegister(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS cbRegion,
4696 uint32_t fFlags, const char *pszDesc, RTHCPTR pvUser,
4697 PFNIOMMMIOWRITE pfnWrite, PFNIOMMMIOREAD pfnRead, PFNIOMMMIOFILL pfnFill,
4698 RTR0PTR pvUserR0, const char *pszWriteR0, const char *pszReadR0, const char *pszFillR0,
4699 RTRCPTR pvUserRC, const char *pszWriteRC, const char *pszReadRC, const char *pszFillRC)
4700{
4701 return pDevIns->pHlpR3->pfnMMIOExPreRegister(pDevIns, iRegion, cbRegion, fFlags, pszDesc,
4702 pvUser, pfnWrite, pfnRead, pfnFill,
4703 pvUserR0, pszWriteR0, pszReadR0, pszFillR0,
4704 pvUserRC, pszWriteRC, pszReadRC, pszFillRC);
4705}
4706
4707/**
4708 * @copydoc PDMDEVHLPR3::pfnMMIOExDeregister
4709 */
4710DECLINLINE(int) PDMDevHlpMMIOExDeregister(PPDMDEVINS pDevIns, uint32_t iRegion)
4711{
4712 return pDevIns->pHlpR3->pfnMMIOExDeregister(pDevIns, iRegion);
4713}
4714
4715/**
4716 * @copydoc PDMDEVHLPR3::pfnMMIOExMap
4717 */
4718DECLINLINE(int) PDMDevHlpMMIOExMap(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
4719{
4720 return pDevIns->pHlpR3->pfnMMIOExMap(pDevIns, iRegion, GCPhys);
4721}
4722
4723/**
4724 * @copydoc PDMDEVHLPR3::pfnMMIOExUnmap
4725 */
4726DECLINLINE(int) PDMDevHlpMMIOExUnmap(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS GCPhys)
4727{
4728 return pDevIns->pHlpR3->pfnMMIOExUnmap(pDevIns, iRegion, GCPhys);
4729}
4730
4731/**
4732 * @copydoc PDMDEVHLPR3::pfnMMHyperMapMMIO2
4733 */
4734DECLINLINE(int) PDMDevHlpMMHyperMapMMIO2(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
4735 const char *pszDesc, PRTRCPTR pRCPtr)
4736{
4737 return pDevIns->pHlpR3->pfnMMHyperMapMMIO2(pDevIns, iRegion, off, cb, pszDesc, pRCPtr);
4738}
4739
4740/**
4741 * @copydoc PDMDEVHLPR3::pfnMMIO2MapKernel
4742 */
4743DECLINLINE(int) PDMDevHlpMMIO2MapKernel(PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
4744 const char *pszDesc, PRTR0PTR pR0Ptr)
4745{
4746 return pDevIns->pHlpR3->pfnMMIO2MapKernel(pDevIns, iRegion, off, cb, pszDesc, pR0Ptr);
4747}
4748
4749/**
4750 * @copydoc PDMDEVHLPR3::pfnROMRegister
4751 */
4752DECLINLINE(int) PDMDevHlpROMRegister(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange,
4753 const void *pvBinary, uint32_t cbBinary, uint32_t fFlags, const char *pszDesc)
4754{
4755 return pDevIns->pHlpR3->pfnROMRegister(pDevIns, GCPhysStart, cbRange, pvBinary, cbBinary, fFlags, pszDesc);
4756}
4757
4758/**
4759 * @copydoc PDMDEVHLPR3::pfnROMProtectShadow
4760 */
4761DECLINLINE(int) PDMDevHlpROMProtectShadow(PPDMDEVINS pDevIns, RTGCPHYS GCPhysStart, uint32_t cbRange, PGMROMPROT enmProt)
4762{
4763 return pDevIns->pHlpR3->pfnROMProtectShadow(pDevIns, GCPhysStart, cbRange, enmProt);
4764}
4765
4766/**
4767 * Register a save state data unit.
4768 *
4769 * @returns VBox status.
4770 * @param pDevIns The device instance.
4771 * @param uVersion Data layout version number.
4772 * @param cbGuess The approximate amount of data in the unit.
4773 * Only for progress indicators.
4774 * @param pfnSaveExec Execute save callback, optional.
4775 * @param pfnLoadExec Execute load callback, optional.
4776 */
4777DECLINLINE(int) PDMDevHlpSSMRegister(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess,
4778 PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVLOADEXEC pfnLoadExec)
4779{
4780 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, NULL /*pszBefore*/,
4781 NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveDone*/,
4782 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
4783 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
4784}
4785
4786/**
4787 * Register a save state data unit with a live save callback as well.
4788 *
4789 * @returns VBox status.
4790 * @param pDevIns The device instance.
4791 * @param uVersion Data layout version number.
4792 * @param cbGuess The approximate amount of data in the unit.
4793 * Only for progress indicators.
4794 * @param pfnLiveExec Execute live callback, optional.
4795 * @param pfnSaveExec Execute save callback, optional.
4796 * @param pfnLoadExec Execute load callback, optional.
4797 */
4798DECLINLINE(int) PDMDevHlpSSMRegister3(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess,
4799 FNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVLOADEXEC pfnLoadExec)
4800{
4801 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, NULL /*pszBefore*/,
4802 NULL /*pfnLivePrep*/, pfnLiveExec, NULL /*pfnLiveDone*/,
4803 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
4804 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
4805}
4806
4807/**
4808 * @copydoc PDMDEVHLPR3::pfnSSMRegister
4809 */
4810DECLINLINE(int) PDMDevHlpSSMRegisterEx(PPDMDEVINS pDevIns, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
4811 PFNSSMDEVLIVEPREP pfnLivePrep, PFNSSMDEVLIVEEXEC pfnLiveExec, PFNSSMDEVLIVEVOTE pfnLiveVote,
4812 PFNSSMDEVSAVEPREP pfnSavePrep, PFNSSMDEVSAVEEXEC pfnSaveExec, PFNSSMDEVSAVEDONE pfnSaveDone,
4813 PFNSSMDEVLOADPREP pfnLoadPrep, PFNSSMDEVLOADEXEC pfnLoadExec, PFNSSMDEVLOADDONE pfnLoadDone)
4814{
4815 return pDevIns->pHlpR3->pfnSSMRegister(pDevIns, uVersion, cbGuess, pszBefore,
4816 pfnLivePrep, pfnLiveExec, pfnLiveVote,
4817 pfnSavePrep, pfnSaveExec, pfnSaveDone,
4818 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
4819}
4820
4821/**
4822 * @copydoc PDMDEVHLPR3::pfnTMTimerCreate
4823 */
4824DECLINLINE(int) PDMDevHlpTMTimerCreate(PPDMDEVINS pDevIns, TMCLOCK enmClock, PFNTMTIMERDEV pfnCallback, void *pvUser, uint32_t fFlags,
4825 const char *pszDesc, PPTMTIMERR3 ppTimer)
4826{
4827 return pDevIns->pHlpR3->pfnTMTimerCreate(pDevIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
4828}
4829
4830/**
4831 * @copydoc PDMDEVHLPR3::pfnTMUtcNow
4832 */
4833DECLINLINE(PRTTIMESPEC) PDMDevHlpTMUtcNow(PPDMDEVINS pDevIns, PRTTIMESPEC pTime)
4834{
4835 return pDevIns->pHlpR3->pfnTMUtcNow(pDevIns, pTime);
4836}
4837
4838#endif /* IN_RING3 */
4839
4840/**
4841 * @copydoc PDMDEVHLPR3::pfnPhysRead
4842 */
4843DECLINLINE(int) PDMDevHlpPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
4844{
4845 return pDevIns->CTX_SUFF(pHlp)->pfnPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
4846}
4847
4848/**
4849 * @copydoc PDMDEVHLPR3::pfnPhysWrite
4850 */
4851DECLINLINE(int) PDMDevHlpPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
4852{
4853 return pDevIns->CTX_SUFF(pHlp)->pfnPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
4854}
4855
4856#ifdef IN_RING3
4857
4858/**
4859 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtr
4860 */
4861DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtr(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void **ppv, PPGMPAGEMAPLOCK pLock)
4862{
4863 return pDevIns->CTX_SUFF(pHlp)->pfnPhysGCPhys2CCPtr(pDevIns, GCPhys, fFlags, ppv, pLock);
4864}
4865
4866/**
4867 * @copydoc PDMDEVHLPR3::pfnPhysGCPhys2CCPtrReadOnly
4868 */
4869DECLINLINE(int) PDMDevHlpPhysGCPhys2CCPtrReadOnly(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t fFlags, void const **ppv,
4870 PPGMPAGEMAPLOCK pLock)
4871{
4872 return pDevIns->CTX_SUFF(pHlp)->pfnPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhys, fFlags, ppv, pLock);
4873}
4874
4875/**
4876 * @copydoc PDMDEVHLPR3::pfnPhysReleasePageMappingLock
4877 */
4878DECLINLINE(void) PDMDevHlpPhysReleasePageMappingLock(PPDMDEVINS pDevIns, PPGMPAGEMAPLOCK pLock)
4879{
4880 pDevIns->CTX_SUFF(pHlp)->pfnPhysReleasePageMappingLock(pDevIns, pLock);
4881}
4882
4883/**
4884 * @copydoc PDMDEVHLPR3::pfnPhysReadGCVirt
4885 */
4886DECLINLINE(int) PDMDevHlpPhysReadGCVirt(PPDMDEVINS pDevIns, void *pvDst, RTGCPTR GCVirtSrc, size_t cb)
4887{
4888 return pDevIns->pHlpR3->pfnPhysReadGCVirt(pDevIns, pvDst, GCVirtSrc, cb);
4889}
4890
4891/**
4892 * @copydoc PDMDEVHLPR3::pfnPhysWriteGCVirt
4893 */
4894DECLINLINE(int) PDMDevHlpPhysWriteGCVirt(PPDMDEVINS pDevIns, RTGCPTR GCVirtDst, const void *pvSrc, size_t cb)
4895{
4896 return pDevIns->pHlpR3->pfnPhysWriteGCVirt(pDevIns, GCVirtDst, pvSrc, cb);
4897}
4898
4899/**
4900 * @copydoc PDMDEVHLPR3::pfnPhysGCPtr2GCPhys
4901 */
4902DECLINLINE(int) PDMDevHlpPhysGCPtr2GCPhys(PPDMDEVINS pDevIns, RTGCPTR GCPtr, PRTGCPHYS pGCPhys)
4903{
4904 return pDevIns->pHlpR3->pfnPhysGCPtr2GCPhys(pDevIns, GCPtr, pGCPhys);
4905}
4906
4907/**
4908 * @copydoc PDMDEVHLPR3::pfnMMHeapAlloc
4909 */
4910DECLINLINE(void *) PDMDevHlpMMHeapAlloc(PPDMDEVINS pDevIns, size_t cb)
4911{
4912 return pDevIns->pHlpR3->pfnMMHeapAlloc(pDevIns, cb);
4913}
4914
4915/**
4916 * @copydoc PDMDEVHLPR3::pfnMMHeapAllocZ
4917 */
4918DECLINLINE(void *) PDMDevHlpMMHeapAllocZ(PPDMDEVINS pDevIns, size_t cb)
4919{
4920 return pDevIns->pHlpR3->pfnMMHeapAllocZ(pDevIns, cb);
4921}
4922
4923/**
4924 * @copydoc PDMDEVHLPR3::pfnMMHeapFree
4925 */
4926DECLINLINE(void) PDMDevHlpMMHeapFree(PPDMDEVINS pDevIns, void *pv)
4927{
4928 pDevIns->pHlpR3->pfnMMHeapFree(pDevIns, pv);
4929}
4930#endif /* IN_RING3 */
4931
4932/**
4933 * @copydoc PDMDEVHLPR3::pfnVMState
4934 */
4935DECLINLINE(VMSTATE) PDMDevHlpVMState(PPDMDEVINS pDevIns)
4936{
4937 return pDevIns->CTX_SUFF(pHlp)->pfnVMState(pDevIns);
4938}
4939
4940#ifdef IN_RING3
4941/**
4942 * @copydoc PDMDEVHLPR3::pfnVMTeleportedAndNotFullyResumedYet
4943 */
4944DECLINLINE(bool) PDMDevHlpVMTeleportedAndNotFullyResumedYet(PPDMDEVINS pDevIns)
4945{
4946 return pDevIns->pHlpR3->pfnVMTeleportedAndNotFullyResumedYet(pDevIns);
4947}
4948#endif /* IN_RING3 */
4949
4950/**
4951 * @copydoc PDMDEVHLPR3::pfnVMSetError
4952 */
4953DECLINLINE(int) RT_IPRT_FORMAT_ATTR(6, 7) PDMDevHlpVMSetError(PPDMDEVINS pDevIns, const int rc, RT_SRC_POS_DECL,
4954 const char *pszFormat, ...)
4955{
4956 va_list va;
4957 va_start(va, pszFormat);
4958 pDevIns->CTX_SUFF(pHlp)->pfnVMSetErrorV(pDevIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
4959 va_end(va);
4960 return rc;
4961}
4962
4963/**
4964 * @copydoc PDMDEVHLPR3::pfnVMSetRuntimeError
4965 */
4966DECLINLINE(int) RT_IPRT_FORMAT_ATTR(4, 5) PDMDevHlpVMSetRuntimeError(PPDMDEVINS pDevIns, uint32_t fFlags, const char *pszErrorId,
4967 const char *pszFormat, ...)
4968{
4969 va_list va;
4970 int rc;
4971 va_start(va, pszFormat);
4972 rc = pDevIns->CTX_SUFF(pHlp)->pfnVMSetRuntimeErrorV(pDevIns, fFlags, pszErrorId, pszFormat, va);
4973 va_end(va);
4974 return rc;
4975}
4976
4977/**
4978 * VBOX_STRICT wrapper for pHlp->pfnDBGFStopV.
4979 *
4980 * @returns VBox status code which must be passed up to the VMM. This will be
4981 * VINF_SUCCESS in non-strict builds.
4982 * @param pDevIns The device instance.
4983 * @param SRC_POS Use RT_SRC_POS.
4984 * @param pszFormat Message. (optional)
4985 * @param ... Message parameters.
4986 */
4987DECLINLINE(int) RT_IPRT_FORMAT_ATTR(5, 6) PDMDevHlpDBGFStop(PPDMDEVINS pDevIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
4988{
4989#ifdef VBOX_STRICT
4990# ifdef IN_RING3
4991 int rc;
4992 va_list args;
4993 va_start(args, pszFormat);
4994 rc = pDevIns->pHlpR3->pfnDBGFStopV(pDevIns, RT_SRC_POS_ARGS, pszFormat, args);
4995 va_end(args);
4996 return rc;
4997# else
4998 NOREF(pDevIns);
4999 NOREF(pszFile);
5000 NOREF(iLine);
5001 NOREF(pszFunction);
5002 NOREF(pszFormat);
5003 return VINF_EM_DBG_STOP;
5004# endif
5005#else
5006 NOREF(pDevIns);
5007 NOREF(pszFile);
5008 NOREF(iLine);
5009 NOREF(pszFunction);
5010 NOREF(pszFormat);
5011 return VINF_SUCCESS;
5012#endif
5013}
5014
5015#ifdef IN_RING3
5016
5017/**
5018 * @copydoc PDMDEVHLPR3::pfnDBGFInfoRegister
5019 */
5020DECLINLINE(int) PDMDevHlpDBGFInfoRegister(PPDMDEVINS pDevIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDEV pfnHandler)
5021{
5022 return pDevIns->pHlpR3->pfnDBGFInfoRegister(pDevIns, pszName, pszDesc, pfnHandler);
5023}
5024
5025/**
5026 * @copydoc PDMDEVHLPR3::pfnDBGFRegRegister
5027 */
5028DECLINLINE(int) PDMDevHlpDBGFRegRegister(PPDMDEVINS pDevIns, PCDBGFREGDESC paRegisters)
5029{
5030 return pDevIns->pHlpR3->pfnDBGFRegRegister(pDevIns, paRegisters);
5031}
5032
5033/**
5034 * @copydoc PDMDEVHLPR3::pfnSTAMRegister
5035 */
5036DECLINLINE(void) PDMDevHlpSTAMRegister(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
5037{
5038 pDevIns->pHlpR3->pfnSTAMRegister(pDevIns, pvSample, enmType, pszName, enmUnit, pszDesc);
5039}
5040
5041/**
5042 * @copydoc PDMDEVHLPR3::pfnSTAMRegisterF
5043 */
5044DECLINLINE(void) RT_IPRT_FORMAT_ATTR(7, 8) PDMDevHlpSTAMRegisterF(PPDMDEVINS pDevIns, void *pvSample, STAMTYPE enmType,
5045 STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
5046 const char *pszDesc, const char *pszName, ...)
5047{
5048 va_list va;
5049 va_start(va, pszName);
5050 pDevIns->pHlpR3->pfnSTAMRegisterV(pDevIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
5051 va_end(va);
5052}
5053
5054/**
5055 * @copydoc PDMDEVHLPR3::pfnPCIRegister
5056 */
5057DECLINLINE(int) PDMDevHlpPCIRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev)
5058{
5059 return pDevIns->pHlpR3->pfnPCIRegister(pDevIns, pPciDev);
5060}
5061
5062/**
5063 * @copydoc PDMDEVHLPR3::pfnPCIIORegionRegister
5064 */
5065DECLINLINE(int) PDMDevHlpPCIIORegionRegister(PPDMDEVINS pDevIns, int iRegion, RTGCPHYS cbRegion,
5066 PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
5067{
5068 return pDevIns->pHlpR3->pfnPCIIORegionRegister(pDevIns, iRegion, cbRegion, enmType, pfnCallback);
5069}
5070
5071/**
5072 * @copydoc PDMDEVHLPR3::pfnPCIRegisterMsi
5073 */
5074DECLINLINE(int) PDMDevHlpPCIRegisterMsi(PPDMDEVINS pDevIns, PPDMMSIREG pMsiReg)
5075{
5076 return pDevIns->pHlpR3->pfnPCIRegisterMsi(pDevIns, pMsiReg);
5077}
5078
5079/**
5080 * @copydoc PDMDEVHLPR3::pfnPCISetConfigCallbacks
5081 */
5082DECLINLINE(void) PDMDevHlpPCISetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev,
5083 PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
5084 PFNPCICONFIGWRITE pfnWrite, PPFNPCICONFIGWRITE ppfnWriteOld)
5085{
5086 pDevIns->pHlpR3->pfnPCISetConfigCallbacks(pDevIns, pPciDev, pfnRead, ppfnReadOld, pfnWrite, ppfnWriteOld);
5087}
5088
5089#endif /* IN_RING3 */
5090
5091/**
5092 * @copydoc PDMDEVHLPR3::pfnPCIPhysRead
5093 */
5094DECLINLINE(int) PDMDevHlpPCIPhysRead(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead)
5095{
5096 return pDevIns->CTX_SUFF(pHlp)->pfnPCIPhysRead(pDevIns, GCPhys, pvBuf, cbRead);
5097}
5098
5099/**
5100 * @copydoc PDMDEVHLPR3::pfnPCIPhysWrite
5101 */
5102DECLINLINE(int) PDMDevHlpPCIPhysWrite(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
5103{
5104 return pDevIns->CTX_SUFF(pHlp)->pfnPCIPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
5105}
5106
5107/**
5108 * @copydoc PDMDEVHLPR3::pfnPCISetIrq
5109 */
5110DECLINLINE(void) PDMDevHlpPCISetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
5111{
5112 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, iIrq, iLevel);
5113}
5114
5115/**
5116 * @copydoc PDMDEVHLPR3::pfnPCISetIrqNoWait
5117 */
5118DECLINLINE(void) PDMDevHlpPCISetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
5119{
5120 pDevIns->CTX_SUFF(pHlp)->pfnPCISetIrq(pDevIns, iIrq, iLevel);
5121}
5122
5123/**
5124 * @copydoc PDMDEVHLPR3::pfnISASetIrq
5125 */
5126DECLINLINE(void) PDMDevHlpISASetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
5127{
5128 pDevIns->CTX_SUFF(pHlp)->pfnISASetIrq(pDevIns, iIrq, iLevel);
5129}
5130
5131/**
5132 * @copydoc PDMDEVHLPR3::pfnISASetIrqNoWait
5133 */
5134DECLINLINE(void) PDMDevHlpISASetIrqNoWait(PPDMDEVINS pDevIns, int iIrq, int iLevel)
5135{
5136 pDevIns->CTX_SUFF(pHlp)->pfnISASetIrq(pDevIns, iIrq, iLevel);
5137}
5138
5139#ifdef IN_RING3
5140
5141/**
5142 * @copydoc PDMDEVHLPR3::pfnDriverAttach
5143 */
5144DECLINLINE(int) PDMDevHlpDriverAttach(PPDMDEVINS pDevIns, uint32_t iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
5145{
5146 return pDevIns->pHlpR3->pfnDriverAttach(pDevIns, iLun, pBaseInterface, ppBaseInterface, pszDesc);
5147}
5148
5149/**
5150 * @copydoc PDMDEVHLPR3::pfnDriverDetach
5151 */
5152DECLINLINE(int) PDMDevHlpDriverDetach(PPDMDEVINS pDevIns, PPDMDRVINS pDrvIns, uint32_t fFlags)
5153{
5154 return pDevIns->pHlpR3->pfnDriverDetach(pDevIns, pDrvIns, fFlags);
5155}
5156
5157/**
5158 * @copydoc PDMDEVHLPR3::pfnQueueCreate
5159 */
5160DECLINLINE(int) PDMDevHlpQueueCreate(PPDMDEVINS pDevIns, size_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
5161 PFNPDMQUEUEDEV pfnCallback, bool fRZEnabled, const char *pszName, PPDMQUEUE *ppQueue)
5162{
5163 return pDevIns->pHlpR3->pfnQueueCreate(pDevIns, cbItem, cItems, cMilliesInterval, pfnCallback, fRZEnabled, pszName, ppQueue);
5164}
5165
5166/**
5167 * Initializes a PDM critical section.
5168 *
5169 * The PDM critical sections are derived from the IPRT critical sections, but
5170 * works in RC and R0 as well.
5171 *
5172 * @returns VBox status code.
5173 * @param pDevIns The device instance.
5174 * @param pCritSect Pointer to the critical section.
5175 * @param SRC_POS Use RT_SRC_POS.
5176 * @param pszNameFmt Format string for naming the critical section.
5177 * For statistics and lock validation.
5178 * @param ... Arguments for the format string.
5179 */
5180DECLINLINE(int) RT_IPRT_FORMAT_ATTR(6, 7) PDMDevHlpCritSectInit(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL,
5181 const char *pszNameFmt, ...)
5182{
5183 int rc;
5184 va_list va;
5185 va_start(va, pszNameFmt);
5186 rc = pDevIns->pHlpR3->pfnCritSectInit(pDevIns, pCritSect, RT_SRC_POS_ARGS, pszNameFmt, va);
5187 va_end(va);
5188 return rc;
5189}
5190
5191/**
5192 * @copydoc PDMDEVHLPR3::pfnCritSectGetNop
5193 */
5194DECLINLINE(PPDMCRITSECT) PDMDevHlpCritSectGetNop(PPDMDEVINS pDevIns)
5195{
5196 return pDevIns->pHlpR3->pfnCritSectGetNop(pDevIns);
5197}
5198
5199/**
5200 * @copydoc PDMDEVHLPR3::pfnCritSectGetNopR0
5201 */
5202DECLINLINE(R0PTRTYPE(PPDMCRITSECT)) PDMDevHlpCritSectGetNopR0(PPDMDEVINS pDevIns)
5203{
5204 return pDevIns->pHlpR3->pfnCritSectGetNopR0(pDevIns);
5205}
5206
5207/**
5208 * @copydoc PDMDEVHLPR3::pfnCritSectGetNopRC
5209 */
5210DECLINLINE(RCPTRTYPE(PPDMCRITSECT)) PDMDevHlpCritSectGetNopRC(PPDMDEVINS pDevIns)
5211{
5212 return pDevIns->pHlpR3->pfnCritSectGetNopRC(pDevIns);
5213}
5214
5215/**
5216 * @copydoc PDMDEVHLPR3::pfnSetDeviceCritSect
5217 */
5218DECLINLINE(int) PDMDevHlpSetDeviceCritSect(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect)
5219{
5220 return pDevIns->pHlpR3->pfnSetDeviceCritSect(pDevIns, pCritSect);
5221}
5222
5223/**
5224 * @copydoc PDMDEVHLPR3::pfnThreadCreate
5225 */
5226DECLINLINE(int) PDMDevHlpThreadCreate(PPDMDEVINS pDevIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDEV pfnThread,
5227 PFNPDMTHREADWAKEUPDEV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
5228{
5229 return pDevIns->pHlpR3->pfnThreadCreate(pDevIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
5230}
5231
5232/**
5233 * @copydoc PDMDEVHLPR3::pfnSetAsyncNotification
5234 */
5235DECLINLINE(int) PDMDevHlpSetAsyncNotification(PPDMDEVINS pDevIns, PFNPDMDEVASYNCNOTIFY pfnAsyncNotify)
5236{
5237 return pDevIns->pHlpR3->pfnSetAsyncNotification(pDevIns, pfnAsyncNotify);
5238}
5239
5240/**
5241 * @copydoc PDMDEVHLPR3::pfnAsyncNotificationCompleted
5242 */
5243DECLINLINE(void) PDMDevHlpAsyncNotificationCompleted(PPDMDEVINS pDevIns)
5244{
5245 pDevIns->pHlpR3->pfnAsyncNotificationCompleted(pDevIns);
5246}
5247
5248/**
5249 * @copydoc PDMDEVHLPR3::pfnA20Set
5250 */
5251DECLINLINE(void) PDMDevHlpA20Set(PPDMDEVINS pDevIns, bool fEnable)
5252{
5253 pDevIns->pHlpR3->pfnA20Set(pDevIns, fEnable);
5254}
5255
5256/**
5257 * @copydoc PDMDEVHLPR3::pfnRTCRegister
5258 */
5259DECLINLINE(int) PDMDevHlpRTCRegister(PPDMDEVINS pDevIns, PCPDMRTCREG pRtcReg, PCPDMRTCHLP *ppRtcHlp)
5260{
5261 return pDevIns->pHlpR3->pfnRTCRegister(pDevIns, pRtcReg, ppRtcHlp);
5262}
5263
5264/**
5265 * @copydoc PDMDEVHLPR3::pfnPCIBusRegister
5266 */
5267DECLINLINE(int) PDMDevHlpPCIBusRegister(PPDMDEVINS pDevIns, PPDMPCIBUSREG pPciBusReg, PCPDMPCIHLPR3 *ppPciHlpR3)
5268{
5269 return pDevIns->pHlpR3->pfnPCIBusRegister(pDevIns, pPciBusReg, ppPciHlpR3);
5270}
5271
5272/**
5273 * @copydoc PDMDEVHLPR3::pfnPICRegister
5274 */
5275DECLINLINE(int) PDMDevHlpPICRegister(PPDMDEVINS pDevIns, PPDMPICREG pPicReg, PCPDMPICHLPR3 *ppPicHlpR3)
5276{
5277 return pDevIns->pHlpR3->pfnPICRegister(pDevIns, pPicReg, ppPicHlpR3);
5278}
5279
5280/**
5281 * @copydoc PDMDEVHLPR3::pfnAPICRegister
5282 */
5283DECLINLINE(int) PDMDevHlpAPICRegister(PPDMDEVINS pDevIns, PPDMAPICREG pApicReg, PCPDMAPICHLPR3 *ppApicHlpR3)
5284{
5285 return pDevIns->pHlpR3->pfnAPICRegister(pDevIns, pApicReg, ppApicHlpR3);
5286}
5287
5288/**
5289 * @copydoc PDMDEVHLPR3::pfnIOAPICRegister
5290 */
5291DECLINLINE(int) PDMDevHlpIOAPICRegister(PPDMDEVINS pDevIns, PPDMIOAPICREG pIoApicReg, PCPDMIOAPICHLPR3 *ppIoApicHlpR3)
5292{
5293 return pDevIns->pHlpR3->pfnIOAPICRegister(pDevIns, pIoApicReg, ppIoApicHlpR3);
5294}
5295
5296/**
5297 * @copydoc PDMDEVHLPR3::pfnHPETRegister
5298 */
5299DECLINLINE(int) PDMDevHlpHPETRegister(PPDMDEVINS pDevIns, PPDMHPETREG pHpetReg, PCPDMHPETHLPR3 *ppHpetHlpR3)
5300{
5301 return pDevIns->pHlpR3->pfnHPETRegister(pDevIns, pHpetReg, ppHpetHlpR3);
5302}
5303
5304/**
5305 * @copydoc PDMDEVHLPR3::pfnPciRawRegister
5306 */
5307DECLINLINE(int) PDMDevHlpPciRawRegister(PPDMDEVINS pDevIns, PPDMPCIRAWREG pPciRawReg, PCPDMPCIRAWHLPR3 *ppPciRawHlpR3)
5308{
5309 return pDevIns->pHlpR3->pfnPciRawRegister(pDevIns, pPciRawReg, ppPciRawHlpR3);
5310}
5311
5312/**
5313 * @copydoc PDMDEVHLPR3::pfnDMACRegister
5314 */
5315DECLINLINE(int) PDMDevHlpDMACRegister(PPDMDEVINS pDevIns, PPDMDMACREG pDmacReg, PCPDMDMACHLP *ppDmacHlp)
5316{
5317 return pDevIns->pHlpR3->pfnDMACRegister(pDevIns, pDmacReg, ppDmacHlp);
5318}
5319
5320/**
5321 * @copydoc PDMDEVHLPR3::pfnDMARegister
5322 */
5323DECLINLINE(int) PDMDevHlpDMARegister(PPDMDEVINS pDevIns, unsigned uChannel, PFNDMATRANSFERHANDLER pfnTransferHandler, void *pvUser)
5324{
5325 return pDevIns->pHlpR3->pfnDMARegister(pDevIns, uChannel, pfnTransferHandler, pvUser);
5326}
5327
5328/**
5329 * @copydoc PDMDEVHLPR3::pfnDMAReadMemory
5330 */
5331DECLINLINE(int) PDMDevHlpDMAReadMemory(PPDMDEVINS pDevIns, unsigned uChannel, void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbRead)
5332{
5333 return pDevIns->pHlpR3->pfnDMAReadMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbRead);
5334}
5335
5336/**
5337 * @copydoc PDMDEVHLPR3::pfnDMAWriteMemory
5338 */
5339DECLINLINE(int) PDMDevHlpDMAWriteMemory(PPDMDEVINS pDevIns, unsigned uChannel, const void *pvBuffer, uint32_t off, uint32_t cbBlock, uint32_t *pcbWritten)
5340{
5341 return pDevIns->pHlpR3->pfnDMAWriteMemory(pDevIns, uChannel, pvBuffer, off, cbBlock, pcbWritten);
5342}
5343
5344/**
5345 * @copydoc PDMDEVHLPR3::pfnDMASetDREQ
5346 */
5347DECLINLINE(int) PDMDevHlpDMASetDREQ(PPDMDEVINS pDevIns, unsigned uChannel, unsigned uLevel)
5348{
5349 return pDevIns->pHlpR3->pfnDMASetDREQ(pDevIns, uChannel, uLevel);
5350}
5351
5352/**
5353 * @copydoc PDMDEVHLPR3::pfnDMAGetChannelMode
5354 */
5355DECLINLINE(uint8_t) PDMDevHlpDMAGetChannelMode(PPDMDEVINS pDevIns, unsigned uChannel)
5356{
5357 return pDevIns->pHlpR3->pfnDMAGetChannelMode(pDevIns, uChannel);
5358}
5359
5360/**
5361 * @copydoc PDMDEVHLPR3::pfnDMASchedule
5362 */
5363DECLINLINE(void) PDMDevHlpDMASchedule(PPDMDEVINS pDevIns)
5364{
5365 pDevIns->pHlpR3->pfnDMASchedule(pDevIns);
5366}
5367
5368/**
5369 * @copydoc PDMDEVHLPR3::pfnCMOSWrite
5370 */
5371DECLINLINE(int) PDMDevHlpCMOSWrite(PPDMDEVINS pDevIns, unsigned iReg, uint8_t u8Value)
5372{
5373 return pDevIns->pHlpR3->pfnCMOSWrite(pDevIns, iReg, u8Value);
5374}
5375
5376/**
5377 * @copydoc PDMDEVHLPR3::pfnCMOSRead
5378 */
5379DECLINLINE(int) PDMDevHlpCMOSRead(PPDMDEVINS pDevIns, unsigned iReg, uint8_t *pu8Value)
5380{
5381 return pDevIns->pHlpR3->pfnCMOSRead(pDevIns, iReg, pu8Value);
5382}
5383
5384/**
5385 * @copydoc PDMDEVHLPR3::pfnCallR0
5386 */
5387DECLINLINE(int) PDMDevHlpCallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
5388{
5389 return pDevIns->pHlpR3->pfnCallR0(pDevIns, uOperation, u64Arg);
5390}
5391
5392/**
5393 * @copydoc PDMDEVHLPR3::pfnVMGetSuspendReason
5394 */
5395DECLINLINE(VMSUSPENDREASON) PDMDevHlpVMGetSuspendReason(PPDMDEVINS pDevIns)
5396{
5397 return pDevIns->pHlpR3->pfnVMGetSuspendReason(pDevIns);
5398}
5399
5400/**
5401 * @copydoc PDMDEVHLPR3::pfnVMGetResumeReason
5402 */
5403DECLINLINE(VMRESUMEREASON) PDMDevHlpVMGetResumeReason(PPDMDEVINS pDevIns)
5404{
5405 return pDevIns->pHlpR3->pfnVMGetResumeReason(pDevIns);
5406}
5407
5408/**
5409 * @copydoc PDMDEVHLPR3::pfnGetUVM
5410 */
5411DECLINLINE(PUVM) PDMDevHlpGetUVM(PPDMDEVINS pDevIns)
5412{
5413 return pDevIns->CTX_SUFF(pHlp)->pfnGetUVM(pDevIns);
5414}
5415
5416#endif /* IN_RING3 */
5417
5418/**
5419 * @copydoc PDMDEVHLPR3::pfnGetVM
5420 */
5421DECLINLINE(PVM) PDMDevHlpGetVM(PPDMDEVINS pDevIns)
5422{
5423 return pDevIns->CTX_SUFF(pHlp)->pfnGetVM(pDevIns);
5424}
5425
5426/**
5427 * @copydoc PDMDEVHLPR3::pfnGetVMCPU
5428 */
5429DECLINLINE(PVMCPU) PDMDevHlpGetVMCPU(PPDMDEVINS pDevIns)
5430{
5431 return pDevIns->CTX_SUFF(pHlp)->pfnGetVMCPU(pDevIns);
5432}
5433
5434/**
5435 * @copydoc PDMDEVHLPR3::pfnGetCurrentCpuId
5436 */
5437DECLINLINE(VMCPUID) PDMDevHlpGetCurrentCpuId(PPDMDEVINS pDevIns)
5438{
5439 return pDevIns->CTX_SUFF(pHlp)->pfnGetCurrentCpuId(pDevIns);
5440}
5441
5442/**
5443 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGet
5444 */
5445DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGet(PPDMDEVINS pDevIns)
5446{
5447 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGet(pDevIns);
5448}
5449
5450/**
5451 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGetFreq
5452 */
5453DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGetFreq(PPDMDEVINS pDevIns)
5454{
5455 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGetFreq(pDevIns);
5456}
5457
5458/**
5459 * @copydoc PDMDEVHLPR3::pfnTMTimeVirtGetFreq
5460 */
5461DECLINLINE(uint64_t) PDMDevHlpTMTimeVirtGetNano(PPDMDEVINS pDevIns)
5462{
5463 return pDevIns->CTX_SUFF(pHlp)->pfnTMTimeVirtGetNano(pDevIns);
5464}
5465
5466#ifdef IN_RING3
5467
5468/**
5469 * @copydoc PDMDEVHLPR3::pfnRegisterVMMDevHeap
5470 */
5471DECLINLINE(int) PDMDevHlpRegisterVMMDevHeap(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTR3PTR pvHeap, unsigned cbHeap)
5472{
5473 return pDevIns->pHlpR3->pfnRegisterVMMDevHeap(pDevIns, GCPhys, pvHeap, cbHeap);
5474}
5475
5476/**
5477 * @copydoc PDMDEVHLPR3::pfnFirmwareRegister
5478 */
5479DECLINLINE(int) PDMDevHlpFirmwareRegister(PPDMDEVINS pDevIns, PCPDMFWREG pFwReg, PCPDMFWHLPR3 *ppFwHlp)
5480{
5481 return pDevIns->pHlpR3->pfnFirmwareRegister(pDevIns, pFwReg, ppFwHlp);
5482}
5483
5484/**
5485 * @copydoc PDMDEVHLPR3::pfnVMReset
5486 */
5487DECLINLINE(int) PDMDevHlpVMReset(PPDMDEVINS pDevIns, uint32_t fFlags)
5488{
5489 return pDevIns->pHlpR3->pfnVMReset(pDevIns, fFlags);
5490}
5491
5492/**
5493 * @copydoc PDMDEVHLPR3::pfnVMSuspend
5494 */
5495DECLINLINE(int) PDMDevHlpVMSuspend(PPDMDEVINS pDevIns)
5496{
5497 return pDevIns->pHlpR3->pfnVMSuspend(pDevIns);
5498}
5499
5500/**
5501 * @copydoc PDMDEVHLPR3::pfnVMSuspendSaveAndPowerOff
5502 */
5503DECLINLINE(int) PDMDevHlpVMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
5504{
5505 return pDevIns->pHlpR3->pfnVMSuspendSaveAndPowerOff(pDevIns);
5506}
5507
5508/**
5509 * @copydoc PDMDEVHLPR3::pfnVMPowerOff
5510 */
5511DECLINLINE(int) PDMDevHlpVMPowerOff(PPDMDEVINS pDevIns)
5512{
5513 return pDevIns->pHlpR3->pfnVMPowerOff(pDevIns);
5514}
5515
5516#endif /* IN_RING3 */
5517
5518/**
5519 * @copydoc PDMDEVHLPR3::pfnA20IsEnabled
5520 */
5521DECLINLINE(bool) PDMDevHlpA20IsEnabled(PPDMDEVINS pDevIns)
5522{
5523 return pDevIns->CTX_SUFF(pHlp)->pfnA20IsEnabled(pDevIns);
5524}
5525
5526#ifdef IN_RING3
5527
5528/**
5529 * @copydoc PDMDEVHLPR3::pfnGetCpuId
5530 */
5531DECLINLINE(void) PDMDevHlpGetCpuId(PPDMDEVINS pDevIns, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
5532{
5533 pDevIns->pHlpR3->pfnGetCpuId(pDevIns, iLeaf, pEax, pEbx, pEcx, pEdx);
5534}
5535
5536/**
5537 * @copydoc PDMDEVHLPR3::pfnGetSupDrvSession
5538 */
5539DECLINLINE(PSUPDRVSESSION) PDMDevHlpGetSupDrvSession(PPDMDEVINS pDevIns)
5540{
5541 return pDevIns->pHlpR3->pfnGetSupDrvSession(pDevIns);
5542}
5543
5544#endif /* IN_RING3 */
5545#ifdef IN_RING0
5546
5547/**
5548 * @copydoc PDMDEVHLPR0::pfnCanEmulateIoBlock
5549 */
5550DECLINLINE(bool) PDMDevHlpCanEmulateIoBlock(PPDMDEVINS pDevIns)
5551{
5552 return pDevIns->CTX_SUFF(pHlp)->pfnCanEmulateIoBlock(pDevIns);
5553}
5554
5555#endif /* IN_RING0 */
5556
5557
5558
5559
5560/** Pointer to callbacks provided to the VBoxDeviceRegister() call. */
5561typedef struct PDMDEVREGCB *PPDMDEVREGCB;
5562
5563/**
5564 * Callbacks for VBoxDeviceRegister().
5565 */
5566typedef struct PDMDEVREGCB
5567{
5568 /** Interface version.
5569 * This is set to PDM_DEVREG_CB_VERSION. */
5570 uint32_t u32Version;
5571
5572 /**
5573 * Registers a device with the current VM instance.
5574 *
5575 * @returns VBox status code.
5576 * @param pCallbacks Pointer to the callback table.
5577 * @param pReg Pointer to the device registration record.
5578 * This data must be permanent and readonly.
5579 */
5580 DECLR3CALLBACKMEMBER(int, pfnRegister,(PPDMDEVREGCB pCallbacks, PCPDMDEVREG pReg));
5581} PDMDEVREGCB;
5582
5583/** Current version of the PDMDEVREGCB structure. */
5584#define PDM_DEVREG_CB_VERSION PDM_VERSION_MAKE(0xffe3, 1, 0)
5585
5586
5587/**
5588 * The VBoxDevicesRegister callback function.
5589 *
5590 * PDM will invoke this function after loading a device module and letting
5591 * the module decide which devices to register and how to handle conflicts.
5592 *
5593 * @returns VBox status code.
5594 * @param pCallbacks Pointer to the callback table.
5595 * @param u32Version VBox version number.
5596 */
5597typedef DECLCALLBACK(int) FNPDMVBOXDEVICESREGISTER(PPDMDEVREGCB pCallbacks, uint32_t u32Version);
5598
5599/** @} */
5600
5601RT_C_DECLS_END
5602
5603#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