Annotation of sys/arch/sparc/dev/flash.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: flash.c,v 1.5 2006/03/15 20:03:06 miod Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 1999 Jason L. Wright (jason@thought.net)
! 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
! 18: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
! 19: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
! 20: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! 21: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
! 22: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 23: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! 24: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! 25: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 26: * POSSIBILITY OF SUCH DAMAGE.
! 27: */
! 28:
! 29: /*
! 30: * Driver for the flash memory found on FORCE CPU-5V boards.
! 31: */
! 32:
! 33: #include <sys/param.h>
! 34: #include <sys/systm.h>
! 35: #include <sys/kernel.h>
! 36: #include <sys/errno.h>
! 37: #include <sys/ioctl.h>
! 38: #include <sys/syslog.h>
! 39: #include <sys/device.h>
! 40: #include <sys/malloc.h>
! 41:
! 42: #include <machine/autoconf.h>
! 43: #include <sparc/cpu.h>
! 44: #include <sparc/sparc/cpuvar.h>
! 45:
! 46: int flashmatch(struct device *, void *, void *);
! 47: void flashattach(struct device *, struct device *, void *);
! 48:
! 49: int flashopen(dev_t, int, int, struct proc *p);
! 50: int flashclose(dev_t, int, int, struct proc *p);
! 51: int flashread(dev_t, struct uio *, int);
! 52: int flashwrite(dev_t, struct uio *, int);
! 53: int flashrw(dev_t, struct uio *, int);
! 54: int flashioctl(dev_t, u_long, caddr_t, int, struct proc *);
! 55:
! 56: /*
! 57: * We see the flash-memory in 512k windows. The current window is
! 58: * changed in the sysconfig registers (FMPCR1), see scf.c.
! 59: */
! 60: #define FLASH_REGS_SIZE 0x80000
! 61:
! 62: struct flash_regs {
! 63: u_int8_t regs[0x80000];
! 64: };
! 65:
! 66: struct flash_softc {
! 67: struct device sc_dv;
! 68: struct flash_regs *sc_regs;
! 69: int sc_node;
! 70: int sc_open;
! 71: };
! 72:
! 73: struct cfattach flash_ca = {
! 74: sizeof (struct flash_softc), flashmatch, flashattach
! 75: };
! 76:
! 77: struct cfdriver flash_cd = {
! 78: NULL, "flash", DV_DULL
! 79: };
! 80:
! 81: int
! 82: flashmatch(parent, vcf, aux)
! 83: struct device *parent;
! 84: void *vcf, *aux;
! 85: {
! 86: struct confargs *ca = aux;
! 87: register struct romaux *ra = &ca->ca_ra;
! 88:
! 89: if (strcmp("flash-memory", ra->ra_name))
! 90: return (0);
! 91: return (1);
! 92: }
! 93:
! 94: void
! 95: flashattach(parent, self, aux)
! 96: struct device *parent, *self;
! 97: void *aux;
! 98: {
! 99: struct confargs *ca = aux;
! 100: struct flash_softc *sc = (struct flash_softc *)self;
! 101:
! 102: /* map registers */
! 103: if (ca->ca_ra.ra_nreg != 1) {
! 104: printf(": expected 1 register, got %d\n", ca->ca_ra.ra_nreg);
! 105: return;
! 106: }
! 107: sc->sc_regs = mapiodev(&(ca->ca_ra.ra_reg[0]), 0,
! 108: ca->ca_ra.ra_reg[0].rr_len);
! 109:
! 110: sc->sc_node = ca->ca_ra.ra_node;
! 111:
! 112: printf(": window 0x%x\n", ca->ca_ra.ra_reg[0].rr_len);
! 113: }
! 114:
! 115: int
! 116: flashopen(dev, flags, mode, p)
! 117: dev_t dev;
! 118: int flags;
! 119: int mode;
! 120: struct proc *p;
! 121: {
! 122: struct flash_softc *sc;
! 123: int card = 0;
! 124:
! 125: if (card >= flash_cd.cd_ndevs)
! 126: return (ENXIO);
! 127: sc = flash_cd.cd_devs[card];
! 128: if (sc == NULL)
! 129: return (ENXIO);
! 130: if (sc->sc_open)
! 131: return (EBUSY);
! 132: sc->sc_open = 1;
! 133: return (0);
! 134: }
! 135:
! 136: int
! 137: flashclose(dev, flags, mode, p)
! 138: dev_t dev;
! 139: int flags;
! 140: int mode;
! 141: struct proc *p;
! 142: {
! 143: struct flash_softc *sc = flash_cd.cd_devs[0];
! 144: sc->sc_open = 0;
! 145: return (0);
! 146: }
! 147:
! 148: int
! 149: flashwrite(dev, uio, flags)
! 150: dev_t dev;
! 151: struct uio *uio;
! 152: int flags;
! 153: {
! 154: return (flashrw(dev, uio, flags));
! 155: }
! 156:
! 157: int
! 158: flashread(dev, uio, flags)
! 159: dev_t dev;
! 160: struct uio *uio;
! 161: int flags;
! 162: {
! 163: return (flashrw(dev, uio, flags));
! 164: }
! 165:
! 166: int
! 167: flashrw(dev, uio, flags)
! 168: dev_t dev;
! 169: struct uio *uio;
! 170: int flags;
! 171: {
! 172: struct flash_softc *sc = flash_cd.cd_devs[0];
! 173: u_int cnt;
! 174: int off;
! 175:
! 176: off = uio->uio_offset;
! 177: if (off >= FLASH_REGS_SIZE)
! 178: return (EFAULT);
! 179:
! 180: cnt = uio->uio_resid;
! 181: if (cnt > (FLASH_REGS_SIZE - off))
! 182: cnt = FLASH_REGS_SIZE - off;
! 183:
! 184: return (uiomove(&sc->sc_regs->regs[0] + off, cnt, uio));
! 185: }
! 186:
! 187: int
! 188: flashioctl(dev, cmd, data, flags, p)
! 189: dev_t dev;
! 190: u_long cmd;
! 191: caddr_t data;
! 192: int flags;
! 193: struct proc *p;
! 194: {
! 195: return (EINVAL);
! 196: }
CVSweb