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