VirtualBox

source: vbox/trunk/src/VBox/VMM/PDMDriver.cpp@ 14492

Last change on this file since 14492 was 14070, checked in by vboxsync, 16 years ago

CFGM: 64-bit MSC warning hunt.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 39.1 KB
Line 
1/* $Id: PDMDriver.cpp 14070 2008-11-10 23:45:24Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, Driver parts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_PDM_DRIVER
27#include "PDMInternal.h"
28#include <VBox/pdm.h>
29#include <VBox/mm.h>
30#include <VBox/cfgm.h>
31#include <VBox/vmm.h>
32#include <VBox/sup.h>
33#include <VBox/vm.h>
34#include <VBox/version.h>
35#include <VBox/err.h>
36
37#include <VBox/log.h>
38#include <iprt/assert.h>
39#include <iprt/thread.h>
40#include <iprt/string.h>
41#include <iprt/asm.h>
42#include <iprt/alloc.h>
43#include <iprt/path.h>
44
45
46/*******************************************************************************
47* Structures and Typedefs *
48*******************************************************************************/
49/**
50 * Internal callback structure pointer.
51 *
52 * The main purpose is to define the extra data we associate
53 * with PDMDRVREGCB so we can find the VM instance and so on.
54 */
55typedef struct PDMDRVREGCBINT
56{
57 /** The callback structure. */
58 PDMDRVREGCB Core;
59 /** A bit of padding. */
60 uint32_t u32[4];
61 /** VM Handle. */
62 PVM pVM;
63} PDMDRVREGCBINT, *PPDMDRVREGCBINT;
64typedef const PDMDRVREGCBINT *PCPDMDRVREGCBINT;
65
66
67/*******************************************************************************
68* Internal Functions *
69*******************************************************************************/
70/** @def PDMDRV_ASSERT_DRVINS
71 * Asserts the validity of the driver instance.
72 */
73#ifdef VBOX_STRICT
74# define PDMDRV_ASSERT_DRVINS(pDrvIns) \
75 do { \
76 AssertPtr(pDrvIns); \
77 Assert(pDrvIns->u32Version == PDM_DRVINS_VERSION); \
78 Assert(pDrvIns->pvInstanceData == (void *)&pDrvIns->achInstanceData[0]); \
79 } while (0)
80#else
81# define PDMDRV_ASSERT_DRVINS(pDrvIns) do { } while (0)
82#endif
83/** @} */
84
85static DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pDrvReg);
86static int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName);
87
88
89
90/**
91 * Register external drivers
92 *
93 * @returns VBox status code.
94 * @param pVM The VM to operate on.
95 * @param pfnCallback Driver registration callback
96 */
97VMMR3DECL(int) PDMR3RegisterDrivers(PVM pVM, FNPDMVBOXDRIVERSREGISTER pfnCallback)
98{
99 /*
100 * The registration callbacks.
101 */
102 PDMDRVREGCBINT RegCB;
103 RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
104 RegCB.Core.pfnRegister = pdmR3DrvRegister;
105 RegCB.pVM = pVM;
106
107 int rc = pfnCallback(&RegCB.Core, VBOX_VERSION);
108 if (RT_FAILURE(rc))
109 AssertMsgFailed(("VBoxDriversRegister failed with rc=%Rrc\n"));
110
111 return rc;
112}
113
114/**
115 * This function will initialize the drivers for this VM instance.
116 *
117 * First of all this mean loading the builtin drivers and letting them
118 * register themselves. Beyond that any additional driver modules are
119 * loaded and called for registration.
120 *
121 * @returns VBox status code.
122 * @param pVM VM Handle.
123 */
124int pdmR3DrvInit(PVM pVM)
125{
126 LogFlow(("pdmR3DrvInit:\n"));
127
128 AssertRelease(!(RT_OFFSETOF(PDMDRVINS, achInstanceData) & 15));
129 PPDMDRVINS pDrvInsAssert;
130 AssertRelease(sizeof(pDrvInsAssert->Internal.s) <= sizeof(pDrvInsAssert->Internal.padding));
131
132 /*
133 * The registration callbacks.
134 */
135 PDMDRVREGCBINT RegCB;
136 RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
137 RegCB.Core.pfnRegister = pdmR3DrvRegister;
138 RegCB.pVM = pVM;
139
140 /*
141 * Load the builtin module
142 */
143 PCFGMNODE pDriversNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM/Drivers");
144 bool fLoadBuiltin;
145 int rc = CFGMR3QueryBool(pDriversNode, "LoadBuiltin", &fLoadBuiltin);
146 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
147 fLoadBuiltin = true;
148 else if (RT_FAILURE(rc))
149 {
150 AssertMsgFailed(("Configuration error: Querying boolean \"LoadBuiltin\" failed with %Rrc\n", rc));
151 return rc;
152 }
153 if (fLoadBuiltin)
154 {
155 /* make filename */
156 char *pszFilename = pdmR3FileR3("VBoxDD", /*fShared=*/true);
157 if (!pszFilename)
158 return VERR_NO_TMP_MEMORY;
159 rc = pdmR3DrvLoad(pVM, &RegCB, pszFilename, "VBoxDD");
160 RTMemTmpFree(pszFilename);
161 if (RT_FAILURE(rc))
162 return rc;
163 }
164
165 /*
166 * Load additional driver modules.
167 */
168 for (PCFGMNODE pCur = CFGMR3GetFirstChild(pDriversNode); pCur; pCur = CFGMR3GetNextChild(pCur))
169 {
170 /*
171 * Get the name and path.
172 */
173 char szName[PDMMOD_NAME_LEN];
174 rc = CFGMR3GetName(pCur, &szName[0], sizeof(szName));
175 if (rc == VERR_CFGM_NOT_ENOUGH_SPACE)
176 {
177 AssertMsgFailed(("configuration error: The module name is too long, cchName=%zu.\n", CFGMR3GetNameLen(pCur)));
178 return VERR_PDM_MODULE_NAME_TOO_LONG;
179 }
180 else if (RT_FAILURE(rc))
181 {
182 AssertMsgFailed(("CFGMR3GetName -> %Rrc.\n", rc));
183 return rc;
184 }
185
186 /* the path is optional, if no path the module name + path is used. */
187 char szFilename[RTPATH_MAX];
188 rc = CFGMR3QueryString(pCur, "Path", &szFilename[0], sizeof(szFilename));
189 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
190 strcpy(szFilename, szName);
191 else if (RT_FAILURE(rc))
192 {
193 AssertMsgFailed(("configuration error: Failure to query the module path, rc=%Rrc.\n", rc));
194 return rc;
195 }
196
197 /* prepend path? */
198 if (!RTPathHavePath(szFilename))
199 {
200 char *psz = pdmR3FileR3(szFilename);
201 if (!psz)
202 return VERR_NO_TMP_MEMORY;
203 size_t cch = strlen(psz) + 1;
204 if (cch > sizeof(szFilename))
205 {
206 RTMemTmpFree(psz);
207 AssertMsgFailed(("Filename too long! cch=%d '%s'\n", cch, psz));
208 return VERR_FILENAME_TOO_LONG;
209 }
210 memcpy(szFilename, psz, cch);
211 RTMemTmpFree(psz);
212 }
213
214 /*
215 * Load the module and register it's drivers.
216 */
217 rc = pdmR3DrvLoad(pVM, &RegCB, szFilename, szName);
218 if (RT_FAILURE(rc))
219 return rc;
220 }
221
222 LogFlow(("pdmR3DrvInit: returns VINF_SUCCESS\n"));
223 return VINF_SUCCESS;
224}
225
226
227/**
228 * Loads one driver module and call the registration entry point.
229 *
230 * @returns VBox status code.
231 * @param pVM VM handle.
232 * @param pRegCB The registration callback stuff.
233 * @param pszFilename Module filename.
234 * @param pszName Module name.
235 */
236static int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName)
237{
238 /*
239 * Load it.
240 */
241 int rc = pdmR3LoadR3U(pVM->pUVM, pszFilename, pszName);
242 if (RT_SUCCESS(rc))
243 {
244 /*
245 * Get the registration export and call it.
246 */
247 FNPDMVBOXDRIVERSREGISTER *pfnVBoxDriversRegister;
248 rc = PDMR3LdrGetSymbolR3(pVM, pszName, "VBoxDriversRegister", (void **)&pfnVBoxDriversRegister);
249 if (RT_SUCCESS(rc))
250 {
251 Log(("PDM: Calling VBoxDriversRegister (%p) of %s (%s)\n", pfnVBoxDriversRegister, pszName, pszFilename));
252 rc = pfnVBoxDriversRegister(&pRegCB->Core, VBOX_VERSION);
253 if (RT_SUCCESS(rc))
254 Log(("PDM: Successfully loaded driver module %s (%s).\n", pszName, pszFilename));
255 else
256 AssertMsgFailed(("VBoxDriversRegister failed with rc=%Rrc\n"));
257 }
258 else
259 {
260 AssertMsgFailed(("Failed to locate 'VBoxDriversRegister' in %s (%s) rc=%Rrc\n", pszName, pszFilename, rc));
261 if (rc == VERR_SYMBOL_NOT_FOUND)
262 rc = VERR_PDM_NO_REGISTRATION_EXPORT;
263 }
264 }
265 else
266 AssertMsgFailed(("Failed to load %s (%s) rc=%Rrc!\n", pszName, pszFilename, rc));
267 return rc;
268}
269
270
271/** @copydoc PDMDRVREGCB::pfnRegister */
272static DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pDrvReg)
273{
274 /*
275 * Validate the registration structure.
276 */
277 Assert(pDrvReg);
278 if (pDrvReg->u32Version != PDM_DRVREG_VERSION)
279 {
280 AssertMsgFailed(("Unknown struct version %#x!\n", pDrvReg->u32Version));
281 return VERR_PDM_UNKNOWN_DRVREG_VERSION;
282 }
283 if ( !pDrvReg->szDriverName[0]
284 || strlen(pDrvReg->szDriverName) >= sizeof(pDrvReg->szDriverName))
285 {
286 AssertMsgFailed(("Invalid name '%s'\n", pDrvReg->szDriverName));
287 return VERR_PDM_INVALID_DRIVER_REGISTRATION;
288 }
289 if ((pDrvReg->fFlags & PDM_DRVREG_FLAGS_HOST_BITS_MASK) != PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT)
290 {
291 AssertMsgFailed(("Invalid host bits flags! fFlags=%#x (Driver %s)\n", pDrvReg->fFlags, pDrvReg->szDriverName));
292 return VERR_PDM_INVALID_DRIVER_HOST_BITS;
293 }
294 if (pDrvReg->cMaxInstances <= 0)
295 {
296 AssertMsgFailed(("Max instances %u! (Driver %s)\n", pDrvReg->cMaxInstances, pDrvReg->szDriverName));
297 return VERR_PDM_INVALID_DRIVER_REGISTRATION;
298 }
299 if (pDrvReg->cbInstance > _1M)
300 {
301 AssertMsgFailed(("Instance size above 1MB, %d bytes! (Driver %s)\n", pDrvReg->cbInstance, pDrvReg->szDriverName));
302 return VERR_PDM_INVALID_DRIVER_REGISTRATION;
303 }
304 if (!pDrvReg->pfnConstruct)
305 {
306 AssertMsgFailed(("No constructore! (Driver %s)\n", pDrvReg->szDriverName));
307 return VERR_PDM_INVALID_DRIVER_REGISTRATION;
308 }
309
310 /*
311 * Check for duplicate and find FIFO entry at the same time.
312 */
313 PCPDMDRVREGCBINT pRegCB = (PCPDMDRVREGCBINT)pCallbacks;
314 PPDMDRV pDrvPrev = NULL;
315 PPDMDRV pDrv = pRegCB->pVM->pdm.s.pDrvs;
316 for (; pDrv; pDrvPrev = pDrv, pDrv = pDrv->pNext)
317 {
318 if (!strcmp(pDrv->pDrvReg->szDriverName, pDrvReg->szDriverName))
319 {
320 AssertMsgFailed(("Driver '%s' already exists\n", pDrvReg->szDriverName));
321 return VERR_PDM_DRIVER_NAME_CLASH;
322 }
323 }
324
325 /*
326 * Allocate new driver structure and insert it into the list.
327 */
328 pDrv = (PPDMDRV)MMR3HeapAlloc(pRegCB->pVM, MM_TAG_PDM_DRIVER, sizeof(*pDrv));
329 if (pDrv)
330 {
331 pDrv->pNext = NULL;
332 pDrv->cInstances = 0;
333 pDrv->pDrvReg = pDrvReg;
334
335 if (pDrvPrev)
336 pDrvPrev->pNext = pDrv;
337 else
338 pRegCB->pVM->pdm.s.pDrvs = pDrv;
339 Log(("PDM: Registered driver '%s'\n", pDrvReg->szDriverName));
340 return VINF_SUCCESS;
341 }
342 return VERR_NO_MEMORY;
343}
344
345
346/**
347 * Lookups a driver structure by name.
348 * @internal
349 */
350PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName)
351{
352 for (PPDMDRV pDrv = pVM->pdm.s.pDrvs; pDrv; pDrv = pDrv->pNext)
353 if (!strcmp(pDrv->pDrvReg->szDriverName, pszName))
354 return pDrv;
355 return NULL;
356}
357
358
359/**
360 * Detaches a driver from whatever it's attached to.
361 * This will of course lead to the destruction of the driver and all drivers below it in the chain.
362 *
363 * @returns VINF_SUCCESS
364 * @param pDrvIns The driver instance to detach.
365 */
366int pdmR3DrvDetach(PPDMDRVINS pDrvIns)
367{
368 PDMDRV_ASSERT_DRVINS(pDrvIns);
369 LogFlow(("pdmR3DrvDetach: pDrvIns=%p '%s'/%d\n", pDrvIns, pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
370 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
371
372 /*
373 * Check that we're not doing this recursively, that could have unwanted sideeffects!
374 */
375 if (pDrvIns->Internal.s.fDetaching)
376 {
377 AssertMsgFailed(("Recursive detach! '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
378 return VINF_SUCCESS;
379 }
380
381 /*
382 * Check that we actually can detach this instance.
383 * The requirement is that the driver/device above has a detach method.
384 */
385 if (pDrvIns->Internal.s.pUp
386 ? !pDrvIns->Internal.s.pUp->pDrvReg->pfnDetach
387 : !pDrvIns->Internal.s.pLun->pDevIns->pDevReg->pfnDetach)
388 {
389 AssertMsgFailed(("Cannot detach driver instance because the driver/device above doesn't support it!\n"));
390 return VERR_PDM_DRIVER_DETACH_NOT_POSSIBLE;
391 }
392
393 /*
394 * Join paths with pdmR3DrvDestroyChain.
395 */
396 pdmR3DrvDestroyChain(pDrvIns);
397 return VINF_SUCCESS;
398}
399
400
401/**
402 * Destroys a driver chain starting with the specified driver.
403 *
404 * This is used when unplugging a device at run time.
405 *
406 * @param pDrvIns Pointer to the driver instance to start with.
407 */
408void pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns)
409{
410 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
411
412 /*
413 * Detach the bottommost driver until we've detached pDrvIns.
414 */
415 pDrvIns->Internal.s.fDetaching = true;
416 PPDMDRVINS pCur;
417 do
418 {
419 /* find the driver to detach. */
420 pCur = pDrvIns;
421 while (pCur->Internal.s.pDown)
422 pCur = pCur->Internal.s.pDown;
423 LogFlow(("pdmR3DrvDetach: pCur=%p '%s'/%d\n", pCur, pCur->pDrvReg->szDriverName, pCur->iInstance));
424
425 /*
426 * Unlink it and notify parent.
427 */
428 pCur->Internal.s.fDetaching = true;
429
430 PPDMLUN pLun = pCur->Internal.s.pLun;
431 Assert(pLun->pBottom == pCur);
432 pLun->pBottom = pCur->Internal.s.pUp;
433
434 if (pCur->Internal.s.pUp)
435 {
436 /* driver parent */
437 PPDMDRVINS pParent = pCur->Internal.s.pUp;
438 pCur->Internal.s.pUp = NULL;
439 pParent->Internal.s.pDown = NULL;
440
441 if (pParent->pDrvReg->pfnDetach)
442 pParent->pDrvReg->pfnDetach(pParent);
443
444 pParent->pDownBase = NULL;
445 }
446 else
447 {
448 /* device parent */
449 Assert(pLun->pTop == pCur);
450 pLun->pTop = NULL;
451 if (pLun->pDevIns->pDevReg->pfnDetach)
452 pLun->pDevIns->pDevReg->pfnDetach(pLun->pDevIns, pLun->iLun);
453 }
454
455 /*
456 * Call destructor.
457 */
458 pCur->pUpBase = NULL;
459 if (pCur->pDrvReg->pfnDestruct)
460 pCur->pDrvReg->pfnDestruct(pCur);
461
462 /*
463 * Free all resources allocated by the driver.
464 */
465 /* Queues. */
466 int rc = PDMR3QueueDestroyDriver(pCur->Internal.s.pVM, pCur);
467 AssertRC(rc);
468 /* Timers. */
469 rc = TMR3TimerDestroyDriver(pCur->Internal.s.pVM, pCur);
470 AssertRC(rc);
471 /* SSM data units. */
472 rc = SSMR3DeregisterDriver(pCur->Internal.s.pVM, pCur, NULL, 0);
473 AssertRC(rc);
474 /* PDM threads. */
475 rc = pdmR3ThreadDestroyDriver(pCur->Internal.s.pVM, pCur);
476 AssertRC(rc);
477 /* Finally, the driver it self. */
478 ASMMemFill32(pCur, RT_OFFSETOF(PDMDRVINS, achInstanceData[pCur->pDrvReg->cbInstance]), 0xdeadd0d0);
479 MMR3HeapFree(pCur);
480
481 } while (pCur != pDrvIns);
482}
483
484
485
486
487/** @name Driver Helpers
488 * @{
489 */
490
491/** @copydoc PDMDRVHLP::pfnAttach */
492static DECLCALLBACK(int) pdmR3DrvHlp_Attach(PPDMDRVINS pDrvIns, PPDMIBASE *ppBaseInterface)
493{
494 PDMDRV_ASSERT_DRVINS(pDrvIns);
495 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
496 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d:\n",
497 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
498
499 /*
500 * Check that there isn't anything attached already.
501 */
502 int rc;
503 if (!pDrvIns->Internal.s.pDown)
504 {
505 Assert(pDrvIns->Internal.s.pLun->pBottom == pDrvIns);
506
507 /*
508 * Get the attached driver configuration.
509 */
510 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
511 if (pNode)
512 {
513 char *pszName;
514 rc = CFGMR3QueryStringAlloc(pNode, "Driver", &pszName);
515 if (RT_SUCCESS(rc))
516 {
517 /*
518 * Find the driver and allocate instance data.
519 */
520 PVM pVM = pDrvIns->Internal.s.pVM;
521 PPDMDRV pDrv = pdmR3DrvLookup(pVM, pszName);
522 if (pDrv)
523 {
524 /* config node */
525 PCFGMNODE pConfigNode = CFGMR3GetChild(pNode, "Config");
526 if (!pConfigNode)
527 rc = CFGMR3InsertNode(pNode, "Config", &pConfigNode);
528 if (RT_SUCCESS(rc))
529 {
530 CFGMR3SetRestrictedRoot(pConfigNode);
531
532 size_t cb = RT_OFFSETOF(PDMDRVINS, achInstanceData[pDrv->pDrvReg->cbInstance]);
533 cb = RT_ALIGN_Z(cb, 16);
534 PPDMDRVINS pNew = (PPDMDRVINS)MMR3HeapAllocZ(pVM, MM_TAG_PDM_DRIVER, cb);
535 if (pNew)
536 {
537 /*
538 * Initialize the instance structure (declaration order).
539 */
540 pNew->u32Version = PDM_DRVINS_VERSION;
541 pNew->Internal.s.pUp = pDrvIns;
542 pNew->Internal.s.pDown = NULL;
543 pNew->Internal.s.pLun = pDrvIns->Internal.s.pLun;
544 pNew->Internal.s.pDrv = pDrv;
545 pNew->Internal.s.pVM = pVM;
546 pNew->Internal.s.fDetaching = false;
547 pNew->Internal.s.pCfgHandle = pNode;
548 pNew->pDrvHlp = &g_pdmR3DrvHlp;
549 pNew->pDrvReg = pDrv->pDrvReg;
550 pNew->pCfgHandle = pConfigNode;
551 pNew->iInstance = pDrv->cInstances++;
552 pNew->pUpBase = &pDrvIns->IBase; /* This ain't safe, you can calc the pDrvIns of the up/down driver! */
553 pNew->pDownBase = NULL;
554 pNew->IBase.pfnQueryInterface = NULL;
555 pNew->pvInstanceData = &pNew->achInstanceData[0];
556
557 /*
558 * Hook it onto the chain and call the constructor.
559 */
560 pDrvIns->Internal.s.pDown = pNew;
561 pDrvIns->Internal.s.pLun->pBottom = pNew;
562
563 Log(("PDM: Constructing driver '%s' instance %d...\n", pNew->pDrvReg->szDriverName, pNew->iInstance));
564 rc = pDrv->pDrvReg->pfnConstruct(pNew, pNew->pCfgHandle);
565 if (RT_SUCCESS(rc))
566 {
567 *ppBaseInterface = &pNew->IBase;
568 rc = VINF_SUCCESS;
569 }
570 else
571 {
572 /*
573 * Unlink and free the data.
574 */
575 Assert(pDrvIns->Internal.s.pLun->pBottom == pNew);
576 pDrvIns->Internal.s.pLun->pBottom = pDrvIns;
577 pDrvIns->Internal.s.pDown = NULL;
578 ASMMemFill32(pNew, cb, 0xdeadd0d0);
579 MMR3HeapFree(pNew);
580 pDrv->cInstances--;
581 }
582 }
583 else
584 {
585 AssertMsgFailed(("Failed to allocate %d bytes for instantiating driver '%s'\n", cb, pszName));
586 rc = VERR_NO_MEMORY;
587 }
588 }
589 else
590 AssertMsgFailed(("Failed to create Config node! rc=%Rrc\n", rc));
591 }
592 else
593 {
594 AssertMsgFailed(("Driver '%s' wasn't found!\n", pszName));
595 rc = VERR_PDM_DRIVER_NOT_FOUND;
596 }
597 MMR3HeapFree(pszName);
598 }
599 else
600 {
601 AssertMsgFailed(("Query for string value of \"Driver\" -> %Rrc\n", rc));
602 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
603 rc = VERR_PDM_CFG_MISSING_DRIVER_NAME;
604 }
605 }
606 else
607 rc = VERR_PDM_NO_ATTACHED_DRIVER;
608 }
609 else
610 {
611 AssertMsgFailed(("Already got a driver attached. The driver should keep track of such things!\n"));
612 rc = VERR_PDM_DRIVER_ALREADY_ATTACHED;
613 }
614
615 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: return %Rrc\n",
616 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
617 return rc;
618}
619
620
621/** @copydoc PDMDRVHLP::pfnDetach */
622static DECLCALLBACK(int) pdmR3DrvHlp_Detach(PPDMDRVINS pDrvIns)
623{
624 PDMDRV_ASSERT_DRVINS(pDrvIns);
625 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d:\n",
626 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
627 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
628
629 /*
630 * Anything attached?
631 */
632 int rc;
633 if (pDrvIns->Internal.s.pDown)
634 {
635 rc = pdmR3DrvDetach(pDrvIns->Internal.s.pDown);
636 }
637 else
638 {
639 AssertMsgFailed(("Nothing attached!\n"));
640 rc = VERR_PDM_NO_DRIVER_ATTACHED;
641 }
642
643 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: returns %Rrc\n",
644 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
645 return rc;
646}
647
648
649/** @copydoc PDMDRVHLP::pfnDetachSelf */
650static DECLCALLBACK(int) pdmR3DrvHlp_DetachSelf(PPDMDRVINS pDrvIns)
651{
652 PDMDRV_ASSERT_DRVINS(pDrvIns);
653 LogFlow(("pdmR3DrvHlp_DetachSelf: caller='%s'/%d:\n",
654 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
655 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
656
657 int rc = pdmR3DrvDetach(pDrvIns);
658
659 LogFlow(("pdmR3DrvHlp_Detach: returns %Rrc\n", rc)); /* pDrvIns is freed by now. */
660 return rc;
661}
662
663
664/** @copydoc PDMDRVHLP::pfnMountPrepare */
665static DECLCALLBACK(int) pdmR3DrvHlp_MountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver)
666{
667 PDMDRV_ASSERT_DRVINS(pDrvIns);
668 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: pszFilename=%p:{%s} pszCoreDriver=%p:{%s}\n",
669 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszFilename, pszFilename, pszCoreDriver, pszCoreDriver));
670 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
671
672 /*
673 * Do the caller have anything attached below itself?
674 */
675 if (pDrvIns->Internal.s.pDown)
676 {
677 AssertMsgFailed(("Cannot prepare a mount when something's attached to you!\n"));
678 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
679 }
680
681 /*
682 * We're asked to prepare, so we'll start off by nuking the
683 * attached configuration tree.
684 */
685 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
686 if (pNode)
687 CFGMR3RemoveNode(pNode);
688
689 /*
690 * If there is no core driver, we'll have to probe for it.
691 */
692 if (!pszCoreDriver)
693 {
694 /** @todo implement image probing. */
695 AssertReleaseMsgFailed(("Not implemented!\n"));
696 return VERR_NOT_IMPLEMENTED;
697 }
698
699 /*
700 * Construct the basic attached driver configuration.
701 */
702 int rc = CFGMR3InsertNode(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver", &pNode);
703 if (RT_SUCCESS(rc))
704 {
705 rc = CFGMR3InsertString(pNode, "Driver", pszCoreDriver);
706 if (RT_SUCCESS(rc))
707 {
708 PCFGMNODE pCfg;
709 rc = CFGMR3InsertNode(pNode, "Config", &pCfg);
710 if (RT_SUCCESS(rc))
711 {
712 rc = CFGMR3InsertString(pCfg, "Path", pszFilename);
713 if (RT_SUCCESS(rc))
714 {
715 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc (Driver=%s)\n",
716 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, pszCoreDriver));
717 return rc;
718 }
719 else
720 AssertMsgFailed(("Path string insert failed, rc=%Rrc\n", rc));
721 }
722 else
723 AssertMsgFailed(("Config node failed, rc=%Rrc\n", rc));
724 }
725 else
726 AssertMsgFailed(("Driver string insert failed, rc=%Rrc\n", rc));
727 CFGMR3RemoveNode(pNode);
728 }
729 else
730 AssertMsgFailed(("AttachedDriver node insert failed, rc=%Rrc\n", rc));
731
732 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc\n",
733 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
734 return rc;
735}
736
737
738/** @copydoc PDMDRVHLP::pfnAssertEMT */
739static DECLCALLBACK(bool) pdmR3DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
740{
741 PDMDRV_ASSERT_DRVINS(pDrvIns);
742 if (VM_IS_EMT(pDrvIns->Internal.s.pVM))
743 return true;
744
745 char szMsg[100];
746 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance);
747 AssertMsg1(szMsg, iLine, pszFile, pszFunction);
748 AssertBreakpoint();
749 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
750 return false;
751}
752
753
754/** @copydoc PDMDRVHLP::pfnAssertOther */
755static DECLCALLBACK(bool) pdmR3DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
756{
757 PDMDRV_ASSERT_DRVINS(pDrvIns);
758 if (!VM_IS_EMT(pDrvIns->Internal.s.pVM))
759 return true;
760
761 char szMsg[100];
762 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance);
763 AssertMsg1(szMsg, iLine, pszFile, pszFunction);
764 AssertBreakpoint();
765 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
766 return false;
767}
768
769
770/** @copydoc PDMDRVHLP::pfnVMSetError */
771static DECLCALLBACK(int) pdmR3DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
772{
773 PDMDRV_ASSERT_DRVINS(pDrvIns);
774 va_list args;
775 va_start(args, pszFormat);
776 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVM, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
777 va_end(args);
778 return rc;
779}
780
781
782/** @copydoc PDMDRVHLP::pfnVMSetErrorV */
783static DECLCALLBACK(int) pdmR3DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
784{
785 PDMDRV_ASSERT_DRVINS(pDrvIns);
786 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVM, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
787 return rc;
788}
789
790
791/** @copydoc PDMDRVHLP::pfnVMSetRuntimeError */
792static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...)
793{
794 PDMDRV_ASSERT_DRVINS(pDrvIns);
795 va_list args;
796 va_start(args, pszFormat);
797 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVM, fFatal, pszErrorID, pszFormat, args);
798 va_end(args);
799 return rc;
800}
801
802
803/** @copydoc PDMDRVHLP::pfnVMSetRuntimeErrorV */
804static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va)
805{
806 PDMDRV_ASSERT_DRVINS(pDrvIns);
807 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVM, fFatal, pszErrorID, pszFormat, va);
808 return rc;
809}
810
811
812/** @copydoc PDMDRVHLP::pfnPDMQueueCreate */
813static DECLCALLBACK(int) pdmR3DrvHlp_PDMQueueCreate(PPDMDRVINS pDrvIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval, PFNPDMQUEUEDRV pfnCallback, PPDMQUEUE *ppQueue)
814{
815 PDMDRV_ASSERT_DRVINS(pDrvIns);
816 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: cbItem=%d cItems=%d cMilliesInterval=%d pfnCallback=%p ppQueue=%p\n",
817 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, ppQueue, ppQueue));
818 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
819
820 int rc = PDMR3QueueCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, cbItem, cItems, cMilliesInterval, pfnCallback, ppQueue);
821
822 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, *ppQueue));
823 return rc;
824}
825
826
827/** @copydoc PDMDRVHLP::pfnPDMPollerRegister */
828static DECLCALLBACK(int) pdmR3DrvHlp_PDMPollerRegister(PPDMDRVINS pDrvIns, PFNPDMDRVPOLLER pfnPoller)
829{
830 PDMDRV_ASSERT_DRVINS(pDrvIns);
831 LogFlow(("pdmR3DrvHlp_PDMPollerRegister: caller='%s'/%d: pfnPoller=%p\n",
832 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pfnPoller));
833 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
834
835 int rc = VINF_SUCCESS;
836 PVM pVM = pDrvIns->Internal.s.pVM;
837 if (pVM->pdm.s.cPollers < RT_ELEMENTS(pVM->pdm.s.apfnPollers))
838 {
839 pVM->pdm.s.apfnPollers[pVM->pdm.s.cPollers] = pfnPoller;
840 pVM->pdm.s.aDrvInsPollers[pVM->pdm.s.cPollers] = pDrvIns;
841 pVM->pdm.s.cPollers++;
842 if (pVM->pdm.s.cPollers == 1)
843 TMTimerSetMillies(pVM->pdm.s.pTimerPollers, 5);
844 }
845 else
846 {
847 AssertMsgFailed(("Too many pollers!\n"));
848 rc = VERR_INTERNAL_ERROR;
849 }
850
851 LogFlow(("pdmR3DrvHlp_PDMPollerRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
852 return rc;
853}
854
855
856/** @copydoc PDMDRVHLP::pfnTMGetVirtualFreq */
857static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualFreq(PPDMDRVINS pDrvIns)
858{
859 PDMDRV_ASSERT_DRVINS(pDrvIns);
860
861 return TMVirtualGetFreq(pDrvIns->Internal.s.pVM);
862}
863
864
865/** @copydoc PDMDRVHLP::pfnTMGetVirtualTime */
866static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualTime(PPDMDRVINS pDrvIns)
867{
868 PDMDRV_ASSERT_DRVINS(pDrvIns);
869
870 return TMVirtualGet(pDrvIns->Internal.s.pVM);
871}
872
873
874/** @copydoc PDMDRVHLP::pfnTMTimerCreate */
875static DECLCALLBACK(int) pdmR3DrvHlp_TMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERR3 ppTimer)
876{
877 PDMDRV_ASSERT_DRVINS(pDrvIns);
878 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pszDesc=%p:{%s} ppTimer=%p\n",
879 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, enmClock, pfnCallback, pszDesc, pszDesc, ppTimer));
880
881 int rc = TMR3TimerCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, enmClock, pfnCallback, pszDesc, ppTimer);
882
883 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: returns %Rrc *ppTimer=%p\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, *ppTimer));
884 return rc;
885}
886
887
888
889/** @copydoc PDMDRVHLP::pfnSSMRegister */
890static DECLCALLBACK(int) pdmR3DrvHlp_SSMRegister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
891 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
892 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
893{
894 PDMDRV_ASSERT_DRVINS(pDrvIns);
895 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
896 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x u32Version=#x cbGuess=%#x pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoaddone=%p\n",
897 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszName, pszName, u32Instance, u32Version, cbGuess, pfnSavePrep, pfnSaveExec, pfnSaveDone, pfnLoadPrep, pfnLoadExec, pfnLoadDone));
898
899 int rc = SSMR3RegisterDriver(pDrvIns->Internal.s.pVM, pDrvIns, pszName, u32Instance, u32Version, cbGuess,
900 pfnSavePrep, pfnSaveExec, pfnSaveDone,
901 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
902
903 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
904 return rc;
905}
906
907
908/** @copydoc PDMDRVHLP::pfnSSMDeregister */
909static DECLCALLBACK(int) pdmR3DrvHlp_SSMDeregister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance)
910{
911 PDMDRV_ASSERT_DRVINS(pDrvIns);
912 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
913 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x\n",
914 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszName, pszName, u32Instance));
915
916 int rc = SSMR3DeregisterDriver(pDrvIns->Internal.s.pVM, pDrvIns, pszName, u32Instance);
917
918 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
919 return rc;
920}
921
922
923/** @copydoc PDMDRVHLP::pfnSTAMRegister */
924static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
925{
926 PDMDRV_ASSERT_DRVINS(pDrvIns);
927 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
928
929 STAM_REG(pDrvIns->Internal.s.pVM, pvSample, enmType, pszName, enmUnit, pszDesc);
930 /** @todo track the samples so they can be dumped & deregistered when the driver instance is destroyed.
931 * For now we just have to be careful not to use this call for drivers which can be unloaded. */
932}
933
934
935/** @copydoc PDMDRVHLP::pfnSTAMRegisterF */
936static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
937 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
938{
939 PDMDRV_ASSERT_DRVINS(pDrvIns);
940 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
941
942 va_list args;
943 va_start(args, pszName);
944 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
945 va_end(args);
946 AssertRC(rc);
947}
948
949
950/** @copydoc PDMDRVHLP::pfnSTAMRegisterV */
951static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
952 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
953{
954 PDMDRV_ASSERT_DRVINS(pDrvIns);
955 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
956
957 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
958 AssertRC(rc);
959}
960
961
962/** @copydoc PDMDRVHLP::pfnSUPCallVMMR0Ex */
963static DECLCALLBACK(int) pdmR3DrvHlp_SUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg)
964{
965 PDMDRV_ASSERT_DRVINS(pDrvIns);
966 LogFlow(("pdmR3DrvHlp_SSMCallVMMR0Ex: caller='%s'/%d: uOperation=%u pvArg=%p cbArg=%d\n",
967 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, uOperation, pvArg, cbArg));
968 int rc;
969 if ( uOperation >= VMMR0_DO_SRV_START
970 && uOperation < VMMR0_DO_SRV_END)
971 rc = SUPCallVMMR0Ex(pDrvIns->Internal.s.pVM->pVMR0, uOperation, 0, (PSUPVMMR0REQHDR)pvArg);
972 else
973 {
974 AssertMsgFailed(("Invalid uOperation=%u\n", uOperation));
975 rc = VERR_INVALID_PARAMETER;
976 }
977
978 LogFlow(("pdmR3DrvHlp_SUPCallVMMR0Ex: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
979 return rc;
980}
981
982
983/** @copydoc PDMDRVHLP::pfnUSBRegisterHub */
984static DECLCALLBACK(int) pdmR3DrvHlp_USBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
985{
986 PDMDRV_ASSERT_DRVINS(pDrvIns);
987 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
988 LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: fVersions=%#x cPorts=%#x pUsbHubReg=%p ppUsbHubHlp=%p\n",
989 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp));
990
991#ifdef VBOX_WITH_USB
992 int rc = pdmR3UsbRegisterHub(pDrvIns->Internal.s.pVM, pDrvIns, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp);
993#else
994 int rc = VERR_NOT_SUPPORTED;
995#endif
996
997 LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
998 return rc;
999}
1000
1001
1002/** @copydoc PDMDRVHLP::pfnPDMThreadCreate */
1003static DECLCALLBACK(int) pdmR3DrvHlp_PDMThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
1004 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
1005{
1006 PDMDRV_ASSERT_DRVINS(pDrvIns);
1007 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
1008 LogFlow(("pdmR3DrvHlp_PDMThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
1009 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
1010
1011 int rc = pdmR3ThreadCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
1012
1013 LogFlow(("pdmR3DrvHlp_PDMThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance,
1014 rc, *ppThread));
1015 return rc;
1016}
1017
1018
1019/** @copydoc PDMDEVHLPR3::pfnVMState */
1020static DECLCALLBACK(VMSTATE) pdmR3DrvHlp_VMState(PPDMDRVINS pDrvIns)
1021{
1022 PDMDRV_ASSERT_DRVINS(pDrvIns);
1023
1024 VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVM);
1025
1026 LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance,
1027 enmVMState, VMR3GetStateName(enmVMState)));
1028 return enmVMState;
1029}
1030
1031
1032#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1033/** @copydoc PDMDRVHLP::pfnPDMAsyncCompletionTemplateCreate */
1034static DECLCALLBACK(int) pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
1035 PFNPDMASYNCCOMPLETEDRV pfnCompleted, const char *pszDesc)
1036{
1037 PDMDRV_ASSERT_DRVINS(pDrvIns);
1038 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
1039 LogFlow(("pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate: caller='%s'/%d: ppTemplate=%p pfnCompleted=%p pszDesc=%p:{%s}\n",
1040 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, ppTemplate, pfnCompleted, pszDesc, pszDesc));
1041
1042 int rc = PDMR3AsyncCompletionTemplateCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, ppTemplate, pfnCompleted, pszDesc);
1043
1044 LogFlow(("pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate: caller='%s'/%d: returns %Rrc *ppThread=%p\n", pDrvIns->pDrvReg->szDriverName,
1045 pDrvIns->iInstance, rc, *ppTemplate));
1046 return rc;
1047}
1048#endif
1049
1050
1051/**
1052 * The driver helper structure.
1053 */
1054const PDMDRVHLP g_pdmR3DrvHlp =
1055{
1056 PDM_DRVHLP_VERSION,
1057 pdmR3DrvHlp_Attach,
1058 pdmR3DrvHlp_Detach,
1059 pdmR3DrvHlp_DetachSelf,
1060 pdmR3DrvHlp_MountPrepare,
1061 pdmR3DrvHlp_AssertEMT,
1062 pdmR3DrvHlp_AssertOther,
1063 pdmR3DrvHlp_VMSetError,
1064 pdmR3DrvHlp_VMSetErrorV,
1065 pdmR3DrvHlp_VMSetRuntimeError,
1066 pdmR3DrvHlp_VMSetRuntimeErrorV,
1067 pdmR3DrvHlp_PDMQueueCreate,
1068 pdmR3DrvHlp_PDMPollerRegister,
1069 pdmR3DrvHlp_TMGetVirtualFreq,
1070 pdmR3DrvHlp_TMGetVirtualTime,
1071 pdmR3DrvHlp_TMTimerCreate,
1072 pdmR3DrvHlp_SSMRegister,
1073 pdmR3DrvHlp_SSMDeregister,
1074 pdmR3DrvHlp_STAMRegister,
1075 pdmR3DrvHlp_STAMRegisterF,
1076 pdmR3DrvHlp_STAMRegisterV,
1077 pdmR3DrvHlp_SUPCallVMMR0Ex,
1078 pdmR3DrvHlp_USBRegisterHub,
1079 pdmR3DrvHlp_PDMThreadCreate,
1080 pdmR3DrvHlp_VMState,
1081#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1082 pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate,
1083#endif
1084 PDM_DRVHLP_VERSION /* u32TheEnd */
1085};
1086
1087/** @} */
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