VirtualBox

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

Last change on this file since 32357 was 30776, checked in by vboxsync, 15 years ago

VBoxBFE: Missing VMMDev bits.

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