VirtualBox

source: vbox/trunk/src/VBox/Main/VMMDevInterface.cpp@ 29034

Last change on this file since 29034 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.9 KB
Line 
1/* $Id: VMMDevInterface.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to VMM device.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "VMMDev.h"
19#include "ConsoleImpl.h"
20#include "DisplayImpl.h"
21#include "GuestImpl.h"
22#include "MouseImpl.h"
23
24#include "Logging.h"
25
26#include <VBox/pdmdrv.h>
27#include <VBox/VMMDev.h>
28#include <VBox/shflsvc.h>
29#include <iprt/asm.h>
30
31#ifdef VBOX_WITH_HGCM
32#include "hgcm/HGCM.h"
33#include "hgcm/HGCMObjects.h"
34# if defined(RT_OS_DARWIN) && defined(VBOX_WITH_CROGL)
35# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
36# endif
37#endif
38
39//
40// defines
41//
42
43#ifdef RT_OS_OS2
44# define VBOXSHAREDFOLDERS_DLL "VBoxSFld"
45#else
46# define VBOXSHAREDFOLDERS_DLL "VBoxSharedFolders"
47#endif
48
49//
50// globals
51//
52
53
54/**
55 * VMMDev driver instance data.
56 */
57typedef struct DRVMAINVMMDEV
58{
59 /** Pointer to the VMMDev object. */
60 VMMDev *pVMMDev;
61 /** Pointer to the driver instance structure. */
62 PPDMDRVINS pDrvIns;
63 /** Pointer to the VMMDev port interface of the driver/device above us. */
64 PPDMIVMMDEVPORT pUpPort;
65 /** Our VMM device connector interface. */
66 PDMIVMMDEVCONNECTOR Connector;
67
68#ifdef VBOX_WITH_HGCM
69 /** Pointer to the HGCM port interface of the driver/device above us. */
70 PPDMIHGCMPORT pHGCMPort;
71 /** Our HGCM connector interface. */
72 PDMIHGCMCONNECTOR HGCMConnector;
73#endif
74} DRVMAINVMMDEV, *PDRVMAINVMMDEV;
75
76/** Converts PDMIVMMDEVCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
77#define PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, Connector)) )
78
79#ifdef VBOX_WITH_HGCM
80/** Converts PDMIHGCMCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
81#define PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, HGCMConnector)) )
82#endif
83
84//
85// constructor / destructor
86//
87VMMDev::VMMDev(Console *console)
88 : mpDrv(NULL),
89 mParent(console)
90{
91 int rc = RTSemEventCreate(&mCredentialsEvent);
92 AssertRC(rc);
93#ifdef VBOX_WITH_HGCM
94 rc = HGCMHostInit ();
95 AssertRC(rc);
96 m_fHGCMActive = true;
97#endif /* VBOX_WITH_HGCM */
98 mu32CredentialsFlags = 0;
99}
100
101VMMDev::~VMMDev()
102{
103#ifdef VBOX_WITH_HGCM
104 if (hgcmIsActive())
105 {
106 ASMAtomicWriteBool(&m_fHGCMActive, false);
107 HGCMHostShutdown();
108 }
109#endif /* VBOX_WITH_HGCM */
110 RTSemEventDestroy (mCredentialsEvent);
111 if (mpDrv)
112 mpDrv->pVMMDev = NULL;
113 mpDrv = NULL;
114}
115
116PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
117{
118 Assert(mpDrv);
119 return mpDrv->pUpPort;
120}
121
122
123
124//
125// public methods
126//
127
128/**
129 * Wait on event semaphore for guest credential judgement result.
130 */
131int VMMDev::WaitCredentialsJudgement (uint32_t u32Timeout, uint32_t *pu32CredentialsFlags)
132{
133 if (u32Timeout == 0)
134 {
135 u32Timeout = 5000;
136 }
137
138 int rc = RTSemEventWait (mCredentialsEvent, u32Timeout);
139
140 if (RT_SUCCESS(rc))
141 {
142 *pu32CredentialsFlags = mu32CredentialsFlags;
143 }
144
145 return rc;
146}
147
148int VMMDev::SetCredentialsJudgementResult (uint32_t u32Flags)
149{
150 mu32CredentialsFlags = u32Flags;
151
152 int rc = RTSemEventSignal (mCredentialsEvent);
153 AssertRC(rc);
154
155 return rc;
156}
157
158
159/**
160 * Report guest OS version.
161 * Called whenever the Additions issue a guest version report request or the VM is reset.
162 *
163 * @param pInterface Pointer to this interface.
164 * @param guestInfo Pointer to guest information structure
165 * @thread The emulation thread.
166 */
167DECLCALLBACK(void) vmmdevUpdateGuestVersion(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestInfo *guestInfo)
168{
169 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
170
171 Assert(guestInfo);
172 if (!guestInfo)
173 return;
174
175 /* store that information in IGuest */
176 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
177 Assert(guest);
178 if (!guest)
179 return;
180
181 if (guestInfo->additionsVersion != 0)
182 {
183 char version[20];
184 RTStrPrintf(version, sizeof(version), "%d", guestInfo->additionsVersion);
185 guest->setAdditionsVersion(Bstr(version), guestInfo->osType);
186
187 /*
188 * Tell the console interface about the event
189 * so that it can notify its consumers.
190 */
191 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
192
193 if (guestInfo->additionsVersion < VMMDEV_VERSION)
194 pDrv->pVMMDev->getParent()->onAdditionsOutdated();
195 }
196 else
197 {
198 /*
199 * The guest additions was disabled because of a reset
200 * or driver unload.
201 */
202 guest->setAdditionsVersion (Bstr(), guestInfo->osType);
203 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
204 }
205}
206
207/**
208 * Update the guest additions capabilities.
209 * This is called when the guest additions capabilities change. The new capabilities
210 * are given and the connector should update its internal state.
211 *
212 * @param pInterface Pointer to this interface.
213 * @param newCapabilities New capabilities.
214 * @thread The emulation thread.
215 */
216DECLCALLBACK(void) vmmdevUpdateGuestCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
217{
218 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
219
220 /* store that information in IGuest */
221 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
222 Assert(guest);
223 if (!guest)
224 return;
225
226 guest->setSupportsSeamless(BOOL (newCapabilities & VMMDEV_GUEST_SUPPORTS_SEAMLESS));
227 guest->setSupportsGraphics(BOOL (newCapabilities & VMMDEV_GUEST_SUPPORTS_GRAPHICS));
228
229 /*
230 * Tell the console interface about the event
231 * so that it can notify its consumers.
232 */
233 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
234
235}
236
237/**
238 * Update the mouse capabilities.
239 * This is called when the mouse capabilities change. The new capabilities
240 * are given and the connector should update its internal state.
241 *
242 * @param pInterface Pointer to this interface.
243 * @param newCapabilities New capabilities.
244 * @thread The emulation thread.
245 */
246DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
247{
248 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
249 /*
250 * Tell the console interface about the event
251 * so that it can notify its consumers.
252 */
253 Mouse *pMouse = pDrv->pVMMDev->getParent()->getMouse();
254 if (pMouse) /** @todo and if not? Can that actually happen? */
255 {
256 pMouse->onVMMDevCanAbsChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE));
257 pMouse->onVMMDevNeedsHostChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR));
258 }
259}
260
261
262/**
263 * Update the pointer shape or visibility.
264 *
265 * This is called when the mouse pointer shape changes or pointer is hidden/displaying.
266 * The new shape is passed as a caller allocated buffer that will be freed after returning.
267 *
268 * @param pInterface Pointer to this interface.
269 * @param fVisible Whether the pointer is visible or not.
270 * @param fAlpha Alpha channel information is present.
271 * @param xHot Horizontal coordinate of the pointer hot spot.
272 * @param yHot Vertical coordinate of the pointer hot spot.
273 * @param width Pointer width in pixels.
274 * @param height Pointer height in pixels.
275 * @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
276 * @thread The emulation thread.
277 */
278DECLCALLBACK(void) vmmdevUpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
279 uint32_t xHot, uint32_t yHot,
280 uint32_t width, uint32_t height,
281 void *pShape)
282{
283 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
284
285 /* tell the console about it */
286 pDrv->pVMMDev->getParent()->onMousePointerShapeChange(fVisible, fAlpha,
287 xHot, yHot, width, height, pShape);
288}
289
290DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
291{
292 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
293
294 Display *display = pDrv->pVMMDev->getParent()->getDisplay();
295
296 if (display)
297 {
298 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
299 return display->VideoAccelEnable (fEnable, pVbvaMemory);
300 }
301
302 return VERR_NOT_SUPPORTED;
303}
304DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
305{
306 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
307
308 Display *display = pDrv->pVMMDev->getParent()->getDisplay();
309
310 if (display)
311 {
312 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
313 display->VideoAccelFlush ();
314 }
315}
316
317DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t display, uint32_t width, uint32_t height,
318 uint32_t bpp, bool *fSupported)
319{
320 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
321
322 if (!fSupported)
323 return VERR_INVALID_PARAMETER;
324#ifdef DEBUG_sunlover
325 Log(("vmmdevVideoModeSupported: [%d]: %dx%dx%d\n", display, width, height, bpp));
326#endif
327 IFramebuffer *framebuffer = NULL;
328 LONG xOrigin = 0;
329 LONG yOrigin = 0;
330 HRESULT hrc = pDrv->pVMMDev->getParent()->getDisplay()->GetFramebuffer(display, &framebuffer, &xOrigin, &yOrigin);
331 if (SUCCEEDED(hrc) && framebuffer)
332 {
333 framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
334 framebuffer->Release();
335 }
336 else
337 {
338#ifdef DEBUG_sunlover
339 Log(("vmmdevVideoModeSupported: hrc %x, framebuffer %p!!!\n", hrc, framebuffer));
340#endif
341 *fSupported = true;
342 }
343 return VINF_SUCCESS;
344}
345
346DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
347{
348 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
349
350 if (!heightReduction)
351 return VERR_INVALID_PARAMETER;
352 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
353 if (framebuffer)
354 framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
355 else
356 *heightReduction = 0;
357 return VINF_SUCCESS;
358}
359
360DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
361{
362 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
363
364 int rc = pDrv->pVMMDev->SetCredentialsJudgementResult (u32Flags);
365
366 return rc;
367}
368
369DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
370{
371 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
372
373 if (!cRect)
374 return VERR_INVALID_PARAMETER;
375#ifdef MMSEAMLESS
376 /* Forward to Display, which calls corresponding framebuffers. */
377 pDrv->pVMMDev->getParent()->getDisplay()->handleSetVisibleRegion(cRect, pRect);
378#else
379 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
380 if (framebuffer)
381 {
382 framebuffer->SetVisibleRegion((BYTE *)pRect, cRect);
383#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
384 {
385 BOOL is3denabled;
386
387 pDrv->pVMMDev->getParent()->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
388
389 if (is3denabled)
390 {
391 VBOXHGCMSVCPARM parms[2];
392
393 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
394 parms[0].u.pointer.addr = pRect;
395 parms[0].u.pointer.size = 0; /* We don't actually care. */
396 parms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
397 parms[1].u.uint32 = cRect;
398
399 int rc = pDrv->pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VISIBLE_REGION, 2, &parms[0]);
400 return rc;
401 }
402 }
403#endif
404 }
405#endif
406
407 return VINF_SUCCESS;
408}
409
410DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
411{
412 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
413
414#ifdef MMSEAMLESS
415 /* Forward to Display, which calls corresponding framebuffers. */
416 pDrv->pVMMDev->getParent()->getDisplay()->handleQueryVisibleRegion(pcRect, pRect);
417#else
418 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
419 if (framebuffer)
420 {
421 ULONG cRect = 0;
422 framebuffer->GetVisibleRegion((BYTE *)pRect, cRect, &cRect);
423
424 *pcRect = cRect;
425 }
426#endif
427
428 return VINF_SUCCESS;
429}
430
431/**
432 * Request the statistics interval
433 *
434 * @returns VBox status code.
435 * @param pInterface Pointer to this interface.
436 * @param pulInterval Pointer to interval in seconds
437 * @thread The emulation thread.
438 */
439DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
440{
441 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
442 ULONG val = 0;
443
444 if (!pulInterval)
445 return VERR_INVALID_POINTER;
446
447 /* store that information in IGuest */
448 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
449 Assert(guest);
450 if (!guest)
451 return VERR_INVALID_PARAMETER; /** @todo wrong error */
452
453 guest->COMGETTER(StatisticsUpdateInterval)(&val);
454 *pulInterval = val;
455 return VINF_SUCCESS;
456}
457
458/**
459 * Query the current balloon size
460 *
461 * @returns VBox status code.
462 * @param pInterface Pointer to this interface.
463 * @param pcbBalloon Balloon size
464 * @thread The emulation thread.
465 */
466DECLCALLBACK(int) vmmdevQueryBalloonSize(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcbBalloon)
467{
468 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
469 ULONG val = 0;
470
471 if (!pcbBalloon)
472 return VERR_INVALID_POINTER;
473
474 /* store that information in IGuest */
475 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
476 Assert(guest);
477 if (!guest)
478 return VERR_INVALID_PARAMETER; /** @todo wrong error */
479
480 guest->COMGETTER(MemoryBalloonSize)(&val);
481 *pcbBalloon = val;
482 return VINF_SUCCESS;
483}
484
485/**
486 * Report new guest statistics
487 *
488 * @returns VBox status code.
489 * @param pInterface Pointer to this interface.
490 * @param pGuestStats Guest statistics
491 * @thread The emulation thread.
492 */
493DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
494{
495 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
496
497 Assert(pGuestStats);
498 if (!pGuestStats)
499 return VERR_INVALID_POINTER;
500
501 /* store that information in IGuest */
502 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
503 Assert(guest);
504 if (!guest)
505 return VERR_INVALID_PARAMETER; /** @todo wrong error */
506
507 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
508 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
509
510 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
511 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
512
513 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
514 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
515
516
517 /** @todo r=bird: Convert from 4KB to 1KB units?
518 * CollectorGuestHAL::getGuestMemLoad says it returns KB units to
519 * preCollect(). I might be wrong ofc, this is convoluted code... */
520 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
521 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
522
523 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
524 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
525
526 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
527 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
528
529 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
530 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
531
532 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
533 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
534
535 return VINF_SUCCESS;
536}
537
538#ifdef VBOX_WITH_HGCM
539
540/* HGCM connector interface */
541
542static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
543{
544 LogSunlover(("Enter\n"));
545
546 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
547
548 if ( !pServiceLocation
549 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
550 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
551 {
552 return VERR_INVALID_PARAMETER;
553 }
554
555 if (!pDrv->pVMMDev->hgcmIsActive ())
556 {
557 return VERR_INVALID_STATE;
558 }
559
560 return HGCMGuestConnect (pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
561}
562
563static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
564{
565 LogSunlover(("Enter\n"));
566
567 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
568
569 if (!pDrv->pVMMDev->hgcmIsActive ())
570 {
571 return VERR_INVALID_STATE;
572 }
573
574 return HGCMGuestDisconnect (pDrv->pHGCMPort, pCmd, u32ClientID);
575}
576
577static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
578 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
579{
580 LogSunlover(("Enter\n"));
581
582 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
583
584 if (!pDrv->pVMMDev->hgcmIsActive ())
585 {
586 return VERR_INVALID_STATE;
587 }
588
589 return HGCMGuestCall (pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
590}
591
592/**
593 * Execute state save operation.
594 *
595 * @returns VBox status code.
596 * @param pDrvIns Driver instance of the driver which registered the data unit.
597 * @param pSSM SSM operation handle.
598 */
599static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
600{
601 LogSunlover(("Enter\n"));
602 return HGCMHostSaveState (pSSM);
603}
604
605
606/**
607 * Execute state load operation.
608 *
609 * @returns VBox status code.
610 * @param pDrvIns Driver instance of the driver which registered the data unit.
611 * @param pSSM SSM operation handle.
612 * @param uVersion Data layout version.
613 * @param uPass The data pass.
614 */
615static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
616{
617 LogFlowFunc(("Enter\n"));
618
619 if (uVersion != HGCM_SSM_VERSION)
620 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
621 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
622
623 return HGCMHostLoadState (pSSM);
624}
625
626int VMMDev::hgcmLoadService (const char *pszServiceLibrary, const char *pszServiceName)
627{
628 if (!hgcmIsActive ())
629 {
630 return VERR_INVALID_STATE;
631 }
632 return HGCMHostLoad (pszServiceLibrary, pszServiceName);
633}
634
635int VMMDev::hgcmHostCall (const char *pszServiceName, uint32_t u32Function,
636 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
637{
638 if (!hgcmIsActive ())
639 {
640 return VERR_INVALID_STATE;
641 }
642 return HGCMHostCall (pszServiceName, u32Function, cParms, paParms);
643}
644
645void VMMDev::hgcmShutdown (void)
646{
647 ASMAtomicWriteBool(&m_fHGCMActive, false);
648 HGCMHostShutdown ();
649}
650
651#endif /* HGCM */
652
653
654/**
655 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
656 */
657DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
658{
659 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
660 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
661
662 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
663 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
664#ifdef VBOX_WITH_HGCM
665 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
666#endif
667 return NULL;
668}
669
670/**
671 * Destruct a VMMDev driver instance.
672 *
673 * @returns VBox status.
674 * @param pDrvIns The driver instance data.
675 */
676DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
677{
678 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
679 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
680#ifdef VBOX_WITH_HGCM
681 /* HGCM is shut down on the VMMDev destructor. */
682#endif /* VBOX_WITH_HGCM */
683 if (pData->pVMMDev)
684 {
685 pData->pVMMDev->mpDrv = NULL;
686 }
687}
688
689/**
690 * Reset notification.
691 *
692 * @returns VBox status.
693 * @param pDrvIns The driver instance data.
694 */
695DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
696{
697 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
698#ifdef VBOX_WITH_HGCM
699 HGCMHostReset ();
700#endif /* VBOX_WITH_HGCM */
701}
702
703/**
704 * Construct a VMMDev driver instance.
705 *
706 * @copydoc FNPDMDRVCONSTRUCT
707 */
708DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
709{
710 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
711 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
712
713 /*
714 * Validate configuration.
715 */
716 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
717 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
718 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
719 ("Configuration error: Not possible to attach anything to this driver!\n"),
720 VERR_PDM_DRVINS_NO_ATTACH);
721
722 /*
723 * IBase.
724 */
725 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
726
727 pData->Connector.pfnUpdateGuestVersion = vmmdevUpdateGuestVersion;
728 pData->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
729 pData->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
730 pData->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
731 pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
732 pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
733 pData->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
734 pData->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
735 pData->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
736 pData->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
737 pData->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
738 pData->Connector.pfnReportStatistics = vmmdevReportStatistics;
739 pData->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
740 pData->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
741
742#ifdef VBOX_WITH_HGCM
743 pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
744 pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
745 pData->HGCMConnector.pfnCall = iface_hgcmCall;
746#endif
747
748 /*
749 * Get the IVMMDevPort interface of the above driver/device.
750 */
751 pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
752 AssertMsgReturn(pData->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
753
754#ifdef VBOX_WITH_HGCM
755 pData->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
756 AssertMsgReturn(pData->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
757#endif
758
759 /*
760 * Get the Console object pointer and update the mpDrv member.
761 */
762 void *pv;
763 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
764 if (RT_FAILURE(rc))
765 {
766 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
767 return rc;
768 }
769
770 pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
771 pData->pVMMDev->mpDrv = pData;
772
773#ifdef VBOX_WITH_HGCM
774 rc = pData->pVMMDev->hgcmLoadService (VBOXSHAREDFOLDERS_DLL,
775 "VBoxSharedFolders");
776 pData->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
777 if (RT_SUCCESS(rc))
778 {
779 PPDMLED pLed;
780 PPDMILEDPORTS pLedPort;
781
782 LogRel(("Shared Folders service loaded.\n"));
783 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
784 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
785 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
786 if (RT_SUCCESS(rc) && pLed)
787 {
788 VBOXHGCMSVCPARM parm;
789
790 parm.type = VBOX_HGCM_SVC_PARM_PTR;
791 parm.u.pointer.addr = pLed;
792 parm.u.pointer.size = sizeof(*pLed);
793
794 rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
795 }
796 else
797 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
798 }
799 else
800 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
801
802 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
803 NULL, NULL, NULL,
804 NULL, iface_hgcmSave, NULL,
805 NULL, iface_hgcmLoad, NULL);
806 if (RT_FAILURE(rc))
807 return rc;
808
809#endif /* VBOX_WITH_HGCM */
810
811 return VINF_SUCCESS;
812}
813
814
815/**
816 * VMMDevice driver registration record.
817 */
818const PDMDRVREG VMMDev::DrvReg =
819{
820 /* u32Version */
821 PDM_DRVREG_VERSION,
822 /* szName */
823 "HGCM",
824 /* szRCMod */
825 "",
826 /* szR0Mod */
827 "",
828 /* pszDescription */
829 "Main VMMDev driver (Main as in the API).",
830 /* fFlags */
831 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
832 /* fClass. */
833 PDM_DRVREG_CLASS_VMMDEV,
834 /* cMaxInstances */
835 ~0,
836 /* cbInstance */
837 sizeof(DRVMAINVMMDEV),
838 /* pfnConstruct */
839 VMMDev::drvConstruct,
840 /* pfnDestruct */
841 VMMDev::drvDestruct,
842 /* pfnRelocate */
843 NULL,
844 /* pfnIOCtl */
845 NULL,
846 /* pfnPowerOn */
847 NULL,
848 /* pfnReset */
849 VMMDev::drvReset,
850 /* pfnSuspend */
851 NULL,
852 /* pfnResume */
853 NULL,
854 /* pfnAttach */
855 NULL,
856 /* pfnDetach */
857 NULL,
858 /* pfnPowerOff */
859 NULL,
860 /* pfnSoftReset */
861 NULL,
862 /* u32EndVersion */
863 PDM_DRVREG_VERSION
864};
865/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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