Annotation of sys/arch/mvme68k/dev/sram.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: sram.c,v 1.17 2005/11/25 19:19:39 miod Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 1995 Theo de Raadt
! 5: * All rights reserved.
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. Redistributions in binary form must reproduce the above copyright
! 13: * notice, this list of conditions and the following disclaimer in the
! 14: * documentation and/or other materials provided with the distribution.
! 15: *
! 16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 17: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 18: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 19: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 20: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 21: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 22: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 23: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 24: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! 25: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 26: */
! 27:
! 28: #include <sys/param.h>
! 29: #include <sys/ioctl.h>
! 30: #include <sys/buf.h>
! 31: #include <sys/systm.h>
! 32: #include <sys/uio.h>
! 33: #include <sys/malloc.h>
! 34: #include <sys/device.h>
! 35:
! 36: #include <machine/autoconf.h>
! 37: #include <machine/conf.h>
! 38: #include <machine/cpu.h>
! 39: #include <machine/mioctl.h>
! 40:
! 41: #include <mvme68k/dev/memdevs.h>
! 42:
! 43: #include "mc.h"
! 44:
! 45: #if NMC > 0
! 46: #include <mvme68k/dev/mcreg.h>
! 47: #endif
! 48:
! 49: #include <uvm/uvm_extern.h>
! 50:
! 51: struct sramsoftc {
! 52: struct device sc_dev;
! 53: paddr_t sc_paddr;
! 54: vaddr_t sc_vaddr;
! 55: int sc_len;
! 56: };
! 57:
! 58: void sramattach(struct device *, struct device *, void *);
! 59: int srammatch(struct device *, void *, void *);
! 60:
! 61: struct cfattach sram_ca = {
! 62: sizeof(struct sramsoftc), srammatch, sramattach
! 63: };
! 64:
! 65: struct cfdriver sram_cd = {
! 66: NULL, "sram", DV_DULL
! 67: };
! 68:
! 69: int
! 70: srammatch(parent, vcf, args)
! 71: struct device *parent;
! 72: void *vcf, *args;
! 73: {
! 74: struct confargs *ca = args;
! 75:
! 76: if (cputyp == CPU_147)
! 77: return (0);
! 78:
! 79: return (!badpaddr(ca->ca_paddr, 1));
! 80: }
! 81:
! 82: void
! 83: sramattach(parent, self, args)
! 84: struct device *parent, *self;
! 85: void *args;
! 86: {
! 87: struct confargs *ca = args;
! 88: struct sramsoftc *sc = (struct sramsoftc *)self;
! 89: #ifdef MVME162
! 90: struct mcreg *mc;
! 91: #endif
! 92:
! 93: switch (cputyp) {
! 94: #ifdef MVME162
! 95: case CPU_162:
! 96: /* XXX this code will almost never be used. just in case. */
! 97: mc = sys_mc;
! 98: if (!mc)
! 99: mc = (struct mcreg *)(IIOV(0xfff00000) + MC_MCCHIP_OFF);
! 100:
! 101: switch (mc->mc_memoptions & MC_MEMOPTIONS_SRAMMASK) {
! 102: case MC_MEMOPTIONS_SRAM128K:
! 103: sc->sc_len = 128*1024;
! 104: break;
! 105: case MC_MEMOPTIONS_SRAM512K:
! 106: sc->sc_len = 512*1024;
! 107: break;
! 108: case MC_MEMOPTIONS_SRAM1M:
! 109: sc->sc_len = 1024*1024;
! 110: break;
! 111: case MC_MEMOPTIONS_SRAM2M:
! 112: sc->sc_len = 2048*1024;
! 113: break;
! 114: }
! 115: break;
! 116: #endif
! 117: #ifdef MVME167
! 118: case CPU_167:
! 119: case CPU_166:
! 120: sc->sc_len = 128*1024; /* always 128K */
! 121: break;
! 122: #endif
! 123: #ifdef MVME177
! 124: case CPU_177:
! 125: sc->sc_len = 128*1024; /* always 128K */
! 126: break;
! 127: #endif
! 128: default:
! 129: sc->sc_len = 0;
! 130: break;
! 131: }
! 132:
! 133: printf(": len %d", sc->sc_len);
! 134:
! 135: sc->sc_paddr = ca->ca_paddr;
! 136: sc->sc_vaddr = mapiodev(sc->sc_paddr, sc->sc_len);
! 137: if (sc->sc_vaddr == 0) {
! 138: sc->sc_len = 0;
! 139: printf(" -- failed to map");
! 140: }
! 141: printf("\n");
! 142: }
! 143:
! 144: /*ARGSUSED*/
! 145: int
! 146: sramopen(dev, flag, mode, p)
! 147: dev_t dev;
! 148: int flag, mode;
! 149: struct proc *p;
! 150: {
! 151: if (minor(dev) >= sram_cd.cd_ndevs ||
! 152: sram_cd.cd_devs[minor(dev)] == NULL)
! 153: return (ENODEV);
! 154: return (0);
! 155: }
! 156:
! 157: /*ARGSUSED*/
! 158: int
! 159: sramclose(dev, flag, mode, p)
! 160: dev_t dev;
! 161: int flag, mode;
! 162: struct proc *p;
! 163: {
! 164:
! 165: return (0);
! 166: }
! 167:
! 168: /*ARGSUSED*/
! 169: int
! 170: sramioctl(dev, cmd, data, flag, p)
! 171: dev_t dev;
! 172: u_long cmd;
! 173: caddr_t data;
! 174: int flag;
! 175: struct proc *p;
! 176: {
! 177: int unit = minor(dev);
! 178: struct sramsoftc *sc = (struct sramsoftc *) sram_cd.cd_devs[unit];
! 179: int error = 0;
! 180:
! 181: switch (cmd) {
! 182: case MIOCGSIZ:
! 183: *(int *)data = sc->sc_len;
! 184: break;
! 185: default:
! 186: error = ENOTTY;
! 187: break;
! 188: }
! 189: return (error);
! 190: }
! 191:
! 192: /*ARGSUSED*/
! 193: int
! 194: sramrw(dev, uio, flags)
! 195: dev_t dev;
! 196: struct uio *uio;
! 197: int flags;
! 198: {
! 199: int unit = minor(dev);
! 200: struct sramsoftc *sc = (struct sramsoftc *) sram_cd.cd_devs[unit];
! 201:
! 202: return (memdevrw(sc->sc_vaddr, sc->sc_len, uio, flags));
! 203: }
! 204:
! 205: paddr_t
! 206: srammmap(dev, off, prot)
! 207: dev_t dev;
! 208: off_t off;
! 209: int prot;
! 210: {
! 211: int unit = minor(dev);
! 212: struct sramsoftc *sc = (struct sramsoftc *) sram_cd.cd_devs[unit];
! 213:
! 214: if (minor(dev) != 0)
! 215: return (-1);
! 216:
! 217: /* allow access only in RAM */
! 218: if (off < 0 || off > sc->sc_len)
! 219: return (-1);
! 220: return (atop(sc->sc_paddr + off));
! 221: }
CVSweb