VirtualBox

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

Last change on this file since 43081 was 43081, checked in by vboxsync, 12 years ago

Additions/x11/vboxvideo: some header file inclusion clean-up.

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