VirtualBox

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

Last change on this file since 39882 was 39882, checked in by vboxsync, 13 years ago

Config.kmk,VMMDev,Main,QtGui,VBoxManage: Refactored IGuest::additionsVersion and associated acts, splitting it up into additionsVersion and additionsRevision like IVirtualBox and IExtPack handles versioning. Fixed missing saved state in VMMDev where the VMMDevReq_ReportGuestInfo2 info was not saved and Main+Frontends led to believe we were running guest additions older than 3.2. The changes have be subjected to limited testing. Added TODOs for another missing save in VMMDev.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette