VirtualBox

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

Last change on this file since 37418 was 37418, checked in by vboxsync, 13 years ago

Fixed a uninitialized variable in a PDM driver method used by VBoxBFE to register its statically linked drivers. Renamed the method.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 57.4 KB
Line 
1/* $Id: PDMDriver.cpp 37418 2011-06-11 08:22:10Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, Driver parts.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
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
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_PDM_DRIVER
23#include "PDMInternal.h"
24#include <VBox/vmm/pdm.h>
25#include <VBox/vmm/mm.h>
26#include <VBox/vmm/cfgm.h>
27#include <VBox/vmm/vmm.h>
28#include <VBox/sup.h>
29#include <VBox/vmm/vm.h>
30#include <VBox/version.h>
31#include <VBox/err.h>
32
33#include <VBox/log.h>
34#include <iprt/assert.h>
35#include <iprt/asm.h>
36#include <iprt/ctype.h>
37#include <iprt/mem.h>
38#include <iprt/thread.h>
39#include <iprt/path.h>
40#include <iprt/string.h>
41
42
43/*******************************************************************************
44* Structures and Typedefs *
45*******************************************************************************/
46/**
47 * Internal callback structure pointer.
48 *
49 * The main purpose is to define the extra data we associate
50 * with PDMDRVREGCB so we can find the VM instance and so on.
51 */
52typedef struct PDMDRVREGCBINT
53{
54 /** The callback structure. */
55 PDMDRVREGCB Core;
56 /** A bit of padding. */
57 uint32_t u32[4];
58 /** VM Handle. */
59 PVM pVM;
60 /** Pointer to the configuration node the registrations should be
61 * associated with. Can be NULL. */
62 PCFGMNODE pCfgNode;
63} PDMDRVREGCBINT, *PPDMDRVREGCBINT;
64typedef const PDMDRVREGCBINT *PCPDMDRVREGCBINT;
65
66
67/*******************************************************************************
68* Internal Functions *
69*******************************************************************************/
70static DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pReg);
71static int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName);
72
73
74/**
75 * Register drivers in a statically linked environment.
76 *
77 * @returns VBox status code.
78 * @param pVM The VM to operate on.
79 * @param pfnCallback Driver registration callback
80 */
81VMMR3DECL(int) PDMR3DrvStaticRegistration(PVM pVM, FNPDMVBOXDRIVERSREGISTER pfnCallback)
82{
83 /*
84 * The registration callbacks.
85 */
86 PDMDRVREGCBINT RegCB;
87 RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
88 RegCB.Core.pfnRegister = pdmR3DrvRegister;
89 RegCB.pVM = pVM;
90 RegCB.pCfgNode = NULL;
91
92 int rc = pfnCallback(&RegCB.Core, VBOX_VERSION);
93 if (RT_FAILURE(rc))
94 AssertMsgFailed(("VBoxDriversRegister failed with rc=%Rrc\n"));
95
96 return rc;
97}
98
99
100/**
101 * This function will initialize the drivers for this VM instance.
102 *
103 * First of all this mean loading the builtin drivers and letting them
104 * register themselves. Beyond that any additional driver modules are
105 * loaded and called for registration.
106 *
107 * @returns VBox status code.
108 * @param pVM VM Handle.
109 */
110int pdmR3DrvInit(PVM pVM)
111{
112 LogFlow(("pdmR3DrvInit:\n"));
113
114 AssertRelease(!(RT_OFFSETOF(PDMDRVINS, achInstanceData) & 15));
115 PPDMDRVINS pDrvInsAssert; NOREF(pDrvInsAssert);
116 AssertCompile(sizeof(pDrvInsAssert->Internal.s) <= sizeof(pDrvInsAssert->Internal.padding));
117 AssertRelease(sizeof(pDrvInsAssert->Internal.s) <= sizeof(pDrvInsAssert->Internal.padding));
118
119 /*
120 * The registration callbacks.
121 */
122 PDMDRVREGCBINT RegCB;
123 RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
124 RegCB.Core.pfnRegister = pdmR3DrvRegister;
125 RegCB.pVM = pVM;
126 RegCB.pCfgNode = NULL;
127
128 /*
129 * Load the builtin module
130 */
131 PCFGMNODE pDriversNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM/Drivers");
132 bool fLoadBuiltin;
133 int rc = CFGMR3QueryBool(pDriversNode, "LoadBuiltin", &fLoadBuiltin);
134 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
135 fLoadBuiltin = true;
136 else if (RT_FAILURE(rc))
137 {
138 AssertMsgFailed(("Configuration error: Querying boolean \"LoadBuiltin\" failed with %Rrc\n", rc));
139 return rc;
140 }
141 if (fLoadBuiltin)
142 {
143 /* make filename */
144 char *pszFilename = pdmR3FileR3("VBoxDD", true /*fShared*/);
145 if (!pszFilename)
146 return VERR_NO_TMP_MEMORY;
147 rc = pdmR3DrvLoad(pVM, &RegCB, pszFilename, "VBoxDD");
148 RTMemTmpFree(pszFilename);
149 if (RT_FAILURE(rc))
150 return rc;
151 }
152
153 /*
154 * Load additional driver modules.
155 */
156 for (PCFGMNODE pCur = CFGMR3GetFirstChild(pDriversNode); pCur; pCur = CFGMR3GetNextChild(pCur))
157 {
158 /*
159 * Get the name and path.
160 */
161 char szName[PDMMOD_NAME_LEN];
162 rc = CFGMR3GetName(pCur, &szName[0], sizeof(szName));
163 if (rc == VERR_CFGM_NOT_ENOUGH_SPACE)
164 {
165 AssertMsgFailed(("configuration error: The module name is too long, cchName=%zu.\n", CFGMR3GetNameLen(pCur)));
166 return VERR_PDM_MODULE_NAME_TOO_LONG;
167 }
168 else if (RT_FAILURE(rc))
169 {
170 AssertMsgFailed(("CFGMR3GetName -> %Rrc.\n", rc));
171 return rc;
172 }
173
174 /* the path is optional, if no path the module name + path is used. */
175 char szFilename[RTPATH_MAX];
176 rc = CFGMR3QueryString(pCur, "Path", &szFilename[0], sizeof(szFilename));
177 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
178 strcpy(szFilename, szName);
179 else if (RT_FAILURE(rc))
180 {
181 AssertMsgFailed(("configuration error: Failure to query the module path, rc=%Rrc.\n", rc));
182 return rc;
183 }
184
185 /* prepend path? */
186 if (!RTPathHavePath(szFilename))
187 {
188 char *psz = pdmR3FileR3(szFilename, false /*fShared*/);
189 if (!psz)
190 return VERR_NO_TMP_MEMORY;
191 size_t cch = strlen(psz) + 1;
192 if (cch > sizeof(szFilename))
193 {
194 RTMemTmpFree(psz);
195 AssertMsgFailed(("Filename too long! cch=%d '%s'\n", cch, psz));
196 return VERR_FILENAME_TOO_LONG;
197 }
198 memcpy(szFilename, psz, cch);
199 RTMemTmpFree(psz);
200 }
201
202 /*
203 * Load the module and register it's drivers.
204 */
205 RegCB.pCfgNode = pCur;
206 rc = pdmR3DrvLoad(pVM, &RegCB, szFilename, szName);
207 if (RT_FAILURE(rc))
208 return rc;
209 }
210
211 LogFlow(("pdmR3DrvInit: returns VINF_SUCCESS\n"));
212 return VINF_SUCCESS;
213}
214
215
216/**
217 * Loads one driver module and call the registration entry point.
218 *
219 * @returns VBox status code.
220 * @param pVM VM handle.
221 * @param pRegCB The registration callback stuff.
222 * @param pszFilename Module filename.
223 * @param pszName Module name.
224 */
225static int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName)
226{
227 /*
228 * Load it.
229 */
230 int rc = pdmR3LoadR3U(pVM->pUVM, pszFilename, pszName);
231 if (RT_SUCCESS(rc))
232 {
233 /*
234 * Get the registration export and call it.
235 */
236 FNPDMVBOXDRIVERSREGISTER *pfnVBoxDriversRegister;
237 rc = PDMR3LdrGetSymbolR3(pVM, pszName, "VBoxDriversRegister", (void **)&pfnVBoxDriversRegister);
238 if (RT_SUCCESS(rc))
239 {
240 Log(("PDM: Calling VBoxDriversRegister (%p) of %s (%s)\n", pfnVBoxDriversRegister, pszName, pszFilename));
241 rc = pfnVBoxDriversRegister(&pRegCB->Core, VBOX_VERSION);
242 if (RT_SUCCESS(rc))
243 Log(("PDM: Successfully loaded driver module %s (%s).\n", pszName, pszFilename));
244 else
245 AssertMsgFailed(("VBoxDriversRegister failed with rc=%Rrc\n"));
246 }
247 else
248 {
249 AssertMsgFailed(("Failed to locate 'VBoxDriversRegister' in %s (%s) rc=%Rrc\n", pszName, pszFilename, rc));
250 if (rc == VERR_SYMBOL_NOT_FOUND)
251 rc = VERR_PDM_NO_REGISTRATION_EXPORT;
252 }
253 }
254 else
255 AssertMsgFailed(("Failed to load %s (%s) rc=%Rrc!\n", pszName, pszFilename, rc));
256 return rc;
257}
258
259
260/** @interface_method_impl{PDMDRVREGCB,pfnRegister} */
261static DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pReg)
262{
263 /*
264 * Validate the registration structure.
265 */
266 AssertPtrReturn(pReg, VERR_INVALID_POINTER);
267 AssertMsgReturn(pReg->u32Version == PDM_DRVREG_VERSION,
268 ("%#x\n", pReg->u32Version),
269 VERR_PDM_UNKNOWN_DRVREG_VERSION);
270 AssertReturn(pReg->szName[0], VERR_PDM_INVALID_DRIVER_REGISTRATION);
271 AssertMsgReturn(RTStrEnd(pReg->szName, sizeof(pReg->szName)),
272 (".*s\n", sizeof(pReg->szName), pReg->szName),
273 VERR_PDM_INVALID_DRIVER_REGISTRATION);
274 AssertMsgReturn( !(pReg->fFlags & PDM_DRVREG_FLAGS_R0)
275 || ( pReg->szR0Mod[0]
276 && RTStrEnd(pReg->szR0Mod, sizeof(pReg->szR0Mod))),
277 ("%s: %.*s\n", pReg->szName, sizeof(pReg->szR0Mod), pReg->szR0Mod),
278 VERR_PDM_INVALID_DRIVER_REGISTRATION);
279 AssertMsgReturn( !(pReg->fFlags & PDM_DRVREG_FLAGS_RC)
280 || ( pReg->szRCMod[0]
281 && RTStrEnd(pReg->szRCMod, sizeof(pReg->szRCMod))),
282 ("%s: %.*s\n", pReg->szName, sizeof(pReg->szRCMod), pReg->szRCMod),
283 VERR_PDM_INVALID_DRIVER_REGISTRATION);
284 AssertMsgReturn(VALID_PTR(pReg->pszDescription),
285 ("%s: %p\n", pReg->szName, pReg->pszDescription),
286 VERR_PDM_INVALID_DRIVER_REGISTRATION);
287 AssertMsgReturn(!(pReg->fFlags & ~(PDM_DRVREG_FLAGS_HOST_BITS_MASK | PDM_DRVREG_FLAGS_R0 | PDM_DRVREG_FLAGS_RC)),
288 ("%s: %#x\n", pReg->szName, pReg->fFlags),
289 VERR_PDM_INVALID_DRIVER_REGISTRATION);
290 AssertMsgReturn((pReg->fFlags & PDM_DRVREG_FLAGS_HOST_BITS_MASK) == PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
291 ("%s: %#x\n", pReg->szName, pReg->fFlags),
292 VERR_PDM_INVALID_DRIVER_HOST_BITS);
293 AssertMsgReturn(pReg->cMaxInstances > 0,
294 ("%s: %#x\n", pReg->szName, pReg->cMaxInstances),
295 VERR_PDM_INVALID_DRIVER_REGISTRATION);
296 AssertMsgReturn(pReg->cbInstance <= _1M,
297 ("%s: %#x\n", pReg->szName, pReg->cbInstance),
298 VERR_PDM_INVALID_DRIVER_REGISTRATION);
299 AssertMsgReturn(VALID_PTR(pReg->pfnConstruct),
300 ("%s: %p\n", pReg->szName, pReg->pfnConstruct),
301 VERR_PDM_INVALID_DRIVER_REGISTRATION);
302 AssertMsgReturn(VALID_PTR(pReg->pfnRelocate) || !(pReg->fFlags & PDM_DRVREG_FLAGS_RC),
303 ("%s: %#x\n", pReg->szName, pReg->cbInstance),
304 VERR_PDM_INVALID_DRIVER_REGISTRATION);
305 AssertMsgReturn(pReg->pfnSoftReset == NULL,
306 ("%s: %p\n", pReg->szName, pReg->pfnSoftReset),
307 VERR_PDM_INVALID_DRIVER_REGISTRATION);
308 AssertMsgReturn(pReg->u32VersionEnd == PDM_DRVREG_VERSION,
309 ("%s: #x\n", pReg->szName, pReg->u32VersionEnd),
310 VERR_PDM_INVALID_DRIVER_REGISTRATION);
311
312 /*
313 * Check for duplicate and find FIFO entry at the same time.
314 */
315 PCPDMDRVREGCBINT pRegCB = (PCPDMDRVREGCBINT)pCallbacks;
316 PPDMDRV pDrvPrev = NULL;
317 PPDMDRV pDrv = pRegCB->pVM->pdm.s.pDrvs;
318 for (; pDrv; pDrvPrev = pDrv, pDrv = pDrv->pNext)
319 {
320 if (!strcmp(pDrv->pReg->szName, pReg->szName))
321 {
322 AssertMsgFailed(("Driver '%s' already exists\n", pReg->szName));
323 return VERR_PDM_DRIVER_NAME_CLASH;
324 }
325 }
326
327 /*
328 * Allocate new driver structure and insert it into the list.
329 */
330 int rc;
331 pDrv = (PPDMDRV)MMR3HeapAlloc(pRegCB->pVM, MM_TAG_PDM_DRIVER, sizeof(*pDrv));
332 if (pDrv)
333 {
334 pDrv->pNext = NULL;
335 pDrv->cInstances = 0;
336 pDrv->iNextInstance = 0;
337 pDrv->pReg = pReg;
338 rc = CFGMR3QueryStringAllocDef( pRegCB->pCfgNode, "RCSearchPath", &pDrv->pszRCSearchPath, NULL);
339 if (RT_SUCCESS(rc))
340 rc = CFGMR3QueryStringAllocDef(pRegCB->pCfgNode, "R0SearchPath", &pDrv->pszR0SearchPath, NULL);
341 if (RT_SUCCESS(rc))
342 {
343 if (pDrvPrev)
344 pDrvPrev->pNext = pDrv;
345 else
346 pRegCB->pVM->pdm.s.pDrvs = pDrv;
347 Log(("PDM: Registered driver '%s'\n", pReg->szName));
348 return VINF_SUCCESS;
349 }
350 MMR3HeapFree(pDrv);
351 }
352 else
353 rc = VERR_NO_MEMORY;
354 return rc;
355}
356
357
358/**
359 * Lookups a driver structure by name.
360 * @internal
361 */
362PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName)
363{
364 for (PPDMDRV pDrv = pVM->pdm.s.pDrvs; pDrv; pDrv = pDrv->pNext)
365 if (!strcmp(pDrv->pReg->szName, pszName))
366 return pDrv;
367 return NULL;
368}
369
370
371/**
372 * Instantiate a driver.
373 *
374 * @returns VBox status code, including informational statuses.
375 *
376 * @param pVM The VM handle.
377 * @param pNode The CFGM node for the driver.
378 * @param pBaseInterface The base interface.
379 * @param pDrvAbove The driver above it. NULL if it's the top-most
380 * driver.
381 * @param pLun The LUN the driver is being attached to. NULL
382 * if we're instantiating a driver chain before
383 * attaching it - untested.
384 * @param ppBaseInterface Where to return the pointer to the base
385 * interface of the newly created driver.
386 *
387 * @remarks Recursive calls to this function is normal as the drivers will
388 * attach to anything below them during the pfnContruct call.
389 */
390int pdmR3DrvInstantiate(PVM pVM, PCFGMNODE pNode, PPDMIBASE pBaseInterface, PPDMDRVINS pDrvAbove,
391 PPDMLUN pLun, PPDMIBASE *ppBaseInterface)
392{
393 Assert(!pDrvAbove || !pDrvAbove->Internal.s.pDown);
394 Assert(!pDrvAbove || !pDrvAbove->pDownBase);
395
396 Assert(pBaseInterface->pfnQueryInterface(pBaseInterface, PDMIBASE_IID) == pBaseInterface);
397
398 /*
399 * Find the driver.
400 */
401 char *pszName;
402 int rc = CFGMR3QueryStringAlloc(pNode, "Driver", &pszName);
403 if (RT_SUCCESS(rc))
404 {
405 PPDMDRV pDrv = pdmR3DrvLookup(pVM, pszName);
406 MMR3HeapFree(pszName);
407 if ( pDrv
408 && pDrv->cInstances < pDrv->pReg->cMaxInstances)
409 {
410 /* config node */
411 PCFGMNODE pConfigNode = CFGMR3GetChild(pNode, "Config");
412 if (!pConfigNode)
413 rc = CFGMR3InsertNode(pNode, "Config", &pConfigNode);
414 if (RT_SUCCESS(rc))
415 {
416 CFGMR3SetRestrictedRoot(pConfigNode);
417
418 /*
419 * Allocate the driver instance.
420 */
421 size_t cb = RT_OFFSETOF(PDMDRVINS, achInstanceData[pDrv->pReg->cbInstance]);
422 cb = RT_ALIGN_Z(cb, 16);
423 bool const fHyperHeap = !!(pDrv->pReg->fFlags & (PDM_DRVREG_FLAGS_R0 | PDM_DRVREG_FLAGS_RC));
424 PPDMDRVINS pNew;
425 if (fHyperHeap)
426 rc = MMHyperAlloc(pVM, cb, 64, MM_TAG_PDM_DRIVER, (void **)&pNew);
427 else
428 rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_DRIVER, cb, (void **)&pNew);
429 if (pNew)
430 {
431 /*
432 * Initialize the instance structure (declaration order).
433 */
434 pNew->u32Version = PDM_DRVINS_VERSION;
435 pNew->Internal.s.pUp = pDrvAbove ? pDrvAbove : NULL;
436 //pNew->Internal.s.pDown = NULL;
437 pNew->Internal.s.pLun = pLun;
438 pNew->Internal.s.pDrv = pDrv;
439 pNew->Internal.s.pVMR3 = pVM;
440 pNew->Internal.s.pVMR0 = pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_R0 ? pVM->pVMR0 : NIL_RTR0PTR;
441 pNew->Internal.s.pVMRC = pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_RC ? pVM->pVMRC : NIL_RTRCPTR;
442 //pNew->Internal.s.fDetaching = false;
443 pNew->Internal.s.fVMSuspended = true;
444 //pNew->Internal.s.fVMReset = false;
445 pNew->Internal.s.fHyperHeap = fHyperHeap;
446 //pNew->Internal.s.pfnAsyncNotify = NULL;
447 pNew->Internal.s.pCfgHandle = pNode;
448 pNew->pReg = pDrv->pReg;
449 pNew->pCfg = pConfigNode;
450 pNew->iInstance = pDrv->iNextInstance;
451 pNew->pUpBase = pBaseInterface;
452 Assert(!pDrvAbove || pBaseInterface == &pDrvAbove->IBase);
453 //pNew->pDownBase = NULL;
454 //pNew->IBase.pfnQueryInterface = NULL;
455 pNew->pHlpR3 = &g_pdmR3DrvHlp;
456 pNew->pvInstanceDataR3 = &pNew->achInstanceData[0];
457 if (pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
458 {
459 pNew->pvInstanceDataR0 = MMHyperR3ToR0(pVM, &pNew->achInstanceData[0]);
460 rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0DrvHlp", &pNew->pHlpR0);
461 AssertReleaseRCReturn(rc, rc);
462
463 }
464 if (pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
465 {
466 pNew->pvInstanceDataR0 = MMHyperR3ToRC(pVM, &pNew->achInstanceData[0]);
467 rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCDrvHlp", &pNew->pHlpRC);
468 AssertReleaseRCReturn(rc, rc);
469 }
470
471 pDrv->iNextInstance++;
472 pDrv->cInstances++;
473
474 /*
475 * Link with it with the driver above / LUN.
476 */
477 if (pDrvAbove)
478 {
479 pDrvAbove->pDownBase = &pNew->IBase;
480 pDrvAbove->Internal.s.pDown = pNew;
481 }
482 else if (pLun)
483 pLun->pTop = pNew;
484 if (pLun)
485 pLun->pBottom = pNew;
486
487 /*
488 * Invoke the constructor.
489 */
490 rc = pDrv->pReg->pfnConstruct(pNew, pNew->pCfg, 0 /*fFlags*/);
491 if (RT_SUCCESS(rc))
492 {
493 AssertPtr(pNew->IBase.pfnQueryInterface);
494 Assert(pNew->IBase.pfnQueryInterface(&pNew->IBase, PDMIBASE_IID) == &pNew->IBase);
495
496 /* Success! */
497 *ppBaseInterface = &pNew->IBase;
498 if (pLun)
499 Log(("PDM: Attached driver %p:'%s'/%d to LUN#%d on device '%s'/%d, pDrvAbove=%p:'%s'/%d\n",
500 pNew, pDrv->pReg->szName, pNew->iInstance,
501 pLun->iLun,
502 pLun->pDevIns ? pLun->pDevIns->pReg->szName : pLun->pUsbIns->pReg->szName,
503 pLun->pDevIns ? pLun->pDevIns->iInstance : pLun->pUsbIns->iInstance,
504 pDrvAbove, pDrvAbove ? pDrvAbove->pReg->szName : "", pDrvAbove ? pDrvAbove->iInstance : UINT32_MAX));
505 else
506 Log(("PDM: Attached driver %p:'%s'/%d, pDrvAbove=%p:'%s'/%d\n",
507 pNew, pDrv->pReg->szName, pNew->iInstance,
508 pDrvAbove, pDrvAbove ? pDrvAbove->pReg->szName : "", pDrvAbove ? pDrvAbove->iInstance : UINT32_MAX));
509 }
510 else
511 {
512 pdmR3DrvDestroyChain(pNew, PDM_TACH_FLAGS_NO_CALLBACKS);
513 if (rc == VERR_VERSION_MISMATCH)
514 rc = VERR_PDM_DRIVER_VERSION_MISMATCH;
515 }
516 }
517 else
518 {
519 AssertMsgFailed(("Failed to allocate %d bytes for instantiating driver '%s'\n", cb, pszName));
520 rc = VERR_NO_MEMORY;
521 }
522 }
523 else
524 AssertMsgFailed(("Failed to create Config node! rc=%Rrc\n", rc));
525 }
526 else if (pDrv)
527 {
528 AssertMsgFailed(("Too many instances of driver '%s', max is %u\n", pszName, pDrv->pReg->cMaxInstances));
529 rc = VERR_PDM_TOO_MANY_DRIVER_INSTANCES;
530 }
531 else
532 {
533 AssertMsgFailed(("Driver '%s' wasn't found!\n", pszName));
534 rc = VERR_PDM_DRIVER_NOT_FOUND;
535 }
536 }
537 else
538 {
539 AssertMsgFailed(("Query for string value of \"Driver\" -> %Rrc\n", rc));
540 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
541 rc = VERR_PDM_CFG_MISSING_DRIVER_NAME;
542 }
543 return rc;
544}
545
546
547/**
548 * Detaches a driver from whatever it's attached to.
549 * This will of course lead to the destruction of the driver and all drivers below it in the chain.
550 *
551 * @returns VINF_SUCCESS
552 * @param pDrvIns The driver instance to detach.
553 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
554 */
555int pdmR3DrvDetach(PPDMDRVINS pDrvIns, uint32_t fFlags)
556{
557 PDMDRV_ASSERT_DRVINS(pDrvIns);
558 LogFlow(("pdmR3DrvDetach: pDrvIns=%p '%s'/%d\n", pDrvIns, pDrvIns->pReg->szName, pDrvIns->iInstance));
559 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
560
561 /*
562 * Check that we're not doing this recursively, that could have unwanted sideeffects!
563 */
564 if (pDrvIns->Internal.s.fDetaching)
565 {
566 AssertMsgFailed(("Recursive detach! '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance));
567 return VINF_SUCCESS; }
568
569 /*
570 * Check that we actually can detach this instance.
571 * The requirement is that the driver/device above has a detach method.
572 */
573 if (pDrvIns->Internal.s.pUp
574 ? !pDrvIns->Internal.s.pUp->pReg->pfnDetach
575 : !pDrvIns->Internal.s.pLun->pDevIns->pReg->pfnDetach)
576 {
577 AssertMsgFailed(("Cannot detach driver instance because the driver/device above doesn't support it!\n"));
578 return VERR_PDM_DRIVER_DETACH_NOT_POSSIBLE;
579 }
580
581 /*
582 * Join paths with pdmR3DrvDestroyChain.
583 */
584 pdmR3DrvDestroyChain(pDrvIns, fFlags);
585 return VINF_SUCCESS;
586}
587
588
589/**
590 * Destroys a driver chain starting with the specified driver.
591 *
592 * This is used when unplugging a device at run time.
593 *
594 * @param pDrvIns Pointer to the driver instance to start with.
595 * @param fFlags PDM_TACH_FLAGS_NOT_HOT_PLUG, PDM_TACH_FLAGS_NO_CALLBACKS
596 * or 0.
597 */
598void pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns, uint32_t fFlags)
599{
600 PVM pVM = pDrvIns->Internal.s.pVMR3;
601 VM_ASSERT_EMT(pVM);
602
603 /*
604 * Detach the bottommost driver until we've detached pDrvIns.
605 */
606 pDrvIns->Internal.s.fDetaching = true;
607 PPDMDRVINS pCur;
608 do
609 {
610 /* find the driver to detach. */
611 pCur = pDrvIns;
612 while (pCur->Internal.s.pDown)
613 pCur = pCur->Internal.s.pDown;
614 LogFlow(("pdmR3DrvDestroyChain: pCur=%p '%s'/%d\n", pCur, pCur->pReg->szName, pCur->iInstance));
615
616 /*
617 * Unlink it and notify parent.
618 */
619 pCur->Internal.s.fDetaching = true;
620
621 PPDMLUN pLun = pCur->Internal.s.pLun;
622 Assert(pLun->pBottom == pCur);
623 pLun->pBottom = pCur->Internal.s.pUp;
624
625 if (pCur->Internal.s.pUp)
626 {
627 /* driver parent */
628 PPDMDRVINS pParent = pCur->Internal.s.pUp;
629 pCur->Internal.s.pUp = NULL;
630 pParent->Internal.s.pDown = NULL;
631
632 if (!(fFlags & PDM_TACH_FLAGS_NO_CALLBACKS) && pParent->pReg->pfnDetach)
633 pParent->pReg->pfnDetach(pParent, fFlags);
634
635 pParent->pDownBase = NULL;
636 }
637 else
638 {
639 /* device parent */
640 Assert(pLun->pTop == pCur);
641 pLun->pTop = NULL;
642 if (!(fFlags & PDM_TACH_FLAGS_NO_CALLBACKS) && pLun->pDevIns->pReg->pfnDetach)
643 pLun->pDevIns->pReg->pfnDetach(pLun->pDevIns, pLun->iLun, fFlags);
644 }
645
646 /*
647 * Call destructor.
648 */
649 pCur->pUpBase = NULL;
650 if (pCur->pReg->pfnDestruct)
651 pCur->pReg->pfnDestruct(pCur);
652 pCur->Internal.s.pDrv->cInstances--;
653
654 /*
655 * Free all resources allocated by the driver.
656 */
657 /* Queues. */
658 int rc = PDMR3QueueDestroyDriver(pVM, pCur);
659 AssertRC(rc);
660
661 /* Timers. */
662 rc = TMR3TimerDestroyDriver(pVM, pCur);
663 AssertRC(rc);
664
665 /* SSM data units. */
666 rc = SSMR3DeregisterDriver(pVM, pCur, NULL, 0);
667 AssertRC(rc);
668
669 /* PDM threads. */
670 rc = pdmR3ThreadDestroyDriver(pVM, pCur);
671 AssertRC(rc);
672
673 /* Info handlers. */
674 rc = DBGFR3InfoDeregisterDriver(pVM, pCur, NULL);
675 AssertRC(rc);
676
677 /* PDM critsects. */
678 rc = pdmR3CritSectDeleteDriver(pVM, pCur);
679 AssertRC(rc);
680
681 /* Block caches. */
682 PDMR3BlkCacheReleaseDriver(pVM, pCur);
683
684 /* Finally, the driver it self. */
685 bool fHyperHeap = pCur->Internal.s.fHyperHeap;
686 ASMMemFill32(pCur, RT_OFFSETOF(PDMDRVINS, achInstanceData[pCur->pReg->cbInstance]), 0xdeadd0d0);
687 if (fHyperHeap)
688 MMHyperFree(pVM, pCur);
689 else
690 MMR3HeapFree(pCur);
691
692 } while (pCur != pDrvIns);
693}
694
695
696
697
698/** @name Driver Helpers
699 * @{
700 */
701
702/** @interface_method_impl{PDMDRVHLP,pfnAttach} */
703static DECLCALLBACK(int) pdmR3DrvHlp_Attach(PPDMDRVINS pDrvIns, uint32_t fFlags, PPDMIBASE *ppBaseInterface)
704{
705 PDMDRV_ASSERT_DRVINS(pDrvIns);
706 PVM pVM = pDrvIns->Internal.s.pVMR3;
707 VM_ASSERT_EMT(pVM);
708 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: fFlags=%#x\n", pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
709 Assert(!(fFlags & ~(PDM_TACH_FLAGS_NOT_HOT_PLUG)));
710
711 /*
712 * Check that there isn't anything attached already.
713 */
714 int rc;
715 if (!pDrvIns->Internal.s.pDown)
716 {
717 Assert(pDrvIns->Internal.s.pLun->pBottom == pDrvIns);
718
719 /*
720 * Get the attached driver configuration.
721 */
722 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
723 if (pNode)
724 rc = pdmR3DrvInstantiate(pVM, pNode, &pDrvIns->IBase, pDrvIns, pDrvIns->Internal.s.pLun, ppBaseInterface);
725 else
726 rc = VERR_PDM_NO_ATTACHED_DRIVER;
727 }
728 else
729 {
730 AssertMsgFailed(("Already got a driver attached. The driver should keep track of such things!\n"));
731 rc = VERR_PDM_DRIVER_ALREADY_ATTACHED;
732 }
733
734 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: return %Rrc\n",
735 pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
736 return rc;
737}
738
739
740/** @interface_method_impl{PDMDRVHLP,pfnDetach} */
741static DECLCALLBACK(int) pdmR3DrvHlp_Detach(PPDMDRVINS pDrvIns, uint32_t fFlags)
742{
743 PDMDRV_ASSERT_DRVINS(pDrvIns);
744 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: fFlags=%#x\n",
745 pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
746 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
747
748 /*
749 * Anything attached?
750 */
751 int rc;
752 if (pDrvIns->Internal.s.pDown)
753 rc = pdmR3DrvDetach(pDrvIns->Internal.s.pDown, fFlags);
754 else
755 {
756 AssertMsgFailed(("Nothing attached!\n"));
757 rc = VERR_PDM_NO_DRIVER_ATTACHED;
758 }
759
760 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: returns %Rrc\n",
761 pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
762 return rc;
763}
764
765
766/** @interface_method_impl{PDMDRVHLP,pfnDetachSelf} */
767static DECLCALLBACK(int) pdmR3DrvHlp_DetachSelf(PPDMDRVINS pDrvIns, uint32_t fFlags)
768{
769 PDMDRV_ASSERT_DRVINS(pDrvIns);
770 LogFlow(("pdmR3DrvHlp_DetachSelf: caller='%s'/%d: fFlags=%#x\n",
771 pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
772 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
773
774 int rc = pdmR3DrvDetach(pDrvIns, fFlags);
775
776 LogFlow(("pdmR3DrvHlp_Detach: returns %Rrc\n", rc)); /* pDrvIns is freed by now. */
777 return rc;
778}
779
780
781/** @interface_method_impl{PDMDRVHLP,pfnMountPrepare} */
782static DECLCALLBACK(int) pdmR3DrvHlp_MountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver)
783{
784 PDMDRV_ASSERT_DRVINS(pDrvIns);
785 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: pszFilename=%p:{%s} pszCoreDriver=%p:{%s}\n",
786 pDrvIns->pReg->szName, pDrvIns->iInstance, pszFilename, pszFilename, pszCoreDriver, pszCoreDriver));
787 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
788
789 /*
790 * Do the caller have anything attached below itself?
791 */
792 if (pDrvIns->Internal.s.pDown)
793 {
794 AssertMsgFailed(("Cannot prepare a mount when something's attached to you!\n"));
795 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
796 }
797
798 /*
799 * We're asked to prepare, so we'll start off by nuking the
800 * attached configuration tree.
801 */
802 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
803 if (pNode)
804 CFGMR3RemoveNode(pNode);
805
806 /*
807 * If there is no core driver, we'll have to probe for it.
808 */
809 if (!pszCoreDriver)
810 {
811 /** @todo implement image probing. */
812 AssertReleaseMsgFailed(("Not implemented!\n"));
813 return VERR_NOT_IMPLEMENTED;
814 }
815
816 /*
817 * Construct the basic attached driver configuration.
818 */
819 int rc = CFGMR3InsertNode(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver", &pNode);
820 if (RT_SUCCESS(rc))
821 {
822 rc = CFGMR3InsertString(pNode, "Driver", pszCoreDriver);
823 if (RT_SUCCESS(rc))
824 {
825 PCFGMNODE pCfg;
826 rc = CFGMR3InsertNode(pNode, "Config", &pCfg);
827 if (RT_SUCCESS(rc))
828 {
829 rc = CFGMR3InsertString(pCfg, "Path", pszFilename);
830 if (RT_SUCCESS(rc))
831 {
832 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc (Driver=%s)\n",
833 pDrvIns->pReg->szName, pDrvIns->iInstance, rc, pszCoreDriver));
834 return rc;
835 }
836 else
837 AssertMsgFailed(("Path string insert failed, rc=%Rrc\n", rc));
838 }
839 else
840 AssertMsgFailed(("Config node failed, rc=%Rrc\n", rc));
841 }
842 else
843 AssertMsgFailed(("Driver string insert failed, rc=%Rrc\n", rc));
844 CFGMR3RemoveNode(pNode);
845 }
846 else
847 AssertMsgFailed(("AttachedDriver node insert failed, rc=%Rrc\n", rc));
848
849 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc\n",
850 pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
851 return rc;
852}
853
854
855/** @interface_method_impl{PDMDRVHLP,pfnAssertEMT} */
856static DECLCALLBACK(bool) pdmR3DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
857{
858 PDMDRV_ASSERT_DRVINS(pDrvIns);
859 if (VM_IS_EMT(pDrvIns->Internal.s.pVMR3))
860 return true;
861
862 char szMsg[100];
863 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance);
864 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
865 AssertBreakpoint();
866 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
867 return false;
868}
869
870
871/** @interface_method_impl{PDMDRVHLP,pfnAssertOther} */
872static DECLCALLBACK(bool) pdmR3DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
873{
874 PDMDRV_ASSERT_DRVINS(pDrvIns);
875 if (!VM_IS_EMT(pDrvIns->Internal.s.pVMR3))
876 return true;
877
878 char szMsg[100];
879 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance);
880 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
881 AssertBreakpoint();
882 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
883 return false;
884}
885
886
887/** @interface_method_impl{PDMDRVHLP,pfnVMSetError} */
888static DECLCALLBACK(int) pdmR3DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
889{
890 PDMDRV_ASSERT_DRVINS(pDrvIns);
891 va_list args;
892 va_start(args, pszFormat);
893 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
894 va_end(args);
895 return rc;
896}
897
898
899/** @interface_method_impl{PDMDRVHLP,pfnVMSetErrorV} */
900static DECLCALLBACK(int) pdmR3DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
901{
902 PDMDRV_ASSERT_DRVINS(pDrvIns);
903 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
904 return rc;
905}
906
907
908/** @interface_method_impl{PDMDRVHLP,pfnVMSetRuntimeError} */
909static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
910{
911 PDMDRV_ASSERT_DRVINS(pDrvIns);
912 va_list args;
913 va_start(args, pszFormat);
914 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, args);
915 va_end(args);
916 return rc;
917}
918
919
920/** @interface_method_impl{PDMDRVHLP,pfnVMSetRuntimeErrorV} */
921static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
922{
923 PDMDRV_ASSERT_DRVINS(pDrvIns);
924 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, va);
925 return rc;
926}
927
928
929/** @interface_method_impl{PDMDEVHLPR3,pfnVMState} */
930static DECLCALLBACK(VMSTATE) pdmR3DrvHlp_VMState(PPDMDRVINS pDrvIns)
931{
932 PDMDRV_ASSERT_DRVINS(pDrvIns);
933
934 VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVMR3);
935
936 LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
937 enmVMState, VMR3GetStateName(enmVMState)));
938 return enmVMState;
939}
940
941
942/** @interface_method_impl{PDMDEVHLPR3,pfnVMTeleportedAndNotFullyResumedYet} */
943static DECLCALLBACK(bool) pdmR3DrvHlp_VMTeleportedAndNotFullyResumedYet(PPDMDRVINS pDrvIns)
944{
945 PDMDRV_ASSERT_DRVINS(pDrvIns);
946
947 bool fRc = VMR3TeleportedAndNotFullyResumedYet(pDrvIns->Internal.s.pVMR3);
948
949 LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %RTbool)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
950 fRc));
951 return fRc;
952}
953
954
955/** @interface_method_impl{PDMDEVHLPR3,pfnGetSupDrvSession} */
956static DECLCALLBACK(PSUPDRVSESSION) pdmR3DrvHlp_GetSupDrvSession(PPDMDRVINS pDrvIns)
957{
958 PDMDRV_ASSERT_DRVINS(pDrvIns);
959
960 PSUPDRVSESSION pSession = pDrvIns->Internal.s.pVMR3->pSession;
961 LogFlow(("pdmR3DrvHlp_GetSupDrvSession: caller='%s'/%d: returns %p)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
962 pSession));
963 return pSession;
964}
965
966
967/** @interface_method_impl{PDMDRVHLP,pfnQueueCreate} */
968static DECLCALLBACK(int) pdmR3DrvHlp_QueueCreate(PPDMDRVINS pDrvIns, uint32_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
969 PFNPDMQUEUEDRV pfnCallback, const char *pszName, PPDMQUEUE *ppQueue)
970{
971 PDMDRV_ASSERT_DRVINS(pDrvIns);
972 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: cbItem=%d cItems=%d cMilliesInterval=%d pfnCallback=%p pszName=%p:{%s} ppQueue=%p\n",
973 pDrvIns->pReg->szName, pDrvIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, pszName, ppQueue, ppQueue));
974 PVM pVM = pDrvIns->Internal.s.pVMR3;
975 VM_ASSERT_EMT(pVM);
976
977 if (pDrvIns->iInstance > 0)
978 {
979 pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DRIVER_DESC, "%s_%u", pszName, pDrvIns->iInstance);
980 AssertLogRelReturn(pszName, VERR_NO_MEMORY);
981 }
982
983 int rc = PDMR3QueueCreateDriver(pVM, pDrvIns, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, ppQueue);
984
985 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc, *ppQueue));
986 return rc;
987}
988
989
990/** @interface_method_impl{PDMDRVHLP,pfnTMGetVirtualFreq} */
991static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualFreq(PPDMDRVINS pDrvIns)
992{
993 PDMDRV_ASSERT_DRVINS(pDrvIns);
994
995 return TMVirtualGetFreq(pDrvIns->Internal.s.pVMR3);
996}
997
998
999/** @interface_method_impl{PDMDRVHLP,pfnTMGetVirtualTime} */
1000static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualTime(PPDMDRVINS pDrvIns)
1001{
1002 PDMDRV_ASSERT_DRVINS(pDrvIns);
1003
1004 return TMVirtualGet(pDrvIns->Internal.s.pVMR3);
1005}
1006
1007
1008/** @interface_method_impl{PDMDRVHLP,pfnTMTimerCreate} */
1009static DECLCALLBACK(int) pdmR3DrvHlp_TMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
1010{
1011 PDMDRV_ASSERT_DRVINS(pDrvIns);
1012 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pvUser=%p fFlags=%#x pszDesc=%p:{%s} ppTimer=%p\n",
1013 pDrvIns->pReg->szName, pDrvIns->iInstance, enmClock, pfnCallback, pvUser, fFlags, pszDesc, pszDesc, ppTimer));
1014
1015 int rc = TMR3TimerCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
1016
1017 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: returns %Rrc *ppTimer=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc, *ppTimer));
1018 return rc;
1019}
1020
1021
1022
1023/** @interface_method_impl{PDMDRVHLP,pfnSSMRegister} */
1024static DECLCALLBACK(int) pdmR3DrvHlp_SSMRegister(PPDMDRVINS pDrvIns, uint32_t uVersion, size_t cbGuess,
1025 PFNSSMDRVLIVEPREP pfnLivePrep, PFNSSMDRVLIVEEXEC pfnLiveExec, PFNSSMDRVLIVEVOTE pfnLiveVote,
1026 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
1027 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
1028{
1029 PDMDRV_ASSERT_DRVINS(pDrvIns);
1030 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1031 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: uVersion=#x cbGuess=%#x \n"
1032 " pfnLivePrep=%p pfnLiveExec=%p pfnLiveVote=%p pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoaddone=%p\n",
1033 pDrvIns->pReg->szName, pDrvIns->iInstance, uVersion, cbGuess,
1034 pfnLivePrep, pfnLiveExec, pfnLiveVote,
1035 pfnSavePrep, pfnSaveExec, pfnSaveDone, pfnLoadPrep, pfnLoadExec, pfnLoadDone));
1036
1037 int rc = SSMR3RegisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pDrvIns->pReg->szName, pDrvIns->iInstance,
1038 uVersion, cbGuess,
1039 pfnLivePrep, pfnLiveExec, pfnLiveVote,
1040 pfnSavePrep, pfnSaveExec, pfnSaveDone,
1041 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
1042
1043 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1044 return rc;
1045}
1046
1047
1048/** @interface_method_impl{PDMDRVHLP,pfnSSMDeregister} */
1049static DECLCALLBACK(int) pdmR3DrvHlp_SSMDeregister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance)
1050{
1051 PDMDRV_ASSERT_DRVINS(pDrvIns);
1052 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1053 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x\n",
1054 pDrvIns->pReg->szName, pDrvIns->iInstance, pszName, pszName, u32Instance));
1055
1056 int rc = SSMR3DeregisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pszName, u32Instance);
1057
1058 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1059 return rc;
1060}
1061
1062
1063/** @interface_method_impl{PDMDEVHLP,pfnDBGFInfoRegister} */
1064static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoRegister(PPDMDRVINS pDrvIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler)
1065{
1066 PDMDRV_ASSERT_DRVINS(pDrvIns);
1067 LogFlow(("pdmR3DrvHlp_DBGFInfoRegister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
1068 pDrvIns->pReg->szName, pDrvIns->iInstance, pszName, pszName, pszDesc, pszDesc, pfnHandler));
1069
1070 int rc = DBGFR3InfoRegisterDriver(pDrvIns->Internal.s.pVMR3, pszName, pszDesc, pfnHandler, pDrvIns);
1071
1072 LogFlow(("pdmR3DrvHlp_DBGFInfoRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1073 return rc;
1074}
1075
1076
1077/** @interface_method_impl{PDMDEVHLP,pfnDBGFInfoDeregister} */
1078static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoDeregister(PPDMDRVINS pDrvIns, const char *pszName)
1079{
1080 PDMDRV_ASSERT_DRVINS(pDrvIns);
1081 LogFlow(("pdmR3DrvHlp_DBGFInfoDeregister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
1082 pDrvIns->pReg->szName, pDrvIns->iInstance, pszName));
1083
1084 int rc = DBGFR3InfoDeregisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pszName);
1085
1086 LogFlow(("pdmR3DrvHlp_DBGFInfoDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1087
1088 return rc;
1089}
1090
1091
1092/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegister} */
1093static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
1094{
1095 PDMDRV_ASSERT_DRVINS(pDrvIns);
1096 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1097
1098 STAM_REG(pDrvIns->Internal.s.pVMR3, pvSample, enmType, pszName, enmUnit, pszDesc);
1099 /** @todo track the samples so they can be dumped & deregistered when the driver instance is destroyed.
1100 * For now we just have to be careful not to use this call for drivers which can be unloaded. */
1101}
1102
1103
1104/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegisterF} */
1105static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1106 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
1107{
1108 PDMDRV_ASSERT_DRVINS(pDrvIns);
1109 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1110
1111 va_list args;
1112 va_start(args, pszName);
1113 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1114 va_end(args);
1115 AssertRC(rc);
1116}
1117
1118
1119/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegisterV} */
1120static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1121 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
1122{
1123 PDMDRV_ASSERT_DRVINS(pDrvIns);
1124 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1125
1126 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1127 AssertRC(rc);
1128}
1129
1130
1131/** @interface_method_impl{PDMDRVHLP,pfnSTAMDeregister} */
1132static DECLCALLBACK(int) pdmR3DrvHlp_STAMDeregister(PPDMDRVINS pDrvIns, void *pvSample)
1133{
1134 PDMDRV_ASSERT_DRVINS(pDrvIns);
1135 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1136
1137 int rc = STAMR3DeregisterU(pDrvIns->Internal.s.pVMR3->pUVM, pvSample);
1138 AssertRC(rc);
1139 return rc;
1140}
1141
1142
1143/** @interface_method_impl{PDMDRVHLP,pfnSUPCallVMMR0Ex} */
1144static DECLCALLBACK(int) pdmR3DrvHlp_SUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg)
1145{
1146 PDMDRV_ASSERT_DRVINS(pDrvIns);
1147 LogFlow(("pdmR3DrvHlp_SSMCallVMMR0Ex: caller='%s'/%d: uOperation=%u pvArg=%p cbArg=%d\n",
1148 pDrvIns->pReg->szName, pDrvIns->iInstance, uOperation, pvArg, cbArg));
1149 int rc;
1150 if ( uOperation >= VMMR0_DO_SRV_START
1151 && uOperation < VMMR0_DO_SRV_END)
1152 rc = SUPR3CallVMMR0Ex(pDrvIns->Internal.s.pVMR3->pVMR0, NIL_VMCPUID, uOperation, 0, (PSUPVMMR0REQHDR)pvArg);
1153 else
1154 {
1155 AssertMsgFailed(("Invalid uOperation=%u\n", uOperation));
1156 rc = VERR_INVALID_PARAMETER;
1157 }
1158
1159 LogFlow(("pdmR3DrvHlp_SUPCallVMMR0Ex: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1160 return rc;
1161}
1162
1163
1164/** @interface_method_impl{PDMDRVHLP,pfnUSBRegisterHub} */
1165static DECLCALLBACK(int) pdmR3DrvHlp_USBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
1166{
1167 PDMDRV_ASSERT_DRVINS(pDrvIns);
1168 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1169 LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: fVersions=%#x cPorts=%#x pUsbHubReg=%p ppUsbHubHlp=%p\n",
1170 pDrvIns->pReg->szName, pDrvIns->iInstance, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp));
1171
1172#ifdef VBOX_WITH_USB
1173 int rc = pdmR3UsbRegisterHub(pDrvIns->Internal.s.pVMR3, pDrvIns, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp);
1174#else
1175 int rc = VERR_NOT_SUPPORTED;
1176#endif
1177
1178 LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1179 return rc;
1180}
1181
1182
1183/** @interface_method_impl{PDMDRVHLP,pfnSetAsyncNotification} */
1184static DECLCALLBACK(int) pdmR3DrvHlp_SetAsyncNotification(PPDMDRVINS pDrvIns, PFNPDMDRVASYNCNOTIFY pfnAsyncNotify)
1185{
1186 PDMDRV_ASSERT_DRVINS(pDrvIns);
1187 VM_ASSERT_EMT0(pDrvIns->Internal.s.pVMR3);
1188 LogFlow(("pdmR3DrvHlp_SetAsyncNotification: caller='%s'/%d: pfnAsyncNotify=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, pfnAsyncNotify));
1189
1190 int rc = VINF_SUCCESS;
1191 AssertStmt(pfnAsyncNotify, rc = VERR_INVALID_PARAMETER);
1192 AssertStmt(!pDrvIns->Internal.s.pfnAsyncNotify, rc = VERR_WRONG_ORDER);
1193 AssertStmt(pDrvIns->Internal.s.fVMSuspended || pDrvIns->Internal.s.fVMReset, rc = VERR_WRONG_ORDER);
1194 VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVMR3);
1195 AssertStmt( enmVMState == VMSTATE_SUSPENDING
1196 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1197 || enmVMState == VMSTATE_SUSPENDING_LS
1198 || enmVMState == VMSTATE_RESETTING
1199 || enmVMState == VMSTATE_RESETTING_LS
1200 || enmVMState == VMSTATE_POWERING_OFF
1201 || enmVMState == VMSTATE_POWERING_OFF_LS,
1202 rc = VERR_INVALID_STATE);
1203
1204 if (RT_SUCCESS(rc))
1205 pDrvIns->Internal.s.pfnAsyncNotify = pfnAsyncNotify;
1206
1207 LogFlow(("pdmR3DrvHlp_SetAsyncNotification: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1208 return rc;
1209}
1210
1211
1212/** @interface_method_impl{PDMDRVHLP,pfnAsyncNotificationCompleted} */
1213static DECLCALLBACK(void) pdmR3DrvHlp_AsyncNotificationCompleted(PPDMDRVINS pDrvIns)
1214{
1215 PDMDRV_ASSERT_DRVINS(pDrvIns);
1216 PVM pVM = pDrvIns->Internal.s.pVMR3;
1217
1218 VMSTATE enmVMState = VMR3GetState(pVM);
1219 if ( enmVMState == VMSTATE_SUSPENDING
1220 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1221 || enmVMState == VMSTATE_SUSPENDING_LS
1222 || enmVMState == VMSTATE_RESETTING
1223 || enmVMState == VMSTATE_RESETTING_LS
1224 || enmVMState == VMSTATE_POWERING_OFF
1225 || enmVMState == VMSTATE_POWERING_OFF_LS)
1226 {
1227 LogFlow(("pdmR3DrvHlp_AsyncNotificationCompleted: caller='%s'/%d:\n", pDrvIns->pReg->szName, pDrvIns->iInstance));
1228 VMR3AsyncPdmNotificationWakeupU(pVM->pUVM);
1229 }
1230 else
1231 LogFlow(("pdmR3DrvHlp_AsyncNotificationCompleted: caller='%s'/%d: enmVMState=%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance, enmVMState));
1232}
1233
1234
1235/** @interface_method_impl{PDMDRVHLP,pfnThreadCreate} */
1236static DECLCALLBACK(int) pdmR3DrvHlp_ThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
1237 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
1238{
1239 PDMDRV_ASSERT_DRVINS(pDrvIns);
1240 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1241 LogFlow(("pdmR3DrvHlp_ThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
1242 pDrvIns->pReg->szName, pDrvIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
1243
1244 int rc = pdmR3ThreadCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
1245
1246 LogFlow(("pdmR3DrvHlp_ThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
1247 rc, *ppThread));
1248 return rc;
1249}
1250
1251
1252/** @interface_method_impl{PDMDRVHLP,pfnAsyncCompletionTemplateCreate} */
1253static DECLCALLBACK(int) pdmR3DrvHlp_AsyncCompletionTemplateCreate(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
1254 PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser,
1255 const char *pszDesc)
1256{
1257 PDMDRV_ASSERT_DRVINS(pDrvIns);
1258 LogFlow(("pdmR3DrvHlp_AsyncCompletionTemplateCreate: caller='%s'/%d: ppTemplate=%p pfnCompleted=%p pszDesc=%p:{%s}\n",
1259 pDrvIns->pReg->szName, pDrvIns->iInstance, ppTemplate, pfnCompleted, pszDesc, pszDesc));
1260
1261 int rc = PDMR3AsyncCompletionTemplateCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppTemplate, pfnCompleted, pvTemplateUser, pszDesc);
1262
1263 LogFlow(("pdmR3DrvHlp_AsyncCompletionTemplateCreate: caller='%s'/%d: returns %Rrc *ppThread=%p\n", pDrvIns->pReg->szName,
1264 pDrvIns->iInstance, rc, *ppTemplate));
1265 return rc;
1266}
1267
1268
1269/** @interface_method_impl{PDMDRVHLP,pfnLdrGetRCInterfaceSymbols} */
1270static DECLCALLBACK(int) pdmR3DrvHlp_LdrGetRCInterfaceSymbols(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
1271 const char *pszSymPrefix, const char *pszSymList)
1272{
1273 PDMDRV_ASSERT_DRVINS(pDrvIns);
1274 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1275 LogFlow(("pdmR3DrvHlp_LdrGetRCInterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
1276 pDrvIns->pReg->szName, pDrvIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
1277
1278 int rc;
1279 if ( strncmp(pszSymPrefix, "drv", 3) == 0
1280 && RTStrIStr(pszSymPrefix + 3, pDrvIns->pReg->szName) != NULL)
1281 {
1282 if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
1283 rc = PDMR3LdrGetInterfaceSymbols(pDrvIns->Internal.s.pVMR3,
1284 pvInterface, cbInterface,
1285 pDrvIns->pReg->szRCMod, pDrvIns->Internal.s.pDrv->pszRCSearchPath,
1286 pszSymPrefix, pszSymList,
1287 false /*fRing0OrRC*/);
1288 else
1289 {
1290 AssertMsgFailed(("Not a raw-mode enabled driver\n"));
1291 rc = VERR_PERMISSION_DENIED;
1292 }
1293 }
1294 else
1295 {
1296 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'drv' and contain the driver name!\n",
1297 pszSymPrefix, pDrvIns->pReg->szName));
1298 rc = VERR_INVALID_NAME;
1299 }
1300
1301 LogFlow(("pdmR3DrvHlp_LdrGetRCInterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
1302 pDrvIns->iInstance, rc));
1303 return rc;
1304}
1305
1306
1307/** @interface_method_impl{PDMDRVHLP,pfnLdrGetR0InterfaceSymbols} */
1308static DECLCALLBACK(int) pdmR3DrvHlp_LdrGetR0InterfaceSymbols(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
1309 const char *pszSymPrefix, const char *pszSymList)
1310{
1311 PDMDRV_ASSERT_DRVINS(pDrvIns);
1312 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1313 LogFlow(("pdmR3DrvHlp_LdrGetR0InterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
1314 pDrvIns->pReg->szName, pDrvIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
1315
1316 int rc;
1317 if ( strncmp(pszSymPrefix, "drv", 3) == 0
1318 && RTStrIStr(pszSymPrefix + 3, pDrvIns->pReg->szName) != NULL)
1319 {
1320 if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
1321 rc = PDMR3LdrGetInterfaceSymbols(pDrvIns->Internal.s.pVMR3,
1322 pvInterface, cbInterface,
1323 pDrvIns->pReg->szR0Mod, pDrvIns->Internal.s.pDrv->pszR0SearchPath,
1324 pszSymPrefix, pszSymList,
1325 true /*fRing0OrRC*/);
1326 else
1327 {
1328 AssertMsgFailed(("Not a ring-0 enabled driver\n"));
1329 rc = VERR_PERMISSION_DENIED;
1330 }
1331 }
1332 else
1333 {
1334 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'drv' and contain the driver name!\n",
1335 pszSymPrefix, pDrvIns->pReg->szName));
1336 rc = VERR_INVALID_NAME;
1337 }
1338
1339 LogFlow(("pdmR3DrvHlp_LdrGetR0InterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
1340 pDrvIns->iInstance, rc));
1341 return rc;
1342}
1343
1344
1345/** @interface_method_impl{PDMDRVHLP,pfnCritSectInit} */
1346static DECLCALLBACK(int) pdmR3DrvHlp_CritSectInit(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect,
1347 RT_SRC_POS_DECL, const char *pszName)
1348{
1349 PDMDRV_ASSERT_DRVINS(pDrvIns);
1350 PVM pVM = pDrvIns->Internal.s.pVMR3;
1351 VM_ASSERT_EMT(pVM);
1352 LogFlow(("pdmR3DrvHlp_CritSectInit: caller='%s'/%d: pCritSect=%p pszName=%s\n",
1353 pDrvIns->pReg->szName, pDrvIns->iInstance, pCritSect, pszName));
1354
1355 int rc = pdmR3CritSectInitDriver(pVM, pDrvIns, pCritSect, RT_SRC_POS_ARGS, "%s_%u", pszName, pDrvIns->iInstance);
1356
1357 LogFlow(("pdmR3DrvHlp_CritSectInit: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
1358 pDrvIns->iInstance, rc));
1359 return rc;
1360}
1361
1362
1363/** @interface_method_impl{PDMDRVHLP,pfnCallR0} */
1364static DECLCALLBACK(int) pdmR3DrvHlp_CallR0(PPDMDRVINS pDrvIns, uint32_t uOperation, uint64_t u64Arg)
1365{
1366 PDMDRV_ASSERT_DRVINS(pDrvIns);
1367 PVM pVM = pDrvIns->Internal.s.pVMR3;
1368 LogFlow(("pdmR3DrvHlp_CallR0: caller='%s'/%d: uOperation=%#x u64Arg=%#RX64\n",
1369 pDrvIns->pReg->szName, pDrvIns->iInstance, uOperation, u64Arg));
1370
1371 /*
1372 * Lazy resolve the ring-0 entry point.
1373 */
1374 int rc = VINF_SUCCESS;
1375 PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0 = pDrvIns->Internal.s.pfnReqHandlerR0;
1376 if (RT_UNLIKELY(pfnReqHandlerR0 == NIL_RTR0PTR))
1377 {
1378 if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
1379 {
1380 char szSymbol[ sizeof("drvR0") + sizeof(pDrvIns->pReg->szName) + sizeof("ReqHandler")];
1381 strcat(strcat(strcpy(szSymbol, "drvR0"), pDrvIns->pReg->szName), "ReqHandler");
1382 szSymbol[sizeof("drvR0") - 1] = RT_C_TO_UPPER(szSymbol[sizeof("drvR0") - 1]);
1383
1384 rc = PDMR3LdrGetSymbolR0Lazy(pVM, pDrvIns->pReg->szR0Mod, pDrvIns->Internal.s.pDrv->pszR0SearchPath, szSymbol,
1385 &pfnReqHandlerR0);
1386 if (RT_SUCCESS(rc))
1387 pDrvIns->Internal.s.pfnReqHandlerR0 = pfnReqHandlerR0;
1388 else
1389 pfnReqHandlerR0 = NIL_RTR0PTR;
1390 }
1391 else
1392 rc = VERR_ACCESS_DENIED;
1393 }
1394 if (RT_LIKELY(pfnReqHandlerR0 != NIL_RTR0PTR))
1395 {
1396 /*
1397 * Make the ring-0 call.
1398 */
1399 PDMDRIVERCALLREQHANDLERREQ Req;
1400 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
1401 Req.Hdr.cbReq = sizeof(Req);
1402 Req.pDrvInsR0 = PDMDRVINS_2_R0PTR(pDrvIns);
1403 Req.uOperation = uOperation;
1404 Req.u32Alignment = 0;
1405 Req.u64Arg = u64Arg;
1406 rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_PDM_DRIVER_CALL_REQ_HANDLER, 0, &Req.Hdr);
1407 }
1408
1409 LogFlow(("pdmR3DrvHlp_CallR0: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
1410 pDrvIns->iInstance, rc));
1411 return rc;
1412}
1413
1414
1415/** @interface_method_impl{PDMDRVHLP,pfnFTSetCheckpoint} */
1416static DECLCALLBACK(int) pdmR3DrvHlp_FTSetCheckpoint(PPDMDRVINS pDrvIns, FTMCHECKPOINTTYPE enmType)
1417{
1418 PDMDRV_ASSERT_DRVINS(pDrvIns);
1419 return FTMSetCheckpoint(pDrvIns->Internal.s.pVMR3, enmType);
1420}
1421
1422
1423/** @interface_method_impl{PDMDRVHLP,pfnBlkCacheRetain} */
1424static DECLCALLBACK(int) pdmR3DrvHlp_BlkCacheRetain(PPDMDRVINS pDrvIns, PPPDMBLKCACHE ppBlkCache,
1425 PFNPDMBLKCACHEXFERCOMPLETEDRV pfnXferComplete,
1426 PFNPDMBLKCACHEXFERENQUEUEDRV pfnXferEnqueue,
1427 const char *pcszId)
1428{
1429 PDMDRV_ASSERT_DRVINS(pDrvIns);
1430 return PDMR3BlkCacheRetainDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppBlkCache,
1431 pfnXferComplete, pfnXferEnqueue, pcszId);
1432}
1433
1434
1435/**
1436 * The driver helper structure.
1437 */
1438const PDMDRVHLPR3 g_pdmR3DrvHlp =
1439{
1440 PDM_DRVHLPR3_VERSION,
1441 pdmR3DrvHlp_Attach,
1442 pdmR3DrvHlp_Detach,
1443 pdmR3DrvHlp_DetachSelf,
1444 pdmR3DrvHlp_MountPrepare,
1445 pdmR3DrvHlp_AssertEMT,
1446 pdmR3DrvHlp_AssertOther,
1447 pdmR3DrvHlp_VMSetError,
1448 pdmR3DrvHlp_VMSetErrorV,
1449 pdmR3DrvHlp_VMSetRuntimeError,
1450 pdmR3DrvHlp_VMSetRuntimeErrorV,
1451 pdmR3DrvHlp_VMState,
1452 pdmR3DrvHlp_VMTeleportedAndNotFullyResumedYet,
1453 pdmR3DrvHlp_GetSupDrvSession,
1454 pdmR3DrvHlp_QueueCreate,
1455 pdmR3DrvHlp_TMGetVirtualFreq,
1456 pdmR3DrvHlp_TMGetVirtualTime,
1457 pdmR3DrvHlp_TMTimerCreate,
1458 pdmR3DrvHlp_SSMRegister,
1459 pdmR3DrvHlp_SSMDeregister,
1460 pdmR3DrvHlp_DBGFInfoRegister,
1461 pdmR3DrvHlp_DBGFInfoDeregister,
1462 pdmR3DrvHlp_STAMRegister,
1463 pdmR3DrvHlp_STAMRegisterF,
1464 pdmR3DrvHlp_STAMRegisterV,
1465 pdmR3DrvHlp_STAMDeregister,
1466 pdmR3DrvHlp_SUPCallVMMR0Ex,
1467 pdmR3DrvHlp_USBRegisterHub,
1468 pdmR3DrvHlp_SetAsyncNotification,
1469 pdmR3DrvHlp_AsyncNotificationCompleted,
1470 pdmR3DrvHlp_ThreadCreate,
1471 pdmR3DrvHlp_AsyncCompletionTemplateCreate,
1472 pdmR3DrvHlp_LdrGetRCInterfaceSymbols,
1473 pdmR3DrvHlp_LdrGetR0InterfaceSymbols,
1474 pdmR3DrvHlp_CritSectInit,
1475 pdmR3DrvHlp_CallR0,
1476 pdmR3DrvHlp_FTSetCheckpoint,
1477 pdmR3DrvHlp_BlkCacheRetain,
1478 PDM_DRVHLPR3_VERSION /* u32TheEnd */
1479};
1480
1481/** @} */
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