diff options
67 files changed, 3626 insertions, 1014 deletions
diff --git a/Makefile.bsd-wrapper b/Makefile.bsd-wrapper new file mode 100644 index 000000000..4bfb09b36 --- /dev/null +++ b/Makefile.bsd-wrapper @@ -0,0 +1,48 @@ +# $OpenBSD: Makefile.bsd-wrapper,v 1.43 2012/06/20 19:56:34 matthieu Exp $ + +.include <bsd.xconf.mk> + +DIST= ${.CURDIR} + +# Machines for which we don't build the Xorg Xserver +NO_XORG_MACHINES= alpha aviion hp300 hppa64 landisk \ + mvme68k mvme88k mvmeppc solbourne vax + +NO_XF86UTIL_MACHINES= hp300 landisk sgi sparc vax + +.for M in ${NO_XORG_MACHINES} +NO_XORG_${M} = --disable-xorg +.endfor +NO_XORG_OPTION=${NO_XORG_${MACHINE}} + +.for M in ${NO_XF86UTIL_MACHINES} +NO_XF86_UTIL_${M} = --disable-xfree86-utils +.endfor +NO_XF86_UTIL_OPTION=${NO_XF86_UTIL_${MACHINE}} + +.if ${XENOCARA_BUILD_GL:L} != "yes" +GLX_OPTION= --disable-glx +.endif + +.if ${XENOCARA_BUILD_DRI:L} == "yes" +DRI_OPTION= --enable-dri --enable-dri2 +.else +DRI_OPTION= --disable-dri --disable-dri2 +.endif + +XKB_PATH= ${X11BASE}/share/X11/xkb +XKB_RULES= base + +CONFIGURE_ARGS= --localstatedir=/var --sysconfdir=/etc/X11 \ + --with-xkb-path=${XKB_PATH} \ + --with-xkb-output=/var/db/xkb \ + --with-default-xkb-rules=${XKB_RULES} \ + --with-module-dir=${LIBDIR}/modules ${GLX_OPTION} \ + --enable-install-setuid --enable-privsep \ + --enable-xcsecurity \ + --without-fop --without-xmlto --without-xsltproc \ + --disable-dmx ${NO_XORG_OPTION} ${NO_XF86_UTIL_OPTION} \ + --disable-unit-tests \ + ${DRI_OPTION} + +.include <bsd.xorg.mk> diff --git a/autogen.sh b/autogen.sh index 4e8b11ba9..4e8b11ba9 100755..100644 --- a/autogen.sh +++ b/autogen.sh diff --git a/config/fdi2iclass.py b/config/fdi2iclass.py index 897444068..897444068 100755..100644 --- a/config/fdi2iclass.py +++ b/config/fdi2iclass.py diff --git a/config/wscons.c b/config/wscons.c index fb114bd71..8b9064ad3 100644 --- a/config/wscons.c +++ b/config/wscons.c @@ -77,6 +77,7 @@ struct nameint kbdopt[] = { struct nameint kbdmodel[] = { {WSKBD_TYPE_ZAURUS, "zaurus"}, + {WSKBD_TYPE_ADB, "macintosh" }, {0} }; @@ -92,7 +93,7 @@ wscons_add_keyboard(void) kbd_t wsenc = 0; /* Find keyboard configuration */ - fd = open(WSCONS_KBD_DEVICE, O_RDWR | O_NONBLOCK | O_EXCL); + fd = priv_open_device(WSCONS_KBD_DEVICE); if (fd == -1) { LogMessage(X_ERROR, "wskbd: open %s: %s\n", WSCONS_KBD_DEVICE, strerror(errno)); @@ -110,7 +111,7 @@ wscons_add_keyboard(void) close(fd); return; } - close(fd); + close (fd); input_options = input_option_new(input_options, "_source", "server/wscons"); if (input_options == NULL) @@ -218,11 +219,13 @@ wscons_add_pointers(void) /* Check pointing devices */ for (i = 0; i < 4; i++) { - snprintf(devname, sizeof(devname), "%s%d", WSCONS_MOUSE_PREFIX, i); + snprintf(devname, sizeof(devname), "%s%d", + WSCONS_MOUSE_PREFIX, i); LogMessageVerb(X_INFO, 10, "wsmouse: checking %s\n", devname); - fd = open_device(devnamem O_RDWR | O_NONBLOCK | O_EXCL); + fd = priv_open_device(devname); if (fd == -1) { - LogMessageVerb(X_WARNING, 10, "%s: %s\n", devname, strerror(errno)); + LogMessageVerb(X_WARNING, 10, "%s: %s\n", devname, + strerror(errno)); continue; } if (ioctl(fd, WSMOUSEIO_GTYPE, &wsmouse_type) != 0) { @@ -233,18 +236,20 @@ wscons_add_pointers(void) } close(fd); switch (wsmouse_type) { - case WSMOUSE_TYPE_SYNAPTICS: - wscons_add_pointer(devname, "synaptics", ATTR_TOUCHPAD); + case WSMOUSE_TYPE_SYNAPTICS: + case WSMOUSE_TYPE_ALPS: + wscons_add_pointer(devname, "synaptics", + ATTR_TOUCHPAD); break; - case WSMOUSE_TYPE_TPANEL: + case WSMOUSE_TYPE_TPANEL: wscons_add_pointer(devname, "ws", ATTR_TOUCHSCREEN); break; - default: + default: break; } } - /* Add a default entry catching all other mux elements as "mouse" */ - wscons_add_pointer(WSCONS_MOUSE_PREFIX, "mouse", ATTR_POINTER); + /* Add a default entry catching all other mux elements as "ws" */ + wscons_add_pointer(WSCONS_MOUSE_PREFIX, "ws", ATTR_POINTER); } int diff --git a/configure.ac b/configure.ac index 24da6e809..215e75e56 100644 --- a/configure.ac +++ b/configure.ac @@ -321,6 +321,7 @@ case $host_cpu in case $host_os in *freebsd*) SYS_LIBS=-lio ;; *netbsd*) AC_DEFINE(USE_ALPHA_PIO, 1, [NetBSD PIO alpha IO]) ;; + *openbsd*) SYS_LIBS=-lalpha ;; esac GLX_ARCH_DEFINES="-D__GLX_ALIGN64 -mieee" ;; @@ -346,6 +347,14 @@ case $host_cpu in *freebsd*) DEFAULT_INT10=stub ;; esac ;; + m68k) + HP300_VIDEO=yes + BSD_ARCH_SOURCES="hp300_video.c ioperm_noop.c" + ;; + mips*) + SGI_VIDEO=yes + BSD_ARCH_SOURCES="sgi_video.c ioperm_noop.c" + ;; sparc*) SPARC64_VIDEO=yes BSD_ARCH_SOURCES="sparc64_video.c ioperm_noop.c" @@ -371,14 +380,23 @@ case $host_cpu in s390*) GLX_ARCH_DEFINES="-D__GLX_ALIGN64" ;; + hppa*) + case $host_os in + *openbsd*) HPPA_VIDEO=yes + ;; + esac + ;; esac AC_SUBST(GLX_ARCH_DEFINES) dnl BSD *_video.c selection AM_CONDITIONAL(ALPHA_VIDEO, [test "x$ALPHA_VIDEO" = xyes]) AM_CONDITIONAL(ARM_VIDEO, [test "x$ARM_VIDEO" = xyes]) +AM_CONDITIONAL(HP300_VIDEO, [test "x$HP300_VIDEO" = xyes]) +AM_CONDITIONAL(HPPA_VIDEO, [test "x$HPPA_VIDEO" = xyes]) AM_CONDITIONAL(I386_VIDEO, [test "x$I386_VIDEO" = xyes]) AM_CONDITIONAL(PPC_VIDEO, [test "x$PPC_VIDEO" = xyes]) +AM_CONDITIONAL(SGI_VIDEO, [test "x$SGI_VIDEO" = xyes]) AM_CONDITIONAL(SPARC64_VIDEO, [test "x$SPARC64_VIDEO" = xyes]) DRI=no @@ -406,6 +424,11 @@ case $host_os in AC_DEFINE(CSRG_BASED, 1, [System is BSD-like]) AC_DEFINE(PCVT_SUPPORT, 1, [System has PC console]) AC_DEFINE(WSCONS_SUPPORT, 1, [System has wscons console]) + # Disable use of SIGIO by default; it breaks multi-card + # configurations. We don't want to run thousands of lines of + # potentially signal-unsafe code for no particular benefit. + USE_SIGIO_BY_DEFAULT="no" + KDRIVE_HW=yes ;; *linux*) DRI=yes @@ -590,6 +613,16 @@ AC_ARG_WITH(khronos-spec-dir, AS_HELP_STRING([--with-khronos-spec-dir=PATH], [Pa [KHRONOS_SPEC_DIR="${withval}"], [KHRONOS_SPEC_DIR=auto]) +dnl Privsep +AC_ARG_ENABLE(privsep, + AC_HELP_STRING([--enable-privsep], + [Build support for X server privilege separation (default is NO)]), + [ENABLE_PRIVSEP="$enableval"], [ENABLE_PRIVSEP="no"]) +if test x$ENABLE_PRIVSEP = xyes ; then + AC_DEFINE(X_PRIVSEP, 1, [Use X server privilege separation]) +fi +AM_CONDITIONAL(X_PRIVSEP, [test x$ENABLE_PRIVSEP = xyes]) + dnl Extensions. AC_ARG_ENABLE(registry, AS_HELP_STRING([--disable-registry], [Build string registry module (default: enabled)]), [XREGISTRY=$enableval], [XREGISTRY=yes]) AC_ARG_ENABLE(composite, AS_HELP_STRING([--disable-composite], [Build Composite extension (default: enabled)]), [COMPOSITE=$enableval], [COMPOSITE=yes]) @@ -1462,6 +1495,18 @@ AC_SUBST([UTILS_SYS_LIBS]) # Some platforms require extra flags to do this. libtool should set the # necessary flags for each platform when -export-dynamic is passed to it. LD_EXPORT_SYMBOLS_FLAG="-export-dynamic" +case $host_os in + openbsd*) + case $host_cpu in + m68k|m88k|vax) + LD_EXPORT_SYMBOLS_FLAGS="" + ;; + *) + LD_EXPORT_SYMBOLS_FLAG="-Wl,--export-dynamic" + ;; + esac + ;; +esac AC_SUBST([LD_EXPORT_SYMBOLS_FLAG]) dnl Imake defines SVR4 on SVR4 systems, and many files check for it, so @@ -1599,7 +1644,14 @@ if test "x$XORG" = xyes; then esac case $host_cpu in sparc*) - xorg_bus_sparc="yes" + case $host_os in + openbsd*) + xorg_bus_sparc="no" + ;; + *) + xorg_bus_sparc="yes" + ;; + esac ;; esac fi @@ -1698,11 +1750,6 @@ if test "x$XORG" = xyes; then ;; esac - case $host_cpu in - i*86) - ;; - esac - if test "x$DGA" = xauto; then PKG_CHECK_MODULES(DGA, $DGAPROTO, [DGA=yes], [DGA=no]) fi @@ -2062,6 +2109,19 @@ if test "$KDRIVE" = yes; then KDRIVE_MOUSE=yes fi ;; + *openbsd*) + KDRIVE_OS_LIB='$(top_builddir)/hw/kdrive/openbsd/libopenbsd.la' + KDRIVEOPENBSD=yes + if test "x$KDRIVE_EVDEV" = xauto; then + KDRIVE_EVDEV=no + fi + if test "x$KDRIVE_KBD" = xauto; then + KDRIVE_KBD=yes + fi + if test "x$KDRIVE_MOUSE" = xauto; then + KDRIVE_MOUSE=yes + fi + ;; *) if test "x$KDRIVE_EVDEV" = xauto; then KDRIVE_EVDEV=no @@ -2090,11 +2150,13 @@ AC_SUBST([KDRIVE_PURE_LIBS]) AC_SUBST([KDRIVE_LOCAL_LIBS]) AC_SUBST([KDRIVE_LIBS]) AM_CONDITIONAL(KDRIVELINUX, [test "x$KDRIVELINUX" = xyes]) +AM_CONDITIONAL(KDRIVEOPENBSD, [test "x$KDRIVEOPENBSD" = xyes]) AM_CONDITIONAL(KDRIVE_EVDEV, [test "x$KDRIVE_EVDEV" = xyes]) AM_CONDITIONAL(KDRIVE_KBD, [test "x$KDRIVE_KBD" = xyes]) AM_CONDITIONAL(KDRIVE_MOUSE, [test "x$KDRIVE_MOUSE" = xyes]) AM_CONDITIONAL(TSLIB, [test "x$HAVE_TSLIB" = xyes]) AM_CONDITIONAL(KDRIVEFBDEV, [test "x$XFBDEV" = xyes]) +AM_CONDITIONAL(KDRIVEWSCONS, [test x"$ac_cv_header_dev_wscons_wsconsio_h" = xyes]) AM_CONDITIONAL(XEPHYR, [test "x$KDRIVE" = xyes && test "x$XEPHYR" = xyes]) AM_CONDITIONAL(BUILD_KDRIVEFBDEVLIB, [test "x$KDRIVE" = xyes && test "x$KDRIVEFBDEVLIB" = xyes]) AM_CONDITIONAL(XFAKESERVER, [test "x$KDRIVE" = xyes && test "x$XFAKE" = xyes]) @@ -2228,7 +2290,9 @@ hw/kdrive/ephyr/man/Makefile hw/kdrive/fake/Makefile hw/kdrive/fbdev/Makefile hw/kdrive/linux/Makefile +hw/kdrive/openbsd/Makefile hw/kdrive/src/Makefile +hw/kdrive/wscons/Makefile test/Makefile test/xi2/Makefile xserver.ent diff --git a/dix/extension.c b/dix/extension.c index 3cdfb5152..b46b36874 100644 --- a/dix/extension.c +++ b/dix/extension.c @@ -77,6 +77,7 @@ AddExtension(const char *name, int NumEvents, int NumErrors, { int i; ExtensionEntry *ext, **newexts; + size_t buflen; if (!MainProc || !SwappedMainProc || !MinorOpcodeProc) return ((ExtensionEntry *) NULL); @@ -148,6 +149,7 @@ AddExtensionAlias(const char *alias, ExtensionEntry * ext) { char *name; char **aliases; + size_t buflen; if (!ext) return FALSE; diff --git a/dix/globals.c b/dix/globals.c index c0cae159a..db38ffd0a 100644 --- a/dix/globals.c +++ b/dix/globals.c @@ -118,7 +118,11 @@ char *defaultCursorFont = COMPILEDCURSORFONT; FontPtr defaultFont; /* not declared in dix.h to avoid including font.h in every compilation of dix code */ CursorPtr rootCursor; +#ifndef __OpenBSD__ Bool party_like_its_1989 = FALSE; +#else +Bool party_like_its_1989 = TRUE; +#endif Bool whiteRoot = FALSE; TimeStamp currentTime; diff --git a/fix-miregion b/fix-miregion index fc502bbfd..fc502bbfd 100755..100644 --- a/fix-miregion +++ b/fix-miregion diff --git a/fix-miregion-private b/fix-miregion-private index ebc24fac0..ebc24fac0 100755..100644 --- a/fix-miregion-private +++ b/fix-miregion-private diff --git a/fix-patch-whitespace b/fix-patch-whitespace index 2d06d8ea8..2d06d8ea8 100755..100644 --- a/fix-patch-whitespace +++ b/fix-patch-whitespace diff --git a/fix-region b/fix-region index ef8eb4218..ef8eb4218 100755..100644 --- a/fix-region +++ b/fix-region diff --git a/hw/kdrive/Makefile.am b/hw/kdrive/Makefile.am index 471ca89dd..da263faf4 100644 --- a/hw/kdrive/Makefile.am +++ b/hw/kdrive/Makefile.am @@ -2,6 +2,10 @@ if BUILD_KDRIVEFBDEVLIB FBDEV_SUBDIRS = fbdev endif +if KDRIVEWSCONS +WSCONS_SUBDIRS = wscons +endif + if XFAKESERVER XFAKE_SUBDIRS = fake endif @@ -14,17 +18,23 @@ if KDRIVELINUX LINUX_SUBDIRS = linux endif +if KDRIVEOPENBSD +OPENBSD_SUBDIRS = openbsd +endif + SERVER_SUBDIRS = \ $(FBDEV_SUBDIRS) \ + $(WSCONS_SUBDIRS) \ $(XEPHYR_SUBDIRS) \ $(XFAKE_SUBDIRS) SUBDIRS = \ src \ $(LINUX_SUBDIRS) \ + $(OPENBSD_SUBDIRS) \ $(SERVER_SUBDIRS) -DIST_SUBDIRS = fbdev ephyr src linux fake +DIST_SUBDIRS = fbdev ephyr src linux fake openbsd wscons relink: $(AM_V_at)for i in $(SERVER_SUBDIRS) ; do $(MAKE) -C $$i relink || exit 1 ; done diff --git a/hw/kdrive/openbsd/Makefile.am b/hw/kdrive/openbsd/Makefile.am new file mode 100644 index 000000000..7746c33f7 --- /dev/null +++ b/hw/kdrive/openbsd/Makefile.am @@ -0,0 +1,16 @@ +# + +INCLUDES = \ + @KDRIVE_INCS@ \ + @KDRIVE_CFLAGS@ + +AM_CFLAGS = -DHAVE_DIX_CONFIG_H + +noinst_LTLIBRARIES =libopenbsd.la + +libopenbsd_la_SOURCES = \ + openbsd.c + +libopenbsd_la_SOURCES += \ + kopenbsd.h + diff --git a/hw/kdrive/openbsd/openbsd.c b/hw/kdrive/openbsd/openbsd.c new file mode 100644 index 000000000..a3c081537 --- /dev/null +++ b/hw/kdrive/openbsd/openbsd.c @@ -0,0 +1,132 @@ +/* $OpenBSD: openbsd.c,v 1.4 2007/12/23 14:28:10 matthieu Exp $ */ +/* + * Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, 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_CONFIG_H +#include <kdrive-config.h> +#endif +#define XK_PUBLISHING +#include <X11/keysym.h> +#include <X11/Xdefs.h> + +#include <errno.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include <dev/wscons/wsconsio.h> + +#include "kdrive.h" + +int WsconsConsoleFd; +int OpenBSDApmFd = -1; +static Bool enabled; + +#define WSCONS_DEV "/dev/ttyC0" + +#define DBG(x) ErrorF x + +static int +OpenBSDInit(void) +{ + DBG(("OpenBSDInit\n")); + WsconsConsoleFd = open(WSCONS_DEV, O_RDWR); + + if (WsconsConsoleFd == -1) { + FatalError("OpenBSDInit: error opening %s (%d)\n", + WSCONS_DEV, errno); + } + return 1; +} + + +static void +OpenBSDEnable(void) +{ + DBG(("OpenBSDEnable\n")); + if (enabled) + return; + if (kdSwitchPending) { + kdSwitchPending = FALSE; + } + /* Open / init APM */ + /* Get a VT */ + /* Switch to graphics mode */ + enabled = TRUE; +} + + +static Bool +OpenBSDSpecialKey(KeySym sym) +{ + DBG(("OpenBSDSpecialKey\n")); + /* Initiate VT switch if needed */ + return FALSE; +} + +static void +OpenBSDDisable(void) +{ + DBG(("OpenBSDDisable\n")); + enabled = FALSE; + /* Back to text mode */ + /* Remove apm hooks */ +} + +static void +OpenBSDFini(void) +{ + int mode = WSDISPLAYIO_MODE_EMUL; + + DBG(("OpenBSDFini\n")); + if (WsconsConsoleFd < 0) + return; + + /* switch back to initial VT */ + if (ioctl(WsconsConsoleFd, WSDISPLAYIO_SMODE, &mode) == -1) { + ErrorF("WSDISPLAYIO_SMODE(EMUL): %s\n", strerror(errno)); + } +} + +static void +OpenBSDBell(int volume, int pitch, int duration) +{ + struct wskbd_bell_data wsb; + + DBG(("OpenBSDBell volume %d pictch %d duration %d\n", + volume, pitch, duration)); + wsb.which = WSKBD_BELL_DOALL; + wsb.pitch = pitch; + wsb.period = duration; + wsb.volume = volume; + if (ioctl(WsconsConsoleFd, WSKBDIO_COMPLEXBELL, &wsb) == -1) + ErrorF("WsconsKeyboardBell: %s\n", strerror(errno)); +} + +KdOsFuncs OpenBSDFuncs = { + OpenBSDInit, + OpenBSDEnable, + OpenBSDSpecialKey, + OpenBSDDisable, + OpenBSDFini, + OpenBSDBell, +}; + +void +OsVendorInit(void) +{ + DBG(("OsVendorInit\n")); + KdOsInit(&OpenBSDFuncs); +} diff --git a/hw/kdrive/wscons/Makefile.am b/hw/kdrive/wscons/Makefile.am new file mode 100644 index 000000000..f2843ed1a --- /dev/null +++ b/hw/kdrive/wscons/Makefile.am @@ -0,0 +1,25 @@ +# + +INCLUDES = \ + @KDRIVE_INCS@ \ + @KDRIVE_CFLAGS@ + +noinst_LIBRARIES = libwscons.a + +bin_PROGRAMS = Xwscons + +libwscons_a_SOURCES = \ + keyboard.c \ + mouse.c \ + wsfb.c \ + wsfb.h + +Xwscons_SOURCES = \ + wsinit.c + +Xwscons_LDADD = \ + libwscons.a \ + @KDRIVE_LIBS@ + +Xwscons_DEPENDENCIES = \ + libwscons.a diff --git a/hw/kdrive/wscons/TODO b/hw/kdrive/wscons/TODO new file mode 100644 index 000000000..64f4437f3 --- /dev/null +++ b/hw/kdrive/wscons/TODO @@ -0,0 +1,7 @@ +- find bugs +- finish kbd support + - xkb ? +- add -shadow to force shadow +- support pseudo-color and other strange framebuffer layouts +- better mouse support (wheel,...) +- man page diff --git a/hw/kdrive/wscons/keyboard.c b/hw/kdrive/wscons/keyboard.c new file mode 100644 index 000000000..ff477731c --- /dev/null +++ b/hw/kdrive/wscons/keyboard.c @@ -0,0 +1,136 @@ +/* $OpenBSD: keyboard.c,v 1.4 2007/12/23 14:28:10 matthieu Exp $ */ +/* + * Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, 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_CONFIG_H +#include <kdrive-config.h> +#endif +#include "kdrive.h" + +#include <X11/keysym.h> + +#include <errno.h> +#include <sys/ioctl.h> +#include <dev/wscons/wsconsio.h> + +#define DBG(x) ErrorF x + +extern int WsconsConsoleFd; + +static void +wskbdLoad(void) +{ + DBG(("wskbdLoad\n")); + + /* Read kernel Mapping */ +} + +#define NUM_EVENTS 64 + +static void +wskbdRead(int fd, void *closure) +{ + struct wscons_event events[NUM_EVENTS]; + int i, n, type; + + DBG(("wskbdRead\n")); + if ((n = read(fd, events, sizeof(events))) > 0) { + n /= sizeof(struct wscons_event); + for (i = 0; i < n; i++) { + type = events[i].type; + if (type == WSCONS_EVENT_KEY_UP || + type == WSCONS_EVENT_KEY_DOWN) { + + KdEnqueueKeyboardEvent(closure, + events[i].value, + type == WSCONS_EVENT_KEY_DOWN ? + TRUE : FALSE); + } + } /* for */ + } +} + +static int +wskbdEnable(KdKeyboardInfo *ki) +{ + int option = WSKBD_RAW; + int fd = WsconsConsoleFd; + + DBG(("wskbdEnable\n")); + if (ki == NULL) + return !Success; + ki->driverPrivate = (void *)fd; + + /* Switch to X mode */ + if (ioctl(fd, WSKBDIO_SETMODE, &option) == -1) { + ErrorF("wskbdEnable: WSKBDIO_SETMODE: %d\n", errno); + return -1; + } + KdRegisterFd (fd, wskbdRead, ki); + return Success; +} + +static void +wskbdDisable(KdKeyboardInfo *ki) +{ + int option = WSKBD_TRANSLATED; + int fd; + + DBG(("wskbdDisable\n")); + if (ki == NULL) + return; + fd = (int)ki->driverPrivate; + /* Back to console mode */ + ioctl(fd, WSKBDIO_SETMODE, &option); +} + +static int +wskbdInit(KdKeyboardInfo *ki) +{ + DBG(("wskbdInit\n")); + if (!ki) + return !Success; + + if (ki->path) + xfree(ki->path); + ki->path = KdSaveString("console"); + if (ki->name) + xfree(ki->name); + ki->name = KdSaveString("Wscons keyboard"); + + wskbdLoad(); + return Success; +} + + +static void +wskbdLeds(KdKeyboardInfo *ki, int leds) +{ + DBG(("wskbdLeds %d\n", leds)); + if (!ki) + return; + if (ioctl(WsconsConsoleFd, WSKBDIO_SETLEDS, &leds) == -1) + ErrorF("wskbd WSKBDIO_SETLEDS: %s\n", + strerror(errno)); +} + +KdKeyboardDriver WsconsKeyboardDriver = { + "keyboard", + .Init = wskbdInit, + .Enable = wskbdEnable, + .Leds = wskbdLeds, + .Disable = wskbdDisable +}; diff --git a/hw/kdrive/wscons/mouse.c b/hw/kdrive/wscons/mouse.c new file mode 100644 index 000000000..c80038056 --- /dev/null +++ b/hw/kdrive/wscons/mouse.c @@ -0,0 +1,148 @@ +/* $OpenBSD: mouse.c,v 1.5 2007/12/23 14:28:10 matthieu Exp $ */ +/* + * Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, 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_CONFIG_H +#include <kdrive-config.h> +#endif +#define NEED_EVENTS +#include <errno.h> +#include <termios.h> +#include <X11/X.h> +#include <X11/Xproto.h> +#include <dev/wscons/wsconsio.h> + +#include "inputstr.h" +#include "scrnintstr.h" +#include "kdrive.h" + +#define DBG(x) ErrorF x + +#define NUMEVENTS 64 + +static unsigned long kdbuttons[] = { + KD_BUTTON_1, + KD_BUTTON_2, + KD_BUTTON_3 +}; + +static void +wsmouseRead(int mousePort, void *closure) +{ + KdPointerInfo *pi = closure; + static struct wscons_event eventList[NUMEVENTS]; + struct wscons_event *event = eventList; + int n; + + n = read(mousePort, &eventList, + NUMEVENTS * sizeof(struct wscons_event)); + if (n <= 0) + return; + n /= sizeof(struct wscons_event); + while (n--) { + int dx = 0, dy = 0; + unsigned long flags = 0; + + switch(event->type) { + case WSCONS_EVENT_MOUSE_UP: + flags &= ~kdbuttons[event->value]; + break; + case WSCONS_EVENT_MOUSE_DOWN: + flags |= kdbuttons[1<<event->value]; + break; + case WSCONS_EVENT_MOUSE_DELTA_X: + dx = event->value; + flags |= KD_MOUSE_DELTA; + break; + case WSCONS_EVENT_MOUSE_DELTA_Y: + dy = event->value; + flags |= KD_MOUSE_DELTA; + break; + case WSCONS_EVENT_MOUSE_ABSOLUTE_X: + dx = event->value; + break; + case WSCONS_EVENT_MOUSE_ABSOLUTE_Y: + dy = event->value; + break; + default: + ErrorF("wsmouseRead: bad wsmouse event type=%d\n", + event->type); + continue; + } /* case */ + KdEnqueuePointerEvent(pi, flags, dx, dy, 0); + } +} + +int MouseInputType; + +static Status +wsmouseInit(KdPointerInfo *pi) +{ + char *device = "/dev/wsmouse"; + + DBG(("wsmouseInit\n")); + + if (pi->path == NULL) + pi->path = KdSaveString(device); + + if (pi->name == NULL) + pi->name = KdSaveString("Wscons mouse"); + return Success; +} + +static Status +wsmouseEnable(KdPointerInfo *pi) +{ + int fd; + + DBG(("wsmouseEnable\n")); + + if (pi == NULL || pi->driverPrivate == NULL || pi->path == NULL) + return BadImplementation; + + fd = open(pi->path, O_RDWR | O_NONBLOCK); + if (fd < 0) + return BadMatch; + + if (!KdRegisterFd(fd, wsmouseRead, pi)) { + close(fd); + return BadAlloc; + } + pi->driverPrivate = (void *)fd; + return Success; +} + +static void +wsmouseDisable(KdPointerInfo *pi) +{ + DBG(("wsmouseDisable\n")); + KdUnregisterFd(pi, (int)pi->driverPrivate, TRUE); +} + +static void +wsmouseFini(KdPointerInfo *pi) +{ + DBG(("wsmouseFini\n")); +} + +KdPointerDriver WsconsMouseDriver = { + "mouse", + wsmouseInit, + wsmouseEnable, + wsmouseDisable, + wsmouseFini, + NULL, +}; diff --git a/hw/kdrive/wscons/wsfb.c b/hw/kdrive/wscons/wsfb.c new file mode 100644 index 000000000..e5fe77dfd --- /dev/null +++ b/hw/kdrive/wscons/wsfb.c @@ -0,0 +1,630 @@ +/* $OpenBSD: wsfb.c,v 1.6 2009/09/06 19:44:25 matthieu Exp $ */ +/* + * Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, 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. + */ +/* Copyright © 1999 Keith Packard + * + * 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 name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD 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_CONFIG_H +#include <kdrive-config.h> +#endif +#include <dev/wscons/wsconsio.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <errno.h> + +#include <X11/X.h> +#include <X11/Xdefs.h> + +#include "wsfb.h" + +#define DEBUG 1 +#define DBG(x) ErrorF x + +extern int WsconsConsoleFd; + +/* Map the framebuffer's memory */ +static void * +wsfbMmap(size_t len, off_t off, int fd) +{ + int pagemask, mapsize; + caddr_t addr; + pointer mapaddr; + + pagemask = getpagesize() - 1; + mapsize = ((int) len + pagemask) & ~pagemask; + addr = 0; + + mapaddr = (pointer) mmap(addr, mapsize, + PROT_READ | PROT_WRITE, MAP_SHARED, + fd, off); + if (mapaddr == (pointer) -1) { + mapaddr = NULL; + } +#if DEBUG + ErrorF("mmap returns: addr %p len 0x%x\n", mapaddr, mapsize); +#endif + return mapaddr; +} + +Bool +wsfbMapFramebuffer(KdScreenInfo *screen) +{ + WsfbScrPriv *scrPriv = screen->driver; + KdPointerMatrix m; + WsfbPriv *priv = screen->card->driver; + size_t len; + + DBG(("wsfbMapFrameBuffer\n")); + + if (scrPriv->mapped) + return TRUE; + if (scrPriv->randr != RR_Rotate_0) + scrPriv->shadow = TRUE; + else + scrPriv->shadow = FALSE; + + KdComputePointerMatrix(&m, scrPriv->randr, + screen->width, screen->height); + KdSetPointerMatrix(&m); + + DBG(("screen->width %d\n", screen->width)); + DBG(("screen->height %d\n", screen->height)); + len = priv->linebytes * screen->height; + priv->fb = wsfbMmap(len, 0, WsconsConsoleFd); + if (priv->fb == NULL) + FatalError("Can't mmap framebuffer\n"); + + screen->memory_base = (CARD8 *)(priv->fb); + screen->memory_size = len; + + if (scrPriv->shadow) { + if (!KdShadowFbAlloc(screen, 0, + scrPriv->randr & (RR_Rotate_90|RR_Rotate_270))) + return FALSE; + screen->off_screen_base = screen->memory_size; + } else { + screen->fb[0].byteStride = priv->linebytes; + screen->fb[0].pixelStride = priv->linebytes * 8 / priv->bpp; + screen->fb[0].frameBuffer = (CARD8 *)(priv->fb); + screen->off_screen_base = + screen->fb[0].byteStride * screen->height; + } + scrPriv->mapped = TRUE; + return TRUE; +} + +static Bool +wsfbInitialize(KdCardInfo *card, WsfbPriv *priv) +{ + + DBG(("wsfbInitialize\n")); + if (WsconsConsoleFd == -1) { + ErrorF("wsfbInitialize: WsconsConsoleFd == -1\n"); + return FALSE; + } + if (ioctl(WsconsConsoleFd, WSDISPLAYIO_GTYPE, &priv->wstype) == -1) { + ErrorF("wsfbInitialize: WSDISPLAY_GTYPE: %s\n", + strerror(errno)); + return FALSE; + } + if (ioctl(WsconsConsoleFd, WSDISPLAYIO_GETSUPPORTEDDEPTH, + &priv->supportedDepths) == -1) { + ErrorF("wsfbInitialize: WSDISPLAYIO_GETSUPPORTEDDEPTH: %s\n", + strerror(errno)); + return FALSE; + } + + return TRUE; +} + +Bool +wsfbCardInit(KdCardInfo *card) +{ + WsfbPriv *priv; + + DBG(("wsfbCardInit\n")); + priv = (WsfbPriv *)xalloc(sizeof(WsfbPriv)); + if (priv == NULL) + return FALSE; + bzero(priv, sizeof(WsfbPriv)); + if (!wsfbInitialize(card, priv)) { + xfree(priv); + return FALSE; + } + card->driver = priv; + + return TRUE; +} + +static Bool +wsfbScreenInitialize(KdScreenInfo *screen, WsfbScrPriv *scrpriv) +{ + struct wsdisplay_gfx_mode gfxmode; + WsfbPriv *priv; + int depth = 24; + + priv = screen->card->driver; + + DBG(("wsfbScreenInitialize\n")); + DBG((" screen dimensions %dx%d\n", screen->width, screen->height)); + DBG((" screen depth %d\n", screen->fb[0].depth)); + DBG((" randr %d\n", screen->randr)); + if (screen->width == 0 || screen->height == 0) { + ErrorF("wsfbScreenInitialize: forcing 640x480\n"); + screen->width = 640; + screen->height = 480; + } + if (screen->fb[0].depth == 0) { + ErrorF("wsfbScreenInitialize: forcing depth 16\n"); + depth = screen->fb[0].depth = 16; + } + DBG((" wstype: %d\n", priv->wstype)); + if (priv->wstype == WSDISPLAY_TYPE_PCIVGA) { + gfxmode.depth = screen->fb[0].depth; + gfxmode.width = screen->width; + gfxmode.height = screen->height; + if (ioctl(WsconsConsoleFd, WSDISPLAYIO_SETGFXMODE, + &gfxmode) == -1) { + ErrorF("wsfbScreenInitialize: " + "WSDISPLAYIO_SETGFXMODE: %s\n", strerror(errno)); + return FALSE; + } + } + if (ioctl(WsconsConsoleFd, WSDISPLAYIO_GINFO, &priv->info) == -1) { + ErrorF("wsfbInitialize: WSDISPLAY_GINFO: %s\n", + strerror(errno)); + return FALSE; + } + if (ioctl(WsconsConsoleFd, WSDISPLAYIO_LINEBYTES, + &priv->linebytes) == -1) { + ErrorF("wsfbInitialize: WSDISPLAYIO_LINEBYTES: %s\n", + strerror(errno)); + return FALSE; + } + switch (depth) { + case 16: + screen->fb[0].visuals = (1 << TrueColor); + screen->fb[0].redMask = 0x1f << 11; + screen->fb[0].greenMask = 0x3f << 5; + screen->fb[0].blueMask = 0x1f; + break; + case 24: + screen->fb[0].visuals = (1 << TrueColor); + screen->fb[0].redMask = 0xff0000; + screen->fb[0].greenMask = 0x00ff00; + screen->fb[0].blueMask = 0x0000ff; + break; + default: + screen->fb[0].redMask = 0; + screen->fb[0].greenMask = 0; + screen->fb[0].blueMask = 0; + break; + } + screen->fb[0].bitsPerPixel = depth; + priv->bpp = depth; /* XXX */ + screen->dumb = TRUE; + screen->rate = 72; + scrpriv->randr = screen->randr; + DBG(("wsfbScreenInitialize: done\n")); + return TRUE; +} + +Bool +wsfbScreenInit(KdScreenInfo *screen) +{ + WsfbScrPriv *scrPriv; + + DBG(("wsfbScreenInit\n")); + scrPriv = (WsfbScrPriv *)xalloc(sizeof(WsfbScrPriv)); + if (scrPriv == NULL) + return FALSE; + bzero(scrPriv, sizeof(WsfbScrPriv)); + screen->driver = scrPriv; + if (!wsfbScreenInitialize(screen, scrPriv)) { + ErrorF("wsfbScreenInitialize: failed to initialize screen\n"); + screen->driver = NULL; + xfree(scrPriv); + return FALSE; + } + return TRUE; +} + +Bool +wsfbInitScreen(ScreenPtr pScreen) +{ + DBG(("wsfbInitScreen\n")); + pScreen->CreateColormap = wsfbCreateColormap; + return TRUE; +} + + +Bool +wsfbFinishInitScreen(ScreenPtr pScreen) +{ + DBG(("wsfbFinishInitScreen\n")); + + if (!shadowSetup(pScreen)) + return FALSE; +#ifdef RANDR + if (!wsfbRandRInit(pScreen)) + return FALSE; +#endif + return TRUE; +} + +Bool +wsfbCreateResources(ScreenPtr pScreen) +{ + DBG(("wsfbCreateResources\n")); + return wsfbSetShadow(pScreen); +} + +void +wsfbPreserve(KdCardInfo *card) +{ + DBG(("wsfbPreserve\n")); +} + + +Bool +wsfbEnable(ScreenPtr pScreen) +{ + KdScreenPriv(pScreen); + KdScreenInfo *screen = pScreenPriv->screen; + int wsmode = WSDISPLAYIO_MODE_DUMBFB; + + DBG(("wsfbEnable\n")); + /* Switch to graphics mode - required before mmap */ + if (ioctl(WsconsConsoleFd, WSDISPLAYIO_SMODE, &wsmode) == -1) { + ErrorF("ioctl WSDISPLAYIO_SMODE: %s\n", strerror(errno)); + return FALSE; + } + if (!wsfbMapFramebuffer(screen)) { + ErrorF("wsfbEnale: can't map framebuffer\n"); + return FALSE; + } + (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap (pScreen), + pScreen->width, + pScreen->height, + screen->fb[0].depth, + screen->fb[0].bitsPerPixel, + screen->fb[0].byteStride, + screen->fb[0].frameBuffer); + DBG(("wsfbEnable done.\n")); + return TRUE; +} + +Bool +wsfbDPMS(ScreenPtr pScreen, int mode) +{ + DBG(("wsfb DPMS %d\n", mode)); + return TRUE; +} + +void +wsfbDisable(ScreenPtr pScreen) +{ + DBG(("wsfbDisable\n")); +} + +void +wsfbRestore(KdCardInfo *card) +{ + int mode = WSDISPLAYIO_MODE_EMUL; + + DBG(("wsfbRestore\n")); + + if (ioctl(WsconsConsoleFd, WSDISPLAYIO_SMODE, &mode) == -1) { + ErrorF("WSDISPLAYIO_SMODE(EMUL): %s\n", strerror(errno)); + } +} + +void +wsfbScreenFini(KdScreenInfo *screen) +{ + + DBG(("wsfbScreenFini\n")); + wsfbUnmapFramebuffer(screen); +} + +void +wsfbCardFini(KdCardInfo *card) +{ + WsfbPriv *priv = card->driver; + + DBG(("wsfbCardFini\n")); + /* unmap framebuffer */ + /* close fd */ + xfree(priv); +} + +void +wsfbGetColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs) +{ + DBG(("wsfbGetColors %d\n", n)); + + while (n--) { + pdefs->red = 0; + pdefs->green = 0; + pdefs->blue = 0; + pdefs++; + } +} + +void +wsfbPutColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs) +{ + DBG(("wsfbPutColors %d\n", n)); +} + +void * +wsfbWindowLinear(ScreenPtr pScreen, + CARD32 row, + CARD32 offset, + int mode, + CARD32 *size, + void *closure) +{ + KdScreenPriv(pScreen); + WsfbPriv *priv = pScreenPriv->card->driver; + + DBG(("wsfbWindowLinear\n")); + + if (!pScreenPriv->enabled) + return NULL; + *size = priv->linebytes; + return (CARD8 *)priv->fb + row * priv->linebytes + offset; +} + +void +wsfbSetScreenSizes(ScreenPtr pScreen) +{ + KdScreenPriv(pScreen); + KdScreenInfo *screen = pScreenPriv->screen; + WsfbScrPriv *scrpriv = screen->driver; + WsfbPriv *priv = screen->card->driver; + + DBG(("wsfbSetScreenSizes\n")); + + if (scrpriv->randr & (RR_Rotate_0|RR_Rotate_180)) { + pScreen->width = priv->info.width; + pScreen->height = priv->info.height; + pScreen->mmWidth = screen->width_mm; + pScreen->mmHeight = screen->height_mm; + } else { + pScreen->width = priv->info.height; + pScreen->height = priv->info.width; + pScreen->mmWidth = screen->height_mm; + pScreen->mmHeight = screen->width_mm; + } +} + +void +wsfbUnmapFramebuffer(KdScreenInfo *screen) +{ + WsfbScrPriv *scrPriv = screen->driver; + + DBG(("wsfbUnmapFramebuffer\n")); + if (!scrPriv->mapped) + return; + KdShadowFbFree(screen, 0); + return; +} + +Bool +wsfbSetShadow(ScreenPtr pScreen) +{ + KdScreenPriv(pScreen); + KdScreenInfo *screen = pScreenPriv->screen; + WsfbScrPriv *scrPriv = screen->driver; + WsfbPriv *priv = screen->card->driver; + ShadowUpdateProc update; + ShadowWindowProc window; + int useXY = 0; + + DBG(("wsfbSetShadow\n")); + window = wsfbWindowLinear; + update = NULL; + if (scrPriv->randr) + if (priv->bpp == 16) { + switch(scrPriv->randr) { + case RR_Rotate_90: + if (useXY) + update = shadowUpdateRotate16_90YX; + else + update = shadowUpdateRotate16_90; + break; + case RR_Rotate_180: + update = shadowUpdateRotate16_180; + break; + case RR_Rotate_270: + if (useXY) + update = shadowUpdateRotate16_270YX; + else + update = shadowUpdateRotate16_270; + break; + default: + update = shadowUpdateRotate16; + break; + } + } else { + update = shadowUpdateRotatePacked; + } + else + update = shadowUpdateRotatePacked; + + return KdShadowSet(pScreen, scrPriv->randr, update, window); +} + +Bool +wsfbCreateColormap(ColormapPtr pmap) +{ + DBG(("wsfbCreateColormap\n")); + return fbInitializeColormap(pmap); +} + +#ifdef RANDR +Bool +wsfbRandRGetInfo(ScreenPtr pScreen, Rotation *rotations) +{ + KdScreenPriv(pScreen); + KdScreenInfo *screen = pScreenPriv->screen; + WsfbScrPriv *scrPriv = screen->driver; + RRScreenSizePtr pSize; + Rotation randr; + int n; + + DBG(("wsfbRandRGetInfo\n")); + *rotations = RR_Rotate_All|RR_Reflect_All; + + for (n = 0; n < pScreen->numDepths; n++) + if (pScreen->allowedDepths[n].numVids != 0) + break; + if (n == pScreen->numDepths) + return FALSE; + pSize = RRRegisterSize(pScreen, + screen->width, + screen->height, + screen->width_mm, + screen->height_mm); + randr = KdSubRotation(scrPriv->randr, screen->randr); + RRSetCurrentConfig(pScreen, randr, 0, pSize); + + return TRUE; +} + +Bool +wsfbRandRSetConfig(ScreenPtr pScreen, + Rotation randr, + int rate, + RRScreenSizePtr pSize) +{ + KdScreenPriv(pScreen); + KdScreenInfo *screen = pScreenPriv->screen; + WsfbScrPriv *scrpriv = screen->driver; + Bool wasEnabled = pScreenPriv->enabled; + WsfbScrPriv oldscr; + int oldwidth; + int oldheight; + int oldmmwidth; + int oldmmheight; + int newwidth, newheight; + + DBG(("wsfbRandRSetConfig\n")); + + if (screen->randr & (RR_Rotate_0|RR_Rotate_180)) { + newwidth = pSize->width; + newheight = pSize->height; + } else { + newwidth = pSize->height; + newheight = pSize->width; + } + + if (wasEnabled) + KdDisableScreen (pScreen); + + oldscr = *scrpriv; + + oldwidth = screen->width; + oldheight = screen->height; + oldmmwidth = pScreen->mmWidth; + oldmmheight = pScreen->mmHeight; + + /* + * Set new configuration + */ + + scrpriv->randr = KdAddRotation (screen->randr, randr); + + wsfbUnmapFramebuffer (screen); + + if (!wsfbMapFramebuffer (screen)) + goto bail4; + + KdShadowUnset (screen->pScreen); + + if (!wsfbSetShadow (screen->pScreen)) + goto bail4; + + wsfbSetScreenSizes (screen->pScreen); + + /* + * Set frame buffer mapping + */ + (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap (pScreen), + pScreen->width, + pScreen->height, + screen->fb[0].depth, + screen->fb[0].bitsPerPixel, + screen->fb[0].byteStride, + screen->fb[0].frameBuffer); + + /* set the subpixel order */ + + KdSetSubpixelOrder (pScreen, scrpriv->randr); + if (wasEnabled) + KdEnableScreen (pScreen); + + return TRUE; + +bail4: + wsfbUnmapFramebuffer (screen); + *scrpriv = oldscr; + (void) wsfbMapFramebuffer (screen); + pScreen->width = oldwidth; + pScreen->height = oldheight; + pScreen->mmWidth = oldmmwidth; + pScreen->mmHeight = oldmmheight; + + if (wasEnabled) + KdEnableScreen (pScreen); + return FALSE; +} + +Bool +wsfbRandRInit(ScreenPtr pScreen) +{ + rrScrPrivPtr pScrPriv; + + DBG(("wsfbRandRInit\n")); + + if (!RRScreenInit (pScreen)) + return FALSE; + + pScrPriv = rrGetScrPriv(pScreen); + pScrPriv->rrGetInfo = wsfbRandRGetInfo; + pScrPriv->rrSetConfig = wsfbRandRSetConfig; + return TRUE; +} +#endif /* RANDR */ diff --git a/hw/kdrive/wscons/wsfb.h b/hw/kdrive/wscons/wsfb.h new file mode 100644 index 000000000..feeb39745 --- /dev/null +++ b/hw/kdrive/wscons/wsfb.h @@ -0,0 +1,80 @@ +/* $OpenBSD: wsfb.h,v 1.3 2007/05/29 20:14:43 matthieu Exp $ */ +/* + * Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, 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. + */ +#ifndef _WSFB_H +#define _WSFB_H + +#include "kdrive.h" +#ifdef RANDR +#include "randrstr.h" +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +typedef struct _wsfbPriv { + int wstype; + struct wsdisplay_fbinfo info; + int linebytes; + int supportedDepths; + int bpp; + char *fb; + char *fb_base; +} WsfbPriv; + +typedef struct _wsfbScrPriv { + int mapped; + Rotation randr; + Bool shadow; + PixmapPtr pShadow; +} WsfbScrPriv; + +extern KdCardFuncs wsfbFuncs; + +Bool wsfbCardInit(KdCardInfo *); +Bool wsfbScreenInit(KdScreenInfo *); +Bool wsfbInitScreen(ScreenPtr); +Bool wsfbFinishInitScreen(ScreenPtr); +Bool wsfbCreateResources(ScreenPtr); +void wsfbPreserve(KdCardInfo *); +Bool wsfbEnable(ScreenPtr); +Bool wsfbDPMS(ScreenPtr, int); +void wsfbDisable(ScreenPtr); +void wsfbRestore(KdCardInfo *); +void wsfbScreenFini(KdScreenInfo *); +void wsfbCardFini(KdCardInfo *); +void wsfbGetColors(ScreenPtr, int, int, xColorItem *); +void wsfbPutColors(ScreenPtr, int, int, xColorItem *); + +Bool wsfbMapFramebuffer(KdScreenInfo *); +void *wsfbWindowLinear(ScreenPtr, CARD32, CARD32, int, CARD32 *, void *); +void wsfbSetScreenSizes(ScreenPtr); +void wsfbUnmapFramebuffer(KdScreenInfo *); +Bool wsfbSetShadow(ScreenPtr); +Bool wsfbCreateColormap(ColormapPtr); + +#ifdef RANDR +Bool wsfbRandRGetInfo(ScreenPtr, Rotation *); +Bool wsfbRandRSetConfig(ScreenPtr, Rotation, int, RRScreenSizePtr); +Bool wsfbRandRInit(ScreenPtr); +#endif + +#endif /* _WSFB_H */ diff --git a/hw/kdrive/wscons/wsinit.c b/hw/kdrive/wscons/wsinit.c new file mode 100644 index 000000000..b2d5d54ab --- /dev/null +++ b/hw/kdrive/wscons/wsinit.c @@ -0,0 +1,98 @@ +/* $OpenBSD: wsinit.c,v 1.3 2007/12/23 14:28:10 matthieu Exp $ */ +/* + * Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, 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_CONFIG_H +#include <kdrive-config.h> +#endif +#include <dev/wscons/wsconsio.h> + +#include "kdrive.h" +#include "wsfb.h" + +#define DBG(x) ErrorF x + +void +InitCard(char *name) +{ + KdCardAttr attr; + + DBG(("InitCard\n")); + KdCardInfoAdd(&wsfbFuncs, &attr, 0); +} + +void +InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) +{ + DBG(("InitOutput\n")); + KdInitOutput(pScreenInfo, argc, argv); +} + +void +InitInput(int argc, char **argv) +{ + KdKeyboardInfo *ki; + + DBG(("InitInput\n")); + KdAddKeyboardDriver(&WsconsKeyboardDriver); + KdAddPointerDriver(&WsconsMouseDriver); + ki = KdParseKeyboard("keybd"); + KdAddKeyboard(ki); + + KdInitInput(); +} + +void +ddxUseMsg(void) +{ + KdUseMsg(); + ErrorF("\nXwsfb device Usage:\n"); + ErrorF("-foo bar\n"); + ErrorF("\n"); +} + +int +ddxProcessArgument(int argc, char **argv, int i) +{ + DBG(("ddxProcessArgument\n")); + return KdProcessArgument(argc, argv, i); +} + +KdCardFuncs wsfbFuncs = { + wsfbCardInit, + wsfbScreenInit, + wsfbInitScreen, + wsfbFinishInitScreen, + wsfbCreateResources, + wsfbPreserve, + wsfbEnable, + wsfbDPMS, + wsfbDisable, + wsfbRestore, + wsfbScreenFini, + wsfbCardFini, + 0, /* initCursor */ + 0, /* enableCursor */ + 0, /* disqbleCursor */ + 0, /* finiCursor */ + 0, /* recolorCursor */ + 0, /* initAccel */ + 0, /* enableAccel */ + 0, /* disableAccel */ + 0, /* finiAccel */ + wsfbGetColors, + wsfbPutColors, +}; diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h index 0abdfb6c3..f1d491d18 100644 --- a/hw/xfree86/common/compiler.h +++ b/hw/xfree86/common/compiler.h @@ -704,7 +704,7 @@ xf86WriteMmio32LeNB(__volatile__ void *base, const unsigned long offset, } #elif defined(__mips__) || (defined(__arm32__) && !defined(__linux__)) -#ifdef __arm32__ +#if defined(__arm32__) || defined(__mips64__) #define PORT_SIZE long #else #define PORT_SIZE short diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c index 43c746b7f..b02aaf031 100644 --- a/hw/xfree86/common/xf86AutoConfig.c +++ b/hw/xfree86/common/xf86AutoConfig.c @@ -40,7 +40,7 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" #include "xf86pciBus.h" -#ifdef __sparc__ +#if defined(__sparc__) && !defined(__OpenBSD__) #include "xf86sbusBus.h" #endif @@ -250,7 +250,7 @@ listPossibleVideoDrivers(char *matches[], int nmatches) } } #endif -#ifdef __sparc__ +#if defined(__sparc__) { char *sbusDriver = sparcDriverName(); @@ -265,7 +265,7 @@ listPossibleVideoDrivers(char *matches[], int nmatches) if (i < (nmatches - 1)) { #if defined(__i386__) || defined(__amd64__) || defined(__hurd__) matches[i++] = xnfstrdup("vesa"); -#elif defined(__sparc__) && !defined(sun) +#elif defined(__sparc__) && defined(__linux__) matches[i++] = xnfstrdup("sunffb"); #endif } @@ -273,7 +273,13 @@ listPossibleVideoDrivers(char *matches[], int nmatches) #if !defined(sun) /* Fallback to platform default frame buffer driver */ if (i < (nmatches - 1)) { -#if !defined(__linux__) && defined(__sparc__) +#if defined(__OpenBSD__) +#if !defined(__i386__) && !defined(__amd64__) + if (i == 0) { + matches[i++] = xnfstrdup("wsfb"); + } +#endif +#elif !defined(__linux__) && defined(__sparc__) matches[i++] = xnfstrdup("wsfb"); #else matches[i++] = xnfstrdup("fbdev"); diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c index b176e8cc4..ccd44f651 100644 --- a/hw/xfree86/common/xf86Bus.c +++ b/hw/xfree86/common/xf86Bus.c @@ -205,7 +205,7 @@ xf86BusProbe(void) #ifdef XSERVER_LIBPCIACCESS xf86PciProbe(); #endif -#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) +#if (defined(__sparc__) || defined(__sparc)) xf86SbusProbe(); #endif } diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index 7491f720d..09ea3fa8c 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -515,14 +515,14 @@ static void fixup_video_driver_list(char **drivers) { static const char *fallback[4] = { "vesa", "fbdev", "wsfb", NULL }; - char **end, **drv; + static const char *blacklist[] = { "radeonhd", "radeon", NULL }; + char **end, **drv, **d; char *x; int i; /* walk to the end of the list */ for (end = drivers; *end && **end; end++); end--; - /* * for each of the fallback drivers, if we find it in the list, * swap it with the last available non-fallback driver. @@ -538,6 +538,16 @@ fixup_video_driver_list(char **drivers) } } } + /* Remove blacklisted drivers */ + for (i = 0; blacklist[i]; i++) { + for (drv = drivers; drv != end; drv++) { + if (strcmp(*drv, blacklist[i]) == 0) { + end--; + for (d = drv; d != end; d++) + *d = *(d+1); + } + } + } } static char ** @@ -781,7 +791,7 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) XkbRMLVOSet set; /* Default options. */ - set.rules = "base"; + set.rules = XKB_DFLT_RULES; set.model = "pc105"; set.layout = "us"; set.variant = NULL; @@ -1131,7 +1141,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) MessageType from = X_DEFAULT; const char *mousedrivers[] = { "mouse", "synaptics", "evdev", "vmmouse", - "void", NULL + "ws", "void", NULL }; /* diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 6f69117d3..d466118d5 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -34,7 +34,6 @@ #define IN_XSERVER #include "Configint.h" #include "xf86DDC.h" -#include "xf86pciBus.h" #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) #include "xf86Bus.h" #include "xf86Sbus.h" @@ -302,8 +301,9 @@ configureDeviceSection(int screennum) if (!ptr->dev_comment) break; p_e = ptr->dev_comment + strlen(ptr->dev_comment); - sprintf(p_e, "%s%-20s%s%s%s", prefix, optname, middle, - opttype, suffix); + snprintf(p_e, len - (ptr->dev_comment - p_e), + "%s%-20s%s%s%s", prefix, optname, middle, + opttype, suffix); free(optname); } } @@ -772,6 +772,7 @@ DoConfigure(void) ErrorF("To test the server, run 'X -config %s'\n\n", filename); bail: + CloseWellKnownConnections(); OsCleanup(TRUE); AbortDDX(EXIT_ERR_CONFIGURE); fflush(stderr); diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index ba80acad7..7c32bf5d9 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -110,6 +110,10 @@ static PixmapFormatRec formats[MAXFORMATS] = { static int numFormats = 7; static Bool formatsDone = FALSE; +#ifdef X_PRIVSEP +static Bool xf86KeepPriv = FALSE; +#endif + #ifndef OSNAME #define OSNAME " unknown" #endif @@ -929,6 +933,11 @@ CloseInput(void) * is called by dix before establishing the well known sockets. */ +#ifdef X_PRIVSEP +extern void xf86DropPriv(char *); +extern void xf86PrivilegedInit(void); +#endif + void OsVendorInit(void) { @@ -962,6 +971,12 @@ OsVendorInit(void) } #endif #endif +#if defined(X_PRIVSEP) + if (!beenHere && !xf86KeepPriv && geteuid() == 0) { + xf86PrivilegedInit(); + xf86DropPriv(display); + } +#endif xf86UnblockSIGIO(0); beenHere = TRUE; @@ -1159,6 +1174,11 @@ ddxProcessArgument(int argc, char **argv, int i) argv[i], argv[i]); } xf86ConfigFile = argv[i + 1]; +#ifdef X_PRIVSEP + /* Cannot drop privs when -xf86config is used with unsafe path */ + if (!xf86PathIsSafe(xf86ConfigFile)) + xf86KeepPriv = TRUE; +#endif return 2; } if (!strcmp(argv[i], "-configdir")) { @@ -1367,8 +1387,21 @@ ddxProcessArgument(int argc, char **argv, int i) } xf86DoConfigure = TRUE; xf86AllowMouseOpenFail = TRUE; +#ifdef X_PRIVSEP + xf86KeepPriv = TRUE; +#endif + return 1; + } +#ifdef X_PRIVSEP + if (!strcmp(argv[i], "-keepPriv")) { + if (getuid() != 0 && geteuid() == 0) { + ErrorF("The '-keepPriv' option can only be used by root.\n"); + exit(1); + } + xf86KeepPriv = TRUE; return 1; } +#endif if (!strcmp(argv[i], "-showopts")) { if (getuid() != 0 && geteuid() == 0) { ErrorF("The '-showopts' option can only be used by root.\n"); @@ -1473,6 +1506,10 @@ ddxUseMsg(void) ErrorF ("-novtswitch don't automatically switch VT at reset & exit\n"); ErrorF("-sharevts share VTs with another X server\n"); +#ifdef X_PRIVSEP + ErrorF("-keepPriv " + "don't revoque privileges when running as root\n"); +#endif /* OS-specific usage */ xf86UseMsg(); ErrorF("\n"); diff --git a/hw/xfree86/common/xf86fbBus.c b/hw/xfree86/common/xf86fbBus.c index 1e5162332..1d50e5102 100644 --- a/hw/xfree86/common/xf86fbBus.c +++ b/hw/xfree86/common/xf86fbBus.c @@ -58,7 +58,7 @@ xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active) if (pciSlotClaimed) return -1; #endif -#if defined(__sparc__) || defined (__sparc64__) +#if (defined(__sparc__) || defined (__sparc64__)) &&!defined(__OpenBSD__) if (sbusSlotClaimed) return -1; #endif diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c index 9530eb40e..13b3fd884 100644 --- a/hw/xfree86/dri/dri.c +++ b/hw/xfree86/dri/dri.c @@ -376,7 +376,6 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) pDRIPriv->createDummyCtxPriv = pDRIInfo->createDummyCtxPriv; pDRIPriv->grabbedDRILock = FALSE; - pDRIPriv->drmSIGIOHandlerInstalled = FALSE; *pDRMFD = pDRIPriv->drmFD; if (pDRIEntPriv->sAreaGrabbed || pDRIInfo->allocSarea) { @@ -556,23 +555,6 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) /* fall through */ case DRI_SERVER_SWAP: - /* For swap methods of DRI_SERVER_SWAP and DRI_HIDE_X_CONTEXT - * setup signal handler for receiving swap requests from kernel - */ - if (!(pDRIPriv->drmSIGIOHandlerInstalled = - drmInstallSIGIOHandler(pDRIPriv->drmFD, DRISwapContext))) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[drm] failed to setup DRM signal handler\n"); - free(pDRIPriv->hiddenContextStore); - free(pDRIPriv->partial3DContextStore); - DRIDestroyContextPriv(pDRIContextPriv); - return FALSE; - } - else { - DRIDrvMsg(pScreen->myNum, X_INFO, - "[drm] installed DRM signal handler\n"); - } - default: break; } @@ -681,13 +663,6 @@ DRICloseScreen(ScreenPtr pScreen) pDRIPriv->wrapped = FALSE; } - if (pDRIPriv->drmSIGIOHandlerInstalled) { - if (!drmRemoveSIGIOHandler(pDRIPriv->drmFD)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[drm] failed to remove DRM signal handler\n"); - } - } - if (pDRIPriv->dummyCtxPriv && pDRIPriv->createDummyCtx) { DRIDestroyDummyContext(pScreen, pDRIPriv->createDummyCtxPriv); } @@ -2440,74 +2415,3 @@ DRICreatePCIBusID(const struct pci_device *dev) return busID; } - -static void -drmSIGIOHandler(int interrupt, void *closure) -{ - unsigned long key; - void *value; - ssize_t count; - drm_ctx_t ctx; - typedef void (*_drmCallback) (int, void *, void *); - char buf[256]; - drm_context_t old; - drm_context_t new; - void *oldctx; - void *newctx; - char *pt; - drmHashEntry *entry; - void *hash_table; - - hash_table = drmGetHashTable(); - - if (!hash_table) - return; - if (drmHashFirst(hash_table, &key, &value)) { - entry = value; - do { -#if 0 - fprintf(stderr, "Trying %d\n", entry->fd); -#endif - if ((count = read(entry->fd, buf, sizeof(buf) - 1)) > 0) { - buf[count] = '\0'; -#if 0 - fprintf(stderr, "Got %s\n", buf); -#endif - - for (pt = buf; *pt != ' '; ++pt); /* Find first space */ - ++pt; - old = strtol(pt, &pt, 0); - new = strtol(pt, NULL, 0); - oldctx = drmGetContextTag(entry->fd, old); - newctx = drmGetContextTag(entry->fd, new); -#if 0 - fprintf(stderr, "%d %d %p %p\n", old, new, oldctx, newctx); -#endif - ((_drmCallback) entry->f) (entry->fd, oldctx, newctx); - ctx.handle = new; - ioctl(entry->fd, DRM_IOCTL_NEW_CTX, &ctx); - } - } while (drmHashNext(hash_table, &key, &value)); - } -} - -int -drmInstallSIGIOHandler(int fd, void (*f) (int, void *, void *)) -{ - drmHashEntry *entry; - - entry = drmGetEntry(fd); - entry->f = f; - - return xf86InstallSIGIOHandler(fd, drmSIGIOHandler, 0); -} - -int -drmRemoveSIGIOHandler(int fd) -{ - drmHashEntry *entry = drmGetEntry(fd); - - entry->f = NULL; - - return xf86RemoveSIGIOHandler(fd); -} diff --git a/hw/xfree86/dummylib/chownlock.c b/hw/xfree86/dummylib/chownlock.c new file mode 100644 index 000000000..f4b01901f --- /dev/null +++ b/hw/xfree86/dummylib/chownlock.c @@ -0,0 +1,10 @@ +/* + * Public domain + */ +/* $OpenBSD: chownlock.c,v 1.1 2006/11/28 20:29:31 matthieu Exp $ */ +#include <sys/types.h> +int +ChownLock(uid_t uid, gid_t gid) +{ + return 0; +} diff --git a/hw/xfree86/dummylib/dispatchException.c b/hw/xfree86/dummylib/dispatchException.c new file mode 100644 index 000000000..6ceb91e84 --- /dev/null +++ b/hw/xfree86/dummylib/dispatchException.c @@ -0,0 +1,8 @@ +/** + ** Public domain + **/ +/* $OpenBSD: dispatchException.c,v 1.1 2006/11/28 20:29:31 matthieu Exp $ */ + +#include "opaque.h" + +volatile char dispatchException; diff --git a/hw/xfree86/dummylib/privsep.c b/hw/xfree86/dummylib/privsep.c new file mode 100644 index 000000000..bb25d6d08 --- /dev/null +++ b/hw/xfree86/dummylib/privsep.c @@ -0,0 +1,18 @@ +/** + ** Public domain + **/ +/* $OpenBSD: privsep.c,v 1.1 2006/11/28 20:29:31 matthieu Exp $ */ +#include <sys/types.h> +#include <fcntl.h> + +int +priv_init(uid_t uid, gid_t gid) +{ + return 0; +} + +int +priv_open_device(char *path) +{ + return open(path, O_RDWR); +} diff --git a/hw/xfree86/dummylib/serverGeneration.c b/hw/xfree86/dummylib/serverGeneration.c new file mode 100644 index 000000000..07982b7bc --- /dev/null +++ b/hw/xfree86/dummylib/serverGeneration.c @@ -0,0 +1,8 @@ +/** + ** Public domain + **/ +/* $OpenBSD: serverGeneration.c,v 1.1 2006/11/28 20:29:31 matthieu Exp $ */ + +#include "misc.h" + +unsigned long serverGeneration; diff --git a/hw/xfree86/dummylib/useMsg.c b/hw/xfree86/dummylib/useMsg.c new file mode 100644 index 000000000..a1ce12cc8 --- /dev/null +++ b/hw/xfree86/dummylib/useMsg.c @@ -0,0 +1,11 @@ +/** + ** Public Domain + **/ +/* $OpenBSD: useMsg.c,v 1.1 2006/11/28 20:29:31 matthieu Exp $ */ + +#include "os.h" + +void +UseMsg(void) +{ +} diff --git a/hw/xfree86/man/Xorg.man b/hw/xfree86/man/Xorg.man index 2fa72d672..0c469129f 100644 --- a/hw/xfree86/man/Xorg.man +++ b/hw/xfree86/man/Xorg.man @@ -270,6 +270,14 @@ is ignored if .I bustype is anything other than \(oqPCI\(cq. .TP 8 +.B \-keepPriv +Prevent the server from revoking its privileges. If this option is +not specified, the X server will change its uid and gid either to +those of the user who started it or to the \fI_x11\fP user and group +if it was started by the super-user, after performing the +initialisations that require super-user privileges. Only root can use +this option. +.TP 8 .B \-keeptty Prevent the server from detaching its initial controlling terminal. This option is only useful when debugging the server. Not all platforms diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c index a773c34c6..aea9e1c7e 100644 --- a/hw/xfree86/modes/xf86RandR12.c +++ b/hw/xfree86/modes/xf86RandR12.c @@ -820,6 +820,7 @@ xf86RandR12CreateScreenResources(ScreenPtr pScreen) pScreen->width = width; pScreen->height = height; xf86RandR12ScreenSetSize(pScreen, width, height, mmWidth, mmHeight); + xf86ReconfigureLayout(); } if (xf86RandR12Key == NULL) diff --git a/hw/xfree86/os-support/bsd/Makefile.am b/hw/xfree86/os-support/bsd/Makefile.am index b6ecdf1d1..a0dc9c734 100644 --- a/hw/xfree86/os-support/bsd/Makefile.am +++ b/hw/xfree86/os-support/bsd/Makefile.am @@ -18,7 +18,7 @@ KMOD_SOURCES = $(srcdir)/../shared/kmod_noop.c endif if AGP -AGP_SOURCES = $(srcdir)/../linux/lnx_agp.c +AGP_SOURCES = bsd_agp.c else AGP_SOURCES = $(srcdir)/../shared/agp_noop.c endif @@ -33,7 +33,18 @@ ARCH_SOURCES = \ endif if ARM_VIDEO -ARCH_SOURCES = arm_video.c +ARCH_SOURCES = arm_video.c \ + $(srcdir)/../shared/ioperm_noop.c +endif + +if HP300_VIDEO +ARCH_SOURCES = hp300_video.c \ + $(srcdir)/../shared/ioperm_noop.c +endif + +if HPPA_VIDEO +ARCH_SOURCES = hppa_video.c\ + $(srcdir)/../shared/ioperm_noop.c endif if I386_VIDEO @@ -41,13 +52,20 @@ ARCH_SOURCES = i386_video.c endif if PPC_VIDEO -ARCH_SOURCES = ppc_video.c +ARCH_SOURCES = ppc_video.c \ + $(srcdir)/../shared/ioperm_noop.c +endif + +if SGI_VIDEO +ARCH_SOURCES = sgi_video.c \ + $(srcdir)/../shared/ioperm_noop.c endif if SPARC64_VIDEO # Cheat here and piggyback other sparc64 bits on SPARC64_VIDEO. ARCH_SOURCES = \ sparc64_video.c \ + bsd_sbus.c \ $(srcdir)/../shared/ioperm_noop.c endif diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c index 91f9fc826..2fc482792 100644 --- a/hw/xfree86/os-support/bsd/alpha_video.c +++ b/hw/xfree86/os-support/bsd/alpha_video.c @@ -6,19 +6,19 @@ * 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 Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of + * documentation, and that the names of Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or * implied warranty. * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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. * */ @@ -39,7 +39,7 @@ #include <machine/sysarch.h> #endif -#include "xf86Axp.h" +#include "shared/xf86Axp.h" #include "xf86_OSlib.h" #include "xf86OSpriv.h" @@ -67,7 +67,6 @@ memory_base(void) if (base == 0) { size_t len = sizeof(base); int error; - #ifdef __OpenBSD__ int mib[3]; @@ -77,11 +76,11 @@ memory_base(void) if ((error = sysctl(mib, 3, &base, &len, NULL, 0)) < 0) #else - if ((error = sysctlbyname("hw.chipset.memory", &base, &len, 0, 0)) < 0) + if ((error = sysctlbyname("hw.chipset.memory", &base, &len, + 0, 0)) < 0) #endif FatalError("xf86MapVidMem: can't find memory\n"); } - return base; } @@ -91,7 +90,6 @@ has_bwx(void) static int bwx = 0; size_t len = sizeof(bwx); int error; - #ifdef __OpenBSD__ int mib[3]; @@ -110,9 +108,9 @@ has_bwx(void) return bwx; #endif } -#else /* __NetBSD__ */ +#else /* __NetBSD__ */ static unsigned long hae_thresh = (1UL << 24); -static unsigned long hae_mask = 0xf8000000UL; /* XXX - should use xf86AXP.c */ +static unsigned long hae_mask = 0xf8000000UL; /* XXX - should use xf86AXP.c */ static struct alpha_bus_window *abw; static int abw_count = -1; @@ -132,7 +130,8 @@ has_bwx(void) if (abw_count < 0) init_abw(); - xf86Msg(X_INFO, "has_bwx = %d\n", abw[0].abw_abst.abst_flags & ABST_BWX ? 1 : 0); /* XXXX */ + xf86Msg(X_INFO, "has_bwx = %d\n", + abw[0].abw_abst.abst_flags & ABST_BWX ? 1 : 0); /* XXXX */ return abw[0].abw_abst.abst_flags & ABST_BWX; } @@ -143,7 +142,8 @@ dense_base(void) init_abw(); /* XXX check abst_flags for ABST_DENSE just to be safe? */ - xf86Msg(X_INFO, "dense base = %#lx\n", abw[0].abw_abst.abst_sys_start); /* XXXX */ + xf86Msg(X_INFO, "dense base = %#lx\n", + abw[0].abw_abst.abst_sys_start); /* XXXX */ return abw[0].abw_abst.abst_sys_start; } @@ -153,37 +153,33 @@ memory_base(void) if (abw_count < 0) init_abw(); - if (abw_count > 1) { - xf86Msg(X_INFO, "memory base = %#lx\n", abw[1].abw_abst.abst_sys_start); /* XXXX */ + if (abw_count > 0) { + xf86Msg(X_INFO, "memory base = %#lx\n", + abw[1].abw_abst.abst_sys_start); /* XXXX */ return abw[1].abw_abst.abst_sys_start; } - else if (abw_count == 1) { - /* assume memory_base == dense_base */ - xf86Msg(X_INFO, "memory base = %#lx\n", abw[0].abw_abst.abst_sys_start); /* XXXX */ - return abw[0].abw_abst.abst_sys_start; - } else { - xf86Msg(X_INFO, "no memory base\n"); /* XXXX */ + xf86Msg(X_INFO, "no memory base\n"); /* XXXX */ return 0; } } -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ */ -#define BUS_BASE dense_base() -#define BUS_BASE_BWX memory_base() +#define BUS_BASE dense_base() +#define BUS_BASE_BWX memory_base() /***************************************************************************/ /* Video Memory Mapping section */ /***************************************************************************/ #ifdef __OpenBSD__ -#define SYSCTL_MSG "\tCheck that you have set 'machdep.allowaperture=1'\n"\ +#define SYSCTL_MSG "\tCheck that you have set 'machdep.allowaperture=1'\n" \ "\tin /etc/sysctl.conf and reboot your machine\n" \ "\trefer to xf86(4) for details" #endif static Bool useDevMem = FALSE; -static int devMemFd = -1; +static int devMemFd = -1; #ifdef HAS_APERTURE_DRV #define DEV_APERTURE "/dev/xf86" @@ -213,11 +209,11 @@ checkDevMem(Bool warn) /* Try the aperture driver first */ if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) { /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); + base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE); if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); + munmap((caddr_t)base, 4096); devMemFd = fd; useDevMem = TRUE; xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n", @@ -234,11 +230,11 @@ checkDevMem(Bool warn) #endif if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); + base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t)0xA0000 + BUS_BASE); if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); + munmap((caddr_t)base, 4096); devMemFd = fd; useDevMem = TRUE; return; @@ -258,11 +254,11 @@ checkDevMem(Bool warn) #ifndef __OpenBSD__ xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" "\t(%s)\n", DEV_APERTURE, DEV_MEM, strerror(errno)); -#else /* __OpenBSD__ */ +#else /* __OpenBSD__ */ xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" "\t(%s)\n%s", DEV_APERTURE, DEV_MEM, strerror(errno), SYSCTL_MSG); -#endif /* __OpenBSD__ */ +#endif /* __OpenBSD__ */ #endif xf86ErrorF("\tlinear framebuffer access unavailable\n"); } @@ -277,12 +273,12 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem) pVidMem->linearSupported = useDevMem; if (has_bwx()) { - xf86Msg(X_PROBED, "Machine type has 8/16 bit access\n"); + xf86Msg(X_PROBED,"Machine type has 8/16 bit access\n"); pVidMem->mapMem = mapVidMem; pVidMem->unmapMem = unmapVidMem; } else { - xf86Msg(X_PROBED, "Machine needs sparse mapping\n"); + xf86Msg(X_PROBED,"Machine needs sparse mapping\n"); pVidMem->mapMem = mapVidMemSparse; pVidMem->unmapMem = unmapVidMemSparse; #ifndef __NetBSD__ @@ -290,7 +286,7 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem) axpSystem = bsdGetAXP(); hae_thresh = xf86AXPParams[axpSystem].hae_thresh; hae_mask = xf86AXPParams[axpSystem].hae_mask; -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ */ } pVidMem->initialised = TRUE; } @@ -301,33 +297,35 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) pointer base; checkDevMem(FALSE); - Base = Base & ((1L << 32) - 1); + Base = Base & ((1L<<32) - 1); if (useDevMem) { if (devMemFd < 0) { FatalError("xf86MapVidMem: failed to open %s (%s)\n", DEV_MEM, strerror(errno)); } - base = mmap((caddr_t) 0, Size, + base = mmap((caddr_t)0, Size, (flags & VIDMEM_READONLY) ? PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, devMemFd, (off_t) Base + BUS_BASE_BWX); + MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX); if (base == MAP_FAILED) { FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)\n", - "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno)); + "xf86MapVidMem", DEV_MEM, Size, Base, + strerror(errno)); } return base; } /* else, mmap /dev/vga */ - if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) { + if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000) { FatalError("%s: Address 0x%lx outside allowable range\n", "xf86MapVidMem", Base); } base = mmap(0, Size, (flags & VIDMEM_READONLY) ? PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base + BUS_BASE); + MAP_FLAGS, xf86Info.consoleFd, + (unsigned long)Base + BUS_BASE); if (base == MAP_FAILED) { FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n", strerror(errno)); @@ -338,14 +336,14 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) static void unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - munmap((caddr_t) Base, Size); + munmap((caddr_t)Base, Size); } /* * Read BIOS via mmap()ing DEV_MEM */ -int +_X_EXPORT int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, int Len) { @@ -362,21 +360,20 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, Offset += Base & (psize - 1); Base &= ~(psize - 1); mlen = (Offset + Len + psize - 1) & ~(psize - 1); - ptr = (unsigned char *) mmap((caddr_t) 0, mlen, PROT_READ, - MAP_SHARED, devMemFd, (off_t) Base + BUS_BASE); - if ((long) ptr == -1) { + ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ, + MAP_SHARED, devMemFd, (off_t)Base+BUS_BASE); + if ((long)ptr == -1) { xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n", DEV_MEM, Len, Base, Offset, strerror(errno)); return -1; } #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, - "xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", Base, - ptr[0] | (ptr[1] << 8)); + xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", + Base, ptr[0] | (ptr[1] << 8)); #endif - (void) memcpy(Buf, (void *) (ptr + Offset), Len); - (void) munmap((caddr_t) ptr, mlen); + (void)memcpy(Buf, (void *)(ptr + Offset), Len); + (void)munmap((caddr_t)ptr, mlen); #ifdef DEBUG xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" "-> %02x %02x %02x %02x...\n", @@ -385,11 +382,12 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, return Len; } + #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) extern int ioperm(unsigned long from, unsigned long num, int on); -Bool +_X_EXPORT Bool xf86EnableIO() { if (!ioperm(0, 65536, TRUE)) @@ -397,13 +395,13 @@ xf86EnableIO() return FALSE; } -void +_X_EXPORT void xf86DisableIO() { return; } -#endif /* __FreeBSD_kernel__ || __OpenBSD__ */ +#endif /* __FreeBSD_kernel__ || __OpenBSD__ */ #ifdef USE_ALPHA_PIO @@ -420,7 +418,7 @@ xf86DisableIO() alpha_pci_io_enable(0); } -#endif /* USE_ALPHA_PIO */ +#endif /* USE_ALPHA_PIO */ #define vuip volatile unsigned int * @@ -431,33 +429,33 @@ extern int readDense8(pointer Base, register unsigned long Offset); extern int readDense16(pointer Base, register unsigned long Offset); extern int readDense32(pointer Base, register unsigned long Offset); extern void - writeDenseNB8(int Value, pointer Base, register unsigned long Offset); +writeDenseNB8(int Value, pointer Base, register unsigned long Offset); extern void - writeDenseNB16(int Value, pointer Base, register unsigned long Offset); +writeDenseNB16(int Value, pointer Base, register unsigned long Offset); extern void - writeDenseNB32(int Value, pointer Base, register unsigned long Offset); +writeDenseNB32(int Value, pointer Base, register unsigned long Offset); extern void - writeDense8(int Value, pointer Base, register unsigned long Offset); +writeDense8(int Value, pointer Base, register unsigned long Offset); extern void - writeDense16(int Value, pointer Base, register unsigned long Offset); +writeDense16(int Value, pointer Base, register unsigned long Offset); extern void - writeDense32(int Value, pointer Base, register unsigned long Offset); +writeDense32(int Value, pointer Base, register unsigned long Offset); static int readSparse8(pointer Base, register unsigned long Offset); static int readSparse16(pointer Base, register unsigned long Offset); static int readSparse32(pointer Base, register unsigned long Offset); static void - writeSparseNB8(int Value, pointer Base, register unsigned long Offset); +writeSparseNB8(int Value, pointer Base, register unsigned long Offset); static void - writeSparseNB16(int Value, pointer Base, register unsigned long Offset); +writeSparseNB16(int Value, pointer Base, register unsigned long Offset); static void - writeSparseNB32(int Value, pointer Base, register unsigned long Offset); +writeSparseNB32(int Value, pointer Base, register unsigned long Offset); static void - writeSparse8(int Value, pointer Base, register unsigned long Offset); +writeSparse8(int Value, pointer Base, register unsigned long Offset); static void - writeSparse16(int Value, pointer Base, register unsigned long Offset); +writeSparse16(int Value, pointer Base, register unsigned long Offset); static void - writeSparse32(int Value, pointer Base, register unsigned long Offset); +writeSparse32(int Value, pointer Base, register unsigned long Offset); #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) extern int sysarch(int, void *); @@ -476,14 +474,13 @@ sethae(u_int64_t hae) if (p.hae != hae) { p.hae = hae; - sysarch(ALPHA_SETHAE, (char *) &p); + sysarch(ALPHA_SETHAE, (char *)&p); } } #endif static pointer -mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, - int flags) +mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { static Bool was_here = FALSE; @@ -502,19 +499,21 @@ mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, xf86ReadMmio16 = readSparse16; xf86ReadMmio32 = readSparse32; - memBase = mmap((caddr_t) 0, 0x100000000, + memBase = mmap((caddr_t)0, 0x100000000, PROT_READ | PROT_WRITE, - MAP_SHARED, devMemFd, (off_t) BUS_BASE); - memSBase = mmap((caddr_t) 0, 0x100000000, + MAP_SHARED, devMemFd, + (off_t) BUS_BASE); + memSBase = mmap((caddr_t)0, 0x100000000, PROT_READ | PROT_WRITE, - MAP_SHARED, devMemFd, (off_t) BUS_BASE_BWX); + MAP_SHARED, devMemFd, + (off_t) BUS_BASE_BWX); - if (memSBase == MAP_FAILED || memBase == MAP_FAILED) { + if (memSBase == MAP_FAILED || memBase == MAP_FAILED) { FatalError("xf86MapVidMem: Could not mmap framebuffer (%s)\n", strerror(errno)); } } - return (pointer) ((unsigned long) memBase + Base); + return (pointer)((unsigned long)memBase + Base); } static void @@ -527,9 +526,8 @@ readSparse8(pointer Base, register unsigned long Offset) { register unsigned long result, shift; register unsigned long msb; - mem_barrier(); - Offset += (unsigned long) Base - (unsigned long) memBase; + Offset += (unsigned long)Base - (unsigned long)memBase; shift = (Offset & 0x3) << 3; if (Offset >= (hae_thresh)) { msb = Offset & hae_mask; @@ -538,7 +536,7 @@ readSparse8(pointer Base, register unsigned long Offset) sethae(msb); #endif } - result = *(vuip) ((unsigned long) memSBase + (Offset << 5)); + result = *(vuip) ((unsigned long)memSBase + (Offset << 5)); result >>= shift; return 0xffUL & result; } @@ -550,7 +548,7 @@ readSparse16(pointer Base, register unsigned long Offset) register unsigned long msb; mem_barrier(); - Offset += (unsigned long) Base - (unsigned long) memBase; + Offset += (unsigned long)Base - (unsigned long)memBase; shift = (Offset & 0x2) << 3; if (Offset >= (hae_thresh)) { msb = Offset & hae_mask; @@ -559,8 +557,7 @@ readSparse16(pointer Base, register unsigned long Offset) sethae(msb); #endif } - result = - *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2))); + result = *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2))); result >>= shift; return 0xffffUL & result; } @@ -569,7 +566,7 @@ static int readSparse32(pointer Base, register unsigned long Offset) { mem_barrier(); - return *(vuip) ((unsigned long) Base + (Offset)); + return *(vuip)((unsigned long)Base+(Offset)); } static void @@ -579,7 +576,7 @@ writeSparse8(int Value, pointer Base, register unsigned long Offset) register unsigned int b = Value & 0xffU; write_mem_barrier(); - Offset += (unsigned long) Base - (unsigned long) memBase; + Offset += (unsigned long)Base - (unsigned long)memBase; if (Offset >= (hae_thresh)) { msb = Offset & hae_mask; Offset -= msb; @@ -587,7 +584,7 @@ writeSparse8(int Value, pointer Base, register unsigned long Offset) sethae(msb); #endif } - *(vuip) ((unsigned long) memSBase + (Offset << 5)) = b * 0x01010101; + *(vuip) ((unsigned long)memSBase + (Offset << 5)) = b * 0x01010101; } static void @@ -597,7 +594,7 @@ writeSparse16(int Value, pointer Base, register unsigned long Offset) register unsigned int w = Value & 0xffffU; write_mem_barrier(); - Offset += (unsigned long) Base - (unsigned long) memBase; + Offset += (unsigned long)Base - (unsigned long)memBase; if (Offset >= (hae_thresh)) { msb = Offset & hae_mask; Offset -= msb; @@ -605,7 +602,7 @@ writeSparse16(int Value, pointer Base, register unsigned long Offset) sethae(msb); #endif } - *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2))) = + *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2))) = w * 0x00010001; } @@ -614,7 +611,7 @@ static void writeSparse32(int Value, pointer Base, register unsigned long Offset) { write_mem_barrier(); - *(vuip) ((unsigned long) Base + (Offset)) = Value; + *(vuip)((unsigned long)Base + (Offset)) = Value; return; } @@ -624,7 +621,7 @@ writeSparseNB8(int Value, pointer Base, register unsigned long Offset) register unsigned long msb; register unsigned int b = Value & 0xffU; - Offset += (unsigned long) Base - (unsigned long) memBase; + Offset += (unsigned long)Base - (unsigned long)memBase; if (Offset >= (hae_thresh)) { msb = Offset & hae_mask; Offset -= msb; @@ -632,7 +629,7 @@ writeSparseNB8(int Value, pointer Base, register unsigned long Offset) sethae(msb); #endif } - *(vuip) ((unsigned long) memSBase + (Offset << 5)) = b * 0x01010101; + *(vuip) ((unsigned long)memSBase + (Offset << 5)) = b * 0x01010101; } static void @@ -641,40 +638,53 @@ writeSparseNB16(int Value, pointer Base, register unsigned long Offset) register unsigned long msb; register unsigned int w = Value & 0xffffU; - Offset += (unsigned long) Base - (unsigned long) memBase; + Offset += (unsigned long)Base - (unsigned long)memBase; if (Offset >= (hae_thresh)) { - msb = Offset & hae_mask; + msb = Offset & hae_mask ; Offset -= msb; #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) sethae(msb); #endif } - *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2))) = + *(vuip)((unsigned long)memSBase+(Offset<<5)+(1<<(5-2))) = w * 0x00010001; } static void writeSparseNB32(int Value, pointer Base, register unsigned long Offset) { - *(vuip) ((unsigned long) Base + (Offset)) = Value; + *(vuip)((unsigned long)Base + (Offset)) = Value; return; } -void (*xf86WriteMmio8) (int Value, pointer Base, unsigned long Offset) - = writeDense8; -void (*xf86WriteMmio16) (int Value, pointer Base, unsigned long Offset) - = writeDense16; -void (*xf86WriteMmio32) (int Value, pointer Base, unsigned long Offset) - = writeDense32; -void (*xf86WriteMmioNB8) (int Value, pointer Base, unsigned long Offset) - = writeDenseNB8; -void (*xf86WriteMmioNB16) (int Value, pointer Base, unsigned long Offset) - = writeDenseNB16; -void (*xf86WriteMmioNB32) (int Value, pointer Base, unsigned long Offset) - = writeDenseNB32; -int (*xf86ReadMmio8) (pointer Base, unsigned long Offset) - = readDense8; -int (*xf86ReadMmio16) (pointer Base, unsigned long Offset) - = readDense16; -int (*xf86ReadMmio32) (pointer Base, unsigned long Offset) - = readDense32; +_X_EXPORT void (*xf86WriteMmio8)(int Value, pointer Base, unsigned long Offset) + = writeDense8; +_X_EXPORT void (*xf86WriteMmio16)(int Value, pointer Base, unsigned long Offset) + = writeDense16; +_X_EXPORT void (*xf86WriteMmio32)(int Value, pointer Base, unsigned long Offset) + = writeDense32; +_X_EXPORT void (*xf86WriteMmioNB8)(int Value, pointer Base, unsigned long Offset) + = writeDenseNB8; +_X_EXPORT void (*xf86WriteMmioNB16)(int Value, pointer Base, unsigned long Offset) + = writeDenseNB16; +_X_EXPORT void (*xf86WriteMmioNB32)(int Value, pointer Base, unsigned long Offset) + = writeDenseNB32; +_X_EXPORT int (*xf86ReadMmio8)(pointer Base, unsigned long Offset) + = readDense8; +_X_EXPORT int (*xf86ReadMmio16)(pointer Base, unsigned long Offset) + = readDense16; +_X_EXPORT int (*xf86ReadMmio32)(pointer Base, unsigned long Offset) + = readDense32; + +/* + * Do all things that need root privileges early + * and revoke those priviledges + */ +_X_EXPORT void +xf86PrivilegedInit(void) +{ + xf86EnableIO(); + checkDevMem(TRUE); + pci_system_init(); + xf86OpenConsole(); +} diff --git a/hw/xfree86/os-support/bsd/arm_video.c b/hw/xfree86/os-support/bsd/arm_video.c index 71064af03..f640511ce 100644 --- a/hw/xfree86/os-support/bsd/arm_video.c +++ b/hw/xfree86/os-support/bsd/arm_video.c @@ -1,3 +1,5 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/ppc_video.c,v 1.6 2003/10/07 23:14:55 herrb Exp $ */ +/* $OpenBSD: arm_video.c,v 1.5 2009/09/06 19:44:26 matthieu Exp $ */ /* * Copyright 1992 by Rich Murphey <Rich@Rice.edu> * Copyright 1993 by David Wexelblat <dwex@goblin.org> @@ -6,19 +8,19 @@ * 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 Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of + * documentation, and that the names of Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or * implied warranty. * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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. * */ @@ -28,7 +30,7 @@ * * Copyright 1997 * Digital Equipment Corporation. All rights reserved. - * This software is furnished under license and may be used and copied only in + * This software is furnished under license and may be used and copied only in * accordance with the following terms and conditions. Subject to these * conditions, you may download, copy, install, use, modify and distribute * this software in source and/or binary form. No title or ownership is @@ -38,7 +40,7 @@ * this copyright notice and list of conditions as they appear in the * source file. * - * 2) No right is granted to use any trade name, trademark, or logo of Digital + * 2) No right is granted to use any trade name, trademark, or logo of Digital * Equipment Corporation. Neither the "Digital Equipment Corporation" * name nor any trademark or logo of Digital Equipment Corporation may be * used to endorse or promote products derived from this software without @@ -50,9 +52,9 @@ * In no event shall DIGITAL be liable for any damages whatsoever, and in * particular, DIGITAL shall not be liable for special, indirect, * consequential, or incidental damages or damages for lost profits, loss - * of revenue or loss of use, whether such damages arise in contract, + * of revenue or loss of use, whether such damages arise in contract, * negligence, tort, under statute, in equity, at law or otherwise, even - * if advised of the possibility of such damage. + * if advised of the possibility of such damage. * */ @@ -63,566 +65,188 @@ #include <X11/X.h> #include "xf86.h" #include "xf86Priv.h" + #include "xf86_OSlib.h" #include "xf86OSpriv.h" -#ifdef __arm32__ -#include "machine/devmap.h" -struct memAccess { - int ioctl; - struct map_info memInfo; - pointer regionVirtBase; - Bool Checked; - Bool OK; -}; - -static pointer xf86MapInfoMap(); -static void xf86MapInfoUnmap(); -static struct memAccess *checkMapInfo(); -extern int vgaPhysLinearBase; - -/* A memAccess structure is needed for each possible region */ -struct memAccess vgaMemInfo = { CONSOLE_GET_MEM_INFO, NULL, NULL, - FALSE, FALSE -}; +#include "bus/Pci.h" -struct memAccess linearMemInfo = { CONSOLE_GET_LINEAR_INFO, NULL, NULL, - FALSE, FALSE -}; - -struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL, - FALSE, FALSE -}; -#endif /* __arm32__ */ - -#if defined(__NetBSD__) && !defined(MAP_FILE) -#define MAP_FLAGS MAP_SHARED -#else -#define MAP_FLAGS (MAP_FILE | MAP_SHARED) +#ifndef MAP_FAILED +#define MAP_FAILED ((caddr_t)-1) #endif -#define BUS_BASE 0L -#define BUS_BASE_BWX 0L +#include <sys/param.h> +#include <sys/sysctl.h> /***************************************************************************/ /* Video Memory Mapping section */ /***************************************************************************/ -static Bool useDevMem = FALSE; -static int devMemFd = -1; - -static pointer mapVidMem(int, unsigned long, unsigned long, int); -static void unmapVidMem(int, pointer, unsigned long); - -/* - * Check if /dev/mem can be mmap'd. If it can't print a warning when - * "warn" is TRUE. - */ -static void -checkDevMem(Bool warn) -{ - static Bool devMemChecked = FALSE; - int fd; - pointer base; - - if (devMemChecked) - return; - devMemChecked = TRUE; - - if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); +#ifdef __OpenBSD__ +#undef DEV_MEM +#define DEV_MEM "/dev/xf86" +#endif - if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); - devMemFd = fd; - useDevMem = TRUE; - return; - } - else { - /* This should not happen */ - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; - } - } - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; -} +static pointer ppcMapVidMem(int, unsigned long, unsigned long, int flags); +static void ppcUnmapVidMem(int, pointer, unsigned long); void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { - - checkDevMem(TRUE); - pVidMem->linearSupported = useDevMem; - pVidMem->mapMem = armMapVidMem; - pVidMem->unmapVidMem = armUnmapVidMem; - + pVidMem->linearSupported = TRUE; + pVidMem->mapMem = ppcMapVidMem; + pVidMem->unmapMem = ppcUnmapVidMem; pVidMem->initialised = TRUE; } + +volatile unsigned char *ioBase = MAP_FAILED; + static pointer -mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { + int fd = xf86Info.consoleFd; pointer base; +#ifdef DEBUG + xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", + Base, Size, fd); +#endif - checkDevMem(FALSE); - - if (useDevMem) { - if (devMemFd < 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_FLAGS, devMemFd, (off_t) Base + BUS_BASE_BWX); - if (base == MAP_FAILED) { - FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n", - "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno)); - } - return base; - } - - /* else, mmap /dev/vga */ - if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) { - FatalError("%s: Address 0x%x outside allowable range\n", - "xf86MapVidMem", Base); - } base = mmap(0, Size, (flags & VIDMEM_READONLY) ? PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base - 0xA0000); - if (base == MAP_FAILED) { - FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n", - strerror(errno)); - } + MAP_SHARED, fd, Base); + if (base == MAP_FAILED) + FatalError("%s: could not mmap screen [s=%lx,a=%lx] (%s)", + "xf86MapVidMem", Size, Base, strerror(errno)); + return base; } static void -unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) +ppcUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - munmap((caddr_t) Base, Size); + munmap(Base, Size); } -/* - * Read BIOS via mmap()ing DEV_MEM - */ +static int kmem = -1; int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, int Len) { - unsigned char *ptr; - int psize; - int mlen; - - checkDevMem(TRUE); - if (devMemFd == -1) { - return -1; - } - - psize = getpagesize(); - Offset += Base & (psize - 1); - Base &= ~(psize - 1); - mlen = (Offset + Len + psize - 1) & ~(psize - 1); - ptr = (unsigned char *) mmap((caddr_t) 0, mlen, PROT_READ, - MAP_SHARED, devMemFd, (off_t) Base + BUS_BASE); - if ((long) ptr == -1) { - xf86Msg(X_WARNING, - "xf86ReadBIOS: %s mmap[s=%x,a=%x,o=%x] failed (%s)\n", - DEV_MEM, Len, Base, Offset, strerror(errno)); - return -1; - } -#ifdef DEBUG - ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", - Base, ptr[0] | (ptr[1] << 8)); -#endif - (void) memcpy(Buf, (void *) (ptr + Offset), Len); - (void) munmap((caddr_t) ptr, mlen); -#ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" - "-> %02x %02x %02x %02x...\n", - Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]); -#endif - return Len; -} - -/* XXX This needs to be updated for the ND */ - -/* -** Find out whether the console driver provides memory mapping information -** for the specified region and return the map_info pointer. Print a warning if required. -*/ -static struct memAccess * -checkMapInfo(Bool warn, int Region) -{ - struct memAccess *memAccP; - - switch (Region) { - case VGA_REGION: - memAccP = &vgaMemInfo; - break; - - case LINEAR_REGION: - memAccP = &linearMemInfo; - break; - - case MMIO_REGION: - memAccP = &ioMemInfo; - break; + int rv; - default: - return NULL; - break; + if (Base < 0x80000000) { + xf86Msg(X_WARNING, "No VGA Base=%#lx\n", Base); + return 0; } - if (!memAccP->Checked) { - if (ioctl(xf86Info.consoleFd, memAccP->ioctl, &(memAccP->memInfo)) == - -1) { - if (warn) { - xf86Msg(X_WARNING, - "checkMapInfo: failed to get map info for region %d\n\t(%s)\n", - Region, strerror(errno)); - } + if (kmem == -1) { + kmem = open(DEV_MEM, 2); + if (kmem == -1) { + FatalError("xf86ReadBIOS: open %s", DEV_MEM); } - else { - if (memAccP->memInfo.u.map_info_mmap.map_offset != MAP_INFO_UNKNOWN) - memAccP->OK = TRUE; - } - memAccP->Checked = TRUE; - } - if (memAccP->OK) { - return memAccP; - } - else { - return NULL; - } -} - -static pointer -xf86MapInfoMap(struct memAccess *memInfoP, pointer Base, unsigned long Size) -{ - struct map_info *mapInfoP = &(memInfoP->memInfo); - - if (mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) { - Size = (unsigned long) Base + Size; - } - else { - Size = mapInfoP->u.map_info_mmap.map_size; - } - - switch (mapInfoP->method) { - case MAP_MMAP: - /* Need to remap if size is unknown because we may not have - mapped the whole region initially */ - if (memInfoP->regionVirtBase == NULL || - mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) { - if ((memInfoP->regionVirtBase = - mmap((caddr_t) 0, - Size, - PROT_READ | PROT_WRITE, - MAP_SHARED, - xf86Info.consoleFd, - (unsigned long) mapInfoP->u.map_info_mmap.map_offset)) - == (pointer) -1) { - FatalError - ("xf86MapInfoMap: Failed to map memory at 0x%x\n\t%s\n", - mapInfoP->u.map_info_mmap.map_offset, strerror(errno)); - } - if (mapInfoP->u.map_info_mmap.internal_offset > 0) - memInfoP->regionVirtBase += - mapInfoP->u.map_info_mmap.internal_offset; - } - break; - - default: - FatalError("xf86MapInfoMap: Unsuported mapping method\n"); - break; - } - - return (pointer) ((int) memInfoP->regionVirtBase + (int) Base); -} - -static void -xf86MapInfoUnmap(struct memAccess *memInfoP, unsigned long Size) -{ - struct map_info *mapInfoP = &(memInfoP->memInfo); - - switch (mapInfoP->method) { - case MAP_MMAP: - if (memInfoP->regionVirtBase != NULL) { - if (mapInfoP->u.map_info_mmap.map_size != MAP_INFO_UNKNOWN) - Size = mapInfoP->u.map_info_mmap.map_size; - munmap((caddr_t) memInfoP->regionVirtBase, Size); - memInfoP->regionVirtBase = NULL; - } - break; - default: - FatalError("xf86MapInfoMap: Unsuported mapping method\n"); - break; - } -} - -static pointer -armMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) -{ - struct memAccess *memInfoP; - - if ((memInfoP = checkMapInfo(FALSE, Region)) != NULL) { - /* - ** xf86 passes in a physical address offset from the start - ** of physical memory, but xf86MapInfoMap expects an - ** offset from the start of the specified region - it gets - ** the physical address of the region from the display driver. - */ - switch (Region) { - case LINEAR_REGION: - if (vgaPhysLinearBase) { - Base -= vgaPhysLinearBase; - } - break; - case VGA_REGION: - Base -= 0xA0000; - break; - } - - base = xf86MapInfoMap(memInfoP, Base, Size); - return base; } - return mapVidMem(ScreenNum, Base, Size, flags); -} - -static void -armUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) -{ - struct memAccess *memInfoP; - - if ((memInfoP = checkMapInfo(FALSE, Region)) != NULL) { - xf86MapInfoUnmap(memInfoP, Base, Size); - } - unmapVidMem(ScreenNum, Base, Size); -} - -#ifdef USE_DEV_IO -static int IoFd = -1; - -Bool -xf86EnableIO() -{ - if (IoFd >= 0) - return TRUE; - - if ((IoFd = open("/dev/io", O_RDWR)) == -1) { - xf86Msg(X_WARNING, "xf86EnableIO: " - "Failed to open /dev/io for extended I/O\n"); - return FALSE; - } - return TRUE; -} - -void -xf86DisableIO() -{ - if (IoFd < 0) - return; - - close(IoFd); - IoFd = -1; - return; -} +#ifdef DEBUG + xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n", + Base, Offset, Len); #endif -#if defined(USE_ARC_MMAP) || defined(__arm32__) - -Bool -xf86EnableIO() -{ - int fd; - pointer base; - - if (ExtendedEnabled) - return TRUE; - - if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { - /* Try to map a page at the pccons I/O space */ - base = (pointer) mmap((caddr_t) 0, 65536, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0x0000); - - if (base != (pointer) -1) { - IOPortBase = base; - } - else { - xf86Msg(X_WARNING, "EnableIO: failed to mmap %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - return FALSE; - } - } - else { - xf86Msg("EnableIO: failed to open %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - return FALSE; - } - - ExtendedEnabled = TRUE; - - return TRUE; + lseek(kmem, Base + Offset, 0); + rv = read(kmem, Buf, Len); + return rv; } -void -xf86DisableIO() -{ - return; -} - -#endif /* USE_ARC_MMAP */ - -#if 0 /* - * XXX This is here for reference. It needs to be handled differently for the - * ND. + * Do all initialisation that need root privileges */ -#if defined(USE_ARC_MMAP) || defined(__arm32__) - -#ifdef USE_ARM32_MMAP -#define DEV_MEM_IOBASE 0x43000000 -#endif - -static Bool ScreenEnabled[MAXSCREENS]; -static Bool ExtendedEnabled = FALSE; -static Bool InitDone = FALSE; - -Bool -xf86EnableIOPorts(ScreenNum) -int ScreenNum; -{ - int i; - int fd; - pointer base; - -#ifdef __arm32__ - struct memAccess *memInfoP; - int *Size; -#endif - - ScreenEnabled[ScreenNum] = TRUE; - - if (ExtendedEnabled) - return TRUE; - -#ifdef USE_ARC_MMAP - if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { - /* Try to map a page at the pccons I/O space */ - base = (pointer) mmap((caddr_t) 0, 65536, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0x0000); - - if (base != (pointer) -1) { - IOPortBase = base; - } - else { - xf86Msg(X_ERROR, - "EnableIOPorts: failed to mmap %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - } - } - else { - xf86Msg(X_ERROR, "EnableIOPorts: failed to open %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - } -#endif - -#ifdef __arm32__ - IOPortBase = (unsigned int) -1; - - if ((memInfoP = checkMapInfo(TRUE, MMIO_REGION)) != NULL) { - /* - * xf86MapInfoMap maps an offset from the start of video IO - * space (e.g. 0x3B0), but IOPortBase is expected to map to - * physical address 0x000, so subtract the start of video I/O - * space from the result. This is safe for now becase we - * actually mmap the start of the page, then the start of video - * I/O space is added as an internal offset. - */ - IOPortBase = (unsigned int) xf86MapInfoMap(memInfoP, (caddr_t) 0x0, 0L) - - memInfoP->memInfo.u.map_info_mmap.internal_offset; - ExtendedEnabled = TRUE; - return TRUE; - } -#ifdef USE_ARM32_MMAP - checkDevMem(TRUE); - - if (devMemFd >= 0 && useDevMem) { - base = (pointer) mmap((caddr_t) 0, 0x400, PROT_READ | PROT_WRITE, - MAP_FLAGS, devMemFd, (off_t) DEV_MEM_IOBASE); - - if (base != (pointer) -1) - IOPortBase = (unsigned int) base; - } - - if (IOPortBase == (unsigned int) -1) { - xf86Msg(X_WARNING, - "xf86EnableIOPorts: failed to open mem device or map IO base. \n\ -Make sure you have the Aperture Driver installed, or a kernel built with the INSECURE option\n"); - return FALSE; - } -#else - /* We don't have the IOBASE, so we can't map the address */ - xf86Msg(X_WARNING, - "xf86EnableIOPorts: failed to open mem device or map IO base. \n\ -Try building the server with USE_ARM32_MMAP defined\n"); - return FALSE; -#endif -#endif - - ExtendedEnabled = TRUE; - - return TRUE; -} - void -xf86DisableIOPorts(ScreenNum) -int ScreenNum; -{ - int i; - -#ifdef __arm32__ - struct memAccess *memInfoP; -#endif - - ScreenEnabled[ScreenNum] = FALSE; - -#ifdef __arm32__ - if ((memInfoP = checkMapInfo(FALSE, MMIO_REGION)) != NULL) { - xf86MapInfoUnmap(memInfoP, 0); +xf86PrivilegedInit(void) +{ + int mib[2]; + char buf[128]; + size_t len; + + mib[0] = CTL_HW; + mib[1] = HW_MACHINE; + len = sizeof(buf); + if (sysctl(mib, 2, buf, &len, NULL, 0) < 0) { + FatalError("Cannot get hw.machine"); + } + if (strcmp(buf, "zaurus") != 0 && + strcmp(buf, "armish") != 0) { + /* Not Zaurus */ + kmem = open(DEV_MEM, 2); + if (kmem == -1) { + ErrorF("errno: %d\n", errno); + FatalError("xf86PrivilegedInit: open %s", DEV_MEM); + } + pci_system_init(); } -#endif - -#ifdef USE_ARM32_MMAP - if (!ExtendedEnabled) - return; - - for (i = 0; i < MAXSCREENS; i++) - if (ScreenEnabled[i]) - return; - - munmap((caddr_t) IOPortBase, 0x400); - IOPortBase = (unsigned int) -1; - ExtendedEnabled = FALSE; -#endif - - return; + xf86OpenConsole(); } -#endif /* USE_ARC_MMAP || USE_ARM32_MMAP */ -#endif +#ifdef __VFP_FP__ +/* + * force softfloat functions into binary, + * yes the protos/ret are all bogus. + */ +arm_softfloat() +{ + void __adddf3(); + void __addsf3(); + void __eqdf2(); + void __eqsf2(); + void __extendsfdf2(); + void __fixdfsi(); + void __fixsfsi(); + void __fixunsdfsi(); + void __fixunssfsi(); + void __floatsidf(); + void __floatsisf(); + void __gedf2(); + void __gesf2(); + void __gtdf2(); + void __gtsf2(); + void __ledf2(); + void __lesf2(); + void __ltdf2(); + void __ltsf2(); + void __nedf2(); + void __negdf2(); + void __negsf2(); + void __nesf2(); + void __subdf3(); + void __subsf3(); + void __truncdfsf2(); + + __adddf3(); + __addsf3(); + __eqdf2(); + __eqsf2(); + __extendsfdf2(); + __fixdfsi(); + __fixsfsi(); + __fixunsdfsi(); + __fixunssfsi(); + __floatsidf(); + __floatsisf(); + __gedf2(); + __gesf2(); + __gtdf2(); + __gtsf2(); + __ledf2(); + __lesf2(); + __ltdf2(); + __ltsf2(); + __nedf2(); + __negdf2(); + __negsf2(); + __nesf2(); + __subdf3(); + __subsf3(); + __truncdfsf2(); +} +#endif /* __VFP_FP__ */ diff --git a/hw/xfree86/os-support/bsd/bsd_agp.c b/hw/xfree86/os-support/bsd/bsd_agp.c new file mode 100644 index 000000000..745124e2b --- /dev/null +++ b/hw/xfree86/os-support/bsd/bsd_agp.c @@ -0,0 +1,340 @@ +/* $OpenBSD: bsd_agp.c,v 1.4 2011/01/28 19:34:22 matthieu Exp $ */ +/* + * Abstraction of the AGP GART interface. + * + * This version is for OpenBSD + * + * Copyright © 2000 VA Linux Systems, Inc. + * Copyright © 2001 The XFree86 Project, Inc. + */ + +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c,v 3.11 2003/04/03 22:47:42 dawes Exp $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <X11/X.h> +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +#include <sys/ioctl.h> +#include <sys/agpio.h> + +/* AGP page size is independent of the host page size. */ +#ifndef AGP_PAGE_SIZE +#define AGP_PAGE_SIZE 4096 +#endif + +static int gartFd = -1; +static int acquiredScreen = -1; +static Bool initDone = FALSE; + +/* + * Close the AGP device. This frees all associated memory allocated during + * this server generation. + */ +Bool +xf86GARTCloseScreen(int screenNum) +{ + if(gartFd != -1) { + if (gartFd != xf86Info.consoleFd) + close(gartFd); + acquiredScreen = -1; + gartFd = -1; + initDone = FALSE; + } + return TRUE; +} + +/* + * Open the AGP device. Keep it open until xf86GARTCloseScreen is called. + */ +static Bool +GARTInit(int screenNum) +{ + struct _agp_info agpinf; + + if (initDone) + return (gartFd != -1); + + initDone = TRUE; + + if (gartFd != -1) + return FALSE; + +#ifndef X_PRIVSEP + gartFd = open(AGP_DEVICE, O_RDWR); +#else + gartFd = priv_open_device(AGP_DEVICE); +#endif + if (gartFd == -1 && errno == ENOENT) { + /* try the old interface */ + gartFd = xf86Info.consoleFd; + } + if (gartFd == -1) + return FALSE; + xf86AcquireGART(-1); + /* Check the kernel driver version. */ + if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { + xf86DrvMsg(screenNum, X_WARNING, + "GARTInit: AGPIOC_INFO failed (%s)\n", strerror(errno)); + gartFd = -1; + return FALSE; + } + xf86ReleaseGART(-1); + + return TRUE; +} + +Bool +xf86AgpGARTSupported() +{ + return GARTInit(-1); +} + +AgpInfoPtr +xf86GetAGPInfo(int screenNum) +{ + struct _agp_info agpinf; + AgpInfoPtr info; + + if (!GARTInit(screenNum)) + return NULL; + + + if ((info = xcalloc(sizeof(AgpInfo), 1)) == NULL) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86GetAGPInfo: Failed to allocate AgpInfo\n"); + return NULL; + } + + memset((char*)&agpinf, 0, sizeof(agpinf)); + + if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n", + strerror(errno)); + return NULL; + } + + info->bridgeId = agpinf.bridge_id; + info->agpMode = agpinf.agp_mode; + info->base = agpinf.aper_base; + info->size = agpinf.aper_size; + info->totalPages = agpinf.pg_total; + info->systemPages = agpinf.pg_system; + info->usedPages = agpinf.pg_used; + + xf86DrvMsg(screenNum, X_INFO, "Kernel reported %lu total, %lu used\n", + (unsigned long)agpinf.pg_total, (unsigned long)agpinf.pg_used); + + return info; +} + +/* + * XXX If multiple screens can acquire the GART, should we have a reference + * count instead of using acquiredScreen? + */ + +Bool +xf86AcquireGART(int screenNum) +{ + if (screenNum != -1 && !GARTInit(screenNum)) + return FALSE; + + if (screenNum == -1 || acquiredScreen != screenNum) { + if (ioctl(gartFd, AGPIOC_ACQUIRE, 0) != 0) { + xf86DrvMsg(screenNum, X_WARNING, + "xf86AcquireGART: AGPIOC_ACQUIRE failed (%s)\n", + strerror(errno)); + return FALSE; + } + acquiredScreen = screenNum; + } + return TRUE; +} + +Bool +xf86ReleaseGART(int screenNum) +{ + if (screenNum != -1 && !GARTInit(screenNum)) + return FALSE; + + if (acquiredScreen == screenNum) { + /* + * The FreeBSD agp driver removes allocations on release. + * The Linux driver doesn't. xf86ReleaseGART() is expected + * to give up access to the GART, but not to remove any + * allocations. + */ + if (screenNum == -1) { + if (ioctl(gartFd, AGPIOC_RELEASE, 0) != 0) { + xf86DrvMsg(screenNum, X_WARNING, + "xf86ReleaseGART: AGPIOC_RELEASE failed (%s)\n", + strerror(errno)); + return FALSE; + } + acquiredScreen = -1; + } + return TRUE; + } + return FALSE; +} + +int +xf86AllocateGARTMemory(int screenNum, unsigned long size, int type, + unsigned long *physical) +{ + struct _agp_allocate alloc; + int pages; + + /* + * Allocates "size" bytes of GART memory (rounds up to the next + * page multiple) or type "type". A handle (key) for the allocated + * memory is returned. On error, the return value is -1. + */ + + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return -1; + + pages = (size / AGP_PAGE_SIZE); + if (size % AGP_PAGE_SIZE != 0) + pages++; + + /* XXX check for pages == 0? */ + + alloc.pg_count = pages; + alloc.type = type; + + if (ioctl(gartFd, AGPIOC_ALLOCATE, &alloc) != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86AllocateGARTMemory: " + "allocation of %d pages failed\n\t(%s)\n", pages, + strerror(errno)); + return -1; + } + + if (physical) + *physical = alloc.physical; + + return alloc.key; +} + +Bool +xf86DeallocateGARTMemory(int screenNum, int key) +{ + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return FALSE; + + if (acquiredScreen != screenNum) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86UnbindGARTMemory: AGP not acquired by this screen\n"); + return FALSE; + } + + if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *)(intptr_t)key) != 0) { + xf86DrvMsg(screenNum, X_WARNING,"xf86DeAllocateGARTMemory: " + "deallocation gart memory with key %d failed\n\t(%s)\n", + key, strerror(errno)); + return FALSE; + } + + return TRUE; +} + +/* Bind GART memory with "key" at "offset" */ +Bool +xf86BindGARTMemory(int screenNum, int key, unsigned long offset) +{ + struct _agp_bind bind; + int pageOffset; + + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return FALSE; + + if (acquiredScreen != screenNum) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86BindGARTMemory: AGP not acquired by this screen\n"); + return FALSE; + } + + if (offset % AGP_PAGE_SIZE != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: " + "offset (0x%lx) is not page-aligned (%d)\n", + offset, AGP_PAGE_SIZE); + return FALSE; + } + pageOffset = offset / AGP_PAGE_SIZE; + + xf86DrvMsgVerb(screenNum, X_INFO, 3, + "xf86BindGARTMemory: bind key %d at 0x%08lx " + "(pgoffset %d)\n", key, offset, pageOffset); + + bind.pg_start = pageOffset; + bind.key = key; + + if (ioctl(gartFd, AGPIOC_BIND, &bind) != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: " + "binding of gart memory with key %d\n" + "\tat offset 0x%lx failed (%s)\n", + key, offset, strerror(errno)); + return FALSE; + } + + return TRUE; +} + + +/* Unbind GART memory with "key" */ +Bool +xf86UnbindGARTMemory(int screenNum, int key) +{ + struct _agp_unbind unbind; + + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return FALSE; + + if (acquiredScreen != screenNum) { + xf86DrvMsg(screenNum, X_ERROR, + "xf86UnbindGARTMemory: AGP not acquired by this screen\n"); + return FALSE; + } + + unbind.priority = 0; + unbind.key = key; + + if (ioctl(gartFd, AGPIOC_UNBIND, &unbind) != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86UnbindGARTMemory: " + "unbinding of gart memory with key %d " + "failed (%s)\n", key, strerror(errno)); + return FALSE; + } + + xf86DrvMsgVerb(screenNum, X_INFO, 3, + "xf86UnbindGARTMemory: unbind key %d\n", key); + + return TRUE; +} + + +/* XXX Interface may change. */ +Bool +xf86EnableAGP(int screenNum, CARD32 mode) +{ + agp_setup setup; + + if (!GARTInit(screenNum) || acquiredScreen != screenNum) + return FALSE; + + setup.agp_mode = mode; + if (ioctl(gartFd, AGPIOC_SETUP, &setup) != 0) { + xf86DrvMsg(screenNum, X_WARNING, "xf86EnableAGP: " + "AGPIOC_SETUP with mode %ld failed (%s)\n", + (unsigned long)mode, strerror(errno)); + return FALSE; + } + + return TRUE; +} diff --git a/hw/xfree86/os-support/bsd/bsd_init.c b/hw/xfree86/os-support/bsd/bsd_init.c index c9f823321..b78912191 100644 --- a/hw/xfree86/os-support/bsd/bsd_init.c +++ b/hw/xfree86/os-support/bsd/bsd_init.c @@ -6,19 +6,19 @@ * 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 Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of + * documentation, and that the names of Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or * implied warranty. * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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. * */ @@ -37,14 +37,17 @@ #include <sys/utsname.h> #include <sys/ioctl.h> +#include <sys/sysctl.h> +#ifdef X_PRIVSEP +#include "os.h" +#include <pwd.h> +#endif #include <stdlib.h> #include <errno.h> static Bool KeepTty = FALSE; -#ifdef PCCONS_SUPPORT static int devConsoleFd = -1; -#endif #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) static int VTnum = -1; static int initialVT = -1; @@ -101,6 +104,7 @@ static char *supported_drivers[] = { #endif }; + /* * Functions to probe for the existance of a supported console driver. * Any function returns either a valid file descriptor (driver probed @@ -109,19 +113,19 @@ static char *supported_drivers[] = { * an X server. */ -typedef int (*xf86ConsOpen_t) (void); +typedef int (*xf86ConsOpen_t)(void); #ifdef PCCONS_SUPPORT static int xf86OpenPccons(void); -#endif /* PCCONS_SUPPORT */ +#endif /* PCCONS_SUPPORT */ #ifdef SYSCONS_SUPPORT static int xf86OpenSyscons(void); -#endif /* SYSCONS_SUPPORT */ +#endif /* SYSCONS_SUPPORT */ #ifdef PCVT_SUPPORT static int xf86OpenPcvt(void); -#endif /* PCVT_SUPPORT */ +#endif /* PCVT_SUPPORT */ #ifdef WSCONS_SUPPORT static int xf86OpenWScons(void); @@ -146,52 +150,55 @@ static xf86ConsOpen_t xf86ConsTab[] = { #ifdef WSCONS_SUPPORT xf86OpenWScons, #endif - (xf86ConsOpen_t) NULL + (xf86ConsOpen_t)NULL }; + void xf86OpenConsole() { int i, fd = -1; xf86ConsOpen_t *driver; - #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) int result; - #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) struct utsname uts; #endif vtmode_t vtmode; #endif + if (xf86Info.consoleFd != -1) { + return; + } if (serverGeneration == 1) { /* check if we are run with euid==0 */ - if (geteuid() != 0) { - FatalError("xf86OpenConsole: Server must be suid root"); + if (geteuid() != 0 && issetugid()) { + FatalError("xf86OpenConsole: Server must either be suid root" + " or without privileges at all"); } if (!KeepTty) { /* * detaching the controlling tty solves problems of kbd character - * loss. This is not interesting for CO driver, because it is + * loss. This is not interesting for CO driver, because it is * exclusive. */ setpgrp(0, getpid()); - if ((i = open("/dev/tty", O_RDWR)) >= 0) { - ioctl(i, TIOCNOTTY, (char *) 0); + if ((i = open("/dev/tty",O_RDWR)) >= 0) { + ioctl(i,TIOCNOTTY,(char *)0); close(i); } } /* detect which driver we are running on */ for (driver = xf86ConsTab; *driver; driver++) { - if ((fd = (*driver) ()) >= 0) + if ((fd = (*driver)()) >= 0) break; } /* Check that a supported console driver was found */ if (fd < 0) { - char cons_drivers[80] = { 0, }; + char cons_drivers[80] = {0, }; for (i = 0; i < sizeof(supported_drivers) / sizeof(char *); i++) { if (i) { strcat(cons_drivers, ", "); @@ -207,7 +214,7 @@ xf86OpenConsole() switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT case PCCONS: - if (ioctl(xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0) { + if (ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0) { FatalError("%s: CONSOLE_X_MODE_ON failed (%s)\n%s", "xf86OpenConsole", strerror(errno), CHECK_DRIVER_MSG); @@ -216,7 +223,7 @@ xf86OpenConsole() * Hack to prevent keyboard hanging when syslogd closes * /dev/console */ - if ((devConsoleFd = open("/dev/console", O_WRONLY, 0)) < 0) { + if ((devConsoleFd = open("/dev/console", O_WRONLY,0)) < 0) { xf86Msg(X_WARNING, "xf86OpenConsole: couldn't open /dev/console (%s)\n", strerror(errno)); @@ -228,12 +235,11 @@ xf86OpenConsole() /* as of FreeBSD 2.2.8, syscons driver does not need the #1 vt * switching anymore. Here we check for FreeBSD 3.1 and up. * Add cases for other *BSD that behave the same. - */ + */ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - uname(&uts); + uname (&uts); i = atof(uts.release) * 100; - if (i >= 310) - goto acquire_vt; + if (i >= 310) goto acquire_vt; #endif /* otherwise fall through */ case PCVT: @@ -246,12 +252,13 @@ xf86OpenConsole() if (initialVT != 1) { if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) != 0) { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); + xf86Msg(X_WARNING, + "xf86OpenConsole: VT_ACTIVATE failed\n"); } sleep(1); } #endif - acquire_vt: +acquire_vt: if (!xf86Info.ShareVTs) { /* * now get the VT @@ -262,23 +269,21 @@ xf86OpenConsole() xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); } SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_WAITACTIVE, - xf86Info.vtno)); + ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno)); if (result != 0) { - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_WAITACTIVE failed\n"); + xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n"); } - signal(SIGUSR1, xf86VTRequest); + signal(SIGUSR2, xf86VTRequest); vtmode.mode = VT_PROCESS; - vtmode.relsig = SIGUSR1; - vtmode.acqsig = SIGUSR1; - vtmode.frsig = SIGUSR1; + vtmode.relsig = SIGUSR2; + vtmode.acqsig = SIGUSR2; + vtmode.frsig = SIGUSR2; if (ioctl(xf86Info.consoleFd, VT_SETMODE, &vtmode) < 0) { FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed"); } -#if !defined(__OpenBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) +#if !defined(__0penBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0) { FatalError("xf86OpenConsole: KDENABIO failed (%s)", strerror(errno)); @@ -288,11 +293,11 @@ xf86OpenConsole() FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed"); } } - else { /* xf86Info.ShareVTs */ + else { /* xf86Info.ShareVTs */ close(xf86Info.consoleFd); } break; -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ #ifdef WSCONS_SUPPORT case WSCONS: /* Nothing to do */ @@ -309,11 +314,12 @@ xf86OpenConsole() xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); } } -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ } return; } + #ifdef PCCONS_SUPPORT static int @@ -322,14 +328,16 @@ xf86OpenPccons() int fd = -1; if ((fd = open(PCCONS_CONSOLE_DEV1, PCCONS_CONSOLE_MODE, 0)) - >= 0 || (fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0)) + >= 0 || + (fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0)) >= 0) { if (ioctl(fd, CONSOLE_X_MODE_OFF, 0) < 0) { - FatalError("%s: CONSOLE_X_MODE_OFF failed (%s)\n%s\n%s", - "xf86OpenPccons", - strerror(errno), - "Was expecting pccons driver with X support", - CHECK_DRIVER_MSG); + FatalError( + "%s: CONSOLE_X_MODE_OFF failed (%s)\n%s\n%s", + "xf86OpenPccons", + strerror(errno), + "Was expecting pccons driver with X support", + CHECK_DRIVER_MSG); } xf86Info.consType = PCCONS; xf86Msg(X_PROBED, "Using pccons driver with X support\n"); @@ -337,7 +345,7 @@ xf86OpenPccons() return fd; } -#endif /* PCCONS_SUPPORT */ +#endif /* PCCONS_SUPPORT */ #ifdef SYSCONS_SUPPORT @@ -414,8 +422,11 @@ xf86OpenSyscons() } close(fd); - snprintf(vtname, sizeof(vtname), "/dev/ttyv%01x", - xf86Info.vtno - 1); +#ifndef __OpenBSD__ + snprintf(vtname, sizeof(vtname), "/dev/ttyv%01x", xf86Info.vtno - 1); +#else + sprintf(vtname, sizeof(vtname), "/dev/ttyC%01x", xf86Info.vtno - 1); +#endif if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0) { FatalError("xf86OpenSyscons: Cannot open %s (%s)", vtname, strerror(errno)); @@ -443,7 +454,8 @@ xf86OpenSyscons() return fd; } -#endif /* SYSCONS_SUPPORT */ +#endif /* SYSCONS_SUPPORT */ + #ifdef PCVT_SUPPORT @@ -462,7 +474,13 @@ xf86OpenPcvt() vtprefix = "/dev/ttyC"; #endif - fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); + if (VTnum != -1) { + snprintf(vtname, sizeof(vtname), "%s%x", vtprefix, VTnum - 1); + fd = open(vtname, PCVT_CONSOLE_MODE, 0); + } + else { + fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); + } #ifdef WSCONS_PCVT_COMPAT_CONSOLE_DEV if (fd < 0) { fd = open(WSCONS_PCVT_COMPAT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); @@ -471,7 +489,7 @@ xf86OpenPcvt() #endif if (fd >= 0) { if (ioctl(fd, VGAPCVTID, &pcvt_version) >= 0) { - if (ioctl(fd, VT_GETMODE, &vtmode) < 0) { + if(ioctl(fd, VT_GETMODE, &vtmode) < 0) { FatalError("%s: VT_GETMODE failed\n%s%s\n%s", "xf86OpenPcvt", "Found pcvt driver but X11 seems to be", @@ -497,23 +515,22 @@ xf86OpenPcvt() xf86Info.vtno = initialVT; } else { - FatalError("%s: Cannot find a free VT", "xf86OpenPcvt"); + FatalError("%s: Cannot find a free VT", + "xf86OpenPcvt"); } } } close(fd); - snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, - xf86Info.vtno - 1); + snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, xf86Info.vtno - 1); if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { ErrorF("xf86OpenPcvt: Cannot open %s (%s)", - vtname, strerror(errno)); + vtname, strerror(errno)); xf86Info.vtno = initialVT; - snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, - xf86Info.vtno - 1); + snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, xf86Info.vtno - 1); if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { - FatalError("xf86OpenPcvt: Cannot open %s (%s)", - vtname, strerror(errno)); + FatalError("xf86OpenPcvt: Cannot open %s (%s)", + vtname, strerror(errno)); } } if (ioctl(fd, VT_GETMODE, &vtmode) < 0) { @@ -539,7 +556,7 @@ xf86OpenPcvt() return fd; } -#endif /* PCVT_SUPPORT */ +#endif /* PCVT_SUPPORT */ #ifdef WSCONS_SUPPORT @@ -550,21 +567,40 @@ xf86OpenWScons() int mode = WSDISPLAYIO_MODE_MAPPED; int i; char ttyname[16]; - - /* XXX Is this ok? */ - for (i = 0; i < 8; i++) { + int mib[2]; + size_t len; + dev_t dev; + +#ifdef KERN_CONSDEV + mib[0] = CTL_KERN; + mib[1] = KERN_CONSDEV; + len = sizeof(dev); + if (sysctl(mib, 2, &dev, &len, NULL, 0) != -1) { + snprintf(ttyname, sizeof(ttyname), "/dev/%s", devname(dev, S_IFCHR)); + if ((fd = open(ttyname, 2)) != -1) { + if (ioctl(fd, WSDISPLAYIO_GTYPE, &i) == -1) { + close(fd); + fd = -1; + } + } + } +#endif + if (fd == -1) { + for (i = 0; i < 8; i++) { #if defined(__NetBSD__) - snprintf(ttyname, sizeof(ttyname), "/dev/ttyE%d", i); + snprintf(ttyname, sizeof(ttyname), "/dev/ttyE%d", i); #elif defined(__OpenBSD__) - snprintf(ttyname, sizeof(ttyname), "/dev/ttyC%x", i); + snprintf(ttyname, sizeof(ttyname), "/dev/ttyC%x", i); #endif - if ((fd = open(ttyname, 2)) != -1) - break; + if ((fd = open(ttyname, 2)) != -1) + break; + } } if (fd != -1) { if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) < 0) { FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed (%s)\n%s", - "xf86OpenConsole", strerror(errno), CHECK_DRIVER_MSG); + "xf86OpenConsole", strerror(errno), + CHECK_DRIVER_MSG); } xf86Info.consType = WSCONS; xf86Msg(X_PROBED, "Using wscons driver\n"); @@ -572,24 +608,23 @@ xf86OpenWScons() return fd; } -#endif /* WSCONS_SUPPORT */ +#endif /* WSCONS_SUPPORT */ void xf86CloseConsole() { #if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) - struct vt_mode VT; + struct vt_mode VT; #endif - if (xf86Info.ShareVTs) - return; + if (xf86Info.ShareVTs) return; switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT case PCCONS: - ioctl(xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0); + ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0); break; -#endif /* PCCONS_SUPPORT */ +#endif /* PCCONS_SUPPORT */ #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) case SYSCONS: case PCVT: @@ -598,7 +633,7 @@ xf86CloseConsole() VT.mode = VT_AUTO; ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */ } -#if !defined(__OpenBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) +#if !defined(OpenBSD) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) if (ioctl(xf86Info.consoleFd, KDDISABIO, 0) < 0) { xf86FatalError("xf86CloseConsole: KDDISABIO failed (%s)", strerror(errno)); @@ -607,19 +642,20 @@ xf86CloseConsole() if (initialVT != -1) ioctl(xf86Info.consoleFd, VT_ACTIVATE, initialVT); break; -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ #ifdef WSCONS_SUPPORT - case WSCONS: - { + case WSCONS: { int mode = WSDISPLAYIO_MODE_EMUL; - ioctl(xf86Info.consoleFd, WSDISPLAYIO_SMODE, &mode); break; - } + } #endif } close(xf86Info.consoleFd); +#ifdef X_PRIVSEP + xf86Info.consoleFd = -1; +#endif #ifdef PCCONS_SUPPORT if (devConsoleFd >= 0) close(devConsoleFd); @@ -631,7 +667,7 @@ int xf86ProcessArgument(int argc, char *argv[], int i) { /* - * Keep server from detaching from controlling tty. This is useful + * Keep server from detaching from controlling tty. This is useful * when debugging (so the server can receive keyboard signals. */ if (!strcmp(argv[i], "-keeptty")) { @@ -640,14 +676,15 @@ xf86ProcessArgument(int argc, char *argv[], int i) } #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { - if (sscanf(argv[i], "vt%2d", &VTnum) == 0 || VTnum < 1 || VTnum > 12) { + if (sscanf(argv[i], "vt%2d", &VTnum) == 0 || + VTnum < 1 || VTnum > 12) { UseMsg(); VTnum = -1; return 0; } return 1; } -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ return 0; } @@ -656,8 +693,45 @@ xf86UseMsg() { #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) ErrorF("vtXX use the specified VT number (1-12)\n"); -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ +#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ ErrorF("-keeptty "); ErrorF("don't detach controlling tty (for debugging only)\n"); return; } + +#ifdef X_PRIVSEP +/* + * Revoke privileges after init. + * If the X server is started as root (xdm case), then switch to _x11 + * if it exists. + * Otherwise use the real uid. + */ +void +xf86DropPriv(char *disp) +{ + struct passwd *pw; + + /* revoke privileges */ + if (getuid() == 0) { + /* Running as root */ + pw = getpwnam("_x11"); + if (!pw) + return; + /* give away lock file to unpriviledged user */ + if (ChownLock(pw->pw_uid, pw->pw_gid) == -1) { + FatalError("Chown Lock"); + } + + /* Start privileged child */ + if (priv_init(pw->pw_uid, pw->pw_gid) == -1) { + FatalError("priv_init"); + } + } + else { + /* Normal user */ + if (priv_init(getuid(), getgid()) == -1) { + FatalError("priv_init"); + } + } +} +#endif diff --git a/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c b/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c index 22943855b..8417c335a 100644 --- a/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c +++ b/hw/xfree86/os-support/bsd/bsd_kqueue_apm.c @@ -157,6 +157,7 @@ bsdPMConfirmEventToOs(int dummyfd, pmEvent event) PMClose xf86OSPMOpen(void) { +#ifndef __OpenBSD__ int kq; struct kevent ev; @@ -179,6 +180,7 @@ xf86OSPMOpen(void) xf86PMGetEventFromOs = bsdPMGetEventFromOS; xf86PMConfirmEventToOs = bsdPMConfirmEventToOs; APMihPtr = xf86AddGeneralHandler(kq, xf86HandlePMEvents, NULL); +#endif return bsdCloseAPM; } diff --git a/hw/xfree86/os-support/bsd/bsd_sbus.c b/hw/xfree86/os-support/bsd/bsd_sbus.c new file mode 100644 index 000000000..883b2728a --- /dev/null +++ b/hw/xfree86/os-support/bsd/bsd_sbus.c @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2008 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, 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 "xf86.h" +#include "xf86Priv.h" + +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +#include "xf86Bus.h" + +#include <dev/wscons/wsconsio.h> + +sbusDevice sbusInfo; + +void +xf86SbusProbe(void) +{ + int fd = xf86Info.consoleFd; + u_int gtype; + + if (ioctl(fd, WSDISPLAYIO_GTYPE, >ype) == -1) + return; + + switch (gtype) { + case WSDISPLAY_TYPE_MGX: + sbusInfo.devId = SBUS_DEVICE_MGX; + break; + case WSDISPLAY_TYPE_SUN24: + sbusInfo.devId = SBUS_DEVICE_LEO; + break; + case WSDISPLAY_TYPE_SUNBW: + sbusInfo.devId = SBUS_DEVICE_BW2; + break; + case WSDISPLAY_TYPE_SUNCG2: + sbusInfo.devId = SBUS_DEVICE_CG2; + break; + case WSDISPLAY_TYPE_SUNCG3: + sbusInfo.devId = SBUS_DEVICE_CG3; + break; + case WSDISPLAY_TYPE_SUNCG4: + sbusInfo.devId = SBUS_DEVICE_CG4; + break; + case WSDISPLAY_TYPE_SUNCG6: + sbusInfo.devId = SBUS_DEVICE_CG6; + break; + case WSDISPLAY_TYPE_SUNCG8: + sbusInfo.devId = SBUS_DEVICE_CG8; + break; + case WSDISPLAY_TYPE_SUNCG12: + sbusInfo.devId = SBUS_DEVICE_CG12; + break; + case WSDISPLAY_TYPE_SUNCG14: + sbusInfo.devId = SBUS_DEVICE_CG14; + break; + case WSDISPLAY_TYPE_SUNFFB: + sbusInfo.devId = SBUS_DEVICE_FFB; + break; + case WSDISPLAY_TYPE_SUNTCX: + sbusInfo.devId = SBUS_DEVICE_TCX; + break; + } + + sbusInfo.fd = -1; +} + +_X_EXPORT int +xf86MatchSbusInstances(const char *driverName, int sbusDevId, + GDevPtr *devList, int numDevs, DriverPtr drvp, + int **foundEntities) +{ + int *retEntities = NULL; + EntityPtr p = NULL; + int num; + + *foundEntities = NULL; + if (sbusDevId == sbusInfo.devId) { + if (xf86DoConfigure && xf86DoConfigurePass1) { + GDevPtr pGDev; + + pGDev = xf86AddBusDeviceToConfigure(drvp->driverName, + BUS_SBUS, + &sbusInfo, -1); + if (pGDev) { + /* + * XF86Match???Instances() treat + * chipID and chipRev as overrides, so + * clobber them here. + */ + pGDev->chipID = pGDev->chipRev = -1; + } + return 1; + } + + sbusInfo.device = devList[0]->identifier; + num = xf86AllocateEntity(); + p = xf86Entities[num]; + p->driver = drvp; + p->chipset = -1; + p->bus.type = BUS_SBUS; + xf86AddDevToEntity(num, devList[0]); + p->active = TRUE; + p->inUse = FALSE; + retEntities = malloc(sizeof(int)); + retEntities[0] = num; + *foundEntities = retEntities; + return 1; + } + + return 0; +} + +_X_EXPORT sbusDevicePtr +xf86GetSbusInfoForEntity(int entityIndex) +{ + return &sbusInfo; +} + +_X_EXPORT void +xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, sbusDevicePtr psdp) +{ + int fd = xf86Info.consoleFd; + struct wsdisplay_fbinfo wdf; + DisplayModePtr mode; + + if (ioctl(fd, WSDISPLAYIO_GINFO, &wdf) == -1) + FatalError("%s: could not get mode (%s)", + "xf86SbusUseBuiltinMode", strerror(errno)); + + mode = calloc(1, sizeof(DisplayModeRec)); + mode->name = "current"; + mode->next = mode; + mode->prev = mode; + mode->type = M_T_BUILTIN; + mode->HDisplay = wdf.width; + mode->VDisplay = wdf.height; + pScrn->modes = mode; + pScrn->virtualX = wdf.width; + pScrn->virtualY = wdf.height; +} + +_X_EXPORT pointer +xf86MapSbusMem(sbusDevicePtr psdp, unsigned long Base, unsigned long Size) +{ + return xf86MapVidMem(0, 0, Base, Size); +} + +_X_EXPORT void +xf86UnmapSbusMem(sbusDevicePtr psdp, pointer Base, unsigned long Size) +{ + xf86UnMapVidMem(0, Base, Size); +} + +_X_EXPORT void +xf86SbusHideOsHwCursor(sbusDevicePtr psdp) +{ +} + +int +sparcPromInit(void) +{ + return -1; +} + +char * +sparcPromNode2Pathname(sbusPromNodePtr pnode) +{ + return NULL; +} + +void +sparcPromClose(void) +{ +} + +char * +sparcDriverName(void) +{ + switch (sbusInfo.devId) { + case SBUS_DEVICE_FFB: + return "sunffb"; + default: + return NULL; + } +} diff --git a/hw/xfree86/os-support/bsd/hp300_video.c b/hw/xfree86/os-support/bsd/hp300_video.c new file mode 100644 index 000000000..757b65348 --- /dev/null +++ b/hw/xfree86/os-support/bsd/hp300_video.c @@ -0,0 +1,121 @@ +/* $OpenBSD: hp300_video.c,v 1.3 2008/02/16 21:40:29 miod Exp $ */ +/* + * Copyright 1992 by Rich Murphey <Rich@Rice.edu> + * 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 Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of + * the software without specific, written prior permission. Rich Murphey and + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 "xf86.h" +#include "xf86Priv.h" + +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +#ifndef MAP_FAILED +#define MAP_FAILED ((caddr_t)-1) +#endif + +/***************************************************************************/ +/* Video Memory Mapping section */ +/***************************************************************************/ + +static pointer hp300MapVidMem(int, unsigned long, unsigned long, int); +static void hp300UnmapVidMem(int, pointer, unsigned long); + + +void +xf86OSInitVidMem(VidMemInfoPtr pVidMem) +{ + pVidMem->linearSupported = TRUE; + pVidMem->mapMem = hp300MapVidMem; + pVidMem->unmapMem = hp300UnmapVidMem; + pVidMem->initialised = TRUE; +} + + +static pointer +hp300MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +{ + int fd = xf86Info.consoleFd; + pointer base; + +#ifdef DEBUG + xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d\n", + Base, Size, fd); +#endif + + base = mmap(0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_SHARED, fd, Base); + if (base == MAP_FAILED) + FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", + "xf86MapVidMem", Size, Base, strerror(errno)); + return base; +} + +static void +hp300UnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) +{ + munmap(Base, Size); +} + +_X_EXPORT int +xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, + int Len) +{ + return 0; +} + +/***************************************************************************/ +/* Interrupt Handling section */ +/***************************************************************************/ + +_X_EXPORT Bool +xf86DisableInterrupts() +{ + + return(TRUE); +} + +_X_EXPORT void +xf86EnableInterrupts() +{ + + return; +} + +#ifdef X_PRIVSEP +/* + * Do all initialisation that need root privileges + */ +_X_EXPORT void +xf86PrivilegedInit(void) +{ + xf86OpenConsole(); +} +#endif diff --git a/hw/xfree86/os-support/bsd/hppa_video.c b/hw/xfree86/os-support/bsd/hppa_video.c new file mode 100644 index 000000000..1bddbd5ea --- /dev/null +++ b/hw/xfree86/os-support/bsd/hppa_video.c @@ -0,0 +1,116 @@ +/* $OpenBSD: hppa_video.c,v 1.2 2009/12/18 22:47:56 matthieu Exp $ */ +/* + * Copyright 1992 by Rich Murphey <Rich@Rice.edu> + * 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 Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of + * the software without specific, written prior permission. Rich Murphey and + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 "xf86.h" +#include "xf86Priv.h" + +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +#ifndef MAP_FAILED +#define MAP_FAILED ((caddr_t)-1) +#endif + + +/***************************************************************************/ +/* Video Memory Mapping section */ +/***************************************************************************/ + +static pointer hppaMapVidMem(int, unsigned long, unsigned long, int); +static void hppaUnmapVidMem(int, pointer, unsigned long); + + +void +xf86OSInitVidMem(VidMemInfoPtr pVidMem) +{ + xf86OpenConsole(); + + pVidMem->linearSupported = TRUE; + pVidMem->mapMem = hppaMapVidMem; + pVidMem->unmapMem = hppaUnmapVidMem; +#if HAVE_PCI_SYSTEM_INIT_DEV_MEM + pci_system_init_dev_mem(xf86Info.consolefd); +#endif + pVidMem->initialised = TRUE; +} + + +volatile unsigned char *ioBase = MAP_FAILED; + +static pointer +hppaMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +{ + int fd = xf86Info.consolefd; + pointer base; + +#ifdef DEBUG + xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d\n", + Base, Size, fd); +#endif + + base = mmap(0, Size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, Base); + if (base == MAP_FAILED) + FatalError("%s: could not mmap screen [s=%lx,a=%lx] (%s)", + "xf86MapVidMem", Size, Base, strerror(errno)); + + return base; +} + + +static void +hppaUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) +{ + + munmap(Base, Size); +} + +int +xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, + int Len) +{ + return 0; +} + +/***************************************************************************/ +/* Interrupt Handling section */ +/***************************************************************************/ + +#ifdef X_PRIVSEP +/* + * Do all initialisation that need root privileges + */ +void +xf86PrivilegedInit(void) +{ + /* pci_system_init(); */ + xf86OpenConsole(); +} +#endif diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c index 569a4ec51..f7057c625 100644 --- a/hw/xfree86/os-support/bsd/i386_video.c +++ b/hw/xfree86/os-support/bsd/i386_video.c @@ -6,19 +6,19 @@ * 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 Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of + * documentation, and that the names of Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or * implied warranty. * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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. * */ @@ -36,7 +36,6 @@ #ifdef HAS_MTRR_SUPPORT #ifndef __NetBSD__ -#include <sys/types.h> #include <sys/memrange.h> #else #include "memrange.h" @@ -66,12 +65,12 @@ #ifdef __OpenBSD__ #define SYSCTL_MSG "\tCheck that you have set 'machdep.allowaperture=1'\n"\ - "\tin /etc/sysctl.conf and reboot your machine\n" \ - "\trefer to xf86(4) for details" + "\tin /etc/sysctl.conf and reboot your machine\n" \ + "\trefer to xf86(4) for details\n" #define SYSCTL_MSG2 \ - "Check that you have set 'machdep.allowaperture=2'\n" \ - "\tin /etc/sysctl.conf and reboot your machine\n" \ - "\trefer to xf86(4) for details" + "Check that you have set 'machdep.allowaperture=2'\n" \ + "\tin /etc/sysctl.conf and reboot your machine\n" \ + "\trefer to xf86(4) for details\n" #endif /***************************************************************************/ @@ -79,7 +78,7 @@ /***************************************************************************/ static Bool useDevMem = FALSE; -static int devMemFd = -1; +static int devMemFd = -1; #ifdef HAS_APERTURE_DRV #define DEV_APERTURE "/dev/xf86" @@ -114,73 +113,66 @@ checkDevMem(Bool warn) return; devMemChecked = TRUE; - if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { +#ifdef HAS_APERTURE_DRV + /* Try the aperture driver first */ + if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) { /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000); + base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t)0xA0000); if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); + munmap((caddr_t)base, 4096); devMemFd = fd; useDevMem = TRUE; + xf86Msg(X_PROBED, "checkDevMem: using aperture driver %s\n", + DEV_APERTURE); return; } else { - /* This should not happen */ if (warn) { xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); + DEV_APERTURE, strerror(errno)); } - useDevMem = FALSE; - return; } } -#ifndef HAS_APERTURE_DRV - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; -#else - /* Failed to open /dev/mem, try the aperture driver */ - if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) { +#endif + if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000); + base = mmap((caddr_t)0, 4096, PROT_READ | PROT_WRITE, + MAP_FLAGS, fd, (off_t)0xA0000); if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); + munmap((caddr_t)base, 4096); devMemFd = fd; useDevMem = TRUE; - xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n", - DEV_APERTURE); return; } else { - if (warn) { xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_APERTURE, strerror(errno)); + DEV_MEM, strerror(errno)); } } } - else { - if (warn) { + if (warn) { +#ifndef HAS_APERTURE_DRV + xf86Msg(X_WARNING, "checkDevMem: failed to open/mmap %s (%s)\n", + DEV_MEM, strerror(errno)); + xf86ErrorF("\tlinear framebuffer access unavailable\n"); +#else #ifndef __OpenBSD__ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n", DEV_MEM, DEV_APERTURE, strerror(errno)); -#else /* __OpenBSD__ */ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n%s", DEV_MEM, DEV_APERTURE, strerror(errno), - SYSCTL_MSG); -#endif /* __OpenBSD__ */ - } - } + xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" + "\t(%s)\n", DEV_APERTURE, DEV_MEM, strerror(errno)); +#else /* __OpenBSD__ */ + xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" + "\t(%s)\n%s", DEV_APERTURE, DEV_MEM, strerror(errno), + SYSCTL_MSG); +#endif /* __OpenBSD__ */ + xf86ErrorF("\tlinear framebuffer access unavailable\n"); + } useDevMem = FALSE; return; - #endif } @@ -222,26 +214,28 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) FatalError("xf86MapVidMem: failed to open %s (%s)", DEV_MEM, strerror(errno)); } - base = mmap((caddr_t) 0, Size, + base = mmap((caddr_t)0, Size, (flags & VIDMEM_READONLY) ? PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, devMemFd, (off_t) Base); + MAP_FLAGS, devMemFd, (off_t)Base); if (base == MAP_FAILED) { FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)", - "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno)); + "xf86MapVidMem", DEV_MEM, Size, Base, + strerror(errno)); } return base; } /* else, mmap /dev/vga */ - if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) { + if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000) { FatalError("%s: Address 0x%lx outside allowable range", "xf86MapVidMem", Base); } base = mmap(0, Size, (flags & VIDMEM_READONLY) ? PROT_READ : (PROT_READ | PROT_WRITE), - MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base - 0xA0000); + MAP_FLAGS, xf86Info.consoleFd, + (unsigned long)Base - 0xA0000); if (base == MAP_FAILED) { FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)", strerror(errno)); @@ -252,7 +246,7 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) static void unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) { - munmap((caddr_t) Base, Size); + munmap((caddr_t)Base, Size); } /* @@ -276,9 +270,9 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, Offset += Base & (psize - 1); Base &= ~(psize - 1); mlen = (Offset + Len + psize - 1) & ~(psize - 1); - ptr = (unsigned char *) mmap((caddr_t) 0, mlen, PROT_READ, - MAP_SHARED, devMemFd, (off_t) Base); - if ((long) ptr == -1) { + ptr = (unsigned char *)mmap((caddr_t)0, mlen, PROT_READ, + MAP_SHARED, devMemFd, (off_t)Base); + if ((long)ptr == -1) { xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n", DEV_MEM, Len, Base, Offset, strerror(errno)); @@ -293,8 +287,8 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", Base, ptr[0] | (ptr[1] << 8)); #endif - (void) memcpy(Buf, (void *) (ptr + Offset), Len); - (void) munmap((caddr_t) ptr, mlen); + (void)memcpy(Buf, (void *)(ptr + Offset), Len); + (void)munmap((caddr_t)ptr, mlen); #ifdef DEBUG xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)" "-> %02x %02x %02x %02x...\n", @@ -316,12 +310,13 @@ xf86EnableIO() if (ExtendedEnabled) return TRUE; - if (i386_iopl(TRUE) < 0) { + if (i386_iopl(TRUE) < 0) + { #ifndef __OpenBSD__ - xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O", "xf86EnableIO"); #else - xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O\n%s", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n%s", "xf86EnableIO", SYSCTL_MSG); #endif return FALSE; @@ -337,13 +332,16 @@ xf86DisableIO() if (!ExtendedEnabled) return; - i386_iopl(FALSE); - ExtendedEnabled = FALSE; + if (i386_iopl(FALSE) == 0) { + ExtendedEnabled = FALSE; + } + /* Otherwise, the X server has revoqued its root uid, + and thus cannot give up IO privileges any more */ return; } -#endif /* USE_I386_IOPL */ +#endif /* USE_I386_IOPL */ #ifdef USE_AMD64_IOPL /***************************************************************************/ @@ -360,10 +358,10 @@ xf86EnableIO() if (amd64_iopl(TRUE) < 0) { #ifndef __OpenBSD__ - xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O", "xf86EnableIO"); #else - xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O\n%s", + xf86Msg(X_WARNING,"%s: Failed to set IOPL for extended I/O\n%s", "xf86EnableIO", SYSCTL_MSG); #endif return FALSE; @@ -382,13 +380,13 @@ xf86DisableIO() if (amd64_iopl(FALSE) == 0) { ExtendedEnabled = FALSE; } - /* Otherwise, the X server has revoqued its root uid, + /* Otherwise, the X server has revoqued its root uid, and thus cannot give up IO privileges any more */ return; } -#endif /* USE_AMD64_IOPL */ +#endif /* USE_AMD64_IOPL */ #ifdef USE_DEV_IO static int IoFd = -1; @@ -400,7 +398,7 @@ xf86EnableIO() return TRUE; if ((IoFd = open("/dev/io", O_RDWR)) == -1) { - xf86Msg(X_WARNING, "xf86EnableIO: " + xf86Msg(X_WARNING,"xf86EnableIO: " "Failed to open /dev/io for extended I/O"); return FALSE; } @@ -430,15 +428,14 @@ xf86SetTVOut(int mode) switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT case PCCONS:{ - - if (ioctl(xf86Info.consoleFd, CONSOLE_X_TV_ON, &mode) < 0) { + if (ioctl (xf86Info.consoleFd, CONSOLE_X_TV_ON, &mode) < 0) { xf86Msg(X_WARNING, "xf86SetTVOut: Could not set console to TV output, %s\n", strerror(errno)); } } - break; -#endif /* PCCONS_SUPPORT */ + break; +#endif /* PCCONS_SUPPORT */ default: FatalError("Xf86SetTVOut: Unsupported console"); @@ -453,15 +450,14 @@ xf86SetRGBOut() switch (xf86Info.consType) { #ifdef PCCONS_SUPPORT case PCCONS:{ - - if (ioctl(xf86Info.consoleFd, CONSOLE_X_TV_OFF, 0) < 0) { + if (ioctl (xf86Info.consoleFd, CONSOLE_X_TV_OFF, 0) < 0) { xf86Msg(X_WARNING, "xf86SetTVOut: Could not set console to RGB output, %s\n", strerror(errno)); } } - break; -#endif /* PCCONS_SUPPORT */ + break; +#endif /* PCCONS_SUPPORT */ default: FatalError("Xf86SetTVOut: Unsupported console"); @@ -532,8 +528,8 @@ cleanMTRR() (mrd[i].mr_flags & MDF_ACTIVE)) { #ifdef DEBUG ErrorF("Clean for (0x%lx,0x%lx)\n", - (unsigned long) mrd[i].mr_base, - (unsigned long) mrd[i].mr_len); + (unsigned long)mrd[i].mr_base, + (unsigned long)mrd[i].mr_len); #endif if (mrd[i].mr_flags & MDF_FIXACTIVE) { mro.mo_arg[0] = MEMRANGE_SET_UPDATE; @@ -628,8 +624,7 @@ sortRangeList(RangePtr list) */ static void -findRanges(unsigned long base, unsigned long size, RangePtr * ucp, - RangePtr * wcp) +findRanges(unsigned long base, unsigned long size, RangePtr *ucp, RangePtr *wcp) { struct mem_range_desc *mrd; int nmr, i; @@ -767,7 +762,8 @@ delWC(int screenNum, unsigned long base, unsigned long size, MessageType from) } else { xf86DrvMsg(screenNum, from, - "Removed Write-combining range (0x%lx,0x%lx)\n", base, size); + "Removed Write-combining range (0x%lx,0x%lx)\n", + base, size); retlist = xnfalloc(sizeof(RangeRec)); retlist->mrd = mrd; retlist->wasWC = TRUE; @@ -797,8 +793,8 @@ undoWC(int screenNum, pointer list) while (rp) { #ifdef DEBUG ErrorF("Undo for (0x%lx,0x%lx), %d\n", - (unsigned long) rp->mrd.mr_base, - (unsigned long) rp->mrd.mr_len, rp->wasWC); + (unsigned long)rp->mrd.mr_base, + (unsigned long)rp->mrd.mr_len, rp->wasWC); #endif failed = FALSE; if (rp->wasWC) { @@ -825,14 +821,15 @@ undoWC(int screenNum, pointer list) if (failed) { xf86DrvMsg(screenNum, X_WARNING, "Failed to restore MTRR range (0x%lx,0x%lx)\n", - (unsigned long) rp->mrd.mr_base, - (unsigned long) rp->mrd.mr_len); + (unsigned long)rp->mrd.mr_base, + (unsigned long)rp->mrd.mr_len); } rp = rp->next; } } -#endif /* HAS_MTRR_SUPPORT */ +#endif /* HAS_MTRR_SUPPORT */ + #if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__) static pointer @@ -846,7 +843,7 @@ NetBSDsetWC(int screenNum, unsigned long base, unsigned long size, Bool enable, "%s MTRR %lx - %lx\n", enable ? "set" : "remove", base, (base + size)); - mtrrp = xnfalloc(sizeof(struct mtrr)); + mtrrp = xnfalloc(sizeof (struct mtrr)); mtrrp->base = base; mtrrp->len = size; mtrrp->type = MTRR_TYPE_WC; @@ -873,7 +870,7 @@ NetBSDsetWC(int screenNum, unsigned long base, unsigned long size, Bool enable, static void NetBSDundoWC(int screenNum, pointer list) { - struct mtrr *mtrrp = (struct mtrr *) list; + struct mtrr *mtrrp = (struct mtrr *)list; int n; if (mtrrp == NULL) @@ -884,3 +881,22 @@ NetBSDundoWC(int screenNum, pointer list) free(mtrrp); } #endif + +#ifdef X_PRIVSEP +#include <pciaccess.h> + +/* + * Do all things that need root privileges early + * and revoke those privileges + */ +_X_EXPORT void +xf86PrivilegedInit(void) +{ + checkDevMem(TRUE); + + pci_system_init(); + pci_legacy_open_io(NULL, 0, 64*1024); + ExtendedEnabled = TRUE; /* Will die with xf86EnableIO() */ + xf86OpenConsole(); +} +#endif diff --git a/hw/xfree86/os-support/bsd/ppc_video.c b/hw/xfree86/os-support/bsd/ppc_video.c index 417adbf4b..7790774d1 100644 --- a/hw/xfree86/os-support/bsd/ppc_video.c +++ b/hw/xfree86/os-support/bsd/ppc_video.c @@ -6,19 +6,19 @@ * 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 Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of + * documentation, and that the names of Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or * implied warranty. * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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. * */ @@ -47,36 +47,44 @@ static pointer ppcMapVidMem(int, unsigned long, unsigned long, int flags); static void ppcUnmapVidMem(int, pointer, unsigned long); +#ifdef __NetBSD__ Bool xf86EnableIO(void); void xf86DisableIO(void); +#endif void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { + xf86OpenConsole(); + pVidMem->linearSupported = TRUE; pVidMem->mapMem = ppcMapVidMem; pVidMem->unmapMem = ppcUnmapVidMem; pVidMem->initialised = TRUE; + + pci_system_init_dev_mem(xf86Info.consoleFd); xf86EnableIO(); } -volatile unsigned char *ioBase = MAP_FAILED; + +_X_EXPORT volatile unsigned char *ioBase = MAP_FAILED; static pointer ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { int fd = xf86Info.consoleFd; pointer base; - #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd); + xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", + Base, Size, fd); #endif base = mmap(0, Size, (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base); + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_SHARED, fd, Base); if (base == MAP_FAILED) - FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", + FatalError("%s: could not mmap screen [s=%lx,a=%lx] (%s)", "xf86MapVidMem", Size, Base, strerror(errno)); return base; @@ -88,12 +96,18 @@ ppcUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) munmap(Base, Size); } -int +static int kmem = -1; + +_X_EXPORT int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, int Len) { int rv; - static int kmem = -1; + + if (Base < 0x80000000) { + xf86Msg(X_WARNING, "No VGA Base=%#lx\n", Base); + return 0; + } if (kmem == -1) { kmem = open(DEV_MEM, 2); @@ -103,23 +117,45 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, } #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n", Base, Offset, Len); + xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n", + Base, Offset, Len); #endif + lseek(kmem, Base + Offset, 0); rv = read(kmem, Buf, Len); return rv; } -Bool -xf86EnableIO() + +#ifdef X_PRIVSEP +/* + * Do all initialisation that need root privileges + */ +_X_EXPORT void +xf86PrivilegedInit(void) +{ + kmem = open(DEV_MEM, 2); + if (kmem == -1) { + xf86Msg(X_PROBED, + "no aperture driver access: only wsfb driver useable\n"); + } + else { + pci_system_init(); + } + xf86OpenConsole(); +} +#endif + +#ifdef __NetBSD__ +Bool xf86EnableIO() { int fd = xf86Info.consoleFd; xf86MsgVerb(X_WARNING, 3, "xf86EnableIO %d\n", fd); if (ioBase == MAP_FAILED) { - ioBase = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, + ioBase = mmap(NULL, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0xf2000000); xf86MsgVerb(X_INFO, 3, "xf86EnableIO: %08x\n", ioBase); if (ioBase == MAP_FAILED) { @@ -130,8 +166,7 @@ xf86EnableIO() return TRUE; } -void -xf86DisableIO() +void xf86DisableIO() { if (ioBase != MAP_FAILED) { @@ -139,3 +174,5 @@ xf86DisableIO() ioBase = MAP_FAILED; } } + +#endif /* __NetBSD__ */ diff --git a/hw/xfree86/os-support/bsd/sgi_video.c b/hw/xfree86/os-support/bsd/sgi_video.c new file mode 100644 index 000000000..66d3d5f3b --- /dev/null +++ b/hw/xfree86/os-support/bsd/sgi_video.c @@ -0,0 +1,118 @@ +/* + * Copyright 1992 by Rich Murphey <Rich@Rice.edu> + * 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 Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of + * the software without specific, written prior permission. Rich Murphey and + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 "xf86.h" +#include "xf86Priv.h" + +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +#ifndef MAP_FAILED +#define MAP_FAILED ((caddr_t)-1) +#endif + +/***************************************************************************/ +/* Video Memory Mapping section */ +/***************************************************************************/ + +static pointer sgiMapVidMem(int, unsigned long, unsigned long, int); +static void sgiUnmapVidMem(int, pointer, unsigned long); + +void +xf86OSInitVidMem(VidMemInfoPtr pVidMem) +{ + pVidMem->linearSupported = TRUE; + pVidMem->mapMem = sgiMapVidMem; + pVidMem->unmapMem = sgiUnmapVidMem; + pVidMem->initialised = TRUE; +} + +static pointer +sgiMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, + int flags) +{ + int fd = xf86Info.consoleFd; + pointer base; + +#ifdef DEBUG + xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", + Base, Size, fd); +#endif + + base = mmap(0, Size, + (flags & VIDMEM_READONLY) ? + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_SHARED, fd, Base); + if (base == MAP_FAILED) + FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", + "xf86MapVidMem", Size, Base, strerror(errno)); + return base; +} + +static void +sgiUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) +{ + munmap(Base, Size); +} + +_X_EXPORT int +xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, + int Len) +{ + return (0); +} + +/***************************************************************************/ +/* Interrupt Handling section */ +/***************************************************************************/ + +_X_EXPORT Bool +xf86DisableInterrupts() +{ + return(TRUE); +} + +_X_EXPORT void +xf86EnableInterrupts() +{ + return; +} + +#ifdef X_PRIVSEP +/* + * Do all things that need root privileges early + * and revoke those privileges + */ +_X_EXPORT void +xf86PrivilegedInit(void) +{ + xf86OpenConsole(); +} +#endif diff --git a/hw/xfree86/os-support/bsd/sparc64_video.c b/hw/xfree86/os-support/bsd/sparc64_video.c index 21c166105..39ccc7a6b 100644 --- a/hw/xfree86/os-support/bsd/sparc64_video.c +++ b/hw/xfree86/os-support/bsd/sparc64_video.c @@ -6,19 +6,19 @@ * 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 Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of + * documentation, and that the names of Rich Murphey and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or + * David Wexelblat make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or * implied warranty. * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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 + * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL RICH MURPHEY 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. * */ @@ -44,9 +44,12 @@ static void sparc64UnmapVidMem(int, pointer, unsigned long); void xf86OSInitVidMem(VidMemInfoPtr pVidMem) { + xf86OpenConsole(); + pVidMem->linearSupported = TRUE; pVidMem->mapMem = sparc64MapVidMem; pVidMem->unmapMem = sparc64UnmapVidMem; + pci_system_init_dev_mem(xf86Info.consoleFd); pVidMem->initialised = TRUE; } @@ -58,12 +61,14 @@ sparc64MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, pointer base; #ifdef DEBUG - xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd); + xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", + Base, Size, fd); #endif base = mmap(0, Size, (flags & VIDMEM_READONLY) ? - PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base); + PROT_READ : (PROT_READ | PROT_WRITE), + MAP_SHARED, fd, Base); if (base == MAP_FAILED) FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)", "xf86MapVidMem", Size, Base, strerror(errno)); @@ -76,10 +81,23 @@ sparc64UnmapVidMem(int ScreenNum, pointer Base, unsigned long Size) munmap(Base, Size); } -int +_X_EXPORT int xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf, int Len) { return 0; } + +#ifdef X_PRIVSEP +/* + * Do all things that need root privileges early + * and revoke those privileges + */ +_X_EXPORT void +xf86PrivilegedInit(void) +{ + pci_system_init(); + xf86OpenConsole(); +} +#endif diff --git a/hw/xfree86/os-support/bus/xf86Sbus.h b/hw/xfree86/os-support/bus/xf86Sbus.h index 8a10d64fe..a24d92269 100644 --- a/hw/xfree86/os-support/bus/xf86Sbus.h +++ b/hw/xfree86/os-support/bus/xf86Sbus.h @@ -36,7 +36,7 @@ #elif defined(SVR4) #include <sys/fbio.h> #include <sys/openpromio.h> -#elif defined(__OpenBSD__) && defined(__sparc64__) +#elif defined(__OpenBSD__) /* XXX */ #elif defined(CSRG_BASED) #if defined(__FreeBSD__) diff --git a/hw/xfree86/os-support/shared/posix_tty.c b/hw/xfree86/os-support/shared/posix_tty.c index ab3757a2a..7491d3410 100644 --- a/hw/xfree86/os-support/shared/posix_tty.c +++ b/hw/xfree86/os-support/shared/posix_tty.c @@ -61,6 +61,7 @@ #include "xf86Priv.h" #include "xf86_OSlib.h" + static int GetBaud(int baudrate) { @@ -124,7 +125,11 @@ xf86OpenSerial(XF86OptionPtr options) return -1; } +#ifndef X_PRIVSEP SYSCALL(fd = open(dev, O_RDWR | O_NONBLOCK)); +#else + fd = priv_open_device (dev); +#endif if (fd == -1) { xf86Msg(X_ERROR, "xf86OpenSerial: Cannot open device %s\n\t%s.\n", @@ -161,7 +166,11 @@ xf86OpenSerial(XF86OptionPtr options) return -1; } +#ifndef X_PRIVSEP SYSCALL(i = fcntl(fd, F_GETFL, 0)); +#else + fd = priv_open_device (dev); +#endif if (i == -1) { SYSCALL(close(fd)); free(dev); diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh index 40ea7c8da..7584e8c88 100755..100644 --- a/hw/xfree86/sdksyms.sh +++ b/hw/xfree86/sdksyms.sh @@ -8,7 +8,6 @@ cat > sdksyms.c << EOF #include <xorg-config.h> #endif - /* These must be included first */ #include "misc.h" #include "miscstruct.h" @@ -142,7 +141,7 @@ cat > sdksyms.c << EOF #endif */ #include "xorgVersion.h" -#if defined(__sparc__) || defined(__sparc) +#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) # include "xf86sbusBus.h" #endif @@ -320,6 +319,14 @@ cat > sdksyms.c << EOF EOF +case `gcc -dumpversion` in + [23].*) + n=2 + ;; + 4.*) + n=3 + ;; +esac topdir=$1 shift LC_ALL=C @@ -361,6 +368,7 @@ BEGIN { if (sdk) { n = 3; + printf("/* %s */\n", $0) # skip attribute, if any while ($n ~ /^(__attribute__|__global)/ || # skip modifiers, if any diff --git a/hw/xquartz/bundle/X11.sh b/hw/xquartz/bundle/X11.sh index 3b8b6799c..3b8b6799c 100755..100644 --- a/hw/xquartz/bundle/X11.sh +++ b/hw/xquartz/bundle/X11.sh diff --git a/hw/xquartz/bundle/mk_bundke.sh b/hw/xquartz/bundle/mk_bundke.sh index 288c6a9de..288c6a9de 100755..100644 --- a/hw/xquartz/bundle/mk_bundke.sh +++ b/hw/xquartz/bundle/mk_bundke.sh diff --git a/hw/xwin/XWin.exe.manifest b/hw/xwin/XWin.exe.manifest index a0d4d7dae..a0d4d7dae 100755..100644 --- a/hw/xwin/XWin.exe.manifest +++ b/hw/xwin/XWin.exe.manifest diff --git a/hw/xwin/glx/gen_gl_wrappers.py b/hw/xwin/glx/gen_gl_wrappers.py index e2d960ec6..e2d960ec6 100755..100644 --- a/hw/xwin/glx/gen_gl_wrappers.py +++ b/hw/xwin/glx/gen_gl_wrappers.py diff --git a/include/dix-config.h.in b/include/dix-config.h.in index 2e4300e19..f66b7268b 100644 --- a/include/dix-config.h.in +++ b/include/dix-config.h.in @@ -402,9 +402,15 @@ /* Support HAL for hotplug */ #undef CONFIG_HAL +/* Use wscons for input auto configuration */ +#undef CONFIG_WSCONS + /* Have a monotonic clock from clock_gettime() */ #undef MONOTONIC_CLOCK +/* Use X server privilege separation */ +#undef X_PRIVSEP + /* Define to 1 if the DTrace Xserver provider probes should be built in */ #undef XSERVER_DTRACE diff --git a/include/os.h b/include/os.h index 4b5b4403f..93a43f4dc 100644 --- a/include/os.h +++ b/include/os.h @@ -306,6 +306,13 @@ LockServer(void); extern _X_EXPORT void UnlockServer(void); +#ifdef X_PRIVSEP +extern _X_EXPORT int +ChownLock(uid_t, gid_t); +extern _X_EXPORT int +priv_open_device(const char *); +#endif + extern _X_EXPORT int OsLookupColor(int /*screen */ , char * /*name */ , diff --git a/include/servermd.h b/include/servermd.h index d6a9a3ad5..e62bd4c2b 100644 --- a/include/servermd.h +++ b/include/servermd.h @@ -75,7 +75,17 @@ SOFTWARE. #endif /* __avr32__ */ -#ifdef __arm32__ +#if defined(vax) || defined(__vax__) + +#define IMAGE_BYTE_ORDER LSBFirst /* Values for the VAX only */ +#define BITMAP_BIT_ORDER LSBFirst +#define GLYPHPADBYTES 4 /* to make fb work */ +#define GETLEFTBITS_ALIGNMENT 1 +#define FAST_UNALIGNED_READS + +#endif /* vax */ + +#if defined(__arm32__) || defined(__arm__) && defined(__OpenBSD__) #define IMAGE_BYTE_ORDER LSBFirst #define BITMAP_BIT_ORDER LSBFirst @@ -112,6 +122,15 @@ SOFTWARE. /* byte boundries */ #endif /* hpux || __hppa__ */ +#if defined (__m88k__) + +#define IMAGE_BYTE_ORDER MSBFirst +#define BITMAP_BIT_ORDER MSBFirst +#define GLYPHPADBYTES 4 +#define GETLEFTBITS_ALIGNMENT 1 + +#endif /* __m88k__ */ + #if defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) #define IMAGE_BYTE_ORDER MSBFirst @@ -272,6 +291,29 @@ SOFTWARE. #endif /* linux/m68k */ +#if defined (OpenBSD) && defined (__mc68020__) + +#define IMAGE_BYTE_ORDER MSBFirst +#define BITMAP_BIT_ORDER MSBFirst +#define FAST_UNALIGNED_READS +#define GLYPHPADBYTES 4 +#define GETLEFTBITS_ALIGNMENT 1 + +#endif /* OpenBSD/m68k */ + +#ifdef sgi + +#define IMAGE_BYTE_ORDER MSBFirst +#define BITMAP_BIT_ORDER MSBFirst +#define GLYPHPADBYTES 4 +#define GETLEFTBITS_ALIGNMENT 1 +#define AVOID_MEMORY_READ +#define FAST_CONSTANT_OFFSET_MODE +#define LARGE_INSTRUCTION_CACHE +#define PLENTIFUL_REGISTERS + +#endif + /* linux on ARM */ #if defined(linux) && defined(__arm__) #define IMAGE_BYTE_ORDER LSBFirst diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in index 2cc416ae7..205f6c239 100644 --- a/include/xorg-config.h.in +++ b/include/xorg-config.h.in @@ -1,5 +1,5 @@ /* xorg-config.h.in: not at all generated. -*- c -*- - * + * * This file differs from xorg-server.h.in in that -server is installed * with the rest of the SDK for external drivers/modules to use, whereas * -config is for internal use only (i.e. building the DDX). @@ -136,4 +136,7 @@ /* Have getresuid */ #undef HAVE_GETRESUID +/* Use X server privilege separation */ +#undef X_PRIVSEP + #endif /* _XORG_CONFIG_H_ */ diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in index 8086f32ae..f3cb87e19 100644 --- a/include/xorg-server.h.in +++ b/include/xorg-server.h.in @@ -205,6 +205,9 @@ /* X Access Control Extension */ #undef XACE +/* Use X server privilege separation */ +#undef X_PRIVSEP + #ifdef _LP64 #define _XSERVER64 1 #endif diff --git a/os/Makefile.am b/os/Makefile.am index 88914852f..abf1c4512 100644 --- a/os/Makefile.am +++ b/os/Makefile.am @@ -4,6 +4,7 @@ AM_CFLAGS = $(DIX_CFLAGS) $(SHA1_CFLAGS) SECURERPC_SRCS = rpcauth.c XDMCP_SRCS = xdmcp.c +PRIVSEP_SRCS = privsep.c XORG_SRCS = log.c libos_la_SOURCES = \ @@ -24,6 +25,7 @@ libos_la_SOURCES = \ xstrans.c \ xprintf.c \ $(XORG_SRCS) + libos_la_LIBADD = @SHA1_LIBS@ $(DLOPEN_LIBS) $(LTLIBOBJS) if SECURE_RPC @@ -34,6 +36,10 @@ if XDMCP libos_la_SOURCES += $(XDMCP_SRCS) endif +if X_PRIVSEP +libos_la_SOURCES += $(PRIVSEP_SRCS) +endif + EXTRA_DIST = $(SECURERPC_SRCS) $(XDMCP_SRCS) if SPECIAL_DTRACE_OBJECTS diff --git a/os/connection.c b/os/connection.c index d7e21f362..9b1ffad6a 100644 --- a/os/connection.c +++ b/os/connection.c @@ -26,13 +26,13 @@ Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. All Rights Reserved -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in +both that copyright notice and this permission notice appear in supporting documentation, and that the name of Digital not be used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. +software without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL @@ -343,6 +343,9 @@ InitParentProcess(void) RunFromSmartParent = TRUE; OsSignal(SIGUSR1, handler); ParentProcess = getppid(); +#ifdef X_PRIVSEP + priv_init_parent_process(ParentProcess); +#endif #endif } @@ -352,7 +355,11 @@ NotifyParentProcess(void) #if !defined(WIN32) if (RunFromSmartParent) { if (ParentProcess > 1) { - kill(ParentProcess, SIGUSR1); +#ifdef X_PRIVSEP + priv_signal_parent(); +#else + kill (ParentProcess, SIGUSR1); +#endif } } if (RunFromSigStopParent) @@ -611,8 +618,8 @@ AuthorizationIDOfClient(ClientPtr client) * CARD8 byteOrder; * BYTE pad; * CARD16 majorVersion, minorVersion; - * CARD16 nbytesAuthProto; - * CARD16 nbytesAuthString; + * CARD16 nbytesAuthProto; + * CARD16 nbytesAuthString; * } xConnClientPrefix; * * It is hoped that eventually one protocol will be agreed upon. In the @@ -937,7 +944,7 @@ CloseDownFileDescriptor(OsCommPtr oc) /***************** * CheckConnections - * Some connection has died, go find which one and shut it down + * Some connection has died, go find which one and shut it down * The file descriptor has been closed, but is still in AllClients. * If would truly be wonderful if select() would put the bogus * file descriptors in the exception mask, but nooooo. So we have @@ -998,7 +1005,7 @@ CheckConnections(void) /***************** * CloseDownConnection - * Delete client from AllClients and free resources + * Delete client from AllClients and free resources *****************/ void diff --git a/os/osdep.h b/os/osdep.h index fff088701..2e5a22907 100644 --- a/os/osdep.h +++ b/os/osdep.h @@ -269,4 +269,11 @@ extern void XdmcpRegisterBroadcastAddress(const struct sockaddr_in *addr); extern void XdmAuthenticationInit(const char *cookie, int cookie_length); #endif +#ifdef X_PRIVSEP +extern int priv_init(uid_t, gid_t); +extern int priv_open_device(const char *); +extern void priv_init_parent_process(pid_t); +extern void priv_signal_parent(void); +#endif + #endif /* _OSDEP_H_ */ diff --git a/os/osinit.c b/os/osinit.c index e2a220886..143e872e7 100644 --- a/os/osinit.c +++ b/os/osinit.c @@ -218,7 +218,7 @@ OsInit(void) if (strlen(display) + strlen(ADMPATH) + 1 < sizeof fname) snprintf(fname, sizeof(fname), ADMPATH, display); else - strcpy(fname, devnull); + strlcpy(fname, devnull, sizeof(fname)); /* * uses stdio to avoid os dependencies here, * a real os would use diff --git a/os/privsep.c b/os/privsep.c new file mode 100644 index 000000000..f31442194 --- /dev/null +++ b/os/privsep.c @@ -0,0 +1,366 @@ +/* $OpenBSD: privsep.c,v 1.25 2012/08/14 15:57:57 matthieu Exp $ */ +/* + * Copyright 2001 Niels Provos <provos@citi.umich.edu> + * All rights reserved. + * + * Copyright (c) 2002 Matthieu Herrb + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <sys/param.h> +#include <sys/uio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "os.h" +#include "osdep.h" + +enum cmd_types { + PRIV_OPEN_DEVICE, + PRIV_SIG_PARENT, +}; + +/* Command parameters */ +typedef struct priv_cmd { + int cmd; + int _pad; + union { + struct _open { + char path[MAXPATHLEN]; + } open; + } arg; +} priv_cmd_t; + + +static int priv_fd = -1; +static pid_t parent_pid = -1; +struct okdev { + const char *const name; + int flags; +} allowed_devices[] = { + /* Serial devices */ + {"/dev/wsmouse", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wsmouse0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wsmouse1", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wsmouse2", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wsmouse3", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/uhid0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/uhid1", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/uhid2", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/uhid3", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/tty00", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/tty01", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/tty02", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/tty03", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/tty04", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttya", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyb", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyc", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyd", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wskbd", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wskbd0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wskbd1", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wskbd2", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/wskbd3", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyC0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyC1", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyC2", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyC3", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyC4", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyC5", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyC6", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyC7", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyD0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyE0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyF0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyG0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyH0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyI0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/ttyJ0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/pci", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/agp0", O_RDWR | O_NONBLOCK | O_EXCL}, + {"/dev/drm0", O_RDWR }, + {"/dev/amdmsr", O_RDWR | O_EXCL}, + {NULL, 0} +}; + +/* return 1 if allowed to open said path */ +static struct okdev * +open_ok(const char *path) +{ + struct okdev *p; + struct stat sb; + + for (p = allowed_devices; p->name != NULL; p++) { + if (strcmp(path, p->name) == 0) { + if (stat(path, &sb) < 0) { + /* path is valid, but doesn't exist */ + return NULL; + } + if (sb.st_mode & S_IFCHR) { + /* File is a character device */ + return p; + } + } + } + /* path is not valid */ + return NULL; +} + +static void +send_fd(int s, int fd) +{ + struct msghdr msg; + union { + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; + struct cmsghdr *cmsg; + struct iovec vec; + int result = 0; + ssize_t n; + + memset(&msg, 0, sizeof(msg)); + + if (fd >= 0) { + msg.msg_control = &cmsgbuf.buf; + msg.msg_controllen = sizeof(cmsgbuf.buf); + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_len = CMSG_LEN(sizeof(int)); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + *(int *)CMSG_DATA(cmsg) = fd; + } else { + result = errno; + } + + vec.iov_base = &result; + vec.iov_len = sizeof(int); + msg.msg_iov = &vec; + msg.msg_iovlen = 1; + + if ((n = sendmsg(s, &msg, 0)) == -1) + warn("%s: sendmsg(%d)", __func__, s); + if (n != sizeof(int)) + warnx("%s: sendmsg: expected sent 1 got %ld", + __func__, (long)n); +} + +static int +receive_fd(int s) +{ + struct msghdr msg; + union { + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; + } cmsgbuf; + struct cmsghdr *cmsg; + struct iovec vec; + ssize_t n; + int result; + int fd; + + memset(&msg, 0, sizeof(msg)); + vec.iov_base = &result; + vec.iov_len = sizeof(int); + msg.msg_iov = &vec; + msg.msg_iovlen = 1; + msg.msg_control = &cmsgbuf.buf; + msg.msg_controllen = sizeof(cmsgbuf.buf); + + do + n = recvmsg(s, &msg, 0); + while (n == -1 && errno == EINTR); + + if (n != sizeof(int)) { + warnx("%s: recvmsg: expected received 1 got %ld", + __func__, (long)n); + return -1; + } + if (result == 0) { + cmsg = CMSG_FIRSTHDR(&msg); + if (cmsg == NULL) { + warnx("%s: no message header", __func__); + return -1; + } + if (cmsg->cmsg_type != SCM_RIGHTS) + warnx("%s: expected type %d got %d", __func__, + SCM_RIGHTS, cmsg->cmsg_type); + fd = (*(int *)CMSG_DATA(cmsg)); + return fd; + } else { + errno = result; + return -1; + } +} + +int +priv_init(uid_t uid, gid_t gid) +{ + int i, fd; + pid_t pid; + int socks[2]; + priv_cmd_t cmd; + struct okdev *dev; + + parent_pid = getppid(); + + /* Create sockets */ + if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, socks) == -1) { + return -1; + } + pid = fork(); + if (pid < 0) { + /* can't fork */ + return -1; + } + if (pid != 0) { + /* Father - drop privileges and return */ + if (setgroups(1, &gid) == -1) + return -1; + if (setegid(gid) == -1) + return -1; + if (setgid(gid) == -1) + return -1; + if (seteuid(uid) == -1) + return -1; + if (setuid(uid) == -1) + return -1; + close(socks[0]); + priv_fd = socks[1]; + return 0; + } + /* son */ + for (i = 1; i <= _NSIG; i++) + signal(i, SIG_DFL); + setproctitle("[priv]"); + close(socks[1]); + + while (1) { + if (read(socks[0], &cmd, sizeof(cmd)) == 0) { + exit(0); + } + switch (cmd.cmd) { + + case PRIV_OPEN_DEVICE: + if ((dev = open_ok(cmd.arg.open.path)) != NULL) { + fd = open(cmd.arg.open.path, dev->flags); + } else { + fd = -1; + errno = EPERM; + } + send_fd(socks[0], fd); + if (fd >= 0) + close(fd); + break; + case PRIV_SIG_PARENT: + if (parent_pid > 1) + kill(parent_pid, SIGUSR1); + break; + default: + errx(1, "%s: unknown command %d", __func__, cmd.cmd); + break; + } + } + _exit(1); +} + +/* Open file */ +int +priv_open_device(const char *path) +{ + priv_cmd_t cmd; + struct okdev *dev; + + if (priv_fd != -1) { + cmd.cmd = PRIV_OPEN_DEVICE; + strlcpy(cmd.arg.open.path, path, MAXPATHLEN); + write(priv_fd, &cmd, sizeof(cmd)); + return receive_fd(priv_fd); + } else { + if ((dev = open_ok(path)) != NULL) + return open(path, dev->flags); + else { + errno = EPERM; + return -1; + } + } +} + +void +priv_init_parent_process(pid_t ppid) +{ + parent_pid = ppid; +} + +/* send signal to parent process */ +void +priv_signal_parent(void) +{ + priv_cmd_t cmd; + + if (priv_fd != -1) { + if (parent_pid == -1) + warnx("parent_pid == -1\n"); + cmd.cmd = PRIV_SIG_PARENT; + write(priv_fd, &cmd, sizeof(cmd)); + } else + if (parent_pid > 1) + kill(parent_pid, SIGUSR1); +} + +#ifdef TEST +/* This is not a complete regression test */ +int +main(int argc, char *argv[]) +{ + int fd; + + if (priv_init(getuid(), getgid()) < 0) { + err(1, "priv_init"); + } + fd = priv_open_device("/dev/wsmouse"); + if (fd < 0) { + err(1, "priv_open_device"); + } + write(fd, "test\n", 5); + close(fd); + exit(0); +} +#endif diff --git a/os/utils.c b/os/utils.c index e33e4d22e..d7be5f6f2 100644 --- a/os/utils.c +++ b/os/utils.c @@ -264,8 +264,10 @@ LockServer(void) len += strlen(tmppath) + strlen(port) + strlen(LOCK_SUFFIX) + 1; if (len > sizeof(LockFile)) FatalError("Display name `%s' is too long\n", port); - (void) sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, port); - (void) sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port); + (void) snprintf(tmp, sizeof(tmp), + "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, port); + (void) snprintf(LockFile, sizeof(LockFile), + "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port); /* * Create a temporary file containing our PID. Attempt three times @@ -297,6 +299,10 @@ LockServer(void) FatalError("Could not create lock file in %s\n", tmp); snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long) getpid()); (void) write(lfd, pid_str, 11); +#ifdef __OpenBSD__ + /* if possible give away the lock file to the real uid/gid */ + fchown(lfd, getuid(), getgid()); +#endif (void) fchmod(lfd, 0444); (void) close(lfd); @@ -382,6 +388,14 @@ UnlockServer(void) } } +#ifdef X_PRIVSEP +int +ChownLock(uid_t uid, gid_t gid) +{ + return chown(LockFile, uid, gid); +} +#endif + /* Force connections to close on SIGHUP from init */ void @@ -513,7 +527,12 @@ UseMsg(void) ErrorF("-r turns off auto-repeat\n"); ErrorF("r turns on auto-repeat \n"); ErrorF("-render [default|mono|gray|color] set render color alloc policy\n"); +#ifndef __OpenBSD__ ErrorF("-retro start with classic stipple and cursor\n"); +#else + ErrorF("-retard start with black background " + "and no cursor\n"); +#endif ErrorF("-s # screen-saver timeout (minutes)\n"); ErrorF("-seat string seat to run on\n"); ErrorF("-t # default pointer threshold (pixels/t)\n"); @@ -776,8 +795,13 @@ ProcessCommandLine(int argc, char *argv[]) defaultKeyboardControl.autoRepeat = TRUE; else if (strcmp(argv[i], "-r") == 0) defaultKeyboardControl.autoRepeat = FALSE; +#ifndef __OpenBSD__ else if (strcmp(argv[i], "-retro") == 0) party_like_its_1989 = TRUE; +#else + else if ( strcmp( argv[i], "-retard") == 0) + party_like_its_1989 = FALSE; +#endif else if (strcmp(argv[i], "-s") == 0) { if (++i < argc) defaultScreenSaverTime = ((CARD32) atoi(argv[i])) * |