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

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

1.1     ! nbrk        1: /*     $OpenBSD: mem.c,v 1.24 2006/05/19 22:51:09 miod Exp $ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1995 Theo de Raadt
        !             5:  *
        !             6:  * Redistribution and use in source and binary forms, with or without
        !             7:  * modification, are permitted provided that the following conditions
        !             8:  * are met:
        !             9:  * 1. Redistributions of source code must retain the above copyright
        !            10:  *    notice, this list of conditions and the following disclaimer.
        !            11:  * 2. Redistributions in binary form must reproduce the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer in the
        !            13:  *    documentation and/or other materials provided with the distribution.
        !            14:  *
        !            15:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
        !            16:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            18:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
        !            19:  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            20:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            21:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            22:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            23:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            24:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            25:  * SUCH DAMAGE.
        !            26:  *
        !            27:  * Copyright (c) 1988 University of Utah.
        !            28:  * Copyright (c) 1982, 1986, 1990, 1993
        !            29:  *     The Regents of the University of California.  All rights reserved.
        !            30:  *
        !            31:  * This code is derived from software contributed to Berkeley by
        !            32:  * the Systems Programming Group of the University of Utah Computer
        !            33:  * Science Department.
        !            34:  *
        !            35:  * Redistribution and use in source and binary forms, with or without
        !            36:  * modification, are permitted provided that the following conditions
        !            37:  * are met:
        !            38:  * 1. Redistributions of source code must retain the above copyright
        !            39:  *    notice, this list of conditions and the following disclaimer.
        !            40:  * 2. Redistributions in binary form must reproduce the above copyright
        !            41:  *    notice, this list of conditions and the following disclaimer in the
        !            42:  *    documentation and/or other materials provided with the distribution.
        !            43:  * 3. Neither the name of the University nor the names of its contributors
        !            44:  *    may be used to endorse or promote products derived from this software
        !            45:  *    without specific prior written permission.
        !            46:  *
        !            47:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            48:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            49:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            50:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            51:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            52:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            53:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            54:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            55:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            56:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            57:  * SUCH DAMAGE.
        !            58:  *
        !            59:  *     @(#)mem.c       8.3 (Berkeley) 1/12/94
        !            60:  */
        !            61:
        !            62: /*
        !            63:  * Memory special file
        !            64:  */
        !            65:
        !            66: #include <sys/param.h>
        !            67: #include <sys/buf.h>
        !            68: #include <sys/systm.h>
        !            69: #include <sys/uio.h>
        !            70: #include <sys/malloc.h>
        !            71:
        !            72: #include <machine/cpu.h>
        !            73: #include <machine/conf.h>
        !            74:
        !            75: #include <uvm/uvm_extern.h>
        !            76:
        !            77: static caddr_t devzeropage;
        !            78:
        !            79: /*ARGSUSED*/
        !            80: int
        !            81: mmopen(dev, flag, mode, p)
        !            82:        dev_t dev;
        !            83:        int flag, mode;
        !            84:        struct proc *p;
        !            85: {
        !            86:
        !            87:        switch (minor(dev)) {
        !            88:                case 0:
        !            89:                case 1:
        !            90:                case 2:
        !            91:                case 12:
        !            92:                        return (0);
        !            93:                default:
        !            94:                        return (ENXIO);
        !            95:        }
        !            96: }
        !            97:
        !            98: /*ARGSUSED*/
        !            99: int
        !           100: mmclose(dev, flag, mode, p)
        !           101:        dev_t dev;
        !           102:        int flag, mode;
        !           103:        struct proc *p;
        !           104: {
        !           105:
        !           106:        return (0);
        !           107: }
        !           108:
        !           109: /*ARGSUSED*/
        !           110: int
        !           111: mmrw(dev, uio, flags)
        !           112:        dev_t dev;
        !           113:        struct uio *uio;
        !           114:        int flags;
        !           115: {
        !           116:        vaddr_t o, v;
        !           117:        int c;
        !           118:        struct iovec *iov;
        !           119:        int error = 0;
        !           120:        static int physlock;
        !           121:
        !           122:        if (minor(dev) == 0) {
        !           123:                /* lock against other uses of shared vmmap */
        !           124:                while (physlock > 0) {
        !           125:                        physlock++;
        !           126:                        error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
        !           127:                            "mmrw", 0);
        !           128:                        if (error)
        !           129:                                return (error);
        !           130:                }
        !           131:                physlock = 1;
        !           132:        }
        !           133:        while (uio->uio_resid > 0 && error == 0) {
        !           134:                iov = uio->uio_iov;
        !           135:                if (iov->iov_len == 0) {
        !           136:                        uio->uio_iov++;
        !           137:                        uio->uio_iovcnt--;
        !           138:                        if (uio->uio_iovcnt < 0)
        !           139:                                panic("mmrw");
        !           140:                        continue;
        !           141:                }
        !           142:                switch (minor(dev)) {
        !           143:
        !           144: /* minor device 0 is physical memory */
        !           145:                case 0:
        !           146:                        v = uio->uio_offset;
        !           147: #ifndef DEBUG
        !           148:                        /* allow reads only in RAM (except for DEBUG) */
        !           149:                        if (v >= 0xFFFFFFFC || v < NBPG) {
        !           150:                                error = EFAULT;
        !           151:                                goto unlock;
        !           152:                        }
        !           153: #endif
        !           154:
        !           155:                        pmap_enter(pmap_kernel(), (vaddr_t)vmmap,
        !           156:                                   trunc_page(v),
        !           157:                                   uio->uio_rw == UIO_READ ? VM_PROT_READ : VM_PROT_WRITE,
        !           158:                                   (uio->uio_rw == UIO_READ ? VM_PROT_READ : VM_PROT_WRITE) | PMAP_WIRED);
        !           159:                        pmap_update(pmap_kernel());
        !           160:                        o = uio->uio_offset & PGOFSET;
        !           161:                        c = min(uio->uio_resid, (int)(NBPG - o));
        !           162:                        error = uiomove((caddr_t)vmmap + o, c, uio);
        !           163:                        pmap_remove(pmap_kernel(), (vaddr_t)vmmap,
        !           164:                            (vaddr_t)vmmap + NBPG);
        !           165:                        pmap_update(pmap_kernel());
        !           166:                        continue;
        !           167:
        !           168: /* minor device 1 is kernel memory */
        !           169:                case 1:
        !           170:                        v = uio->uio_offset;
        !           171:                        c = min(iov->iov_len, MAXPHYS);
        !           172:                        if (!uvm_kernacc((caddr_t)v, c,
        !           173:                            uio->uio_rw == UIO_READ ? B_READ : B_WRITE))
        !           174:                                return (EFAULT);
        !           175:                        if (v < NBPG)
        !           176:                                return (EFAULT);
        !           177:                        error = uiomove((caddr_t)v, c, uio);
        !           178:                        continue;
        !           179:
        !           180: /* minor device 2 is EOF/RATHOLE */
        !           181:                case 2:
        !           182:                        if (uio->uio_rw == UIO_WRITE)
        !           183:                                uio->uio_resid = 0;
        !           184:                        return (0);
        !           185:
        !           186: /* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */
        !           187:                case 12:
        !           188:                        if (uio->uio_rw == UIO_WRITE) {
        !           189:                                c = iov->iov_len;
        !           190:                                break;
        !           191:                        }
        !           192:                        /*
        !           193:                         * On the first call, allocate and zero a page
        !           194:                         * of memory for use with /dev/zero.
        !           195:                         *
        !           196:                         * XXX on the mvme68k we already know where there
        !           197:                         * is a global zeroed page, the null segment table.
        !           198:                         */
        !           199:                        if (devzeropage == NULL) {
        !           200:                                extern caddr_t Segtabzero;
        !           201:                                devzeropage = Segtabzero;
        !           202:                        }
        !           203:                        c = min(iov->iov_len, PAGE_SIZE);
        !           204:                        error = uiomove(devzeropage, c, uio);
        !           205:                        continue;
        !           206:
        !           207:                default:
        !           208:                        return (ENXIO);
        !           209:                }
        !           210:                if (error)
        !           211:                        break;
        !           212:                iov->iov_base += c;
        !           213:                iov->iov_len -= c;
        !           214:                uio->uio_offset += c;
        !           215:                uio->uio_resid -= c;
        !           216:        }
        !           217:        if (minor(dev) == 0) {
        !           218: unlock:
        !           219:                if (physlock > 1)
        !           220:                        wakeup((caddr_t)&physlock);
        !           221:                physlock = 0;
        !           222:        }
        !           223:        return (error);
        !           224: }
        !           225:
        !           226: paddr_t
        !           227: mmmmap(dev, off, prot)
        !           228:        dev_t dev;
        !           229:        off_t off;
        !           230:        int prot;
        !           231: {
        !           232:        /*
        !           233:         * /dev/mem is the only one that makes sense through this
        !           234:         * interface.  For /dev/kmem any physaddr we return here
        !           235:         * could be transient and hence incorrect or invalid at
        !           236:         * a later time.  /dev/null just doesn't make any sense
        !           237:         * and /dev/zero is a hack that is handled via the default
        !           238:         * pager in mmap().
        !           239:         */
        !           240:        if (minor(dev) != 0)
        !           241:                return (-1);
        !           242:        /*
        !           243:         * Allow access only in RAM.
        !           244:         *
        !           245:         * XXX could be extended to allow access to IO space but must
        !           246:         * be very careful.
        !           247:         */
        !           248:        if ((unsigned)off >= 0xFFFFFFFC || (unsigned)off < NBPG)
        !           249:                return (-1);
        !           250:        return (atop(off));
        !           251: }
        !           252:
        !           253: /*ARGSUSED*/
        !           254: int
        !           255: mmioctl(dev, cmd, data, flags, p)
        !           256:        dev_t dev;
        !           257:        u_long cmd;
        !           258:        caddr_t data;
        !           259:        int flags;
        !           260:        struct proc *p;
        !           261: {
        !           262:        return (EOPNOTSUPP);
        !           263: }

CVSweb