Annotation of sys/arch/sparc/sparc/mem.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: mem.c,v 1.21 2003/06/02 23:27:55 millert Exp $ */
! 2: /* $NetBSD: mem.c,v 1.13 1996/03/30 21:12:16 christos 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/buf.h>
! 46: #include <sys/systm.h>
! 47: #include <sys/uio.h>
! 48: #include <sys/malloc.h>
! 49: #include <sys/proc.h>
! 50: #include <sys/conf.h>
! 51:
! 52: #include <sparc/sparc/vaddrs.h>
! 53: #include <machine/eeprom.h>
! 54: #include <machine/conf.h>
! 55:
! 56: #include <uvm/uvm_extern.h>
! 57:
! 58: extern vaddr_t prom_vstart;
! 59: extern vaddr_t prom_vend;
! 60: caddr_t zeropage;
! 61: vaddr_t mem_page;
! 62:
! 63: /*ARGSUSED*/
! 64: int
! 65: mmopen(dev, flag, mode, p)
! 66: dev_t dev;
! 67: int flag, mode;
! 68: struct proc *p;
! 69: {
! 70:
! 71: switch (minor(dev)) {
! 72: case 0:
! 73: case 1:
! 74: case 2:
! 75: case 11:
! 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: int o;
! 102: paddr_t pa;
! 103: vaddr_t va;
! 104: int c;
! 105: struct iovec *iov;
! 106: int error = 0;
! 107: static int physlock;
! 108:
! 109: if (minor(dev) == 0) {
! 110: /* lock against other uses of shared mem_page */
! 111: while (physlock > 0) {
! 112: physlock++;
! 113: error = tsleep((caddr_t)&physlock, PZERO | PCATCH,
! 114: "mmrw", 0);
! 115: if (error)
! 116: return (error);
! 117: }
! 118: physlock = 1;
! 119: if (mem_page == 0)
! 120: mem_page = uvm_km_valloc_wait(kernel_map, NBPG);
! 121: if (mem_page == 0)
! 122: panic("mmrw: out of space in kernel_map");
! 123: }
! 124: while (uio->uio_resid > 0 && error == 0) {
! 125: iov = uio->uio_iov;
! 126: if (iov->iov_len == 0) {
! 127: uio->uio_iov++;
! 128: uio->uio_iovcnt--;
! 129: if (uio->uio_iovcnt < 0)
! 130: panic("mmrw");
! 131: continue;
! 132: }
! 133: switch (minor(dev)) {
! 134:
! 135: /* minor device 0 is physical memory */
! 136: case 0:
! 137: pa = (paddr_t)uio->uio_offset;
! 138: if (!pmap_pa_exists(pa)) {
! 139: error = EFAULT;
! 140: goto unlock;
! 141: }
! 142: pmap_enter(pmap_kernel(), mem_page,
! 143: trunc_page(pa), uio->uio_rw == UIO_READ ?
! 144: VM_PROT_READ : VM_PROT_WRITE, PMAP_WIRED);
! 145: pmap_update(pmap_kernel());
! 146: o = uio->uio_offset & PGOFSET;
! 147: c = min(uio->uio_resid, (int)(NBPG - o));
! 148: error = uiomove((caddr_t)mem_page + o, c, uio);
! 149: pmap_remove(pmap_kernel(), mem_page, mem_page + NBPG);
! 150: pmap_update(pmap_kernel());
! 151: continue;
! 152:
! 153: /* minor device 1 is kernel memory */
! 154: case 1:
! 155: va = (vaddr_t)uio->uio_offset;
! 156: if (va >= MSGBUF_VA && va < MSGBUF_VA+NBPG) {
! 157: c = min(iov->iov_len, 4096);
! 158: } else if (va >= prom_vstart && va < prom_vend &&
! 159: uio->uio_rw == UIO_READ) {
! 160: /* Allow read-only access to the PROM */
! 161: c = min(iov->iov_len, prom_vend - prom_vstart);
! 162: } else {
! 163: c = min(iov->iov_len, MAXPHYS);
! 164: if (!uvm_kernacc((caddr_t)va, c,
! 165: uio->uio_rw == UIO_READ ? B_READ : B_WRITE))
! 166: return (EFAULT);
! 167: }
! 168: error = uiomove((caddr_t)va, c, uio);
! 169: continue;
! 170:
! 171: /* minor device 2 is EOF/RATHOLE */
! 172: case 2:
! 173: if (uio->uio_rw == UIO_WRITE)
! 174: uio->uio_resid = 0;
! 175: return (0);
! 176:
! 177: /* XXX should add sbus, etc */
! 178:
! 179: #if defined(SUN4)
! 180: /* minor device 11 (/dev/eeprom) is the old-style (a'la Sun 3) EEPROM */
! 181: case 11:
! 182: if (cputyp == CPU_SUN4)
! 183: error = eeprom_uio(uio);
! 184: else
! 185: error = ENXIO;
! 186:
! 187: continue;
! 188: #endif /* SUN4 */
! 189:
! 190: /* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */
! 191: case 12:
! 192: if (uio->uio_rw == UIO_WRITE) {
! 193: uio->uio_resid = 0;
! 194: return 0;
! 195: }
! 196: if (zeropage == NULL) {
! 197: zeropage = (caddr_t)
! 198: malloc(PAGE_SIZE, M_TEMP, M_WAITOK);
! 199: bzero(zeropage, PAGE_SIZE);
! 200: }
! 201: c = min(iov->iov_len, PAGE_SIZE);
! 202: error = uiomove(zeropage, c, uio);
! 203: continue;
! 204:
! 205: default:
! 206: return (ENXIO);
! 207: }
! 208: }
! 209: if (minor(dev) == 0) {
! 210: unlock:
! 211: if (physlock > 1)
! 212: wakeup((caddr_t)&physlock);
! 213: physlock = 0;
! 214: }
! 215: return (error);
! 216: }
! 217:
! 218: paddr_t
! 219: mmmmap(dev, off, prot)
! 220: dev_t dev;
! 221: off_t off;
! 222: int prot;
! 223: {
! 224:
! 225: return (-1);
! 226: }
! 227:
! 228: /*ARGSUSED*/
! 229: int
! 230: mmioctl(dev, cmd, data, flags, p)
! 231: dev_t dev;
! 232: u_long cmd;
! 233: caddr_t data;
! 234: int flags;
! 235: struct proc *p;
! 236: {
! 237: return (EOPNOTSUPP);
! 238: }
CVSweb