aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xfree86/os-support
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-12-01 08:14:05 +0000
committermarha <marha@users.sourceforge.net>2010-12-01 08:14:05 +0000
commit6cbbd31fd2f24fdda51df2de8a8f62ec83b5db03 (patch)
treefd434665398565d3bb9c68b97c978b63a7756add /xorg-server/hw/xfree86/os-support
parentd8f61fbb152bca029b56b117c679b03b6a72b467 (diff)
parent30eaf03aef5847adb6da7efd4bbf4a4abaf5d738 (diff)
downloadvcxsrv-6cbbd31fd2f24fdda51df2de8a8f62ec83b5db03.tar.gz
vcxsrv-6cbbd31fd2f24fdda51df2de8a8f62ec83b5db03.tar.bz2
vcxsrv-6cbbd31fd2f24fdda51df2de8a8f62ec83b5db03.zip
svn merge ^/branches/released .
Diffstat (limited to 'xorg-server/hw/xfree86/os-support')
-rw-r--r--xorg-server/hw/xfree86/os-support/Makefile.am52
-rw-r--r--xorg-server/hw/xfree86/os-support/linux/lnx_init.c108
-rw-r--r--xorg-server/hw/xfree86/os-support/shared/VTsw_usl.c15
-rw-r--r--xorg-server/hw/xfree86/os-support/sysv/Makefile.am1
-rw-r--r--xorg-server/hw/xfree86/os-support/sysv/sysv_init.c252
-rw-r--r--xorg-server/hw/xfree86/os-support/sysv/sysv_video.c315
6 files changed, 43 insertions, 700 deletions
diff --git a/xorg-server/hw/xfree86/os-support/Makefile.am b/xorg-server/hw/xfree86/os-support/Makefile.am
index 04997a6cb..c0504d5eb 100644
--- a/xorg-server/hw/xfree86/os-support/Makefile.am
+++ b/xorg-server/hw/xfree86/os-support/Makefile.am
@@ -1,26 +1,26 @@
-SUBDIRS = bus @XORG_OS_SUBDIR@ misc $(DRI_SUBDIRS)
-DIST_SUBDIRS = bsd bus misc linux solaris sysv sco hurd
-
-sdk_HEADERS = xf86_OSproc.h xf86_OSlib.h
-
-EXTRA_DIST = int10Defines.h xf86OSpriv.h
-
-# to get the grouping semantics right, you have to glom these three together
-# as one library, otherwise libtool will actively defeat your attempts to
-# list them multiple times on the link line.
-noinst_LTLIBRARIES = libxorgos.la
-libxorgos_la_SOURCES = xorgos.c
-libxorgos_la_LIBADD = @XORG_OS_SUBDIR@/lib@XORG_OS_SUBDIR@.la \
- bus/libbus.la \
- misc/libmisc.la
-
-AM_CFLAGS = $(DIX_CFLAGS)
-
-xorgos.c:
- touch $@
-
-DISTCLEANFILES = xorgos.c
-
-# FIXME: These don't seem to be used anywhere
-EXTRA_DIST += \
- shared/bios_devmem.c
+SUBDIRS = bus @XORG_OS_SUBDIR@ misc $(DRI_SUBDIRS)
+DIST_SUBDIRS = bsd bus misc linux solaris sco hurd
+
+sdk_HEADERS = xf86_OSproc.h xf86_OSlib.h
+
+EXTRA_DIST = int10Defines.h xf86OSpriv.h
+
+# to get the grouping semantics right, you have to glom these three together
+# as one library, otherwise libtool will actively defeat your attempts to
+# list them multiple times on the link line.
+noinst_LTLIBRARIES = libxorgos.la
+libxorgos_la_SOURCES = xorgos.c
+libxorgos_la_LIBADD = @XORG_OS_SUBDIR@/lib@XORG_OS_SUBDIR@.la \
+ bus/libbus.la \
+ misc/libmisc.la
+
+AM_CFLAGS = $(DIX_CFLAGS)
+
+xorgos.c:
+ touch $@
+
+DISTCLEANFILES = xorgos.c
+
+# FIXME: These don't seem to be used anywhere
+EXTRA_DIST += \
+ shared/bios_devmem.c
diff --git a/xorg-server/hw/xfree86/os-support/linux/lnx_init.c b/xorg-server/hw/xfree86/os-support/linux/lnx_init.c
index 7adf0ff73..d1f29d909 100644
--- a/xorg-server/hw/xfree86/os-support/linux/lnx_init.c
+++ b/xorg-server/hw/xfree86/os-support/linux/lnx_init.c
@@ -39,47 +39,14 @@
#include <sys/stat.h>
static Bool KeepTty = FALSE;
-static int VTnum = -1;
static Bool VTSwitch = TRUE;
static Bool ShareVTs = FALSE;
static int activeVT = -1;
-static int vtPermSave[4];
static char vtname[11];
static struct termios tty_attr; /* tty state to restore */
static int tty_mode; /* kbd mode to restore */
-static int
-saveVtPerms(void)
-{
- /* We need to use stat to get permissions. */
- struct stat svtp;
-
- /* Do them numerically ordered, hard coded tty0 first. */
- if (stat("/dev/tty0", &svtp) != 0)
- return 0;
- vtPermSave[0] = (int)svtp.st_uid;
- vtPermSave[1] = (int)svtp.st_gid;
-
- /* Now check the console we are dealing with. */
- if (stat(vtname, &svtp) != 0)
- return 0;
- vtPermSave[2] = (int)svtp.st_uid;
- vtPermSave[3] = (int)svtp.st_gid;
-
- return 1;
-}
-
-static void
-restoreVtPerms(void)
-{
- if (geteuid() == 0) {
- /* Set the terminal permissions back to before we started. */
- (void)chown("/dev/tty0", vtPermSave[0], vtPermSave[1]);
- (void)chown(vtname, vtPermSave[2], vtPermSave[3]);
- }
-}
-
static void *console_handler;
static void
@@ -92,6 +59,16 @@ drain_console(int fd, void *closure)
}
}
+static void
+switch_to(int vt, const char *from)
+{
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt) < 0)
+ FatalError("%s: VT_ACTIVATE failed: %s\n", from, strerror(errno));
+
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt) < 0)
+ FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno));
+}
+
void
xf86OpenConsole(void)
{
@@ -112,8 +89,7 @@ xf86OpenConsole(void)
/*
* setup the virtual terminal manager
*/
- if (VTnum != -1) {
- xf86Info.vtno = VTnum;
+ if (xf86Info.vtno != -1) {
from = X_CMDLINE;
} else {
@@ -179,34 +155,6 @@ xf86OpenConsole(void)
FatalError("xf86OpenConsole: Cannot open virtual console"
" %d (%s)\n", xf86Info.vtno, strerror(errno));
- if (!ShareVTs)
- {
- /*
- * Grab the vt ownership before we overwrite it.
- * Hard coded /dev/tty0 into this function as well for below.
- */
- if (!saveVtPerms())
- xf86Msg(X_WARNING,
- "xf86OpenConsole: Could not save ownership of VT\n");
-
- if (geteuid() == 0) {
- /* change ownership of the vt */
- if (chown(vtname, getuid(), getgid()) < 0)
- xf86Msg(X_WARNING,"xf86OpenConsole: chown %s failed: %s\n",
- vtname, strerror(errno));
-
- /*
- * the current VT device we're running on is not
- * "console", we want to grab all consoles too
- *
- * Why is this needed??
- */
- if (chown("/dev/tty0", getuid(), getgid()) < 0)
- xf86Msg(X_WARNING,"xf86OpenConsole: chown /dev/tty0 failed: %s\n",
- strerror(errno));
- }
- }
-
/*
* Linux doesn't switch to an active vt after the last close of a vt,
* so we do this ourselves by remembering which is active now.
@@ -236,13 +184,7 @@ xf86OpenConsole(void)
/*
* now get the VT. This _must_ succeed, or else fail completely.
*/
- if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
- FatalError("xf86OpenConsole: VT_ACTIVATE failed: %s\n",
- strerror(errno));
-
- if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
- FatalError("xf86OpenConsole: VT_WAITACTIVE failed: %s\n",
- strerror(errno));
+ switch_to(xf86Info.vtno, "xf86OpenConsole");
if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
FatalError("xf86OpenConsole: VT_GETMODE failed %s\n",
@@ -289,16 +231,8 @@ xf86OpenConsole(void)
} else { /* serverGeneration != 1 */
if (!ShareVTs && VTSwitch)
{
- /*
- * now get the VT
- */
- if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
- xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed %s\n",
- strerror(errno));
-
- if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
- xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed %s\n",
- strerror(errno));
+ /* now get the VT */
+ switch_to(xf86Info.vtno, "xf86OpenConsole");
}
}
}
@@ -343,19 +277,11 @@ xf86CloseConsole(void)
* Perform a switch back to the active VT when we were started
*/
if (activeVT >= 0) {
- if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT) < 0)
- xf86Msg(X_WARNING, "xf86CloseConsole: VT_ACTIVATE failed: %s\n",
- strerror(errno));
- if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, activeVT) < 0)
- xf86Msg(X_WARNING,
- "xf86CloseConsole: VT_WAITACTIVE failed: %s\n",
- strerror(errno));
+ switch_to(activeVT, "xf86CloseConsole");
activeVT = -1;
}
}
close(xf86Info.consoleFd); /* make the vt-manager happy */
-
- restoreVtPerms(); /* restore the permissions */
}
int
@@ -382,10 +308,10 @@ xf86ProcessArgument(int argc, char *argv[], int i)
}
if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
{
- if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ if (sscanf(argv[i], "vt%2d", &xf86Info.vtno) == 0)
{
UseMsg();
- VTnum = -1;
+ xf86Info.vtno = -1;
return 0;
}
return 1;
diff --git a/xorg-server/hw/xfree86/os-support/shared/VTsw_usl.c b/xorg-server/hw/xfree86/os-support/shared/VTsw_usl.c
index 00bfb7151..769fa009c 100644
--- a/xorg-server/hw/xfree86/os-support/shared/VTsw_usl.c
+++ b/xorg-server/hw/xfree86/os-support/shared/VTsw_usl.c
@@ -31,10 +31,6 @@
#include "xf86Priv.h"
#include "xf86_OSlib.h"
-#ifdef OSHEADER
-# include OSHEADER
-#endif
-
/*
* Handle the VT-switching interface for OSs that use USL-style ioctl()s
* (the sysv, sco, and linux subdirs).
@@ -63,16 +59,9 @@ xf86VTSwitchAway(void)
{
xf86Info.vtRequestsPending = FALSE;
if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0)
- {
return FALSE;
- }
else
- {
-#ifdef OSSWITCHAWAY
- OSSWITCHAWAY;
-#endif
return TRUE;
- }
}
Bool
@@ -80,13 +69,9 @@ xf86VTSwitchTo(void)
{
xf86Info.vtRequestsPending = FALSE;
if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0)
- {
return FALSE;
- }
else
- {
return TRUE;
- }
}
Bool
diff --git a/xorg-server/hw/xfree86/os-support/sysv/Makefile.am b/xorg-server/hw/xfree86/os-support/sysv/Makefile.am
deleted file mode 100644
index e86e70ad1..000000000
--- a/xorg-server/hw/xfree86/os-support/sysv/Makefile.am
+++ /dev/null
@@ -1 +0,0 @@
-EXTRA_DIST = sysv_init.c sysv_video.c
diff --git a/xorg-server/hw/xfree86/os-support/sysv/sysv_init.c b/xorg-server/hw/xfree86/os-support/sysv/sysv_init.c
deleted file mode 100644
index 3b94ac135..000000000
--- a/xorg-server/hw/xfree86/os-support/sysv/sysv_init.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
- * Copyright 1993 by David Wexelblat <dwex@goblin.org>
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the names of Thomas Roell and David Wexelblat
- * not be used in advertising or publicity pertaining to distribution of
- * the software without specific, written prior permission. Thomas Roell and
- * David Wexelblat makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without express or
- * implied warranty.
- *
- * THOMAS ROELL AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID WEXELBLAT BE LIABLE FOR
- * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include <X11/Xmd.h>
-
-#include "compiler.h"
-
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-
-static Bool KeepTty = FALSE;
-#ifdef SVR4
-static Bool Protect0 = FALSE;
-#endif
-static int VTnum = -1;
-
-
-void
-xf86OpenConsole()
-{
- int fd;
- struct vt_mode VT;
- char vtname1[10],vtname2[10];
- MessageType from = X_PROBED;
-
- if (serverGeneration == 1)
- {
- /* check if we're run with euid==0 */
- if (geteuid() != 0)
- {
- FatalError("xf86OpenConsole: Server must be suid root\n");
- }
-
-#ifdef SVR4
- /* Protect page 0 to help find NULL dereferencing */
- /* mprotect() doesn't seem to work */
- if (Protect0)
- {
- int fd = -1;
-
- if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0)
- {
- xf86Msg(X_WARNING,
- "xf86OpenConsole: cannot open /dev/zero (%s)\n",
- strerror(errno));
- }
- else
- {
- if ((int)mmap(0, 0x1000, PROT_NONE,
- MAP_FIXED | MAP_SHARED, fd, 0) == -1)
- {
- xf86Msg(X_WARNING,
- "xf86OpenConsole: failed to protect page 0 (%s)\n",
- strerror(errno));
- }
- close(fd);
- }
- }
-#endif
- /*
- * setup the virtual terminal manager
- */
- if (VTnum != -1)
- {
- xf86Info.vtno = VTnum;
- from = X_CMDLINE;
- }
- else
- {
- if ((fd = open("/dev/console",O_WRONLY,0)) < 0)
- {
- FatalError(
- "xf86OpenConsole: Cannot open /dev/console (%s)\n",
- strerror(errno));
- }
- if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
- (xf86Info.vtno == -1))
- {
- FatalError("xf86OpenConsole: Cannot find a free VT\n");
- }
- close(fd);
- }
- xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
-
- sprintf(vtname1,"/dev/vc%02d",xf86Info.vtno); /* ESIX */
- sprintf(vtname2,"/dev/vt%02d",xf86Info.vtno); /* rest of the world */
-
- if (!KeepTty)
- {
- setpgrp();
- }
-
- if (((xf86Info.consoleFd = open(vtname1, O_RDWR|O_NDELAY, 0)) < 0) &&
- ((xf86Info.consoleFd = open(vtname2, O_RDWR|O_NDELAY, 0)) < 0))
- {
- FatalError("xf86OpenConsole: Cannot open %s (%s) (%s)\n",
- vtname2, vtname1, strerror(errno));
- }
-
- /* change ownership of the vt */
- if (chown(vtname1, getuid(), getgid()) < 0)
- {
- chown(vtname2, getuid(), getgid());
- }
-
- /*
- * now get the VT
- */
- if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
- {
- xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
- }
- if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
- {
- xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
- }
- if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
- {
- FatalError("xf86OpenConsole: VT_GETMODE failed\n");
- }
-
- signal(SIGUSR1, xf86VTRequest);
-
- VT.mode = VT_PROCESS;
- VT.relsig = SIGUSR1;
- VT.acqsig = SIGUSR1;
- if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
- {
- FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
- }
- if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
- {
- FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n");
- }
- }
- else
- {
- /* serverGeneration != 1 */
- /*
- * now get the VT
- */
- if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
- {
- xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
- }
- if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
- {
- xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
- }
- /*
- * If the server doesn't have the VT when the reset occurs,
- * this is to make sure we don't continue until the activate
- * signal is received.
- */
- if (!xf86Screens[0]->vtSema)
- sleep(5);
- }
- return;
-}
-
-void
-xf86CloseConsole()
-{
- struct vt_mode VT;
-
-#if 0
- ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno);
- ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0);
-#endif
- ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */
- if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
- {
- VT.mode = VT_AUTO;
- ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */
- }
- close(xf86Info.consoleFd); /* make the vt-manager happy */
- return;
-}
-
-int
-xf86ProcessArgument(int argc, char *argv[], int i)
-{
- /*
- * Keep server from detaching from controlling tty. This is useful
- * when debugging (so the server can receive keyboard signals.
- */
- if (!strcmp(argv[i], "-keeptty"))
- {
- KeepTty = TRUE;
- return 1;
- }
-#ifdef SVR4
- /*
- * Undocumented flag to protect page 0 from read/write to help
- * catch NULL pointer dereferences. This is purely a debugging
- * flag.
- */
- if (!strcmp(argv[i], "-protect0"))
- {
- Protect0 = TRUE;
- return 1;
- }
-#endif
- if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
- {
- if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
- {
- UseMsg();
- VTnum = -1;
- return 0;
- }
- return 1;
- }
- return 0;
-}
-
-void
-xf86UseMsg()
-{
- ErrorF("vtXX use the specified VT number\n");
- ErrorF("-keeptty ");
- ErrorF("don't detach controlling tty (for debugging only)\n");
- return;
-}
diff --git a/xorg-server/hw/xfree86/os-support/sysv/sysv_video.c b/xorg-server/hw/xfree86/os-support/sysv/sysv_video.c
deleted file mode 100644
index 6d5948796..000000000
--- a/xorg-server/hw/xfree86/os-support/sysv/sysv_video.c
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
- * Copyright 1993 by David Wexelblat <dwex@goblin.org>
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the names of Thomas Roell and David Wexelblat
- * not be used in advertising or publicity pertaining to distribution of
- * the software without specific, written prior permission. Thomas Roell and
- * David Wexelblat makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without express or
- * implied warranty.
- *
- * THOMAS ROELL AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO
- * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR DAVID WEXELBLAT BE LIABLE FOR
- * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-
-#define _NEED_SYSI86
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-#include "xf86OSpriv.h"
-
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *)-1)
-#endif
-
-#ifndef SI86IOPL
-#define SET_IOPL() sysi86(SI86V86,V86SC_IOPL,PS_IOPL)
-#define RESET_IOPL() sysi86(SI86V86,V86SC_IOPL,0)
-#else
-#define SET_IOPL() sysi86(SI86IOPL,3)
-#define RESET_IOPL() sysi86(SI86IOPL,0)
-#endif
-
-/***************************************************************************/
-/* Video Memory Mapping section */
-/***************************************************************************/
-
-/*
- * XXX Support for SVR3 will need to be reworked if needed. In particular
- * the Region parameter is no longer passed, and will need to be dealt
- * with internally if required.
- * OK, i'll rework that thing ... (clean it up a lot)
- * SVR3 Support only with SVR3_MMAPDRV (mr)
- *
- */
-
-#ifdef HAS_SVR3_MMAPDRV
-#ifndef MMAP_DEBUG
-#define MMAP_DEBUG 3
-#endif
-
-struct kd_memloc MapDSC;
-int mmapFd = -2;
-
-static int
-mmapStat(pointer Base, unsigned long Size) {
-
- int nmmreg,i=0,region=-1;
- mmapinfo_t *ibuf;
-
- nmmreg = ioctl(mmapFd, GETNMMREG);
-
- if(nmmreg <= 0)
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "\nNo physical memory mapped currently.\n\n");
- else {
- if((ibuf = (mmapinfo_t *)malloc(nmmreg*sizeof(mmapinfo_t))) == NULL)
- xf86Msg(X_WARNING,
- "Couldn't allocate memory 4 mmapinfo_t\n");
- else {
- if(ioctl(mmapFd, GETMMREG, ibuf) != -1)
- {
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "# mmapStat: [Size=%x,Base=%x]\n", Size, Base);
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "# Physical Address Size Reference Count\n");
- for(i = 0; i < nmmreg; i++) {
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "%-4d 0x%08X %5dk %5d ",
- i, ibuf[i].physaddr, ibuf[i].length/1024, ibuf[i].refcnt);
- if (ibuf[i].physaddr == Base || ibuf[i].length == Size ) {
- xf86MsgVerb(X_INFO, MMAP_DEBUG,"MATCH !!!");
- if (region==-1) region=i;
- }
- xf86ErrorFVerb(MMAP_DEBUG, "\n");
- }
- xf86ErrorFVerb(MMAP_DEBUG, "\n");
- }
- free(ibuf);
- }
- }
- if (region == -1 && nmmreg > 0) region=region * i;
- return region;
-}
-#endif
-
-
-static Bool
-linearVidMem()
-{
-#ifdef SVR4
- return TRUE;
-#elif defined(HAS_SVR3_MMAPDRV)
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "# xf86LinearVidMem: MMAP 2.2.2 called\n");
-
- if(mmapFd >= 0) return TRUE;
-
- if ((mmapFd = open("/dev/mmap", O_RDWR)) != -1)
- {
- if(ioctl(mmapFd, GETVERSION) < 0x0222) {
- xf86Msg(X_WARNING,
- "xf86LinearVidMem: MMAP 2.2.2 or above required\n");
- xf86ErrorF("\tlinear memory access disabled\n");
- return FALSE;
- }
- return TRUE;
- }
- xf86Msg(X_WARNING, "xf86LinearVidMem: failed to open /dev/mmap (%s)\n",
- strerror(errno));
- xf86ErrorF("\tlinear memory access disabled\n");
- return FALSE;
-#endif
-}
-
-static pointer
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
- pointer base;
- int fd;
-
-#if defined(SVR4)
- fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
- if (fd < 0)
- {
- FatalError("xf86MapVidMem: failed to open %s (%s)\n",
- DEV_MEM, strerror(errno));
- }
- base = mmap((caddr_t)0, Size,
- (flags & VIDMEM_READONLY) ?
- PROT_READ : (PROT_READ | PROT_WRITE),
- MAP_SHARED, fd, (off_t)Base);
- close(fd);
- if (base == MAP_FAILED)
- {
- FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
- "xf86MapVidMem", Size, Base, strerror(errno));
- }
-#else /* SVR4 */
-#ifdef HAS_SVR3_MMAPDRV
-
- xf86MsgVerb(X_INFO, MMAP_DEBUG, "# xf86MapVidMem: MMAP 2.2.2 called\n");
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "MMAP_VERSION: 0x%x\n",ioctl(mmapFd, GETVERSION));
- if (ioctl(mmapFd, GETVERSION) == -1)
- {
- xf86LinearVidMem();
- }
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "MMAP_VERSION: 0x%x\n",ioctl(mmapFd, GETVERSION));
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "xf86MapVidMem: Screen: %d\n", ScreenNum);
- mmapStat(Base,Size);
- /* To force the MMAP driver to provide the address */
- base = (pointer)0;
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "xf86MapVidMem: [s=%x,a=%x]\n", Size, Base);
- MapDSC.vaddr = (char *)base;
- MapDSC.physaddr = (char *)Base;
- MapDSC.length = Size;
- MapDSC.ioflg = 1;
- if(mmapFd >= 0)
- {
- if((base = (pointer)ioctl(mmapFd, MAP, &MapDSC)) == (pointer)-1)
- {
- FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
- "xf86MapVidMem", Size, Base, strerror(errno));
- /* NOTREACHED */
- }
-
- /* Next time we want the same address! */
- MapDSC.vaddr = (char *)base;
- }
-
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "MapDSC.vaddr : 0x%x\n", MapDSC.vaddr);
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "MapDSC.physaddr: 0x%x\n", MapDSC.physaddr);
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "MapDSC.length : %d\n", MapDSC.length);
- mmapStat(Base,Size);
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "xf86MapVidMem: [s=%x,a=%x,b=%x]\n", Size, Base, base);
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "xf86MapVidMem: SUCCEED Mapping FrameBuffer \n");
-#endif /* HAS_SVR3_MMAPDRV */
-#endif /* SVR4 */
- return base;
-}
-
-/* ARGSUSED */
-static void
-unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
-{
-#if defined (SVR4)
- munmap(Base, Size);
-#else /* SVR4 */
-#ifdef HAS_SVR3_MMAPDRV
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "# xf86UnMapVidMem: UNMapping FrameBuffer\n");
- mmapStat(Base,Size);
- ioctl(mmapFd, UNMAPRM , Base);
- mmapStat(Base,Size);
- xf86MsgVerb(X_INFO, MMAP_DEBUG,
- "# xf86UnMapVidMem: Screen: %d [v=%x]\n", ScreenNum, Base);
-#endif /* HAS_SVR3_MMAPDRV */
-#endif /* SVR4 */
- return;
-}
-
-#if defined(SVR4) && defined(__i386__) && !defined(sun)
-/*
- * For some SVR4 versions, a 32-bit read is done for the first location
- * in each page when the page is first mapped. If this is done while
- * memory access is enabled for regions that have read side-effects,
- * this can cause unexpected results, including lockups on some hardware.
- * This function is called to make sure each page is mapped while it is
- * safe to do so.
- */
-
-/*
- * XXX Should get this the correct way (see os/xalloc.c), but since this is
- * for one platform I'll be lazy.
- */
-#define X_PAGE_SIZE 4096
-
-static void
-readSideEffects(int ScreenNum, pointer Base, unsigned long Size)
-{
- unsigned long base, end, addr;
- CARD32 val;
-
- base = (unsigned long)Base;
- end = base + Size;
-
- for (addr = base; addr < end; addr += X_PAGE_SIZE)
- val = *(volatile CARD32 *)addr;
-}
-#endif
-
-void
-xf86OSInitVidMem(VidMemInfoPtr pVidMem)
-{
- pVidMem->linearSupported = linearVidMem();
- pVidMem->mapMem = mapVidMem;
- pVidMem->unmapMem = unmapVidMem;
-#if defined(SVR4) && defined(__i386__) && !defined(sun)
- pVidMem->readSideEffects = readSideEffects;
-#endif
- pVidMem->initialised = TRUE;
-}
-
-/***************************************************************************/
-/* I/O Permissions section */
-/***************************************************************************/
-
-static Bool ExtendedEnabled = FALSE;
-static Bool InitDone = FALSE;
-
-Bool
-xf86EnableIO()
-{
- int i;
-
- if (ExtendedEnabled)
- return TRUE;
-
- if (SET_IOPL() < 0)
- {
- xf86Msg(X_WARNING,
- "xf86EnableIO: Failed to set IOPL for extended I/O\n");
- return FALSE;
- }
- ExtendedEnabled = TRUE;
-
- return TRUE;
-}
-
-void
-xf86DisableIO()
-{
- if (!ExtendedEnabled)
- return;
-
- RESET_IOPL();
- ExtendedEnabled = FALSE;
-
- return;
-}