[BACK]Return to mem.c CVS log [TXT][DIR] Up to [local] / sys / arch / sh / sh

Annotation of sys/arch/sh/sh/mem.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: mem.c,v 1.2 2006/12/05 19:55:43 drahn Exp $   */
        !             2: /*     $NetBSD: mem.c,v 1.21 2006/07/23 22:06:07 ad Exp $      */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 2002 The NetBSD Foundation, Inc.
        !             6:  * All rights reserved.
        !             7:  * Copyright (c) 1982, 1986, 1990, 1993
        !             8:  *     The Regents of the University of California.  All rights reserved.
        !             9:  *
        !            10:  * This code is derived from software contributed to Berkeley by
        !            11:  * the Systems Programming Group of the University of Utah Computer
        !            12:  * Science Department.
        !            13:  *
        !            14:  * Redistribution and use in source and binary forms, with or without
        !            15:  * modification, are permitted provided that the following conditions
        !            16:  * are met:
        !            17:  * 1. Redistributions of source code must retain the above copyright
        !            18:  *    notice, this list of conditions and the following disclaimer.
        !            19:  * 2. Redistributions in binary form must reproduce the above copyright
        !            20:  *    notice, this list of conditions and the following disclaimer in the
        !            21:  *    documentation and/or other materials provided with the distribution.
        !            22:  * 3. Neither the name of the University nor the names of its contributors
        !            23:  *    may be used to endorse or promote products derived from this software
        !            24:  *    without specific prior written permission.
        !            25:  *
        !            26:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            36:  * SUCH DAMAGE.
        !            37:  *
        !            38:  *     @(#)mem.c       8.3 (Berkeley) 1/12/94
        !            39:  */
        !            40:
        !            41: /*
        !            42:  * Copyright (c) 1988 University of Utah.
        !            43:  *
        !            44:  * This code is derived from software contributed to Berkeley by
        !            45:  * the Systems Programming Group of the University of Utah Computer
        !            46:  * Science Department.
        !            47:  *
        !            48:  * Redistribution and use in source and binary forms, with or without
        !            49:  * modification, are permitted provided that the following conditions
        !            50:  * are met:
        !            51:  * 1. Redistributions of source code must retain the above copyright
        !            52:  *    notice, this list of conditions and the following disclaimer.
        !            53:  * 2. Redistributions in binary form must reproduce the above copyright
        !            54:  *    notice, this list of conditions and the following disclaimer in the
        !            55:  *    documentation and/or other materials provided with the distribution.
        !            56:  * 3. All advertising materials mentioning features or use of this software
        !            57:  *    must display the following acknowledgement:
        !            58:  *     This product includes software developed by the University of
        !            59:  *     California, Berkeley and its contributors.
        !            60:  * 4. Neither the name of the University nor the names of its contributors
        !            61:  *    may be used to endorse or promote products derived from this software
        !            62:  *    without specific prior written permission.
        !            63:  *
        !            64:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            65:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            66:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            67:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            68:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            69:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            70:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            71:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            72:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            73:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            74:  * SUCH DAMAGE.
        !            75:  *
        !            76:  *     @(#)mem.c       8.3 (Berkeley) 1/12/94
        !            77:  */
        !            78:
        !            79: /*
        !            80:  * Memory special file
        !            81:  */
        !            82:
        !            83: #include <sys/param.h>
        !            84: #include <sys/systm.h>
        !            85: #include <sys/buf.h>
        !            86: #include <sys/uio.h>
        !            87: #include <sys/malloc.h>
        !            88: #include <sys/proc.h>
        !            89: #include <sys/conf.h>
        !            90:
        !            91: #include <uvm/uvm_extern.h>
        !            92:
        !            93: caddr_t zeropage;
        !            94: boolean_t __mm_mem_addr(paddr_t);
        !            95:
        !            96: #define mmread mmrw
        !            97: #define mmwrite        mmrw
        !            98: cdev_decl(mm);
        !            99:
        !           100: #define        DEV_MEM         0
        !           101: #define        DEV_KMEM        1
        !           102: #define        DEV_NULL        2
        !           103: #define        DEV_ZERO        12
        !           104:
        !           105: /* ARGSUSED */
        !           106: int
        !           107: mmopen(dev_t dev, int flag, int mode, struct proc *p)
        !           108: {
        !           109:        switch (minor(dev)) {
        !           110:        case DEV_MEM:
        !           111:        case DEV_KMEM:
        !           112:        case DEV_NULL:
        !           113:        case DEV_ZERO:
        !           114:                break;
        !           115:        default:
        !           116:                return (ENXIO);
        !           117:        }
        !           118:
        !           119:        return (0);
        !           120: }
        !           121:
        !           122: /*ARGSUSED*/
        !           123: int
        !           124: mmclose(dev_t dev, int flag, int mode, struct proc *p)
        !           125: {
        !           126:        return (0);
        !           127: }
        !           128:
        !           129: /*ARGSUSED*/
        !           130: int
        !           131: mmrw(dev_t dev, struct uio *uio, int flags)
        !           132: {
        !           133:        struct iovec *iov;
        !           134:        vaddr_t v, o;
        !           135:        int c;
        !           136:        int error = 0;
        !           137:
        !           138:        while (uio->uio_resid > 0 && !error) {
        !           139:                iov = uio->uio_iov;
        !           140:                if (iov->iov_len == 0) {
        !           141:                        uio->uio_iov++;
        !           142:                        uio->uio_iovcnt--;
        !           143:                        if (uio->uio_iovcnt < 0)
        !           144:                                panic("mmrw");
        !           145:                        continue;
        !           146:                }
        !           147:
        !           148:                v = uio->uio_offset;
        !           149:
        !           150:                switch (minor(dev)) {
        !           151:                case DEV_MEM:
        !           152:                        /* Physical address */
        !           153:                        if (__mm_mem_addr(v)) {
        !           154:                                o = v & PGOFSET;
        !           155:                                c = min(uio->uio_resid, (int)(PAGE_SIZE - o));
        !           156:                                error = uiomove((caddr_t)SH3_PHYS_TO_P1SEG(v),
        !           157:                                    c, uio);
        !           158:                        } else {
        !           159:                                return (EFAULT);
        !           160:                        }
        !           161:                        break;
        !           162:
        !           163:                case DEV_KMEM:
        !           164:                        if (v < SH3_P1SEG_BASE)                 /* P0 */
        !           165:                                return (EFAULT);
        !           166:                        if (v < SH3_P2SEG_BASE) {               /* P1 */
        !           167:                                /* permitted */
        !           168:                        /*
        !           169:                                if (__mm_mem_addr(SH3_P1SEG_TO_PHYS(v))
        !           170:                                    == FALSE)
        !           171:                                        return (EFAULT);
        !           172:                        */
        !           173:                                c = min(iov->iov_len, MAXPHYS);
        !           174:                                error = uiomove((caddr_t)v, c, uio);
        !           175:                        } else if (v < SH3_P3SEG_BASE)          /* P2 */
        !           176:                                return (EFAULT);
        !           177:                        else {                                  /* P3 */
        !           178:                                c = min(iov->iov_len, MAXPHYS);
        !           179:                                if (!uvm_kernacc((void *)v, c,
        !           180:                                    uio->uio_rw == UIO_READ ? B_READ : B_WRITE))
        !           181:                                        return (EFAULT);
        !           182:                                error = uiomove((caddr_t)v, c, uio);
        !           183:                        }
        !           184:                        break;
        !           185:
        !           186:                case DEV_NULL:
        !           187:                        if (uio->uio_rw == UIO_WRITE)
        !           188:                                uio->uio_resid = 0;
        !           189:                        return (0);
        !           190:
        !           191:                case DEV_ZERO:
        !           192:                        if (uio->uio_rw == UIO_WRITE) {
        !           193:                                uio->uio_resid = 0;
        !           194:                                return (0);
        !           195:                        }
        !           196:                        if (zeropage == NULL) {
        !           197:                                zeropage = malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
        !           198:                                memset(zeropage, 0, PAGE_SIZE);
        !           199:                        }
        !           200:                        c = min(iov->iov_len, PAGE_SIZE);
        !           201:                        error = uiomove(zeropage, c, uio);
        !           202:                        break;
        !           203:
        !           204:                default:
        !           205:                        return (ENXIO);
        !           206:                }
        !           207:        }
        !           208:
        !           209:        return (error);
        !           210: }
        !           211:
        !           212: /*ARGSUSED*/
        !           213: paddr_t
        !           214: mmmmap(dev_t dev, off_t off, int prot)
        !           215: {
        !           216:        struct proc *p = curproc;
        !           217:
        !           218:        if (minor(dev) != DEV_MEM)
        !           219:                return (-1);
        !           220:
        !           221:        if (__mm_mem_addr((paddr_t)off) == FALSE && suser(p, 0) != 0)
        !           222:                return (-1);
        !           223:        return (atop((paddr_t)off));
        !           224: }
        !           225:
        !           226: /*ARGSUSED*/
        !           227: int
        !           228: mmioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
        !           229: {
        !           230:        return (EOPNOTSUPP);
        !           231: }
        !           232:
        !           233: /*
        !           234:  * boolean_t __mm_mem_addr(paddr_t pa):
        !           235:  *     Check specified physical address is in physical memory, with the
        !           236:  *     kernel image off-limits.
        !           237:  */
        !           238: boolean_t
        !           239: __mm_mem_addr(paddr_t pa)
        !           240: {
        !           241: #if 0
        !           242:        extern vaddr_t kernend; /* from machdep.c */
        !           243: #endif
        !           244:        struct vm_physseg *seg;
        !           245:        unsigned int segno;
        !           246:
        !           247:        for (segno = 0, seg = vm_physmem; segno < vm_nphysseg; segno++, seg++) {
        !           248:                if (pa < seg->start || pa >= seg->end)
        !           249:                        continue;
        !           250:
        !           251: #if 0
        !           252:                /*
        !           253:                 * This assumes the kernel image occupies the beginning of a
        !           254:                 * memory segment.
        !           255:                 */
        !           256:                if (kernend >= seg->start && kernend < seg->end) {
        !           257:                        if (pa < kernend)
        !           258:                                return (FALSE);
        !           259:                }
        !           260: #endif
        !           261:
        !           262:                return (TRUE);
        !           263:        }
        !           264:
        !           265:        return (FALSE);
        !           266: }

CVSweb