VirtualBox

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

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

Main: better handle null shapes

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