VirtualBox

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

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

Main: use RT_FROM_MEMBER instead of RT_OFFSETOF; some Assert* cleanup

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