vboxvideo.c revision ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354
/* $Id$ */
/** @file
*
* Linux Additions X11 graphics driver
*/
/*
* Copyright (C) 2006-2011 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 "xf86.h"
#include "xf86_OSproc.h"
# include "xf86Resources.h"
#endif
#ifndef PCIACCESS
/* Drivers for PCI hardware need this */
# include "xf86PciInfo.h"
/* Drivers that need to access the PCI config space directly need this */
# include "xf86Pci.h"
#endif
#include "fb.h"
#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"
/* 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);
int flags);
/* locally used functions */
{
if (!pScrn->driverPrivate)
}
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 *ramdacSymbols[] = {
"xf86InitCursor",
"xf86CreateCursorInfoRec",
};
static const char *vgahwSymbols[] = {
"vgaHWFreeHWRec",
"vgaHWGetHWRec",
"vgaHWGetIOBase",
"vgaHWGetIndex",
"vgaHWRestore",
"vgaHWSave",
"vgaHWSetStdFuncs",
};
#endif /* !XORG_7X */
#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();
if (!pVBox)
return FALSE;
}
}
#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();
}
/*
* 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. */
if (!pVBox)
return FALSE;
/* Initialise the guest library */
/* Entity information seems to mean bus information. */
/* The ramdac module is needed for the hardware cursor. */
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. */
/** @note needed during colourmap initialisation */
/* Let's create a nice, capable virtual monitor. */
/* Using the PCI information caused problems with non-powers-of-two
sized video RAM configurations */
/* Check if the chip restricts horizontal resolution or not. */
/* 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. */
/* VGA hardware initialisation */
if (!vgaHWGetHWRec(pScrn))
return FALSE;
/* Must be called before any VGA registers are saved or restored */
/* 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? */
if (pScrn->memPhysBase == 0) {
#ifdef PCIACCESS
#else
#endif
}
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();
if (!VBOXMapVidMem(pScrn))
return (FALSE);
/* save current video state */
/* mi layer - reset the visual list (?)*/
return (FALSE);
if (!miSetPixmapDepths())
return (FALSE);
#ifdef VBOX_DRI
#endif
return (FALSE);
/* Fixup RGB ordering */
/** @note the X server uses this even in true colour. */
}
}
/* 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);
}
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
}
/* 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;
}
static void
{
TRACE_ENTRY();
/* Don't fiddle with the hardware if we are switched
* to a virtual terminal. */
TRACE_EXIT();
}
static void
{
/* Destroy the VGA hardware record */
/* And our private record */
}
static Bool
{
TRACE_ENTRY();
{
#ifdef PCIACCESS
#else
#endif
}
return rc;
}
static void
{
TRACE_ENTRY();
return;
#ifdef PCIACCESS
#else
#endif
TRACE_EXIT();
}
static Bool
{
return TRUE;
}
void
{
TRACE_ENTRY();
&pVBox->cSavedPitch,
&pVBox->fSavedFlags);
}
void
{
TRACE_ENTRY();
if (pVBox->fSavedVBEMode)
pVBox->fSavedFlags, 0, 0);
else
}
static void
int flags)
{
}