VirtualBox

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

Last change on this file since 91490 was 90691, checked in by vboxsync, 3 years ago

pdmifs: display reporting doxygen (brief + newline + detailed description) and parameter type+name.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.0 KB
Line 
1/* $Id: VMMDevInterface.cpp 90691 2021-08-16 08:43:03Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to VMM device.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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#endif
36
37//
38// defines
39//
40
41#ifdef RT_OS_OS2
42# define VBOXSHAREDFOLDERS_DLL "VBoxSFld"
43#else
44# define VBOXSHAREDFOLDERS_DLL "VBoxSharedFolders"
45#endif
46
47//
48// globals
49//
50
51
52/**
53 * VMMDev driver instance data.
54 */
55typedef struct DRVMAINVMMDEV
56{
57 /** Pointer to the VMMDev object. */
58 VMMDev *pVMMDev;
59 /** Pointer to the driver instance structure. */
60 PPDMDRVINS pDrvIns;
61 /** Pointer to the VMMDev port interface of the driver/device above us. */
62 PPDMIVMMDEVPORT pUpPort;
63 /** Our VMM device connector interface. */
64 PDMIVMMDEVCONNECTOR Connector;
65
66#ifdef VBOX_WITH_HGCM
67 /** Pointer to the HGCM port interface of the driver/device above us. */
68 PPDMIHGCMPORT pHGCMPort;
69 /** Our HGCM connector interface. */
70 PDMIHGCMCONNECTOR HGCMConnector;
71#endif
72
73#ifdef VBOX_WITH_GUEST_PROPS
74 HGCMSVCEXTHANDLE hHgcmSvcExtGstProps;
75#endif
76#ifdef VBOX_WITH_GUEST_CONTROL
77 HGCMSVCEXTHANDLE hHgcmSvcExtGstCtrl;
78#endif
79} DRVMAINVMMDEV, *PDRVMAINVMMDEV;
80
81//
82// constructor / destructor
83//
84VMMDev::VMMDev(Console *console)
85 : mpDrv(NULL)
86 , mParent(console)
87{
88 int rc = RTSemEventCreate(&mCredentialsEvent);
89 AssertRC(rc);
90#ifdef VBOX_WITH_HGCM
91 rc = HGCMHostInit();
92 AssertRC(rc);
93 m_fHGCMActive = true;
94#endif /* VBOX_WITH_HGCM */
95 mu32CredentialsFlags = 0;
96}
97
98VMMDev::~VMMDev()
99{
100#ifdef VBOX_WITH_HGCM
101 if (ASMAtomicCmpXchgBool(&m_fHGCMActive, false, true))
102 HGCMHostShutdown(true /*fUvmIsInvalid*/);
103#endif
104 RTSemEventDestroy(mCredentialsEvent);
105 if (mpDrv)
106 mpDrv->pVMMDev = NULL;
107 mpDrv = NULL;
108}
109
110PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
111{
112 if (!mpDrv)
113 return NULL;
114 return mpDrv->pUpPort;
115}
116
117
118
119//
120// public methods
121//
122
123/**
124 * Wait on event semaphore for guest credential judgement result.
125 */
126int VMMDev::WaitCredentialsJudgement(uint32_t u32Timeout, uint32_t *pu32CredentialsFlags)
127{
128 if (u32Timeout == 0)
129 {
130 u32Timeout = 5000;
131 }
132
133 int rc = RTSemEventWait(mCredentialsEvent, u32Timeout);
134
135 if (RT_SUCCESS(rc))
136 {
137 *pu32CredentialsFlags = mu32CredentialsFlags;
138 }
139
140 return rc;
141}
142
143int VMMDev::SetCredentialsJudgementResult(uint32_t u32Flags)
144{
145 mu32CredentialsFlags = u32Flags;
146
147 int rc = RTSemEventSignal(mCredentialsEvent);
148 AssertRC(rc);
149
150 return rc;
151}
152
153
154/**
155 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestStatus}
156 */
157DECLCALLBACK(void) vmmdevUpdateGuestStatus(PPDMIVMMDEVCONNECTOR pInterface, uint32_t uFacility, uint16_t uStatus,
158 uint32_t fFlags, PCRTTIMESPEC pTimeSpecTS)
159{
160 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
161 Console *pConsole = pDrv->pVMMDev->getParent();
162
163 /* Store that information in IGuest */
164 Guest* guest = pConsole->i_getGuest();
165 AssertPtrReturnVoid(guest);
166
167 guest->i_setAdditionsStatus((VBoxGuestFacilityType)uFacility, (VBoxGuestFacilityStatus)uStatus, fFlags, pTimeSpecTS);
168 pConsole->i_onAdditionsStateChange();
169}
170
171
172/**
173 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestUserState}
174 */
175DECLCALLBACK(void) vmmdevUpdateGuestUserState(PPDMIVMMDEVCONNECTOR pInterface,
176 const char *pszUser, const char *pszDomain,
177 uint32_t uState,
178 const uint8_t *pabDetails, uint32_t cbDetails)
179{
180 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
181 AssertPtr(pDrv);
182 Console *pConsole = pDrv->pVMMDev->getParent();
183 AssertPtr(pConsole);
184
185 /* Store that information in IGuest. */
186 Guest* pGuest = pConsole->i_getGuest();
187 AssertPtrReturnVoid(pGuest);
188
189 pGuest->i_onUserStateChanged(Utf8Str(pszUser), Utf8Str(pszDomain), (VBoxGuestUserState)uState, 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
463/**
464 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateMonitorPositions}
465 */
466static DECLCALLBACK(int) vmmdevUpdateMonitorPositions(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cPositions, PCRTPOINT paPositions)
467{
468 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
469 Console *pConsole = pDrv->pVMMDev->getParent();
470
471 pConsole->i_getDisplay()->i_handleUpdateMonitorPositions(cPositions, paPositions);
472
473 return VINF_SUCCESS;
474}
475
476DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRects, PRTRECT paRects)
477{
478 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
479 Console *pConsole = pDrv->pVMMDev->getParent();
480
481 /* Forward to Display, which calls corresponding framebuffers. */
482 pConsole->i_getDisplay()->i_handleQueryVisibleRegion(pcRects, paRects);
483
484 return VINF_SUCCESS;
485}
486
487/**
488 * Request the statistics interval
489 *
490 * @returns VBox status code.
491 * @param pInterface Pointer to this interface.
492 * @param pulInterval Pointer to interval in seconds
493 * @thread The emulation thread.
494 */
495DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
496{
497 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
498 Console *pConsole = pDrv->pVMMDev->getParent();
499 ULONG val = 0;
500
501 if (!pulInterval)
502 return VERR_INVALID_POINTER;
503
504 /* store that information in IGuest */
505 Guest* guest = pConsole->i_getGuest();
506 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
507
508 guest->COMGETTER(StatisticsUpdateInterval)(&val);
509 *pulInterval = val;
510 return VINF_SUCCESS;
511}
512
513/**
514 * Query the current balloon size
515 *
516 * @returns VBox status code.
517 * @param pInterface Pointer to this interface.
518 * @param pcbBalloon Balloon size
519 * @thread The emulation thread.
520 */
521DECLCALLBACK(int) vmmdevQueryBalloonSize(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcbBalloon)
522{
523 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
524 Console *pConsole = pDrv->pVMMDev->getParent();
525 ULONG val = 0;
526
527 if (!pcbBalloon)
528 return VERR_INVALID_POINTER;
529
530 /* store that information in IGuest */
531 Guest* guest = pConsole->i_getGuest();
532 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
533
534 guest->COMGETTER(MemoryBalloonSize)(&val);
535 *pcbBalloon = val;
536 return VINF_SUCCESS;
537}
538
539/**
540 * Query the current page fusion setting
541 *
542 * @returns VBox status code.
543 * @param pInterface Pointer to this interface.
544 * @param pfPageFusionEnabled Pointer to boolean
545 * @thread The emulation thread.
546 */
547DECLCALLBACK(int) vmmdevIsPageFusionEnabled(PPDMIVMMDEVCONNECTOR pInterface, bool *pfPageFusionEnabled)
548{
549 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
550 Console *pConsole = pDrv->pVMMDev->getParent();
551
552 if (!pfPageFusionEnabled)
553 return VERR_INVALID_POINTER;
554
555 /* store that information in IGuest */
556 Guest* guest = pConsole->i_getGuest();
557 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
558
559 *pfPageFusionEnabled = !!guest->i_isPageFusionEnabled();
560 return VINF_SUCCESS;
561}
562
563/**
564 * Report new guest statistics
565 *
566 * @returns VBox status code.
567 * @param pInterface Pointer to this interface.
568 * @param pGuestStats Guest statistics
569 * @thread The emulation thread.
570 */
571DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
572{
573 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
574 Console *pConsole = pDrv->pVMMDev->getParent();
575
576 AssertPtrReturn(pGuestStats, VERR_INVALID_POINTER);
577
578 /* store that information in IGuest */
579 Guest* guest = pConsole->i_getGuest();
580 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
581
582 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
583 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
584
585 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
586 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
587
588 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
589 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
590
591
592 /** @todo r=bird: Convert from 4KB to 1KB units?
593 * CollectorGuestHAL::i_getGuestMemLoad says it returns KB units to
594 * preCollect(). I might be wrong ofc, this is convoluted code... */
595 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
596 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
597
598 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
599 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
600
601 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
602 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
603
604 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
605 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
606
607 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
608 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
609
610 return VINF_SUCCESS;
611}
612
613#ifdef VBOX_WITH_HGCM
614
615/* HGCM connector interface */
616
617static DECLCALLBACK(int) iface_hgcmConnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd,
618 PHGCMSERVICELOCATION pServiceLocation,
619 uint32_t *pu32ClientID)
620{
621 Log9(("Enter\n"));
622
623 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
624
625 if ( !pServiceLocation
626 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
627 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
628 {
629 return VERR_INVALID_PARAMETER;
630 }
631
632 /* Check if service name is a string terminated by zero*/
633 size_t cchInfo = 0;
634 if (RTStrNLenEx(pServiceLocation->u.host.achName, sizeof(pServiceLocation->u.host.achName), &cchInfo) != VINF_SUCCESS)
635 {
636 return VERR_INVALID_PARAMETER;
637 }
638
639 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
640 return VERR_INVALID_STATE;
641 return HGCMGuestConnect(pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
642}
643
644static DECLCALLBACK(int) iface_hgcmDisconnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
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 HGCMGuestDisconnect(pDrv->pHGCMPort, pCmd, u32ClientID);
654}
655
656static DECLCALLBACK(int) iface_hgcmCall(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID,
657 uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms, uint64_t tsArrival)
658{
659 Log9(("Enter\n"));
660
661 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
662
663 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
664 return VERR_INVALID_STATE;
665
666 return HGCMGuestCall(pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms, tsArrival);
667}
668
669static DECLCALLBACK(void) iface_hgcmCancelled(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t idClient)
670{
671 Log9(("Enter\n"));
672
673 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
674 if ( pDrv->pVMMDev
675 && pDrv->pVMMDev->hgcmIsActive())
676 return HGCMGuestCancelled(pDrv->pHGCMPort, pCmd, idClient);
677}
678
679/**
680 * Execute state save operation.
681 *
682 * @returns VBox status code.
683 * @param pDrvIns Driver instance of the driver which registered the data unit.
684 * @param pSSM SSM operation handle.
685 */
686static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
687{
688 RT_NOREF(pDrvIns);
689 Log9(("Enter\n"));
690 return HGCMHostSaveState(pSSM);
691}
692
693
694/**
695 * Execute state load operation.
696 *
697 * @returns VBox status code.
698 * @param pDrvIns Driver instance of the driver which registered the data unit.
699 * @param pSSM SSM operation handle.
700 * @param uVersion Data layout version.
701 * @param uPass The data pass.
702 */
703static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
704{
705 RT_NOREF(pDrvIns);
706 LogFlowFunc(("Enter\n"));
707
708 if ( uVersion != HGCM_SAVED_STATE_VERSION
709 && uVersion != HGCM_SAVED_STATE_VERSION_V2)
710 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
711 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
712
713 return HGCMHostLoadState(pSSM, uVersion);
714}
715
716int VMMDev::hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName)
717{
718 if (!hgcmIsActive())
719 return VERR_INVALID_STATE;
720
721 /** @todo Construct all the services in the VMMDev::drvConstruct()!! */
722 Assert( (mpDrv && mpDrv->pHGCMPort)
723 || !strcmp(pszServiceLibrary, "VBoxHostChannel")
724 || !strcmp(pszServiceLibrary, "VBoxSharedClipboard")
725 || !strcmp(pszServiceLibrary, "VBoxDragAndDropSvc")
726 || !strcmp(pszServiceLibrary, "VBoxGuestPropSvc")
727 || !strcmp(pszServiceLibrary, "VBoxSharedCrOpenGL")
728 );
729 Console::SafeVMPtrQuiet ptrVM(mParent);
730 return HGCMHostLoad(pszServiceLibrary, pszServiceName, ptrVM.rawUVM(), mpDrv ? mpDrv->pHGCMPort : NULL);
731}
732
733int VMMDev::hgcmHostCall(const char *pszServiceName, uint32_t u32Function,
734 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
735{
736 if (!hgcmIsActive())
737 return VERR_INVALID_STATE;
738 return HGCMHostCall(pszServiceName, u32Function, cParms, paParms);
739}
740
741/**
742 * Used by Console::i_powerDown to shut down the services before the VM is destroyed.
743 */
744void VMMDev::hgcmShutdown(bool fUvmIsInvalid /*= false*/)
745{
746#ifdef VBOX_WITH_GUEST_PROPS
747 if (mpDrv && mpDrv->hHgcmSvcExtGstProps)
748 {
749 HGCMHostUnregisterServiceExtension(mpDrv->hHgcmSvcExtGstProps);
750 mpDrv->hHgcmSvcExtGstProps = NULL;
751 }
752#endif
753
754#ifdef VBOX_WITH_GUEST_CONTROL
755 if (mpDrv && mpDrv->hHgcmSvcExtGstCtrl)
756 {
757 HGCMHostUnregisterServiceExtension(mpDrv->hHgcmSvcExtGstCtrl);
758 mpDrv->hHgcmSvcExtGstCtrl = NULL;
759 }
760#endif
761
762 if (ASMAtomicCmpXchgBool(&m_fHGCMActive, false, true))
763 HGCMHostShutdown(fUvmIsInvalid);
764}
765
766#endif /* HGCM */
767
768
769/**
770 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
771 */
772DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
773{
774 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
775 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
776
777 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
778 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
779#ifdef VBOX_WITH_HGCM
780 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
781#endif
782 return NULL;
783}
784
785/**
786 * @interface_method_impl{PDMDRVREG,pfnSuspend}
787 */
788/*static*/ DECLCALLBACK(void) VMMDev::drvSuspend(PPDMDRVINS pDrvIns)
789{
790 RT_NOREF(pDrvIns);
791#ifdef VBOX_WITH_HGCM
792 HGCMBroadcastEvent(HGCMNOTIFYEVENT_SUSPEND);
793#endif
794}
795
796/**
797 * @interface_method_impl{PDMDRVREG,pfnResume}
798 */
799/*static*/ DECLCALLBACK(void) VMMDev::drvResume(PPDMDRVINS pDrvIns)
800{
801 RT_NOREF(pDrvIns);
802#ifdef VBOX_WITH_HGCM
803 HGCMBroadcastEvent(HGCMNOTIFYEVENT_RESUME);
804#endif
805}
806
807/**
808 * @interface_method_impl{PDMDRVREG,pfnPowerOff}
809 */
810/*static*/ DECLCALLBACK(void) VMMDev::drvPowerOff(PPDMDRVINS pDrvIns)
811{
812 RT_NOREF(pDrvIns);
813#ifdef VBOX_WITH_HGCM
814 HGCMBroadcastEvent(HGCMNOTIFYEVENT_POWER_ON);
815#endif
816}
817
818/**
819 * @interface_method_impl{PDMDRVREG,pfnPowerOn}
820 */
821/*static*/ DECLCALLBACK(void) VMMDev::drvPowerOn(PPDMDRVINS pDrvIns)
822{
823 RT_NOREF(pDrvIns);
824#ifdef VBOX_WITH_HGCM
825 HGCMBroadcastEvent(HGCMNOTIFYEVENT_POWER_ON);
826#endif
827}
828
829/**
830 * @interface_method_impl{PDMDRVREG,pfnReset}
831 */
832DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
833{
834 RT_NOREF(pDrvIns);
835 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
836#ifdef VBOX_WITH_HGCM
837 HGCMHostReset(false /*fForShutdown*/);
838#endif
839}
840
841/**
842 * @interface_method_impl{PDMDRVREG,pfnDestruct}
843 */
844DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
845{
846 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
847 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
848 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
849
850#ifdef VBOX_WITH_GUEST_PROPS
851 if (pThis->hHgcmSvcExtGstProps)
852 {
853 HGCMHostUnregisterServiceExtension(pThis->hHgcmSvcExtGstProps);
854 pThis->hHgcmSvcExtGstProps = NULL;
855 }
856#endif
857
858#ifdef VBOX_WITH_GUEST_CONTROL
859 if (pThis->hHgcmSvcExtGstCtrl)
860 {
861 HGCMHostUnregisterServiceExtension(pThis->hHgcmSvcExtGstCtrl);
862 pThis->hHgcmSvcExtGstCtrl = NULL;
863 }
864#endif
865
866 if (pThis->pVMMDev)
867 {
868#ifdef VBOX_WITH_HGCM
869 /* When VM construction goes wrong, we prefer shutting down HGCM here
870 while pUVM is still valid, rather than in ~VMMDev. */
871 if (ASMAtomicCmpXchgBool(&pThis->pVMMDev->m_fHGCMActive, false, true))
872 HGCMHostShutdown();
873#endif
874 pThis->pVMMDev->mpDrv = NULL;
875 }
876}
877
878#ifdef VBOX_WITH_GUEST_PROPS
879
880/**
881 * Set an array of guest properties
882 */
883void VMMDev::i_guestPropSetMultiple(void *names, void *values, void *timestamps, void *flags)
884{
885 VBOXHGCMSVCPARM parms[4];
886
887 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
888 parms[0].u.pointer.addr = names;
889 parms[0].u.pointer.size = 0; /* We don't actually care. */
890 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
891 parms[1].u.pointer.addr = values;
892 parms[1].u.pointer.size = 0; /* We don't actually care. */
893 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
894 parms[2].u.pointer.addr = timestamps;
895 parms[2].u.pointer.size = 0; /* We don't actually care. */
896 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
897 parms[3].u.pointer.addr = flags;
898 parms[3].u.pointer.size = 0; /* We don't actually care. */
899
900 hgcmHostCall("VBoxGuestPropSvc", GUEST_PROP_FN_HOST_SET_PROPS, 4, &parms[0]);
901}
902
903/**
904 * Set a single guest property
905 */
906void VMMDev::i_guestPropSet(const char *pszName, const char *pszValue, const char *pszFlags)
907{
908 VBOXHGCMSVCPARM parms[4];
909
910 AssertPtrReturnVoid(pszName);
911 AssertPtrReturnVoid(pszValue);
912 AssertPtrReturnVoid(pszFlags);
913 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
914 parms[0].u.pointer.addr = (void *)pszName;
915 parms[0].u.pointer.size = (uint32_t)strlen(pszName) + 1;
916 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
917 parms[1].u.pointer.addr = (void *)pszValue;
918 parms[1].u.pointer.size = (uint32_t)strlen(pszValue) + 1;
919 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
920 parms[2].u.pointer.addr = (void *)pszFlags;
921 parms[2].u.pointer.size = (uint32_t)strlen(pszFlags) + 1;
922 hgcmHostCall("VBoxGuestPropSvc", GUEST_PROP_FN_HOST_SET_PROP, 3, &parms[0]);
923}
924
925/**
926 * Set the global flags value by calling the service
927 * @returns the status returned by the call to the service
928 *
929 * @param pTable the service instance handle
930 * @param eFlags the flags to set
931 */
932int VMMDev::i_guestPropSetGlobalPropertyFlags(uint32_t fFlags)
933{
934 VBOXHGCMSVCPARM parm;
935 HGCMSvcSetU32(&parm, fFlags);
936 int rc = hgcmHostCall("VBoxGuestPropSvc", GUEST_PROP_FN_HOST_SET_GLOBAL_FLAGS, 1, &parm);
937 if (RT_FAILURE(rc))
938 {
939 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
940 if (RT_FAILURE(GuestPropWriteFlags(fFlags, szFlags)))
941 Log(("Failed to set the global flags.\n"));
942 else
943 Log(("Failed to set the global flags \"%s\".\n", szFlags));
944 }
945 return rc;
946}
947
948
949/**
950 * Set up the Guest Property service, populate it with properties read from
951 * the machine XML and set a couple of initial properties.
952 */
953int VMMDev::i_guestPropLoadAndConfigure()
954{
955 Assert(mpDrv);
956 ComObjPtr<Console> ptrConsole = this->mParent;
957 AssertReturn(ptrConsole.isNotNull(), VERR_INVALID_POINTER);
958
959 /*
960 * Load the service
961 */
962 int rc = hgcmLoadService("VBoxGuestPropSvc", "VBoxGuestPropSvc");
963 if (RT_FAILURE(rc))
964 {
965 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
966 return VINF_SUCCESS; /* That is not a fatal failure. */
967 }
968
969 /*
970 * Pull over the properties from the server.
971 */
972 SafeArray<BSTR> namesOut;
973 SafeArray<BSTR> valuesOut;
974 SafeArray<LONG64> timestampsOut;
975 SafeArray<BSTR> flagsOut;
976 HRESULT hrc = ptrConsole->i_pullGuestProperties(ComSafeArrayAsOutParam(namesOut),
977 ComSafeArrayAsOutParam(valuesOut),
978 ComSafeArrayAsOutParam(timestampsOut),
979 ComSafeArrayAsOutParam(flagsOut));
980 AssertLogRelMsgReturn(SUCCEEDED(hrc), ("hrc=%Rhrc\n", hrc), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR);
981 size_t const cProps = namesOut.size();
982 size_t const cAlloc = cProps + 1;
983 AssertLogRelReturn(valuesOut.size() == cProps, VERR_INTERNAL_ERROR_2);
984 AssertLogRelReturn(timestampsOut.size() == cProps, VERR_INTERNAL_ERROR_3);
985 AssertLogRelReturn(flagsOut.size() == cProps, VERR_INTERNAL_ERROR_4);
986
987 char szEmpty[] = "";
988 char **papszNames = (char **)RTMemTmpAllocZ(sizeof(char *) * cAlloc);
989 char **papszValues = (char **)RTMemTmpAllocZ(sizeof(char *) * cAlloc);
990 LONG64 *pai64Timestamps = (LONG64 *)RTMemTmpAllocZ(sizeof(LONG64) * cAlloc);
991 char **papszFlags = (char **)RTMemTmpAllocZ(sizeof(char *) * cAlloc);
992 if (papszNames && papszValues && pai64Timestamps && papszFlags)
993 {
994 for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
995 {
996 AssertPtrBreakStmt(namesOut[i], rc = VERR_INVALID_PARAMETER);
997 rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
998 if (RT_FAILURE(rc))
999 break;
1000 if (valuesOut[i])
1001 rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
1002 else
1003 papszValues[i] = szEmpty;
1004 if (RT_FAILURE(rc))
1005 break;
1006 pai64Timestamps[i] = timestampsOut[i];
1007 if (flagsOut[i])
1008 rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
1009 else
1010 papszFlags[i] = szEmpty;
1011 }
1012 if (RT_SUCCESS(rc))
1013 i_guestPropSetMultiple((void *)papszNames, (void *)papszValues, (void *)pai64Timestamps, (void *)papszFlags);
1014 for (unsigned i = 0; i < cProps; ++i)
1015 {
1016 RTStrFree(papszNames[i]);
1017 if (valuesOut[i])
1018 RTStrFree(papszValues[i]);
1019 if (flagsOut[i])
1020 RTStrFree(papszFlags[i]);
1021 }
1022 }
1023 else
1024 rc = VERR_NO_MEMORY;
1025 RTMemTmpFree(papszNames);
1026 RTMemTmpFree(papszValues);
1027 RTMemTmpFree(pai64Timestamps);
1028 RTMemTmpFree(papszFlags);
1029 AssertRCReturn(rc, rc);
1030
1031 /*
1032 * Register the host notification callback
1033 */
1034 HGCMHostRegisterServiceExtension(&mpDrv->hHgcmSvcExtGstProps, "VBoxGuestPropSvc", Console::i_doGuestPropNotification, ptrConsole.m_p);
1035
1036# ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
1037 rc = i_guestPropSetGlobalPropertyFlags(GUEST_PROP_F_RDONLYGUEST);
1038 AssertRCReturn(rc, rc);
1039# endif
1040
1041 Log(("Set VBoxGuestPropSvc property store\n"));
1042 return VINF_SUCCESS;
1043}
1044
1045#endif /* VBOX_WITH_GUEST_PROPS */
1046
1047/**
1048 * @interface_method_impl{PDMDRVREG,pfnConstruct}
1049 */
1050DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
1051{
1052 RT_NOREF(fFlags);
1053 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
1054 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
1055 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
1056
1057 /*
1058 * Validate configuration.
1059 */
1060 if (!CFGMR3AreValuesValid(pCfgHandle, ""))
1061 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
1062 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
1063 ("Configuration error: Not possible to attach anything to this driver!\n"),
1064 VERR_PDM_DRVINS_NO_ATTACH);
1065
1066 /*
1067 * IBase.
1068 */
1069 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
1070
1071 pThis->Connector.pfnUpdateGuestStatus = vmmdevUpdateGuestStatus;
1072 pThis->Connector.pfnUpdateGuestUserState = vmmdevUpdateGuestUserState;
1073 pThis->Connector.pfnUpdateGuestInfo = vmmdevUpdateGuestInfo;
1074 pThis->Connector.pfnUpdateGuestInfo2 = vmmdevUpdateGuestInfo2;
1075 pThis->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
1076 pThis->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
1077 pThis->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
1078 pThis->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
1079 pThis->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
1080 pThis->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
1081 pThis->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
1082 pThis->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
1083 pThis->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
1084 pThis->Connector.pfnUpdateMonitorPositions = vmmdevUpdateMonitorPositions;
1085 pThis->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
1086 pThis->Connector.pfnReportStatistics = vmmdevReportStatistics;
1087 pThis->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
1088 pThis->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
1089 pThis->Connector.pfnIsPageFusionEnabled = vmmdevIsPageFusionEnabled;
1090
1091#ifdef VBOX_WITH_HGCM
1092 pThis->HGCMConnector.pfnConnect = iface_hgcmConnect;
1093 pThis->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
1094 pThis->HGCMConnector.pfnCall = iface_hgcmCall;
1095 pThis->HGCMConnector.pfnCancelled = iface_hgcmCancelled;
1096#endif
1097
1098 /*
1099 * Get the IVMMDevPort interface of the above driver/device.
1100 */
1101 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
1102 AssertMsgReturn(pThis->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1103
1104#ifdef VBOX_WITH_HGCM
1105 pThis->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
1106 AssertMsgReturn(pThis->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1107#endif
1108
1109 /*
1110 * Get the Console object pointer and update the mpDrv member.
1111 */
1112 com::Guid uuid(VMMDEV_OID);
1113 pThis->pVMMDev = (VMMDev*)PDMDrvHlpQueryGenericUserObject(pDrvIns, uuid.raw());
1114 if (!pThis->pVMMDev)
1115 {
1116 AssertMsgFailed(("Configuration error: No/bad VMMDev object!\n"));
1117 return VERR_NOT_FOUND;
1118 }
1119 pThis->pVMMDev->mpDrv = pThis;
1120
1121 int rc = VINF_SUCCESS;
1122#ifdef VBOX_WITH_HGCM
1123 /*
1124 * Load & configure the shared folders service.
1125 */
1126 rc = pThis->pVMMDev->hgcmLoadService(VBOXSHAREDFOLDERS_DLL, "VBoxSharedFolders");
1127 pThis->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
1128 if (RT_SUCCESS(rc))
1129 {
1130 PPDMLED pLed;
1131 PPDMILEDPORTS pLedPort;
1132
1133 LogRel(("Shared Folders service loaded\n"));
1134 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
1135 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1136 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
1137 if (RT_SUCCESS(rc) && pLed)
1138 {
1139 VBOXHGCMSVCPARM parm;
1140
1141 parm.type = VBOX_HGCM_SVC_PARM_PTR;
1142 parm.u.pointer.addr = pLed;
1143 parm.u.pointer.size = sizeof(*pLed);
1144
1145 rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
1146 }
1147 else
1148 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
1149 }
1150 else
1151 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
1152
1153
1154 /*
1155 * Load and configure the guest control service.
1156 */
1157# ifdef VBOX_WITH_GUEST_CONTROL
1158 rc = pThis->pVMMDev->hgcmLoadService("VBoxGuestControlSvc", "VBoxGuestControlSvc");
1159 if (RT_SUCCESS(rc))
1160 {
1161 rc = HGCMHostRegisterServiceExtension(&pThis->hHgcmSvcExtGstCtrl, "VBoxGuestControlSvc",
1162 &Guest::i_notifyCtrlDispatcher,
1163 pThis->pVMMDev->mParent->i_getGuest());
1164 if (RT_SUCCESS(rc))
1165 LogRel(("Guest Control service loaded\n"));
1166 else
1167 LogRel(("Warning: Cannot register VBoxGuestControlSvc extension! rc=%Rrc\n", rc));
1168 }
1169 else
1170 LogRel(("Warning!: Failed to load the Guest Control Service! %Rrc\n", rc));
1171# endif /* VBOX_WITH_GUEST_CONTROL */
1172
1173
1174 /*
1175 * Load and configure the guest properties service.
1176 */
1177# ifdef VBOX_WITH_GUEST_PROPS
1178 rc = pThis->pVMMDev->i_guestPropLoadAndConfigure();
1179 AssertLogRelRCReturn(rc, rc);
1180# endif
1181
1182
1183 /*
1184 * The HGCM saved state.
1185 */
1186 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SAVED_STATE_VERSION, 4096 /* bad guess */,
1187 NULL, NULL, NULL,
1188 NULL, iface_hgcmSave, NULL,
1189 NULL, iface_hgcmLoad, NULL);
1190 if (RT_FAILURE(rc))
1191 return rc;
1192
1193#endif /* VBOX_WITH_HGCM */
1194
1195 return VINF_SUCCESS;
1196}
1197
1198
1199/**
1200 * VMMDevice driver registration record.
1201 */
1202const PDMDRVREG VMMDev::DrvReg =
1203{
1204 /* u32Version */
1205 PDM_DRVREG_VERSION,
1206 /* szName */
1207 "HGCM",
1208 /* szRCMod */
1209 "",
1210 /* szR0Mod */
1211 "",
1212 /* pszDescription */
1213 "Main VMMDev driver (Main as in the API).",
1214 /* fFlags */
1215 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
1216 /* fClass. */
1217 PDM_DRVREG_CLASS_VMMDEV,
1218 /* cMaxInstances */
1219 ~0U,
1220 /* cbInstance */
1221 sizeof(DRVMAINVMMDEV),
1222 /* pfnConstruct */
1223 VMMDev::drvConstruct,
1224 /* pfnDestruct */
1225 VMMDev::drvDestruct,
1226 /* pfnRelocate */
1227 NULL,
1228 /* pfnIOCtl */
1229 NULL,
1230 /* pfnPowerOn */
1231 VMMDev::drvPowerOn,
1232 /* pfnReset */
1233 VMMDev::drvReset,
1234 /* pfnSuspend */
1235 VMMDev::drvSuspend,
1236 /* pfnResume */
1237 VMMDev::drvResume,
1238 /* pfnAttach */
1239 NULL,
1240 /* pfnDetach */
1241 NULL,
1242 /* pfnPowerOff */
1243 VMMDev::drvPowerOff,
1244 /* pfnSoftReset */
1245 NULL,
1246 /* u32EndVersion */
1247 PDM_DRVREG_VERSION
1248};
1249/* 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