diff options
author | jrfonseca <jrfonseca> | 2003-11-29 15:15:19 +0000 |
---|---|---|
committer | jrfonseca <jrfonseca> | 2003-11-29 15:15:19 +0000 |
commit | f1286aa8631ae97529ca9419823d4f50ae40b3a2 (patch) | |
tree | 0d8cb85af777b1dfd5f29dba88f003241a134cd5 | |
parent | 1139e0d4d9ddd6d2480612643db394545a6a2ab4 (diff) |
Bring the changes from the trunk in order to compile with newer versions of glibc.s3virge-0-0-1-branch
10 files changed, 311 insertions, 70 deletions
diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile b/xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile index 919d13f90..0af1e3fb1 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile @@ -1,5 +1,5 @@ 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.43 2000/11/16 19:45:03 eich Exp $ +XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/Imakefile,v 3.47 2003/06/12 14:12:36 eich Exp $ #include <Server.tmpl> @@ -26,7 +26,10 @@ DRI_OBJ = sigio.o MOUSESRC = lnx_mouse.c MOUSEOBJ = lnx_mouse.o -#if defined(i386Architecture) || defined(ia64Architecture) +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 @@ -42,12 +45,12 @@ AXP_OBJ=lnx_ev56.o xf86Axp.o lnx_axp.o 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 $(MOUSESRC) \ lnx_pci.c vidmem.c lnx_apm.c $(JOYSTICK_SRC) $(DRI_SRC) $(RES_SRCS) \ - $(AXP_SRC) lnx_kmod.c lnx_agp.c + $(AXP_SRC) lnx_kmod.c lnx_agp.c $(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 $(MOUSEOBJ) \ lnx_pci.o vidmem.o lnx_apm.o $(JOYSTICK_OBJ) $(DRI_OBJ) $(RES_OBJS) \ - $(AXP_OBJ) lnx_kmod.o lnx_agp.o + $(AXP_OBJ) lnx_kmod.o lnx_agp.o $(KBDOBJ) /*wcHelper.o*/ INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC) -I. -I$(SERVERSRC)/include \ -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(XF86OSSRC)/shared @@ -95,6 +98,7 @@ InstallDynamicModule(lnx_jstk.o,$(MODULEDIR),input) 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) @@ -103,7 +107,7 @@ LinkSourceFile(kmod_noop.c,../shared) LinkSourceFile($(DRI_SRC),../shared) -#if defined(i386Architecture) || defined(ia64Architecture) +#if defined(i386Architecture) || defined(ia64Architecture) || defined (AMD64Architecture) LinkSourceFile(stdResource.c,../shared) #endif #if defined(AlphaArchitecture) diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx.h b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx.h index a81bfc201..f2dd16267 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx.h +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx.h @@ -1,11 +1,43 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx.h,v 3.2 2000/02/15 02:00:14 eich Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx.h,v 3.3 2002/11/25 14:05:04 eich Exp $ */ #ifndef LNX_H_ -#ifdef __alpha__ +# 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)); -#endif + +/* new pciconfig_iobase syscall added in 2.2.15 and 2.3.99 */ +# include <linux/unistd.h> +# include <asm/pci.h> +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__ */ #define LNX_H_ diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c index 14af61417..04e2f07c0 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnxResource.c,v 3.17 2001/11/01 23:35:33 dawes Exp $ */ +/* $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 */ @@ -12,8 +12,20 @@ #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__ -resRange PciAvoid[] = {_PCI_AVOID_PC_STYLE, _END}; resPtr xf86BusAccWindowsFromOS(void) @@ -112,6 +124,8 @@ xf86PciBusAccWindowsFromOS(void) return ret; } +#ifdef INCLUDE_UNUSED + resPtr xf86IsaBusAccWindowsFromOS(void) { @@ -126,6 +140,8 @@ xf86IsaBusAccWindowsFromOS(void) return ret; } +#endif /* INCLUDE_UNUSED */ + resPtr xf86AccResFromOS(resPtr ret) { @@ -165,18 +181,19 @@ xf86AccResFromOS(resPtr ret) return ret; } -#elif defined(__powerpc__) || defined(__sparc__) || defined(__mips__) || defined(__sh__) || defined(__mc68000__) || defined(__arm__) || defined(__s390__) || defined(__hppa__) +#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. */ -#ifdef __sparc__ -resRange PciAvoid[] = {_END}; -#else -resRange PciAvoid[] = {_PCI_AVOID_PC_STYLE, _END}; -#endif - resPtr xf86BusAccWindowsFromOS(void) { @@ -213,6 +230,8 @@ xf86PciBusAccWindowsFromOS(void) return ret; } +#ifdef INCLUDE_UNUSED */ + resPtr xf86IsaBusAccWindowsFromOS(void) { @@ -231,6 +250,8 @@ xf86IsaBusAccWindowsFromOS(void) return ret; } +#endif /* INCLUDE_UNUSED */ + resPtr xf86AccResFromOS(resPtr ret) { @@ -261,3 +282,5 @@ xf86AccResFromOS(resPtr ret) #error : Put your platform dependent code here!! #endif + +#endif /* INCLUDE_XF86_NO_DOMAIN */ diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c index 5de1089af..05e299b11 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c @@ -7,7 +7,7 @@ * Copyright © 2001 The XFree86 Project, Inc. */ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c,v 3.8 2001/11/26 19:02:02 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_agp.c,v 3.11 2003/04/03 22:47:42 dawes Exp $ */ #include "X.h" #include "xf86.h" @@ -18,7 +18,7 @@ #if defined(linux) #include <asm/ioctl.h> #include <linux/agpgart.h> -#elif defined(__FreeBSD__) || defined(__NetBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #include <sys/ioctl.h> #include <sys/agpio.h> #endif @@ -89,9 +89,16 @@ GARTInit(int screenNum) xf86ReleaseGART(-1); #if defined(linux) - /* Should this look for version >= rather than version == ? */ - if (agpinf.version.major != AGPGART_MAJOR_VERSION && - agpinf.version.minor != AGPGART_MINOR_VERSION) { + /* 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", @@ -262,6 +269,10 @@ xf86BindGARTMemory(int screenNum, int key, unsigned long offset) } pageOffset = offset / AGP_PAGE_SIZE; + xf86DrvMsgVerb(screenNum, X_INFO, 3, + "xf86BindGARTMemory: bind key %d at 0x%08x " + "(pgoffset %d)\n", key, offset, pageOffset); + bind.pg_start = pageOffset; bind.key = key; @@ -302,6 +313,9 @@ xf86UnbindGARTMemory(int screenNum, int key) return FALSE; } + xf86DrvMsgVerb(screenNum, X_INFO, 3, + "xf86UnbindGARTMemory: unbind key %d\n", key); + return TRUE; } diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c index b5585da5d..f2f326959 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c,v 3.12 2001/12/24 22:54:31 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_apm.c,v 3.13 2002/10/16 01:24:28 dawes Exp $ */ #include "X.h" #include "os.h" @@ -97,8 +97,12 @@ lnxPMConfirmEventToOs(int fd, pmEvent event) case XF86_APM_SYS_SUSPEND: case XF86_APM_CRITICAL_SUSPEND: case XF86_APM_USER_SUSPEND: - if (ioctl( fd, APM_IOC_SUSPEND, NULL )) - return PM_FAILED; + if (ioctl( fd, APM_IOC_SUSPEND, NULL )) { + if (errno == EBUSY) + return PM_CONTINUE; + else + return PM_FAILED; + } return PM_CONTINUE; case XF86_APM_STANDBY_RESUME: case XF86_APM_NORMAL_RESUME: diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c index 69f805d89..5813ef4e9 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c,v 1.4 2001/02/15 19:46:03 eich Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_axp.c,v 1.5 2002/11/25 14:05:04 eich Exp $ */ #include <stdio.h> #include "X.h" @@ -106,3 +106,91 @@ lnxGetAXP(void) } while (1); } +/* + * pciconfig_iobase wrappers and dynamic i/o selection + */ +#include <linux/unistd.h> +#include <asm/pci.h> +#include <errno.h> + +/* 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/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c index bbaa7625d..bfcb0d70f 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c,v 3.6 2001/02/15 11:03:56 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_ev56.c,v 3.7 2002/11/25 14:05:04 eich Exp $ */ #include "X.h" #include "input.h" @@ -85,3 +85,63 @@ 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/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c index c3f4b7d83..cc4b04122 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_io.c @@ -51,15 +51,15 @@ xf86SoundKbdBell(int loudness, int pitch, int duration) void xf86SetKbdLeds(int leds) { - ioctl(xf86Info.consoleFd, KDSETLED, leds); + ioctl(xf86Info.consoleFd, KDSETLED, leds); } int xf86GetKbdLeds() { - int leds; + int leds = 0; - ioctl(xf86Info.consoleFd, KDGETLED, &leds); + ioctl(xf86Info.consoleFd, KDGETLED, &leds); return(leds); } @@ -67,11 +67,19 @@ xf86GetKbdLeds() * from util-linux-2.9t package */ #include <linux/kd.h> +#include <linux/version.h> #ifdef __sparc__ #include <asm/param.h> #include <asm/kbio.h> #endif +/* Deal with spurious kernel header change */ +#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__) @@ -133,6 +141,7 @@ KIOCSRATE_ioctl_ok(int rate, int delay) { #endif /* KIOCSRATE */ } +#undef rate #if NeedFunctionPrototypes void xf86SetKbdRepeat(char rad) diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c index 39993c40a..5477b9130 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c,v 3.7 2001/06/01 20:03:05 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c,v 3.9 2003/02/17 15:29:22 dawes Exp $ */ #include <stdio.h> #include "X.h" @@ -11,11 +11,11 @@ #ifdef __sparc__ #define PCIADDR_TYPE long long -#define PCIADDR_IGNORE_FMT "%*llx" +#define PCIADDR_IGNORE_FMT "%*x" #define PCIADDR_FMT "%llx" #else #define PCIADDR_TYPE long -#define PCIADDR_IGNORE_FMT "%*lx" +#define PCIADDR_IGNORE_FMT "%*x" #define PCIADDR_FMT "%lx" #endif @@ -25,7 +25,7 @@ xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits) FILE *file; char c[0x200]; char *res; - int bus, devfn, dev, fn; + unsigned int bus, devfn, dev, fn; unsigned PCIADDR_TYPE size[7]; unsigned int num; signed PCIADDR_TYPE Size; diff --git a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c index 9e0ecbaa2..9f9e2d02c 100644 --- a/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c +++ b/xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_video.c,v 3.60 2001/11/01 23:35:33 dawes 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 <obz@Kodak.com> * Copyright 1993 by David Wexelblat <dwex@goblin.org> @@ -42,8 +42,6 @@ #include <asm/mtrr.h> #endif -extern int ioperm(unsigned long from, unsigned long num, int turn_on); - #ifndef MAP_FAILED #define MAP_FAILED ((void *)-1) #endif @@ -265,22 +263,14 @@ mtrr_add_wc_region(int screenNum, unsigned long base, unsigned long size, */ { - unsigned long last, lbase, d_size; + unsigned long lbase, d_size = 1; unsigned long n_size = size; unsigned long n_base = base; - - int i = 0; - last = n_base + n_size - 1; - for (lbase = n_base; !(lbase & 1) && (last & 1); - lbase = lbase >> 1, last = last >> 1, i++) - if (lbase != last) { - while((lbase & 1) == (last & 1)) { - i++; - lbase >>= 1; - last >>= 1; - } - } - d_size = 1 << i; + + 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 @@ -417,6 +407,7 @@ 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); @@ -439,20 +430,26 @@ mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags) mapflags |= MAP_NONCACHED; #endif -#if defined(__ia64__) +#if 0 /* this will disappear when people upgrade their kernels */ - if ((fd = open(DEV_MEM, O_RDWR|O_SYNC)) < 0) + fd = open(DEV_MEM, + ((flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR) | O_SYNC); #else - if ((fd = open(DEV_MEM, O_RDWR)) < 0) + 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_READ|PROT_WRITE, - mapflags, fd, + base = mmap((caddr_t)0, Size + alignOff, prot, mapflags, fd, (off_t)(off_t)realBase + BUS_BASE); close(fd); if (base == MAP_FAILED) { @@ -510,7 +507,7 @@ xf86EnableIO(void) fd = open("/dev/mem", O_RDWR); if (ioBase == NULL) { ioBase = (volatile unsigned char *)mmap(0, 0x20000, - PROT_READ|PROT_WRITE, MAP_SHARED, fd, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, ioBase_phys); /* Should this be fatal or just a warning? */ #if 0 @@ -666,7 +663,7 @@ static unsigned long msb_set = 0; static pointer mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { - int fd; + int fd, prot; unsigned long ret, rets = 0; static Bool was_here = FALSE; @@ -685,7 +682,8 @@ mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags xf86ReadMmio32 = readSparse32; } - if ((fd = open(DEV_MEM, O_RDWR)) < 0) { + 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)); } @@ -695,14 +693,18 @@ mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags 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_READ | PROT_WRITE, - MAP_SHARED, fd, + prot, MAP_SHARED, fd, (off_t) (bus_base + Base)); /* @@ -716,14 +718,13 @@ mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) { rets = (unsigned long)mmap((caddr_t)(SPARSE_BASE + (Base << 5)), - Size << 5, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, + Size << 5, prot, MAP_SHARED, fd, (off_t) _bus_base_sparse() + (Base << 5)); } close(fd); - if (ret == (unsigned long)MAP_FAILED || ret != (DENSE_BASE + Base)) { + if (ret == (unsigned long)MAP_FAILED) { FatalError("xf86MapVidMemSparse: Could not (dense) mmap fb (%s)\n", strerror(errno)); } @@ -750,7 +751,7 @@ mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size, int flags Base, Size, ret); #endif - return (pointer)(DENSE_BASE + Base); + return (pointer) ret; } static void @@ -978,7 +979,7 @@ static pointer mapVidMemJensen(int ScreenNum, unsigned long Base, unsigned long Size, int flags) { pointer base; - int fd; + int fd, prot; xf86WriteMmio8 = writeSparseJensen8; xf86WriteMmio16 = writeSparseJensen16; @@ -990,14 +991,20 @@ mapVidMemJensen(int ScreenNum, unsigned long Base, unsigned long Size, int flags xf86ReadMmio16 = readSparseJensen16; xf86ReadMmio32 = readSparseJensen32; - if ((fd = open(DEV_MEM, O_RDWR)) < 0) { + 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 (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, JENSEN_SHIFT(Size), - PROT_READ|PROT_WRITE, - MAP_SHARED, fd, + prot, MAP_SHARED, fd, (off_t)(JENSEN_SHIFT((off_t)Base) + _bus_base_sparse())); close(fd); if (base == MAP_FAILED) { |