[23] | 1 | /* $Id: PDMDriver.cpp 48980 2013-10-08 21:20:06Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
| 3 | * PDM - Pluggable Device and Driver Manager, Driver parts.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[44358] | 7 | * Copyright (C) 2006-2013 Oracle Corporation
|
---|
[1] | 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
|
---|
[5999] | 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.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | /*******************************************************************************
|
---|
| 20 | * Header Files *
|
---|
| 21 | *******************************************************************************/
|
---|
| 22 | #define LOG_GROUP LOG_GROUP_PDM_DRIVER
|
---|
| 23 | #include "PDMInternal.h"
|
---|
[35346] | 24 | #include <VBox/vmm/pdm.h>
|
---|
| 25 | #include <VBox/vmm/mm.h>
|
---|
| 26 | #include <VBox/vmm/cfgm.h>
|
---|
[45808] | 27 | #include <VBox/vmm/hm.h>
|
---|
[35346] | 28 | #include <VBox/vmm/vmm.h>
|
---|
[1] | 29 | #include <VBox/sup.h>
|
---|
[35346] | 30 | #include <VBox/vmm/vm.h>
|
---|
[1] | 31 | #include <VBox/version.h>
|
---|
| 32 | #include <VBox/err.h>
|
---|
| 33 |
|
---|
| 34 | #include <VBox/log.h>
|
---|
| 35 | #include <iprt/assert.h>
|
---|
[29521] | 36 | #include <iprt/asm.h>
|
---|
| 37 | #include <iprt/ctype.h>
|
---|
| 38 | #include <iprt/mem.h>
|
---|
[1] | 39 | #include <iprt/thread.h>
|
---|
[29521] | 40 | #include <iprt/path.h>
|
---|
[1] | 41 | #include <iprt/string.h>
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | /*******************************************************************************
|
---|
| 45 | * Structures and Typedefs *
|
---|
| 46 | *******************************************************************************/
|
---|
| 47 | /**
|
---|
| 48 | * Internal callback structure pointer.
|
---|
[3857] | 49 | *
|
---|
[1] | 50 | * The main purpose is to define the extra data we associate
|
---|
| 51 | * with PDMDRVREGCB so we can find the VM instance and so on.
|
---|
| 52 | */
|
---|
| 53 | typedef struct PDMDRVREGCBINT
|
---|
| 54 | {
|
---|
| 55 | /** The callback structure. */
|
---|
| 56 | PDMDRVREGCB Core;
|
---|
| 57 | /** A bit of padding. */
|
---|
| 58 | uint32_t u32[4];
|
---|
| 59 | /** VM Handle. */
|
---|
| 60 | PVM pVM;
|
---|
[34241] | 61 | /** Pointer to the configuration node the registrations should be
|
---|
| 62 | * associated with. Can be NULL. */
|
---|
| 63 | PCFGMNODE pCfgNode;
|
---|
[1] | 64 | } PDMDRVREGCBINT, *PPDMDRVREGCBINT;
|
---|
| 65 | typedef const PDMDRVREGCBINT *PCPDMDRVREGCBINT;
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | /*******************************************************************************
|
---|
| 69 | * Internal Functions *
|
---|
| 70 | *******************************************************************************/
|
---|
[26161] | 71 | static DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pReg);
|
---|
[1] | 72 | static int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName);
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | /**
|
---|
[37418] | 76 | * Register drivers in a statically linked environment.
|
---|
[1] | 77 | *
|
---|
| 78 | * @returns VBox status code.
|
---|
[41801] | 79 | * @param pVM Pointer to the VM.
|
---|
[1] | 80 | * @param pfnCallback Driver registration callback
|
---|
| 81 | */
|
---|
[37418] | 82 | VMMR3DECL(int) PDMR3DrvStaticRegistration(PVM pVM, FNPDMVBOXDRIVERSREGISTER pfnCallback)
|
---|
[1] | 83 | {
|
---|
| 84 | /*
|
---|
| 85 | * The registration callbacks.
|
---|
| 86 | */
|
---|
| 87 | PDMDRVREGCBINT RegCB;
|
---|
| 88 | RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
|
---|
| 89 | RegCB.Core.pfnRegister = pdmR3DrvRegister;
|
---|
| 90 | RegCB.pVM = pVM;
|
---|
[37418] | 91 | RegCB.pCfgNode = NULL;
|
---|
[1] | 92 |
|
---|
| 93 | int rc = pfnCallback(&RegCB.Core, VBOX_VERSION);
|
---|
[13816] | 94 | if (RT_FAILURE(rc))
|
---|
[13818] | 95 | AssertMsgFailed(("VBoxDriversRegister failed with rc=%Rrc\n"));
|
---|
[1] | 96 |
|
---|
| 97 | return rc;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[37418] | 100 |
|
---|
[1] | 101 | /**
|
---|
| 102 | * This function will initialize the drivers for this VM instance.
|
---|
| 103 | *
|
---|
| 104 | * First of all this mean loading the builtin drivers and letting them
|
---|
| 105 | * register themselves. Beyond that any additional driver modules are
|
---|
| 106 | * loaded and called for registration.
|
---|
| 107 | *
|
---|
| 108 | * @returns VBox status code.
|
---|
[41800] | 109 | * @param pVM Pointer to the VM.
|
---|
[1] | 110 | */
|
---|
| 111 | int pdmR3DrvInit(PVM pVM)
|
---|
| 112 | {
|
---|
| 113 | LogFlow(("pdmR3DrvInit:\n"));
|
---|
| 114 |
|
---|
| 115 | AssertRelease(!(RT_OFFSETOF(PDMDRVINS, achInstanceData) & 15));
|
---|
[30217] | 116 | PPDMDRVINS pDrvInsAssert; NOREF(pDrvInsAssert);
|
---|
| 117 | AssertCompile(sizeof(pDrvInsAssert->Internal.s) <= sizeof(pDrvInsAssert->Internal.padding));
|
---|
[1] | 118 | AssertRelease(sizeof(pDrvInsAssert->Internal.s) <= sizeof(pDrvInsAssert->Internal.padding));
|
---|
| 119 |
|
---|
| 120 | /*
|
---|
| 121 | * The registration callbacks.
|
---|
| 122 | */
|
---|
| 123 | PDMDRVREGCBINT RegCB;
|
---|
| 124 | RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
|
---|
| 125 | RegCB.Core.pfnRegister = pdmR3DrvRegister;
|
---|
| 126 | RegCB.pVM = pVM;
|
---|
[34241] | 127 | RegCB.pCfgNode = NULL;
|
---|
[1] | 128 |
|
---|
| 129 | /*
|
---|
| 130 | * Load the builtin module
|
---|
| 131 | */
|
---|
| 132 | PCFGMNODE pDriversNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM/Drivers");
|
---|
| 133 | bool fLoadBuiltin;
|
---|
| 134 | int rc = CFGMR3QueryBool(pDriversNode, "LoadBuiltin", &fLoadBuiltin);
|
---|
| 135 | if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
|
---|
| 136 | fLoadBuiltin = true;
|
---|
[13816] | 137 | else if (RT_FAILURE(rc))
|
---|
[1] | 138 | {
|
---|
[13818] | 139 | AssertMsgFailed(("Configuration error: Querying boolean \"LoadBuiltin\" failed with %Rrc\n", rc));
|
---|
[1] | 140 | return rc;
|
---|
| 141 | }
|
---|
| 142 | if (fLoadBuiltin)
|
---|
| 143 | {
|
---|
| 144 | /* make filename */
|
---|
[34241] | 145 | char *pszFilename = pdmR3FileR3("VBoxDD", true /*fShared*/);
|
---|
[1] | 146 | if (!pszFilename)
|
---|
| 147 | return VERR_NO_TMP_MEMORY;
|
---|
| 148 | rc = pdmR3DrvLoad(pVM, &RegCB, pszFilename, "VBoxDD");
|
---|
| 149 | RTMemTmpFree(pszFilename);
|
---|
[13816] | 150 | if (RT_FAILURE(rc))
|
---|
[1] | 151 | return rc;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | /*
|
---|
| 155 | * Load additional driver modules.
|
---|
| 156 | */
|
---|
| 157 | for (PCFGMNODE pCur = CFGMR3GetFirstChild(pDriversNode); pCur; pCur = CFGMR3GetNextChild(pCur))
|
---|
| 158 | {
|
---|
| 159 | /*
|
---|
| 160 | * Get the name and path.
|
---|
| 161 | */
|
---|
| 162 | char szName[PDMMOD_NAME_LEN];
|
---|
| 163 | rc = CFGMR3GetName(pCur, &szName[0], sizeof(szName));
|
---|
| 164 | if (rc == VERR_CFGM_NOT_ENOUGH_SPACE)
|
---|
| 165 | {
|
---|
[14070] | 166 | AssertMsgFailed(("configuration error: The module name is too long, cchName=%zu.\n", CFGMR3GetNameLen(pCur)));
|
---|
[1] | 167 | return VERR_PDM_MODULE_NAME_TOO_LONG;
|
---|
| 168 | }
|
---|
[13816] | 169 | else if (RT_FAILURE(rc))
|
---|
[1] | 170 | {
|
---|
[13818] | 171 | AssertMsgFailed(("CFGMR3GetName -> %Rrc.\n", rc));
|
---|
[1] | 172 | return rc;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | /* the path is optional, if no path the module name + path is used. */
|
---|
| 176 | char szFilename[RTPATH_MAX];
|
---|
| 177 | rc = CFGMR3QueryString(pCur, "Path", &szFilename[0], sizeof(szFilename));
|
---|
| 178 | if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
|
---|
| 179 | strcpy(szFilename, szName);
|
---|
[13816] | 180 | else if (RT_FAILURE(rc))
|
---|
[1] | 181 | {
|
---|
[13818] | 182 | AssertMsgFailed(("configuration error: Failure to query the module path, rc=%Rrc.\n", rc));
|
---|
[1] | 183 | return rc;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | /* prepend path? */
|
---|
| 187 | if (!RTPathHavePath(szFilename))
|
---|
| 188 | {
|
---|
[34241] | 189 | char *psz = pdmR3FileR3(szFilename, false /*fShared*/);
|
---|
[1] | 190 | if (!psz)
|
---|
| 191 | return VERR_NO_TMP_MEMORY;
|
---|
| 192 | size_t cch = strlen(psz) + 1;
|
---|
| 193 | if (cch > sizeof(szFilename))
|
---|
| 194 | {
|
---|
| 195 | RTMemTmpFree(psz);
|
---|
| 196 | AssertMsgFailed(("Filename too long! cch=%d '%s'\n", cch, psz));
|
---|
| 197 | return VERR_FILENAME_TOO_LONG;
|
---|
| 198 | }
|
---|
| 199 | memcpy(szFilename, psz, cch);
|
---|
| 200 | RTMemTmpFree(psz);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /*
|
---|
| 204 | * Load the module and register it's drivers.
|
---|
| 205 | */
|
---|
[34241] | 206 | RegCB.pCfgNode = pCur;
|
---|
[1] | 207 | rc = pdmR3DrvLoad(pVM, &RegCB, szFilename, szName);
|
---|
[13816] | 208 | if (RT_FAILURE(rc))
|
---|
[1] | 209 | return rc;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | LogFlow(("pdmR3DrvInit: returns VINF_SUCCESS\n"));
|
---|
| 213 | return VINF_SUCCESS;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 | /**
|
---|
| 218 | * Loads one driver module and call the registration entry point.
|
---|
| 219 | *
|
---|
| 220 | * @returns VBox status code.
|
---|
[41800] | 221 | * @param pVM Pointer to the VM.
|
---|
[1] | 222 | * @param pRegCB The registration callback stuff.
|
---|
| 223 | * @param pszFilename Module filename.
|
---|
| 224 | * @param pszName Module name.
|
---|
| 225 | */
|
---|
| 226 | static int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName)
|
---|
| 227 | {
|
---|
| 228 | /*
|
---|
| 229 | * Load it.
|
---|
| 230 | */
|
---|
[6796] | 231 | int rc = pdmR3LoadR3U(pVM->pUVM, pszFilename, pszName);
|
---|
[13816] | 232 | if (RT_SUCCESS(rc))
|
---|
[1] | 233 | {
|
---|
| 234 | /*
|
---|
| 235 | * Get the registration export and call it.
|
---|
| 236 | */
|
---|
| 237 | FNPDMVBOXDRIVERSREGISTER *pfnVBoxDriversRegister;
|
---|
[12975] | 238 | rc = PDMR3LdrGetSymbolR3(pVM, pszName, "VBoxDriversRegister", (void **)&pfnVBoxDriversRegister);
|
---|
[13816] | 239 | if (RT_SUCCESS(rc))
|
---|
[1] | 240 | {
|
---|
| 241 | Log(("PDM: Calling VBoxDriversRegister (%p) of %s (%s)\n", pfnVBoxDriversRegister, pszName, pszFilename));
|
---|
| 242 | rc = pfnVBoxDriversRegister(&pRegCB->Core, VBOX_VERSION);
|
---|
[13816] | 243 | if (RT_SUCCESS(rc))
|
---|
[1] | 244 | Log(("PDM: Successfully loaded driver module %s (%s).\n", pszName, pszFilename));
|
---|
| 245 | else
|
---|
[13818] | 246 | AssertMsgFailed(("VBoxDriversRegister failed with rc=%Rrc\n"));
|
---|
[1] | 247 | }
|
---|
| 248 | else
|
---|
| 249 | {
|
---|
[13818] | 250 | AssertMsgFailed(("Failed to locate 'VBoxDriversRegister' in %s (%s) rc=%Rrc\n", pszName, pszFilename, rc));
|
---|
[1] | 251 | if (rc == VERR_SYMBOL_NOT_FOUND)
|
---|
| 252 | rc = VERR_PDM_NO_REGISTRATION_EXPORT;
|
---|
| 253 | }
|
---|
| 254 | }
|
---|
| 255 | else
|
---|
[13818] | 256 | AssertMsgFailed(("Failed to load %s (%s) rc=%Rrc!\n", pszName, pszFilename, rc));
|
---|
[1] | 257 | return rc;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 |
|
---|
[26151] | 261 | /** @interface_method_impl{PDMDRVREGCB,pfnRegister} */
|
---|
[26161] | 262 | static DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pReg)
|
---|
[1] | 263 | {
|
---|
| 264 | /*
|
---|
| 265 | * Validate the registration structure.
|
---|
| 266 | */
|
---|
[26161] | 267 | AssertPtrReturn(pReg, VERR_INVALID_POINTER);
|
---|
| 268 | AssertMsgReturn(pReg->u32Version == PDM_DRVREG_VERSION,
|
---|
| 269 | ("%#x\n", pReg->u32Version),
|
---|
[25893] | 270 | VERR_PDM_UNKNOWN_DRVREG_VERSION);
|
---|
[26166] | 271 | AssertReturn(pReg->szName[0], VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[30320] | 272 | AssertMsgReturn(RTStrEnd(pReg->szName, sizeof(pReg->szName)),
|
---|
[39839] | 273 | ("%.*s\n", sizeof(pReg->szName), pReg->szName),
|
---|
[22277] | 274 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[39839] | 275 | AssertMsgReturn(pdmR3IsValidName(pReg->szName), ("%.*s\n", pReg->szName),
|
---|
| 276 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 277 | AssertMsgReturn( !(pReg->fFlags & PDM_DRVREG_FLAGS_R0)
|
---|
| 278 | || ( pReg->szR0Mod[0]
|
---|
[30320] | 279 | && RTStrEnd(pReg->szR0Mod, sizeof(pReg->szR0Mod))),
|
---|
[26166] | 280 | ("%s: %.*s\n", pReg->szName, sizeof(pReg->szR0Mod), pReg->szR0Mod),
|
---|
[25893] | 281 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 282 | AssertMsgReturn( !(pReg->fFlags & PDM_DRVREG_FLAGS_RC)
|
---|
| 283 | || ( pReg->szRCMod[0]
|
---|
[30320] | 284 | && RTStrEnd(pReg->szRCMod, sizeof(pReg->szRCMod))),
|
---|
[26166] | 285 | ("%s: %.*s\n", pReg->szName, sizeof(pReg->szRCMod), pReg->szRCMod),
|
---|
[25893] | 286 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 287 | AssertMsgReturn(VALID_PTR(pReg->pszDescription),
|
---|
[26166] | 288 | ("%s: %p\n", pReg->szName, pReg->pszDescription),
|
---|
[25893] | 289 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 290 | AssertMsgReturn(!(pReg->fFlags & ~(PDM_DRVREG_FLAGS_HOST_BITS_MASK | PDM_DRVREG_FLAGS_R0 | PDM_DRVREG_FLAGS_RC)),
|
---|
[26166] | 291 | ("%s: %#x\n", pReg->szName, pReg->fFlags),
|
---|
[25893] | 292 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 293 | AssertMsgReturn((pReg->fFlags & PDM_DRVREG_FLAGS_HOST_BITS_MASK) == PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
[26166] | 294 | ("%s: %#x\n", pReg->szName, pReg->fFlags),
|
---|
[22277] | 295 | VERR_PDM_INVALID_DRIVER_HOST_BITS);
|
---|
[26161] | 296 | AssertMsgReturn(pReg->cMaxInstances > 0,
|
---|
[26166] | 297 | ("%s: %#x\n", pReg->szName, pReg->cMaxInstances),
|
---|
[22277] | 298 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 299 | AssertMsgReturn(pReg->cbInstance <= _1M,
|
---|
[26166] | 300 | ("%s: %#x\n", pReg->szName, pReg->cbInstance),
|
---|
[22277] | 301 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 302 | AssertMsgReturn(VALID_PTR(pReg->pfnConstruct),
|
---|
[26166] | 303 | ("%s: %p\n", pReg->szName, pReg->pfnConstruct),
|
---|
[22277] | 304 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 305 | AssertMsgReturn(VALID_PTR(pReg->pfnRelocate) || !(pReg->fFlags & PDM_DRVREG_FLAGS_RC),
|
---|
[26166] | 306 | ("%s: %#x\n", pReg->szName, pReg->cbInstance),
|
---|
[22277] | 307 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 308 | AssertMsgReturn(pReg->pfnSoftReset == NULL,
|
---|
[26166] | 309 | ("%s: %p\n", pReg->szName, pReg->pfnSoftReset),
|
---|
[22277] | 310 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[26161] | 311 | AssertMsgReturn(pReg->u32VersionEnd == PDM_DRVREG_VERSION,
|
---|
[26166] | 312 | ("%s: #x\n", pReg->szName, pReg->u32VersionEnd),
|
---|
[25893] | 313 | VERR_PDM_INVALID_DRIVER_REGISTRATION);
|
---|
[1] | 314 |
|
---|
| 315 | /*
|
---|
| 316 | * Check for duplicate and find FIFO entry at the same time.
|
---|
| 317 | */
|
---|
| 318 | PCPDMDRVREGCBINT pRegCB = (PCPDMDRVREGCBINT)pCallbacks;
|
---|
| 319 | PPDMDRV pDrvPrev = NULL;
|
---|
| 320 | PPDMDRV pDrv = pRegCB->pVM->pdm.s.pDrvs;
|
---|
| 321 | for (; pDrv; pDrvPrev = pDrv, pDrv = pDrv->pNext)
|
---|
| 322 | {
|
---|
[26166] | 323 | if (!strcmp(pDrv->pReg->szName, pReg->szName))
|
---|
[1] | 324 | {
|
---|
[26166] | 325 | AssertMsgFailed(("Driver '%s' already exists\n", pReg->szName));
|
---|
[1] | 326 | return VERR_PDM_DRIVER_NAME_CLASH;
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | /*
|
---|
| 331 | * Allocate new driver structure and insert it into the list.
|
---|
| 332 | */
|
---|
[34241] | 333 | int rc;
|
---|
[1] | 334 | pDrv = (PPDMDRV)MMR3HeapAlloc(pRegCB->pVM, MM_TAG_PDM_DRIVER, sizeof(*pDrv));
|
---|
| 335 | if (pDrv)
|
---|
| 336 | {
|
---|
[34241] | 337 | pDrv->pNext = NULL;
|
---|
| 338 | pDrv->cInstances = 0;
|
---|
[25401] | 339 | pDrv->iNextInstance = 0;
|
---|
[34241] | 340 | pDrv->pReg = pReg;
|
---|
| 341 | rc = CFGMR3QueryStringAllocDef( pRegCB->pCfgNode, "RCSearchPath", &pDrv->pszRCSearchPath, NULL);
|
---|
| 342 | if (RT_SUCCESS(rc))
|
---|
| 343 | rc = CFGMR3QueryStringAllocDef(pRegCB->pCfgNode, "R0SearchPath", &pDrv->pszR0SearchPath, NULL);
|
---|
| 344 | if (RT_SUCCESS(rc))
|
---|
| 345 | {
|
---|
| 346 | if (pDrvPrev)
|
---|
| 347 | pDrvPrev->pNext = pDrv;
|
---|
| 348 | else
|
---|
| 349 | pRegCB->pVM->pdm.s.pDrvs = pDrv;
|
---|
| 350 | Log(("PDM: Registered driver '%s'\n", pReg->szName));
|
---|
| 351 | return VINF_SUCCESS;
|
---|
| 352 | }
|
---|
| 353 | MMR3HeapFree(pDrv);
|
---|
[1] | 354 | }
|
---|
[34241] | 355 | else
|
---|
| 356 | rc = VERR_NO_MEMORY;
|
---|
| 357 | return rc;
|
---|
[1] | 358 | }
|
---|
| 359 |
|
---|
| 360 |
|
---|
| 361 | /**
|
---|
| 362 | * Lookups a driver structure by name.
|
---|
| 363 | * @internal
|
---|
| 364 | */
|
---|
| 365 | PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName)
|
---|
| 366 | {
|
---|
| 367 | for (PPDMDRV pDrv = pVM->pdm.s.pDrvs; pDrv; pDrv = pDrv->pNext)
|
---|
[26166] | 368 | if (!strcmp(pDrv->pReg->szName, pszName))
|
---|
[1] | 369 | return pDrv;
|
---|
| 370 | return NULL;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 |
|
---|
| 374 | /**
|
---|
[39839] | 375 | * Transforms the driver chain as it's being instantiated.
|
---|
| 376 | *
|
---|
| 377 | * Worker for pdmR3DrvInstantiate.
|
---|
| 378 | *
|
---|
| 379 | * @returns VBox status code.
|
---|
[41783] | 380 | * @param pVM Pointer to the VM.
|
---|
[39839] | 381 | * @param pDrvAbove The driver above, NULL if top.
|
---|
| 382 | * @param pLun The LUN.
|
---|
| 383 | * @param ppNode The AttachedDriver node, replaced if any
|
---|
| 384 | * morphing took place.
|
---|
| 385 | */
|
---|
| 386 | static int pdmR3DrvMaybeTransformChain(PVM pVM, PPDMDRVINS pDrvAbove, PPDMLUN pLun, PCFGMNODE *ppNode)
|
---|
| 387 | {
|
---|
| 388 | /*
|
---|
| 389 | * The typical state of affairs is that there are no injections.
|
---|
| 390 | */
|
---|
| 391 | PCFGMNODE pCurTrans = CFGMR3GetFirstChild(CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM/DriverTransformations"));
|
---|
| 392 | if (!pCurTrans)
|
---|
| 393 | return VINF_SUCCESS;
|
---|
| 394 |
|
---|
| 395 | /*
|
---|
| 396 | * Gather the attributes used in the matching process.
|
---|
| 397 | */
|
---|
[42138] | 398 | const char *pszDevice = pLun->pDevIns
|
---|
[42141] | 399 | ? pLun->pDevIns->Internal.s.pDevR3->pReg->szName
|
---|
| 400 | : pLun->pUsbIns->Internal.s.pUsbDev->pReg->szName;
|
---|
[39839] | 401 | char szLun[32];
|
---|
| 402 | RTStrPrintf(szLun, sizeof(szLun), "%u", pLun->iLun);
|
---|
| 403 | const char *pszAbove = pDrvAbove ? pDrvAbove->Internal.s.pDrv->pReg->szName : "<top>";
|
---|
| 404 | char *pszThisDrv;
|
---|
| 405 | int rc = CFGMR3QueryStringAlloc(*ppNode, "Driver", &pszThisDrv);
|
---|
| 406 | AssertMsgRCReturn(rc, ("Query for string value of \"Driver\" -> %Rrc\n", rc),
|
---|
| 407 | rc == VERR_CFGM_VALUE_NOT_FOUND ? VERR_PDM_CFG_MISSING_DRIVER_NAME : rc);
|
---|
| 408 |
|
---|
[39854] | 409 | uint64_t uInjectTransformationAbove = 0;
|
---|
| 410 | if (pDrvAbove)
|
---|
| 411 | {
|
---|
| 412 | rc = CFGMR3QueryIntegerDef(CFGMR3GetParent(*ppNode), "InjectTransformationPtr", &uInjectTransformationAbove, 0);
|
---|
| 413 | AssertLogRelRCReturn(rc, rc);
|
---|
| 414 | }
|
---|
[39839] | 415 |
|
---|
[39854] | 416 |
|
---|
[39839] | 417 | /*
|
---|
| 418 | * Enumerate possible driver chain transformations.
|
---|
| 419 | */
|
---|
[39854] | 420 | unsigned cTransformations = 0;
|
---|
[39839] | 421 | for (; pCurTrans != NULL; pCurTrans = CFGMR3GetNextChild(pCurTrans))
|
---|
| 422 | {
|
---|
[39854] | 423 | char szCurTransNm[256];
|
---|
| 424 | rc = CFGMR3GetName(pCurTrans, szCurTransNm, sizeof(szCurTransNm));
|
---|
| 425 | AssertLogRelRCReturn(rc, rc);
|
---|
| 426 |
|
---|
[39839] | 427 | /* Match against the driver multi pattern. */
|
---|
| 428 | char *pszMultiPat;
|
---|
| 429 | rc = CFGMR3QueryStringAllocDef(pCurTrans, "Driver", &pszMultiPat, "*");
|
---|
| 430 | AssertLogRelRCReturn(rc, rc);
|
---|
| 431 | bool fMatch = RTStrSimplePatternMultiMatch(pszMultiPat, RTSTR_MAX, pszDevice, RTSTR_MAX, NULL);
|
---|
| 432 | MMR3HeapFree(pszMultiPat);
|
---|
| 433 | if (!fMatch)
|
---|
| 434 | continue;
|
---|
| 435 |
|
---|
| 436 | /* Match against the lun multi pattern. */
|
---|
| 437 | rc = CFGMR3QueryStringAllocDef(pCurTrans, "LUN", &pszMultiPat, "*");
|
---|
| 438 | AssertLogRelRCReturn(rc, rc);
|
---|
| 439 | fMatch = RTStrSimplePatternMultiMatch(pszMultiPat, RTSTR_MAX, szLun, RTSTR_MAX, NULL);
|
---|
| 440 | MMR3HeapFree(pszMultiPat);
|
---|
| 441 | if (!fMatch)
|
---|
| 442 | continue;
|
---|
| 443 |
|
---|
| 444 | /* Match against the below-driver multi pattern. */
|
---|
| 445 | rc = CFGMR3QueryStringAllocDef(pCurTrans, "BelowDriver", &pszMultiPat, "*");
|
---|
| 446 | AssertLogRelRCReturn(rc, rc);
|
---|
| 447 | fMatch = RTStrSimplePatternMultiMatch(pszMultiPat, RTSTR_MAX, pszAbove, RTSTR_MAX, NULL);
|
---|
| 448 | MMR3HeapFree(pszMultiPat);
|
---|
| 449 | if (!fMatch)
|
---|
| 450 | continue;
|
---|
| 451 |
|
---|
| 452 | /* Match against the above-driver multi pattern. */
|
---|
[39854] | 453 | rc = CFGMR3QueryStringAlloc(pCurTrans, "AboveDriver", &pszMultiPat);
|
---|
| 454 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
| 455 | rc = VINF_SUCCESS;
|
---|
| 456 | else
|
---|
| 457 | {
|
---|
| 458 | AssertLogRelRCReturn(rc, rc);
|
---|
| 459 | fMatch = RTStrSimplePatternMultiMatch(pszMultiPat, RTSTR_MAX, pszThisDrv, RTSTR_MAX, NULL);
|
---|
| 460 | MMR3HeapFree(pszMultiPat);
|
---|
| 461 | if (!fMatch)
|
---|
| 462 | continue;
|
---|
| 463 | if (uInjectTransformationAbove == (uintptr_t)pCurTrans)
|
---|
| 464 | continue;
|
---|
| 465 | }
|
---|
[39839] | 466 |
|
---|
| 467 | /*
|
---|
| 468 | * We've got a match! Now, what are we supposed to do?
|
---|
| 469 | */
|
---|
| 470 | char szAction[16];
|
---|
| 471 | rc = CFGMR3QueryStringDef(pCurTrans, "Action", szAction, sizeof(szAction), "inject");
|
---|
| 472 | AssertLogRelRCReturn(rc, rc);
|
---|
| 473 | AssertLogRelMsgReturn( !strcmp(szAction, "inject")
|
---|
[39854] | 474 | || !strcmp(szAction, "mergeconfig")
|
---|
| 475 | || !strcmp(szAction, "remove")
|
---|
| 476 | || !strcmp(szAction, "removetree")
|
---|
[39839] | 477 | || !strcmp(szAction, "replace")
|
---|
[39854] | 478 | || !strcmp(szAction, "replacetree")
|
---|
| 479 | ,
|
---|
| 480 | ("Action='%s', valid values are 'inject', 'mergeconfig', 'replace', 'replacetree', 'remove', 'removetree'.\n", szAction),
|
---|
[39839] | 481 | VERR_PDM_MISCONFIGURED_DRV_TRANSFORMATION);
|
---|
[39854] | 482 | LogRel(("Applying '%s' to '%s'::[%s]...'%s': %s\n", szCurTransNm, pszDevice, szLun, pszThisDrv, szAction));
|
---|
| 483 | CFGMR3Dump(*ppNode);
|
---|
| 484 | CFGMR3Dump(pCurTrans);
|
---|
[39839] | 485 |
|
---|
| 486 | /* Get the attached driver to inject. */
|
---|
| 487 | PCFGMNODE pTransAttDrv = NULL;
|
---|
[39854] | 488 | if (!strcmp(szAction, "inject") || !strcmp(szAction, "replace") || !strcmp(szAction, "replacetree"))
|
---|
[39839] | 489 | {
|
---|
| 490 | pTransAttDrv = CFGMR3GetChild(pCurTrans, "AttachedDriver");
|
---|
| 491 | AssertLogRelMsgReturn(pTransAttDrv,
|
---|
| 492 | ("An %s transformation requires an AttachedDriver child node!\n", szAction),
|
---|
| 493 | VERR_PDM_MISCONFIGURED_DRV_TRANSFORMATION);
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 |
|
---|
| 497 | /*
|
---|
| 498 | * Remove the node.
|
---|
| 499 | */
|
---|
[39854] | 500 | if (!strcmp(szAction, "remove") || !strcmp(szAction, "removetree"))
|
---|
[39839] | 501 | {
|
---|
| 502 | PCFGMNODE pBelowThis = CFGMR3GetChild(*ppNode, "AttachedDriver");
|
---|
[39854] | 503 | if (!pBelowThis || !strcmp(szAction, "removetree"))
|
---|
[39839] | 504 | {
|
---|
[39854] | 505 | CFGMR3RemoveNode(*ppNode);
|
---|
| 506 | *ppNode = NULL;
|
---|
| 507 | }
|
---|
| 508 | else
|
---|
| 509 | {
|
---|
| 510 | PCFGMNODE pBelowThisCopy;
|
---|
| 511 | rc = CFGMR3DuplicateSubTree(pBelowThis, &pBelowThisCopy);
|
---|
| 512 | AssertLogRelRCReturn(rc, rc);
|
---|
[39839] | 513 |
|
---|
| 514 | rc = CFGMR3ReplaceSubTree(*ppNode, pBelowThisCopy);
|
---|
| 515 | if (RT_FAILURE(rc))
|
---|
| 516 | {
|
---|
| 517 | CFGMR3RemoveNode(pBelowThis);
|
---|
| 518 | AssertLogRelReturn(("rc=%Rrc\n", rc), rc);
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 | }
|
---|
| 522 | /*
|
---|
| 523 | * Replace the driver about to be instantiated.
|
---|
| 524 | */
|
---|
[39854] | 525 | else if (!strcmp(szAction, "replace") || !strcmp(szAction, "replacetree"))
|
---|
[39839] | 526 | {
|
---|
[39854] | 527 | PCFGMNODE pTransCopy;
|
---|
| 528 | rc = CFGMR3DuplicateSubTree(pTransAttDrv, &pTransCopy);
|
---|
| 529 | AssertLogRelRCReturn(rc, rc);
|
---|
[39839] | 530 |
|
---|
| 531 | PCFGMNODE pBelowThis = CFGMR3GetChild(*ppNode, "AttachedDriver");
|
---|
[39854] | 532 | if (!pBelowThis || !strcmp(szAction, "replacetree"))
|
---|
[39839] | 533 | rc = VINF_SUCCESS;
|
---|
| 534 | else
|
---|
| 535 | {
|
---|
[39854] | 536 | PCFGMNODE pBelowThisCopy;
|
---|
| 537 | rc = CFGMR3DuplicateSubTree(pBelowThis, &pBelowThisCopy);
|
---|
| 538 | if (RT_SUCCESS(rc))
|
---|
[39839] | 539 | {
|
---|
| 540 | rc = CFGMR3InsertSubTree(pTransCopy, "AttachedDriver", pBelowThisCopy, NULL);
|
---|
| 541 | AssertLogRelRC(rc);
|
---|
| 542 | if (RT_FAILURE(rc))
|
---|
| 543 | CFGMR3RemoveNode(pBelowThisCopy);
|
---|
| 544 | }
|
---|
| 545 | }
|
---|
| 546 | if (RT_SUCCESS(rc))
|
---|
| 547 | rc = CFGMR3ReplaceSubTree(*ppNode, pTransCopy);
|
---|
| 548 | if (RT_FAILURE(rc))
|
---|
| 549 | CFGMR3RemoveNode(pTransCopy);
|
---|
| 550 | }
|
---|
| 551 | /*
|
---|
| 552 | * Inject a driver before the driver about to be instantiated.
|
---|
| 553 | */
|
---|
| 554 | else if (!strcmp(szAction, "inject"))
|
---|
| 555 | {
|
---|
[39854] | 556 | PCFGMNODE pTransCopy;
|
---|
| 557 | rc = CFGMR3DuplicateSubTree(pTransAttDrv, &pTransCopy);
|
---|
| 558 | AssertLogRelRCReturn(rc, rc);
|
---|
[39839] | 559 |
|
---|
[39854] | 560 | PCFGMNODE pThisCopy;
|
---|
| 561 | rc = CFGMR3DuplicateSubTree(*ppNode, &pThisCopy);
|
---|
| 562 | if (RT_SUCCESS(rc))
|
---|
[39839] | 563 | {
|
---|
| 564 | rc = CFGMR3InsertSubTree(pTransCopy, "AttachedDriver", pThisCopy, NULL);
|
---|
[39854] | 565 | if (RT_SUCCESS(rc))
|
---|
| 566 | {
|
---|
| 567 | rc = CFGMR3InsertInteger(pTransCopy, "InjectTransformationPtr", (uintptr_t)pCurTrans);
|
---|
| 568 | AssertLogRelRC(rc);
|
---|
| 569 | rc = CFGMR3InsertString(pTransCopy, "InjectTransformationNm", szCurTransNm);
|
---|
| 570 | AssertLogRelRC(rc);
|
---|
| 571 | if (RT_SUCCESS(rc))
|
---|
| 572 | rc = CFGMR3ReplaceSubTree(*ppNode, pTransCopy);
|
---|
| 573 | }
|
---|
| 574 | else
|
---|
| 575 | {
|
---|
| 576 | AssertLogRelRC(rc);
|
---|
[39839] | 577 | CFGMR3RemoveNode(pThisCopy);
|
---|
[39854] | 578 | }
|
---|
[39839] | 579 | }
|
---|
| 580 | if (RT_FAILURE(rc))
|
---|
| 581 | CFGMR3RemoveNode(pTransCopy);
|
---|
| 582 | }
|
---|
[39854] | 583 | /*
|
---|
| 584 | * Merge the Config node of the transformation with the one of the
|
---|
| 585 | * current driver.
|
---|
| 586 | */
|
---|
| 587 | else if (!strcmp(szAction, "mergeconfig"))
|
---|
| 588 | {
|
---|
| 589 | PCFGMNODE pTransConfig = CFGMR3GetChild(pCurTrans, "Config");
|
---|
| 590 | AssertLogRelReturn(pTransConfig, VERR_PDM_MISCONFIGURED_DRV_TRANSFORMATION);
|
---|
| 591 |
|
---|
| 592 | PCFGMNODE pDrvConfig = CFGMR3GetChild(*ppNode, "Config");
|
---|
| 593 | if (*ppNode)
|
---|
| 594 | CFGMR3InsertNode(*ppNode, "Config", &pDrvConfig);
|
---|
| 595 | AssertLogRelReturn(pDrvConfig, VERR_PDM_CANNOT_TRANSFORM_REMOVED_DRIVER);
|
---|
| 596 |
|
---|
[39858] | 597 | rc = CFGMR3CopyTree(pDrvConfig, pTransConfig, CFGM_COPY_FLAGS_REPLACE_VALUES | CFGM_COPY_FLAGS_MERGE_KEYS);
|
---|
[39854] | 598 | AssertLogRelRCReturn(rc, rc);
|
---|
| 599 | }
|
---|
[39839] | 600 | else
|
---|
| 601 | AssertFailed();
|
---|
[39854] | 602 |
|
---|
| 603 | cTransformations++;
|
---|
| 604 | if (*ppNode)
|
---|
| 605 | CFGMR3Dump(*ppNode);
|
---|
| 606 | else
|
---|
| 607 | LogRel(("The transformation removed the driver.\n"));
|
---|
[39839] | 608 | }
|
---|
| 609 |
|
---|
[39854] | 610 | /*
|
---|
| 611 | * Note what happened in the release log.
|
---|
| 612 | */
|
---|
| 613 | if (cTransformations > 0)
|
---|
| 614 | LogRel(("Transformations done. Applied %u driver transformations.\n", cTransformations));
|
---|
| 615 |
|
---|
[39839] | 616 | return rc;
|
---|
| 617 | }
|
---|
| 618 |
|
---|
| 619 |
|
---|
| 620 | /**
|
---|
[25891] | 621 | * Instantiate a driver.
|
---|
| 622 | *
|
---|
| 623 | * @returns VBox status code, including informational statuses.
|
---|
| 624 | *
|
---|
[41783] | 625 | * @param pVM Pointer to the VM.
|
---|
[25891] | 626 | * @param pNode The CFGM node for the driver.
|
---|
| 627 | * @param pBaseInterface The base interface.
|
---|
| 628 | * @param pDrvAbove The driver above it. NULL if it's the top-most
|
---|
| 629 | * driver.
|
---|
| 630 | * @param pLun The LUN the driver is being attached to. NULL
|
---|
| 631 | * if we're instantiating a driver chain before
|
---|
| 632 | * attaching it - untested.
|
---|
| 633 | * @param ppBaseInterface Where to return the pointer to the base
|
---|
| 634 | * interface of the newly created driver.
|
---|
| 635 | *
|
---|
| 636 | * @remarks Recursive calls to this function is normal as the drivers will
|
---|
| 637 | * attach to anything below them during the pfnContruct call.
|
---|
[39854] | 638 | *
|
---|
| 639 | * @todo Need to extend this interface a bit so that the driver
|
---|
| 640 | * transformation feature can attach drivers to unconfigured LUNs and
|
---|
| 641 | * at the end of chains.
|
---|
[25891] | 642 | */
|
---|
| 643 | int pdmR3DrvInstantiate(PVM pVM, PCFGMNODE pNode, PPDMIBASE pBaseInterface, PPDMDRVINS pDrvAbove,
|
---|
| 644 | PPDMLUN pLun, PPDMIBASE *ppBaseInterface)
|
---|
| 645 | {
|
---|
| 646 | Assert(!pDrvAbove || !pDrvAbove->Internal.s.pDown);
|
---|
| 647 | Assert(!pDrvAbove || !pDrvAbove->pDownBase);
|
---|
| 648 |
|
---|
[25966] | 649 | Assert(pBaseInterface->pfnQueryInterface(pBaseInterface, PDMIBASE_IID) == pBaseInterface);
|
---|
| 650 |
|
---|
[25891] | 651 | /*
|
---|
[39839] | 652 | * Do driver chain injections
|
---|
| 653 | */
|
---|
| 654 | int rc = pdmR3DrvMaybeTransformChain(pVM, pDrvAbove, pLun, &pNode);
|
---|
| 655 | if (RT_FAILURE(rc))
|
---|
| 656 | return rc;
|
---|
[39854] | 657 | if (!pNode)
|
---|
| 658 | return VERR_PDM_NO_ATTACHED_DRIVER;
|
---|
[39839] | 659 |
|
---|
| 660 | /*
|
---|
[25891] | 661 | * Find the driver.
|
---|
| 662 | */
|
---|
| 663 | char *pszName;
|
---|
[39839] | 664 | rc = CFGMR3QueryStringAlloc(pNode, "Driver", &pszName);
|
---|
[25891] | 665 | if (RT_SUCCESS(rc))
|
---|
| 666 | {
|
---|
| 667 | PPDMDRV pDrv = pdmR3DrvLookup(pVM, pszName);
|
---|
| 668 | if ( pDrv
|
---|
[26161] | 669 | && pDrv->cInstances < pDrv->pReg->cMaxInstances)
|
---|
[25891] | 670 | {
|
---|
| 671 | /* config node */
|
---|
| 672 | PCFGMNODE pConfigNode = CFGMR3GetChild(pNode, "Config");
|
---|
| 673 | if (!pConfigNode)
|
---|
| 674 | rc = CFGMR3InsertNode(pNode, "Config", &pConfigNode);
|
---|
| 675 | if (RT_SUCCESS(rc))
|
---|
| 676 | {
|
---|
| 677 | CFGMR3SetRestrictedRoot(pConfigNode);
|
---|
| 678 |
|
---|
| 679 | /*
|
---|
| 680 | * Allocate the driver instance.
|
---|
| 681 | */
|
---|
[26161] | 682 | size_t cb = RT_OFFSETOF(PDMDRVINS, achInstanceData[pDrv->pReg->cbInstance]);
|
---|
[25891] | 683 | cb = RT_ALIGN_Z(cb, 16);
|
---|
[26161] | 684 | bool const fHyperHeap = !!(pDrv->pReg->fFlags & (PDM_DRVREG_FLAGS_R0 | PDM_DRVREG_FLAGS_RC));
|
---|
[25891] | 685 | PPDMDRVINS pNew;
|
---|
| 686 | if (fHyperHeap)
|
---|
| 687 | rc = MMHyperAlloc(pVM, cb, 64, MM_TAG_PDM_DRIVER, (void **)&pNew);
|
---|
| 688 | else
|
---|
| 689 | rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_DRIVER, cb, (void **)&pNew);
|
---|
| 690 | if (pNew)
|
---|
| 691 | {
|
---|
| 692 | /*
|
---|
| 693 | * Initialize the instance structure (declaration order).
|
---|
| 694 | */
|
---|
| 695 | pNew->u32Version = PDM_DRVINS_VERSION;
|
---|
[40920] | 696 | pNew->iInstance = pDrv->iNextInstance;
|
---|
[25891] | 697 | pNew->Internal.s.pUp = pDrvAbove ? pDrvAbove : NULL;
|
---|
| 698 | //pNew->Internal.s.pDown = NULL;
|
---|
| 699 | pNew->Internal.s.pLun = pLun;
|
---|
| 700 | pNew->Internal.s.pDrv = pDrv;
|
---|
| 701 | pNew->Internal.s.pVMR3 = pVM;
|
---|
[26161] | 702 | pNew->Internal.s.pVMR0 = pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_R0 ? pVM->pVMR0 : NIL_RTR0PTR;
|
---|
| 703 | pNew->Internal.s.pVMRC = pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_RC ? pVM->pVMRC : NIL_RTRCPTR;
|
---|
[25891] | 704 | //pNew->Internal.s.fDetaching = false;
|
---|
[48890] | 705 | pNew->Internal.s.fVMSuspended = true; /** @todo: should be 'false', if driver is attached at runtime. */
|
---|
[25891] | 706 | //pNew->Internal.s.fVMReset = false;
|
---|
| 707 | pNew->Internal.s.fHyperHeap = fHyperHeap;
|
---|
| 708 | //pNew->Internal.s.pfnAsyncNotify = NULL;
|
---|
| 709 | pNew->Internal.s.pCfgHandle = pNode;
|
---|
[26169] | 710 | pNew->pReg = pDrv->pReg;
|
---|
[26172] | 711 | pNew->pCfg = pConfigNode;
|
---|
[25891] | 712 | pNew->pUpBase = pBaseInterface;
|
---|
| 713 | Assert(!pDrvAbove || pBaseInterface == &pDrvAbove->IBase);
|
---|
| 714 | //pNew->pDownBase = NULL;
|
---|
| 715 | //pNew->IBase.pfnQueryInterface = NULL;
|
---|
[40920] | 716 | //pNew->fTracing = 0;
|
---|
| 717 | pNew->idTracing = ++pVM->pdm.s.idTracingOther;
|
---|
[26169] | 718 | pNew->pHlpR3 = &g_pdmR3DrvHlp;
|
---|
[25891] | 719 | pNew->pvInstanceDataR3 = &pNew->achInstanceData[0];
|
---|
[26161] | 720 | if (pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
|
---|
[25891] | 721 | {
|
---|
| 722 | pNew->pvInstanceDataR0 = MMHyperR3ToR0(pVM, &pNew->achInstanceData[0]);
|
---|
[26168] | 723 | rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0DrvHlp", &pNew->pHlpR0);
|
---|
[25891] | 724 | AssertReleaseRCReturn(rc, rc);
|
---|
| 725 | }
|
---|
[45808] | 726 | if ( (pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
|
---|
| 727 | && !HMIsEnabled(pVM))
|
---|
[25891] | 728 | {
|
---|
| 729 | pNew->pvInstanceDataR0 = MMHyperR3ToRC(pVM, &pNew->achInstanceData[0]);
|
---|
[26168] | 730 | rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCDrvHlp", &pNew->pHlpRC);
|
---|
[25891] | 731 | AssertReleaseRCReturn(rc, rc);
|
---|
| 732 | }
|
---|
| 733 |
|
---|
| 734 | pDrv->iNextInstance++;
|
---|
| 735 | pDrv->cInstances++;
|
---|
| 736 |
|
---|
| 737 | /*
|
---|
| 738 | * Link with it with the driver above / LUN.
|
---|
| 739 | */
|
---|
| 740 | if (pDrvAbove)
|
---|
| 741 | {
|
---|
| 742 | pDrvAbove->pDownBase = &pNew->IBase;
|
---|
| 743 | pDrvAbove->Internal.s.pDown = pNew;
|
---|
| 744 | }
|
---|
| 745 | else if (pLun)
|
---|
| 746 | pLun->pTop = pNew;
|
---|
| 747 | if (pLun)
|
---|
| 748 | pLun->pBottom = pNew;
|
---|
| 749 |
|
---|
| 750 | /*
|
---|
| 751 | * Invoke the constructor.
|
---|
| 752 | */
|
---|
[26172] | 753 | rc = pDrv->pReg->pfnConstruct(pNew, pNew->pCfg, 0 /*fFlags*/);
|
---|
[25891] | 754 | if (RT_SUCCESS(rc))
|
---|
| 755 | {
|
---|
| 756 | AssertPtr(pNew->IBase.pfnQueryInterface);
|
---|
[25966] | 757 | Assert(pNew->IBase.pfnQueryInterface(&pNew->IBase, PDMIBASE_IID) == &pNew->IBase);
|
---|
[25891] | 758 |
|
---|
| 759 | /* Success! */
|
---|
| 760 | *ppBaseInterface = &pNew->IBase;
|
---|
| 761 | if (pLun)
|
---|
| 762 | Log(("PDM: Attached driver %p:'%s'/%d to LUN#%d on device '%s'/%d, pDrvAbove=%p:'%s'/%d\n",
|
---|
[26166] | 763 | pNew, pDrv->pReg->szName, pNew->iInstance,
|
---|
[26112] | 764 | pLun->iLun,
|
---|
[26165] | 765 | pLun->pDevIns ? pLun->pDevIns->pReg->szName : pLun->pUsbIns->pReg->szName,
|
---|
[26264] | 766 | pLun->pDevIns ? pLun->pDevIns->iInstance : pLun->pUsbIns->iInstance,
|
---|
| 767 | pDrvAbove, pDrvAbove ? pDrvAbove->pReg->szName : "", pDrvAbove ? pDrvAbove->iInstance : UINT32_MAX));
|
---|
[25891] | 768 | else
|
---|
| 769 | Log(("PDM: Attached driver %p:'%s'/%d, pDrvAbove=%p:'%s'/%d\n",
|
---|
[26166] | 770 | pNew, pDrv->pReg->szName, pNew->iInstance,
|
---|
[26264] | 771 | pDrvAbove, pDrvAbove ? pDrvAbove->pReg->szName : "", pDrvAbove ? pDrvAbove->iInstance : UINT32_MAX));
|
---|
[25891] | 772 | }
|
---|
| 773 | else
|
---|
[35810] | 774 | {
|
---|
[25891] | 775 | pdmR3DrvDestroyChain(pNew, PDM_TACH_FLAGS_NO_CALLBACKS);
|
---|
[35810] | 776 | if (rc == VERR_VERSION_MISMATCH)
|
---|
| 777 | rc = VERR_PDM_DRIVER_VERSION_MISMATCH;
|
---|
| 778 | }
|
---|
[25891] | 779 | }
|
---|
| 780 | else
|
---|
| 781 | {
|
---|
| 782 | AssertMsgFailed(("Failed to allocate %d bytes for instantiating driver '%s'\n", cb, pszName));
|
---|
| 783 | rc = VERR_NO_MEMORY;
|
---|
| 784 | }
|
---|
| 785 | }
|
---|
| 786 | else
|
---|
| 787 | AssertMsgFailed(("Failed to create Config node! rc=%Rrc\n", rc));
|
---|
| 788 | }
|
---|
| 789 | else if (pDrv)
|
---|
| 790 | {
|
---|
[26161] | 791 | AssertMsgFailed(("Too many instances of driver '%s', max is %u\n", pszName, pDrv->pReg->cMaxInstances));
|
---|
[25891] | 792 | rc = VERR_PDM_TOO_MANY_DRIVER_INSTANCES;
|
---|
| 793 | }
|
---|
| 794 | else
|
---|
| 795 | {
|
---|
| 796 | AssertMsgFailed(("Driver '%s' wasn't found!\n", pszName));
|
---|
| 797 | rc = VERR_PDM_DRIVER_NOT_FOUND;
|
---|
| 798 | }
|
---|
[40274] | 799 | MMR3HeapFree(pszName);
|
---|
[25891] | 800 | }
|
---|
| 801 | else
|
---|
| 802 | {
|
---|
| 803 | if (rc == VERR_CFGM_VALUE_NOT_FOUND)
|
---|
| 804 | rc = VERR_PDM_CFG_MISSING_DRIVER_NAME;
|
---|
[43037] | 805 | else
|
---|
| 806 | AssertMsgFailed(("Query for string value of \"Driver\" -> %Rrc\n", rc));
|
---|
[25891] | 807 | }
|
---|
| 808 | return rc;
|
---|
| 809 | }
|
---|
| 810 |
|
---|
| 811 |
|
---|
| 812 | /**
|
---|
[1] | 813 | * Detaches a driver from whatever it's attached to.
|
---|
| 814 | * This will of course lead to the destruction of the driver and all drivers below it in the chain.
|
---|
| 815 | *
|
---|
| 816 | * @returns VINF_SUCCESS
|
---|
| 817 | * @param pDrvIns The driver instance to detach.
|
---|
[21188] | 818 | * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
|
---|
[1] | 819 | */
|
---|
[21188] | 820 | int pdmR3DrvDetach(PPDMDRVINS pDrvIns, uint32_t fFlags)
|
---|
[1] | 821 | {
|
---|
| 822 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[26166] | 823 | LogFlow(("pdmR3DrvDetach: pDrvIns=%p '%s'/%d\n", pDrvIns, pDrvIns->pReg->szName, pDrvIns->iInstance));
|
---|
[25891] | 824 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 825 |
|
---|
| 826 | /*
|
---|
| 827 | * Check that we're not doing this recursively, that could have unwanted sideeffects!
|
---|
| 828 | */
|
---|
| 829 | if (pDrvIns->Internal.s.fDetaching)
|
---|
| 830 | {
|
---|
[26166] | 831 | AssertMsgFailed(("Recursive detach! '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance));
|
---|
[48980] | 832 | return VINF_SUCCESS;
|
---|
| 833 | }
|
---|
[1] | 834 |
|
---|
| 835 | /*
|
---|
| 836 | * Check that we actually can detach this instance.
|
---|
[5722] | 837 | * The requirement is that the driver/device above has a detach method.
|
---|
[1] | 838 | */
|
---|
[42140] | 839 | if ( pDrvIns->Internal.s.pUp
|
---|
[26161] | 840 | ? !pDrvIns->Internal.s.pUp->pReg->pfnDetach
|
---|
[42138] | 841 | : pDrvIns->Internal.s.pLun->pDevIns
|
---|
[42140] | 842 | ? !pDrvIns->Internal.s.pLun->pDevIns->pReg->pfnDetach
|
---|
| 843 | : !pDrvIns->Internal.s.pLun->pUsbIns->pReg->pfnDriverDetach
|
---|
[42138] | 844 | )
|
---|
[1] | 845 | {
|
---|
| 846 | AssertMsgFailed(("Cannot detach driver instance because the driver/device above doesn't support it!\n"));
|
---|
| 847 | return VERR_PDM_DRIVER_DETACH_NOT_POSSIBLE;
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 | /*
|
---|
[5722] | 851 | * Join paths with pdmR3DrvDestroyChain.
|
---|
[1] | 852 | */
|
---|
[21188] | 853 | pdmR3DrvDestroyChain(pDrvIns, fFlags);
|
---|
[5722] | 854 | return VINF_SUCCESS;
|
---|
| 855 | }
|
---|
| 856 |
|
---|
| 857 |
|
---|
| 858 | /**
|
---|
| 859 | * Destroys a driver chain starting with the specified driver.
|
---|
| 860 | *
|
---|
| 861 | * This is used when unplugging a device at run time.
|
---|
| 862 | *
|
---|
| 863 | * @param pDrvIns Pointer to the driver instance to start with.
|
---|
[25891] | 864 | * @param fFlags PDM_TACH_FLAGS_NOT_HOT_PLUG, PDM_TACH_FLAGS_NO_CALLBACKS
|
---|
| 865 | * or 0.
|
---|
[5722] | 866 | */
|
---|
[21188] | 867 | void pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns, uint32_t fFlags)
|
---|
[5722] | 868 | {
|
---|
[25891] | 869 | PVM pVM = pDrvIns->Internal.s.pVMR3;
|
---|
| 870 | VM_ASSERT_EMT(pVM);
|
---|
[5722] | 871 |
|
---|
| 872 | /*
|
---|
| 873 | * Detach the bottommost driver until we've detached pDrvIns.
|
---|
| 874 | */
|
---|
[1] | 875 | pDrvIns->Internal.s.fDetaching = true;
|
---|
| 876 | PPDMDRVINS pCur;
|
---|
| 877 | do
|
---|
| 878 | {
|
---|
| 879 | /* find the driver to detach. */
|
---|
| 880 | pCur = pDrvIns;
|
---|
| 881 | while (pCur->Internal.s.pDown)
|
---|
| 882 | pCur = pCur->Internal.s.pDown;
|
---|
[26166] | 883 | LogFlow(("pdmR3DrvDestroyChain: pCur=%p '%s'/%d\n", pCur, pCur->pReg->szName, pCur->iInstance));
|
---|
[1] | 884 |
|
---|
| 885 | /*
|
---|
| 886 | * Unlink it and notify parent.
|
---|
| 887 | */
|
---|
| 888 | pCur->Internal.s.fDetaching = true;
|
---|
[5722] | 889 |
|
---|
| 890 | PPDMLUN pLun = pCur->Internal.s.pLun;
|
---|
| 891 | Assert(pLun->pBottom == pCur);
|
---|
| 892 | pLun->pBottom = pCur->Internal.s.pUp;
|
---|
| 893 |
|
---|
[1] | 894 | if (pCur->Internal.s.pUp)
|
---|
| 895 | {
|
---|
| 896 | /* driver parent */
|
---|
| 897 | PPDMDRVINS pParent = pCur->Internal.s.pUp;
|
---|
| 898 | pCur->Internal.s.pUp = NULL;
|
---|
| 899 | pParent->Internal.s.pDown = NULL;
|
---|
| 900 |
|
---|
[26161] | 901 | if (!(fFlags & PDM_TACH_FLAGS_NO_CALLBACKS) && pParent->pReg->pfnDetach)
|
---|
| 902 | pParent->pReg->pfnDetach(pParent, fFlags);
|
---|
[1] | 903 |
|
---|
| 904 | pParent->pDownBase = NULL;
|
---|
| 905 | }
|
---|
| 906 | else
|
---|
| 907 | {
|
---|
| 908 | /* device parent */
|
---|
[5722] | 909 | Assert(pLun->pTop == pCur);
|
---|
[1] | 910 | pLun->pTop = NULL;
|
---|
[42138] | 911 | if (!(fFlags & PDM_TACH_FLAGS_NO_CALLBACKS))
|
---|
[38847] | 912 | {
|
---|
[42138] | 913 | if (pLun->pDevIns)
|
---|
| 914 | {
|
---|
[42140] | 915 | if (pLun->pDevIns->pReg->pfnDetach)
|
---|
[42138] | 916 | {
|
---|
| 917 | PDMCritSectEnter(pLun->pDevIns->pCritSectRoR3, VERR_IGNORED);
|
---|
[42140] | 918 | pLun->pDevIns->pReg->pfnDetach(pLun->pDevIns, pLun->iLun, fFlags);
|
---|
[42138] | 919 | PDMCritSectLeave(pLun->pDevIns->pCritSectRoR3);
|
---|
| 920 | }
|
---|
| 921 | }
|
---|
| 922 | else
|
---|
| 923 | {
|
---|
[42140] | 924 | if (pLun->pUsbIns->pReg->pfnDriverDetach)
|
---|
[42138] | 925 | {
|
---|
| 926 | /** @todo USB device locking? */
|
---|
[48980] | 927 | pLun->pUsbIns->pReg->pfnDriverDetach(pLun->pUsbIns, pLun->iLun, fFlags);
|
---|
[42138] | 928 | }
|
---|
| 929 | }
|
---|
[38847] | 930 | }
|
---|
[1] | 931 | }
|
---|
| 932 |
|
---|
| 933 | /*
|
---|
| 934 | * Call destructor.
|
---|
| 935 | */
|
---|
| 936 | pCur->pUpBase = NULL;
|
---|
[26161] | 937 | if (pCur->pReg->pfnDestruct)
|
---|
| 938 | pCur->pReg->pfnDestruct(pCur);
|
---|
[25401] | 939 | pCur->Internal.s.pDrv->cInstances--;
|
---|
[1] | 940 |
|
---|
| 941 | /*
|
---|
| 942 | * Free all resources allocated by the driver.
|
---|
| 943 | */
|
---|
| 944 | /* Queues. */
|
---|
[25891] | 945 | int rc = PDMR3QueueDestroyDriver(pVM, pCur);
|
---|
[1] | 946 | AssertRC(rc);
|
---|
[25891] | 947 |
|
---|
[1] | 948 | /* Timers. */
|
---|
[25891] | 949 | rc = TMR3TimerDestroyDriver(pVM, pCur);
|
---|
[1] | 950 | AssertRC(rc);
|
---|
[25891] | 951 |
|
---|
[3520] | 952 | /* SSM data units. */
|
---|
[25891] | 953 | rc = SSMR3DeregisterDriver(pVM, pCur, NULL, 0);
|
---|
[1] | 954 | AssertRC(rc);
|
---|
[25891] | 955 |
|
---|
[3520] | 956 | /* PDM threads. */
|
---|
[25891] | 957 | rc = pdmR3ThreadDestroyDriver(pVM, pCur);
|
---|
[3520] | 958 | AssertRC(rc);
|
---|
[25891] | 959 |
|
---|
[34207] | 960 | /* Info handlers. */
|
---|
| 961 | rc = DBGFR3InfoDeregisterDriver(pVM, pCur, NULL);
|
---|
| 962 | AssertRC(rc);
|
---|
| 963 |
|
---|
[28258] | 964 | /* PDM critsects. */
|
---|
[45152] | 965 | rc = pdmR3CritSectBothDeleteDriver(pVM, pCur);
|
---|
[28258] | 966 | AssertRC(rc);
|
---|
| 967 |
|
---|
[34219] | 968 | /* Block caches. */
|
---|
| 969 | PDMR3BlkCacheReleaseDriver(pVM, pCur);
|
---|
| 970 |
|
---|
[44358] | 971 | #ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
|
---|
| 972 | /* Completion templates.*/
|
---|
| 973 | pdmR3AsyncCompletionTemplateDestroyDriver(pVM, pCur);
|
---|
| 974 | #endif
|
---|
| 975 |
|
---|
[1] | 976 | /* Finally, the driver it self. */
|
---|
[25891] | 977 | bool fHyperHeap = pCur->Internal.s.fHyperHeap;
|
---|
[26161] | 978 | ASMMemFill32(pCur, RT_OFFSETOF(PDMDRVINS, achInstanceData[pCur->pReg->cbInstance]), 0xdeadd0d0);
|
---|
[25891] | 979 | if (fHyperHeap)
|
---|
| 980 | MMHyperFree(pVM, pCur);
|
---|
| 981 | else
|
---|
| 982 | MMR3HeapFree(pCur);
|
---|
[1] | 983 |
|
---|
| 984 | } while (pCur != pDrvIns);
|
---|
| 985 | }
|
---|
| 986 |
|
---|
| 987 |
|
---|
[12986] | 988 |
|
---|
| 989 |
|
---|
| 990 | /** @name Driver Helpers
|
---|
| 991 | * @{
|
---|
| 992 | */
|
---|
| 993 |
|
---|
[26151] | 994 | /** @interface_method_impl{PDMDRVHLP,pfnAttach} */
|
---|
[22277] | 995 | static DECLCALLBACK(int) pdmR3DrvHlp_Attach(PPDMDRVINS pDrvIns, uint32_t fFlags, PPDMIBASE *ppBaseInterface)
|
---|
[1] | 996 | {
|
---|
| 997 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 998 | PVM pVM = pDrvIns->Internal.s.pVMR3;
|
---|
| 999 | VM_ASSERT_EMT(pVM);
|
---|
[26166] | 1000 | LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: fFlags=%#x\n", pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
|
---|
[22277] | 1001 | Assert(!(fFlags & ~(PDM_TACH_FLAGS_NOT_HOT_PLUG)));
|
---|
[1] | 1002 |
|
---|
| 1003 | /*
|
---|
| 1004 | * Check that there isn't anything attached already.
|
---|
| 1005 | */
|
---|
| 1006 | int rc;
|
---|
| 1007 | if (!pDrvIns->Internal.s.pDown)
|
---|
| 1008 | {
|
---|
[5722] | 1009 | Assert(pDrvIns->Internal.s.pLun->pBottom == pDrvIns);
|
---|
| 1010 |
|
---|
[1] | 1011 | /*
|
---|
| 1012 | * Get the attached driver configuration.
|
---|
| 1013 | */
|
---|
[5722] | 1014 | PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
|
---|
[1] | 1015 | if (pNode)
|
---|
[25891] | 1016 | rc = pdmR3DrvInstantiate(pVM, pNode, &pDrvIns->IBase, pDrvIns, pDrvIns->Internal.s.pLun, ppBaseInterface);
|
---|
[1] | 1017 | else
|
---|
| 1018 | rc = VERR_PDM_NO_ATTACHED_DRIVER;
|
---|
| 1019 | }
|
---|
| 1020 | else
|
---|
| 1021 | {
|
---|
| 1022 | AssertMsgFailed(("Already got a driver attached. The driver should keep track of such things!\n"));
|
---|
| 1023 | rc = VERR_PDM_DRIVER_ALREADY_ATTACHED;
|
---|
| 1024 | }
|
---|
| 1025 |
|
---|
[13818] | 1026 | LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: return %Rrc\n",
|
---|
[26166] | 1027 | pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
[1] | 1028 | return rc;
|
---|
| 1029 | }
|
---|
| 1030 |
|
---|
| 1031 |
|
---|
[26151] | 1032 | /** @interface_method_impl{PDMDRVHLP,pfnDetach} */
|
---|
[22277] | 1033 | static DECLCALLBACK(int) pdmR3DrvHlp_Detach(PPDMDRVINS pDrvIns, uint32_t fFlags)
|
---|
[1] | 1034 | {
|
---|
| 1035 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[22277] | 1036 | LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: fFlags=%#x\n",
|
---|
[26166] | 1037 | pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
|
---|
[25891] | 1038 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1039 |
|
---|
| 1040 | /*
|
---|
| 1041 | * Anything attached?
|
---|
| 1042 | */
|
---|
| 1043 | int rc;
|
---|
| 1044 | if (pDrvIns->Internal.s.pDown)
|
---|
[22277] | 1045 | rc = pdmR3DrvDetach(pDrvIns->Internal.s.pDown, fFlags);
|
---|
[1] | 1046 | else
|
---|
| 1047 | {
|
---|
| 1048 | AssertMsgFailed(("Nothing attached!\n"));
|
---|
| 1049 | rc = VERR_PDM_NO_DRIVER_ATTACHED;
|
---|
| 1050 | }
|
---|
| 1051 |
|
---|
[13818] | 1052 | LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: returns %Rrc\n",
|
---|
[26166] | 1053 | pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
[1] | 1054 | return rc;
|
---|
| 1055 | }
|
---|
| 1056 |
|
---|
| 1057 |
|
---|
[26151] | 1058 | /** @interface_method_impl{PDMDRVHLP,pfnDetachSelf} */
|
---|
[22277] | 1059 | static DECLCALLBACK(int) pdmR3DrvHlp_DetachSelf(PPDMDRVINS pDrvIns, uint32_t fFlags)
|
---|
[1] | 1060 | {
|
---|
| 1061 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[22277] | 1062 | LogFlow(("pdmR3DrvHlp_DetachSelf: caller='%s'/%d: fFlags=%#x\n",
|
---|
[26166] | 1063 | pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
|
---|
[25891] | 1064 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1065 |
|
---|
[22277] | 1066 | int rc = pdmR3DrvDetach(pDrvIns, fFlags);
|
---|
[1] | 1067 |
|
---|
[13818] | 1068 | LogFlow(("pdmR3DrvHlp_Detach: returns %Rrc\n", rc)); /* pDrvIns is freed by now. */
|
---|
[1] | 1069 | return rc;
|
---|
| 1070 | }
|
---|
| 1071 |
|
---|
| 1072 |
|
---|
[26151] | 1073 | /** @interface_method_impl{PDMDRVHLP,pfnMountPrepare} */
|
---|
[1] | 1074 | static DECLCALLBACK(int) pdmR3DrvHlp_MountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver)
|
---|
| 1075 | {
|
---|
| 1076 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1077 | LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: pszFilename=%p:{%s} pszCoreDriver=%p:{%s}\n",
|
---|
[26166] | 1078 | pDrvIns->pReg->szName, pDrvIns->iInstance, pszFilename, pszFilename, pszCoreDriver, pszCoreDriver));
|
---|
[25891] | 1079 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1080 |
|
---|
| 1081 | /*
|
---|
| 1082 | * Do the caller have anything attached below itself?
|
---|
| 1083 | */
|
---|
| 1084 | if (pDrvIns->Internal.s.pDown)
|
---|
| 1085 | {
|
---|
| 1086 | AssertMsgFailed(("Cannot prepare a mount when something's attached to you!\n"));
|
---|
| 1087 | return VERR_PDM_DRIVER_ALREADY_ATTACHED;
|
---|
| 1088 | }
|
---|
| 1089 |
|
---|
| 1090 | /*
|
---|
| 1091 | * We're asked to prepare, so we'll start off by nuking the
|
---|
| 1092 | * attached configuration tree.
|
---|
| 1093 | */
|
---|
| 1094 | PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
|
---|
| 1095 | if (pNode)
|
---|
| 1096 | CFGMR3RemoveNode(pNode);
|
---|
| 1097 |
|
---|
| 1098 | /*
|
---|
| 1099 | * If there is no core driver, we'll have to probe for it.
|
---|
| 1100 | */
|
---|
| 1101 | if (!pszCoreDriver)
|
---|
| 1102 | {
|
---|
| 1103 | /** @todo implement image probing. */
|
---|
| 1104 | AssertReleaseMsgFailed(("Not implemented!\n"));
|
---|
| 1105 | return VERR_NOT_IMPLEMENTED;
|
---|
| 1106 | }
|
---|
| 1107 |
|
---|
| 1108 | /*
|
---|
| 1109 | * Construct the basic attached driver configuration.
|
---|
| 1110 | */
|
---|
| 1111 | int rc = CFGMR3InsertNode(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver", &pNode);
|
---|
[13816] | 1112 | if (RT_SUCCESS(rc))
|
---|
[1] | 1113 | {
|
---|
| 1114 | rc = CFGMR3InsertString(pNode, "Driver", pszCoreDriver);
|
---|
[13816] | 1115 | if (RT_SUCCESS(rc))
|
---|
[1] | 1116 | {
|
---|
| 1117 | PCFGMNODE pCfg;
|
---|
| 1118 | rc = CFGMR3InsertNode(pNode, "Config", &pCfg);
|
---|
[13816] | 1119 | if (RT_SUCCESS(rc))
|
---|
[1] | 1120 | {
|
---|
| 1121 | rc = CFGMR3InsertString(pCfg, "Path", pszFilename);
|
---|
[13816] | 1122 | if (RT_SUCCESS(rc))
|
---|
[1] | 1123 | {
|
---|
[13818] | 1124 | LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc (Driver=%s)\n",
|
---|
[26166] | 1125 | pDrvIns->pReg->szName, pDrvIns->iInstance, rc, pszCoreDriver));
|
---|
[1] | 1126 | return rc;
|
---|
| 1127 | }
|
---|
| 1128 | else
|
---|
[13818] | 1129 | AssertMsgFailed(("Path string insert failed, rc=%Rrc\n", rc));
|
---|
[1] | 1130 | }
|
---|
| 1131 | else
|
---|
[13818] | 1132 | AssertMsgFailed(("Config node failed, rc=%Rrc\n", rc));
|
---|
[1] | 1133 | }
|
---|
| 1134 | else
|
---|
[13818] | 1135 | AssertMsgFailed(("Driver string insert failed, rc=%Rrc\n", rc));
|
---|
[1] | 1136 | CFGMR3RemoveNode(pNode);
|
---|
| 1137 | }
|
---|
| 1138 | else
|
---|
[13818] | 1139 | AssertMsgFailed(("AttachedDriver node insert failed, rc=%Rrc\n", rc));
|
---|
[1] | 1140 |
|
---|
[13818] | 1141 | LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc\n",
|
---|
[26166] | 1142 | pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
[1] | 1143 | return rc;
|
---|
| 1144 | }
|
---|
| 1145 |
|
---|
| 1146 |
|
---|
[26151] | 1147 | /** @interface_method_impl{PDMDRVHLP,pfnAssertEMT} */
|
---|
[1] | 1148 | static DECLCALLBACK(bool) pdmR3DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
|
---|
| 1149 | {
|
---|
| 1150 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1151 | if (VM_IS_EMT(pDrvIns->Internal.s.pVMR3))
|
---|
[1] | 1152 | return true;
|
---|
| 1153 |
|
---|
| 1154 | char szMsg[100];
|
---|
[26166] | 1155 | RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance);
|
---|
[25528] | 1156 | RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
|
---|
[1] | 1157 | AssertBreakpoint();
|
---|
[25891] | 1158 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1159 | return false;
|
---|
| 1160 | }
|
---|
| 1161 |
|
---|
| 1162 |
|
---|
[26151] | 1163 | /** @interface_method_impl{PDMDRVHLP,pfnAssertOther} */
|
---|
[1] | 1164 | static DECLCALLBACK(bool) pdmR3DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
|
---|
| 1165 | {
|
---|
| 1166 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1167 | if (!VM_IS_EMT(pDrvIns->Internal.s.pVMR3))
|
---|
[1] | 1168 | return true;
|
---|
| 1169 |
|
---|
| 1170 | char szMsg[100];
|
---|
[26166] | 1171 | RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance);
|
---|
[25528] | 1172 | RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
|
---|
[1] | 1173 | AssertBreakpoint();
|
---|
[25891] | 1174 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1175 | return false;
|
---|
| 1176 | }
|
---|
| 1177 |
|
---|
| 1178 |
|
---|
[26151] | 1179 | /** @interface_method_impl{PDMDRVHLP,pfnVMSetError} */
|
---|
[1] | 1180 | static DECLCALLBACK(int) pdmR3DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
|
---|
| 1181 | {
|
---|
| 1182 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1183 | va_list args;
|
---|
| 1184 | va_start(args, pszFormat);
|
---|
[25891] | 1185 | int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
|
---|
[1] | 1186 | va_end(args);
|
---|
| 1187 | return rc;
|
---|
| 1188 | }
|
---|
| 1189 |
|
---|
| 1190 |
|
---|
[26151] | 1191 | /** @interface_method_impl{PDMDRVHLP,pfnVMSetErrorV} */
|
---|
[1] | 1192 | static DECLCALLBACK(int) pdmR3DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
|
---|
| 1193 | {
|
---|
| 1194 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1195 | int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
|
---|
[1] | 1196 | return rc;
|
---|
| 1197 | }
|
---|
| 1198 |
|
---|
| 1199 |
|
---|
[26151] | 1200 | /** @interface_method_impl{PDMDRVHLP,pfnVMSetRuntimeError} */
|
---|
[18645] | 1201 | static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
|
---|
[3112] | 1202 | {
|
---|
| 1203 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1204 | va_list args;
|
---|
| 1205 | va_start(args, pszFormat);
|
---|
[25891] | 1206 | int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, args);
|
---|
[3112] | 1207 | va_end(args);
|
---|
| 1208 | return rc;
|
---|
| 1209 | }
|
---|
| 1210 |
|
---|
| 1211 |
|
---|
[26151] | 1212 | /** @interface_method_impl{PDMDRVHLP,pfnVMSetRuntimeErrorV} */
|
---|
[18645] | 1213 | static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
|
---|
[3112] | 1214 | {
|
---|
| 1215 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1216 | int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, va);
|
---|
[3112] | 1217 | return rc;
|
---|
| 1218 | }
|
---|
| 1219 |
|
---|
| 1220 |
|
---|
[26151] | 1221 | /** @interface_method_impl{PDMDEVHLPR3,pfnVMState} */
|
---|
[23915] | 1222 | static DECLCALLBACK(VMSTATE) pdmR3DrvHlp_VMState(PPDMDRVINS pDrvIns)
|
---|
| 1223 | {
|
---|
| 1224 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1225 |
|
---|
[25891] | 1226 | VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVMR3);
|
---|
[23915] | 1227 |
|
---|
[26166] | 1228 | LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
|
---|
[23915] | 1229 | enmVMState, VMR3GetStateName(enmVMState)));
|
---|
| 1230 | return enmVMState;
|
---|
| 1231 | }
|
---|
| 1232 |
|
---|
| 1233 |
|
---|
[26151] | 1234 | /** @interface_method_impl{PDMDEVHLPR3,pfnVMTeleportedAndNotFullyResumedYet} */
|
---|
[23915] | 1235 | static DECLCALLBACK(bool) pdmR3DrvHlp_VMTeleportedAndNotFullyResumedYet(PPDMDRVINS pDrvIns)
|
---|
| 1236 | {
|
---|
| 1237 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1238 |
|
---|
[25891] | 1239 | bool fRc = VMR3TeleportedAndNotFullyResumedYet(pDrvIns->Internal.s.pVMR3);
|
---|
[23915] | 1240 |
|
---|
[26166] | 1241 | LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %RTbool)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
|
---|
[23915] | 1242 | fRc));
|
---|
| 1243 | return fRc;
|
---|
| 1244 | }
|
---|
| 1245 |
|
---|
| 1246 |
|
---|
[28327] | 1247 | /** @interface_method_impl{PDMDEVHLPR3,pfnGetSupDrvSession} */
|
---|
| 1248 | static DECLCALLBACK(PSUPDRVSESSION) pdmR3DrvHlp_GetSupDrvSession(PPDMDRVINS pDrvIns)
|
---|
| 1249 | {
|
---|
| 1250 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1251 |
|
---|
| 1252 | PSUPDRVSESSION pSession = pDrvIns->Internal.s.pVMR3->pSession;
|
---|
| 1253 | LogFlow(("pdmR3DrvHlp_GetSupDrvSession: caller='%s'/%d: returns %p)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
|
---|
| 1254 | pSession));
|
---|
| 1255 | return pSession;
|
---|
| 1256 | }
|
---|
| 1257 |
|
---|
| 1258 |
|
---|
[28258] | 1259 | /** @interface_method_impl{PDMDRVHLP,pfnQueueCreate} */
|
---|
| 1260 | static DECLCALLBACK(int) pdmR3DrvHlp_QueueCreate(PPDMDRVINS pDrvIns, uint32_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
|
---|
| 1261 | PFNPDMQUEUEDRV pfnCallback, const char *pszName, PPDMQUEUE *ppQueue)
|
---|
[1] | 1262 | {
|
---|
| 1263 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[21363] | 1264 | LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: cbItem=%d cItems=%d cMilliesInterval=%d pfnCallback=%p pszName=%p:{%s} ppQueue=%p\n",
|
---|
[26166] | 1265 | pDrvIns->pReg->szName, pDrvIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, pszName, ppQueue, ppQueue));
|
---|
[25891] | 1266 | PVM pVM = pDrvIns->Internal.s.pVMR3;
|
---|
[21363] | 1267 | VM_ASSERT_EMT(pVM);
|
---|
[1] | 1268 |
|
---|
[21363] | 1269 | if (pDrvIns->iInstance > 0)
|
---|
| 1270 | {
|
---|
[21789] | 1271 | pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DRIVER_DESC, "%s_%u", pszName, pDrvIns->iInstance);
|
---|
[21363] | 1272 | AssertLogRelReturn(pszName, VERR_NO_MEMORY);
|
---|
| 1273 | }
|
---|
[1] | 1274 |
|
---|
[21363] | 1275 | int rc = PDMR3QueueCreateDriver(pVM, pDrvIns, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, ppQueue);
|
---|
| 1276 |
|
---|
[26166] | 1277 | LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc, *ppQueue));
|
---|
[1] | 1278 | return rc;
|
---|
| 1279 | }
|
---|
| 1280 |
|
---|
| 1281 |
|
---|
[26151] | 1282 | /** @interface_method_impl{PDMDRVHLP,pfnTMGetVirtualFreq} */
|
---|
[1] | 1283 | static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualFreq(PPDMDRVINS pDrvIns)
|
---|
| 1284 | {
|
---|
| 1285 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1286 |
|
---|
[25891] | 1287 | return TMVirtualGetFreq(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1288 | }
|
---|
| 1289 |
|
---|
| 1290 |
|
---|
[26151] | 1291 | /** @interface_method_impl{PDMDRVHLP,pfnTMGetVirtualTime} */
|
---|
[1] | 1292 | static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualTime(PPDMDRVINS pDrvIns)
|
---|
| 1293 | {
|
---|
| 1294 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1295 |
|
---|
[25891] | 1296 | return TMVirtualGet(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1297 | }
|
---|
| 1298 |
|
---|
[12986] | 1299 |
|
---|
[26151] | 1300 | /** @interface_method_impl{PDMDRVHLP,pfnTMTimerCreate} */
|
---|
[20096] | 1301 | static DECLCALLBACK(int) pdmR3DrvHlp_TMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
|
---|
[1] | 1302 | {
|
---|
| 1303 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[20096] | 1304 | LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pvUser=%p fFlags=%#x pszDesc=%p:{%s} ppTimer=%p\n",
|
---|
[26166] | 1305 | pDrvIns->pReg->szName, pDrvIns->iInstance, enmClock, pfnCallback, pvUser, fFlags, pszDesc, pszDesc, ppTimer));
|
---|
[1] | 1306 |
|
---|
[25891] | 1307 | int rc = TMR3TimerCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
|
---|
[1] | 1308 |
|
---|
[26166] | 1309 | LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: returns %Rrc *ppTimer=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc, *ppTimer));
|
---|
[1] | 1310 | return rc;
|
---|
| 1311 | }
|
---|
| 1312 |
|
---|
| 1313 |
|
---|
| 1314 |
|
---|
[26151] | 1315 | /** @interface_method_impl{PDMDRVHLP,pfnSSMRegister} */
|
---|
[22480] | 1316 | static DECLCALLBACK(int) pdmR3DrvHlp_SSMRegister(PPDMDRVINS pDrvIns, uint32_t uVersion, size_t cbGuess,
|
---|
| 1317 | PFNSSMDRVLIVEPREP pfnLivePrep, PFNSSMDRVLIVEEXEC pfnLiveExec, PFNSSMDRVLIVEVOTE pfnLiveVote,
|
---|
[1] | 1318 | PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
|
---|
| 1319 | PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
|
---|
| 1320 | {
|
---|
| 1321 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1322 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[22480] | 1323 | LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: uVersion=#x cbGuess=%#x \n"
|
---|
| 1324 | " pfnLivePrep=%p pfnLiveExec=%p pfnLiveVote=%p pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoaddone=%p\n",
|
---|
[26166] | 1325 | pDrvIns->pReg->szName, pDrvIns->iInstance, uVersion, cbGuess,
|
---|
[22480] | 1326 | pfnLivePrep, pfnLiveExec, pfnLiveVote,
|
---|
| 1327 | pfnSavePrep, pfnSaveExec, pfnSaveDone, pfnLoadPrep, pfnLoadExec, pfnLoadDone));
|
---|
[1] | 1328 |
|
---|
[26166] | 1329 | int rc = SSMR3RegisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pDrvIns->pReg->szName, pDrvIns->iInstance,
|
---|
[22480] | 1330 | uVersion, cbGuess,
|
---|
| 1331 | pfnLivePrep, pfnLiveExec, pfnLiveVote,
|
---|
[1] | 1332 | pfnSavePrep, pfnSaveExec, pfnSaveDone,
|
---|
| 1333 | pfnLoadPrep, pfnLoadExec, pfnLoadDone);
|
---|
| 1334 |
|
---|
[26166] | 1335 | LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
[1] | 1336 | return rc;
|
---|
| 1337 | }
|
---|
| 1338 |
|
---|
| 1339 |
|
---|
[26151] | 1340 | /** @interface_method_impl{PDMDRVHLP,pfnSSMDeregister} */
|
---|
[1] | 1341 | static DECLCALLBACK(int) pdmR3DrvHlp_SSMDeregister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance)
|
---|
| 1342 | {
|
---|
| 1343 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1344 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1345 | LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x\n",
|
---|
[26166] | 1346 | pDrvIns->pReg->szName, pDrvIns->iInstance, pszName, pszName, u32Instance));
|
---|
[1] | 1347 |
|
---|
[25891] | 1348 | int rc = SSMR3DeregisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pszName, u32Instance);
|
---|
[1] | 1349 |
|
---|
[26166] | 1350 | LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
[1] | 1351 | return rc;
|
---|
| 1352 | }
|
---|
| 1353 |
|
---|
| 1354 |
|
---|
[34207] | 1355 | /** @interface_method_impl{PDMDEVHLP,pfnDBGFInfoRegister} */
|
---|
| 1356 | static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoRegister(PPDMDRVINS pDrvIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler)
|
---|
| 1357 | {
|
---|
| 1358 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1359 | LogFlow(("pdmR3DrvHlp_DBGFInfoRegister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
|
---|
| 1360 | pDrvIns->pReg->szName, pDrvIns->iInstance, pszName, pszName, pszDesc, pszDesc, pfnHandler));
|
---|
| 1361 |
|
---|
| 1362 | int rc = DBGFR3InfoRegisterDriver(pDrvIns->Internal.s.pVMR3, pszName, pszDesc, pfnHandler, pDrvIns);
|
---|
| 1363 |
|
---|
| 1364 | LogFlow(("pdmR3DrvHlp_DBGFInfoRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
| 1365 | return rc;
|
---|
| 1366 | }
|
---|
| 1367 |
|
---|
| 1368 |
|
---|
| 1369 | /** @interface_method_impl{PDMDEVHLP,pfnDBGFInfoDeregister} */
|
---|
| 1370 | static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoDeregister(PPDMDRVINS pDrvIns, const char *pszName)
|
---|
| 1371 | {
|
---|
| 1372 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1373 | LogFlow(("pdmR3DrvHlp_DBGFInfoDeregister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
|
---|
| 1374 | pDrvIns->pReg->szName, pDrvIns->iInstance, pszName));
|
---|
| 1375 |
|
---|
| 1376 | int rc = DBGFR3InfoDeregisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pszName);
|
---|
| 1377 |
|
---|
| 1378 | LogFlow(("pdmR3DrvHlp_DBGFInfoDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
| 1379 |
|
---|
| 1380 | return rc;
|
---|
| 1381 | }
|
---|
| 1382 |
|
---|
| 1383 |
|
---|
[26151] | 1384 | /** @interface_method_impl{PDMDRVHLP,pfnSTAMRegister} */
|
---|
[1] | 1385 | static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
|
---|
| 1386 | {
|
---|
| 1387 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1388 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1389 |
|
---|
[25891] | 1390 | STAM_REG(pDrvIns->Internal.s.pVMR3, pvSample, enmType, pszName, enmUnit, pszDesc);
|
---|
[1] | 1391 | /** @todo track the samples so they can be dumped & deregistered when the driver instance is destroyed.
|
---|
| 1392 | * For now we just have to be careful not to use this call for drivers which can be unloaded. */
|
---|
| 1393 | }
|
---|
| 1394 |
|
---|
| 1395 |
|
---|
[26151] | 1396 | /** @interface_method_impl{PDMDRVHLP,pfnSTAMRegisterF} */
|
---|
[1] | 1397 | static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
| 1398 | STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
|
---|
| 1399 | {
|
---|
| 1400 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1401 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1402 |
|
---|
| 1403 | va_list args;
|
---|
| 1404 | va_start(args, pszName);
|
---|
[25891] | 1405 | int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
|
---|
[1] | 1406 | va_end(args);
|
---|
| 1407 | AssertRC(rc);
|
---|
| 1408 | }
|
---|
| 1409 |
|
---|
| 1410 |
|
---|
[26151] | 1411 | /** @interface_method_impl{PDMDRVHLP,pfnSTAMRegisterV} */
|
---|
[1] | 1412 | static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
| 1413 | STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
|
---|
| 1414 | {
|
---|
| 1415 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1416 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[1] | 1417 |
|
---|
[25891] | 1418 | int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
|
---|
[1] | 1419 | AssertRC(rc);
|
---|
| 1420 | }
|
---|
| 1421 |
|
---|
| 1422 |
|
---|
[26151] | 1423 | /** @interface_method_impl{PDMDRVHLP,pfnSTAMDeregister} */
|
---|
[20706] | 1424 | static DECLCALLBACK(int) pdmR3DrvHlp_STAMDeregister(PPDMDRVINS pDrvIns, void *pvSample)
|
---|
| 1425 | {
|
---|
| 1426 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1427 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[20706] | 1428 |
|
---|
[46493] | 1429 | int rc = STAMR3DeregisterByAddr(pDrvIns->Internal.s.pVMR3->pUVM, pvSample);
|
---|
[20706] | 1430 | AssertRC(rc);
|
---|
| 1431 | return rc;
|
---|
| 1432 | }
|
---|
| 1433 |
|
---|
| 1434 |
|
---|
[26151] | 1435 | /** @interface_method_impl{PDMDRVHLP,pfnSUPCallVMMR0Ex} */
|
---|
[1] | 1436 | static DECLCALLBACK(int) pdmR3DrvHlp_SUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg)
|
---|
| 1437 | {
|
---|
| 1438 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1439 | LogFlow(("pdmR3DrvHlp_SSMCallVMMR0Ex: caller='%s'/%d: uOperation=%u pvArg=%p cbArg=%d\n",
|
---|
[26166] | 1440 | pDrvIns->pReg->szName, pDrvIns->iInstance, uOperation, pvArg, cbArg));
|
---|
[1] | 1441 | int rc;
|
---|
| 1442 | if ( uOperation >= VMMR0_DO_SRV_START
|
---|
| 1443 | && uOperation < VMMR0_DO_SRV_END)
|
---|
[25891] | 1444 | rc = SUPR3CallVMMR0Ex(pDrvIns->Internal.s.pVMR3->pVMR0, NIL_VMCPUID, uOperation, 0, (PSUPVMMR0REQHDR)pvArg);
|
---|
[1] | 1445 | else
|
---|
| 1446 | {
|
---|
| 1447 | AssertMsgFailed(("Invalid uOperation=%u\n", uOperation));
|
---|
| 1448 | rc = VERR_INVALID_PARAMETER;
|
---|
| 1449 | }
|
---|
| 1450 |
|
---|
[26166] | 1451 | LogFlow(("pdmR3DrvHlp_SUPCallVMMR0Ex: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
[1] | 1452 | return rc;
|
---|
| 1453 | }
|
---|
| 1454 |
|
---|
[3852] | 1455 |
|
---|
[26151] | 1456 | /** @interface_method_impl{PDMDRVHLP,pfnUSBRegisterHub} */
|
---|
[5525] | 1457 | static DECLCALLBACK(int) pdmR3DrvHlp_USBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
|
---|
[3852] | 1458 | {
|
---|
| 1459 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1460 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[5525] | 1461 | LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: fVersions=%#x cPorts=%#x pUsbHubReg=%p ppUsbHubHlp=%p\n",
|
---|
[26166] | 1462 | pDrvIns->pReg->szName, pDrvIns->iInstance, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp));
|
---|
[3852] | 1463 |
|
---|
[5530] | 1464 | #ifdef VBOX_WITH_USB
|
---|
[25891] | 1465 | int rc = pdmR3UsbRegisterHub(pDrvIns->Internal.s.pVMR3, pDrvIns, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp);
|
---|
[5530] | 1466 | #else
|
---|
| 1467 | int rc = VERR_NOT_SUPPORTED;
|
---|
| 1468 | #endif
|
---|
[3852] | 1469 |
|
---|
[26166] | 1470 | LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
[3852] | 1471 | return rc;
|
---|
| 1472 | }
|
---|
| 1473 |
|
---|
[4012] | 1474 |
|
---|
[26151] | 1475 | /** @interface_method_impl{PDMDRVHLP,pfnSetAsyncNotification} */
|
---|
[24730] | 1476 | static DECLCALLBACK(int) pdmR3DrvHlp_SetAsyncNotification(PPDMDRVINS pDrvIns, PFNPDMDRVASYNCNOTIFY pfnAsyncNotify)
|
---|
| 1477 | {
|
---|
| 1478 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1479 | VM_ASSERT_EMT0(pDrvIns->Internal.s.pVMR3);
|
---|
[26166] | 1480 | LogFlow(("pdmR3DrvHlp_SetAsyncNotification: caller='%s'/%d: pfnAsyncNotify=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, pfnAsyncNotify));
|
---|
[24730] | 1481 |
|
---|
| 1482 | int rc = VINF_SUCCESS;
|
---|
| 1483 | AssertStmt(pfnAsyncNotify, rc = VERR_INVALID_PARAMETER);
|
---|
| 1484 | AssertStmt(!pDrvIns->Internal.s.pfnAsyncNotify, rc = VERR_WRONG_ORDER);
|
---|
[24744] | 1485 | AssertStmt(pDrvIns->Internal.s.fVMSuspended || pDrvIns->Internal.s.fVMReset, rc = VERR_WRONG_ORDER);
|
---|
[25891] | 1486 | VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVMR3);
|
---|
[24730] | 1487 | AssertStmt( enmVMState == VMSTATE_SUSPENDING
|
---|
| 1488 | || enmVMState == VMSTATE_SUSPENDING_EXT_LS
|
---|
| 1489 | || enmVMState == VMSTATE_SUSPENDING_LS
|
---|
[24744] | 1490 | || enmVMState == VMSTATE_RESETTING
|
---|
| 1491 | || enmVMState == VMSTATE_RESETTING_LS
|
---|
[24730] | 1492 | || enmVMState == VMSTATE_POWERING_OFF
|
---|
| 1493 | || enmVMState == VMSTATE_POWERING_OFF_LS,
|
---|
| 1494 | rc = VERR_INVALID_STATE);
|
---|
| 1495 |
|
---|
| 1496 | if (RT_SUCCESS(rc))
|
---|
| 1497 | pDrvIns->Internal.s.pfnAsyncNotify = pfnAsyncNotify;
|
---|
| 1498 |
|
---|
[26166] | 1499 | LogFlow(("pdmR3DrvHlp_SetAsyncNotification: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
|
---|
[24730] | 1500 | return rc;
|
---|
| 1501 | }
|
---|
| 1502 |
|
---|
| 1503 |
|
---|
[26151] | 1504 | /** @interface_method_impl{PDMDRVHLP,pfnAsyncNotificationCompleted} */
|
---|
[24740] | 1505 | static DECLCALLBACK(void) pdmR3DrvHlp_AsyncNotificationCompleted(PPDMDRVINS pDrvIns)
|
---|
| 1506 | {
|
---|
| 1507 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1508 | PVM pVM = pDrvIns->Internal.s.pVMR3;
|
---|
[24740] | 1509 |
|
---|
| 1510 | VMSTATE enmVMState = VMR3GetState(pVM);
|
---|
| 1511 | if ( enmVMState == VMSTATE_SUSPENDING
|
---|
| 1512 | || enmVMState == VMSTATE_SUSPENDING_EXT_LS
|
---|
| 1513 | || enmVMState == VMSTATE_SUSPENDING_LS
|
---|
[24744] | 1514 | || enmVMState == VMSTATE_RESETTING
|
---|
| 1515 | || enmVMState == VMSTATE_RESETTING_LS
|
---|
[24740] | 1516 | || enmVMState == VMSTATE_POWERING_OFF
|
---|
| 1517 | || enmVMState == VMSTATE_POWERING_OFF_LS)
|
---|
| 1518 | {
|
---|
[26166] | 1519 | LogFlow(("pdmR3DrvHlp_AsyncNotificationCompleted: caller='%s'/%d:\n", pDrvIns->pReg->szName, pDrvIns->iInstance));
|
---|
[24740] | 1520 | VMR3AsyncPdmNotificationWakeupU(pVM->pUVM);
|
---|
| 1521 | }
|
---|
| 1522 | else
|
---|
[26166] | 1523 | LogFlow(("pdmR3DrvHlp_AsyncNotificationCompleted: caller='%s'/%d: enmVMState=%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance, enmVMState));
|
---|
[24740] | 1524 | }
|
---|
| 1525 |
|
---|
| 1526 |
|
---|
[28258] | 1527 | /** @interface_method_impl{PDMDRVHLP,pfnThreadCreate} */
|
---|
| 1528 | static DECLCALLBACK(int) pdmR3DrvHlp_ThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
|
---|
| 1529 | PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
|
---|
[4012] | 1530 | {
|
---|
| 1531 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[25891] | 1532 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[28258] | 1533 | LogFlow(("pdmR3DrvHlp_ThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
|
---|
[26166] | 1534 | pDrvIns->pReg->szName, pDrvIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
|
---|
[4012] | 1535 |
|
---|
[25891] | 1536 | int rc = pdmR3ThreadCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
|
---|
[4012] | 1537 |
|
---|
[28258] | 1538 | LogFlow(("pdmR3DrvHlp_ThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
|
---|
[4012] | 1539 | rc, *ppThread));
|
---|
| 1540 | return rc;
|
---|
| 1541 | }
|
---|
| 1542 |
|
---|
[7768] | 1543 |
|
---|
[28258] | 1544 | /** @interface_method_impl{PDMDRVHLP,pfnAsyncCompletionTemplateCreate} */
|
---|
| 1545 | static DECLCALLBACK(int) pdmR3DrvHlp_AsyncCompletionTemplateCreate(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
|
---|
| 1546 | PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser,
|
---|
| 1547 | const char *pszDesc)
|
---|
[6221] | 1548 | {
|
---|
| 1549 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
[28258] | 1550 | LogFlow(("pdmR3DrvHlp_AsyncCompletionTemplateCreate: caller='%s'/%d: ppTemplate=%p pfnCompleted=%p pszDesc=%p:{%s}\n",
|
---|
[26166] | 1551 | pDrvIns->pReg->szName, pDrvIns->iInstance, ppTemplate, pfnCompleted, pszDesc, pszDesc));
|
---|
[6221] | 1552 |
|
---|
[44358] | 1553 | int rc = pdmR3AsyncCompletionTemplateCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppTemplate, pfnCompleted, pvTemplateUser, pszDesc);
|
---|
[6221] | 1554 |
|
---|
[28258] | 1555 | LogFlow(("pdmR3DrvHlp_AsyncCompletionTemplateCreate: caller='%s'/%d: returns %Rrc *ppThread=%p\n", pDrvIns->pReg->szName,
|
---|
[6221] | 1556 | pDrvIns->iInstance, rc, *ppTemplate));
|
---|
| 1557 | return rc;
|
---|
| 1558 | }
|
---|
| 1559 |
|
---|
[12986] | 1560 |
|
---|
[40652] | 1561 | #ifdef VBOX_WITH_NETSHAPER
|
---|
| 1562 | /** @interface_method_impl{PDMDRVHLP,pfnNetShaperAttach} */
|
---|
| 1563 | static DECLCALLBACK(int) pdmR3DrvHlp_NetShaperAttach(PPDMDRVINS pDrvIns, const char *pszBwGroup, PPDMNSFILTER pFilter)
|
---|
| 1564 | {
|
---|
| 1565 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1566 | LogFlow(("pdmR3DrvHlp_NetShaperAttach: caller='%s'/%d: pFilter=%p pszBwGroup=%p:{%s}\n",
|
---|
| 1567 | pDrvIns->pReg->szName, pDrvIns->iInstance, pFilter, pszBwGroup, pszBwGroup));
|
---|
| 1568 |
|
---|
[44355] | 1569 | int rc = PDMR3NsAttach(pDrvIns->Internal.s.pVMR3->pUVM, pDrvIns, pszBwGroup, pFilter);
|
---|
[40652] | 1570 |
|
---|
| 1571 | LogFlow(("pdmR3DrvHlp_NetShaperAttach: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
|
---|
| 1572 | pDrvIns->iInstance, rc));
|
---|
| 1573 | return rc;
|
---|
| 1574 | }
|
---|
| 1575 |
|
---|
| 1576 |
|
---|
| 1577 | /** @interface_method_impl{PDMDRVHLP,pfnNetShaperDetach} */
|
---|
| 1578 | static DECLCALLBACK(int) pdmR3DrvHlp_NetShaperDetach(PPDMDRVINS pDrvIns, PPDMNSFILTER pFilter)
|
---|
| 1579 | {
|
---|
| 1580 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1581 | LogFlow(("pdmR3DrvHlp_NetShaperDetach: caller='%s'/%d: pFilter=%p\n",
|
---|
| 1582 | pDrvIns->pReg->szName, pDrvIns->iInstance, pFilter));
|
---|
| 1583 |
|
---|
[44355] | 1584 | int rc = PDMR3NsDetach(pDrvIns->Internal.s.pVMR3->pUVM, pDrvIns, pFilter);
|
---|
[40652] | 1585 |
|
---|
| 1586 | LogFlow(("pdmR3DrvHlp_NetShaperDetach: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
|
---|
| 1587 | pDrvIns->iInstance, rc));
|
---|
| 1588 | return rc;
|
---|
| 1589 | }
|
---|
| 1590 | #endif /* VBOX_WITH_NETSHAPER */
|
---|
| 1591 |
|
---|
| 1592 |
|
---|
[28258] | 1593 | /** @interface_method_impl{PDMDRVHLP,pfnLdrGetRCInterfaceSymbols} */
|
---|
| 1594 | static DECLCALLBACK(int) pdmR3DrvHlp_LdrGetRCInterfaceSymbols(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
|
---|
| 1595 | const char *pszSymPrefix, const char *pszSymList)
|
---|
[26151] | 1596 | {
|
---|
| 1597 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1598 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[28258] | 1599 | LogFlow(("pdmR3DrvHlp_LdrGetRCInterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
|
---|
[26166] | 1600 | pDrvIns->pReg->szName, pDrvIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
|
---|
[26151] | 1601 |
|
---|
| 1602 | int rc;
|
---|
| 1603 | if ( strncmp(pszSymPrefix, "drv", 3) == 0
|
---|
[26166] | 1604 | && RTStrIStr(pszSymPrefix + 3, pDrvIns->pReg->szName) != NULL)
|
---|
[26151] | 1605 | {
|
---|
[26161] | 1606 | if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
|
---|
[34241] | 1607 | rc = PDMR3LdrGetInterfaceSymbols(pDrvIns->Internal.s.pVMR3,
|
---|
| 1608 | pvInterface, cbInterface,
|
---|
| 1609 | pDrvIns->pReg->szRCMod, pDrvIns->Internal.s.pDrv->pszRCSearchPath,
|
---|
| 1610 | pszSymPrefix, pszSymList,
|
---|
[26151] | 1611 | false /*fRing0OrRC*/);
|
---|
| 1612 | else
|
---|
| 1613 | {
|
---|
| 1614 | AssertMsgFailed(("Not a raw-mode enabled driver\n"));
|
---|
| 1615 | rc = VERR_PERMISSION_DENIED;
|
---|
| 1616 | }
|
---|
| 1617 | }
|
---|
| 1618 | else
|
---|
| 1619 | {
|
---|
| 1620 | AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'drv' and contain the driver name!\n",
|
---|
[26166] | 1621 | pszSymPrefix, pDrvIns->pReg->szName));
|
---|
[26151] | 1622 | rc = VERR_INVALID_NAME;
|
---|
| 1623 | }
|
---|
| 1624 |
|
---|
[28258] | 1625 | LogFlow(("pdmR3DrvHlp_LdrGetRCInterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
|
---|
[26151] | 1626 | pDrvIns->iInstance, rc));
|
---|
| 1627 | return rc;
|
---|
| 1628 | }
|
---|
| 1629 |
|
---|
| 1630 |
|
---|
[28258] | 1631 | /** @interface_method_impl{PDMDRVHLP,pfnLdrGetR0InterfaceSymbols} */
|
---|
| 1632 | static DECLCALLBACK(int) pdmR3DrvHlp_LdrGetR0InterfaceSymbols(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
|
---|
| 1633 | const char *pszSymPrefix, const char *pszSymList)
|
---|
[26151] | 1634 | {
|
---|
| 1635 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1636 | VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
|
---|
[28258] | 1637 | LogFlow(("pdmR3DrvHlp_LdrGetR0InterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
|
---|
[26166] | 1638 | pDrvIns->pReg->szName, pDrvIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
|
---|
[26151] | 1639 |
|
---|
| 1640 | int rc;
|
---|
| 1641 | if ( strncmp(pszSymPrefix, "drv", 3) == 0
|
---|
[26166] | 1642 | && RTStrIStr(pszSymPrefix + 3, pDrvIns->pReg->szName) != NULL)
|
---|
[26151] | 1643 | {
|
---|
[26161] | 1644 | if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
|
---|
[34241] | 1645 | rc = PDMR3LdrGetInterfaceSymbols(pDrvIns->Internal.s.pVMR3,
|
---|
| 1646 | pvInterface, cbInterface,
|
---|
| 1647 | pDrvIns->pReg->szR0Mod, pDrvIns->Internal.s.pDrv->pszR0SearchPath,
|
---|
| 1648 | pszSymPrefix, pszSymList,
|
---|
[26151] | 1649 | true /*fRing0OrRC*/);
|
---|
| 1650 | else
|
---|
| 1651 | {
|
---|
| 1652 | AssertMsgFailed(("Not a ring-0 enabled driver\n"));
|
---|
| 1653 | rc = VERR_PERMISSION_DENIED;
|
---|
| 1654 | }
|
---|
| 1655 | }
|
---|
| 1656 | else
|
---|
| 1657 | {
|
---|
| 1658 | AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'drv' and contain the driver name!\n",
|
---|
[26166] | 1659 | pszSymPrefix, pDrvIns->pReg->szName));
|
---|
[26151] | 1660 | rc = VERR_INVALID_NAME;
|
---|
| 1661 | }
|
---|
| 1662 |
|
---|
[28258] | 1663 | LogFlow(("pdmR3DrvHlp_LdrGetR0InterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
|
---|
[26151] | 1664 | pDrvIns->iInstance, rc));
|
---|
| 1665 | return rc;
|
---|
| 1666 | }
|
---|
| 1667 |
|
---|
| 1668 |
|
---|
[28258] | 1669 | /** @interface_method_impl{PDMDRVHLP,pfnCritSectInit} */
|
---|
| 1670 | static DECLCALLBACK(int) pdmR3DrvHlp_CritSectInit(PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect,
|
---|
| 1671 | RT_SRC_POS_DECL, const char *pszName)
|
---|
| 1672 | {
|
---|
| 1673 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1674 | PVM pVM = pDrvIns->Internal.s.pVMR3;
|
---|
| 1675 | VM_ASSERT_EMT(pVM);
|
---|
| 1676 | LogFlow(("pdmR3DrvHlp_CritSectInit: caller='%s'/%d: pCritSect=%p pszName=%s\n",
|
---|
| 1677 | pDrvIns->pReg->szName, pDrvIns->iInstance, pCritSect, pszName));
|
---|
| 1678 |
|
---|
| 1679 | int rc = pdmR3CritSectInitDriver(pVM, pDrvIns, pCritSect, RT_SRC_POS_ARGS, "%s_%u", pszName, pDrvIns->iInstance);
|
---|
| 1680 |
|
---|
| 1681 | LogFlow(("pdmR3DrvHlp_CritSectInit: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
|
---|
| 1682 | pDrvIns->iInstance, rc));
|
---|
| 1683 | return rc;
|
---|
| 1684 | }
|
---|
| 1685 |
|
---|
| 1686 |
|
---|
[28425] | 1687 | /** @interface_method_impl{PDMDRVHLP,pfnCallR0} */
|
---|
| 1688 | static DECLCALLBACK(int) pdmR3DrvHlp_CallR0(PPDMDRVINS pDrvIns, uint32_t uOperation, uint64_t u64Arg)
|
---|
| 1689 | {
|
---|
| 1690 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1691 | PVM pVM = pDrvIns->Internal.s.pVMR3;
|
---|
| 1692 | LogFlow(("pdmR3DrvHlp_CallR0: caller='%s'/%d: uOperation=%#x u64Arg=%#RX64\n",
|
---|
| 1693 | pDrvIns->pReg->szName, pDrvIns->iInstance, uOperation, u64Arg));
|
---|
| 1694 |
|
---|
| 1695 | /*
|
---|
| 1696 | * Lazy resolve the ring-0 entry point.
|
---|
| 1697 | */
|
---|
| 1698 | int rc = VINF_SUCCESS;
|
---|
| 1699 | PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0 = pDrvIns->Internal.s.pfnReqHandlerR0;
|
---|
| 1700 | if (RT_UNLIKELY(pfnReqHandlerR0 == NIL_RTR0PTR))
|
---|
| 1701 | {
|
---|
| 1702 | if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
|
---|
| 1703 | {
|
---|
| 1704 | char szSymbol[ sizeof("drvR0") + sizeof(pDrvIns->pReg->szName) + sizeof("ReqHandler")];
|
---|
| 1705 | strcat(strcat(strcpy(szSymbol, "drvR0"), pDrvIns->pReg->szName), "ReqHandler");
|
---|
[29521] | 1706 | szSymbol[sizeof("drvR0") - 1] = RT_C_TO_UPPER(szSymbol[sizeof("drvR0") - 1]);
|
---|
| 1707 |
|
---|
[34241] | 1708 | rc = PDMR3LdrGetSymbolR0Lazy(pVM, pDrvIns->pReg->szR0Mod, pDrvIns->Internal.s.pDrv->pszR0SearchPath, szSymbol,
|
---|
| 1709 | &pfnReqHandlerR0);
|
---|
[28425] | 1710 | if (RT_SUCCESS(rc))
|
---|
| 1711 | pDrvIns->Internal.s.pfnReqHandlerR0 = pfnReqHandlerR0;
|
---|
| 1712 | else
|
---|
| 1713 | pfnReqHandlerR0 = NIL_RTR0PTR;
|
---|
| 1714 | }
|
---|
| 1715 | else
|
---|
| 1716 | rc = VERR_ACCESS_DENIED;
|
---|
| 1717 | }
|
---|
| 1718 | if (RT_LIKELY(pfnReqHandlerR0 != NIL_RTR0PTR))
|
---|
| 1719 | {
|
---|
| 1720 | /*
|
---|
| 1721 | * Make the ring-0 call.
|
---|
| 1722 | */
|
---|
| 1723 | PDMDRIVERCALLREQHANDLERREQ Req;
|
---|
| 1724 | Req.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
|
---|
| 1725 | Req.Hdr.cbReq = sizeof(Req);
|
---|
| 1726 | Req.pDrvInsR0 = PDMDRVINS_2_R0PTR(pDrvIns);
|
---|
| 1727 | Req.uOperation = uOperation;
|
---|
| 1728 | Req.u32Alignment = 0;
|
---|
| 1729 | Req.u64Arg = u64Arg;
|
---|
| 1730 | rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_PDM_DRIVER_CALL_REQ_HANDLER, 0, &Req.Hdr);
|
---|
| 1731 | }
|
---|
| 1732 |
|
---|
| 1733 | LogFlow(("pdmR3DrvHlp_CallR0: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
|
---|
| 1734 | pDrvIns->iInstance, rc));
|
---|
| 1735 | return rc;
|
---|
| 1736 | }
|
---|
| 1737 |
|
---|
[32156] | 1738 |
|
---|
[32135] | 1739 | /** @interface_method_impl{PDMDRVHLP,pfnFTSetCheckpoint} */
|
---|
| 1740 | static DECLCALLBACK(int) pdmR3DrvHlp_FTSetCheckpoint(PPDMDRVINS pDrvIns, FTMCHECKPOINTTYPE enmType)
|
---|
| 1741 | {
|
---|
| 1742 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1743 | return FTMSetCheckpoint(pDrvIns->Internal.s.pVMR3, enmType);
|
---|
| 1744 | }
|
---|
[28425] | 1745 |
|
---|
[32156] | 1746 |
|
---|
[34222] | 1747 | /** @interface_method_impl{PDMDRVHLP,pfnBlkCacheRetain} */
|
---|
| 1748 | static DECLCALLBACK(int) pdmR3DrvHlp_BlkCacheRetain(PPDMDRVINS pDrvIns, PPPDMBLKCACHE ppBlkCache,
|
---|
| 1749 | PFNPDMBLKCACHEXFERCOMPLETEDRV pfnXferComplete,
|
---|
| 1750 | PFNPDMBLKCACHEXFERENQUEUEDRV pfnXferEnqueue,
|
---|
[38878] | 1751 | PFNPDMBLKCACHEXFERENQUEUEDISCARDDRV pfnXferEnqueueDiscard,
|
---|
[34222] | 1752 | const char *pcszId)
|
---|
| 1753 | {
|
---|
| 1754 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1755 | return PDMR3BlkCacheRetainDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppBlkCache,
|
---|
[38878] | 1756 | pfnXferComplete, pfnXferEnqueue, pfnXferEnqueueDiscard, pcszId);
|
---|
[34222] | 1757 | }
|
---|
| 1758 |
|
---|
| 1759 |
|
---|
[46788] | 1760 |
|
---|
| 1761 | /** @interface_method_impl{PDMDRVHLP,pfnVMGetSuspendReason} */
|
---|
| 1762 | static DECLCALLBACK(VMSUSPENDREASON) pdmR3DrvHlp_VMGetSuspendReason(PPDMDRVINS pDrvIns)
|
---|
| 1763 | {
|
---|
| 1764 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1765 | PVM pVM = pDrvIns->Internal.s.pVMR3;
|
---|
| 1766 | VM_ASSERT_EMT(pVM);
|
---|
| 1767 | VMSUSPENDREASON enmReason = VMR3GetSuspendReason(pVM->pUVM);
|
---|
| 1768 | LogFlow(("pdmR3DrvHlp_VMGetSuspendReason: caller='%s'/%d: returns %d\n",
|
---|
| 1769 | pDrvIns->pReg->szName, pDrvIns->iInstance, enmReason));
|
---|
| 1770 | return enmReason;
|
---|
| 1771 | }
|
---|
| 1772 |
|
---|
| 1773 |
|
---|
| 1774 | /** @interface_method_impl{PDMDRVHLP,pfnVMGetResumeReason} */
|
---|
| 1775 | static DECLCALLBACK(VMRESUMEREASON) pdmR3DrvHlp_VMGetResumeReason(PPDMDRVINS pDrvIns)
|
---|
| 1776 | {
|
---|
| 1777 | PDMDRV_ASSERT_DRVINS(pDrvIns);
|
---|
| 1778 | PVM pVM = pDrvIns->Internal.s.pVMR3;
|
---|
| 1779 | VM_ASSERT_EMT(pVM);
|
---|
| 1780 | VMRESUMEREASON enmReason = VMR3GetResumeReason(pVM->pUVM);
|
---|
| 1781 | LogFlow(("pdmR3DrvHlp_VMGetResumeReason: caller='%s'/%d: returns %d\n",
|
---|
| 1782 | pDrvIns->pReg->szName, pDrvIns->iInstance, enmReason));
|
---|
| 1783 | return enmReason;
|
---|
| 1784 | }
|
---|
| 1785 |
|
---|
| 1786 |
|
---|
[12986] | 1787 | /**
|
---|
| 1788 | * The driver helper structure.
|
---|
| 1789 | */
|
---|
[25891] | 1790 | const PDMDRVHLPR3 g_pdmR3DrvHlp =
|
---|
[12986] | 1791 | {
|
---|
[25891] | 1792 | PDM_DRVHLPR3_VERSION,
|
---|
[12986] | 1793 | pdmR3DrvHlp_Attach,
|
---|
| 1794 | pdmR3DrvHlp_Detach,
|
---|
| 1795 | pdmR3DrvHlp_DetachSelf,
|
---|
| 1796 | pdmR3DrvHlp_MountPrepare,
|
---|
| 1797 | pdmR3DrvHlp_AssertEMT,
|
---|
| 1798 | pdmR3DrvHlp_AssertOther,
|
---|
| 1799 | pdmR3DrvHlp_VMSetError,
|
---|
| 1800 | pdmR3DrvHlp_VMSetErrorV,
|
---|
| 1801 | pdmR3DrvHlp_VMSetRuntimeError,
|
---|
| 1802 | pdmR3DrvHlp_VMSetRuntimeErrorV,
|
---|
[23915] | 1803 | pdmR3DrvHlp_VMState,
|
---|
| 1804 | pdmR3DrvHlp_VMTeleportedAndNotFullyResumedYet,
|
---|
[28327] | 1805 | pdmR3DrvHlp_GetSupDrvSession,
|
---|
[28258] | 1806 | pdmR3DrvHlp_QueueCreate,
|
---|
[12986] | 1807 | pdmR3DrvHlp_TMGetVirtualFreq,
|
---|
| 1808 | pdmR3DrvHlp_TMGetVirtualTime,
|
---|
| 1809 | pdmR3DrvHlp_TMTimerCreate,
|
---|
| 1810 | pdmR3DrvHlp_SSMRegister,
|
---|
| 1811 | pdmR3DrvHlp_SSMDeregister,
|
---|
[34207] | 1812 | pdmR3DrvHlp_DBGFInfoRegister,
|
---|
| 1813 | pdmR3DrvHlp_DBGFInfoDeregister,
|
---|
[12986] | 1814 | pdmR3DrvHlp_STAMRegister,
|
---|
| 1815 | pdmR3DrvHlp_STAMRegisterF,
|
---|
| 1816 | pdmR3DrvHlp_STAMRegisterV,
|
---|
[20706] | 1817 | pdmR3DrvHlp_STAMDeregister,
|
---|
[12986] | 1818 | pdmR3DrvHlp_SUPCallVMMR0Ex,
|
---|
| 1819 | pdmR3DrvHlp_USBRegisterHub,
|
---|
[24730] | 1820 | pdmR3DrvHlp_SetAsyncNotification,
|
---|
[24740] | 1821 | pdmR3DrvHlp_AsyncNotificationCompleted,
|
---|
[28258] | 1822 | pdmR3DrvHlp_ThreadCreate,
|
---|
| 1823 | pdmR3DrvHlp_AsyncCompletionTemplateCreate,
|
---|
[40652] | 1824 | #ifdef VBOX_WITH_NETSHAPER
|
---|
| 1825 | pdmR3DrvHlp_NetShaperAttach,
|
---|
| 1826 | pdmR3DrvHlp_NetShaperDetach,
|
---|
| 1827 | #endif /* VBOX_WITH_NETSHAPER */
|
---|
[28258] | 1828 | pdmR3DrvHlp_LdrGetRCInterfaceSymbols,
|
---|
| 1829 | pdmR3DrvHlp_LdrGetR0InterfaceSymbols,
|
---|
| 1830 | pdmR3DrvHlp_CritSectInit,
|
---|
[28425] | 1831 | pdmR3DrvHlp_CallR0,
|
---|
[32135] | 1832 | pdmR3DrvHlp_FTSetCheckpoint,
|
---|
[34222] | 1833 | pdmR3DrvHlp_BlkCacheRetain,
|
---|
[46788] | 1834 | pdmR3DrvHlp_VMGetSuspendReason,
|
---|
| 1835 | pdmR3DrvHlp_VMGetResumeReason,
|
---|
| 1836 | NULL,
|
---|
| 1837 | NULL,
|
---|
| 1838 | NULL,
|
---|
| 1839 | NULL,
|
---|
| 1840 | NULL,
|
---|
| 1841 | NULL,
|
---|
| 1842 | NULL,
|
---|
| 1843 | NULL,
|
---|
| 1844 | NULL,
|
---|
| 1845 | NULL,
|
---|
[25891] | 1846 | PDM_DRVHLPR3_VERSION /* u32TheEnd */
|
---|
[12986] | 1847 | };
|
---|
| 1848 |
|
---|
| 1849 | /** @} */
|
---|