VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/VMMDevInterface.cpp@ 47294

Last change on this file since 47294 was 47294, checked in by vboxsync, 11 years ago

Guest user state reporting: Update.

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