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

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

1.1       nbrk        1: /*     $OpenBSD: mem.c,v 1.3 2004/05/07 15:30:02 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/board.h>
                     50: #include <machine/conf.h>
                     51:
                     52: #include <uvm/uvm_extern.h>
                     53:
                     54: caddr_t zeropage;
                     55: extern vaddr_t last_addr;
                     56:
                     57: /*ARGSUSED*/
                     58: int
                     59: mmopen(dev, flag, mode, p)
                     60:        dev_t dev;
                     61:        int flag, mode;
                     62:        struct proc *p;
                     63: {
                     64:
                     65:        switch (minor(dev)) {
                     66:                case 0:
                     67:                case 1:
                     68:                case 2:
                     69:                case 12:
                     70:                        return (0);
                     71:                default:
                     72:                        return (ENXIO);
                     73:        }
                     74: }
                     75:
                     76: /*ARGSUSED*/
                     77: int
                     78: mmclose(dev, flag, mode, p)
                     79:        dev_t dev;
                     80:        int flag, mode;
                     81:        struct proc *p;
                     82: {
                     83:
                     84:        return (0);
                     85: }
                     86:
                     87: /*ARGSUSED*/
                     88: int
                     89: mmrw(dev, uio, flags)
                     90:        dev_t dev;
                     91:        struct uio *uio;
                     92:        int flags;
                     93: {
                     94:        vaddr_t o, v;
                     95:        int c;
                     96:        struct iovec *iov;
                     97:        int error = 0;
                     98:        static int physlock = 0;
                     99:        extern caddr_t vmmap;
                    100:
                    101:        if (minor(dev) == 0) {
                    102:                /* lock against other uses of shared vmmap */
                    103:                while (physlock > 0) {
                    104:                        physlock++;
                    105:                        error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
                    106:                            "mmrw", 0);
                    107:                        if (error)
                    108:                                return (error);
                    109:                }
                    110:                physlock = 1;
                    111:        }
                    112:        while (uio->uio_resid > 0 && error == 0) {
                    113:                iov = uio->uio_iov;
                    114:                if (iov->iov_len == 0) {
                    115:                        uio->uio_iov++;
                    116:                        uio->uio_iovcnt--;
                    117:                        if (uio->uio_iovcnt < 0)
                    118:                                panic("mmrw");
                    119:                        continue;
                    120:                }
                    121:                switch (minor(dev)) {
                    122:
                    123: /* minor device 0 is physical memory */
                    124:                case 0:
                    125:                        /* move one page at a time */
                    126:                        v = uio->uio_offset;
                    127:                        if (v > last_addr) {
                    128:                                error = EFAULT;
                    129:                                goto unlock;
                    130:                        }
                    131:                        pmap_enter(pmap_kernel(), (vaddr_t)vmmap,
                    132:                            trunc_page(v),
                    133:                            uio->uio_rw == UIO_READ ? VM_PROT_READ : VM_PROT_WRITE,
                    134:                            (uio->uio_rw == UIO_READ ? VM_PROT_READ : VM_PROT_WRITE) | PMAP_WIRED);
                    135:                        pmap_update(pmap_kernel());
                    136:                        o = uio->uio_offset & PGOFSET;
                    137:                        c = min(uio->uio_resid, (int)(NBPG - o));
                    138:                        error = uiomove((caddr_t)vmmap + o, c, uio);
                    139:                        pmap_remove(pmap_kernel(), (vaddr_t)vmmap,
                    140:                            (vaddr_t)vmmap + NBPG);
                    141:                        pmap_update(pmap_kernel());
                    142:                        continue;
                    143:
                    144: /* minor device 1 is kernel memory */
                    145:                case 1:
                    146:                        v = uio->uio_offset;
                    147:                        c = min(iov->iov_len, MAXPHYS);
                    148:                        if (!uvm_kernacc((caddr_t)v, c,
                    149:                            uio->uio_rw == UIO_READ ? B_READ : B_WRITE))
                    150:                                return (EFAULT);
                    151:                        if (v < NBPG) {
                    152: #ifdef DEBUG
                    153:                                /*
                    154:                                 * For now, return zeros on read of page 0
                    155:                                 * and EFAULT for writes.
                    156:                                 */
                    157:                                if (uio->uio_rw == UIO_READ) {
                    158:                                        if (zeropage == NULL) {
                    159:                                                zeropage = (caddr_t)
                    160:                                                    malloc(PAGE_SIZE, M_TEMP,
                    161:                                                    M_WAITOK);
                    162:                                                bzero(zeropage, PAGE_SIZE);
                    163:                                        }
                    164:                                        c = min(c, NBPG - (int)v);
                    165:                                        v = (vaddr_t)zeropage;
                    166:                                } else
                    167: #endif
                    168:                                        return (EFAULT);
                    169:                        }
                    170:                        error = uiomove((caddr_t)v, c, uio);
                    171:                        continue;
                    172:
                    173: /* minor device 2 is EOF/RATHOLE */
                    174:                case 2:
                    175:                        if (uio->uio_rw == UIO_WRITE)
                    176:                                uio->uio_resid = 0;
                    177:                        return (0);
                    178:
                    179: /* should add vme bus so that we can do user level probes */
                    180:
                    181: /* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */
                    182:                case 12:
                    183:                        if (uio->uio_rw == UIO_WRITE) {
                    184:                                c = iov->iov_len;
                    185:                                break;
                    186:                        }
                    187:                        if (zeropage == NULL) {
                    188:                                zeropage = (caddr_t)
                    189:                                    malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
                    190:                                bzero(zeropage, PAGE_SIZE);
                    191:                        }
                    192:                        c = min(iov->iov_len, PAGE_SIZE);
                    193:                        error = uiomove(zeropage, c, uio);
                    194:                        continue;
                    195:
                    196:                default:
                    197:                        return (ENXIO);
                    198:                }
                    199:                if (error)
                    200:                        break;
                    201:                iov->iov_base += c;
                    202:                iov->iov_len -= c;
                    203:                uio->uio_offset += c;
                    204:                uio->uio_resid -= c;
                    205:        }
                    206:        if (minor(dev) == 0) {
                    207: unlock:
                    208:                if (physlock > 1)
                    209:                        wakeup((caddr_t)&physlock);
                    210:                physlock = 0;
                    211:        }
                    212:        return (error);
                    213: }
                    214:
                    215: paddr_t
                    216: mmmmap(dev, off, prot)
                    217:         dev_t dev;
                    218:         off_t off;
                    219:        int prot;
                    220: {
                    221:        return (-1);
                    222: }
                    223:
                    224: /*ARGSUSED*/
                    225: int
                    226: mmioctl(dev, cmd, data, flags, p)
                    227:        dev_t dev;
                    228:        u_long cmd;
                    229:        caddr_t data;
                    230:        int flags;
                    231:        struct proc *p;
                    232: {
                    233:        return (EOPNOTSUPP);
                    234: }

CVSweb