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