VirtualBox

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

Last change on this file since 10353 was 8715, checked in by vboxsync, 17 years ago

Fix using several NAT adapters in a single VM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 34.3 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, Drivers.
3 */
4
5/*
6 * Copyright (C) 2006-2007 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/tm.h>
39#include <VBox/ssm.h>
40#include <VBox/cfgm.h>
41#include <VBox/dbgf.h>
42#include <VBox/mm.h>
43#include <VBox/err.h>
44#include <iprt/stdarg.h>
45
46#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
47# include <VBox/pdmasynccompletion.h>
48#endif
49
50__BEGIN_DECLS
51
52/** @defgroup grp_pdm_driver Drivers
53 * @ingroup grp_pdm
54 * @{
55 */
56
57/**
58 * Construct a driver instance for a VM.
59 *
60 * @returns VBox status.
61 * @param pDrvIns The driver instance data.
62 * If the registration structure is needed, pDrvIns->pDrvReg points to it.
63 * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
64 * of the driver instance. It's also found in pDrvIns->pCfgHandle as it's expected
65 * to be used frequently in this function.
66 */
67typedef DECLCALLBACK(int) FNPDMDRVCONSTRUCT(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle);
68/** Pointer to a FNPDMDRVCONSTRUCT() function. */
69typedef FNPDMDRVCONSTRUCT *PFNPDMDRVCONSTRUCT;
70
71/**
72 * Destruct a driver instance.
73 *
74 * Most VM resources are freed by the VM. This callback is provided so that
75 * any non-VM resources can be freed correctly.
76 *
77 * @param pDrvIns The driver instance data.
78 */
79typedef DECLCALLBACK(void) FNPDMDRVDESTRUCT(PPDMDRVINS pDrvIns);
80/** Pointer to a FNPDMDRVDESTRUCT() function. */
81typedef FNPDMDRVDESTRUCT *PFNPDMDRVDESTRUCT;
82
83/**
84 * Driver I/O Control interface.
85 *
86 * This is used by external components, such as the COM interface, to
87 * communicate with a driver using a driver specific interface. Generally,
88 * the driver interfaces are used for this task.
89 *
90 * @returns VBox status code.
91 * @param pDrvIns Pointer to the driver instance.
92 * @param uFunction Function to perform.
93 * @param pvIn Pointer to input data.
94 * @param cbIn Size of input data.
95 * @param pvOut Pointer to output data.
96 * @param cbOut Size of output data.
97 * @param pcbOut Where to store the actual size of the output data.
98 */
99typedef DECLCALLBACK(int) FNPDMDRVIOCTL(PPDMDRVINS pDrvIns, RTUINT uFunction,
100 void *pvIn, RTUINT cbIn,
101 void *pvOut, RTUINT cbOut, PRTUINT pcbOut);
102/** Pointer to a FNPDMDRVIOCTL() function. */
103typedef FNPDMDRVIOCTL *PFNPDMDRVIOCTL;
104
105/**
106 * Power On notification.
107 *
108 * @param pDrvIns The driver instance data.
109 */
110typedef DECLCALLBACK(void) FNPDMDRVPOWERON(PPDMDRVINS pDrvIns);
111/** Pointer to a FNPDMDRVPOWERON() function. */
112typedef FNPDMDRVPOWERON *PFNPDMDRVPOWERON;
113
114/**
115 * Reset notification.
116 *
117 * @returns VBox status.
118 * @param pDrvIns The driver instance data.
119 */
120typedef DECLCALLBACK(void) FNPDMDRVRESET(PPDMDRVINS pDrvIns);
121/** Pointer to a FNPDMDRVRESET() function. */
122typedef FNPDMDRVRESET *PFNPDMDRVRESET;
123
124/**
125 * Suspend notification.
126 *
127 * @returns VBox status.
128 * @param pDrvIns The driver instance data.
129 */
130typedef DECLCALLBACK(void) FNPDMDRVSUSPEND(PPDMDRVINS pDrvIns);
131/** Pointer to a FNPDMDRVSUSPEND() function. */
132typedef FNPDMDRVSUSPEND *PFNPDMDRVSUSPEND;
133
134/**
135 * Resume notification.
136 *
137 * @returns VBox status.
138 * @param pDrvIns The driver instance data.
139 */
140typedef DECLCALLBACK(void) FNPDMDRVRESUME(PPDMDRVINS pDrvIns);
141/** Pointer to a FNPDMDRVRESUME() function. */
142typedef FNPDMDRVRESUME *PFNPDMDRVRESUME;
143
144/**
145 * Power Off notification.
146 *
147 * @param pDrvIns The driver instance data.
148 */
149typedef DECLCALLBACK(void) FNPDMDRVPOWEROFF(PPDMDRVINS pDrvIns);
150/** Pointer to a FNPDMDRVPOWEROFF() function. */
151typedef FNPDMDRVPOWEROFF *PFNPDMDRVPOWEROFF;
152
153/**
154 * Detach notification.
155 *
156 * This is called when a driver below it in the chain is detaching itself
157 * from it. The driver should adjust it's state to reflect this.
158 *
159 * This is like ejecting a cdrom or floppy.
160 *
161 * @param pDrvIns The driver instance.
162 */
163typedef DECLCALLBACK(void) FNPDMDRVDETACH(PPDMDRVINS pDrvIns);
164/** Pointer to a FNPDMDRVDETACH() function. */
165typedef FNPDMDRVDETACH *PFNPDMDRVDETACH;
166
167
168
169/** PDM Driver Registration Structure,
170 * This structure is used when registering a driver from
171 * VBoxInitDrivers() (HC Ring-3). PDM will continue use till
172 * the VM is terminated.
173 */
174typedef struct PDMDRVREG
175{
176 /** Structure version. PDM_DRVREG_VERSION defines the current version. */
177 uint32_t u32Version;
178 /** Driver name. */
179 char szDriverName[32];
180 /** The description of the driver. The UTF-8 string pointed to shall, like this structure,
181 * remain unchanged from registration till VM destruction. */
182 const char *pszDescription;
183
184 /** Flags, combination of the PDM_DRVREG_FLAGS_* \#defines. */
185 RTUINT fFlags;
186 /** Driver class(es), combination of the PDM_DRVREG_CLASS_* \#defines. */
187 RTUINT fClass;
188 /** Maximum number of instances (per VM). */
189 RTUINT cMaxInstances;
190 /** Size of the instance data. */
191 RTUINT cbInstance;
192
193 /** Construct instance - required. */
194 PFNPDMDRVCONSTRUCT pfnConstruct;
195 /** Destruct instance - optional. */
196 PFNPDMDRVDESTRUCT pfnDestruct;
197 /** I/O control - optional. */
198 PFNPDMDRVIOCTL pfnIOCtl;
199 /** Power on notification - optional. */
200 PFNPDMDRVPOWERON pfnPowerOn;
201 /** Reset notification - optional. */
202 PFNPDMDRVRESET pfnReset;
203 /** Suspend notification - optional. */
204 PFNPDMDRVSUSPEND pfnSuspend;
205 /** Resume notification - optional. */
206 PFNPDMDRVRESUME pfnResume;
207 /** Detach notification - optional. */
208 PFNPDMDRVDETACH pfnDetach;
209 /** Power off notification - optional. */
210 PFNPDMDRVPOWEROFF pfnPowerOff;
211
212} PDMDRVREG;
213/** Pointer to a PDM Driver Structure. */
214typedef PDMDRVREG *PPDMDRVREG;
215/** Const pointer to a PDM Driver Structure. */
216typedef PDMDRVREG const *PCPDMDRVREG;
217
218/** Current DRVREG version number. */
219#define PDM_DRVREG_VERSION 0x80010000
220
221/** PDM Device Flags.
222 * @{ */
223/** @def PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT
224 * The bit count for the current host. */
225#if HC_ARCH_BITS == 32
226# define PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT 0x000000001
227#elif HC_ARCH_BITS == 64
228# define PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT 0x000000002
229#else
230# error Unsupported HC_ARCH_BITS value.
231#endif
232/** The host bit count mask. */
233#define PDM_DRVREG_FLAGS_HOST_BITS_MASK 0x000000003
234
235/** @} */
236
237
238/** PDM Driver Classes.
239 * @{ */
240/** Mouse input driver. */
241#define PDM_DRVREG_CLASS_MOUSE RT_BIT(0)
242/** Keyboard input driver. */
243#define PDM_DRVREG_CLASS_KEYBOARD RT_BIT(1)
244/** Display driver. */
245#define PDM_DRVREG_CLASS_DISPLAY RT_BIT(2)
246/** Network transport driver. */
247#define PDM_DRVREG_CLASS_NETWORK RT_BIT(3)
248/** Block driver. */
249#define PDM_DRVREG_CLASS_BLOCK RT_BIT(4)
250/** Media driver. */
251#define PDM_DRVREG_CLASS_MEDIA RT_BIT(5)
252/** Mountable driver. */
253#define PDM_DRVREG_CLASS_MOUNTABLE RT_BIT(6)
254/** Audio driver. */
255#define PDM_DRVREG_CLASS_AUDIO RT_BIT(7)
256/** VMMDev driver. */
257#define PDM_DRVREG_CLASS_VMMDEV RT_BIT(8)
258/** Status driver. */
259#define PDM_DRVREG_CLASS_STATUS RT_BIT(9)
260/** ACPI driver. */
261#define PDM_DRVREG_CLASS_ACPI RT_BIT(10)
262/** USB related driver. */
263#define PDM_DRVREG_CLASS_USB RT_BIT(11)
264/** ISCSI Transport related driver. */
265#define PDM_DRVREG_CLASS_ISCSITRANSPORT RT_BIT(12)
266/** Char driver. */
267#define PDM_DRVREG_CLASS_CHAR RT_BIT(13)
268/** Stream driver. */
269#define PDM_DRVREG_CLASS_STREAM RT_BIT(14)
270/** @} */
271
272
273/**
274 * USB hub registration structure.
275 */
276typedef struct PDMUSBHUBREG
277{
278 /** Structure version number. PDM_USBHUBREG_VERSION defines the current version. */
279 uint32_t u32Version;
280
281 /**
282 * Request the hub to attach of the specified device.
283 *
284 * @returns VBox status code.
285 * @param pDrvIns The hub instance.
286 * @param pUsbIns The device to attach.
287 * @param piPort Where to store the port number the device was attached to.
288 * @thread EMT.
289 */
290 DECLR3CALLBACKMEMBER(int, pfnAttachDevice,(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, uint32_t *piPort));
291
292 /**
293 * Request the hub to detach of the specified device.
294 *
295 * The device has previously been attached to the hub with the
296 * pfnAttachDevice call. This call is not currently expected to
297 * fail.
298 *
299 * @returns VBox status code.
300 * @param pDrvIns The hub instance.
301 * @param pUsbIns The device to detach.
302 * @param iPort The port number returned by the attach call.
303 * @thread EMT.
304 */
305 DECLR3CALLBACKMEMBER(int, pfnDetachDevice,(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, uint32_t iPort));
306
307 /** Counterpart to u32Version, same value. */
308 uint32_t u32TheEnd;
309} PDMUSBHUBREG;
310/** Pointer to a const USB hub registration structure. */
311typedef const PDMUSBHUBREG *PCPDMUSBHUBREG;
312
313/** Current PDMUSBHUBREG version number. */
314#define PDM_USBHUBREG_VERSION 0xeb010000
315
316
317/**
318 * USB hub helpers.
319 * This is currently just a place holder.
320 */
321typedef struct PDMUSBHUBHLP
322{
323 /** Structure version. PDM_USBHUBHLP_VERSION defines the current version. */
324 uint32_t u32Version;
325
326 /** Just a safety precaution. */
327 uint32_t u32TheEnd;
328} PDMUSBHUBHLP;
329/** Pointer to PCI helpers. */
330typedef PDMUSBHUBHLP *PPDMUSBHUBHLP;
331/** Pointer to const PCI helpers. */
332typedef const PDMUSBHUBHLP *PCPDMUSBHUBHLP;
333/** Pointer to const PCI helpers pointer. */
334typedef PCPDMUSBHUBHLP *PPCPDMUSBHUBHLP;
335
336/** Current PDMUSBHUBHLP version number. */
337#define PDM_USBHUBHLP_VERSION 0xea010000
338
339
340
341/**
342 * Poller callback.
343 *
344 * @param pDrvIns The driver instance.
345 */
346typedef DECLCALLBACK(void) FNPDMDRVPOLLER(PPDMDRVINS pDrvIns);
347/** Pointer to a FNPDMDRVPOLLER function. */
348typedef FNPDMDRVPOLLER *PFNPDMDRVPOLLER;
349
350#ifdef IN_RING3
351/**
352 * PDM Driver API.
353 */
354typedef struct PDMDRVHLP
355{
356 /** Structure version. PDM_DRVHLP_VERSION defines the current version. */
357 uint32_t u32Version;
358
359 /**
360 * Attaches a driver (chain) to the driver.
361 *
362 * @returns VBox status code.
363 * @param pDrvIns Driver instance.
364 * @param ppBaseInterface Where to store the pointer to the base interface.
365 */
366 DECLR3CALLBACKMEMBER(int, pfnAttach,(PPDMDRVINS pDrvIns, PPDMIBASE *ppBaseInterface));
367
368 /**
369 * Detach the driver the drivers below us.
370 *
371 * @returns VBox status code.
372 * @param pDrvIns Driver instance.
373 */
374 DECLR3CALLBACKMEMBER(int, pfnDetach,(PPDMDRVINS pDrvIns));
375
376 /**
377 * Detach the driver from the driver above it and destroy this
378 * driver and all drivers below it.
379 *
380 * @returns VBox status code.
381 * @param pDrvIns Driver instance.
382 */
383 DECLR3CALLBACKMEMBER(int, pfnDetachSelf,(PPDMDRVINS pDrvIns));
384
385 /**
386 * Prepare a media mount.
387 *
388 * The driver must not have anything attached to itself
389 * when calling this function as the purpose is to set up the configuration
390 * of an future attachment.
391 *
392 * @returns VBox status code
393 * @param pDrvIns Driver instance.
394 * @param pszFilename Pointer to filename. If this is NULL it assumed that the caller have
395 * constructed a configuration which can be attached to the bottom driver.
396 * @param pszCoreDriver Core driver name. NULL will cause autodetection. Ignored if pszFilanem is NULL.
397 */
398 DECLR3CALLBACKMEMBER(int, pfnMountPrepare,(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver));
399
400 /**
401 * Assert that the current thread is the emulation thread.
402 *
403 * @returns True if correct.
404 * @returns False if wrong.
405 * @param pDrvIns Driver instance.
406 * @param pszFile Filename of the assertion location.
407 * @param iLine Linenumber of the assertion location.
408 * @param pszFunction Function of the assertion location.
409 */
410 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
411
412 /**
413 * Assert that the current thread is NOT the emulation thread.
414 *
415 * @returns True if correct.
416 * @returns False if wrong.
417 * @param pDrvIns Driver instance.
418 * @param pszFile Filename of the assertion location.
419 * @param iLine Linenumber of the assertion location.
420 * @param pszFunction Function of the assertion location.
421 */
422 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction));
423
424 /**
425 * Set the VM error message
426 *
427 * @returns rc.
428 * @param pDrvIns Driver instance.
429 * @param rc VBox status code.
430 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
431 * @param pszFormat Error message format string.
432 * @param ... Error message arguments.
433 */
434 DECLR3CALLBACKMEMBER(int, pfnVMSetError,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...));
435
436 /**
437 * Set the VM error message
438 *
439 * @returns rc.
440 * @param pDrvIns Driver instance.
441 * @param rc VBox status code.
442 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
443 * @param pszFormat Error message format string.
444 * @param va Error message arguments.
445 */
446 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
447
448 /**
449 * Set the VM runtime error message
450 *
451 * @returns VBox status code.
452 * @param pDrvIns Driver instance.
453 * @param fFatal Whether it is a fatal error or not.
454 * @param pszErrorID Error ID string.
455 * @param pszFormat Error message format string.
456 * @param ... Error message arguments.
457 */
458 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeError,(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...));
459
460 /**
461 * Set the VM runtime error message
462 *
463 * @returns VBox status code.
464 * @param pDrvIns Driver instance.
465 * @param fFatal Whether it is a fatal error or not.
466 * @param pszErrorID Error ID string.
467 * @param pszFormat Error message format string.
468 * @param va Error message arguments.
469 */
470 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
471
472 /**
473 * Create a queue.
474 *
475 * @returns VBox status code.
476 * @param pDrvIns Driver instance.
477 * @param cbItem Size a queue item.
478 * @param cItems Number of items in the queue.
479 * @param cMilliesInterval Number of milliseconds between polling the queue.
480 * If 0 then the emulation thread will be notified whenever an item arrives.
481 * @param pfnCallback The consumer function.
482 * @param ppQueue Where to store the queue handle on success.
483 * @thread The emulation thread.
484 */
485 DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMDRVINS pDrvIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval, PFNPDMQUEUEDRV pfnCallback, PPDMQUEUE *ppQueue));
486
487 /**
488 * Register a poller function.
489 * TEMPORARY HACK FOR NETWORKING! DON'T USE!
490 *
491 * @returns VBox status code.
492 * @param pDrvIns Driver instance.
493 * @param pfnPoller The callback function.
494 */
495 DECLR3CALLBACKMEMBER(int, pfnPDMPollerRegister,(PPDMDRVINS pDrvIns, PFNPDMDRVPOLLER pfnPoller));
496
497 /**
498 * Query the virtual timer frequency.
499 *
500 * @returns Frequency in Hz.
501 * @param pDrvIns Driver instance.
502 * @thread Any thread.
503 */
504 DECLR3CALLBACKMEMBER(uint64_t, pfnTMGetVirtualFreq,(PPDMDRVINS pDrvIns));
505
506 /**
507 * Query the virtual time.
508 *
509 * @returns The current virtual time.
510 * @param pDrvIns Driver instance.
511 * @thread Any thread.
512 */
513 DECLR3CALLBACKMEMBER(uint64_t, pfnTMGetVirtualTime,(PPDMDRVINS pDrvIns));
514
515 /**
516 * Creates a timer.
517 *
518 * @returns VBox status.
519 * @param pDrvIns Driver instance.
520 * @param enmClock The clock to use on this timer.
521 * @param pfnCallback Callback function.
522 * @param pszDesc Pointer to description string which must stay around
523 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
524 * @param ppTimer Where to store the timer on success.
525 */
526 DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer));
527
528 /**
529 * Register a save state data unit.
530 *
531 * @returns VBox status.
532 * @param pDrvIns Driver instance.
533 * @param pszName Data unit name.
534 * @param u32Instance The instance identifier of the data unit.
535 * This must together with the name be unique.
536 * @param u32Version Data layout version number.
537 * @param cbGuess The approximate amount of data in the unit.
538 * Only for progress indicators.
539 * @param pfnSavePrep Prepare save callback, optional.
540 * @param pfnSaveExec Execute save callback, optional.
541 * @param pfnSaveDone Done save callback, optional.
542 * @param pfnLoadPrep Prepare load callback, optional.
543 * @param pfnLoadExec Execute load callback, optional.
544 * @param pfnLoadDone Done load callback, optional.
545 */
546 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
547 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
548 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone));
549
550 /**
551 * Deregister a save state data unit.
552 *
553 * @returns VBox status.
554 * @param pDrvIns Driver instance.
555 * @param pszName Data unit name.
556 * @param u32Instance The instance identifier of the data unit.
557 * This must together with the name be unique.
558 */
559 DECLR3CALLBACKMEMBER(int, pfnSSMDeregister,(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance));
560
561 /**
562 * Registers a statistics sample if statistics are enabled.
563 *
564 * @param pDrvIns Driver instance.
565 * @param pvSample Pointer to the sample.
566 * @param enmType Sample type. This indicates what pvSample is pointing at.
567 * @param pszName Sample name. The name is on this form "/<component>/<sample>".
568 * Further nesting is possible.
569 * @param enmUnit Sample unit.
570 * @param pszDesc Sample description.
571 */
572 DECLR3CALLBACKMEMBER(void, pfnSTAMRegister,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName,
573 STAMUNIT enmUnit, const char *pszDesc));
574
575 /**
576 * Same as pfnSTAMRegister except that the name is specified in a
577 * RTStrPrintf like fashion.
578 *
579 * @returns VBox status.
580 * @param pDrvIns Driver instance.
581 * @param pvSample Pointer to the sample.
582 * @param enmType Sample type. This indicates what pvSample is pointing at.
583 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
584 * @param enmUnit Sample unit.
585 * @param pszDesc Sample description.
586 * @param pszName The sample name format string.
587 * @param ... Arguments to the format string.
588 */
589 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterF,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
590 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...));
591
592 /**
593 * Same as pfnSTAMRegister except that the name is specified in a
594 * RTStrPrintfV like fashion.
595 *
596 * @returns VBox status.
597 * @param pDrvIns Driver instance.
598 * @param pvSample Pointer to the sample.
599 * @param enmType Sample type. This indicates what pvSample is pointing at.
600 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
601 * @param enmUnit Sample unit.
602 * @param pszDesc Sample description.
603 * @param pszName The sample name format string.
604 * @param args Arguments to the format string.
605 */
606 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
607 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args));
608
609 /**
610 * Calls the HC R0 VMM entry point, in a safer but slower manner than SUPCallVMMR0.
611 *
612 * When entering using this call the R0 components can call into the host kernel
613 * (i.e. use the SUPR0 and RT APIs).
614 *
615 * See VMMR0Entry() for more details.
616 *
617 * @returns error code specific to uFunction.
618 * @param pDrvIns The driver instance.
619 * @param uOperation Operation to execute.
620 * This is limited to services.
621 * @param pvArg Pointer to argument structure or if cbArg is 0 just an value.
622 * @param cbArg The size of the argument. This is used to copy whatever the argument
623 * points at into a kernel buffer to avoid problems like the user page
624 * being invalidated while we're executing the call.
625 */
626 DECLR3CALLBACKMEMBER(int, pfnSUPCallVMMR0Ex,(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg));
627
628 /**
629 * Registers a USB HUB.
630 *
631 * @returns VBox status code.
632 * @param pDrvIns The driver instance.
633 * @param fVersions Indicates the kinds of USB devices that can be attached to this HUB.
634 * @param cPorts The number of ports.
635 * @param pUsbHubReg The hub callback structure that PDMUsb uses to interact with it.
636 * @param ppUsbHubHlp The helper callback structure that the hub uses to talk to PDMUsb.
637 *
638 * @thread EMT.
639 */
640 DECLR3CALLBACKMEMBER(int, pfnUSBRegisterHub,(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp));
641
642 /**
643 * Creates a PDM thread.
644 *
645 * This differs from the RTThreadCreate() API in that PDM takes care of suspending,
646 * resuming, and destroying the thread as the VM state changes.
647 *
648 * @returns VBox status code.
649 * @param pDrvIns The driver instance.
650 * @param ppThread Where to store the thread 'handle'.
651 * @param pvUser The user argument to the thread function.
652 * @param pfnThread The thread function.
653 * @param pfnWakeup The wakup callback. This is called on the EMT thread when
654 * a state change is pending.
655 * @param cbStack See RTThreadCreate.
656 * @param enmType See RTThreadCreate.
657 * @param pszName See RTThreadCreate.
658 */
659 DECLR3CALLBACKMEMBER(int, pfnPDMThreadCreate,(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
660 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName));
661
662 /**
663 * Gets the VM state.
664 *
665 * @returns VM state.
666 * @param pDrvIns The driver instance.
667 * @thread Any thread (just keep in mind that it's volatile info).
668 */
669 DECLR3CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMDRVINS pDrvIns));
670
671#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
672 /**
673 * Creates a async completion template for a driver instance.
674 *
675 * The template is used when creating new completion tasks.
676 *
677 * @returns VBox status code.
678 * @param pDrvIns The driver instance.
679 * @param ppTemplate Where to store the template pointer on success.
680 * @param pfnCompleted The completion callback routine.
681 * @param pszDesc Description.
682 */
683 DECLR3CALLBACKMEMBER(int, pfnPDMAsyncCompletionTemplateCreate,(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
684 PFNPDMASYNCCOMPLETEDRV pfnCompleted, const char *pszDesc));
685#endif
686
687 /** Just a safety precaution. */
688 uint32_t u32TheEnd;
689} PDMDRVHLP;
690/** Pointer PDM Driver API. */
691typedef PDMDRVHLP *PPDMDRVHLP;
692/** Pointer const PDM Driver API. */
693typedef const PDMDRVHLP *PCPDMDRVHLP;
694
695/** Current DRVHLP version number. */
696#define PDM_DRVHLP_VERSION 0x90020001
697
698
699
700/**
701 * PDM Driver Instance.
702 */
703typedef struct PDMDRVINS
704{
705 /** Structure version. PDM_DRVINS_VERSION defines the current version. */
706 uint32_t u32Version;
707
708 /** Internal data. */
709 union
710 {
711#ifdef PDMDRVINSINT_DECLARED
712 PDMDRVINSINT s;
713#endif
714 uint8_t padding[HC_ARCH_BITS == 32 ? 32 : 64];
715 } Internal;
716
717 /** Pointer the PDM Driver API. */
718 R3PTRTYPE(PCPDMDRVHLP) pDrvHlp;
719 /** Pointer to driver registration structure. */
720 R3PTRTYPE(PCPDMDRVREG) pDrvReg;
721 /** Configuration handle. */
722 R3PTRTYPE(PCFGMNODE) pCfgHandle;
723 /** Driver instance number. */
724 RTUINT iInstance;
725 /** Pointer to the base interface of the device/driver instance above. */
726 R3PTRTYPE(PPDMIBASE) pUpBase;
727 /** Pointer to the base interface of the driver instance below. */
728 R3PTRTYPE(PPDMIBASE) pDownBase;
729 /** The base interface of the driver.
730 * The driver constructor initializes this. */
731 PDMIBASE IBase;
732 /* padding to make achInstanceData aligned at 16 byte boundrary. */
733 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 3 : 1];
734 /** Pointer to driver instance data. */
735 R3PTRTYPE(void *) pvInstanceData;
736 /** Driver instance data. The size of this area is defined
737 * in the PDMDRVREG::cbInstanceData field. */
738 char achInstanceData[4];
739} PDMDRVINS;
740
741/** Current DRVREG version number. */
742#define PDM_DRVINS_VERSION 0xa0010000
743
744/** Converts a pointer to the PDMDRVINS::IBase to a pointer to PDMDRVINS. */
745#define PDMIBASE_2_PDMDRV(pInterface) ( (PPDMDRVINS)((char *)(pInterface) - RT_OFFSETOF(PDMDRVINS, IBase)) )
746
747/**
748 * @copydoc PDMDRVHLP::pfnVMSetError
749 */
750DECLINLINE(int) PDMDrvHlpVMSetError(PPDMDRVINS pDrvIns, const int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
751{
752 va_list va;
753 va_start(va, pszFormat);
754 pDrvIns->pDrvHlp->pfnVMSetErrorV(pDrvIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
755 va_end(va);
756 return rc;
757}
758
759/** @def PDMDRV_SET_ERROR
760 * Set the VM error. See PDMDrvHlpVMSetError() for printf like message formatting.
761 */
762#define PDMDRV_SET_ERROR(pDrvIns, rc, pszError) \
763 PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, "%s", pszError)
764
765/**
766 * @copydoc PDMDRVHLP::pfnVMSetRuntimeError
767 */
768DECLINLINE(int) PDMDrvHlpVMSetRuntimeError(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...)
769{
770 va_list va;
771 int rc;
772 va_start(va, pszFormat);
773 rc = pDrvIns->pDrvHlp->pfnVMSetRuntimeErrorV(pDrvIns, fFatal, pszErrorID, pszFormat, va);
774 va_end(va);
775 return rc;
776}
777
778/** @def PDMDRV_SET_RUNTIME_ERROR
779 * Set the VM runtime error. See PDMDrvHlpVMSetRuntimeError() for printf like message formatting.
780 */
781#define PDMDRV_SET_RUNTIME_ERROR(pDrvIns, fFatal, pszErrorID, pszError) \
782 PDMDrvHlpVMSetRuntimeError(pDrvIns, fFatal, pszErrorID, "%s", pszError)
783
784#endif /* IN_RING3 */
785
786
787/** @def PDMDRV_ASSERT_EMT
788 * Assert that the current thread is the emulation thread.
789 */
790#ifdef VBOX_STRICT
791# define PDMDRV_ASSERT_EMT(pDrvIns) pDrvIns->pDrvHlp->pfnAssertEMT(pDrvIns, __FILE__, __LINE__, __FUNCTION__)
792#else
793# define PDMDRV_ASSERT_EMT(pDrvIns) do { } while (0)
794#endif
795
796/** @def PDMDRV_ASSERT_OTHER
797 * Assert that the current thread is NOT the emulation thread.
798 */
799#ifdef VBOX_STRICT
800# define PDMDRV_ASSERT_OTHER(pDrvIns) pDrvIns->pDrvHlp->pfnAssertOther(pDrvIns, __FILE__, __LINE__, __FUNCTION__)
801#else
802# define PDMDRV_ASSERT_OTHER(pDrvIns) do { } while (0)
803#endif
804
805
806#ifdef IN_RING3
807/**
808 * @copydoc PDMDRVHLP::pfnSSMRegister
809 */
810DECLINLINE(int) PDMDrvHlpSSMRegister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
811 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
812 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
813{
814 return pDrvIns->pDrvHlp->pfnSSMRegister(pDrvIns, pszName, u32Instance, u32Version, cbGuess,
815 pfnSavePrep, pfnSaveExec, pfnSaveDone,
816 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
817}
818
819
820/**
821 * @copydoc PDMDRVHLP::pfnSTAMRegister
822 */
823DECLINLINE(void) PDMDrvHlpSTAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
824{
825 pDrvIns->pDrvHlp->pfnSTAMRegister(pDrvIns, pvSample, enmType, pszName, enmUnit, pszDesc);
826}
827
828/**
829 * @copydoc PDMDRVHLP::pfnSTAMRegisterF
830 */
831DECLINLINE(void) PDMDrvHlpSTAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit,
832 const char *pszDesc, const char *pszName, ...)
833{
834 va_list va;
835 va_start(va, pszName);
836 pDrvIns->pDrvHlp->pfnSTAMRegisterV(pDrvIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
837 va_end(va);
838}
839
840/**
841 * @copydoc PDMDRVHLP::pfnUSBRegisterHub
842 */
843DECLINLINE(int) PDMDrvHlpUSBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
844{
845 return pDrvIns->pDrvHlp->pfnUSBRegisterHub(pDrvIns, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp);
846}
847
848/**
849 * @copydoc PDMDRVHLP::pfnPDMThreadCreate
850 */
851DECLINLINE(int) PDMDrvHlpPDMThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
852 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
853{
854 return pDrvIns->pDrvHlp->pfnPDMThreadCreate(pDrvIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
855}
856
857/**
858 * @copydoc PDMDRVHLP::pfnVMState
859 */
860DECLINLINE(VMSTATE) PDMDrvHlpVMState(PPDMDRVINS pDrvIns)
861{
862 return pDrvIns->pDrvHlp->pfnVMState(pDrvIns);
863}
864
865#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
866/**
867 * @copydoc PDMDRVHLP::pfnPDMAsyncCompletionTemplateCreate
868 */
869DECLINLINE(int) PDMDrvHlpPDMAsyncCompletionTemplateCreate(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
870 PFNPDMASYNCCOMPLETEDRV pfnCompleted, const char *pszDesc)
871{
872 return pDrvIns->pDrvHlp->pfnPDMAsyncCompletionTemplateCreate(pDrvIns, ppTemplate, pfnCompleted, pszDesc);
873}
874#endif
875
876#endif /* IN_RING3 */
877
878
879
880/** Pointer to callbacks provided to the VBoxDriverRegister() call. */
881typedef struct PDMDRVREGCB *PPDMDRVREGCB;
882/** Pointer to const callbacks provided to the VBoxDriverRegister() call. */
883typedef const struct PDMDRVREGCB *PCPDMDRVREGCB;
884
885/**
886 * Callbacks for VBoxDriverRegister().
887 */
888typedef struct PDMDRVREGCB
889{
890 /** Interface version.
891 * This is set to PDM_DRVREG_CB_VERSION. */
892 uint32_t u32Version;
893
894 /**
895 * Registers a driver with the current VM instance.
896 *
897 * @returns VBox status code.
898 * @param pCallbacks Pointer to the callback table.
899 * @param pDrvReg Pointer to the driver registration record.
900 * This data must be permanent and readonly.
901 */
902 DECLR3CALLBACKMEMBER(int, pfnRegister,(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pDrvReg));
903} PDMDRVREGCB;
904
905/** Current version of the PDMDRVREGCB structure. */
906#define PDM_DRVREG_CB_VERSION 0xb0010000
907
908
909/**
910 * The VBoxDriverRegister callback function.
911 *
912 * PDM will invoke this function after loading a driver module and letting
913 * the module decide which drivers to register and how to handle conflicts.
914 *
915 * @returns VBox status code.
916 * @param pCallbacks Pointer to the callback table.
917 * @param u32Version VBox version number.
918 */
919typedef DECLCALLBACK(int) FNPDMVBOXDRIVERSREGISTER(PCPDMDRVREGCB pCallbacks, uint32_t u32Version);
920
921/**
922 * Register external drivers
923 *
924 * @returns VBox status code.
925 * @param pVM The VM to operate on.
926 * @param pfnCallback Driver registration callback
927 */
928PDMR3DECL(int) PDMR3RegisterDrivers(PVM pVM, FNPDMVBOXDRIVERSREGISTER pfnCallback);
929
930/** @} */
931
932__END_DECLS
933
934#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