VirtualBox

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

Last change on this file since 34207 was 34207, checked in by vboxsync, 14 years ago

pdmdrv: introduced PDMDrvHlpDBGFInfoRegister / PDMDrvHlpDBGFInfoDeregister

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