1 | /* $Id: vboxvideo.c 65381 2017-01-20 09:23:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Linux Additions X11 graphics driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 Oracle Corporation
|
---|
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 | *
|
---|
18 | * This code is based on the X.Org VESA driver with the following copyrights:
|
---|
19 | *
|
---|
20 | * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
|
---|
21 | * Copyright 2008 Red Hat, Inc.
|
---|
22 | * Copyright 2012 Red Hat, Inc.
|
---|
23 | *
|
---|
24 | * and the following permission notice (not all original sourse files include
|
---|
25 | * the last paragraph):
|
---|
26 | *
|
---|
27 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
28 | * copy of this software and associated documentation files (the "Software"),
|
---|
29 | * to deal in the Software without restriction, including without limitation
|
---|
30 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
31 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
32 | * Software is furnished to do so, subject to the following conditions:
|
---|
33 | *
|
---|
34 | * The above copyright notice and this permission notice shall be included in
|
---|
35 | * all copies or substantial portions of the Software.
|
---|
36 | *
|
---|
37 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
38 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
39 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
40 | * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
41 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
---|
42 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
---|
43 | * SOFTWARE.
|
---|
44 | *
|
---|
45 | * Except as contained in this notice, the name of Conectiva Linux shall
|
---|
46 | * not be used in advertising or otherwise to promote the sale, use or other
|
---|
47 | * dealings in this Software without prior written authorization from
|
---|
48 | * Conectiva Linux.
|
---|
49 | *
|
---|
50 | * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
|
---|
51 | * David Dawes <dawes@xfree86.org>
|
---|
52 | * Adam Jackson <ajax@redhat.com>
|
---|
53 | * Dave Airlie <airlied@redhat.com>
|
---|
54 | */
|
---|
55 |
|
---|
56 | #include "vboxvideo.h"
|
---|
57 | #include <VBox/VBoxGuest.h>
|
---|
58 | #include <VBox/VBoxGuestLib.h>
|
---|
59 | #include <VBoxVideoVBE.h>
|
---|
60 | #include "version-generated.h"
|
---|
61 | #include "product-generated.h"
|
---|
62 | #include "revision-generated.h"
|
---|
63 |
|
---|
64 | /* Basic definitions and functions needed by all drivers. */
|
---|
65 | #include "xf86.h"
|
---|
66 | /* For video memory mapping. */
|
---|
67 | #include "xf86_OSproc.h"
|
---|
68 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
|
---|
69 | /* PCI resources. */
|
---|
70 | # include "xf86Resources.h"
|
---|
71 | #endif
|
---|
72 | /* Generic server linear frame-buffer APIs. */
|
---|
73 | #include "fb.h"
|
---|
74 | /* Colormap and visual handling. */
|
---|
75 | #include "micmap.h"
|
---|
76 | #include "xf86cmap.h"
|
---|
77 | /* ShadowFB support */
|
---|
78 | #include "shadowfb.h"
|
---|
79 | /* VGA hardware functions for setting and restoring text mode */
|
---|
80 | #include "vgaHW.h"
|
---|
81 | #ifdef VBOXVIDEO_13
|
---|
82 | /* X.org 1.3+ mode setting */
|
---|
83 | # define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
|
---|
84 | # include "xf86Crtc.h"
|
---|
85 | # include "xf86Modes.h"
|
---|
86 | /* For xf86RandR12GetOriginalVirtualSize(). */
|
---|
87 | # include "xf86RandR12.h"
|
---|
88 | #endif
|
---|
89 | /* For setting the root window property. */
|
---|
90 | #include "property.h"
|
---|
91 | #include "X11/Xatom.h"
|
---|
92 |
|
---|
93 | #ifdef XORG_7X
|
---|
94 | # include <stdlib.h>
|
---|
95 | # include <string.h>
|
---|
96 | # include <fcntl.h>
|
---|
97 | # include <unistd.h>
|
---|
98 | #endif
|
---|
99 |
|
---|
100 | /* Mandatory functions */
|
---|
101 |
|
---|
102 | static const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid);
|
---|
103 | static void VBOXIdentify(int flags);
|
---|
104 | #ifndef PCIACCESS
|
---|
105 | static Bool VBOXProbe(DriverPtr drv, int flags);
|
---|
106 | #else
|
---|
107 | static Bool VBOXPciProbe(DriverPtr drv, int entity_num,
|
---|
108 | struct pci_device *dev, intptr_t match_data);
|
---|
109 | #endif
|
---|
110 | static Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags);
|
---|
111 | static Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv);
|
---|
112 | static Bool VBOXEnterVT(ScrnInfoPtr pScrn);
|
---|
113 | static void VBOXLeaveVT(ScrnInfoPtr pScrn);
|
---|
114 | static Bool VBOXCloseScreen(ScreenPtr pScreen);
|
---|
115 | #ifndef VBOXVIDEO_13
|
---|
116 | static Bool VBOXSaveScreen(ScreenPtr pScreen, int mode);
|
---|
117 | #endif
|
---|
118 | static Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode);
|
---|
119 | static void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y);
|
---|
120 | static void VBOXFreeScreen(ScrnInfoPtr pScrn);
|
---|
121 | #ifndef VBOXVIDEO_13
|
---|
122 | static void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode, int flags);
|
---|
123 | #endif
|
---|
124 |
|
---|
125 | /* locally used functions */
|
---|
126 | static Bool VBOXMapVidMem(ScrnInfoPtr pScrn);
|
---|
127 | static void VBOXUnmapVidMem(ScrnInfoPtr pScrn);
|
---|
128 | static void VBOXSaveMode(ScrnInfoPtr pScrn);
|
---|
129 | static void VBOXRestoreMode(ScrnInfoPtr pScrn);
|
---|
130 | static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, bool fScreenInitTime);
|
---|
131 |
|
---|
132 | #ifndef XF86_SCRN_INTERFACE
|
---|
133 | # define xf86ScreenToScrn(pScreen) xf86Screens[(pScreen)->myNum]
|
---|
134 | # define xf86ScrnToScreen(pScrn) screenInfo.screens[(pScrn)->scrnIndex]
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | static inline void VBOXSetRec(ScrnInfoPtr pScrn)
|
---|
138 | {
|
---|
139 | if (!pScrn->driverPrivate)
|
---|
140 | {
|
---|
141 | VBOXPtr pVBox = (VBOXPtr)xnfcalloc(sizeof(VBOXRec), 1);
|
---|
142 | pScrn->driverPrivate = pVBox;
|
---|
143 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
144 | pVBox->fdACPIDevices = -1;
|
---|
145 | #endif
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | enum GenericTypes
|
---|
150 | {
|
---|
151 | CHIP_VBOX_GENERIC
|
---|
152 | };
|
---|
153 |
|
---|
154 | #ifdef PCIACCESS
|
---|
155 | static const struct pci_id_match vbox_device_match[] = {
|
---|
156 | {
|
---|
157 | VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY,
|
---|
158 | 0, 0, 0
|
---|
159 | },
|
---|
160 |
|
---|
161 | { 0, 0, 0 },
|
---|
162 | };
|
---|
163 | #endif
|
---|
164 |
|
---|
165 | /* Supported chipsets */
|
---|
166 | static SymTabRec VBOXChipsets[] =
|
---|
167 | {
|
---|
168 | {VBOX_DEVICEID, "vbox"},
|
---|
169 | {-1, NULL}
|
---|
170 | };
|
---|
171 |
|
---|
172 | static PciChipsets VBOXPCIchipsets[] = {
|
---|
173 | { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA },
|
---|
174 | { -1, -1, RES_UNDEFINED },
|
---|
175 | };
|
---|
176 |
|
---|
177 | /*
|
---|
178 | * This contains the functions needed by the server after loading the
|
---|
179 | * driver module. It must be supplied, and gets added the driver list by
|
---|
180 | * the Module Setup function in the dynamic case. In the static case a
|
---|
181 | * reference to this is compiled in, and this requires that the name of
|
---|
182 | * this DriverRec be an upper-case version of the driver name.
|
---|
183 | */
|
---|
184 |
|
---|
185 | #ifdef XORG_7X
|
---|
186 | _X_EXPORT
|
---|
187 | #endif
|
---|
188 | DriverRec VBOXVIDEO = {
|
---|
189 | VBOX_VERSION,
|
---|
190 | VBOX_DRIVER_NAME,
|
---|
191 | VBOXIdentify,
|
---|
192 | #ifdef PCIACCESS
|
---|
193 | NULL,
|
---|
194 | #else
|
---|
195 | VBOXProbe,
|
---|
196 | #endif
|
---|
197 | VBOXAvailableOptions,
|
---|
198 | NULL,
|
---|
199 | 0,
|
---|
200 | #ifdef XORG_7X
|
---|
201 | NULL,
|
---|
202 | #endif
|
---|
203 | #ifdef PCIACCESS
|
---|
204 | vbox_device_match,
|
---|
205 | VBOXPciProbe
|
---|
206 | #endif
|
---|
207 | };
|
---|
208 |
|
---|
209 | /* No options for now */
|
---|
210 | static const OptionInfoRec VBOXOptions[] = {
|
---|
211 | { -1, NULL, OPTV_NONE, {0}, FALSE }
|
---|
212 | };
|
---|
213 |
|
---|
214 | #ifndef XORG_7X
|
---|
215 | /*
|
---|
216 | * List of symbols from other modules that this module references. This
|
---|
217 | * list is used to tell the loader that it is OK for symbols here to be
|
---|
218 | * unresolved providing that it hasn't been told that they haven't been
|
---|
219 | * told that they are essential via a call to xf86LoaderReqSymbols() or
|
---|
220 | * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
|
---|
221 | * unresolved symbols that are not required.
|
---|
222 | */
|
---|
223 | static const char *fbSymbols[] = {
|
---|
224 | "fbPictureInit",
|
---|
225 | "fbScreenInit",
|
---|
226 | NULL
|
---|
227 | };
|
---|
228 |
|
---|
229 | static const char *shadowfbSymbols[] = {
|
---|
230 | "ShadowFBInit2",
|
---|
231 | NULL
|
---|
232 | };
|
---|
233 |
|
---|
234 | static const char *ramdacSymbols[] = {
|
---|
235 | "xf86DestroyCursorInfoRec",
|
---|
236 | "xf86InitCursor",
|
---|
237 | "xf86CreateCursorInfoRec",
|
---|
238 | NULL
|
---|
239 | };
|
---|
240 |
|
---|
241 | static const char *vgahwSymbols[] = {
|
---|
242 | "vgaHWFreeHWRec",
|
---|
243 | "vgaHWGetHWRec",
|
---|
244 | "vgaHWGetIOBase",
|
---|
245 | "vgaHWGetIndex",
|
---|
246 | "vgaHWRestore",
|
---|
247 | "vgaHWSave",
|
---|
248 | "vgaHWSetStdFuncs",
|
---|
249 | NULL
|
---|
250 | };
|
---|
251 | #endif /* !XORG_7X */
|
---|
252 |
|
---|
253 | /** Resize the virtual framebuffer. */
|
---|
254 | static Bool adjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height)
|
---|
255 | {
|
---|
256 | ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
|
---|
257 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
258 | int adjustedWidth = pScrn->bitsPerPixel == 16 ? (width + 1) & ~1 : width;
|
---|
259 | int cbLine = adjustedWidth * pScrn->bitsPerPixel / 8;
|
---|
260 | PixmapPtr pPixmap;
|
---|
261 |
|
---|
262 | TRACE_LOG("width=%d, height=%d\n", width, height);
|
---|
263 | VBVXASSERT(width >= 0 && height >= 0, ("Invalid negative width (%d) or height (%d)\n", width, height));
|
---|
264 | if (pScreen == NULL) /* Not yet initialised. */
|
---|
265 | return TRUE;
|
---|
266 | pPixmap = pScreen->GetScreenPixmap(pScreen);
|
---|
267 | VBVXASSERT(pPixmap != NULL, ("Failed to get the screen pixmap.\n"));
|
---|
268 | TRACE_LOG("pPixmap=%p adjustedWidth=%d height=%d pScrn->depth=%d pScrn->bitsPerPixel=%d cbLine=%d pVBox->base=%p pPixmap->drawable.width=%d pPixmap->drawable.height=%d\n",
|
---|
269 | pPixmap, adjustedWidth, height, pScrn->depth, pScrn->bitsPerPixel, cbLine, pVBox->base, pPixmap->drawable.width,
|
---|
270 | pPixmap->drawable.height);
|
---|
271 | if ( adjustedWidth != pPixmap->drawable.width
|
---|
272 | || height != pPixmap->drawable.height)
|
---|
273 | {
|
---|
274 | if ( adjustedWidth > VBOX_VIDEO_MAX_VIRTUAL || height > VBOX_VIDEO_MAX_VIRTUAL
|
---|
275 | || (unsigned)cbLine * (unsigned)height >= pVBox->cbFBMax)
|
---|
276 | {
|
---|
277 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
278 | "Virtual framebuffer %dx%d too large. For information, video memory: %u Kb.\n",
|
---|
279 | adjustedWidth, height, (unsigned) pVBox->cbFBMax / 1024);
|
---|
280 | return FALSE;
|
---|
281 | }
|
---|
282 | if (pScrn->vtSema)
|
---|
283 | vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8),
|
---|
284 | ((size_t)adjustedWidth) * height * (pScrn->bitsPerPixel / 8));
|
---|
285 | pScreen->ModifyPixmapHeader(pPixmap, adjustedWidth, height, pScrn->depth, pScrn->bitsPerPixel, cbLine, pVBox->base);
|
---|
286 | }
|
---|
287 | pScrn->displayWidth = pScrn->virtualX = adjustedWidth;
|
---|
288 | pScrn->virtualY = height;
|
---|
289 | return TRUE;
|
---|
290 | }
|
---|
291 |
|
---|
292 | #ifndef VBOXVIDEO_13
|
---|
293 | /** Set a video mode to the hardware, RandR 1.1 version.
|
---|
294 | *
|
---|
295 | * Since we no longer do virtual frame buffers, adjust the screen pixmap
|
---|
296 | * dimensions to match. The "override" parameters are for when we received a
|
---|
297 | * mode hint while switched to a virtual terminal. In this case VBoxClient will
|
---|
298 | * have told us about the mode, but not yet been able to do a mode switch using
|
---|
299 | * RandR. We solve this by setting the requested mode to the host but keeping
|
---|
300 | * the virtual frame-
|
---|
301 | * buffer matching what the X server expects. */
|
---|
302 | static void setModeRandR11(ScrnInfoPtr pScrn, DisplayModePtr pMode, bool fScreenInitTime, bool fEnterVTTime,
|
---|
303 | int cXOverRide, int cYOverRide)
|
---|
304 | {
|
---|
305 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
306 | struct vbvxFrameBuffer frameBuffer = { 0, 0, pMode->HDisplay, pMode->VDisplay, pScrn->bitsPerPixel};
|
---|
307 | int cXPhysical = cXOverRide > 0 ? min(cXOverRide, pMode->HDisplay) : pMode->HDisplay;
|
---|
308 | int cYPhysical = cYOverRide > 0 ? min(cYOverRide, pMode->VDisplay) : pMode->VDisplay;
|
---|
309 |
|
---|
310 | pVBox->pScreens[0].aScreenLocation.cx = pMode->HDisplay;
|
---|
311 | pVBox->pScreens[0].aScreenLocation.cy = pMode->VDisplay;
|
---|
312 | if (fScreenInitTime)
|
---|
313 | {
|
---|
314 | /* The screen structure is not fully set up yet, so do not touch it. */
|
---|
315 | pScrn->displayWidth = pScrn->virtualX = pMode->HDisplay;
|
---|
316 | pScrn->virtualY = pMode->VDisplay;
|
---|
317 | }
|
---|
318 | else
|
---|
319 | {
|
---|
320 | xf86ScrnToScreen(pScrn)->width = pMode->HDisplay;
|
---|
321 | xf86ScrnToScreen(pScrn)->height = pMode->VDisplay;
|
---|
322 | /* This prevents a crash in CentOS 3. I was unable to debug it to
|
---|
323 | * satisfaction, partly due to the lack of symbols. My guess is that
|
---|
324 | * pScrn->ModifyPixmapHeader() expects certain things to be set up when
|
---|
325 | * it sees pScrn->vtSema set to true which are not quite done at this
|
---|
326 | * point of the VT switch. */
|
---|
327 | if (fEnterVTTime)
|
---|
328 | pScrn->vtSema = FALSE;
|
---|
329 | adjustScreenPixmap(pScrn, pMode->HDisplay, pMode->VDisplay);
|
---|
330 | if (fEnterVTTime)
|
---|
331 | pScrn->vtSema = TRUE;
|
---|
332 | }
|
---|
333 | if (pMode->HDisplay != 0 && pMode->VDisplay != 0 && pScrn->vtSema)
|
---|
334 | vbvxSetMode(pScrn, 0, cXPhysical, cYPhysical, 0, 0, true, true, &frameBuffer);
|
---|
335 | pScrn->currentMode = pMode;
|
---|
336 | }
|
---|
337 | #endif
|
---|
338 |
|
---|
339 | #ifdef VBOXVIDEO_13
|
---|
340 | /* X.org 1.3+ mode-setting support ******************************************/
|
---|
341 |
|
---|
342 | /** Set a video mode to the hardware, RandR 1.2 version. If this is the first
|
---|
343 | * screen, re-set the current mode for all others (the offset for the first
|
---|
344 | * screen is always treated as zero by the hardware, so all other screens need
|
---|
345 | * to be changed to compensate for any changes!). The mode to set is taken
|
---|
346 | * from the X.Org Crtc structure. */
|
---|
347 | static void setModeRandR12(ScrnInfoPtr pScrn, unsigned cScreen)
|
---|
348 | {
|
---|
349 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
350 | unsigned i;
|
---|
351 | struct vbvxFrameBuffer frameBuffer = { pVBox->pScreens[0].paCrtcs->x, pVBox->pScreens[0].paCrtcs->y, pScrn->virtualX,
|
---|
352 | pScrn->virtualY, pScrn->bitsPerPixel };
|
---|
353 | unsigned cFirst = cScreen;
|
---|
354 | unsigned cLast = cScreen != 0 ? cScreen + 1 : pVBox->cScreens;
|
---|
355 | int originalX, originalY;
|
---|
356 |
|
---|
357 | /* Check that this code cannot trigger the resizing bug in X.Org Server 1.3.
|
---|
358 | * See the work-around in ScreenInit. */
|
---|
359 | xf86RandR12GetOriginalVirtualSize(pScrn, &originalX, &originalY);
|
---|
360 | VBVXASSERT(originalX == VBOX_VIDEO_MAX_VIRTUAL && originalY == VBOX_VIDEO_MAX_VIRTUAL, ("OriginalSize=%dx%d",
|
---|
361 | originalX, originalY));
|
---|
362 | for (i = cFirst; i < cLast; ++i)
|
---|
363 | if (pVBox->pScreens[i].paCrtcs->mode.HDisplay != 0 && pVBox->pScreens[i].paCrtcs->mode.VDisplay != 0 && pScrn->vtSema)
|
---|
364 | vbvxSetMode(pScrn, i, pVBox->pScreens[i].paCrtcs->mode.HDisplay, pVBox->pScreens[i].paCrtcs->mode.VDisplay,
|
---|
365 | pVBox->pScreens[i].paCrtcs->x, pVBox->pScreens[i].paCrtcs->y, pVBox->pScreens[i].fPowerOn,
|
---|
366 | pVBox->pScreens[i].paOutputs->status == XF86OutputStatusConnected, &frameBuffer);
|
---|
367 | }
|
---|
368 |
|
---|
369 | /** Wrapper around setModeRandR12() to avoid exposing non-obvious semantics.
|
---|
370 | */
|
---|
371 | static void setAllModesRandR12(ScrnInfoPtr pScrn)
|
---|
372 | {
|
---|
373 | setModeRandR12(pScrn, 0);
|
---|
374 | }
|
---|
375 |
|
---|
376 | /* For descriptions of these functions and structures, see
|
---|
377 | hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
|
---|
378 | X.Org source tree. */
|
---|
379 |
|
---|
380 | static Bool vbox_config_resize(ScrnInfoPtr pScrn, int cw, int ch)
|
---|
381 | {
|
---|
382 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
383 | Bool rc;
|
---|
384 | unsigned i;
|
---|
385 |
|
---|
386 | TRACE_LOG("width=%d, height=%d\n", cw, ch);
|
---|
387 | rc = adjustScreenPixmap(pScrn, cw, ch);
|
---|
388 | /* Power-on all screens (the server expects this) and set the new pitch to them. */
|
---|
389 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
390 | pVBox->pScreens[i].fPowerOn = true;
|
---|
391 | setAllModesRandR12(pScrn);
|
---|
392 | vbvxSetSolarisMouseRange(cw, ch);
|
---|
393 | return rc;
|
---|
394 | }
|
---|
395 |
|
---|
396 | static const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
|
---|
397 | vbox_config_resize
|
---|
398 | };
|
---|
399 |
|
---|
400 | static void
|
---|
401 | vbox_crtc_dpms(xf86CrtcPtr crtc, int mode)
|
---|
402 | {
|
---|
403 | ScrnInfoPtr pScrn = crtc->scrn;
|
---|
404 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
405 | unsigned cDisplay = (uintptr_t)crtc->driver_private;
|
---|
406 |
|
---|
407 | TRACE_LOG("mode=%d\n", mode);
|
---|
408 | pVBox->pScreens[cDisplay].fPowerOn = (mode != DPMSModeOff);
|
---|
409 | setModeRandR12(pScrn, cDisplay);
|
---|
410 | }
|
---|
411 |
|
---|
412 | static Bool
|
---|
413 | vbox_crtc_lock (xf86CrtcPtr crtc)
|
---|
414 | { (void) crtc; return FALSE; }
|
---|
415 |
|
---|
416 |
|
---|
417 | /* We use this function to check whether the X server owns the active virtual
|
---|
418 | * terminal before attempting a mode switch, since the RandR extension isn't
|
---|
419 | * very dilligent here, which can mean crashes if we are unlucky. This is
|
---|
420 | * not the way it the function is intended - it is meant for reporting modes
|
---|
421 | * which the hardware can't handle. I hope that this won't confuse any clients
|
---|
422 | * connecting to us. */
|
---|
423 | static Bool
|
---|
424 | vbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
425 | DisplayModePtr adjusted_mode)
|
---|
426 | { (void) crtc; (void) mode; (void) adjusted_mode; return TRUE; }
|
---|
427 |
|
---|
428 | static void
|
---|
429 | vbox_crtc_stub (xf86CrtcPtr crtc)
|
---|
430 | { (void) crtc; }
|
---|
431 |
|
---|
432 | static void
|
---|
433 | vbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
434 | DisplayModePtr adjusted_mode, int x, int y)
|
---|
435 | {
|
---|
436 | (void) mode;
|
---|
437 | VBOXPtr pVBox = VBOXGetRec(crtc->scrn);
|
---|
438 | unsigned cDisplay = (uintptr_t)crtc->driver_private;
|
---|
439 |
|
---|
440 | TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
|
---|
441 | adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y);
|
---|
442 | pVBox->pScreens[cDisplay].fPowerOn = true;
|
---|
443 | pVBox->pScreens[cDisplay].aScreenLocation.cx = adjusted_mode->HDisplay;
|
---|
444 | pVBox->pScreens[cDisplay].aScreenLocation.cy = adjusted_mode->VDisplay;
|
---|
445 | pVBox->pScreens[cDisplay].aScreenLocation.x = x;
|
---|
446 | pVBox->pScreens[cDisplay].aScreenLocation.y = y;
|
---|
447 | setModeRandR12(crtc->scrn, cDisplay);
|
---|
448 | }
|
---|
449 |
|
---|
450 | static void
|
---|
451 | vbox_crtc_gamma_set (xf86CrtcPtr crtc, CARD16 *red,
|
---|
452 | CARD16 *green, CARD16 *blue, int size)
|
---|
453 | { (void) crtc; (void) red; (void) green; (void) blue; (void) size; }
|
---|
454 |
|
---|
455 | static void *
|
---|
456 | vbox_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
|
---|
457 | { (void) crtc; (void) width; (void) height; return NULL; }
|
---|
458 |
|
---|
459 | static const xf86CrtcFuncsRec VBOXCrtcFuncs = {
|
---|
460 | .dpms = vbox_crtc_dpms,
|
---|
461 | .save = NULL, /* These two are never called by the server. */
|
---|
462 | .restore = NULL,
|
---|
463 | .lock = vbox_crtc_lock,
|
---|
464 | .unlock = NULL, /* This will not be invoked if lock returns FALSE. */
|
---|
465 | .mode_fixup = vbox_crtc_mode_fixup,
|
---|
466 | .prepare = vbox_crtc_stub,
|
---|
467 | .mode_set = vbox_crtc_mode_set,
|
---|
468 | .commit = vbox_crtc_stub,
|
---|
469 | .gamma_set = vbox_crtc_gamma_set,
|
---|
470 | .shadow_allocate = vbox_crtc_shadow_allocate,
|
---|
471 | .shadow_create = NULL, /* These two should not be invoked if allocate
|
---|
472 | returns NULL. */
|
---|
473 | .shadow_destroy = NULL,
|
---|
474 | .set_cursor_colors = NULL, /* We are still using the old cursor API. */
|
---|
475 | .set_cursor_position = NULL,
|
---|
476 | .show_cursor = NULL,
|
---|
477 | .hide_cursor = NULL,
|
---|
478 | .load_cursor_argb = NULL,
|
---|
479 | .destroy = vbox_crtc_stub
|
---|
480 | };
|
---|
481 |
|
---|
482 | static void
|
---|
483 | vbox_output_stub (xf86OutputPtr output)
|
---|
484 | { (void) output; }
|
---|
485 |
|
---|
486 | static void
|
---|
487 | vbox_output_dpms (xf86OutputPtr output, int mode)
|
---|
488 | {
|
---|
489 | (void)output; (void)mode;
|
---|
490 | }
|
---|
491 |
|
---|
492 | static int
|
---|
493 | vbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode)
|
---|
494 | {
|
---|
495 | return MODE_OK;
|
---|
496 | }
|
---|
497 |
|
---|
498 | static Bool
|
---|
499 | vbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode,
|
---|
500 | DisplayModePtr adjusted_mode)
|
---|
501 | { (void) output; (void) mode; (void) adjusted_mode; return TRUE; }
|
---|
502 |
|
---|
503 | static void
|
---|
504 | vbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode,
|
---|
505 | DisplayModePtr adjusted_mode)
|
---|
506 | { (void) output; (void) mode; (void) adjusted_mode; }
|
---|
507 |
|
---|
508 | /* A virtual monitor is always connected. */
|
---|
509 | static xf86OutputStatus
|
---|
510 | vbox_output_detect (xf86OutputPtr output)
|
---|
511 | {
|
---|
512 | ScrnInfoPtr pScrn = output->scrn;
|
---|
513 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
514 | uint32_t iScreen = (uintptr_t)output->driver_private;
|
---|
515 | return pVBox->pScreens[iScreen].afConnected
|
---|
516 | ? XF86OutputStatusConnected : XF86OutputStatusDisconnected;
|
---|
517 | }
|
---|
518 |
|
---|
519 | static DisplayModePtr vbox_output_add_mode(VBOXPtr pVBox, DisplayModePtr *pModes, const char *pszName, int x, int y,
|
---|
520 | Bool isPreferred, Bool isUserDef)
|
---|
521 | {
|
---|
522 | TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName ? pszName : "(null)", x, y);
|
---|
523 | DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
|
---|
524 | int cRefresh = 60;
|
---|
525 |
|
---|
526 | pMode->status = MODE_OK;
|
---|
527 | /* We don't ask the host whether it likes user defined modes,
|
---|
528 | * as we assume that the user really wanted that mode. */
|
---|
529 | pMode->type = isUserDef ? M_T_USERDEF : M_T_BUILTIN;
|
---|
530 | if (isPreferred)
|
---|
531 | pMode->type |= M_T_PREFERRED;
|
---|
532 | /* Older versions of VBox only support screen widths which are a multiple
|
---|
533 | * of 8 */
|
---|
534 | if (pVBox->fAnyX)
|
---|
535 | pMode->HDisplay = x;
|
---|
536 | else
|
---|
537 | pMode->HDisplay = x & ~7;
|
---|
538 | pMode->HSyncStart = pMode->HDisplay + 2;
|
---|
539 | pMode->HSyncEnd = pMode->HDisplay + 4;
|
---|
540 | pMode->HTotal = pMode->HDisplay + 6;
|
---|
541 | pMode->VDisplay = y;
|
---|
542 | pMode->VSyncStart = pMode->VDisplay + 2;
|
---|
543 | pMode->VSyncEnd = pMode->VDisplay + 4;
|
---|
544 | pMode->VTotal = pMode->VDisplay + 6;
|
---|
545 | pMode->Clock = pMode->HTotal * pMode->VTotal * cRefresh / 1000; /* kHz */
|
---|
546 | if (NULL == pszName) {
|
---|
547 | xf86SetModeDefaultName(pMode);
|
---|
548 | } else {
|
---|
549 | pMode->name = xnfstrdup(pszName);
|
---|
550 | }
|
---|
551 | *pModes = xf86ModesAdd(*pModes, pMode);
|
---|
552 | return pMode;
|
---|
553 | }
|
---|
554 |
|
---|
555 | static DisplayModePtr
|
---|
556 | vbox_output_get_modes (xf86OutputPtr output)
|
---|
557 | {
|
---|
558 | DisplayModePtr pModes = NULL;
|
---|
559 | DisplayModePtr pPreferred = NULL;
|
---|
560 | ScrnInfoPtr pScrn = output->scrn;
|
---|
561 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
562 |
|
---|
563 | TRACE_ENTRY();
|
---|
564 | uint32_t iScreen = (uintptr_t)output->driver_private;
|
---|
565 | pPreferred = vbox_output_add_mode(pVBox, &pModes, NULL,
|
---|
566 | RT_CLAMP(pVBox->pScreens[iScreen].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL),
|
---|
567 | RT_CLAMP(pVBox->pScreens[iScreen].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL),
|
---|
568 | TRUE, FALSE);
|
---|
569 | vbox_output_add_mode(pVBox, &pModes, NULL, 2560, 1600, FALSE, FALSE);
|
---|
570 | vbox_output_add_mode(pVBox, &pModes, NULL, 2560, 1440, FALSE, FALSE);
|
---|
571 | vbox_output_add_mode(pVBox, &pModes, NULL, 2048, 1536, FALSE, FALSE);
|
---|
572 | vbox_output_add_mode(pVBox, &pModes, NULL, 1920, 1600, FALSE, FALSE);
|
---|
573 | vbox_output_add_mode(pVBox, &pModes, NULL, 1920, 1080, FALSE, FALSE);
|
---|
574 | vbox_output_add_mode(pVBox, &pModes, NULL, 1680, 1050, FALSE, FALSE);
|
---|
575 | vbox_output_add_mode(pVBox, &pModes, NULL, 1600, 1200, FALSE, FALSE);
|
---|
576 | vbox_output_add_mode(pVBox, &pModes, NULL, 1400, 1050, FALSE, FALSE);
|
---|
577 | vbox_output_add_mode(pVBox, &pModes, NULL, 1280, 1024, FALSE, FALSE);
|
---|
578 | vbox_output_add_mode(pVBox, &pModes, NULL, 1024, 768, FALSE, FALSE);
|
---|
579 | vbox_output_add_mode(pVBox, &pModes, NULL, 800, 600, FALSE, FALSE);
|
---|
580 | vbox_output_add_mode(pVBox, &pModes, NULL, 640, 480, FALSE, FALSE);
|
---|
581 | VBOXEDIDSet(output, pPreferred);
|
---|
582 | TRACE_EXIT();
|
---|
583 | return pModes;
|
---|
584 | }
|
---|
585 |
|
---|
586 | static const xf86OutputFuncsRec VBOXOutputFuncs = {
|
---|
587 | .create_resources = vbox_output_stub,
|
---|
588 | .dpms = vbox_output_dpms,
|
---|
589 | .save = NULL, /* These two are never called by the server. */
|
---|
590 | .restore = NULL,
|
---|
591 | .mode_valid = vbox_output_mode_valid,
|
---|
592 | .mode_fixup = vbox_output_mode_fixup,
|
---|
593 | .prepare = vbox_output_stub,
|
---|
594 | .commit = vbox_output_stub,
|
---|
595 | .mode_set = vbox_output_mode_set,
|
---|
596 | .detect = vbox_output_detect,
|
---|
597 | .get_modes = vbox_output_get_modes,
|
---|
598 | #ifdef RANDR_12_INTERFACE
|
---|
599 | .set_property = NULL,
|
---|
600 | #endif
|
---|
601 | .destroy = vbox_output_stub
|
---|
602 | };
|
---|
603 | #endif /* VBOXVIDEO_13 */
|
---|
604 |
|
---|
605 | /* Module loader interface */
|
---|
606 | static MODULESETUPPROTO(vboxSetup);
|
---|
607 |
|
---|
608 | static XF86ModuleVersionInfo vboxVersionRec =
|
---|
609 | {
|
---|
610 | VBOX_DRIVER_NAME,
|
---|
611 | VBOX_VENDOR,
|
---|
612 | MODINFOSTRING1,
|
---|
613 | MODINFOSTRING2,
|
---|
614 | #ifdef XORG_7X
|
---|
615 | XORG_VERSION_CURRENT,
|
---|
616 | #else
|
---|
617 | XF86_VERSION_CURRENT,
|
---|
618 | #endif
|
---|
619 | 1, /* Module major version. Xorg-specific */
|
---|
620 | 0, /* Module minor version. Xorg-specific */
|
---|
621 | 1, /* Module patchlevel. Xorg-specific */
|
---|
622 | ABI_CLASS_VIDEODRV, /* This is a video driver */
|
---|
623 | ABI_VIDEODRV_VERSION,
|
---|
624 | MOD_CLASS_VIDEODRV,
|
---|
625 | {0, 0, 0, 0}
|
---|
626 | };
|
---|
627 |
|
---|
628 | /*
|
---|
629 | * This data is accessed by the loader. The name must be the module name
|
---|
630 | * followed by "ModuleData".
|
---|
631 | */
|
---|
632 | #ifdef XORG_7X
|
---|
633 | _X_EXPORT
|
---|
634 | #endif
|
---|
635 | XF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
|
---|
636 |
|
---|
637 | static pointer
|
---|
638 | vboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
|
---|
639 | {
|
---|
640 | static Bool Initialised = FALSE;
|
---|
641 | RT_NOREF(Options, ErrorMinor);
|
---|
642 |
|
---|
643 | if (!Initialised)
|
---|
644 | {
|
---|
645 | Initialised = TRUE;
|
---|
646 | #ifdef PCIACCESS
|
---|
647 | xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs);
|
---|
648 | #else
|
---|
649 | xf86AddDriver(&VBOXVIDEO, Module, 0);
|
---|
650 | #endif
|
---|
651 | #ifndef XORG_7X
|
---|
652 | LoaderRefSymLists(fbSymbols,
|
---|
653 | shadowfbSymbols,
|
---|
654 | ramdacSymbols,
|
---|
655 | vgahwSymbols,
|
---|
656 | NULL);
|
---|
657 | #endif
|
---|
658 | xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n",
|
---|
659 | (void *)&VBOXVIDEO);
|
---|
660 | return (pointer)TRUE;
|
---|
661 | }
|
---|
662 |
|
---|
663 | if (ErrorMajor)
|
---|
664 | *ErrorMajor = LDR_ONCEONLY;
|
---|
665 | return (NULL);
|
---|
666 | }
|
---|
667 |
|
---|
668 |
|
---|
669 | static const OptionInfoRec *
|
---|
670 | VBOXAvailableOptions(int chipid, int busid)
|
---|
671 | {
|
---|
672 | RT_NOREF(chipid, busid);
|
---|
673 | return (VBOXOptions);
|
---|
674 | }
|
---|
675 |
|
---|
676 | static void
|
---|
677 | VBOXIdentify(int flags)
|
---|
678 | {
|
---|
679 | RT_NOREF(flags);
|
---|
680 | xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
|
---|
681 | }
|
---|
682 |
|
---|
683 | #ifndef XF86_SCRN_INTERFACE
|
---|
684 | # define SCRNINDEXAPI(pfn) pfn ## Index
|
---|
685 | static Bool VBOXScreenInitIndex(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
|
---|
686 | {
|
---|
687 | RT_NOREF(scrnIndex);
|
---|
688 | return VBOXScreenInit(pScreen, argc, argv);
|
---|
689 | }
|
---|
690 |
|
---|
691 | static Bool VBOXEnterVTIndex(int scrnIndex, int flags)
|
---|
692 | { (void) flags; return VBOXEnterVT(xf86Screens[scrnIndex]); }
|
---|
693 |
|
---|
694 | static void VBOXLeaveVTIndex(int scrnIndex, int flags)
|
---|
695 | { (void) flags; VBOXLeaveVT(xf86Screens[scrnIndex]); }
|
---|
696 |
|
---|
697 | static Bool VBOXCloseScreenIndex(int scrnIndex, ScreenPtr pScreen)
|
---|
698 | { (void) scrnIndex; return VBOXCloseScreen(pScreen); }
|
---|
699 |
|
---|
700 | static Bool VBOXSwitchModeIndex(int scrnIndex, DisplayModePtr pMode, int flags)
|
---|
701 | { (void) flags; return VBOXSwitchMode(xf86Screens[scrnIndex], pMode); }
|
---|
702 |
|
---|
703 | static void VBOXAdjustFrameIndex(int scrnIndex, int x, int y, int flags)
|
---|
704 | { (void) flags; VBOXAdjustFrame(xf86Screens[scrnIndex], x, y); }
|
---|
705 |
|
---|
706 | static void VBOXFreeScreenIndex(int scrnIndex, int flags)
|
---|
707 | { (void) flags; VBOXFreeScreen(xf86Screens[scrnIndex]); }
|
---|
708 | # else
|
---|
709 | # define SCRNINDEXAPI(pfn) pfn
|
---|
710 | #endif /* XF86_SCRN_INTERFACE */
|
---|
711 |
|
---|
712 | static void setScreenFunctions(ScrnInfoPtr pScrn, xf86ProbeProc pfnProbe)
|
---|
713 | {
|
---|
714 | pScrn->driverVersion = VBOX_VERSION;
|
---|
715 | pScrn->driverName = VBOX_DRIVER_NAME;
|
---|
716 | pScrn->name = VBOX_NAME;
|
---|
717 | pScrn->Probe = pfnProbe;
|
---|
718 | pScrn->PreInit = VBOXPreInit;
|
---|
719 | pScrn->ScreenInit = SCRNINDEXAPI(VBOXScreenInit);
|
---|
720 | pScrn->SwitchMode = SCRNINDEXAPI(VBOXSwitchMode);
|
---|
721 | pScrn->AdjustFrame = SCRNINDEXAPI(VBOXAdjustFrame);
|
---|
722 | pScrn->EnterVT = SCRNINDEXAPI(VBOXEnterVT);
|
---|
723 | pScrn->LeaveVT = SCRNINDEXAPI(VBOXLeaveVT);
|
---|
724 | pScrn->FreeScreen = SCRNINDEXAPI(VBOXFreeScreen);
|
---|
725 | }
|
---|
726 |
|
---|
727 | /*
|
---|
728 | * One of these functions is called once, at the start of the first server
|
---|
729 | * generation to do a minimal probe for supported hardware.
|
---|
730 | */
|
---|
731 |
|
---|
732 | #ifdef PCIACCESS
|
---|
733 | static Bool
|
---|
734 | VBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
|
---|
735 | intptr_t match_data)
|
---|
736 | {
|
---|
737 | ScrnInfoPtr pScrn;
|
---|
738 | int drmFd;
|
---|
739 |
|
---|
740 | TRACE_ENTRY();
|
---|
741 |
|
---|
742 | drmFd = open("/dev/dri/card0", O_RDWR, 0);
|
---|
743 | if (drmFd >= 0)
|
---|
744 | {
|
---|
745 | xf86Msg(X_INFO, "vboxvideo: kernel driver found, not loading.\n");
|
---|
746 | close(drmFd);
|
---|
747 | return FALSE;
|
---|
748 | }
|
---|
749 | /* It is safe to call this, as the X server enables I/O access before
|
---|
750 | * calling the probe call-backs. */
|
---|
751 | if (!xf86EnableIO())
|
---|
752 | {
|
---|
753 | xf86Msg(X_INFO, "vboxvideo: this driver requires direct hardware access. You may wish to use the kernel driver instead.\n");
|
---|
754 | return FALSE;
|
---|
755 | }
|
---|
756 | pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
|
---|
757 | NULL, NULL, NULL, NULL, NULL);
|
---|
758 | if (pScrn != NULL) {
|
---|
759 | VBOXPtr pVBox;
|
---|
760 |
|
---|
761 | VBOXSetRec(pScrn);
|
---|
762 | pVBox = VBOXGetRec(pScrn);
|
---|
763 | if (!pVBox)
|
---|
764 | return FALSE;
|
---|
765 | setScreenFunctions(pScrn, NULL);
|
---|
766 | pVBox->pciInfo = dev;
|
---|
767 | }
|
---|
768 |
|
---|
769 | TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
|
---|
770 | return (pScrn != NULL);
|
---|
771 | }
|
---|
772 | #endif
|
---|
773 |
|
---|
774 | #ifndef PCIACCESS
|
---|
775 | static Bool
|
---|
776 | VBOXProbe(DriverPtr drv, int flags)
|
---|
777 | {
|
---|
778 | Bool foundScreen = FALSE;
|
---|
779 | int numDevSections;
|
---|
780 | GDevPtr *devSections;
|
---|
781 |
|
---|
782 | /*
|
---|
783 | * Find the config file Device sections that match this
|
---|
784 | * driver, and return if there are none.
|
---|
785 | */
|
---|
786 | if ((numDevSections = xf86MatchDevice(VBOX_NAME,
|
---|
787 | &devSections)) <= 0)
|
---|
788 | return (FALSE);
|
---|
789 |
|
---|
790 | /* PCI BUS */
|
---|
791 | if (xf86GetPciVideoInfo())
|
---|
792 | {
|
---|
793 | int numUsed;
|
---|
794 | int *usedChips;
|
---|
795 | int i;
|
---|
796 | numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
|
---|
797 | VBOXChipsets, VBOXPCIchipsets,
|
---|
798 | devSections, numDevSections,
|
---|
799 | drv, &usedChips);
|
---|
800 | if (numUsed > 0)
|
---|
801 | {
|
---|
802 | if (flags & PROBE_DETECT)
|
---|
803 | foundScreen = TRUE;
|
---|
804 | else
|
---|
805 | for (i = 0; i < numUsed; i++)
|
---|
806 | {
|
---|
807 | ScrnInfoPtr pScrn = NULL;
|
---|
808 | /* Allocate a ScrnInfoRec */
|
---|
809 | if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
|
---|
810 | VBOXPCIchipsets,NULL,
|
---|
811 | NULL,NULL,NULL,NULL)))
|
---|
812 | {
|
---|
813 | setScreenFunctions(pScrn, VBOXProbe);
|
---|
814 | foundScreen = TRUE;
|
---|
815 | }
|
---|
816 | }
|
---|
817 | free(usedChips);
|
---|
818 | }
|
---|
819 | }
|
---|
820 | free(devSections);
|
---|
821 | return (foundScreen);
|
---|
822 | }
|
---|
823 | #endif
|
---|
824 |
|
---|
825 |
|
---|
826 | /*
|
---|
827 | * QUOTE from the XFree86 DESIGN document:
|
---|
828 | *
|
---|
829 | * The purpose of this function is to find out all the information
|
---|
830 | * required to determine if the configuration is usable, and to initialise
|
---|
831 | * those parts of the ScrnInfoRec that can be set once at the beginning of
|
---|
832 | * the first server generation.
|
---|
833 | *
|
---|
834 | * (...)
|
---|
835 | *
|
---|
836 | * This includes probing for video memory, clocks, ramdac, and all other
|
---|
837 | * HW info that is needed. It includes determining the depth/bpp/visual
|
---|
838 | * and related info. It includes validating and determining the set of
|
---|
839 | * video modes that will be used (and anything that is required to
|
---|
840 | * determine that).
|
---|
841 | *
|
---|
842 | * This information should be determined in the least intrusive way
|
---|
843 | * possible. The state of the HW must remain unchanged by this function.
|
---|
844 | * Although video memory (including MMIO) may be mapped within this
|
---|
845 | * function, it must be unmapped before returning.
|
---|
846 | *
|
---|
847 | * END QUOTE
|
---|
848 | */
|
---|
849 |
|
---|
850 | static Bool
|
---|
851 | VBOXPreInit(ScrnInfoPtr pScrn, int flags)
|
---|
852 | {
|
---|
853 | VBOXPtr pVBox;
|
---|
854 | Gamma gzeros = {0.0, 0.0, 0.0};
|
---|
855 | rgb rzeros = {0, 0, 0};
|
---|
856 |
|
---|
857 | TRACE_ENTRY();
|
---|
858 | /* Are we really starting the server, or is this just a dummy run? */
|
---|
859 | if (flags & PROBE_DETECT)
|
---|
860 | return (FALSE);
|
---|
861 |
|
---|
862 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "VirtualBox guest additions video driver version " VBOX_VERSION_STRING "r%d\n",
|
---|
863 | VBOX_SVN_REV);
|
---|
864 |
|
---|
865 | /* The ramdac module is needed for the hardware cursor. */
|
---|
866 | if (!xf86LoadSubModule(pScrn, "ramdac"))
|
---|
867 | return FALSE;
|
---|
868 |
|
---|
869 | /* The framebuffer module. */
|
---|
870 | if (!xf86LoadSubModule(pScrn, "fb"))
|
---|
871 | return (FALSE);
|
---|
872 |
|
---|
873 | if (!xf86LoadSubModule(pScrn, "shadowfb"))
|
---|
874 | return FALSE;
|
---|
875 |
|
---|
876 | if (!xf86LoadSubModule(pScrn, "vgahw"))
|
---|
877 | return FALSE;
|
---|
878 |
|
---|
879 | /* Get our private data from the ScrnInfoRec structure. */
|
---|
880 | VBOXSetRec(pScrn);
|
---|
881 | pVBox = VBOXGetRec(pScrn);
|
---|
882 | if (!pVBox)
|
---|
883 | return FALSE;
|
---|
884 |
|
---|
885 | /* Entity information seems to mean bus information. */
|
---|
886 | pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
|
---|
887 |
|
---|
888 | #ifndef PCIACCESS
|
---|
889 | if (pVBox->pEnt->location.type != BUS_PCI)
|
---|
890 | return FALSE;
|
---|
891 |
|
---|
892 | pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
|
---|
893 | pVBox->pciTag = pciTag(pVBox->pciInfo->bus,
|
---|
894 | pVBox->pciInfo->device,
|
---|
895 | pVBox->pciInfo->func);
|
---|
896 | #endif
|
---|
897 |
|
---|
898 | /* Set up our ScrnInfoRec structure to describe our virtual
|
---|
899 | capabilities to X. */
|
---|
900 |
|
---|
901 | pScrn->chipset = "vbox";
|
---|
902 | /** @note needed during colourmap initialisation */
|
---|
903 | pScrn->rgbBits = 8;
|
---|
904 |
|
---|
905 | /* Let's create a nice, capable virtual monitor. */
|
---|
906 | pScrn->monitor = pScrn->confScreen->monitor;
|
---|
907 | pScrn->monitor->DDC = NULL;
|
---|
908 | pScrn->monitor->nHsync = 1;
|
---|
909 | pScrn->monitor->hsync[0].lo = 1;
|
---|
910 | pScrn->monitor->hsync[0].hi = 10000;
|
---|
911 | pScrn->monitor->nVrefresh = 1;
|
---|
912 | pScrn->monitor->vrefresh[0].lo = 1;
|
---|
913 | pScrn->monitor->vrefresh[0].hi = 100;
|
---|
914 |
|
---|
915 | pScrn->progClock = TRUE;
|
---|
916 |
|
---|
917 | /* Using the PCI information caused problems with non-powers-of-two
|
---|
918 | sized video RAM configurations */
|
---|
919 | pVBox->cbFBMax = VBoxVideoGetVRAMSize();
|
---|
920 | pScrn->videoRam = pVBox->cbFBMax / 1024;
|
---|
921 |
|
---|
922 | /* Check if the chip restricts horizontal resolution or not. */
|
---|
923 | pVBox->fAnyX = VBoxVideoAnyWidthAllowed();
|
---|
924 |
|
---|
925 | /* Set up clock information that will support all modes we need. */
|
---|
926 | pScrn->clockRanges = xnfcalloc(sizeof(ClockRange), 1);
|
---|
927 | pScrn->clockRanges->minClock = 1000;
|
---|
928 | pScrn->clockRanges->maxClock = 1000000000;
|
---|
929 | pScrn->clockRanges->clockIndex = -1;
|
---|
930 | pScrn->clockRanges->ClockMulFactor = 1;
|
---|
931 | pScrn->clockRanges->ClockDivFactor = 1;
|
---|
932 |
|
---|
933 | if (!xf86SetDepthBpp(pScrn, 24, 0, 0, Support32bppFb))
|
---|
934 | return FALSE;
|
---|
935 | /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
|
---|
936 | if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
|
---|
937 | {
|
---|
938 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
939 | "The VBox additions only support 16 and 32bpp graphics modes\n");
|
---|
940 | return FALSE;
|
---|
941 | }
|
---|
942 | xf86PrintDepthBpp(pScrn);
|
---|
943 | vboxAddModes(pScrn);
|
---|
944 |
|
---|
945 | #ifdef VBOXVIDEO_13
|
---|
946 | pScrn->virtualX = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
947 | pScrn->virtualY = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
948 | #else
|
---|
949 | /* We don't validate with xf86ValidateModes and xf86PruneModes as we
|
---|
950 | * already know what we like and what we don't. */
|
---|
951 |
|
---|
952 | pScrn->currentMode = pScrn->modes;
|
---|
953 |
|
---|
954 | /* Set the right virtual resolution. */
|
---|
955 | pScrn->virtualX = pScrn->bitsPerPixel == 16 ? (pScrn->currentMode->HDisplay + 1) & ~1 : pScrn->currentMode->HDisplay;
|
---|
956 | pScrn->virtualY = pScrn->currentMode->VDisplay;
|
---|
957 |
|
---|
958 | #endif /* !VBOXVIDEO_13 */
|
---|
959 |
|
---|
960 | pScrn->displayWidth = pScrn->virtualX;
|
---|
961 |
|
---|
962 | xf86PrintModes(pScrn);
|
---|
963 |
|
---|
964 | /* VGA hardware initialisation */
|
---|
965 | if (!vgaHWGetHWRec(pScrn))
|
---|
966 | return FALSE;
|
---|
967 | /* Must be called before any VGA registers are saved or restored */
|
---|
968 | vgaHWSetStdFuncs(VGAHWPTR(pScrn));
|
---|
969 | vgaHWGetIOBase(VGAHWPTR(pScrn));
|
---|
970 |
|
---|
971 | /* Colour weight - we always call this, since we are always in
|
---|
972 | truecolour. */
|
---|
973 | if (!xf86SetWeight(pScrn, rzeros, rzeros))
|
---|
974 | return (FALSE);
|
---|
975 |
|
---|
976 | /* visual init */
|
---|
977 | if (!xf86SetDefaultVisual(pScrn, -1))
|
---|
978 | return (FALSE);
|
---|
979 |
|
---|
980 | xf86SetGamma(pScrn, gzeros);
|
---|
981 |
|
---|
982 | /* Set the DPI. Perhaps we should read this from the host? */
|
---|
983 | xf86SetDpi(pScrn, 96, 96);
|
---|
984 |
|
---|
985 | if (pScrn->memPhysBase == 0) {
|
---|
986 | #ifdef PCIACCESS
|
---|
987 | pScrn->memPhysBase = pVBox->pciInfo->regions[0].base_addr;
|
---|
988 | #else
|
---|
989 | pScrn->memPhysBase = pVBox->pciInfo->memBase[0];
|
---|
990 | #endif
|
---|
991 | pScrn->fbOffset = 0;
|
---|
992 | }
|
---|
993 |
|
---|
994 | TRACE_EXIT();
|
---|
995 | return (TRUE);
|
---|
996 | }
|
---|
997 |
|
---|
998 | /**
|
---|
999 | * Dummy function for setting the colour palette, which we actually never
|
---|
1000 | * touch. However, the server still requires us to provide this.
|
---|
1001 | */
|
---|
1002 | static void
|
---|
1003 | vboxLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
|
---|
1004 | LOCO *colors, VisualPtr pVisual)
|
---|
1005 | {
|
---|
1006 | (void)pScrn; (void) numColors; (void) indices; (void) colors;
|
---|
1007 | (void)pVisual;
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | /** Set the graphics and guest cursor support capabilities to the host if
|
---|
1011 | * the user-space helper is running. */
|
---|
1012 | static void updateGraphicsCapability(ScrnInfoPtr pScrn, Bool hasVT)
|
---|
1013 | {
|
---|
1014 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1015 |
|
---|
1016 | if (!pVBox->fHaveHGSMIModeHints)
|
---|
1017 | return;
|
---|
1018 | VBoxHGSMISendCapsInfo(&pVBox->guestCtx, hasVT
|
---|
1019 | ? VBVACAPS_VIDEO_MODE_HINTS | VBVACAPS_DISABLE_CURSOR_INTEGRATION
|
---|
1020 | : VBVACAPS_DISABLE_CURSOR_INTEGRATION);
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | #ifndef VBOXVIDEO_13
|
---|
1024 |
|
---|
1025 | #define PREFERRED_MODE_ATOM_NAME "VBOXVIDEO_PREFERRED_MODE"
|
---|
1026 |
|
---|
1027 | static void setSizesRandR11(ScrnInfoPtr pScrn)
|
---|
1028 | {
|
---|
1029 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1030 | DisplayModePtr pNewMode;
|
---|
1031 | int32_t propertyValue;
|
---|
1032 |
|
---|
1033 | pNewMode = pScrn->modes != pScrn->currentMode ? pScrn->modes : pScrn->modes->next;
|
---|
1034 | pNewMode->HDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1035 | pNewMode->VDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1036 | propertyValue = (pNewMode->HDisplay << 16) + pNewMode->VDisplay;
|
---|
1037 | ChangeWindowProperty(ROOT_WINDOW(pScrn), MakeAtom(PREFERRED_MODE_ATOM_NAME,
|
---|
1038 | sizeof(PREFERRED_MODE_ATOM_NAME) - 1, TRUE), XA_INTEGER, 32,
|
---|
1039 | PropModeReplace, 1, &propertyValue, TRUE);
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | #endif
|
---|
1043 |
|
---|
1044 | static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, bool fScreenInitTime)
|
---|
1045 | {
|
---|
1046 | RT_NOREF(fScreenInitTime);
|
---|
1047 | TRACE_LOG("fScreenInitTime=%d\n", (int)fScreenInitTime);
|
---|
1048 | #ifdef VBOXVIDEO_13
|
---|
1049 | # if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 5
|
---|
1050 | RRGetInfo(xf86ScrnToScreen(pScrn), TRUE);
|
---|
1051 | # else
|
---|
1052 | RRGetInfo(xf86ScrnToScreen(pScrn));
|
---|
1053 | # endif
|
---|
1054 | #else
|
---|
1055 | setSizesRandR11(pScrn);
|
---|
1056 | #endif
|
---|
1057 | /* This calls EnableDisableFBAccess(), so only use when switched in. */
|
---|
1058 | if (pScrn->vtSema)
|
---|
1059 | vbvxReprobeCursor(pScrn);
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | /* We update the size hints from the X11 property set by VBoxClient every time
|
---|
1063 | * that the X server goes to sleep (to catch the property change request).
|
---|
1064 | * Although this is far more often than necessary it should not have real-life
|
---|
1065 | * performance consequences and allows us to simplify the code quite a bit. */
|
---|
1066 | static void vboxBlockHandler(pointer pData, OSTimePtr pTimeout, pointer pReadmask)
|
---|
1067 | {
|
---|
1068 | ScrnInfoPtr pScrn = (ScrnInfoPtr)pData;
|
---|
1069 | bool fNeedUpdate = false;
|
---|
1070 |
|
---|
1071 | (void)pTimeout;
|
---|
1072 | (void)pReadmask;
|
---|
1073 | if (pScrn->vtSema)
|
---|
1074 | vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, &fNeedUpdate);
|
---|
1075 | if (fNeedUpdate)
|
---|
1076 | setSizesAndCursorIntegration(pScrn, false);
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 | /*
|
---|
1080 | * QUOTE from the XFree86 DESIGN document:
|
---|
1081 | *
|
---|
1082 | * This is called at the start of each server generation.
|
---|
1083 | *
|
---|
1084 | * (...)
|
---|
1085 | *
|
---|
1086 | * Decide which operations need to be placed under resource access
|
---|
1087 | * control. (...) Map any video memory or other memory regions. (...)
|
---|
1088 | * Save the video card state. (...) Initialise the initial video
|
---|
1089 | * mode.
|
---|
1090 | *
|
---|
1091 | * End QUOTE.
|
---|
1092 | */
|
---|
1093 | static Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv)
|
---|
1094 | {
|
---|
1095 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
---|
1096 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1097 | VisualPtr visual;
|
---|
1098 | RT_NOREF(argc, argv);
|
---|
1099 |
|
---|
1100 | TRACE_ENTRY();
|
---|
1101 |
|
---|
1102 | /* Initialise our guest library if possible: ignore failure. */
|
---|
1103 | VbglR3Init();
|
---|
1104 | if (!VBOXMapVidMem(pScrn))
|
---|
1105 | return (FALSE);
|
---|
1106 |
|
---|
1107 | /* save current video state */
|
---|
1108 | VBOXSaveMode(pScrn);
|
---|
1109 |
|
---|
1110 | /* mi layer - reset the visual list (?)*/
|
---|
1111 | miClearVisualTypes();
|
---|
1112 | if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
|
---|
1113 | pScrn->rgbBits, TrueColor))
|
---|
1114 | return (FALSE);
|
---|
1115 | if (!miSetPixmapDepths())
|
---|
1116 | return (FALSE);
|
---|
1117 |
|
---|
1118 | if (!fbScreenInit(pScreen, pVBox->base,
|
---|
1119 | pScrn->virtualX, pScrn->virtualY,
|
---|
1120 | pScrn->xDpi, pScrn->yDpi,
|
---|
1121 | pScrn->displayWidth, pScrn->bitsPerPixel))
|
---|
1122 | return (FALSE);
|
---|
1123 |
|
---|
1124 | /* Fixup RGB ordering */
|
---|
1125 | /** @note the X server uses this even in true colour. */
|
---|
1126 | visual = pScreen->visuals + pScreen->numVisuals;
|
---|
1127 | while (--visual >= pScreen->visuals) {
|
---|
1128 | if ((visual->class | DynamicClass) == DirectColor) {
|
---|
1129 | visual->offsetRed = pScrn->offset.red;
|
---|
1130 | visual->offsetGreen = pScrn->offset.green;
|
---|
1131 | visual->offsetBlue = pScrn->offset.blue;
|
---|
1132 | visual->redMask = pScrn->mask.red;
|
---|
1133 | visual->greenMask = pScrn->mask.green;
|
---|
1134 | visual->blueMask = pScrn->mask.blue;
|
---|
1135 | }
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | /* must be after RGB ordering fixed */
|
---|
1139 | fbPictureInit(pScreen, 0, 0);
|
---|
1140 |
|
---|
1141 | xf86SetBlackWhitePixels(pScreen);
|
---|
1142 | pScrn->vtSema = TRUE;
|
---|
1143 |
|
---|
1144 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
1145 | vbvxSetUpLinuxACPI(pScreen);
|
---|
1146 | #endif
|
---|
1147 |
|
---|
1148 | if (!VBoxHGSMIIsSupported())
|
---|
1149 | {
|
---|
1150 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Graphics device too old to support.\n");
|
---|
1151 | return FALSE;
|
---|
1152 | }
|
---|
1153 | vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
|
---|
1154 | pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx);
|
---|
1155 | pVBox->pScreens = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->pScreens));
|
---|
1156 | pVBox->paVBVAModeHints = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->paVBVAModeHints));
|
---|
1157 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n", pVBox->cScreens);
|
---|
1158 | vboxEnableVbva(pScrn);
|
---|
1159 | /* Set up the dirty rectangle handler. It will be added into a function
|
---|
1160 | * chain and gets removed when the screen is cleaned up. */
|
---|
1161 | if (ShadowFBInit2(pScreen, NULL, vbvxHandleDirtyRect) != TRUE)
|
---|
1162 | return FALSE;
|
---|
1163 | VBoxInitialiseSizeHints(pScrn);
|
---|
1164 |
|
---|
1165 | #ifdef VBOXVIDEO_13
|
---|
1166 | /* Initialise CRTC and output configuration for use with randr1.2. */
|
---|
1167 | xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs);
|
---|
1168 |
|
---|
1169 | {
|
---|
1170 | uint32_t i;
|
---|
1171 |
|
---|
1172 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1173 | {
|
---|
1174 | char szOutput[256];
|
---|
1175 |
|
---|
1176 | /* Setup our virtual CRTCs. */
|
---|
1177 | pVBox->pScreens[i].paCrtcs = xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
|
---|
1178 | pVBox->pScreens[i].paCrtcs->driver_private = (void *)(uintptr_t)i;
|
---|
1179 |
|
---|
1180 | /* Set up our virtual outputs. */
|
---|
1181 | snprintf(szOutput, sizeof(szOutput), "VGA-%u", i);
|
---|
1182 | pVBox->pScreens[i].paOutputs
|
---|
1183 | = xf86OutputCreate(pScrn, &VBOXOutputFuncs, szOutput);
|
---|
1184 |
|
---|
1185 | /* We are not interested in the monitor section in the
|
---|
1186 | * configuration file. */
|
---|
1187 | xf86OutputUseScreenMonitor(pVBox->pScreens[i].paOutputs, FALSE);
|
---|
1188 | pVBox->pScreens[i].paOutputs->possible_crtcs = 1 << i;
|
---|
1189 | pVBox->pScreens[i].paOutputs->possible_clones = 0;
|
---|
1190 | pVBox->pScreens[i].paOutputs->driver_private = (void *)(uintptr_t)i;
|
---|
1191 | TRACE_LOG("Created crtc (%p) and output %s (%p)\n",
|
---|
1192 | (void *)pVBox->pScreens[i].paCrtcs, szOutput,
|
---|
1193 | (void *)pVBox->pScreens[i].paOutputs);
|
---|
1194 | }
|
---|
1195 | }
|
---|
1196 |
|
---|
1197 | /* Set a sane minimum and maximum mode size to match what the hardware
|
---|
1198 | * supports. */
|
---|
1199 | xf86CrtcSetSizeRange(pScrn, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1200 |
|
---|
1201 | /* Now create our initial CRTC/output configuration. */
|
---|
1202 | if (!xf86InitialConfiguration(pScrn, TRUE)) {
|
---|
1203 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
|
---|
1204 | return (FALSE);
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | /* Work around a bug in the original X server modesetting code, which took
|
---|
1208 | * the first valid values set to these two as maxima over the server
|
---|
1209 | * lifetime. This bug was introduced on Feb 15 2007 and was fixed in commit
|
---|
1210 | * fa877d7f three months later, so it was present in X.Org Server 1.3. */
|
---|
1211 | pScrn->virtualX = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
1212 | pScrn->virtualY = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
1213 |
|
---|
1214 | /* Initialise randr 1.2 mode-setting functions. */
|
---|
1215 | if (!xf86CrtcScreenInit(pScreen)) {
|
---|
1216 | return FALSE;
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | /* set first video mode */
|
---|
1220 | if (!xf86SetDesiredModes(pScrn)) {
|
---|
1221 | return FALSE;
|
---|
1222 | }
|
---|
1223 | #else /* !VBOXVIDEO_13 */
|
---|
1224 | /* set first video mode */
|
---|
1225 | setModeRandR11(pScrn, pScrn->currentMode, true, false, 0, 0);
|
---|
1226 | #endif /* !VBOXVIDEO_13 */
|
---|
1227 |
|
---|
1228 | /* Say that we support graphics. */
|
---|
1229 | updateGraphicsCapability(pScrn, TRUE);
|
---|
1230 |
|
---|
1231 | /* Register block and wake-up handlers for getting new screen size hints. */
|
---|
1232 | RegisterBlockAndWakeupHandlers(vboxBlockHandler, (WakeupHandlerProcPtr)NoopDDA, (pointer)pScrn);
|
---|
1233 |
|
---|
1234 | /* software cursor */
|
---|
1235 | miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
|
---|
1236 |
|
---|
1237 | /* colourmap code */
|
---|
1238 | if (!miCreateDefColormap(pScreen))
|
---|
1239 | return (FALSE);
|
---|
1240 |
|
---|
1241 | if(!xf86HandleColormaps(pScreen, 256, 8, vboxLoadPalette, NULL, 0))
|
---|
1242 | return (FALSE);
|
---|
1243 |
|
---|
1244 | pVBox->CloseScreen = pScreen->CloseScreen;
|
---|
1245 | pScreen->CloseScreen = SCRNINDEXAPI(VBOXCloseScreen);
|
---|
1246 | #ifdef VBOXVIDEO_13
|
---|
1247 | pScreen->SaveScreen = xf86SaveScreen;
|
---|
1248 | #else
|
---|
1249 | pScreen->SaveScreen = VBOXSaveScreen;
|
---|
1250 | #endif
|
---|
1251 |
|
---|
1252 | #ifdef VBOXVIDEO_13
|
---|
1253 | xf86DPMSInit(pScreen, xf86DPMSSet, 0);
|
---|
1254 | #else
|
---|
1255 | /* We probably do want to support power management - even if we just use
|
---|
1256 | a dummy function. */
|
---|
1257 | xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
|
---|
1258 | #endif
|
---|
1259 |
|
---|
1260 | /* Report any unused options (only for the first generation) */
|
---|
1261 | if (serverGeneration == 1)
|
---|
1262 | xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
|
---|
1263 |
|
---|
1264 | if (vbvxCursorInit(pScreen) != TRUE)
|
---|
1265 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
1266 | "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
|
---|
1267 |
|
---|
1268 | return (TRUE);
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | #define NO_VT_ATOM_NAME "VBOXVIDEO_NO_VT"
|
---|
1272 |
|
---|
1273 | static Bool VBOXEnterVT(ScrnInfoPtr pScrn)
|
---|
1274 | {
|
---|
1275 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1276 | #ifndef VBOXVIDEO_13
|
---|
1277 | /* If we got a mode request while we were switched out, temporarily override
|
---|
1278 | * the physical mode set to the device while keeping things consistent from
|
---|
1279 | * the server's point of view. */
|
---|
1280 | int cXOverRide = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1281 | int cYOverRide = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1282 | #endif
|
---|
1283 |
|
---|
1284 | TRACE_ENTRY();
|
---|
1285 | vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
|
---|
1286 | vboxEnableVbva(pScrn);
|
---|
1287 | /* Re-set video mode */
|
---|
1288 | #ifdef VBOXVIDEO_13
|
---|
1289 | if (!xf86SetDesiredModes(pScrn)) {
|
---|
1290 | return FALSE;
|
---|
1291 | }
|
---|
1292 | #else
|
---|
1293 | setModeRandR11(pScrn, pScrn->currentMode, false, true, cXOverRide, cYOverRide);
|
---|
1294 | DeleteProperty(ROOT_WINDOW(pScrn), MakeAtom(NO_VT_ATOM_NAME, sizeof(NO_VT_ATOM_NAME) - 1, TRUE));
|
---|
1295 | #endif
|
---|
1296 | updateGraphicsCapability(pScrn, TRUE);
|
---|
1297 | return TRUE;
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | static void VBOXLeaveVT(ScrnInfoPtr pScrn)
|
---|
1301 | {
|
---|
1302 | #ifdef VBOXVIDEO_13
|
---|
1303 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1304 | unsigned i;
|
---|
1305 | #else
|
---|
1306 | int32_t propertyValue = 0;
|
---|
1307 | #endif
|
---|
1308 |
|
---|
1309 | TRACE_ENTRY();
|
---|
1310 | #ifdef VBOXVIDEO_13
|
---|
1311 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1312 | vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff);
|
---|
1313 | #else
|
---|
1314 | ChangeWindowProperty(ROOT_WINDOW(pScrn), MakeAtom(NO_VT_ATOM_NAME, sizeof(NO_VT_ATOM_NAME) - 1, FALSE), XA_INTEGER, 32,
|
---|
1315 | PropModeReplace, 1, &propertyValue, TRUE);
|
---|
1316 | #endif
|
---|
1317 | updateGraphicsCapability(pScrn, FALSE);
|
---|
1318 | vboxDisableVbva(pScrn);
|
---|
1319 | vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8), 0);
|
---|
1320 | VBOXRestoreMode(pScrn);
|
---|
1321 | TRACE_EXIT();
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | static Bool VBOXCloseScreen(ScreenPtr pScreen)
|
---|
1325 | {
|
---|
1326 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
---|
1327 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1328 | BOOL ret;
|
---|
1329 |
|
---|
1330 | if (pScrn->vtSema)
|
---|
1331 | {
|
---|
1332 | #ifdef VBOXVIDEO_13
|
---|
1333 | unsigned i;
|
---|
1334 |
|
---|
1335 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1336 | vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff);
|
---|
1337 | #endif
|
---|
1338 | vboxDisableVbva(pScrn);
|
---|
1339 | vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8), 0);
|
---|
1340 | }
|
---|
1341 | if (pScrn->vtSema)
|
---|
1342 | VBOXRestoreMode(pScrn);
|
---|
1343 | if (pScrn->vtSema)
|
---|
1344 | VBOXUnmapVidMem(pScrn);
|
---|
1345 | pScrn->vtSema = FALSE;
|
---|
1346 |
|
---|
1347 | vbvxCursorTerm(pVBox);
|
---|
1348 |
|
---|
1349 | pScreen->CloseScreen = pVBox->CloseScreen;
|
---|
1350 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
1351 | vbvxCleanUpLinuxACPI(pScreen);
|
---|
1352 | #endif
|
---|
1353 | #ifndef XF86_SCRN_INTERFACE
|
---|
1354 | ret = pScreen->CloseScreen(pScreen->myNum, pScreen);
|
---|
1355 | #else
|
---|
1356 | ret = pScreen->CloseScreen(pScreen);
|
---|
1357 | #endif
|
---|
1358 | VbglR3Term();
|
---|
1359 | return ret;
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | static Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
|
---|
1363 | {
|
---|
1364 | Bool rc = TRUE;
|
---|
1365 |
|
---|
1366 | TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
|
---|
1367 | #ifdef VBOXVIDEO_13
|
---|
1368 | rc = xf86SetSingleMode(pScrn, pMode, RR_Rotate_0);
|
---|
1369 | #else
|
---|
1370 | setModeRandR11(pScrn, pMode, false, false, 0, 0);
|
---|
1371 | #endif
|
---|
1372 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1373 | return rc;
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | static void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
|
---|
1377 | { (void)pScrn; (void)x; (void)y; }
|
---|
1378 |
|
---|
1379 | static void VBOXFreeScreen(ScrnInfoPtr pScrn)
|
---|
1380 | {
|
---|
1381 | /* Destroy the VGA hardware record */
|
---|
1382 | vgaHWFreeHWRec(pScrn);
|
---|
1383 | /* And our private record */
|
---|
1384 | free(pScrn->driverPrivate);
|
---|
1385 | pScrn->driverPrivate = NULL;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | static Bool
|
---|
1389 | VBOXMapVidMem(ScrnInfoPtr pScrn)
|
---|
1390 | {
|
---|
1391 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1392 | Bool rc = TRUE;
|
---|
1393 |
|
---|
1394 | TRACE_ENTRY();
|
---|
1395 | if (!pVBox->base)
|
---|
1396 | {
|
---|
1397 | #ifdef PCIACCESS
|
---|
1398 | (void) pci_device_map_range(pVBox->pciInfo,
|
---|
1399 | pScrn->memPhysBase,
|
---|
1400 | pScrn->videoRam * 1024,
|
---|
1401 | PCI_DEV_MAP_FLAG_WRITABLE,
|
---|
1402 | & pVBox->base);
|
---|
1403 | #else
|
---|
1404 | pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
|
---|
1405 | VIDMEM_FRAMEBUFFER,
|
---|
1406 | pVBox->pciTag, pScrn->memPhysBase,
|
---|
1407 | (unsigned) pScrn->videoRam * 1024);
|
---|
1408 | #endif
|
---|
1409 | if (!pVBox->base)
|
---|
1410 | rc = FALSE;
|
---|
1411 | }
|
---|
1412 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1413 | return rc;
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | static void
|
---|
1417 | VBOXUnmapVidMem(ScrnInfoPtr pScrn)
|
---|
1418 | {
|
---|
1419 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1420 |
|
---|
1421 | TRACE_ENTRY();
|
---|
1422 | if (pVBox->base == NULL)
|
---|
1423 | return;
|
---|
1424 |
|
---|
1425 | #ifdef PCIACCESS
|
---|
1426 | (void) pci_device_unmap_range(pVBox->pciInfo,
|
---|
1427 | pVBox->base,
|
---|
1428 | pScrn->videoRam * 1024);
|
---|
1429 | #else
|
---|
1430 | xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
|
---|
1431 | (unsigned) pScrn->videoRam * 1024);
|
---|
1432 | #endif
|
---|
1433 | pVBox->base = NULL;
|
---|
1434 | TRACE_EXIT();
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | #ifndef VBOXVIDEO_13
|
---|
1438 | static Bool
|
---|
1439 | VBOXSaveScreen(ScreenPtr pScreen, int mode)
|
---|
1440 | {
|
---|
1441 | (void)pScreen; (void)mode;
|
---|
1442 | return TRUE;
|
---|
1443 | }
|
---|
1444 | #endif
|
---|
1445 |
|
---|
1446 | void
|
---|
1447 | VBOXSaveMode(ScrnInfoPtr pScrn)
|
---|
1448 | {
|
---|
1449 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1450 | vgaRegPtr vgaReg;
|
---|
1451 |
|
---|
1452 | TRACE_ENTRY();
|
---|
1453 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1454 | vgaHWSave(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1455 | pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth,
|
---|
1456 | &pVBox->cSavedHeight,
|
---|
1457 | &pVBox->cSavedPitch,
|
---|
1458 | &pVBox->cSavedBPP,
|
---|
1459 | &pVBox->fSavedFlags);
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | void
|
---|
1463 | VBOXRestoreMode(ScrnInfoPtr pScrn)
|
---|
1464 | {
|
---|
1465 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1466 | vgaRegPtr vgaReg;
|
---|
1467 |
|
---|
1468 | TRACE_ENTRY();
|
---|
1469 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1470 | vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1471 | if (pVBox->fSavedVBEMode)
|
---|
1472 | VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight,
|
---|
1473 | pVBox->cSavedPitch, pVBox->cSavedBPP,
|
---|
1474 | pVBox->fSavedFlags, 0, 0);
|
---|
1475 | else
|
---|
1476 | VBoxVideoDisableVBE();
|
---|
1477 | }
|
---|
1478 |
|
---|
1479 | #ifndef VBOXVIDEO_13
|
---|
1480 | static void
|
---|
1481 | VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode, int flags)
|
---|
1482 | {
|
---|
1483 | (void)pScrn; (void)mode; (void) flags;
|
---|
1484 | }
|
---|
1485 | #endif
|
---|