1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox Driver Interface to VMM device
|
---|
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.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 | #include "VMMDev.h"
|
---|
23 | #include "ConsoleImpl.h"
|
---|
24 | #include "DisplayImpl.h"
|
---|
25 | #include "GuestImpl.h"
|
---|
26 |
|
---|
27 | #include "Logging.h"
|
---|
28 |
|
---|
29 | #include <VBox/pdm.h>
|
---|
30 | #include <VBox/VBoxDev.h>
|
---|
31 | #include <VBox/VBoxGuest.h>
|
---|
32 | #include <VBox/cfgm.h>
|
---|
33 | #include <VBox/err.h>
|
---|
34 | #include <iprt/asm.h>
|
---|
35 |
|
---|
36 | #ifdef VBOX_HGCM
|
---|
37 | #include "hgcm/HGCM.h"
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | //
|
---|
41 | // defines
|
---|
42 | //
|
---|
43 |
|
---|
44 |
|
---|
45 | //
|
---|
46 | // globals
|
---|
47 | //
|
---|
48 |
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * VMMDev driver instance data.
|
---|
52 | */
|
---|
53 | typedef struct DRVMAINVMMDEV
|
---|
54 | {
|
---|
55 | /** Pointer to the VMMDev object. */
|
---|
56 | VMMDev *pVMMDev;
|
---|
57 | /** Pointer to the driver instance structure. */
|
---|
58 | PPDMDRVINS pDrvIns;
|
---|
59 | /** Pointer to the VMMDev port interface of the driver/device above us. */
|
---|
60 | PPDMIVMMDEVPORT pUpPort;
|
---|
61 | /** Our VMM device connector interface. */
|
---|
62 | PDMIVMMDEVCONNECTOR Connector;
|
---|
63 | #ifdef VBOX_HGCM
|
---|
64 | /** Pointer to the HGCM port interface of the driver/device above us. */
|
---|
65 | PPDMIHGCMPORT pHGCMPort;
|
---|
66 | /** Our HGCM connector interface. */
|
---|
67 | PDMIHGCMCONNECTOR HGCMConnector;
|
---|
68 | #endif
|
---|
69 | } DRVMAINVMMDEV, *PDRVMAINVMMDEV;
|
---|
70 |
|
---|
71 | /** Converts PDMIVMMDEVCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
|
---|
72 | #define PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, Connector)) )
|
---|
73 |
|
---|
74 | #ifdef VBOX_HGCM
|
---|
75 | /** Converts PDMIHGCMCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
|
---|
76 | #define PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, HGCMConnector)) )
|
---|
77 | #endif
|
---|
78 |
|
---|
79 | //
|
---|
80 | // constructor / destructor
|
---|
81 | //
|
---|
82 | VMMDev::VMMDev(Console *console) : mpDrv(NULL)
|
---|
83 | {
|
---|
84 | mParent = console;
|
---|
85 | int rc = RTSemEventCreate(&mCredentialsEvent);
|
---|
86 | AssertRC(rc);
|
---|
87 | #ifdef VBOX_HGCM
|
---|
88 | rc = hgcmInit ();
|
---|
89 | AssertRC(rc);
|
---|
90 | #endif /* VBOX_HGCM */
|
---|
91 | mu32CredentialsFlags = 0;
|
---|
92 | }
|
---|
93 |
|
---|
94 | VMMDev::~VMMDev()
|
---|
95 | {
|
---|
96 | RTSemEventDestroy (mCredentialsEvent);
|
---|
97 | if (mpDrv)
|
---|
98 | mpDrv->pVMMDev = NULL;
|
---|
99 | mpDrv = NULL;
|
---|
100 | }
|
---|
101 |
|
---|
102 | PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
|
---|
103 | {
|
---|
104 | Assert(mpDrv);
|
---|
105 | return mpDrv->pUpPort;
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | //
|
---|
111 | // public methods
|
---|
112 | //
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Wait on event semaphore for guest credential judgement result.
|
---|
116 | */
|
---|
117 | int VMMDev::WaitCredentialsJudgement (uint32_t u32Timeout, uint32_t *pu32CredentialsFlags)
|
---|
118 | {
|
---|
119 | if (u32Timeout == 0)
|
---|
120 | {
|
---|
121 | u32Timeout = 5000;
|
---|
122 | }
|
---|
123 |
|
---|
124 | int rc = RTSemEventWait (mCredentialsEvent, u32Timeout);
|
---|
125 |
|
---|
126 | if (VBOX_SUCCESS (rc))
|
---|
127 | {
|
---|
128 | *pu32CredentialsFlags = mu32CredentialsFlags;
|
---|
129 | }
|
---|
130 |
|
---|
131 | return rc;
|
---|
132 | }
|
---|
133 |
|
---|
134 | int VMMDev::SetCredentialsJudgementResult (uint32_t u32Flags)
|
---|
135 | {
|
---|
136 | mu32CredentialsFlags = u32Flags;
|
---|
137 |
|
---|
138 | int rc = RTSemEventSignal (mCredentialsEvent);
|
---|
139 | AssertRC(rc);
|
---|
140 |
|
---|
141 | return rc;
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Report guest OS version.
|
---|
147 | * Called whenever the Additions issue a guest version report request.
|
---|
148 | *
|
---|
149 | * @param pInterface Pointer to this interface.
|
---|
150 | * @param guestInfo Pointer to guest information structure
|
---|
151 | * @thread The emulation thread.
|
---|
152 | */
|
---|
153 | DECLCALLBACK(void) vmmdevUpdateGuestVersion(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestInfo *guestInfo)
|
---|
154 | {
|
---|
155 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
156 |
|
---|
157 | Assert(guestInfo);
|
---|
158 | if (!guestInfo)
|
---|
159 | return;
|
---|
160 |
|
---|
161 | /* store that information in IGuest */
|
---|
162 | Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
|
---|
163 | Assert(guest);
|
---|
164 | if (!guest)
|
---|
165 | return;
|
---|
166 |
|
---|
167 | char version[20];
|
---|
168 | sprintf(version, "%d", guestInfo->additionsVersion);
|
---|
169 | guest->setAdditionsVersion(Bstr(version));
|
---|
170 |
|
---|
171 | /*
|
---|
172 | * Tell the console interface about the event
|
---|
173 | * so that it can notify its consumers.
|
---|
174 | */
|
---|
175 | pDrv->pVMMDev->getParent()->onAdditionsStateChange();
|
---|
176 |
|
---|
177 | if (guestInfo->additionsVersion < VMMDEV_VERSION)
|
---|
178 | {
|
---|
179 | pDrv->pVMMDev->getParent()->onAdditionsOutdated();
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Update the mouse capabilities.
|
---|
185 | * This is called when the mouse capabilities change. The new capabilities
|
---|
186 | * are given and the connector should update its internal state.
|
---|
187 | *
|
---|
188 | * @param pInterface Pointer to this interface.
|
---|
189 | * @param newCapabilities New capabilities.
|
---|
190 | * @thread The emulation thread.
|
---|
191 | */
|
---|
192 | DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
|
---|
193 | {
|
---|
194 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
195 | /*
|
---|
196 | * Tell the console interface about the event
|
---|
197 | * so that it can notify its consumers.
|
---|
198 | */
|
---|
199 | pDrv->pVMMDev->getParent()->onMouseCapabilityChange(BOOL (newCapabilities & VMMDEV_MOUSEGUESTWANTSABS),
|
---|
200 | BOOL (newCapabilities & VMMDEV_MOUSEGUESTNEEDSHOSTCUR));
|
---|
201 | }
|
---|
202 |
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * Update the pointer shape or visibility.
|
---|
206 | *
|
---|
207 | * This is called when the mouse pointer shape changes or pointer is hidden/displaying.
|
---|
208 | * The new shape is passed as a caller allocated buffer that will be freed after returning.
|
---|
209 | *
|
---|
210 | * @param pInterface Pointer to this interface.
|
---|
211 | * @param fVisible Whether the pointer is visible or not.
|
---|
212 | * @param fAlpha Alpha channel information is present.
|
---|
213 | * @param xHot Horizontal coordinate of the pointer hot spot.
|
---|
214 | * @param yHot Vertical coordinate of the pointer hot spot.
|
---|
215 | * @param width Pointer width in pixels.
|
---|
216 | * @param height Pointer height in pixels.
|
---|
217 | * @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
|
---|
218 | * @thread The emulation thread.
|
---|
219 | */
|
---|
220 | DECLCALLBACK(void) vmmdevUpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
|
---|
221 | uint32_t xHot, uint32_t yHot,
|
---|
222 | uint32_t width, uint32_t height,
|
---|
223 | void *pShape)
|
---|
224 | {
|
---|
225 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
226 |
|
---|
227 | /* tell the console about it */
|
---|
228 | pDrv->pVMMDev->getParent()->onMousePointerShapeChange(fVisible, fAlpha,
|
---|
229 | xHot, yHot, width, height, pShape);
|
---|
230 | }
|
---|
231 |
|
---|
232 | DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
|
---|
233 | {
|
---|
234 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
235 |
|
---|
236 | Display *display = pDrv->pVMMDev->getParent()->getDisplay();
|
---|
237 |
|
---|
238 | if (display)
|
---|
239 | {
|
---|
240 | LogFlow(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
|
---|
241 | return display->VideoAccelEnable (fEnable, pVbvaMemory);
|
---|
242 | }
|
---|
243 |
|
---|
244 | return VERR_NOT_SUPPORTED;
|
---|
245 | }
|
---|
246 | DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
|
---|
247 | {
|
---|
248 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
249 |
|
---|
250 | Display *display = pDrv->pVMMDev->getParent()->getDisplay();
|
---|
251 |
|
---|
252 | if (display)
|
---|
253 | {
|
---|
254 | LogFlow(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
|
---|
255 | display->VideoAccelFlush ();
|
---|
256 | }
|
---|
257 | }
|
---|
258 |
|
---|
259 | DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t width, uint32_t height,
|
---|
260 | uint32_t bpp, bool *fSupported)
|
---|
261 | {
|
---|
262 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
263 |
|
---|
264 | if (!fSupported)
|
---|
265 | return VERR_INVALID_PARAMETER;
|
---|
266 | IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
|
---|
267 | Assert(framebuffer);
|
---|
268 | framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
|
---|
269 | return VINF_SUCCESS;
|
---|
270 | }
|
---|
271 |
|
---|
272 | DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
|
---|
273 | {
|
---|
274 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
275 |
|
---|
276 | if (!heightReduction)
|
---|
277 | return VERR_INVALID_PARAMETER;
|
---|
278 | IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
|
---|
279 | Assert(framebuffer);
|
---|
280 | framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
|
---|
281 | return VINF_SUCCESS;
|
---|
282 | }
|
---|
283 |
|
---|
284 | DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
|
---|
285 | {
|
---|
286 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
287 |
|
---|
288 | int rc = pDrv->pVMMDev->SetCredentialsJudgementResult (u32Flags);
|
---|
289 |
|
---|
290 | return rc;
|
---|
291 | }
|
---|
292 |
|
---|
293 | #ifdef VBOX_HGCM
|
---|
294 |
|
---|
295 | /* HGCM connector interface */
|
---|
296 |
|
---|
297 | static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
|
---|
298 | {
|
---|
299 | PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
300 |
|
---|
301 | return hgcmConnectInternal (pDrv->pHGCMPort, pCmd, pServiceLocation, pu32ClientID, false);
|
---|
302 | }
|
---|
303 |
|
---|
304 | static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
|
---|
305 | {
|
---|
306 | PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
307 |
|
---|
308 | return hgcmDisconnectInternal (pDrv->pHGCMPort, pCmd, u32ClientID, false);
|
---|
309 | }
|
---|
310 |
|
---|
311 | static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
|
---|
312 | uint32_t cParms, PVBOXHGCMSVCPARM paParms)
|
---|
313 | {
|
---|
314 | PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
315 |
|
---|
316 | return hgcmGuestCallInternal (pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms, false);
|
---|
317 | }
|
---|
318 |
|
---|
319 | int VMMDev::hgcmLoadService (const char *pszServiceName, const char *pszServiceLibrary)
|
---|
320 | {
|
---|
321 | return hgcmLoadInternal (pszServiceName, pszServiceLibrary);
|
---|
322 | }
|
---|
323 |
|
---|
324 | int VMMDev::hgcmConnect (PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
|
---|
325 | {
|
---|
326 | return hgcmConnectInternal (mpDrv->pHGCMPort, pCmd, pServiceLocation, pu32ClientID, true);
|
---|
327 | }
|
---|
328 |
|
---|
329 | int VMMDev::hgcmDisconnect (PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
|
---|
330 | {
|
---|
331 | return hgcmDisconnectInternal (mpDrv->pHGCMPort, pCmd, u32ClientID, true);
|
---|
332 | }
|
---|
333 |
|
---|
334 | int VMMDev::hgcmHostCall (const char *pszServiceName, uint32_t u32Function,
|
---|
335 | uint32_t cParms, PVBOXHGCMSVCPARM paParms)
|
---|
336 | {
|
---|
337 | return hgcmHostCallInternal (pszServiceName, u32Function, cParms, paParms);
|
---|
338 | }
|
---|
339 |
|
---|
340 | #endif
|
---|
341 |
|
---|
342 |
|
---|
343 | /**
|
---|
344 | * Queries an interface to the driver.
|
---|
345 | *
|
---|
346 | * @returns Pointer to interface.
|
---|
347 | * @returns NULL if the interface was not supported by the driver.
|
---|
348 | * @param pInterface Pointer to this interface structure.
|
---|
349 | * @param enmInterface The requested interface identification.
|
---|
350 | */
|
---|
351 | DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
|
---|
352 | {
|
---|
353 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
354 | PDRVMAINVMMDEV pDrv = PDMINS2DATA(pDrvIns, PDRVMAINVMMDEV);
|
---|
355 | switch (enmInterface)
|
---|
356 | {
|
---|
357 | case PDMINTERFACE_BASE:
|
---|
358 | return &pDrvIns->IBase;
|
---|
359 | case PDMINTERFACE_VMMDEV_CONNECTOR:
|
---|
360 | return &pDrv->Connector;
|
---|
361 | #ifdef VBOX_HGCM
|
---|
362 | case PDMINTERFACE_HGCM_CONNECTOR:
|
---|
363 | return &pDrv->HGCMConnector;
|
---|
364 | #endif
|
---|
365 | default:
|
---|
366 | return NULL;
|
---|
367 | }
|
---|
368 | }
|
---|
369 |
|
---|
370 |
|
---|
371 | /**
|
---|
372 | * Destruct a VMMDev driver instance.
|
---|
373 | *
|
---|
374 | * @returns VBox status.
|
---|
375 | * @param pDrvIns The driver instance data.
|
---|
376 | */
|
---|
377 | DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
378 | {
|
---|
379 | PDRVMAINVMMDEV pData = PDMINS2DATA(pDrvIns, PDRVMAINVMMDEV);
|
---|
380 | LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
381 | #ifdef VBOX_HGCM
|
---|
382 | /* Unload Shared Folder HGCM service */
|
---|
383 | if (pData->pVMMDev->mSharedFolderClientId)
|
---|
384 | {
|
---|
385 | uint64_t dummy = 0;
|
---|
386 | PVBOXHGCMCMD cmd = (PVBOXHGCMCMD)&dummy;
|
---|
387 |
|
---|
388 | pData->pVMMDev->hgcmDisconnect(cmd, pData->pVMMDev->getShFlClientId());
|
---|
389 | }
|
---|
390 |
|
---|
391 | /// @todo hgcmShutdown
|
---|
392 | #endif
|
---|
393 | if (pData->pVMMDev)
|
---|
394 | {
|
---|
395 | pData->pVMMDev->mpDrv = NULL;
|
---|
396 | }
|
---|
397 | }
|
---|
398 |
|
---|
399 | /**
|
---|
400 | * Reset notification.
|
---|
401 | *
|
---|
402 | * @returns VBox status.
|
---|
403 | * @param pDrvIns The driver instance data.
|
---|
404 | */
|
---|
405 | DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
|
---|
406 | {
|
---|
407 | PDRVMAINVMMDEV pData = PDMINS2DATA(pDrvIns, PDRVMAINVMMDEV);
|
---|
408 | LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
|
---|
409 | #ifdef VBOX_HGCM
|
---|
410 | /* Unload Shared Folder HGCM service */
|
---|
411 | if (pData->pVMMDev->mSharedFolderClientId)
|
---|
412 | {
|
---|
413 | uint64_t dummy = 0;
|
---|
414 | PVBOXHGCMCMD cmd = (PVBOXHGCMCMD)&dummy;
|
---|
415 |
|
---|
416 | pData->pVMMDev->hgcmDisconnect(cmd, pData->pVMMDev->getShFlClientId());
|
---|
417 |
|
---|
418 | /* Reload Shared Folder HGCM service */
|
---|
419 | HGCMSERVICELOCATION loc;
|
---|
420 |
|
---|
421 | cmd = (PVBOXHGCMCMD)&dummy;
|
---|
422 |
|
---|
423 | Log(("Connect to Shared Folders service\n"));
|
---|
424 | pData->pVMMDev->mSharedFolderClientId = 0;
|
---|
425 | loc.type = VMMDevHGCMLoc_LocalHost;
|
---|
426 | strcpy(loc.u.host.achName, "VBoxSharedFolders");
|
---|
427 | int rc = pData->pVMMDev->hgcmConnect(cmd, &loc, &pData->pVMMDev->mSharedFolderClientId);
|
---|
428 | if (rc != VINF_SUCCESS)
|
---|
429 | {
|
---|
430 | AssertMsgFailed(("hgcmConnect returned %Vrc\n", rc));
|
---|
431 | }
|
---|
432 | }
|
---|
433 | #endif
|
---|
434 | }
|
---|
435 |
|
---|
436 | /**
|
---|
437 | * Construct a VMMDev driver instance.
|
---|
438 | *
|
---|
439 | * @returns VBox status.
|
---|
440 | * @param pDrvIns The driver instance data.
|
---|
441 | * If the registration structure is needed, pDrvIns->pDrvReg points to it.
|
---|
442 | * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
|
---|
443 | * of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
|
---|
444 | * iInstance it's expected to be used a bit in this function.
|
---|
445 | */
|
---|
446 | DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
|
---|
447 | {
|
---|
448 | PDRVMAINVMMDEV pData = PDMINS2DATA(pDrvIns, PDRVMAINVMMDEV);
|
---|
449 | LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
450 |
|
---|
451 | /*
|
---|
452 | * Validate configuration.
|
---|
453 | */
|
---|
454 | if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
|
---|
455 | return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
|
---|
456 | PPDMIBASE pBaseIgnore;
|
---|
457 | int rc = pDrvIns->pDrvHlp->pfnAttach(pDrvIns, &pBaseIgnore);
|
---|
458 | if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
|
---|
459 | {
|
---|
460 | AssertMsgFailed(("Configuration error: Not possible to attach anything to this driver!\n"));
|
---|
461 | return VERR_PDM_DRVINS_NO_ATTACH;
|
---|
462 | }
|
---|
463 |
|
---|
464 | /*
|
---|
465 | * IBase.
|
---|
466 | */
|
---|
467 | pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
|
---|
468 |
|
---|
469 | pData->Connector.pfnUpdateGuestVersion = vmmdevUpdateGuestVersion;
|
---|
470 | pData->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
|
---|
471 | pData->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
|
---|
472 | pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
|
---|
473 | pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
|
---|
474 | pData->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
|
---|
475 | pData->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
|
---|
476 | pData->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
|
---|
477 |
|
---|
478 | #ifdef VBOX_HGCM
|
---|
479 | pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
|
---|
480 | pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
|
---|
481 | pData->HGCMConnector.pfnCall = iface_hgcmCall;
|
---|
482 | #endif
|
---|
483 |
|
---|
484 | /*
|
---|
485 | * Get the IVMMDevPort interface of the above driver/device.
|
---|
486 | */
|
---|
487 | pData->pUpPort = (PPDMIVMMDEVPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_VMMDEV_PORT);
|
---|
488 | if (!pData->pUpPort)
|
---|
489 | {
|
---|
490 | AssertMsgFailed(("Configuration error: No VMMDev port interface above!\n"));
|
---|
491 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
492 | }
|
---|
493 |
|
---|
494 | #ifdef VBOX_HGCM
|
---|
495 | pData->pHGCMPort = (PPDMIHGCMPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_HGCM_PORT);
|
---|
496 | if (!pData->pHGCMPort)
|
---|
497 | {
|
---|
498 | AssertMsgFailed(("Configuration error: No HGCM port interface above!\n"));
|
---|
499 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
500 | }
|
---|
501 | #endif
|
---|
502 |
|
---|
503 | /*
|
---|
504 | * Get the Console object pointer and update the mpDrv member.
|
---|
505 | */
|
---|
506 | void *pv;
|
---|
507 | rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
|
---|
508 | if (VBOX_FAILURE(rc))
|
---|
509 | {
|
---|
510 | AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Vrc\n", rc));
|
---|
511 | return rc;
|
---|
512 | }
|
---|
513 |
|
---|
514 | pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
|
---|
515 | pData->pVMMDev->mpDrv = pData;
|
---|
516 |
|
---|
517 | #ifdef VBOX_HGCM
|
---|
518 |
|
---|
519 | /* Load Shared Folder HGCM service */
|
---|
520 | HGCMSERVICELOCATION loc;
|
---|
521 | uint64_t dummy = 0;
|
---|
522 | PVBOXHGCMCMD pCmd = (PVBOXHGCMCMD)&dummy;
|
---|
523 |
|
---|
524 | Log(("Connect to Shared Folders service\n"));
|
---|
525 | pData->pVMMDev->mSharedFolderClientId = 0;
|
---|
526 |
|
---|
527 | rc = pData->pVMMDev->hgcmLoadService ("VBoxSharedFolders", "VBoxSharedFolders");
|
---|
528 |
|
---|
529 | if (rc == VINF_SUCCESS)
|
---|
530 | {
|
---|
531 | loc.type = VMMDevHGCMLoc_LocalHost;
|
---|
532 | strcpy(loc.u.host.achName, "VBoxSharedFolders");
|
---|
533 | rc = pData->pVMMDev->hgcmConnect(pCmd, &loc, &pData->pVMMDev->mSharedFolderClientId);
|
---|
534 | }
|
---|
535 |
|
---|
536 | if (rc != VINF_SUCCESS)
|
---|
537 | {
|
---|
538 | Log(("hgcmConnect returned %Vrc, shared folders are unavailable!!!\n", rc));
|
---|
539 |
|
---|
540 | /* This is not a fatal error; the shared folder dll can e.g. be missing */
|
---|
541 | rc = VINF_SUCCESS;
|
---|
542 | pData->pVMMDev->mSharedFolderClientId = 0;
|
---|
543 | }
|
---|
544 | #endif
|
---|
545 |
|
---|
546 | return VINF_SUCCESS;
|
---|
547 | }
|
---|
548 |
|
---|
549 |
|
---|
550 | /**
|
---|
551 | * VMMDevice driver registration record.
|
---|
552 | */
|
---|
553 | const PDMDRVREG VMMDev::DrvReg =
|
---|
554 | {
|
---|
555 | /* u32Version */
|
---|
556 | PDM_DRVREG_VERSION,
|
---|
557 | /* szDriverName */
|
---|
558 | "MainVMMDev",
|
---|
559 | /* pszDescription */
|
---|
560 | "Main VMMDev driver (Main as in the API).",
|
---|
561 | /* fFlags */
|
---|
562 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
563 | /* fClass. */
|
---|
564 | PDM_DRVREG_CLASS_VMMDEV,
|
---|
565 | /* cMaxInstances */
|
---|
566 | ~0,
|
---|
567 | /* cbInstance */
|
---|
568 | sizeof(DRVMAINVMMDEV),
|
---|
569 | /* pfnConstruct */
|
---|
570 | VMMDev::drvConstruct,
|
---|
571 | /* pfnDestruct */
|
---|
572 | VMMDev::drvDestruct,
|
---|
573 | /* pfnIOCtl */
|
---|
574 | NULL,
|
---|
575 | /* pfnPowerOn */
|
---|
576 | NULL,
|
---|
577 | /* pfnReset */
|
---|
578 | VMMDev::drvReset,
|
---|
579 | /* pfnSuspend */
|
---|
580 | NULL,
|
---|
581 | /* pfnResume */
|
---|
582 | NULL,
|
---|
583 | /* pfnDetach */
|
---|
584 | NULL
|
---|
585 | };
|
---|