VirtualBox

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

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

Hooked up the PDMThread stuff.

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