Annotation of sys/arch/mvme68k/dev/mc.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: mc.c,v 1.17 2005/11/24 22:43:16 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: /*
! 29: * VME162/VME172 MCchip
! 30: */
! 31: #include <sys/param.h>
! 32: #include <sys/conf.h>
! 33: #include <sys/ioctl.h>
! 34: #include <sys/proc.h>
! 35: #include <sys/user.h>
! 36: #include <sys/tty.h>
! 37: #include <sys/uio.h>
! 38: #include <sys/systm.h>
! 39: #include <sys/kernel.h>
! 40: #include <sys/syslog.h>
! 41: #include <sys/fcntl.h>
! 42: #include <sys/device.h>
! 43: #include <machine/cpu.h>
! 44: #include <machine/autoconf.h>
! 45: #include <dev/cons.h>
! 46:
! 47: #include <mvme68k/dev/mcreg.h>
! 48:
! 49: struct mcsoftc {
! 50: struct device sc_dev;
! 51: vaddr_t sc_vaddr;
! 52: paddr_t sc_paddr;
! 53: struct mcreg *sc_mc;
! 54: struct intrhand sc_nmiih;
! 55: };
! 56:
! 57: void mcattach(struct device *, struct device *, void *);
! 58: int mcmatch(struct device *, void *, void *);
! 59: int mcabort(void *);
! 60: int mc_print(void *, const char *);
! 61: int mc_scan(struct device *, void *, void *);
! 62:
! 63: struct cfattach mc_ca = {
! 64: sizeof(struct mcsoftc), mcmatch, mcattach
! 65: };
! 66:
! 67: struct cfdriver mc_cd = {
! 68: NULL, "mc", DV_DULL
! 69: };
! 70:
! 71: struct mcreg *sys_mc = NULL;
! 72:
! 73: int
! 74: mcmatch(parent, vcf, args)
! 75: struct device *parent;
! 76: void *vcf, *args;
! 77: {
! 78: struct confargs *ca = args;
! 79: struct mcreg *mc = (struct mcreg *)(IIOV(ca->ca_paddr) + MC_MCCHIP_OFF);
! 80:
! 81: if ((cputyp != CPU_172 && cputyp != CPU_162) ||
! 82: badvaddr((vaddr_t)mc, 1) || mc->mc_chipid != MC_CHIPID)
! 83: return (0);
! 84: return (1);
! 85: }
! 86:
! 87: int
! 88: mc_print(args, bus)
! 89: void *args;
! 90: const char *bus;
! 91: {
! 92: struct confargs *ca = args;
! 93:
! 94: if (ca->ca_offset != -1)
! 95: printf(" offset 0x%x", ca->ca_offset);
! 96: if (ca->ca_ipl > 0)
! 97: printf(" ipl %d", ca->ca_ipl);
! 98: return (UNCONF);
! 99: }
! 100:
! 101: int
! 102: mc_scan(parent, child, args)
! 103: struct device *parent;
! 104: void *child, *args;
! 105: {
! 106: struct cfdata *cf = child;
! 107: struct mcsoftc *sc = (struct mcsoftc *)parent;
! 108: struct confargs oca;
! 109:
! 110: bzero(&oca, sizeof oca);
! 111: oca.ca_offset = cf->cf_loc[0];
! 112: oca.ca_ipl = cf->cf_loc[1];
! 113: if (oca.ca_offset != -1 && ISIIOVA(sc->sc_vaddr + oca.ca_offset)) {
! 114: oca.ca_vaddr = sc->sc_vaddr + oca.ca_offset;
! 115: oca.ca_paddr = sc->sc_paddr + oca.ca_offset;
! 116: } else {
! 117: oca.ca_vaddr = (vaddr_t)-1;
! 118: oca.ca_paddr = (paddr_t)-1;
! 119: }
! 120: oca.ca_bustype = BUS_MC;
! 121: oca.ca_name = cf->cf_driver->cd_name;
! 122: if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
! 123: return (0);
! 124: config_attach(parent, cf, &oca, mc_print);
! 125: return (1);
! 126: }
! 127:
! 128: void
! 129: mcattach(parent, self, args)
! 130: struct device *parent, *self;
! 131: void *args;
! 132: {
! 133: struct confargs *ca = args;
! 134: struct mcsoftc *sc = (struct mcsoftc *)self;
! 135:
! 136: if (sys_mc)
! 137: panic("mc already attached!");
! 138:
! 139: /*
! 140: * since we know ourself to land in intiobase land,
! 141: * we must adjust our address
! 142: */
! 143: sc->sc_paddr = ca->ca_paddr;
! 144: sc->sc_vaddr = IIOV(sc->sc_paddr);
! 145: sc->sc_mc = (struct mcreg *)(sc->sc_vaddr + MC_MCCHIP_OFF);
! 146: sys_mc = sc->sc_mc;
! 147:
! 148: printf(": rev %d\n", sc->sc_mc->mc_chiprev);
! 149:
! 150: sc->sc_nmiih.ih_fn = mcabort;
! 151: sc->sc_nmiih.ih_ipl = 7;
! 152: sc->sc_nmiih.ih_wantframe = 1;
! 153: mcintr_establish(MCV_ABORT, &sc->sc_nmiih, self->dv_xname);
! 154:
! 155: sc->sc_mc->mc_abortirq = 7 | MC_IRQ_IEN | MC_IRQ_ICLR;
! 156: sc->sc_mc->mc_vecbase = MC_VECBASE;
! 157:
! 158: sc->sc_mc->mc_genctl |= MC_GENCTL_IEN; /* global irq enable */
! 159:
! 160: config_search(mc_scan, self, args);
! 161: }
! 162:
! 163: /*
! 164: * MC interrupts land in a MC_NVEC sized hole starting at MC_VECBASE
! 165: */
! 166: int
! 167: mcintr_establish(vec, ih, name)
! 168: int vec;
! 169: struct intrhand *ih;
! 170: const char *name;
! 171: {
! 172: #ifdef DIAGNOSTIC
! 173: if (vec < 0 || vec >= MC_NVEC)
! 174: panic("mcintr_establish: illegal vector for %s: 0x%x",
! 175: name, vec);
! 176: #endif
! 177:
! 178: return intr_establish(MC_VECBASE + vec, ih, name);
! 179: }
! 180:
! 181: int
! 182: mcabort(frame)
! 183: void *frame;
! 184: {
! 185: /* wait for it to debounce */
! 186: while (sys_mc->mc_abortirq & MC_ABORT_ABS)
! 187: ;
! 188:
! 189: sys_mc->mc_abortirq = sys_mc->mc_abortirq | MC_IRQ_ICLR;
! 190:
! 191: nmihand(frame);
! 192: return (1);
! 193: }
! 194:
! 195: #include "flash.h"
! 196:
! 197: #if NFLASH > 0
! 198: void
! 199: mc_enableflashwrite(on)
! 200: int on;
! 201: {
! 202: struct mcsoftc *sc = (struct mcsoftc *) mc_cd.cd_devs[0];
! 203: volatile u_char *ena, x;
! 204: /*
! 205: * Check MC chip revision, as the way to enable flash writes
! 206: * has been changed from a memory location in BBRAM to a
! 207: * bit in the Flash Control Reg. XXX - smurph
! 208: */
! 209: if (sc->sc_mc->mc_chiprev == 0x01) {
! 210: if (on)
! 211: sc->sc_mc->mc_flashctl |= MC_FLASHCTL_WRITE;
! 212: else
! 213: sc->sc_mc->mc_flashctl &= ~MC_FLASHCTL_WRITE;
! 214: } else {
! 215: ena = (u_char *)sc->sc_vaddr +
! 216: (on ? MC_ENAFLASHWRITE_OFFSET : MC_DISFLASHWRITE_OFFSET);
! 217: x = *ena;
! 218: }
! 219: }
! 220: /*
! 221: * Function to check if we booted from flash or prom.
! 222: * If we booted from PROM, flash mem is available.
! 223: */
! 224: int
! 225: mc_hasflash(void)
! 226: {
! 227: struct mcsoftc *sc = (struct mcsoftc *) mc_cd.cd_devs[0];
! 228: if (sc->sc_mc->mc_input & MC_INPUT_PROM)
! 229: return 1;
! 230: else
! 231: return 0;
! 232: }
! 233: #endif
CVSweb