VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/VMMDevInterface.cpp@ 26951

Last change on this file since 26951 was 26834, checked in by vboxsync, 15 years ago

FE/BFE: resynchronise MouseImpl from Main

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.8 KB
Line 
1/* $Id: VMMDevInterface.cpp 26834 2010-02-26 12:10:36Z vboxsync $ */
2/** @file
3 * VBox frontends: Basic Frontend (BFE):
4 * Implementation of VMMDev: driver interface to VMM device
5 */
6
7/*
8 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#define LOG_GROUP LOG_GROUP_MAIN
24
25#ifdef VBOXBFE_WITHOUT_COM
26# include "COMDefs.h"
27#else
28# include <VBox/com/defs.h>
29#endif
30#include <VBox/pdm.h>
31#include <VBox/VMMDev.h>
32#include <VBox/cfgm.h>
33#include <VBox/err.h>
34#include <iprt/assert.h>
35#include <VBox/log.h>
36#include <iprt/asm.h>
37#include <iprt/uuid.h>
38
39#include "VBoxBFE.h"
40#include "VMMDevInterface.h"
41#include "MouseImpl.h"
42#include "DisplayImpl.h"
43#include "ConsoleImpl.h"
44#ifdef VBOX_WITH_HGCM
45#include "HGCM.h"
46#endif
47
48#ifdef RT_OS_OS2
49# define VBOXSHAREDFOLDERS_DLL "VBoxSFld"
50#else
51# define VBOXSHAREDFOLDERS_DLL "VBoxSharedFolders"
52#endif
53
54#ifdef RT_OS_L4
55#include <l4/util/util.h> /* for l4_sleep */
56#endif
57/**
58 * VMMDev driver instance data.
59 */
60typedef struct DRVMAINVMMDEV
61{
62 /** Pointer to the VMMDev object. */
63 VMMDev *pVMMDev;
64 /** Pointer to the driver instance structure. */
65 PPDMDRVINS pDrvIns;
66 /** Pointer to the VMMDev port interface of the driver/device above us. */
67 PPDMIVMMDEVPORT pUpPort;
68 /** Our VMM device connector interface. */
69 PDMIVMMDEVCONNECTOR Connector;
70
71#ifdef VBOX_WITH_HGCM
72 /** Pointer to the HGCM port interface of the driver/device above us. */
73 PPDMIHGCMPORT pHGCMPort;
74 /** Our HGCM connector interface. */
75 PDMIHGCMCONNECTOR HGCMConnector;
76#endif
77} DRVMAINVMMDEV, *PDRVMAINVMMDEV;
78
79/** Converts PDMIVMMDEVCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
80#define PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, Connector)) )
81
82#ifdef VBOX_WITH_HGCM
83/** Converts PDMIHGCMCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
84#define PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, HGCMConnector)) )
85#endif
86
87VMMDev::VMMDev() : mpDrv(NULL)
88{
89#ifdef VBOX_WITH_HGCM
90 int rc = VINF_SUCCESS;
91 if (fActivateHGCM())
92 rc = HGCMHostInit();
93 AssertRC(rc);
94#endif
95}
96
97VMMDev::~VMMDev()
98{
99#ifdef VBOX_WITH_HGCM
100 if (fActivateHGCM())
101 HGCMHostShutdown ();
102#endif /* VBOX_WITH_HGCM */
103}
104
105
106PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
107{
108 Assert(mpDrv);
109 return mpDrv->pUpPort;
110}
111
112int VMMDev::SetMouseCapabilities(uint32_t mouseCaps)
113{
114 return mpDrv->pUpPort->pfnSetMouseCapabilities(mpDrv->pUpPort, mouseCaps);
115}
116
117
118int VMMDev::SetAbsoluteMouse(uint32_t mouseXAbs, uint32_t mouseYAbs)
119{
120 return mpDrv->pUpPort->pfnSetAbsoluteMouse(mpDrv->pUpPort, mouseXAbs, mouseYAbs);
121}
122
123void VMMDev::QueryMouseCapabilities(uint32_t *pMouseCaps)
124{
125
126 Assert(mpDrv);
127 mpDrv->pUpPort->pfnQueryMouseCapabilities(mpDrv->pUpPort, pMouseCaps);
128}
129
130
131/**
132 * Report guest OS version.
133 * Called whenever the Additions issue a guest version report request.
134 *
135 * @param pInterface Pointer to this interface.
136 * @param guestInfo Pointer to guest information structure
137 * @thread The emulation thread.
138 */
139DECLCALLBACK(void) VMMDev::UpdateGuestVersion(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestInfo *guestInfo)
140{
141 return;
142}
143
144/**
145 * Update the guest additions capabilities.
146 * This is called when the guest additions capabilities change. The new capabilities
147 * are given and the connector should update its internal state.
148 *
149 * @param pInterface Pointer to this interface.
150 * @param newCapabilities New capabilities.
151 * @thread The emulation thread.
152 */
153DECLCALLBACK(void) VMMDev::UpdateGuestCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
154{
155 return;
156}
157
158/**
159 * Update the mouse capabilities.
160 * This is called when the mouse capabilities change. The new capabilities
161 * are given and the connector should update its internal state.
162 *
163 * @param pInterface Pointer to this interface.
164 * @param newCapabilities New capabilities.
165 * @thread The emulation thread.
166 */
167DECLCALLBACK(void) VMMDev::UpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
168{
169 /*
170 * Tell the console interface about the event so that it can notify its consumers.
171 */
172
173 if (gMouse)
174 {
175 gMouse->onVMMDevCanAbsChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE));
176 gMouse->onVMMDevNeedsHostChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR));
177 }
178 if (gConsole)
179 {
180 gConsole->resetCursor();
181 }
182}
183
184
185/**
186 * Update the pointer shape or visibility.
187 *
188 * This is called when the mouse pointer shape changes or pointer is hidden/displaying.
189 * The new shape is passed as a caller allocated buffer that will be freed after returning.
190 *
191 * @param pInterface Pointer to this interface.
192 * @param fVisible Whether the pointer is visible or not.
193 * @param fAlpha Alpha channel information is present.
194 * @param xHot Horizontal coordinate of the pointer hot spot.
195 * @param yHot Vertical coordinate of the pointer hot spot.
196 * @param width Pointer width in pixels.
197 * @param height Pointer height in pixels.
198 * @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
199 * @thread The emulation thread.
200 */
201DECLCALLBACK(void) VMMDev::UpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
202 uint32_t xHot, uint32_t yHot,
203 uint32_t width, uint32_t height,
204 void *pShape)
205{
206 if (gConsole)
207 gConsole->onMousePointerShapeChange(fVisible, fAlpha, xHot,
208 yHot, width, height, pShape);
209}
210
211DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
212{
213 LogFlow(("VMMDev::VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
214 if (gDisplay)
215 gDisplay->VideoAccelEnable (fEnable, pVbvaMemory);
216 return VINF_SUCCESS;
217}
218
219DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
220{
221 if (gDisplay)
222 gDisplay->VideoAccelFlush ();
223}
224
225DECLCALLBACK(int) iface_SetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
226{
227 /* not implemented */
228 return VINF_SUCCESS;
229}
230
231DECLCALLBACK(int) iface_QueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
232{
233 /* not implemented */
234 return VINF_SUCCESS;
235}
236
237DECLCALLBACK(int) VMMDev::VideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t width, uint32_t height,
238 uint32_t bpp, bool *fSupported)
239{
240 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
241 (void)pDrv;
242
243 if (!fSupported)
244 return VERR_INVALID_PARAMETER;
245 *fSupported = true;
246 return VINF_SUCCESS;
247}
248
249DECLCALLBACK(int) VMMDev::GetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
250{
251 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
252 (void)pDrv;
253
254 if (!heightReduction)
255 return VERR_INVALID_PARAMETER;
256 /* XXX hard-coded */
257 *heightReduction = 18;
258 return VINF_SUCCESS;
259}
260
261#ifdef VBOX_WITH_HGCM
262
263/* HGCM connector interface */
264
265static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
266{
267 LogSunlover(("Enter\n"));
268
269 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
270
271 if ( !pServiceLocation
272 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
273 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
274 {
275 return VERR_INVALID_PARAMETER;
276 }
277
278 return HGCMGuestConnect (pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
279}
280
281static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
282{
283 LogSunlover(("Enter\n"));
284
285 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
286
287 return HGCMGuestDisconnect (pDrv->pHGCMPort, pCmd, u32ClientID);
288}
289
290static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
291 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
292{
293 LogSunlover(("Enter\n"));
294
295 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
296
297 return HGCMGuestCall (pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
298}
299
300/**
301 * Execute state save operation.
302 *
303 * @returns VBox status code.
304 * @param pDrvIns Driver instance of the driver which registered the data unit.
305 * @param pSSM SSM operation handle.
306 */
307static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
308{
309 LogSunlover(("Enter\n"));
310 return HGCMHostSaveState (pSSM);
311}
312
313
314/**
315 * Execute state load operation.
316 *
317 * @returns VBox status code.
318 * @param pDrvIns Driver instance of the driver which registered the data unit.
319 * @param pSSM SSM operation handle.
320 * @param uVersion Data layout version.
321 * @param uPass The data pass.
322 */
323static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
324{
325 LogFlowFunc(("Enter\n"));
326
327 if (uVersion != HGCM_SSM_VERSION)
328 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
329 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
330
331 return HGCMHostLoadState (pSSM);
332}
333
334int VMMDev::hgcmLoadService (const char *pszServiceLibrary, const char *pszServiceName)
335{
336 return HGCMHostLoad (pszServiceLibrary, pszServiceName);
337}
338
339int VMMDev::hgcmHostCall (const char *pszServiceName, uint32_t u32Function,
340 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
341{
342 return HGCMHostCall (pszServiceName, u32Function, cParms, paParms);
343}
344#endif /* HGCM */
345
346/**
347 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
348 */
349DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
350{
351 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
352 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
353 if (RTUuidCompare2Strs(pszIID, PDMIBASE_IID) == 0)
354 return &pDrvIns->IBase;
355 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
356#ifdef VBOX_WITH_HGCM
357 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, fActivateHGCM() ? &pDrv->HGCMConnector : NULL);
358#endif
359 return NULL;
360}
361
362
363/**
364 * Destruct a VMMDev driver instance.
365 *
366 * @returns VBox status.
367 * @param pDrvIns The driver instance data.
368 */
369DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
370{
371 /*PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV); - unused variables makes gcc bitch. */
372}
373
374
375/**
376 * Construct a VMMDev driver instance.
377 *
378 * @copydoc FNPDMDRVCONSTRUCT
379 */
380DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
381{
382 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
383 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
384
385 /*
386 * Validate configuration.
387 */
388 if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
389 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
390 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
391 ("Configuration error: Not possible to attach anything to this driver!\n"),
392 VERR_PDM_DRVINS_NO_ATTACH);
393
394 /*
395 * IBase.
396 */
397 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
398
399 pData->Connector.pfnUpdateGuestVersion = VMMDev::UpdateGuestVersion;
400 pData->Connector.pfnUpdateGuestCapabilities = VMMDev::UpdateGuestCapabilities;
401 pData->Connector.pfnUpdateMouseCapabilities = VMMDev::UpdateMouseCapabilities;
402 pData->Connector.pfnUpdatePointerShape = VMMDev::UpdatePointerShape;
403 pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
404 pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
405 pData->Connector.pfnVideoModeSupported = VMMDev::VideoModeSupported;
406 pData->Connector.pfnGetHeightReduction = VMMDev::GetHeightReduction;
407 pData->Connector.pfnSetVisibleRegion = iface_SetVisibleRegion;
408 pData->Connector.pfnQueryVisibleRegion = iface_QueryVisibleRegion;
409
410#ifdef VBOX_WITH_HGCM
411 if (fActivateHGCM())
412 {
413 pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
414 pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
415 pData->HGCMConnector.pfnCall = iface_hgcmCall;
416 }
417#endif
418
419 /*
420 * Get the IVMMDevPort interface of the above driver/device.
421 */
422 pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
423 AssertMsgReturn(pData->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
424
425#ifdef VBOX_WITH_HGCM
426 if (fActivateHGCM())
427 {
428 pData->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
429 AssertMsgReturn(pData->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
430 }
431#endif
432
433 /*
434 * Get the VMMDev object pointer and update the mpDrv member.
435 */
436 void *pv;
437 int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
438 if (RT_FAILURE(rc))
439 {
440 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
441 return rc;
442 }
443
444 pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
445 pData->pVMMDev->mpDrv = pData;
446
447#ifdef VBOX_WITH_HGCM
448 if (fActivateHGCM())
449 {
450 rc = pData->pVMMDev->hgcmLoadService (VBOXSHAREDFOLDERS_DLL, "VBoxSharedFolders");
451 pData->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
452 if (RT_SUCCESS(rc))
453 LogRel(("Shared Folders service loaded.\n"));
454 else
455 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
456
457
458 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
459 NULL, NULL, NULL,
460 NULL, iface_hgcmSave, NULL,
461 NULL, iface_hgcmLoad, NULL);
462 if (RT_FAILURE(rc))
463 return rc;
464
465 }
466#endif /* VBOX_WITH_HGCM */
467
468 return VINF_SUCCESS;
469}
470
471
472/**
473 * VMMDevice driver registration record.
474 */
475const PDMDRVREG VMMDev::DrvReg =
476{
477 /* u32Version */
478 PDM_DRVREG_VERSION,
479 /* szName */
480 "HGCM",
481 /* szRCMod */
482 "",
483 /* szR0Mod */
484 "",
485 /* pszDescription */
486 "Main VMMDev driver (Main as in the API).",
487 /* fFlags */
488 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
489 /* fClass. */
490 PDM_DRVREG_CLASS_VMMDEV,
491 /* cMaxInstances */
492 ~0,
493 /* cbInstance */
494 sizeof(DRVMAINVMMDEV),
495 /* pfnConstruct */
496 VMMDev::drvConstruct,
497 /* pfnDestruct */
498 VMMDev::drvDestruct,
499 /* pfnRelocate */
500 NULL,
501 /* pfnIOCtl */
502 NULL,
503 /* pfnPowerOn */
504 NULL,
505 /* pfnReset */
506 NULL,
507 /* pfnSuspend */
508 NULL,
509 /* pfnResume */
510 NULL,
511 /* pfnAttach */
512 NULL,
513 /* pfnDetach */
514 NULL,
515 /* pfnPowerOff */
516 NULL,
517 /* pfnSoftReset */
518 NULL,
519 /* u32EndVersion */
520 PDM_DRVREG_VERSION
521};
522
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette