VirtualBox

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

Last change on this file since 6468 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

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