vboxvideo.c revision 03493c32c4a1ce2b083405efe6f3b070bead1be6
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Linux Additions X11 graphics driver
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Copyright (C) 2006-2011 Oracle Corporation
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * This file is part of VirtualBox Open Source Edition (OSE), as
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * available from http://www.virtualbox.org. This file is free software;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * you can redistribute it and/or modify it under the terms of the GNU
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * General Public License (GPL) as published by the Free Software
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Foundation, in version 2 as it comes in the "COPYING" file of the
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * --------------------------------------------------------------------
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * This code is based on the X.Org VESA driver with the following copyrights:
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Copyright 2008 Red Hat, Inc.
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Copyright 2012 Red Hat, Inc.
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * and the following permission notice (not all original sourse files include
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * the last paragraph):
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Permission is hereby granted, free of charge, to any person obtaining a
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * copy of this software and associated documentation files (the "Software"),
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * to deal in the Software without restriction, including without limitation
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * the rights to use, copy, modify, merge, publish, distribute, sublicense,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * and/or sell copies of the Software, and to permit persons to whom the
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Software is furnished to do so, subject to the following conditions:
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * The above copyright notice and this permission notice shall be included in
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * all copies or substantial portions of the Software.
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Except as contained in this notice, the name of Conectiva Linux shall
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * not be used in advertising or otherwise to promote the sale, use or other
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * dealings in this Software without prior written authorization from
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Conectiva Linux.
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * David Dawes <dawes@xfree86.org>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Adam Jackson <ajax@redhat.com>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Dave Airlie <airlied@redhat.com>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* Drivers for PCI hardware need this */
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff/* Drivers that need to access the PCI config space directly need this */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* All drivers initialising the SW cursor need this */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* Colormap handling */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* #define DPMS_SERVER
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* VGA hardware functions for setting and restoring text mode */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* X.org 1.3+ mode setting */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff# define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* Mandatory functions */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXProbe(DriverPtr drv, int flags);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXPciProbe(DriverPtr drv, int entity_num,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXScreenInit(int Index, ScreenPtr pScreen, int argc,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic Bool VBOXEnterVT(int scrnIndex, int flags);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void VBOXLeaveVT(int scrnIndex, int flags);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic Bool VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic Bool VBOXSaveScreen(ScreenPtr pScreen, int mode);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic void VBOXAdjustFrame(int scrnIndex, int x, int y, int flags);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic void VBOXFreeScreen(int scrnIndex, int flags);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* locally used functions */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic inline void VBOXSetRec(ScrnInfoPtr pScrn)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->driverPrivate = calloc(sizeof(VBOXRec), 1);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniffstatic const struct pci_id_match vbox_device_match[] = {
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff { 0, 0, 0 },
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff/* Supported chipsets */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA },
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * This contains the functions needed by the server after loading the
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * driver module. It must be supplied, and gets added the driver list by
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * the Module Setup function in the dynamic case. In the static case a
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * reference to this is compiled in, and this requires that the name of
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * this DriverRec be an upper-case version of the driver name.
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* No options for now */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * List of symbols from other modules that this module references. This
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * list is used to tell the loader that it is OK for symbols here to be
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * unresolved providing that it hasn't been told that they haven't been
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * told that they are essential via a call to xf86LoaderReqSymbols() or
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * unresolved symbols that are not required.
2353184083624510261e335c156a05e8cae2fc41Jeff Conniffstatic const char *fbSymbols[] = {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff "fbPictureInit",
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff "fbScreenInit",
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const char *shadowfbSymbols[] = {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "ShadowFBInit2",
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const char *ramdacSymbols[] = {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "xf86InitCursor",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "xf86CreateCursorInfoRec",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic const char *vgahwSymbols[] = {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "vgaHWFreeHWRec",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "vgaHWGetHWRec",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "vgaHWGetIOBase",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "vgaHWGetIndex",
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "vgaHWRestore",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "vgaHWSave",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "vgaHWSetStdFuncs",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif /* !XORG_7X */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* X.org 1.3+ mode-setting support ******************************************/
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* For descriptions of these functions and structures, see
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff X.Org source tree. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool vbox_config_resize(ScrnInfoPtr pScrn, int cw, int ch)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /* Save the size in case we need to re-set it later. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /* Don't fiddle with the hardware if we are switched
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * to a virtual terminal. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "We do not own the active VT, exiting.\n");
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff unsigned cDisplay = (uintptr_t)crtc->driver_private;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff TRACE_LOG("cDisplay=%u, mode=%i\n", cDisplay, mode);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->afDisabled[cDisplay] = (mode != DPMSModeOn);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Don't fiddle with the hardware if we are switched
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * to a virtual terminal. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "We do not own the active VT, exiting.\n");
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* We use this function to check whether the X server owns the active virtual
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * terminal before attempting a mode switch, since the RandR extension isn't
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * very dilligent here, which can mean crashes if we are unlucky. This is
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * not the way it the function is intended - it is meant for reporting modes
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * which the hardware can't handle. I hope that this won't confuse any clients
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * connecting to us. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{ (void) crtc; (void) mode; (void) adjusted_mode; return TRUE; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff unsigned cDisplay = (uintptr_t)crtc->driver_private;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->aScreenLocation[cDisplay].cx = adjusted_mode->HDisplay;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pVBox->aScreenLocation[cDisplay].cy = adjusted_mode->VDisplay;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Don't remember any modes set while we are seamless, as they are
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * just temporary. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff vboxSaveVideoMode(crtc->scrn, adjusted_mode->HDisplay,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff adjusted_mode->VDisplay, crtc->scrn->bitsPerPixel);
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff /* Don't fiddle with the hardware if we are switched
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * to a virtual terminal. */
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff "We do not own the active VT, exiting.\n");
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOXSetMode(crtc->scrn, cDisplay, adjusted_mode->HDisplay,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_crtc_gamma_set (xf86CrtcPtr crtc, CARD16 *red,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{ (void) crtc; (void) red; (void) green; (void) blue; (void) size; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic void *
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{ (void) crtc; (void) width; (void) height; return NULL; }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .save = NULL, /* These two are never called by the server. */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff .unlock = NULL, /* This will not be invoked if lock returns FALSE. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .shadow_create = NULL, /* These two should not be invoked if allocate
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff returns NULL. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .set_cursor_colors = NULL, /* We are still using the old cursor API. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_dpms (xf86OutputPtr output, int mode)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_LOG("HDisplay=%d, VDisplay=%d\n", mode->HDisplay, mode->VDisplay);
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff /* We always like modes specified by the user in the configuration
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff * file and modes requested by the host, as doing otherwise is likely to
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff * annoy people. */
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff && !vboxHostLikesVideoMode(pScrn, mode->HDisplay, mode->VDisplay,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_LOG("returning %s\n", MODE_OK == rc ? "MODE_OK" : "MODE_BAD");
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{ (void) output; (void) mode; (void) adjusted_mode; return TRUE; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{ (void) output; (void) mode; (void) adjusted_mode; }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* A virtual monitor is always connected. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_add_mode (VBOXPtr pVBox, DisplayModePtr *pModes,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff const char *pszName, int x, int y,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName, x, y);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* We don't ask the host whether it likes user defined modes,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * as we assume that the user really wanted that mode. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->type = isUserDef ? M_T_USERDEF : M_T_BUILTIN;
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff /* Older versions of VBox only support screen widths which are a multiple
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->Clock = pMode->HTotal * pMode->VTotal * 60 / 1000; /* kHz */
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff unsigned i, cIndex = 0;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff vboxGetPreferredMode(pScrn, iScreen, &x, &y, &bpp);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode = vbox_output_add_mode(pVBox, &pModes, NULL, x, y, TRUE, FALSE);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /* Add standard modes supported by the host */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff cIndex = vboxNextStandardMode(pScrn, cIndex, &x, &y, NULL);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff vbox_output_add_mode(pVBox, &pModes, NULL, x, y, FALSE, FALSE);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Also report any modes the user may have requested in the xorg.conf
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * configuration file. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff for (i = 0; pScrn->display->modes[i] != NULL; i++)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (2 == sscanf(pScrn->display->modes[i], "%ux%u", &x, &y))
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff vbox_output_add_mode(pVBox, &pModes, pScrn->display->modes[i], x, y,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return MakeAtom("VBOX_MODE", sizeof("VBOX_MODE") - 1, TRUE);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return MakeAtom("EDID", sizeof("EDID") - 1, TRUE);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/** We use this for receiving information from clients for the purpose of
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * dynamic resizing, and later possibly other things too.
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_output_set_property(xf86OutputPtr output, Atom property,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff TRACE_LOG("property=%d, value->type=%d, value->format=%d, value->size=%ld\n",
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff (int)property, (int)value->type, value->format, value->size);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff uint32_t cDisplay = (uintptr_t)output->driver_private;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_LOG("screen=%u, property value=%s\n", cDisplay, sz);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const xf86OutputFuncsRec VBOXOutputFuncs = {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff .save = NULL, /* These two are never called by the server. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif /* VBOXVIDEO_13 */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* Module loader interface */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff 0, /* Module minor version. Xorg-specific */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff ABI_CLASS_VIDEODRV, /* This is a video driver */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff {0, 0, 0, 0}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * This data is accessed by the loader. The name must be the module name
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * followed by "ModuleData".
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffXF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffvboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n",
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif /* XFree86Loader defined */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * This function is called once, at the start of the first server generation to
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * do a minimal probe for supported hardware.
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffVBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * Find the config file Device sections that match this
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * driver, and return if there are none.
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff if ((numDevSections = xf86MatchDevice(VBOX_NAME,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* PCI BUS */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff for (i = 0; i < numUsed; i++) {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* Allocate a ScrnInfoRec */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * QUOTE from the XFree86 DESIGN document:
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * The purpose of this function is to find out all the information
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * required to determine if the configuration is usable, and to initialise
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * those parts of the ScrnInfoRec that can be set once at the beginning of
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * the first server generation.
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * This includes probing for video memory, clocks, ramdac, and all other
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * HW info that is needed. It includes determining the depth/bpp/visual
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * and related info. It includes validating and determining the set of
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * video modes that will be used (and anything that is required to
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * determine that).
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * This information should be determined in the least intrusive way
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * possible. The state of the HW must remain unchanged by this function.
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * Although video memory (including MMIO) may be mapped within this
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * function, it must be unmapped before returning.
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* Are we really starting the server, or is this just a dummy run? */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff "VirtualBox guest additions video driver version "
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* Get our private data from the ScrnInfoRec structure. */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* Initialise the guest library */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* Entity information seems to mean bus information. */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* The ramdac module is needed for the hardware cursor. */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* The framebuffer module. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Load the dri module. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Set up our ScrnInfoRec structure to describe our virtual
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff capabilities to X. */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /** @note needed during colourmap initialisation */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Let's create a nice, capable virtual monitor. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Using the PCI information caused problems with non-powers-of-two
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff sized video RAM configurations */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* Check if the chip restricts horizontal resolution or not. */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* Set up clock information that will support all modes we need. */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->clockRanges = xnfcalloc(sizeof(ClockRange), 1);
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* Query the host for the preferred colour depth */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff vboxGetPreferredMode(pScrn, 0, &cx, &cy, &cBits);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (!xf86SetDepthBpp(pScrn, cBits, 0, 0, Support32bppFb))
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "The VBox additions only support 16 and 32bpp graphics modes\n");
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Work around a bug in the original X server modesetting code, which
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * took the first valid values set to these two as maxima over the
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * server lifetime. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* We don't validate with xf86ValidateModes and xf86PruneModes as we
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * already know what we like and what we don't. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Set the right virtual resolution. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pScrn->virtualX = pScrn->currentMode->HDisplay;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->virtualY = pScrn->currentMode->VDisplay;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif /* !VBOXVIDEO_13 */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /* Needed before we initialise DRI. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->cbLine = vboxLineLength(pScrn, pScrn->virtualX);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->displayWidth = vboxDisplayPitch(pScrn, pVBox->cbLine);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* VGA hardware initialisation */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Must be called before any VGA registers are saved or restored */
return (FALSE);
return (FALSE);
#ifdef PCIACCESS
TRACE_EXIT();
return (TRUE);
(void)pVisual;
static Bool
unsigned flags;
TRACE_ENTRY();
return (FALSE);
return (FALSE);
if (!miSetPixmapDepths())
return (FALSE);
#ifdef VBOX_DRI
return (FALSE);
#ifdef VBOXVIDEO_13
uint32_t i;
szOutput);
return (FALSE);
return FALSE;
uint32_t i;
FALSE);
return FALSE;
return FALSE;
return (FALSE);
return (FALSE);
#ifdef VBOXVIDEO_13
#ifdef VBOXVIDEO_13
#ifdef VBOX_DRI
return (TRUE);
static Bool
TRACE_ENTRY();
#ifdef VBOX_DRI
#ifdef VBOXVIDEO_13
return FALSE;
return FALSE;
return TRUE;
TRACE_ENTRY();
#ifdef VBOX_DRI
TRACE_EXIT();
static Bool
#ifdef VBOX_DRI
static Bool
#ifndef VBOXVIDEO_13
return TRUE;
#ifdef VBOXVIDEO_13
if (rc)
return rc;
TRACE_ENTRY();
TRACE_EXIT();
static Bool
TRACE_ENTRY();
#ifdef PCIACCESS
return rc;
TRACE_ENTRY();
#ifdef PCIACCESS
TRACE_EXIT();
static Bool
return TRUE;
TRACE_ENTRY();
TRACE_ENTRY();
int flags)