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