VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/VMMDevInterface.cpp@ 2426

Last change on this file since 2426 was 1550, checked in by vboxsync, 18 years ago

don't include VBoxGuest.h if we don't need to because it drags in ostypes.h and that conflicts with a core darwin type.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/** @file
2 *
3 * VBox frontends: Basic Frontend (BFE):
4 * Implementation of VMMDev: driver interface to VMM device
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#define LOG_GROUP LOG_GROUP_MAIN
24
25#ifdef VBOXBFE_WITHOUT_COM
26# include "COMDefs.h"
27#else
28# include <VBox/com/defs.h>
29#endif
30#include <VBox/pdm.h>
31#include <VBox/VBoxDev.h>
32#include <VBox/VBoxGuest.h>
33#include <VBox/cfgm.h>
34#include <VBox/err.h>
35#include <iprt/assert.h>
36#include <VBox/log.h>
37#include <iprt/asm.h>
38
39#include "VBoxBFE.h"
40#include "VMMDevInterface.h"
41#include "MouseImpl.h"
42#include "DisplayImpl.h"
43#include "ConsoleImpl.h"
44
45#ifdef __L4__
46#include <l4/util/util.h> /* for l4_sleep */
47#endif
48/**
49 * VMMDev driver instance data.
50 */
51typedef struct DRVMAINVMMDEV
52{
53 /** Pointer to the VMMDev object. */
54 VMMDev *pVMMDev;
55 /** Pointer to the driver instance structure. */
56 PPDMDRVINS pDrvIns;
57 /** Pointer to the VMMDev port interface of the driver/device above us. */
58 PPDMIVMMDEVPORT pUpPort;
59 /** Our VMM device connector interface. */
60 PDMIVMMDEVCONNECTOR Connector;
61} DRVMAINVMMDEV, *PDRVMAINVMMDEV;
62
63/** Converts PDMIVMMDEVCONNECTOR pointer to a DRVMAINVMMDEV pointer. */
64#define PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface) ( (PDRVMAINVMMDEV) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINVMMDEV, Connector)) )
65
66
67PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
68{
69 Assert(mpDrv);
70 return mpDrv->pUpPort;
71}
72
73int VMMDev::SetMouseCapabilities(uint32_t mouseCaps)
74{
75 return mpDrv->pUpPort->pfnSetMouseCapabilities(mpDrv->pUpPort, mouseCaps);
76}
77
78
79int VMMDev::SetAbsoluteMouse(uint32_t mouseXAbs, uint32_t mouseYAbs)
80{
81 return mpDrv->pUpPort->pfnSetAbsoluteMouse(mpDrv->pUpPort, mouseXAbs, mouseYAbs);
82}
83
84void VMMDev::QueryMouseCapabilities(uint32_t *pMouseCaps)
85{
86
87 Assert(mpDrv);
88 mpDrv->pUpPort->pfnQueryMouseCapabilities(mpDrv->pUpPort, pMouseCaps);
89}
90
91
92/**
93 * Report guest OS version.
94 * Called whenever the Additions issue a guest version report request.
95 *
96 * @param pInterface Pointer to this interface.
97 * @param guestInfo Pointer to guest information structure
98 * @thread The emulation thread.
99 */
100DECLCALLBACK(void) VMMDev::UpdateGuestVersion(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestInfo *guestInfo)
101{
102 return;
103}
104
105/**
106 * Update the mouse capabilities.
107 * This is called when the mouse capabilities change. The new capabilities
108 * are given and the connector should update its internal state.
109 *
110 * @param pInterface Pointer to this interface.
111 * @param newCapabilities New capabilities.
112 * @thread The emulation thread.
113 */
114DECLCALLBACK(void) VMMDev::UpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
115{
116 /*
117 * Tell the console interface about the event so that it can notify its consumers.
118 */
119
120 if (gMouse)
121 {
122 gMouse->setAbsoluteCoordinates(!!(newCapabilities & VMMDEV_MOUSEGUESTWANTSABS));
123 gMouse->setNeedsHostCursor(!!(newCapabilities & VMMDEV_MOUSEGUESTNEEDSHOSTCUR));
124 }
125 if (gConsole)
126 {
127 gConsole->resetCursor();
128 }
129}
130
131
132/**
133 * Update the pointer shape or visibility.
134 *
135 * This is called when the mouse pointer shape changes or pointer is hidden/displaying.
136 * The new shape is passed as a caller allocated buffer that will be freed after returning.
137 *
138 * @param pInterface Pointer to this interface.
139 * @param fVisible Whether the pointer is visible or not.
140 * @param fAlpha Alpha channel information is present.
141 * @param xHot Horizontal coordinate of the pointer hot spot.
142 * @param yHot Vertical coordinate of the pointer hot spot.
143 * @param width Pointer width in pixels.
144 * @param height Pointer height in pixels.
145 * @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
146 * @thread The emulation thread.
147 */
148DECLCALLBACK(void) VMMDev::UpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
149 uint32_t xHot, uint32_t yHot,
150 uint32_t width, uint32_t height,
151 void *pShape)
152{
153 if (gConsole)
154 gConsole->onMousePointerShapeChange(fVisible, fAlpha, xHot,
155 yHot, width, height, pShape);
156}
157
158DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
159{
160 LogFlow(("VMMDev::VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
161 if (gDisplay)
162 gDisplay->VideoAccelEnable (fEnable, pVbvaMemory);
163 return VINF_SUCCESS;
164}
165
166DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
167{
168 if (gDisplay)
169 gDisplay->VideoAccelFlush ();
170}
171
172DECLCALLBACK(int) VMMDev::VideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t width, uint32_t height,
173 uint32_t bpp, bool *fSupported)
174{
175 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
176 (void)pDrv;
177
178 if (!fSupported)
179 return VERR_INVALID_PARAMETER;
180 *fSupported = true;
181 return VINF_SUCCESS;
182}
183
184DECLCALLBACK(int) VMMDev::GetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
185{
186 PDRVMAINVMMDEV pDrv = PDMIVMMDEVCONNECTOR_2_MAINVMMDEV(pInterface);
187 (void)pDrv;
188
189 if (!heightReduction)
190 return VERR_INVALID_PARAMETER;
191 /* XXX hard-coded */
192 *heightReduction = 18;
193 return VINF_SUCCESS;
194}
195
196/**
197 * Queries an interface to the driver.
198 *
199 * @returns Pointer to interface.
200 * @returns NULL if the interface was not supported by the driver.
201 * @param pInterface Pointer to this interface structure.
202 * @param enmInterface The requested interface identification.
203 */
204DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
205{
206 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
207 PDRVMAINVMMDEV pDrv = PDMINS2DATA(pDrvIns, PDRVMAINVMMDEV);
208 switch (enmInterface)
209 {
210 case PDMINTERFACE_BASE:
211 return &pDrvIns->IBase;
212 case PDMINTERFACE_VMMDEV_CONNECTOR:
213 return &pDrv->Connector;
214 default:
215 return NULL;
216 }
217}
218
219
220/**
221 * Destruct a VMMDev driver instance.
222 *
223 * @returns VBox status.
224 * @param pDrvIns The driver instance data.
225 */
226DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
227{
228 /*PDRVMAINVMMDEV pData = PDMINS2DATA(pDrvIns, PDRVMAINVMMDEV); - unused variables makes gcc bitch. */
229}
230
231
232/**
233 * Construct a VMMDev driver instance.
234 *
235 * @returns VBox status.
236 * @param pDrvIns The driver instance data.
237 * If the registration structure is needed, pDrvIns->pDrvReg points to it.
238 * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
239 * of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
240 * iInstance it's expected to be used a bit in this function.
241 */
242DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
243{
244 PDRVMAINVMMDEV pData = PDMINS2DATA(pDrvIns, PDRVMAINVMMDEV);
245 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
246
247 /*
248 * Validate configuration.
249 */
250 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
251 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
252
253 PPDMIBASE pBaseIgnore;
254 int rc = pDrvIns->pDrvHlp->pfnAttach(pDrvIns, &pBaseIgnore);
255 if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
256 {
257 AssertMsgFailed(("Configuration error: Not possible to attach anything to this driver!\n"));
258 return VERR_PDM_DRVINS_NO_ATTACH;
259 }
260
261 /*
262 * IBase.
263 */
264 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
265
266 pData->Connector.pfnUpdateGuestVersion = VMMDev::UpdateGuestVersion;
267 pData->Connector.pfnUpdateMouseCapabilities = VMMDev::UpdateMouseCapabilities;
268 pData->Connector.pfnUpdatePointerShape = VMMDev::UpdatePointerShape;
269 pData->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
270 pData->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
271 pData->Connector.pfnVideoModeSupported = VMMDev::VideoModeSupported;
272 pData->Connector.pfnGetHeightReduction = VMMDev::GetHeightReduction;
273
274 /*
275 * Get the IVMMDevPort interface of the above driver/device.
276 */
277 pData->pUpPort = (PPDMIVMMDEVPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_VMMDEV_PORT);
278 if (!pData->pUpPort)
279 {
280 AssertMsgFailed(("Configuration error: No VMMDev port interface above!\n"));
281 return VERR_PDM_MISSING_INTERFACE_ABOVE;
282 }
283
284 /*
285 * Get the VMMDev object pointer and update the mpDrv member.
286 */
287 void *pv;
288 rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
289 if (VBOX_FAILURE(rc))
290 {
291 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Vrc\n", rc));
292 return rc;
293 }
294
295 pData->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
296 pData->pVMMDev->mpDrv = pData;
297 return VINF_SUCCESS;
298}
299
300
301/**
302 * VMMDevice driver registration record.
303 */
304const PDMDRVREG VMMDev::DrvReg =
305{
306 /* u32Version */
307 PDM_DRVREG_VERSION,
308 /* szDriverName */
309 "MainVMMDev",
310 /* pszDescription */
311 "Main VMMDev driver (Main as in the API).",
312 /* fFlags */
313 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
314 /* fClass. */
315 PDM_DRVREG_CLASS_VMMDEV,
316 /* cMaxInstances */
317 ~0,
318 /* cbInstance */
319 sizeof(DRVMAINVMMDEV),
320 /* pfnConstruct */
321 VMMDev::drvConstruct,
322 /* pfnDestruct */
323 VMMDev::drvDestruct,
324 /* pfnIOCtl */
325 NULL,
326 /* pfnPowerOn */
327 NULL,
328 /* pfnReset */
329 NULL,
330 /* pfnSuspend */
331 NULL,
332 /* pfnResume */
333 NULL,
334 /* pfnDetach */
335 NULL
336};
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