Annotation of sys/arch/mac68k/dev/sbc_obio.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: sbc_obio.c,v 1.15 2006/12/13 21:12:56 miod Exp $ */
! 2: /* $NetBSD: sbc_obio.c,v 1.1 1997/03/01 20:18:59 scottr Exp $ */
! 3:
! 4: /*
! 5: * Copyright (C) 1996,1997 Scott Reynolds. 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: * 3. All advertising materials mentioning features or use of this software
! 16: * must display the following acknowledgement:
! 17: * This product includes software developed by Scott Reynolds for
! 18: * the NetBSD Project.
! 19: * 4. The name of the author may not be used to endorse or promote products
! 20: * derived from this software without specific prior written permission
! 21: *
! 22: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 23: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 24: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 25: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 26: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 27: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 28: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 29: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 30: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! 31: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 32: */
! 33:
! 34: #include <sys/types.h>
! 35: #include <sys/param.h>
! 36: #include <sys/systm.h>
! 37: #include <sys/kernel.h>
! 38: #include <sys/errno.h>
! 39: #include <sys/device.h>
! 40: #include <sys/buf.h>
! 41: #include <sys/proc.h>
! 42: #include <sys/user.h>
! 43:
! 44: #include <scsi/scsi_all.h>
! 45: #include <scsi/scsi_debug.h>
! 46: #include <scsi/scsiconf.h>
! 47:
! 48: #include <dev/ic/ncr5380reg.h>
! 49: #include <dev/ic/ncr5380var.h>
! 50:
! 51: #include <machine/cpu.h>
! 52: #include <machine/viareg.h>
! 53:
! 54: #include "sbcreg.h"
! 55: #include "sbcvar.h"
! 56:
! 57: /*
! 58: * From Guide to the Macintosh Family Hardware, pp. 137-143
! 59: * These are offsets from SCSIBase (see pmap_bootstrap.c)
! 60: */
! 61: #define SBC_REG_OFS 0x10000
! 62: #define SBC_DMA_OFS 0x12000
! 63: #define SBC_HSK_OFS 0x06000
! 64:
! 65: #define SBC_DMA_OFS_PB500 0x06000
! 66:
! 67: #define SBC_REG_OFS_IIFX 0x08000 /* Just guessing... */
! 68: #define SBC_DMA_OFS_IIFX 0x0c000
! 69: #define SBC_HSK_OFS_IIFX 0x0e000
! 70:
! 71: #define SBC_REG_OFS_DUO2 0x00000
! 72: #define SBC_DMA_OFS_DUO2 0x02000
! 73: #define SBC_HSK_OFS_DUO2 0x04000
! 74:
! 75: static int sbc_obio_match(struct device *, void *, void *);
! 76: static void sbc_obio_attach(struct device *, struct device *, void *);
! 77:
! 78: void sbc_intr_enable(struct ncr5380_softc *);
! 79: void sbc_intr_disable(struct ncr5380_softc *);
! 80: void sbc_obio_clrintr(struct ncr5380_softc *);
! 81:
! 82: struct cfattach sbc_obio_ca = {
! 83: sizeof(struct sbc_softc), sbc_obio_match, sbc_obio_attach
! 84: };
! 85:
! 86: static int
! 87: sbc_obio_match(parent, vcf, args)
! 88: struct device *parent;
! 89: void *vcf;
! 90: void *args;
! 91: {
! 92: struct cfdata *cf = (struct cfdata *) vcf;
! 93:
! 94: switch (current_mac_model->machineid) {
! 95: case MACH_MACIIFX: /* Note: the IIfx isn't (yet) supported. */
! 96: break;
! 97: case MACH_MACPB210:
! 98: case MACH_MACPB230:
! 99: case MACH_MACPB250:
! 100: case MACH_MACPB270:
! 101: case MACH_MACPB280:
! 102: case MACH_MACPB280C:
! 103: if (cf->cf_unit == 1)
! 104: return 1;
! 105: /*FALLTHROUGH*/
! 106: default:
! 107: if (cf->cf_unit == 0 && mac68k_machine.scsi80)
! 108: return 1;
! 109: }
! 110: return 0;
! 111: }
! 112:
! 113: static void
! 114: sbc_obio_attach(parent, self, args)
! 115: struct device *parent, *self;
! 116: void *args;
! 117: {
! 118: struct sbc_softc *sc = (struct sbc_softc *) self;
! 119: struct ncr5380_softc *ncr_sc = (struct ncr5380_softc *) sc;
! 120: struct scsibus_attach_args saa;
! 121: extern vaddr_t SCSIBase;
! 122:
! 123: /* Pull in the options flags. */
! 124: sc->sc_options = ((ncr_sc->sc_dev.dv_cfdata->cf_flags | sbc_options)
! 125: & SBC_OPTIONS_MASK);
! 126:
! 127: /*
! 128: * Set up offsets to 5380 registers and GLUE I/O space, and turn
! 129: * off options we know we can't support on certain models.
! 130: */
! 131: switch (current_mac_model->machineid) {
! 132: case MACH_MACIIFX: /* Note: the IIfx isn't (yet) supported. */
! 133: sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS_IIFX);
! 134: sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS_IIFX);
! 135: sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS_IIFX);
! 136: sc->sc_options &= ~(SBC_INTR | SBC_RESELECT);
! 137: break;
! 138: case MACH_MACPB500:
! 139: sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS);
! 140: sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS); /*??*/
! 141: sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS_PB500);
! 142: sc->sc_options &= ~(SBC_INTR | SBC_RESELECT);
! 143: break;
! 144: case MACH_MACPB210:
! 145: case MACH_MACPB230:
! 146: case MACH_MACPB250:
! 147: case MACH_MACPB270:
! 148: case MACH_MACPB280:
! 149: case MACH_MACPB280C:
! 150: if (ncr_sc->sc_dev.dv_unit == 1) {
! 151: sc->sc_regs = (struct sbc_regs *)(0xfee00000 + SBC_REG_OFS_DUO2);
! 152: sc->sc_drq_addr = (vaddr_t)(0xfee00000 + SBC_HSK_OFS_DUO2);
! 153: sc->sc_nodrq_addr = (vaddr_t)(0xfee00000 + SBC_DMA_OFS_DUO2);
! 154: break;
! 155: }
! 156: /*FALLTHROUGH*/
! 157: default:
! 158: sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS);
! 159: sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS);
! 160: sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS);
! 161: break;
! 162: }
! 163:
! 164: /*
! 165: * Fill in the prototype scsi_link.
! 166: */
! 167: ncr_sc->sc_link.adapter_softc = sc;
! 168: ncr_sc->sc_link.adapter_target = 7;
! 169: ncr_sc->sc_link.adapter = &sbc_ops;
! 170: ncr_sc->sc_link.device = &sbc_dev;
! 171: ncr_sc->sc_link.openings = 4;
! 172:
! 173: /*
! 174: * Initialize fields used by the MI code
! 175: */
! 176: ncr_sc->sci_r0 = &sc->sc_regs->sci_pr0.sci_reg;
! 177: ncr_sc->sci_r1 = &sc->sc_regs->sci_pr1.sci_reg;
! 178: ncr_sc->sci_r2 = &sc->sc_regs->sci_pr2.sci_reg;
! 179: ncr_sc->sci_r3 = &sc->sc_regs->sci_pr3.sci_reg;
! 180: ncr_sc->sci_r4 = &sc->sc_regs->sci_pr4.sci_reg;
! 181: ncr_sc->sci_r5 = &sc->sc_regs->sci_pr5.sci_reg;
! 182: ncr_sc->sci_r6 = &sc->sc_regs->sci_pr6.sci_reg;
! 183: ncr_sc->sci_r7 = &sc->sc_regs->sci_pr7.sci_reg;
! 184:
! 185: /*
! 186: * MD function pointers used by the MI code.
! 187: */
! 188: if (sc->sc_options & SBC_PDMA) {
! 189: ncr_sc->sc_pio_out = sbc_pdma_out;
! 190: ncr_sc->sc_pio_in = sbc_pdma_in;
! 191: } else {
! 192: ncr_sc->sc_pio_out = ncr5380_pio_out;
! 193: ncr_sc->sc_pio_in = ncr5380_pio_in;
! 194: }
! 195: ncr_sc->sc_dma_alloc = NULL;
! 196: ncr_sc->sc_dma_free = NULL;
! 197: ncr_sc->sc_dma_poll = NULL;
! 198: ncr_sc->sc_intr_on = NULL;
! 199: ncr_sc->sc_intr_off = NULL;
! 200: ncr_sc->sc_dma_setup = NULL;
! 201: ncr_sc->sc_dma_start = NULL;
! 202: ncr_sc->sc_dma_stop = NULL;
! 203: ncr_sc->sc_flags = 0;
! 204: ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
! 205:
! 206: if (sc->sc_options & SBC_INTR) {
! 207: ncr_sc->sc_dma_alloc = sbc_dma_alloc;
! 208: ncr_sc->sc_dma_free = sbc_dma_free;
! 209: ncr_sc->sc_dma_poll = sbc_dma_poll;
! 210: ncr_sc->sc_dma_setup = sbc_dma_setup;
! 211: ncr_sc->sc_dma_start = sbc_dma_start;
! 212: ncr_sc->sc_dma_stop = sbc_dma_stop;
! 213:
! 214: sc->sc_ih_drq.vh_fn = sbc_drq_intr;
! 215: sc->sc_ih_drq.vh_arg = ncr_sc;
! 216: sc->sc_ih_drq.vh_ipl = VIA2_SCSIDRQ;
! 217: via2_register_irq(&sc->sc_ih_drq, ncr_sc->sc_dev.dv_xname);
! 218: }
! 219:
! 220: sc->sc_ih_irq.vh_fn = sbc_irq_intr;
! 221: sc->sc_ih_irq.vh_arg = ncr_sc;
! 222: sc->sc_ih_irq.vh_ipl = VIA2_SCSIIRQ;
! 223: via2_register_irq(&sc->sc_ih_irq, ncr_sc->sc_dev.dv_xname);
! 224: sc->sc_clrintr = sbc_obio_clrintr;
! 225:
! 226: if (sc->sc_options)
! 227: printf(": options=0x%x", sc->sc_options);
! 228: printf("\n");
! 229:
! 230: /* Enable SCSI interrupts through VIA2 */
! 231: sbc_intr_enable(ncr_sc);
! 232:
! 233: #ifdef SBC_DEBUG
! 234: if (sbc_debug)
! 235: printf("%s: softc=%p regs=%p\n", ncr_sc->sc_dev.dv_xname,
! 236: sc, sc->sc_regs);
! 237: ncr_sc->sc_link.flags |= sbc_link_flags;
! 238: #endif
! 239:
! 240: bzero(&saa, sizeof(saa));
! 241: saa.saa_sc_link = &(ncr_sc->sc_link);
! 242:
! 243: /*
! 244: * Initialize the SCSI controller itself.
! 245: */
! 246: ncr5380_init(ncr_sc);
! 247: ncr5380_reset_scsibus(ncr_sc);
! 248: config_found(self, &saa, scsiprint);
! 249: }
! 250:
! 251: /*
! 252: * Interrupt support routines.
! 253: */
! 254: void
! 255: sbc_intr_enable(ncr_sc)
! 256: struct ncr5380_softc *ncr_sc;
! 257: {
! 258: struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
! 259: int s, flags;
! 260:
! 261: flags = V2IF_SCSIIRQ;
! 262: if (sc->sc_options & SBC_INTR)
! 263: flags |= V2IF_SCSIDRQ;
! 264:
! 265: s = splhigh();
! 266: if (VIA2 == VIA2OFF)
! 267: via2_reg(vIER) = 0x80 | flags;
! 268: else
! 269: via2_reg(rIER) = 0x80 | flags;
! 270: splx(s);
! 271: }
! 272:
! 273: void
! 274: sbc_intr_disable(ncr_sc)
! 275: struct ncr5380_softc *ncr_sc;
! 276: {
! 277: struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
! 278: int s, flags;
! 279:
! 280: flags = V2IF_SCSIIRQ;
! 281: if (sc->sc_options & SBC_INTR)
! 282: flags |= V2IF_SCSIDRQ;
! 283:
! 284: s = splhigh();
! 285: if (VIA2 == VIA2OFF)
! 286: via2_reg(vIER) = flags;
! 287: else
! 288: via2_reg(rIER) = flags;
! 289: splx(s);
! 290: }
! 291:
! 292: void
! 293: sbc_obio_clrintr(ncr_sc)
! 294: struct ncr5380_softc *ncr_sc;
! 295: {
! 296: struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
! 297: int flags;
! 298:
! 299: flags = V2IF_SCSIIRQ;
! 300: if (sc->sc_options & SBC_INTR)
! 301: flags |= V2IF_SCSIDRQ;
! 302:
! 303: if (VIA2 == VIA2OFF)
! 304: via2_reg(vIFR) = 0x80 | flags;
! 305: else
! 306: via2_reg(rIFR) = 0x80 | flags;
! 307: }
CVSweb