VirtualBox

source: vbox/trunk/src/VBox/Main/VMMDevInterface.cpp@ 31744

Last change on this file since 31744 was 31692, checked in by vboxsync, 14 years ago

Cleaned up IGuest page fusion api

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