VirtualBox

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

Last change on this file since 73037 was 70599, checked in by vboxsync, 7 years ago

Main: Minor HGCM fixes, ?bugref:9064

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