VirtualBox

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

Last change on this file since 53401 was 52934, checked in by vboxsync, 10 years ago

Main: safearray cleanup, removed unnecessary SafeArray<->vector conversions

  • 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 52934 2014-10-02 13:53:30Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to VMM device.
4 */
5
6/*
7 * Copyright (C) 2006-2014 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->i_getGuest();
163 AssertPtrReturnVoid(guest);
164
165 guest->i_setAdditionsStatus((VBoxGuestFacilityType)uFacility, (VBoxGuestFacilityStatus)uStatus, fFlags, pTimeSpecTS);
166 pConsole->i_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->i_getGuest();
185 AssertPtrReturnVoid(pGuest);
186
187 pGuest->i_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->i_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->i_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->i_onAdditionsStateChange();
224
225 if (guestInfo->interfaceVersion < VMMDEV_VERSION)
226 pConsole->i_onAdditionsOutdated();
227 }
228 else
229 {
230 /*
231 * The guest additions was disabled because of a reset
232 * or driver unload.
233 */
234 guest->i_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->i_setAdditionsInfo2(0, "", 0, 0); /* Clear Guest Additions version. */
238 RTTIMESPEC TimeSpecTS;
239 RTTimeNow(&TimeSpecTS);
240 guest->i_setAdditionsStatus(VBoxGuestFacilityType_All, VBoxGuestFacilityStatus_Inactive, 0 /*fFlags*/, &TimeSpecTS);
241 pConsole->i_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()->i_getGuest();
257 AssertPtrReturnVoid(pGuest);
258
259 /* Just pass it on... */
260 pGuest->i_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->i_getGuest();
286 AssertPtrReturnVoid(pGuest);
287
288 /*
289 * Report our current capabilities (and assume none is active yet).
290 */
291 pGuest->i_setSupportedFeatures(newCapabilities);
292
293 /*
294 * Tell the console interface about the event
295 * so that it can notify its consumers.
296 */
297 pConsole->i_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->i_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 uint32_t cbShape = 0;
349 if (pShape)
350 {
351 cbShape = (width + 7) / 8 * height; /* size of the AND mask */
352 cbShape = ((cbShape + 3) & ~3) + width * 4 * height; /* + gap + size of the XOR mask */
353 }
354 pConsole->i_onMousePointerShapeChange(fVisible, fAlpha, xHot, yHot, width, height, (uint8_t *)pShape, cbShape);
355}
356
357DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
358{
359 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
360 Console *pConsole = pDrv->pVMMDev->getParent();
361
362 Display *display = pConsole->i_getDisplay();
363
364 if (display)
365 {
366 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
367 return display->VideoAccelEnableVMMDev(fEnable, pVbvaMemory);
368 }
369
370 return VERR_NOT_SUPPORTED;
371}
372DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
373{
374 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
375 Console *pConsole = pDrv->pVMMDev->getParent();
376
377 Display *display = pConsole->i_getDisplay();
378
379 if (display)
380 {
381 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
382 display->VideoAccelFlushVMMDev();
383 }
384}
385
386DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t display, uint32_t width, uint32_t height,
387 uint32_t bpp, bool *fSupported)
388{
389 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
390 Console *pConsole = pDrv->pVMMDev->getParent();
391
392 if (!fSupported)
393 return VERR_INVALID_PARAMETER;
394#ifdef DEBUG_sunlover
395 Log(("vmmdevVideoModeSupported: [%d]: %dx%dx%d\n", display, width, height, bpp));
396#endif
397 IFramebuffer *framebuffer = NULL;
398 HRESULT hrc = pConsole->i_getDisplay()->QueryFramebuffer(display, &framebuffer);
399 if (SUCCEEDED(hrc) && framebuffer)
400 {
401 framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
402 framebuffer->Release();
403 }
404 else
405 {
406#ifdef DEBUG_sunlover
407 Log(("vmmdevVideoModeSupported: hrc %x, framebuffer %p!!!\n", hrc, framebuffer));
408#endif
409 *fSupported = true;
410 }
411 return VINF_SUCCESS;
412}
413
414DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
415{
416 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
417 Console *pConsole = pDrv->pVMMDev->getParent();
418
419 if (!heightReduction)
420 return VERR_INVALID_PARAMETER;
421 IFramebuffer *framebuffer = NULL;
422 HRESULT hrc = pConsole->i_getDisplay()->QueryFramebuffer(0, &framebuffer);
423 if (SUCCEEDED(hrc) && framebuffer)
424 {
425 framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
426 framebuffer->Release();
427 }
428 else
429 *heightReduction = 0;
430 return VINF_SUCCESS;
431}
432
433DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
434{
435 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
436
437 if (pDrv->pVMMDev)
438 return pDrv->pVMMDev->SetCredentialsJudgementResult (u32Flags);
439
440 return VERR_GENERAL_FAILURE;
441}
442
443DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
444{
445 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
446 Console *pConsole = pDrv->pVMMDev->getParent();
447
448 /* Forward to Display, which calls corresponding framebuffers. */
449 pConsole->i_getDisplay()->i_handleSetVisibleRegion(cRect, pRect);
450
451 return VINF_SUCCESS;
452}
453
454DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
455{
456 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
457 Console *pConsole = pDrv->pVMMDev->getParent();
458
459 /* Forward to Display, which calls corresponding framebuffers. */
460 pConsole->i_getDisplay()->i_handleQueryVisibleRegion(pcRect, pRect);
461
462 return VINF_SUCCESS;
463}
464
465/**
466 * Request the statistics interval
467 *
468 * @returns VBox status code.
469 * @param pInterface Pointer to this interface.
470 * @param pulInterval Pointer to interval in seconds
471 * @thread The emulation thread.
472 */
473DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
474{
475 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
476 Console *pConsole = pDrv->pVMMDev->getParent();
477 ULONG val = 0;
478
479 if (!pulInterval)
480 return VERR_INVALID_POINTER;
481
482 /* store that information in IGuest */
483 Guest* guest = pConsole->i_getGuest();
484 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
485
486 guest->COMGETTER(StatisticsUpdateInterval)(&val);
487 *pulInterval = val;
488 return VINF_SUCCESS;
489}
490
491/**
492 * Query the current balloon size
493 *
494 * @returns VBox status code.
495 * @param pInterface Pointer to this interface.
496 * @param pcbBalloon Balloon size
497 * @thread The emulation thread.
498 */
499DECLCALLBACK(int) vmmdevQueryBalloonSize(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcbBalloon)
500{
501 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
502 Console *pConsole = pDrv->pVMMDev->getParent();
503 ULONG val = 0;
504
505 if (!pcbBalloon)
506 return VERR_INVALID_POINTER;
507
508 /* store that information in IGuest */
509 Guest* guest = pConsole->i_getGuest();
510 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
511
512 guest->COMGETTER(MemoryBalloonSize)(&val);
513 *pcbBalloon = val;
514 return VINF_SUCCESS;
515}
516
517/**
518 * Query the current page fusion setting
519 *
520 * @returns VBox status code.
521 * @param pInterface Pointer to this interface.
522 * @param pfPageFusionEnabled Pointer to boolean
523 * @thread The emulation thread.
524 */
525DECLCALLBACK(int) vmmdevIsPageFusionEnabled(PPDMIVMMDEVCONNECTOR pInterface, bool *pfPageFusionEnabled)
526{
527 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
528 Console *pConsole = pDrv->pVMMDev->getParent();
529 BOOL val = 0;
530
531 if (!pfPageFusionEnabled)
532 return VERR_INVALID_POINTER;
533
534 /* store that information in IGuest */
535 Guest* guest = pConsole->i_getGuest();
536 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
537
538 *pfPageFusionEnabled = !!guest->i_isPageFusionEnabled();
539 return VINF_SUCCESS;
540}
541
542/**
543 * Report new guest statistics
544 *
545 * @returns VBox status code.
546 * @param pInterface Pointer to this interface.
547 * @param pGuestStats Guest statistics
548 * @thread The emulation thread.
549 */
550DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
551{
552 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
553 Console *pConsole = pDrv->pVMMDev->getParent();
554
555 AssertPtrReturn(pGuestStats, VERR_INVALID_POINTER);
556
557 /* store that information in IGuest */
558 Guest* guest = pConsole->i_getGuest();
559 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
560
561 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
562 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
563
564 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
565 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
566
567 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
568 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
569
570
571 /** @todo r=bird: Convert from 4KB to 1KB units?
572 * CollectorGuestHAL::i_getGuestMemLoad says it returns KB units to
573 * preCollect(). I might be wrong ofc, this is convoluted code... */
574 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
575 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
576
577 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
578 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
579
580 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
581 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
582
583 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
584 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
585
586 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
587 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
588
589 return VINF_SUCCESS;
590}
591
592#ifdef VBOX_WITH_HGCM
593
594/* HGCM connector interface */
595
596static DECLCALLBACK(int) iface_hgcmConnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd,
597 PHGCMSERVICELOCATION pServiceLocation,
598 uint32_t *pu32ClientID)
599{
600 LogSunlover(("Enter\n"));
601
602 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
603
604 if ( !pServiceLocation
605 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
606 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
607 {
608 return VERR_INVALID_PARAMETER;
609 }
610
611 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
612 return VERR_INVALID_STATE;
613
614 return HGCMGuestConnect(pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
615}
616
617static DECLCALLBACK(int) iface_hgcmDisconnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
618{
619 LogSunlover(("Enter\n"));
620
621 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
622
623 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
624 return VERR_INVALID_STATE;
625
626 return HGCMGuestDisconnect(pDrv->pHGCMPort, pCmd, u32ClientID);
627}
628
629static DECLCALLBACK(int) iface_hgcmCall(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID,
630 uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms)
631{
632 LogSunlover(("Enter\n"));
633
634 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
635
636 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
637 return VERR_INVALID_STATE;
638
639 return HGCMGuestCall(pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
640}
641
642/**
643 * Execute state save operation.
644 *
645 * @returns VBox status code.
646 * @param pDrvIns Driver instance of the driver which registered the data unit.
647 * @param pSSM SSM operation handle.
648 */
649static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
650{
651 LogSunlover(("Enter\n"));
652 return HGCMHostSaveState(pSSM);
653}
654
655
656/**
657 * Execute state load 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 * @param uVersion Data layout version.
663 * @param uPass The data pass.
664 */
665static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
666{
667 LogFlowFunc(("Enter\n"));
668
669 if (uVersion != HGCM_SSM_VERSION)
670 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
671 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
672
673 return HGCMHostLoadState(pSSM);
674}
675
676int VMMDev::hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName)
677{
678 if (!hgcmIsActive())
679 return VERR_INVALID_STATE;
680
681 return HGCMHostLoad(pszServiceLibrary, pszServiceName);
682}
683
684int VMMDev::hgcmHostCall(const char *pszServiceName, uint32_t u32Function,
685 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
686{
687 if (!hgcmIsActive())
688 return VERR_INVALID_STATE;
689 return HGCMHostCall(pszServiceName, u32Function, cParms, paParms);
690}
691
692void VMMDev::hgcmShutdown(void)
693{
694 ASMAtomicWriteBool(&m_fHGCMActive, false);
695 HGCMHostShutdown();
696}
697
698# ifdef VBOX_WITH_CRHGSMI
699int VMMDev::hgcmHostSvcHandleCreate(const char *pszServiceName, HGCMCVSHANDLE * phSvc)
700{
701 if (!hgcmIsActive())
702 return VERR_INVALID_STATE;
703 return HGCMHostSvcHandleCreate(pszServiceName, phSvc);
704}
705
706int VMMDev::hgcmHostSvcHandleDestroy(HGCMCVSHANDLE hSvc)
707{
708 if (!hgcmIsActive())
709 return VERR_INVALID_STATE;
710 return HGCMHostSvcHandleDestroy(hSvc);
711}
712
713int VMMDev::hgcmHostFastCallAsync(HGCMCVSHANDLE hSvc, uint32_t function, PVBOXHGCMSVCPARM pParm,
714 PHGCMHOSTFASTCALLCB pfnCompletion, void *pvCompletion)
715{
716 if (!hgcmIsActive())
717 return VERR_INVALID_STATE;
718 return HGCMHostFastCallAsync(hSvc, function, pParm, pfnCompletion, pvCompletion);
719}
720# endif
721
722#endif /* HGCM */
723
724
725/**
726 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
727 */
728DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
729{
730 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
731 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
732
733 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
734 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
735#ifdef VBOX_WITH_HGCM
736 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
737#endif
738 return NULL;
739}
740
741/**
742 * @interface_method_impl{PDMDRVREG,pfnReset}
743 */
744DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
745{
746 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
747#ifdef VBOX_WITH_HGCM
748 HGCMHostReset ();
749#endif /* VBOX_WITH_HGCM */
750}
751
752/**
753 * @interface_method_impl{PDMDRVREG,pfnDestruct}
754 */
755DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
756{
757 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
758 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
759 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
760
761#ifdef VBOX_WITH_HGCM
762 /* HGCM is shut down on the VMMDev destructor. */
763#endif /* VBOX_WITH_HGCM */
764 if (pThis->pVMMDev)
765 pThis->pVMMDev->mpDrv = NULL;
766}
767
768/**
769 * @interface_method_impl{PDMDRVREG,pfnConstruct}
770 */
771DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
772{
773 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
774 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
775 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
776
777 /*
778 * Validate configuration.
779 */
780 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
781 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
782 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
783 ("Configuration error: Not possible to attach anything to this driver!\n"),
784 VERR_PDM_DRVINS_NO_ATTACH);
785
786 /*
787 * IBase.
788 */
789 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
790
791 pThis->Connector.pfnUpdateGuestStatus = vmmdevUpdateGuestStatus;
792 pThis->Connector.pfnUpdateGuestUserState = vmmdevUpdateGuestUserState;
793 pThis->Connector.pfnUpdateGuestInfo = vmmdevUpdateGuestInfo;
794 pThis->Connector.pfnUpdateGuestInfo2 = vmmdevUpdateGuestInfo2;
795 pThis->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
796 pThis->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
797 pThis->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
798 pThis->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
799 pThis->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
800 pThis->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
801 pThis->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
802 pThis->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
803 pThis->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
804 pThis->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
805 pThis->Connector.pfnReportStatistics = vmmdevReportStatistics;
806 pThis->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
807 pThis->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
808 pThis->Connector.pfnIsPageFusionEnabled = vmmdevIsPageFusionEnabled;
809
810#ifdef VBOX_WITH_HGCM
811 pThis->HGCMConnector.pfnConnect = iface_hgcmConnect;
812 pThis->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
813 pThis->HGCMConnector.pfnCall = iface_hgcmCall;
814#endif
815
816 /*
817 * Get the IVMMDevPort interface of the above driver/device.
818 */
819 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
820 AssertMsgReturn(pThis->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
821
822#ifdef VBOX_WITH_HGCM
823 pThis->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
824 AssertMsgReturn(pThis->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
825#endif
826
827 /*
828 * Get the Console object pointer and update the mpDrv member.
829 */
830 void *pv;
831 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
832 if (RT_FAILURE(rc))
833 {
834 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
835 return rc;
836 }
837
838 pThis->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
839 pThis->pVMMDev->mpDrv = pThis;
840
841#ifdef VBOX_WITH_HGCM
842 rc = pThis->pVMMDev->hgcmLoadService(VBOXSHAREDFOLDERS_DLL,
843 "VBoxSharedFolders");
844 pThis->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
845 if (RT_SUCCESS(rc))
846 {
847 PPDMLED pLed;
848 PPDMILEDPORTS pLedPort;
849
850 LogRel(("Shared Folders service loaded\n"));
851 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
852 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
853 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
854 if (RT_SUCCESS(rc) && pLed)
855 {
856 VBOXHGCMSVCPARM parm;
857
858 parm.type = VBOX_HGCM_SVC_PARM_PTR;
859 parm.u.pointer.addr = pLed;
860 parm.u.pointer.size = sizeof(*pLed);
861
862 rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
863 }
864 else
865 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
866 }
867 else
868 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
869
870 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
871 NULL, NULL, NULL,
872 NULL, iface_hgcmSave, NULL,
873 NULL, iface_hgcmLoad, NULL);
874 if (RT_FAILURE(rc))
875 return rc;
876
877#endif /* VBOX_WITH_HGCM */
878
879 return VINF_SUCCESS;
880}
881
882
883/**
884 * VMMDevice driver registration record.
885 */
886const PDMDRVREG VMMDev::DrvReg =
887{
888 /* u32Version */
889 PDM_DRVREG_VERSION,
890 /* szName */
891 "HGCM",
892 /* szRCMod */
893 "",
894 /* szR0Mod */
895 "",
896 /* pszDescription */
897 "Main VMMDev driver (Main as in the API).",
898 /* fFlags */
899 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
900 /* fClass. */
901 PDM_DRVREG_CLASS_VMMDEV,
902 /* cMaxInstances */
903 ~0U,
904 /* cbInstance */
905 sizeof(DRVMAINVMMDEV),
906 /* pfnConstruct */
907 VMMDev::drvConstruct,
908 /* pfnDestruct */
909 VMMDev::drvDestruct,
910 /* pfnRelocate */
911 NULL,
912 /* pfnIOCtl */
913 NULL,
914 /* pfnPowerOn */
915 NULL,
916 /* pfnReset */
917 VMMDev::drvReset,
918 /* pfnSuspend */
919 NULL,
920 /* pfnResume */
921 NULL,
922 /* pfnAttach */
923 NULL,
924 /* pfnDetach */
925 NULL,
926 /* pfnPowerOff */
927 NULL,
928 /* pfnSoftReset */
929 NULL,
930 /* u32EndVersion */
931 PDM_DRVREG_VERSION
932};
933/* 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