diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 1998-02-17 23:49:32 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 1998-02-17 23:49:32 +0000 |
commit | 185c1e53c88c0f99d32dd8744c7c2283e38c7aaa (patch) | |
tree | 86fe54b6e9b846be2e8fea242aa97c1cd342e21a /sys | |
parent | 7e873f48bff5884f2fecc61729b41743bb2aa8a7 (diff) |
add an in-kernel /dev/xf86 aperture driver. the 'machdep.allowaperture'
sysctl controls whether it is permitted to access it. This sysctl can only
be manipulated when securelevel=0, hence in sysctl.conf
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/i386/conf/GENERIC | 3 | ||||
-rw-r--r-- | sys/arch/i386/i386/machdep.c | 19 | ||||
-rw-r--r-- | sys/arch/i386/i386/mem.c | 40 | ||||
-rw-r--r-- | sys/arch/i386/include/cpu.h | 6 |
4 files changed, 61 insertions, 7 deletions
diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC index 3cb01c4d356..50b4226818c 100644 --- a/sys/arch/i386/conf/GENERIC +++ b/sys/arch/i386/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.60 1998/01/06 02:35:18 deraadt Exp $ +# $OpenBSD: GENERIC,v 1.61 1998/02/17 23:49:28 matthieu Exp $ # $NetBSD: GENERIC,v 1.48 1996/05/20 18:17:23 mrg Exp $ # # GENERIC -- everything that's currently supported @@ -17,6 +17,7 @@ option GPL_MATH_EMULATE # floating point emulation #option VM86 # Virtual 8086 emulation #option USER_LDT # user-settable LDT; used by WINE option XSERVER +option APERTURE # in-kernel aperture driver for XFree86 # Some BIOSes don't get the size of extended memory right. If you # have a broken BIOS, uncomment the following and set the value diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 90c45de024f..dbae8873a20 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.77 1998/01/22 02:30:46 niklas Exp $ */ +/* $OpenBSD: machdep.c,v 1.78 1998/02/17 23:49:29 matthieu Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -230,6 +230,14 @@ int bus_mem_add_mapping __P((bus_addr_t, bus_size_t, extern u_int cnvmem; /* BIOS's conventional memory size */ extern u_int extmem; /* BIOS's extended memory size */ +#ifdef APERTURE +#ifdef INSECURE +int allowaperture = 1; +#else +int allowaperture = 0; +#endif +#endif + void cyrix6x86_cpu_setup __P((const char *)); void intel586_cpu_setup __P((const char *)); @@ -1871,6 +1879,15 @@ cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) return (ENOTDIR); /* overloaded */ dev = chrtoblk((dev_t)name[1]); return sysctl_rdstruct(oldp, oldlenp, newp, &dev, sizeof(dev)); +#ifdef APERTURE + case CPU_ALLOWAPERTURE: + if (securelevel > 0) + return (sysctl_rdint(oldp, oldlenp, newp, + allowaperture)); + else + return (sysctl_int(oldp, oldlenp, newp, newlen, + &allowaperture)); +#endif default: return EOPNOTSUPP; } diff --git a/sys/arch/i386/i386/mem.c b/sys/arch/i386/i386/mem.c index 175b016f334..4b1ec10f896 100644 --- a/sys/arch/i386/i386/mem.c +++ b/sys/arch/i386/i386/mem.c @@ -60,6 +60,13 @@ extern char *vmmap; /* poor name! */ caddr_t zeropage; +/* open counter for aperture */ +static int ap_open_count = 0; +extern int allowaperture; + +#define VGA_START 0xA0000 +#define VGA_END 0xBFFFF + /*ARGSUSED*/ int mmopen(dev, flag, mode, p) @@ -79,7 +86,21 @@ mmopen(dev, flag, mode, p) } break; #endif - +#ifdef APERTURE + case 4: + if (suser(p->p_ucred, &p->p_acflag) != 0) { + return(EPERM); + } + if (!allowaperture) { + return(EPERM); + } + /* authorize only one simultaneous open() */ + if (ap_open_count > 0) { + return(EPERM); + } + ap_open_count++; + break; +#endif default: break; } @@ -93,7 +114,11 @@ mmclose(dev, flag, mode, p) int flag, mode; struct proc *p; { - +#ifdef APERTURE + if (minor(dev) == 4) { + ap_open_count--; + } +#endif return (0); } @@ -215,7 +240,16 @@ mmmmap(dev, off, prot) if (!kernacc((caddr_t)off, NBPG, B_READ)) return -1; return i386_btop(vtophys(off)); - +#ifdef APERTURE +/* minor device 4 is aperture driver */ + case 4: + if (allowaperture + && (((off >= VGA_START && off <= VGA_END ) + || (unsigned)off > (unsigned)ctob(physmem)))) + return i386_btop(off); + else + return -1; +#endif default: return -1; } diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h index 33527023919..fed648fadf4 100644 --- a/sys/arch/i386/include/cpu.h +++ b/sys/arch/i386/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.19 1997/12/17 08:54:51 downsj Exp $ */ +/* $OpenBSD: cpu.h,v 1.20 1998/02/17 23:49:31 matthieu Exp $ */ /* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */ /*- @@ -234,7 +234,8 @@ void setconf __P((void)); #define CPU_BIOS 2 /* BIOS variables */ #define CPU_BLK2CHR 3 /* convert blk maj into chr one */ #define CPU_CHR2BLK 4 /* convert chr maj into blk one */ -#define CPU_MAXID 5 /* number of valid machdep ids */ +#define CPU_ALLOWAPERTURE 5 /* allow mmap of /dev/xf86 */ +#define CPU_MAXID 6 /* number of valid machdep ids */ #define CTL_MACHDEP_NAMES { \ { 0, 0 }, \ @@ -242,6 +243,7 @@ void setconf __P((void)); { "bios", CTLTYPE_INT }, \ { "blk2chr", CTLTYPE_STRUCT }, \ { "chr2blk", CTLTYPE_STRUCT }, \ + { "allowaperture", CTLTYPE_INT }, \ } #endif /* !_I386_CPU_H_ */ |