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