Annotation of sys/arch/vax/vax/mem.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: mem.c,v 1.14 2005/11/06 22:21:33 miod Exp $ */
! 2: /* $NetBSD: mem.c,v 1.15 1999/03/24 05:51:17 mrg Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1988 University of Utah.
! 6: * Copyright (c) 1982, 1986, 1990, 1993
! 7: * The Regents of the University of California. All rights reserved.
! 8: *
! 9: * This code is derived from software contributed to Berkeley by
! 10: * the Systems Programming Group of the University of Utah Computer
! 11: * Science Department.
! 12: *
! 13: * Redistribution and use in source and binary forms, with or without
! 14: * modification, are permitted provided that the following conditions
! 15: * are met:
! 16: * 1. Redistributions of source code must retain the above copyright
! 17: * notice, this list of conditions and the following disclaimer.
! 18: * 2. Redistributions in binary form must reproduce the above copyright
! 19: * notice, this list of conditions and the following disclaimer in the
! 20: * documentation and/or other materials provided with the distribution.
! 21: * 3. Neither the name of the University nor the names of its contributors
! 22: * may be used to endorse or promote products derived from this software
! 23: * without specific prior written permission.
! 24: *
! 25: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 26: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 27: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 28: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 29: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 30: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 31: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 32: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 33: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 34: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 35: * SUCH DAMAGE.
! 36: *
! 37: * @(#)mem.c 8.3 (Berkeley) 1/12/94
! 38: */
! 39:
! 40: /*
! 41: * Memory special file
! 42: */
! 43:
! 44: #include <sys/param.h>
! 45: #include <sys/conf.h>
! 46: #include <sys/buf.h>
! 47: #include <sys/systm.h>
! 48: #include <sys/uio.h>
! 49: #include <sys/malloc.h>
! 50: #include <sys/proc.h>
! 51:
! 52: #include <machine/pte.h>
! 53: #include <machine/mtpr.h>
! 54:
! 55: #include <uvm/uvm_extern.h>
! 56:
! 57: extern unsigned int avail_end;
! 58: caddr_t zeropage;
! 59:
! 60: #define mmread mmrw
! 61: #define mmwrite mmrw
! 62: cdev_decl(mm);
! 63:
! 64: /*ARGSUSED*/
! 65: int
! 66: mmopen(dev, flag, mode, p)
! 67: dev_t dev;
! 68: int flag, mode;
! 69: struct proc *p;
! 70: {
! 71:
! 72: switch (minor(dev)) {
! 73: case 0:
! 74: case 1:
! 75: case 2:
! 76: case 12:
! 77: return (0);
! 78: default:
! 79: return (ENXIO);
! 80: }
! 81: }
! 82:
! 83: /*ARGSUSED*/
! 84: int
! 85: mmclose(dev, flag, mode, p)
! 86: dev_t dev;
! 87: int flag, mode;
! 88: struct proc *p;
! 89: {
! 90:
! 91: return (0);
! 92: }
! 93:
! 94: /*ARGSUSED*/
! 95: int
! 96: mmrw(dev, uio, flags)
! 97: dev_t dev;
! 98: struct uio *uio;
! 99: int flags;
! 100: {
! 101: vaddr_t v;
! 102: int c;
! 103: struct iovec *iov;
! 104: int error = 0;
! 105:
! 106: while (uio->uio_resid > 0 && error == 0) {
! 107: iov = uio->uio_iov;
! 108: if (iov->iov_len == 0) {
! 109: uio->uio_iov++;
! 110: uio->uio_iovcnt--;
! 111: if (uio->uio_iovcnt < 0)
! 112: panic("mmrw");
! 113: continue;
! 114: }
! 115: switch (minor(dev)) {
! 116:
! 117: /* minor device 0 is physical memory */
! 118: case 0:
! 119: v = uio->uio_offset;
! 120: if (v < 0 || v >= avail_end) {
! 121: return (EFAULT);
! 122: }
! 123:
! 124: c = min(iov->iov_len, MAXPHYS);
! 125: error = uiomove((caddr_t)v + KERNBASE, c, uio);
! 126: continue;
! 127: /* minor device 1 is kernel memory */
! 128: case 1:
! 129: v = uio->uio_offset;
! 130: c = min(iov->iov_len, MAXPHYS);
! 131: if (!uvm_kernacc((caddr_t)v, c,
! 132: uio->uio_rw == UIO_READ ? B_READ : B_WRITE))
! 133: return (EFAULT);
! 134: error = uiomove((caddr_t)v, c, uio);
! 135: continue;
! 136:
! 137: /* minor device 2 is EOF/RATHOLE */
! 138: case 2:
! 139: if (uio->uio_rw == UIO_WRITE)
! 140: uio->uio_resid = 0;
! 141: return (0);
! 142:
! 143: /* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */
! 144: case 12:
! 145: if (uio->uio_rw == UIO_WRITE) {
! 146: c = iov->iov_len;
! 147: break;
! 148: }
! 149: if (zeropage == NULL) {
! 150: zeropage = (caddr_t)
! 151: malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
! 152: bzero(zeropage, PAGE_SIZE);
! 153: }
! 154: c = min(iov->iov_len, PAGE_SIZE);
! 155: error = uiomove(zeropage, c, uio);
! 156: continue;
! 157:
! 158: default:
! 159: return (ENXIO);
! 160: }
! 161: if (error)
! 162: break;
! 163: iov->iov_base = (caddr_t)iov->iov_base + c;
! 164: iov->iov_len -= c;
! 165: uio->uio_offset += c;
! 166: uio->uio_resid -= c;
! 167: }
! 168: return (error);
! 169: }
! 170:
! 171: paddr_t
! 172: mmmmap(dev, off, prot)
! 173: dev_t dev;
! 174: off_t off;
! 175: int prot;
! 176: {
! 177:
! 178: return (-1);
! 179: }
! 180:
! 181: int
! 182: mmioctl(dev, cmd, data, flags, p)
! 183: dev_t dev;
! 184: u_long cmd;
! 185: caddr_t data;
! 186: int flags;
! 187: struct proc *p;
! 188: {
! 189: return (EOPNOTSUPP);
! 190: }
CVSweb