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