VirtualBox

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

Last change on this file since 8768 was 8690, checked in by vboxsync, 17 years ago

UpdateGuestVersion fixes.

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