VirtualBox

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

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

More fine grained Guest Additions status; now marks Additions as active when VBoxService was started successfully.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette