VirtualBox

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

Last change on this file since 31312 was 31241, checked in by vboxsync, 14 years ago

Removed use of interface version for IGuest::getAdditionsVersion, some cleanup.

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