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