From f4092abdf94af6a99aff944d6264bc1284e8bdd4 Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Mon, 10 Oct 2011 17:43:39 +0200 Subject: Imported nx-X11-3.1.0-1.tar.gz Summary: Imported nx-X11-3.1.0-1.tar.gz Keywords: Imported nx-X11-3.1.0-1.tar.gz into Git repository --- .../Xserver/hw/xfree86/os-support/linux/Imakefile | 142 +++ .../hw/xfree86/os-support/linux/drm/Imakefile | 64 ++ .../hw/xfree86/os-support/linux/drm/drmmodule.c | 60 + .../hw/xfree86/os-support/linux/int10/Imakefile | 77 ++ .../hw/xfree86/os-support/linux/int10/linux.c | 649 +++++++++++ .../xfree86/os-support/linux/int10/vm86/Imakefile | 55 + .../os-support/linux/int10/vm86/linux_vm86.c | 302 +++++ .../os-support/linux/int10/x86emu/Imakefile | 86 ++ .../Xserver/hw/xfree86/os-support/linux/lnx.h | 55 + .../hw/xfree86/os-support/linux/lnxResource.c | 291 +++++ .../hw/xfree86/os-support/linux/lnx_KbdMap.c | 606 ++++++++++ .../Xserver/hw/xfree86/os-support/linux/lnx_acpi.c | 170 +++ .../Xserver/hw/xfree86/os-support/linux/lnx_agp.c | 371 +++++++ .../Xserver/hw/xfree86/os-support/linux/lnx_apm.c | 192 ++++ .../Xserver/hw/xfree86/os-support/linux/lnx_axp.c | 200 ++++ .../Xserver/hw/xfree86/os-support/linux/lnx_ev56.c | 151 +++ .../Xserver/hw/xfree86/os-support/linux/lnx_font.c | 291 +++++ .../Xserver/hw/xfree86/os-support/linux/lnx_ia64.c | 74 ++ .../Xserver/hw/xfree86/os-support/linux/lnx_init.c | 415 +++++++ .../Xserver/hw/xfree86/os-support/linux/lnx_io.c | 275 +++++ .../Xserver/hw/xfree86/os-support/linux/lnx_jstk.c | 188 ++++ .../Xserver/hw/xfree86/os-support/linux/lnx_kbd.c | 559 ++++++++++ .../Xserver/hw/xfree86/os-support/linux/lnx_kbd.h | 5 + .../Xserver/hw/xfree86/os-support/linux/lnx_kmod.c | 113 ++ .../hw/xfree86/os-support/linux/lnx_mouse.c | 206 ++++ .../Xserver/hw/xfree86/os-support/linux/lnx_pci.c | 230 ++++ .../hw/xfree86/os-support/linux/lnx_video.c | 1169 ++++++++++++++++++++ 27 files changed, 6996 insertions(+) create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/Imakefile create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx.h create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_KbdMap.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ia64.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.h create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c create mode 100644 nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c (limited to 'nx-X11/programs/Xserver/hw/xfree86/os-support/linux') diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/Imakefile new file mode 100644 index 000000000..8ef246842 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/Imakefile @@ -0,0 +1,142 @@ +XCOMM $XConsortium: Imakefile /main/10 1996/10/19 18:06:19 kaleb $ +XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile,v 3.45 2002/09/16 18:06:13 eich Exp $ + +#include + +#if BuildXInputExt +# if JoystickSupport + JOYSTICK_SRC = lnx_jstk.c +# endif +# if DoLoadableServer +SHARED_CFLAGS = PositionIndependentCFlags +# else +# if JoystickSupport + JOYSTICK_OBJ = lnx_jstk.o +# endif +# endif +#endif + +#if HasMTRRSupport +MTRRDEFINES = -DHAS_MTRR_SUPPORT +#endif + +DRI_SRC = sigio.c +DRI_OBJ = sigio.o + +MOUSESRC = lnx_mouse.c +MOUSEOBJ = lnx_mouse.o + +KBDSRC = lnx_kbd.c lnx_KbdMap.c at_scancode.c +KBDOBJ = lnx_kbd.o lnx_KbdMap.o at_scancode.o + +#if defined(i386Architecture) || defined(ia64Architecture) || defined(AMD64Architecture) +RES_SRCS=stdResource.c +RES_OBJS=stdResource.o +#else +RES_SRCS=lnxResource.c +RES_OBJS=lnxResource.o +#endif + +#if defined(AlphaArchitecture) +PLATFORM_SRC=lnx_ev56.c xf86Axp.c lnx_axp.c +PLATFORM_OBJ=lnx_ev56.o xf86Axp.o lnx_axp.o +#endif +#if defined (ia64Architecture) +PLATFORM_SRC=ia64Pci.c lnx_ia64.c +PLATFORM_OBJ=ia64Pci.o lnx_ia64.o +PLATFORM_DEFINES=-DOS_PROBE_PCI_CHIPSET=lnxProbePciChipset +#endif + +#if DoOSFontRestore +FONTSRC=lnx_font.c +FONTOBJ=lnx_font.o +# ifndef FontRestoreCheckOsVersion +# define FontRestoreCheckOsVersion YES +# endif +FONT_DEFINES=-DDO_OS_FONTRESTORE -DCHECK_OS_VERSION=FontRestoreCheckOsVersion +#endif + +SRCS = lnx_init.c lnx_video.c lnx_io.c libc_wrapper.c bios_mmap.c \ + VTsw_usl.c std_kbdEv.c posix_tty.c lnx_acpi.c $(MOUSESRC) \ + lnx_pci.c vidmem.c lnx_apm.c $(JOYSTICK_SRC) $(DRI_SRC) $(RES_SRCS) \ + $(PLATFORM_SRC) lnx_kmod.c lnx_agp.c $(FONTSRC) $(KBDSRC) /*wcHelper.c*/ + +OBJS = lnx_init.o lnx_video.o lnx_io.o libc_wrapper.o bios_mmap.o \ + VTsw_usl.o std_kbdEv.o posix_tty.o lnx_acpi.o $(MOUSEOBJ) \ + lnx_pci.o vidmem.o lnx_apm.o $(JOYSTICK_OBJ) $(DRI_OBJ) $(RES_OBJS) \ + $(PLATFORM_OBJ) lnx_kmod.o lnx_agp.o $(FONTOBJ) $(KBDOBJ) /*wcHelper.o*/ + +INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \ + -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(XF86OSSRC)/shared \ + -I$(XF86OSSRC)/bus -I$(DRMSRCDIR)/shared-core + +RESDEFINES = -DUSESTDRES + +DEFINES = $(MTRRDEFINES) $(RESDEFINES) $(PLATFORM_DEFINES) $(FONT_DEFINES) -DHAVE_SYSV_IPC + +#if defined(AlphaArchitecture) +SpecialObjectRule(lnx_ev56.o, lnx_ev56.c, -mcpu=ev56) +#endif + +#if DoOSFontRestore +SpecialObjectRule(VTsw_usl.o, VTsw_usl.c, -DOSHEADER=\"lnx.h\" -DOSSWITCHAWAY="lnx_switchaway()") +#endif + +SubdirLibraryRule($(OBJS)) +NormalLibraryObjectRule() + +#if BuildXF86DRI +DRISUBDIR = drm +#endif +TESTVAR = XF86INT10_BUILD + +#if XF86INT10_BUILD > X86EMU_GENERIC +INT10SUBDIR = int10 +#endif + +#if BuildXF86DRI || (XF86INT10_BUILD > X86EMU_GENERIC) +#define IHaveSubdirs +SUBDIRS = $(DRISUBDIR) $(INT10SUBDIR) +#endif + +#ifdef IHaveSubdirs +MakeSubdirs($(SUBDIRS)) +DependSubdirs($(SUBDIRS)) +#endif + +#if BuildXInputExt +# if DoLoadableServer +# if JoystickSupport +AllTarget(lnx_jstk.o) +#if 0 +InstallDynamicModule(lnx_jstk.o,$(MODULEDIR),input) +#endif +# endif +# endif +#endif + +LinkSourceFile(bios_mmap.c,../shared) +LinkSourceFile(std_kbdEv.c,../shared) +LinkSourceFile(at_scancode.c,../shared) +LinkSourceFile(posix_tty.c,../shared) +LinkSourceFile(libc_wrapper.c,../shared) +LinkSourceFile(vidmem.c,../shared) +LinkSourceFile(VTsw_usl.c,../shared) +LinkSourceFile(kmod_noop.c,../shared) + +LinkSourceFile($(DRI_SRC),../shared) + +#if defined(i386Architecture) || defined(ia64Architecture) || defined (AMD64Architecture) +LinkSourceFile(stdResource.c,../shared) +#endif +#if defined(AlphaArchitecture) +LinkSourceFile(xf86Axp.c,../shared) +#endif +#if defined(ia64Architecture) +LinkSourceFile(ia64Pci.c,../shared) +#endif +DependTarget() + +#if 0 +InstallDriverSDKDynamicModule(lnx_jstk.o,$(DRIVERSDKMODULEDIR)) +#endif diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile new file mode 100644 index 000000000..54511fbe0 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/Imakefile @@ -0,0 +1,64 @@ +XCOMM $XFree86: Imakefile,v 1.13 2002/10/30 12:52:32 alanh Exp $ + +#define IHaveModules +#include + +#if DoLoadableServer +MSRC = drmmodule.c +MOBJ = drmmodule.o +#endif + +#if BuildXF86DRI +#if HasMTRRSupport +MTRR_DEFINES = -DHAS_MTRR_SUPPORT +#endif + + SRCS = xf86drm.c \ + xf86drmHash.c \ + xf86drmRandom.c \ + xf86drmSL.c \ + $(MSRC) + + OBJS = xf86drm.o \ + xf86drmHash.o \ + xf86drmRandom.o \ + xf86drmSL.o \ + $(MOBJ) + +INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \ + -I$(XINCLUDESRC) -I$(EXTINCSRC) -I../.. -I$(DRMSRCDIR)/linux-core \ + -I$(DRMSRCDIR)/shared-core + +DEFINES = $(MTRR_DEFINES) $(GLX_DEFINES) + +LIBDRM_DIR = ../../../../../../../extras/drm/libdrm + +LinkSourceFile(xf86drm.c,$(LIBDRM_DIR)) +LinkSourceFile(xf86drmHash.c,$(LIBDRM_DIR)) +LinkSourceFile(xf86drmRandom.c,$(LIBDRM_DIR)) +LinkSourceFile(xf86drmSL.c,$(LIBDRM_DIR)) + +#if DoLoadableServer + +ModuleObjectRule() +LibraryModuleTarget(drm,$(OBJS)) +NormalLintTarget($(SRCS)) + +#ifdef LinuxArchitecture +InstallLibraryModule(drm,$(MODULEDIR),linux) +#endif + +#else + +SubdirLibraryRule($(OBJS)) +NormalLibraryObjectRule() + +#endif + + +DependTarget() +#endif + + + +InstallDriverSDKLibraryModule(drm,$(DRIVERSDKMODULEDIR),linux) diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c new file mode 100644 index 000000000..fd751e756 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c @@ -0,0 +1,60 @@ +/* drmmodule.c -- Module initialization + * Created: Fri Jun 4 09:05:48 1999 by faith@precisioninsight.com + * + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: Rickard E. (Rik) Faith + * + * $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/drmmodule.c,v 1.2 2000/02/23 04:47:22 martin Exp $ + * + */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include "xf86Module.h" + +static MODULESETUPPROTO(drmSetup); + +static XF86ModuleVersionInfo VersRec = +{ + "drm", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 1, 0, 0, + ABI_CLASS_EXTENSION, + ABI_EXTENSION_VERSION, + MOD_CLASS_NONE, + {0,0,0,0} +}; + +XF86ModuleData drmModuleData = { &VersRec, drmSetup, NULL }; + +static pointer +drmSetup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + return (void *)1; +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile new file mode 100644 index 000000000..6a23e75e5 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile @@ -0,0 +1,77 @@ +XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/int10/Imakefile,v 1.15 2003/06/12 14:12:36 eich Exp $ + +#define IHaveModules + +#include + +#define IHaveSubdirs + + +#if defined(XF86INT10_BUILD) && \ + ( !defined(DoLoadableServer) || !defined(Int10SubLibs)) +#define DoSingleLib +# if XF86INT10_BUILD == X86VM +EXPOBJS = vm86/helper_exec.o vm86/linux_vm86.o vm86/xf86int10.o +SUBDIRS = vm86 +# elif XF86INT10_BUILD == X86EMU_OS +EXPOBJS = x86emu/x86emu.o x86emu/xf86int10.o x86emu/helper_exec.o \ + x86emu/xf86x86emu.o +SUBDIRS = x86emu +# endif +#else +SUBDIRS = vm86 x86emu +LNXDEF = -DDoSubModules +#endif + + +#ifdef IHaveSubdirs +MakeSubdirs($(SUBDIRS)) +DependSubdirs($(SUBDIRS)) +#endif + +SRCS = pci.c xf86int10module.c helper_mem.c linux.c +OBJS = pci.o xf86int10module.o helper_mem.o linux.o + + +LinkSourceFile(helper_mem.c,$(XF86SRC)/int10) +LinkSourceFile(pci.c,$(XF86SRC)/int10) +LinkSourceFile(xf86int10module.c,$(XF86SRC)/int10) + + +INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86SRC)/int10 \ + -I$(XF86OSSRC) \ + -I$(SERVERSRC)/include -I$(XINCLUDESRC) -I$(X86EMUINCLUDES) + +DEFINES=-DHAVE_SYSV_IPC $(X86EMUDEFINES) $(EXTRADEFINES) + +#if defined(i386Architecture) || defined (AMD64Architecture) +EXTRADEFINES=-D_PC +#endif + + +SpecialObjectRule(linux.o, linux.c, -DHAVE_SYSV_IPC $(LNXDEF)) + + +#if defined(XF86INT10_BUILD) && XF86INT10_BUILD > X86EMU_GENERIC + +ModuleObjectRule() + +#if HasParallelMake && defined (DoSingleLib) +MakeMutex($(SUBDIRS) $(EXPOBJS) $(DONES)) +#endif + +LibraryModuleTarget(int10, $(OBJS) $(EXPOBJS)) + +InstallLibraryModule(int10,$(MODULEDIR),linux) + +all:: + @(set -x; cd ../..; \ + RemoveFile(LibraryTargetName(int10)); \ + $(LN) linux/int10/LibraryTargetName(int10) . ) + +InstallDriverSDKLibraryModule(int10,$(DRIVERSDKMODULEDIR),.) + +#endif + +DependTarget() + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c new file mode 100644 index 000000000..b8e821cd1 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c @@ -0,0 +1,649 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/int10/linux.c,v 1.32 2004/02/05 18:24:59 eich Exp $ */ +/* + * linux specific part of the int10 module + * Copyright 1999, 2000, 2001, 2002, 2003, 2004 Egbert Eich + */ +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include "xf86.h" +#include "xf86_OSproc.h" +#include "xf86_ansic.h" +#include "xf86Pci.h" +#include "compiler.h" +#define _INT10_PRIVATE +#include "xf86int10.h" +#ifdef __sparc__ +#define DEV_MEM "/dev/fb" +#else +#define DEV_MEM "/dev/mem" +#endif +#ifndef XFree86LOADER +#include +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif +#endif +#define ALLOC_ENTRIES(x) ((V_RAM / x) - 1) +#define SHMERRORPTR (pointer)(-1) + +static int counter = 0; +static unsigned long int10Generation = 0; + +static CARD8 read_b(xf86Int10InfoPtr pInt, int addr); +static CARD16 read_w(xf86Int10InfoPtr pInt, int addr); +static CARD32 read_l(xf86Int10InfoPtr pInt, int addr); +static void write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val); +static void write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val); +static void write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val); + +int10MemRec linuxMem = { + read_b, + read_w, + read_l, + write_b, + write_w, + write_l +}; + +typedef struct { + int lowMem; + int highMem; + char* base; + char* base_high; + int screen; + char* alloc; +} linuxInt10Priv; + +#if defined DoSubModules + +typedef enum { + INT10_NOT_LOADED, + INT10_LOADED_VM86, + INT10_LOADED_X86EMU, + INT10_LOAD_FAILED +} Int10LinuxSubModuleState; + +static Int10LinuxSubModuleState loadedSubModule = INT10_NOT_LOADED; + +static Int10LinuxSubModuleState int10LinuxLoadSubModule(ScrnInfoPtr pScrn); + +#endif /* DoSubModules */ + +xf86Int10InfoPtr +xf86InitInt10(int entityIndex) +{ + return xf86ExtendedInitInt10(entityIndex, 0); +} + +xf86Int10InfoPtr +xf86ExtendedInitInt10(int entityIndex, int Flags) +{ + xf86Int10InfoPtr pInt = NULL; + CARD8 *bios_base; + int screen; + int fd; + static void* vidMem = NULL; + static void* sysMem = NULL; + void* vMem = NULL; + void *options = NULL; + int low_mem; + int high_mem = -1; + char *base = SHMERRORPTR; + char *base_high = SHMERRORPTR; + int pagesize; + memType cs; + legacyVGARec vga; + xf86int10BiosLocation bios; + Bool videoBiosMapped = FALSE; + + if (int10Generation != serverGeneration) { + counter = 0; + int10Generation = serverGeneration; + } + + screen = (xf86FindScreenForEntity(entityIndex))->scrnIndex; + + options = xf86HandleInt10Options(xf86Screens[screen],entityIndex); + + if (int10skip(options)) { + xfree(options); + return NULL; + } + +#if defined DoSubModules + if (loadedSubModule == INT10_NOT_LOADED) + loadedSubModule = int10LinuxLoadSubModule(xf86Screens[screen]); + + if (loadedSubModule == INT10_LOAD_FAILED) + return NULL; +#endif + + if ((!vidMem) || (!sysMem)) { + if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { + if (!sysMem) { +#ifdef DEBUG + ErrorF("Mapping sys bios area\n"); +#endif + if ((sysMem = mmap((void *)(SYS_BIOS), BIOS_SIZE, + PROT_READ | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, SYS_BIOS)) + == MAP_FAILED) { + xf86DrvMsg(screen, X_ERROR, "Cannot map SYS BIOS\n"); + close(fd); + goto error0; + } + } + if (!vidMem) { +#ifdef DEBUG + ErrorF("Mapping VRAM area\n"); +#endif + if ((vidMem = mmap((void *)(V_RAM), VRAM_SIZE, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, V_RAM)) + == MAP_FAILED) { + xf86DrvMsg(screen, X_ERROR, "Cannot map V_RAM\n"); + close(fd); + goto error0; + } + } + close(fd); + } else { + xf86DrvMsg(screen, X_ERROR, "Cannot open %s\n", DEV_MEM); + goto error0; + } + } + + pInt = (xf86Int10InfoPtr)xnfcalloc(1, sizeof(xf86Int10InfoRec)); + pInt->scrnIndex = screen; + pInt->entityIndex = entityIndex; + if (!xf86Int10ExecSetup(pInt)) + goto error0; + pInt->mem = &linuxMem; + pagesize = getpagesize(); + pInt->private = (pointer)xnfcalloc(1, sizeof(linuxInt10Priv)); + ((linuxInt10Priv*)pInt->private)->screen = screen; + ((linuxInt10Priv*)pInt->private)->alloc = + (pointer)xnfcalloc(1, ALLOC_ENTRIES(pagesize)); + + if (!xf86IsEntityPrimary(entityIndex)) { +#ifdef DEBUG + ErrorF("Mapping high memory area\n"); +#endif + if ((high_mem = shmget(counter++, HIGH_MEM_SIZE, + IPC_CREAT | SHM_R | SHM_W)) == -1) { + if (errno == ENOSYS) + xf86DrvMsg(screen, X_ERROR, "shmget error\n Please reconfigure" + " your kernel to include System V IPC support\n"); + else + xf86DrvMsg(screen, X_ERROR, + "shmget(highmem) error: %s\n",strerror(errno)); + goto error1; + } + } else { +#ifdef DEBUG + ErrorF("Mapping Video BIOS\n"); +#endif + videoBiosMapped = TRUE; + if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { + if ((vMem = mmap((void *)(V_BIOS), SYS_BIOS - V_BIOS, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, V_BIOS)) + == MAP_FAILED) { + xf86DrvMsg(screen, X_ERROR, "Cannot map V_BIOS\n"); + close(fd); + goto error1; + } + close (fd); + } else + goto error1; + } + ((linuxInt10Priv*)pInt->private)->highMem = high_mem; + +#ifdef DEBUG + ErrorF("Mapping 640kB area\n"); +#endif + if ((low_mem = shmget(counter++, V_RAM, + IPC_CREAT | SHM_R | SHM_W)) == -1) { + xf86DrvMsg(screen, X_ERROR, + "shmget(lowmem) error: %s\n",strerror(errno)); + goto error2; + } + + ((linuxInt10Priv*)pInt->private)->lowMem = low_mem; + base = shmat(low_mem, 0, 0); + if (base == SHMERRORPTR) { + xf86DrvMsg(screen, X_ERROR, + "shmat(low_mem) error: %s\n",strerror(errno)); + goto error3; + } + ((linuxInt10Priv *)pInt->private)->base = base; + if (high_mem > -1) { + base_high = shmat(high_mem, 0, 0); + if (base_high == SHMERRORPTR) { + xf86DrvMsg(screen, X_ERROR, + "shmat(high_mem) error: %s\n",strerror(errno)); + goto error3; + } + ((linuxInt10Priv*)pInt->private)->base_high = base_high; + } else + ((linuxInt10Priv*)pInt->private)->base_high = NULL; + + if (!MapCurrentInt10(pInt)) + goto error3; + + Int10Current = pInt; + +#ifdef DEBUG + ErrorF("Mapping int area\n"); +#endif + if (xf86ReadBIOS(0, 0, (unsigned char *)0, LOW_PAGE_SIZE) < 0) { + xf86DrvMsg(screen, X_ERROR, "Cannot read int vect\n"); + goto error3; + } +#ifdef DEBUG + ErrorF("done\n"); +#endif + /* + * Read in everything between V_BIOS and SYS_BIOS as some system BIOSes + * have executable code there. Note that xf86ReadBIOS() can only bring in + * 64K bytes at a time. + */ + if (!videoBiosMapped) { + (void)memset((pointer)V_BIOS, 0, SYS_BIOS - V_BIOS); +#ifdef DEBUG + ErrorF("Reading BIOS\n"); +#endif + for (cs = V_BIOS; cs < SYS_BIOS; cs += V_BIOS_SIZE) + if (xf86ReadBIOS(cs, 0, (pointer)cs, V_BIOS_SIZE) < V_BIOS_SIZE) + xf86DrvMsg(screen, X_WARNING, + "Unable to retrieve all of segment 0x%06lX.\n", cs); +#ifdef DEBUG + ErrorF("done\n"); +#endif + } + + xf86int10ParseBiosLocation(options,&bios); + + if (xf86IsEntityPrimary(entityIndex) + && !(initPrimary(options))) { + if (bios.bus == BUS_ISA && bios.location.legacy) { + xf86DrvMsg(screen, X_CONFIG, + "Overriding BIOS location: 0x%x\n", + bios.location.legacy); + cs = bios.location.legacy >> 4; + bios_base = (unsigned char *)(cs << 4); + if (!int10_check_bios(screen, cs, bios_base)) { + xf86DrvMsg(screen, X_ERROR, + "No V_BIOS at specified address 0x%lx\n",cs << 4); + goto error3; + } + } else { + if (bios.bus == BUS_PCI) { + xf86DrvMsg(screen, X_WARNING, + "Option BiosLocation for primary device ignored: " + "It points to PCI.\n"); + xf86DrvMsg(screen, X_WARNING, + "You must set Option InitPrimary also\n"); + } + + cs = ((CARD16*)0)[(0x10<<1) + 1]; + + bios_base = (unsigned char *)(cs << 4); + + if (!int10_check_bios(screen, cs, bios_base)) { + cs = ((CARD16*)0)[(0x42 << 1) + 1]; + bios_base = (unsigned char *)(cs << 4); + if (!int10_check_bios(screen, cs, bios_base)) { + cs = V_BIOS >> 4; + bios_base = (unsigned char *)(cs << 4); + if (!int10_check_bios(screen, cs, bios_base)) { + xf86DrvMsg(screen, X_ERROR, "No V_BIOS found\n"); + goto error3; + } + } + } + } + + xf86DrvMsg(screen, X_INFO, "Primary V_BIOS segment is: 0x%lx\n", cs); + + pInt->BIOSseg = cs; + set_return_trap(pInt); +#ifdef _PC + pInt->Flags = Flags & (SET_BIOS_SCRATCH | RESTORE_BIOS_SCRATCH); + if (! (pInt->Flags & SET_BIOS_SCRATCH)) + pInt->Flags &= ~RESTORE_BIOS_SCRATCH; + xf86Int10SaveRestoreBIOSVars(pInt, TRUE); +#endif + } else { + EntityInfoPtr pEnt = xf86GetEntityInfo(pInt->entityIndex); + BusType location_type; + + if (bios.bus != BUS_NONE) { + switch (location_type = bios.bus) { + case BUS_PCI: + xf86DrvMsg(screen,X_CONFIG,"Overriding bios location: " + "PCI:%i:%i%i\n",bios.location.pci.bus, + bios.location.pci.dev,bios.location.pci.func); + break; + case BUS_ISA: + if (bios.location.legacy) + xf86DrvMsg(screen,X_CONFIG,"Overriding bios location: " + "Legacy:0x%x\n",bios.location.legacy); + else + xf86DrvMsg(screen,X_CONFIG,"Overriding bios location: " + "Legacy\n"); + break; + default: + break; + } + } else + location_type = pEnt->location.type; + + switch (location_type) { + case BUS_PCI: + { + int pci_entity; + + if (bios.bus == BUS_PCI) + pci_entity = xf86GetPciEntity(bios.location.pci.bus, + bios.location.pci.dev, + bios.location.pci.func); + else + pci_entity = pInt->entityIndex; + if (!mapPciRom(pci_entity, (unsigned char *)(V_BIOS))) { + xf86DrvMsg(screen, X_ERROR, "Cannot read V_BIOS\n"); + goto error3; + } + pInt->BIOSseg = V_BIOS >> 4; + break; + } + case BUS_ISA: + if (bios.bus == BUS_ISA && bios.location.legacy) { + cs = bios.location.legacy >> 4; + bios_base = (unsigned char *)(cs << 4); + if (!int10_check_bios(screen, cs, bios_base)) { + xf86DrvMsg(screen,X_ERROR,"No V_BIOS found " + "on override address %p\n",bios_base); + goto error3; + } + } else { + cs = ((CARD16*)0)[(0x10<<1)+1]; + bios_base = (unsigned char *)(cs << 4); + + if (!int10_check_bios(screen, cs, bios_base)) { + cs = ((CARD16*)0)[(0x42<<1)+1]; + bios_base = (unsigned char *)(cs << 4); + if (!int10_check_bios(screen, cs, bios_base)) { + cs = V_BIOS >> 4; + bios_base = (unsigned char *)(cs << 4); + if (!int10_check_bios(screen, cs, bios_base)) { + xf86DrvMsg(screen,X_ERROR,"No V_BIOS found\n"); + goto error3; + } + } + } + } + xf86DrvMsg(screen,X_INFO,"Primary V_BIOS segment is: 0x%lx\n",cs); + pInt->BIOSseg = cs; + break; + default: + goto error3; + } + xfree(pEnt); + pInt->num = 0xe6; + reset_int_vect(pInt); + set_return_trap(pInt); + LockLegacyVGA(pInt, &vga); + xf86ExecX86int10(pInt); + UnlockLegacyVGA(pInt, &vga); + } +#ifdef DEBUG + dprint(0xc0000, 0x20); +#endif + + xfree(options); + return pInt; + +error3: + if (base_high) + shmdt(base_high); + shmdt(base); + shmdt(0); + if (base_high) + shmdt((char*)HIGH_MEM); + shmctl(low_mem, IPC_RMID, NULL); + Int10Current = NULL; +error2: + if (high_mem > -1) + shmctl(high_mem, IPC_RMID,NULL); +error1: + if (vMem) + munmap(vMem, SYS_BIOS - V_BIOS); + xfree(((linuxInt10Priv*)pInt->private)->alloc); + xfree(pInt->private); +error0: + xfree(options); + xfree(pInt); + return NULL; +} + +Bool +MapCurrentInt10(xf86Int10InfoPtr pInt) +{ + pointer addr; + int fd = -1; + + if (Int10Current) { + shmdt(0); + if (((linuxInt10Priv*)Int10Current->private)->highMem >= 0) + shmdt((char*)HIGH_MEM); + else + munmap((pointer)V_BIOS, (SYS_BIOS - V_BIOS)); + } + addr = shmat(((linuxInt10Priv*)pInt->private)->lowMem, (char*)1, SHM_RND); + if (addr == SHMERRORPTR) { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot shmat() low memory\n"); + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "shmat(low_mem) error: %s\n",strerror(errno)); + return FALSE; + } + + if (((linuxInt10Priv*)pInt->private)->highMem >= 0) { + addr = shmat(((linuxInt10Priv*)pInt->private)->highMem, + (char*)HIGH_MEM, 0); + if (addr == SHMERRORPTR) { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "Cannot shmat() high memory\n"); + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "shmget error: %s\n",strerror(errno)); + return FALSE; + } + } else { + if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { + if (mmap((void *)(V_BIOS), SYS_BIOS - V_BIOS, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_SHARED | MAP_FIXED, fd, V_BIOS) + == MAP_FAILED) { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot map V_BIOS\n"); + close (fd); + return FALSE; + } + } else { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot open %s\n",DEV_MEM); + return FALSE; + } + close (fd); + } + + return TRUE; +} + +void +xf86FreeInt10(xf86Int10InfoPtr pInt) +{ + if (!pInt) + return; + +#ifdef _PC + xf86Int10SaveRestoreBIOSVars(pInt, FALSE); +#endif + if (Int10Current == pInt) { + shmdt(0); + if (((linuxInt10Priv*)pInt->private)->highMem >= 0) + shmdt((char*)HIGH_MEM); + else + munmap((pointer)V_BIOS, (SYS_BIOS - V_BIOS)); + Int10Current = NULL; + } + + if (((linuxInt10Priv*)pInt->private)->base_high) + shmdt(((linuxInt10Priv*)pInt->private)->base_high); + shmdt(((linuxInt10Priv*)pInt->private)->base); + shmctl(((linuxInt10Priv*)pInt->private)->lowMem, IPC_RMID, NULL); + if (((linuxInt10Priv*)pInt->private)->highMem >= 0) + shmctl(((linuxInt10Priv*)pInt->private)->highMem, IPC_RMID, NULL); + xfree(((linuxInt10Priv*)pInt->private)->alloc); + xfree(pInt->private); + xfree(pInt); +} + +void * +xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num, int *off) +{ + int pagesize = getpagesize(); + int num_pages = ALLOC_ENTRIES(pagesize); + int i, j; + + for (i = 0; i < (num_pages - num); i++) { + if (((linuxInt10Priv*)pInt->private)->alloc[i] == 0) { + for (j = i; j < (num + i); j++) + if ((((linuxInt10Priv*)pInt->private)->alloc[j] != 0)) + break; + if (j == (num + i)) + break; + else + i = i + num; + } + } + if (i == (num_pages - num)) + return NULL; + + for (j = i; j < (i + num); j++) + ((linuxInt10Priv*)pInt->private)->alloc[j] = 1; + + *off = (i + 1) * pagesize; + + return ((linuxInt10Priv*)pInt->private)->base + ((i + 1) * pagesize); +} + +void +xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num) +{ + int pagesize = getpagesize(); + int first = (((unsigned long)pbase + - (unsigned long)((linuxInt10Priv*)pInt->private)->base) + / pagesize) - 1; + int i; + + for (i = first; i < (first + num); i++) + ((linuxInt10Priv*)pInt->private)->alloc[i] = 0; +} + +static CARD8 +read_b(xf86Int10InfoPtr pInt, int addr) +{ + return *((CARD8 *)(memType)addr); +} + +static CARD16 +read_w(xf86Int10InfoPtr pInt, int addr) +{ + return *((CARD16 *)(memType)addr); +} + +static CARD32 +read_l(xf86Int10InfoPtr pInt, int addr) +{ + return *((CARD32 *)(memType)addr); +} + +static void +write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val) +{ + *((CARD8 *)(memType)addr) = val; +} + +static void +write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val) +{ + *((CARD16 *)(memType)addr) = val; +} + +static +void write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val) +{ + *((CARD32 *)(memType) addr) = val; +} + +pointer +xf86int10Addr(xf86Int10InfoPtr pInt, CARD32 addr) +{ + if (addr < V_RAM) + return ((linuxInt10Priv*)pInt->private)->base + addr; + else if (addr < V_BIOS) + return (pointer)(memType)addr; + else if (addr < SYS_BIOS) { + if (((linuxInt10Priv*)pInt->private)->base_high) + return (pointer)(((linuxInt10Priv*)pInt->private)->base_high + - V_BIOS + addr); + else + return (pointer) (memType)addr; + } else + return (pointer) (memType)addr; +} + +#if defined DoSubModules + +static Bool +vm86_tst(void) +{ + int __res; + +#ifdef __PIC__ + /* When compiling with -fPIC, we can't use asm constraint "b" because + %ebx is already taken by gcc. */ + __asm__ __volatile__("pushl %%ebx\n\t" + "movl %2,%%ebx\n\t" + "movl %1,%%eax\n\t" + "int $0x80\n\t" + "popl %%ebx" + :"=a" (__res) + :"n" ((int)113), "r" (NULL)); +#else + __asm__ __volatile__("int $0x80\n\t" + :"=a" (__res):"a" ((int)113), + "b" ((struct vm86_struct *)NULL)); +#endif + + if (__res < 0 && __res == -ENOSYS) + return FALSE; + + return TRUE; +} + +static Int10LinuxSubModuleState +int10LinuxLoadSubModule(ScrnInfoPtr pScrn) +{ + if (vm86_tst()) { + if (xf86LoadSubModule(pScrn,"vm86")) + return INT10_LOADED_VM86; + } + if (xf86LoadSubModule(pScrn,"x86emu")) + return INT10_LOADED_X86EMU; + + return INT10_LOAD_FAILED; +} + +#endif /* DoSubModules */ diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile new file mode 100644 index 000000000..522369894 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile @@ -0,0 +1,55 @@ +XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/Imakefile,v 1.2 2003/06/12 14:12:37 eich Exp $ + +#define IHaveModules + +#include + +SRCS1 = linux_vm86.c helper_exec.c xf86int10.c +OBJS1 = linux_vm86.o helper_exec.o xf86int10.o + +#if defined(DoLoadableServer) && defined(Int10SubLibs) +SUBMODSRCS = xf86vm86module.c +SUBMODOBJS = xf86vm86module.o +#endif + +OBJS = $(SUBMODOBJS) $(OBJS1) +SRCS = $(SUBMODSRCS) $(SRCS1) + +LinkSourceFile(helper_exec.c,$(XF86SRC)/int10) +LinkSourceFile(xf86int10.c,$(XF86SRC)/int10) +LinkFile(xf86vm86module.c,$(XF86SRC)/int10/xf86int10module.c) + + +INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86SRC)/int10 \ + -I$(XF86OSSRC) \ + -I$(SERVERSRC)/include -I$(XINCLUDESRC) -I$(X86EMUINCLUDES) + +DEFINES=-DHAVE_SYSV_IPC $(X86EMUDEFINES) $(EXTRADEFINES) + +#if defined(i386Architecture) || defined (AMD64Architecture) +EXTRADEFINES=-D_PC +#endif + +SpecialObjectRule(xf86vm86module.o, xf86vm86module.c, -DMOD_NAME=vm86) +SpecialObjectRule(helper_exec.o, helper_exec.c, -D_VM86_LINUX) +SpecialObjectRule(xf86int10.o, xf86int10.c, -D_VM86_LINUX -DSHOW_ALL_DEVICES) +SpecialObjectRule(linux_vm86.o, linux_vm86.c, -D_VM86_LINUX) + +ModuleObjectRule() + +#if defined(DoLoadableServer) && defined(Int10SubLibs) +LibraryModuleTarget(vm86, $(OBJS)) +InstallLibraryModule(vm86,$(MODULEDIR),linux) + +all:: + @(set -x; cd ../..; \ + RemoveFile(LibraryTargetName(vm86)); \ + $(LN) linux/int10/vm86/LibraryTargetName(vm86) . ) + +InstallDriverSDKLibraryModule(vm86,$(DRIVERSDKMODULEDIR),.) +#else +SubdirLibraryRule($(OBJS)) +#endif + +DependTarget() + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c new file mode 100644 index 000000000..e99cde8da --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c @@ -0,0 +1,302 @@ +/* $XFree86$ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include "xf86.h" +#include "xf86_OSproc.h" +#include "xf86_ansic.h" +#include "xf86Pci.h" +#include "compiler.h" +#define _INT10_PRIVATE +#include "xf86int10.h" + +#define REG pInt + +#ifdef _VM86_LINUX +#include "int10Defines.h" + +static int vm86_rep(struct vm86_struct *ptr); +static struct vm86_struct vm86_s; + +Bool +xf86Int10ExecSetup(xf86Int10InfoPtr pInt) +{ +#define VM86S ((struct vm86_struct *)pInt->cpuRegs) + + pInt->cpuRegs = &vm86_s; + VM86S->flags = 0; + VM86S->screen_bitmap = 0; + VM86S->cpu_type = CPU_586; + memset(&VM86S->int_revectored, 0xff, sizeof(VM86S->int_revectored)); + memset(&VM86S->int21_revectored, 0xff, sizeof(VM86S->int21_revectored)); + return TRUE; +} + +/* get the linear address */ +#define LIN_PREF_SI ((pref_seg << 4) + X86_SI) +#define LWECX ((prefix66 ^ prefix67) ? X86_ECX : X86_CX) +#define LWECX_ZERO {if (prefix66 ^ prefix67) X86_ECX = 0; else X86_CX = 0;} +#define DF (1 << 10) + +/* vm86 fault handling */ +static Bool +vm86_GP_fault(xf86Int10InfoPtr pInt) +{ + unsigned char *csp, *lina; + CARD32 org_eip; + int pref_seg; + int done, is_rep, prefix66, prefix67; + + csp = lina = SEG_ADR((unsigned char *), X86_CS, IP); + + is_rep = 0; + prefix66 = prefix67 = 0; + pref_seg = -1; + + /* eat up prefixes */ + done = 0; + do { + switch (MEM_RB(pInt, (int)csp++)) { + case 0x66: /* operand prefix */ prefix66=1; break; + case 0x67: /* address prefix */ prefix67=1; break; + case 0x2e: /* CS */ pref_seg=X86_CS; break; + case 0x3e: /* DS */ pref_seg=X86_DS; break; + case 0x26: /* ES */ pref_seg=X86_ES; break; + case 0x36: /* SS */ pref_seg=X86_SS; break; + case 0x65: /* GS */ pref_seg=X86_GS; break; + case 0x64: /* FS */ pref_seg=X86_FS; break; + case 0xf0: /* lock */ break; + case 0xf2: /* repnz */ + case 0xf3: /* rep */ is_rep=1; break; + default: done=1; + } + } while (!done); + csp--; /* oops one too many */ + org_eip = X86_EIP; + X86_IP += (csp - lina); + + switch (MEM_RB(pInt, (int)csp)) { + case 0x6c: /* insb */ + /* NOTE: ES can't be overwritten; prefixes 66,67 should use esi,edi,ecx + * but is anyone using extended regs in real mode? */ + /* WARNING: no test for DI wrapping! */ + X86_EDI += port_rep_inb(pInt, X86_DX, SEG_EADR((CARD32), X86_ES, DI), + X86_FLAGS & DF, is_rep ? LWECX : 1); + if (is_rep) LWECX_ZERO; + X86_IP++; + break; + + case 0x6d: /* (rep) insw / insd */ + /* NOTE: ES can't be overwritten */ + /* WARNING: no test for _DI wrapping! */ + if (prefix66) { + X86_DI += port_rep_inl(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI), + X86_EFLAGS & DF, is_rep ? LWECX : 1); + } + else { + X86_DI += port_rep_inw(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI), + X86_FLAGS & DF, is_rep ? LWECX : 1); + } + if (is_rep) LWECX_ZERO; + X86_IP++; + break; + + case 0x6e: /* (rep) outsb */ + if (pref_seg < 0) pref_seg = X86_DS; + /* WARNING: no test for _SI wrapping! */ + X86_SI += port_rep_outb(pInt, X86_DX, (CARD32)LIN_PREF_SI, + X86_FLAGS & DF, is_rep ? LWECX : 1); + if (is_rep) LWECX_ZERO; + X86_IP++; + break; + + case 0x6f: /* (rep) outsw / outsd */ + if (pref_seg < 0) pref_seg = X86_DS; + /* WARNING: no test for _SI wrapping! */ + if (prefix66) { + X86_SI += port_rep_outl(pInt, X86_DX, (CARD32)LIN_PREF_SI, + X86_EFLAGS & DF, is_rep ? LWECX : 1); + } + else { + X86_SI += port_rep_outw(pInt, X86_DX, (CARD32)LIN_PREF_SI, + X86_FLAGS & DF, is_rep ? LWECX : 1); + } + if (is_rep) LWECX_ZERO; + X86_IP++; + break; + + case 0xe5: /* inw xx, inl xx */ + if (prefix66) X86_EAX = x_inl(csp[1]); + else X86_AX = x_inw(csp[1]); + X86_IP += 2; + break; + + case 0xe4: /* inb xx */ + X86_AL = x_inb(csp[1]); + X86_IP += 2; + break; + + case 0xed: /* inw dx, inl dx */ + if (prefix66) X86_EAX = x_inl(X86_DX); + else X86_AX = x_inw(X86_DX); + X86_IP += 1; + break; + + case 0xec: /* inb dx */ + X86_AL = x_inb(X86_DX); + X86_IP += 1; + break; + + case 0xe7: /* outw xx */ + if (prefix66) x_outl(csp[1], X86_EAX); + else x_outw(csp[1], X86_AX); + X86_IP += 2; + break; + + case 0xe6: /* outb xx */ + x_outb(csp[1], X86_AL); + X86_IP += 2; + break; + + case 0xef: /* outw dx */ + if (prefix66) x_outl(X86_DX, X86_EAX); + else x_outw(X86_DX, X86_AX); + X86_IP += 1; + break; + + case 0xee: /* outb dx */ + x_outb(X86_DX, X86_AL); + X86_IP += 1; + break; + + case 0xf4: +#ifdef DEBUG + ErrorF("hlt at %p\n", lina); +#endif + return FALSE; + + case 0x0f: + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "CPU 0x0f Trap at CS:EIP=0x%4.4x:0x%8.8lx\n", X86_CS, X86_EIP); + goto op0ferr; + + default: + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown reason for exception\n"); + + op0ferr: + dump_registers(pInt); + stack_trace(pInt); + dump_code(pInt); + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "cannot continue\n"); + return FALSE; + } /* end of switch() */ + return TRUE; +} + +static int +do_vm86(xf86Int10InfoPtr pInt) +{ + int retval, signo; + + xf86InterceptSignals(&signo); + retval = vm86_rep(VM86S); + xf86InterceptSignals(NULL); + + if (signo >= 0) { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "vm86() syscall generated signal %d.\n", signo); + dump_registers(pInt); + dump_code(pInt); + stack_trace(pInt); + return 0; + } + + switch (VM86_TYPE(retval)) { + case VM86_UNKNOWN: + if (!vm86_GP_fault(pInt)) return 0; + break; + case VM86_STI: + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "vm86_sti :-((\n"); + dump_registers(pInt); + dump_code(pInt); + stack_trace(pInt); + return 0; + case VM86_INTx: + pInt->num = VM86_ARG(retval); + if (!int_handler(pInt)) { + xf86DrvMsg(pInt->scrnIndex, X_ERROR, + "Unknown vm86_int: 0x%X\n\n", VM86_ARG(retval)); + dump_registers(pInt); + dump_code(pInt); + stack_trace(pInt); + return 0; + } + /* I'm not sure yet what to do if we can handle ints */ + break; + case VM86_SIGNAL: + return 1; + /* + * we used to warn here and bail out - but now the sigio stuff + * always fires signals at us. So we just ignore them for now. + */ + xf86DrvMsg(pInt->scrnIndex, X_WARNING, "received signal\n"); + return 0; + default: + xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown type(0x%x)=0x%x\n", + VM86_ARG(retval), VM86_TYPE(retval)); + dump_registers(pInt); + dump_code(pInt); + stack_trace(pInt); + return 0; + } + + return 1; +} + +void +xf86ExecX86int10(xf86Int10InfoPtr pInt) +{ + int sig = setup_int(pInt); + + if (int_handler(pInt)) + while(do_vm86(pInt)) {}; + + finish_int(pInt, sig); +} + +static int +vm86_rep(struct vm86_struct *ptr) +{ + int __res; + +#ifdef __PIC__ + /* When compiling with -fPIC, we can't use asm constraint "b" because + %ebx is already taken by gcc. */ + __asm__ __volatile__("pushl %%ebx\n\t" + "push %%gs\n\t" + "movl %2,%%ebx\n\t" + "movl %1,%%eax\n\t" + "int $0x80\n\t" + "pop %%gs\n\t" + "popl %%ebx" + :"=a" (__res) + :"n" ((int)113), "r" ((struct vm86_struct *)ptr)); +#else + __asm__ __volatile__("push %%gs\n\t" + "int $0x80\n\t" + "pop %%gs" + :"=a" (__res):"a" ((int)113), + "b" ((struct vm86_struct *)ptr)); +#endif + + if (__res < 0) { + errno = -__res; + __res = -1; + } + else errno = 0; + return __res; +} + +#endif diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile new file mode 100644 index 000000000..8a0dc4463 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile @@ -0,0 +1,86 @@ +XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/int10/x86emu/Imakefile,v 1.2 2003/06/12 14:12:37 eich Exp $ + +#define IHaveModules + +#include + +SRCS1 = xf86x86emu.c helper_exec.c xf86int10.c +OBJS1 = xf86x86emu.o helper_exec.o xf86int10.o + +#if defined(DoLoadableServer) && defined(Int10SubLibs) +SUBMODSRCS = xf86x86emumodule.c +SUBMODOBJS = xf86x86emumodule.o +#endif + +SRCS2 = $(SUBMODSRCS) $(SRCS1) +OBJS2 = $(SUBMODOBJS) $(OBJS1) + +LinkSourceFile(helper_exec.c,$(XF86SRC)/int10) +LinkSourceFile(xf86int10.c,$(XF86SRC)/int10) +LinkSourceFile(xf86x86emu.c,$(XF86SRC)/int10) +LinkFile(xf86x86emumodule.c,$(XF86SRC)/int10/xf86int10module.c) + + +INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86SRC)/int10 \ + -I$(XF86OSSRC) \ + -I$(SERVERSRC)/include -I$(XINCLUDESRC) -I$(X86EMUINCLUDES) + +DEFINES=-DHAVE_SYSV_IPC $(X86EMUDEFINES) $(EXTRADEFINES) + +#if defined(i386Architecture) || defined (AMD64Architecture) +EXTRADEFINES=-D_PC +#endif + +SpecialObjectRule(xf86x86emumodule.o, xf86x86emumodule.c, -DMOD_NAME=x86emu) +SpecialObjectRule(helper_exec.o, helper_exec.c, -D_X86EMU) +SpecialObjectRule(xf86int10.o, xf86int10.c, -D_X86EMU -DSHOW_ALL_DEVICES) +SpecialObjectRule(linux.o, linux.c, -D_X86EMU -DHAVE_SYSV_IPC) + +X86TOPDIR = $(TOP)/extras/x86emu +X86SRCDIR = $(X86TOPDIR)/src/x86emu +X86EMUINCLUDES = $(X86TOPDIR)/include -I$(X86SRCDIR) +# if DoLoadableServer +X86EMUMODDEFS = -DNO_SYS_HEADERS +# endif + +X86EMUDEFINES = -D__DRIVER__ -DFORCE_POST -D_CEXPORT= -DNO_LONG_LONG $(X86EMUMODDEFS) + +#if !defined(X86EMU_LIBPATH) +X86EMUSRCS = x86emu.c +X86EMUOBJS = x86emu.o + +LinkSourceFile(x86emu.c,$(XF86SRC)/int10) +LinkSourceFile(debug.c,$(X86SRCDIR)) +LinkSourceFile(decode.c,$(X86SRCDIR)) +LinkSourceFile(fpu.c,$(X86SRCDIR)) +LinkSourceFile(ops.c,$(X86SRCDIR)) +LinkSourceFile(ops2.c,$(X86SRCDIR)) +LinkSourceFile(prim_ops.c,$(X86SRCDIR)) +LinkSourceFile(sys.c,$(X86SRCDIR)) +#else +BuildObjectFromLibraryWithPath(X86EMU_LIBPATH,x86emu,x86emu) +X86EMUOBJS = x86emu.o +#endif + +SRCS = $(SRCS2) $(X86EMUSRCS) +OBJS = $(OBJS2) $(X86EMUOBJS) + +ModuleObjectRule() + +#if defined(DoLoadableServer) && defined(Int10SubLibs) +LibraryModuleTarget(x86emu, $(OBJS)) + +InstallLibraryModule(x86emu,$(MODULEDIR),linux) + +all:: + @(set -x; cd ../..; \ + RemoveFile(LibraryTargetName(x86emu)); \ + $(LN) linux/int10/x86emu/LibraryTargetName(x86emu) . ) + +InstallDriverSDKLibraryModule(x86emu,$(DRIVERSDKMODULEDIR),.) +#else +SubdirLibraryRule($(OBJS)) +#endif + +DependTarget() + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx.h new file mode 100644 index 000000000..68ad34011 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx.h @@ -0,0 +1,55 @@ +/* $XFree86: Exp $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#ifndef LNX_H_ +# ifdef __alpha__ +extern unsigned long _bus_base __P ((void)) __attribute__ ((const)); +extern unsigned long _bus_base_sparse __P ((void)) __attribute__ ((const)); +extern int iopl __P ((int __level)); + +/* new pciconfig_iobase syscall added in 2.2.15 and 2.3.99 */ +# include +# include +extern long (*_iobase)(unsigned, int, int, int); + +/* + * _iobase deals with the case the __NR_pciconfig_iobase is either undefined + * or unsupported by the kernel, but we need to make sure that the `which' + * argument symbols are defined. + */ +# ifndef IOBASE_HOSE +# define IOBASE_HOSE 0 +# endif +# ifndef IOBASE_SPARSE_MEM +# define IOBASE_SPARSE_MEM 1 +# endif +# ifndef IOBASE_DENSE_MEM +# define IOBASE_DENSE_MEM 2 +# endif +# ifndef IOBASE_SPARSE_IO +# define IOBASE_SPARSE_IO 3 +# endif +# ifndef IOBASE_DENSE_IO +# define IOBASE_DENSE_IO 4 +# endif +# ifndef IOBASE_ROOT_BUS +# define IOBASE_ROOT_BUS 5 +# endif +# ifndef IOBASE_FROM_HOSE +# define IOBASE_FROM_HOSE 0x10000 +# endif +# endif /* __alpha__ */ + +# if defined(DO_OS_FONTRESTORE) +Bool lnx_savefont(void); +Bool lnx_restorefont(void); +Bool lnx_switchaway(void); +void lnx_freefontdata(void); +# endif + +#define LNX_H_ + +#endif diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c new file mode 100644 index 000000000..690d3bc8f --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c @@ -0,0 +1,291 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c,v 3.18 2002/01/25 21:56:19 tsi Exp $ */ + +/* Resource information code */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86Privstr.h" +#include "xf86Pci.h" +#include "xf86Resources.h" +#define NEED_OS_RAC_PROTOS +#include "xf86_OSlib.h" +#include "lnx.h" + +/* Avoid Imakefile changes */ +#include "bus/Pci.h" + +resRange PciAvoid[] = +{ +#if !defined(__sparc__) || !defined(INCLUDE_XF86_NO_DOMAIN) + _PCI_AVOID_PC_STYLE, +#endif + _END +}; + +#ifdef INCLUDE_XF86_NO_DOMAIN + +#ifdef __alpha__ + +resPtr +xf86BusAccWindowsFromOS(void) +{ + resPtr ret = NULL; + resRange range; + + RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + + RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock); + ret = xf86AddResToList(ret, &range, -1); + return ret; +} + +resPtr +xf86PciBusAccWindowsFromOS(void) +{ + resPtr ret = NULL; + resRange range; + /* + * On the Alpha the first 16MB of every 128 Mb segment in + * sparse address space are an image of the ISA bus range + */ + if (_bus_base_sparse()) { + RANGE(range, 0x00000000, 0x07ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x09000000, 0x0fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x11000000, 0x17ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x19000000, 0x1fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x21000000, 0x27ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x29000000, 0x2fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x31000000, 0x37ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x39000000, 0x3fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x41000000, 0x47ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x49000000, 0x4fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x51000000, 0x57ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x59000000, 0x5fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x61000000, 0x67ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x69000000, 0x6fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x71000000, 0x77ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x79000000, 0x7fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x81000000, 0x87ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x89000000, 0x8fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x91000000, 0x97ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x99000000, 0x9fffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xa1000000, 0xa7ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xa9000000, 0xafffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xb1000000, 0xb7ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xb9000000, 0xbfffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xc1000000, 0xc7ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xc9000000, 0xcfffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xd1000000, 0xd7ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xd9000000, 0xdfffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xe1000000, 0xe7ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xe9000000, 0xefffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xf1000000, 0xf7ffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xf9000000, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + } else { + RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + } + RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock); + ret = xf86AddResToList(ret, &range, -1); + return ret; +} + +#ifdef INCLUDE_UNUSED + +resPtr +xf86IsaBusAccWindowsFromOS(void) +{ + resPtr ret = NULL; + resRange range; + + RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + + RANGE(range, 0x00000000, 0xffffffff, ResExcIoBlock); + ret = xf86AddResToList(ret, &range, -1); + return ret; +} + +#endif /* INCLUDE_UNUSED */ + +resPtr +xf86AccResFromOS(resPtr ret) +{ + resRange range; + + /* + * Fallback is to claim the following areas: + * + * 0x000c0000 - 0x000effff location of VGA and other extensions ROMS + */ + + RANGE(range, 0x000c0000, 0x000effff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + + /* + * Fallback would be to claim well known ports in the 0x0 - 0x3ff range + * along with their sparse I/O aliases, but that's too imprecise. Instead + * claim a bare minimum here. + */ + RANGE(range, 0x00000000, 0x000000ff, ResExcIoBlock); /* For mainboard */ + ret = xf86AddResToList(ret, &range, -1); + + /* + * At minimum, the top and bottom resources must be claimed, so that + * resources that are (or appear to be) unallocated can be relocated. + */ + RANGE(range, 0x00000000, 0x00000000, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xffffffff, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); +/* RANGE(range, 0x00000000, 0x00000000, ResExcIoBlock); + ret = xf86AddResToList(ret, &range, -1); */ + RANGE(range, 0xffffffff, 0xffffffff, ResExcIoBlock); + ret = xf86AddResToList(ret, &range, -1); + + /* XXX add others */ + return ret; +} + +#elif defined(__powerpc__) || \ + defined(__sparc__) || \ + defined(__mips__) || \ + defined(__sh__) || \ + defined(__mc68000__) || \ + defined(__arm__) || \ + defined(__s390__) || \ + defined(__hppa__) + + /* + * XXX this isn't exactly correct but it will get the server working + * for now until we get something better. + */ + +resPtr +xf86BusAccWindowsFromOS(void) +{ + resPtr ret = NULL; + resRange range; + + RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + +#if defined(__sparc__) || defined(__powerpc__) + RANGE(range, 0x00000000, 0x00ffffff, ResExcIoBlock); +#else + RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock); +#endif + ret = xf86AddResToList(ret, &range, -1); + return ret; +} + +resPtr +xf86PciBusAccWindowsFromOS(void) +{ + resPtr ret = NULL; + resRange range; + + RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + +#if defined(__sparc__) || defined(__powerpc__) + RANGE(range, 0x00000000, 0x00ffffff, ResExcIoBlock); +#else + RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock); +#endif + ret = xf86AddResToList(ret, &range, -1); + return ret; +} + +#ifdef INCLUDE_UNUSED + +resPtr +xf86IsaBusAccWindowsFromOS(void) +{ + resPtr ret = NULL; + resRange range; + + RANGE(range, 0x00000000, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + +#if defined(__sparc__) || defined(__powerpc__) + RANGE(range, 0x00000000, 0x00ffffff, ResExcIoBlock); +#else + RANGE(range, 0x00000000, 0x0000ffff, ResExcIoBlock); +#endif + ret = xf86AddResToList(ret, &range, -1); + return ret; +} + +#endif /* INCLUDE_UNUSED */ + +resPtr +xf86AccResFromOS(resPtr ret) +{ + resRange range; + + /* + * At minimum, the top and bottom resources must be claimed, so that + * resources that are (or appear to be) unallocated can be relocated. + */ + RANGE(range, 0x00000000, 0x00000000, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0xffffffff, 0xffffffff, ResExcMemBlock); + ret = xf86AddResToList(ret, &range, -1); + RANGE(range, 0x00000000, 0x00000000, ResExcIoBlock); + ret = xf86AddResToList(ret, &range, -1); +#if defined(__sparc__) || defined(__powerpc__) + RANGE(range, 0x00ffffff, 0x00ffffff, ResExcIoBlock); +#else + RANGE(range, 0x0000ffff, 0x0000ffff, ResExcIoBlock); +#endif + ret = xf86AddResToList(ret, &range, -1); + + return ret; +} + +#else + +#error : Put your platform dependent code here!! + +#endif + +#endif /* INCLUDE_XF86_NO_DOMAIN */ diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_KbdMap.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_KbdMap.c new file mode 100644 index 000000000..3a5a57b8c --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_KbdMap.c @@ -0,0 +1,606 @@ +/* $XFree86$ */ + +/* + * Slightly modified xf86KbdLnx.c which is + * + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include +#include "input.h" +#include "scrnintstr.h" + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86Xinput.h" +#include "xf86OSKbd.h" +#include "atKeynames.h" + +#include "xf86Keymap.h" + +#include "lnx_kbd.h" + +/*ARGSUSED*/ + +/* + * KbdGetMapping -- + * Get the national keyboard mapping. The keyboard type is set, a new map + * and the modifiermap is computed. + */ + +static void readKernelMapping(InputInfoPtr pInfo, + KeySymsPtr pKeySyms, CARD8 *pModMap); +void +KbdGetMapping (InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + KeySym *k; + char type; + int i; + + readKernelMapping(pInfo, pKeySyms, pModMap); + + /* + * compute the modifier map + */ + for (i = 0; i < MAP_LENGTH; i++) + pModMap[i] = NoSymbol; /* make sure it is restored */ + + for (k = map, i = MIN_KEYCODE; + i < (NUM_KEYCODES + MIN_KEYCODE); + i++, k += 4) + + switch(*k) { + + case XK_Shift_L: + case XK_Shift_R: + pModMap[i] = ShiftMask; + break; + + case XK_Control_L: + case XK_Control_R: + pModMap[i] = ControlMask; + break; + + case XK_Caps_Lock: + pModMap[i] = LockMask; + break; + + case XK_Alt_L: + case XK_Alt_R: + pModMap[i] = AltMask; + break; + + case XK_Num_Lock: + pModMap[i] = NumLockMask; + break; + + case XK_Scroll_Lock: + pModMap[i] = ScrollLockMask; + break; + + /* kana support */ + case XK_Kana_Lock: + case XK_Kana_Shift: + pModMap[i] = KanaMask; + break; + + /* alternate toggle for multinational support */ + case XK_Mode_switch: + pModMap[i] = AltLangMask; + break; + + } + + pKbd->kbdType = ioctl(pInfo->fd, KDGKBTYPE, &type) != -1 ? type : KB_101; + + pKeySyms->map = map; + pKeySyms->mapWidth = GLYPHS_PER_KEY; + pKeySyms->minKeyCode = MIN_KEYCODE; + pKeySyms->maxKeyCode = MAX_KEYCODE; +} + +#include + +static KeySym linux_to_x[256] = { + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + XK_BackSpace, XK_Tab, XK_Linefeed, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, XK_Escape, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + XK_space, XK_exclam, XK_quotedbl, XK_numbersign, + XK_dollar, XK_percent, XK_ampersand, XK_apostrophe, + XK_parenleft, XK_parenright, XK_asterisk, XK_plus, + XK_comma, XK_minus, XK_period, XK_slash, + XK_0, XK_1, XK_2, XK_3, + XK_4, XK_5, XK_6, XK_7, + XK_8, XK_9, XK_colon, XK_semicolon, + XK_less, XK_equal, XK_greater, XK_question, + XK_at, XK_A, XK_B, XK_C, + XK_D, XK_E, XK_F, XK_G, + XK_H, XK_I, XK_J, XK_K, + XK_L, XK_M, XK_N, XK_O, + XK_P, XK_Q, XK_R, XK_S, + XK_T, XK_U, XK_V, XK_W, + XK_X, XK_Y, XK_Z, XK_bracketleft, + XK_backslash, XK_bracketright,XK_asciicircum, XK_underscore, + XK_grave, XK_a, XK_b, XK_c, + XK_d, XK_e, XK_f, XK_g, + XK_h, XK_i, XK_j, XK_k, + XK_l, XK_m, XK_n, XK_o, + XK_p, XK_q, XK_r, XK_s, + XK_t, XK_u, XK_v, XK_w, + XK_x, XK_y, XK_z, XK_braceleft, + XK_bar, XK_braceright, XK_asciitilde, XK_BackSpace, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + XK_nobreakspace,XK_exclamdown, XK_cent, XK_sterling, + XK_currency, XK_yen, XK_brokenbar, XK_section, + XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft, + XK_notsign, XK_hyphen, XK_registered, XK_macron, + XK_degree, XK_plusminus, XK_twosuperior, XK_threesuperior, + XK_acute, XK_mu, XK_paragraph, XK_periodcentered, + XK_cedilla, XK_onesuperior, XK_masculine, XK_guillemotright, + XK_onequarter, XK_onehalf, XK_threequarters,XK_questiondown, + XK_Agrave, XK_Aacute, XK_Acircumflex, XK_Atilde, + XK_Adiaeresis, XK_Aring, XK_AE, XK_Ccedilla, + XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis, + XK_Igrave, XK_Iacute, XK_Icircumflex, XK_Idiaeresis, + XK_ETH, XK_Ntilde, XK_Ograve, XK_Oacute, + XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_multiply, + XK_Ooblique, XK_Ugrave, XK_Uacute, XK_Ucircumflex, + XK_Udiaeresis, XK_Yacute, XK_THORN, XK_ssharp, + XK_agrave, XK_aacute, XK_acircumflex, XK_atilde, + XK_adiaeresis, XK_aring, XK_ae, XK_ccedilla, + XK_egrave, XK_eacute, XK_ecircumflex, XK_ediaeresis, + XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis, + XK_eth, XK_ntilde, XK_ograve, XK_oacute, + XK_ocircumflex, XK_otilde, XK_odiaeresis, XK_division, + XK_oslash, XK_ugrave, XK_uacute, XK_ucircumflex, + XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis +}; + +/* + * Maps the AT keycodes to Linux keycodes + */ +static unsigned char at2lnx[NUM_KEYCODES] = +{ + 0x01, /* KEY_Escape */ 0x02, /* KEY_1 */ + 0x03, /* KEY_2 */ 0x04, /* KEY_3 */ + 0x05, /* KEY_4 */ 0x06, /* KEY_5 */ + 0x07, /* KEY_6 */ 0x08, /* KEY_7 */ + 0x09, /* KEY_8 */ 0x0a, /* KEY_9 */ + 0x0b, /* KEY_0 */ 0x0c, /* KEY_Minus */ + 0x0d, /* KEY_Equal */ 0x0e, /* KEY_BackSpace */ + 0x0f, /* KEY_Tab */ 0x10, /* KEY_Q */ + 0x11, /* KEY_W */ 0x12, /* KEY_E */ + 0x13, /* KEY_R */ 0x14, /* KEY_T */ + 0x15, /* KEY_Y */ 0x16, /* KEY_U */ + 0x17, /* KEY_I */ 0x18, /* KEY_O */ + 0x19, /* KEY_P */ 0x1a, /* KEY_LBrace */ + 0x1b, /* KEY_RBrace */ 0x1c, /* KEY_Enter */ + 0x1d, /* KEY_LCtrl */ 0x1e, /* KEY_A */ + 0x1f, /* KEY_S */ 0x20, /* KEY_D */ + 0x21, /* KEY_F */ 0x22, /* KEY_G */ + 0x23, /* KEY_H */ 0x24, /* KEY_J */ + 0x25, /* KEY_K */ 0x26, /* KEY_L */ + 0x27, /* KEY_SemiColon */ 0x28, /* KEY_Quote */ + 0x29, /* KEY_Tilde */ 0x2a, /* KEY_ShiftL */ + 0x2b, /* KEY_BSlash */ 0x2c, /* KEY_Z */ + 0x2d, /* KEY_X */ 0x2e, /* KEY_C */ + 0x2f, /* KEY_V */ 0x30, /* KEY_B */ + 0x31, /* KEY_N */ 0x32, /* KEY_M */ + 0x33, /* KEY_Comma */ 0x34, /* KEY_Period */ + 0x35, /* KEY_Slash */ 0x36, /* KEY_ShiftR */ + 0x37, /* KEY_KP_Multiply */ 0x38, /* KEY_Alt */ + 0x39, /* KEY_Space */ 0x3a, /* KEY_CapsLock */ + 0x3b, /* KEY_F1 */ 0x3c, /* KEY_F2 */ + 0x3d, /* KEY_F3 */ 0x3e, /* KEY_F4 */ + 0x3f, /* KEY_F5 */ 0x40, /* KEY_F6 */ + 0x41, /* KEY_F7 */ 0x42, /* KEY_F8 */ + 0x43, /* KEY_F9 */ 0x44, /* KEY_F10 */ + 0x45, /* KEY_NumLock */ 0x46, /* KEY_ScrollLock */ + 0x47, /* KEY_KP_7 */ 0x48, /* KEY_KP_8 */ + 0x49, /* KEY_KP_9 */ 0x4a, /* KEY_KP_Minus */ + 0x4b, /* KEY_KP_4 */ 0x4c, /* KEY_KP_5 */ + 0x4d, /* KEY_KP_6 */ 0x4e, /* KEY_KP_Plus */ + 0x4f, /* KEY_KP_1 */ 0x50, /* KEY_KP_2 */ + 0x51, /* KEY_KP_3 */ 0x52, /* KEY_KP_0 */ + 0x53, /* KEY_KP_Decimal */ 0x54, /* KEY_SysReqest */ + 0x00, /* 0x55 */ 0x56, /* KEY_Less */ + 0x57, /* KEY_F11 */ 0x58, /* KEY_F12 */ + 0x66, /* KEY_Home */ 0x67, /* KEY_Up */ + 0x68, /* KEY_PgUp */ 0x69, /* KEY_Left */ + 0x5d, /* KEY_Begin */ 0x6a, /* KEY_Right */ + 0x6b, /* KEY_End */ 0x6c, /* KEY_Down */ + 0x6d, /* KEY_PgDown */ 0x6e, /* KEY_Insert */ + 0x6f, /* KEY_Delete */ 0x60, /* KEY_KP_Enter */ + 0x61, /* KEY_RCtrl */ 0x77, /* KEY_Pause */ + 0x63, /* KEY_Print */ 0x62, /* KEY_KP_Divide */ + 0x64, /* KEY_AltLang */ 0x65, /* KEY_Break */ + 0x00, /* KEY_LMeta */ 0x00, /* KEY_RMeta */ + 0x7A, /* KEY_Menu/FOCUS_PF11*/0x00, /* 0x6e */ + 0x7B, /* FOCUS_PF12 */ 0x00, /* 0x70 */ + 0x00, /* 0x71 */ 0x00, /* 0x72 */ + 0x59, /* FOCUS_PF2 */ 0x78, /* FOCUS_PF9 */ + 0x00, /* 0x75 */ 0x00, /* 0x76 */ + 0x5A, /* FOCUS_PF3 */ 0x5B, /* FOCUS_PF4 */ + 0x5C, /* FOCUS_PF5 */ 0x5D, /* FOCUS_PF6 */ + 0x5E, /* FOCUS_PF7 */ 0x5F, /* FOCUS_PF8 */ + 0x7C, /* JAP_86 */ 0x79, /* FOCUS_PF10 */ + 0x00, /* 0x7f */ +}; +#define NUM_AT2LNX (sizeof(at2lnx) / sizeof(at2lnx[0])) + +#define NUM_CUSTOMKEYS NR_KEYS + +static void +readKernelMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms, CARD8 *pModMap) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + KeySym *k; + int i; + int maxkey; + static unsigned char tbl[GLYPHS_PER_KEY] = + { + 0, /* unshifted */ + 1, /* shifted */ + 0, /* modeswitch unshifted */ + 0 /* modeswitch shifted */ + }; + + /* + * Read the mapping from the kernel. + * Since we're still using the XFree86 scancode->AT keycode mapping + * routines, we need to convert the AT keycodes to Linux keycodes, + * then translate the Linux keysyms into X keysyms. + * + * First, figure out which tables to use for the modeswitch columns + * above, from the XF86Config fields. + */ + tbl[2] = 8; /* alt */ + tbl[3] = tbl[2] | 1; + + if (pKbd->CustomKeycodes) { + k = map; + maxkey = NUM_CUSTOMKEYS; + } + else { + k = map+GLYPHS_PER_KEY; + maxkey = NUM_AT2LNX; + } + + for (i = 0; i < maxkey; ++i) + { + struct kbentry kbe; + int j; + + if (pKbd->CustomKeycodes) + kbe.kb_index = i; + else + kbe.kb_index = at2lnx[i]; + + for (j = 0; j < GLYPHS_PER_KEY; ++j, ++k) + { + unsigned short kval; + + *k = NoSymbol; + + kbe.kb_table = tbl[j]; + if ( + (!pKbd->CustomKeycodes && kbe.kb_index == 0) || + ioctl(pInfo->fd, KDGKBENT, &kbe)) + continue; + + kval = KVAL(kbe.kb_value); + switch (KTYP(kbe.kb_value)) + { + case KT_LATIN: + case KT_LETTER: + *k = linux_to_x[kval]; + break; + + case KT_FN: + if (kval <= 19) + *k = XK_F1 + kval; + else switch (kbe.kb_value) + { + case K_FIND: + *k = XK_Home; /* or XK_Find */ + break; + case K_INSERT: + *k = XK_Insert; + break; + case K_REMOVE: + *k = XK_Delete; + break; + case K_SELECT: + *k = XK_End; /* or XK_Select */ + break; + case K_PGUP: + *k = XK_Prior; + break; + case K_PGDN: + *k = XK_Next; + break; + case K_HELP: + *k = XK_Help; + break; + case K_DO: + *k = XK_Execute; + break; + case K_PAUSE: + *k = XK_Pause; + break; + case K_MACRO: + *k = XK_Menu; + break; + default: + break; + } + break; + + case KT_SPEC: + switch (kbe.kb_value) + { + case K_ENTER: + *k = XK_Return; + break; + case K_BREAK: + *k = XK_Break; + break; + case K_CAPS: + *k = XK_Caps_Lock; + break; + case K_NUM: + *k = XK_Num_Lock; + break; + case K_HOLD: + *k = XK_Scroll_Lock; + break; + case K_COMPOSE: + *k = XK_Multi_key; + break; + default: + break; + } + break; + + case KT_PAD: + switch (kbe.kb_value) + { + case K_PPLUS: + *k = XK_KP_Add; + break; + case K_PMINUS: + *k = XK_KP_Subtract; + break; + case K_PSTAR: + *k = XK_KP_Multiply; + break; + case K_PSLASH: + *k = XK_KP_Divide; + break; + case K_PENTER: + *k = XK_KP_Enter; + break; + case K_PCOMMA: + *k = XK_KP_Separator; + break; + case K_PDOT: + *k = XK_KP_Decimal; + break; + case K_PPLUSMINUS: + *k = XK_KP_Subtract; + break; + default: + if (kval <= 9) + *k = XK_KP_0 + kval; + break; + } + break; + + /* + * KT_DEAD keys are for accelerated diacritical creation. + */ + case KT_DEAD: + switch (kbe.kb_value) + { + case K_DGRAVE: + *k = XK_dead_grave; + break; + case K_DACUTE: + *k = XK_dead_acute; + break; + case K_DCIRCM: + *k = XK_dead_circumflex; + break; + case K_DTILDE: + *k = XK_dead_tilde; + break; + case K_DDIERE: + *k = XK_dead_diaeresis; + break; + } + break; + + case KT_CUR: + switch (kbe.kb_value) + { + case K_DOWN: + *k = XK_Down; + break; + case K_LEFT: + *k = XK_Left; + break; + case K_RIGHT: + *k = XK_Right; + break; + case K_UP: + *k = XK_Up; + break; + } + break; + + case KT_SHIFT: + switch (kbe.kb_value) + { + case K_ALTGR: + *k = XK_Alt_R; + break; + case K_ALT: + *k = (kbe.kb_index == 0x64 ? + XK_Alt_R : XK_Alt_L); + break; + case K_CTRL: + *k = (kbe.kb_index == 0x61 ? + XK_Control_R : XK_Control_L); + break; + case K_CTRLL: + *k = XK_Control_L; + break; + case K_CTRLR: + *k = XK_Control_R; + break; + case K_SHIFT: + *k = (kbe.kb_index == 0x36 ? + XK_Shift_R : XK_Shift_L); + break; + case K_SHIFTL: + *k = XK_Shift_L; + break; + case K_SHIFTR: + *k = XK_Shift_R; + break; + default: + break; + } + break; + + /* + * KT_ASCII keys accumulate a 3 digit decimal number that gets + * emitted when the shift state changes. We can't emulate that. + */ + case KT_ASCII: + break; + + case KT_LOCK: + if (kbe.kb_value == K_SHIFTLOCK) + *k = XK_Shift_Lock; + break; + + default: + break; + } + } + + if (k[-1] == k[-2]) k[-1] = NoSymbol; + if (k[-2] == k[-3]) k[-2] = NoSymbol; + if (k[-3] == k[-4]) k[-3] = NoSymbol; + if (k[-4] == k[-2] && k[-3] == k[-1]) k[-2] = k[-1] = NoSymbol; + if (k[-1] == k[-4] && k[-2] == k[-3] && k[-2] == NoSymbol) k[-1] =NoSymbol; + } + + if (!pKbd->CustomKeycodes) + return; + + /* + * Find the Mapping for the special server functions + */ + pKbd->specialMap = (TransMapPtr) xcalloc(NUM_CUSTOMKEYS, 1); + if (pKbd->specialMap != NULL) { + pKbd->specialMap->end = NUM_CUSTOMKEYS; + pKbd->specialMap->map = (unsigned char*) xcalloc(NUM_CUSTOMKEYS, 1); + if (pKbd->specialMap == NULL) { + xfree(pKbd->specialMap); + pKbd->specialMap = NULL; + } + } + if (pKbd->specialMap == NULL) { + xf86Msg(X_ERROR, "%s can't allocate \"special map\"\n", pInfo->name); + return; + } + + for (i = 0; i < NUM_CUSTOMKEYS; ++i) { + struct kbentry kbe; + int special = 0; + + kbe.kb_index = i; + kbe.kb_table = 0; /* Plain map */ + if (!ioctl(pInfo->fd, KDGKBENT, &kbe)) + switch (kbe.kb_value) { + case K(KT_LATIN,0x7f): /* This catches DEL too... But who cares? */ + special = KEY_BackSpace; + break; + case K_PMINUS: + special = KEY_KP_Minus; + break; + case K_PPLUS: + special = KEY_KP_Plus; + break; + case K_F1: + special = KEY_F1; + break; + case K_F2: + special = KEY_F2; + break; + case K_F3: + special = KEY_F3; + break; + case K_F4: + special = KEY_F4; + break; + case K_F5: + special = KEY_F5; + break; + case K_F6: + special = KEY_F6; + break; + case K_F7: + special = KEY_F7; + break; + case K_F8: + special = KEY_F8; + break; + case K_F9: + special = KEY_F9; + break; + case K_F10: + special = KEY_F10; + break; + case K_F11: + special = KEY_F11; + break; + case K_F12: + special = KEY_F12; + break; + case K_ALT: + special = KEY_Alt; + break; + case K_ALTGR: + special = KEY_AltLang; + break; + case K_CONS: + special = KEY_SysReqest; + break; + } + pKbd->specialMap->map[i] = special; + } +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c new file mode 100644 index 000000000..9d1dea77d --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_acpi.c @@ -0,0 +1,170 @@ +#include "X.h" +#include "os.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS +#include "xf86_OSproc.h" +#include +#include +#include +#include +#include +#include +#include + +#define ACPI_SOCKET "/var/run/acpid.socket" +#define ACPI_EVENTS "/proc/acpi/event" + +#define ACPI_VIDEO_NOTIFY_SWITCH 0x80 +#define ACPI_VIDEO_NOTIFY_PROBE 0x81 +#define ACPI_VIDEO_NOTIFY_CYCLE 0x82 +#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83 +#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84 + +#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82 +#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83 +#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84 +#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85 +#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86 + +#define ACPI_VIDEO_HEAD_INVALID (~0u - 1) +#define ACPI_VIDEO_HEAD_END (~0u) + +static void lnxCloseACPI(void); +static pointer ACPIihPtr = NULL; +PMClose lnxACPIOpen(void); + +#define LINE_LENGTH 80 + +static int +lnxACPIGetEventFromOs(int fd, pmEvent *events, int num) +{ + char ev[LINE_LENGTH]; + int n; + + memset(ev, 0, LINE_LENGTH); + + n = read( fd, ev, LINE_LENGTH ); + + /* Check that we have a video event */ + if (strstr(ev, "video") == ev) { + char *video = NULL; + char *GFX = NULL; + char *notify = NULL; + char *data = NULL; /* doesn't appear to be used in the kernel */ + unsigned long int notify_l, data_l; + + video = strtok(ev, "video"); + + GFX = strtok(NULL, " "); +#if 0 + ErrorF("GFX: %s\n",GFX); +#endif + + notify = strtok(NULL, " "); + notify_l = strtoul(notify, NULL, 16); +#if 0 + ErrorF("notify: 0x%lx\n",notify_l); +#endif + + data = strtok(NULL, " "); + data_l = strtoul(data, NULL, 16); +#if 0 + ErrorF("data: 0x%lx\n",data_l); +#endif + + /* We currently don't differentiate between any event */ + switch (notify_l) { + case ACPI_VIDEO_NOTIFY_SWITCH: + break; + case ACPI_VIDEO_NOTIFY_PROBE: + break; + case ACPI_VIDEO_NOTIFY_CYCLE: + break; + case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: + break; + case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: + break; + default: + break; + } + + /* Deal with all ACPI events as a capability change */ + events[0] = XF86_APM_CAPABILITY_CHANGED; + + return 1; + } + + return 0; +} + +static pmWait +lnxACPIConfirmEventToOs(int fd, pmEvent event) +{ + /* No ability to send back to the kernel in ACPI */ + switch (event) { + default: + return PM_NONE; + } +} + +PMClose +lnxACPIOpen(void) +{ + int fd; + struct sockaddr_un addr; + int r = -1; + +#ifdef DEBUG + ErrorF("ACPI: OSPMOpen called\n"); +#endif + if (ACPIihPtr || !xf86Info.pmFlag) + return NULL; + +#ifdef DEBUG + ErrorF("ACPI: Opening device\n"); +#endif + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) > -1) { + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strcpy(addr.sun_path, ACPI_SOCKET); + if ((r = connect(fd, (struct sockaddr*)&addr, sizeof(addr))) == -1) { + shutdown(fd, 2); + close(fd); + fd = -1; + } + } + + /* acpid's socket isn't available, so try going direct */ + if (fd == -1) { + if ((fd = open(ACPI_EVENTS, O_RDONLY)) < 0) { + xf86MsgVerb(X_WARNING,3,"Open ACPI failed (%s) (%s)\n", ACPI_EVENTS, + strerror(errno)); + return NULL; + } + } + + xf86PMGetEventFromOs = lnxACPIGetEventFromOs; + xf86PMConfirmEventToOs = lnxACPIConfirmEventToOs; + ACPIihPtr = xf86AddInputHandler(fd,xf86HandlePMEvents,NULL); + xf86MsgVerb(X_INFO,3,"Open ACPI successful (%s)\n", (r != -1) ? ACPI_SOCKET : ACPI_EVENTS); + + return lnxCloseACPI; +} + +static void +lnxCloseACPI(void) +{ + int fd; + +#ifdef DEBUG + ErrorF("ACPI: Closing device\n"); +#endif + if (ACPIihPtr) { + fd = xf86RemoveInputHandler(ACPIihPtr); + shutdown(fd, 2); + close(fd); + ACPIihPtr = NULL; + } +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c new file mode 100644 index 000000000..6a5c83db2 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c @@ -0,0 +1,371 @@ +/* + * Abstraction of the AGP GART interface. + * + * This version is for both Linux and FreeBSD. + * + * 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 +#endif + +#include +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +#if defined(linux) +#include +#include +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +#include +#include +#endif + +#ifndef AGP_DEVICE +#define AGP_DEVICE "/dev/agpgart" +#endif +/* AGP page size is independent of the host page size. */ +#ifndef AGP_PAGE_SIZE +#define AGP_PAGE_SIZE 4096 +#endif +#define AGPGART_MAJOR_VERSION 0 +#define AGPGART_MINOR_VERSION 99 + +static int gartFd = -1; +static int acquiredScreen = -1; +static Bool initDone = FALSE; +/* + * Close /dev/agpgart. This frees all associated memory allocated during + * this server generation. + */ +Bool +xf86GARTCloseScreen(int screenNum) +{ + if(gartFd != -1) { + close(gartFd); + acquiredScreen = -1; + gartFd = -1; + initDone = FALSE; + } + return TRUE; +} + +/* + * Open /dev/agpgart. 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) + gartFd = open(AGP_DEVICE, O_RDWR, 0); + else + return FALSE; + + if (gartFd == -1) { + xf86DrvMsg(screenNum, X_ERROR, + "GARTInit: Unable to open " AGP_DEVICE " (%s)\n", + strerror(errno)); + return FALSE; + } + + xf86AcquireGART(-1); + /* Check the kernel driver version. */ + if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { + xf86DrvMsg(screenNum, X_ERROR, + "GARTInit: AGPIOC_INFO failed (%s)\n", strerror(errno)); + close(gartFd); + gartFd = -1; + return FALSE; + } + xf86ReleaseGART(-1); + +#if defined(linux) + /* Per Dave Jones, every effort will be made to keep the + * agpgart interface backwards compatible, so allow all + * future versions. + */ + if ( +#if (AGPGART_MAJOR_VERSION > 0) /* quiet compiler */ + agpinf.version.major < AGPGART_MAJOR_VERSION || +#endif + (agpinf.version.major == AGPGART_MAJOR_VERSION && + agpinf.version.minor < AGPGART_MINOR_VERSION)) { + xf86DrvMsg(screenNum, X_ERROR, + "GARTInit: Kernel agpgart driver version is not current" + " (%d.%d vs %d.%d)\n", + agpinf.version.major, agpinf.version.minor, + AGPGART_MAJOR_VERSION, AGPGART_MINOR_VERSION); + close(gartFd); + gartFd = -1; + return FALSE; + } +#endif + + 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 %d total, %d used\n", agpinf.pg_total, 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 !defined(linux) + if (screenNum == -1) +#endif + { + 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 *)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/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c new file mode 100644 index 000000000..bd78d877f --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c @@ -0,0 +1,192 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c,v 3.12 2001/12/24 22:54:31 dawes Exp $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include "os.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS +#include "xf86_OSproc.h" +#include "lnx.h" +#include +#include +#include +#include +#include +#include +#include + +#define APM_PROC "/proc/apm" +#define APM_DEVICE "/dev/apm_bios" + +#ifndef APM_STANDBY_FAILED +# define APM_STANDBY_FAILED 0xf000 +#endif +#ifndef APM_SUSPEND_FAILED +# define APM_SUSPEND_FAILED 0xf001 +#endif + +static PMClose lnxAPMOpen(void); +extern PMClose lnxACPIOpen(void); +static void lnxCloseAPM(void); +static pointer APMihPtr = NULL; + +static struct { + apm_event_t apmLinux; + pmEvent xf86; +} LinuxToXF86[] = { + { APM_SYS_STANDBY, XF86_APM_SYS_STANDBY }, + { APM_SYS_SUSPEND, XF86_APM_SYS_SUSPEND }, + { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME }, + { APM_CRITICAL_RESUME, XF86_APM_CRITICAL_RESUME }, + { APM_LOW_BATTERY, XF86_APM_LOW_BATTERY }, + { APM_POWER_STATUS_CHANGE, XF86_APM_POWER_STATUS_CHANGE }, + { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME }, + { APM_CRITICAL_SUSPEND, XF86_APM_CRITICAL_SUSPEND }, + { APM_USER_STANDBY, XF86_APM_USER_STANDBY }, + { APM_USER_SUSPEND, XF86_APM_USER_SUSPEND }, + { APM_STANDBY_RESUME, XF86_APM_STANDBY_RESUME }, +#if defined(APM_CAPABILITY_CHANGED) + { APM_CAPABILITY_CHANGED, XF86_CAPABILITY_CHANGED }, +#endif +#if 0 + { APM_STANDBY_FAILED, XF86_APM_STANDBY_FAILED }, + { APM_SUSPEND_FAILED, XF86_APM_SUSPEND_FAILED } +#endif +}; + +#define numApmEvents (sizeof(LinuxToXF86) / sizeof(LinuxToXF86[0])) + +/* + * APM is still under construction. + * I'm not sure if the places where I initialize/deinitialize + * apm is correct. Also I don't know what to do in SETUP state. + * This depends if wakeup gets called in this situation, too. + * Also we need to check if the action that is taken on an + * event is reasonable. + */ +static int +lnxPMGetEventFromOs(int fd, pmEvent *events, int num) +{ + int i,j,n; + apm_event_t linuxEvents[8]; + + if ((n = read( fd, linuxEvents, num * sizeof(apm_event_t) )) == -1) + return 0; + n /= sizeof(apm_event_t); + if (n > num) + n = num; + for (i = 0; i < n; i++) { + for (j = 0; j < numApmEvents; j++) + if (LinuxToXF86[j].apmLinux == linuxEvents[i]) { + events[i] = LinuxToXF86[j].xf86; + break; + } + if (j == numApmEvents) + events[i] = XF86_APM_UNKNOWN; + } + return n; +} + +static pmWait +lnxPMConfirmEventToOs(int fd, pmEvent event) +{ + switch (event) { + case XF86_APM_SYS_STANDBY: + case XF86_APM_USER_STANDBY: + if (ioctl( fd, APM_IOC_STANDBY, NULL )) + return PM_FAILED; + return PM_CONTINUE; + case XF86_APM_SYS_SUSPEND: + case XF86_APM_CRITICAL_SUSPEND: + case XF86_APM_USER_SUSPEND: + if (ioctl( fd, APM_IOC_SUSPEND, NULL )) { + /* I believe this is wrong (EE) + EBUSY is sent when a device refuses to be suspended. + In this case we still need to undo everything we have + done to suspend ourselves or we will stay in suspended + state forever. */ + if (errno == EBUSY) + return PM_CONTINUE; + else + return PM_FAILED; + } + return PM_CONTINUE; + case XF86_APM_STANDBY_RESUME: + case XF86_APM_NORMAL_RESUME: + case XF86_APM_CRITICAL_RESUME: + case XF86_APM_STANDBY_FAILED: + case XF86_APM_SUSPEND_FAILED: + return PM_CONTINUE; + default: + return PM_NONE; + } +} + +PMClose +xf86OSPMOpen(void) +{ + PMClose ret = NULL; + + /* Favour ACPI over APM, but only when enabled */ + + if (!xf86acpiDisableFlag) + ret = lnxACPIOpen(); + + if (!ret) + ret = lnxAPMOpen(); + + return ret; +} + +static PMClose +lnxAPMOpen(void) +{ + int fd, pfd; + +#ifdef DEBUG + ErrorF("APM: OSPMOpen called\n"); +#endif + if (APMihPtr || !xf86Info.pmFlag) + return NULL; + +#ifdef DEBUG + ErrorF("APM: Opening device\n"); +#endif + if ((fd = open( APM_DEVICE, O_RDWR )) > -1) { + if (access( APM_PROC, R_OK ) || + ((pfd = open( APM_PROC, O_RDONLY)) == -1)) { + xf86MsgVerb(X_WARNING,3,"Cannot open APM (%s) (%s)\n", + APM_PROC, strerror(errno)); + close(fd); + return NULL; + } else + close(pfd); + xf86PMGetEventFromOs = lnxPMGetEventFromOs; + xf86PMConfirmEventToOs = lnxPMConfirmEventToOs; + APMihPtr = xf86AddInputHandler(fd,xf86HandlePMEvents,NULL); + xf86MsgVerb(X_INFO,3,"Open APM successful\n"); + return lnxCloseAPM; + } + xf86MsgVerb(X_INFO,3,"No APM support in BIOS or kernel\n"); + return NULL; +} + +static void +lnxCloseAPM(void) +{ + int fd; + +#ifdef DEBUG + ErrorF("APM: Closing device\n"); +#endif + if (APMihPtr) { + fd = xf86RemoveInputHandler(APMihPtr); + close(fd); + APMihPtr = NULL; + } +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c new file mode 100644 index 000000000..fd47a5559 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c @@ -0,0 +1,200 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c,v 1.3 2001/02/15 11:03:56 alanh Exp $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include +#include "os.h" +#include "xf86.h" +#include "xf86Priv.h" +#include "shared/xf86Axp.h" + +axpDevice lnxGetAXP(void); + +typedef struct + { char* sysName; + char* sysVari; + char* cpu; + axpDevice sys; } +AXP; + +static AXP axpList[] = { + { "Tsunami", NULL, NULL, TSUNAMI }, + { "Eiger", NULL, NULL, TSUNAMI }, + {"Noname", NULL, NULL, LCA }, + { "AlphaBook1", NULL, NULL, LCA }, + {"EB66", NULL, NULL, LCA}, + {"EB64+",NULL,NULL, APECS}, + {"Noritake",NULL,"EV5",CIA}, + {"Noritake",NULL,"EV56",CIA}, + {"Noritake",NULL,NULL,APECS}, + {"XL",NULL,NULL,APECS}, + {"Avanti",NULL,NULL,APECS}, + {"Mikasa",NULL,"EV5",CIA}, + {"Mikasa",NULL,"EV56",CIA}, + {"Mikasa",NULL,NULL,APECS}, + {"EB164","EB164",NULL,CIA}, + {"EB164","PC164", NULL,CIA}, + {"EB164","LX164",NULL, PYXIS}, + {"EB164","SX164",NULL, PYXIS}, + {"EB164","RX164",NULL, POLARIS}, + {"Alcor",NULL,NULL,CIA}, + {"Takara",NULL,NULL,CIA}, + {"Sable",NULL, "EV5",T2_GAMMA}, + {"Sable",NULL,"EV56",T2_GAMMA}, + {"Sable",NULL,NULL,T2}, + {"Rawhide",NULL,NULL,MCPCIA}, + {"Jensen",NULL,NULL,JENSEN}, + {"Miata",NULL,NULL,PYXIS_CIA}, + {"Ruffian",NULL,NULL,PYXIS_CIA}, + {"Nautilus",NULL,NULL,IRONGATE}, + {NULL,NULL,NULL,NONE} +}; + + +axpDevice +lnxGetAXP(void) +{ + FILE *file; + int count = 0; + char res[256]; + char cpu[255]; + char systype[255]; + char sysvari[255]; + if (!(file = fopen("/proc/cpuinfo","r"))) + return SYS_NONE; + do { + if (!fgets(res,0xff,file)) return SYS_NONE; + switch (count) { + case 1: + sscanf(res, "cpu model : %s",cpu); +#ifdef DEBUG + ErrorF("CPU %s\n",cpu); +#endif + break; + case 5: + sscanf(res, "system type : %s",systype); +#ifdef DEBUG + ErrorF("system type : %s\n",systype); +#endif + break; + case 6: + sscanf(res, "system variation : %s",sysvari); +#ifdef DEBUG + ErrorF("system variation: %s\n",sysvari); +#endif + break; + } + count++; + } while (count < 8); + + fclose(file); + + count = 0; + + do { + if (!axpList[count].sysName || !strcmp(axpList[count].sysName,systype)) { + if (axpList[count].sysVari && strcmp(axpList[count].sysVari,sysvari)) { + count++; + continue; + }; + if (axpList[count].cpu && strcmp(axpList[count].cpu,cpu)) { + count++; + continue; + } + return axpList[count].sys; + } + count++; + } while (1); +} + +/* + * pciconfig_iobase wrappers and dynamic i/o selection + */ +#include +#include +#include + +/* glibc versions (single hose only) */ +extern void _outb(char val, unsigned long port); +extern void _outw(short val, unsigned long port); +extern void _outl(int val, unsigned long port); +extern unsigned int _inb(unsigned long port); +extern unsigned int _inw(unsigned long port); +extern unsigned int _inl(unsigned long port); + +extern void _dense_outb(char, unsigned long); +extern void _dense_outw(short, unsigned long); +extern void _dense_outl(int, unsigned long); +extern unsigned int _dense_inb(unsigned long); +extern unsigned int _dense_inw(unsigned long); +extern unsigned int _dense_inl(unsigned long); + +void (*_alpha_outb)(char, unsigned long) = _outb; +void (*_alpha_outw)(short, unsigned long) = _outw; +void (*_alpha_outl)(int, unsigned long) = _outl; +unsigned int (*_alpha_inb)(unsigned long) = _inb; +unsigned int (*_alpha_inw)(unsigned long) = _inw; +unsigned int (*_alpha_inl)(unsigned long) = _inl; + +static long _alpha_iobase_query(unsigned, int, int, int); +long (*_iobase)(unsigned, int, int, int) = _alpha_iobase_query; + +static long +_alpha_iobase(unsigned flags, int hose, int bus, int devfn) +{ +#ifdef __NR_pciconfig_iobase + if (bus < 0) { + bus = hose; + flags |= IOBASE_FROM_HOSE; + } + + return syscall(__NR_pciconfig_iobase, flags, bus, devfn); +#else + return -ENOSYS +#endif +} + +static long +_alpha_iobase_legacy(unsigned flags, int hose, int bus, int devfn) +{ + if (hose > 0) return -ENODEV; + if (flags & IOBASE_DENSE_MEM) return _bus_base(); + if (flags & IOBASE_SPARSE_MEM) return _bus_base_sparse(); + return 0; +} + +static long +_alpha_iobase_query(unsigned flags, int hose, int bus, int devfn) +{ + /* + * Only use iobase if the syscall is supported *and* it's + * a dense io system + */ + if (_alpha_iobase(IOBASE_DENSE_IO, 0, 0, 0) > 0) { + /* + * The syscall worked and it's a dense io system - take over the + * io subsystem + */ + _iobase = _alpha_iobase; + +#ifndef INCLUDE_XF86_NO_DOMAIN + /* + * Only take over the inx/outx functions if this is a dense I/O + * system *and* addressing domains are being used. The dense I/O + * routines expect I/O to be mapped (as done in xf86MapDomainIO) + */ + _alpha_outb = _dense_outb; + _alpha_outw = _dense_outw; + _alpha_outl = _dense_outl; + _alpha_inb = _dense_inb; + _alpha_inw = _dense_inw; + _alpha_inl = _dense_inl; +#endif /* !INCLUDE_XF86_NO_DOMAIN */ + } else _iobase = _alpha_iobase_legacy; + + return _iobase(flags, hose, bus, devfn); +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c new file mode 100644 index 000000000..63077e907 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c @@ -0,0 +1,151 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c,v 3.5 2000/02/17 13:45:49 dawes Exp $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include "input.h" +#include "scrnintstr.h" +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" + +int readDense8(pointer Base, register unsigned long Offset); +int readDense16(pointer Base, register unsigned long Offset); +int readDense32(pointer Base, register unsigned long Offset); +void +writeDenseNB8(int Value, pointer Base, register unsigned long Offset); +void +writeDenseNB16(int Value, pointer Base, register unsigned long Offset); +void +writeDenseNB32(int Value, pointer Base, register unsigned long Offset); +void +writeDense8(int Value, pointer Base, register unsigned long Offset); +void +writeDense16(int Value, pointer Base, register unsigned long Offset); +void +writeDense32(int Value, pointer Base, register unsigned long Offset); + +int +readDense8(pointer Base, register unsigned long Offset) +{ + mem_barrier(); + return *(volatile CARD8*) ((unsigned long)Base+(Offset)); +} + +int +readDense16(pointer Base, register unsigned long Offset) +{ + mem_barrier(); + return *(volatile CARD16*) ((unsigned long)Base+(Offset)); +} + +int +readDense32(pointer Base, register unsigned long Offset) +{ + mem_barrier(); + return *(volatile CARD32*)((unsigned long)Base+(Offset)); +} + +void +writeDenseNB8(int Value, pointer Base, register unsigned long Offset) +{ + *(volatile CARD8*)((unsigned long)Base+(Offset)) = Value; +} + +void +writeDenseNB16(int Value, pointer Base, register unsigned long Offset) +{ + *(volatile CARD16*)((unsigned long)Base + (Offset)) = Value; +} + +void +writeDenseNB32(int Value, pointer Base, register unsigned long Offset) +{ + *(volatile CARD32*)((unsigned long)Base+(Offset)) = Value; +} + +void +writeDense8(int Value, pointer Base, register unsigned long Offset) +{ + write_mem_barrier(); + *(volatile CARD8 *)((unsigned long)Base+(Offset)) = Value; +} + +void +writeDense16(int Value, pointer Base, register unsigned long Offset) +{ + write_mem_barrier(); + *(volatile CARD16 *)((unsigned long)Base+(Offset)) = Value; +} + +void +writeDense32(int Value, pointer Base, register unsigned long Offset) +{ + write_mem_barrier(); + *(volatile CARD32 *)((unsigned long)Base+(Offset)) = Value; +} + + +#ifndef INCLUDE_XF86_NO_DOMAIN + +void +_dense_outb(char val, unsigned long port) +{ + if ((port & ~0xffff) == 0) return _outb(val, port); + + write_mem_barrier(); + *(volatile CARD8 *)port = val; +} + +void +_dense_outw(short val, unsigned long port) +{ + if ((port & ~0xffff) == 0) return _outw(val, port); + + write_mem_barrier(); + *(volatile CARD16 *)port = val; +} + +void +_dense_outl(int val, unsigned long port) +{ + if ((port & ~0xffff) == 0) return _outl(val, port); + + write_mem_barrier(); + *(volatile CARD32 *)port = val; +} + +unsigned int +_dense_inb(unsigned long port) +{ + if ((port & ~0xffff) == 0) return _inb(port); + + mem_barrier(); + return *(volatile CARD8 *)port; +} + +unsigned int +_dense_inw(unsigned long port) +{ + if ((port & ~0xffff) == 0) return _inw(port); + + mem_barrier(); + return *(volatile CARD16 *)port; +} + +unsigned int +_dense_inl(unsigned long port) +{ + if ((port & ~0xffff) == 0) return _inl(port); + + mem_barrier(); + return *(volatile CARD32 *)port; +} + +#endif /* !INCLUDE_XF86_NO_DOMAIN */ + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c new file mode 100644 index 000000000..e9a5b6aef --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_font.c @@ -0,0 +1,291 @@ +/* + * Copyright 2004, Egbert Eich + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * EGBERT EICH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON- + * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Egbert Eich shall not + * be used in advertising or otherwise to promote the sale, use or other deal- + *ings in this Software without prior written authorization from Egbert Eich. + * + */ +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "lnx.h" + +#include +#include +#include + +struct { + int width; + int height; + int charcount; + unsigned char *data; +} lnxfont = { 0, 0, 0, NULL }; + + +static Bool +getfont(int *width, int *height, + int *charcount, unsigned char *data) +{ + struct console_font_op op; + struct consolefontdesc ds; + int result; + + op.op = KD_FONT_OP_GET; + op.width = *width; + op.height = *height; + op.charcount = *charcount; + op.data = data; + op.flags = 0; + + SYSCALL(result = ioctl(xf86Info.consoleFd, KDFONTOP, &op)); +#ifdef DEBUG + ErrorF("Console font read: h: %i count: %i\n",op.height,op.charcount); +#endif + + if (!result) { + + *width = op.width; + *height = op.height; + *charcount = op.charcount; + + return TRUE; + } + + if (errno != ENOSYS && errno != EINVAL) + return FALSE; + + /* GIO_FONTX fallback */ + ds.charcount = *charcount; + ds.charheight = *height; + ds.chardata = (char *)data; + *width = 8; + + SYSCALL(result = ioctl(xf86Info.consoleFd, GIO_FONTX, &ds)); + + if (!result) { + + *charcount = ds.charcount; + *height = ds.charheight; + + return TRUE; + } + + if (errno != ENOSYS && errno != EINVAL) + return FALSE; + + /* GIO_FONT fallback */ + if (*charcount < 256) + return FALSE; + + SYSCALL(result = ioctl(xf86Info.consoleFd, GIO_FONT, data)); + + if (!result) { + *height = 0; + *charcount = 512; + return TRUE; + } + + return FALSE; + +} + +#define VERSION_LEN 31 + +Bool +lnx_savefont(void) +{ + unsigned char *fontdata; +#if CHECK_OS_VERSION + char kernel_version[VERSION_LEN + 1]; + int k_major, k_minor, k_release; +#endif + int size; + int fd; + int width = 32, height = 32, charcount = 2048; + +#ifdef DEBUG + ErrorF("SAVE font\n"); +#endif + +#if CHECK_OS_VERSION + /* Check if the kernel has full support for this */ + if ((fd = open ("/proc/sys/kernel/osrelease",O_RDONLY)) == -1) { + close (fd); + return TRUE; + } + size = read(fd, kernel_version, VERSION_LEN); + close (fd); + + if (size < 0) + return TRUE; + + size = sscanf(kernel_version, "%d.%d.%d",&k_major,&k_minor,&k_release); + if (size < 3 + || (k_major < 2) + || ((k_major == 2) + && ((k_minor < 6) + || ( k_minor == 6 + && k_release < 11)))) + return TRUE; +#endif + + /* if we are in fbdev mode we don't bother saving fonts */ + if ((fd = open ("/dev/fb0",O_RDWR)) != -1) { + close (fd); + return TRUE; + } + + if (!getfont(&width, &height, &charcount, NULL)) { + xf86Msg(X_WARNING, + "lnx_savefont: cannot obtain font info\n"); + goto error; + } else if (charcount == 2048) { + xf86Msg(X_WARNING, "lnx_savefont: " + "kernel bug: kernel doesn't report font info\n"); + return FALSE; + } + + size = (width + 7)/8 * 32 * charcount; + fontdata = (unsigned char *)xnfalloc(size); + if (!fontdata) { + xf86Msg(X_WARNING, + "lnx_savefont: cannot allocate memory to save font\n"); + goto error; + } + + if (!getfont(&width, &height, &charcount, fontdata)) { + xf86Msg(X_WARNING,"lnx_savefont: cannot read font data\n"); + goto error; + } + lnxfont.width = width; + lnxfont.height = height; + lnxfont.charcount = charcount; + lnxfont.data = fontdata; + + return TRUE; + + error: + return FALSE; +} + +static Bool +setfont(int width, int height, + int charcount, unsigned char *data) +{ + struct console_font_op op; + struct consolefontdesc ds; + int result; + + op.op = KD_FONT_OP_SET; + op.flags = 0; + op.charcount = charcount; + op.width = width; + op.height = height; + op.data = data; + + SYSCALL(result = ioctl(xf86Info.consoleFd, KDFONTOP, &op)); + + if (!result) + return TRUE; + + if (errno != ENOSYS && errno != EINVAL) + return FALSE; + + /* PIO_FONTX fallback */ + if (width != 8) + return FALSE; + + ds.charcount = charcount; + ds.chardata = (char *)data; + ds.charheight = height; + SYSCALL(result = ioctl(xf86Info.consoleFd, PIO_FONTX, &ds)); + + if (!result) + return TRUE; + + if (errno != ENOSYS && errno != EINVAL) + return FALSE; + + /* PIO_FONT fallback */ + SYSCALL(result = ioctl(xf86Info.consoleFd, PIO_FONT, data)); + + if (!result) + return TRUE; + + return FALSE; +} + +Bool +lnx_restorefont(void) +{ + if (lnxfont.data == NULL) + return FALSE; +#ifdef DEBUG + ErrorF("RESTORE font\n"); +#endif +#if 0 + /* must wack the height to make the kernel reprogram the VGA registers */ + if (!setfont(lnxfont.width, lnxfont.height + 1, lnxfont.charcount, + lnxfont.data)) { + xf86Msg(X_WARNING,"lnx_fontretore: cannot write font data\n"); + return FALSE; + } +#endif + if (!setfont(lnxfont.width, lnxfont.height, lnxfont.charcount, + lnxfont.data)) { + xf86Msg(X_WARNING,"lnx_restorefont: cannot write font data\n"); + return FALSE; + } + + return TRUE; +} + +Bool +lnx_switchaway(void) +{ + Bool ret; + + /* temporarily switch to text mode */ + ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); + ret = lnx_restorefont(); + ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS); + return ret; +} + +void +lnx_freefontdata(void) +{ + if (lnxfont.data == NULL) + return; + + xfree(lnxfont.data); + lnxfont.data = NULL; + lnxfont.width = lnxfont.height = lnxfont.charcount = 0; +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ia64.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ia64.c new file mode 100644 index 000000000..5f742d01f --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_ia64.c @@ -0,0 +1,74 @@ +/* + * Copyright 2004, Egbert Eich + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * EGBERT EICH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON- + * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Egbert Eich shall not + * be used in advertising or otherwise to promote the sale, use or other deal- + *ings in this Software without prior written authorization from Egbert Eich. + * + */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "ia64Pci.h" +#include "Pci.h" + +#if defined OS_PROBE_PCI_CHIPSET +IA64Chipset OS_PROBE_PCI_CHIPSET(scanpciWrapperOpt flags) +{ + struct stat unused; + struct utsname utsName; + + if (!stat("/proc/bus/mckinley/zx1",&unused) + || !stat("/proc/bus/mckinley/zx2",&unused)) + return ZX1_CHIPSET; + + if (!stat("/proc/sgi_sn/licenseID", &unused)) { + int major, minor, patch; + char *c; + + /* We need a 2.6.11 or better kernel for Altix support */ + uname(&utsName); + c = utsName.release; + + major = atoi(c); + c = strstr(c, ".") + 1; + minor = atoi(c); + c = strstr(c, ".") + 1; + patch = atoi(c); + + if (major < 2 || (major == 2 && minor < 6) || + (major == 2 && minor == 6 && patch < 11)) { + ErrorF("Kernel 2.6.11 or better needed for Altix support\n"); + return NONE_CHIPSET; + } + return ALTIX_CHIPSET; + } + + return NONE_CHIPSET; +} +#endif diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c new file mode 100644 index 000000000..1eb0f33fe --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c @@ -0,0 +1,415 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 1.9 2005/08/26 07:35:55 daniels Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 3.14 2001/10/31 22:50:30 tsi Exp $ */ +/* + * Copyright 1992 by Orest Zborowski + * Copyright 1993 by David Wexelblat + * + * 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 Orest Zborowski and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of + * the software without specific, written prior permission. Orest Zborowski + * 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. + * + * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI 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. + * + */ +/* $XConsortium: lnx_init.c /main/7 1996/10/23 18:46:30 kaleb $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "lnx.h" + +#include + +#ifdef USE_DEV_FB +extern char *getenv(const char *); +#include +char *fb_dev_name; +#endif + +static Bool KeepTty = FALSE; +static int VTnum = -1; +static Bool VTSwitch = TRUE; +static Bool ShareVTs = FALSE; +static int activeVT = -1; + +static int vtPermSave[4]; +static char vtname[11]; + +static int +saveVtPerms(void) +{ + /* We need to use stat to get permissions. */ + struct stat svtp; + + /* Do them numerically ordered, hard coded tty0 first. */ + if (stat("/dev/tty0", &svtp) != 0) + return 0; + vtPermSave[0] = (int)svtp.st_uid; + vtPermSave[1] = (int)svtp.st_gid; + + /* Now check the console we are dealing with. */ + if (stat(vtname, &svtp) != 0) + return 0; + vtPermSave[2] = (int)svtp.st_uid; + vtPermSave[3] = (int)svtp.st_gid; + + return 1; +} + +static void +restoreVtPerms(void) +{ + /* Set the terminal permissions back to before we started. */ + chown("/dev/tty0", vtPermSave[0], vtPermSave[1]); + chown(vtname, vtPermSave[2], vtPermSave[3]); +} + +void +xf86OpenConsole(void) +{ + int i, fd = -1; + struct vt_mode VT; + struct vt_stat vts; + MessageType from = X_PROBED; +#ifdef USE_DEV_FB + struct fb_var_screeninfo var; + int fbfd; +#endif + char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; + char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; + + if (serverGeneration == 1) { + + /* when KeepTty check if we're run with euid==0 */ + if (KeepTty && geteuid() != 0) + FatalError("xf86OpenConsole:" + " Server must be suid root for option \"KeepTTY\"\n"); + + /* + * setup the virtual terminal manager + */ + if (VTnum != -1) { + xf86Info.vtno = VTnum; + from = X_CMDLINE; + } else { + + i=0; + while (tty0[i] != NULL) { + if ((fd = open(tty0[i],O_WRONLY,0)) >= 0) + break; + i++; + } + + if (fd < 0) + FatalError( + "xf86OpenConsole: Cannot open /dev/tty0 (%s)\n", + strerror(errno)); + + if (ShareVTs) + { + if (ioctl(fd, VT_GETSTATE, &vts) == 0) + xf86Info.vtno = vts.v_active; + else + FatalError("xf86OpenConsole: Cannot find the current" + " VT (%s)\n", strerror(errno)); + } else { + if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || + (xf86Info.vtno == -1)) + FatalError("xf86OpenConsole: Cannot find a free VT: %s\n", + strerror(errno)); + } + close(fd); + } + +#ifdef USE_DEV_FB + if (!ShareVTs) + { + fb_dev_name=getenv("FRAMEBUFFER"); + if (!fb_dev_name) + fb_dev_name="/dev/fb0current"; + + if ((fbfd = open(fb_dev_name, O_RDONLY)) < 0) + FatalError("xf86OpenConsole: Cannot open %s (%s)\n", + fb_dev_name, strerror(errno)); + + if (ioctl(fbfd, FBIOGET_VSCREENINFO, &var) < 0) + FatalError("xf86OpenConsole: Unable to get screen info %s\n", + strerror(errno)); + } +#endif + xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); + + if (!KeepTty) { + pid_t ppid = getppid(); + pid_t ppgid; + ppgid = getpgid(ppid); + + /* + * change to parent process group that pgid != pid so + * that setsid() doesn't fail and we become process + * group leader + */ + if (setpgid(0,ppgid) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: setpgid failed: %s\n", + strerror(errno)); + + /* become process group leader */ + if ((setsid() < 0)) + xf86Msg(X_WARNING, "xf86OpenConsole: setsid failed: %s\n", + strerror(errno)); + } + + i=0; + while (vcs[i] != NULL) { + sprintf(vtname, vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ + if ((xf86Info.consoleFd = open(vtname, O_RDWR|O_NDELAY, 0)) >= 0) + break; + i++; + } + + if (xf86Info.consoleFd < 0) + FatalError("xf86OpenConsole: Cannot open virtual console" + " %d (%s)\n", xf86Info.vtno, strerror(errno)); + + if (!ShareVTs) + { + /* + * Grab the vt ownership before we overwrite it. + * Hard coded /dev/tty0 into this function as well for below. + */ + if (!saveVtPerms()) + xf86Msg(X_WARNING, + "xf86OpenConsole: Could not save ownership of VT\n"); + + /* change ownership of the vt */ + if (chown(vtname, getuid(), getgid()) < 0) + xf86Msg(X_WARNING,"xf86OpenConsole: chown %s failed: %s\n", + vtname, strerror(errno)); + + /* + * the current VT device we're running on is not "console", we want + * to grab all consoles too + * + * Why is this needed?? + */ + if (chown("/dev/tty0", getuid(), getgid()) < 0) + xf86Msg(X_WARNING,"xf86OpenConsole: chown /dev/tty0 failed: %s\n", + strerror(errno)); + } + + /* + * Linux doesn't switch to an active vt after the last close of a vt, + * so we do this ourselves by remembering which is active now. + */ + if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0) + xf86Msg(X_WARNING,"xf86OpenConsole: VT_GETSTATE failed: %s\n", + strerror(errno)); + else + activeVT = vts.v_active; + +#if 0 + if (!KeepTty) { + /* + * Detach from the controlling tty to avoid char loss + */ + if ((i = open("/dev/tty",O_RDWR)) >= 0) { + ioctl(i, TIOCNOTTY, 0); + close(i); + } + } +#endif + + if (!ShareVTs) + { +#if defined(DO_OS_FONTRESTORE) + lnx_savefont(); +#endif + /* + * now get the VT + */ + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed: %s\n", + strerror(errno)); + + if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed: %s\n", + strerror(errno)); + + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_GETMODE failed %s\n", + strerror(errno)); + + signal(SIGUSR1, xf86VTRequest); + + VT.mode = VT_PROCESS; + VT.relsig = SIGUSR1; + VT.acqsig = SIGUSR1; + + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) + FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n", + strerror(errno)); + + if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) + FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n", + strerror(errno)); + + /* we really should have a InitOSInputDevices() function instead + * of Init?$#*&Device(). So I just place it here */ + +#ifdef USE_DEV_FB + /* copy info to new console */ + var.yoffset=0; + var.xoffset=0; + if (ioctl(fbfd, FBIOPUT_VSCREENINFO, &var)) + FatalError("Unable to set screen info\n"); + close(fbfd); +#endif + } else { /* ShareVTs */ + close(xf86Info.consoleFd); + } + signal(SIGUSR2, xf86ReloadInputDevs); + } else { /* serverGeneration != 1 */ + if (!ShareVTs && VTSwitch) + { + /* + * now get the VT + */ + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed %s\n", + strerror(errno)); + } + + if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0) + xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed %s\n", + strerror(errno)); + } + return; +} + +void +xf86CloseConsole() +{ + struct vt_mode VT; +#if defined(DO_OS_FONTRESTORE) + struct vt_stat vts; + int vtno = -1; +#endif + + if (ShareVTs) return; + +#if defined(DO_OS_FONTRESTORE) + if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETSTATE failed: %s\n", + strerror(errno)); + else + vtno = vts.v_active; +#endif + + /* Back to text mode ... */ + if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n", + strerror(errno)); + + if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n", + strerror(errno)); + else { + /* set dflt vt handling */ + VT.mode = VT_AUTO; + if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n", + strerror(errno)); + } + + if (VTSwitch) + { + /* + * Perform a switch back to the active VT when we were started + */ + if (activeVT >= 0) { + if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT) < 0) + xf86Msg(X_WARNING, "xf86CloseConsole: VT_ACTIVATE failed: %s\n", + strerror(errno)); + activeVT = -1; + } + +#if defined(DO_OS_FONTRESTORE) + if (xf86Info.vtno == vtno) /* check if we are active */ + lnx_restorefont(); + lnx_freefontdata(); +#endif + } + close(xf86Info.consoleFd); /* make the vt-manager happy */ + + restoreVtPerms(); /* restore the permissions */ + + return; +} + +int +xf86ProcessArgument(int argc, char *argv[], int i) +{ + /* + * Keep server from detaching from controlling tty. This is useful + * when debugging (so the server can receive keyboard signals. + */ + if (!strcmp(argv[i], "-keeptty")) + { + KeepTty = TRUE; + return(1); + } + if (!strcmp(argv[i], "-novtswitch")) + { + VTSwitch = FALSE; + return(1); + } + if (!strcmp(argv[i], "-sharevts")) + { + ShareVTs = TRUE; + return(1); + } + if ((argv[i][0] == 'v') && (argv[i][1] == 't')) + { + if (sscanf(argv[i], "vt%2d", &VTnum) == 0) + { + UseMsg(); + VTnum = -1; + return(0); + } + return(1); + } + return(0); +} + +void +xf86UseMsg() +{ + ErrorF("vtXX use the specified VT number\n"); + ErrorF("-keeptty "); + ErrorF("don't detach controlling tty (for debugging only)\n"); + ErrorF("-novtswitch don't immediately switch to new VT\n"); + ErrorF("-sharevts share VTs with another X server\n"); + return; +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c new file mode 100644 index 000000000..47df0dfb6 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c @@ -0,0 +1,275 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c,v 3.25 2003/08/19 17:32:34 tsi Exp $ */ +/* + * Copyright 1992 by Orest Zborowski + * Copyright 1993 by David Dawes + * + * 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 Orest Zborowski and David Dawes + * not be used in advertising or publicity pertaining to distribution of + * the software without specific, written prior permission. Orest Zborowski + * and David Dawes make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * OREST ZBOROWSKI AND DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID DAWES 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. + * + */ +/* $XConsortium: lnx_io.c /main/8 1996/10/19 18:06:28 kaleb $ */ + +#define NEED_EVENTS +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +#define KBC_TIMEOUT 250 /* Timeout in ms for sending to keyboard controller */ + +void +xf86SoundKbdBell(int loudness, int pitch, int duration) +{ + if (loudness && pitch) + { + ioctl(xf86Info.consoleFd, KDMKTONE, + ((1193190 / pitch) & 0xffff) | + (((unsigned long)duration * + loudness / 50) << 16)); + } +} + +void +xf86SetKbdLeds(int leds) +{ + ioctl(xf86Info.consoleFd, KDSETLED, leds); +} + +int +xf86GetKbdLeds() +{ + int leds = 0; + + ioctl(xf86Info.consoleFd, KDGETLED, &leds); + return(leds); +} + +/* kbd rate stuff based on kbdrate.c from Rik Faith et.al. + * from util-linux-2.9t package */ + +#include +#include +#ifdef __sparc__ +#include +#include +#endif + +/* Deal with spurious kernel header change in struct kbd_repeat. + We undo this define after the routine using that struct is over, + so as not to interfere with other 'rate' elements. */ +#if defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION) +# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,42) +# define rate period +# endif +#endif + +static int +KDKBDREP_ioctl_ok(int rate, int delay) { +#if defined(KDKBDREP) && !defined(__sparc__) + /* This ioctl is defined in but is not + implemented anywhere - must be in some m68k patches. */ + struct kbd_repeat kbdrep_s; + + /* don't change, just test */ + kbdrep_s.rate = -1; + kbdrep_s.delay = -1; + if (ioctl( xf86Info.consoleFd, KDKBDREP, &kbdrep_s )) { + return 0; + } + /* do the change */ + if (rate == 0) /* switch repeat off */ + kbdrep_s.rate = 0; + else + kbdrep_s.rate = 10000 / rate; /* convert cps to msec */ + if (kbdrep_s.rate < 1) + kbdrep_s.rate = 1; + kbdrep_s.delay = delay; + if (kbdrep_s.delay < 1) + kbdrep_s.delay = 1; + + if (ioctl( xf86Info.consoleFd, KDKBDREP, &kbdrep_s )) { + return 0; + } + + return 1; /* success! */ +#else /* no KDKBDREP */ + return 0; +#endif /* KDKBDREP */ +} + +#undef rate + +/* Undo the earlier define for the struct kbd_repeat problem. */ +#if defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION) +# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,42) +# undef rate +# endif +#endif + +static int +KIOCSRATE_ioctl_ok(int rate, int delay) { +#ifdef KIOCSRATE + struct kbd_rate kbdrate_s; + int fd; + + fd = open("/dev/kbd", O_RDONLY); + if (fd == -1) + return 0; + + kbdrate_s.rate = (rate + 5) / 10; /* must be integer, so round up */ + kbdrate_s.delay = delay * HZ / 1000; /* convert ms to Hz */ + if (kbdrate_s.rate > 50) + kbdrate_s.rate = 50; + + if (ioctl( fd, KIOCSRATE, &kbdrate_s )) { + return 0; + } + + close( fd ); + + return 1; +#else /* no KIOCSRATE */ + return 0; +#endif /* KIOCSRATE */ +} + +void xf86SetKbdRepeat(char rad) +{ +#ifdef __sparc__ + int rate = 500; /* Default rate */ + int delay = 200; /* Default delay */ +#else + int rate = 300; /* Default rate */ + int delay = 250; /* Default delay */ +#endif + +#if defined(__alpha__) || defined (__i386__) || defined(__ia64__) + int i; + int timeout; + int value = 0x7f; /* Maximum delay with slowest rate */ + + static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150, + 133, 120, 109, 100, 92, 86, 80, 75, 67, + 60, 55, 50, 46, 43, 40, 37, 33, 30, 27, + 25, 23, 21, 20 }; +#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int )) + + static int valid_delays[] = { 250, 500, 750, 1000 }; +#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int )) +#endif + + if (xf86Info.kbdRate >= 0) + rate = xf86Info.kbdRate * 10; + if (xf86Info.kbdDelay >= 0) + delay = xf86Info.kbdDelay; + + if(KDKBDREP_ioctl_ok(rate, delay)) /* m68k? */ + return; + + if(KIOCSRATE_ioctl_ok(rate, delay)) /* sparc? */ + return; + + if (xf86IsPc98()) + return; + +#if defined(__alpha__) || defined (__i386__) || defined(__ia64__) + + /* The ioport way */ + + for (i = 0; i < RATE_COUNT; i++) + if (rate >= valid_rates[i]) { + value &= 0x60; + value |= i; + break; + } + + for (i = 0; i < DELAY_COUNT; i++) + if (delay <= valid_delays[i]) { + value &= 0x1f; + value |= i << 5; + break; + } + + timeout = KBC_TIMEOUT; + while (((inb(0x64) & 2) == 2) && --timeout) + usleep(1000); /* wait */ + + if (timeout == 0) + return; + + outb(0x60, 0xf3); /* set typematic rate */ + while (((inb(0x64) & 2) == 2) && --timeout) + usleep(1000); /* wait */ + + usleep(10000); + outb(0x60, value); + +#endif /* __alpha__ || __i386__ || __ia64__ */ +} + +static int kbdtrans; +static struct termios kbdtty; + +void +xf86KbdInit() +{ + ioctl (xf86Info.consoleFd, KDGKBMODE, &kbdtrans); + tcgetattr (xf86Info.consoleFd, &kbdtty); +} + +int +xf86KbdOn() +{ + struct termios nTty; + +#ifdef __powerpc__ + if (xf86Info.kbdCustomKeycodes) + ioctl(xf86Info.consoleFd, KDSKBMODE, K_MEDIUMRAW); + else +#endif + ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW); + + nTty = kbdtty; + nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); + nTty.c_oflag = 0; + nTty.c_cflag = CREAD | CS8; + nTty.c_lflag = 0; + nTty.c_cc[VTIME]=0; + nTty.c_cc[VMIN]=1; + cfsetispeed(&nTty, 9600); + cfsetospeed(&nTty, 9600); + tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty); + return(xf86Info.consoleFd); +} + +int +xf86KbdOff() +{ + ioctl(xf86Info.consoleFd, KDSKBMODE, kbdtrans); + tcsetattr(xf86Info.consoleFd, TCSANOW, &kbdtty); + return(xf86Info.consoleFd); +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c new file mode 100644 index 000000000..dafdc0594 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c @@ -0,0 +1,188 @@ +/* $XConsortium: lnx_jstk.c /main/7 1996/02/21 17:51:36 kaleb $ */ +/* Id: lnx_jstk.c,v 1.1 1995/12/20 14:06:09 lepied Exp */ +/* + * Copyright 1995 by Frederic Lepied, France. + * + * 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 Frederic Lepied not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Frederic Lepied makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL FREDERIC LEPIED 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. + * + */ + +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_jstk.c,v 3.8.2.1 1998/06/05 16:23:12 dawes Exp $ */ + +static const char rcs_id[] = "Id: lnx_jstk.c,v 1.1 1995/12/20 14:06:09 lepied Exp"; + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#define inline __inline__ +#include +#include +#include + +#ifdef XFree86LOADER +#include "xf86.h" +#include "xf86_ansic.h" +#endif + +#if !defined(JSIOCGTIMELIMIT) +/* make 2.1.x joystick.h backward compatable */ +#define JSIOCGTIMELIMIT JS_GET_TIMELIMIT +#define JSIOCSTIMELIMIT JS_SET_TIMELIMIT +#define js_status JS_DATA_TYPE +#endif + + +/*********************************************************************** + * + * xf86JoystickOn -- + * + * open the device and init timeout according to the device value. + * + *********************************************************************** + */ + +int +xf86JoystickOn(char *name, int *timeout, int *centerX, int *centerY) +{ + int fd; + struct js_status js; + +#ifdef DEBUG + ErrorF("xf86JoystickOn %s\n", name); +#endif + + if ((fd = open(name, O_RDWR | O_NDELAY, 0)) < 0) + { + xf86Msg(X_WARNING, "Cannot open joystick '%s' (%s)\n", name, + strerror(errno)); + return -1; + } + + if (*timeout == 0) { + if (ioctl (fd, JSIOCGTIMELIMIT, timeout) == -1) { + Error("joystick JSIOCGTIMELIMIT ioctl"); + } + else { + xf86Msg(X_CONFIG, "Joystick: timeout value = %d\n", *timeout); + } + } + else { + if (ioctl(fd, JSIOCSTIMELIMIT, timeout) == -1) { + Error("joystick JSIOCSTIMELIMIT ioctl"); + } + } + + /* Assume the joystick is centred when this is called */ + read(fd, &js, JS_RETURN); + if (*centerX < 0) { + *centerX = js.x; + xf86Msg(X_CONFIG, "Joystick: CenterX set to %d\n", *centerX); + } + if (*centerY < 0) { + *centerY = js.y; + xf86Msg(X_CONFIG, "Joystick: CenterY set to %d\n", *centerY); + } + + return fd; +} + +/*********************************************************************** + * + * xf86JoystickInit -- + * + * called when X device is initialized. + * + *********************************************************************** + */ + +void +xf86JoystickInit() +{ + return; +} + +/*********************************************************************** + * + * xf86JoystickOff -- + * + * close the handle. + * + *********************************************************************** + */ + +int +xf86JoystickOff(int *fd, int doclose) +{ + int oldfd; + + if (((oldfd = *fd) >= 0) && doclose) { + close(*fd); + *fd = -1; + } + return oldfd; +} + +/*********************************************************************** + * + * xf86JoystickGetState -- + * + * return the state of buttons and the position of the joystick. + * + *********************************************************************** + */ + +int +xf86JoystickGetState(int fd, int *x, int *y, int *buttons) +{ + struct js_status js; + int status; + + status = read(fd, &js, JS_RETURN); + + if (status != JS_RETURN) + { + Error("Joystick read"); + return 0; + } + + *x = js.x; + *y = js.y; + *buttons = js.buttons; + + return 1; +} + +#ifdef XFree86LOADER +/* + * Entry point for XFree86 Loader + */ +void +linux_jstkModuleInit(pointer *data, INT32 *magic) +{ + *magic = MAGIC_DONE; + *data = NULL; +} +#endif + +/* end of lnx_jstk.c */ diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c new file mode 100644 index 000000000..b1fc95b56 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c @@ -0,0 +1,559 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.c,v 1.4 2003/11/03 05:11:52 tsi Exp $ */ + +/* + * Copyright (c) 2002 by The XFree86 Project, Inc. + * Author: Ivan Pascal. + * + * Based on the code from lnx_io.c which is + * Copyright 1992 by Orest Zborowski + * Copyright 1993 by David Dawes + */ + +#define NEED_EVENTS +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include + +#include "compiler.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" + +#include "xf86Xinput.h" +#include "xf86OSKbd.h" +#include "atKeynames.h" +#if defined(DO_OS_FONTRESTORE) +#include "lnx.h" +#endif +#include "lnx_kbd.h" + +#define KBC_TIMEOUT 250 /* Timeout in ms for sending to keyboard controller */ + +static KbdProtocolRec protocols[] = { + {"standard", PROT_STD }, + { NULL, PROT_UNKNOWN_KBD } +}; + +extern Bool VTSwitchEnabled; +#ifdef USE_VT_SYSREQ +extern Bool VTSysreqToggle; +#endif + +static void +SoundBell(InputInfoPtr pInfo, int loudness, int pitch, int duration) +{ + if (loudness && pitch) + { + ioctl(pInfo->fd, KDMKTONE, + ((1193190 / pitch) & 0xffff) | + (((unsigned long)duration * + loudness / 50) << 16)); + } +} + +static void +SetKbdLeds(InputInfoPtr pInfo, int leds) +{ + int real_leds = 0; + +#if defined (__sparc__) + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + if (pKbd->sunKbd) { + if (leds & 0x08) real_leds |= XLED1; + if (leds & 0x04) real_leds |= XLED3; + if (leds & 0x02) real_leds |= XLED4; + if (leds & 0x01) real_leds |= XLED2; + leds = real_leds; + real_leds = 0; + } +#endif /* defined (__sparc__) */ +#ifdef LED_CAP + if (leds & XLED1) real_leds |= LED_CAP; + if (leds & XLED2) real_leds |= LED_NUM; + if (leds & XLED3) real_leds |= LED_SCR; +#ifdef LED_COMP + if (leds & XLED4) real_leds |= LED_COMP; +#else + if (leds & XLED4) real_leds |= LED_SCR; +#endif +#endif + ioctl(pInfo->fd, KDSETLED, real_leds); +} + +static int +GetKbdLeds(InputInfoPtr pInfo) +{ + int real_leds, leds = 0; + + ioctl(pInfo->fd, KDGETLED, &real_leds); + + if (real_leds & LED_CAP) leds |= XLED1; + if (real_leds & LED_NUM) leds |= XLED2; + if (real_leds & LED_SCR) leds |= XLED3; + + return(leds); +} + +/* kbd rate stuff based on kbdrate.c from Rik Faith et.al. + * from util-linux-2.9t package */ + +#include +#include +#ifdef __sparc__ +#include +#include +#endif + +/* Deal with spurious kernel header change in struct kbd_repeat. + We undo this define after the routine using that struct is over, + so as not to interfere with other 'rate' elements. */ +#if defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION) +# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,42) +# define rate period +# endif +#endif + +static int +KDKBDREP_ioctl_ok(int rate, int delay) { +#if defined(KDKBDREP) && !defined(__sparc__) + /* This ioctl is defined in but is not + implemented anywhere - must be in some m68k patches. */ + struct kbd_repeat kbdrep_s; + + /* don't change, just test */ + kbdrep_s.rate = -1; + kbdrep_s.delay = -1; + if (ioctl( xf86Info.consoleFd, KDKBDREP, &kbdrep_s )) { + return 0; + } + + /* do the change */ + if (rate == 0) /* switch repeat off */ + kbdrep_s.rate = 0; + else + kbdrep_s.rate = 10000 / rate; /* convert cps to msec */ + if (kbdrep_s.rate < 1) + kbdrep_s.rate = 1; + kbdrep_s.delay = delay; + if (kbdrep_s.delay < 1) + kbdrep_s.delay = 1; + + if (ioctl( xf86Info.consoleFd, KDKBDREP, &kbdrep_s )) { + return 0; + } + + return 1; /* success! */ +#else /* no KDKBDREP */ + return 0; +#endif /* KDKBDREP */ +} + +#undef rate + +/* Undo the earlier define for the struct kbd_repeat problem. */ +#if defined(LINUX_VERSION_CODE) && defined(KERNEL_VERSION) +# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,42) +# undef rate +# endif +#endif + +static int +KIOCSRATE_ioctl_ok(int rate, int delay) { +#ifdef KIOCSRATE + struct kbd_rate kbdrate_s; + int fd; + + fd = open("/dev/kbd", O_RDONLY); + if (fd == -1) + return 0; + + kbdrate_s.rate = (rate + 5) / 10; /* must be integer, so round up */ + kbdrate_s.delay = delay * HZ / 1000; /* convert ms to Hz */ + if (kbdrate_s.rate > 50) + kbdrate_s.rate = 50; + + if (ioctl( fd, KIOCSRATE, &kbdrate_s )) { + return 0; + } + + close( fd ); + + return 1; +#else /* no KIOCSRATE */ + return 0; +#endif /* KIOCSRATE */ +} + +#undef rate + +static void +SetKbdRepeat(InputInfoPtr pInfo, char rad) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + int i; + int timeout; + int value = 0x7f; /* Maximum delay with slowest rate */ + +#ifdef __sparc__ + int rate = 500; /* Default rate */ + int delay = 200; /* Default delay */ +#else + int rate = 300; /* Default rate */ + int delay = 250; /* Default delay */ +#endif + + static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150, + 133, 120, 109, 100, 92, 86, 80, 75, 67, + 60, 55, 50, 46, 43, 40, 37, 33, 30, 27, + 25, 23, 21, 20 }; +#define RATE_COUNT (sizeof( valid_rates ) / sizeof( int )) + + static int valid_delays[] = { 250, 500, 750, 1000 }; +#define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int )) + + if (pKbd->rate >= 0) + rate = pKbd->rate * 10; + if (pKbd->delay >= 0) + delay = pKbd->delay; + + if(KDKBDREP_ioctl_ok(rate, delay)) /* m68k? */ + return; + + if(KIOCSRATE_ioctl_ok(rate, delay)) /* sparc? */ + return; + + if (xf86IsPc98()) + return; + +#if defined(__alpha__) || defined (__i386__) || defined(__ia64__) + + if (!xorgHWAccess) { + if (xf86EnableIO()) + xorgHWAccess = TRUE; + else + return; + } + + /* The ioport way */ + + for (i = 0; i < RATE_COUNT; i++) + if (rate >= valid_rates[i]) { + value &= 0x60; + value |= i; + break; + } + + for (i = 0; i < DELAY_COUNT; i++) + if (delay <= valid_delays[i]) { + value &= 0x1f; + value |= i << 5; + break; + } + + timeout = KBC_TIMEOUT; + while (((inb(0x64) & 2) == 2) && --timeout) + usleep(1000); /* wait */ + + if (timeout == 0) + return; + + outb(0x60, 0xf3); /* set typematic rate */ + while (((inb(0x64) & 2) == 2) && --timeout) + usleep(1000); /* wait */ + + usleep(10000); + outb(0x60, value); + +#endif /* __alpha__ || __i386__ || __ia64__ */ +} + +typedef struct { + int kbdtrans; + struct termios kbdtty; +} LnxKbdPrivRec, *LnxKbdPrivPtr; + +static int +KbdInit(InputInfoPtr pInfo, int what) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + LnxKbdPrivPtr priv = (LnxKbdPrivPtr) pKbd->private; + + if (pKbd->isConsole) { + ioctl (pInfo->fd, KDGKBMODE, &(priv->kbdtrans)); + tcgetattr (pInfo->fd, &(priv->kbdtty)); + } + if (!pKbd->CustomKeycodes) { + pKbd->RemapScanCode = ATScancode; + } + + return Success; +} + +static int +KbdOn(InputInfoPtr pInfo, int what) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + LnxKbdPrivPtr priv = (LnxKbdPrivPtr) pKbd->private; + struct termios nTty; + + if (pKbd->isConsole) { + if (pKbd->CustomKeycodes) + ioctl(pInfo->fd, KDSKBMODE, K_MEDIUMRAW); + else + ioctl(pInfo->fd, KDSKBMODE, K_RAW); + + nTty = priv->kbdtty; + nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); + nTty.c_oflag = 0; + nTty.c_cflag = CREAD | CS8; + nTty.c_lflag = 0; + nTty.c_cc[VTIME]=0; + nTty.c_cc[VMIN]=1; + cfsetispeed(&nTty, 9600); + cfsetospeed(&nTty, 9600); + tcsetattr(pInfo->fd, TCSANOW, &nTty); + } + return Success; +} + +static int +KbdOff(InputInfoPtr pInfo, int what) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + LnxKbdPrivPtr priv = (LnxKbdPrivPtr) pKbd->private; + + if (pKbd->isConsole) { + ioctl(pInfo->fd, KDSKBMODE, priv->kbdtrans); + tcsetattr(pInfo->fd, TCSANOW, &(priv->kbdtty)); + } + return Success; +} + +static int +GetSpecialKey(InputInfoPtr pInfo, int scanCode) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + int specialkey = scanCode; + +#if defined (__sparc__) + if (pKbd->sunKbd) { + switch (scanCode) { + case 0x2b: specialkey = KEY_BackSpace; break; + case 0x47: specialkey = KEY_KP_Minus; break; + case 0x7d: specialkey = KEY_KP_Plus; break; + /* XXX needs cases for KEY_KP_Divide and KEY_KP_Multiply */ + case 0x05: specialkey = KEY_F1; break; + case 0x06: specialkey = KEY_F2; break; + case 0x08: specialkey = KEY_F3; break; + case 0x0a: specialkey = KEY_F4; break; + case 0x0c: specialkey = KEY_F5; break; + case 0x0e: specialkey = KEY_F6; break; + case 0x10: specialkey = KEY_F7; break; + case 0x11: specialkey = KEY_F8; break; + case 0x12: specialkey = KEY_F9; break; + case 0x07: specialkey = KEY_F10; break; + case 0x09: specialkey = KEY_F11; break; + case 0x0b: specialkey = KEY_F12; break; + default: specialkey = 0; break; + } + return specialkey; + } +#endif + + if (pKbd->CustomKeycodes) { + specialkey = pKbd->specialMap->map[scanCode]; + } + return specialkey; +} + +#define ModifierSet(k) ((modifiers & (k)) == (k)) + +static +Bool SpecialKey(InputInfoPtr pInfo, int key, Bool down, int modifiers) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + + if(!pKbd->vtSwitchSupported) + return FALSE; + + if ((ModifierSet(ControlMask | AltMask)) || + (ModifierSet(ControlMask | AltLangMask))) { + if (VTSwitchEnabled && !xf86Info.vtSysreq && !xf86Info.dontVTSwitch) { + switch (key) { + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + if (down) { + ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F1 + 1); + return TRUE; + } + case KEY_F11: + case KEY_F12: + if (down) { + ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F11 + 11); + return TRUE; + } + } + } + } +#ifdef USE_VT_SYSREQ + if (VTSwitchEnabled && xf86Info.vtSysreq && !xf86Info.dontVTSwitch) { + switch (key) { + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + if (VTSysreqToggle && down) { + ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F1 + 1); + VTSysreqToggle = FALSE; + return TRUE; + } + break; + case KEY_F11: + case KEY_F12: + if (VTSysreqToggle && down) { + ioctl(xf86Info.consoleFd, VT_ACTIVATE, key - KEY_F11 + 11); + VTSysreqToggle = FALSE; + return TRUE; + } + break; + /* Ignore these keys -- ie don't let them cancel an alt-sysreq */ + case KEY_Alt: + case KEY_AltLang: + break; + case KEY_SysReqest: + if ((ModifierSet(AltMask) || ModifierSet(AltLangMask)) && down) + VTSysreqToggle = TRUE; + break; + default: + /* + * We only land here when Alt-SysReq is followed by a + * non-switching key. + */ + if (VTSysreqToggle) + VTSysreqToggle = FALSE; + } + } +#endif /* USE_VT_SYSREQ */ + return FALSE; +} + +static void +stdReadInput(InputInfoPtr pInfo) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + unsigned char rBuf[64]; + int nBytes, i; + if ((nBytes = read( pInfo->fd, (char *)rBuf, sizeof(rBuf))) > 0) { + for (i = 0; i < nBytes; i++) + pKbd->PostEvent(pInfo, rBuf[i] & 0x7f, + rBuf[i] & 0x80 ? FALSE : TRUE); + } +} + +static Bool +OpenKeyboard(InputInfoPtr pInfo) +{ + KbdDevPtr pKbd = (KbdDevPtr) pInfo->private; + int i; + KbdProtocolId prot = PROT_UNKNOWN_KBD; + char *s; + + s = xf86SetStrOption(pInfo->options, "Protocol", NULL); + for (i = 0; protocols[i].name; i++) { + if (xf86NameCmp(s, protocols[i].name) == 0) { + prot = protocols[i].id; + break; + } + } + + switch (prot) { + case PROT_STD: + pInfo->read_input = stdReadInput; + break; + default: + xf86Msg(X_ERROR,"\"%s\" is not a valid keyboard protocol name\n", s); + xfree(s); + return FALSE; + } + + xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, s); + xfree(s); + + s = xf86SetStrOption(pInfo->options, "Device", NULL); + if (s == NULL) { + pInfo->fd = xf86Info.consoleFd; + pKbd->isConsole = TRUE; + } else { + pInfo->fd = open(s, O_RDONLY | O_NONBLOCK | O_EXCL); + if (pInfo->fd == -1) { + xf86Msg(X_ERROR, "%s: cannot open \"%s\"\n", pInfo->name, s); + xfree(s); + return FALSE; + } + pKbd->isConsole = FALSE; + xfree(s); + } + + if (pKbd->isConsole) + pKbd->vtSwitchSupported = TRUE; + + return TRUE; +} + +Bool +xf86OSKbdPreInit(InputInfoPtr pInfo) +{ + KbdDevPtr pKbd = pInfo->private; + + pKbd->KbdInit = KbdInit; + pKbd->KbdOn = KbdOn; + pKbd->KbdOff = KbdOff; + pKbd->Bell = SoundBell; + pKbd->SetLeds = SetKbdLeds; + pKbd->GetLeds = GetKbdLeds; + pKbd->SetKbdRepeat = SetKbdRepeat; + pKbd->KbdGetMapping = KbdGetMapping; + pKbd->SpecialKey = SpecialKey; + + pKbd->RemapScanCode = NULL; + pKbd->GetSpecialKey = GetSpecialKey; + + pKbd->OpenKeyboard = OpenKeyboard; + pKbd->vtSwitchSupported = FALSE; + + pKbd->private = xcalloc(sizeof(LnxKbdPrivRec), 1); + if (pKbd->private == NULL) { + xf86Msg(X_ERROR,"can't allocate keyboard OS private data\n"); + return FALSE; + } + +#if defined(__powerpc__) + { + FILE *f; + f = fopen("/proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes","r"); + if (f) { + if (fgetc(f) == '0') + pKbd->CustomKeycodes = TRUE; + fclose(f); + } + } +#endif + return TRUE; +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.h b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.h new file mode 100644 index 000000000..7b9cd434e --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kbd.h @@ -0,0 +1,5 @@ +/* $XFree86$ */ + +extern void KbdGetMapping(InputInfoPtr pInfo, KeySymsPtr pKeySyms, + CARD8 *pModMap); + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c new file mode 100644 index 000000000..c211d115a --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c @@ -0,0 +1,113 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_kmod.c,v 3.5 2001/10/01 13:44:14 eich Exp $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include "xf86_OSlib.h" +#include "xf86.h" + + +#define MODPROBE_PATH_FILE "/proc/sys/kernel/modprobe" +#define MAX_PATH 1024 + + +#if 0 +/* XFree86 #defines execl to be the xf86execl() function which does + * a fork AND exec. We don't want that. We want the regular, + * standard execl(). + */ +#ifdef execl +#undef execl +#endif +#endif + + +/* + * Load a Linux kernel module. + * This is used by the DRI/DRM to load a DRM kernel module when + * the X server starts. It could be used for other purposes in the future. + * Input: + * modName - name of the kernel module (Ex: "tdfx") + * Return: + * 0 for failure, 1 for success + */ +int +xf86LoadKernelModule(const char *modName) +{ + char mpPath[MAX_PATH] = ""; + int fd = -1, status, n; + pid_t pid; + + /* get the path to the modprobe program */ + fd = open(MODPROBE_PATH_FILE, O_RDONLY); + if (fd >= 0) { + int count = read(fd, mpPath, MAX_PATH - 1); + if (count <= 0) { + mpPath[0] = 0; + } + else if (mpPath[count - 1] == '\n') { + mpPath[count - 1] = 0; /* replaces \n with \0 */ + } + close(fd); + /* if this worked, mpPath will be "/sbin/modprobe" or similar. */ + } + + if (mpPath[0] == 0) { + /* we failed to get the path from the system, use a default */ + strcpy(mpPath, "/sbin/modprobe"); + } + + /* now fork/exec the modprobe command */ + /* + * It would be good to capture stdout/stderr so that it can be directed + * to the log file. modprobe errors currently are missing from the log + * file. + */ + switch (pid = fork()) { + case 0: /* child */ + /* change real/effective user ID to 0/0 as we need to + * preinstall agpgart module for some DRM modules + */ + if (setreuid(0,0)) { + xf86Msg(X_WARNING,"LoadKernelModule: " + "Setting of real/effective user Id to 0/0 failed"); + } + setenv("PATH","/sbin",1); + n = execl(mpPath, "modprobe", modName, NULL); + xf86Msg(X_WARNING,"LoadKernelModule %s\n",strerror(errno)); + exit(EXIT_FAILURE); /* if we get here the child's exec failed */ + break; + case -1: /* fork failed */ + return 0; + default: /* fork worked */ + { + /* XXX we loop over waitpid() because it sometimes fails on + * the first attempt. Don't know why! + */ + int count = 0, p; + do { + p = waitpid(pid, &status, 0); + } while (p == -1 && count++ < 4); + + if (p == -1) { + return 0; + } + + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { + return 1; /* success! */ + } + else { + return 0; + } + } + } + + /* never get here */ + return 0; +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c new file mode 100644 index 000000000..d73c69853 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c @@ -0,0 +1,206 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_mouse.c,v 1.2 2003/10/08 14:58:30 dawes Exp $ */ + +/* + * Copyright 1999 by The XFree86 Project, Inc. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include "xf86.h" +#include "xf86Xinput.h" +#include "xf86OSmouse.h" +#include "xf86_OSlib.h" +#include +#include +#include + +static int +SupportedInterfaces(void) +{ + return MSE_SERIAL | MSE_BUS | MSE_PS2 | MSE_XPS2 | MSE_AUTO; +} + +static const char * +DefaultProtocol(void) +{ + return "Auto"; +} + +#define DEFAULT_MOUSE_DEV "/dev/mouse" +#define DEFAULT_PS2_DEV "/dev/psaux" +#define DEFAULT_GPM_DATA_DEV "/dev/gpmdata" +#define DEFAULT_GPM_CTL_DEV "/dev/gpmdata" + +static const char *mouseDevs[] = { + DEFAULT_MOUSE_DEV, + DEFAULT_PS2_DEV, + DEFAULT_GPM_DATA_DEV, + NULL +}; + +typedef enum { + MOUSE_PROTO_UNKNOWN = 0, + MOUSE_PROTO_SERIAL, + MOUSE_PROTO_PS2, + MOUSE_PROTO_MSC, + MOUSE_PROTO_GPM +} protocolTypes; + +static struct { + protocolTypes proto; + const char *name; +} devproto[] = { + { MOUSE_PROTO_UNKNOWN, NULL }, + { MOUSE_PROTO_PS2, "PS/2" }, + { MOUSE_PROTO_MSC, "MouseSystems" }, + { MOUSE_PROTO_GPM, "GPM" } +}; + +static const char * +FindDevice(InputInfoPtr pInfo, const char *protocol, int flags) +{ + int fd = -1; + const char **pdev; + + for (pdev = mouseDevs; *pdev; pdev++) { + SYSCALL (fd = open(*pdev, O_RDWR | O_NONBLOCK | O_EXCL)); + if (fd == -1) { +#ifdef DEBUG + ErrorF("Cannot open %s (%s)\n", *pdev, strerror(errno)); +#endif + } else + break; + } + + if (*pdev) { + close(fd); + /* Set the Device option. */ + pInfo->conf_idev->commonOptions = + xf86AddNewOption(pInfo->conf_idev->commonOptions, "Device", *pdev); + xf86Msg(X_INFO, "%s: Setting Device option to \"%s\"\n", + pInfo->name, *pdev); + } + + return *pdev; +} + +static const char * +GuessProtocol(InputInfoPtr pInfo, int flags) +{ + int fd = -1; + const char *dev; + char *realdev; + struct stat sbuf; + int i; + int proto = MOUSE_PROTO_UNKNOWN; + + dev = xf86SetStrOption(pInfo->conf_idev->commonOptions, "Device", NULL); + if (!dev) { +#ifdef DEBUG + ErrorF("xf86SetStrOption failed to return the device name\n"); +#endif + return NULL; + } + /* Look at the device name to guess the protocol. */ + realdev = NULL; + if (strcmp(dev, DEFAULT_MOUSE_DEV) == 0) { + if (lstat(dev, &sbuf) != 0) { +#ifdef DEBUG + ErrorF("lstat failed for %s (%s)\n", dev, strerror(errno)); +#endif + return NULL; + } + if (S_ISLNK(sbuf.st_mode)) { + realdev = xnfalloc(PATH_MAX + 1); + i = readlink(dev, realdev, PATH_MAX); + if (i <= 0) { +#ifdef DEBUG + ErrorF("readlink failed for %s (%s)\n", dev, strerror(errno)); +#endif + xfree(realdev); + return NULL; + } + realdev[i] = '\0'; + } + } + if (!realdev) + realdev = xnfstrdup(dev); + else { + /* If realdev doesn't contain a '/' then prepend "/dev/" */ + if (!strchr(realdev, '/')) { + char *tmp = xnfalloc(strlen(realdev) + 5 + 1); + sprintf(tmp, "/dev/%s", realdev); + xfree(realdev); + realdev = tmp; + } + } + + if (strcmp(realdev, DEFAULT_PS2_DEV) == 0) + proto = MOUSE_PROTO_PS2; + else if (strcmp(realdev, DEFAULT_GPM_DATA_DEV) == 0) + proto = MOUSE_PROTO_MSC; + else if (strcmp(realdev, DEFAULT_GPM_CTL_DEV) == 0) + proto = MOUSE_PROTO_GPM; + xfree(realdev); + /* + * If the protocol can't be guessed from the device name, + * try to characterise it. + */ + if (proto == MOUSE_PROTO_UNKNOWN) { + SYSCALL (fd = open(dev, O_RDWR | O_NONBLOCK | O_EXCL)); + if (isatty(fd)) { + /* Serial PnP has already failed, so give up. */ + } else { + if (fstat(fd, &sbuf) != 0) { +#ifdef DEBUG + ErrorF("fstat failed for %s (%s)\n", dev, strerror(errno)); +#endif + close(fd); + return NULL; + } + if (S_ISFIFO(sbuf.st_mode)) { + /* Assume GPM data in MSC format. */ + proto = MOUSE_PROTO_MSC; + } else { + /* Default to PS/2 */ + proto = MOUSE_PROTO_PS2; + } + } + close(fd); + } + if (proto == MOUSE_PROTO_UNKNOWN) { + xf86Msg(X_ERROR, "%s: GuessProtocol: Cannot find mouse protocol.\n", + pInfo->name); + return NULL; + } else { + for (i = 0; i < sizeof(devproto)/sizeof(devproto[0]); i++) { + if (devproto[i].proto == proto) { + xf86Msg(X_INFO, + "%s: GuessProtocol: " + "setting mouse protocol to \"%s\"\n", + pInfo->name, devproto[i].name); + return devproto[i].name; + } + } + } + return NULL; +} + +OSMouseInfoPtr +xf86OSMouseInit(int flags) +{ + OSMouseInfoPtr p; + + p = xcalloc(sizeof(OSMouseInfoRec), 1); + if (!p) + return NULL; + p->SupportedInterfaces = SupportedInterfaces; + p->DefaultProtocol = DefaultProtocol; + p->FindDevice = FindDevice; + p->GuessProtocol = GuessProtocol; + return p; +} + diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c new file mode 100644 index 000000000..cec9226c8 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c @@ -0,0 +1,230 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c,v 3.8 2002/04/09 15:59:37 tsi Exp $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include +#include "os.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS +#include "xf86_OSproc.h" +#include "xf86Pci.h" + +#ifdef __sparc__ +#define PCIADDR_TYPE long long +#define PCIADDR_IGNORE_FMT "%*x" +#define PCIADDR_FMT "%llx" +#else +#define PCIADDR_TYPE long +#define PCIADDR_IGNORE_FMT "%*x" +#define PCIADDR_FMT "%lx" +#endif + +FILE *xf86OSLinuxPCIFile = NULL; + +Bool +xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits) +{ + char c[0x200]; + char *res; + unsigned int bus, devfn, dev, fn; + unsigned PCIADDR_TYPE size[7]; + unsigned int num; + signed PCIADDR_TYPE Size; + + if (index > 7) + return FALSE; + + if (!xf86OSLinuxPCIFile && \ + !(xf86OSLinuxPCIFile = fopen("/proc/bus/pci/devices","r"))) + return FALSE; + do { + res = fgets(c,0x1ff,xf86OSLinuxPCIFile); + if (res) { + num = sscanf(res, + /*bus+dev vendorid deviceid irq */ + "%02x%02x\t%*04x%*04x\t%*x" + /* 7 PCI resource base addresses */ + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + /* 7 PCI resource sizes, and then optionally a driver name */ + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT, + &bus,&devfn,&size[0],&size[1],&size[2],&size[3], + &size[4],&size[5],&size[6]); + if (num != 9) { /* apparantly not 2.3 style */ + fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET); + return FALSE; + } + dev = devfn >> 3; + fn = devfn & 0x7; + if (tag == pciTag(bus,dev,fn)) { + *bits = 0; + if (size[index] != 0) { + Size = size[index] - ((PCIADDR_TYPE) 1); + while (Size & ((PCIADDR_TYPE) 0x01)) { + Size = Size >> ((PCIADDR_TYPE) 1); + (*bits)++; + } + } + fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET); + return TRUE; + } + } + } while (res); + + fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET); + return FALSE; +} + + + +/* Query the kvirt address (64bit) of a BAR range from TAG */ +Bool +xf86GetPciOffsetFromOS(PCITAG tag, int index, unsigned long* bases) +{ + FILE *file; + char c[0x200]; + char *res; + unsigned int bus, devfn, dev, fn; + unsigned PCIADDR_TYPE offset[7]; + unsigned int num; + + if (index > 7) + return FALSE; + + if (!(file = fopen("/proc/bus/pci/devices","r"))) + return FALSE; + do { + res = fgets(c,0x1ff,file); + if (res) { + num = sscanf(res, + /*bus+dev vendorid deviceid irq */ + "%02x%02x\t%*04x%*04x\t%*x" + /* 7 PCI resource base addresses */ + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + /* 7 PCI resource sizes, and then optionally a driver name */ + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT + "\t" PCIADDR_IGNORE_FMT, + &bus,&devfn,&offset[0],&offset[1],&offset[2],&offset[3], + &offset[4],&offset[5],&offset[6]); + if (num != 9) { /* apparantly not 2.3 style */ + fclose(file); + return FALSE; + } + + dev = devfn >> 3; + fn = devfn & 0x7; + if (tag == pciTag(bus,dev,fn)) { + /* return the offset for the index requested */ + *bases = offset[index]; + fclose(file); + return TRUE; + } + } + } while (res); + + fclose(file); + return FALSE; +} + +/* Query the kvirt address (64bit) of a BAR range from size for a given TAG */ +unsigned long +xf86GetOSOffsetFromPCI(PCITAG tag, int space, unsigned long base) +{ + FILE *file; + char c[0x200]; + char *res; + unsigned int bus, devfn, dev, fn; + unsigned PCIADDR_TYPE offset[7]; + unsigned PCIADDR_TYPE size[7]; + unsigned int num; + unsigned int ndx; + + if (!(file = fopen("/proc/bus/pci/devices","r"))) + return 0; + do { + res = fgets(c,0x1ff,file); + if (res) { + num = sscanf(res, + /*bus+dev vendorid deviceid irq */ + "%02x%02x\t%*04x%*04x\t%*x" + /* 7 PCI resource base addresses */ + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + /* 7 PCI resource sizes, and then optionally a driver name */ + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT + "\t" PCIADDR_FMT, + &bus,&devfn,&offset[0],&offset[1],&offset[2],&offset[3], + &offset[4],&offset[5],&offset[6], &size[0], &size[1], &size[2], + &size[3], &size[4], &size[5], &size[6]); + if (num != 16) { /* apparantly not 2.3 style */ + fclose(file); + return 0; + } + + dev = devfn >> 3; + fn = devfn & 0x7; + if (tag == pciTag(bus,dev,fn)) { + /* ok now look through all the BAR values of this device */ + for (ndx=0; ndx<7; ndx++) { + unsigned long savePtr; + /* + * remember to lop of the last 4bits of the BAR values as they are + * memory attributes + */ + if (ndx == 6) + savePtr = (0xFFFFFFF0) & + pciReadLong(tag, PCI_CMD_BIOS_REG); + else /* this the ROM bar */ + savePtr = (0xFFFFFFF0) & + pciReadLong(tag, PCI_CMD_BASE_REG + (0x4 * ndx)); + + /* find the index of the incoming base */ + if (base >= savePtr && base <= (savePtr + size[ndx])) { + fclose(file); + return (offset[ndx] & ~(0xFUL)) + (base - savePtr); + } + } + } + } + } while (res); + + fclose(file); + return 0; + +} diff --git a/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c new file mode 100644 index 000000000..577439c54 --- /dev/null +++ b/nx-X11/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c @@ -0,0 +1,1169 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c,v 1.10 2005/09/19 18:38:26 alanc Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c,v 3.67 2003/06/25 18:27:07 eich Exp $ */ +/* + * Copyright 1992 by Orest Zborowski + * Copyright 1993 by David Wexelblat + * + * 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 Orest Zborowski and David Wexelblat + * not be used in advertising or publicity pertaining to distribution of + * the software without specific, written prior permission. Orest Zborowski + * 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. + * + * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI 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. + * + */ +/* $XConsortium: lnx_video.c /main/9 1996/10/19 18:06:34 kaleb $ */ + +#ifdef HAVE_XORG_CONFIG_H +#include +#endif + +#include +#include + +#include +#include "input.h" +#include "scrnintstr.h" + +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86_OSlib.h" +#include "xf86OSpriv.h" +#include "lnx.h" +#ifdef __alpha__ +#include "shared/xf86Axp.h" +#endif + +#ifdef HAS_MTRR_SUPPORT +#include +#endif + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +static Bool ExtendedEnabled = FALSE; + +#ifdef __ia64__ + +#include "compiler.h" +#include + +#elif !defined(__powerpc__) && \ + !defined(__mc68000__) && \ + !defined(__sparc__) && \ + !defined(__mips__) + +/* + * Due to conflicts with "compiler.h", don't rely on to declare + * these. + */ +extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on); +extern int iopl(int __level); + +#endif + +#ifdef __alpha__ + +# ifdef LIBC_IS_FIXED +extern void sethae(unsigned long hae); +# else +# include +# define sethae(x) syscall(301,x); +# endif + +/* define to test the Sparse addressing on a non-Jensen */ +# ifdef TEST_JENSEN_CODE +# define isJensen (1) +# else +# define isJensen (axpSystem == JENSEN) +# endif + +# define BUS_BASE bus_base + +#else + +#define BUS_BASE (0) + +#endif /* __alpha__ */ + +/***************************************************************************/ +/* Video Memory Mapping section */ +/***************************************************************************/ + +static pointer mapVidMem(int, unsigned long, unsigned long, int); +static void unmapVidMem(int, pointer, unsigned long); +#if defined (__alpha__) +static pointer mapVidMemSparse(int, unsigned long, unsigned long, int); +extern axpDevice lnxGetAXP(void); +static void unmapVidMemSparse(int, pointer, unsigned long); +# if defined(JENSEN_SUPPORT) +static pointer mapVidMemJensen(int, unsigned long, unsigned long, int); +static void unmapVidMemJensen(int, pointer, unsigned long); +# endif +static axpDevice axpSystem = -1; +static Bool needSparse; +static unsigned long hae_thresh; +static unsigned long hae_mask; +static unsigned long bus_base; +static unsigned long sparse_size; +#endif + +#ifdef HAS_MTRR_SUPPORT + +#define SPLIT_WC_REGIONS 1 + +static pointer setWC(int, unsigned long, unsigned long, Bool, MessageType); +static void undoWC(int, pointer); + +/* The file desc for /proc/mtrr. Once opened, left opened, and the mtrr + driver will clean up when we exit. */ +#define MTRR_FD_UNOPENED (-1) /* We have yet to open /proc/mtrr */ +#define MTRR_FD_PROBLEM (-2) /* We tried to open /proc/mtrr, but had + a problem. */ +static int mtrr_fd = MTRR_FD_UNOPENED; + +/* Open /proc/mtrr. FALSE on failure. Will always fail on Linux 2.0, + and will fail on Linux 2.2 with MTRR support configured out, + so verbosity should be chosen appropriately. */ +static Bool +mtrr_open(int verbosity) +{ + /* Only report absence of /proc/mtrr once. */ + static Bool warned = FALSE; + + char **fn; + static char *mtrr_files[] = { + "/dev/cpu/mtrr", /* Possible future name */ + "/proc/mtrr", /* Current name */ + NULL + }; + + if (mtrr_fd == MTRR_FD_UNOPENED) { + /* So open it. */ + for (fn = mtrr_files; mtrr_fd < 0 && *fn; fn++) + mtrr_fd = open(*fn, O_WRONLY); + + if (mtrr_fd < 0) + mtrr_fd = MTRR_FD_PROBLEM; + } + + if (mtrr_fd == MTRR_FD_PROBLEM) { + /* To make sure we only ever warn once, need to check + verbosity outside xf86MsgVerb */ + if (!warned && verbosity <= xf86GetVerbosity()) { + xf86MsgVerb(X_WARNING, verbosity, + "System lacks support for changing MTRRs\n"); + warned = TRUE; + } + + return FALSE; + } + else + return TRUE; +} + +/* + * We maintain a list of WC regions for each physical mapping so they can + * be undone when unmapping. + */ + +struct mtrr_wc_region { + struct mtrr_sentry sentry; + Bool added; /* added WC or removed it */ + struct mtrr_wc_region * next; +}; + + +static struct mtrr_wc_region * +mtrr_cull_wc_region(int screenNum, unsigned long base, unsigned long size, + MessageType from) +{ + /* Some BIOS writers thought that setting wc over the mmio + region of a graphics devices was a good idea. Try to fix + it. */ + + struct mtrr_gentry gent; + struct mtrr_wc_region *wcreturn = NULL, *wcr; + int count, ret=0; + + /* Linux 2.0 users should not get a warning without -verbose */ + if (!mtrr_open(2)) + return NULL; + + for (gent.regnum = 0; + ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; + gent.regnum++) { + if (gent.type != MTRR_TYPE_WRCOMB + || gent.base + gent.size <= base + || base + size <= gent.base) + continue; + + /* Found an overlapping region. Delete it. */ + + wcr = xalloc(sizeof(*wcr)); + if (!wcr) + return NULL; + wcr->sentry.base = gent.base; + wcr->sentry.size = gent.size; + wcr->sentry.type = MTRR_TYPE_WRCOMB; + wcr->added = FALSE; + + count = 3; + while (count-- && + (ret = ioctl(mtrr_fd, MTRRIOC_KILL_ENTRY, &(wcr->sentry))) < 0); + + if (ret >= 0) { + xf86DrvMsg(screenNum, from, + "Removed MMIO write-combining range " + "(0x%lx,0x%lx)\n", + (unsigned long) gent.base, (unsigned long) gent.size); + wcr->next = wcreturn; + wcreturn = wcr; + gent.regnum--; + } else { + xfree(wcr); + xf86DrvMsgVerb(screenNum, X_WARNING, 0, + "Failed to remove MMIO " + "write-combining range (0x%lx,0x%lx)\n", + gent.base, (unsigned long) gent.size); + } + } + return wcreturn; +} + + +static struct mtrr_wc_region * +mtrr_remove_offending(int screenNum, unsigned long base, unsigned long size, + MessageType from) +{ + struct mtrr_gentry gent; + struct mtrr_wc_region *wcreturn = NULL, **wcr; + + if (!mtrr_open(2)) + return NULL; + + wcr = &wcreturn; + for (gent.regnum = 0; + ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; gent.regnum++ ) { + if (gent.type == MTRR_TYPE_WRCOMB + && ((gent.base >= base && gent.base + gent.size < base + size) || + (gent.base > base && gent.base + gent.size <= base + size))) { + *wcr = mtrr_cull_wc_region(screenNum, gent.base, gent.size, from); + if (*wcr) gent.regnum--; + while(*wcr) { + wcr = &((*wcr)->next); + } + } + } + return wcreturn; +} + + +static struct mtrr_wc_region * +mtrr_add_wc_region(int screenNum, unsigned long base, unsigned long size, + MessageType from) +{ + struct mtrr_wc_region **wcr, *wcreturn, *curwcr; + + /* + * There can be only one.... + */ + + wcreturn = mtrr_remove_offending(screenNum, base, size, from); + wcr = &wcreturn; + while (*wcr) { + wcr = &((*wcr)->next); + } + + /* Linux 2.0 should not warn, unless the user explicitly asks for + WC. */ + + if (!mtrr_open(from == X_CONFIG ? 0 : 2)) + return wcreturn; + + *wcr = curwcr = xalloc(sizeof(**wcr)); + if (!curwcr) + return wcreturn; + + curwcr->sentry.base = base; + curwcr->sentry.size = size; + curwcr->sentry.type = MTRR_TYPE_WRCOMB; + curwcr->added = TRUE; + curwcr->next = NULL; + +#if SPLIT_WC_REGIONS + /* + * Splits up the write-combining region if it is not aligned on a + * size boundary. + */ + + { + unsigned long lbase, d_size = 1; + unsigned long n_size = size; + unsigned long n_base = base; + + for (lbase = n_base, d_size = 1; !(lbase & 1); + lbase = lbase >> 1, d_size <<= 1); + while (d_size > n_size) + d_size = d_size >> 1; +#ifdef DEBUG + ErrorF("WC_BASE: 0x%lx WC_END: 0x%lx\n",base,base+d_size-1); +#endif + n_base += d_size; + n_size -= d_size; + if (n_size) { + xf86DrvMsgVerb(screenNum,X_INFO,3,"Splitting WC range: " + "base: 0x%lx, size: 0x%lx\n",base,size); + curwcr->next = mtrr_add_wc_region(screenNum, n_base, n_size,from); + } + curwcr->sentry.size = d_size; + } + + /*****************************************************************/ +#endif /* SPLIT_WC_REGIONS */ + + if (ioctl(mtrr_fd, MTRRIOC_ADD_ENTRY, &curwcr->sentry) >= 0) { + /* Avoid printing on every VT switch */ + if (xf86ServerIsInitialising()) { + xf86DrvMsg(screenNum, from, + "Write-combining range (0x%lx,0x%lx)\n", + base, size); + } + return wcreturn; + } + else { + *wcr = curwcr->next; + xfree(curwcr); + + /* Don't complain about the VGA region: MTRR fixed + regions aren't currently supported, but might be in + the future. */ + if ((unsigned long)base >= 0x100000) { + xf86DrvMsgVerb(screenNum, X_WARNING, 0, + "Failed to set up write-combining range " + "(0x%lx,0x%lx)\n", base, size); + } + return wcreturn; + } +} + +static void +mtrr_undo_wc_region(int screenNum, struct mtrr_wc_region *wcr) +{ + struct mtrr_wc_region *p, *prev; + + if (mtrr_fd > 0) { + p = wcr; + while (p) { + if (p->added) + ioctl(mtrr_fd, MTRRIOC_DEL_ENTRY, &p->sentry); + prev = p; + p = p->next; + xfree(prev); + } + } +} + +static pointer +setWC(int screenNum, unsigned long base, unsigned long size, Bool enable, + MessageType from) +{ + if (enable) + return mtrr_add_wc_region(screenNum, base, size, from); + else + return mtrr_cull_wc_region(screenNum, base, size, from); +} + +static void +undoWC(int screenNum, pointer regioninfo) +{ + mtrr_undo_wc_region(screenNum, regioninfo); +} + +#endif /* HAS_MTRR_SUPPORT */ + +void +xf86OSInitVidMem(VidMemInfoPtr pVidMem) +{ + pVidMem->linearSupported = TRUE; +#ifdef __alpha__ + if (axpSystem == -1) { + axpSystem = lnxGetAXP(); + if ((needSparse = (_bus_base_sparse() > 0))) { + hae_thresh = xf86AXPParams[axpSystem].hae_thresh; + hae_mask = xf86AXPParams[axpSystem].hae_mask; + sparse_size = xf86AXPParams[axpSystem].size; + } + bus_base = _bus_base(); + } + if (isJensen) { +# ifndef JENSEN_SUPPORT + FatalError("Jensen is not supported any more\n" + "If you are intereseted in fixing Jensen support\n" + "please contact xfree86@xfree86.org\n"); +# else + xf86Msg(X_INFO,"Machine type is Jensen\n"); + pVidMem->mapMem = mapVidMemJensen; + pVidMem->unmapMem = unmapVidMemJensen; +# endif /* JENSEN_SUPPORT */ + } else if (needSparse) { + xf86Msg(X_INFO,"Machine needs sparse mapping\n"); + pVidMem->mapMem = mapVidMemSparse; + pVidMem->unmapMem = unmapVidMemSparse; + } else { + xf86Msg(X_INFO,"Machine type has 8/16 bit access\n"); + pVidMem->mapMem = mapVidMem; + pVidMem->unmapMem = unmapVidMem; + } +#else + pVidMem->mapMem = mapVidMem; + pVidMem->unmapMem = unmapVidMem; +#endif /* __alpha__ */ + + +#ifdef HAS_MTRR_SUPPORT + pVidMem->setWC = setWC; + pVidMem->undoWC = undoWC; +#endif + pVidMem->initialised = TRUE; +} + +#ifdef __sparc__ +/* Basically, you simply cannot do this on Sparc. You have to do something portable + * like use /dev/fb* or mmap() on /proc/bus/pci/X/Y nodes. -DaveM + */ +static pointer mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +{ + return NULL; +} +#else +static pointer +mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +{ + pointer base; + int fd; + int mapflags = MAP_SHARED; + int prot; + memType realBase, alignOff; + + realBase = Base & ~(getpagesize() - 1); + alignOff = Base - realBase; +#ifdef DEBUG + ErrorF("base: %lx, realBase: %lx, alignOff: %lx \n", + Base,realBase,alignOff); +#endif + +#if defined(__ia64__) +#ifndef MAP_WRITECOMBINED +#define MAP_WRITECOMBINED 0x00010000 +#endif +#ifndef MAP_NONCACHED +#define MAP_NONCACHED 0x00020000 +#endif + if(flags & VIDMEM_FRAMEBUFFER) + mapflags |= MAP_WRITECOMBINED; + else + mapflags |= MAP_NONCACHED; +#endif + +#if 0 + /* this will disappear when people upgrade their kernels */ + fd = open(DEV_MEM, + ((flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR) | O_SYNC); +#else + fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR); +#endif + if (fd < 0) + { + FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n", + strerror(errno)); + } + + if (flags & VIDMEM_READONLY) + prot = PROT_READ; + else + prot = PROT_READ | PROT_WRITE; + + /* This requires linux-0.99.pl10 or above */ + base = mmap((caddr_t)0, Size + alignOff, prot, mapflags, fd, + (off_t)realBase + BUS_BASE); + close(fd); + if (base == MAP_FAILED) { + FatalError("xf86MapVidMem: Could not mmap framebuffer" + " (0x%08lx,0x%lx) (%s)\n", Base, Size, + strerror(errno)); + } +#ifdef DEBUG + ErrorF("base: %lx aligned base: %lx\n",base, base + alignOff); +#endif + return (char *)base + alignOff; +} +#endif /* !(__sparc__) */ + +static void +unmapVidMem(int ScreenNum, pointer Base, unsigned long Size) +{ + memType alignOff = (memType)Base + - ((memType)Base & ~(getpagesize() - 1)); + +#ifdef DEBUG + ErrorF("alignment offset: %lx\n",alignOff); +#endif + munmap((caddr_t)((memType)Base - alignOff), (Size + alignOff)); +} + + +/***************************************************************************/ +/* I/O Permissions section */ +/***************************************************************************/ + +#if defined(__powerpc__) +volatile unsigned char *ioBase = NULL; + +#ifndef __NR_pciconfig_iobase +#define __NR_pciconfig_iobase 200 +#endif + +#endif + +Bool +xf86EnableIO(void) +{ +#if defined(__powerpc__) + int fd; + unsigned int ioBase_phys; +#endif + + if (ExtendedEnabled) + return TRUE; + +#if defined(__powerpc__) + ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); + + fd = open("/dev/mem", O_RDWR); + if (ioBase == NULL) { + ioBase = (volatile unsigned char *)mmap(0, 0x20000, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, + ioBase_phys); +/* Should this be fatal or just a warning? */ +#if 0 + if (ioBase == MAP_FAILED) { + xf86Msg(X_WARNING, + "xf86EnableIOPorts: Failed to map iobase (%s)\n", + strerror(errno)); + return FALSE; + } +#endif + } + close(fd); +#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) + if (ioperm(0, 1024, 1) || iopl(3)) { + if (errno == ENODEV) + ErrorF("xf86EnableIOPorts: no I/O ports found\n"); + else + FatalError("xf86EnableIOPorts: failed to set IOPL" + " for I/O (%s)\n", strerror(errno)); + return FALSE; + } +# if !defined(__alpha__) + ioperm(0x40,4,0); /* trap access to the timer chip */ + ioperm(0x60,4,0); /* trap access to the keyboard controller */ +# endif +#endif + ExtendedEnabled = TRUE; + + return TRUE; +} + +void +xf86DisableIO(void) +{ + if (!ExtendedEnabled) + return; +#if defined(__powerpc__) + munmap(ioBase, 0x20000); + ioBase = NULL; +#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) + iopl(0); + ioperm(0, 1024, 0); +#endif + ExtendedEnabled = FALSE; + + return; +} + + +/***************************************************************************/ +/* Interrupt Handling section */ +/***************************************************************************/ + +/* XXX The #ifdefs should be made simpler. */ + +Bool +xf86DisableInterrupts() +{ +#if !defined(__mc68000__) && !defined(__powerpc__) && !defined(__sparc__) && !defined(__mips__) && !defined(__ia64__) && !defined(__sh__) && !defined(__hppa__) + if (!ExtendedEnabled) + if (iopl(3) || ioperm(0, 1024, 1)) + return (FALSE); +#endif +#if defined(__alpha__) || defined(__mc68000__) || defined(__powerpc__) || defined(__sparc__) || defined(__mips__) || defined(__arm__) || defined(__sh__) || defined(__ia64__) || defined(__hppa__) +#else +# ifdef __GNUC__ +# if defined(__ia64__) +# if 0 + __asm__ __volatile__ (";; rsm psr.i;; srlz.d" ::: "memory"); +# endif +# else + __asm__ __volatile__("cli"); +# endif +# else + asm("cli"); +# endif +#endif +#if !defined(__mc68000__) && !defined(__powerpc__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__ia64__) && !defined(__hppa__) + if (!ExtendedEnabled) { + iopl(0); + ioperm(0, 1024, 0); + } + +#endif + return (TRUE); +} + +void +xf86EnableInterrupts() +{ +#if !defined(__mc68000__) && !defined(__powerpc__) && !defined(__sparc__) && !defined(__mips__) && !defined(__ia64__) && !defined(__sh__) && !defined(__hppa__) + if (!ExtendedEnabled) + if (iopl(3) || ioperm(0, 1024, 1)) + return; +#endif +#if defined(__alpha__) || defined(__mc68000__) || defined(__powerpc__) || defined(__sparc__) || defined(__mips__) || defined(__arm__) || defined(__sh__) || defined(__ia64__) || defined(__hppa__) +#else +# ifdef __GNUC__ +# if defined(__ia64__) +# if 0 + __asm__ __volatile__ (";; ssm psr.i;; srlz.d" ::: "memory"); +# endif +# else + __asm__ __volatile__("sti"); +# endif +# else + asm("sti"); +# endif +#endif +#if !defined(__mc68000__) && !defined(__powerpc__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__ia64__) && !defined(__hppa__) + if (!ExtendedEnabled) { + iopl(0); + ioperm(0, 1024, 0); + } +#endif + return; +} + +#if defined (__alpha__) + +#define vuip volatile unsigned int * + +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); +extern void +writeDenseNB16(int Value, pointer Base, register unsigned long Offset); +extern void +writeDenseNB32(int Value, pointer Base, register unsigned long Offset); +extern void +writeDense8(int Value, pointer Base, register unsigned long Offset); +extern void +writeDense16(int Value, pointer Base, register unsigned long Offset); +extern void +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); +static void +writeSparseNB16(int Value, pointer Base, register unsigned long Offset); +static void +writeSparseNB32(int Value, pointer Base, register unsigned long Offset); +static void +writeSparse8(int Value, pointer Base, register unsigned long Offset); +static void +writeSparse16(int Value, pointer Base, register unsigned long Offset); +static void +writeSparse32(int Value, pointer Base, register unsigned long Offset); + +#define DENSE_BASE 0x2ff00000000UL +#define SPARSE_BASE 0x30000000000UL + +static unsigned long msb_set = 0; + +static pointer +mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags) +{ + int fd, prot; + unsigned long ret, rets = 0; + + static Bool was_here = FALSE; + + if (!was_here) { + was_here = TRUE; + + xf86WriteMmio8 = writeSparse8; + xf86WriteMmio16 = writeSparse16; + xf86WriteMmio32 = writeSparse32; + xf86WriteMmioNB8 = writeSparseNB8; + xf86WriteMmioNB16 = writeSparseNB16; + xf86WriteMmioNB32 = writeSparseNB32; + xf86ReadMmio8 = readSparse8; + xf86ReadMmio16 = readSparse16; + xf86ReadMmio32 = readSparse32; + } + + fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR); + if (fd < 0) { + FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n", + strerror(errno)); + } + +#if 0 + xf86Msg(X_INFO,"mapVidMemSparse: try Base 0x%lx size 0x%lx flags 0x%x\n", + Base, Size, flags); +#endif + + if (flags & VIDMEM_READONLY) + prot = PROT_READ; + else + prot = PROT_READ | PROT_WRITE; + + /* This requirers linux-0.99.pl10 or above */ + + /* + * Always do DENSE mmap, since read32/write32 currently require it. + */ + ret = (unsigned long)mmap((caddr_t)(DENSE_BASE + Base), Size, + prot, MAP_SHARED, fd, + (off_t) (bus_base + Base)); + + /* + * Do SPARSE mmap only when MMIO and not MMIO_32BIT, or FRAMEBUFFER + * and SPARSE (which should require the use of read/write macros). + * + * By not SPARSE mmapping an 8MB framebuffer, we can save approx. 256K + * bytes worth of pagetable (32 pages). + */ + if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) || + ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) + { + rets = (unsigned long)mmap((caddr_t)(SPARSE_BASE + (Base << 5)), + Size << 5, prot, MAP_SHARED, fd, + (off_t) _bus_base_sparse() + (Base << 5)); + } + + close(fd); + + if (ret == (unsigned long)MAP_FAILED) { + FatalError("xf86MapVidMemSparse: Could not (dense) mmap fb (%s)\n", + strerror(errno)); + } + + if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) || + ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) + { + if (rets == (unsigned long)MAP_FAILED || + rets != (SPARSE_BASE + (Base << 5))) + { + FatalError("mapVidMemSparse: Could not (sparse) mmap fb (%s)\n", + strerror(errno)); + } + } + +#if 1 + if (rets) + xf86Msg(X_INFO,"mapVidMemSparse: mapped Base 0x%lx size 0x%lx" + " to DENSE at 0x%lx and SPARSE at 0x%lx\n", + Base, Size, ret, rets); + else + xf86Msg(X_INFO,"mapVidMemSparse: mapped Base 0x%lx size 0x%lx" + " to DENSE only at 0x%lx\n", + Base, Size, ret); + +#endif + return (pointer) ret; +} + +static void +unmapVidMemSparse(int ScreenNum, pointer Base, unsigned long Size) +{ + unsigned long Offset = (unsigned long)Base - DENSE_BASE; +#if 1 + xf86Msg(X_INFO,"unmapVidMemSparse: unmapping Base 0x%lx Size 0x%lx\n", + Base, Size); +#endif + /* Unmap DENSE always. */ + munmap((caddr_t)Base, Size); + + /* Unmap SPARSE always, and ignore error in case we did not map it. */ + munmap((caddr_t)(SPARSE_BASE + (Offset << 5)), Size << 5); +} + +static int +readSparse8(pointer Base, register unsigned long Offset) +{ + register unsigned long result, shift; + register unsigned long msb; + + mem_barrier(); + Offset += (unsigned long)Base - DENSE_BASE; + shift = (Offset & 0x3) << 3; + if (Offset >= (hae_thresh)) { + msb = Offset & hae_mask; + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } + } + + mem_barrier(); + result = *(vuip) (SPARSE_BASE + (Offset << 5)); + result >>= shift; + return 0xffUL & result; +} + +static int +readSparse16(pointer Base, register unsigned long Offset) +{ + register unsigned long result, shift; + register unsigned long msb; + + mem_barrier(); + Offset += (unsigned long)Base - DENSE_BASE; + shift = (Offset & 0x2) << 3; + if (Offset >= hae_thresh) { + msb = Offset & hae_mask; + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } + } + + mem_barrier(); + result = *(vuip)(SPARSE_BASE + (Offset<<5) + (1<<(5-2))); + result >>= shift; + return 0xffffUL & result; +} + +static int +readSparse32(pointer Base, register unsigned long Offset) +{ + /* NOTE: this is really using DENSE. */ + mem_barrier(); + return *(vuip)((unsigned long)Base+(Offset)); +} + +static void +writeSparse8(int Value, pointer Base, register unsigned long Offset) +{ + register unsigned long msb; + register unsigned int b = Value & 0xffU; + + write_mem_barrier(); + Offset += (unsigned long)Base - DENSE_BASE; + if (Offset >= hae_thresh) { + msb = Offset & hae_mask; + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } + } + + write_mem_barrier(); + *(vuip) (SPARSE_BASE + (Offset << 5)) = b * 0x01010101; +} + +static void +writeSparse16(int Value, pointer Base, register unsigned long Offset) +{ + register unsigned long msb; + register unsigned int w = Value & 0xffffU; + + write_mem_barrier(); + Offset += (unsigned long)Base - DENSE_BASE; + if (Offset >= hae_thresh) { + msb = Offset & hae_mask; + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } + } + + write_mem_barrier(); + *(vuip)(SPARSE_BASE + (Offset<<5) + (1<<(5-2))) = w * 0x00010001; +} + +static void +writeSparse32(int Value, pointer Base, register unsigned long Offset) +{ + /* NOTE: this is really using DENSE. */ + write_mem_barrier(); + *(vuip)((unsigned long)Base + (Offset)) = Value; + return; +} + +static void +writeSparseNB8(int Value, pointer Base, register unsigned long Offset) +{ + register unsigned long msb; + register unsigned int b = Value & 0xffU; + + Offset += (unsigned long)Base - DENSE_BASE; + if (Offset >= hae_thresh) { + msb = Offset & hae_mask; + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } + } + *(vuip) (SPARSE_BASE + (Offset << 5)) = b * 0x01010101; +} + +static void +writeSparseNB16(int Value, pointer Base, register unsigned long Offset) +{ + register unsigned long msb; + register unsigned int w = Value & 0xffffU; + + Offset += (unsigned long)Base - DENSE_BASE; + if (Offset >= hae_thresh) { + msb = Offset & hae_mask; + Offset -= msb; + if (msb_set != msb) { + sethae(msb); + msb_set = msb; + } + } + *(vuip)(SPARSE_BASE+(Offset<<5)+(1<<(5-2))) = w * 0x00010001; +} + +static void +writeSparseNB32(int Value, pointer Base, register unsigned long Offset) +{ + /* NOTE: this is really using DENSE. */ + *(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; + +#ifdef JENSEN_SUPPORT + +static int +readSparseJensen8(pointer Base, register unsigned long Offset); +static int +readSparseJensen16(pointer Base, register unsigned long Offset); +static int +readSparseJensen32(pointer Base, register unsigned long Offset); +static void +writeSparseJensen8(int Value, pointer Base, register unsigned long Offset); +static void +writeSparseJensen16(int Value, pointer Base, register unsigned long Offset); +static void +writeSparseJensen32(int Value, pointer Base, register unsigned long Offset); +static void +writeSparseJensenNB8(int Value, pointer Base, register unsigned long Offset); +static void +writeSparseJensenNB16(int Value, pointer Base, register unsigned long Offset); +static void +writeSparseJensenNB32(int Value, pointer Base, register unsigned long Offset); + +/* + * The Jensen lacks dense memory, thus we have to address the bus via + * the sparse addressing scheme. + * + * Martin Ostermann (ost@comnets.rwth-aachen.de) - Apr.-Sep. 1996 + */ + +#ifdef TEST_JENSEN_CODE +#define SPARSE (5) +#else +#define SPARSE (7) +#endif + +#define JENSEN_SHIFT(x) ((long)x<>= shift; + return 0xffUL & result; +} + +static int +readSparseJensen16(pointer Base, register unsigned long Offset) +{ + register unsigned long result, shift; + + mem_barrier(); + shift = (Offset & 0x2) << 3; + + result = *(vuip)((unsigned long)Base+(Offset<>= shift; + return 0xffffUL & result; +} + +static int +readSparseJensen32(pointer Base, register unsigned long Offset) +{ + register unsigned long result; + + mem_barrier(); + result = *(vuip)((unsigned long)Base+(Offset<