VirtualBox

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

Last change on this file since 8170 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

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