1 | /* $Id: $ */
|
---|
2 | /** @file
|
---|
3 | * Linux Additions X11 graphics driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | * --------------------------------------------------------------------
|
---|
17 | *
|
---|
18 | * This code is based on:
|
---|
19 | *
|
---|
20 | * X11 VESA driver
|
---|
21 | *
|
---|
22 | * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
|
---|
23 | *
|
---|
24 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
25 | * copy of this software and associated documentation files (the "Software"),
|
---|
26 | * to deal in the Software without restriction, including without limitation
|
---|
27 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
28 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
29 | * Software is furnished to do so, subject to the following conditions:
|
---|
30 | *
|
---|
31 | * The above copyright notice and this permission notice shall be included in
|
---|
32 | * all copies or substantial portions of the Software.
|
---|
33 | *
|
---|
34 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
35 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
36 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
37 | * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
38 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
---|
39 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
---|
40 | * SOFTWARE.
|
---|
41 | *
|
---|
42 | * Except as contained in this notice, the name of Conectiva Linux shall
|
---|
43 | * not be used in advertising or otherwise to promote the sale, use or other
|
---|
44 | * dealings in this Software without prior written authorization from
|
---|
45 | * Conectiva Linux.
|
---|
46 | *
|
---|
47 | * Authors: Paulo César Pereira de Andrade <[email protected]>
|
---|
48 | */
|
---|
49 |
|
---|
50 | #include "xorg-server.h"
|
---|
51 | #include "vboxvideo.h"
|
---|
52 | #include "version-generated.h"
|
---|
53 | #include "product-generated.h"
|
---|
54 | #include <xf86.h>
|
---|
55 |
|
---|
56 | /* All drivers initialising the SW cursor need this */
|
---|
57 | #include "mipointer.h"
|
---|
58 |
|
---|
59 | /* All drivers implementing backing store need this */
|
---|
60 | #include "mibstore.h"
|
---|
61 |
|
---|
62 | /* Colormap handling */
|
---|
63 | #include "micmap.h"
|
---|
64 | #include "xf86cmap.h"
|
---|
65 |
|
---|
66 | /* DPMS */
|
---|
67 | /* #define DPMS_SERVER
|
---|
68 | #include "extensions/dpms.h" */
|
---|
69 |
|
---|
70 | /* VGA hardware functions for setting and restoring text mode */
|
---|
71 | #include "vgaHW.h"
|
---|
72 |
|
---|
73 | /* X.org 1.3+ mode setting */
|
---|
74 | #define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
|
---|
75 | #include "xf86Crtc.h"
|
---|
76 | #include "xf86Modes.h"
|
---|
77 |
|
---|
78 | /* Mandatory functions */
|
---|
79 |
|
---|
80 | static const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid);
|
---|
81 | static void VBOXIdentify(int flags);
|
---|
82 | #ifndef PCIACCESS
|
---|
83 | static Bool VBOXProbe(DriverPtr drv, int flags);
|
---|
84 | #else
|
---|
85 | static Bool VBOXPciProbe(DriverPtr drv, int entity_num,
|
---|
86 | struct pci_device *dev, intptr_t match_data);
|
---|
87 | #endif
|
---|
88 | static Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags);
|
---|
89 | static Bool VBOXScreenInit(int Index, ScreenPtr pScreen, int argc,
|
---|
90 | char **argv);
|
---|
91 | static Bool VBOXEnterVT(int scrnIndex, int flags);
|
---|
92 | static void VBOXLeaveVT(int scrnIndex, int flags);
|
---|
93 | static Bool VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen);
|
---|
94 | static Bool VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags);
|
---|
95 | static ModeStatus VBOXValidMode(int scrn, DisplayModePtr p, Bool flag, int pass);
|
---|
96 | static Bool VBOXSetMode(ScrnInfoPtr pScrn, DisplayModePtr pMode);
|
---|
97 | static void VBOXAdjustFrame(int scrnIndex, int x, int y, int flags);
|
---|
98 | static void VBOXFreeScreen(int scrnIndex, int flags);
|
---|
99 | static void VBOXFreeRec(ScrnInfoPtr pScrn);
|
---|
100 |
|
---|
101 | /* locally used functions */
|
---|
102 | static Bool VBOXMapVidMem(ScrnInfoPtr pScrn);
|
---|
103 | static void VBOXUnmapVidMem(ScrnInfoPtr pScrn);
|
---|
104 | static Bool VBOXSaveRestore(ScrnInfoPtr pScrn,
|
---|
105 | vbeSaveRestoreFunction function);
|
---|
106 |
|
---|
107 | enum GenericTypes
|
---|
108 | {
|
---|
109 | CHIP_VBOX_GENERIC
|
---|
110 | };
|
---|
111 |
|
---|
112 | #ifdef PCIACCESS
|
---|
113 | static const struct pci_id_match vbox_device_match[] = {
|
---|
114 | {
|
---|
115 | VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY,
|
---|
116 | 0, 0, 0
|
---|
117 | },
|
---|
118 |
|
---|
119 | { 0, 0, 0 },
|
---|
120 | };
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | /* Supported chipsets */
|
---|
124 | static SymTabRec VBOXChipsets[] =
|
---|
125 | {
|
---|
126 | {VBOX_DEVICEID, "vbox"},
|
---|
127 | {-1, NULL}
|
---|
128 | };
|
---|
129 |
|
---|
130 | static PciChipsets VBOXPCIchipsets[] = {
|
---|
131 | { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA },
|
---|
132 | { -1, -1, RES_UNDEFINED },
|
---|
133 | };
|
---|
134 |
|
---|
135 | /*
|
---|
136 | * This contains the functions needed by the server after loading the
|
---|
137 | * driver module. It must be supplied, and gets added the driver list by
|
---|
138 | * the Module Setup funtion in the dynamic case. In the static case a
|
---|
139 | * reference to this is compiled in, and this requires that the name of
|
---|
140 | * this DriverRec be an upper-case version of the driver name.
|
---|
141 | */
|
---|
142 |
|
---|
143 | _X_EXPORT DriverRec VBOXVIDEO = {
|
---|
144 | VBOX_VERSION,
|
---|
145 | VBOX_DRIVER_NAME,
|
---|
146 | VBOXIdentify,
|
---|
147 | #ifdef PCIACCESS
|
---|
148 | NULL,
|
---|
149 | #else
|
---|
150 | VBOXProbe,
|
---|
151 | #endif
|
---|
152 | VBOXAvailableOptions,
|
---|
153 | NULL,
|
---|
154 | 0,
|
---|
155 | NULL,
|
---|
156 |
|
---|
157 | #ifdef PCIACCESS
|
---|
158 | vbox_device_match,
|
---|
159 | VBOXPciProbe
|
---|
160 | #endif
|
---|
161 | };
|
---|
162 |
|
---|
163 | /* No options for now */
|
---|
164 | static const OptionInfoRec VBOXOptions[] = {
|
---|
165 | { -1, NULL, OPTV_NONE, {0}, FALSE }
|
---|
166 | };
|
---|
167 |
|
---|
168 | static VBOXPtr
|
---|
169 | VBOXGetRec(ScrnInfoPtr pScrn)
|
---|
170 | {
|
---|
171 | if (!pScrn->driverPrivate) {
|
---|
172 | pScrn->driverPrivate = xcalloc(sizeof(VBOXRec), 1);
|
---|
173 | }
|
---|
174 |
|
---|
175 | return ((VBOXPtr)pScrn->driverPrivate);
|
---|
176 | }
|
---|
177 |
|
---|
178 | static void
|
---|
179 | VBOXFreeRec(ScrnInfoPtr pScrn)
|
---|
180 | {
|
---|
181 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
182 | xfree(pVBox->savedPal);
|
---|
183 | xfree(pVBox->fonts);
|
---|
184 | xfree(pScrn->driverPrivate);
|
---|
185 | pScrn->driverPrivate = NULL;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* X.org 1.3+ mode-setting support ******************************************/
|
---|
189 |
|
---|
190 | /* For descriptions of these functions and structures, see
|
---|
191 | hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
|
---|
192 | X.Org source tree. */
|
---|
193 |
|
---|
194 | static Bool
|
---|
195 | VBOXCrtcResize(ScrnInfoPtr scrn, int width, int height)
|
---|
196 | {
|
---|
197 | int bpp = scrn->bitsPerPixel;
|
---|
198 | ScreenPtr pScreen = scrn->pScreen;
|
---|
199 | PixmapPtr pPixmap = NULL;
|
---|
200 | VBOXPtr pVBox = VBOXGetRec(scrn);
|
---|
201 | Bool rc = TRUE;
|
---|
202 |
|
---|
203 | TRACE_LOG("width=%d, height=%d\n", width, height);
|
---|
204 | /* We only support horizontal resolutions which are a multiple of 8.
|
---|
205 | * Round up if necessary. */
|
---|
206 | width = (width + 7) & ~7;
|
---|
207 | if (width * height * bpp / 8 >= scrn->videoRam * 1024)
|
---|
208 | {
|
---|
209 | xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
---|
210 | "Unable to set up a virtual screen size of %dx%d with %d Kb of video memory. Please increase the video memory size.\n",
|
---|
211 | width, height, scrn->videoRam);
|
---|
212 | rc = FALSE;
|
---|
213 | }
|
---|
214 | if (rc) {
|
---|
215 | pPixmap = pScreen->GetScreenPixmap(pScreen);
|
---|
216 | if (NULL == pPixmap) {
|
---|
217 | xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
---|
218 | "Failed to get the screen pixmap.\n");
|
---|
219 | rc = FALSE;
|
---|
220 | }
|
---|
221 | }
|
---|
222 | if (rc) {
|
---|
223 | if (
|
---|
224 | !pScreen->ModifyPixmapHeader(pPixmap, width, height,
|
---|
225 | scrn->depth, bpp, width * bpp / 8,
|
---|
226 | pVBox->base)
|
---|
227 | ) {
|
---|
228 | xf86DrvMsg(scrn->scrnIndex, X_ERROR,
|
---|
229 | "Failed to set up the screen pixmap.\n");
|
---|
230 | rc = FALSE;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | if (rc) {
|
---|
234 | scrn->virtualX = width;
|
---|
235 | scrn->virtualY = height;
|
---|
236 | scrn->displayWidth = width;
|
---|
237 | #ifdef VBOX_DRI
|
---|
238 | if (pVBox->useDRI)
|
---|
239 | VBOXDRIUpdateStride(scrn, pVBox);
|
---|
240 | #endif
|
---|
241 | /* Write the new values to the hardware */
|
---|
242 | rc = xf86SetDesiredModes(scrn);
|
---|
243 | }
|
---|
244 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
245 | return rc;
|
---|
246 | }
|
---|
247 |
|
---|
248 | static const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
|
---|
249 | VBOXCrtcResize
|
---|
250 | };
|
---|
251 |
|
---|
252 | static void
|
---|
253 | vbox_crtc_dpms(xf86CrtcPtr crtc, int mode)
|
---|
254 | { (void) crtc; (void) mode; }
|
---|
255 |
|
---|
256 | static Bool
|
---|
257 | vbox_crtc_lock (xf86CrtcPtr crtc)
|
---|
258 | { (void) crtc; return FALSE; }
|
---|
259 |
|
---|
260 | static Bool
|
---|
261 | vbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
262 | DisplayModePtr adjusted_mode)
|
---|
263 | {
|
---|
264 | ScrnInfoPtr pScrn = crtc->scrn;
|
---|
265 | int xRes = adjusted_mode->HDisplay;
|
---|
266 |
|
---|
267 | (void) mode;
|
---|
268 | TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d\n", adjusted_mode->name,
|
---|
269 | adjusted_mode->HDisplay, adjusted_mode->VDisplay);
|
---|
270 | /* We only support horizontal resolutions which are a multiple of 8. Round down if
|
---|
271 | necessary. */
|
---|
272 | if (xRes % 8 != 0)
|
---|
273 | {
|
---|
274 | xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
|
---|
275 | "VirtualBox only supports screen widths which are a multiple of 8. Rounding down from %d to %d\n",
|
---|
276 | xRes, xRes - (xRes % 8));
|
---|
277 | adjusted_mode->HDisplay = xRes - (xRes % 8);
|
---|
278 | }
|
---|
279 | return TRUE;
|
---|
280 | }
|
---|
281 |
|
---|
282 | static void
|
---|
283 | vbox_crtc_stub (xf86CrtcPtr crtc)
|
---|
284 | { (void) crtc; }
|
---|
285 |
|
---|
286 | static void
|
---|
287 | vbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
288 | DisplayModePtr adjusted_mode, int x, int y)
|
---|
289 | {
|
---|
290 | (void) mode;
|
---|
291 | TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
|
---|
292 | adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y);
|
---|
293 | VBOXSetMode(crtc->scrn, adjusted_mode);
|
---|
294 | VBOXAdjustFrame(crtc->scrn->scrnIndex, x, y, 0);
|
---|
295 | /* Don't remember any modes set while we are seamless, as they are
|
---|
296 | * just temporary. */
|
---|
297 | if (!vboxGuestIsSeamless(crtc->scrn))
|
---|
298 | vboxSaveVideoMode(crtc->scrn, adjusted_mode->HDisplay,
|
---|
299 | adjusted_mode->VDisplay, crtc->scrn->bitsPerPixel);
|
---|
300 | }
|
---|
301 |
|
---|
302 | static void
|
---|
303 | vbox_crtc_gamma_set (xf86CrtcPtr crtc, CARD16 *red,
|
---|
304 | CARD16 *green, CARD16 *blue, int size)
|
---|
305 | { (void) crtc; (void) red; (void) green; (void) blue; (void) size; }
|
---|
306 |
|
---|
307 | static void *
|
---|
308 | vbox_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
|
---|
309 | { (void) crtc; (void) width; (void) height; return NULL; }
|
---|
310 |
|
---|
311 | static const xf86CrtcFuncsRec VBOXCrtcFuncs = {
|
---|
312 | .dpms = vbox_crtc_dpms,
|
---|
313 | .save = NULL, /* These two are never called by the server. */
|
---|
314 | .restore = NULL,
|
---|
315 | .lock = vbox_crtc_lock,
|
---|
316 | .unlock = NULL, /* This will not be invoked if lock returns FALSE. */
|
---|
317 | .mode_fixup = vbox_crtc_mode_fixup,
|
---|
318 | .prepare = vbox_crtc_stub,
|
---|
319 | .mode_set = vbox_crtc_mode_set,
|
---|
320 | .commit = vbox_crtc_stub,
|
---|
321 | .gamma_set = vbox_crtc_gamma_set,
|
---|
322 | .shadow_allocate = vbox_crtc_shadow_allocate,
|
---|
323 | .shadow_create = NULL, /* These two should not be invoked if allocate
|
---|
324 | returns NULL. */
|
---|
325 | .shadow_destroy = NULL,
|
---|
326 | .set_cursor_colors = NULL, /* We are still using the old cursor API. */
|
---|
327 | .set_cursor_position = NULL,
|
---|
328 | .show_cursor = NULL,
|
---|
329 | .hide_cursor = NULL,
|
---|
330 | .load_cursor_argb = NULL,
|
---|
331 | .destroy = vbox_crtc_stub
|
---|
332 | };
|
---|
333 |
|
---|
334 | static void
|
---|
335 | vbox_output_stub (xf86OutputPtr output)
|
---|
336 | { (void) output; }
|
---|
337 |
|
---|
338 | static void
|
---|
339 | vbox_output_dpms (xf86OutputPtr output, int mode)
|
---|
340 | { (void) output; (void) mode; }
|
---|
341 |
|
---|
342 | static int
|
---|
343 | vbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode)
|
---|
344 | {
|
---|
345 | ScrnInfoPtr pScrn = output->scrn;
|
---|
346 | int rc = MODE_OK;
|
---|
347 | TRACE_LOG("HDisplay=%d, VDisplay=%d\n", mode->HDisplay, mode->VDisplay);
|
---|
348 | /* We always like modes specified by the user in the configuration
|
---|
349 | * file and modes requested by the host, as doing otherwise is likely to
|
---|
350 | * annoy people. */
|
---|
351 | if ( !(mode->type & M_T_USERDEF)
|
---|
352 | && !(mode->type & M_T_PREFERRED)
|
---|
353 | && vbox_device_available(VBOXGetRec(pScrn))
|
---|
354 | && !vboxHostLikesVideoMode(pScrn, mode->HDisplay, mode->VDisplay,
|
---|
355 | pScrn->bitsPerPixel)
|
---|
356 | )
|
---|
357 | rc = MODE_BAD;
|
---|
358 | TRACE_LOG("returning %s\n", MODE_OK == rc ? "MODE_OK" : "MODE_BAD");
|
---|
359 | return rc;
|
---|
360 | }
|
---|
361 |
|
---|
362 | static Bool
|
---|
363 | vbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode,
|
---|
364 | DisplayModePtr adjusted_mode)
|
---|
365 | { (void) output; (void) mode; (void) adjusted_mode; return TRUE; }
|
---|
366 |
|
---|
367 | static void
|
---|
368 | vbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode,
|
---|
369 | DisplayModePtr adjusted_mode)
|
---|
370 | { (void) output; (void) mode; (void) adjusted_mode; }
|
---|
371 |
|
---|
372 | /* A virtual monitor is always connected. */
|
---|
373 | static xf86OutputStatus
|
---|
374 | vbox_output_detect (xf86OutputPtr output)
|
---|
375 | {
|
---|
376 | (void) output;
|
---|
377 | return XF86OutputStatusConnected;
|
---|
378 | }
|
---|
379 |
|
---|
380 | static void
|
---|
381 | vbox_output_add_mode (DisplayModePtr *pModes, const char *pszName, int x, int y,
|
---|
382 | Bool isPreferred, Bool isUserDef)
|
---|
383 | {
|
---|
384 | TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName, x, y);
|
---|
385 | DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
|
---|
386 |
|
---|
387 | pMode->status = MODE_OK;
|
---|
388 | /* We don't ask the host whether it likes user defined modes,
|
---|
389 | * as we assume that the user really wanted that mode. */
|
---|
390 | pMode->type = isUserDef ? M_T_USERDEF : M_T_BUILTIN;
|
---|
391 | if (isPreferred)
|
---|
392 | pMode->type |= M_T_PREFERRED;
|
---|
393 | /* VBox only supports screen widths which are a multiple of 8 */
|
---|
394 | pMode->HDisplay = (x + 7) & ~7;
|
---|
395 | pMode->HSyncStart = pMode->HDisplay + 2;
|
---|
396 | pMode->HSyncEnd = pMode->HDisplay + 4;
|
---|
397 | pMode->HTotal = pMode->HDisplay + 6;
|
---|
398 | pMode->VDisplay = y;
|
---|
399 | pMode->VSyncStart = pMode->VDisplay + 2;
|
---|
400 | pMode->VSyncEnd = pMode->VDisplay + 4;
|
---|
401 | pMode->VTotal = pMode->VDisplay + 6;
|
---|
402 | pMode->Clock = pMode->HTotal * pMode->VTotal * 60 / 1000; /* kHz */
|
---|
403 | if (NULL == pszName) {
|
---|
404 | xf86SetModeDefaultName(pMode);
|
---|
405 | } else {
|
---|
406 | pMode->name = xnfstrdup(pszName);
|
---|
407 | }
|
---|
408 | *pModes = xf86ModesAdd(*pModes, pMode);
|
---|
409 | }
|
---|
410 |
|
---|
411 | static DisplayModePtr
|
---|
412 | vbox_output_get_modes (xf86OutputPtr output)
|
---|
413 | {
|
---|
414 | bool rc;
|
---|
415 | unsigned i;
|
---|
416 | DisplayModePtr pModes = NULL;
|
---|
417 | ScrnInfoPtr pScrn = output->scrn;
|
---|
418 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
419 |
|
---|
420 | TRACE_ENTRY();
|
---|
421 | if (vbox_device_available(pVBox))
|
---|
422 | {
|
---|
423 | uint32_t x, y, bpp, iScreen;
|
---|
424 | rc = vboxGetDisplayChangeRequest(pScrn, &x, &y, &bpp, &iScreen);
|
---|
425 | /* @todo - check the display number once we support multiple displays. */
|
---|
426 | /* If we don't find a display request, see if we have a saved hint
|
---|
427 | * from a previous session. */
|
---|
428 | if (!rc || (0 == x) || (0 == y))
|
---|
429 | rc = vboxRetrieveVideoMode(pScrn, &x, &y, &bpp);
|
---|
430 | if (rc && (0 != x) && (0 != y)) {
|
---|
431 | /* We prefer a slightly smaller size to a slightly larger one */
|
---|
432 | x -= (x % 8);
|
---|
433 | vbox_output_add_mode(&pModes, NULL, x, y, TRUE, FALSE);
|
---|
434 | }
|
---|
435 | }
|
---|
436 | /* Also report any modes the user may have requested in the xorg.conf
|
---|
437 | * configuration file. */
|
---|
438 | for (i = 0; pScrn->display->modes[i] != NULL; i++)
|
---|
439 | {
|
---|
440 | int x, y;
|
---|
441 | if (2 == sscanf(pScrn->display->modes[i], "%dx%d", &x, &y))
|
---|
442 | vbox_output_add_mode(&pModes, pScrn->display->modes[i], x, y,
|
---|
443 | FALSE, TRUE);
|
---|
444 | }
|
---|
445 | TRACE_EXIT();
|
---|
446 | return pModes;
|
---|
447 | }
|
---|
448 |
|
---|
449 | #ifdef RANDR_12_INTERFACE
|
---|
450 | /* We don't yet have mutable properties, whatever they are. */
|
---|
451 | static Bool
|
---|
452 | vbox_output_set_property(xf86OutputPtr output, Atom property,
|
---|
453 | RRPropertyValuePtr value)
|
---|
454 | { (void) output; (void) property; (void) value; return FALSE; }
|
---|
455 | #endif
|
---|
456 |
|
---|
457 | static const xf86OutputFuncsRec VBOXOutputFuncs = {
|
---|
458 | .create_resources = vbox_output_stub,
|
---|
459 | .dpms = vbox_output_dpms,
|
---|
460 | .save = NULL, /* These two are never called by the server. */
|
---|
461 | .restore = NULL,
|
---|
462 | .mode_valid = vbox_output_mode_valid,
|
---|
463 | .mode_fixup = vbox_output_mode_fixup,
|
---|
464 | .prepare = vbox_output_stub,
|
---|
465 | .commit = vbox_output_stub,
|
---|
466 | .mode_set = vbox_output_mode_set,
|
---|
467 | .detect = vbox_output_detect,
|
---|
468 | .get_modes = vbox_output_get_modes,
|
---|
469 | #ifdef RANDR_12_INTERFACE
|
---|
470 | .set_property = vbox_output_set_property,
|
---|
471 | #endif
|
---|
472 | .destroy = vbox_output_stub
|
---|
473 | };
|
---|
474 |
|
---|
475 | #ifdef XFree86LOADER
|
---|
476 | /* Module loader interface */
|
---|
477 | static MODULESETUPPROTO(vboxSetup);
|
---|
478 |
|
---|
479 | static XF86ModuleVersionInfo vboxVersionRec =
|
---|
480 | {
|
---|
481 | VBOX_DRIVER_NAME,
|
---|
482 | VBOX_VENDOR,
|
---|
483 | MODINFOSTRING1,
|
---|
484 | MODINFOSTRING2,
|
---|
485 | XORG_VERSION_CURRENT,
|
---|
486 | 1, /* Module major version. Xorg-specific */
|
---|
487 | 0, /* Module minor version. Xorg-specific */
|
---|
488 | 1, /* Module patchlevel. Xorg-specific */
|
---|
489 | ABI_CLASS_VIDEODRV, /* This is a video driver */
|
---|
490 | ABI_VIDEODRV_VERSION,
|
---|
491 | MOD_CLASS_VIDEODRV,
|
---|
492 | {0, 0, 0, 0}
|
---|
493 | };
|
---|
494 |
|
---|
495 | /*
|
---|
496 | * This data is accessed by the loader. The name must be the module name
|
---|
497 | * followed by "ModuleData".
|
---|
498 | */
|
---|
499 | _X_EXPORT XF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
|
---|
500 |
|
---|
501 | static pointer
|
---|
502 | vboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
|
---|
503 | {
|
---|
504 | static Bool Initialised = FALSE;
|
---|
505 |
|
---|
506 | if (!Initialised)
|
---|
507 | {
|
---|
508 | Initialised = TRUE;
|
---|
509 | #ifdef PCIACCESS
|
---|
510 | xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs);
|
---|
511 | #else
|
---|
512 | xf86AddDriver(&VBOXVIDEO, Module, 0);
|
---|
513 | #endif
|
---|
514 | xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n",
|
---|
515 | (void *)&VBOXVIDEO);
|
---|
516 | return (pointer)TRUE;
|
---|
517 | }
|
---|
518 |
|
---|
519 | if (ErrorMajor)
|
---|
520 | *ErrorMajor = LDR_ONCEONLY;
|
---|
521 | return (NULL);
|
---|
522 | }
|
---|
523 |
|
---|
524 | #endif /* XFree86Loader defined */
|
---|
525 |
|
---|
526 | static const OptionInfoRec *
|
---|
527 | VBOXAvailableOptions(int chipid, int busid)
|
---|
528 | {
|
---|
529 | return (VBOXOptions);
|
---|
530 | }
|
---|
531 |
|
---|
532 | static void
|
---|
533 | VBOXIdentify(int flags)
|
---|
534 | {
|
---|
535 | xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
|
---|
536 | }
|
---|
537 |
|
---|
538 | /*
|
---|
539 | * This function is called once, at the start of the first server generation to
|
---|
540 | * do a minimal probe for supported hardware.
|
---|
541 | */
|
---|
542 |
|
---|
543 | #ifdef PCIACCESS
|
---|
544 | static Bool
|
---|
545 | VBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
|
---|
546 | intptr_t match_data)
|
---|
547 | {
|
---|
548 | ScrnInfoPtr pScrn;
|
---|
549 |
|
---|
550 | TRACE_ENTRY();
|
---|
551 | pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
|
---|
552 | NULL, NULL, NULL, NULL, NULL);
|
---|
553 | if (pScrn != NULL) {
|
---|
554 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
555 |
|
---|
556 | pScrn->driverVersion = VBOX_VERSION;
|
---|
557 | pScrn->driverName = VBOX_DRIVER_NAME;
|
---|
558 | pScrn->name = VBOX_NAME;
|
---|
559 | pScrn->Probe = NULL;
|
---|
560 | pScrn->PreInit = VBOXPreInit;
|
---|
561 | pScrn->ScreenInit = VBOXScreenInit;
|
---|
562 | pScrn->SwitchMode = VBOXSwitchMode;
|
---|
563 | pScrn->ValidMode = VBOXValidMode;
|
---|
564 | pScrn->AdjustFrame = VBOXAdjustFrame;
|
---|
565 | pScrn->EnterVT = VBOXEnterVT;
|
---|
566 | pScrn->LeaveVT = VBOXLeaveVT;
|
---|
567 | pScrn->FreeScreen = VBOXFreeScreen;
|
---|
568 |
|
---|
569 | pVBox->pciInfo = dev;
|
---|
570 | }
|
---|
571 |
|
---|
572 | TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
|
---|
573 | return (pScrn != NULL);
|
---|
574 | }
|
---|
575 | #endif
|
---|
576 |
|
---|
577 | #ifndef PCIACCESS
|
---|
578 | static Bool
|
---|
579 | VBOXProbe(DriverPtr drv, int flags)
|
---|
580 | {
|
---|
581 | Bool foundScreen = FALSE;
|
---|
582 | int numDevSections;
|
---|
583 | GDevPtr *devSections;
|
---|
584 |
|
---|
585 | /*
|
---|
586 | * Find the config file Device sections that match this
|
---|
587 | * driver, and return if there are none.
|
---|
588 | */
|
---|
589 | if ((numDevSections = xf86MatchDevice(VBOX_NAME,
|
---|
590 | &devSections)) <= 0)
|
---|
591 | return (FALSE);
|
---|
592 |
|
---|
593 | /* PCI BUS */
|
---|
594 | if (xf86GetPciVideoInfo()) {
|
---|
595 | int numUsed;
|
---|
596 | int *usedChips;
|
---|
597 | int i;
|
---|
598 | numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
|
---|
599 | VBOXChipsets, VBOXPCIchipsets,
|
---|
600 | devSections, numDevSections,
|
---|
601 | drv, &usedChips);
|
---|
602 | if (numUsed > 0) {
|
---|
603 | if (flags & PROBE_DETECT)
|
---|
604 | foundScreen = TRUE;
|
---|
605 | else {
|
---|
606 | for (i = 0; i < numUsed; i++) {
|
---|
607 | ScrnInfoPtr pScrn = NULL;
|
---|
608 | /* Allocate a ScrnInfoRec */
|
---|
609 | if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
|
---|
610 | VBOXPCIchipsets,NULL,
|
---|
611 | NULL,NULL,NULL,NULL))) {
|
---|
612 | pScrn->driverVersion = VBOX_VERSION;
|
---|
613 | pScrn->driverName = VBOX_DRIVER_NAME;
|
---|
614 | pScrn->name = VBOX_NAME;
|
---|
615 | pScrn->Probe = VBOXProbe;
|
---|
616 | pScrn->PreInit = VBOXPreInit;
|
---|
617 | pScrn->ScreenInit = VBOXScreenInit;
|
---|
618 | pScrn->SwitchMode = VBOXSwitchMode;
|
---|
619 | pScrn->ValidMode = VBOXValidMode;
|
---|
620 | pScrn->AdjustFrame = VBOXAdjustFrame;
|
---|
621 | pScrn->EnterVT = VBOXEnterVT;
|
---|
622 | pScrn->LeaveVT = VBOXLeaveVT;
|
---|
623 | pScrn->FreeScreen = VBOXFreeScreen;
|
---|
624 | foundScreen = TRUE;
|
---|
625 | }
|
---|
626 | }
|
---|
627 | }
|
---|
628 | xfree(usedChips);
|
---|
629 | }
|
---|
630 | }
|
---|
631 |
|
---|
632 | xfree(devSections);
|
---|
633 |
|
---|
634 | return (foundScreen);
|
---|
635 | }
|
---|
636 | #endif
|
---|
637 |
|
---|
638 | /*
|
---|
639 | * QUOTE from the XFree86 DESIGN document:
|
---|
640 | *
|
---|
641 | * The purpose of this function is to find out all the information
|
---|
642 | * required to determine if the configuration is usable, and to initialise
|
---|
643 | * those parts of the ScrnInfoRec that can be set once at the beginning of
|
---|
644 | * the first server generation.
|
---|
645 | *
|
---|
646 | * (...)
|
---|
647 | *
|
---|
648 | * This includes probing for video memory, clocks, ramdac, and all other
|
---|
649 | * HW info that is needed. It includes determining the depth/bpp/visual
|
---|
650 | * and related info. It includes validating and determining the set of
|
---|
651 | * video modes that will be used (and anything that is required to
|
---|
652 | * determine that).
|
---|
653 | *
|
---|
654 | * This information should be determined in the least intrusive way
|
---|
655 | * possible. The state of the HW must remain unchanged by this function.
|
---|
656 | * Although video memory (including MMIO) may be mapped within this
|
---|
657 | * function, it must be unmapped before returning.
|
---|
658 | *
|
---|
659 | * END QUOTE
|
---|
660 | */
|
---|
661 |
|
---|
662 | static Bool
|
---|
663 | VBOXPreInit(ScrnInfoPtr pScrn, int flags)
|
---|
664 | {
|
---|
665 | VBOXPtr pVBox;
|
---|
666 | Gamma gzeros = {0.0, 0.0, 0.0};
|
---|
667 | rgb rzeros = {0, 0, 0};
|
---|
668 | xf86OutputPtr output;
|
---|
669 |
|
---|
670 | /* Are we really starting the server, or is this just a dummy run? */
|
---|
671 | if (flags & PROBE_DETECT)
|
---|
672 | return (FALSE);
|
---|
673 |
|
---|
674 | xf86DrvMsg(pScrn->scrnIndex, X_INFO,
|
---|
675 | "VirtualBox guest additions video driver version "
|
---|
676 | VBOX_VERSION_STRING "\n");
|
---|
677 |
|
---|
678 | /* Get our private data from the ScrnInfoRec structure. */
|
---|
679 | pVBox = VBOXGetRec(pScrn);
|
---|
680 |
|
---|
681 | /* Initialise the guest library */
|
---|
682 | vbox_init(pScrn->scrnIndex, pVBox);
|
---|
683 |
|
---|
684 | /* Entity information seems to mean bus information. */
|
---|
685 | pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
|
---|
686 |
|
---|
687 | /* We need the vbe module because we use VBE code to save and restore
|
---|
688 | text mode, in order to keep our code simple. */
|
---|
689 | if (!xf86LoadSubModule(pScrn, "vbe"))
|
---|
690 | return (FALSE);
|
---|
691 |
|
---|
692 | if ((pVBox->pVbe = VBEExtendedInit(NULL, pVBox->pEnt->index,
|
---|
693 | SET_BIOS_SCRATCH
|
---|
694 | | RESTORE_BIOS_SCRATCH)) == NULL)
|
---|
695 | return (FALSE);
|
---|
696 |
|
---|
697 | #ifndef PCIACCESS
|
---|
698 | if (pVBox->pEnt->location.type != BUS_PCI)
|
---|
699 | return FALSE;
|
---|
700 |
|
---|
701 | pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
|
---|
702 | pVBox->pciTag = pciTag(pVBox->pciInfo->bus,
|
---|
703 | pVBox->pciInfo->device,
|
---|
704 | pVBox->pciInfo->func);
|
---|
705 | #endif
|
---|
706 |
|
---|
707 | /* The ramdac module is needed for the hardware cursor. */
|
---|
708 | if (!xf86LoadSubModule(pScrn, "ramdac"))
|
---|
709 | return FALSE;
|
---|
710 |
|
---|
711 | /* The framebuffer module. */
|
---|
712 | if (xf86LoadSubModule(pScrn, "fb") == NULL)
|
---|
713 | return (FALSE);
|
---|
714 |
|
---|
715 | if (!xf86LoadSubModule(pScrn, "shadowfb"))
|
---|
716 | return FALSE;
|
---|
717 |
|
---|
718 | if (!xf86LoadSubModule(pScrn, "vgahw"))
|
---|
719 | return FALSE;
|
---|
720 |
|
---|
721 | /* Set up our ScrnInfoRec structure to describe our virtual
|
---|
722 | capabilities to X. */
|
---|
723 |
|
---|
724 | pScrn->chipset = "vbox";
|
---|
725 |
|
---|
726 | /* This *is* still needed, at least for server version 1.3 */
|
---|
727 | pScrn->monitor = pScrn->confScreen->monitor;
|
---|
728 |
|
---|
729 | pScrn->progClock = TRUE;
|
---|
730 | pScrn->rgbBits = 8;
|
---|
731 |
|
---|
732 | /* Using the PCI information caused problems with non-powers-of-two
|
---|
733 | sized video RAM configurations */
|
---|
734 | pScrn->videoRam = inl(VBE_DISPI_IOPORT_DATA) / 1024;
|
---|
735 |
|
---|
736 | /* Query the host for the preferred colour depth */
|
---|
737 | {
|
---|
738 | uint32_t cx, cy, iDisplay, cBits = 24;
|
---|
739 |
|
---|
740 | if (vbox_device_available(pVBox))
|
---|
741 | {
|
---|
742 | /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
|
---|
743 | if ( vboxGetDisplayChangeRequest(pScrn, &cx, &cy, &cBits,
|
---|
744 | &iDisplay)
|
---|
745 | && (cBits != 16)
|
---|
746 | )
|
---|
747 | cBits = 24;
|
---|
748 | }
|
---|
749 | if (!xf86SetDepthBpp(pScrn, cBits, 0, 0, Support32bppFb))
|
---|
750 | return FALSE;
|
---|
751 | }
|
---|
752 | if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
|
---|
753 | {
|
---|
754 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
755 | "The VBox additions only support 16 and 32bpp graphics modes\n");
|
---|
756 | return FALSE;
|
---|
757 | }
|
---|
758 | xf86PrintDepthBpp(pScrn);
|
---|
759 |
|
---|
760 | /* options */
|
---|
761 | xf86CollectOptions(pScrn, NULL);
|
---|
762 | if (!(pVBox->Options = xalloc(sizeof(VBOXOptions))))
|
---|
763 | return FALSE;
|
---|
764 | memcpy(pVBox->Options, VBOXOptions, sizeof(VBOXOptions));
|
---|
765 | xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pVBox->Options);
|
---|
766 |
|
---|
767 | /* Work around a bug in the original X server modesetting code, which
|
---|
768 | * took the first valid values set to these two as maxima over the
|
---|
769 | * server lifetime. */
|
---|
770 | pScrn->virtualX = 32000;
|
---|
771 | pScrn->virtualY = 32000;
|
---|
772 |
|
---|
773 | /* Initialise CRTC and output configuration for use with randr1.2. */
|
---|
774 | xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs);
|
---|
775 |
|
---|
776 | /* Setup our single virtual CRTC. */
|
---|
777 | xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
|
---|
778 |
|
---|
779 | /* Set up our single virtual output. */
|
---|
780 | output = xf86OutputCreate(pScrn, &VBOXOutputFuncs, "VBOX1");
|
---|
781 |
|
---|
782 | /* Set a sane minimum and maximum mode size */
|
---|
783 | xf86CrtcSetSizeRange(pScrn, 64, 64, 32000, 32000);
|
---|
784 |
|
---|
785 | /* We are not interested in the monitor section in the configuration file. */
|
---|
786 | xf86OutputUseScreenMonitor(output, FALSE);
|
---|
787 | output->possible_crtcs = 1;
|
---|
788 | output->possible_clones = 0;
|
---|
789 |
|
---|
790 | /* Now create our initial CRTC/output configuration. */
|
---|
791 | if (!xf86InitialConfiguration(pScrn, TRUE)) {
|
---|
792 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
|
---|
793 | return (FALSE);
|
---|
794 | }
|
---|
795 |
|
---|
796 | /* Colour weight - we always call this, since we are always in
|
---|
797 | truecolour. */
|
---|
798 | if (!xf86SetWeight(pScrn, rzeros, rzeros))
|
---|
799 | return (FALSE);
|
---|
800 |
|
---|
801 | /* visual init */
|
---|
802 | if (!xf86SetDefaultVisual(pScrn, -1))
|
---|
803 | return (FALSE);
|
---|
804 |
|
---|
805 | xf86SetGamma(pScrn, gzeros);
|
---|
806 |
|
---|
807 | /* Set a default display resolution. */
|
---|
808 | xf86SetDpi(pScrn, 96, 96);
|
---|
809 |
|
---|
810 | /* Framebuffer-related setup */
|
---|
811 | pScrn->bitmapBitOrder = BITMAP_BIT_ORDER;
|
---|
812 |
|
---|
813 | /* VGA hardware initialisation */
|
---|
814 | if (!vgaHWGetHWRec(pScrn))
|
---|
815 | return FALSE;
|
---|
816 |
|
---|
817 | #ifdef VBOX_DRI
|
---|
818 | /* Load the dri module. */
|
---|
819 | if (!xf86LoadSubModule(pScrn, "dri"))
|
---|
820 | return FALSE;
|
---|
821 | #endif
|
---|
822 | return (TRUE);
|
---|
823 | }
|
---|
824 |
|
---|
825 | /**
|
---|
826 | * This function hooks into the chain that is called when framebuffer access
|
---|
827 | * is allowed or disallowed by a call to EnableDisableFBAccess in the server.
|
---|
828 | * In other words, it observes when the server wishes access to the
|
---|
829 | * framebuffer to be enabled and when it should be disabled. We need to know
|
---|
830 | * this because we disable access ourselves during mode switches (presumably
|
---|
831 | * the server should do this but it doesn't) and want to know whether to
|
---|
832 | * restore it or not afterwards.
|
---|
833 | */
|
---|
834 | static void
|
---|
835 | vboxEnableDisableFBAccess(int scrnIndex, Bool enable)
|
---|
836 | {
|
---|
837 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
838 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
839 |
|
---|
840 | TRACE_LOG("enable=%s\n", enable ? "TRUE" : "FALSE");
|
---|
841 | pVBox->accessEnabled = enable;
|
---|
842 | pVBox->EnableDisableFBAccess(scrnIndex, enable);
|
---|
843 | TRACE_EXIT();
|
---|
844 | }
|
---|
845 |
|
---|
846 | /*
|
---|
847 | * QUOTE from the XFree86 DESIGN document:
|
---|
848 | *
|
---|
849 | * This is called at the start of each server generation.
|
---|
850 | *
|
---|
851 | * (...)
|
---|
852 | *
|
---|
853 | * Decide which operations need to be placed under resource access
|
---|
854 | * control. (...) Map any video memory or other memory regions. (...)
|
---|
855 | * Save the video card state. (...) Initialise the initial video
|
---|
856 | * mode.
|
---|
857 | *
|
---|
858 | * End QUOTE.Initialise the initial video mode.
|
---|
859 | */
|
---|
860 | static Bool
|
---|
861 | VBOXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
|
---|
862 | {
|
---|
863 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
864 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
865 | VisualPtr visual;
|
---|
866 | unsigned flags;
|
---|
867 |
|
---|
868 | if (pVBox->mapPhys == 0) {
|
---|
869 | #ifdef PCIACCESS
|
---|
870 | pVBox->mapPhys = pVBox->pciInfo->regions[0].base_addr;
|
---|
871 | #else
|
---|
872 | pVBox->mapPhys = pVBox->pciInfo->memBase[0];
|
---|
873 | #endif
|
---|
874 | /* pVBox->mapSize = 1 << pVBox->pciInfo->size[0]; */
|
---|
875 | /* Using the PCI information caused problems with
|
---|
876 | non-powers-of-two sized video RAM configurations */
|
---|
877 | pVBox->mapSize = inl(VBE_DISPI_IOPORT_DATA);
|
---|
878 | pVBox->mapOff = 0;
|
---|
879 | }
|
---|
880 |
|
---|
881 | if (!VBOXMapVidMem(pScrn))
|
---|
882 | return (FALSE);
|
---|
883 |
|
---|
884 | /* save current video state */
|
---|
885 | VBOXSaveRestore(pScrn, MODE_SAVE);
|
---|
886 | pVBox->savedPal = VBESetGetPaletteData(pVBox->pVbe, FALSE, 0, 256,
|
---|
887 | NULL, FALSE, FALSE);
|
---|
888 |
|
---|
889 | /* mi layer - reset the visual list (?)*/
|
---|
890 | miClearVisualTypes();
|
---|
891 | if (!xf86SetDefaultVisual(pScrn, -1))
|
---|
892 | return (FALSE);
|
---|
893 | if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
|
---|
894 | pScrn->rgbBits, TrueColor))
|
---|
895 | return (FALSE);
|
---|
896 | if (!miSetPixmapDepths())
|
---|
897 | return (FALSE);
|
---|
898 |
|
---|
899 | /* Needed before we initialise DRI. */
|
---|
900 | pScrn->virtualX = (pScrn->virtualX + 7) & ~7;
|
---|
901 | pScrn->displayWidth = pScrn->virtualX;
|
---|
902 |
|
---|
903 | #ifdef VBOX_DRI
|
---|
904 | pVBox->useDRI = VBOXDRIScreenInit(scrnIndex, pScreen, pVBox);
|
---|
905 | #endif
|
---|
906 |
|
---|
907 | /* I checked in the sources, and XFree86 4.2 does seem to support
|
---|
908 | this function for 32bpp. */
|
---|
909 | if (!fbScreenInit(pScreen, pVBox->base,
|
---|
910 | pScrn->virtualX, pScrn->virtualY,
|
---|
911 | pScrn->xDpi, pScrn->yDpi,
|
---|
912 | pScrn->displayWidth, pScrn->bitsPerPixel))
|
---|
913 | return (FALSE);
|
---|
914 |
|
---|
915 | /* Fixup RGB ordering */
|
---|
916 | visual = pScreen->visuals + pScreen->numVisuals;
|
---|
917 | while (--visual >= pScreen->visuals) {
|
---|
918 | if ((visual->class | DynamicClass) == DirectColor) {
|
---|
919 | visual->offsetRed = pScrn->offset.red;
|
---|
920 | visual->offsetGreen = pScrn->offset.green;
|
---|
921 | visual->offsetBlue = pScrn->offset.blue;
|
---|
922 | visual->redMask = pScrn->mask.red;
|
---|
923 | visual->greenMask = pScrn->mask.green;
|
---|
924 | visual->blueMask = pScrn->mask.blue;
|
---|
925 | }
|
---|
926 | }
|
---|
927 |
|
---|
928 | /* must be after RGB ordering fixed */
|
---|
929 | fbPictureInit(pScreen, 0, 0);
|
---|
930 |
|
---|
931 | xf86SetBlackWhitePixels(pScreen);
|
---|
932 | miInitializeBackingStore(pScreen);
|
---|
933 | xf86SetBackingStore(pScreen);
|
---|
934 |
|
---|
935 | /* We need to keep track of whether we are currently switched to a virtual
|
---|
936 | * terminal to know whether a mode set operation is currently safe to do.
|
---|
937 | */
|
---|
938 | pVBox->vtSwitch = FALSE;
|
---|
939 | /* Initialise DGA. The cast is unfortunately correct - it gets cast back
|
---|
940 | to (unsigned char *) later. */
|
---|
941 | xf86DiDGAInit(pScreen, (unsigned long) pVBox->base);
|
---|
942 |
|
---|
943 | /* Initialise randr 1.2 mode-setting functions and set first mode. */
|
---|
944 | if (!xf86CrtcScreenInit(pScreen)) {
|
---|
945 | return FALSE;
|
---|
946 | }
|
---|
947 |
|
---|
948 | if (!xf86SetDesiredModes(pScrn)) {
|
---|
949 | return FALSE;
|
---|
950 | }
|
---|
951 |
|
---|
952 | /* software cursor */
|
---|
953 | miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
|
---|
954 |
|
---|
955 | /* colourmap code */
|
---|
956 | if (!miCreateDefColormap(pScreen))
|
---|
957 | return (FALSE);
|
---|
958 |
|
---|
959 | flags = CMAP_RELOAD_ON_MODE_SWITCH;
|
---|
960 |
|
---|
961 | if(!vgaHWHandleColormaps(pScreen))
|
---|
962 | return (FALSE);
|
---|
963 |
|
---|
964 | /* Hook our observer function ito the chain which is called when
|
---|
965 | * framebuffer access is enabled or disabled in the server, and
|
---|
966 | * assume an initial state of enabled. */
|
---|
967 | pVBox->accessEnabled = TRUE;
|
---|
968 | pVBox->EnableDisableFBAccess = pScrn->EnableDisableFBAccess;
|
---|
969 | pScrn->EnableDisableFBAccess = vboxEnableDisableFBAccess;
|
---|
970 |
|
---|
971 | pVBox->CloseScreen = pScreen->CloseScreen;
|
---|
972 | pScreen->CloseScreen = VBOXCloseScreen;
|
---|
973 | pScreen->SaveScreen = xf86SaveScreen;
|
---|
974 |
|
---|
975 | /* We probably do want to support power management - even if we just use
|
---|
976 | a dummy function. */
|
---|
977 | xf86DPMSInit(pScreen, xf86DPMSSet, 0);
|
---|
978 |
|
---|
979 | /* Report any unused options (only for the first generation) */
|
---|
980 | if (serverGeneration == 1)
|
---|
981 | xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
|
---|
982 |
|
---|
983 | if (vbox_device_available(pVBox) && vbox_open (pScrn, pScreen, pVBox)) {
|
---|
984 | if (vbox_cursor_init(pScreen) != TRUE)
|
---|
985 | xf86DrvMsg(scrnIndex, X_ERROR,
|
---|
986 | "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
|
---|
987 | if (vboxEnableVbva(pScrn) == TRUE)
|
---|
988 | xf86DrvMsg(scrnIndex, X_INFO,
|
---|
989 | "The VBox video extensions are now enabled.\n");
|
---|
990 | vboxEnableGraphicsCap(pVBox);
|
---|
991 | }
|
---|
992 |
|
---|
993 | #ifdef VBOX_DRI
|
---|
994 | if (pVBox->useDRI)
|
---|
995 | pVBox->useDRI = VBOXDRIFinishScreenInit(pScreen);
|
---|
996 | #endif
|
---|
997 | return (TRUE);
|
---|
998 | }
|
---|
999 |
|
---|
1000 | static Bool
|
---|
1001 | VBOXEnterVT(int scrnIndex, int flags)
|
---|
1002 | {
|
---|
1003 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1004 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1005 | bool rc;
|
---|
1006 |
|
---|
1007 | TRACE_ENTRY();
|
---|
1008 | pVBox->vtSwitch = FALSE;
|
---|
1009 | #ifdef VBOX_DRI
|
---|
1010 | if (pVBox->useDRI)
|
---|
1011 | DRIUnlock(screenInfo.screens[scrnIndex]);
|
---|
1012 | #endif
|
---|
1013 | rc = xf86SetDesiredModes(pScrn);
|
---|
1014 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1015 | return rc;
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | static void
|
---|
1019 | VBOXLeaveVT(int scrnIndex, int flags)
|
---|
1020 | {
|
---|
1021 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1022 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1023 |
|
---|
1024 | TRACE_ENTRY();
|
---|
1025 | pVBox->vtSwitch = TRUE;
|
---|
1026 | VBOXSaveRestore(pScrn, MODE_RESTORE);
|
---|
1027 | if (vbox_device_available(pVBox))
|
---|
1028 | {
|
---|
1029 | if (pVBox->useVbva == TRUE)
|
---|
1030 | vboxDisableVbva(pScrn);
|
---|
1031 | vboxDisableGraphicsCap(pVBox);
|
---|
1032 | }
|
---|
1033 | #ifdef VBOX_DRI
|
---|
1034 | if (pVBox->useDRI)
|
---|
1035 | DRILock(screenInfo.screens[scrnIndex], 0);
|
---|
1036 | #endif
|
---|
1037 | TRACE_EXIT();
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | static Bool
|
---|
1041 | VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen)
|
---|
1042 | {
|
---|
1043 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1044 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1045 |
|
---|
1046 | #ifdef VBOX_DRI
|
---|
1047 | if (pVBox->useDRI)
|
---|
1048 | VBOXDRICloseScreen(pScreen, pVBox);
|
---|
1049 | pVBox->useDRI = false;
|
---|
1050 | #endif
|
---|
1051 |
|
---|
1052 | if (vbox_device_available(pVBox))
|
---|
1053 | {
|
---|
1054 | if (TRUE == pVBox->useVbva)
|
---|
1055 | vboxDisableVbva(pScrn);
|
---|
1056 | vboxDisableGraphicsCap(pVBox);
|
---|
1057 | }
|
---|
1058 | if (pScrn->vtSema) {
|
---|
1059 | VBOXSaveRestore(xf86Screens[scrnIndex], MODE_RESTORE);
|
---|
1060 | if (pVBox->savedPal)
|
---|
1061 | VBESetGetPaletteData(pVBox->pVbe, TRUE, 0, 256,
|
---|
1062 | pVBox->savedPal, FALSE, TRUE);
|
---|
1063 | VBOXUnmapVidMem(pScrn);
|
---|
1064 | }
|
---|
1065 | pScrn->vtSema = FALSE;
|
---|
1066 |
|
---|
1067 | /* Destroy the VGA hardware record */
|
---|
1068 | vgaHWFreeHWRec(pScrn);
|
---|
1069 |
|
---|
1070 | /* Remove our observer functions from the X server call chains. */
|
---|
1071 | pScrn->EnableDisableFBAccess = pVBox->EnableDisableFBAccess;
|
---|
1072 | pScreen->CloseScreen = pVBox->CloseScreen;
|
---|
1073 | return pScreen->CloseScreen(scrnIndex, pScreen);
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | /**
|
---|
1077 | * Quoted from "How to add an (S)VGA driver to XFree86"
|
---|
1078 | * (http://www.xfree86.org/3.3.6/VGADriver.html):
|
---|
1079 | *
|
---|
1080 | * The ValidMode() function is required. It is used to check for any
|
---|
1081 | * chipset-dependent reasons why a graphics mode might not be valid. It gets
|
---|
1082 | * called by higher levels of the code after the Probe() stage. In many cases
|
---|
1083 | * no special checking will be required and this function will simply return
|
---|
1084 | * TRUE always.
|
---|
1085 | *
|
---|
1086 | * Note: we check here that our generated video modes fulfil the X server's
|
---|
1087 | * criteria for the monitor, since this can otherwise cause problems in
|
---|
1088 | * randr 1.2.
|
---|
1089 | */
|
---|
1090 | static ModeStatus
|
---|
1091 | VBOXValidMode(int scrn, DisplayModePtr p, Bool flag, int pass)
|
---|
1092 | {
|
---|
1093 | static int warned = 0;
|
---|
1094 | ScrnInfoPtr pScrn = xf86Screens[scrn];
|
---|
1095 | MonPtr mon = pScrn->monitor;
|
---|
1096 | ModeStatus ret = MODE_BAD;
|
---|
1097 | DisplayModePtr mode;
|
---|
1098 | float v;
|
---|
1099 |
|
---|
1100 | TRACE_LOG("HDisplay=%d, VDisplay=%d, flag=%s, pass=%d\n",
|
---|
1101 | p->HDisplay, p->VDisplay, flag ? "TRUE" : "FALSE", pass);
|
---|
1102 | if (pass != MODECHECK_FINAL) {
|
---|
1103 | if (!warned) {
|
---|
1104 | xf86DrvMsg(scrn, X_WARNING, "VBOXValidMode called unexpectedly\n");
|
---|
1105 | warned = 1;
|
---|
1106 | }
|
---|
1107 | }
|
---|
1108 | #if 0
|
---|
1109 | /*
|
---|
1110 | * First off, if this isn't a mode we handed to the server (ie,
|
---|
1111 | * M_T_BUILTIN), then we reject it out of hand.
|
---|
1112 | */
|
---|
1113 | if (!(p->type & M_T_BUILTIN))
|
---|
1114 | return MODE_NOMODE;
|
---|
1115 | #endif
|
---|
1116 | /*
|
---|
1117 | * Finally, walk through the vsync rates 1Hz at a time looking for a mode
|
---|
1118 | * that will fit. This is assuredly a terrible way to do this, but
|
---|
1119 | * there's no obvious method for computing a mode of a given size that
|
---|
1120 | * will pass xf86CheckModeForMonitor.
|
---|
1121 | */
|
---|
1122 | for (v = mon->vrefresh[0].lo; v <= mon->vrefresh[0].hi; v++) {
|
---|
1123 | mode = xf86CVTMode(p->HDisplay, p->VDisplay, v, 0, 0);
|
---|
1124 | ret = xf86CheckModeForMonitor(mode, mon);
|
---|
1125 | xfree(mode);
|
---|
1126 | if (ret == MODE_OK)
|
---|
1127 | break;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | if (ret != MODE_OK)
|
---|
1131 | {
|
---|
1132 | xf86DrvMsg(scrn, X_WARNING, "Graphics mode %s rejected by the X server\n", p->name);
|
---|
1133 | }
|
---|
1134 | TRACE_LOG("returning %d\n", ret);
|
---|
1135 | return ret;
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | static Bool
|
---|
1139 | VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags)
|
---|
1140 | {
|
---|
1141 | ScrnInfoPtr pScrn;
|
---|
1142 | VBOXPtr pVBox;
|
---|
1143 | Bool rc;
|
---|
1144 |
|
---|
1145 | TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
|
---|
1146 | pScrn = xf86Screens[scrnIndex]; /* Why does X have three ways of refering to the screen? */
|
---|
1147 | pVBox = VBOXGetRec(pScrn);
|
---|
1148 | /* We want to disable access to the framebuffer before switching mode.
|
---|
1149 | * After doing the switch, we allow access if it was allowed before. */
|
---|
1150 | if (pVBox->accessEnabled)
|
---|
1151 | pVBox->EnableDisableFBAccess(scrnIndex, FALSE);
|
---|
1152 | rc = xf86SetSingleMode(pScrn, pMode, 0);
|
---|
1153 | if (pVBox->accessEnabled)
|
---|
1154 | pVBox->EnableDisableFBAccess(scrnIndex, TRUE);
|
---|
1155 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1156 | return rc;
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | /* Set a graphics mode. Poke the required values into registers, enable
|
---|
1160 | guest-host acceleration functions and tell the host we support advanced
|
---|
1161 | graphics functions. */
|
---|
1162 | static Bool
|
---|
1163 | VBOXSetMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
|
---|
1164 | {
|
---|
1165 | VBOXPtr pVBox;
|
---|
1166 | Bool rc = TRUE;
|
---|
1167 |
|
---|
1168 | int bpp = pScrn->depth == 24 ? 32 : 16;
|
---|
1169 | TRACE_LOG("HDisplay=%d, VDisplay=%d, displayWidth=%d\n",
|
---|
1170 | pMode->HDisplay, pMode->VDisplay, pScrn->displayWidth);
|
---|
1171 | pVBox = VBOXGetRec(pScrn);
|
---|
1172 | /* Don't fiddle with the hardware if we are switched
|
---|
1173 | * to a virtual terminal. */
|
---|
1174 | if (!pVBox->vtSwitch)
|
---|
1175 | {
|
---|
1176 | if ( vbox_device_available(pVBox)
|
---|
1177 | && (TRUE == pVBox->useVbva)
|
---|
1178 | && (vboxDisableVbva(pScrn) != TRUE)
|
---|
1179 | ) /* This would be bad. */
|
---|
1180 | rc = FALSE;
|
---|
1181 | if (rc)
|
---|
1182 | {
|
---|
1183 | /* Disable linear framebuffer mode before making changes to the resolution. */
|
---|
1184 | outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
|
---|
1185 | outw(VBE_DISPI_IOPORT_DATA, VBE_DISPI_DISABLED);
|
---|
1186 | /* Unlike the resolution, the depth is fixed for a given screen
|
---|
1187 | for the lifetime of the X session. */
|
---|
1188 | outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_BPP);
|
---|
1189 | outw(VBE_DISPI_IOPORT_DATA, bpp);
|
---|
1190 | /* HDisplay and VDisplay are actually monitor information about
|
---|
1191 | the display part of the scanlines. */
|
---|
1192 | outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_XRES);
|
---|
1193 | outw(VBE_DISPI_IOPORT_DATA, pMode->HDisplay);
|
---|
1194 | outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_YRES);
|
---|
1195 | outw(VBE_DISPI_IOPORT_DATA, pMode->VDisplay);
|
---|
1196 | /* Set the virtual resolution. We are still using VESA to control
|
---|
1197 | the virtual offset. */
|
---|
1198 | outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_VIRT_WIDTH);
|
---|
1199 | outw(VBE_DISPI_IOPORT_DATA, pScrn->displayWidth);
|
---|
1200 | /* Enable linear framebuffer mode. */
|
---|
1201 | outw(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ENABLE);
|
---|
1202 | outw(VBE_DISPI_IOPORT_DATA,
|
---|
1203 | VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED);
|
---|
1204 | /* Enable acceleration and tell the host we support graphics */
|
---|
1205 | if (vbox_device_available(pVBox))
|
---|
1206 | {
|
---|
1207 | if ((TRUE == pVBox->useVbva) && (vboxEnableVbva(pScrn) != TRUE))
|
---|
1208 | /* Bad but not fatal */
|
---|
1209 | pVBox->useVbva = FALSE;
|
---|
1210 | vboxEnableGraphicsCap(pVBox);
|
---|
1211 | }
|
---|
1212 | }
|
---|
1213 | }
|
---|
1214 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1215 | return rc;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | static void
|
---|
1219 | VBOXAdjustFrame(int scrnIndex, int x, int y, int flags)
|
---|
1220 | {
|
---|
1221 | VBOXPtr pVBox = VBOXGetRec(xf86Screens[scrnIndex]);
|
---|
1222 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1223 |
|
---|
1224 | TRACE_ENTRY();
|
---|
1225 | /* Don't fiddle with the hardware if we are switched
|
---|
1226 | * to a virtual terminal. */
|
---|
1227 | if (!pVBox->vtSwitch) {
|
---|
1228 | pVBox->viewportX = x;
|
---|
1229 | pVBox->viewportY = y;
|
---|
1230 | /* If VBVA is enabled the graphics card will not notice the change. */
|
---|
1231 | if (pVBox->useVbva == TRUE)
|
---|
1232 | vboxDisableVbva(pScrn);
|
---|
1233 | VBESetDisplayStart(pVBox->pVbe, x, y, TRUE);
|
---|
1234 | if (pVBox->useVbva == TRUE)
|
---|
1235 | vboxEnableVbva(pScrn);
|
---|
1236 | }
|
---|
1237 | TRACE_EXIT();
|
---|
1238 | }
|
---|
1239 |
|
---|
1240 | static void
|
---|
1241 | VBOXFreeScreen(int scrnIndex, int flags)
|
---|
1242 | {
|
---|
1243 | VBOXFreeRec(xf86Screens[scrnIndex]);
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 | static Bool
|
---|
1247 | VBOXMapVidMem(ScrnInfoPtr pScrn)
|
---|
1248 | {
|
---|
1249 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1250 | Bool rc = TRUE;
|
---|
1251 |
|
---|
1252 | TRACE_ENTRY();
|
---|
1253 | if (!pVBox->base)
|
---|
1254 | {
|
---|
1255 | pScrn->memPhysBase = pVBox->mapPhys;
|
---|
1256 | pScrn->fbOffset = pVBox->mapOff;
|
---|
1257 |
|
---|
1258 | #ifdef PCIACCESS
|
---|
1259 | (void) pci_device_map_range(pVBox->pciInfo,
|
---|
1260 | pScrn->memPhysBase,
|
---|
1261 | pVBox->mapSize,
|
---|
1262 | PCI_DEV_MAP_FLAG_WRITABLE,
|
---|
1263 | & pVBox->base);
|
---|
1264 | #else
|
---|
1265 | pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
|
---|
1266 | VIDMEM_FRAMEBUFFER,
|
---|
1267 | pVBox->pciTag, pVBox->mapPhys,
|
---|
1268 | (unsigned) pVBox->mapSize);
|
---|
1269 | #endif
|
---|
1270 | if (pVBox->base)
|
---|
1271 | {
|
---|
1272 | /* We need this for saving/restoring textmode */
|
---|
1273 | VGAHWPTR(pScrn)->IOBase = pScrn->domainIOBase;
|
---|
1274 | rc = vgaHWMapMem(pScrn);
|
---|
1275 | }
|
---|
1276 | else
|
---|
1277 | rc = FALSE;
|
---|
1278 | }
|
---|
1279 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1280 | return rc;
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | static void
|
---|
1284 | VBOXUnmapVidMem(ScrnInfoPtr pScrn)
|
---|
1285 | {
|
---|
1286 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1287 |
|
---|
1288 | TRACE_ENTRY();
|
---|
1289 | if (pVBox->base == NULL)
|
---|
1290 | return;
|
---|
1291 |
|
---|
1292 | #ifdef PCIACCESS
|
---|
1293 | (void) pci_device_unmap_range(pVBox->pciInfo,
|
---|
1294 | pVBox->base,
|
---|
1295 | pVBox->mapSize);
|
---|
1296 | #else
|
---|
1297 | xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
|
---|
1298 | (unsigned) pVBox->mapSize);
|
---|
1299 | #endif
|
---|
1300 | vgaHWUnmapMem(pScrn);
|
---|
1301 | pVBox->base = NULL;
|
---|
1302 | TRACE_EXIT();
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 |
|
---|
1306 | Bool
|
---|
1307 | VBOXSaveRestore(ScrnInfoPtr pScrn, vbeSaveRestoreFunction function)
|
---|
1308 | {
|
---|
1309 | VBOXPtr pVBox;
|
---|
1310 | Bool rc = TRUE;
|
---|
1311 |
|
---|
1312 | TRACE_ENTRY();
|
---|
1313 | if (MODE_QUERY < 0 || function > MODE_RESTORE)
|
---|
1314 | rc = FALSE;
|
---|
1315 |
|
---|
1316 | if (rc)
|
---|
1317 | {
|
---|
1318 | pVBox = VBOXGetRec(pScrn);
|
---|
1319 |
|
---|
1320 | /* Query amount of memory to save state */
|
---|
1321 | if (function == MODE_QUERY ||
|
---|
1322 | (function == MODE_SAVE && pVBox->state == NULL))
|
---|
1323 | {
|
---|
1324 |
|
---|
1325 | /* Make sure we save at least this information in case of failure */
|
---|
1326 | (void)VBEGetVBEMode(pVBox->pVbe, &pVBox->stateMode);
|
---|
1327 | vgaHWSaveFonts(pScrn, &pVBox->vgaRegs);
|
---|
1328 |
|
---|
1329 | if (!VBESaveRestore(pVBox->pVbe,function,(pointer)&pVBox->state,
|
---|
1330 | &pVBox->stateSize,&pVBox->statePage)
|
---|
1331 | )
|
---|
1332 | rc = FALSE;
|
---|
1333 | }
|
---|
1334 | }
|
---|
1335 | if (rc)
|
---|
1336 | {
|
---|
1337 | /* Save/Restore Super VGA state */
|
---|
1338 | if (function != MODE_QUERY) {
|
---|
1339 |
|
---|
1340 | if (function == MODE_RESTORE)
|
---|
1341 | memcpy(pVBox->state, pVBox->pstate,
|
---|
1342 | (unsigned) pVBox->stateSize);
|
---|
1343 |
|
---|
1344 | if ( (rc = VBESaveRestore(pVBox->pVbe,function,
|
---|
1345 | (pointer)&pVBox->state,
|
---|
1346 | &pVBox->stateSize,&pVBox->statePage)
|
---|
1347 | )
|
---|
1348 | && (function == MODE_SAVE)
|
---|
1349 | )
|
---|
1350 | {
|
---|
1351 | /* don't rely on the memory not being touched */
|
---|
1352 | if (pVBox->pstate == NULL)
|
---|
1353 | pVBox->pstate = xalloc(pVBox->stateSize);
|
---|
1354 | memcpy(pVBox->pstate, pVBox->state,
|
---|
1355 | (unsigned) pVBox->stateSize);
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | if (function == MODE_RESTORE)
|
---|
1359 | {
|
---|
1360 | VBESetVBEMode(pVBox->pVbe, pVBox->stateMode, NULL);
|
---|
1361 | vgaHWRestoreFonts(pScrn, &pVBox->vgaRegs);
|
---|
1362 | }
|
---|
1363 | }
|
---|
1364 | }
|
---|
1365 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1366 | return rc;
|
---|
1367 | }
|
---|