VirtualBox

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

Last change on this file since 6276 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

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