diff options
author | 2002-02-23 16:59:36 +0000 | |
---|---|---|
committer | 2002-02-23 16:59:36 +0000 | |
commit | 8b9af3c1c545e002d6efa501adf10e0788a93fdc (patch) | |
tree | 9d33b243a3d2a9cfceb1794c20d72a6d17a017d5 | |
parent | remove things we do not need (diff) | |
download | wireguard-openbsd-8b9af3c1c545e002d6efa501adf10e0788a93fdc.tar.xz wireguard-openbsd-8b9af3c1c545e002d6efa501adf10e0788a93fdc.zip |
Add aperture driver support for macppc, and also place writing to /dev/pci
under the control of machdep.allowaperture.
This allows to run the X server on macppc with securelevel=1, given that
machdep.allowaperture is != 0.
OK deraadt@
-rw-r--r-- | sys/arch/macppc/conf/GENERIC | 3 | ||||
-rw-r--r-- | sys/arch/macppc/include/cpu.h | 13 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/machdep.c | 21 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/mem.c | 29 | ||||
-rw-r--r-- | sys/dev/pci/pci.c | 12 |
5 files changed, 71 insertions, 7 deletions
diff --git a/sys/arch/macppc/conf/GENERIC b/sys/arch/macppc/conf/GENERIC index 2244c3d5fcd..4cec9de45b0 100644 --- a/sys/arch/macppc/conf/GENERIC +++ b/sys/arch/macppc/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.11 2001/12/17 03:23:43 drahn Exp $ +# $OpenBSD: GENERIC,v 1.12 2002/02/23 16:59:36 matthieu Exp $ # # PPC GENERIC config file # @@ -17,6 +17,7 @@ option PCIVERBOSE option USBVERBOSE #option MACOBIOVERBOSE #option PPC_VECTOR_SUPPORTED +option APERTURE option USER_PCICONF # user-space PCI configuration diff --git a/sys/arch/macppc/include/cpu.h b/sys/arch/macppc/include/cpu.h index 0a1bd865f7d..f535ea93285 100644 --- a/sys/arch/macppc/include/cpu.h +++ b/sys/arch/macppc/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.3 2002/01/07 05:03:23 drahn Exp $ */ +/* $OpenBSD: cpu.h,v 1.4 2002/02/23 16:59:36 matthieu Exp $ */ /* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 ws Exp $ */ /* @@ -60,4 +60,15 @@ syncicache(void *from, int len) __asm__ __volatile__ ("isync"); } +/* + * CTL_MACHDEP definitions. + */ +#define CPU_ALLOWAPERTURE 1 /* allow mmap of /dev/xf86 */ +#define CPU_MAXID 2 /* number of valid machdep ids */ + + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "allowaperture", CTLTYPE_INT }, \ +} #endif /* _MACHINE_CPU_H_ */ diff --git a/sys/arch/macppc/macppc/machdep.c b/sys/arch/macppc/macppc/machdep.c index c0d39b92c43..fa2713fc10a 100644 --- a/sys/arch/macppc/macppc/machdep.c +++ b/sys/arch/macppc/macppc/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.25 2002/02/17 22:59:52 maja Exp $ */ +/* $OpenBSD: machdep.c,v 1.26 2002/02/23 16:59:36 matthieu Exp $ */ /* $NetBSD: machdep.c,v 1.4 1996/10/16 19:33:11 ws Exp $ */ /* @@ -150,6 +150,14 @@ struct firmware *fw = NULL; void * startsym, *endsym; #endif +#ifdef APERTURE +#ifdef INSECURE +int allowaperture = 1; +#else +int allowaperture = 0; +#endif +#endif + void ofw_dbg(char *str); caddr_t allocsys __P((caddr_t)); @@ -823,6 +831,17 @@ cpu_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) if (namelen != 1) return ENOTDIR; switch (name[0]) { + case CPU_ALLOWAPERTURE: +#ifdef APERTURE + if (securelevel > 0) + return (sysctl_rdint(oldp, oldlenp, newp, + allowaperture)); + else + return (sysctl_int(oldp, oldlenp, newp, newlen, + &allowaperture)); +#else + return (sysctl_rdint(oldp, oldlenp, newp, 0)); +#endif default: return EOPNOTSUPP; } diff --git a/sys/arch/macppc/macppc/mem.c b/sys/arch/macppc/macppc/mem.c index a35222c0271..a97c8faa94c 100644 --- a/sys/arch/macppc/macppc/mem.c +++ b/sys/arch/macppc/macppc/mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mem.c,v 1.3 2001/11/06 19:53:15 miod Exp $ */ +/* $OpenBSD: mem.c,v 1.4 2002/02/23 16:59:36 matthieu Exp $ */ /* $NetBSD: mem.c,v 1.1 1996/09/30 16:34:50 ws Exp $ */ /* @@ -59,6 +59,12 @@ #include <machine/conf.h> +/* open counter for aperture */ +#ifdef APERTURE +static int ap_open_count = 0; +extern int allowaperture; +#endif + /*ARGSUSED*/ int mmopen(dev, flag, mode, p) @@ -72,10 +78,24 @@ mmopen(dev, flag, mode, p) case 1: case 2: case 12: - return (0); + break; +#ifdef APERTURE + case 4: + /* printf("open aperture allow %d count %d\n", + allowaperture, ap_open_count); */ + if (suser(p->p_ucred, &p->p_acflag) != 0 || !allowaperture) + return (EPERM); + + /* authorize only one simultaneous open() */ + if (ap_open_count > 0) + return(EPERM); + ap_open_count++; + break; +#endif default: return (ENXIO); } + return (0); } /*ARGSUSED*/ @@ -85,7 +105,10 @@ mmclose(dev, flag, mode, p) int flag, mode; struct proc *p; { - +#ifdef APERTURE + if (minor(dev) == 4) + ap_open_count--; +#endif return 0; } diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index a97d72886b6..bbe7dac8142 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci.c,v 1.25 2002/02/18 23:23:46 matthieu Exp $ */ +/* $OpenBSD: pci.c,v 1.26 2002/02/23 16:59:36 matthieu Exp $ */ /* $NetBSD: pci.c,v 1.31 1997/06/06 23:48:04 thorpej Exp $ */ /* @@ -54,6 +54,10 @@ struct pci_softc { }; #endif +#ifdef APERTURE +extern int allowaperture; +#endif + struct cfattach pci_ca = { #ifndef USER_PCICONF sizeof(struct device), pcimatch, pciattach @@ -386,9 +390,15 @@ pciopen(dev_t dev, int oflags, int devtype, struct proc *p) { PCIDEBUG(("pciopen ndevs: %d\n" , pci_cd.cd_ndevs)); +#ifndef APERTURE if ((oflags & FWRITE) && securelevel > 0) { return EPERM; } +#else + if ((oflags & FWRITE) && securelevel > 0 && allowaperture == 0) { + return EPERM; + } +#endif return 0; } |