VirtualBox

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

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

PDM,Devices,Drivers: Add async discard API and make us of it

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 57.7 KB
Line 
1/* $Id: PDMDriver.cpp 38878 2011-09-27 09:07:07Z 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 {
644 PDMCritSectEnter(pLun->pDevIns->pCritSectRoR3, VERR_IGNORED);
645 pLun->pDevIns->pReg->pfnDetach(pLun->pDevIns, pLun->iLun, fFlags);
646 PDMCritSectLeave(pLun->pDevIns->pCritSectRoR3);
647 }
648 }
649
650 /*
651 * Call destructor.
652 */
653 pCur->pUpBase = NULL;
654 if (pCur->pReg->pfnDestruct)
655 pCur->pReg->pfnDestruct(pCur);
656 pCur->Internal.s.pDrv->cInstances--;
657
658 /*
659 * Free all resources allocated by the driver.
660 */
661 /* Queues. */
662 int rc = PDMR3QueueDestroyDriver(pVM, pCur);
663 AssertRC(rc);
664
665 /* Timers. */
666 rc = TMR3TimerDestroyDriver(pVM, pCur);
667 AssertRC(rc);
668
669 /* SSM data units. */
670 rc = SSMR3DeregisterDriver(pVM, pCur, NULL, 0);
671 AssertRC(rc);
672
673 /* PDM threads. */
674 rc = pdmR3ThreadDestroyDriver(pVM, pCur);
675 AssertRC(rc);
676
677 /* Info handlers. */
678 rc = DBGFR3InfoDeregisterDriver(pVM, pCur, NULL);
679 AssertRC(rc);
680
681 /* PDM critsects. */
682 rc = pdmR3CritSectDeleteDriver(pVM, pCur);
683 AssertRC(rc);
684
685 /* Block caches. */
686 PDMR3BlkCacheReleaseDriver(pVM, pCur);
687
688 /* Finally, the driver it self. */
689 bool fHyperHeap = pCur->Internal.s.fHyperHeap;
690 ASMMemFill32(pCur, RT_OFFSETOF(PDMDRVINS, achInstanceData[pCur->pReg->cbInstance]), 0xdeadd0d0);
691 if (fHyperHeap)
692 MMHyperFree(pVM, pCur);
693 else
694 MMR3HeapFree(pCur);
695
696 } while (pCur != pDrvIns);
697}
698
699
700
701
702/** @name Driver Helpers
703 * @{
704 */
705
706/** @interface_method_impl{PDMDRVHLP,pfnAttach} */
707static DECLCALLBACK(int) pdmR3DrvHlp_Attach(PPDMDRVINS pDrvIns, uint32_t fFlags, PPDMIBASE *ppBaseInterface)
708{
709 PDMDRV_ASSERT_DRVINS(pDrvIns);
710 PVM pVM = pDrvIns->Internal.s.pVMR3;
711 VM_ASSERT_EMT(pVM);
712 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: fFlags=%#x\n", pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
713 Assert(!(fFlags & ~(PDM_TACH_FLAGS_NOT_HOT_PLUG)));
714
715 /*
716 * Check that there isn't anything attached already.
717 */
718 int rc;
719 if (!pDrvIns->Internal.s.pDown)
720 {
721 Assert(pDrvIns->Internal.s.pLun->pBottom == pDrvIns);
722
723 /*
724 * Get the attached driver configuration.
725 */
726 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
727 if (pNode)
728 rc = pdmR3DrvInstantiate(pVM, pNode, &pDrvIns->IBase, pDrvIns, pDrvIns->Internal.s.pLun, ppBaseInterface);
729 else
730 rc = VERR_PDM_NO_ATTACHED_DRIVER;
731 }
732 else
733 {
734 AssertMsgFailed(("Already got a driver attached. The driver should keep track of such things!\n"));
735 rc = VERR_PDM_DRIVER_ALREADY_ATTACHED;
736 }
737
738 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: return %Rrc\n",
739 pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
740 return rc;
741}
742
743
744/** @interface_method_impl{PDMDRVHLP,pfnDetach} */
745static DECLCALLBACK(int) pdmR3DrvHlp_Detach(PPDMDRVINS pDrvIns, uint32_t fFlags)
746{
747 PDMDRV_ASSERT_DRVINS(pDrvIns);
748 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: fFlags=%#x\n",
749 pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
750 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
751
752 /*
753 * Anything attached?
754 */
755 int rc;
756 if (pDrvIns->Internal.s.pDown)
757 rc = pdmR3DrvDetach(pDrvIns->Internal.s.pDown, fFlags);
758 else
759 {
760 AssertMsgFailed(("Nothing attached!\n"));
761 rc = VERR_PDM_NO_DRIVER_ATTACHED;
762 }
763
764 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: returns %Rrc\n",
765 pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
766 return rc;
767}
768
769
770/** @interface_method_impl{PDMDRVHLP,pfnDetachSelf} */
771static DECLCALLBACK(int) pdmR3DrvHlp_DetachSelf(PPDMDRVINS pDrvIns, uint32_t fFlags)
772{
773 PDMDRV_ASSERT_DRVINS(pDrvIns);
774 LogFlow(("pdmR3DrvHlp_DetachSelf: caller='%s'/%d: fFlags=%#x\n",
775 pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
776 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
777
778 int rc = pdmR3DrvDetach(pDrvIns, fFlags);
779
780 LogFlow(("pdmR3DrvHlp_Detach: returns %Rrc\n", rc)); /* pDrvIns is freed by now. */
781 return rc;
782}
783
784
785/** @interface_method_impl{PDMDRVHLP,pfnMountPrepare} */
786static DECLCALLBACK(int) pdmR3DrvHlp_MountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver)
787{
788 PDMDRV_ASSERT_DRVINS(pDrvIns);
789 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: pszFilename=%p:{%s} pszCoreDriver=%p:{%s}\n",
790 pDrvIns->pReg->szName, pDrvIns->iInstance, pszFilename, pszFilename, pszCoreDriver, pszCoreDriver));
791 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
792
793 /*
794 * Do the caller have anything attached below itself?
795 */
796 if (pDrvIns->Internal.s.pDown)
797 {
798 AssertMsgFailed(("Cannot prepare a mount when something's attached to you!\n"));
799 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
800 }
801
802 /*
803 * We're asked to prepare, so we'll start off by nuking the
804 * attached configuration tree.
805 */
806 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
807 if (pNode)
808 CFGMR3RemoveNode(pNode);
809
810 /*
811 * If there is no core driver, we'll have to probe for it.
812 */
813 if (!pszCoreDriver)
814 {
815 /** @todo implement image probing. */
816 AssertReleaseMsgFailed(("Not implemented!\n"));
817 return VERR_NOT_IMPLEMENTED;
818 }
819
820 /*
821 * Construct the basic attached driver configuration.
822 */
823 int rc = CFGMR3InsertNode(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver", &pNode);
824 if (RT_SUCCESS(rc))
825 {
826 rc = CFGMR3InsertString(pNode, "Driver", pszCoreDriver);
827 if (RT_SUCCESS(rc))
828 {
829 PCFGMNODE pCfg;
830 rc = CFGMR3InsertNode(pNode, "Config", &pCfg);
831 if (RT_SUCCESS(rc))
832 {
833 rc = CFGMR3InsertString(pCfg, "Path", pszFilename);
834 if (RT_SUCCESS(rc))
835 {
836 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc (Driver=%s)\n",
837 pDrvIns->pReg->szName, pDrvIns->iInstance, rc, pszCoreDriver));
838 return rc;
839 }
840 else
841 AssertMsgFailed(("Path string insert failed, rc=%Rrc\n", rc));
842 }
843 else
844 AssertMsgFailed(("Config node failed, rc=%Rrc\n", rc));
845 }
846 else
847 AssertMsgFailed(("Driver string insert failed, rc=%Rrc\n", rc));
848 CFGMR3RemoveNode(pNode);
849 }
850 else
851 AssertMsgFailed(("AttachedDriver node insert failed, rc=%Rrc\n", rc));
852
853 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc\n",
854 pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
855 return rc;
856}
857
858
859/** @interface_method_impl{PDMDRVHLP,pfnAssertEMT} */
860static DECLCALLBACK(bool) pdmR3DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
861{
862 PDMDRV_ASSERT_DRVINS(pDrvIns);
863 if (VM_IS_EMT(pDrvIns->Internal.s.pVMR3))
864 return true;
865
866 char szMsg[100];
867 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance);
868 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
869 AssertBreakpoint();
870 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
871 return false;
872}
873
874
875/** @interface_method_impl{PDMDRVHLP,pfnAssertOther} */
876static DECLCALLBACK(bool) pdmR3DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
877{
878 PDMDRV_ASSERT_DRVINS(pDrvIns);
879 if (!VM_IS_EMT(pDrvIns->Internal.s.pVMR3))
880 return true;
881
882 char szMsg[100];
883 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance);
884 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
885 AssertBreakpoint();
886 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
887 return false;
888}
889
890
891/** @interface_method_impl{PDMDRVHLP,pfnVMSetError} */
892static DECLCALLBACK(int) pdmR3DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
893{
894 PDMDRV_ASSERT_DRVINS(pDrvIns);
895 va_list args;
896 va_start(args, pszFormat);
897 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
898 va_end(args);
899 return rc;
900}
901
902
903/** @interface_method_impl{PDMDRVHLP,pfnVMSetErrorV} */
904static DECLCALLBACK(int) pdmR3DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
905{
906 PDMDRV_ASSERT_DRVINS(pDrvIns);
907 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
908 return rc;
909}
910
911
912/** @interface_method_impl{PDMDRVHLP,pfnVMSetRuntimeError} */
913static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
914{
915 PDMDRV_ASSERT_DRVINS(pDrvIns);
916 va_list args;
917 va_start(args, pszFormat);
918 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, args);
919 va_end(args);
920 return rc;
921}
922
923
924/** @interface_method_impl{PDMDRVHLP,pfnVMSetRuntimeErrorV} */
925static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
926{
927 PDMDRV_ASSERT_DRVINS(pDrvIns);
928 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, va);
929 return rc;
930}
931
932
933/** @interface_method_impl{PDMDEVHLPR3,pfnVMState} */
934static DECLCALLBACK(VMSTATE) pdmR3DrvHlp_VMState(PPDMDRVINS pDrvIns)
935{
936 PDMDRV_ASSERT_DRVINS(pDrvIns);
937
938 VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVMR3);
939
940 LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
941 enmVMState, VMR3GetStateName(enmVMState)));
942 return enmVMState;
943}
944
945
946/** @interface_method_impl{PDMDEVHLPR3,pfnVMTeleportedAndNotFullyResumedYet} */
947static DECLCALLBACK(bool) pdmR3DrvHlp_VMTeleportedAndNotFullyResumedYet(PPDMDRVINS pDrvIns)
948{
949 PDMDRV_ASSERT_DRVINS(pDrvIns);
950
951 bool fRc = VMR3TeleportedAndNotFullyResumedYet(pDrvIns->Internal.s.pVMR3);
952
953 LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %RTbool)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
954 fRc));
955 return fRc;
956}
957
958
959/** @interface_method_impl{PDMDEVHLPR3,pfnGetSupDrvSession} */
960static DECLCALLBACK(PSUPDRVSESSION) pdmR3DrvHlp_GetSupDrvSession(PPDMDRVINS pDrvIns)
961{
962 PDMDRV_ASSERT_DRVINS(pDrvIns);
963
964 PSUPDRVSESSION pSession = pDrvIns->Internal.s.pVMR3->pSession;
965 LogFlow(("pdmR3DrvHlp_GetSupDrvSession: caller='%s'/%d: returns %p)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
966 pSession));
967 return pSession;
968}
969
970
971/** @interface_method_impl{PDMDRVHLP,pfnQueueCreate} */
972static DECLCALLBACK(int) pdmR3DrvHlp_QueueCreate(PPDMDRVINS pDrvIns, uint32_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
973 PFNPDMQUEUEDRV pfnCallback, const char *pszName, PPDMQUEUE *ppQueue)
974{
975 PDMDRV_ASSERT_DRVINS(pDrvIns);
976 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: cbItem=%d cItems=%d cMilliesInterval=%d pfnCallback=%p pszName=%p:{%s} ppQueue=%p\n",
977 pDrvIns->pReg->szName, pDrvIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, pszName, ppQueue, ppQueue));
978 PVM pVM = pDrvIns->Internal.s.pVMR3;
979 VM_ASSERT_EMT(pVM);
980
981 if (pDrvIns->iInstance > 0)
982 {
983 pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DRIVER_DESC, "%s_%u", pszName, pDrvIns->iInstance);
984 AssertLogRelReturn(pszName, VERR_NO_MEMORY);
985 }
986
987 int rc = PDMR3QueueCreateDriver(pVM, pDrvIns, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, ppQueue);
988
989 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc, *ppQueue));
990 return rc;
991}
992
993
994/** @interface_method_impl{PDMDRVHLP,pfnTMGetVirtualFreq} */
995static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualFreq(PPDMDRVINS pDrvIns)
996{
997 PDMDRV_ASSERT_DRVINS(pDrvIns);
998
999 return TMVirtualGetFreq(pDrvIns->Internal.s.pVMR3);
1000}
1001
1002
1003/** @interface_method_impl{PDMDRVHLP,pfnTMGetVirtualTime} */
1004static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualTime(PPDMDRVINS pDrvIns)
1005{
1006 PDMDRV_ASSERT_DRVINS(pDrvIns);
1007
1008 return TMVirtualGet(pDrvIns->Internal.s.pVMR3);
1009}
1010
1011
1012/** @interface_method_impl{PDMDRVHLP,pfnTMTimerCreate} */
1013static DECLCALLBACK(int) pdmR3DrvHlp_TMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
1014{
1015 PDMDRV_ASSERT_DRVINS(pDrvIns);
1016 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pvUser=%p fFlags=%#x pszDesc=%p:{%s} ppTimer=%p\n",
1017 pDrvIns->pReg->szName, pDrvIns->iInstance, enmClock, pfnCallback, pvUser, fFlags, pszDesc, pszDesc, ppTimer));
1018
1019 int rc = TMR3TimerCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
1020
1021 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: returns %Rrc *ppTimer=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc, *ppTimer));
1022 return rc;
1023}
1024
1025
1026
1027/** @interface_method_impl{PDMDRVHLP,pfnSSMRegister} */
1028static DECLCALLBACK(int) pdmR3DrvHlp_SSMRegister(PPDMDRVINS pDrvIns, uint32_t uVersion, size_t cbGuess,
1029 PFNSSMDRVLIVEPREP pfnLivePrep, PFNSSMDRVLIVEEXEC pfnLiveExec, PFNSSMDRVLIVEVOTE pfnLiveVote,
1030 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
1031 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
1032{
1033 PDMDRV_ASSERT_DRVINS(pDrvIns);
1034 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1035 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: uVersion=#x cbGuess=%#x \n"
1036 " pfnLivePrep=%p pfnLiveExec=%p pfnLiveVote=%p pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoaddone=%p\n",
1037 pDrvIns->pReg->szName, pDrvIns->iInstance, uVersion, cbGuess,
1038 pfnLivePrep, pfnLiveExec, pfnLiveVote,
1039 pfnSavePrep, pfnSaveExec, pfnSaveDone, pfnLoadPrep, pfnLoadExec, pfnLoadDone));
1040
1041 int rc = SSMR3RegisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pDrvIns->pReg->szName, pDrvIns->iInstance,
1042 uVersion, cbGuess,
1043 pfnLivePrep, pfnLiveExec, pfnLiveVote,
1044 pfnSavePrep, pfnSaveExec, pfnSaveDone,
1045 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
1046
1047 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1048 return rc;
1049}
1050
1051
1052/** @interface_method_impl{PDMDRVHLP,pfnSSMDeregister} */
1053static DECLCALLBACK(int) pdmR3DrvHlp_SSMDeregister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance)
1054{
1055 PDMDRV_ASSERT_DRVINS(pDrvIns);
1056 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1057 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x\n",
1058 pDrvIns->pReg->szName, pDrvIns->iInstance, pszName, pszName, u32Instance));
1059
1060 int rc = SSMR3DeregisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pszName, u32Instance);
1061
1062 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1063 return rc;
1064}
1065
1066
1067/** @interface_method_impl{PDMDEVHLP,pfnDBGFInfoRegister} */
1068static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoRegister(PPDMDRVINS pDrvIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler)
1069{
1070 PDMDRV_ASSERT_DRVINS(pDrvIns);
1071 LogFlow(("pdmR3DrvHlp_DBGFInfoRegister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
1072 pDrvIns->pReg->szName, pDrvIns->iInstance, pszName, pszName, pszDesc, pszDesc, pfnHandler));
1073
1074 int rc = DBGFR3InfoRegisterDriver(pDrvIns->Internal.s.pVMR3, pszName, pszDesc, pfnHandler, pDrvIns);
1075
1076 LogFlow(("pdmR3DrvHlp_DBGFInfoRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1077 return rc;
1078}
1079
1080
1081/** @interface_method_impl{PDMDEVHLP,pfnDBGFInfoDeregister} */
1082static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoDeregister(PPDMDRVINS pDrvIns, const char *pszName)
1083{
1084 PDMDRV_ASSERT_DRVINS(pDrvIns);
1085 LogFlow(("pdmR3DrvHlp_DBGFInfoDeregister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
1086 pDrvIns->pReg->szName, pDrvIns->iInstance, pszName));
1087
1088 int rc = DBGFR3InfoDeregisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pszName);
1089
1090 LogFlow(("pdmR3DrvHlp_DBGFInfoDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1091
1092 return rc;
1093}
1094
1095
1096/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegister} */
1097static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
1098{
1099 PDMDRV_ASSERT_DRVINS(pDrvIns);
1100 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1101
1102 STAM_REG(pDrvIns->Internal.s.pVMR3, pvSample, enmType, pszName, enmUnit, pszDesc);
1103 /** @todo track the samples so they can be dumped & deregistered when the driver instance is destroyed.
1104 * For now we just have to be careful not to use this call for drivers which can be unloaded. */
1105}
1106
1107
1108/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegisterF} */
1109static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1110 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
1111{
1112 PDMDRV_ASSERT_DRVINS(pDrvIns);
1113 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1114
1115 va_list args;
1116 va_start(args, pszName);
1117 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1118 va_end(args);
1119 AssertRC(rc);
1120}
1121
1122
1123/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegisterV} */
1124static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1125 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
1126{
1127 PDMDRV_ASSERT_DRVINS(pDrvIns);
1128 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1129
1130 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1131 AssertRC(rc);
1132}
1133
1134
1135/** @interface_method_impl{PDMDRVHLP,pfnSTAMDeregister} */
1136static DECLCALLBACK(int) pdmR3DrvHlp_STAMDeregister(PPDMDRVINS pDrvIns, void *pvSample)
1137{
1138 PDMDRV_ASSERT_DRVINS(pDrvIns);
1139 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1140
1141 int rc = STAMR3DeregisterU(pDrvIns->Internal.s.pVMR3->pUVM, pvSample);
1142 AssertRC(rc);
1143 return rc;
1144}
1145
1146
1147/** @interface_method_impl{PDMDRVHLP,pfnSUPCallVMMR0Ex} */
1148static DECLCALLBACK(int) pdmR3DrvHlp_SUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg)
1149{
1150 PDMDRV_ASSERT_DRVINS(pDrvIns);
1151 LogFlow(("pdmR3DrvHlp_SSMCallVMMR0Ex: caller='%s'/%d: uOperation=%u pvArg=%p cbArg=%d\n",
1152 pDrvIns->pReg->szName, pDrvIns->iInstance, uOperation, pvArg, cbArg));
1153 int rc;
1154 if ( uOperation >= VMMR0_DO_SRV_START
1155 && uOperation < VMMR0_DO_SRV_END)
1156 rc = SUPR3CallVMMR0Ex(pDrvIns->Internal.s.pVMR3->pVMR0, NIL_VMCPUID, uOperation, 0, (PSUPVMMR0REQHDR)pvArg);
1157 else
1158 {
1159 AssertMsgFailed(("Invalid uOperation=%u\n", uOperation));
1160 rc = VERR_INVALID_PARAMETER;
1161 }
1162
1163 LogFlow(("pdmR3DrvHlp_SUPCallVMMR0Ex: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1164 return rc;
1165}
1166
1167
1168/** @interface_method_impl{PDMDRVHLP,pfnUSBRegisterHub} */
1169static DECLCALLBACK(int) pdmR3DrvHlp_USBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
1170{
1171 PDMDRV_ASSERT_DRVINS(pDrvIns);
1172 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1173 LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: fVersions=%#x cPorts=%#x pUsbHubReg=%p ppUsbHubHlp=%p\n",
1174 pDrvIns->pReg->szName, pDrvIns->iInstance, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp));
1175
1176#ifdef VBOX_WITH_USB
1177 int rc = pdmR3UsbRegisterHub(pDrvIns->Internal.s.pVMR3, pDrvIns, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp);
1178#else
1179 int rc = VERR_NOT_SUPPORTED;
1180#endif
1181
1182 LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1183 return rc;
1184}
1185
1186
1187/** @interface_method_impl{PDMDRVHLP,pfnSetAsyncNotification} */
1188static DECLCALLBACK(int) pdmR3DrvHlp_SetAsyncNotification(PPDMDRVINS pDrvIns, PFNPDMDRVASYNCNOTIFY pfnAsyncNotify)
1189{
1190 PDMDRV_ASSERT_DRVINS(pDrvIns);
1191 VM_ASSERT_EMT0(pDrvIns->Internal.s.pVMR3);
1192 LogFlow(("pdmR3DrvHlp_SetAsyncNotification: caller='%s'/%d: pfnAsyncNotify=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, pfnAsyncNotify));
1193
1194 int rc = VINF_SUCCESS;
1195 AssertStmt(pfnAsyncNotify, rc = VERR_INVALID_PARAMETER);
1196 AssertStmt(!pDrvIns->Internal.s.pfnAsyncNotify, rc = VERR_WRONG_ORDER);
1197 AssertStmt(pDrvIns->Internal.s.fVMSuspended || pDrvIns->Internal.s.fVMReset, rc = VERR_WRONG_ORDER);
1198 VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVMR3);
1199 AssertStmt( enmVMState == VMSTATE_SUSPENDING
1200 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1201 || enmVMState == VMSTATE_SUSPENDING_LS
1202 || enmVMState == VMSTATE_RESETTING
1203 || enmVMState == VMSTATE_RESETTING_LS
1204 || enmVMState == VMSTATE_POWERING_OFF
1205 || enmVMState == VMSTATE_POWERING_OFF_LS,
1206 rc = VERR_INVALID_STATE);
1207
1208 if (RT_SUCCESS(rc))
1209 pDrvIns->Internal.s.pfnAsyncNotify = pfnAsyncNotify;
1210
1211 LogFlow(("pdmR3DrvHlp_SetAsyncNotification: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
1212 return rc;
1213}
1214
1215
1216/** @interface_method_impl{PDMDRVHLP,pfnAsyncNotificationCompleted} */
1217static DECLCALLBACK(void) pdmR3DrvHlp_AsyncNotificationCompleted(PPDMDRVINS pDrvIns)
1218{
1219 PDMDRV_ASSERT_DRVINS(pDrvIns);
1220 PVM pVM = pDrvIns->Internal.s.pVMR3;
1221
1222 VMSTATE enmVMState = VMR3GetState(pVM);
1223 if ( enmVMState == VMSTATE_SUSPENDING
1224 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1225 || enmVMState == VMSTATE_SUSPENDING_LS
1226 || enmVMState == VMSTATE_RESETTING
1227 || enmVMState == VMSTATE_RESETTING_LS
1228 || enmVMState == VMSTATE_POWERING_OFF
1229 || enmVMState == VMSTATE_POWERING_OFF_LS)
1230 {
1231 LogFlow(("pdmR3DrvHlp_AsyncNotificationCompleted: caller='%s'/%d:\n", pDrvIns->pReg->szName, pDrvIns->iInstance));
1232 VMR3AsyncPdmNotificationWakeupU(pVM->pUVM);
1233 }
1234 else
1235 LogFlow(("pdmR3DrvHlp_AsyncNotificationCompleted: caller='%s'/%d: enmVMState=%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance, enmVMState));
1236}
1237
1238
1239/** @interface_method_impl{PDMDRVHLP,pfnThreadCreate} */
1240static DECLCALLBACK(int) pdmR3DrvHlp_ThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
1241 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
1242{
1243 PDMDRV_ASSERT_DRVINS(pDrvIns);
1244 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1245 LogFlow(("pdmR3DrvHlp_ThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
1246 pDrvIns->pReg->szName, pDrvIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
1247
1248 int rc = pdmR3ThreadCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
1249
1250 LogFlow(("pdmR3DrvHlp_ThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
1251 rc, *ppThread));
1252 return rc;
1253}
1254
1255
1256/** @interface_method_impl{PDMDRVHLP,pfnAsyncCompletionTemplateCreate} */
1257static DECLCALLBACK(int) pdmR3DrvHlp_AsyncCompletionTemplateCreate(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
1258 PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser,
1259 const char *pszDesc)
1260{
1261 PDMDRV_ASSERT_DRVINS(pDrvIns);
1262 LogFlow(("pdmR3DrvHlp_AsyncCompletionTemplateCreate: caller='%s'/%d: ppTemplate=%p pfnCompleted=%p pszDesc=%p:{%s}\n",
1263 pDrvIns->pReg->szName, pDrvIns->iInstance, ppTemplate, pfnCompleted, pszDesc, pszDesc));
1264
1265 int rc = PDMR3AsyncCompletionTemplateCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppTemplate, pfnCompleted, pvTemplateUser, pszDesc);
1266
1267 LogFlow(("pdmR3DrvHlp_AsyncCompletionTemplateCreate: caller='%s'/%d: returns %Rrc *ppThread=%p\n", pDrvIns->pReg->szName,
1268 pDrvIns->iInstance, rc, *ppTemplate));
1269 return rc;
1270}
1271
1272
1273/** @interface_method_impl{PDMDRVHLP,pfnLdrGetRCInterfaceSymbols} */
1274static DECLCALLBACK(int) pdmR3DrvHlp_LdrGetRCInterfaceSymbols(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
1275 const char *pszSymPrefix, const char *pszSymList)
1276{
1277 PDMDRV_ASSERT_DRVINS(pDrvIns);
1278 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1279 LogFlow(("pdmR3DrvHlp_LdrGetRCInterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
1280 pDrvIns->pReg->szName, pDrvIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
1281
1282 int rc;
1283 if ( strncmp(pszSymPrefix, "drv", 3) == 0
1284 && RTStrIStr(pszSymPrefix + 3, pDrvIns->pReg->szName) != NULL)
1285 {
1286 if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
1287 rc = PDMR3LdrGetInterfaceSymbols(pDrvIns->Internal.s.pVMR3,
1288 pvInterface, cbInterface,
1289 pDrvIns->pReg->szRCMod, pDrvIns->Internal.s.pDrv->pszRCSearchPath,
1290 pszSymPrefix, pszSymList,
1291 false /*fRing0OrRC*/);
1292 else
1293 {
1294 AssertMsgFailed(("Not a raw-mode enabled driver\n"));
1295 rc = VERR_PERMISSION_DENIED;
1296 }
1297 }
1298 else
1299 {
1300 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'drv' and contain the driver name!\n",
1301 pszSymPrefix, pDrvIns->pReg->szName));
1302 rc = VERR_INVALID_NAME;
1303 }
1304
1305 LogFlow(("pdmR3DrvHlp_LdrGetRCInterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
1306 pDrvIns->iInstance, rc));
1307 return rc;
1308}
1309
1310
1311/** @interface_method_impl{PDMDRVHLP,pfnLdrGetR0InterfaceSymbols} */
1312static DECLCALLBACK(int) pdmR3DrvHlp_LdrGetR0InterfaceSymbols(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
1313 const char *pszSymPrefix, const char *pszSymList)
1314{
1315 PDMDRV_ASSERT_DRVINS(pDrvIns);
1316 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
1317 LogFlow(("pdmR3DrvHlp_LdrGetR0InterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
1318 pDrvIns->pReg->szName, pDrvIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
1319
1320 int rc;
1321 if ( strncmp(pszSymPrefix, "drv", 3) == 0
1322 && RTStrIStr(pszSymPrefix + 3, pDrvIns->pReg->szName) != NULL)
1323 {
1324 if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
1325 rc = PDMR3LdrGetInterfaceSymbols(pDrvIns->Internal.s.pVMR3,
1326 pvInterface, cbInterface,
1327 pDrvIns->pReg->szR0Mod, pDrvIns->Internal.s.pDrv->pszR0SearchPath,
1328 pszSymPrefix, pszSymList,
1329 true /*fRing0OrRC*/);
1330 else
1331 {
1332 AssertMsgFailed(("Not a ring-0 enabled driver\n"));
1333 rc = VERR_PERMISSION_DENIED;
1334 }
1335 }
1336 else
1337 {
1338 AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'drv' and contain the driver name!\n",
1339 pszSymPrefix, pDrvIns->pReg->szName));
1340 rc = VERR_INVALID_NAME;
1341 }
1342
1343 LogFlow(("pdmR3DrvHlp_LdrGetR0InterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
1344 pDrvIns->iInstance, rc));
1345 return rc;
1346}
1347
1348
1349/** @interface_method_impl{PDMDRVHLP,pfnCritSectInit} */
1350static DECLCALLBACK(int) pdmR3DrvHlp_CritSectInit(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect,
1351 RT_SRC_POS_DECL, const char *pszName)
1352{
1353 PDMDRV_ASSERT_DRVINS(pDrvIns);
1354 PVM pVM = pDrvIns->Internal.s.pVMR3;
1355 VM_ASSERT_EMT(pVM);
1356 LogFlow(("pdmR3DrvHlp_CritSectInit: caller='%s'/%d: pCritSect=%p pszName=%s\n",
1357 pDrvIns->pReg->szName, pDrvIns->iInstance, pCritSect, pszName));
1358
1359 int rc = pdmR3CritSectInitDriver(pVM, pDrvIns, pCritSect, RT_SRC_POS_ARGS, "%s_%u", pszName, pDrvIns->iInstance);
1360
1361 LogFlow(("pdmR3DrvHlp_CritSectInit: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
1362 pDrvIns->iInstance, rc));
1363 return rc;
1364}
1365
1366
1367/** @interface_method_impl{PDMDRVHLP,pfnCallR0} */
1368static DECLCALLBACK(int) pdmR3DrvHlp_CallR0(PPDMDRVINS pDrvIns, uint32_t uOperation, uint64_t u64Arg)
1369{
1370 PDMDRV_ASSERT_DRVINS(pDrvIns);
1371 PVM pVM = pDrvIns->Internal.s.pVMR3;
1372 LogFlow(("pdmR3DrvHlp_CallR0: caller='%s'/%d: uOperation=%#x u64Arg=%#RX64\n",
1373 pDrvIns->pReg->szName, pDrvIns->iInstance, uOperation, u64Arg));
1374
1375 /*
1376 * Lazy resolve the ring-0 entry point.
1377 */
1378 int rc = VINF_SUCCESS;
1379 PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0 = pDrvIns->Internal.s.pfnReqHandlerR0;
1380 if (RT_UNLIKELY(pfnReqHandlerR0 == NIL_RTR0PTR))
1381 {
1382 if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
1383 {
1384 char szSymbol[ sizeof("drvR0") + sizeof(pDrvIns->pReg->szName) + sizeof("ReqHandler")];
1385 strcat(strcat(strcpy(szSymbol, "drvR0"), pDrvIns->pReg->szName), "ReqHandler");
1386 szSymbol[sizeof("drvR0") - 1] = RT_C_TO_UPPER(szSymbol[sizeof("drvR0") - 1]);
1387
1388 rc = PDMR3LdrGetSymbolR0Lazy(pVM, pDrvIns->pReg->szR0Mod, pDrvIns->Internal.s.pDrv->pszR0SearchPath, szSymbol,
1389 &pfnReqHandlerR0);
1390 if (RT_SUCCESS(rc))
1391 pDrvIns->Internal.s.pfnReqHandlerR0 = pfnReqHandlerR0;
1392 else
1393 pfnReqHandlerR0 = NIL_RTR0PTR;
1394 }
1395 else
1396 rc = VERR_ACCESS_DENIED;
1397 }
1398 if (RT_LIKELY(pfnReqHandlerR0 != NIL_RTR0PTR))
1399 {
1400 /*
1401 * Make the ring-0 call.
1402 */
1403 PDMDRIVERCALLREQHANDLERREQ Req;
1404 Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
1405 Req.Hdr.cbReq = sizeof(Req);
1406 Req.pDrvInsR0 = PDMDRVINS_2_R0PTR(pDrvIns);
1407 Req.uOperation = uOperation;
1408 Req.u32Alignment = 0;
1409 Req.u64Arg = u64Arg;
1410 rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_PDM_DRIVER_CALL_REQ_HANDLER, 0, &Req.Hdr);
1411 }
1412
1413 LogFlow(("pdmR3DrvHlp_CallR0: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
1414 pDrvIns->iInstance, rc));
1415 return rc;
1416}
1417
1418
1419/** @interface_method_impl{PDMDRVHLP,pfnFTSetCheckpoint} */
1420static DECLCALLBACK(int) pdmR3DrvHlp_FTSetCheckpoint(PPDMDRVINS pDrvIns, FTMCHECKPOINTTYPE enmType)
1421{
1422 PDMDRV_ASSERT_DRVINS(pDrvIns);
1423 return FTMSetCheckpoint(pDrvIns->Internal.s.pVMR3, enmType);
1424}
1425
1426
1427/** @interface_method_impl{PDMDRVHLP,pfnBlkCacheRetain} */
1428static DECLCALLBACK(int) pdmR3DrvHlp_BlkCacheRetain(PPDMDRVINS pDrvIns, PPPDMBLKCACHE ppBlkCache,
1429 PFNPDMBLKCACHEXFERCOMPLETEDRV pfnXferComplete,
1430 PFNPDMBLKCACHEXFERENQUEUEDRV pfnXferEnqueue,
1431 PFNPDMBLKCACHEXFERENQUEUEDISCARDDRV pfnXferEnqueueDiscard,
1432 const char *pcszId)
1433{
1434 PDMDRV_ASSERT_DRVINS(pDrvIns);
1435 return PDMR3BlkCacheRetainDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppBlkCache,
1436 pfnXferComplete, pfnXferEnqueue, pfnXferEnqueueDiscard, pcszId);
1437}
1438
1439
1440/**
1441 * The driver helper structure.
1442 */
1443const PDMDRVHLPR3 g_pdmR3DrvHlp =
1444{
1445 PDM_DRVHLPR3_VERSION,
1446 pdmR3DrvHlp_Attach,
1447 pdmR3DrvHlp_Detach,
1448 pdmR3DrvHlp_DetachSelf,
1449 pdmR3DrvHlp_MountPrepare,
1450 pdmR3DrvHlp_AssertEMT,
1451 pdmR3DrvHlp_AssertOther,
1452 pdmR3DrvHlp_VMSetError,
1453 pdmR3DrvHlp_VMSetErrorV,
1454 pdmR3DrvHlp_VMSetRuntimeError,
1455 pdmR3DrvHlp_VMSetRuntimeErrorV,
1456 pdmR3DrvHlp_VMState,
1457 pdmR3DrvHlp_VMTeleportedAndNotFullyResumedYet,
1458 pdmR3DrvHlp_GetSupDrvSession,
1459 pdmR3DrvHlp_QueueCreate,
1460 pdmR3DrvHlp_TMGetVirtualFreq,
1461 pdmR3DrvHlp_TMGetVirtualTime,
1462 pdmR3DrvHlp_TMTimerCreate,
1463 pdmR3DrvHlp_SSMRegister,
1464 pdmR3DrvHlp_SSMDeregister,
1465 pdmR3DrvHlp_DBGFInfoRegister,
1466 pdmR3DrvHlp_DBGFInfoDeregister,
1467 pdmR3DrvHlp_STAMRegister,
1468 pdmR3DrvHlp_STAMRegisterF,
1469 pdmR3DrvHlp_STAMRegisterV,
1470 pdmR3DrvHlp_STAMDeregister,
1471 pdmR3DrvHlp_SUPCallVMMR0Ex,
1472 pdmR3DrvHlp_USBRegisterHub,
1473 pdmR3DrvHlp_SetAsyncNotification,
1474 pdmR3DrvHlp_AsyncNotificationCompleted,
1475 pdmR3DrvHlp_ThreadCreate,
1476 pdmR3DrvHlp_AsyncCompletionTemplateCreate,
1477 pdmR3DrvHlp_LdrGetRCInterfaceSymbols,
1478 pdmR3DrvHlp_LdrGetR0InterfaceSymbols,
1479 pdmR3DrvHlp_CritSectInit,
1480 pdmR3DrvHlp_CallR0,
1481 pdmR3DrvHlp_FTSetCheckpoint,
1482 pdmR3DrvHlp_BlkCacheRetain,
1483 PDM_DRVHLPR3_VERSION /* u32TheEnd */
1484};
1485
1486/** @} */
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