Index: arch/acorn26/acorn26/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/acorn26/acorn26/machdep.c,v retrieving revision 1.22 diff -u -p -r1.22 machdep.c --- arch/acorn26/acorn26/machdep.c 25 Oct 2007 09:43:24 -0000 1.22 +++ arch/acorn26/acorn26/machdep.c 2 Mar 2008 14:07:55 -0000 @@ -51,6 +51,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include +#include + int physmem; char machine[] = MACHINE; char machine_arch[] = MACHINE_ARCH; @@ -228,3 +230,29 @@ cpu_need_resched(struct cpu_info *ci, in if (curlwp != ci->ci_data.cpu_idlelwp) setsoftast(); } + +bool +mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr) +{ + *vaddr = (vaddr_t)MEMC_PHYS_BASE + paddr; + return true; +} + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (atop(pa) >= physmem) + return EFAULT; + return 0; +} + +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + if (ptr >= MEMC_PHYS_BASE && + (char *)ptr < (char *)MEMC_PHYS_BASE + ptoa(physmem)) + *handled = true; + else + *handled = false; + return 0; +} Index: arch/acorn26/acorn26/mem.c =================================================================== RCS file: arch/acorn26/acorn26/mem.c diff -N arch/acorn26/acorn26/mem.c --- arch/acorn26/acorn26/mem.c 5 Mar 2007 16:39:21 -0000 1.10 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,223 +0,0 @@ -/* $NetBSD: mem.c,v 1.10 2007/03/05 16:39:21 he Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Memory special file - */ - -#include "opt_compat_netbsd.h" - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.10 2007/03/05 16:39:21 he Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -void *zeropage; -int physlock; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - register vm_offset_t v; - register int c; - register struct iovec *iov; - int error = 0; - - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - /* - * On arm26, there's no need to map in the - * relevant page, as we've got physical memory - * mapped in at another address and can just - * use that. - */ - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - /* XXX Should use pmap_find(). */ - if (v < 0 || - (char *)v + c > - (char*)MEMC_PHYS_BASE + ptoa(physmem)) - return EFAULT; - error = uiomove((char*)MEMC_PHYS_BASE + uio->uio_offset, - uio->uio_resid, uio); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - /* Allow reading from physically mapped space. */ - if (((void *)v >= MEMC_PHYS_BASE && - (char *)v + c < - (char*)MEMC_PHYS_BASE + ptoa(physmem)) || - uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? - B_READ : B_WRITE)) - error = uiomove((void *)v, c, uio); - else - return (EFAULT); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - -#ifdef COMPAT_16 - case _DEV_ZERO_oARM: -#endif - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - bzero(zeropage, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - if (minor(dev) == DEV_MEM) { -/*unlock:*/ - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev, off, prot) - dev_t dev; - off_t off; - int prot; -{ - int ppn; - - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - - /* minor device 0 is physical memory */ - - /* XXX This may botch our cacheing assumptions. Do we care? */ - ppn = atop(off); - if (ppn >= 0 && ppn < physmem) - return ppn; - return -1; -} Index: arch/acorn26/conf/files.acorn26 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/acorn26/conf/files.acorn26,v retrieving revision 1.12 diff -u -p -r1.12 files.acorn26 --- arch/acorn26/conf/files.acorn26 20 Feb 2008 21:43:33 -0000 1.12 +++ arch/acorn26/conf/files.acorn26 2 Mar 2008 14:07:55 -0000 @@ -194,7 +194,6 @@ file arch/acorn26/acorn26/cpuswitch.c file arch/acorn26/acorn26/except.c file arch/acorn26/acorn26/irq.c file arch/acorn26/acorn26/machdep.c -file arch/acorn26/acorn26/mem.c file arch/acorn26/acorn26/pmap.c #file arch/acorn26/acorn26/rscons.c file arch/acorn26/acorn26/stubs.c Index: arch/acorn26/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/acorn26/include/types.h,v retrieving revision 1.11 diff -u -p -r1.11 types.h --- arch/acorn26/include/types.h 20 Jan 2008 18:09:04 -0000 1.11 +++ arch/acorn26/include/types.h 2 Mar 2008 14:07:55 -0000 @@ -6,5 +6,7 @@ #include #define __GENERIC_SOFT_INTERRUPTS_ALL_LEVELS +#define __HAVE_MM_MD_DIRECT_MAPPED_PHYS +#define __HAVE_MM_MD_KERNACC #endif /* _ACORN26_TYPES_H_ */ Index: arch/alpha/alpha/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/alpha/alpha/machdep.c,v retrieving revision 1.302 diff -u -p -r1.302 machdep.c --- arch/alpha/alpha/machdep.c 28 Nov 2007 17:40:03 -0000 1.302 +++ arch/alpha/alpha/machdep.c 7 Mar 2008 17:12:13 -0000 @@ -138,6 +138,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include +#include + #include "ksyms.h" struct vm_map *exec_map = NULL; @@ -1846,31 +1848,47 @@ cpu_exec_ecoff_probe(l, epp) #endif /* EXEC_ECOFF */ int -alpha_pa_access(pa) - u_long pa; +mm_md_physacc(paddr_t pa, vm_prot_t prot) { + u_quad_t size; int i; for (i = 0; i < mem_cluster_cnt; i++) { if (pa < mem_clusters[i].start) continue; - if ((pa - mem_clusters[i].start) >= - (mem_clusters[i].size & ~PAGE_MASK)) + size = mem_clusters[i].size & ~PAGE_MASK; + if (pa >= mem_clusters[i].start + size) continue; - return (mem_clusters[i].size & PAGE_MASK); /* prot */ + if ((prot & mem_clusters[i].size & PAGE_MASK) != prot) + return EFAULT; + else + return 0; } - /* - * Address is not a memory address. If we're secure, disallow - * access. Otherwise, grant read/write. - */ - if (kauth_authorize_machdep(kauth_cred_get(), - KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL) != 0) - return (PROT_NONE); - else - return (PROT_READ | PROT_WRITE); + return kauth_authorize_machdep(kauth_cred_get(), + KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL); +} + +bool +mm_md_direct_mapped_io(void *addr, paddr_t *paddr) +{ + vaddr_t va = (vaddr_t)addr; + + if (va >= ALPHA_K0SEG_BASE && va < ALPHA_K0SEG_END) { + *paddr = ALPHA_K0SEG_TO_PHYS(va); + return true; + } + return false; } +bool +mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr) +{ + *vaddr = ALPHA_PHYS_TO_K0SEG(paddr); + return true; +} + + /* XXX XXX BEGIN XXX XXX */ paddr_t alpha_XXX_dmamap_or; /* XXX */ /* XXX */ Index: arch/alpha/alpha/mem.c =================================================================== RCS file: arch/alpha/alpha/mem.c diff -N arch/alpha/alpha/mem.c --- arch/alpha/alpha/mem.c 17 Oct 2007 19:52:56 -0000 1.39 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,226 +0,0 @@ -/* $NetBSD: mem.c,v 1.39 2007/10/17 19:52:56 garbled Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include /* RCS ID & Copyright macro defns */ - -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.39 2007/10/17 19:52:56 garbled Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -void *zeropage; -extern int firstusablepage, lastusablepage; -extern void *msgbufaddr; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - register vaddr_t o, v; - register int c; - register struct iovec *iov; - int error = 0, rw; - - while (uio->uio_resid > 0 && !error) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; -kmemphys: - if (v >= ALPHA_K0SEG_TO_PHYS((vaddr_t)msgbufaddr)) { - if (msgbufmapped == 0) { - printf("Message Buf not Mapped\n"); - error = EFAULT; - break; - } - } - - /* Allow reads only in RAM. */ - rw = (uio->uio_rw == UIO_READ) ? PROT_READ : PROT_WRITE; - if ((alpha_pa_access(v) & rw) != rw) { - error = EFAULT; - break; - } - - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = - uiomove((void *)ALPHA_PHYS_TO_K0SEG(v), c, uio); - break; - - case DEV_KMEM: - v = uio->uio_offset; - - if (v >= ALPHA_K0SEG_BASE && v <= ALPHA_K0SEG_END) { - v = ALPHA_K0SEG_TO_PHYS(v); - goto kmemphys; - } - - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - return (error); -} - -paddr_t -mmmmap(dev, off, prot) - dev_t dev; - off_t off; - int prot; -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - - /* - * Allow access only in RAM. - */ - if ((prot & alpha_pa_access(off)) != prot) - return (-1); - return (alpha_btop(off)); -} Index: arch/alpha/conf/files.alpha =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/alpha/conf/files.alpha,v retrieving revision 1.179 diff -u -p -r1.179 files.alpha --- arch/alpha/conf/files.alpha 20 Feb 2008 21:43:33 -0000 1.179 +++ arch/alpha/conf/files.alpha 2 Mar 2008 14:07:55 -0000 @@ -404,7 +404,6 @@ file arch/alpha/alpha/ipifuncs.c multip file arch/alpha/alpha/kobj_machdep.c modular file arch/alpha/alpha/machdep.c file arch/alpha/alpha/mainbus.c -file arch/alpha/alpha/mem.c file arch/alpha/alpha/patch.c file arch/alpha/alpha/pmap.c file arch/alpha/alpha/process_machdep.c Index: arch/alpha/include/alpha.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/alpha/include/alpha.h,v retrieving revision 1.23 diff -u -p -r1.23 alpha.h --- arch/alpha/include/alpha.h 28 Nov 2007 17:40:03 -0000 1.23 +++ arch/alpha/include/alpha.h 2 Mar 2008 14:07:55 -0000 @@ -118,7 +118,6 @@ void XentRestart(void); /* MAGIC */ void XentSys(u_int64_t, u_int64_t, u_int64_t); /* MAGIC */ void XentUna(u_int64_t, u_int64_t, u_int64_t); /* MAGIC */ void alpha_init(u_long, u_long, u_long, u_long, u_long); -int alpha_pa_access(u_long); void ast(struct trapframe *); int badaddr(void *, size_t); int badaddr_read(void *, size_t, void *); Index: arch/alpha/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/alpha/include/types.h,v retrieving revision 1.40 diff -u -p -r1.40 types.h --- arch/alpha/include/types.h 20 Jan 2008 18:09:04 -0000 1.40 +++ arch/alpha/include/types.h 2 Mar 2008 14:07:55 -0000 @@ -66,6 +66,8 @@ typedef volatile int __cpu_simple_lock_ #define __HAVE_MINIMAL_EMUL #define __HAVE_AST_PERPROC #define __HAVE_ATOMIC64_OPS +#define __HAVE_MM_MD_DIRECT_MAPPED_IO +#define __HAVE_MM_MD_DIRECT_MAPPED_PHYS #if defined(_KERNEL) #define __HAVE_RAS Index: arch/amd64/amd64/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/amd64/amd64/machdep.c,v retrieving revision 1.85 diff -u -p -r1.85 machdep.c --- arch/amd64/amd64/machdep.c 12 Feb 2008 17:52:19 -0000 1.85 +++ arch/amd64/amd64/machdep.c 2 Mar 2008 14:07:55 -0000 @@ -217,6 +217,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #endif +#include + #include "isa.h" #include "isadma.h" #include "ksyms.h" @@ -2053,3 +2055,21 @@ valid_user_selector(struct lwp *l, uint6 { return memseg_baseaddr(l, seg, ldtp, len, NULL); } + +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + extern int start, __data_start; + + if (ptr >= (void *)&start && ptr < (void *)kern_end) { + *handled = true; + if (ptr < (void *)&__data_start && (prot & VM_PROT_WRITE)) + return EFAULT; + } else if (ptr >= (void *)lkm_start && ptr < (void *)lkm_end) { + *handled = true; + if (!uvm_map_checkprot(lkm_map, (vaddr_t)ptr, + (vaddr_t)ptr + 1, prot)) + return EFAULT; + } + return 0; +} Index: arch/amd64/amd64/mem.c =================================================================== RCS file: arch/amd64/amd64/mem.c diff -N arch/amd64/amd64/mem.c --- arch/amd64/amd64/mem.c 13 Feb 2008 12:48:11 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,235 +0,0 @@ -/* $NetBSD: mem.c,v 1.13 2008/02/13 12:48:11 joerg Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.13 2008/02/13 12:48:11 joerg Exp $"); - -#include "opt_compat_netbsd.h" - -/* - * Memory special file - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern char *vmmap; /* poor name! */ -void *zeropage; -extern int start, end, __data_start; -extern vaddr_t kern_end; -extern vaddr_t lkm_start, lkm_end; -extern struct vm_map *lkm_map; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter -}; - -int check_pa_acc(paddr_t, vm_prot_t); - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - register vaddr_t o, v; - register int c; - register struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && !error) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - error = check_pa_acc(uio->uio_offset, prot); - if (error) - break; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, PMAP_WIRED|prot); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - break; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (v >= (vaddr_t)&start && v < - (vaddr_t)kern_end) { - if (v < (vaddr_t)&__data_start && - uio->uio_rw == UIO_WRITE) - return EFAULT; - } else if (v >= lkm_start && v < lkm_end) { - if (!uvm_map_checkprot(lkm_map, v, v + c, - uio->uio_rw == UIO_READ ? - VM_PROT_READ: VM_PROT_WRITE)) - return EFAULT; - } else { - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return EFAULT; - } - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - if (minor(dev) == 0) { - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - - if (check_pa_acc(off, prot) != 0) - return (-1); - - return (x86_btop(off)); -} Index: arch/amd64/conf/files.amd64 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/amd64/conf/files.amd64,v retrieving revision 1.58 diff -u -p -r1.58 files.amd64 --- arch/amd64/conf/files.amd64 20 Feb 2008 21:43:33 -0000 1.58 +++ arch/amd64/conf/files.amd64 2 Mar 2008 14:07:55 -0000 @@ -44,7 +44,6 @@ file kern/subr_disk_mbr.c disk file arch/amd64/amd64/gdt.c file arch/amd64/amd64/machdep.c file arch/amd64/amd64/identcpu.c -file arch/amd64/amd64/mem.c file arch/amd64/amd64/process_machdep.c file arch/amd64/amd64/procfs_machdep.c procfs file arch/amd64/amd64/syscall.c Index: arch/amd64/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/amd64/include/types.h,v retrieving revision 1.26 diff -u -p -r1.26 types.h --- arch/amd64/include/types.h 21 Feb 2008 16:31:13 -0000 1.26 +++ arch/amd64/include/types.h 2 Mar 2008 14:07:55 -0000 @@ -72,6 +72,7 @@ typedef volatile unsigned char __cpu_si #define __HAVE_SYSCALL_INTERN #define __HAVE_MINIMAL_EMUL #define __HAVE_ATOMIC64_OPS +#define __HAVE_MM_MD_KERNACC #define __HAVE_ATOMIC_AS_MEMBAR #ifdef _KERNEL_OPT Index: arch/amiga/amiga/amiga_init.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/amiga/amiga/amiga_init.c,v retrieving revision 1.99 diff -u -p -r1.99 amiga_init.c --- arch/amiga/amiga/amiga_init.c 6 Jan 2008 18:50:29 -0000 1.99 +++ arch/amiga/amiga/amiga_init.c 2 Mar 2008 14:07:55 -0000 @@ -65,6 +65,8 @@ __KERNEL_RCSID(0, "$NetBSD: amiga_init.c #include #include +#include + #define RELOC(v, t) *((t*)((u_int)&(v) + loadbase)) extern u_int lowram; @@ -1111,3 +1113,18 @@ kernel_reload_write(uio) return(0); } #endif + +int +mm_md_readwrite(dev_t dev, struct uio *uio) +{ + switch (minor(dev)) { +#ifdef DEVRELOAD + case DEV_RELOAD: + if (uio->uio_rw == UIO_READ) + return 0; + return kernel_reload_write(uio); +#endif + default: + return ENXIO; + } +} Index: arch/amiga/amiga/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/amiga/amiga/machdep.c,v retrieving revision 1.208 diff -u -p -r1.208 machdep.c --- arch/amiga/amiga/machdep.c 6 Jan 2008 18:50:30 -0000 1.208 +++ arch/amiga/amiga/machdep.c 2 Mar 2008 14:07:55 -0000 @@ -143,6 +143,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include +#include + #include "fd.h" #include "ser.h" #include "ksyms.h" @@ -1521,3 +1523,12 @@ int ipl2spl_table[_NIPL] = { [IPL_HIGH] = PSL_IPL7|PSL_S, #endif /* defined(LEV6_DEFER) */ }; + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa >= 0xFFFFFFFC || pa < lowram) + return EFAULT; + + return 0; +} Index: arch/amiga/amiga/mem.c =================================================================== RCS file: arch/amiga/amiga/mem.c diff -N arch/amiga/amiga/mem.c --- arch/amiga/amiga/mem.c 5 Mar 2007 20:30:09 -0000 1.42 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,251 +0,0 @@ -/* $NetBSD: mem.c,v 1.42 2007/03/05 20:30:09 he Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.42 2007/03/05 20:30:09 he Exp $"); - -/* - * Memory special file - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include "opt_devreload.h" -#ifdef DEVRELOAD -#define DEV_RELOAD 20 /* minor device 20 is magic memory - * which you can write a kernel image to, - * causing a reboot into that kernel - */ - -extern int kernel_reload_write(struct uio *uio); -#endif - -extern u_int lowram; -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - register vm_offset_t o, v; - register int c; - register struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - /* minor device 0 is physical memory */ - case DEV_MEM: - v = uio->uio_offset; -#ifndef DEBUG - /* allow reads only in RAM (except for DEBUG) */ - if (v >= 0xFFFFFFFC || v < lowram) { - error = EFAULT; - goto unlock; - } -#endif - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vm_offset_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vm_offset_t)vmmap, - (vm_offset_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - if (v < PAGE_SIZE) { -#ifdef DEBUG - /* - * For now, return zeros on read of page 0 - * and EFAULT for writes. - */ - if (uio->uio_rw == UIO_READ) { - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, - M_WAITOK); - bzero(devzeropage, PAGE_SIZE); - } - c = min(c, PAGE_SIZE - (int)v); - v = (vm_offset_t) devzeropage; - } else -#endif - return (EFAULT); - } - error = uiomove((void *)v, c, uio); - continue; - - /* minor device 2 is EOF/RATHOLE */ - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - /* - * minor device 12 (/dev/zero) is source of nulls on read, - * rathole on write - */ - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - bzero(devzeropage, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; -#ifdef DEVRELOAD - case DEV_RELOAD: - if (uio->uio_rw == UIO_READ) - return 0; - error = kernel_reload_write(uio); - continue; -#endif - default: - return (ENXIO); - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == DEV_MEM) { -#ifndef DEBUG -unlock: -#endif - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} Index: arch/amiga/conf/files.amiga =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/amiga/conf/files.amiga,v retrieving revision 1.140 diff -u -p -r1.140 files.amiga --- arch/amiga/conf/files.amiga 20 Feb 2008 21:43:33 -0000 1.140 +++ arch/amiga/conf/files.amiga 2 Mar 2008 14:07:55 -0000 @@ -434,7 +434,6 @@ file arch/amiga/amiga/conf.c file arch/amiga/amiga/disksubr.c file arch/amiga/amiga/dkbad.c file arch/amiga/amiga/machdep.c -file arch/amiga/amiga/mem.c file arch/amiga/amiga/pmap.c file arch/amiga/amiga/pmap_bootstrap.c file arch/amiga/amiga/trap.c Index: arch/amiga/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/amiga/include/types.h,v retrieving revision 1.22 diff -u -p -r1.22 types.h --- arch/amiga/include/types.h 20 Jan 2008 18:09:04 -0000 1.22 +++ arch/amiga/include/types.h 2 Mar 2008 14:07:55 -0000 @@ -6,5 +6,6 @@ #include #define __GENERIC_SOFT_INTERRUPTS_ALL_LEVELS +#define __HAVE_MM_MD_READWRITE #endif Index: arch/arm/arm32/arm32_machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/arm/arm32/arm32_machdep.c,v retrieving revision 1.55 diff -u -p -r1.55 arm32_machdep.c --- arch/arm/arm32/arm32_machdep.c 19 Jan 2008 15:04:09 -0000 1.55 +++ arch/arm/arm32/arm32_machdep.c 2 Mar 2008 14:07:55 -0000 @@ -52,6 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: arm32_machde #include #include #include +#include #include #include #include @@ -63,6 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: arm32_machde #include #include +#include #include #include @@ -437,3 +439,13 @@ cpu_intr_p(void) return curcpu()->ci_idepth != 0; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa < ctob(physmem)) + return 0; + + return kauth_authorize_machdep(kauth_cred_get(), + KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL); +} Index: arch/arm/arm32/mem.c =================================================================== RCS file: arch/arm/arm32/mem.c diff -N arch/arm/arm32/mem.c --- arch/arm/arm32/mem.c 1 Jan 2008 14:06:42 -0000 1.20 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,226 +0,0 @@ -/* $NetBSD: mem.c,v 1.20 2008/01/01 14:06:42 chris Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Memory special file - */ - -#include "opt_compat_netbsd.h" - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.20 2008/01/01 14:06:42 chris Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern vaddr_t memhook; /* poor name! */ -void *zeropage; -int physlock; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - register vaddr_t o, v; - register int c; - register struct iovec *iov; - int error = 0; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), memhook, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)memhook + o, c, uio); - pmap_remove(pmap_kernel(), memhook, - memhook + PAGE_SIZE); - pmap_update(pmap_kernel()); - break; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - -#ifdef COMPAT_16 - case _DEV_ZERO_oARM: -#endif - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - if (minor(dev) == DEV_MEM) { -/*unlock:*/ - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev, off, prot) - dev_t dev; - off_t off; - int prot; -{ - struct lwp *l = curlwp; /* XXX */ - - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - - /* minor device 0 is physical memory */ - - if (off >= ctob(physmem) && kauth_authorize_machdep(l->l_cred, - KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL) != 0) - return -1; - return arm_btop(off); -} Index: arch/arm/conf/files.arm =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/arm/conf/files.arm,v retrieving revision 1.89 diff -u -p -r1.89 files.arm --- arch/arm/conf/files.arm 26 Jan 2008 02:06:04 -0000 1.89 +++ arch/arm/conf/files.arm 2 Mar 2008 14:07:56 -0000 @@ -137,7 +137,6 @@ file arch/arm/arm32/exception.S arm32 file arch/arm/arm32/fault.c arm32 file arch/arm/arm32/fusu.S arm32 file arch/arm/arm32/kobj_machdep.c arm32 & modular -file arch/arm/arm32/mem.c arm32 file arch/arm/arm32/pmap.c arm32 file arch/arm/arm32/setcpsr.S arm32 file arch/arm/arm32/setstack.S arm32 Index: arch/atari/atari/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/atari/atari/machdep.c,v retrieving revision 1.149 diff -u -p -r1.149 machdep.c --- arch/atari/atari/machdep.c 8 Jan 2008 18:04:15 -0000 1.149 +++ arch/atari/atari/machdep.c 2 Mar 2008 14:07:56 -0000 @@ -126,8 +126,12 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include +#include #include "ksyms.h" +#include "nvr.h" + +#define DEV_NVRAM 11 /* Nvram minor-number */ static void bootsync(void); static void call_sicallbacks(void); @@ -887,3 +891,30 @@ nmihandler(void) printf("nmihandler: plx_status = 0x%08lx\n", plx_status); } #endif + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + struct memseg *ms; + + for (ms = boot_segs; ms->start != ms->end; ms++) { + if ((pa >= ms->start) && (pa < ms->end)) + return 0; + } + return EFAULT; +} + +int +mm_md_readwrite(dev_t dev, struct uio *uio) +{ + switch (minor(dev)) { + case DEV_NVRAM: +#if NNVR > 0 + return nvram_uio(uio); +#else + return ENXIO; +#endif + default: + return ENXIO; + } +} Index: arch/atari/atari/mem.c =================================================================== RCS file: arch/atari/atari/mem.c diff -N arch/atari/atari/mem.c --- arch/atari/atari/mem.c 6 Mar 2007 13:53:32 -0000 1.33 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,222 +0,0 @@ -/* $NetBSD: mem.c,v 1.33 2007/03/06 13:53:32 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.33 2007/03/06 13:53:32 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include "nvr.h" - -#define DEV_NVRAM 11 /* Nvram minor-number */ - -extern u_int lowram; -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - vsize_t o, v; - int c; - struct iovec *iov; - struct memseg *ms; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - - /* - * Limit access to RAM actually present - */ - for (ms = boot_segs; ms->start != ms->end; ms++) - if ((v >= ms->start) && (v < ms->end)) - break; - if (ms->start == ms->end) { - error = EFAULT; - goto unlock; - } - - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - break; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_NVRAM: -#if NNVR > 0 - error = nvram_uio(uio); - return (error); -#else - return (ENXIO); -#endif - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - bzero(devzeropage, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - if (minor(dev) == 0) { -unlock: - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} Index: arch/atari/conf/files.atari =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/atari/conf/files.atari,v retrieving revision 1.112 diff -u -p -r1.112 files.atari --- arch/atari/conf/files.atari 20 Feb 2008 21:43:33 -0000 1.112 +++ arch/atari/conf/files.atari 2 Mar 2008 14:07:56 -0000 @@ -201,7 +201,6 @@ file arch/atari/atari/dkbad.c file arch/atari/atari/le_bus.c pci | isa file arch/atari/atari/machdep.c file arch/atari/atari/mainbus.c -file arch/atari/atari/mem.c file arch/atari/atari/pmap.c file arch/atari/atari/trap.c file arch/atari/atari/stalloc.c Index: arch/atari/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/atari/include/types.h,v retrieving revision 1.13 diff -u -p -r1.13 types.h --- arch/atari/include/types.h 20 Jan 2008 18:09:05 -0000 1.13 +++ arch/atari/include/types.h 2 Mar 2008 14:07:56 -0000 @@ -5,4 +5,6 @@ #include +#define __HAVE_MM_MD_READWRITE + #endif Index: arch/cesfic/cesfic/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/cesfic/cesfic/machdep.c,v retrieving revision 1.40 diff -u -p -r1.40 machdep.c --- arch/cesfic/cesfic/machdep.c 31 Dec 2007 13:38:47 -0000 1.40 +++ arch/cesfic/cesfic/machdep.c 2 Mar 2008 14:07:56 -0000 @@ -135,6 +135,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include #include +#include #include #include #include @@ -735,3 +736,11 @@ cpu_exec_aout_makecmds(l, epp) return ENOEXEC; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa < lowram || pa >= 0xFFFFFFFC) + return EFAULT; + return 0; +} Index: arch/cesfic/cesfic/mem.c =================================================================== RCS file: arch/cesfic/cesfic/mem.c diff -N arch/cesfic/cesfic/mem.c --- arch/cesfic/cesfic/mem.c 5 Mar 2007 12:30:37 -0000 1.11 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,252 +0,0 @@ -/* $NetBSD: mem.c,v 1.11 2007/03/05 12:30:37 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.11 2007/03/05 12:30:37 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern u_int lowram; -extern char *extiobase; -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - vm_offset_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - - /* - * Only allow reads in physical RAM. - */ - if (v >= 0xFFFFFFFC || v < lowram) { - error = EFAULT; - goto unlock; - } - - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vm_offset_t)vmmap, - (vm_offset_t)vmmap + PAGE_SIZE); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - - /* - * Don't allow reading intio or dio - * device space. This could lead to - * corruption of device registers. - */ -#if 0 - if (ISIIOVA(v) || - ((void *)v >= extiobase && - (void *)v < (extiobase + - (EIOMAPSIZE * PAGE_SIZE)))) - return (EFAULT); -#endif - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - bzero(devzeropage, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; - - default: - return (ENXIO); - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == DEV_MEM) { -unlock: - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev, off, prot) - dev_t dev; - off_t off; - int prot; -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - - /* - * Allow access only in RAM. - */ - if ((u_int)off < lowram || (u_int)off >= 0xFFFFFFFC) - return (-1); - return (m68k_btop(off)); -} Index: arch/cesfic/conf/files.cesfic =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/cesfic/conf/files.cesfic,v retrieving revision 1.16 diff -u -p -r1.16 files.cesfic --- arch/cesfic/conf/files.cesfic 3 Dec 2007 15:33:25 -0000 1.16 +++ arch/cesfic/conf/files.cesfic 2 Mar 2008 14:07:56 -0000 @@ -53,7 +53,6 @@ file arch/cesfic/cesfic/autoconf.c file arch/cesfic/cesfic/clock.c file arch/cesfic/cesfic/machdep.c file arch/cesfic/cesfic/isr.c -file arch/cesfic/cesfic/mem.c file arch/cesfic/cesfic/pmap_bootstrap.c file arch/cesfic/cesfic/trap.c file arch/m68k/m68k/cacheops.c Index: arch/hp300/conf/files.hp300 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/hp300/conf/files.hp300,v retrieving revision 1.78 diff -u -p -r1.78 files.hp300 --- arch/hp300/conf/files.hp300 31 Dec 2007 13:38:48 -0000 1.78 +++ arch/hp300/conf/files.hp300 2 Mar 2008 14:07:56 -0000 @@ -186,7 +186,6 @@ file arch/hp300/hp300/dkbad.c file arch/hp300/hp300/machdep.c file arch/hp300/hp300/intr.c file arch/hp300/hp300/leds.c useleds -file arch/hp300/hp300/mem.c file arch/hp300/hp300/pmap_bootstrap.c compile-with "${NOPROF_C}" file arch/hp300/hp300/trap.c file arch/hp300/hp300/disksubr.c Index: arch/hp300/hp300/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/hp300/hp300/machdep.c,v retrieving revision 1.198 diff -u -p -r1.198 machdep.c --- arch/hp300/hp300/machdep.c 31 Dec 2007 13:38:49 -0000 1.198 +++ arch/hp300/hp300/machdep.c 2 Mar 2008 14:07:56 -0000 @@ -130,6 +130,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include /* XXX should be pulled in by sys/kcore.h */ #include +#include #define MAXMEM 64*1024 /* XXX - from cmap.h */ #include @@ -1290,3 +1291,27 @@ cpu_exec_aout_makecmds(struct lwp *l, st return ENOEXEC; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa < lowram || pa >= 0xFFFFFFFC) + return EFAULT; + return 0; +} + +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + /* + * Don't allow reading intio or dio + * device space. This could lead to + * corruption of device registers. + */ + if (ISIIOVA(ptr) || + ((uint8_t *)ptr >= extiobase && (uint8_t *)ptr < extiobase + (EIOMAPSIZE * PAGE_SIZE))) { + *handled = true; + return EFAULT; + } + return 0; +} Index: arch/hp300/hp300/mem.c =================================================================== RCS file: arch/hp300/hp300/mem.c diff -N arch/hp300/hp300/mem.c --- arch/hp300/hp300/mem.c 17 Oct 2007 19:54:24 -0000 1.48 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,245 +0,0 @@ -/* $NetBSD: mem.c,v 1.48 2007/10/17 19:54:24 garbled Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.48 2007/10/17 19:54:24 garbled Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern u_int lowram; -static void *devzeropage; - -static dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -static dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -static int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - vaddr_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return error; - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - - /* - * Only allow reads in physical RAM. - */ - if (v >= 0xFFFFFFFC || v < lowram) { - error = EFAULT; - goto unlock; - } - - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return EFAULT; - - /* - * Don't allow reading intio or dio - * device space. This could lead to - * corruption of device registers. - */ - if (ISIIOVA(v) || - (v >= (vaddr_t)extiobase && - v < ((vaddr_t)extiobase + - (EIOMAPSIZE * PAGE_SIZE)))) - return EFAULT; - - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return 0; - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (devzeropage == NULL) { - devzeropage = malloc(PAGE_SIZE, M_TEMP, - M_WAITOK | M_ZERO); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; - - default: - return ENXIO; - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == 0) { -unlock: - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return error; -} - -static paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return -1; - - /* - * Allow access only in RAM. - */ - if ((u_int)off < lowram || (u_int)off >= 0xFFFFFFFC) - return -1; - return m68k_btop((u_int)off); -} Index: arch/hp300/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/hp300/include/types.h,v retrieving revision 1.20 diff -u -p -r1.20 types.h --- arch/hp300/include/types.h 20 Jan 2008 18:09:06 -0000 1.20 +++ arch/hp300/include/types.h 2 Mar 2008 14:07:56 -0000 @@ -6,6 +6,7 @@ #include #define __HAVE_DEVICE_REGISTER +#define __HAVE_MM_MD_KERNACC #if defined(_KERNEL) #define __HAVE_RAS Index: arch/hp700/dev/mem.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/hp700/dev/mem.c,v retrieving revision 1.15 diff -u -p -r1.15 mem.c --- arch/hp700/dev/mem.c 6 Dec 2007 17:00:32 -0000 1.15 +++ arch/hp700/dev/mem.c 2 Mar 2008 14:07:56 -0000 @@ -157,22 +157,6 @@ void memattach(struct device *, struct d CFATTACH_DECL(mem, sizeof(struct mem_softc), memmatch, memattach, NULL, NULL); -extern struct cfdriver mem_cd; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, -}; - -static void *zeropage; - -/* A lock for the vmmap. */ -kmutex_t vmmap_lock; - int memmatch(struct device *parent, struct cfdata *cf, void *aux) { @@ -262,9 +246,11 @@ memattach(struct device *parent, struct void viper_setintrwnd(uint32_t mask) { + device_t dv; struct mem_softc *sc; - sc = mem_cd.cd_devs[0]; + dv = device_find_by_driver_unit("mem", 0); + sc = device_private(dv); if (sc->sc_vp) sc->sc_vp->vi_intrwd; @@ -273,134 +259,15 @@ viper_setintrwnd(uint32_t mask) void viper_eisa_en(void) { + device_t dv; struct mem_softc *sc; int pagezero_cookie; - sc = mem_cd.cd_devs[0]; + dv = device_find_by_driver_unit("mem", 0); + sc = device_private(dv); pagezero_cookie = hp700_pagezero_map(); if (sc->sc_vp) ((struct vi_ctrl *)&VI_CTRL)->eisa_den = 0; hp700_pagezero_unmap(pagezero_cookie); } - -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - struct iovec *iov; - vaddr_t v, o; - vm_prot_t prot; - u_int c; - int error = 0; - int rw; - - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: /* /dev/mem */ - - /* If the address isn't in RAM, bail. */ - v = uio->uio_offset; - if (btoc(v) > totalphysmem) { - error = EFAULT; - /* this will break us out of the loop */ - continue; - } - - /* - * If the address is inside our large - * directly-mapped kernel BTLB entries, - * use kmem instead. - */ - if (v < virtual_start) { - goto use_kmem; - } - - mutex_enter(&vmmap_lock); - - /* Temporarily map the memory at vmmap. */ - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - - mutex_exit(&vmmap_lock); - break; - - case DEV_KMEM: /* /dev/kmem */ - v = uio->uio_offset; -use_kmem: - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - rw = (uio->uio_rw == UIO_READ) ? B_READ : B_WRITE; - if (!uvm_kernacc((void *)v, c, rw)) { - error = EFAULT; - /* this will break us out of the loop */ - continue; - } - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: /* /dev/null */ - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: /* /dev/zero */ - /* Write to /dev/zero is ignored. */ - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - - if (minor(dev) != 0) - return (-1); - - /* - * Allow access only in RAM. - */ -#if 0 - if (off < ctob(firstusablepage) || - off >= ctob(lastusablepage + 1)) - return (-1); -#endif - return (btop(off)); -} Index: arch/hp700/hp700/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/hp700/hp700/machdep.c,v retrieving revision 1.46 diff -u -p -r1.46 machdep.c --- arch/hp700/hp700/machdep.c 7 Feb 2008 12:25:42 -0000 1.46 +++ arch/hp700/hp700/machdep.c 2 Mar 2008 14:07:56 -0000 @@ -109,6 +109,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include +#include #include #include @@ -421,8 +422,6 @@ const struct hppa_cpu_info hppa_cpu_pa86 #endif /* !HP8600_CPU */ }; -extern kmutex_t vmmap_lock; - void hppa_init(paddr_t start, void *bi) { @@ -901,8 +900,6 @@ cpu_startup(void) */ vmmap = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_VAONLY | UVM_KMF_WAITVA); - - mutex_init(&vmmap_lock, MUTEX_DEFAULT, IPL_NONE); } /* @@ -1820,3 +1817,11 @@ consinit(void) cninit(); } } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (btoc(pa) > totalphysmem) + return EFAULT; + return 0; +} Index: arch/i386/conf/files.i386 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/i386/conf/files.i386,v retrieving revision 1.334 diff -u -p -r1.334 files.i386 --- arch/i386/conf/files.i386 26 Feb 2008 18:24:28 -0000 1.334 +++ arch/i386/conf/files.i386 2 Mar 2008 14:07:56 -0000 @@ -83,7 +83,6 @@ file arch/i386/i386/kobj_machdep.c modul file arch/i386/i386/machdep.c file arch/i386/i386/identcpu.c file arch/i386/i386/longrun.c -file arch/i386/i386/mem.c file arch/i386/i386/mtrr_k6.c mtrr file arch/i386/i386/process_machdep.c file arch/i386/i386/procfs_machdep.c procfs Index: arch/i386/i386/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/i386/i386/machdep.c,v retrieving revision 1.627 diff -u -p -r1.627 machdep.c --- arch/i386/i386/machdep.c 26 Feb 2008 18:24:28 -0000 1.627 +++ arch/i386/i386/machdep.c 2 Mar 2008 14:07:56 -0000 @@ -77,6 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include "opt_beep.h" #include "opt_compat_ibcs2.h" #include "opt_compat_mach.h" /* need to get the right segment def */ +#include "opt_compat_freebsd.h" #include "opt_compat_netbsd.h" #include "opt_compat_svr4.h" #include "opt_cpureset_delay.h" @@ -227,6 +228,8 @@ uint32_t arch_i386_xbox_memsize = 0; #include /* XXX */ #endif /* XXX */ +#include + /* the following is used externally (sysctl_hw) */ char machine[] = "i386"; /* CPU "architecture" */ char machine_arch[] = "i386"; /* machine == machine_arch */ @@ -2281,3 +2284,27 @@ cpu_initclocks() (*initclock_func)(); } + +int +mm_md_open(dev_t dev, int flag, int mode, struct lwp *l) +{ + switch (minor(dev)) { + case DEV_IO: +#if defined(COMAT_10) || defined(COMPAT_FREEBSD) + if (flag & FWRITE) { + struct trapframe *fp; + int error; + + error = kauth_authorize_machdep(l->l_cred, + KAUTH_MACHDEP_IOPL, NULL, NULL, NULL, NULL); + if (error) + return error; + fp->curlwp->l_md.md_regs; + fp->tf_eflags |= PSL_IOPL; + } +#endif + return 0; + default: + return 0; + } +} Index: arch/i386/i386/mem.c =================================================================== RCS file: arch/i386/i386/mem.c diff -N arch/i386/i386/mem.c --- arch/i386/i386/mem.c 4 Mar 2007 05:59:57 -0000 1.69 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,259 +0,0 @@ -/* $NetBSD: mem.c,v 1.69 2007/03/04 05:59:57 christos Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.69 2007/03/04 05:59:57 christos Exp $"); - -#include "opt_compat_netbsd.h" -#include "opt_compat_freebsd.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#define DEV_IO 14 /* iopl for compat_10 */ - -extern char *vmmap; /* poor name! */ -void *zeropage; - -dev_type_open(mmopen); -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - mmopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, D_OTHER, -}; - -int check_pa_acc(paddr_t, vm_prot_t); - -/*ARGSUSED*/ -int -mmopen(dev_t dev, int flag, int mode, struct lwp *l) -{ - - switch (minor(dev)) { -#if defined(COMPAT_10) || defined(COMPAT_FREEBSD) - /* This is done by i386_iopl(3) now. */ - case DEV_IO: - if (flag & FWRITE) { - struct trapframe *fp; - int error; - - error = kauth_authorize_machdep(l->l_cred, - KAUTH_MACHDEP_IOPL, NULL, NULL, NULL, NULL); - if (error) - return (error); - - fp = curlwp->l_md.md_regs; - fp->tf_eflags |= PSL_IOPL; - } - break; -#else - (void) flag; -#endif - - default: - break; - } - return (0); -} - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - register vaddr_t o, v; - register int c; - register struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && !error) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - case DEV_MEM: - v = uio->uio_offset; - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - error = check_pa_acc(uio->uio_offset, prot); - if (error) { - break; - } - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, PMAP_WIRED|prot); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - break; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - if (minor(dev) == DEV_MEM) { - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return -1; - - if (check_pa_acc(off, prot) != 0) { - return -1; - } - - return x86_btop(off); -} Index: arch/i386/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/i386/include/types.h,v retrieving revision 1.59 diff -u -p -r1.59 types.h --- arch/i386/include/types.h 21 Feb 2008 16:31:13 -0000 1.59 +++ arch/i386/include/types.h 2 Mar 2008 14:07:56 -0000 @@ -83,6 +83,7 @@ typedef volatile unsigned char __cpu_si #define __HAVE_OLD_DISKLABEL #define __HAVE_ATOMIC64_OPS #define __HAVE_ATOMIC_AS_MEMBAR +#define __HAVE_MM_MD_OPEN #if defined(_KERNEL) #define __HAVE_RAS Index: arch/ia64/conf/files.ia64 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/ia64/conf/files.ia64,v retrieving revision 1.4 diff -u -p -r1.4 files.ia64 --- arch/ia64/conf/files.ia64 17 Oct 2007 19:54:59 -0000 1.4 +++ arch/ia64/conf/files.ia64 2 Mar 2008 14:07:56 -0000 @@ -16,7 +16,6 @@ define cpubus {} file arch/ia64/ia64/autoconf.c file arch/ia64/ia64/machdep.c file arch/ia64/ia64/clock.c -file arch/ia64/ia64/mem.c file arch/ia64/ia64/process_machdep.c file arch/ia64/ia64/pmap.c file arch/ia64/ia64/sys_machdep.c Index: arch/ia64/ia64/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/ia64/ia64/machdep.c,v retrieving revision 1.6 diff -u -p -r1.6 machdep.c --- arch/ia64/ia64/machdep.c 4 Mar 2007 06:00:02 -0000 1.6 +++ arch/ia64/ia64/machdep.c 2 Mar 2008 14:07:56 -0000 @@ -120,6 +120,7 @@ #include #include +#include extern void main __P((void)); @@ -893,5 +894,8 @@ cpu_setmcontext(l, mcp, flags) return (EINVAL); } - - +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + return 0; /* XXX */ +} Index: arch/ia64/ia64/mem.c =================================================================== RCS file: arch/ia64/ia64/mem.c diff -N arch/ia64/ia64/mem.c --- arch/ia64/ia64/mem.c 8 Apr 2006 14:52:09 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,57 +0,0 @@ -/* $NetBSD: mem.c,v 1.2 2006/04/08 14:52:09 cherry Exp $ */ - -/* - * Copyright (c) 2006 The NetBSD Foundation, Inc. - * All rights reserved. - * - * - * Author: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Memory special file - */ - -#include /* RCS ID & Copyright macro defns */ - -#include -#include -#include -#include -#include -#include -#include - -const struct cdevsw mem_cdevsw = { - noopen, noclose, noread, nowrite, noioctl, - nostop, notty, nopoll, nommap, nokqfilter, -}; - Index: arch/luna68k/conf/files.luna68k =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/luna68k/conf/files.luna68k,v retrieving revision 1.20 diff -u -p -r1.20 files.luna68k --- arch/luna68k/conf/files.luna68k 20 Feb 2008 21:43:34 -0000 1.20 +++ arch/luna68k/conf/files.luna68k 2 Mar 2008 14:07:57 -0000 @@ -12,7 +12,6 @@ file arch/luna68k/luna68k/clock.c file arch/luna68k/luna68k/disksubr.c file arch/luna68k/luna68k/isr.c file arch/luna68k/luna68k/machdep.c -file arch/luna68k/luna68k/mem.c file arch/luna68k/luna68k/pmap_bootstrap.c file arch/luna68k/luna68k/trap.c file arch/m68k/m68k/cacheops.c Index: arch/luna68k/luna68k/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/luna68k/luna68k/machdep.c,v retrieving revision 1.53 diff -u -p -r1.53 machdep.c --- arch/luna68k/luna68k/machdep.c 17 Oct 2007 19:55:04 -0000 1.53 +++ arch/luna68k/luna68k/machdep.c 2 Mar 2008 14:07:57 -0000 @@ -63,6 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include #include +#include #include #include #include @@ -90,6 +91,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #endif +#include + #include "ksyms.h" /* @@ -890,3 +893,15 @@ romcngetc(dev) return c; } #endif + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + extern u_int lowram; + + if (pa >= lowram && pa < 0xFFFFFFFC) + return 0; + + return kauth_authorize_machdep(kauth_cred_get(), + KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL); +} Index: arch/luna68k/luna68k/mem.c =================================================================== RCS file: arch/luna68k/luna68k/mem.c diff -N arch/luna68k/luna68k/mem.c --- arch/luna68k/luna68k/mem.c 4 Mar 2007 12:49:10 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,243 +0,0 @@ -/* $NetBSD: mem.c,v 1.13 2007/03/04 12:49:10 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -#include /* RCS ID & Copyright macro defns */ - -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.13 2007/03/04 12:49:10 tsutsui Exp $"); - -/* - * Memory special file - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern u_int lowram; -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - vaddr_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; -#ifndef DEBUG - /* allow reads only in RAM (except for DEBUG) */ - if (v >= 0xFFFFFFFC || v < lowram) { - error = EFAULT; - goto unlock; - } -#endif - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - bzero(devzeropage, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; - - default: - return (ENXIO); - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == DEV_MEM) { -#ifndef DEBUG -unlock: -#endif - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev, off, prot) - dev_t dev; - off_t off; - int prot; -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - /* - * Allow access only in RAM. - * - * XXX could be extended to allow access to IO space but must - * be very careful. - */ - if ((u_int)off < lowram || (u_int)off >= 0xFFFFFFFC) - return (-1); - return (m68k_btop((u_int)off)); -} Index: arch/mac68k/conf/files.mac68k =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/mac68k/conf/files.mac68k,v retrieving revision 1.121 diff -u -p -r1.121 files.mac68k --- arch/mac68k/conf/files.mac68k 20 Feb 2008 21:43:34 -0000 1.121 +++ arch/mac68k/conf/files.mac68k 2 Mar 2008 14:07:57 -0000 @@ -160,7 +160,6 @@ file arch/mac68k/mac68k/machdep.c file arch/mac68k/mac68k/macrom.c file arch/mac68k/mac68k/macromasm.s file arch/mac68k/mac68k/mainbus.c -file arch/mac68k/mac68k/mem.c file arch/mac68k/mac68k/pmap_bootstrap.c compile-with "${NOPROF_C}" file arch/mac68k/mac68k/pram.c file arch/mac68k/mac68k/pramasm.s Index: arch/mac68k/mac68k/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/mac68k/mac68k/machdep.c,v retrieving revision 1.320 diff -u -p -r1.320 machdep.c --- arch/mac68k/mac68k/machdep.c 17 Oct 2007 19:55:15 -0000 1.320 +++ arch/mac68k/mac68k/machdep.c 2 Mar 2008 14:07:57 -0000 @@ -181,6 +181,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #endif #include +#include + #include "ksyms.h" int symsize, end, *ssym, *esym; @@ -2745,3 +2747,13 @@ mac68k_ring_bell(int freq, int length, i else return (ENXIO); } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + extern u_long maxaddr; + + if (pa < maxaddr) + return 0; + return EFAULT; +} Index: arch/mac68k/mac68k/mem.c =================================================================== RCS file: arch/mac68k/mac68k/mem.c diff -N arch/mac68k/mac68k/mem.c --- arch/mac68k/mac68k/mem.c 5 Mar 2007 12:30:38 -0000 1.39 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,235 +0,0 @@ -/* $NetBSD: mem.c,v 1.39 2007/03/05 12:30:38 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.39 2007/03/05 12:30:38 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern u_long maxaddr; -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - vaddr_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - - /* - * Only allow reads in physical RAM. - */ - if (v >= maxaddr || v < 0) { - error = EFAULT; - goto unlock; - } - - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = m68k_page_offset(uio->uio_offset); - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - bzero(devzeropage, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; - - default: - return (ENXIO); - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == DEV_MEM) { -unlock: - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - - /* - * Only allow access to physical RAM. - */ - if ((u_int)off >= maxaddr) - return (-1); - - return (m68k_btop((u_int)off)); -} Index: arch/mips/conf/files.mips =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/mips/conf/files.mips,v retrieving revision 1.58 diff -u -p -r1.58 files.mips --- arch/mips/conf/files.mips 25 Jan 2008 21:12:12 -0000 1.58 +++ arch/mips/conf/files.mips 2 Mar 2008 14:07:57 -0000 @@ -29,7 +29,6 @@ file arch/mips/mips/db_disasm.c ddb file arch/mips/mips/db_interface.c ddb | kgdb file arch/mips/mips/db_trace.c ddb file arch/mips/mips/kgdb_machdep.c kgdb -file arch/mips/mips/mem.c file arch/mips/mips/pmap.c file arch/mips/mips/trap.c # trap handlers file arch/mips/mips/syscall.c # syscall entries Index: arch/mips/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/mips/include/types.h,v retrieving revision 1.43 diff -u -p -r1.43 types.h --- arch/mips/include/types.h 29 Nov 2007 00:58:03 -0000 1.43 +++ arch/mips/include/types.h 2 Mar 2008 14:08:14 -0000 @@ -108,4 +108,7 @@ typedef volatile int __cpu_simple_lock_ #define __HAVE_RAS #endif +#define __HAVE_MM_MD_DIRECT_MAPPED_PHYS +#define __HAVE_MM_MD_KERNACC + #endif /* _MACHTYPES_H_ */ Index: arch/mips/mips/mem.c =================================================================== RCS file: arch/mips/mips/mem.c diff -N arch/mips/mips/mem.c --- arch/mips/mips/mem.c 17 Oct 2007 19:55:38 -0000 1.35 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,204 +0,0 @@ -/* $NetBSD: mem.c,v 1.35 2007/10/17 19:55:38 garbled Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department and Ralph Campbell. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department and Ralph Campbell. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include "opt_cputype.h" -#include "opt_mips_cache.h" - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.35 2007/10/17 19:55:38 garbled Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include - -extern paddr_t avail_end; -void *zeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, nokqfilter, -}; - -#if defined(pmax) -const struct cdevsw mem_ultrix_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, nokqfilter, -}; -#endif /* defined(pmax) */ - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - vaddr_t v; - int c; - struct iovec *iov; - int error = 0; - - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - c = iov->iov_len; - /* - * XXX Broken; assumes contiguous physical memory. - */ - if (v + c > ctob(physmem)) - return (EFAULT); - v += MIPS_KSEG0_START; - error = uiomove((void *)v, c, uio); -#if defined(MIPS3_PLUS) - if (mips_cache_virtual_alias) - mips_dcache_wbinv_range(v, c); -#endif - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (v < MIPS_KSEG0_START) - return (EFAULT); - if (v > MIPS_PHYS_TO_KSEG0(avail_end + - mips_round_page(MSGBUFSIZE) - c) && - (v < MIPS_KSEG2_START || - !uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE))) - return (EFAULT); - error = uiomove((void *)v, c, uio); -#if defined(MIPS3_PLUS) - if (mips_cache_virtual_alias) - mips_dcache_wbinv_range(v, c); -#endif - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - if (zeropage == NULL) { - zeropage = malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - continue; - - default: - return (ENXIO); - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - return (error); -} Index: arch/mips/mips/mips_machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/mips/mips/mips_machdep.c,v retrieving revision 1.199 diff -u -p -r1.199 mips_machdep.c --- arch/mips/mips/mips_machdep.c 19 Feb 2008 12:15:46 -0000 1.199 +++ arch/mips/mips/mips_machdep.c 2 Mar 2008 14:08:52 -0000 @@ -166,6 +166,8 @@ __KERNEL_RCSID(0, "$NetBSD: mips_machdep #include /* MIPS32/MIPS64 registers */ #endif +#include + /* Internal routines. */ int cpu_dumpsize(void); u_long cpu_dump_mempagecnt(void); @@ -1804,3 +1806,40 @@ cpu_intr_p(void) return curcpu()->ci_idepth != 0; } + +bool +mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr) +{ + *vaddr = (vaddr_t)MIPS_KSEG0_START + paddr; + return true; +} + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa < ctob(physmem)) + return 0; + return EFAULT; +} + +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + extern paddr_t avail_end; + + if (ptr < (void *)MIPS_KSEG0_START) { + *handled = true; + return EFAULT; + } + if (ptr < (void *)MIPS_PHYS_TO_KSEG0(avail_end + + mips_round_page(MSGBUFSIZE))) { + *handled = true; + return 0; + } + if (ptr < (void *)MIPS_KSEG2_START) { + *handled = true; + return EFAULT; + } + *handled = false; + return 0; +} Index: arch/mvme68k/conf/files.mvme68k =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/mvme68k/conf/files.mvme68k,v retrieving revision 1.61 diff -u -p -r1.61 files.mvme68k --- arch/mvme68k/conf/files.mvme68k 3 Dec 2007 15:33:58 -0000 1.61 +++ arch/mvme68k/conf/files.mvme68k 2 Mar 2008 14:07:57 -0000 @@ -93,7 +93,6 @@ file arch/mvme68k/mvme68k/conf.c file arch/mvme68k/mvme68k/disksubr.c file arch/mvme68k/mvme68k/isr.c file arch/mvme68k/mvme68k/machdep.c -file arch/mvme68k/mvme68k/mem.c file arch/mvme68k/mvme68k/pmap_bootstrap.c compile-with "${NOPROF_C}" file arch/mvme68k/mvme68k/trap.c file arch/m68k/m68k/cacheops.c Index: arch/mvme68k/mvme68k/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/mvme68k/mvme68k/machdep.c,v retrieving revision 1.127 diff -u -p -r1.127 machdep.c --- arch/mvme68k/mvme68k/machdep.c 12 Jan 2008 09:54:29 -0000 1.127 +++ arch/mvme68k/mvme68k/machdep.c 2 Mar 2008 14:07:57 -0000 @@ -139,6 +139,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #endif +#include + #define MAXMEM 64*1024 /* XXX - from cmap.h */ /* the following is used externally (sysctl_hw) */ @@ -1193,3 +1195,11 @@ makeiplcookie(ipl_t ipl) return (ipl_cookie_t){._psl = ipl2psl_table[ipl] | PSL_S}; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa >= lowram && pa < 0xFFFFFFFC) + return 0; + return EFAULT; +} Index: arch/mvme68k/mvme68k/mem.c =================================================================== RCS file: arch/mvme68k/mvme68k/mem.c diff -N arch/mvme68k/mvme68k/mem.c --- arch/mvme68k/mvme68k/mem.c 12 Jan 2008 09:54:29 -0000 1.27 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,239 +0,0 @@ -/* $NetBSD: mem.c,v 1.27 2008/01/12 09:54:29 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.27 2008/01/12 09:54:29 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern u_int lowram; -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - vaddr_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; -#ifndef DEBUG - /* allow reads only in RAM (except for DEBUG) */ - if (v >= 0xFFFFFFFC || v < lowram) { - error = EFAULT; - goto unlock; - } -#endif - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return 0; - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - * - * XXX on the hp300 we already know where there - * is a global zeroed page, the null segment table. - */ - if (devzeropage == NULL) { - extern void *Segtabzero; - devzeropage = Segtabzero; - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; - - default: - return ENXIO; - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == DEV_MEM) { -#ifndef DEBUG -unlock: -#endif - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return error; -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return -1; - /* - * Allow access only in RAM. - * - * XXX could be extended to allow access to IO space but must - * be very careful. - */ - if ((u_int)off < lowram || (u_int)off >= 0xFFFFFFFC) - return (-1); - return m68k_btop((u_int)off); -} Index: arch/news68k/conf/files.news68k =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/news68k/conf/files.news68k,v retrieving revision 1.31 diff -u -p -r1.31 files.news68k --- arch/news68k/conf/files.news68k 20 Feb 2008 21:43:34 -0000 1.31 +++ arch/news68k/conf/files.news68k 2 Mar 2008 14:07:57 -0000 @@ -18,7 +18,6 @@ file arch/news68k/news68k/disksubr.c di file arch/news68k/news68k/isr.c file arch/news68k/news68k/machdep.c file arch/news68k/news68k/mainbus.c -file arch/news68k/news68k/mem.c file arch/news68k/news68k/pmap_bootstrap.c compile-with "${NOPROF_C}" file arch/news68k/news68k/trap.c file arch/m68k/m68k/cacheops.c Index: arch/news68k/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/news68k/include/types.h,v retrieving revision 1.11 diff -u -p -r1.11 types.h --- arch/news68k/include/types.h 20 Jan 2008 18:09:08 -0000 1.11 +++ arch/news68k/include/types.h 2 Mar 2008 14:07:57 -0000 @@ -1,3 +1,4 @@ /* $NetBSD: types.h,v 1.11 2008/01/20 18:09:08 joerg Exp $ */ #include +#define __HAVE_MM_MD_KERNACC Index: arch/news68k/news68k/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/news68k/news68k/machdep.c,v retrieving revision 1.70 diff -u -p -r1.70 machdep.c --- arch/news68k/news68k/machdep.c 28 Jan 2008 17:07:20 -0000 1.70 +++ arch/news68k/news68k/machdep.c 2 Mar 2008 14:07:57 -0000 @@ -119,6 +119,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include /* XXX should be pulled in by sys/kcore.h */ #include +#include #define MAXMEM 64*1024 /* XXX - from cmap.h */ #include @@ -1102,3 +1103,23 @@ consinit(void) Debugger(); #endif } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa >= lowram && pa < 0xFFFFFFFC) + return 0; + return EFAULT; +} + +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + if (ISIIOVA(ptr)) { + *handled = true; + return EFAULT; + } + + *handled = false; + return 0; +} Index: arch/news68k/news68k/mem.c =================================================================== RCS file: arch/news68k/news68k/mem.c diff -N arch/news68k/news68k/mem.c --- arch/news68k/news68k/mem.c 4 Mar 2007 11:00:01 -0000 1.19 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,240 +0,0 @@ -/* $NetBSD: mem.c,v 1.19 2007/03/04 11:00:01 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.19 2007/03/04 11:00:01 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern u_int lowram; -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - vaddr_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return error; - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - - /* - * Only allow reads in physical RAM. - */ - if (v >= 0xFFFFFFFC || v < lowram) { - error = EFAULT; - goto unlock; - } - - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = m68k_page_offset(uio->uio_offset); - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return EFAULT; - - /* - * Don't allow reading intio - * device space. This could lead to - * corruption of device registers. - */ - if (ISIIOVA(v)) - return EFAULT; - - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return 0; - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (devzeropage == NULL) - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK|M_ZERO); - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; - - default: - return ENXIO; - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == DEV_MEM) { - unlock: - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return error; -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return -1; - - /* - * Allow access only in RAM. - */ - if ((u_int)off < lowram || (u_int)off >= 0xFFFFFFFC) - return -1; - return m68k_btop((u_int)off); -} Index: arch/next68k/conf/files.next68k =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/next68k/conf/files.next68k,v retrieving revision 1.39 diff -u -p -r1.39 files.next68k --- arch/next68k/conf/files.next68k 20 Feb 2008 21:43:34 -0000 1.39 +++ arch/next68k/conf/files.next68k 2 Mar 2008 14:07:57 -0000 @@ -43,7 +43,6 @@ file arch/m68k/m68k/vm_machdep.c # include "arch/m68k/fpe/files.fpe" file arch/next68k/next68k/trap.c -file arch/next68k/next68k/mem.c file arch/next68k/next68k/pmap_bootstrap.c file arch/next68k/next68k/machdep.c file arch/next68k/next68k/clock.c Index: arch/next68k/next68k/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/next68k/next68k/machdep.c,v retrieving revision 1.83 diff -u -p -r1.83 machdep.c --- arch/next68k/next68k/machdep.c 31 Dec 2007 13:38:52 -0000 1.83 +++ arch/next68k/next68k/machdep.c 2 Mar 2008 14:07:57 -0000 @@ -146,6 +146,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include +#include + #include "ksyms.h" int nsym; @@ -949,3 +951,11 @@ cpu_exec_aout_makecmds(struct lwp *l, st { return ENOEXEC; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa >= lowram && pa < 0xFFFFFFFC) + return 0; + return EFAULT; +} Index: arch/next68k/next68k/mem.c =================================================================== RCS file: arch/next68k/next68k/mem.c diff -N arch/next68k/next68k/mem.c --- arch/next68k/next68k/mem.c 5 Mar 2007 12:30:38 -0000 1.25 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,244 +0,0 @@ -/* $NetBSD: mem.c,v 1.25 2007/03/05 12:30:38 tsutsui Exp $ */ - -/* - * This file was taken from mvme68k/mvme68k/mem.c - * should probably be re-synced when needed. - * Darrin B. Jewell Tue Nov 10 05:07:16 1998 - * original cvs id: NetBSD: mem.c,v 1.5 1998/08/22 10:55:35 scw Exp - */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.25 2007/03/05 12:30:38 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern u_int lowram; -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - vaddr_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep(&physlock, PZERO | PCATCH, "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; -#ifndef DEBUG - /* allow reads only in RAM (except for DEBUG) */ - if (v >= 0xFFFFFFFC || v < lowram) { - error = EFAULT; - goto unlock; - } -#endif - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - * - * XXX on the hp300 we already know where there - * is a global zeroed page, the null segment table. - */ - if (devzeropage == NULL) { - extern void *Segtabzero; - devzeropage = Segtabzero; - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; - - default: - return (ENXIO); - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == DEV_MEM) { -#ifndef DEBUG -unlock: -#endif - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - /* - * Allow access only in RAM. - * - * XXX could be extended to allow access to IO space but must - * be very careful. - */ - if ((u_int)off < lowram || (u_int)off >= 0xFFFFFFFC) - return (-1); - return (m68k_btop((u_int)off)); -} Index: arch/powerpc/conf/files.powerpc =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/powerpc/conf/files.powerpc,v retrieving revision 1.69 diff -u -p -r1.69 files.powerpc --- arch/powerpc/conf/files.powerpc 5 Feb 2008 22:31:49 -0000 1.69 +++ arch/powerpc/conf/files.powerpc 2 Mar 2008 14:07:57 -0000 @@ -14,7 +14,6 @@ file arch/powerpc/powerpc/ipkdb_glue.c file arch/powerpc/powerpc/kgdb_machdep.c kgdb file arch/powerpc/powerpc/kobj_machdep.c modular file arch/powerpc/powerpc/lock_stubs.S -file arch/powerpc/powerpc/mem.c file arch/powerpc/powerpc/openpic.c openpic file arch/powerpc/powerpc/pmap_subr.c ppc_oea | ppc_oea64 | ppc_oea64_bridge | ppc_oea601 file arch/powerpc/powerpc/powerpc_machdep.c Index: arch/powerpc/powerpc/mem.c =================================================================== RCS file: arch/powerpc/powerpc/mem.c diff -N arch/powerpc/powerpc/mem.c --- arch/powerpc/powerpc/mem.c 4 Mar 2007 06:00:38 -0000 1.29 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,173 +0,0 @@ -/* $NetBSD: mem.c,v 1.29 2007/03/04 06:00:38 christos Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.29 2007/03/04 06:00:38 christos Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, D_OTHER, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - vaddr_t v; - u_int c; - struct iovec *iov; - int error = 0; - static void *zeropage; - - while (uio->uio_resid > 0 && !error) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - c = uio->uio_resid; - error = uiomove((void *)v, c, uio); - break; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - struct lwp *l = curlwp; - - if (minor(dev) != DEV_MEM) - return (-1); - - if (atop(off) >= physmem && kauth_authorize_machdep(l->l_cred, - KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL) != 0) - return (-1); - return (trunc_page((paddr_t)off)); -} Index: arch/powerpc/powerpc/powerpc_machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/powerpc/powerpc/powerpc_machdep.c,v retrieving revision 1.38 diff -u -p -r1.38 powerpc_machdep.c --- arch/powerpc/powerpc/powerpc_machdep.c 5 Feb 2008 18:52:56 -0000 1.38 +++ arch/powerpc/powerpc/powerpc_machdep.c 2 Mar 2008 14:07:57 -0000 @@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: powerpc_mach #include #include #include +#include #include #include #include @@ -48,6 +49,8 @@ __KERNEL_RCSID(0, "$NetBSD: powerpc_mach #include #include +#include + int cpu_timebase; int cpu_printfataltraps; #if !defined(PPC_IBM4XX) @@ -277,3 +280,12 @@ cpu_intr_p(void) return curcpu()->ci_idepth != 0; } +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (atop(pa) < physmem) + return 0; + + return kauth_authorize_machdep(kauth_cred_get(), + KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL); +} Index: arch/sh3/conf/files.sh3 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sh3/conf/files.sh3,v retrieving revision 1.39 diff -u -p -r1.39 files.sh3 --- arch/sh3/conf/files.sh3 2 Feb 2008 02:19:42 -0000 1.39 +++ arch/sh3/conf/files.sh3 2 Mar 2008 14:07:58 -0000 @@ -17,7 +17,6 @@ file arch/sh3/sh3/exception_vector.S file arch/sh3/sh3/locore_c.c file arch/sh3/sh3/locore_subr.S file arch/sh3/sh3/lock_stubs.S -file arch/sh3/sh3/mem.c file arch/sh3/sh3/pmap.c file arch/sh3/sh3/process_machdep.c file arch/sh3/sh3/sh3_machdep.c Index: arch/sh3/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sh3/include/types.h,v retrieving revision 1.27 diff -u -p -r1.27 types.h --- arch/sh3/include/types.h 20 Jan 2008 18:09:09 -0000 1.27 +++ arch/sh3/include/types.h 2 Mar 2008 14:07:58 -0000 @@ -66,6 +66,9 @@ typedef volatile unsigned char __cpu_sim #define __HAVE_AST_PERPROC #define __HAVE_SYSCALL_INTERN +#define __HAVE_MM_MD_DIRECT_MAPPED_IO +#define __HAVE_MM_MD_DIRECT_MAPPED_PHYS +#define __HAVE_MM_MD_KERNACC #if defined(_KERNEL) #define __HAVE_RAS Index: arch/sh3/sh3/mem.c =================================================================== RCS file: arch/sh3/sh3/mem.c diff -N arch/sh3/sh3/mem.c --- arch/sh3/sh3/mem.c 4 Mar 2007 06:00:41 -0000 1.26 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,212 +0,0 @@ -/* $NetBSD: mem.c,v 1.26 2007/03/04 06:00:41 christos Exp $ */ - -/* - * Copyright (c) 2002 The NetBSD Foundation, Inc. - * All rights reserved. - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.26 2007/03/04 06:00:41 christos Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void *zeropage; -bool __mm_mem_addr(paddr_t); - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - struct iovec *iov; - vaddr_t v, o; - int c; - int error = 0; - - while (uio->uio_resid > 0 && !error) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - - v = uio->uio_offset; - - switch (minor(dev)) { - kmemphys: - case DEV_MEM: - /* Physical address */ - if (__mm_mem_addr(v)) { - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((void *)SH3_PHYS_TO_P1SEG(v), - c, uio); - } else { - return (EFAULT); - } - break; - - case DEV_KMEM: - /* P0 */ - if (v < SH3_P1SEG_BASE) - return (EFAULT); - /* P1 */ - if (v < SH3_P2SEG_BASE) { - v = SH3_P1SEG_TO_PHYS(v); - goto kmemphys; - } - /* P2 */ - if (v < SH3_P3SEG_BASE) - return (EFAULT); - /* P3 */ - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - if (zeropage == NULL) { - zeropage = malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - } - - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - struct lwp *l = curlwp; - - if (minor(dev) != DEV_MEM) - return (-1); - - if (!__mm_mem_addr(off) && kauth_authorize_machdep(l->l_cred, - KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL) != 0) - return (-1); - return (sh3_btop((paddr_t)off)); -} - -/* - * bool __mm_mem_addr(paddr_t pa): - * Check specified physical address is memory device. - */ -bool -__mm_mem_addr(paddr_t pa) -{ - - return ((atop(pa) < vm_physmem[0].start || PHYS_TO_VM_PAGE(pa) != NULL) - ? true : false); -} Index: arch/sh3/sh3/vm_machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sh3/sh3/vm_machdep.c,v retrieving revision 1.62 diff -u -p -r1.62 vm_machdep.c --- arch/sh3/sh3/vm_machdep.c 15 Feb 2008 03:02:43 -0000 1.62 +++ arch/sh3/sh3/vm_machdep.c 2 Mar 2008 14:07:58 -0000 @@ -97,6 +97,7 @@ __KERNEL_RCSID(0, "$NetBSD: vm_machdep.c #include #include #include +#include #include #include @@ -108,6 +109,8 @@ __KERNEL_RCSID(0, "$NetBSD: vm_machdep.c #include #include +#include + extern void lwp_trampoline(void); extern void lwp_setfunc_trampoline(void); @@ -439,3 +442,53 @@ vunmapbuf(struct buf *bp, vsize_t len) bp->b_data = bp->b_saveaddr; bp->b_saveaddr = 0; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (atop(pa) < vm_physmem[0].start || PHYS_TO_VM_PAGE(pa) != NULL) + return 0; + + return kauth_authorize_machdep(kauth_cred_get(), + KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL); +} + +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + vaddr_t va = (vaddr_t)ptr; + + if (va >= SH3_P1SEG_BASE && va < SH3_P2SEG_BASE) { + *handled = true; + return 0; + } + + if (va < SH3_P1SEG_BASE || + (va >= SH3_P2SEG_BASE && va < SH3_P3SEG_BASE)) { + *handled = true; + return EFAULT; + } + /* v < SH3_P3SEG_BASE is physmem, anything special needed? */ + + *handled = false; + return 0; +} + +bool +mm_md_direct_mapped_io(void *ptr, paddr_t *paddr) +{ + vaddr_t va = (vaddr_t)ptr; + + if (va >= SH3_P1SEG_BASE && va < SH3_P2SEG_BASE) { + *paddr = SH3_P1SEG_TO_PHYS(va); + return true; + } + return false; +} + +bool +mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr) +{ + *vaddr = SH3_PHYS_TO_P1SEG(paddr); + return true; +} Index: arch/shark/ofw/ofrom.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/shark/ofw/ofrom.c,v retrieving revision 1.15 diff -u -p -r1.15 ofrom.c --- arch/shark/ofw/ofrom.c 4 Mar 2007 10:21:26 -0000 1.15 +++ arch/shark/ofw/ofrom.c 2 Mar 2008 14:07:58 -0000 @@ -58,6 +58,8 @@ struct ofrom_softc { paddr_t size; }; +static int physlock; + int ofromprobe __P((struct device *, struct cfdata *, void *)); void ofromattach __P((struct device *, struct device *, void *)); Index: arch/sparc/conf/files.sparc =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sparc/conf/files.sparc,v retrieving revision 1.146 diff -u -p -r1.146 files.sparc --- arch/sparc/conf/files.sparc 20 Feb 2008 21:43:35 -0000 1.146 +++ arch/sparc/conf/files.sparc 2 Mar 2008 14:07:58 -0000 @@ -293,7 +293,6 @@ file arch/sparc/sparc/kobj_machdep.c mo # because it must come first in the "ld" command line. file arch/sparc/sparc/machdep.c file arch/sparc/sparc/process_machdep.c -file arch/sparc/sparc/mem.c file arch/sparc/sparc/promlib.c file arch/sparc/sparc/openfirm.c file arch/sparc/sparc/openprom.c Index: arch/sparc/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sparc/include/types.h,v retrieving revision 1.50 diff -u -p -r1.50 types.h --- arch/sparc/include/types.h 20 Jan 2008 18:09:09 -0000 1.50 +++ arch/sparc/include/types.h 2 Mar 2008 14:07:58 -0000 @@ -102,6 +102,7 @@ typedef volatile unsigned char __cpu_si #define __HAVE_DEVICE_REGISTER #define __HAVE_SYSCALL_INTERN #define __GENERIC_SOFT_INTERRUPTS_ALL_LEVELS +#define __HAVE_MM_MD_READWRITE #ifdef SUN4U #define __HAVE_ATOMIC64_OPS Index: arch/sparc/sparc/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sparc/sparc/machdep.c,v retrieving revision 1.276 diff -u -p -r1.276 machdep.c --- arch/sparc/sparc/machdep.c 5 Jan 2008 22:48:21 -0000 1.276 +++ arch/sparc/sparc/machdep.c 2 Mar 2008 14:07:58 -0000 @@ -125,12 +125,15 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include #include +#include #include #include #include #include +#include + #include "fb.h" #include "power.h" @@ -2354,3 +2357,45 @@ struct sparc_bus_space_tag mainbus_space sparc_bus_space_write_4, /* bus_space_write_4 */ sparc_bus_space_write_8 /* bus_space_write_8 */ }; + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + return pmap_pa_exists(pa) ? 0 : EFAULT; +} + +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + extern vaddr_t prom_vstart; + extern vaddr_t prom_vend; + + if (ptr >= (void *)MSGBUF_VA && (char *)ptr < (char *)MSGBUF_VA + PAGE_SIZE) { + *handled = true; + return 0; + } + + if (ptr >= (void *)prom_vstart && ptr < (void *)prom_vend) { + *handled = true; + return (prot & VM_PROT_WRITE) == 0 ? 0 : EFAULT; + } + + *handled = false; + return 0; +} + +int +mm_md_readwrite(dev_t dev, struct uio *uio) +{ + switch (minor(dev)) { +#if defined(SUN4) + case DEV_EEPROM: + if (cputyp == CPU_SUN4) + return eeprom_uio(uio); + else +#endif + return ENXIO; + default: + return ENXIO; + } +} Index: arch/sparc/sparc/mem.c =================================================================== RCS file: arch/sparc/sparc/mem.c diff -N arch/sparc/sparc/mem.c --- arch/sparc/sparc/mem.c 4 Mar 2007 09:23:29 -0000 1.40 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,231 +0,0 @@ -/* $NetBSD: mem.c,v 1.40 2007/03/04 09:23:29 macallan Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.40 2007/03/04 09:23:29 macallan Exp $"); - -#include "opt_sparc_arch.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -extern vaddr_t prom_vstart; -extern vaddr_t prom_vend; -void *zeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - vaddr_t va; - paddr_t pa; - int o, c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - extern void *vmmap; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - int n; - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - - /* Note how much is still to go */ - n = uio->uio_resid; - - switch (minor(dev)) { - - case DEV_MEM: - pa = (paddr_t)uio->uio_offset; - if (!pmap_pa_exists(pa)) { - error = EFAULT; - goto unlock; - } - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(pa), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)vmmap + o, c, uio); - pmap_remove(pmap_kernel(), - (vaddr_t)vmmap, (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - break; - - case DEV_KMEM: - va = (vaddr_t)uio->uio_offset; - if (va >= MSGBUF_VA && va < MSGBUF_VA+PAGE_SIZE) { - c = min(iov->iov_len, 4096); - } else if (va >= prom_vstart && va < prom_vend && - uio->uio_rw == UIO_READ) { - /* Allow read-only access to the PROM */ - c = min(iov->iov_len, prom_vend - prom_vstart); - } else { - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)va, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - } - error = uiomove((void *)va, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - -/* XXX should add sbus, etc */ - -#if defined(SUN4) - case DEV_EEPROM: - if (cputyp == CPU_SUN4) - error = eeprom_uio(uio); - else - error = ENXIO; - - break; -#endif /* SUN4 */ - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return(0); - } - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - bzero(zeropage, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - - /* If we didn't make any progress (i.e. EOF), we're done here */ - if (n == uio->uio_resid) - break; - } - if (minor(dev) == 0) { -unlock: - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} Index: arch/sparc64/conf/files.sparc64 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sparc64/conf/files.sparc64,v retrieving revision 1.118 diff -u -p -r1.118 files.sparc64 --- arch/sparc64/conf/files.sparc64 20 Feb 2008 21:43:35 -0000 1.118 +++ arch/sparc64/conf/files.sparc64 2 Mar 2008 14:07:58 -0000 @@ -186,7 +186,6 @@ file arch/sparc64/sparc64/kobj_machdep.c file arch/sparc64/sparc64/machdep.c file arch/sparc64/sparc64/process_machdep.c file arch/sparc64/sparc64/procfs_machdep.c procfs -file arch/sparc64/sparc64/mem.c file arch/sparc/sparc/openprom.c file arch/sparc/sparc/openfirm.c file arch/sparc64/sparc64/ofw_machdep.c Index: arch/sparc64/sparc64/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sparc64/sparc64/machdep.c,v retrieving revision 1.216 diff -u -p -r1.216 machdep.c --- arch/sparc64/sparc64/machdep.c 22 Feb 2008 10:55:00 -0000 1.216 +++ arch/sparc64/sparc64/machdep.c 2 Mar 2008 14:07:58 -0000 @@ -132,6 +132,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include +#include + /* #include "fb.h" */ int bus_space_debug = 0; /* This may be used by macros elsewhere. */ @@ -1980,3 +1982,33 @@ cpu_intr_p(void) return curcpu()->ci_idepth >= 0; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + return pmap_pa_exists(pa) ? 0 : EFAULT; +} + +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + /* Don't know where PROMs are on Ultras. Think it's at f000000 */ + vaddr_t prom_vstart = 0xf000000; + vaddr_t prom_vend = 0xf0100000; + + size_t msgbufsz = msgbufp->msg_bufs + + offsetof(struct kern_msgbuf, msg_bufc); + if ((char *)ptr >= (char *)msgbufp && + (char *)ptr < (char *)msgbufp + msgbufsz) { + *handled = true; + return 0; + } + + if ((vaddr_t)ptr >= prom_vstart && (vaddr_t)ptr < prom_vend) { + *handled = true; + return (prot & VM_PROT_WRITE) == 0 ? 0 : EFAULT; + } + + *handled = false; + return 0; +} Index: arch/sparc64/sparc64/mem.c =================================================================== RCS file: arch/sparc64/sparc64/mem.c diff -N arch/sparc64/sparc64/mem.c --- arch/sparc64/sparc64/mem.c 4 Mar 2007 07:54:07 -0000 1.34 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,291 +0,0 @@ -/* $NetBSD: mem.c,v 1.34 2007/03/04 07:54:07 christos Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.34 2007/03/04 07:54:07 christos Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -vaddr_t prom_vstart = 0xf000000; -vaddr_t prom_vend = 0xf0100000; -void *zeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, nommap, nokqfilter, D_OTHER -}; - -/*ARGSUSED*/ -int -mmrw(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - vaddr_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - extern void *vmmap; - vsize_t msgbufsz; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - int n; - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - - /* Note how much is still to go */ - n = uio->uio_resid; - - switch (minor(dev)) { - - case DEV_MEM: -#if 1 - v = uio->uio_offset; - if (!pmap_pa_exists(v)) { - error = EFAULT; - goto unlock; - } - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - break; -#else - /* On v9 we can just use the physical ASI and not bother w/mapin & mapout */ - v = uio->uio_offset; - if (!pmap_pa_exists(v)) { - error = EFAULT; - goto unlock; - } - o = uio->uio_offset & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - /* However, we do need to partially re-implement uiomove() */ - if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE) - panic("mmrw: uio mode"); - if (uio->uio_segflg == UIO_USERSPACE && uio->uio_lwp != curlwp) - panic("mmrw: uio proc"); - while (c > 0 && uio->uio_resid) { - struct iovec *iov; - u_int cnt; - int d; - - iov = uio->uio_iov; - cnt = iov->iov_len; - if (cnt == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - continue; - } - if (cnt > c) - cnt = c; - d = iov->iov_base; - switch (uio->uio_segflg) { - - case UIO_USERSPACE: - if (uio->uio_rw == UIO_READ) - while (cnt--) - if(subyte(d++, lduba(v++, ASI_PHYS_CACHED))) { - error = EFAULT; - goto unlock; - } - else - while (cnt--) - stba(v++, ASI_PHYS_CACHED, fubyte(d++)); - if (error) - goto unlock; - break; - - case UIO_SYSSPACE: - if (uio->uio_rw == UIO_READ) - while (cnt--) - stba(d++, ASI_P, lduba(v++, ASI_PHYS_CACHED)); - else - while (cnt--) - stba(v++, ASI_PHYS_CACHED, lduba(d++, ASI_P)); - break; - } - iov->iov_base = (void *)iov->iov_base + cnt; - iov->iov_len -= cnt; - uio->uio_resid -= cnt; - uio->uio_offset += cnt; - c -= cnt; - } - break; -#endif - - case DEV_KMEM: - v = uio->uio_offset; - msgbufsz = msgbufp->msg_bufs + - offsetof(struct kern_msgbuf, msg_bufc); - if (v >= (vaddr_t)msgbufp && - v < (vaddr_t)(msgbufp + msgbufsz)) { - c = min(iov->iov_len, msgbufsz); -#if 1 /* Don't know where PROMs are on Ultras. Think it's at f000000 */ - } else if (v >= prom_vstart && v < prom_vend && - uio->uio_rw == UIO_READ) { - /* Allow read-only access to the PROM */ - c = min(iov->iov_len, prom_vend - prom_vstart); -#endif - } else { - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - } - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - -/* XXX should add sbus, etc */ - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return(0); - } - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(zeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - break; - - default: - return (ENXIO); - } - - /* If we didn't make any progress (i.e. EOF), we're done here */ - if (n == uio->uio_resid) - break; - } - if (minor(dev) == 0) { -unlock: - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} Index: arch/sun2/conf/files.sun2 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sun2/conf/files.sun2,v retrieving revision 1.19 diff -u -p -r1.19 files.sun2 --- arch/sun2/conf/files.sun2 20 Feb 2008 21:43:35 -0000 1.19 +++ arch/sun2/conf/files.sun2 2 Mar 2008 14:07:58 -0000 @@ -14,10 +14,10 @@ file arch/sun2/sun2/locore2.c file arch/sun2/sun2/machdep.c file arch/sun2/sun2/pmap.c file arch/sun2/sun2/control.c -file arch/sun2/sun2/mem.c file arch/sun2/sun2/db_machdep.c ddb file arch/sun2/sun2/db_memrw.c ddb | kgdb file arch/sun2/sun2/leds.c +file arch/sun2/sun2/mm_md.c file arch/sun2/sun2/idprom.c file arch/sun2/sun2/promlib.c file arch/sun2/sun2/sys_machdep.c Index: arch/sun2/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sun2/include/types.h,v retrieving revision 1.9 diff -u -p -r1.9 types.h --- arch/sun2/include/types.h 20 Jan 2008 18:09:09 -0000 1.9 +++ arch/sun2/include/types.h 2 Mar 2008 14:07:58 -0000 @@ -1,3 +1,7 @@ /* $NetBSD: types.h,v 1.9 2008/01/20 18:09:09 joerg Exp $ */ #include +#define __HAVE_MM_MD_KERNACC +#define __HAVE_MM_MD_DIRECT_MAPPED_PHYS +#define __HAVE_MM_MD_READWRITE +#define __HAVE_MM_MD_MMAP Index: arch/sun2/sun2/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sun2/sun2/machdep.c,v retrieving revision 1.50 diff -u -p -r1.50 machdep.c --- arch/sun2/sun2/machdep.c 4 Dec 2007 15:12:07 -0000 1.50 +++ arch/sun2/sun2/machdep.c 2 Mar 2008 14:07:58 -0000 @@ -221,6 +221,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include +#include #include #include @@ -1199,3 +1200,41 @@ find_prom_map(paddr_t pa, bus_type_t ios restore_context(saved_ctx); return ENOENT; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + /* Allow access only in "managed" RAM. */ + if (pa < avail_start || pa >= avail_end) + return EFAULT; + else + return 0; +} + +bool +mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr) +{ + if (paddr >= avail_start) + return false; + *vaddr = paddr; + return true; +} + +/* + * Allow access to the PROM mapping similiar to uvm_kernacc(). + */ +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + if ((vaddr_t)ptr < SUN2_PROM_BASE || (vaddr_t)ptr > SUN2_MONEND) { + *handled = false; + return 0; + } + + *handled = true; + /* Read in the PROM itself is OK, write not. */ + if ((prot & VM_PROT_WRITE) == 0) + return 0; + else + return EFAULT; +} Index: arch/sun2/sun2/mem.c =================================================================== RCS file: arch/sun2/sun2/mem.c diff -N arch/sun2/sun2/mem.c --- arch/sun2/sun2/mem.c 10 Mar 2007 22:29:24 -0000 1.16 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,325 +0,0 @@ -/* $NetBSD: mem.c,v 1.16 2007/03/10 22:29:24 thorpej Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Copyright (c) 1994, 1995 Gordon W. Ross - * Copyright (c) 1993 Adam Glass - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.16 2007/03/10 22:29:24 thorpej Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#define DEV_VME16D16 5 /* minor device 5 is /dev/vme16d16 */ -#define DEV_VME24D16 6 /* minor device 6 is /dev/vme24d16 */ -#define DEV_EEPROM 11 /* minor device 11 is eeprom */ -#define DEV_LEDS 13 /* minor device 13 is leds */ - -static int promacc(void *, int, int); -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - struct iovec *iov; - vaddr_t o, v; - int c, rw; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - if (vmmap == 0) - return (EIO); - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - /* allow reads only in RAM */ - if (v >= avail_end) { - error = EFAULT; - goto unlock; - } - /* - * If the offset (physical address) is outside the - * region of physical memory that is "managed" by - * the pmap system, then we are not allowed to - * call pmap_enter with that physical address. - * Physical 0x0 -> physical 0x2000 is unmapped. - * Everything from 0x2000 to avail_start is mapped - * linearly with physical 0x2000 at virtual 0x2000, - * so redirect the access to /dev/kmem instead. - * This is a better alternative than hacking the - * pmap to deal with requests on unmanaged memory. - * Also note: unlock done at end of function. - */ - if (v < 0x2000) { - error = EFAULT; - goto unlock; - } - if (v < avail_start) { - goto use_kmem; - } - /* Temporarily map the memory at vmmap. */ - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((void *)(vmmap + o), c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - break; - - case DEV_KMEM: - v = uio->uio_offset; - use_kmem: - /* - * Watch out! You might assume it is OK to copy - * up to MAXPHYS bytes here, but that is wrong. - * The next page might NOT be part of the range: - * (KERNBASE..(KERNBASE+avail_start)) - * which is asked for here via the goto in the - * /dev/mem case above. The consequence is that - * we copy one page at a time. No big deal, as - * most requests are less than one page anyway. - */ - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - rw = (uio->uio_rw == UIO_READ) ? B_READ : B_WRITE; - if (!(uvm_kernacc((void *)v, c, rw) || - promacc((void *)v, c, rw))) - { - error = EFAULT; - /* Note: case 0 can get here, so must unlock! */ - goto unlock; - } - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - /* Write to /dev/zero is ignored. */ - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(devzeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - break; - - case DEV_LEDS: - error = leds_uio(uio); - /* Yes, return (not break) so EOF works. */ - return (error); - - default: - return (ENXIO); - } - } - - /* - * Note the different location of this label, compared with - * other ports. This is because the /dev/mem to /dev/kmem - * redirection above jumps here on error to do its unlock. - */ -unlock: - if (minor(dev) == DEV_MEM) { - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * Check address validity. - */ - if (off & PGOFSET) - return (-1); - - switch (minor(dev)) { - - case DEV_MEM: - /* Allow access only in "managed" RAM. */ - if (off < avail_start || off >= avail_end) - break; - return (off); - - case DEV_VME16D16: - if (off & 0xffff0000) - break; - off |= 0xff0000; - /* fall through */ - case DEV_VME24D16: - if (off & 0xff000000) - break; - return (off | (off & 0x800000 ? PMAP_VME8: PMAP_VME0)); - - } - - return (-1); -} - - -/* - * Just like uvm_kernacc(), but for the PROM mappings. - * Return non-zero if access at VA is allowed. - */ -static int -promacc(void *va, int len, int rw) -{ - vaddr_t sva, eva; - - sva = (vaddr_t)va; - eva = (vaddr_t)va + len; - - /* Test for the most common case first. */ - if (sva < SUN2_PROM_BASE) - return (0); - - /* Read in the PROM itself is OK. */ - if ((rw == B_READ) && (eva <= SUN2_MONEND)) - return (1); - - /* otherwise, not OK to touch */ - return (0); -} Index: arch/sun2/sun2/mm_md.c =================================================================== RCS file: arch/sun2/sun2/mm_md.c diff -N arch/sun2/sun2/mm_md.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ arch/sun2/sun2/mm_md.c 2 Mar 2008 14:07:58 -0000 @@ -0,0 +1,120 @@ +/* $NetBSD: mem.c,v 1.16 2007/03/10 22:29:24 thorpej Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 + */ + +/* + * Copyright (c) 1994, 1995 Gordon W. Ross + * Copyright (c) 1993 Adam Glass + * Copyright (c) 1988 University of Utah. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.16 2007/03/10 22:29:24 thorpej Exp $"); + +#include +#include +#include +#include +#include +#include + +#define DEV_VME16D16 5 /* minor device 5 is /dev/vme16d16 */ +#define DEV_VME24D16 6 /* minor device 6 is /dev/vme24d16 */ +#define DEV_EEPROM 11 /* minor device 11 is eeprom */ +#define DEV_LEDS 13 /* minor device 13 is leds */ + +int +mm_md_readwrite(dev_t dev, struct uio *uio) +{ + switch (minor(dev)) { + case DEV_LEDS: + return leds_uio(uio); + default: + return ENXIO; + } +} + +paddr_t +mm_md_mmap(dev_t dev, off_t off, int prot) +{ + switch (minor(dev)) { + case DEV_VME16D16: + if (off & 0xffff0000) + return -1; + off |= 0xff0000; + /* fall through */ + case DEV_VME24D16: + if (off & 0xff000000) + return -1; + return (off | (off & 0x800000 ? PMAP_VME8: PMAP_VME0)); + default: + return (-1); + } +} Index: arch/sun3/conf/files.sun3 =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sun3/conf/files.sun3,v retrieving revision 1.78 diff -u -p -r1.78 files.sun3 --- arch/sun3/conf/files.sun3 20 Feb 2008 21:43:35 -0000 1.78 +++ arch/sun3/conf/files.sun3 2 Mar 2008 14:07:58 -0000 @@ -17,7 +17,7 @@ file arch/sun3/sun3/dvma.c _sun3_ file arch/sun3/sun3/enable.c _sun3_ file arch/sun3/sun3/locore2.c _sun3_ file arch/sun3/sun3/machdep.c _sun3_ -file arch/sun3/sun3/mem.c _sun3_ +file arch/sun3/sun3/mm_md.c _sun3_ file arch/sun3/sun3/pmap.c _sun3_ # Standard stuff (Sun3X-specific) @@ -26,7 +26,7 @@ file arch/sun3/sun3x/dvma.c _sun3x_ file arch/sun3/sun3x/enable.c _sun3x_ file arch/sun3/sun3x/locore2.c _sun3x_ file arch/sun3/sun3x/machdep.c _sun3x_ -file arch/sun3/sun3x/mem.c _sun3x_ +file arch/sun3/sun3x/mm_md.c _sun3x_ file arch/sun3/sun3x/pmap.c _sun3x_ # Standard stuff (common to Sun3 and Sun3X) Index: arch/sun3/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sun3/include/types.h,v retrieving revision 1.17 diff -u -p -r1.17 types.h --- arch/sun3/include/types.h 20 Jan 2008 18:09:09 -0000 1.17 +++ arch/sun3/include/types.h 2 Mar 2008 14:07:58 -0000 @@ -3,3 +3,7 @@ #include #define __BROKEN_CONFIG_UNIT_USAGE +#define __HAVE_MM_MD_KERNACC +#define __HAVE_MM_MD_DIRECT_MAPPED_PHYS +#define __HAVE_MM_MD_MMAP +#define __HAVE_MM_MD_READWRITE Index: arch/sun3/sun3/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sun3/sun3/machdep.c,v retrieving revision 1.184 diff -u -p -r1.184 machdep.c --- arch/sun3/sun3/machdep.c 17 Oct 2007 19:57:46 -0000 1.184 +++ arch/sun3/sun3/machdep.c 2 Mar 2008 14:07:58 -0000 @@ -119,6 +119,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include #include +#include #include #include #include @@ -129,6 +130,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #endif +#include + #include #include "ksyms.h" @@ -742,3 +745,46 @@ cpu_exec_aout_makecmds(struct lwp *l, st { return ENOEXEC; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + /* Allow access only in "managed" RAM. */ + if (pa < avail_start || pa >= avail_end) + return EFAULT; + else + return 0; +} + +bool +mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr) +{ + if (paddr >= avail_start) + return false; + *vaddr = KERNBASE + paddr; + return true; +} + +/* + * Allow access to the PROM mapping similiar to uvm_kernacc(). + */ +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + if ((vaddr_t)ptr < SUN3_PROM_BASE || (vaddr_t)ptr > SUN3_MONEND) { + *handled = false; + return 0; + } + + *handled = true; + /* Read in the PROM itself is OK. */ + if ((prot & VM_PROT_WRITE) == 0) + return 0; + + /* PROM data page is OK for read/write. */ + if ((vaddr_t)ptr >= SUN3_MONSHORTPAGE && + (vaddr_t)ptr < SUN3_MONSHORTPAGE + PAGE_SIZE) + return 0; + else + return EFAULT; +} Index: arch/sun3/sun3/mem.c =================================================================== RCS file: arch/sun3/sun3/mem.c diff -N arch/sun3/sun3/mem.c --- arch/sun3/sun3/mem.c 4 Mar 2007 14:03:03 -0000 1.51 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,352 +0,0 @@ -/* $NetBSD: mem.c,v 1.51 2007/03/04 14:03:03 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Copyright (c) 1994, 1995 Gordon W. Ross - * Copyright (c) 1993 Adam Glass - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.51 2007/03/04 14:03:03 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#define DEV_VME16D16 5 /* minor device 5 is /dev/vme16d16 */ -#define DEV_VME24D16 6 /* minor device 6 is /dev/vme24d16 */ -#define DEV_VME32D16 7 /* minor device 7 is /dev/vme32d16 */ -#define DEV_VME16D32 8 /* minor device 8 is /dev/vme16d32 */ -#define DEV_VME24D32 9 /* minor device 9 is /dev/vme24d32 */ -#define DEV_VME32D32 10 /* minor device 10 is /dev/vme32d32 */ -#define DEV_EEPROM 11 /* minor device 11 is eeprom */ -#define DEV_LEDS 13 /* minor device 13 is leds */ - -static int promacc(void *, int, int); -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - struct iovec *iov; - vaddr_t o, v; - int c, rw; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - if (vmmap == 0) - return (EIO); - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - /* allow reads only in RAM */ - if (v >= avail_end) { - error = EFAULT; - goto unlock; - } - /* - * If the offset (physical address) is outside the - * region of physical memory that is "managed" by - * the pmap system, then we are not allowed to - * call pmap_enter with that physical address. - * Everything from zero to avail_start is mapped - * linearly with physical zero at virtual KERNBASE, - * so redirect the access to /dev/kmem instead. - * This is a better alternative than hacking the - * pmap to deal with requests on unmanaged memory. - * Also note: unlock done at end of function. - */ - if (v < avail_start) { - v += KERNBASE; - goto use_kmem; - } - /* Temporarily map the memory at vmmap. */ - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - break; - - case DEV_KMEM: - v = uio->uio_offset; - use_kmem: - /* - * Watch out! You might assume it is OK to copy - * up to MAXPHYS bytes here, but that is wrong. - * The next page might NOT be part of the range: - * (KERNBASE..(KERNBASE+avail_start)) - * which is asked for here via the goto in the - * /dev/mem case above. The consequence is that - * we copy one page at a time. No big deal, as - * most requests are less than one page anyway. - */ - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - rw = (uio->uio_rw == UIO_READ) ? B_READ : B_WRITE; - if (!(uvm_kernacc((void *)v, c, rw) || - promacc((void *)v, c, rw))) - { - error = EFAULT; - /* Note: case 0 can get here, so must unlock! */ - goto unlock; - } - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_EEPROM: - error = eeprom_uio(uio); - /* Yes, return (not break) so EOF works. */ - return (error); - - case DEV_ZERO: - /* Write to /dev/zero is ignored. */ - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(devzeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - break; - - case DEV_LEDS: - error = leds_uio(uio); - /* Yes, return (not break) so EOF works. */ - return (error); - - default: - return (ENXIO); - } - } - - /* - * Note the different location of this label, compared with - * other ports. This is because the /dev/mem to /dev/kmem - * redirection above jumps here on error to do its unlock. - */ -unlock: - if (minor(dev) == DEV_MEM) { - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * Check address validity. - */ - if (off & PGOFSET) - return (-1); - - switch (minor(dev)) { - - case DEV_MEM: - /* Allow access only in "managed" RAM. */ - if (off < avail_start || off >= avail_end) - break; - return (off); - - case DEV_VME16D16: - if (off & 0xffff0000) - break; - off |= 0xff0000; - /* fall through */ - case DEV_VME24D16: - if (off & 0xff000000) - break; - off |= 0xff000000; - /* fall through */ - case DEV_VME32D16: - return (off | PMAP_VME16); - - case DEV_VME16D32: - if (off & 0xffff0000) - break; - off |= 0xff0000; - /* fall through */ - case DEV_VME24D32: - if (off & 0xff000000) - break; - off |= 0xff000000; - /* fall through */ - case DEV_VME32D32: - return (off | PMAP_VME32); - } - - return (-1); -} - - -/* - * Just like uvm_kernacc(), but for the PROM mappings. - * Return non-zero if access at VA is allowed. - */ -static int -promacc(void *va, int len, int rw) -{ - vaddr_t sva, eva; - - sva = (vaddr_t)va; - eva = (vaddr_t)va + len; - - /* Test for the most common case first. */ - if (sva < SUN3_PROM_BASE) - return (0); - - /* Read in the PROM itself is OK. */ - if ((rw == B_READ) && (eva <= SUN3_MONEND)) - return (1); - - /* PROM data page is OK for read/write. */ - if ((sva >= SUN3_MONSHORTPAGE) && - (eva <= (SUN3_MONSHORTPAGE+PAGE_SIZE))) - return (1); - - /* otherwise, not OK to touch */ - return (0); -} Index: arch/sun3/sun3/mm_md.c =================================================================== RCS file: arch/sun3/sun3/mm_md.c diff -N arch/sun3/sun3/mm_md.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ arch/sun3/sun3/mm_md.c 2 Mar 2008 14:07:58 -0000 @@ -0,0 +1,143 @@ +/* $NetBSD: mem.c,v 1.51 2007/03/04 14:03:03 tsutsui Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 + */ + +/* + * Copyright (c) 1994, 1995 Gordon W. Ross + * Copyright (c) 1993 Adam Glass + * Copyright (c) 1988 University of Utah. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.16 2007/03/10 22:29:24 thorpej Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +#define DEV_VME16D16 5 /* minor device 5 is /dev/vme16d16 */ +#define DEV_VME24D16 6 /* minor device 6 is /dev/vme24d16 */ +#define DEV_VME32D16 7 /* minor device 7 is /dev/vme32d16 */ +#define DEV_VME16D32 8 /* minor device 8 is /dev/vme16d32 */ +#define DEV_VME24D32 9 /* minor device 9 is /dev/vme24d32 */ +#define DEV_VME32D32 10 /* minor device 10 is /dev/vme32d32 */ +#define DEV_EEPROM 11 /* minor device 11 is eeprom */ +#define DEV_LEDS 13 /* minor device 13 is leds */ + +int +mm_md_readwrite(dev_t dev, struct uio *uio) +{ + switch (minor(dev)) { + case DEV_EEPROM: + return eeprom_uio(uio); + case DEV_LEDS: + return leds_uio(uio); + default: + return ENXIO; + } +} + +paddr_t +mm_md_mmap(dev_t dev, off_t off, int prot) +{ + switch (minor(dev)) { + case DEV_VME16D16: + if (off & 0xffff0000) + return -1; + off |= 0xff0000; + /* fall through */ + case DEV_VME24D16: + if (off & 0xff000000) + return -1; + off |= 0xff000000; + /* fall through */ + case DEV_VME32D16: + return (off | PMAP_VME16); + + case DEV_VME16D32: + if (off & 0xffff0000) + return -1; + off |= 0xff0000; + /* fall through */ + case DEV_VME24D32: + if (off & 0xff000000) + return -1; + off |= 0xff000000; + /* fall through */ + case DEV_VME32D32: + return off | PMAP_VME32; + default: + return -1; + } +} Index: arch/sun3/sun3x/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/sun3/sun3x/machdep.c,v retrieving revision 1.110 diff -u -p -r1.110 machdep.c --- arch/sun3/sun3x/machdep.c 17 Oct 2007 19:57:47 -0000 1.110 +++ arch/sun3/sun3x/machdep.c 2 Mar 2008 14:07:58 -0000 @@ -119,6 +119,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include #include +#include #if defined(DDB) #include @@ -128,6 +129,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include +#include + #include "ksyms.h" /* Defined in locore.s */ @@ -742,3 +745,44 @@ cpu_exec_aout_makecmds(struct lwp *l, st { return ENOEXEC; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + return pmap_pa_exists(pa) ? 0 : EFAULT; +} + +bool +mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr) +{ + extern paddr_t avail_start; + + if (paddr >= avail_start) + return false; + *vaddr = KERNBASE + paddr; + return true; +} + +/* + * Allow access to the PROM mapping similiar to uvm_kernacc(). + */ +int +mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled) +{ + if ((vaddr_t)ptr < SUN3X_PROM_BASE || (vaddr_t)ptr > SUN3X_MONEND) { + *handled = false; + return 0; + } + + *handled = true; + /* Read in the PROM itself is OK. */ + if ((prot & VM_PROT_WRITE) == 0) + return 0; + + /* PROM data page is OK for read/write. */ + if ((vaddr_t)ptr >= SUN3X_MONDATA && + (vaddr_t)ptr < SUN3X_MONDATA + PAGE_SIZE) + return 0; + else + return EFAULT; +} Index: arch/sun3/sun3x/mem.c =================================================================== RCS file: arch/sun3/sun3x/mem.c diff -N arch/sun3/sun3x/mem.c --- arch/sun3/sun3x/mem.c 4 Mar 2007 14:03:03 -0000 1.33 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,342 +0,0 @@ -/* $NetBSD: mem.c,v 1.33 2007/03/04 14:03:03 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.33 2007/03/04 14:03:03 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#define DEV_VME16D16 5 /* minor device 5 is /dev/vme16d16 */ -#define DEV_VME24D16 6 /* minor device 6 is /dev/vme24d16 */ -#define DEV_VME32D16 7 /* minor device 7 is /dev/vme32d16 */ -#define DEV_VME16D32 8 /* minor device 8 is /dev/vme16d32 */ -#define DEV_VME24D32 9 /* minor device 9 is /dev/vme24d32 */ -#define DEV_VME32D32 10 /* minor device 10 is /dev/vme32d32 */ -#define DEV_EEPROM 11 /* minor device 11 is eeprom */ -#define DEV_LEDS 13 /* minor device 13 is leds */ - -/* XXX - Put this in pmap_pvt.h or something? */ -extern paddr_t avail_start; - -static int promacc(void *, int, int); -static void *devzeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - struct iovec *iov; - vaddr_t o, v; - int c, rw; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - if (vmmap == 0) - return (EIO); - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - /* allow reads only in RAM */ - if (!pmap_pa_exists(v)) { - error = EFAULT; - goto unlock; - } - /* - * If the offset (physical address) is within the - * linearly mapped range (0 .. avail_start) then - * we can save some hair by using the /dev/kmem - * alias mapping known to exist for this range. - */ - if (v < avail_start) { - v += KERNBASE; - goto use_kmem; - } - /* Temporarily map the memory at vmmap. */ - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove((char *)vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - break; - - case DEV_KMEM: - v = uio->uio_offset; - use_kmem: - /* - * One page at a time to simplify access checks. - * Note that we can get here from case 0 above! - */ - o = v & PGOFSET; - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - rw = (uio->uio_rw == UIO_READ) ? B_READ : B_WRITE; - if (!(uvm_kernacc((void *)v, c, rw) || - promacc((void *)v, c, rw))) - { - error = EFAULT; - /* Note: case 0 can get here, so must unlock! */ - goto unlock; - } - error = uiomove((void *)v, c, uio); - break; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_EEPROM: - error = eeprom_uio(uio); - /* Yes, return (not break) so EOF works. */ - return (error); - - case DEV_ZERO: - /* Write to /dev/zero is ignored. */ - if (uio->uio_rw == UIO_WRITE) { - uio->uio_resid = 0; - return (0); - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - */ - if (devzeropage == NULL) { - devzeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - memset(devzeropage, 0, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - break; - - case DEV_LEDS: - error = leds_uio(uio); - /* Yes, return (not break) so EOF works. */ - return (error); - - default: - return (ENXIO); - } - } - - /* - * Note the different location of this label, compared with - * other ports. This is because the /dev/mem to /dev/kmem - * redirection above jumps here on error to do its unlock. - */ -unlock: - if (minor(dev) == DEV_MEM) { - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * Check address validity. - */ - if (off & PGOFSET) - return (-1); - - switch (minor(dev)) { - - case DEV_MEM: /* dev/mem */ - /* Allow access only in valid memory. */ - if (!pmap_pa_exists(off)) - break; - return (off); - -#if 0 /* XXX - NOTYET */ - /* XXX - Move this to bus_subr.c? */ - case DEV_VME16D16: - if (off & 0xffff0000) - break; - off |= 0xff0000; - /* fall through */ - case DEV_VME24D16: - if (off & 0xff000000) - break; - off |= 0xff000000; - /* fall through */ - case DEV_VME32D16: - return (off | PMAP_VME16); - - case DEV_VME16D32: - if (off & 0xffff0000) - break; - off |= 0xff0000; - /* fall through */ - case DEV_VME24D32: - if (off & 0xff000000) - break; - off |= 0xff000000; - /* fall through */ - case DEV_VME32D32: - return (off | PMAP_VME32); -#endif /* XXX */ - } - - return (-1); -} - - -/* - * Just like uvm_kernacc(), but for the PROM mappings. - * Return non-zero if access at VA is allowed. - */ -static int -promacc(void *va, int len, int rw) -{ - vaddr_t sva, eva; - - sva = (vaddr_t)va; - eva = (vaddr_t)va + len; - - /* Test for the most common case first. */ - if (sva < SUN3X_PROM_BASE) - return (0); - - /* Read in the PROM itself is OK. */ - if ((rw == B_READ) && (eva <= SUN3X_MONEND)) - return (1); - - /* PROM data page is OK for read/write. */ - if ((sva >= SUN3X_MONDATA) && - (eva <= (SUN3X_MONDATA + PAGE_SIZE))) - return (1); - - /* otherwise, not OK to touch */ - return (0); -} Index: arch/sun3/sun3x/mm_md.c =================================================================== RCS file: arch/sun3/sun3x/mm_md.c diff -N arch/sun3/sun3x/mm_md.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ arch/sun3/sun3x/mm_md.c 2 Mar 2008 14:07:58 -0000 @@ -0,0 +1,143 @@ +/* $NetBSD: mem.c,v 1.51 2007/03/04 14:03:03 tsutsui Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 + */ + +/* + * Copyright (c) 1988 University of Utah. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)mem.c 8.3 (Berkeley) 1/12/94 + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.16 2007/03/10 22:29:24 thorpej Exp $"); + +#include +#include +#include +#include +#include +#include +#include + +#define DEV_VME16D16 5 /* minor device 5 is /dev/vme16d16 */ +#define DEV_VME24D16 6 /* minor device 6 is /dev/vme24d16 */ +#define DEV_VME32D16 7 /* minor device 7 is /dev/vme32d16 */ +#define DEV_VME16D32 8 /* minor device 8 is /dev/vme16d32 */ +#define DEV_VME24D32 9 /* minor device 9 is /dev/vme24d32 */ +#define DEV_VME32D32 10 /* minor device 10 is /dev/vme32d32 */ +#define DEV_EEPROM 11 /* minor device 11 is eeprom */ +#define DEV_LEDS 13 /* minor device 13 is leds */ + +int +mm_md_readwrite(dev_t dev, struct uio *uio) +{ + switch (minor(dev)) { + case DEV_EEPROM: + return eeprom_uio(uio); + case DEV_LEDS: + return leds_uio(uio); + default: + return ENXIO; + } +} + +paddr_t +mm_md_mmap(dev_t dev, off_t off, int prot) +{ + switch (minor(dev)) { +#if 0 /* not yet */ + case DEV_VME16D16: + if (off & 0xffff0000) + return -1; + off |= 0xff0000; + /* fall through */ + case DEV_VME24D16: + if (off & 0xff000000) + return -1; + off |= 0xff000000; + /* fall through */ + case DEV_VME32D16: + return (off | PMAP_VME16); + + case DEV_VME16D32: + if (off & 0xffff0000) + return -1; + off |= 0xff0000; + /* fall through */ + case DEV_VME24D32: + if (off & 0xff000000) + return -1; + off |= 0xff000000; + /* fall through */ + case DEV_VME32D32: + return off | PMAP_VME32; +#endif + default: + return -1; + } +} Index: arch/usermode/conf/files.usermode =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/usermode/conf/files.usermode,v retrieving revision 1.2 diff -u -p -r1.2 files.usermode --- arch/usermode/conf/files.usermode 25 Jan 2008 21:12:13 -0000 1.2 +++ arch/usermode/conf/files.usermode 2 Mar 2008 14:07:58 -0000 @@ -25,7 +25,6 @@ file arch/usermode/dev/ttycons.c ttycon file arch/usermode/usermode/copy.c file arch/usermode/usermode/machdep.c -file arch/usermode/usermode/mem.c file arch/usermode/usermode/pmap.c file arch/usermode/usermode/process_machdep.c file arch/usermode/usermode/sys_machdep.c Index: arch/usermode/usermode/mem.c =================================================================== RCS file: arch/usermode/usermode/mem.c diff -N arch/usermode/usermode/mem.c --- arch/usermode/usermode/mem.c 29 Dec 2007 14:38:36 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,58 +0,0 @@ -/* $NetBSD: mem.c,v 1.1 2007/12/29 14:38:36 jmcneill Exp $ */ - -/*- - * Copyright (c) 2007 Jared D. McNeill - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Jared D. McNeill. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.1 2007/12/29 14:38:36 jmcneill Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -dev_type_read(memrw); -dev_type_ioctl(mmioctl); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, memrw, memrw, mmioctl, - nostop, notty, nopoll, nommap, nokqfilter, D_OTHER -}; - -int -memrw(dev_t dev, struct uio *uio, int flags) -{ - return ENXIO; -} Index: arch/vax/conf/INSTALL =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/vax/conf/INSTALL,v retrieving revision 1.47 diff -u -p -r1.47 INSTALL --- arch/vax/conf/INSTALL 29 Dec 2006 21:49:03 -0000 1.47 +++ arch/vax/conf/INSTALL 1 Mar 2008 11:03:07 -0000 @@ -33,7 +33,7 @@ maxusers 8 options MEMORY_DISK_HOOKS options MEMORY_DISK_IS_ROOT # force root on memory disk options MEMORY_DISK_SERVER=0 # no userspace memory disk support -options MEMORY_DISK_ROOT_SIZE=3072 # size of memory disk, in blocks +options MEMORY_DISK_ROOT_SIZE=4096 # size of memory disk, in blocks # Kernel compiled-in symbolic debugger & system call tracer Index: arch/vax/conf/Makefile.vax =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/vax/conf/Makefile.vax,v retrieving revision 1.79 diff -u -p -r1.79 Makefile.vax --- arch/vax/conf/Makefile.vax 22 Dec 2007 08:17:57 -0000 1.79 +++ arch/vax/conf/Makefile.vax 1 Mar 2008 09:53:43 -0000 @@ -69,7 +69,7 @@ LINKFLAGS_NORMAL= -S tmscp.o ts.o uba.o uda.o clock.o emulate.o intvec.o: Makefile sbi.o subr.o: Makefile -unimpl_emul.o: assym.h +lock_stubs.o unimpl_emul.o: assym.h ## ## (7) misc settings Index: arch/vax/conf/files.vax =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/vax/conf/files.vax,v retrieving revision 1.110 diff -u -p -r1.110 files.vax --- arch/vax/conf/files.vax 22 Feb 2008 17:38:38 -0000 1.110 +++ arch/vax/conf/files.vax 2 Mar 2008 14:07:58 -0000 @@ -312,7 +312,6 @@ file arch/vax/uba/dh.c dh needs-flag file dev/cons.c file dev/cninit.c file arch/vax/vax/locore.c -file arch/vax/vax/mem.c file arch/vax/vax/clock.c file arch/vax/vax/gencons.c vax8600 | vax780 | vax750 | vax630 | vax8200 | vax680 | vax650 | vax660 | Index: arch/vax/include/types.h =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/vax/include/types.h,v retrieving revision 1.39 diff -u -p -r1.39 types.h --- arch/vax/include/types.h 20 Feb 2008 16:37:52 -0000 1.39 +++ arch/vax/include/types.h 2 Mar 2008 14:07:58 -0000 @@ -69,4 +69,6 @@ typedef volatile char __cpu_simple_lock_ #define __HAVE_SYSCALL_INTERN #define __HAVE_FAST_SOFTINTS +#define __HAVE_MM_MD_READWRITE + #endif /* _MACHTYPES_H_ */ Index: arch/vax/vax/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/vax/vax/machdep.c,v retrieving revision 1.163 diff -u -p -r1.163 machdep.c --- arch/vax/vax/machdep.c 23 Feb 2008 05:48:14 -0000 1.163 +++ arch/vax/vax/machdep.c 2 Mar 2008 14:07:58 -0000 @@ -111,8 +111,10 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include #include +#include #include +#include #include #include @@ -136,6 +138,9 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include "smg.h" #include "ksyms.h" +#include "leds.h" + +#define DEV_LEDS 13 /* minor device 13 is leds */ extern vaddr_t virtual_avail, virtual_end; /* @@ -748,3 +753,25 @@ generic_reboot(int arg) __asm("halt"); } +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + if (pa < ctob(physmem)) + return 0; + + return kauth_authorize_machdep(kauth_cred_get(), + KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL); +} + +int +mm_md_readwrite(dev_t dev, struct uio *uio) +{ + switch (minor(dev)) { +#if NLEDS + case DEV_LEDS: + return leds_uio(uio); +#endif + default: + return ENXIO; + } +} Index: arch/vax/vax/mem.c =================================================================== RCS file: arch/vax/vax/mem.c diff -N arch/vax/vax/mem.c --- arch/vax/vax/mem.c 4 Mar 2007 19:21:55 -0000 1.36 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,208 +0,0 @@ -/* $NetBSD: mem.c,v 1.36 2007/03/04 19:21:55 christos Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.36 2007/03/04 19:21:55 christos Exp $"); - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include "leds.h" - -#define DEV_LEDS 13 /* minor device 13 is leds */ - -extern paddr_t avail_end; -static void *zeropage; - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter, -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - register vaddr_t v; - register int c; - register struct iovec *iov; - int error = 0; - - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; - if (v < 0 || v >= avail_end) { - return (EFAULT); - } - - c = min(iov->iov_len, MAXPHYS); - error = uiomove((char *)v + KERNBASE, c, uio); - continue; - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - if (zeropage == NULL) { - zeropage = (void *) - malloc(PAGE_SIZE, M_TEMP, M_WAITOK); - bzero(zeropage, PAGE_SIZE); - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(zeropage, c, uio); - continue; -#if NLEDS - case DEV_LEDS: - error = leds_uio(uio); - /* Yes, return (not break) so EOF works. */ - return (error); -#endif - - default: - return (ENXIO); - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - struct lwp *l = curlwp; /* XXX */ - - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - - if ((u_int)off > ctob(physmem) && kauth_authorize_machdep(l->l_cred, - KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL) != 0) - return (-1); - return (btop((u_int)off)); -} - Index: arch/x68k/conf/files.x68k =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/x68k/conf/files.x68k,v retrieving revision 1.65 diff -u -p -r1.65 files.x68k --- arch/x68k/conf/files.x68k 20 Feb 2008 21:43:35 -0000 1.65 +++ arch/x68k/conf/files.x68k 2 Mar 2008 14:07:59 -0000 @@ -30,7 +30,6 @@ file arch/x68k/x68k/autoconf.c file arch/x68k/x68k/conf.c file arch/x68k/x68k/disksubr.c disk file arch/x68k/x68k/machdep.c -file arch/x68k/x68k/mem.c file arch/x68k/x68k/pmap_bootstrap.c compile-with "${NOPROF_C}" file arch/x68k/x68k/trap.c file arch/x68k/x68k/fpu.c Index: arch/x68k/x68k/machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/x68k/x68k/machdep.c,v retrieving revision 1.146 diff -u -p -r1.146 machdep.c --- arch/x68k/x68k/machdep.c 3 Dec 2007 15:34:26 -0000 1.146 +++ arch/x68k/x68k/machdep.c 2 Mar 2008 14:07:59 -0000 @@ -92,6 +92,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include #include +#include #include #include #include @@ -141,6 +142,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v #include #include +#include + void initcpu(void); void identifycpu(void); void doboot(void) __attribute__((__noreturn__)); @@ -1258,3 +1261,18 @@ cpu_intr_p(void) return idepth != 0; } + +int +mm_md_physacc(paddr_t pa, vm_prot_t prot) +{ + int i; + + for (i = 0; i < vm_nphysseg; i++) { + if (ctob(vm_physmem[i].start) <= pa && + pa < ctob(vm_physmem[i].end)) + return 0; + } + + return kauth_authorize_machdep(kauth_cred_get(), + KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL); +} Index: arch/x68k/x68k/mem.c =================================================================== RCS file: arch/x68k/x68k/mem.c diff -N arch/x68k/x68k/mem.c --- arch/x68k/x68k/mem.c 5 Mar 2007 12:30:38 -0000 1.36 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,252 +0,0 @@ -/* $NetBSD: mem.c,v 1.36 2007/03/05 12:30:38 tsutsui Exp $ */ - -/* - * Copyright (c) 1982, 1986, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ -/* - * Copyright (c) 1988 University of Utah. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mem.c 8.3 (Berkeley) 1/12/94 - */ - -/* - * Memory special file - */ - -#include -__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.36 2007/03/05 12:30:38 tsutsui Exp $"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -extern void *Segtabzero; -static void *devzeropage; - -static int isinram(paddr_t); - -dev_type_read(mmrw); -dev_type_ioctl(mmioctl); -dev_type_mmap(mmmmap); - -const struct cdevsw mem_cdevsw = { - nullopen, nullclose, mmrw, mmrw, mmioctl, - nostop, notty, nopoll, mmmmap, nokqfilter -}; - -/*ARGSUSED*/ -int -mmrw(dev_t dev, struct uio *uio, int flags) -{ - vaddr_t o, v; - int c; - struct iovec *iov; - int error = 0; - static int physlock; - vm_prot_t prot; - - if (minor(dev) == DEV_MEM) { - /* lock against other uses of shared vmmap */ - while (physlock > 0) { - physlock++; - error = tsleep((void *)&physlock, PZERO | PCATCH, - "mmrw", 0); - if (error) - return (error); - } - physlock = 1; - } - while (uio->uio_resid > 0 && error == 0) { - iov = uio->uio_iov; - if (iov->iov_len == 0) { - uio->uio_iov++; - uio->uio_iovcnt--; - if (uio->uio_iovcnt < 0) - panic("mmrw"); - continue; - } - switch (minor(dev)) { - - case DEV_MEM: - v = uio->uio_offset; -#ifndef DEBUG - /* allow reads only in RAM (except for DEBUG) */ - if (!isinram((paddr_t) v)) { - error = EFAULT; - goto unlock; - } -#endif - prot = uio->uio_rw == UIO_READ ? VM_PROT_READ : - VM_PROT_WRITE; - pmap_enter(pmap_kernel(), (vaddr_t)vmmap, - trunc_page(v), prot, prot|PMAP_WIRED); - pmap_update(pmap_kernel()); - o = m68k_page_offset(uio->uio_offset); - c = min(uio->uio_resid, (int)(PAGE_SIZE - o)); - error = uiomove(vmmap + o, c, uio); - pmap_remove(pmap_kernel(), (vaddr_t)vmmap, - (vaddr_t)vmmap + PAGE_SIZE); - pmap_update(pmap_kernel()); - continue; - - case DEV_KMEM: - v = uio->uio_offset; - c = min(iov->iov_len, MAXPHYS); - if (!uvm_kernacc((void *)v, c, - uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) - return (EFAULT); - error = uiomove((void *)v, c, uio); - continue; - - case DEV_NULL: - if (uio->uio_rw == UIO_WRITE) - uio->uio_resid = 0; - return (0); - - case DEV_ZERO: - if (uio->uio_rw == UIO_WRITE) { - c = iov->iov_len; - break; - } - /* - * On the first call, allocate and zero a page - * of memory for use with /dev/zero. - * - * XXX on the hp300 we already know where there - * is a global zeroed page, the null segment table. - */ - if (devzeropage == NULL) { - devzeropage = Segtabzero; - } - c = min(iov->iov_len, PAGE_SIZE); - error = uiomove(devzeropage, c, uio); - continue; - - default: - return (ENXIO); - } - if (error) - break; - iov->iov_base = (char *)iov->iov_base + c; - iov->iov_len -= c; - uio->uio_offset += c; - uio->uio_resid -= c; - } - if (minor(dev) == DEV_MEM) { -#ifndef DEBUG -unlock: -#endif - if (physlock > 1) - wakeup((void *)&physlock); - physlock = 0; - } - return (error); -} - -paddr_t -mmmmap(dev_t dev, off_t off, int prot) -{ - /* - * /dev/mem is the only one that makes sense through this - * interface. For /dev/kmem any physaddr we return here - * could be transient and hence incorrect or invalid at - * a later time. /dev/null just doesn't make any sense - * and /dev/zero is a hack that is handled via the default - * pager in mmap(). - */ - if (minor(dev) != DEV_MEM) - return (-1); - /* - * Allow access only in RAM. - * - * XXX could be extended to allow access to IO space but must - * be very careful. - */ - if (!isinram ((paddr_t) off)) - return (-1); - return (m68k_btop((u_int)off)); -} - -static int -isinram(paddr_t addr) -{ - int i; - - for (i = 0; i < vm_nphysseg; i++) { - if (ctob(vm_physmem[i].start) <= addr && - addr < ctob(vm_physmem[i].end)) - return 1; - } - return 0; -} Index: arch/x86/x86/x86_machdep.c =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/x86/x86/x86_machdep.c,v retrieving revision 1.15 diff -u -p -r1.15 x86_machdep.c --- arch/x86/x86/x86_machdep.c 6 Dec 2007 13:58:38 -0000 1.15 +++ arch/x86/x86/x86_machdep.c 2 Mar 2008 14:07:59 -0000 @@ -57,7 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: x86_machdep. #include -int check_pa_acc(paddr_t, vm_prot_t); +#include /* --------------------------------------------------------------------- */ @@ -96,10 +96,10 @@ lookup_bootinfo(int type) } /* - * check_pa_acc: check if given pa is accessible. + * mm_md_physacc: check if given pa is accessible. */ int -check_pa_acc(paddr_t pa, vm_prot_t prot) +mm_md_physacc(paddr_t pa, vm_prot_t prot) { extern phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX]; extern int mem_cluster_cnt; Index: arch/xen/conf/files.xen =================================================================== RCS file: /data/repo/netbsd/src/sys/arch/xen/conf/files.xen,v retrieving revision 1.83 diff -u -p -r1.83 files.xen --- arch/xen/conf/files.xen 27 Feb 2008 04:19:24 -0000 1.83 +++ arch/xen/conf/files.xen 2 Mar 2008 14:07:59 -0000 @@ -50,7 +50,6 @@ file arch/i386/i386/machdep.c file arch/i386/i386/identcpu.c file arch/x86/x86/x86_identcpu.c file arch/i386/i386/longrun.c -file arch/i386/i386/mem.c file arch/i386/i386/mtrr_k6.c mtrr file arch/x86/x86/pmap.c file arch/i386/i386/process_machdep.c @@ -84,7 +83,6 @@ file arch/amd64/amd64/gdt.c file arch/amd64/amd64/machdep.c file arch/amd64/amd64/identcpu.c file arch/x86/x86/x86_identcpu.c -file arch/amd64/amd64/mem.c file arch/x86/x86/pmap.c file arch/amd64/amd64/process_machdep.c file arch/amd64/amd64/procfs_machdep.c procfs Index: dev/mm.c =================================================================== RCS file: /data/repo/netbsd/src/sys/dev/mm.c,v retrieving revision 1.10 diff -u -p -r1.10 mm.c --- dev/mm.c 4 Mar 2007 06:01:43 -0000 1.10 +++ dev/mm.c 7 Mar 2008 16:27:03 -0000 @@ -1,11 +1,11 @@ /* $NetBSD: mm.c,v 1.10 2007/03/04 06:01:43 christos Exp $ */ /*- - * Copyright (c) 2002 The NetBSD Foundation, Inc. + * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation - * by Christos Zoulas. + * by Christos Zoulas and Joerg Sonnenberger. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,40 +40,272 @@ #include __KERNEL_RCSID(0, "$NetBSD: mm.c,v 1.10 2007/03/04 06:01:43 christos Exp $"); -/* - * Memory special file - */ +#include "opt_compat_netbsd.h" #include #include -#include -#include -#include -#include #include -#include +#include +#include +#include +#include + +static void *dev_zero_page; +static size_t dev_zero_pagesize; +static kmutex_t dev_mem_mutex; +static vaddr_t dev_mem_addr; + +static dev_type_read(mm_readwrite); +static dev_type_ioctl(mm_ioctl); +static dev_type_mmap(mm_mmap); +static dev_type_ioctl(mm_ioctl); + +const struct cdevsw mem_cdevsw = { +#ifdef __HAVE_MM_MD_OPEN + mm_md_open, +#else + nullopen, +#endif + nullclose, mm_readwrite, mm_readwrite, + mm_ioctl, nostop, notty, nopoll, mm_mmap, nokqfilter, + D_MPSAFE +}; + +#ifdef pmax +const struct cdevsw mem_ultrix_cdevsw = { + nullopen, nullclose, mm_readwrite, mm_readwrite, + mm_ioctl, nostop, notty, nopoll, mm_mmap, nokqfilter, + D_MPSAFE +}; +#endif + +static int +dev_mem_readwrite(struct uio *uio, struct iovec *iov) +{ + bool have_direct; + paddr_t paddr; + vaddr_t vaddr; + vm_prot_t prot; + size_t len, offset; + int error; + + if ((intptr_t)uio->uio_offset != uio->uio_offset) + return EFAULT; + paddr = uio->uio_offset & ~PAGE_MASK; + offset = uio->uio_offset & PAGE_MASK; + len = min(uio->uio_resid, PAGE_SIZE - offset); + prot = uio->uio_rw == UIO_WRITE ? VM_PROT_WRITE : VM_PROT_READ; + + + if ((error = mm_md_physacc(paddr, prot)) != 0) + return error; + +#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS + have_direct = mm_md_direct_mapped_phys(paddr, &vaddr); +#else + have_direct = false; +#endif + + if (!have_direct) { + mutex_enter(&dev_mem_mutex); + pmap_enter(pmap_kernel(), dev_mem_addr, paddr, prot, + prot | PMAP_WIRED); + pmap_update(pmap_kernel()); + vaddr = dev_mem_addr + offset; + } + error = uiomove((void *)vaddr, len, uio); + if (!have_direct) { + pmap_remove(pmap_kernel(), dev_mem_addr, PAGE_SIZE); + mutex_exit(&dev_mem_mutex); + } -dev_type_ioctl(mmioctl); + return error; +} -int -mmioctl(dev_t dev, u_long cmd, void *data, int flag, - struct lwp *l) +static int +dev_kmem_readwrite(struct uio *uio, struct iovec *iov) { +#ifdef __HAVE_MM_MD_DIRECT_MAPPED_IO + paddr_t paddr; +#endif + void *addr; + size_t len, offset; + vm_prot_t prot; + int error; + bool md_kva; + + addr = (void *)(intptr_t)uio->uio_offset; + if ((uintptr_t)addr != uio->uio_offset) + return EFAULT; + offset = uio->uio_offset & PAGE_MASK; + len = min(uio->uio_resid, PAGE_SIZE - offset); + prot = uio->uio_rw == UIO_WRITE ? VM_PROT_WRITE : VM_PROT_READ; + +#ifdef __HAVE_MM_MD_DIRECT_MAPPED_IO + if (mm_md_direct_mapped_io(addr, &paddr)) { + if ((error = mm_md_physacc(paddr, prot)) != 0) + return error; + md_kva = true; + } +#endif + +#ifdef __HAVE_MM_MD_KERNACC + if (!md_kva && (error = mm_md_kernacc(addr, prot, &md_kva)) != 0) + return error; +#else + md_kva = false; +#endif + + if (!md_kva && !uvm_kernacc(addr, prot)) + return EFAULT; + error = uiomove(addr, len, uio); + return error; +} + +static int +dev_zero_readwrite(struct uio *uio, struct iovec *iov) +{ + size_t len; + + if (uio->uio_rw == UIO_WRITE) { + uio->uio_resid = 0; + return 0; + } + + len = min(iov->iov_len, dev_zero_pagesize); + return uiomove(dev_zero_page, len, uio); +} + +static int +mm_readwrite(dev_t dev, struct uio *uio, int flags) +{ + struct iovec *iov; + int error; + +#ifdef __HAVE_MM_MD_READWRITE switch (minor(dev)) { + case DEV_MEM: + case DEV_KMEM: + case DEV_NULL: + case DEV_ZERO: +#if defined(COMPAT_16) && defined(__arm) + case _DEV_ZERO_oARM: +#endif + break; default: - switch (cmd) { - case FIONBIO: /* We never block anyway */ - return 0; - case FIOSETOWN: - case FIOGETOWN: - case TIOCGPGRP: - case TIOCSPGRP: - return ENOTTY; - case FIOASYNC: - if ((*(int *)data) == 0) - return 0; - /*FALLTHROUGH*/ + return mm_md_readwrite(dev, uio); + } +#endif + + error = 0; + while (uio->uio_resid > 0 && error == 0) { + iov = uio->uio_iov; + if (iov->iov_len == 0) { + ++uio->uio_iov; + --uio->uio_iovcnt; + KASSERT(uio->uio_iovcnt >= 0); + continue; + } + switch (minor(dev)) { + case DEV_MEM: + error = dev_mem_readwrite(uio, iov); + break; + case DEV_KMEM: + error = dev_kmem_readwrite(uio, iov); + break; + case DEV_NULL: + if (uio->uio_rw == UIO_WRITE) + uio->uio_resid = 0; + return 0; /* Break directly out of the loop. */ +#if defined(COMPAT_16) && defined(__arm) + case _DEV_ZERO_oARM: +#endif + case DEV_ZERO: + error = dev_zero_readwrite(uio, iov); + break; + default: + error = ENXIO; + break; } + } + return error; +} + +static paddr_t +mm_mmap(dev_t dev, off_t off, int acc) +{ + vm_prot_t prot; + +#ifdef __HAVE_MM_MD_MMAP + switch (minor(dev)) { + case DEV_MEM: + case DEV_KMEM: + case DEV_NULL: +#if defined(COMPAT_16) && defined(__arm) + case _DEV_ZERO_oARM: +#endif + case DEV_ZERO: + break; + default: + return mm_md_mmap(dev, off, acc); + } +#endif + + /* + * /dev/null doesn't make sense, /dev/kmem is volatile and + * /dev/zero is handled in mmap already. + */ + if (minor(dev) != DEV_MEM) + return -1; + + prot = 0; + if (acc & PROT_EXEC) + prot |= VM_PROT_EXECUTE; + if (acc & PROT_READ) + prot |= VM_PROT_READ; + if (acc & PROT_WRITE) + prot |= VM_PROT_WRITE; + + if (mm_md_physacc(off, prot) != 0) + return -1; + + return off >> PGSHIFT; +} + +static int +mm_ioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) +{ + switch (cmd) { + case FIONBIO: /* We never block anyway */ + return 0; + case FIOSETOWN: + case FIOGETOWN: + case TIOCGPGRP: + case TIOCSPGRP: + return ENOTTY; + case FIOASYNC: + if ((*(int *)data) == 0) + return 0; + /*FALLTHROUGH*/ + default: return EOPNOTSUPP; } } + +void +mm_init(void) +{ + vaddr_t pg; + + mutex_init(&dev_mem_mutex, MUTEX_DEFAULT, IPL_NONE); + + dev_zero_pagesize = PAGE_SIZE; + pg = uvm_km_alloc(kernel_map, dev_zero_pagesize, 0, + UVM_KMF_WIRED | UVM_KMF_ZERO); + KASSERT(pg != 0); + dev_zero_page = (void *)pg; + //pmap_protect(pmap_kernel(), pg, pg + dev_zero_pagesize, VM_PROT_READ); + + dev_mem_addr = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_VAONLY); + KASSERT(dev_mem_addr != 0); +} Index: dev/mm.h =================================================================== RCS file: dev/mm.h diff -N dev/mm.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dev/mm.h 2 Mar 2008 14:07:59 -0000 @@ -0,0 +1,88 @@ +/* $NetBSD$ */ +/*- + * Copyright (c) 2008 Joerg Sonnenberger . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _SYS_DEV_MM_H_ +#define _SYS_DEV_MM_H_ + +#include +#include + +/* + * Optional open() hook for MD. Used by i386 for /dev/io emulation. + * + * machine/types.h must define __HAVE_MM_MD_OPEN to use this. + */ +int mm_md_open(dev_t, int, int, struct lwp *); + +/* + * Optional read/write hook for additional minor devices. + * Must handle the complete uio, not execute in a loop. + * + * machine/types.h must define __HAVE_MM_MD_READWRITE to use this. + */ +int mm_md_readwrite(dev_t, struct uio *); + +/* + * Optional mmap hook for additional MD minor devices. + * + * machine/types.h must define __HAVE_MM_MD_READWRITE to use this. + */ +paddr_t mm_md_mmap(dev_t, off_t, int); + +/* + * Optional access check for the virtual address. The third argument tells + * mm that the check was done and uvm_kernacc is overriden. + * + * machine/types.h must define __HAVE_MM_MD_KERNACC to use this. + */ +int mm_md_kernacc(void *, vm_prot_t, bool *); + +/* + * Required access check for the physical address. + */ +int mm_md_physacc(paddr_t, vm_prot_t); + +/* + * Optional hook to map physical address back to pre-mapped virtual space. + * This is used e.g. when physical memory is lineary mapped. + * + * machine/types.h must define __HAVE_MM_MD_DIRECT_MAPPED_PHYS to use this. + */ +bool mm_md_direct_mapped_phys(paddr_t, vaddr_t *); + +/* + * Optional hook to map virtual address back to physical address for explicit + * access check. This is used e.g. when physical memory is lineary mapped. + * + * machine/types.h must define __HAVE_MM_MD_DIRECT_MAPPED_IO1;2Q to use this. + */ +bool mm_md_direct_mapped_io(void *, paddr_t *); + +#endif /* _SYS_DEV_MM_H_ */ Index: kern/init_main.c =================================================================== RCS file: /data/repo/netbsd/src/sys/kern/init_main.c,v retrieving revision 1.341 diff -u -p -r1.341 init_main.c --- kern/init_main.c 20 Jan 2008 18:09:11 -0000 1.341 +++ kern/init_main.c 2 Mar 2008 14:07:59 -0000 @@ -455,6 +455,8 @@ main(void) /* Lock the kernel on behalf of proc0. */ KERNEL_LOCK(1, l); + mm_init(); + #ifdef SYSVSHM /* Initialize System V style shared memory. */ shminit(); Index: sys/conf.h =================================================================== RCS file: /data/repo/netbsd/src/sys/sys/conf.h,v retrieving revision 1.129 diff -u -p -r1.129 conf.h --- sys/conf.h 7 Nov 2007 15:56:23 -0000 1.129 +++ sys/conf.h 2 Mar 2008 14:07:59 -0000 @@ -238,6 +238,8 @@ const char *devsw_blk2name(int); int devsw_name2blk(const char *, char *, size_t); dev_t devsw_chr2blk(dev_t); dev_t devsw_blk2chr(dev_t); + +void mm_init(void); #endif /* _KERNEL */ #ifdef _KERNEL Index: uvm/uvm_extern.h =================================================================== RCS file: /data/repo/netbsd/src/sys/uvm/uvm_extern.h,v retrieving revision 1.145 diff -u -p -r1.145 uvm_extern.h --- uvm/uvm_extern.h 29 Feb 2008 20:35:23 -0000 1.145 +++ uvm/uvm_extern.h 2 Mar 2008 14:07:59 -0000 @@ -584,7 +584,7 @@ int uvm_coredump_walkmap(struct proc * void uvm_proc_exit(struct proc *); void uvm_lwp_exit(struct lwp *); void uvm_init_limits(struct proc *); -bool uvm_kernacc(void *, size_t, int); +bool uvm_kernacc(void *, vm_prot_t); __dead void uvm_scheduler(void); void uvm_kick_scheduler(void); void uvm_swapin(struct lwp *); Index: uvm/uvm_glue.c =================================================================== RCS file: /data/repo/netbsd/src/sys/uvm/uvm_glue.c,v retrieving revision 1.118 diff -u -p -r1.118 uvm_glue.c --- uvm/uvm_glue.c 29 Feb 2008 12:08:04 -0000 1.118 +++ uvm/uvm_glue.c 2 Mar 2008 14:07:59 -0000 @@ -108,20 +108,18 @@ static void uvm_swapout(struct lwp *); /* * uvm_kernacc: can the kernel access a region of memory * - * - used only by /dev/kmem driver (mem.c) + * - used only by /dev/kmem driver (dev/mm.c) */ bool -uvm_kernacc(void *addr, size_t len, int rw) +uvm_kernacc(void *addr, vm_prot_t prot) { bool rv; - vaddr_t saddr, eaddr; - vm_prot_t prot = rw == B_READ ? VM_PROT_READ : VM_PROT_WRITE; + vaddr_t saddr; saddr = trunc_page((vaddr_t)addr); - eaddr = round_page((vaddr_t)addr + len); vm_map_lock_read(kernel_map); - rv = uvm_map_checkprot(kernel_map, saddr, eaddr, prot); + rv = uvm_map_checkprot(kernel_map, saddr, saddr + 1, prot); vm_map_unlock_read(kernel_map); return(rv);