VirtualBox

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

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

Additions/x11/vboxvideo: do not save the video mode for size hints sent while in seamless

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