VirtualBox

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

Last change on this file since 32928 was 32851, checked in by vboxsync, 14 years ago

Main: defer creation of the VMMDev instance in Console to Console::powerUpThread so that the VMMDev with the HGCM thread only gets created for session/console pairs any more which actually power up a VM; this avoids creating dozens of HGCM threads for every single session even if it never starts a VM; some more Console code cleanup while we're at it

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