VirtualBox

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

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

Devices/VMMDev, Frontends/VBoxBFE, Main: add a guest request to report the maximum resolution currently supported by the additions - host side

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