VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_13.c@ 26040

Last change on this file since 26040 was 26040, checked in by vboxsync, 15 years ago

Additions/x11/vboxvideo: do not reject saved video modes if the front-end does not like them

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette