VirtualBox

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

Last change on this file since 30787 was 30778, checked in by vboxsync, 14 years ago

Guest Additions status: Use more enums.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.4 KB
Line 
1/* $Id: VMMDevInterface.cpp 30778 2010-07-12 08:40:54Z 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 * Reports Guest Additions status.
161 * Called whenever the Additions issue a guest status 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) vmmdevUpdateGuestStatus(PPDMIVMMDEVCONNECTOR pInterface, const VBoxGuestStatus *guestStatus)
168{
169 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
170
171 Assert(guestStatus);
172 if (!guestStatus)
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 guest->setAdditionsStatus((VBoxGuestStatusFacility)guestStatus->facility,
182 (VBoxGuestStatusCurrent)guestStatus->status,
183 guestStatus->flags);
184 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
185}
186
187
188/**
189 * Reports Guest Additions API and OS version.
190 * Called whenever the Additions issue a guest version report request or the VM is reset.
191 *
192 * @param pInterface Pointer to this interface.
193 * @param guestInfo Pointer to guest information structure
194 * @thread The emulation thread.
195 */
196DECLCALLBACK(void) vmmdevUpdateGuestInfo(PPDMIVMMDEVCONNECTOR pInterface, const VBoxGuestInfo *guestInfo)
197{
198 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
199
200 Assert(guestInfo);
201 if (!guestInfo)
202 return;
203
204 /* Store that information in IGuest */
205 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
206 Assert(guest);
207 if (!guest)
208 return;
209
210 if (guestInfo->additionsVersion != 0)
211 {
212 char version[20];
213 RTStrPrintf(version, sizeof(version), "%d", guestInfo->additionsVersion);
214 guest->setAdditionsInfo(Bstr(version), guestInfo->osType);
215
216 /*
217 * Tell the console interface about the event
218 * so that it can notify its consumers.
219 */
220 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
221
222 if (guestInfo->additionsVersion < VMMDEV_VERSION)
223 pDrv->pVMMDev->getParent()->onAdditionsOutdated();
224 }
225 else
226 {
227 /*
228 * The guest additions was disabled because of a reset
229 * or driver unload.
230 */
231 guest->setAdditionsInfo(Bstr(), guestInfo->osType);
232 guest->setAdditionsStatus(VBoxGuestStatusFacility_Unknown,
233 VBoxGuestStatusCurrent_Disabled,
234 0); /* Flags; not used. */
235 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
236 }
237}
238
239/**
240 * Update the guest additions capabilities.
241 * This is called when the guest additions capabilities change. The new capabilities
242 * are given and the connector should update its internal state.
243 *
244 * @param pInterface Pointer to this interface.
245 * @param newCapabilities New capabilities.
246 * @thread The emulation thread.
247 */
248DECLCALLBACK(void) vmmdevUpdateGuestCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
249{
250 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
251
252 /* store that information in IGuest */
253 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
254 Assert(guest);
255 if (!guest)
256 return;
257
258 /*
259 * Report our current capabilites (and assume none is active yet).
260 */
261 guest->setSupportedFeatures((ULONG64)newCapabilities, 0 /* Active capabilities, not used here. */);
262
263 /*
264 * Tell the console interface about the event
265 * so that it can notify its consumers.
266 */
267 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
268
269}
270
271/**
272 * Update the mouse capabilities.
273 * This is called when the mouse capabilities change. The new capabilities
274 * are given and the connector should update its internal state.
275 *
276 * @param pInterface Pointer to this interface.
277 * @param newCapabilities New capabilities.
278 * @thread The emulation thread.
279 */
280DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
281{
282 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
283 /*
284 * Tell the console interface about the event
285 * so that it can notify its consumers.
286 */
287 Mouse *pMouse = pDrv->pVMMDev->getParent()->getMouse();
288 if (pMouse) /** @todo and if not? Can that actually happen? */
289 {
290 pMouse->onVMMDevCanAbsChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE));
291 pMouse->onVMMDevNeedsHostChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR));
292 }
293}
294
295
296/**
297 * Update the pointer shape or visibility.
298 *
299 * This is called when the mouse pointer shape changes or pointer is hidden/displaying.
300 * The new shape is passed as a caller allocated buffer that will be freed after returning.
301 *
302 * @param pInterface Pointer to this interface.
303 * @param fVisible Whether the pointer is visible or not.
304 * @param fAlpha Alpha channel information is present.
305 * @param xHot Horizontal coordinate of the pointer hot spot.
306 * @param yHot Vertical coordinate of the pointer hot spot.
307 * @param width Pointer width in pixels.
308 * @param height Pointer height in pixels.
309 * @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
310 * @thread The emulation thread.
311 */
312DECLCALLBACK(void) vmmdevUpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
313 uint32_t xHot, uint32_t yHot,
314 uint32_t width, uint32_t height,
315 void *pShape)
316{
317 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
318
319 /* tell the console about it */
320 size_t cbShapeSize = 0;
321
322 if (pShape)
323 {
324 cbShapeSize = (width + 7) / 8 * height; /* size of the AND mask */
325 cbShapeSize = ((cbShapeSize + 3) & ~3) + width * 4 * height; /* + gap + size of the XOR mask */
326 }
327 com::SafeArray<BYTE> shapeData(cbShapeSize);
328 if (pShape)
329 ::memcpy(shapeData.raw(), pShape, cbShapeSize);
330 pDrv->pVMMDev->getParent()->onMousePointerShapeChange(fVisible, fAlpha,
331 xHot, yHot, width, height, ComSafeArrayAsInParam(shapeData));
332}
333
334DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
335{
336 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
337
338 Display *display = pDrv->pVMMDev->getParent()->getDisplay();
339
340 if (display)
341 {
342 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
343 return display->VideoAccelEnable (fEnable, pVbvaMemory);
344 }
345
346 return VERR_NOT_SUPPORTED;
347}
348DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
349{
350 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
351
352 Display *display = pDrv->pVMMDev->getParent()->getDisplay();
353
354 if (display)
355 {
356 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
357 display->VideoAccelFlush ();
358 }
359}
360
361DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t display, uint32_t width, uint32_t height,
362 uint32_t bpp, bool *fSupported)
363{
364 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
365
366 if (!fSupported)
367 return VERR_INVALID_PARAMETER;
368#ifdef DEBUG_sunlover
369 Log(("vmmdevVideoModeSupported: [%d]: %dx%dx%d\n", display, width, height, bpp));
370#endif
371 IFramebuffer *framebuffer = NULL;
372 LONG xOrigin = 0;
373 LONG yOrigin = 0;
374 HRESULT hrc = pDrv->pVMMDev->getParent()->getDisplay()->GetFramebuffer(display, &framebuffer, &xOrigin, &yOrigin);
375 if (SUCCEEDED(hrc) && framebuffer)
376 {
377 framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
378 framebuffer->Release();
379 }
380 else
381 {
382#ifdef DEBUG_sunlover
383 Log(("vmmdevVideoModeSupported: hrc %x, framebuffer %p!!!\n", hrc, framebuffer));
384#endif
385 *fSupported = true;
386 }
387 return VINF_SUCCESS;
388}
389
390DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
391{
392 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
393
394 if (!heightReduction)
395 return VERR_INVALID_PARAMETER;
396 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
397 if (framebuffer)
398 framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
399 else
400 *heightReduction = 0;
401 return VINF_SUCCESS;
402}
403
404DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
405{
406 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
407
408 int rc = pDrv->pVMMDev->SetCredentialsJudgementResult (u32Flags);
409
410 return rc;
411}
412
413DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
414{
415 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
416
417 if (!cRect)
418 return VERR_INVALID_PARAMETER;
419#ifdef MMSEAMLESS
420 /* Forward to Display, which calls corresponding framebuffers. */
421 pDrv->pVMMDev->getParent()->getDisplay()->handleSetVisibleRegion(cRect, pRect);
422#else
423 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
424 if (framebuffer)
425 {
426 framebuffer->SetVisibleRegion((BYTE *)pRect, cRect);
427#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
428 {
429 BOOL is3denabled;
430
431 pDrv->pVMMDev->getParent()->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
432
433 if (is3denabled)
434 {
435 VBOXHGCMSVCPARM parms[2];
436
437 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
438 parms[0].u.pointer.addr = pRect;
439 parms[0].u.pointer.size = 0; /* We don't actually care. */
440 parms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
441 parms[1].u.uint32 = cRect;
442
443 int rc = pDrv->pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VISIBLE_REGION, 2, &parms[0]);
444 return rc;
445 }
446 }
447#endif
448 }
449#endif
450
451 return VINF_SUCCESS;
452}
453
454DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
455{
456 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
457
458#ifdef MMSEAMLESS
459 /* Forward to Display, which calls corresponding framebuffers. */
460 pDrv->pVMMDev->getParent()->getDisplay()->handleQueryVisibleRegion(pcRect, pRect);
461#else
462 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
463 if (framebuffer)
464 {
465 ULONG cRect = 0;
466 framebuffer->GetVisibleRegion((BYTE *)pRect, cRect, &cRect);
467
468 *pcRect = cRect;
469 }
470#endif
471
472 return VINF_SUCCESS;
473}
474
475/**
476 * Request the statistics interval
477 *
478 * @returns VBox status code.
479 * @param pInterface Pointer to this interface.
480 * @param pulInterval Pointer to interval in seconds
481 * @thread The emulation thread.
482 */
483DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
484{
485 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
486 ULONG val = 0;
487
488 if (!pulInterval)
489 return VERR_INVALID_POINTER;
490
491 /* store that information in IGuest */
492 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
493 Assert(guest);
494 if (!guest)
495 return VERR_INVALID_PARAMETER; /** @todo wrong error */
496
497 guest->COMGETTER(StatisticsUpdateInterval)(&val);
498 *pulInterval = val;
499 return VINF_SUCCESS;
500}
501
502/**
503 * Query the current balloon size
504 *
505 * @returns VBox status code.
506 * @param pInterface Pointer to this interface.
507 * @param pcbBalloon Balloon size
508 * @thread The emulation thread.
509 */
510DECLCALLBACK(int) vmmdevQueryBalloonSize(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcbBalloon)
511{
512 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
513 ULONG val = 0;
514
515 if (!pcbBalloon)
516 return VERR_INVALID_POINTER;
517
518 /* store that information in IGuest */
519 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
520 Assert(guest);
521 if (!guest)
522 return VERR_INVALID_PARAMETER; /** @todo wrong error */
523
524 guest->COMGETTER(MemoryBalloonSize)(&val);
525 *pcbBalloon = val;
526 return VINF_SUCCESS;
527}
528
529/**
530 * Query the current page fusion setting
531 *
532 * @returns VBox status code.
533 * @param pInterface Pointer to this interface.
534 * @param pfPageFusionEnabled Pointer to boolean
535 * @thread The emulation thread.
536 */
537DECLCALLBACK(int) vmmdevIsPageFusionEnabled(PPDMIVMMDEVCONNECTOR pInterface, bool *pfPageFusionEnabled)
538{
539 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
540 BOOL val = 0;
541
542 if (!pfPageFusionEnabled)
543 return VERR_INVALID_POINTER;
544
545 /* store that information in IGuest */
546 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
547 Assert(guest);
548 if (!guest)
549 return VERR_INVALID_PARAMETER; /** @todo wrong error */
550
551 guest->COMGETTER(PageFusionEnabled)(&val);
552 *pfPageFusionEnabled = !!val;
553 return VINF_SUCCESS;
554}
555
556/**
557 * Report new guest statistics
558 *
559 * @returns VBox status code.
560 * @param pInterface Pointer to this interface.
561 * @param pGuestStats Guest statistics
562 * @thread The emulation thread.
563 */
564DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
565{
566 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
567
568 Assert(pGuestStats);
569 if (!pGuestStats)
570 return VERR_INVALID_POINTER;
571
572 /* store that information in IGuest */
573 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
574 Assert(guest);
575 if (!guest)
576 return VERR_INVALID_PARAMETER; /** @todo wrong error */
577
578 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
579 guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
580
581 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
582 guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
583
584 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
585 guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
586
587
588 /** @todo r=bird: Convert from 4KB to 1KB units?
589 * CollectorGuestHAL::getGuestMemLoad says it returns KB units to
590 * preCollect(). I might be wrong ofc, this is convoluted code... */
591 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
592 guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
593
594 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
595 guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
596
597 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
598 guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
599
600 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
601 guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
602
603 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
604 guest->setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
605
606 return VINF_SUCCESS;
607}
608
609#ifdef VBOX_WITH_HGCM
610
611/* HGCM connector interface */
612
613static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
614{
615 LogSunlover(("Enter\n"));
616
617 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
618
619 if ( !pServiceLocation
620 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
621 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
622 {
623 return VERR_INVALID_PARAMETER;
624 }
625
626 if (!pDrv->pVMMDev->hgcmIsActive ())
627 {
628 return VERR_INVALID_STATE;
629 }
630
631 return HGCMGuestConnect (pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
632}
633
634static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
635{
636 LogSunlover(("Enter\n"));
637
638 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
639
640 if (!pDrv->pVMMDev->hgcmIsActive ())
641 {
642 return VERR_INVALID_STATE;
643 }
644
645 return HGCMGuestDisconnect (pDrv->pHGCMPort, pCmd, u32ClientID);
646}
647
648static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
649 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
650{
651 LogSunlover(("Enter\n"));
652
653 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
654
655 if (!pDrv->pVMMDev->hgcmIsActive ())
656 {
657 return VERR_INVALID_STATE;
658 }
659
660 return HGCMGuestCall (pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
661}
662
663/**
664 * Execute state save operation.
665 *
666 * @returns VBox status code.
667 * @param pDrvIns Driver instance of the driver which registered the data unit.
668 * @param pSSM SSM operation handle.
669 */
670static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
671{
672 LogSunlover(("Enter\n"));
673 return HGCMHostSaveState (pSSM);
674}
675
676
677/**
678 * Execute state load operation.
679 *
680 * @returns VBox status code.
681 * @param pDrvIns Driver instance of the driver which registered the data unit.
682 * @param pSSM SSM operation handle.
683 * @param uVersion Data layout version.
684 * @param uPass The data pass.
685 */
686static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
687{
688 LogFlowFunc(("Enter\n"));
689
690 if (uVersion != HGCM_SSM_VERSION)
691 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
692 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
693
694 return HGCMHostLoadState (pSSM);
695}
696
697int VMMDev::hgcmLoadService (const char *pszServiceLibrary, const char *pszServiceName)
698{
699 if (!hgcmIsActive ())
700 {
701 return VERR_INVALID_STATE;
702 }
703 return HGCMHostLoad (pszServiceLibrary, pszServiceName);
704}
705
706int VMMDev::hgcmHostCall (const char *pszServiceName, uint32_t u32Function,
707 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
708{
709 if (!hgcmIsActive ())
710 {
711 return VERR_INVALID_STATE;
712 }
713 return HGCMHostCall (pszServiceName, u32Function, cParms, paParms);
714}
715
716void VMMDev::hgcmShutdown (void)
717{
718 ASMAtomicWriteBool(&m_fHGCMActive, false);
719 HGCMHostShutdown ();
720}
721
722#endif /* HGCM */
723
724
725/**
726 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
727 */
728DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
729{
730 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
731 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
732
733 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
734 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
735#ifdef VBOX_WITH_HGCM
736 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
737#endif
738 return NULL;
739}
740
741/**
742 * Destruct a VMMDev driver instance.
743 *
744 * @returns VBox status.
745 * @param pDrvIns The driver instance data.
746 */
747DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
748{
749 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
750 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
751#ifdef VBOX_WITH_HGCM
752 /* HGCM is shut down on the VMMDev destructor. */
753#endif /* VBOX_WITH_HGCM */
754 if (pData->pVMMDev)
755 {
756 pData->pVMMDev->mpDrv = NULL;
757 }
758}
759
760/**
761 * Reset notification.
762 *
763 * @returns VBox status.
764 * @param pDrvIns The driver instance data.
765 */
766DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
767{
768 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
769#ifdef VBOX_WITH_HGCM
770 HGCMHostReset ();
771#endif /* VBOX_WITH_HGCM */
772}
773
774/**
775 * Construct a VMMDev driver instance.
776 *
777 * @copydoc FNPDMDRVCONSTRUCT
778 */
779DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
780{
781 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
782 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
783
784 /*
785 * Validate configuration.
786 */
787 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
788 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
789 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
790 ("Configuration error: Not possible to attach anything to this driver!\n"),
791 VERR_PDM_DRVINS_NO_ATTACH);
792
793 /*
794 * IBase.
795 */
796 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
797
798 pData->Connector.pfnUpdateGuestStatus = vmmdevUpdateGuestStatus;
799 pData->Connector.pfnUpdateGuestInfo = vmmdevUpdateGuestInfo;
800 pData->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
801 pData->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
802 pData->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
803 pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
804 pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
805 pData->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
806 pData->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
807 pData->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
808 pData->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
809 pData->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
810 pData->Connector.pfnReportStatistics = vmmdevReportStatistics;
811 pData->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
812 pData->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
813 pData->Connector.pfnIsPageFusionEnabled = vmmdevIsPageFusionEnabled;
814
815#ifdef VBOX_WITH_HGCM
816 pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
817 pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
818 pData->HGCMConnector.pfnCall = iface_hgcmCall;
819#endif
820
821 /*
822 * Get the IVMMDevPort interface of the above driver/device.
823 */
824 pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
825 AssertMsgReturn(pData->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
826
827#ifdef VBOX_WITH_HGCM
828 pData->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
829 AssertMsgReturn(pData->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
830#endif
831
832 /*
833 * Get the Console object pointer and update the mpDrv member.
834 */
835 void *pv;
836 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
837 if (RT_FAILURE(rc))
838 {
839 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
840 return rc;
841 }
842
843 pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
844 pData->pVMMDev->mpDrv = pData;
845
846#ifdef VBOX_WITH_HGCM
847 rc = pData->pVMMDev->hgcmLoadService (VBOXSHAREDFOLDERS_DLL,
848 "VBoxSharedFolders");
849 pData->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
850 if (RT_SUCCESS(rc))
851 {
852 PPDMLED pLed;
853 PPDMILEDPORTS pLedPort;
854
855 LogRel(("Shared Folders service loaded.\n"));
856 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
857 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
858 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
859 if (RT_SUCCESS(rc) && pLed)
860 {
861 VBOXHGCMSVCPARM parm;
862
863 parm.type = VBOX_HGCM_SVC_PARM_PTR;
864 parm.u.pointer.addr = pLed;
865 parm.u.pointer.size = sizeof(*pLed);
866
867 rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
868 }
869 else
870 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
871 }
872 else
873 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
874
875 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
876 NULL, NULL, NULL,
877 NULL, iface_hgcmSave, NULL,
878 NULL, iface_hgcmLoad, NULL);
879 if (RT_FAILURE(rc))
880 return rc;
881
882#endif /* VBOX_WITH_HGCM */
883
884 return VINF_SUCCESS;
885}
886
887
888/**
889 * VMMDevice driver registration record.
890 */
891const PDMDRVREG VMMDev::DrvReg =
892{
893 /* u32Version */
894 PDM_DRVREG_VERSION,
895 /* szName */
896 "HGCM",
897 /* szRCMod */
898 "",
899 /* szR0Mod */
900 "",
901 /* pszDescription */
902 "Main VMMDev driver (Main as in the API).",
903 /* fFlags */
904 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
905 /* fClass. */
906 PDM_DRVREG_CLASS_VMMDEV,
907 /* cMaxInstances */
908 ~0,
909 /* cbInstance */
910 sizeof(DRVMAINVMMDEV),
911 /* pfnConstruct */
912 VMMDev::drvConstruct,
913 /* pfnDestruct */
914 VMMDev::drvDestruct,
915 /* pfnRelocate */
916 NULL,
917 /* pfnIOCtl */
918 NULL,
919 /* pfnPowerOn */
920 NULL,
921 /* pfnReset */
922 VMMDev::drvReset,
923 /* pfnSuspend */
924 NULL,
925 /* pfnResume */
926 NULL,
927 /* pfnAttach */
928 NULL,
929 /* pfnDetach */
930 NULL,
931 /* pfnPowerOff */
932 NULL,
933 /* pfnSoftReset */
934 NULL,
935 /* u32EndVersion */
936 PDM_DRVREG_VERSION
937};
938/* 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