1 | /* $Id: VMMDevInterface.cpp 28051 2010-04-07 14:09:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Driver Interface to VMM device.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 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 | #include "MouseImpl.h"
|
---|
27 |
|
---|
28 | #include "Logging.h"
|
---|
29 |
|
---|
30 | #include <VBox/pdmdrv.h>
|
---|
31 | #include <VBox/VMMDev.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 | */
|
---|
61 | typedef 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 | //
|
---|
91 | VMMDev::VMMDev(Console *console)
|
---|
92 | : mpDrv(NULL),
|
---|
93 | mParent(console)
|
---|
94 | {
|
---|
95 | int rc = RTSemEventCreate(&mCredentialsEvent);
|
---|
96 | AssertRC(rc);
|
---|
97 | #ifdef VBOX_WITH_HGCM
|
---|
98 | rc = HGCMHostInit ();
|
---|
99 | AssertRC(rc);
|
---|
100 | m_fHGCMActive = true;
|
---|
101 | #endif /* VBOX_WITH_HGCM */
|
---|
102 | mu32CredentialsFlags = 0;
|
---|
103 | }
|
---|
104 |
|
---|
105 | VMMDev::~VMMDev()
|
---|
106 | {
|
---|
107 | #ifdef VBOX_WITH_HGCM
|
---|
108 | if (hgcmIsActive())
|
---|
109 | {
|
---|
110 | ASMAtomicWriteBool(&m_fHGCMActive, false);
|
---|
111 | HGCMHostShutdown();
|
---|
112 | }
|
---|
113 | #endif /* VBOX_WITH_HGCM */
|
---|
114 | RTSemEventDestroy (mCredentialsEvent);
|
---|
115 | if (mpDrv)
|
---|
116 | mpDrv->pVMMDev = NULL;
|
---|
117 | mpDrv = NULL;
|
---|
118 | }
|
---|
119 |
|
---|
120 | PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
|
---|
121 | {
|
---|
122 | Assert(mpDrv);
|
---|
123 | return mpDrv->pUpPort;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 | //
|
---|
129 | // public methods
|
---|
130 | //
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Wait on event semaphore for guest credential judgement result.
|
---|
134 | */
|
---|
135 | int VMMDev::WaitCredentialsJudgement (uint32_t u32Timeout, uint32_t *pu32CredentialsFlags)
|
---|
136 | {
|
---|
137 | if (u32Timeout == 0)
|
---|
138 | {
|
---|
139 | u32Timeout = 5000;
|
---|
140 | }
|
---|
141 |
|
---|
142 | int rc = RTSemEventWait (mCredentialsEvent, u32Timeout);
|
---|
143 |
|
---|
144 | if (RT_SUCCESS(rc))
|
---|
145 | {
|
---|
146 | *pu32CredentialsFlags = mu32CredentialsFlags;
|
---|
147 | }
|
---|
148 |
|
---|
149 | return rc;
|
---|
150 | }
|
---|
151 |
|
---|
152 | int VMMDev::SetCredentialsJudgementResult (uint32_t u32Flags)
|
---|
153 | {
|
---|
154 | mu32CredentialsFlags = u32Flags;
|
---|
155 |
|
---|
156 | int rc = RTSemEventSignal (mCredentialsEvent);
|
---|
157 | AssertRC(rc);
|
---|
158 |
|
---|
159 | return rc;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * Report guest OS version.
|
---|
165 | * Called whenever the Additions issue a guest version report request or the VM is reset.
|
---|
166 | *
|
---|
167 | * @param pInterface Pointer to this interface.
|
---|
168 | * @param guestInfo Pointer to guest information structure
|
---|
169 | * @thread The emulation thread.
|
---|
170 | */
|
---|
171 | DECLCALLBACK(void) vmmdevUpdateGuestVersion(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestInfo *guestInfo)
|
---|
172 | {
|
---|
173 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
174 |
|
---|
175 | Assert(guestInfo);
|
---|
176 | if (!guestInfo)
|
---|
177 | return;
|
---|
178 |
|
---|
179 | /* store that information in IGuest */
|
---|
180 | Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
|
---|
181 | Assert(guest);
|
---|
182 | if (!guest)
|
---|
183 | return;
|
---|
184 |
|
---|
185 | if (guestInfo->additionsVersion != 0)
|
---|
186 | {
|
---|
187 | char version[20];
|
---|
188 | RTStrPrintf(version, sizeof(version), "%d", guestInfo->additionsVersion);
|
---|
189 | guest->setAdditionsVersion(Bstr(version), guestInfo->osType);
|
---|
190 |
|
---|
191 | /*
|
---|
192 | * Tell the console interface about the event
|
---|
193 | * so that it can notify its consumers.
|
---|
194 | */
|
---|
195 | pDrv->pVMMDev->getParent()->onAdditionsStateChange();
|
---|
196 |
|
---|
197 | if (guestInfo->additionsVersion < VMMDEV_VERSION)
|
---|
198 | pDrv->pVMMDev->getParent()->onAdditionsOutdated();
|
---|
199 | }
|
---|
200 | else
|
---|
201 | {
|
---|
202 | /*
|
---|
203 | * The guest additions was disabled because of a reset
|
---|
204 | * or driver unload.
|
---|
205 | */
|
---|
206 | guest->setAdditionsVersion (Bstr(), guestInfo->osType);
|
---|
207 | pDrv->pVMMDev->getParent()->onAdditionsStateChange();
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Update the guest additions capabilities.
|
---|
213 | * This is called when the guest additions 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 | */
|
---|
220 | DECLCALLBACK(void) vmmdevUpdateGuestCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
|
---|
221 | {
|
---|
222 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
223 |
|
---|
224 | /* store that information in IGuest */
|
---|
225 | Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
|
---|
226 | Assert(guest);
|
---|
227 | if (!guest)
|
---|
228 | return;
|
---|
229 |
|
---|
230 | guest->setSupportsSeamless(BOOL (newCapabilities & VMMDEV_GUEST_SUPPORTS_SEAMLESS));
|
---|
231 | guest->setSupportsGraphics(BOOL (newCapabilities & VMMDEV_GUEST_SUPPORTS_GRAPHICS));
|
---|
232 |
|
---|
233 | /*
|
---|
234 | * Tell the console interface about the event
|
---|
235 | * so that it can notify its consumers.
|
---|
236 | */
|
---|
237 | pDrv->pVMMDev->getParent()->onAdditionsStateChange();
|
---|
238 |
|
---|
239 | }
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * Update the mouse capabilities.
|
---|
243 | * This is called when the mouse capabilities change. The new capabilities
|
---|
244 | * are given and the connector should update its internal state.
|
---|
245 | *
|
---|
246 | * @param pInterface Pointer to this interface.
|
---|
247 | * @param newCapabilities New capabilities.
|
---|
248 | * @thread The emulation thread.
|
---|
249 | */
|
---|
250 | DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
|
---|
251 | {
|
---|
252 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
253 | /*
|
---|
254 | * Tell the console interface about the event
|
---|
255 | * so that it can notify its consumers.
|
---|
256 | */
|
---|
257 | Mouse *pMouse = pDrv->pVMMDev->getParent()->getMouse();
|
---|
258 | if (pMouse) /** @todo and if not? Can that actually happen? */
|
---|
259 | {
|
---|
260 | pMouse->onVMMDevCanAbsChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE));
|
---|
261 | pMouse->onVMMDevNeedsHostChange(!!(newCapabilities & VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR));
|
---|
262 | }
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Update the pointer shape or visibility.
|
---|
268 | *
|
---|
269 | * This is called when the mouse pointer shape changes or pointer is hidden/displaying.
|
---|
270 | * The new shape is passed as a caller allocated buffer that will be freed after returning.
|
---|
271 | *
|
---|
272 | * @param pInterface Pointer to this interface.
|
---|
273 | * @param fVisible Whether the pointer is visible or not.
|
---|
274 | * @param fAlpha Alpha channel information is present.
|
---|
275 | * @param xHot Horizontal coordinate of the pointer hot spot.
|
---|
276 | * @param yHot Vertical coordinate of the pointer hot spot.
|
---|
277 | * @param width Pointer width in pixels.
|
---|
278 | * @param height Pointer height in pixels.
|
---|
279 | * @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
|
---|
280 | * @thread The emulation thread.
|
---|
281 | */
|
---|
282 | DECLCALLBACK(void) vmmdevUpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
|
---|
283 | uint32_t xHot, uint32_t yHot,
|
---|
284 | uint32_t width, uint32_t height,
|
---|
285 | void *pShape)
|
---|
286 | {
|
---|
287 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
288 |
|
---|
289 | /* tell the console about it */
|
---|
290 | pDrv->pVMMDev->getParent()->onMousePointerShapeChange(fVisible, fAlpha,
|
---|
291 | xHot, yHot, width, height, pShape);
|
---|
292 | }
|
---|
293 |
|
---|
294 | DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
|
---|
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_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
|
---|
303 | return display->VideoAccelEnable (fEnable, pVbvaMemory);
|
---|
304 | }
|
---|
305 |
|
---|
306 | return VERR_NOT_SUPPORTED;
|
---|
307 | }
|
---|
308 | DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
|
---|
309 | {
|
---|
310 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
311 |
|
---|
312 | Display *display = pDrv->pVMMDev->getParent()->getDisplay();
|
---|
313 |
|
---|
314 | if (display)
|
---|
315 | {
|
---|
316 | LogSunlover(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
|
---|
317 | display->VideoAccelFlush ();
|
---|
318 | }
|
---|
319 | }
|
---|
320 |
|
---|
321 | DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t width, uint32_t height,
|
---|
322 | uint32_t bpp, bool *fSupported)
|
---|
323 | {
|
---|
324 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
325 |
|
---|
326 | if (!fSupported)
|
---|
327 | return VERR_INVALID_PARAMETER;
|
---|
328 | IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
|
---|
329 | if (framebuffer)
|
---|
330 | framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
|
---|
331 | else
|
---|
332 | *fSupported = true;
|
---|
333 | return VINF_SUCCESS;
|
---|
334 | }
|
---|
335 |
|
---|
336 | DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
|
---|
337 | {
|
---|
338 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
339 |
|
---|
340 | if (!heightReduction)
|
---|
341 | return VERR_INVALID_PARAMETER;
|
---|
342 | IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
|
---|
343 | if (framebuffer)
|
---|
344 | framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
|
---|
345 | else
|
---|
346 | *heightReduction = 0;
|
---|
347 | return VINF_SUCCESS;
|
---|
348 | }
|
---|
349 |
|
---|
350 | DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
|
---|
351 | {
|
---|
352 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
353 |
|
---|
354 | int rc = pDrv->pVMMDev->SetCredentialsJudgementResult (u32Flags);
|
---|
355 |
|
---|
356 | return rc;
|
---|
357 | }
|
---|
358 |
|
---|
359 | DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
|
---|
360 | {
|
---|
361 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
362 |
|
---|
363 | if (!cRect)
|
---|
364 | return VERR_INVALID_PARAMETER;
|
---|
365 | IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
|
---|
366 | if (framebuffer)
|
---|
367 | {
|
---|
368 | framebuffer->SetVisibleRegion((BYTE *)pRect, cRect);
|
---|
369 | #if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
|
---|
370 | {
|
---|
371 | BOOL is3denabled;
|
---|
372 |
|
---|
373 | pDrv->pVMMDev->getParent()->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
|
---|
374 |
|
---|
375 | if (is3denabled)
|
---|
376 | {
|
---|
377 | VBOXHGCMSVCPARM parms[2];
|
---|
378 |
|
---|
379 | parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
380 | parms[0].u.pointer.addr = pRect;
|
---|
381 | parms[0].u.pointer.size = 0; /* We don't actually care. */
|
---|
382 | parms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
383 | parms[1].u.uint32 = cRect;
|
---|
384 |
|
---|
385 | int rc = pDrv->pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VISIBLE_REGION, 2, &parms[0]);
|
---|
386 | return rc;
|
---|
387 | }
|
---|
388 | }
|
---|
389 | #endif
|
---|
390 | }
|
---|
391 |
|
---|
392 | return VINF_SUCCESS;
|
---|
393 | }
|
---|
394 |
|
---|
395 | DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRect, PRTRECT pRect)
|
---|
396 | {
|
---|
397 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
398 |
|
---|
399 | IFramebuffer *framebuffer = pDrv->pVMMDev->getParent()->getDisplay()->getFramebuffer();
|
---|
400 | if (framebuffer)
|
---|
401 | {
|
---|
402 | ULONG cRect = 0;
|
---|
403 | framebuffer->GetVisibleRegion((BYTE *)pRect, cRect, &cRect);
|
---|
404 |
|
---|
405 | *pcRect = cRect;
|
---|
406 | }
|
---|
407 |
|
---|
408 | return VINF_SUCCESS;
|
---|
409 | }
|
---|
410 |
|
---|
411 | /**
|
---|
412 | * Request the statistics interval
|
---|
413 | *
|
---|
414 | * @returns VBox status code.
|
---|
415 | * @param pInterface Pointer to this interface.
|
---|
416 | * @param pulInterval Pointer to interval in seconds
|
---|
417 | * @thread The emulation thread.
|
---|
418 | */
|
---|
419 | DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
|
---|
420 | {
|
---|
421 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
422 | ULONG val = 0;
|
---|
423 |
|
---|
424 | if (!pulInterval)
|
---|
425 | return VERR_INVALID_POINTER;
|
---|
426 |
|
---|
427 | /* store that information in IGuest */
|
---|
428 | Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
|
---|
429 | Assert(guest);
|
---|
430 | if (!guest)
|
---|
431 | return VERR_INVALID_PARAMETER; /** @todo wrong error */
|
---|
432 |
|
---|
433 | guest->COMGETTER(StatisticsUpdateInterval)(&val);
|
---|
434 | *pulInterval = val;
|
---|
435 | return VINF_SUCCESS;
|
---|
436 | }
|
---|
437 |
|
---|
438 | /**
|
---|
439 | * Query the current balloon size
|
---|
440 | *
|
---|
441 | * @returns VBox status code.
|
---|
442 | * @param pInterface Pointer to this interface.
|
---|
443 | * @param pcbBalloon Balloon size
|
---|
444 | * @thread The emulation thread.
|
---|
445 | */
|
---|
446 | DECLCALLBACK(int) vmmdevQueryBalloonSize(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcbBalloon)
|
---|
447 | {
|
---|
448 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
449 | ULONG val = 0;
|
---|
450 |
|
---|
451 | if (!pcbBalloon)
|
---|
452 | return VERR_INVALID_POINTER;
|
---|
453 |
|
---|
454 | /* store that information in IGuest */
|
---|
455 | Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
|
---|
456 | Assert(guest);
|
---|
457 | if (!guest)
|
---|
458 | return VERR_INVALID_PARAMETER; /** @todo wrong error */
|
---|
459 |
|
---|
460 | guest->COMGETTER(MemoryBalloonSize)(&val);
|
---|
461 | *pcbBalloon = val;
|
---|
462 | return VINF_SUCCESS;
|
---|
463 | }
|
---|
464 |
|
---|
465 | /**
|
---|
466 | * Report new guest statistics
|
---|
467 | *
|
---|
468 | * @returns VBox status code.
|
---|
469 | * @param pInterface Pointer to this interface.
|
---|
470 | * @param pGuestStats Guest statistics
|
---|
471 | * @thread The emulation thread.
|
---|
472 | */
|
---|
473 | DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
|
---|
474 | {
|
---|
475 | PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
476 |
|
---|
477 | Assert(pGuestStats);
|
---|
478 | if (!pGuestStats)
|
---|
479 | return VERR_INVALID_POINTER;
|
---|
480 |
|
---|
481 | /* store that information in IGuest */
|
---|
482 | Guest* guest = pDrv->pVMMDev->getParent()->getGuest();
|
---|
483 | Assert(guest);
|
---|
484 | if (!guest)
|
---|
485 | return VERR_INVALID_PARAMETER; /** @todo wrong error */
|
---|
486 |
|
---|
487 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
|
---|
488 | guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
|
---|
489 |
|
---|
490 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
|
---|
491 | guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
|
---|
492 |
|
---|
493 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
|
---|
494 | guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
|
---|
495 |
|
---|
496 |
|
---|
497 | /** @todo r=bird: Convert from 4KB to 1KB units?
|
---|
498 | * CollectorGuestHAL::getGuestMemLoad says it returns KB units to
|
---|
499 | * preCollect(). I might be wrong ofc, this is convoluted code... */
|
---|
500 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
|
---|
501 | guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
|
---|
502 |
|
---|
503 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
|
---|
504 | guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
|
---|
505 |
|
---|
506 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
|
---|
507 | guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
|
---|
508 |
|
---|
509 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
|
---|
510 | guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
|
---|
511 |
|
---|
512 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
|
---|
513 | guest->SetStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
|
---|
514 |
|
---|
515 | return VINF_SUCCESS;
|
---|
516 | }
|
---|
517 |
|
---|
518 | #ifdef VBOX_WITH_HGCM
|
---|
519 |
|
---|
520 | /* HGCM connector interface */
|
---|
521 |
|
---|
522 | static DECLCALLBACK(int) iface_hgcmConnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, PHGCMSERVICELOCATION pServiceLocation, uint32_t *pu32ClientID)
|
---|
523 | {
|
---|
524 | LogSunlover(("Enter\n"));
|
---|
525 |
|
---|
526 | PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
527 |
|
---|
528 | if ( !pServiceLocation
|
---|
529 | || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
|
---|
530 | && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
|
---|
531 | {
|
---|
532 | return VERR_INVALID_PARAMETER;
|
---|
533 | }
|
---|
534 |
|
---|
535 | if (!pDrv->pVMMDev->hgcmIsActive ())
|
---|
536 | {
|
---|
537 | return VERR_INVALID_STATE;
|
---|
538 | }
|
---|
539 |
|
---|
540 | return HGCMGuestConnect (pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
|
---|
541 | }
|
---|
542 |
|
---|
543 | static DECLCALLBACK(int) iface_hgcmDisconnect (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
|
---|
544 | {
|
---|
545 | LogSunlover(("Enter\n"));
|
---|
546 |
|
---|
547 | PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
548 |
|
---|
549 | if (!pDrv->pVMMDev->hgcmIsActive ())
|
---|
550 | {
|
---|
551 | return VERR_INVALID_STATE;
|
---|
552 | }
|
---|
553 |
|
---|
554 | return HGCMGuestDisconnect (pDrv->pHGCMPort, pCmd, u32ClientID);
|
---|
555 | }
|
---|
556 |
|
---|
557 | static DECLCALLBACK(int) iface_hgcmCall (PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID, uint32_t u32Function,
|
---|
558 | uint32_t cParms, PVBOXHGCMSVCPARM paParms)
|
---|
559 | {
|
---|
560 | LogSunlover(("Enter\n"));
|
---|
561 |
|
---|
562 | PDRVMAINVMMDEV pDrv = PDMIHGCMCONNECTOR_2_MAINVMMDEV(pInterface);
|
---|
563 |
|
---|
564 | if (!pDrv->pVMMDev->hgcmIsActive ())
|
---|
565 | {
|
---|
566 | return VERR_INVALID_STATE;
|
---|
567 | }
|
---|
568 |
|
---|
569 | return HGCMGuestCall (pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms);
|
---|
570 | }
|
---|
571 |
|
---|
572 | /**
|
---|
573 | * Execute state save operation.
|
---|
574 | *
|
---|
575 | * @returns VBox status code.
|
---|
576 | * @param pDrvIns Driver instance of the driver which registered the data unit.
|
---|
577 | * @param pSSM SSM operation handle.
|
---|
578 | */
|
---|
579 | static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
|
---|
580 | {
|
---|
581 | LogSunlover(("Enter\n"));
|
---|
582 | return HGCMHostSaveState (pSSM);
|
---|
583 | }
|
---|
584 |
|
---|
585 |
|
---|
586 | /**
|
---|
587 | * Execute state load operation.
|
---|
588 | *
|
---|
589 | * @returns VBox status code.
|
---|
590 | * @param pDrvIns Driver instance of the driver which registered the data unit.
|
---|
591 | * @param pSSM SSM operation handle.
|
---|
592 | * @param uVersion Data layout version.
|
---|
593 | * @param uPass The data pass.
|
---|
594 | */
|
---|
595 | static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
|
---|
596 | {
|
---|
597 | LogFlowFunc(("Enter\n"));
|
---|
598 |
|
---|
599 | if (uVersion != HGCM_SSM_VERSION)
|
---|
600 | return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
|
---|
601 | Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
|
---|
602 |
|
---|
603 | return HGCMHostLoadState (pSSM);
|
---|
604 | }
|
---|
605 |
|
---|
606 | int VMMDev::hgcmLoadService (const char *pszServiceLibrary, const char *pszServiceName)
|
---|
607 | {
|
---|
608 | if (!hgcmIsActive ())
|
---|
609 | {
|
---|
610 | return VERR_INVALID_STATE;
|
---|
611 | }
|
---|
612 | return HGCMHostLoad (pszServiceLibrary, pszServiceName);
|
---|
613 | }
|
---|
614 |
|
---|
615 | int VMMDev::hgcmHostCall (const char *pszServiceName, uint32_t u32Function,
|
---|
616 | uint32_t cParms, PVBOXHGCMSVCPARM paParms)
|
---|
617 | {
|
---|
618 | if (!hgcmIsActive ())
|
---|
619 | {
|
---|
620 | return VERR_INVALID_STATE;
|
---|
621 | }
|
---|
622 | return HGCMHostCall (pszServiceName, u32Function, cParms, paParms);
|
---|
623 | }
|
---|
624 |
|
---|
625 | void VMMDev::hgcmShutdown (void)
|
---|
626 | {
|
---|
627 | ASMAtomicWriteBool(&m_fHGCMActive, false);
|
---|
628 | HGCMHostShutdown ();
|
---|
629 | }
|
---|
630 |
|
---|
631 | #endif /* HGCM */
|
---|
632 |
|
---|
633 |
|
---|
634 | /**
|
---|
635 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
636 | */
|
---|
637 | DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
638 | {
|
---|
639 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
640 | PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
|
---|
641 |
|
---|
642 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
643 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
|
---|
644 | #ifdef VBOX_WITH_HGCM
|
---|
645 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
|
---|
646 | #endif
|
---|
647 | return NULL;
|
---|
648 | }
|
---|
649 |
|
---|
650 | /**
|
---|
651 | * Destruct a VMMDev driver instance.
|
---|
652 | *
|
---|
653 | * @returns VBox status.
|
---|
654 | * @param pDrvIns The driver instance data.
|
---|
655 | */
|
---|
656 | DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
657 | {
|
---|
658 | PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
|
---|
659 | LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
660 | #ifdef VBOX_WITH_HGCM
|
---|
661 | /* HGCM is shut down on the VMMDev destructor. */
|
---|
662 | #endif /* VBOX_WITH_HGCM */
|
---|
663 | if (pData->pVMMDev)
|
---|
664 | {
|
---|
665 | pData->pVMMDev->mpDrv = NULL;
|
---|
666 | }
|
---|
667 | }
|
---|
668 |
|
---|
669 | /**
|
---|
670 | * Reset notification.
|
---|
671 | *
|
---|
672 | * @returns VBox status.
|
---|
673 | * @param pDrvIns The driver instance data.
|
---|
674 | */
|
---|
675 | DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
|
---|
676 | {
|
---|
677 | LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
|
---|
678 | #ifdef VBOX_WITH_HGCM
|
---|
679 | HGCMHostReset ();
|
---|
680 | #endif /* VBOX_WITH_HGCM */
|
---|
681 | }
|
---|
682 |
|
---|
683 | /**
|
---|
684 | * Construct a VMMDev driver instance.
|
---|
685 | *
|
---|
686 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
687 | */
|
---|
688 | DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
|
---|
689 | {
|
---|
690 | PDRVMAINVMMDEV pData = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
|
---|
691 | LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
692 |
|
---|
693 | /*
|
---|
694 | * Validate configuration.
|
---|
695 | */
|
---|
696 | if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
|
---|
697 | return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
|
---|
698 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
699 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
700 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
701 |
|
---|
702 | /*
|
---|
703 | * IBase.
|
---|
704 | */
|
---|
705 | pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
|
---|
706 |
|
---|
707 | pData->Connector.pfnUpdateGuestVersion = vmmdevUpdateGuestVersion;
|
---|
708 | pData->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
|
---|
709 | pData->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
|
---|
710 | pData->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
|
---|
711 | pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
|
---|
712 | pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
|
---|
713 | pData->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
|
---|
714 | pData->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
|
---|
715 | pData->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
|
---|
716 | pData->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
|
---|
717 | pData->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
|
---|
718 | pData->Connector.pfnReportStatistics = vmmdevReportStatistics;
|
---|
719 | pData->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
|
---|
720 | pData->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
|
---|
721 |
|
---|
722 | #ifdef VBOX_WITH_HGCM
|
---|
723 | pData->HGCMConnector.pfnConnect = iface_hgcmConnect;
|
---|
724 | pData->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
|
---|
725 | pData->HGCMConnector.pfnCall = iface_hgcmCall;
|
---|
726 | #endif
|
---|
727 |
|
---|
728 | /*
|
---|
729 | * Get the IVMMDevPort interface of the above driver/device.
|
---|
730 | */
|
---|
731 | pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
|
---|
732 | AssertMsgReturn(pData->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
|
---|
733 |
|
---|
734 | #ifdef VBOX_WITH_HGCM
|
---|
735 | pData->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
|
---|
736 | AssertMsgReturn(pData->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
|
---|
737 | #endif
|
---|
738 |
|
---|
739 | /*
|
---|
740 | * Get the Console object pointer and update the mpDrv member.
|
---|
741 | */
|
---|
742 | void *pv;
|
---|
743 | int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
|
---|
744 | if (RT_FAILURE(rc))
|
---|
745 | {
|
---|
746 | AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
|
---|
747 | return rc;
|
---|
748 | }
|
---|
749 |
|
---|
750 | pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
|
---|
751 | pData->pVMMDev->mpDrv = pData;
|
---|
752 |
|
---|
753 | #ifdef VBOX_WITH_HGCM
|
---|
754 | rc = pData->pVMMDev->hgcmLoadService (VBOXSHAREDFOLDERS_DLL,
|
---|
755 | "VBoxSharedFolders");
|
---|
756 | pData->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
|
---|
757 | if (RT_SUCCESS(rc))
|
---|
758 | {
|
---|
759 | PPDMLED pLed;
|
---|
760 | PPDMILEDPORTS pLedPort;
|
---|
761 |
|
---|
762 | LogRel(("Shared Folders service loaded.\n"));
|
---|
763 | pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
|
---|
764 | AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
|
---|
765 | rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
|
---|
766 | if (RT_SUCCESS(rc) && pLed)
|
---|
767 | {
|
---|
768 | VBOXHGCMSVCPARM parm;
|
---|
769 |
|
---|
770 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
771 | parm.u.pointer.addr = pLed;
|
---|
772 | parm.u.pointer.size = sizeof(*pLed);
|
---|
773 |
|
---|
774 | rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
|
---|
775 | }
|
---|
776 | else
|
---|
777 | AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
|
---|
778 | }
|
---|
779 | else
|
---|
780 | LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
|
---|
781 |
|
---|
782 | rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SSM_VERSION, 4096 /* bad guess */,
|
---|
783 | NULL, NULL, NULL,
|
---|
784 | NULL, iface_hgcmSave, NULL,
|
---|
785 | NULL, iface_hgcmLoad, NULL);
|
---|
786 | if (RT_FAILURE(rc))
|
---|
787 | return rc;
|
---|
788 |
|
---|
789 | #endif /* VBOX_WITH_HGCM */
|
---|
790 |
|
---|
791 | return VINF_SUCCESS;
|
---|
792 | }
|
---|
793 |
|
---|
794 |
|
---|
795 | /**
|
---|
796 | * VMMDevice driver registration record.
|
---|
797 | */
|
---|
798 | const PDMDRVREG VMMDev::DrvReg =
|
---|
799 | {
|
---|
800 | /* u32Version */
|
---|
801 | PDM_DRVREG_VERSION,
|
---|
802 | /* szName */
|
---|
803 | "HGCM",
|
---|
804 | /* szRCMod */
|
---|
805 | "",
|
---|
806 | /* szR0Mod */
|
---|
807 | "",
|
---|
808 | /* pszDescription */
|
---|
809 | "Main VMMDev driver (Main as in the API).",
|
---|
810 | /* fFlags */
|
---|
811 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
812 | /* fClass. */
|
---|
813 | PDM_DRVREG_CLASS_VMMDEV,
|
---|
814 | /* cMaxInstances */
|
---|
815 | ~0,
|
---|
816 | /* cbInstance */
|
---|
817 | sizeof(DRVMAINVMMDEV),
|
---|
818 | /* pfnConstruct */
|
---|
819 | VMMDev::drvConstruct,
|
---|
820 | /* pfnDestruct */
|
---|
821 | VMMDev::drvDestruct,
|
---|
822 | /* pfnRelocate */
|
---|
823 | NULL,
|
---|
824 | /* pfnIOCtl */
|
---|
825 | NULL,
|
---|
826 | /* pfnPowerOn */
|
---|
827 | NULL,
|
---|
828 | /* pfnReset */
|
---|
829 | VMMDev::drvReset,
|
---|
830 | /* pfnSuspend */
|
---|
831 | NULL,
|
---|
832 | /* pfnResume */
|
---|
833 | NULL,
|
---|
834 | /* pfnAttach */
|
---|
835 | NULL,
|
---|
836 | /* pfnDetach */
|
---|
837 | NULL,
|
---|
838 | /* pfnPowerOff */
|
---|
839 | NULL,
|
---|
840 | /* pfnSoftReset */
|
---|
841 | NULL,
|
---|
842 | /* u32EndVersion */
|
---|
843 | PDM_DRVREG_VERSION
|
---|
844 | };
|
---|
845 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|