VirtualBox

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

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

Main: onMousePointerShapeChange reworked

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.2 KB
Line 
1/* $Id: VMMDevInterface.cpp 29518 2010-05-17 10:06:22Z 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 AssertReturn(mpDrv, NULL);
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 size_t cbShapeSize = (width + 7) / 8 * height; /* size of the AND mask */
287 cbShapeSize = ((cbShapeSize + 3) & ~3) + width * 4 * height; /* + gap + size of the XOR mask */
288 com::SafeArray<BYTE> shapeData(cbShapeSize);
289 ::memcpy(shapeData.raw(), pShape, cbShapeSize);
290 pDrv->pVMMDev->getParent()->onMousePointerShapeChange(fVisible, fAlpha,
291 xHot, yHot, width, height, ComSafeArrayAsInParam(shapeData));
292}
293
294DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
295{
296 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
297
298 Display *display = pDrv->pVMMDev->getParent()->getDisplay();
299
300 if (display)
301 {
302 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
303 return display->VideoAccelEnable (fEnable, pVbvaMemory);
304 }
305
306 return VERR_NOT_SUPPORTED;
307}
308DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
309{
310 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
311
312 Display *display = pDrv->pVMMDev->getParent()->getDisplay();
313
314 if (display)
315 {
316 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
317 display->VideoAccelFlush ();
318 }
319}
320
321DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t display, uint32_t width, uint32_t height,
322 uint32_t bpp, bool *fSupported)
323{
324 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
325
326 if (!fSupported)
327 return VERR_INVALID_PARAMETER;
328#ifdef DEBUG_sunlover
329 Log(("vmmdevVideoModeSupported: [%d]: %dx%dx%d\n", display, width, height, bpp));
330#endif
331 IFramebuffer *framebuffer = NULL;
332 LONG xOrigin = 0;
333 LONG yOrigin = 0;
334 HRESULT hrc = pDrv->pVMMDev->getParent()->getDisplay()->GetFramebuffer(display, &framebuffer, &xOrigin, &yOrigin);
335 if (SUCCEEDED(hrc) && framebuffer)
336 {
337 framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
338 framebuffer->Release();
339 }
340 else
341 {
342#ifdef DEBUG_sunlover
343 Log(("vmmdevVideoModeSupported: hrc %x, framebuffer %p!!!\n", hrc, framebuffer));
344#endif
345 *fSupported = true;
346 }
347 return VINF_SUCCESS;
348}
349
350DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
351{
352 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
353
354 if (!heightReduction)
355 return VERR_INVALID_PARAMETER;
356 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
357 if (framebuffer)
358 framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
359 else
360 *heightReduction = 0;
361 return VINF_SUCCESS;
362}
363
364DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
365{
366 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
367
368 int rc = pDrv->pVMMDev->SetCredentialsJudgementResult (u32Flags);
369
370 return rc;
371}
372
373DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
374{
375 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
376
377 if (!cRect)
378 return VERR_INVALID_PARAMETER;
379#ifdef MMSEAMLESS
380 /* Forward to Display, which calls corresponding framebuffers. */
381 pDrv->pVMMDev->getParent()->getDisplay()->handleSetVisibleRegion(cRect, pRect);
382#else
383 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
384 if (framebuffer)
385 {
386 framebuffer->SetVisibleRegion((BYTE *)pRect, cRect);
387#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
388 {
389 BOOL is3denabled;
390
391 pDrv->pVMMDev->getParent()->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
392
393 if (is3denabled)
394 {
395 VBOXHGCMSVCPARM parms[2];
396
397 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
398 parms[0].u.pointer.addr = pRect;
399 parms[0].u.pointer.size = 0; /* We don't actually care. */
400 parms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
401 parms[1].u.uint32 = cRect;
402
403 int rc = pDrv->pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VISIBLE_REGION, 2, &parms[0]);
404 return rc;
405 }
406 }
407#endif
408 }
409#endif
410
411 return VINF_SUCCESS;
412}
413
414DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
415{
416 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
417
418#ifdef MMSEAMLESS
419 /* Forward to Display, which calls corresponding framebuffers. */
420 pDrv->pVMMDev->getParent()->getDisplay()->handleQueryVisibleRegion(pcRect, pRect);
421#else
422 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
423 if (framebuffer)
424 {
425 ULONG cRect = 0;
426 framebuffer->GetVisibleRegion((BYTE *)pRect, cRect, &cRect);
427
428 *pcRect = cRect;
429 }
430#endif
431
432 return VINF_SUCCESS;
433}
434
435/**
436 * Request the statistics interval
437 *
438 * @returns VBox status code.
439 * @param pInterface Pointer to this interface.
440 * @param pulInterval Pointer to interval in seconds
441 * @thread The emulation thread.
442 */
443DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
444{
445 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
446 ULONG val = 0;
447
448 if (!pulInterval)
449 return VERR_INVALID_POINTER;
450
451 /* store that information in IGuest */
452 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
453 Assert(guest);
454 if (!guest)
455 return VERR_INVALID_PARAMETER; /** @todo wrong error */
456
457 guest->COMGETTER(StatisticsUpdateInterval)(&val);
458 *pulInterval = val;
459 return VINF_SUCCESS;
460}
461
462/**
463 * Query the current balloon size
464 *
465 * @returns VBox status code.
466 * @param pInterface Pointer to this interface.
467 * @param pcbBalloon Balloon size
468 * @thread The emulation thread.
469 */
470DECLCALLBACK(int) vmmdevQueryBalloonSize(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcbBalloon)
471{
472 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
473 ULONG val = 0;
474
475 if (!pcbBalloon)
476 return VERR_INVALID_POINTER;
477
478 /* store that information in IGuest */
479 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
480 Assert(guest);
481 if (!guest)
482 return VERR_INVALID_PARAMETER; /** @todo wrong error */
483
484 guest->COMGETTER(MemoryBalloonSize)(&val);
485 *pcbBalloon = val;
486 return VINF_SUCCESS;
487}
488
489/**
490 * Report new guest statistics
491 *
492 * @returns VBox status code.
493 * @param pInterface Pointer to this interface.
494 * @param pGuestStats Guest statistics
495 * @thread The emulation thread.
496 */
497DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
498{
499 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
500
501 Assert(pGuestStats);
502 if (!pGuestStats)
503 return VERR_INVALID_POINTER;
504
505 /* store that information in IGuest */
506 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
507 Assert(guest);
508 if (!guest)
509 return VERR_INVALID_PARAMETER; /** @todo wrong error */
510
511 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
512 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
513
514 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
515 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
516
517 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
518 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
519
520
521 /** @todo r=bird: Convert from 4KB to 1KB units?
522 * CollectorGuestHAL::getGuestMemLoad says it returns KB units to
523 * preCollect(). I might be wrong ofc, this is convoluted code... */
524 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
525 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
526
527 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
528 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
529
530 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
531 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
532
533 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
534 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
535
536 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
537 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
538
539 return VINF_SUCCESS;
540}
541
542#ifdef VBOX_WITH_HGCM
543
544/* HGCM connector interface */
545
546static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
547{
548 LogSunlover(("Enter\n"));
549
550 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
551
552 if ( !pServiceLocation
553 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
554 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
555 {
556 return VERR_INVALID_PARAMETER;
557 }
558
559 if (!pDrv->pVMMDev->hgcmIsActive ())
560 {
561 return VERR_INVALID_STATE;
562 }
563
564 return HGCMGuestConnect (pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
565}
566
567static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
568{
569 LogSunlover(("Enter\n"));
570
571 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
572
573 if (!pDrv->pVMMDev->hgcmIsActive ())
574 {
575 return VERR_INVALID_STATE;
576 }
577
578 return HGCMGuestDisconnect (pDrv->pHGCMPort, pCmd, u32ClientID);
579}
580
581static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
582 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
583{
584 LogSunlover(("Enter\n"));
585
586 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
587
588 if (!pDrv->pVMMDev->hgcmIsActive ())
589 {
590 return VERR_INVALID_STATE;
591 }
592
593 return HGCMGuestCall (pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
594}
595
596/**
597 * Execute state save operation.
598 *
599 * @returns VBox status code.
600 * @param pDrvIns Driver instance of the driver which registered the data unit.
601 * @param pSSM SSM operation handle.
602 */
603static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
604{
605 LogSunlover(("Enter\n"));
606 return HGCMHostSaveState (pSSM);
607}
608
609
610/**
611 * Execute state load operation.
612 *
613 * @returns VBox status code.
614 * @param pDrvIns Driver instance of the driver which registered the data unit.
615 * @param pSSM SSM operation handle.
616 * @param uVersion Data layout version.
617 * @param uPass The data pass.
618 */
619static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
620{
621 LogFlowFunc(("Enter\n"));
622
623 if (uVersion != HGCM_SSM_VERSION)
624 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
625 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
626
627 return HGCMHostLoadState (pSSM);
628}
629
630int VMMDev::hgcmLoadService (const char *pszServiceLibrary, const char *pszServiceName)
631{
632 if (!hgcmIsActive ())
633 {
634 return VERR_INVALID_STATE;
635 }
636 return HGCMHostLoad (pszServiceLibrary, pszServiceName);
637}
638
639int VMMDev::hgcmHostCall (const char *pszServiceName, uint32_t u32Function,
640 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
641{
642 if (!hgcmIsActive ())
643 {
644 return VERR_INVALID_STATE;
645 }
646 return HGCMHostCall (pszServiceName, u32Function, cParms, paParms);
647}
648
649void VMMDev::hgcmShutdown (void)
650{
651 ASMAtomicWriteBool(&m_fHGCMActive, false);
652 HGCMHostShutdown ();
653}
654
655#endif /* HGCM */
656
657
658/**
659 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
660 */
661DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
662{
663 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
664 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
665
666 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
667 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
668#ifdef VBOX_WITH_HGCM
669 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
670#endif
671 return NULL;
672}
673
674/**
675 * Destruct a VMMDev driver instance.
676 *
677 * @returns VBox status.
678 * @param pDrvIns The driver instance data.
679 */
680DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
681{
682 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
683 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
684#ifdef VBOX_WITH_HGCM
685 /* HGCM is shut down on the VMMDev destructor. */
686#endif /* VBOX_WITH_HGCM */
687 if (pData->pVMMDev)
688 {
689 pData->pVMMDev->mpDrv = NULL;
690 }
691}
692
693/**
694 * Reset notification.
695 *
696 * @returns VBox status.
697 * @param pDrvIns The driver instance data.
698 */
699DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
700{
701 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
702#ifdef VBOX_WITH_HGCM
703 HGCMHostReset ();
704#endif /* VBOX_WITH_HGCM */
705}
706
707/**
708 * Construct a VMMDev driver instance.
709 *
710 * @copydoc FNPDMDRVCONSTRUCT
711 */
712DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
713{
714 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
715 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
716
717 /*
718 * Validate configuration.
719 */
720 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
721 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
722 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
723 ("Configuration error: Not possible to attach anything to this driver!\n"),
724 VERR_PDM_DRVINS_NO_ATTACH);
725
726 /*
727 * IBase.
728 */
729 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
730
731 pData->Connector.pfnUpdateGuestVersion = vmmdevUpdateGuestVersion;
732 pData->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
733 pData->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
734 pData->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
735 pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
736 pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
737 pData->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
738 pData->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
739 pData->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
740 pData->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
741 pData->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
742 pData->Connector.pfnReportStatistics = vmmdevReportStatistics;
743 pData->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
744 pData->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
745
746#ifdef VBOX_WITH_HGCM
747 pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
748 pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
749 pData->HGCMConnector.pfnCall = iface_hgcmCall;
750#endif
751
752 /*
753 * Get the IVMMDevPort interface of the above driver/device.
754 */
755 pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
756 AssertMsgReturn(pData->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
757
758#ifdef VBOX_WITH_HGCM
759 pData->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
760 AssertMsgReturn(pData->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
761#endif
762
763 /*
764 * Get the Console object pointer and update the mpDrv member.
765 */
766 void *pv;
767 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
768 if (RT_FAILURE(rc))
769 {
770 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
771 return rc;
772 }
773
774 pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
775 pData->pVMMDev->mpDrv = pData;
776
777#ifdef VBOX_WITH_HGCM
778 rc = pData->pVMMDev->hgcmLoadService (VBOXSHAREDFOLDERS_DLL,
779 "VBoxSharedFolders");
780 pData->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
781 if (RT_SUCCESS(rc))
782 {
783 PPDMLED pLed;
784 PPDMILEDPORTS pLedPort;
785
786 LogRel(("Shared Folders service loaded.\n"));
787 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
788 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
789 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
790 if (RT_SUCCESS(rc) && pLed)
791 {
792 VBOXHGCMSVCPARM parm;
793
794 parm.type = VBOX_HGCM_SVC_PARM_PTR;
795 parm.u.pointer.addr = pLed;
796 parm.u.pointer.size = sizeof(*pLed);
797
798 rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
799 }
800 else
801 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
802 }
803 else
804 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
805
806 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
807 NULL, NULL, NULL,
808 NULL, iface_hgcmSave, NULL,
809 NULL, iface_hgcmLoad, NULL);
810 if (RT_FAILURE(rc))
811 return rc;
812
813#endif /* VBOX_WITH_HGCM */
814
815 return VINF_SUCCESS;
816}
817
818
819/**
820 * VMMDevice driver registration record.
821 */
822const PDMDRVREG VMMDev::DrvReg =
823{
824 /* u32Version */
825 PDM_DRVREG_VERSION,
826 /* szName */
827 "HGCM",
828 /* szRCMod */
829 "",
830 /* szR0Mod */
831 "",
832 /* pszDescription */
833 "Main VMMDev driver (Main as in the API).",
834 /* fFlags */
835 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
836 /* fClass. */
837 PDM_DRVREG_CLASS_VMMDEV,
838 /* cMaxInstances */
839 ~0,
840 /* cbInstance */
841 sizeof(DRVMAINVMMDEV),
842 /* pfnConstruct */
843 VMMDev::drvConstruct,
844 /* pfnDestruct */
845 VMMDev::drvDestruct,
846 /* pfnRelocate */
847 NULL,
848 /* pfnIOCtl */
849 NULL,
850 /* pfnPowerOn */
851 NULL,
852 /* pfnReset */
853 VMMDev::drvReset,
854 /* pfnSuspend */
855 NULL,
856 /* pfnResume */
857 NULL,
858 /* pfnAttach */
859 NULL,
860 /* pfnDetach */
861 NULL,
862 /* pfnPowerOff */
863 NULL,
864 /* pfnSoftReset */
865 NULL,
866 /* u32EndVersion */
867 PDM_DRVREG_VERSION
868};
869/* 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