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