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

Annotation of sys/arch/aviion/aviion/mem.c, Revision 1.1.1.1

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

CVSweb