vboxvideo.c revision acca7ab818eb8c2832aa27e27ce53133fba927db
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Linux Additions X11 graphics driver
29a65fa8b740a860f86812328cf900b8d68d93bevboxsync * Copyright (C) 2006-2011 Oracle Corporation
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * available from http://www.virtualbox.org. This file is free software;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * you can redistribute it and/or modify it under the terms of the GNU
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * General Public License (GPL) as published by the Free Software
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * --------------------------------------------------------------------
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * This code is based on the X.Org VESA driver with the following copyrights:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * Copyright 2008 Red Hat, Inc.
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * Copyright 2012 Red Hat, Inc.
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * and the following permission notice (not all original sourse files include
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * the last paragraph):
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Permission is hereby granted, free of charge, to any person obtaining a
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * copy of this software and associated documentation files (the "Software"),
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * to deal in the Software without restriction, including without limitation
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * the rights to use, copy, modify, merge, publish, distribute, sublicense,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * and/or sell copies of the Software, and to permit persons to whom the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Software is furnished to do so, subject to the following conditions:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The above copyright notice and this permission notice shall be included in
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * all copies or substantial portions of the Software.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * SOFTWARE.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Except as contained in this notice, the name of Conectiva Linux shall
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * not be used in advertising or otherwise to promote the sale, use or other
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * dealings in this Software without prior written authorization from
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Conectiva Linux.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * David Dawes <dawes@xfree86.org>
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * Adam Jackson <ajax@redhat.com>
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * Dave Airlie <airlied@redhat.com>
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync/* Drivers for PCI hardware need this */
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync/* Drivers that need to access the PCI config space directly need this */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* All drivers initialising the SW cursor need this */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* Colormap handling */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* #define DPMS_SERVER
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* VGA hardware functions for setting and restoring text mode */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* X.org 1.3+ mode setting */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync# define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* Mandatory functions */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic Bool VBOXPciProbe(DriverPtr drv, int entity_num,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic Bool VBOXSaveScreen(ScreenPtr pScreen, int mode);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* locally used functions */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic const struct pci_id_match vbox_device_match[] = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync { 0, 0, 0 },
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* Supported chipsets */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This contains the functions needed by the server after loading the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * driver module. It must be supplied, and gets added the driver list by
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * the Module Setup function in the dynamic case. In the static case a
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * reference to this is compiled in, and this requires that the name of
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * this DriverRec be an upper-case version of the driver name.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* No options for now */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * List of symbols from other modules that this module references. This
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * list is used to tell the loader that it is OK for symbols here to be
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * unresolved providing that it hasn't been told that they haven't been
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * told that they are essential via a call to xf86LoaderReqSymbols() or
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * unresolved symbols that are not required.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic const char *fbSymbols[] = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "fbPictureInit",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "fbScreenInit",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic const char *shadowfbSymbols[] = {
7755c0a4b7b215f612d9d27848c2584ffafe7a66vboxsync "ShadowFBInit2",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic const char *ramdacSymbols[] = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "xf86InitCursor",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "xf86CreateCursorInfoRec",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic const char *vgahwSymbols[] = {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "vgaHWFreeHWRec",
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync "vgaHWGetHWRec",
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync "vgaHWGetIOBase",
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync "vgaHWGetIndex",
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync "vgaHWRestore",
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync "vgaHWSave",
602e0e27740395dba64bee2e0a8aef023ebd7650vboxsync "vgaHWSetStdFuncs",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* !XORG_7X */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* X.org 1.3+ mode-setting support ******************************************/
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* For descriptions of these functions and structures, see
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync X.Org source tree. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsyncstatic Bool vbox_config_resize(ScrnInfoPtr pScrn, int cw, int ch)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Save the size in case we need to re-set it later. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Don't fiddle with the hardware if we are switched
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * to a virtual terminal. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync "We do not own the active VT, exiting.\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
78df65edff21c11c537f38e736707ea434ab5623vboxsync unsigned cDisplay = (uintptr_t)crtc->driver_private;
78df65edff21c11c537f38e736707ea434ab5623vboxsync TRACE_LOG("cDisplay=%u, mode=%i\n", cDisplay, mode);
78df65edff21c11c537f38e736707ea434ab5623vboxsync pVBox->afDisabled[cDisplay] = (mode != DPMSModeOn);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Don't fiddle with the hardware if we are switched
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * to a virtual terminal. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync "We do not own the active VT, exiting.\n");
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync/* We use this function to check whether the X server owns the active virtual
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * terminal before attempting a mode switch, since the RandR extension isn't
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * very dilligent here, which can mean crashes if we are unlucky. This is
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * not the way it the function is intended - it is meant for reporting modes
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * which the hardware can't handle. I hope that this won't confuse any clients
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * connecting to us. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{ (void) crtc; (void) mode; (void) adjusted_mode; return TRUE; }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
78df65edff21c11c537f38e736707ea434ab5623vboxsync unsigned cDisplay = (uintptr_t)crtc->driver_private;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync pVBox->aScreenLocation[cDisplay].cx = adjusted_mode->HDisplay;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync pVBox->aScreenLocation[cDisplay].cy = adjusted_mode->VDisplay;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Don't remember any modes set while we are seamless, as they are
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * just temporary. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vboxSaveVideoMode(crtc->scrn, adjusted_mode->HDisplay,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync adjusted_mode->VDisplay, crtc->scrn->bitsPerPixel);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Don't fiddle with the hardware if we are switched
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * to a virtual terminal. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync "We do not own the active VT, exiting.\n");
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync VBOXSetMode(crtc->scrn, cDisplay, adjusted_mode->HDisplay,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{ (void) crtc; (void) red; (void) green; (void) blue; (void) size; }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic void *
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvbox_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{ (void) crtc; (void) width; (void) height; return NULL; }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync .save = NULL, /* These two are never called by the server. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync .unlock = NULL, /* This will not be invoked if lock returns FALSE. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync .shadow_create = NULL, /* These two should not be invoked if allocate
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync returns NULL. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync .set_cursor_colors = NULL, /* We are still using the old cursor API. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TRACE_LOG("HDisplay=%d, VDisplay=%d\n", mode->HDisplay, mode->VDisplay);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* We always like modes specified by the user in the configuration
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * file and modes requested by the host, as doing otherwise is likely to
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * annoy people. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync && !vboxHostLikesVideoMode(pScrn, mode->HDisplay, mode->VDisplay,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TRACE_LOG("returning %s\n", MODE_OK == rc ? "MODE_OK" : "MODE_BAD");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{ (void) output; (void) mode; (void) adjusted_mode; return TRUE; }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync{ (void) output; (void) mode; (void) adjusted_mode; }
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* A virtual monitor is always connected. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvbox_output_add_mode (VBOXPtr pVBox, DisplayModePtr *pModes,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const char *pszName, int x, int y,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName, x, y);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* We don't ask the host whether it likes user defined modes,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * as we assume that the user really wanted that mode. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pMode->type = isUserDef ? M_T_USERDEF : M_T_BUILTIN;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Older versions of VBox only support screen widths which are a multiple
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pMode->Clock = pMode->HTotal * pMode->VTotal * 60 / 1000; /* kHz */
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync unsigned i, cIndex = 0;
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync vboxGetPreferredMode(pScrn, iScreen, &x, &y, &bpp);
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync pMode = vbox_output_add_mode(pVBox, &pModes, NULL, x, y, TRUE, FALSE);
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync /* Add standard modes supported by the host */
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync for ( ; ; )
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync cIndex = vboxNextStandardMode(pScrn, cIndex, &x, &y, NULL);
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync vbox_output_add_mode(pVBox, &pModes, NULL, x, y, FALSE, FALSE);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Also report any modes the user may have requested in the xorg.conf
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * configuration file. */
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync if (2 == sscanf(pScrn->display->modes[i], "%ux%u", &x, &y))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vbox_output_add_mode(pVBox, &pModes, pScrn->display->modes[i], x, y,
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync return MakeAtom("VBOX_MODE", sizeof("VBOX_MODE") - 1, TRUE);
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync/** We use this for receiving information from clients for the purpose of
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync * dynamic resizing, and later possibly other things too.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvbox_output_set_property(xf86OutputPtr output, Atom property,
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync TRACE_LOG("property=%d, value->type=%d, value->format=%d, value->size=%ld\n",
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync (int)property, (int)value->type, value->format, value->size);
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync uint32_t cDisplay = (uintptr_t)output->driver_private;
a86135e41c89c7b599607649347a4240809c784bvboxsync TRACE_LOG("screen=%u, property value=%s\n", cDisplay, sz);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync .save = NULL, /* These two are never called by the server. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* VBOXVIDEO_13 */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* Module loader interface */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync 0, /* Module minor version. Xorg-specific */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync {0, 0, 0, 0}
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This data is accessed by the loader. The name must be the module name
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * followed by "ModuleData".
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncXF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync# define xf86ScreenToScrn(pScreen) xf86Screens[(pScreen)->myNum]
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync# define xf86ScrnToScreen(pScrn) screenInfo.screens[(pScrn)->scrnIndex]
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic Bool VBOXScreenInitIndex(int scrnIndex, ScreenPtr pScreen, int argc,
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic Bool VBOXEnterVTIndex(int scrnIndex, int flags)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync{ (void) flags; return VBOXEnterVT(xf86Screens[scrnIndex]); }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic void VBOXLeaveVTIndex(int scrnIndex, int flags)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync{ (void) flags; VBOXLeaveVT(xf86Screens[scrnIndex]); }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic Bool VBOXCloseScreenIndex(int scrnIndex, ScreenPtr pScreen)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync{ (void) scrnIndex; return VBOXCloseScreen(pScreen); }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic Bool VBOXSwitchModeIndex(int scrnIndex, DisplayModePtr pMode, int flags)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync{ (void) flags; return VBOXSwitchMode(xf86Screens[scrnIndex], pMode); }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic void VBOXAdjustFrameIndex(int scrnIndex, int x, int y, int flags)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync{ (void) flags; VBOXAdjustFrame(xf86Screens[scrnIndex], x, y); }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic void VBOXFreeScreenIndex(int scrnIndex, int flags)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync{ (void) flags; VBOXFreeScreen(xf86Screens[scrnIndex]); }
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync#endif /* XF86_SCRN_INTERFACE */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic void setScreenFunctions(ScrnInfoPtr pScrn, xf86ProbeProc pfnProbe)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pScrn->AdjustFrame = SCRNINDEXAPI(VBOXAdjustFrame);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync * One of these functions is called once, at the start of the first server
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync * generation to do a minimal probe for supported hardware.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncVBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Find the config file Device sections that match this
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * driver, and return if there are none.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* PCI BUS */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync for (i = 0; i < numUsed; i++)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync /* Allocate a ScrnInfoRec */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * QUOTE from the XFree86 DESIGN document:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * The purpose of this function is to find out all the information
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * required to determine if the configuration is usable, and to initialise
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * those parts of the ScrnInfoRec that can be set once at the beginning of
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * the first server generation.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This includes probing for video memory, clocks, ramdac, and all other
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * HW info that is needed. It includes determining the depth/bpp/visual
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * and related info. It includes validating and determining the set of
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * video modes that will be used (and anything that is required to
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * determine that).
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This information should be determined in the least intrusive way
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * possible. The state of the HW must remain unchanged by this function.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Although video memory (including MMIO) may be mapped within this
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * function, it must be unmapped before returning.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * END QUOTE
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Are we really starting the server, or is this just a dummy run? */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "VirtualBox guest additions video driver version "
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Get our private data from the ScrnInfoRec structure. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Initialise the guest library */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Entity information seems to mean bus information. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* The ramdac module is needed for the hardware cursor. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* The framebuffer module. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Load the dri module. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Set up our ScrnInfoRec structure to describe our virtual
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync capabilities to X. */
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync /** @note needed during colourmap initialisation */
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync /* Let's create a nice, capable virtual monitor. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Using the PCI information caused problems with non-powers-of-two
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync sized video RAM configurations */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Check if the chip restricts horizontal resolution or not. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Set up clock information that will support all modes we need. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pScrn->clockRanges = xnfcalloc(sizeof(ClockRange), 1);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Query the host for the preferred colour depth */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!xf86SetDepthBpp(pScrn, cBits, 0, 0, Support32bppFb))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "The VBox additions only support 16 and 32bpp graphics modes\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Work around a bug in the original X server modesetting code, which
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * took the first valid values set to these two as maxima over the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * server lifetime. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* We don't validate with xf86ValidateModes and xf86PruneModes as we
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * already know what we like and what we don't. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Set the right virtual resolution. */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync#endif /* !VBOXVIDEO_13 */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /* Needed before we initialise DRI. */
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync pVBox->cbLine = vboxLineLength(pScrn, pScrn->virtualX);
af0a09edb4c1431b606fe207d4138da008f67f13vboxsync pScrn->displayWidth = vboxDisplayPitch(pScrn, pVBox->cbLine);
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync /* VGA hardware initialisation */
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync /* Must be called before any VGA registers are saved or restored */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Colour weight - we always call this, since we are always in
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync truecolour. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* visual init */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Set the DPI. Perhaps we should read this from the host? */
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync pScrn->memPhysBase = pVBox->pciInfo->regions[0].base_addr;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Dummy function for setting the colour palette, which we actually never
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * touch. However, the server still requires us to provide this.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvboxLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync (void)pScrn; (void) numColors; (void) indices; (void) colors;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * QUOTE from the XFree86 DESIGN document:
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This is called at the start of each server generation.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Decide which operations need to be placed under resource access
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * control. (...) Map any video memory or other memory regions. (...)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Save the video card state. (...) Initialise the initial video
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * End QUOTE.
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* save current video state */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* mi layer - reset the visual list (?)*/
bc5c5b5cd56ce8e64ada076691018f1dff17b2c2vboxsync pVBox->useDRI = VBOXDRIScreenInit(pScrn, pScreen, pVBox);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Fixup RGB ordering */
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync /** @note the X server uses this even in true colour. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if ((visual->class | DynamicClass) == DirectColor) {
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* must be after RGB ordering fixed */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /* Initialise CRTC and output configuration for use with randr1.2. */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /* Setup our virtual CRTCs. */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync pVBox->paCrtcs[i] = xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
11c2b573e2625474a51ae55ee1f3f82936f125davboxsync pVBox->paCrtcs[i]->driver_private = (void *)(uintptr_t)i;
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /* Set up our virtual outputs. */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync pVBox->paOutputs[i] = xf86OutputCreate(pScrn, &VBOXOutputFuncs,
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /* We are not interested in the monitor section in the
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * configuration file. */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync xf86OutputUseScreenMonitor(pVBox->paOutputs[i], FALSE);
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync pVBox->paOutputs[i]->driver_private = (void *)(uintptr_t)i;
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync TRACE_LOG("Created crtc (%p) and output %s (%p)\n",
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /* Set a sane minimum and maximum mode size */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync /* Now create our initial CRTC/output configuration. */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Initialise randr 1.2 mode-setting functions and set first mode.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Note that the mode won't be usable until the server has resized the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * framebuffer to something reasonable. */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync /* Create our VBOX_MODE display properties. */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync RRChangeOutputProperty(pVBox->paOutputs[i]->randr_output,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#else /* !VBOXVIDEO_13 */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* set first video mode */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!VBOXSetMode(pScrn, 0, pScrn->currentMode->HDisplay,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* And make sure that a non-current dynamic mode is at the front of the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* !VBOXVIDEO_13 */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* software cursor */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* colourmap code */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if(!xf86HandleColormaps(pScreen, 256, 8, vboxLoadPalette, NULL, 0))
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pScreen->CloseScreen = SCRNINDEXAPI(VBOXCloseScreen);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* We probably do want to support power management - even if we just use
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync a dummy function. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Report any unused options (only for the first generation) */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Re-assert this in case we had a change request while switched out. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync VBOXAdjustScreenPixmap(pScrn, pVBox->FBSize.cx, pVBox->FBSize.cy);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!VBOXSetMode(pScrn, 0, pScrn->currentMode->HDisplay,
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync /* Do additional bits which are separate for historical reasons */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync return pScreen->CloseScreen(pScreen->myNum, pScreen);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Save the size in case we need to re-set it later. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync "We do not own the active VT, exiting.\n");
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync VBOXAdjustScreenPixmap(pScrn, pMode->HDisplay, pMode->VDisplay);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync rc = VBOXSetMode(pScrn, 0, pMode->HDisplay, pMode->VDisplay,
03493c32c4a1ce2b083405efe6f3b070bead1be6vboxsync vboxSaveVideoMode(pScrn, pMode->HDisplay, pMode->VDisplay,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Don't fiddle with the hardware if we are switched
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * to a virtual terminal. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync "We do not own the active VT, exiting.\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync VBOXSetMode(pScrn, 0, pVBox->aScreenLocation[0].cx,
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync /* Destroy the VGA hardware record */
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync /* And our private record */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth,
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight,