VirtualBox

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

Last change on this file since 26600 was 26350, checked in by vboxsync, 15 years ago

Removed the balloon interface from Main's VMM device. Directly call PGMR3PhysFreeRamPages in VMMDev.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.4 KB
Line 
1/* $Id: VMMDevInterface.cpp 26350 2010-02-09 09:21:38Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to VMM device.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include "VMMDev.h"
23#include "ConsoleImpl.h"
24#include "DisplayImpl.h"
25#include "GuestImpl.h"
26
27#include "Logging.h"
28
29#include <VBox/pdmdrv.h>
30#include <VBox/VMMDev.h>
31#include <VBox/shflsvc.h>
32#include <iprt/asm.h>
33
34#ifdef VBOX_WITH_HGCM
35#include "hgcm/HGCM.h"
36#include "hgcm/HGCMObjects.h"
37# if defined(RT_OS_DARWIN) && defined(VBOX_WITH_CROGL)
38# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
39# endif
40#endif
41
42//
43// defines
44//
45
46#ifdef RT_OS_OS2
47# define VBOXSHAREDFOLDERS_DLL "VBoxSFld"
48#else
49# define VBOXSHAREDFOLDERS_DLL "VBoxSharedFolders"
50#endif
51
52//
53// globals
54//
55
56
57/**
58 * VMMDev driver instance data.
59 */
60typedef struct DRVMAINVMMDEV
61{
62 /** Pointer to the VMMDev object. */
63 VMMDev *pVMMDev;
64 /** Pointer to the driver instance structure. */
65 PPDMDRVINS pDrvIns;
66 /** Pointer to the VMMDev port interface of the driver/device above us. */
67 PPDMIVMMDEVPORT pUpPort;
68 /** Our VMM device connector interface. */
69 PDMIVMMDEVCONNECTOR Connector;
70
71#ifdef VBOX_WITH_HGCM
72 /** Pointer to the HGCM port interface of the driver/device above us. */
73 PPDMIHGCMPORT pHGCMPort;
74 /** Our HGCM connector interface. */
75 PDMIHGCMCONNECTOR HGCMConnector;
76#endif
77} DRVMAINVMMDEV, *PDRVMAINVMMDEV;
78
79/** Converts PDMIVMMDEVCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
80#define PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, Connector)) )
81
82#ifdef VBOX_WITH_HGCM
83/** Converts PDMIHGCMCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
84#define PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, HGCMConnector)) )
85#endif
86
87//
88// constructor / destructor
89//
90VMMDev::VMMDev(Console *console) : mpDrv(NULL)
91{
92 mParent = console;
93 int rc = RTSemEventCreate(&mCredentialsEvent);
94 AssertRC(rc);
95#ifdef VBOX_WITH_HGCM
96 rc = HGCMHostInit ();
97 AssertRC(rc);
98 m_fHGCMActive = true;
99#endif /* VBOX_WITH_HGCM */
100 mu32CredentialsFlags = 0;
101}
102
103VMMDev::~VMMDev()
104{
105#ifdef VBOX_WITH_HGCM
106 if (hgcmIsActive())
107 {
108 ASMAtomicWriteBool(&m_fHGCMActive, false);
109 HGCMHostShutdown();
110 }
111#endif /* VBOX_WITH_HGCM */
112 RTSemEventDestroy (mCredentialsEvent);
113 if (mpDrv)
114 mpDrv->pVMMDev = NULL;
115 mpDrv = NULL;
116}
117
118PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
119{
120 Assert(mpDrv);
121 return mpDrv->pUpPort;
122}
123
124
125
126//
127// public methods
128//
129
130/**
131 * Wait on event semaphore for guest credential judgement result.
132 */
133int VMMDev::WaitCredentialsJudgement (uint32_t u32Timeout, uint32_t *pu32CredentialsFlags)
134{
135 if (u32Timeout == 0)
136 {
137 u32Timeout = 5000;
138 }
139
140 int rc = RTSemEventWait (mCredentialsEvent, u32Timeout);
141
142 if (RT_SUCCESS(rc))
143 {
144 *pu32CredentialsFlags = mu32CredentialsFlags;
145 }
146
147 return rc;
148}
149
150int VMMDev::SetCredentialsJudgementResult (uint32_t u32Flags)
151{
152 mu32CredentialsFlags = u32Flags;
153
154 int rc = RTSemEventSignal (mCredentialsEvent);
155 AssertRC(rc);
156
157 return rc;
158}
159
160
161/**
162 * Report guest OS version.
163 * Called whenever the Additions issue a guest version report request or the VM is reset.
164 *
165 * @param pInterface Pointer to this interface.
166 * @param guestInfo Pointer to guest information structure
167 * @thread The emulation thread.
168 */
169DECLCALLBACK(void) vmmdevUpdateGuestVersion(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestInfo *guestInfo)
170{
171 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
172
173 Assert(guestInfo);
174 if (!guestInfo)
175 return;
176
177 /* store that information in IGuest */
178 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
179 Assert(guest);
180 if (!guest)
181 return;
182
183 if (guestInfo->additionsVersion != 0)
184 {
185 char version[20];
186 RTStrPrintf(version, sizeof(version), "%d", guestInfo->additionsVersion);
187 guest->setAdditionsVersion(Bstr(version), guestInfo->osType);
188
189 /*
190 * Tell the console interface about the event
191 * so that it can notify its consumers.
192 */
193 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
194
195 if (guestInfo->additionsVersion < VMMDEV_VERSION)
196 pDrv->pVMMDev->getParent()->onAdditionsOutdated();
197 }
198 else
199 {
200 /*
201 * The guest additions was disabled because of a reset
202 * or driver unload.
203 */
204 guest->setAdditionsVersion (Bstr(), guestInfo->osType);
205 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
206 }
207}
208
209/**
210 * Update the guest additions capabilities.
211 * This is called when the guest additions capabilities change. The new capabilities
212 * are given and the connector should update its internal state.
213 *
214 * @param pInterface Pointer to this interface.
215 * @param newCapabilities New capabilities.
216 * @thread The emulation thread.
217 */
218DECLCALLBACK(void) vmmdevUpdateGuestCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
219{
220 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
221
222 /* store that information in IGuest */
223 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
224 Assert(guest);
225 if (!guest)
226 return;
227
228 guest->setSupportsSeamless(BOOL (newCapabilities & VMMDEV_GUEST_SUPPORTS_SEAMLESS));
229 guest->setSupportsGraphics(BOOL (newCapabilities & VMMDEV_GUEST_SUPPORTS_GRAPHICS));
230
231 /*
232 * Tell the console interface about the event
233 * so that it can notify its consumers.
234 */
235 pDrv->pVMMDev->getParent()->onAdditionsStateChange();
236
237}
238
239/**
240 * Update the mouse capabilities.
241 * This is called when the mouse capabilities change. The new capabilities
242 * are given and the connector should update its internal state.
243 *
244 * @param pInterface Pointer to this interface.
245 * @param newCapabilities New capabilities.
246 * @thread The emulation thread.
247 */
248DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
249{
250 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
251 /*
252 * Tell the console interface about the event
253 * so that it can notify its consumers.
254 */
255 pDrv->pVMMDev->getParent()->onMouseCapabilityChange(BOOL (newCapabilities & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE),
256 BOOL (newCapabilities & VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR));
257}
258
259
260/**
261 * Update the pointer shape or visibility.
262 *
263 * This is called when the mouse pointer shape changes or pointer is hidden/displaying.
264 * The new shape is passed as a caller allocated buffer that will be freed after returning.
265 *
266 * @param pInterface Pointer to this interface.
267 * @param fVisible Whether the pointer is visible or not.
268 * @param fAlpha Alpha channel information is present.
269 * @param xHot Horizontal coordinate of the pointer hot spot.
270 * @param yHot Vertical coordinate of the pointer hot spot.
271 * @param width Pointer width in pixels.
272 * @param height Pointer height in pixels.
273 * @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
274 * @thread The emulation thread.
275 */
276DECLCALLBACK(void) vmmdevUpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
277 uint32_t xHot, uint32_t yHot,
278 uint32_t width, uint32_t height,
279 void *pShape)
280{
281 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
282
283 /* tell the console about it */
284 pDrv->pVMMDev->getParent()->onMousePointerShapeChange(fVisible, fAlpha,
285 xHot, yHot, width, height, pShape);
286}
287
288DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
289{
290 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
291
292 Display *display = pDrv->pVMMDev->getParent()->getDisplay();
293
294 if (display)
295 {
296 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
297 return display->VideoAccelEnable (fEnable, pVbvaMemory);
298 }
299
300 return VERR_NOT_SUPPORTED;
301}
302DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
303{
304 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
305
306 Display *display = pDrv->pVMMDev->getParent()->getDisplay();
307
308 if (display)
309 {
310 LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
311 display->VideoAccelFlush ();
312 }
313}
314
315DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t width, uint32_t height,
316 uint32_t bpp, bool *fSupported)
317{
318 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
319
320 if (!fSupported)
321 return VERR_INVALID_PARAMETER;
322 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
323 if (framebuffer)
324 framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
325 else
326 *fSupported = true;
327 return VINF_SUCCESS;
328}
329
330DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
331{
332 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
333
334 if (!heightReduction)
335 return VERR_INVALID_PARAMETER;
336 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
337 if (framebuffer)
338 framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
339 else
340 *heightReduction = 0;
341 return VINF_SUCCESS;
342}
343
344DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
345{
346 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
347
348 int rc = pDrv->pVMMDev->SetCredentialsJudgementResult (u32Flags);
349
350 return rc;
351}
352
353DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
354{
355 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
356
357 if (!cRect)
358 return VERR_INVALID_PARAMETER;
359 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
360 if (framebuffer)
361 {
362 framebuffer->SetVisibleRegion((BYTE *)pRect, cRect);
363#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
364 {
365 BOOL is3denabled;
366
367 pDrv->pVMMDev->getParent()->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
368
369 if (is3denabled)
370 {
371 VBOXHGCMSVCPARM parms[2];
372
373 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
374 parms[0].u.pointer.addr = pRect;
375 parms[0].u.pointer.size = 0; /* We don't actually care. */
376 parms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
377 parms[1].u.uint32 = cRect;
378
379 int rc = pDrv->pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VISIBLE_REGION, 2, &parms[0]);
380 return rc;
381 }
382 }
383#endif
384 }
385
386 return VINF_SUCCESS;
387}
388
389DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
390{
391 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
392
393 IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
394 if (framebuffer)
395 {
396 ULONG cRect = 0;
397 framebuffer->GetVisibleRegion((BYTE *)pRect, cRect, &cRect);
398
399 *pcRect = cRect;
400 }
401
402 return VINF_SUCCESS;
403}
404
405/**
406 * Request the statistics interval
407 *
408 * @returns VBox status code.
409 * @param pInterface Pointer to this interface.
410 * @param pulInterval Pointer to interval in seconds
411 * @thread The emulation thread.
412 */
413DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
414{
415 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
416 ULONG val = 0;
417
418 if (!pulInterval)
419 return VERR_INVALID_POINTER;
420
421 /* store that information in IGuest */
422 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
423 Assert(guest);
424 if (!guest)
425 return VERR_INVALID_PARAMETER; /** @todo wrong error */
426
427 guest->COMGETTER(StatisticsUpdateInterval)(&val);
428 *pulInterval = val;
429 return VINF_SUCCESS;
430}
431
432/**
433 * Report new guest statistics
434 *
435 * @returns VBox status code.
436 * @param pInterface Pointer to this interface.
437 * @param pGuestStats Guest statistics
438 * @thread The emulation thread.
439 */
440DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
441{
442 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
443
444 Assert(pGuestStats);
445 if (!pGuestStats)
446 return VERR_INVALID_POINTER;
447
448 /* store that information in IGuest */
449 Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
450 Assert(guest);
451 if (!guest)
452 return VERR_INVALID_PARAMETER; /** @todo wrong error */
453
454 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
455 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_CPULoad_Idle, pGuestStats->u32CpuLoad_Idle);
456
457 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
458 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_CPULoad_Kernel, pGuestStats->u32CpuLoad_Kernel);
459
460 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
461 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_CPULoad_User, pGuestStats->u32CpuLoad_User);
462
463 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
464 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_Threads, pGuestStats->u32Threads);
465
466 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
467 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_Processes, pGuestStats->u32Processes);
468
469 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
470 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_Handles, pGuestStats->u32Handles);
471
472 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
473 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemoryLoad, pGuestStats->u32MemoryLoad);
474
475 /* Note that reported values are in pages; upper layers expect them in megabytes */
476 Assert(pGuestStats->u32PageSize == 4096);
477 if (pGuestStats->u32PageSize != 4096)
478 pGuestStats->u32PageSize = 4096;
479
480 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
481 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_PhysMemTotal, (pGuestStats->u32PhysMemTotal + (_1M/pGuestStats->u32PageSize)-1) / (_1M/pGuestStats->u32PageSize));
482
483 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
484 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_PhysMemAvailable, pGuestStats->u32PhysMemAvail / (_1M/pGuestStats->u32PageSize));
485
486 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
487 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_PhysMemBalloon, pGuestStats->u32PhysMemBalloon / (_1M/pGuestStats->u32PageSize));
488
489 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
490 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemCommitTotal, pGuestStats->u32MemCommitTotal / (_1M/pGuestStats->u32PageSize));
491
492 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
493 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemKernelTotal, pGuestStats->u32MemKernelTotal / (_1M/pGuestStats->u32PageSize));
494
495 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
496 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemKernelPaged, pGuestStats->u32MemKernelPaged / (_1M/pGuestStats->u32PageSize));
497
498 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
499 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemKernelNonpaged, pGuestStats->u32MemKernelNonPaged / (_1M/pGuestStats->u32PageSize));
500
501 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
502 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_MemSystemCache, pGuestStats->u32MemSystemCache / (_1M/pGuestStats->u32PageSize));
503
504 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
505 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_PageFileSize, pGuestStats->u32PageFileSize / (_1M/pGuestStats->u32PageSize));
506
507 /* increase sample number */
508 ULONG sample;
509
510 int rc = guest->GetStatistic(0, GuestStatisticType_SampleNumber, &sample);
511 if (SUCCEEDED(rc))
512 guest->SetStatistic(pGuestStats->u32CpuId, GuestStatisticType_SampleNumber, sample+1);
513
514 return VINF_SUCCESS;
515}
516
517#ifdef VBOX_WITH_HGCM
518
519/* HGCM connector interface */
520
521static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
522{
523 LogSunlover(("Enter\n"));
524
525 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
526
527 if ( !pServiceLocation
528 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
529 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
530 {
531 return VERR_INVALID_PARAMETER;
532 }
533
534 if (!pDrv->pVMMDev->hgcmIsActive ())
535 {
536 return VERR_INVALID_STATE;
537 }
538
539 return HGCMGuestConnect (pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
540}
541
542static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
543{
544 LogSunlover(("Enter\n"));
545
546 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
547
548 if (!pDrv->pVMMDev->hgcmIsActive ())
549 {
550 return VERR_INVALID_STATE;
551 }
552
553 return HGCMGuestDisconnect (pDrv->pHGCMPort, pCmd, u32ClientID);
554}
555
556static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
557 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
558{
559 LogSunlover(("Enter\n"));
560
561 PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
562
563 if (!pDrv->pVMMDev->hgcmIsActive ())
564 {
565 return VERR_INVALID_STATE;
566 }
567
568 return HGCMGuestCall (pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
569}
570
571/**
572 * Execute state save operation.
573 *
574 * @returns VBox status code.
575 * @param pDrvIns Driver instance of the driver which registered the data unit.
576 * @param pSSM SSM operation handle.
577 */
578static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
579{
580 LogSunlover(("Enter\n"));
581 return HGCMHostSaveState (pSSM);
582}
583
584
585/**
586 * Execute state load operation.
587 *
588 * @returns VBox status code.
589 * @param pDrvIns Driver instance of the driver which registered the data unit.
590 * @param pSSM SSM operation handle.
591 * @param uVersion Data layout version.
592 * @param uPass The data pass.
593 */
594static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
595{
596 LogFlowFunc(("Enter\n"));
597
598 if (uVersion != HGCM_SSM_VERSION)
599 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
600 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
601
602 return HGCMHostLoadState (pSSM);
603}
604
605int VMMDev::hgcmLoadService (const char *pszServiceLibrary, const char *pszServiceName)
606{
607 if (!hgcmIsActive ())
608 {
609 return VERR_INVALID_STATE;
610 }
611 return HGCMHostLoad (pszServiceLibrary, pszServiceName);
612}
613
614int VMMDev::hgcmHostCall (const char *pszServiceName, uint32_t u32Function,
615 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
616{
617 if (!hgcmIsActive ())
618 {
619 return VERR_INVALID_STATE;
620 }
621 return HGCMHostCall (pszServiceName, u32Function, cParms, paParms);
622}
623
624void VMMDev::hgcmShutdown (void)
625{
626 ASMAtomicWriteBool(&m_fHGCMActive, false);
627 HGCMHostShutdown ();
628}
629
630#endif /* HGCM */
631
632
633/**
634 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
635 */
636DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
637{
638 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
639 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
640
641 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
642 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
643#ifdef VBOX_WITH_HGCM
644 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
645#endif
646 return NULL;
647}
648
649/**
650 * Destruct a VMMDev driver instance.
651 *
652 * @returns VBox status.
653 * @param pDrvIns The driver instance data.
654 */
655DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
656{
657 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
658 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
659#ifdef VBOX_WITH_HGCM
660 /* HGCM is shut down on the VMMDev destructor. */
661#endif /* VBOX_WITH_HGCM */
662 if (pData->pVMMDev)
663 {
664 pData->pVMMDev->mpDrv = NULL;
665 }
666}
667
668/**
669 * Reset notification.
670 *
671 * @returns VBox status.
672 * @param pDrvIns The driver instance data.
673 */
674DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
675{
676 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
677#ifdef VBOX_WITH_HGCM
678 HGCMHostReset ();
679#endif /* VBOX_WITH_HGCM */
680}
681
682/**
683 * Construct a VMMDev driver instance.
684 *
685 * @copydoc FNPDMDRVCONSTRUCT
686 */
687DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
688{
689 PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
690 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
691
692 /*
693 * Validate configuration.
694 */
695 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
696 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
697 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
698 ("Configuration error: Not possible to attach anything to this driver!\n"),
699 VERR_PDM_DRVINS_NO_ATTACH);
700
701 /*
702 * IBase.
703 */
704 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
705
706 pData->Connector.pfnUpdateGuestVersion = vmmdevUpdateGuestVersion;
707 pData->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
708 pData->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
709 pData->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
710 pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
711 pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
712 pData->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
713 pData->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
714 pData->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
715 pData->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
716 pData->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
717 pData->Connector.pfnReportStatistics = vmmdevReportStatistics;
718 pData->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
719
720#ifdef VBOX_WITH_HGCM
721 pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
722 pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
723 pData->HGCMConnector.pfnCall = iface_hgcmCall;
724#endif
725
726 /*
727 * Get the IVMMDevPort interface of the above driver/device.
728 */
729 pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
730 AssertMsgReturn(pData->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
731
732#ifdef VBOX_WITH_HGCM
733 pData->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
734 AssertMsgReturn(pData->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
735#endif
736
737 /*
738 * Get the Console object pointer and update the mpDrv member.
739 */
740 void *pv;
741 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
742 if (RT_FAILURE(rc))
743 {
744 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
745 return rc;
746 }
747
748 pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
749 pData->pVMMDev->mpDrv = pData;
750
751#ifdef VBOX_WITH_HGCM
752 rc = pData->pVMMDev->hgcmLoadService (VBOXSHAREDFOLDERS_DLL,
753 "VBoxSharedFolders");
754 pData->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
755 if (RT_SUCCESS(rc))
756 {
757 PPDMLED pLed;
758 PPDMILEDPORTS pLedPort;
759
760 LogRel(("Shared Folders service loaded.\n"));
761 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
762 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
763 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
764 if (RT_SUCCESS(rc) && pLed)
765 {
766 VBOXHGCMSVCPARM parm;
767
768 parm.type = VBOX_HGCM_SVC_PARM_PTR;
769 parm.u.pointer.addr = pLed;
770 parm.u.pointer.size = sizeof(*pLed);
771
772 rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
773 }
774 else
775 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
776 }
777 else
778 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
779
780 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
781 NULL, NULL, NULL,
782 NULL, iface_hgcmSave, NULL,
783 NULL, iface_hgcmLoad, NULL);
784 if (RT_FAILURE(rc))
785 return rc;
786
787#endif /* VBOX_WITH_HGCM */
788
789 return VINF_SUCCESS;
790}
791
792
793/**
794 * VMMDevice driver registration record.
795 */
796const PDMDRVREG VMMDev::DrvReg =
797{
798 /* u32Version */
799 PDM_DRVREG_VERSION,
800 /* szName */
801 "HGCM",
802 /* szRCMod */
803 "",
804 /* szR0Mod */
805 "",
806 /* pszDescription */
807 "Main VMMDev driver (Main as in the API).",
808 /* fFlags */
809 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
810 /* fClass. */
811 PDM_DRVREG_CLASS_VMMDEV,
812 /* cMaxInstances */
813 ~0,
814 /* cbInstance */
815 sizeof(DRVMAINVMMDEV),
816 /* pfnConstruct */
817 VMMDev::drvConstruct,
818 /* pfnDestruct */
819 VMMDev::drvDestruct,
820 /* pfnRelocate */
821 NULL,
822 /* pfnIOCtl */
823 NULL,
824 /* pfnPowerOn */
825 NULL,
826 /* pfnReset */
827 VMMDev::drvReset,
828 /* pfnSuspend */
829 NULL,
830 /* pfnResume */
831 NULL,
832 /* pfnAttach */
833 NULL,
834 /* pfnDetach */
835 NULL,
836 /* pfnPowerOff */
837 NULL,
838 /* pfnSoftReset */
839 NULL,
840 /* u32EndVersion */
841 PDM_DRVREG_VERSION
842};
843/* 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