vboxvideo_70.c revision e60b397fc7f34482960cc63f63db84d6a02226d1
/** @file
*
* Linux Additions X11 graphics driver
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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>
*/
#define DEBUG_VERB 2
#ifdef XFree86LOADER
# include "xorg-server.h"
#else
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
#endif
#include "vboxvideo.h"
#include "version-generated.h"
#include <xf86.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" */
/* Mandatory functions */
static void VBOXIdentify(int flags);
char **argv);
int flags);
/* locally used functions */
int *indices,
/* Initialise DGA */
/*
* 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 funtion 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.
*/
NULL,
0,
};
/* Supported chipsets */
static SymTabRec VBOXChipsets[] =
{
{VBOX_VESA_DEVICEID, "vbox"},
{-1, NULL}
};
static PciChipsets VBOXPCIchipsets[] = {
};
typedef enum {
} VBOXOpts;
/* No options for now */
static const OptionInfoRec VBOXOptions[] = {
};
/*
* 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",
};
#ifdef XFree86LOADER
/* Module loader interface */
static MODULESETUPPROTO(vboxSetup);
static XF86ModuleVersionInfo vboxVersionRec =
{
"Sun Microsystems, Inc.",
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".
*/
static pointer
{
if (!Initialised)
{
Initialised = TRUE;
NULL);
}
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.
*/
static Bool
{
int numDevSections, numUsed;
int *usedChips;
int i;
/*
* Find the config file Device sections that match this
* driver, and return if there are none.
*/
&devSections)) <= 0)
return (FALSE);
/* PCI BUS */
if (xf86GetPciVideoInfo()) {
if (numUsed > 0) {
if (flags & PROBE_DETECT)
foundScreen = TRUE;
else {
for (i = 0; i < numUsed; i++) {
/* Allocate a ScrnInfoRec */
foundScreen = TRUE;
}
}
}
}
}
return (foundScreen);
}
static VBOXPtr
{
if (!pScrn->driverPrivate)
{
#if 0
#endif
}
}
static void
{
#if 0
#endif
}
/*
* 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
{
int i;
char *pcHostModeName = NULL;
/* 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. */
return FALSE;
/* 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;
/* Set up our ScrnInfoRec structure to describe our virtual
capabilities to X. */
/* Let's create a nice, capable virtual monitor. */
/* Determine the size of the VBox video RAM from PCI data*/
#if 0
#endif
/* Using the PCI information caused problems with non-powers-of-two
sized video RAM configurations */
/* Set up clock information that will support all modes we need. */
/* Query the host for the preferred resolution and colour depth */
{
pVBox))
{
/* 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;
}
/* To get around the problem of SUSE specifying a single, invalid mode in their
* Xorg.conf by default, we add additional modes to the end of the user specified
* list. This means that if all user modes are invalid, X will try our mode before
* falling back to its standard mode list. */
{
i = 0;
/* The user specified no modes at all. */
}
else
{
* sizeof(char *));
}
/* Add additional modes to the end of the mode list in case the others are
all invalid. */
if (pcHostModeName != NULL)
{
++i;
}
{
++i;
}
{
++i;
}
/* A mode of last resort */
++i;
/* Create a builtin mode for every specified mode. This allows to specify arbitrary
* screen resolutions */
{
int x = 0, y = 0;
m->type = M_T_BUILTIN;
/* VBox does only support screen widths which are a multiple of 8 */
m->VDisplay = y;
if (!m_prev)
else
m_prev = m;
}
/* Colour weight - we always call this, since we are always in
truecolour. */
return (FALSE);
/* visual init */
return (FALSE);
/* Set a sane minimum mode size and the maximum allowed by the available VRAM */
{
do {
trySize += 128;
/* I don't know exactly what these are for (and they are only used in a couple
of places in the X server code). */
}
/* Filter out video modes not supported by the virtual hardware
we described. */
if (i <= 0) {
return (FALSE);
}
/* Set display resolution. Perhaps we should read this from the host. */
return (FALSE);
}
/* options */
return FALSE;
/* Framebuffer-related setup */
return (TRUE);
}
/*
* 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.Initialise the initial video mode.
*/
static Bool
{
unsigned flags;
/* 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);
/* pVBox->mapSize = 1 << pVBox->pciInfo->size[0]; */
/* Using the PCI information caused problems with
non-powers-of-two sized video RAM configurations */
}
if (!VBOXMapVidMem(pScrn))
return (FALSE);
/* save current video state */
/* set first video mode */
return FALSE;
/* set the viewport */
/* Blank the screen for aesthetic reasons. */
/* mi layer - reset the visual list (?)*/
return (FALSE);
return (FALSE);
if (!miSetPixmapDepths())
return (FALSE);
/* 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);
/* software cursor */
/* colourmap code - apparently, we need this even in Truecolour */
if (!miCreateDefColormap(pScreen))
return (FALSE);
8 /* DAC is switchable to 8 bits per primary color */,
return (FALSE);
/* However, we probably do want to support power management -
even if we just use a dummy function. */
/* 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");
"The VBox video extensions are now enabled.\n");
}
return (TRUE);
}
static Bool
{
return FALSE;
return TRUE;
}
static void
{
}
static Bool
{
}
}
}
static Bool
{
return FALSE;
return FALSE;
return TRUE;
}
/* Set a graphics mode */
static Bool
{
{
"Unable to set up a virtual screen size of %dx%d with %d Kb of video memory. Please increase the video memory size.\n",
return FALSE;
}
/* We only support horizontal resolutions which are a multiple of 8. Round down if
necessary. */
if (xRes % 8 != 0)
{
"VirtualBox only supports screen widths which are a multiple of 8. Rounding down from %d to %d\n",
}
/* Disable linear framebuffer mode before making changes to the resolution. */
/* Unlike the resolution, the depth is fixed for a given screen
for the lifetime of the X session. */
/* HDisplay and VDisplay are actually monitor information about
the display part of the scanlines. */
/* Enable linear framebuffer mode. */
/* Set the virtual resolution. We are still using VESA to control
the virtual offset. */
return (TRUE);
}
static void
{
}
static void
{
}
static Bool
{
return (TRUE);
0xa0000, 0x10000);
}
}
static void
{
return;
}
static void
{
int i, idx;
#define VBOXDACDelay() \
do { \
} while (0)
for (i = 0; i < numColors; i++) {
VBOXDACDelay();
VBOXDACDelay();
VBOXDACDelay();
VBOXDACDelay();
}
}
/*
* Just adapted from the std* functions in vgaHW.c
*/
static void
{
index |= 0x20;
}
static int
{
index |= 0x20;
}
static int
{
}
static int
{
}
static void
{
if (start) {
}
else {
}
}
static void
{
return;
/* If in graphics mode, don't save anything */
if (attr10 & 0x01)
return;
/* save the registers that are needed here */
miscOut = ReadMiscOut();
/* Force into colour mode */
/*font1 */
/* font2 */
/* Restore clobbered registers */
}
static void
{
return;
/* save the registers that are needed here */
miscOut = ReadMiscOut();
/* Force into colour mode */
/* GJA */
}
/* restore the registers that were changed */
}
static Bool
{
if (on)
if (on)
scrn &= ~0x20;
else
scrn |= 0x20;
}
return (TRUE);
}
{
return (FALSE);
/* Query amount of memory to save state */
if (function == MODE_QUERY ||
{
/* Make sure we save at least this information in case of failure */
return FALSE;
}
if (function != MODE_QUERY) {
if (function == MODE_RESTORE)
{
/* don't rely on the memory not being touched */
}
if (function == MODE_RESTORE)
{
}
if (!retval)
return (FALSE);
}
return (TRUE);
}
static void
int flags)
{
/* VBox is always power efficient... */
}
/***********************************************************************
* DGA stuff
***********************************************************************/
unsigned char **ApertureBase,
int *ApertureSize, int *ApertureOffset,
int *flags);
static Bool
unsigned char **ApertureBase, int *ApertureSize,
int *ApertureOffset, int *flags)
{
*flags = DGA_NEED_ROOT;
return (TRUE);
}
static Bool
{
if (pDGAMode) {
}
else {
return (TRUE);
}
return (FALSE);
return (TRUE);
}
static void
{
}
static int
{
return (0);
}
static DGAFunctionRec VBOXDGAFunctions =
{
NULL, /* CloseFramebuffer */
NULL, /* Sync */
NULL, /* FillRect */
NULL, /* BlitRect */
NULL, /* BlitTransRect */
};
static void
{
do {
if (!pDGAMode)
break;
}
static Bool
{
}