VirtualBox

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

Last change on this file since 22016 was 21789, checked in by vboxsync, 15 years ago

PDMDriver/DevHlp.cpp: Don't use dash when mangling queue names, STAM will bitch.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 39.4 KB
Line 
1/* $Id: PDMDriver.cpp 21789 2009-07-24 17:29:12Z 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 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
366 */
367int pdmR3DrvDetach(PPDMDRVINS pDrvIns, uint32_t fFlags)
368{
369 PDMDRV_ASSERT_DRVINS(pDrvIns);
370 LogFlow(("pdmR3DrvDetach: pDrvIns=%p '%s'/%d\n", pDrvIns, pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
371 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
372
373 /*
374 * Check that we're not doing this recursively, that could have unwanted sideeffects!
375 */
376 if (pDrvIns->Internal.s.fDetaching)
377 {
378 AssertMsgFailed(("Recursive detach! '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
379 return VINF_SUCCESS;
380 }
381
382 /*
383 * Check that we actually can detach this instance.
384 * The requirement is that the driver/device above has a detach method.
385 */
386 if (pDrvIns->Internal.s.pUp
387 ? !pDrvIns->Internal.s.pUp->pDrvReg->pfnDetach
388 : !pDrvIns->Internal.s.pLun->pDevIns->pDevReg->pfnDetach)
389 {
390 AssertMsgFailed(("Cannot detach driver instance because the driver/device above doesn't support it!\n"));
391 return VERR_PDM_DRIVER_DETACH_NOT_POSSIBLE;
392 }
393
394 /*
395 * Join paths with pdmR3DrvDestroyChain.
396 */
397 pdmR3DrvDestroyChain(pDrvIns, fFlags);
398 return VINF_SUCCESS;
399}
400
401
402/**
403 * Destroys a driver chain starting with the specified driver.
404 *
405 * This is used when unplugging a device at run time.
406 *
407 * @param pDrvIns Pointer to the driver instance to start with.
408 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
409 */
410void pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns, uint32_t fFlags)
411{
412 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
413
414 /*
415 * Detach the bottommost driver until we've detached pDrvIns.
416 */
417 pDrvIns->Internal.s.fDetaching = true;
418 PPDMDRVINS pCur;
419 do
420 {
421 /* find the driver to detach. */
422 pCur = pDrvIns;
423 while (pCur->Internal.s.pDown)
424 pCur = pCur->Internal.s.pDown;
425 LogFlow(("pdmR3DrvDetach: pCur=%p '%s'/%d\n", pCur, pCur->pDrvReg->szDriverName, pCur->iInstance));
426
427 /*
428 * Unlink it and notify parent.
429 */
430 pCur->Internal.s.fDetaching = true;
431
432 PPDMLUN pLun = pCur->Internal.s.pLun;
433 Assert(pLun->pBottom == pCur);
434 pLun->pBottom = pCur->Internal.s.pUp;
435
436 if (pCur->Internal.s.pUp)
437 {
438 /* driver parent */
439 PPDMDRVINS pParent = pCur->Internal.s.pUp;
440 pCur->Internal.s.pUp = NULL;
441 pParent->Internal.s.pDown = NULL;
442
443 if (pParent->pDrvReg->pfnDetach)
444 pParent->pDrvReg->pfnDetach(pParent);
445
446 pParent->pDownBase = NULL;
447 }
448 else
449 {
450 /* device parent */
451 Assert(pLun->pTop == pCur);
452 pLun->pTop = NULL;
453 if (pLun->pDevIns->pDevReg->pfnDetach)
454 pLun->pDevIns->pDevReg->pfnDetach(pLun->pDevIns, pLun->iLun, fFlags);
455 }
456
457 /*
458 * Call destructor.
459 */
460 pCur->pUpBase = NULL;
461 if (pCur->pDrvReg->pfnDestruct)
462 pCur->pDrvReg->pfnDestruct(pCur);
463
464 /*
465 * Free all resources allocated by the driver.
466 */
467 /* Queues. */
468 int rc = PDMR3QueueDestroyDriver(pCur->Internal.s.pVM, pCur);
469 AssertRC(rc);
470 /* Timers. */
471 rc = TMR3TimerDestroyDriver(pCur->Internal.s.pVM, pCur);
472 AssertRC(rc);
473 /* SSM data units. */
474 rc = SSMR3DeregisterDriver(pCur->Internal.s.pVM, pCur, NULL, 0);
475 AssertRC(rc);
476 /* PDM threads. */
477 rc = pdmR3ThreadDestroyDriver(pCur->Internal.s.pVM, pCur);
478 AssertRC(rc);
479 /* Finally, the driver it self. */
480 ASMMemFill32(pCur, RT_OFFSETOF(PDMDRVINS, achInstanceData[pCur->pDrvReg->cbInstance]), 0xdeadd0d0);
481 MMR3HeapFree(pCur);
482
483 } while (pCur != pDrvIns);
484}
485
486
487
488
489/** @name Driver Helpers
490 * @{
491 */
492
493/** @copydoc PDMDRVHLP::pfnAttach */
494static DECLCALLBACK(int) pdmR3DrvHlp_Attach(PPDMDRVINS pDrvIns, PPDMIBASE *ppBaseInterface)
495{
496 PDMDRV_ASSERT_DRVINS(pDrvIns);
497 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
498 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d:\n",
499 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
500
501 /*
502 * Check that there isn't anything attached already.
503 */
504 int rc;
505 if (!pDrvIns->Internal.s.pDown)
506 {
507 Assert(pDrvIns->Internal.s.pLun->pBottom == pDrvIns);
508
509 /*
510 * Get the attached driver configuration.
511 */
512 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
513 if (pNode)
514 {
515 char *pszName;
516 rc = CFGMR3QueryStringAlloc(pNode, "Driver", &pszName);
517 if (RT_SUCCESS(rc))
518 {
519 /*
520 * Find the driver and allocate instance data.
521 */
522 PVM pVM = pDrvIns->Internal.s.pVM;
523 PPDMDRV pDrv = pdmR3DrvLookup(pVM, pszName);
524 if (pDrv)
525 {
526 /* config node */
527 PCFGMNODE pConfigNode = CFGMR3GetChild(pNode, "Config");
528 if (!pConfigNode)
529 rc = CFGMR3InsertNode(pNode, "Config", &pConfigNode);
530 if (RT_SUCCESS(rc))
531 {
532 CFGMR3SetRestrictedRoot(pConfigNode);
533
534 size_t cb = RT_OFFSETOF(PDMDRVINS, achInstanceData[pDrv->pDrvReg->cbInstance]);
535 cb = RT_ALIGN_Z(cb, 16);
536 PPDMDRVINS pNew = (PPDMDRVINS)MMR3HeapAllocZ(pVM, MM_TAG_PDM_DRIVER, cb);
537 if (pNew)
538 {
539 /*
540 * Initialize the instance structure (declaration order).
541 */
542 pNew->u32Version = PDM_DRVINS_VERSION;
543 pNew->Internal.s.pUp = pDrvIns;
544 pNew->Internal.s.pDown = NULL;
545 pNew->Internal.s.pLun = pDrvIns->Internal.s.pLun;
546 pNew->Internal.s.pDrv = pDrv;
547 pNew->Internal.s.pVM = pVM;
548 pNew->Internal.s.fDetaching = false;
549 pNew->Internal.s.pCfgHandle = pNode;
550 pNew->pDrvHlp = &g_pdmR3DrvHlp;
551 pNew->pDrvReg = pDrv->pDrvReg;
552 pNew->pCfgHandle = pConfigNode;
553 pNew->iInstance = pDrv->cInstances++;
554 pNew->pUpBase = &pDrvIns->IBase; /* This ain't safe, you can calc the pDrvIns of the up/down driver! */
555 pNew->pDownBase = NULL;
556 pNew->IBase.pfnQueryInterface = NULL;
557 pNew->pvInstanceData = &pNew->achInstanceData[0];
558
559 /*
560 * Hook it onto the chain and call the constructor.
561 */
562 pDrvIns->Internal.s.pDown = pNew;
563 pDrvIns->Internal.s.pLun->pBottom = pNew;
564
565 Log(("PDM: Constructing driver '%s' instance %d...\n", pNew->pDrvReg->szDriverName, pNew->iInstance));
566 rc = pDrv->pDrvReg->pfnConstruct(pNew, pNew->pCfgHandle);
567 if (RT_SUCCESS(rc))
568 {
569 *ppBaseInterface = &pNew->IBase;
570 rc = VINF_SUCCESS;
571 }
572 else
573 {
574 /*
575 * Unlink and free the data.
576 */
577 Assert(pDrvIns->Internal.s.pLun->pBottom == pNew);
578 pDrvIns->Internal.s.pLun->pBottom = pDrvIns;
579 pDrvIns->Internal.s.pDown = NULL;
580 ASMMemFill32(pNew, cb, 0xdeadd0d0);
581 MMR3HeapFree(pNew);
582 pDrv->cInstances--;
583 }
584 }
585 else
586 {
587 AssertMsgFailed(("Failed to allocate %d bytes for instantiating driver '%s'\n", cb, pszName));
588 rc = VERR_NO_MEMORY;
589 }
590 }
591 else
592 AssertMsgFailed(("Failed to create Config node! rc=%Rrc\n", rc));
593 }
594 else
595 {
596 AssertMsgFailed(("Driver '%s' wasn't found!\n", pszName));
597 rc = VERR_PDM_DRIVER_NOT_FOUND;
598 }
599 MMR3HeapFree(pszName);
600 }
601 else
602 {
603 AssertMsgFailed(("Query for string value of \"Driver\" -> %Rrc\n", rc));
604 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
605 rc = VERR_PDM_CFG_MISSING_DRIVER_NAME;
606 }
607 }
608 else
609 rc = VERR_PDM_NO_ATTACHED_DRIVER;
610 }
611 else
612 {
613 AssertMsgFailed(("Already got a driver attached. The driver should keep track of such things!\n"));
614 rc = VERR_PDM_DRIVER_ALREADY_ATTACHED;
615 }
616
617 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: return %Rrc\n",
618 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
619 return rc;
620}
621
622
623/** @copydoc PDMDRVHLP::pfnDetach */
624static DECLCALLBACK(int) pdmR3DrvHlp_Detach(PPDMDRVINS pDrvIns)
625{
626 PDMDRV_ASSERT_DRVINS(pDrvIns);
627 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d:\n",
628 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
629 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
630
631 /*
632 * Anything attached?
633 */
634 int rc;
635 if (pDrvIns->Internal.s.pDown)
636 {
637 /** @todo: Current assumption is that drivers will never initiate hot plug events. */
638 rc = pdmR3DrvDetach(pDrvIns->Internal.s.pDown, PDMDEVATT_FLAGS_NOT_HOT_PLUG);
639 }
640 else
641 {
642 AssertMsgFailed(("Nothing attached!\n"));
643 rc = VERR_PDM_NO_DRIVER_ATTACHED;
644 }
645
646 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: returns %Rrc\n",
647 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
648 return rc;
649}
650
651
652/** @copydoc PDMDRVHLP::pfnDetachSelf */
653static DECLCALLBACK(int) pdmR3DrvHlp_DetachSelf(PPDMDRVINS pDrvIns)
654{
655 PDMDRV_ASSERT_DRVINS(pDrvIns);
656 LogFlow(("pdmR3DrvHlp_DetachSelf: caller='%s'/%d:\n",
657 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
658 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
659
660 /** @todo: Current assumption is that drivers will never initiate hot plug events. */
661 int rc = pdmR3DrvDetach(pDrvIns, PDMDEVATT_FLAGS_NOT_HOT_PLUG);
662
663 LogFlow(("pdmR3DrvHlp_Detach: returns %Rrc\n", rc)); /* pDrvIns is freed by now. */
664 return rc;
665}
666
667
668/** @copydoc PDMDRVHLP::pfnMountPrepare */
669static DECLCALLBACK(int) pdmR3DrvHlp_MountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver)
670{
671 PDMDRV_ASSERT_DRVINS(pDrvIns);
672 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: pszFilename=%p:{%s} pszCoreDriver=%p:{%s}\n",
673 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszFilename, pszFilename, pszCoreDriver, pszCoreDriver));
674 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
675
676 /*
677 * Do the caller have anything attached below itself?
678 */
679 if (pDrvIns->Internal.s.pDown)
680 {
681 AssertMsgFailed(("Cannot prepare a mount when something's attached to you!\n"));
682 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
683 }
684
685 /*
686 * We're asked to prepare, so we'll start off by nuking the
687 * attached configuration tree.
688 */
689 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
690 if (pNode)
691 CFGMR3RemoveNode(pNode);
692
693 /*
694 * If there is no core driver, we'll have to probe for it.
695 */
696 if (!pszCoreDriver)
697 {
698 /** @todo implement image probing. */
699 AssertReleaseMsgFailed(("Not implemented!\n"));
700 return VERR_NOT_IMPLEMENTED;
701 }
702
703 /*
704 * Construct the basic attached driver configuration.
705 */
706 int rc = CFGMR3InsertNode(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver", &pNode);
707 if (RT_SUCCESS(rc))
708 {
709 rc = CFGMR3InsertString(pNode, "Driver", pszCoreDriver);
710 if (RT_SUCCESS(rc))
711 {
712 PCFGMNODE pCfg;
713 rc = CFGMR3InsertNode(pNode, "Config", &pCfg);
714 if (RT_SUCCESS(rc))
715 {
716 rc = CFGMR3InsertString(pCfg, "Path", pszFilename);
717 if (RT_SUCCESS(rc))
718 {
719 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc (Driver=%s)\n",
720 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, pszCoreDriver));
721 return rc;
722 }
723 else
724 AssertMsgFailed(("Path string insert failed, rc=%Rrc\n", rc));
725 }
726 else
727 AssertMsgFailed(("Config node failed, rc=%Rrc\n", rc));
728 }
729 else
730 AssertMsgFailed(("Driver string insert failed, rc=%Rrc\n", rc));
731 CFGMR3RemoveNode(pNode);
732 }
733 else
734 AssertMsgFailed(("AttachedDriver node insert failed, rc=%Rrc\n", rc));
735
736 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc\n",
737 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
738 return rc;
739}
740
741
742/** @copydoc PDMDRVHLP::pfnAssertEMT */
743static DECLCALLBACK(bool) pdmR3DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
744{
745 PDMDRV_ASSERT_DRVINS(pDrvIns);
746 if (VM_IS_EMT(pDrvIns->Internal.s.pVM))
747 return true;
748
749 char szMsg[100];
750 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance);
751 AssertMsg1(szMsg, iLine, pszFile, pszFunction);
752 AssertBreakpoint();
753 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
754 return false;
755}
756
757
758/** @copydoc PDMDRVHLP::pfnAssertOther */
759static DECLCALLBACK(bool) pdmR3DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
760{
761 PDMDRV_ASSERT_DRVINS(pDrvIns);
762 if (!VM_IS_EMT(pDrvIns->Internal.s.pVM))
763 return true;
764
765 char szMsg[100];
766 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance);
767 AssertMsg1(szMsg, iLine, pszFile, pszFunction);
768 AssertBreakpoint();
769 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
770 return false;
771}
772
773
774/** @copydoc PDMDRVHLP::pfnVMSetError */
775static DECLCALLBACK(int) pdmR3DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
776{
777 PDMDRV_ASSERT_DRVINS(pDrvIns);
778 va_list args;
779 va_start(args, pszFormat);
780 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVM, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
781 va_end(args);
782 return rc;
783}
784
785
786/** @copydoc PDMDRVHLP::pfnVMSetErrorV */
787static DECLCALLBACK(int) pdmR3DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
788{
789 PDMDRV_ASSERT_DRVINS(pDrvIns);
790 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVM, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
791 return rc;
792}
793
794
795/** @copydoc PDMDRVHLP::pfnVMSetRuntimeError */
796static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
797{
798 PDMDRV_ASSERT_DRVINS(pDrvIns);
799 va_list args;
800 va_start(args, pszFormat);
801 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVM, fFlags, pszErrorId, pszFormat, args);
802 va_end(args);
803 return rc;
804}
805
806
807/** @copydoc PDMDRVHLP::pfnVMSetRuntimeErrorV */
808static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
809{
810 PDMDRV_ASSERT_DRVINS(pDrvIns);
811 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVM, fFlags, pszErrorId, pszFormat, va);
812 return rc;
813}
814
815
816/** @copydoc PDMDRVHLP::pfnPDMQueueCreate */
817static DECLCALLBACK(int) pdmR3DrvHlp_PDMQueueCreate(PPDMDRVINS pDrvIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
818 PFNPDMQUEUEDRV pfnCallback, const char *pszName, PPDMQUEUE *ppQueue)
819{
820 PDMDRV_ASSERT_DRVINS(pDrvIns);
821 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: cbItem=%d cItems=%d cMilliesInterval=%d pfnCallback=%p pszName=%p:{%s} ppQueue=%p\n",
822 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, pszName, ppQueue, ppQueue));
823 PVM pVM = pDrvIns->Internal.s.pVM;
824 VM_ASSERT_EMT(pVM);
825
826 if (pDrvIns->iInstance > 0)
827 {
828 pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DRIVER_DESC, "%s_%u", pszName, pDrvIns->iInstance);
829 AssertLogRelReturn(pszName, VERR_NO_MEMORY);
830 }
831
832 int rc = PDMR3QueueCreateDriver(pVM, pDrvIns, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, ppQueue);
833
834 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, *ppQueue));
835 return rc;
836}
837
838
839/** @copydoc PDMDRVHLP::pfnTMGetVirtualFreq */
840static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualFreq(PPDMDRVINS pDrvIns)
841{
842 PDMDRV_ASSERT_DRVINS(pDrvIns);
843
844 return TMVirtualGetFreq(pDrvIns->Internal.s.pVM);
845}
846
847
848/** @copydoc PDMDRVHLP::pfnTMGetVirtualTime */
849static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualTime(PPDMDRVINS pDrvIns)
850{
851 PDMDRV_ASSERT_DRVINS(pDrvIns);
852
853 return TMVirtualGet(pDrvIns->Internal.s.pVM);
854}
855
856
857/** @copydoc PDMDRVHLP::pfnTMTimerCreate */
858static DECLCALLBACK(int) pdmR3DrvHlp_TMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
859{
860 PDMDRV_ASSERT_DRVINS(pDrvIns);
861 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pvUser=%p fFlags=%#x pszDesc=%p:{%s} ppTimer=%p\n",
862 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, enmClock, pfnCallback, pvUser, fFlags, pszDesc, pszDesc, ppTimer));
863
864 int rc = TMR3TimerCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
865
866 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: returns %Rrc *ppTimer=%p\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, *ppTimer));
867 return rc;
868}
869
870
871
872/** @copydoc PDMDRVHLP::pfnSSMRegister */
873static DECLCALLBACK(int) pdmR3DrvHlp_SSMRegister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
874 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
875 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
876{
877 PDMDRV_ASSERT_DRVINS(pDrvIns);
878 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
879 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",
880 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszName, pszName, u32Instance, u32Version, cbGuess, pfnSavePrep, pfnSaveExec, pfnSaveDone, pfnLoadPrep, pfnLoadExec, pfnLoadDone));
881
882 int rc = SSMR3RegisterDriver(pDrvIns->Internal.s.pVM, pDrvIns, pszName, u32Instance, u32Version, cbGuess,
883 pfnSavePrep, pfnSaveExec, pfnSaveDone,
884 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
885
886 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
887 return rc;
888}
889
890
891/** @copydoc PDMDRVHLP::pfnSSMDeregister */
892static DECLCALLBACK(int) pdmR3DrvHlp_SSMDeregister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance)
893{
894 PDMDRV_ASSERT_DRVINS(pDrvIns);
895 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
896 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x\n",
897 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszName, pszName, u32Instance));
898
899 int rc = SSMR3DeregisterDriver(pDrvIns->Internal.s.pVM, pDrvIns, pszName, u32Instance);
900
901 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
902 return rc;
903}
904
905
906/** @copydoc PDMDRVHLP::pfnSTAMRegister */
907static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
908{
909 PDMDRV_ASSERT_DRVINS(pDrvIns);
910 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
911
912 STAM_REG(pDrvIns->Internal.s.pVM, pvSample, enmType, pszName, enmUnit, pszDesc);
913 /** @todo track the samples so they can be dumped & deregistered when the driver instance is destroyed.
914 * For now we just have to be careful not to use this call for drivers which can be unloaded. */
915}
916
917
918/** @copydoc PDMDRVHLP::pfnSTAMRegisterF */
919static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
920 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
921{
922 PDMDRV_ASSERT_DRVINS(pDrvIns);
923 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
924
925 va_list args;
926 va_start(args, pszName);
927 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
928 va_end(args);
929 AssertRC(rc);
930}
931
932
933/** @copydoc PDMDRVHLP::pfnSTAMRegisterV */
934static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
935 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
936{
937 PDMDRV_ASSERT_DRVINS(pDrvIns);
938 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
939
940 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
941 AssertRC(rc);
942}
943
944
945/** @copydoc PDMDRVHLP::pfnSTAMDeregister */
946static DECLCALLBACK(int) pdmR3DrvHlp_STAMDeregister(PPDMDRVINS pDrvIns, void *pvSample)
947{
948 PDMDRV_ASSERT_DRVINS(pDrvIns);
949 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
950
951 int rc = STAMR3DeregisterU(pDrvIns->Internal.s.pVM->pUVM, pvSample);
952 AssertRC(rc);
953 return rc;
954}
955
956
957/** @copydoc PDMDRVHLP::pfnSUPCallVMMR0Ex */
958static DECLCALLBACK(int) pdmR3DrvHlp_SUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg)
959{
960 PDMDRV_ASSERT_DRVINS(pDrvIns);
961 LogFlow(("pdmR3DrvHlp_SSMCallVMMR0Ex: caller='%s'/%d: uOperation=%u pvArg=%p cbArg=%d\n",
962 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, uOperation, pvArg, cbArg));
963 int rc;
964 if ( uOperation >= VMMR0_DO_SRV_START
965 && uOperation < VMMR0_DO_SRV_END)
966 rc = SUPR3CallVMMR0Ex(pDrvIns->Internal.s.pVM->pVMR0, NIL_VMCPUID, uOperation, 0, (PSUPVMMR0REQHDR)pvArg);
967 else
968 {
969 AssertMsgFailed(("Invalid uOperation=%u\n", uOperation));
970 rc = VERR_INVALID_PARAMETER;
971 }
972
973 LogFlow(("pdmR3DrvHlp_SUPCallVMMR0Ex: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
974 return rc;
975}
976
977
978/** @copydoc PDMDRVHLP::pfnUSBRegisterHub */
979static DECLCALLBACK(int) pdmR3DrvHlp_USBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
980{
981 PDMDRV_ASSERT_DRVINS(pDrvIns);
982 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
983 LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: fVersions=%#x cPorts=%#x pUsbHubReg=%p ppUsbHubHlp=%p\n",
984 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp));
985
986#ifdef VBOX_WITH_USB
987 int rc = pdmR3UsbRegisterHub(pDrvIns->Internal.s.pVM, pDrvIns, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp);
988#else
989 int rc = VERR_NOT_SUPPORTED;
990#endif
991
992 LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: returns %Rrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
993 return rc;
994}
995
996
997/** @copydoc PDMDRVHLP::pfnPDMThreadCreate */
998static DECLCALLBACK(int) pdmR3DrvHlp_PDMThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
999 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
1000{
1001 PDMDRV_ASSERT_DRVINS(pDrvIns);
1002 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
1003 LogFlow(("pdmR3DrvHlp_PDMThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
1004 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
1005
1006 int rc = pdmR3ThreadCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
1007
1008 LogFlow(("pdmR3DrvHlp_PDMThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance,
1009 rc, *ppThread));
1010 return rc;
1011}
1012
1013
1014/** @copydoc PDMDEVHLPR3::pfnVMState */
1015static DECLCALLBACK(VMSTATE) pdmR3DrvHlp_VMState(PPDMDRVINS pDrvIns)
1016{
1017 PDMDRV_ASSERT_DRVINS(pDrvIns);
1018
1019 VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVM);
1020
1021 LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance,
1022 enmVMState, VMR3GetStateName(enmVMState)));
1023 return enmVMState;
1024}
1025
1026
1027#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1028/** @copydoc PDMDRVHLP::pfnPDMAsyncCompletionTemplateCreate */
1029static DECLCALLBACK(int) pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
1030 PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser,
1031 const char *pszDesc)
1032{
1033 PDMDRV_ASSERT_DRVINS(pDrvIns);
1034 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
1035 LogFlow(("pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate: caller='%s'/%d: ppTemplate=%p pfnCompleted=%p pszDesc=%p:{%s}\n",
1036 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, ppTemplate, pfnCompleted, pszDesc, pszDesc));
1037
1038 int rc = PDMR3AsyncCompletionTemplateCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, ppTemplate, pfnCompleted, pvTemplateUser, pszDesc);
1039
1040 LogFlow(("pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate: caller='%s'/%d: returns %Rrc *ppThread=%p\n", pDrvIns->pDrvReg->szDriverName,
1041 pDrvIns->iInstance, rc, *ppTemplate));
1042 return rc;
1043}
1044#endif
1045
1046
1047/**
1048 * The driver helper structure.
1049 */
1050const PDMDRVHLP g_pdmR3DrvHlp =
1051{
1052 PDM_DRVHLP_VERSION,
1053 pdmR3DrvHlp_Attach,
1054 pdmR3DrvHlp_Detach,
1055 pdmR3DrvHlp_DetachSelf,
1056 pdmR3DrvHlp_MountPrepare,
1057 pdmR3DrvHlp_AssertEMT,
1058 pdmR3DrvHlp_AssertOther,
1059 pdmR3DrvHlp_VMSetError,
1060 pdmR3DrvHlp_VMSetErrorV,
1061 pdmR3DrvHlp_VMSetRuntimeError,
1062 pdmR3DrvHlp_VMSetRuntimeErrorV,
1063 pdmR3DrvHlp_PDMQueueCreate,
1064 pdmR3DrvHlp_TMGetVirtualFreq,
1065 pdmR3DrvHlp_TMGetVirtualTime,
1066 pdmR3DrvHlp_TMTimerCreate,
1067 pdmR3DrvHlp_SSMRegister,
1068 pdmR3DrvHlp_SSMDeregister,
1069 pdmR3DrvHlp_STAMRegister,
1070 pdmR3DrvHlp_STAMRegisterF,
1071 pdmR3DrvHlp_STAMRegisterV,
1072 pdmR3DrvHlp_STAMDeregister,
1073 pdmR3DrvHlp_SUPCallVMMR0Ex,
1074 pdmR3DrvHlp_USBRegisterHub,
1075 pdmR3DrvHlp_PDMThreadCreate,
1076 pdmR3DrvHlp_VMState,
1077#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
1078 pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate,
1079#endif
1080 PDM_DRVHLP_VERSION /* u32TheEnd */
1081};
1082
1083/** @} */
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