VirtualBox

source: vbox/trunk/include/VBox/pdmdrv.h@ 27965

Last change on this file since 27965 was 27935, checked in by vboxsync, 15 years ago

PDM: Document the pfnPowerOff behavior.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 56.9 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Drivers. (VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_pdmdrv_h
31#define ___VBox_pdmdrv_h
32
33#include <VBox/pdmqueue.h>
34#include <VBox/pdmcritsect.h>
35#include <VBox/pdmthread.h>
36#include <VBox/pdmifs.h>
37#include <VBox/pdmins.h>
38#include <VBox/pdmcommon.h>
39#include <VBox/pdmasynccompletion.h>
40#include <VBox/tm.h>
41#include <VBox/ssm.h>
42#include <VBox/cfgm.h>
43#include <VBox/dbgf.h>
44#include <VBox/mm.h>
45#include <VBox/err.h>
46#include <iprt/stdarg.h>
47
48RT_C_DECLS_BEGIN
49
50/** @defgroup grp_pdm_driver The PDM Drivers API
51 * @ingroup grp_pdm
52 * @{
53 */
54
55/** Pointer const PDM Driver API, ring-3. */
56typedef R3PTRTYPE(struct PDMDRVHLPR3 const *) PCPDMDRVHLPR3;
57/** Pointer const PDM Driver API, ring-0. */
58typedef R0PTRTYPE(struct PDMDRVHLPR0 const *) PCPDMDRVHLPR0;
59/** Pointer const PDM Driver API, raw-mode context. */
60typedef RCPTRTYPE(struct PDMDRVHLPRC const *) PCPDMDRVHLPRC;
61
62
63/**
64 * Construct a driver instance for a VM.
65 *
66 * @returns VBox status.
67 * @param pDrvIns The driver instance data. If the registration structure
68 * is needed, it can be accessed thru pDrvIns->pReg.
69 * @param pCfg Configuration node handle for the driver. This is
70 * expected to be in high demand in the constructor and is
71 * therefore passed as an argument. When using it at other
72 * times, it can be accessed via pDrvIns->pCfg.
73 * @param fFlags Flags, combination of the PDM_TACH_FLAGS_* \#defines.
74 */
75typedef DECLCALLBACK(int) FNPDMDRVCONSTRUCT(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
76/** Pointer to a FNPDMDRVCONSTRUCT() function. */
77typedef FNPDMDRVCONSTRUCT *PFNPDMDRVCONSTRUCT;
78
79/**
80 * Destruct a driver instance.
81 *
82 * Most VM resources are freed by the VM. This callback is provided so that
83 * any non-VM resources can be freed correctly.
84 *
85 * @param pDrvIns The driver instance data.
86 */
87typedef DECLCALLBACK(void) FNPDMDRVDESTRUCT(PPDMDRVINS pDrvIns);
88/** Pointer to a FNPDMDRVDESTRUCT() function. */
89typedef FNPDMDRVDESTRUCT *PFNPDMDRVDESTRUCT;
90
91/**
92 * Driver relocation callback.
93 *
94 * This is called when the instance data has been relocated in raw-mode context
95 * (RC). It is also called when the RC hypervisor selects changes. The driver
96 * must fixup all necessary pointers and re-query all interfaces to other RC
97 * devices and drivers.
98 *
99 * Before the RC code is executed the first time, this function will be called
100 * with a 0 delta so RC pointer calculations can be one in one place.
101 *
102 * @param pDrvIns Pointer to the driver instance.
103 * @param offDelta The relocation delta relative to the old location.
104 *
105 * @remark A relocation CANNOT fail.
106 */
107typedef DECLCALLBACK(void) FNPDMDRVRELOCATE(PPDMDRVINS pDrvIns, RTGCINTPTR offDelta);
108/** Pointer to a FNPDMDRVRELOCATE() function. */
109typedef FNPDMDRVRELOCATE *PFNPDMDRVRELOCATE;
110
111/**
112 * Driver I/O Control interface.
113 *
114 * This is used by external components, such as the COM interface, to
115 * communicate with a driver using a driver specific interface. Generally,
116 * the driver interfaces are used for this task.
117 *
118 * @returns VBox status code.
119 * @param pDrvIns Pointer to the driver instance.
120 * @param uFunction Function to perform.
121 * @param pvIn Pointer to input data.
122 * @param cbIn Size of input data.
123 * @param pvOut Pointer to output data.
124 * @param cbOut Size of output data.
125 * @param pcbOut Where to store the actual size of the output data.
126 */
127typedef DECLCALLBACK(int) FNPDMDRVIOCTL(PPDMDRVINS pDrvIns, uint32_t uFunction,
128 void *pvIn, uint32_t cbIn,
129 void *pvOut, uint32_t cbOut, uint32_t *pcbOut);
130/** Pointer to a FNPDMDRVIOCTL() function. */
131typedef FNPDMDRVIOCTL *PFNPDMDRVIOCTL;
132
133/**
134 * Power On notification.
135 *
136 * @param pDrvIns The driver instance data.
137 */
138typedef DECLCALLBACK(void) FNPDMDRVPOWERON(PPDMDRVINS pDrvIns);
139/** Pointer to a FNPDMDRVPOWERON() function. */
140typedef FNPDMDRVPOWERON *PFNPDMDRVPOWERON;
141
142/**
143 * Reset notification.
144 *
145 * @returns VBox status.
146 * @param pDrvIns The driver instance data.
147 */
148typedef DECLCALLBACK(void) FNPDMDRVRESET(PPDMDRVINS pDrvIns);
149/** Pointer to a FNPDMDRVRESET() function. */
150typedef FNPDMDRVRESET *PFNPDMDRVRESET;
151
152/**
153 * Suspend notification.
154 *
155 * @returns VBox status.
156 * @param pDrvIns The driver instance data.
157 */
158typedef DECLCALLBACK(void) FNPDMDRVSUSPEND(PPDMDRVINS pDrvIns);
159/** Pointer to a FNPDMDRVSUSPEND() function. */
160typedef FNPDMDRVSUSPEND *PFNPDMDRVSUSPEND;
161
162/**
163 * Resume notification.
164 *
165 * @returns VBox status.
166 * @param pDrvIns The driver instance data.
167 */
168typedef DECLCALLBACK(void) FNPDMDRVRESUME(PPDMDRVINS pDrvIns);
169/** Pointer to a FNPDMDRVRESUME() function. */
170typedef FNPDMDRVRESUME *PFNPDMDRVRESUME;
171
172/**
173 * Power Off notification.
174 *
175 * This is only called when the VMR3PowerOff call is made on a running VM. This
176 * means that there is no notification if the VM was suspended before being
177 * powered of. There will also be no callback when hot plugging devices or when
178 * replumbing the driver stack.
179 *
180 * @param pDrvIns The driver instance data.
181 */
182typedef DECLCALLBACK(void) FNPDMDRVPOWEROFF(PPDMDRVINS pDrvIns);
183/** Pointer to a FNPDMDRVPOWEROFF() function. */
184typedef FNPDMDRVPOWEROFF *PFNPDMDRVPOWEROFF;
185
186/**
187 * Attach command.
188 *
189 * This is called to let the drive attach to a driver at runtime. This is not
190 * called during VM construction, the driver constructor have to do this by
191 * calling PDMDrvHlpAttach.
192 *
193 * This is like plugging in the keyboard or mouse after turning on the PC.
194 *
195 * @returns VBox status code.
196 * @param pDrvIns The driver instance.
197 * @param fFlags Flags, combination of the PDM_TACH_FLAGS_* \#defines.
198 */
199typedef DECLCALLBACK(int) FNPDMDRVATTACH(PPDMDRVINS pDrvIns, uint32_t fFlags);
200/** Pointer to a FNPDMDRVATTACH() function. */
201typedef FNPDMDRVATTACH *PFNPDMDRVATTACH;
202
203/**
204 * Detach notification.
205 *
206 * This is called when a driver below it in the chain is detaching itself
207 * from it. The driver should adjust it's state to reflect this.
208 *
209 * This is like ejecting a cdrom or floppy.
210 *
211 * @param pDrvIns The driver instance.
212 * @param fFlags PDM_TACH_FLAGS_NOT_HOT_PLUG or 0.
213 */
214typedef DECLCALLBACK(void) FNPDMDRVDETACH(PPDMDRVINS pDrvIns, uint32_t fFlags);
215/** Pointer to a FNPDMDRVDETACH() function. */
216typedef FNPDMDRVDETACH *PFNPDMDRVDETACH;
217
218
219
220/**
221 * PDM Driver Registration Structure.
222 *
223 * This structure is used when registering a driver from VBoxInitDrivers() (in
224 * host ring-3 context). PDM will continue use till the VM is terminated.
225 */
226typedef struct PDMDRVREG
227{
228 /** Structure version. PDM_DRVREG_VERSION defines the current version. */
229 uint32_t u32Version;
230 /** Driver name. */
231 char szName[32];
232 /** Name of the raw-mode context module (no path).
233 * Only evalutated if PDM_DRVREG_FLAGS_RC is set. */
234 char szRCMod[32];
235 /** Name of the ring-0 module (no path).
236 * Only evalutated if PDM_DRVREG_FLAGS_R0 is set. */
237 char szR0Mod[32];
238 /** The description of the driver. The UTF-8 string pointed to shall, like this structure,
239 * remain unchanged from registration till VM destruction. */
240 const char *pszDescription;
241
242 /** Flags, combination of the PDM_DRVREG_FLAGS_* \#defines. */
243 uint32_t fFlags;
244 /** Driver class(es), combination of the PDM_DRVREG_CLASS_* \#defines. */
245 uint32_t fClass;
246 /** Maximum number of instances (per VM). */
247 uint32_t cMaxInstances;
248 /** Size of the instance data. */
249 uint32_t cbInstance;
250
251 /** Construct instance - required. */
252 PFNPDMDRVCONSTRUCT pfnConstruct;
253 /** Destruct instance - optional. */
254 PFNPDMDRVDESTRUCT pfnDestruct;
255 /** Relocation command - optional. */
256 PFNPDMDRVRELOCATE pfnRelocate;
257 /** I/O control - optional. */
258 PFNPDMDRVIOCTL pfnIOCtl;
259 /** Power on notification - optional. */
260 PFNPDMDRVPOWERON pfnPowerOn;
261 /** Reset notification - optional. */
262 PFNPDMDRVRESET pfnReset;
263 /** Suspend notification - optional. */
264 PFNPDMDRVSUSPEND pfnSuspend;
265 /** Resume notification - optional. */
266 PFNPDMDRVRESUME pfnResume;
267 /** Attach command - optional. */
268 PFNPDMDRVATTACH pfnAttach;
269 /** Detach notification - optional. */
270 PFNPDMDRVDETACH pfnDetach;
271 /** Power off notification - optional. */
272 PFNPDMDRVPOWEROFF pfnPowerOff;
273 /** @todo */
274 PFNRT pfnSoftReset;
275 /** Initialization safty marker. */
276 uint32_t u32VersionEnd;
277} PDMDRVREG;
278/** Pointer to a PDM Driver Structure. */
279typedef PDMDRVREG *PPDMDRVREG;
280/** Const pointer to a PDM Driver Structure. */
281typedef PDMDRVREG const *PCPDMDRVREG;
282
283/** Current DRVREG version number. */
284#define PDM_DRVREG_VERSION PDM_VERSION_MAKE(0xf0ff, 1, 0)
285
286/** PDM Driver Flags.
287 * @{ */
288/** @def PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT
289 * The bit count for the current host. */
290#if HC_ARCH_BITS == 32
291# define PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT UINT32_C(0x00000001)
292#elif HC_ARCH_BITS == 64
293# define PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT UINT32_C(0x00000002)
294#else
295# error Unsupported HC_ARCH_BITS value.
296#endif
297/** The host bit count mask. */
298#define PDM_DRVREG_FLAGS_HOST_BITS_MASK UINT32_C(0x00000003)
299/** This flag is used to indicate that the driver has a RC component. */
300#define PDM_DRVREG_FLAGS_RC UINT32_C(0x00000010)
301/** This flag is used to indicate that the driver has a R0 component. */
302#define PDM_DRVREG_FLAGS_R0 UINT32_C(0x00000020)
303
304/** @} */
305
306
307/** PDM Driver Classes.
308 * @{ */
309/** Mouse input driver. */
310#define PDM_DRVREG_CLASS_MOUSE RT_BIT(0)
311/** Keyboard input driver. */
312#define PDM_DRVREG_CLASS_KEYBOARD RT_BIT(1)
313/** Display driver. */
314#define PDM_DRVREG_CLASS_DISPLAY RT_BIT(2)
315/** Network transport driver. */
316#define PDM_DRVREG_CLASS_NETWORK RT_BIT(3)
317/** Block driver. */
318#define PDM_DRVREG_CLASS_BLOCK RT_BIT(4)
319/** Media driver. */
320#define PDM_DRVREG_CLASS_MEDIA RT_BIT(5)
321/** Mountable driver. */
322#define PDM_DRVREG_CLASS_MOUNTABLE RT_BIT(6)
323/** Audio driver. */
324#define PDM_DRVREG_CLASS_AUDIO RT_BIT(7)
325/** VMMDev driver. */
326#define PDM_DRVREG_CLASS_VMMDEV RT_BIT(8)
327/** Status driver. */
328#define PDM_DRVREG_CLASS_STATUS RT_BIT(9)
329/** ACPI driver. */
330#define PDM_DRVREG_CLASS_ACPI RT_BIT(10)
331/** USB related driver. */
332#define PDM_DRVREG_CLASS_USB RT_BIT(11)
333/** ISCSI Transport related driver. */
334#define PDM_DRVREG_CLASS_ISCSITRANSPORT RT_BIT(12)
335/** Char driver. */
336#define PDM_DRVREG_CLASS_CHAR RT_BIT(13)
337/** Stream driver. */
338#define PDM_DRVREG_CLASS_STREAM RT_BIT(14)
339/** SCSI driver. */
340#define PDM_DRVREG_CLASS_SCSI RT_BIT(15)
341/** @} */
342
343
344/**
345 * PDM Driver Instance.
346 *
347 * @implements PDMIBASE
348 */
349typedef struct PDMDRVINS
350{
351 /** Structure version. PDM_DRVINS_VERSION defines the current version. */
352 uint32_t u32Version;
353 /** Driver instance number. */
354 uint32_t iInstance;
355
356 /** Pointer the PDM Driver API. */
357 RCPTRTYPE(PCPDMDRVHLPRC) pHlpRC;
358 /** Pointer to driver instance data. */
359 RCPTRTYPE(void *) pvInstanceDataRC;
360
361 /** Pointer the PDM Driver API. */
362 R0PTRTYPE(PCPDMDRVHLPR0) pHlpR0;
363 /** Pointer to driver instance data. */
364 R0PTRTYPE(void *) pvInstanceDataR0;
365
366 /** Pointer the PDM Driver API. */
367 R3PTRTYPE(PCPDMDRVHLPR3) pHlpR3;
368 /** Pointer to driver instance data. */
369 R3PTRTYPE(void *) pvInstanceDataR3;
370
371 /** Pointer to driver registration structure. */
372 R3PTRTYPE(PCPDMDRVREG) pReg;
373 /** Configuration handle. */
374 R3PTRTYPE(PCFGMNODE) pCfg;
375
376 /** Pointer to the base interface of the device/driver instance above. */
377 R3PTRTYPE(PPDMIBASE) pUpBase;
378 /** Pointer to the base interface of the driver instance below. */
379 R3PTRTYPE(PPDMIBASE) pDownBase;
380
381 /** The base interface of the driver.
382 * The driver constructor initializes this. */
383 PDMIBASE IBase;
384 /** Align the internal data more naturally. */
385 RTR3PTR R3PtrPadding;
386
387 /** Internal data. */
388 union
389 {
390#ifdef PDMDRVINSINT_DECLARED
391 PDMDRVINSINT s;
392#endif
393 uint8_t padding[HC_ARCH_BITS == 32 ? 40 + 32 : 72 + 24];
394 } Internal;
395
396 /** Driver instance data. The size of this area is defined
397 * in the PDMDRVREG::cbInstanceData field. */
398 char achInstanceData[4];
399} PDMDRVINS;
400
401/** Current DRVREG version number. */
402#define PDM_DRVINS_VERSION PDM_VERSION_MAKE(0xf0fe, 1, 0)
403
404/** Converts a pointer to the PDMDRVINS::IBase to a pointer to PDMDRVINS. */
405#define PDMIBASE_2_PDMDRV(pInterface) ( (PPDMDRVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDRVINS, IBase)) )
406
407/**
408 * Checks the structure versions of the drive instance and driver helpers,
409 * returning if they are incompatible.
410 *
411 * Intended for the constructor.
412 *
413 * @param pDrvIns Pointer to the PDM driver instance.
414 */
415#define PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns) \
416 do \
417 { \
418 PPDMDRVINS pDrvInsTypeCheck = (pDrvIns); NOREF(pDrvInsTypeCheck); \
419 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDrvIns)->u32Version, PDM_DRVINS_VERSION), \
420 ("DrvIns=%#x mine=%#x\n", (pDrvIns)->u32Version, PDM_DRVINS_VERSION), \
421 VERR_VERSION_MISMATCH); \
422 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pDrvIns)->pHlpR3->u32Version, PDM_DRVHLPR3_VERSION), \
423 ("DrvHlp=%#x mine=%#x\n", (pDrvIns)->pHlpR3->u32Version, PDM_DRVHLPR3_VERSION), \
424 VERR_VERSION_MISMATCH); \
425 } while (0)
426
427/**
428 * Quietly checks the structure versions of the drive instance and driver
429 * helpers, returning if they are incompatible.
430 *
431 * Intended for the destructor.
432 *
433 * @param pDrvIns Pointer to the PDM driver instance.
434 */
435#define PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns) \
436 do \
437 { \
438 PPDMDRVINS pDrvInsTypeCheck = (pDrvIns); NOREF(pDrvInsTypeCheck); \
439 if (RT_UNLIKELY( !PDM_VERSION_ARE_COMPATIBLE((pDrvIns)->u32Version, PDM_DRVINS_VERSION) \
440 || !PDM_VERSION_ARE_COMPATIBLE((pDrvIns)->pHlpR3->u32Version, PDM_DRVHLPR3_VERSION)) ) \
441 return; \
442 } while (0)
443
444/**
445 * Wrapper around CFGMR3ValidateConfig for the root config for use in the
446 * constructor - returns on failure.
447 *
448 * This should be invoked after having initialized the instance data
449 * sufficiently for the correct operation of the destructor. The destructor is
450 * always called!
451 *
452 * @param pDrvIns Pointer to the PDM driver instance.
453 * @param pszValidValues Patterns describing the valid value names. See
454 * RTStrSimplePatternMultiMatch for details on the
455 * pattern syntax.
456 * @param pszValidNodes Patterns describing the valid node (key) names.
457 * Pass empty string if no valid nodess.
458 */
459#define PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, pszValidValues, pszValidNodes) \
460 do \
461 { \
462 int rcValCfg = CFGMR3ValidateConfig((pDrvIns)->pCfg, "/", pszValidValues, pszValidNodes, \
463 (pDrvIns)->pReg->szName, (pDrvIns)->iInstance); \
464 if (RT_FAILURE(rcValCfg)) \
465 return rcValCfg; \
466 } while (0)
467
468
469
470/**
471 * USB hub registration structure.
472 */
473typedef struct PDMUSBHUBREG
474{
475 /** Structure version number. PDM_USBHUBREG_VERSION defines the current version. */
476 uint32_t u32Version;
477
478 /**
479 * Request the hub to attach of the specified device.
480 *
481 * @returns VBox status code.
482 * @param pDrvIns The hub instance.
483 * @param pUsbIns The device to attach.
484 * @param piPort Where to store the port number the device was attached to.
485 * @thread EMT.
486 */
487 DECLR3CALLBACKMEMBER(int, pfnAttachDevice,(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, uint32_t *piPort));
488
489 /**
490 * Request the hub to detach of the specified device.
491 *
492 * The device has previously been attached to the hub with the
493 * pfnAttachDevice call. This call is not currently expected to
494 * fail.
495 *
496 * @returns VBox status code.
497 * @param pDrvIns The hub instance.
498 * @param pUsbIns The device to detach.
499 * @param iPort The port number returned by the attach call.
500 * @thread EMT.
501 */
502 DECLR3CALLBACKMEMBER(int, pfnDetachDevice,(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, uint32_t iPort));
503
504 /** Counterpart to u32Version, same value. */
505 uint32_t u32TheEnd;
506} PDMUSBHUBREG;
507/** Pointer to a const USB hub registration structure. */
508typedef const PDMUSBHUBREG *PCPDMUSBHUBREG;
509
510/** Current PDMUSBHUBREG version number. */
511#define PDM_USBHUBREG_VERSION PDM_VERSION_MAKE(0xf0fd, 1, 0)
512
513
514/**
515 * USB hub helpers.
516 * This is currently just a place holder.
517 */
518typedef struct PDMUSBHUBHLP
519{
520 /** Structure version. PDM_USBHUBHLP_VERSION defines the current version. */
521 uint32_t u32Version;
522
523 /** Just a safety precaution. */
524 uint32_t u32TheEnd;
525} PDMUSBHUBHLP;
526/** Pointer to PCI helpers. */
527typedef PDMUSBHUBHLP *PPDMUSBHUBHLP;
528/** Pointer to const PCI helpers. */
529typedef const PDMUSBHUBHLP *PCPDMUSBHUBHLP;
530/** Pointer to const PCI helpers pointer. */
531typedef PCPDMUSBHUBHLP *PPCPDMUSBHUBHLP;
532
533/** Current PDMUSBHUBHLP version number. */
534#define PDM_USBHUBHLP_VERSION PDM_VERSION_MAKE(0xf0fc, 1, 0)
535
536
537/**
538 * PDM Driver API - raw-mode context variant.
539 */
540typedef struct PDMDRVHLPRC
541{
542 /** Structure version. PDM_DRVHLPRC_VERSION defines the current version. */
543 uint32_t u32Version;
544
545 /**
546 * Set the VM error message
547 *
548 * @returns rc.
549 * @param pDrvIns Driver instance.
550 * @param rc VBox status code.
551 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
552 * @param pszFormat Error message format string.
553 * @param ... Error message arguments.
554 */
555 DECLRCCALLBACKMEMBER(int, pfnVMSetError,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
556
557 /**
558 * Set the VM error message
559 *
560 * @returns rc.
561 * @param pDrvIns Driver instance.
562 * @param rc VBox status code.
563 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
564 * @param pszFormat Error message format string.
565 * @param va Error message arguments.
566 */
567 DECLRCCALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
568
569 /**
570 * Set the VM runtime error message
571 *
572 * @returns VBox status code.
573 * @param pDrvIns Driver instance.
574 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
575 * @param pszErrorId Error ID string.
576 * @param pszFormat Error message format string.
577 * @param ... Error message arguments.
578 */
579 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
580
581 /**
582 * Set the VM runtime error message
583 *
584 * @returns VBox status code.
585 * @param pDrvIns Driver instance.
586 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
587 * @param pszErrorId Error ID string.
588 * @param pszFormat Error message format string.
589 * @param va Error message arguments.
590 */
591 DECLRCCALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
592
593 /**
594 * Assert that the current thread is the emulation thread.
595 *
596 * @returns True if correct.
597 * @returns False if wrong.
598 * @param pDrvIns Driver instance.
599 * @param pszFile Filename of the assertion location.
600 * @param iLine Linenumber of the assertion location.
601 * @param pszFunction Function of the assertion location.
602 */
603 DECLRCCALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
604
605 /**
606 * Assert that the current thread is NOT the emulation thread.
607 *
608 * @returns True if correct.
609 * @returns False if wrong.
610 * @param pDrvIns Driver instance.
611 * @param pszFile Filename of the assertion location.
612 * @param iLine Linenumber of the assertion location.
613 * @param pszFunction Function of the assertion location.
614 */
615 DECLRCCALLBACKMEMBER(bool, pfnAssertOther,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
616
617 /** Just a safety precaution. */
618 uint32_t u32TheEnd;
619} PDMDRVHLPRC;
620/** Current PDMDRVHLPRC version number. */
621#define PDM_DRVHLPRC_VERSION PDM_VERSION_MAKE(0xf0f9, 1, 0)
622
623
624/**
625 * PDM Driver API, ring-0 context.
626 */
627typedef struct PDMDRVHLPR0
628{
629 /** Structure version. PDM_DRVHLPR0_VERSION defines the current version. */
630 uint32_t u32Version;
631
632 /**
633 * Set the VM error message
634 *
635 * @returns rc.
636 * @param pDrvIns Driver instance.
637 * @param rc VBox status code.
638 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
639 * @param pszFormat Error message format string.
640 * @param ... Error message arguments.
641 */
642 DECLR0CALLBACKMEMBER(int, pfnVMSetError,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
643
644 /**
645 * Set the VM error message
646 *
647 * @returns rc.
648 * @param pDrvIns Driver instance.
649 * @param rc VBox status code.
650 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
651 * @param pszFormat Error message format string.
652 * @param va Error message arguments.
653 */
654 DECLR0CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
655
656 /**
657 * Set the VM runtime error message
658 *
659 * @returns VBox status code.
660 * @param pDrvIns Driver instance.
661 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
662 * @param pszErrorId Error ID string.
663 * @param pszFormat Error message format string.
664 * @param ... Error message arguments.
665 */
666 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
667
668 /**
669 * Set the VM runtime error message
670 *
671 * @returns VBox status code.
672 * @param pDrvIns Driver instance.
673 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
674 * @param pszErrorId Error ID string.
675 * @param pszFormat Error message format string.
676 * @param va Error message arguments.
677 */
678 DECLR0CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
679
680 /**
681 * Assert that the current thread is the emulation thread.
682 *
683 * @returns True if correct.
684 * @returns False if wrong.
685 * @param pDrvIns Driver instance.
686 * @param pszFile Filename of the assertion location.
687 * @param iLine Linenumber of the assertion location.
688 * @param pszFunction Function of the assertion location.
689 */
690 DECLR0CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
691
692 /**
693 * Assert that the current thread is NOT the emulation thread.
694 *
695 * @returns True if correct.
696 * @returns False if wrong.
697 * @param pDrvIns Driver instance.
698 * @param pszFile Filename of the assertion location.
699 * @param iLine Linenumber of the assertion location.
700 * @param pszFunction Function of the assertion location.
701 */
702 DECLR0CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
703
704 /** Just a safety precaution. */
705 uint32_t u32TheEnd;
706} PDMDRVHLPR0;
707/** Current DRVHLP version number. */
708#define PDM_DRVHLPR0_VERSION PDM_VERSION_MAKE(0xf0f8, 1, 0)
709
710
711#ifdef IN_RING3
712
713/**
714 * PDM Driver API.
715 */
716typedef struct PDMDRVHLPR3
717{
718 /** Structure version. PDM_DRVHLPR3_VERSION defines the current version. */
719 uint32_t u32Version;
720
721 /**
722 * Attaches a driver (chain) to the driver.
723 *
724 * @returns VBox status code.
725 * @param pDrvIns Driver instance.
726 * @param fFlags PDM_TACH_FLAGS_NOT_HOT_PLUG or 0.
727 * @param ppBaseInterface Where to store the pointer to the base interface.
728 */
729 DECLR3CALLBACKMEMBER(int, pfnAttach,(PPDMDRVINS pDrvIns, uint32_t fFlags, PPDMIBASE *ppBaseInterface));
730
731 /**
732 * Detach the driver the drivers below us.
733 *
734 * @returns VBox status code.
735 * @param pDrvIns Driver instance.
736 * @param fFlags PDM_TACH_FLAGS_NOT_HOT_PLUG or 0.
737 */
738 DECLR3CALLBACKMEMBER(int, pfnDetach,(PPDMDRVINS pDrvIns, uint32_t fFlags));
739
740 /**
741 * Detach the driver from the driver above it and destroy this
742 * driver and all drivers below it.
743 *
744 * @returns VBox status code.
745 * @param pDrvIns Driver instance.
746 * @param fFlags PDM_TACH_FLAGS_NOT_HOT_PLUG or 0.
747 */
748 DECLR3CALLBACKMEMBER(int, pfnDetachSelf,(PPDMDRVINS pDrvIns, uint32_t fFlags));
749
750 /**
751 * Prepare a media mount.
752 *
753 * The driver must not have anything attached to itself
754 * when calling this function as the purpose is to set up the configuration
755 * of an future attachment.
756 *
757 * @returns VBox status code
758 * @param pDrvIns Driver instance.
759 * @param pszFilename Pointer to filename. If this is NULL it assumed that the caller have
760 * constructed a configuration which can be attached to the bottom driver.
761 * @param pszCoreDriver Core driver name. NULL will cause autodetection. Ignored if pszFilanem is NULL.
762 */
763 DECLR3CALLBACKMEMBER(int, pfnMountPrepare,(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver));
764
765 /**
766 * Assert that the current thread is the emulation thread.
767 *
768 * @returns True if correct.
769 * @returns False if wrong.
770 * @param pDrvIns Driver instance.
771 * @param pszFile Filename of the assertion location.
772 * @param iLine Linenumber of the assertion location.
773 * @param pszFunction Function of the assertion location.
774 */
775 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
776
777 /**
778 * Assert that the current thread is NOT the emulation thread.
779 *
780 * @returns True if correct.
781 * @returns False if wrong.
782 * @param pDrvIns Driver instance.
783 * @param pszFile Filename of the assertion location.
784 * @param iLine Linenumber of the assertion location.
785 * @param pszFunction Function of the assertion location.
786 */
787 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
788
789 /**
790 * Set the VM error message
791 *
792 * @returns rc.
793 * @param pDrvIns Driver instance.
794 * @param rc VBox status code.
795 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
796 * @param pszFormat Error message format string.
797 * @param ... Error message arguments.
798 */
799 DECLR3CALLBACKMEMBER(int, pfnVMSetError,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
800
801 /**
802 * Set the VM error message
803 *
804 * @returns rc.
805 * @param pDrvIns Driver instance.
806 * @param rc VBox status code.
807 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
808 * @param pszFormat Error message format string.
809 * @param va Error message arguments.
810 */
811 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
812
813 /**
814 * Set the VM runtime error message
815 *
816 * @returns VBox status code.
817 * @param pDrvIns Driver instance.
818 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
819 * @param pszErrorId Error ID string.
820 * @param pszFormat Error message format string.
821 * @param ... Error message arguments.
822 */
823 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...));
824
825 /**
826 * Set the VM runtime error message
827 *
828 * @returns VBox status code.
829 * @param pDrvIns Driver instance.
830 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
831 * @param pszErrorId Error ID string.
832 * @param pszFormat Error message format string.
833 * @param va Error message arguments.
834 */
835 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
836
837 /**
838 * Gets the VM state.
839 *
840 * @returns VM state.
841 * @param pDrvIns The driver instance.
842 * @thread Any thread (just keep in mind that it's volatile info).
843 */
844 DECLR3CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDRVINS pDrvIns));
845
846 /**
847 * Checks if the VM was teleported and hasn't been fully resumed yet.
848 *
849 * @returns true / false.
850 * @param pDrvIns The driver instance.
851 * @thread Any thread.
852 */
853 DECLR3CALLBACKMEMBER(bool, pfnVMTeleportedAndNotFullyResumedYet,(PPDMDRVINS pDrvIns));
854
855 /**
856 * Create a queue.
857 *
858 * @returns VBox status code.
859 * @param pDrvIns Driver instance.
860 * @param cbItem Size a queue item.
861 * @param cItems Number of items in the queue.
862 * @param cMilliesInterval Number of milliseconds between polling the queue.
863 * If 0 then the emulation thread will be notified whenever an item arrives.
864 * @param pfnCallback The consumer function.
865 * @param pszName The queue base name. The instance number will be
866 * appended automatically.
867 * @param ppQueue Where to store the queue handle on success.
868 * @thread The emulation thread.
869 */
870 DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMDRVINS pDrvIns, uint32_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
871 PFNPDMQUEUEDRV pfnCallback, const char *pszName, PPDMQUEUE *ppQueue));
872
873 /**
874 * Query the virtual timer frequency.
875 *
876 * @returns Frequency in Hz.
877 * @param pDrvIns Driver instance.
878 * @thread Any thread.
879 */
880 DECLR3CALLBACKMEMBER(uint64_t, pfnTMGetVirtualFreq,(PPDMDRVINS pDrvIns));
881
882 /**
883 * Query the virtual time.
884 *
885 * @returns The current virtual time.
886 * @param pDrvIns Driver instance.
887 * @thread Any thread.
888 */
889 DECLR3CALLBACKMEMBER(uint64_t, pfnTMGetVirtualTime,(PPDMDRVINS pDrvIns));
890
891 /**
892 * Creates a timer.
893 *
894 * @returns VBox status.
895 * @param pDrvIns Driver instance.
896 * @param enmClock The clock to use on this timer.
897 * @param pfnCallback Callback function.
898 * @param pvUser The user argument to the callback.
899 * @param fFlags Timer creation flags, see grp_tm_timer_flags.
900 * @param pszDesc Pointer to description string which must stay around
901 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
902 * @param ppTimer Where to store the timer on success.
903 * @thread EMT
904 */
905 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer));
906
907 /**
908 * Register a save state data unit.
909 *
910 * @returns VBox status.
911 * @param pDrvIns Driver instance.
912 * @param uVersion Data layout version number.
913 * @param cbGuess The approximate amount of data in the unit.
914 * Only for progress indicators.
915 *
916 * @param pfnLivePrep Prepare live save callback, optional.
917 * @param pfnLiveExec Execute live save callback, optional.
918 * @param pfnLiveVote Vote live save callback, optional.
919 *
920 * @param pfnSavePrep Prepare save callback, optional.
921 * @param pfnSaveExec Execute save callback, optional.
922 * @param pfnSaveDone Done save callback, optional.
923 *
924 * @param pfnLoadPrep Prepare load callback, optional.
925 * @param pfnLoadExec Execute load callback, optional.
926 * @param pfnLoadDone Done load callback, optional.
927 */
928 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMDRVINS pDrvIns, uint32_t uVersion, size_t cbGuess,
929 PFNSSMDRVLIVEPREP pfnLivePrep, PFNSSMDRVLIVEEXEC pfnLiveExec, PFNSSMDRVLIVEVOTE pfnLiveVote,
930 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
931 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone));
932
933 /**
934 * Deregister a save state data unit.
935 *
936 * @returns VBox status.
937 * @param pDrvIns Driver instance.
938 * @param pszName Data unit name.
939 * @param uInstance The instance identifier of the data unit.
940 * This must together with the name be unique.
941 */
942 DECLR3CALLBACKMEMBER(int, pfnSSMDeregister,(PPDMDRVINS pDrvIns, const char *pszName, uint32_t uInstance));
943
944 /**
945 * Registers a statistics sample if statistics are enabled.
946 *
947 * @param pDrvIns Driver instance.
948 * @param pvSample Pointer to the sample.
949 * @param enmType Sample type. This indicates what pvSample is pointing at.
950 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
951 * Further nesting is possible.
952 * @param enmUnit Sample unit.
953 * @param pszDesc Sample description.
954 */
955 DECLR3CALLBACKMEMBER(void, pfnSTAMRegister,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName,
956 STAMUNIT enmUnit, const char *pszDesc));
957
958 /**
959 * Same as pfnSTAMRegister except that the name is specified in a
960 * RTStrPrintf like fashion.
961 *
962 * @param pDrvIns Driver instance.
963 * @param pvSample Pointer to the sample.
964 * @param enmType Sample type. This indicates what pvSample is pointing at.
965 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
966 * @param enmUnit Sample unit.
967 * @param pszDesc Sample description.
968 * @param pszName The sample name format string.
969 * @param ... Arguments to the format string.
970 */
971 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterF,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
972 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...));
973
974 /**
975 * Same as pfnSTAMRegister except that the name is specified in a
976 * RTStrPrintfV like fashion.
977 *
978 * @param pDrvIns Driver instance.
979 * @param pvSample Pointer to the sample.
980 * @param enmType Sample type. This indicates what pvSample is pointing at.
981 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
982 * @param enmUnit Sample unit.
983 * @param pszDesc Sample description.
984 * @param pszName The sample name format string.
985 * @param args Arguments to the format string.
986 */
987 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
988 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args));
989
990 /**
991 * Deregister a statistic item previously registered with pfnSTAMRegister,
992 * pfnSTAMRegisterF or pfnSTAMRegisterV
993 *
994 * @returns VBox status.
995 * @param pDrvIns Driver instance.
996 * @param pvSample Pointer to the sample.
997 */
998 DECLR3CALLBACKMEMBER(int, pfnSTAMDeregister,(PPDMDRVINS pDrvIns, void *pvSample));
999
1000 /**
1001 * Calls the HC R0 VMM entry point, in a safer but slower manner than
1002 * SUPR3CallVMMR0.
1003 *
1004 * When entering using this call the R0 components can call into the host kernel
1005 * (i.e. use the SUPR0 and RT APIs).
1006 *
1007 * See VMMR0Entry() for more details.
1008 *
1009 * @returns error code specific to uFunction.
1010 * @param pDrvIns The driver instance.
1011 * @param uOperation Operation to execute.
1012 * This is limited to services.
1013 * @param pvArg Pointer to argument structure or if cbArg is 0 just an value.
1014 * @param cbArg The size of the argument. This is used to copy whatever the argument
1015 * points at into a kernel buffer to avoid problems like the user page
1016 * being invalidated while we're executing the call.
1017 */
1018 DECLR3CALLBACKMEMBER(int, pfnSUPCallVMMR0Ex,(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg));
1019
1020 /**
1021 * Registers a USB HUB.
1022 *
1023 * @returns VBox status code.
1024 * @param pDrvIns The driver instance.
1025 * @param fVersions Indicates the kinds of USB devices that can be attached to this HUB.
1026 * @param cPorts The number of ports.
1027 * @param pUsbHubReg The hub callback structure that PDMUsb uses to interact with it.
1028 * @param ppUsbHubHlp The helper callback structure that the hub uses to talk to PDMUsb.
1029 *
1030 * @thread EMT.
1031 */
1032 DECLR3CALLBACKMEMBER(int, pfnUSBRegisterHub,(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp));
1033
1034 /**
1035 * Set up asynchronous handling of a suspend, reset or power off notification.
1036 *
1037 * This shall only be called when getting the notification. It must be called
1038 * for each one.
1039 *
1040 * @returns VBox status code.
1041 * @param pDrvIns The driver instance.
1042 * @param pfnAsyncNotify The callback.
1043 * @thread EMT(0)
1044 */
1045 DECLR3CALLBACKMEMBER(int, pfnSetAsyncNotification, (PPDMDRVINS pDrvIns, PFNPDMDRVASYNCNOTIFY pfnAsyncNotify));
1046
1047 /**
1048 * Notify EMT(0) that the driver has completed the asynchronous notification
1049 * handling.
1050 *
1051 * This can be called at any time, spurious calls will simply be ignored.
1052 *
1053 * @param pDrvIns The driver instance.
1054 * @thread Any
1055 */
1056 DECLR3CALLBACKMEMBER(void, pfnAsyncNotificationCompleted, (PPDMDRVINS pDrvIns));
1057
1058 /**
1059 * Creates a PDM thread.
1060 *
1061 * This differs from the RTThreadCreate() API in that PDM takes care of suspending,
1062 * resuming, and destroying the thread as the VM state changes.
1063 *
1064 * @returns VBox status code.
1065 * @param pDrvIns The driver instance.
1066 * @param ppThread Where to store the thread 'handle'.
1067 * @param pvUser The user argument to the thread function.
1068 * @param pfnThread The thread function.
1069 * @param pfnWakeup The wakup callback. This is called on the EMT thread when
1070 * a state change is pending.
1071 * @param cbStack See RTThreadCreate.
1072 * @param enmType See RTThreadCreate.
1073 * @param pszName See RTThreadCreate.
1074 */
1075 DECLR3CALLBACKMEMBER(int, pfnPDMThreadCreate,(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
1076 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName));
1077
1078 /**
1079 * Creates a async completion template for a driver instance.
1080 *
1081 * The template is used when creating new completion tasks.
1082 *
1083 * @returns VBox status code.
1084 * @param pDrvIns The driver instance.
1085 * @param ppTemplate Where to store the template pointer on success.
1086 * @param pfnCompleted The completion callback routine.
1087 * @param pvTemplateUser Template user argument.
1088 * @param pszDesc Description.
1089 */
1090 DECLR3CALLBACKMEMBER(int, pfnPDMAsyncCompletionTemplateCreate,(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
1091 PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser,
1092 const char *pszDesc));
1093
1094
1095 /**
1096 * Resolves the symbol for a raw-mode context interface.
1097 *
1098 * @returns VBox status code.
1099 * @param pDrvIns The driver instance.
1100 * @param pvInterface The interface structure.
1101 * @param cbInterface The size of the interface structure.
1102 * @param pszSymPrefix What to prefix the symbols in the list with before
1103 * resolving them. This must start with 'drv' and
1104 * contain the driver name.
1105 * @param pszSymList List of symbols corresponding to the interface.
1106 * There is generally a there is generally a define
1107 * holding this list associated with the interface
1108 * definition (INTERFACE_SYM_LIST). For more details
1109 * see PDMR3LdrGetInterfaceSymbols.
1110 * @thread EMT
1111 */
1112 DECLR3CALLBACKMEMBER(int, pfnPDMLdrGetRCInterfaceSymbols,(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
1113 const char *pszSymPrefix, const char *pszSymList));
1114
1115 /**
1116 * Resolves the symbol for a ring-0 context interface.
1117 *
1118 * @returns VBox status code.
1119 * @param pDrvIns The driver instance.
1120 * @param pvInterface The interface structure.
1121 * @param cbInterface The size of the interface structure.
1122 * @param pszSymPrefix What to prefix the symbols in the list with before
1123 * resolving them. This must start with 'drv' and
1124 * contain the driver name.
1125 * @param pszSymList List of symbols corresponding to the interface.
1126 * There is generally a there is generally a define
1127 * holding this list associated with the interface
1128 * definition (INTERFACE_SYM_LIST). For more details
1129 * see PDMR3LdrGetInterfaceSymbols.
1130 * @thread EMT
1131 */
1132 DECLR3CALLBACKMEMBER(int, pfnPDMLdrGetR0InterfaceSymbols,(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
1133 const char *pszSymPrefix, const char *pszSymList));
1134 /** Just a safety precaution. */
1135 uint32_t u32TheEnd;
1136} PDMDRVHLPR3;
1137/** Current DRVHLP version number. */
1138#define PDM_DRVHLPR3_VERSION PDM_VERSION_MAKE(0xf0fb, 1, 0)
1139
1140#endif /* IN_RING3 */
1141
1142
1143/**
1144 * @copydoc PDMDRVHLP::pfnVMSetError
1145 */
1146DECLINLINE(int) PDMDrvHlpVMSetError(PPDMDRVINS pDrvIns, const int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
1147{
1148 va_list va;
1149 va_start(va, pszFormat);
1150 pDrvIns->CTX_SUFF(pHlp)->pfnVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
1151 va_end(va);
1152 return rc;
1153}
1154
1155/** @def PDMDRV_SET_ERROR
1156 * Set the VM error. See PDMDrvHlpVMSetError() for printf like message formatting.
1157 */
1158#define PDMDRV_SET_ERROR(pDrvIns, rc, pszError) \
1159 PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, "%s", pszError)
1160
1161/**
1162 * @copydoc PDMDRVHLP::pfnVMSetErrorV
1163 */
1164DECLINLINE(int) PDMDrvHlpVMSetErrorV(PPDMDRVINS pDrvIns, const int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
1165{
1166 return pDrvIns->CTX_SUFF(pHlp)->pfnVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
1167}
1168
1169
1170/**
1171 * @copydoc PDMDRVHLP::pfnVMSetRuntimeError
1172 */
1173DECLINLINE(int) PDMDrvHlpVMSetRuntimeError(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
1174{
1175 va_list va;
1176 int rc;
1177 va_start(va, pszFormat);
1178 rc = pDrvIns->CTX_SUFF(pHlp)->pfnVMSetRuntimeErrorV(pDrvIns, fFlags, pszErrorId, pszFormat, va);
1179 va_end(va);
1180 return rc;
1181}
1182
1183/** @def PDMDRV_SET_RUNTIME_ERROR
1184 * Set the VM runtime error. See PDMDrvHlpVMSetRuntimeError() for printf like message formatting.
1185 */
1186#define PDMDRV_SET_RUNTIME_ERROR(pDrvIns, fFlags, pszErrorId, pszError) \
1187 PDMDrvHlpVMSetRuntimeError(pDrvIns, fFlags, pszErrorId, "%s", pszError)
1188
1189/**
1190 * @copydoc PDMDRVHLP::pfnVMSetRuntimeErrorV
1191 */
1192DECLINLINE(int) PDMDrvHlpVMSetRuntimeErrorV(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
1193{
1194 return pDrvIns->CTX_SUFF(pHlp)->pfnVMSetRuntimeErrorV(pDrvIns, fFlags, pszErrorId, pszFormat, va);
1195}
1196
1197
1198
1199/** @def PDMDRV_ASSERT_EMT
1200 * Assert that the current thread is the emulation thread.
1201 */
1202#ifdef VBOX_STRICT
1203# define PDMDRV_ASSERT_EMT(pDrvIns) pDrvIns->CTX_SUFF(pHlp)->pfnAssertEMT(pDrvIns, __FILE__, __LINE__, __FUNCTION__)
1204#else
1205# define PDMDRV_ASSERT_EMT(pDrvIns) do { } while (0)
1206#endif
1207
1208/** @def PDMDRV_ASSERT_OTHER
1209 * Assert that the current thread is NOT the emulation thread.
1210 */
1211#ifdef VBOX_STRICT
1212# define PDMDRV_ASSERT_OTHER(pDrvIns) pDrvIns->CTX_SUFF(pHlp)->pfnAssertOther(pDrvIns, __FILE__, __LINE__, __FUNCTION__)
1213#else
1214# define PDMDRV_ASSERT_OTHER(pDrvIns) do { } while (0)
1215#endif
1216
1217
1218#ifdef IN_RING3
1219
1220/**
1221 * @copydoc PDMDRVHLP::pfnAttach
1222 */
1223DECLINLINE(int) PDMDrvHlpAttach(PPDMDRVINS pDrvIns, uint32_t fFlags, PPDMIBASE *ppBaseInterface)
1224{
1225 return pDrvIns->pHlpR3->pfnAttach(pDrvIns, fFlags, ppBaseInterface);
1226}
1227
1228/**
1229 * Check that there is no driver below the us that we should attach to.
1230 *
1231 * @returns VERR_PDM_NO_ATTACHED_DRIVER if there is no driver.
1232 * @param pDrvIns The driver instance.
1233 */
1234DECLINLINE(int) PDMDrvHlpNoAttach(PPDMDRVINS pDrvIns)
1235{
1236 return pDrvIns->pHlpR3->pfnAttach(pDrvIns, 0, NULL);
1237}
1238
1239/**
1240 * @copydoc PDMDRVHLP::pfnDetach
1241 */
1242DECLINLINE(int) PDMDrvHlpDetach(PPDMDRVINS pDrvIns, uint32_t fFlags)
1243{
1244 return pDrvIns->pHlpR3->pfnDetach(pDrvIns, fFlags);
1245}
1246
1247/**
1248 * @copydoc PDMDRVHLP::pfnDetachSelf
1249 */
1250DECLINLINE(int) PDMDrvHlpDetachSelf(PPDMDRVINS pDrvIns, uint32_t fFlags)
1251{
1252 return pDrvIns->pHlpR3->pfnDetachSelf(pDrvIns, fFlags);
1253}
1254
1255/**
1256 * @copydoc PDMDRVHLP::pfnMountPrepare
1257 */
1258DECLINLINE(int) PDMDrvHlpMountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver)
1259{
1260 return pDrvIns->pHlpR3->pfnMountPrepare(pDrvIns, pszFilename, pszCoreDriver);
1261}
1262
1263/**
1264 * @copydoc PDMDRVHLP::pfnVMState
1265 */
1266DECLINLINE(VMSTATE) PDMDrvHlpVMState(PPDMDRVINS pDrvIns)
1267{
1268 return pDrvIns->CTX_SUFF(pHlp)->pfnVMState(pDrvIns);
1269}
1270
1271/**
1272 * @copydoc PDMDRVHLP::pfnVMTeleportedAndNotFullyResumedYet
1273 */
1274DECLINLINE(bool) PDMDrvHlpVMTeleportedAndNotFullyResumedYet(PPDMDRVINS pDrvIns)
1275{
1276 return pDrvIns->pHlpR3->pfnVMTeleportedAndNotFullyResumedYet(pDrvIns);
1277}
1278
1279/**
1280 * @copydoc PDMDRVHLP::pfnPDMQueueCreate
1281 */
1282DECLINLINE(int) PDMDrvHlpPDMQueueCreate(PPDMDRVINS pDrvIns, uint32_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
1283 PFNPDMQUEUEDRV pfnCallback, const char *pszName, PPDMQUEUE *ppQueue)
1284{
1285 return pDrvIns->pHlpR3->pfnPDMQueueCreate(pDrvIns, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, ppQueue);
1286}
1287
1288/**
1289 * @copydoc PDMDRVHLP::pfnTMGetVirtualFreq
1290 */
1291DECLINLINE(uint64_t) PDMDrvHlpTMGetVirtualFreq(PPDMDRVINS pDrvIns)
1292{
1293 return pDrvIns->pHlpR3->pfnTMGetVirtualFreq(pDrvIns);
1294}
1295
1296/**
1297 * @copydoc PDMDRVHLP::pfnTMGetVirtualTime
1298 */
1299DECLINLINE(uint64_t) PDMDrvHlpTMGetVirtualTime(PPDMDRVINS pDrvIns)
1300{
1301 return pDrvIns->pHlpR3->pfnTMGetVirtualTime(pDrvIns);
1302}
1303
1304/**
1305 * @copydoc PDMDRVHLP::pfnTMTimerCreate
1306 */
1307DECLINLINE(int) PDMDrvHlpTMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
1308{
1309 return pDrvIns->pHlpR3->pfnTMTimerCreate(pDrvIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
1310}
1311
1312/**
1313 * Register a save state data unit.
1314 *
1315 * @returns VBox status.
1316 * @param pDrvIns Driver instance.
1317 * @param uVersion Data layout version number.
1318 * @param cbGuess The approximate amount of data in the unit.
1319 * Only for progress indicators.
1320 * @param pfnSaveExec Execute save callback, optional.
1321 * @param pfnLoadExec Execute load callback, optional.
1322 */
1323DECLINLINE(int) PDMDrvHlpSSMRegister(PPDMDRVINS pDrvIns, uint32_t uVersion, size_t cbGuess,
1324 PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVLOADEXEC pfnLoadExec)
1325{
1326 return pDrvIns->pHlpR3->pfnSSMRegister(pDrvIns, uVersion, cbGuess,
1327 NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveVote*/,
1328 NULL /*pfnSavePrep*/, pfnSaveExec, NULL /*pfnSaveDone*/,
1329 NULL /*pfnLoadPrep*/, pfnLoadExec, NULL /*pfnLoadDone*/);
1330}
1331
1332/**
1333 * @copydoc PDMDRVHLP::pfnSSMRegister
1334 */
1335DECLINLINE(int) PDMDrvHlpSSMRegisterEx(PPDMDRVINS pDrvIns, uint32_t uVersion, size_t cbGuess,
1336 PFNSSMDRVLIVEPREP pfnLivePrep, PFNSSMDRVLIVEEXEC pfnLiveExec, PFNSSMDRVLIVEVOTE pfnLiveVote,
1337 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
1338 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
1339{
1340 return pDrvIns->pHlpR3->pfnSSMRegister(pDrvIns, uVersion, cbGuess,
1341 pfnLivePrep, pfnLiveExec, pfnLiveVote,
1342 pfnSavePrep, pfnSaveExec, pfnSaveDone,
1343 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
1344}
1345
1346/**
1347 * Register a load done callback.
1348 *
1349 * @returns VBox status.
1350 * @param pDrvIns Driver instance.
1351 * @param pfnLoadDone Done load callback, optional.
1352 */
1353DECLINLINE(int) PDMDrvHlpSSMRegisterLoadDone(PPDMDRVINS pDrvIns, PFNSSMDRVLOADDONE pfnLoadDone)
1354{
1355 return pDrvIns->pHlpR3->pfnSSMRegister(pDrvIns, 0 /*uVersion*/, 0 /*cbGuess*/,
1356 NULL /*pfnLivePrep*/, NULL /*pfnLiveExec*/, NULL /*pfnLiveVote*/,
1357 NULL /*pfnSavePrep*/, NULL /*pfnSaveExec*/, NULL /*pfnSaveDone*/,
1358 NULL /*pfnLoadPrep*/, NULL /*pfnLoadExec*/, pfnLoadDone);
1359}
1360
1361/**
1362 * @copydoc PDMDRVHLP::pfnSTAMRegister
1363 */
1364DECLINLINE(void) PDMDrvHlpSTAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
1365{
1366 pDrvIns->pHlpR3->pfnSTAMRegister(pDrvIns, pvSample, enmType, pszName, enmUnit, pszDesc);
1367}
1368
1369/**
1370 * @copydoc PDMDRVHLP::pfnSTAMRegisterF
1371 */
1372DECLINLINE(void) PDMDrvHlpSTAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
1373 const char *pszDesc, const char *pszName, ...)
1374{
1375 va_list va;
1376 va_start(va, pszName);
1377 pDrvIns->pHlpR3->pfnSTAMRegisterV(pDrvIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
1378 va_end(va);
1379}
1380
1381/**
1382 * @copydoc PDMDRVHLP::pfnSTAMDeregister
1383 */
1384DECLINLINE(int) PDMDrvHlpSTAMDeregister(PPDMDRVINS pDrvIns, void *pvSample)
1385{
1386 return pDrvIns->pHlpR3->pfnSTAMDeregister(pDrvIns, pvSample);
1387}
1388
1389/**
1390 * @copydoc PDMDRVHLP::pfnSUPCallVMMR0Ex
1391 */
1392DECLINLINE(int) PDMDrvHlpSUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg)
1393{
1394 return pDrvIns->pHlpR3->pfnSUPCallVMMR0Ex(pDrvIns, uOperation, pvArg, cbArg);
1395}
1396
1397/**
1398 * @copydoc PDMDRVHLP::pfnUSBRegisterHub
1399 */
1400DECLINLINE(int) PDMDrvHlpUSBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
1401{
1402 return pDrvIns->pHlpR3->pfnUSBRegisterHub(pDrvIns, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp);
1403}
1404
1405/**
1406 * @copydoc PDMDRVHLP::pfnSetAsyncNotification
1407 */
1408DECLINLINE(int) PDMDrvHlpSetAsyncNotification(PPDMDRVINS pDrvIns, PFNPDMDRVASYNCNOTIFY pfnAsyncNotify)
1409{
1410 return pDrvIns->pHlpR3->pfnSetAsyncNotification(pDrvIns, pfnAsyncNotify);
1411}
1412
1413/**
1414 * @copydoc PDMDRVHLP::pfnAsyncNotificationCompleted
1415 */
1416DECLINLINE(void) PDMDrvHlpAsyncNotificationCompleted(PPDMDRVINS pDrvIns)
1417{
1418 pDrvIns->pHlpR3->pfnAsyncNotificationCompleted(pDrvIns);
1419}
1420
1421/**
1422 * @copydoc PDMDRVHLP::pfnPDMThreadCreate
1423 */
1424DECLINLINE(int) PDMDrvHlpPDMThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
1425 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
1426{
1427 return pDrvIns->pHlpR3->pfnPDMThreadCreate(pDrvIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
1428}
1429
1430# ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1431/**
1432 * @copydoc PDMDRVHLP::pfnPDMAsyncCompletionTemplateCreate
1433 */
1434DECLINLINE(int) PDMDrvHlpPDMAsyncCompletionTemplateCreate(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
1435 PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser, const char *pszDesc)
1436{
1437 return pDrvIns->pHlpR3->pfnPDMAsyncCompletionTemplateCreate(pDrvIns, ppTemplate, pfnCompleted, pvTemplateUser, pszDesc);
1438}
1439# endif
1440
1441
1442/** Pointer to callbacks provided to the VBoxDriverRegister() call. */
1443typedef struct PDMDRVREGCB *PPDMDRVREGCB;
1444/** Pointer to const callbacks provided to the VBoxDriverRegister() call. */
1445typedef const struct PDMDRVREGCB *PCPDMDRVREGCB;
1446
1447/**
1448 * Callbacks for VBoxDriverRegister().
1449 */
1450typedef struct PDMDRVREGCB
1451{
1452 /** Interface version.
1453 * This is set to PDM_DRVREG_CB_VERSION. */
1454 uint32_t u32Version;
1455
1456 /**
1457 * Registers a driver with the current VM instance.
1458 *
1459 * @returns VBox status code.
1460 * @param pCallbacks Pointer to the callback table.
1461 * @param pReg Pointer to the driver registration record.
1462 * This data must be permanent and readonly.
1463 */
1464 DECLR3CALLBACKMEMBER(int, pfnRegister,(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pReg));
1465} PDMDRVREGCB;
1466
1467/** Current version of the PDMDRVREGCB structure. */
1468#define PDM_DRVREG_CB_VERSION PDM_VERSION_MAKE(0xf0fa, 1, 0)
1469
1470
1471/**
1472 * The VBoxDriverRegister callback function.
1473 *
1474 * PDM will invoke this function after loading a driver module and letting
1475 * the module decide which drivers to register and how to handle conflicts.
1476 *
1477 * @returns VBox status code.
1478 * @param pCallbacks Pointer to the callback table.
1479 * @param u32Version VBox version number.
1480 */
1481typedef DECLCALLBACK(int) FNPDMVBOXDRIVERSREGISTER(PCPDMDRVREGCB pCallbacks, uint32_t u32Version);
1482
1483VMMR3DECL(int) PDMR3RegisterDrivers(PVM pVM, FNPDMVBOXDRIVERSREGISTER pfnCallback);
1484
1485#endif /* IN_RING3 */
1486
1487/** @} */
1488
1489RT_C_DECLS_END
1490
1491#endif
Note: See TracBrowser for help on using the repository browser.

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