vboxvideo.c revision 7fee49908ea4b9f6cb4f9cc745633c4969ed6318
/* $Id$ */
/** @file
*
* Linux Additions X11 graphics driver
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
* --------------------------------------------------------------------
*
* This code is based on:
*
* X11 VESA driver
*
* Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of Conectiva Linux shall
* not be used in advertising or otherwise to promote the sale, use or other
* dealings in this Software without prior written authorization from
* Conectiva Linux.
*
* Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
*/
#ifdef XORG_7X
# include "xorg-server.h"
# include <string.h>
#endif
#include "vboxvideo.h"
#include <iprt/asm-math.h>
#include "version-generated.h"
#include "product-generated.h"
#include <xf86.h>
#include <misc.h>
/* All drivers initialising the SW cursor need this */
#include "mipointer.h"
/* All drivers implementing backing store need this */
#include "mibstore.h"
/* Colormap handling */
#include "micmap.h"
#include "xf86cmap.h"
/* DPMS */
/* #define DPMS_SERVER
#include "extensions/dpms.h" */
/* VGA hardware functions for setting and restoring text mode */
#include "vgaHW.h"
#ifdef VBOXVIDEO_13
/* X.org 1.3+ mode setting */
# define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
# include "xf86Crtc.h"
# include "xf86Modes.h"
#endif
/* Mandatory functions */
static void VBOXIdentify(int flags);
#ifndef PCIACCESS
#else
#endif
char **argv);
unsigned cHeight, int x, int y);
int flags);
/* locally used functions */
enum GenericTypes
{
};
#ifdef PCIACCESS
static const struct pci_id_match vbox_device_match[] = {
{
0, 0, 0
},
{ 0, 0, 0 },
};
#endif
/* Supported chipsets */
static SymTabRec VBOXChipsets[] =
{
{VBOX_DEVICEID, "vbox"},
{-1, NULL}
};
static PciChipsets VBOXPCIchipsets[] = {
};
/*
* This contains the functions needed by the server after loading the
* driver module. It must be supplied, and gets added the driver list by
* the Module Setup function in the dynamic case. In the static case a
* reference to this is compiled in, and this requires that the name of
* this DriverRec be an upper-case version of the driver name.
*/
#ifdef XORG_7X
#endif
#ifdef PCIACCESS
NULL,
#else
#endif
NULL,
0,
#ifdef XORG_7X
NULL,
#endif
#ifdef PCIACCESS
#endif
};
/* No options for now */
static const OptionInfoRec VBOXOptions[] = {
};
#ifndef XORG_7X
/*
* List of symbols from other modules that this module references. This
* list is used to tell the loader that it is OK for symbols here to be
* unresolved providing that it hasn't been told that they haven't been
* told that they are essential via a call to xf86LoaderReqSymbols() or
* xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
* unresolved symbols that are not required.
*/
static const char *fbSymbols[] = {
"fbPictureInit",
"fbScreenInit",
};
static const char *shadowfbSymbols[] = {
"ShadowFBInit2",
};
static const char *vbeSymbols[] = {
"VBEExtendedInit",
"VBEFindSupportedDepths",
"VBEGetModeInfo",
"VBEGetVBEInfo",
"VBEGetVBEMode",
"VBEPrintModes",
"VBESaveRestore",
"VBESetDisplayStart",
"VBESetGetDACPaletteFormat",
"VBESetGetLogicalScanlineLength",
"VBESetGetPaletteData",
"VBESetModeNames",
"VBESetModeParameters",
"VBESetVBEMode",
"VBEValidateModes",
"vbeDoEDID",
"vbeFree",
};
static const char *ramdacSymbols[] = {
"xf86InitCursor",
"xf86CreateCursorInfoRec",
};
static const char *vgahwSymbols[] = {
"vgaHWGetHWRec",
"vgaHWHandleColormaps",
"vgaHWFreeHWRec",
"vgaHWMapMem",
"vgaHWUnmapMem",
"vgaHWSaveFonts",
"vgaHWRestoreFonts",
"vgaHWGetIndex",
"vgaHWSaveScreen",
"vgaHWDPMSSet",
};
#endif /* !XORG_7X */
static VBOXPtr
{
if (!pScrn->driverPrivate)
{
}
}
static void
{
}
#ifdef VBOXVIDEO_13
/* X.org 1.3+ mode-setting support ******************************************/
/* For descriptions of these functions and structures, see
hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
X.Org source tree. */
static const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
};
static void
{
}
static Bool
static Bool
static void
{ (void) crtc; }
static void
DisplayModePtr adjusted_mode, int x, int y)
{
(void) mode;
adjusted_mode->VDisplay, x, y);
/* Don't remember any modes set while we are seamless, as they are
* just temporary. */
}
static void
static void *
static const xf86CrtcFuncsRec VBOXCrtcFuncs = {
.dpms = vbox_crtc_dpms,
.lock = vbox_crtc_lock,
.commit = vbox_crtc_stub,
returns NULL. */
.shadow_destroy = NULL,
.show_cursor = NULL,
.hide_cursor = NULL,
.load_cursor_argb = NULL,
};
static void
{ (void) output; }
static void
static int
{
/* We always like modes specified by the user in the configuration
* file and modes requested by the host, as doing otherwise is likely to
* annoy people. */
)
return rc;
}
static Bool
static void
/* A virtual monitor is always connected. */
static xf86OutputStatus
{
(void) output;
return XF86OutputStatusConnected;
}
static DisplayModePtr
const char *pszName, int x, int y,
{
/* We don't ask the host whether it likes user defined modes,
* as we assume that the user really wanted that mode. */
if (isPreferred)
/* Older versions of VBox only support screen widths which are a multiple
* of 8 */
else
} else {
}
return pMode;
}
static DisplayModePtr
{
unsigned i, cIndex = 0;
TRACE_ENTRY();
/* Add standard modes supported by the host */
for ( ; ; )
{
if (cIndex == 0)
break;
}
/* Also report any modes the user may have requested in the xorg.conf
* configuration file. */
{
}
TRACE_EXIT();
return pModes;
}
#ifdef RANDR_12_INTERFACE
static Atom
vboxAtomVBoxMode(void)
{
}
static Atom
vboxAtomEDID(void)
{
}
/** We use this for receiving information from clients for the purpose of
* dynamic resizing, and later possibly other things too.
*/
static Bool
{
TRACE_LOG("property=%d, value->type=%d, value->format=%d, value->size=%ld\n",
if (property == vboxAtomVBoxMode())
{
char sz[256] = { 0 };
int w, h;
return FALSE;
return FALSE;
return TRUE;
}
if (property == vboxAtomEDID())
return TRUE;
return FALSE;
}
#endif
static const xf86OutputFuncsRec VBOXOutputFuncs = {
.dpms = vbox_output_dpms,
#ifdef RANDR_12_INTERFACE
#endif
};
#endif /* VBOXVIDEO_13 */
#ifdef XFree86LOADER
/* Module loader interface */
static MODULESETUPPROTO(vboxSetup);
static XF86ModuleVersionInfo vboxVersionRec =
{
#ifdef XORG_7X
#else
#endif
1, /* Module major version. Xorg-specific */
0, /* Module minor version. Xorg-specific */
1, /* Module patchlevel. Xorg-specific */
ABI_CLASS_VIDEODRV, /* This is a video driver */
{0, 0, 0, 0}
};
/*
* This data is accessed by the loader. The name must be the module name
* followed by "ModuleData".
*/
#ifdef XORG_7X
#endif
static pointer
{
if (!Initialised)
{
Initialised = TRUE;
#ifdef PCIACCESS
#else
#endif
#ifndef XORG_7X
NULL);
#endif
(void *)&VBOXVIDEO);
}
if (ErrorMajor)
return (NULL);
}
#endif /* XFree86Loader defined */
static const OptionInfoRec *
{
return (VBOXOptions);
}
static void
VBOXIdentify(int flags)
{
}
/*
* This function is called once, at the start of the first server generation to
* do a minimal probe for supported hardware.
*/
#ifdef PCIACCESS
static Bool
{
TRACE_ENTRY();
}
}
#endif
#ifndef PCIACCESS
static Bool
{
int numDevSections;
/*
* Find the config file Device sections that match this
* driver, and return if there are none.
*/
&devSections)) <= 0)
return (FALSE);
/* PCI BUS */
if (xf86GetPciVideoInfo()) {
int numUsed;
int *usedChips;
int i;
if (numUsed > 0) {
if (flags & PROBE_DETECT)
foundScreen = TRUE;
else {
for (i = 0; i < numUsed; i++) {
/* Allocate a ScrnInfoRec */
foundScreen = TRUE;
}
}
}
}
}
return (foundScreen);
}
#endif
/**
* This function hooks into the chain that is called when framebuffer access
* is allowed or disallowed by a call to EnableDisableFBAccess in the server.
* In other words, it observes when the server wishes access to the
* framebuffer to be enabled and when it should be disabled. We need to know
* this because we disable access ourselves during mode switches (presumably
* the server should do this but it doesn't) and want to know whether to
* restore it or not afterwards.
*/
static void
{
TRACE_EXIT();
}
/** Calculate the BPP from the screen depth */
static uint16_t
{
}
/** Calculate the scan line length for a display width */
static int32_t
{
}
/** Calculate the display pitch from the scan line length */
static int32_t
{
}
/*
* QUOTE from the XFree86 DESIGN document:
*
* The purpose of this function is to find out all the information
* required to determine if the configuration is usable, and to initialise
* those parts of the ScrnInfoRec that can be set once at the beginning of
* the first server generation.
*
* (...)
*
* This includes probing for video memory, clocks, ramdac, and all other
* and related info. It includes validating and determining the set of
* video modes that will be used (and anything that is required to
* determine that).
*
* This information should be determined in the least intrusive way
* possible. The state of the HW must remain unchanged by this function.
* Although video memory (including MMIO) may be mapped within this
* function, it must be unmapped before returning.
*
* END QUOTE
*/
static Bool
{
unsigned DispiId;
TRACE_ENTRY();
/* Are we really starting the server, or is this just a dummy run? */
if (flags & PROBE_DETECT)
return (FALSE);
"VirtualBox guest additions video driver version "
VBOX_VERSION_STRING "\n");
/* Get our private data from the ScrnInfoRec structure. */
/* Initialise the guest library */
/* Entity information seems to mean bus information. */
/* The ramdac module is needed for the hardware cursor. */
return FALSE;
/* We need the vbe module because we use VBE code to save and restore
text mode, in order to keep our code simple. */
return (FALSE);
/* The framebuffer module. */
return (FALSE);
return FALSE;
return FALSE;
#ifdef VBOX_DRI
/* Load the dri module. */
return FALSE;
#endif
#ifndef PCIACCESS
return FALSE;
#endif
/* Set up our ScrnInfoRec structure to describe our virtual
capabilities to X. */
/* Let's create a nice, capable virtual monitor.
* This *is* still needed, at least for server version 1.3 */
/* Using the PCI information caused problems with non-powers-of-two
sized video RAM configurations */
/* Check if the chip restricts horizontal resolution or not. */
if (DispiId == VBE_DISPI_ID_ANYX)
else
/* Set up clock information that will support all modes we need. */
/* Query the host for the preferred colour depth */
{
/* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
if (cBits != 16)
cBits = 24;
return FALSE;
}
{
"The VBox additions only support 16 and 32bpp graphics modes\n");
return FALSE;
}
#ifdef VBOXVIDEO_13
/* Work around a bug in the original X server modesetting code, which
* took the first valid values set to these two as maxima over the
* server lifetime. */
#else
/* We don't validate with xf86ValidateModes and xf86PruneModes as we
* already know what we like and what we don't. */
/* Set the right virtual resolution. */
#endif /* !VBOXVIDEO_13 */
/* Needed before we initialise DRI. */
/* Colour weight - we always call this, since we are always in
truecolour. */
return (FALSE);
/* visual init */
return (FALSE);
/* Set the DPI. Perhaps we should read this from the host? */
/* Framebuffer-related setup */
/* VGA hardware initialisation */
if (!vgaHWGetHWRec(pScrn))
return FALSE;
TRACE_EXIT();
return (TRUE);
}
/**
* Dummy function for setting the colour palette, which we actually never
* touch. However, the server still requires us to provide this.
*/
static void
{
(void)pVisual;
}
/*
* QUOTE from the XFree86 DESIGN document:
*
* This is called at the start of each server generation.
*
* (...)
*
* Decide which operations need to be placed under resource access
* control. (...) Map any video memory or other memory regions. (...)
* Save the video card state. (...) Initialise the initial video
* mode.
*
* End QUOTE.
*/
static Bool
{
unsigned flags;
TRACE_ENTRY();
/* We make use of the X11 VBE code to save and restore text mode, in
order to keep our code simple. */
| RESTORE_BIOS_SCRATCH)) == NULL)
return (FALSE);
if (pScrn->memPhysBase == 0) {
#ifdef PCIACCESS
#else
#endif
}
if (!VBOXMapVidMem(pScrn))
return (FALSE);
/* save current video state */
/* mi layer - reset the visual list (?)*/
return (FALSE);
return (FALSE);
if (!miSetPixmapDepths())
return (FALSE);
#ifdef VBOX_DRI
#endif
/* I checked in the sources, and XFree86 4.2 does seem to support
this function for 32bpp. */
return (FALSE);
/* Fixup RGB ordering */
}
}
/* must be after RGB ordering fixed */
fbPictureInit(pScreen, 0, 0);
/* We need to keep track of whether we are currently switched to a virtual
* terminal to know whether a mode set operation is currently safe to do.
*/
}
#ifdef VBOXVIDEO_13
/* Initialise CRTC and output configuration for use with randr1.2. */
{
uint32_t i;
{
char szOutput[256];
/* Setup our virtual CRTCs. */
/* Set up our virtual outputs. */
szOutput);
/* We are not interested in the monitor section in the
* configuration file. */
TRACE_LOG("Created crtc (%p) and output %s (%p)\n",
}
}
/* Set a sane minimum and maximum mode size */
return (FALSE);
}
/* Initialise randr 1.2 mode-setting functions and set first mode.
* Note that the mode won't be usable until the server has resized the
* framebuffer to something reasonable. */
if (!xf86CrtcScreenInit(pScreen)) {
return FALSE;
}
/* Create our VBOX_MODE display properties. */
{
uint32_t i;
{
char csz[] = "0x0";
FALSE);
}
}
if (!xf86SetDesiredModes(pScrn)) {
return FALSE;
}
#else /* !VBOXVIDEO_13 */
/* set first video mode */
return FALSE;
/* And make sure that a non-current dynamic mode is at the front of the
* list */
#endif /* !VBOXVIDEO_13 */
/* software cursor */
/* colourmap code */
if (!miCreateDefColormap(pScreen))
return (FALSE);
return (FALSE);
/* Hook our observer function ito the chain which is called when
* framebuffer access is enabled or disabled in the server, and
* assume an initial state of enabled. */
#ifdef VBOXVIDEO_13
#else
#endif
#ifdef VBOXVIDEO_13
#else
/* We probably do want to support power management - even if we just use
a dummy function. */
#endif
/* Report any unused options (only for the first generation) */
if (serverGeneration == 1)
"Unable to start the VirtualBox mouse pointer integration with the host system.\n");
#ifdef VBOX_DRI
#endif
return (TRUE);
}
/** Clear the virtual framebuffer in VRAM. Optionally also clear up to the
* size of a new framebuffer. Framebuffer sizes larger than available VRAM
* be treated as zero and passed over. */
static void
{
cbOldFB = 0;
cbNewFB = 0;
}
static Bool
{
TRACE_ENTRY();
vboxClearVRAM(pScrn, 0, 0);
if (pVBox->fHaveHGSMI)
#ifdef VBOX_DRI
#endif
#ifdef VBOXVIDEO_13
if (!xf86SetDesiredModes(pScrn))
return FALSE;
#else
return FALSE;
#endif
return TRUE;
}
static void
{
TRACE_ENTRY();
if (pVBox->fHaveHGSMI)
vboxClearVRAM(pScrn, 0, 0);
#ifdef VBOX_DRI
#endif
TRACE_EXIT();
}
static Bool
{
if (pVBox->fHaveHGSMI)
vboxClearVRAM(pScrn, 0, 0);
#ifdef VBOX_DRI
#endif
}
/* Destroy the VGA hardware record */
/* And do additional bits which are separate for historical reasons */
/* Remove our observer functions from the X server call chains. */
}
static Bool
{
/* We want to disable access to the framebuffer before switching mode.
* After doing the switch, we allow access if it was allowed before. */
if (pVBox->accessEnabled)
#ifdef VBOXVIDEO_13
#else
if (rc)
{
}
#endif
if (pVBox->accessEnabled)
return rc;
}
/** Set a graphics mode. Poke any required values into registers, do an HGSMI
* mode set and tell the host we support advanced graphics functions. This
* procedure is complicated by the fact that X.Org can implicitly disable a
* screen by resizing the virtual framebuffer so that the screen is no longer
* inside it. We have to spot and handle this.
*/
static Bool
unsigned cHeight, int x, int y)
{
TRACE_LOG("cDisplay=%u, cWidth=%u, cHeight=%u, x=%d, y=%d, displayWidth=%d\n",
/* Deactivate the screen if the mode - specifically the virtual width - is
* too large for VRAM as we sometimes have to do this - see comments in
* VBOXPreInit. */
/* Deactivate the screen if it is outside of the virtual framebuffer and
* clamp it to lie inside if it is partly outside. */
else
TRACE_LOG("pVBox->afDisabled[cDisplay]=%d, fActive=%d\n",
/* Don't fiddle with the hardware if we are switched
* to a virtual terminal. */
{
if (cDisplay == 0)
/* Tell the host we support graphics */
if (vbox_device_available(pVBox))
}
if ( (pVBox->fHaveHGSMI)
| (fActive ? 0: VBVA_SCREEN_F_DISABLED));
return rc;
}
/** Resize the virtual framebuffer. After resizing we reset all modes
* (X.Org 1.3+) to adjust them to the new framebuffer.
*/
{
if (!pPixmap) {
"Failed to get the screen pixmap.\n");
return FALSE;
}
{
"Unable to set up a virtual screen size of %dx%d with %lu of %d Kb of video memory available. Please increase the video memory size.\n",
return FALSE;
}
#ifdef VBOX_DRI
#endif
#ifdef VBOXVIDEO_13
/* Write the new values to the hardware */
{
unsigned i;
pVBox->aScreenLocation[i].x,
pVBox->aScreenLocation[i].y);
}
#endif
return TRUE;
}
static void
{
TRACE_ENTRY();
/* Don't fiddle with the hardware if we are switched
* to a virtual terminal. */
TRACE_EXIT();
}
static void
{
}
static Bool
{
TRACE_ENTRY();
{
#ifdef PCIACCESS
#else
#endif
{
}
else
}
return rc;
}
static void
{
TRACE_ENTRY();
return;
#ifdef PCIACCESS
#else
#endif
TRACE_EXIT();
}
static Bool
{
return TRUE;
}
{
TRACE_ENTRY();
if (rc)
{
/* Query amount of memory to save state */
if (function == MODE_QUERY ||
{
/* Make sure we save at least this information in case of failure */
)
}
}
if (rc)
{
if (function != MODE_QUERY) {
if (function == MODE_RESTORE)
)
)
{
/* don't rely on the memory not being touched */
}
if (function == MODE_RESTORE)
{
}
}
}
return rc;
}
static void
int flags)
{
}