vboxvideo.c revision 03493c32c4a1ce2b083405efe6f3b070bead1be6
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* $Id$ */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/** @file
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff *
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Linux Additions X11 graphics driver
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/*
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Copyright (C) 2006-2011 Oracle Corporation
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff *
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 *
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * This code is based on the X.Org VESA driver with the following copyrights:
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff *
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 *
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * and the following permission notice (not all original sourse files include
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * the last paragraph):
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff *
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 *
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * The above copyright notice and this permission notice shall be included in
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * all copies or substantial portions of the Software.
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff *
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 * SOFTWARE.
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff *
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 *
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 */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifdef XORG_7X
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff# include "xorg-server.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff# include <string.h>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "xf86.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "xf86_OSproc.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff# include "xf86Resources.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifndef PCIACCESS
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* Drivers for PCI hardware need this */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff# include "xf86PciInfo.h"
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff/* Drivers that need to access the PCI config space directly need this */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff# include "xf86Pci.h"
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "fb.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "vboxvideo.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include <iprt/asm-math.h>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "version-generated.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "product-generated.h"
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#include <xf86.h>
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff#include <misc.h>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* All drivers initialising the SW cursor need this */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "mipointer.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* Colormap handling */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "micmap.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#include "xf86cmap.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* DPMS */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* #define DPMS_SERVER
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#include "extensions/dpms.h" */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* VGA hardware functions for setting and restoring text mode */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#include "vgaHW.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifdef VBOXVIDEO_13
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* X.org 1.3+ mode setting */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff# define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff# include "xf86Crtc.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff# include "xf86Modes.h"
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff# include <X11/Xatom.h>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* Mandatory functions */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void VBOXIdentify(int flags);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifndef PCIACCESS
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXProbe(DriverPtr drv, int flags);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#else
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXPciProbe(DriverPtr drv, int entity_num,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff struct pci_device *dev, intptr_t match_data);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXScreenInit(int Index, ScreenPtr pScreen, int argc,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff char **argv);
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 int flags);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* locally used functions */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool VBOXMapVidMem(ScrnInfoPtr pScrn);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void VBOXUnmapVidMem(ScrnInfoPtr pScrn);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void VBOXSaveMode(ScrnInfoPtr pScrn);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void VBOXRestoreMode(ScrnInfoPtr pScrn);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic inline void VBOXSetRec(ScrnInfoPtr pScrn)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (!pScrn->driverPrivate)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->driverPrivate = calloc(sizeof(VBOXRec), 1);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffenum GenericTypes
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff CHIP_VBOX_GENERIC
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff};
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef PCIACCESS
44c68f247b9311ea767cb4656220793317e3383bJeff Conniffstatic const struct pci_id_match vbox_device_match[] = {
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff {
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff 0, 0, 0
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff },
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff { 0, 0, 0 },
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff};
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff#endif
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff/* Supported chipsets */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic SymTabRec VBOXChipsets[] =
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff {VBOX_DEVICEID, "vbox"},
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff {-1, NULL}
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff};
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic PciChipsets VBOXPCIchipsets[] = {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA },
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff { -1, -1, RES_UNDEFINED },
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff};
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff/*
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 */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifdef XORG_7X
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff_X_EXPORT
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffDriverRec VBOXVIDEO = {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOX_VERSION,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOX_DRIVER_NAME,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOXIdentify,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff#ifdef PCIACCESS
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff NULL,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#else
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOXProbe,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOXAvailableOptions,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff NULL,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff 0,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifdef XORG_7X
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff NULL,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef PCIACCESS
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff vbox_device_match,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOXPciProbe
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff};
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* No options for now */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic const OptionInfoRec VBOXOptions[] = {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff { -1, NULL, OPTV_NONE, {0}, FALSE }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff};
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifndef XORG_7X
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/*
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 Conniff */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniffstatic const char *fbSymbols[] = {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff "fbPictureInit",
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff "fbScreenInit",
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff NULL
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff};
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const char *shadowfbSymbols[] = {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "ShadowFBInit2",
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff NULL
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff};
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const char *ramdacSymbols[] = {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "xf86InitCursor",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "xf86CreateCursorInfoRec",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff NULL
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff};
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
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 NULL
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff};
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif /* !XORG_7X */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifdef VBOXVIDEO_13
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* X.org 1.3+ mode-setting support ******************************************/
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
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 Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool vbox_config_resize(ScrnInfoPtr pScrn, int cw, int ch)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOXPtr pVBox = VBOXGetRec(pScrn);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_LOG("width=%d, height=%d\n", cw, ch);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /* Save the size in case we need to re-set it later. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->FBSize.cx = cw;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->FBSize.cy = ch;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /* Don't fiddle with the hardware if we are switched
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * to a virtual terminal. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (!pScrn->vtSema) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "We do not own the active VT, exiting.\n");
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return TRUE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return VBOXAdjustScreenPixmap(pScrn, cw, ch);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff vbox_config_resize
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff};
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic void
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_crtc_dpms(xf86CrtcPtr crtc, int mode)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOXPtr pVBox = VBOXGetRec(crtc->scrn);
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 if (!crtc->scrn->vtSema) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "We do not own the active VT, exiting.\n");
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if ( pVBox->aScreenLocation[cDisplay].cx
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff && pVBox->aScreenLocation[cDisplay].cy)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOXSetMode(crtc->scrn, cDisplay,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->aScreenLocation[cDisplay].cx,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->aScreenLocation[cDisplay].cy,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->aScreenLocation[cDisplay].x,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->aScreenLocation[cDisplay].y);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff}
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic Bool
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_crtc_lock (xf86CrtcPtr crtc)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{ (void) crtc; return FALSE; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
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 Conniffstatic Bool
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff DisplayModePtr adjusted_mode)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{ (void) crtc; (void) mode; (void) adjusted_mode; return TRUE; }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_crtc_stub (xf86CrtcPtr crtc)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{ (void) crtc; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic void
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff DisplayModePtr adjusted_mode, int x, int y)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff (void) mode;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOXPtr pVBox = VBOXGetRec(crtc->scrn);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff unsigned cDisplay = (uintptr_t)crtc->driver_private;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
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->afDisabled[cDisplay] = false;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->aScreenLocation[cDisplay].cx = adjusted_mode->HDisplay;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pVBox->aScreenLocation[cDisplay].cy = adjusted_mode->VDisplay;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->aScreenLocation[cDisplay].x = x;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->aScreenLocation[cDisplay].y = y;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Don't remember any modes set while we are seamless, as they are
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * just temporary. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (!vboxGuestIsSeamless(crtc->scrn))
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. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (!crtc->scrn->vtSema)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff "We do not own the active VT, exiting.\n");
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOXSetMode(crtc->scrn, cDisplay, adjusted_mode->HDisplay,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff adjusted_mode->VDisplay, x, y);
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff}
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
2353184083624510261e335c156a05e8cae2fc41Jeff Conniffstatic void
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_crtc_gamma_set (xf86CrtcPtr crtc, CARD16 *red,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff CARD16 *green, CARD16 *blue, int size)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{ (void) crtc; (void) red; (void) green; (void) blue; (void) size; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
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
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const xf86CrtcFuncsRec VBOXCrtcFuncs = {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .dpms = vbox_crtc_dpms,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .save = NULL, /* These two are never called by the server. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .restore = NULL,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .lock = vbox_crtc_lock,
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff .unlock = NULL, /* This will not be invoked if lock returns FALSE. */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff .mode_fixup = vbox_crtc_mode_fixup,
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff .prepare = vbox_crtc_stub,
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff .mode_set = vbox_crtc_mode_set,
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff .commit = vbox_crtc_stub,
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff .gamma_set = vbox_crtc_gamma_set,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .shadow_allocate = vbox_crtc_shadow_allocate,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .shadow_create = NULL, /* These two should not be invoked if allocate
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff returns NULL. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .shadow_destroy = NULL,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .set_cursor_colors = NULL, /* We are still using the old cursor API. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .set_cursor_position = NULL,
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff .show_cursor = NULL,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .hide_cursor = NULL,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .load_cursor_argb = NULL,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .destroy = vbox_crtc_stub
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff};
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_output_stub (xf86OutputPtr output)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{ (void) output; }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_dpms (xf86OutputPtr output, int mode)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{ (void) output; (void) mode; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic int
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff ScrnInfoPtr pScrn = output->scrn;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff int rc = MODE_OK;
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 if ( !(mode->type & M_T_USERDEF)
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff && !(mode->type & M_T_PREFERRED)
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff && vbox_device_available(VBOXGetRec(pScrn))
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff && !vboxHostLikesVideoMode(pScrn, mode->HDisplay, mode->VDisplay,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->bitsPerPixel)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff )
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff rc = MODE_BAD;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_LOG("returning %s\n", MODE_OK == rc ? "MODE_OK" : "MODE_BAD");
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return rc;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic Bool
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff DisplayModePtr adjusted_mode)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{ (void) output; (void) mode; (void) adjusted_mode; return TRUE; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic void
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff DisplayModePtr adjusted_mode)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{ (void) output; (void) mode; (void) adjusted_mode; }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/* A virtual monitor is always connected. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic xf86OutputStatus
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_output_detect (xf86OutputPtr output)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff (void) output;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return XF86OutputStatusConnected;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic DisplayModePtr
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffvbox_output_add_mode (VBOXPtr pVBox, DisplayModePtr *pModes,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff const char *pszName, int x, int y,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff Bool isPreferred, Bool isUserDef)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName, x, y);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->status = MODE_OK;
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 if (isPreferred)
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff pMode->type |= M_T_PREFERRED;
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff /* Older versions of VBox only support screen widths which are a multiple
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff * of 8 */
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff if (pVBox->fAnyX)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->HDisplay = x;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff else
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->HDisplay = x & ~7;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->HSyncStart = pMode->HDisplay + 2;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->HSyncEnd = pMode->HDisplay + 4;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pMode->HTotal = pMode->HDisplay + 6;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->VDisplay = y;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->VSyncStart = pMode->VDisplay + 2;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->VSyncEnd = pMode->VDisplay + 4;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->VTotal = pMode->VDisplay + 6;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode->Clock = pMode->HTotal * pMode->VTotal * 60 / 1000; /* kHz */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (NULL == pszName) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86SetModeDefaultName(pMode);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff } else {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pMode->name = xnfstrdup(pszName);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff *pModes = xf86ModesAdd(*pModes, pMode);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return pMode;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic DisplayModePtr
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_output_get_modes (xf86OutputPtr output)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff unsigned i, cIndex = 0;
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff DisplayModePtr pModes = NULL, pMode;
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff ScrnInfoPtr pScrn = output->scrn;
eeefbdad0b1d6614c497d69b0087c3a6bc5061b3Jeff Conniff VBOXPtr pVBox = VBOXGetRec(pScrn);
eeefbdad0b1d6614c497d69b0087c3a6bc5061b3Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff TRACE_ENTRY();
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff uint32_t x, y, bpp, iScreen;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff iScreen = (uintptr_t)output->driver_private;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff vboxGetPreferredMode(pScrn, iScreen, &x, &y, &bpp);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pMode = vbox_output_add_mode(pVBox, &pModes, NULL, x, y, TRUE, FALSE);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOXEDIDSet(output, pMode);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /* Add standard modes supported by the host */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff for ( ; ; )
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff cIndex = vboxNextStandardMode(pScrn, cIndex, &x, &y, NULL);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (cIndex == 0)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff break;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff vbox_output_add_mode(pVBox, &pModes, NULL, x, y, FALSE, FALSE);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
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 {
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,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff FALSE, TRUE);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff TRACE_EXIT();
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff return pModes;
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff}
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef RANDR_12_INTERFACE
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Atom
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffvboxAtomVBoxMode(void)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return MakeAtom("VBOX_MODE", sizeof("VBOX_MODE") - 1, TRUE);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Atom
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffvboxAtomEDID(void)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return MakeAtom("EDID", sizeof("EDID") - 1, TRUE);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff}
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
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 Conniff */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic Bool
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffvbox_output_set_property(xf86OutputPtr output, Atom property,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff RRPropertyValuePtr value)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff ScrnInfoPtr pScrn = output->scrn;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff VBOXPtr pVBox = VBOXGetRec(pScrn);
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 if (property == vboxAtomVBoxMode())
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff uint32_t cDisplay = (uintptr_t)output->driver_private;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff char sz[256] = { 0 };
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff int w, h;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if ( value->type != XA_STRING
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff || (unsigned) value->size > (sizeof(sz) - 1))
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return FALSE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff strncpy(sz, value->data, value->size);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_LOG("screen=%u, property value=%s\n", cDisplay, sz);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (sscanf(sz, "%dx%d", &w, &h) != 2)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return FALSE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->aPreferredSize[cDisplay].cx = w;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->aPreferredSize[cDisplay].cy = h;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return TRUE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (property == vboxAtomEDID())
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return TRUE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return FALSE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic const xf86OutputFuncsRec VBOXOutputFuncs = {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .create_resources = vbox_output_stub,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .dpms = vbox_output_dpms,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff .save = NULL, /* These two are never called by the server. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff .restore = NULL,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff .mode_valid = vbox_output_mode_valid,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff .mode_fixup = vbox_output_mode_fixup,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff .prepare = vbox_output_stub,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff .commit = vbox_output_stub,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff .mode_set = vbox_output_mode_set,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .detect = vbox_output_detect,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .get_modes = vbox_output_get_modes,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef RANDR_12_INTERFACE
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .set_property = vbox_output_set_property,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff .destroy = vbox_output_stub
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff};
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif /* VBOXVIDEO_13 */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef XFree86LOADER
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/* Module loader interface */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic MODULESETUPPROTO(vboxSetup);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic XF86ModuleVersionInfo vboxVersionRec =
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOX_DRIVER_NAME,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOX_VENDOR,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff MODINFOSTRING1,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff MODINFOSTRING2,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef XORG_7X
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff XORG_VERSION_CURRENT,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#else
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff XF86_VERSION_CURRENT,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff 1, /* Module major version. Xorg-specific */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff 0, /* Module minor version. Xorg-specific */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff 1, /* Module patchlevel. Xorg-specific */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff ABI_CLASS_VIDEODRV, /* This is a video driver */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff ABI_VIDEODRV_VERSION,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff MOD_CLASS_VIDEODRV,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff {0, 0, 0, 0}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff};
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/*
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * This data is accessed by the loader. The name must be the module name
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * followed by "ModuleData".
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifdef XORG_7X
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff_X_EXPORT
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffXF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic pointer
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffvboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff static Bool Initialised = FALSE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (!Initialised)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff Initialised = TRUE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef PCIACCESS
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#else
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86AddDriver(&VBOXVIDEO, Module, 0);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifndef XORG_7X
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff LoaderRefSymLists(fbSymbols,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff shadowfbSymbols,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff ramdacSymbols,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff vgahwSymbols,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff NULL);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n",
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff (void *)&VBOXVIDEO);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return (pointer)TRUE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (ErrorMajor)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff *ErrorMajor = LDR_ONCEONLY;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return (NULL);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff}
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif /* XFree86Loader defined */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic const OptionInfoRec *
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff ConniffVBOXAvailableOptions(int chipid, int busid)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff{
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return (VBOXOptions);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff}
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniffstatic void
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffVBOXIdentify(int flags)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff/*
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 Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifdef PCIACCESS
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniffstatic Bool
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffVBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff intptr_t match_data)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff{
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff ScrnInfoPtr pScrn;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_ENTRY();
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff NULL, NULL, NULL, NULL, NULL);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (pScrn != NULL) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOXPtr pVBox;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOXSetRec(pScrn);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox = VBOXGetRec(pScrn);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (!pVBox)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return FALSE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->driverVersion = VBOX_VERSION;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->driverName = VBOX_DRIVER_NAME;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->name = VBOX_NAME;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->Probe = NULL;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->PreInit = VBOXPreInit;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->ScreenInit = VBOXScreenInit;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->SwitchMode = VBOXSwitchMode;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->AdjustFrame = VBOXAdjustFrame;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pScrn->EnterVT = VBOXEnterVT;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->LeaveVT = VBOXLeaveVT;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->FreeScreen = VBOXFreeScreen;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pVBox->pciInfo = dev;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return (pScrn != NULL);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff}
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifndef PCIACCESS
44c68f247b9311ea767cb4656220793317e3383bJeff Conniffstatic Bool
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff ConniffVBOXProbe(DriverPtr drv, int flags)
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff{
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff Bool foundScreen = FALSE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff int numDevSections;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff GDevPtr *devSections;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /*
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * Find the config file Device sections that match this
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * driver, and return if there are none.
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff if ((numDevSections = xf86MatchDevice(VBOX_NAME,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff &devSections)) <= 0)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return (FALSE);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* PCI BUS */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (xf86GetPciVideoInfo()) {
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff int numUsed;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff int *usedChips;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff int i;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff VBOXChipsets, VBOXPCIchipsets,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff devSections, numDevSections,
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff drv, &usedChips);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff if (numUsed > 0) {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff if (flags & PROBE_DETECT)
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff foundScreen = TRUE;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff else {
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff for (i = 0; i < numUsed; i++) {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff ScrnInfoPtr pScrn = NULL;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* Allocate a ScrnInfoRec */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff VBOXPCIchipsets,NULL,
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff NULL,NULL,NULL,NULL))) {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->driverVersion = VBOX_VERSION;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->driverName = VBOX_DRIVER_NAME;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->name = VBOX_NAME;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->Probe = VBOXProbe;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->PreInit = VBOXPreInit;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->ScreenInit = VBOXScreenInit;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pScrn->SwitchMode = VBOXSwitchMode;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pScrn->AdjustFrame = VBOXAdjustFrame;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pScrn->EnterVT = VBOXEnterVT;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pScrn->LeaveVT = VBOXLeaveVT;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pScrn->FreeScreen = VBOXFreeScreen;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff foundScreen = TRUE;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff }
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff }
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff }
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff free(usedChips);
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff }
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff }
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff free(devSections);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff return (foundScreen);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff}
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff#endif
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff/*
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * QUOTE from the XFree86 DESIGN document:
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff *
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 *
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * (...)
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff *
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 *
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 *
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * END QUOTE
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniffstatic Bool
44c68f247b9311ea767cb4656220793317e3383bJeff ConniffVBOXPreInit(ScrnInfoPtr pScrn, int flags)
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff{
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff VBOXPtr pVBox;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff Gamma gzeros = {0.0, 0.0, 0.0};
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff rgb rzeros = {0, 0, 0};
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff unsigned DispiId;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff TRACE_ENTRY();
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* Are we really starting the server, or is this just a dummy run? */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff if (flags & PROBE_DETECT)
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff return (FALSE);
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff xf86DrvMsg(pScrn->scrnIndex, X_INFO,
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff "VirtualBox guest additions video driver version "
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff VBOX_VERSION_STRING "\n");
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* Get our private data from the ScrnInfoRec structure. */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff VBOXSetRec(pScrn);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pVBox = VBOXGetRec(pScrn);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff if (!pVBox)
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff return FALSE;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* Initialise the guest library */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff vbox_init(pScrn->scrnIndex, pVBox);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* Entity information seems to mean bus information. */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /* The ramdac module is needed for the hardware cursor. */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff if (!xf86LoadSubModule(pScrn, "ramdac"))
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff return FALSE;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* The framebuffer module. */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff if (!xf86LoadSubModule(pScrn, "fb"))
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff return (FALSE);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (!xf86LoadSubModule(pScrn, "shadowfb"))
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return FALSE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (!xf86LoadSubModule(pScrn, "vgahw"))
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return FALSE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef VBOX_DRI
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Load the dri module. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (!xf86LoadSubModule(pScrn, "dri"))
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return FALSE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff#ifndef PCIACCESS
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (pVBox->pEnt->location.type != BUS_PCI)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return FALSE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->pciTag = pciTag(pVBox->pciInfo->bus,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->pciInfo->device,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pVBox->pciInfo->func);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Set up our ScrnInfoRec structure to describe our virtual
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff capabilities to X. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pScrn->chipset = "vbox";
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /** @note needed during colourmap initialisation */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff pScrn->rgbBits = 8;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Let's create a nice, capable virtual monitor. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->monitor = pScrn->confScreen->monitor;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->monitor->DDC = NULL;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->monitor->nHsync = 1;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->monitor->hsync[0].lo = 1;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->monitor->hsync[0].hi = 10000;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->monitor->nVrefresh = 1;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->monitor->vrefresh[0].lo = 1;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->monitor->vrefresh[0].hi = 100;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pScrn->progClock = TRUE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Using the PCI information caused problems with non-powers-of-two
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff sized video RAM configurations */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pVBox->cbFBMax = VBoxVideoGetVRAMSize();
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->videoRam = pVBox->cbFBMax / 1024;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* Check if the chip restricts horizontal resolution or not. */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pVBox->fAnyX = VBoxVideoAnyWidthAllowed();
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* Set up clock information that will support all modes we need. */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->clockRanges = xnfcalloc(sizeof(ClockRange), 1);
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->clockRanges->minClock = 1000;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->clockRanges->maxClock = 1000000000;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->clockRanges->clockIndex = -1;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->clockRanges->ClockMulFactor = 1;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff pScrn->clockRanges->ClockDivFactor = 1;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /* Query the host for the preferred colour depth */
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff uint32_t cx = 0, cy = 0, cBits = 0;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
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 (cBits != 16)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff cBits = 24;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (!xf86SetDepthBpp(pScrn, cBits, 0, 0, Support32bppFb))
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return FALSE;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff vboxAddModes(pScrn, cx, cy);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "The VBox additions only support 16 and 32bpp graphics modes\n");
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return FALSE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86PrintDepthBpp(pScrn);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#ifdef VBOXVIDEO_13
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 pScrn->virtualX = 32000;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pScrn->virtualY = 32000;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#else
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
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pScrn->currentMode = pScrn->modes;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Set the right virtual resolution. */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff pScrn->virtualX = pScrn->currentMode->HDisplay;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->virtualY = pScrn->currentMode->VDisplay;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff#endif /* !VBOXVIDEO_13 */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /* Needed before we initialise DRI. */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pVBox->cbLine = vboxLineLength(pScrn, pScrn->virtualX);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff pScrn->displayWidth = vboxDisplayPitch(pScrn, pVBox->cbLine);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff xf86PrintModes(pScrn);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* VGA hardware initialisation */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (!vgaHWGetHWRec(pScrn))
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return FALSE;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /* Must be called before any VGA registers are saved or restored */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff vgaHWSetStdFuncs(VGAHWPTR(pScrn));
vgaHWGetIOBase(VGAHWPTR(pScrn));
/* Colour weight - we always call this, since we are always in
truecolour. */
if (!xf86SetWeight(pScrn, rzeros, rzeros))
return (FALSE);
/* visual init */
if (!xf86SetDefaultVisual(pScrn, -1))
return (FALSE);
xf86SetGamma(pScrn, gzeros);
/* Set the DPI. Perhaps we should read this from the host? */
xf86SetDpi(pScrn, 96, 96);
if (pScrn->memPhysBase == 0) {
#ifdef PCIACCESS
pScrn->memPhysBase = pVBox->pciInfo->regions[0].base_addr;
#else
pScrn->memPhysBase = pVBox->pciInfo->memBase[0];
#endif
pScrn->fbOffset = 0;
}
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
vboxLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
LOCO *colors, VisualPtr pVisual)
{
(void)pScrn; (void) numColors; (void) indices; (void) colors;
(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
VBOXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
{
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
VBOXPtr pVBox = VBOXGetRec(pScrn);
VisualPtr visual;
unsigned flags;
TRACE_ENTRY();
if (!VBOXMapVidMem(pScrn))
return (FALSE);
/* save current video state */
VBOXSaveMode(pScrn);
/* mi layer - reset the visual list (?)*/
miClearVisualTypes();
if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
pScrn->rgbBits, TrueColor))
return (FALSE);
if (!miSetPixmapDepths())
return (FALSE);
#ifdef VBOX_DRI
pVBox->useDRI = VBOXDRIScreenInit(pScrn, pScreen, pVBox);
#endif
if (!fbScreenInit(pScreen, pVBox->base,
pScrn->virtualX, pScrn->virtualY,
pScrn->xDpi, pScrn->yDpi,
pScrn->displayWidth, pScrn->bitsPerPixel))
return (FALSE);
/* Fixup RGB ordering */
/** @note the X server uses this even in true colour. */
visual = pScreen->visuals + pScreen->numVisuals;
while (--visual >= pScreen->visuals) {
if ((visual->class | DynamicClass) == DirectColor) {
visual->offsetRed = pScrn->offset.red;
visual->offsetGreen = pScrn->offset.green;
visual->offsetBlue = pScrn->offset.blue;
visual->redMask = pScrn->mask.red;
visual->greenMask = pScrn->mask.green;
visual->blueMask = pScrn->mask.blue;
}
}
/* must be after RGB ordering fixed */
fbPictureInit(pScreen, 0, 0);
xf86SetBlackWhitePixels(pScreen);
pScrn->vtSema = TRUE;
if (vbox_open (pScrn, pScreen, pVBox)) {
vboxEnableVbva(pScrn);
vboxEnableGraphicsCap(pVBox);
}
#ifdef VBOXVIDEO_13
/* Initialise CRTC and output configuration for use with randr1.2. */
xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs);
{
uint32_t i;
for (i = 0; i < pVBox->cScreens; ++i)
{
char szOutput[256];
/* Setup our virtual CRTCs. */
pVBox->paCrtcs[i] = xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
pVBox->paCrtcs[i]->driver_private = (void *)(uintptr_t)i;
/* Set up our virtual outputs. */
snprintf(szOutput, sizeof(szOutput), "VBOX%u", i);
pVBox->paOutputs[i] = xf86OutputCreate(pScrn, &VBOXOutputFuncs,
szOutput);
/* We are not interested in the monitor section in the
* configuration file. */
xf86OutputUseScreenMonitor(pVBox->paOutputs[i], FALSE);
pVBox->paOutputs[i]->possible_crtcs = 1 << i;
pVBox->paOutputs[i]->possible_clones = 0;
pVBox->paOutputs[i]->driver_private = (void *)(uintptr_t)i;
TRACE_LOG("Created crtc (%p) and output %s (%p)\n",
(void *)pVBox->paCrtcs[i], szOutput,
(void *)pVBox->paOutputs[i]);
}
}
/* Set a sane minimum and maximum mode size */
xf86CrtcSetSizeRange(pScrn, 64, 64, 32000, 32000);
/* Now create our initial CRTC/output configuration. */
if (!xf86InitialConfiguration(pScrn, TRUE)) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
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;
for (i = 0; i < pVBox->cScreens; ++i)
{
char csz[] = "0x0";
RRChangeOutputProperty(pVBox->paOutputs[i]->randr_output,
vboxAtomVBoxMode(), XA_STRING, 8,
PropModeReplace, sizeof(csz), csz, TRUE,
FALSE);
}
}
if (!xf86SetDesiredModes(pScrn)) {
return FALSE;
}
#else /* !VBOXVIDEO_13 */
/* set first video mode */
if (!VBOXSetMode(pScrn, 0, pScrn->currentMode->HDisplay,
pScrn->currentMode->VDisplay, pScrn->frameX0,
pScrn->frameY0))
return FALSE;
/* And make sure that a non-current dynamic mode is at the front of the
* list */
vboxWriteHostModes(pScrn, pScrn->currentMode);
#endif /* !VBOXVIDEO_13 */
/* software cursor */
miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
/* colourmap code */
if (!miCreateDefColormap(pScreen))
return (FALSE);
if(!xf86HandleColormaps(pScreen, 256, 8, vboxLoadPalette, NULL, 0))
return (FALSE);
pVBox->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = VBOXCloseScreen;
#ifdef VBOXVIDEO_13
pScreen->SaveScreen = xf86SaveScreen;
#else
pScreen->SaveScreen = VBOXSaveScreen;
#endif
#ifdef VBOXVIDEO_13
xf86DPMSInit(pScreen, xf86DPMSSet, 0);
#else
/* We probably do want to support power management - even if we just use
a dummy function. */
xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
#endif
/* Report any unused options (only for the first generation) */
if (serverGeneration == 1)
xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
if (vbox_cursor_init(pScreen) != TRUE)
xf86DrvMsg(scrnIndex, X_ERROR,
"Unable to start the VirtualBox mouse pointer integration with the host system.\n");
#ifdef VBOX_DRI
if (pVBox->useDRI)
pVBox->useDRI = VBOXDRIFinishScreenInit(pScreen);
#endif
return (TRUE);
}
static Bool
VBOXEnterVT(int scrnIndex, int flags)
{
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
VBOXPtr pVBox = VBOXGetRec(pScrn);
TRACE_ENTRY();
vboxClearVRAM(pScrn, 0, 0);
if (pVBox->fHaveHGSMI)
vboxEnableVbva(pScrn);
#ifdef VBOX_DRI
if (pVBox->useDRI)
DRIUnlock(screenInfo.screens[scrnIndex]);
#endif
/* Re-assert this in case we had a change request while switched out. */
VBOXAdjustScreenPixmap(pScrn, pVBox->FBSize.cx, pVBox->FBSize.cy);
#ifdef VBOXVIDEO_13
if (!xf86SetDesiredModes(pScrn))
return FALSE;
#else
if (!VBOXSetMode(pScrn, 0, pScrn->currentMode->HDisplay,
pScrn->currentMode->VDisplay, pScrn->frameX0,
pScrn->frameY0))
return FALSE;
#endif
return TRUE;
}
static void
VBOXLeaveVT(int scrnIndex, int flags)
{
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
VBOXPtr pVBox = VBOXGetRec(pScrn);
TRACE_ENTRY();
if (pVBox->fHaveHGSMI)
vboxDisableVbva(pScrn);
vboxClearVRAM(pScrn, 0, 0);
VBOXRestoreMode(pScrn);
vboxDisableGraphicsCap(pVBox);
#ifdef VBOX_DRI
if (pVBox->useDRI)
DRILock(screenInfo.screens[scrnIndex], 0);
#endif
TRACE_EXIT();
}
static Bool
VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
VBOXPtr pVBox = VBOXGetRec(pScrn);
if (pScrn->vtSema)
{
if (pVBox->fHaveHGSMI)
vboxDisableVbva(pScrn);
if (pScrn->vtSema)
vboxDisableGraphicsCap(pVBox);
vboxClearVRAM(pScrn, 0, 0);
}
#ifdef VBOX_DRI
if (pVBox->useDRI)
VBOXDRICloseScreen(pScreen, pVBox);
pVBox->useDRI = false;
#endif
if (pScrn->vtSema) {
VBOXRestoreMode(xf86Screens[scrnIndex]);
VBOXUnmapVidMem(pScrn);
}
pScrn->vtSema = FALSE;
/* Do additional bits which are separate for historical reasons */
vbox_close(pScrn, pVBox);
pScreen->CloseScreen = pVBox->CloseScreen;
return pScreen->CloseScreen(scrnIndex, pScreen);
}
static Bool
VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags)
{
ScrnInfoPtr pScrn;
VBOXPtr pVBox;
Bool rc;
TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
pScrn = xf86Screens[scrnIndex]; /* Why does X have three ways of referring to the screen? */
#ifndef VBOXVIDEO_13
pVBox = VBOXGetRec(pScrn);
/* Save the size in case we need to re-set it later. */
pVBox->FBSize.cx = pMode->HDisplay;
pVBox->FBSize.cy = pMode->VDisplay;
pVBox->aScreenLocation[0].cx = pMode->HDisplay;
pVBox->aScreenLocation[0].cy = pMode->VDisplay;
pVBox->aScreenLocation[0].x = pScrn->frameX0;
pVBox->aScreenLocation[0].y = pScrn->frameY0;
#endif
if (!pScrn->vtSema)
{
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"We do not own the active VT, exiting.\n");
return TRUE;
}
#ifdef VBOXVIDEO_13
rc = xf86SetSingleMode(pScrn, pMode, 0);
#else
VBOXAdjustScreenPixmap(pScrn, pMode->HDisplay, pMode->VDisplay);
rc = VBOXSetMode(pScrn, 0, pMode->HDisplay, pMode->VDisplay,
pScrn->frameX0, pScrn->frameY0);
if (rc)
{
vboxWriteHostModes(pScrn, pMode);
xf86PrintModes(pScrn);
}
if (rc && !vboxGuestIsSeamless(pScrn))
vboxSaveVideoMode(pScrn, pMode->HDisplay, pMode->VDisplay,
pScrn->bitsPerPixel);
#endif
TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
return rc;
}
static void
VBOXAdjustFrame(int scrnIndex, int x, int y, int flags)
{
VBOXPtr pVBox = VBOXGetRec(xf86Screens[scrnIndex]);
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
TRACE_ENTRY();
pVBox->aScreenLocation[0].x = x;
pVBox->aScreenLocation[0].y = y;
/* Don't fiddle with the hardware if we are switched
* to a virtual terminal. */
if (!pScrn->vtSema)
{
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"We do not own the active VT, exiting.\n");
return;
}
VBOXSetMode(pScrn, 0, pVBox->aScreenLocation[0].cx,
pVBox->aScreenLocation[0].cy, x, y);
TRACE_EXIT();
}
static void
VBOXFreeScreen(int scrnIndex, int flags)
{
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
/* Destroy the VGA hardware record */
vgaHWFreeHWRec(pScrn);
/* And our private record */
free(pScrn->driverPrivate);
pScrn->driverPrivate = NULL;
}
static Bool
VBOXMapVidMem(ScrnInfoPtr pScrn)
{
VBOXPtr pVBox = VBOXGetRec(pScrn);
Bool rc = TRUE;
TRACE_ENTRY();
if (!pVBox->base)
{
#ifdef PCIACCESS
(void) pci_device_map_range(pVBox->pciInfo,
pScrn->memPhysBase,
pScrn->videoRam * 1024,
PCI_DEV_MAP_FLAG_WRITABLE,
& pVBox->base);
#else
pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
VIDMEM_FRAMEBUFFER,
pVBox->pciTag, pScrn->memPhysBase,
(unsigned) pScrn->videoRam * 1024);
#endif
if (!pVBox->base)
rc = FALSE;
}
TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
return rc;
}
static void
VBOXUnmapVidMem(ScrnInfoPtr pScrn)
{
VBOXPtr pVBox = VBOXGetRec(pScrn);
TRACE_ENTRY();
if (pVBox->base == NULL)
return;
#ifdef PCIACCESS
(void) pci_device_unmap_range(pVBox->pciInfo,
pVBox->base,
pScrn->videoRam * 1024);
#else
xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
(unsigned) pScrn->videoRam * 1024);
#endif
pVBox->base = NULL;
TRACE_EXIT();
}
static Bool
VBOXSaveScreen(ScreenPtr pScreen, int mode)
{
(void)pScreen; (void)mode;
return TRUE;
}
void
VBOXSaveMode(ScrnInfoPtr pScrn)
{
VBOXPtr pVBox = VBOXGetRec(pScrn);
vgaRegPtr vgaReg;
TRACE_ENTRY();
vgaReg = &VGAHWPTR(pScrn)->SavedReg;
vgaHWSave(pScrn, vgaReg, VGA_SR_ALL);
pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth,
&pVBox->cSavedHeight,
&pVBox->cSavedPitch,
&pVBox->cSavedBPP,
&pVBox->fSavedFlags);
}
void
VBOXRestoreMode(ScrnInfoPtr pScrn)
{
VBOXPtr pVBox = VBOXGetRec(pScrn);
vgaRegPtr vgaReg;
TRACE_ENTRY();
vgaReg = &VGAHWPTR(pScrn)->SavedReg;
vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL);
if (pVBox->fSavedVBEMode)
VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight,
pVBox->cSavedPitch, pVBox->cSavedBPP,
pVBox->fSavedFlags, 0, 0);
else
VBoxVideoDisableVBE();
}
static void
VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
int flags)
{
(void)pScrn; (void)mode; (void) flags;
}