VirtualBox

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

Last change on this file since 20818 was 18637, checked in by vboxsync, 16 years ago

crOpenGL: add seamless mode clip regions to opengl ones

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