VirtualBox

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

Last change on this file since 23194 was 22793, checked in by vboxsync, 15 years ago

SSM,*: Renamed phase to pass (uPhase/SSM_PHASE_FINAL) and wrote the remainder of the live snapshot / migration SSM code.

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