VirtualBox

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

Last change on this file since 24760 was 24744, checked in by vboxsync, 15 years ago

PDM: Async reset notification handling as well.

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