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