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