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