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