VirtualBox

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

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

Connect page fusion state

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.1 KB
Line 
1/* $Id: VMMDevInterface.cpp 29589 2010-05-18 06:55:00Z 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 * Query the current page fusion setting
497 *
498 * @returns VBox status code.
499 * @param pInterface Pointer to this interface.
500 * @param pfPageFusionEnabled Pointer to boolean
501 * @thread The emulation thread.
502 */
503DECLCALLBACK(int) vmmdevIsPageFusionEnabled(PPDMIVMMDEVCONNECTOR pInterface, bool *pfPageFusionEnabled)
504{
505 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
506 BOOL val = 0;
507
508 if (!pfPageFusionEnabled)
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 guest->COMGETTER(PageFusionEnabled)(&val);
518 *pfPageFusionEnabled = !!val;
519 return VINF_SUCCESS;
520}
521
522/**
523 * Report new guest statistics
524 *
525 * @returns VBox status code.
526 * @param pInterface Pointer to this interface.
527 * @param pGuestStats Guest statistics
528 * @thread The emulation thread.
529 */
530DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
531{
532 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
533
534 Assert(pGuestStats);
535 if (!pGuestStats)
536 return VERR_INVALID_POINTER;
537
538 /* store that information in IGuest */
539 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
540 Assert(guest);
541 if (!guest)
542 return VERR_INVALID_PARAMETER; /** @todo wrong error */
543
544 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
545 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
546
547 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
548 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
549
550 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
551 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
552
553
554 /** @todo r=bird: Convert from 4KB to 1KB units?
555 * CollectorGuestHAL::getGuestMemLoad says it returns KB units to
556 * preCollect(). I might be wrong ofc, this is convoluted code... */
557 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
558 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
559
560 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
561 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
562
563 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
564 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
565
566 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
567 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
568
569 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
570 guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
571
572 return VINF_SUCCESS;
573}
574
575#ifdef VBOX_WITH_HGCM
576
577/* HGCM connector interface */
578
579static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
580{
581 LogSunlover(("Enter\n"));
582
583 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
584
585 if ( !pServiceLocation
586 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
587 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
588 {
589 return VERR_INVALID_PARAMETER;
590 }
591
592 if (!pDrv->pVMMDev->hgcmIsActive ())
593 {
594 return VERR_INVALID_STATE;
595 }
596
597 return HGCMGuestConnect (pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
598}
599
600static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
601{
602 LogSunlover(("Enter\n"));
603
604 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
605
606 if (!pDrv->pVMMDev->hgcmIsActive ())
607 {
608 return VERR_INVALID_STATE;
609 }
610
611 return HGCMGuestDisconnect (pDrv->pHGCMPort, pCmd, u32ClientID);
612}
613
614static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
615 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
616{
617 LogSunlover(("Enter\n"));
618
619 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
620
621 if (!pDrv->pVMMDev->hgcmIsActive ())
622 {
623 return VERR_INVALID_STATE;
624 }
625
626 return HGCMGuestCall (pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
627}
628
629/**
630 * Execute state save operation.
631 *
632 * @returns VBox status code.
633 * @param pDrvIns Driver instance of the driver which registered the data unit.
634 * @param pSSM SSM operation handle.
635 */
636static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
637{
638 LogSunlover(("Enter\n"));
639 return HGCMHostSaveState (pSSM);
640}
641
642
643/**
644 * Execute state load operation.
645 *
646 * @returns VBox status code.
647 * @param pDrvIns Driver instance of the driver which registered the data unit.
648 * @param pSSM SSM operation handle.
649 * @param uVersion Data layout version.
650 * @param uPass The data pass.
651 */
652static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
653{
654 LogFlowFunc(("Enter\n"));
655
656 if (uVersion != HGCM_SSM_VERSION)
657 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
658 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
659
660 return HGCMHostLoadState (pSSM);
661}
662
663int VMMDev::hgcmLoadService (const char *pszServiceLibrary, const char *pszServiceName)
664{
665 if (!hgcmIsActive ())
666 {
667 return VERR_INVALID_STATE;
668 }
669 return HGCMHostLoad (pszServiceLibrary, pszServiceName);
670}
671
672int VMMDev::hgcmHostCall (const char *pszServiceName, uint32_t u32Function,
673 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
674{
675 if (!hgcmIsActive ())
676 {
677 return VERR_INVALID_STATE;
678 }
679 return HGCMHostCall (pszServiceName, u32Function, cParms, paParms);
680}
681
682void VMMDev::hgcmShutdown (void)
683{
684 ASMAtomicWriteBool(&m_fHGCMActive, false);
685 HGCMHostShutdown ();
686}
687
688#endif /* HGCM */
689
690
691/**
692 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
693 */
694DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
695{
696 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
697 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
698
699 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
700 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
701#ifdef VBOX_WITH_HGCM
702 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
703#endif
704 return NULL;
705}
706
707/**
708 * Destruct a VMMDev driver instance.
709 *
710 * @returns VBox status.
711 * @param pDrvIns The driver instance data.
712 */
713DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
714{
715 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
716 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
717#ifdef VBOX_WITH_HGCM
718 /* HGCM is shut down on the VMMDev destructor. */
719#endif /* VBOX_WITH_HGCM */
720 if (pData->pVMMDev)
721 {
722 pData->pVMMDev->mpDrv = NULL;
723 }
724}
725
726/**
727 * Reset notification.
728 *
729 * @returns VBox status.
730 * @param pDrvIns The driver instance data.
731 */
732DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
733{
734 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
735#ifdef VBOX_WITH_HGCM
736 HGCMHostReset ();
737#endif /* VBOX_WITH_HGCM */
738}
739
740/**
741 * Construct a VMMDev driver instance.
742 *
743 * @copydoc FNPDMDRVCONSTRUCT
744 */
745DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
746{
747 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
748 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
749
750 /*
751 * Validate configuration.
752 */
753 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
754 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
755 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
756 ("Configuration error: Not possible to attach anything to this driver!\n"),
757 VERR_PDM_DRVINS_NO_ATTACH);
758
759 /*
760 * IBase.
761 */
762 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
763
764 pData->Connector.pfnUpdateGuestVersion = vmmdevUpdateGuestVersion;
765 pData->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
766 pData->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
767 pData->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
768 pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
769 pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
770 pData->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
771 pData->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
772 pData->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
773 pData->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
774 pData->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
775 pData->Connector.pfnReportStatistics = vmmdevReportStatistics;
776 pData->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
777 pData->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
778 pData->Connector.pfnIsPageFusionEnabled = vmmdevIsPageFusionEnabled;
779
780#ifdef VBOX_WITH_HGCM
781 pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
782 pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
783 pData->HGCMConnector.pfnCall = iface_hgcmCall;
784#endif
785
786 /*
787 * Get the IVMMDevPort interface of the above driver/device.
788 */
789 pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
790 AssertMsgReturn(pData->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
791
792#ifdef VBOX_WITH_HGCM
793 pData->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
794 AssertMsgReturn(pData->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
795#endif
796
797 /*
798 * Get the Console object pointer and update the mpDrv member.
799 */
800 void *pv;
801 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
802 if (RT_FAILURE(rc))
803 {
804 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
805 return rc;
806 }
807
808 pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
809 pData->pVMMDev->mpDrv = pData;
810
811#ifdef VBOX_WITH_HGCM
812 rc = pData->pVMMDev->hgcmLoadService (VBOXSHAREDFOLDERS_DLL,
813 "VBoxSharedFolders");
814 pData->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
815 if (RT_SUCCESS(rc))
816 {
817 PPDMLED pLed;
818 PPDMILEDPORTS pLedPort;
819
820 LogRel(("Shared Folders service loaded.\n"));
821 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
822 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
823 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
824 if (RT_SUCCESS(rc) && pLed)
825 {
826 VBOXHGCMSVCPARM parm;
827
828 parm.type = VBOX_HGCM_SVC_PARM_PTR;
829 parm.u.pointer.addr = pLed;
830 parm.u.pointer.size = sizeof(*pLed);
831
832 rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
833 }
834 else
835 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
836 }
837 else
838 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
839
840 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
841 NULL, NULL, NULL,
842 NULL, iface_hgcmSave, NULL,
843 NULL, iface_hgcmLoad, NULL);
844 if (RT_FAILURE(rc))
845 return rc;
846
847#endif /* VBOX_WITH_HGCM */
848
849 return VINF_SUCCESS;
850}
851
852
853/**
854 * VMMDevice driver registration record.
855 */
856const PDMDRVREG VMMDev::DrvReg =
857{
858 /* u32Version */
859 PDM_DRVREG_VERSION,
860 /* szName */
861 "HGCM",
862 /* szRCMod */
863 "",
864 /* szR0Mod */
865 "",
866 /* pszDescription */
867 "Main VMMDev driver (Main as in the API).",
868 /* fFlags */
869 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
870 /* fClass. */
871 PDM_DRVREG_CLASS_VMMDEV,
872 /* cMaxInstances */
873 ~0,
874 /* cbInstance */
875 sizeof(DRVMAINVMMDEV),
876 /* pfnConstruct */
877 VMMDev::drvConstruct,
878 /* pfnDestruct */
879 VMMDev::drvDestruct,
880 /* pfnRelocate */
881 NULL,
882 /* pfnIOCtl */
883 NULL,
884 /* pfnPowerOn */
885 NULL,
886 /* pfnReset */
887 VMMDev::drvReset,
888 /* pfnSuspend */
889 NULL,
890 /* pfnResume */
891 NULL,
892 /* pfnAttach */
893 NULL,
894 /* pfnDetach */
895 NULL,
896 /* pfnPowerOff */
897 NULL,
898 /* pfnSoftReset */
899 NULL,
900 /* u32EndVersion */
901 PDM_DRVREG_VERSION
902};
903/* 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