Home | History | Annotate | Line # | Download | only in obio
sbc_obio.c revision 1.22
      1 /*	$NetBSD: sbc_obio.c,v 1.22 2006/03/29 04:16:45 thorpej 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. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: sbc_obio.c,v 1.22 2006/03/29 04:16:45 thorpej Exp $");
     31 
     32 #include <sys/types.h>
     33 #include <sys/param.h>
     34 #include <sys/systm.h>
     35 #include <sys/kernel.h>
     36 #include <sys/errno.h>
     37 #include <sys/device.h>
     38 #include <sys/buf.h>
     39 #include <sys/proc.h>
     40 #include <sys/user.h>
     41 
     42 #include <dev/scsipi/scsi_all.h>
     43 #include <dev/scsipi/scsipi_all.h>
     44 #include <dev/scsipi/scsipi_debug.h>
     45 #include <dev/scsipi/scsiconf.h>
     46 
     47 #include <dev/ic/ncr5380reg.h>
     48 #include <dev/ic/ncr5380var.h>
     49 
     50 #include <machine/cpu.h>
     51 #include <machine/bus.h>
     52 #include <machine/viareg.h>
     53 
     54 #include <mac68k/dev/sbcreg.h>
     55 #include <mac68k/dev/sbcvar.h>
     56 
     57 #include <mac68k/obio/obiovar.h>
     58 
     59 /*
     60  * From Guide to the Macintosh Family Hardware, pp. 137-143
     61  * These are offsets from SCSIBase (see pmap_bootstrap.c)
     62  */
     63 #define	SBC_REG_OFS		0x10000
     64 #define	SBC_DMA_OFS		0x12000
     65 #define	SBC_HSK_OFS		0x06000
     66 
     67 #define	SBC_DMA_OFS_PB500	0x06000
     68 
     69 #define	SBC_REG_OFS_IIFX	0x08000		/* Just guessing... */
     70 #define	SBC_DMA_OFS_IIFX	0x0c000
     71 #define	SBC_HSK_OFS_IIFX	0x0e000
     72 
     73 #define	SBC_REG_OFS_DUO2	0x00000
     74 #define	SBC_DMA_OFS_DUO2	0x02000
     75 #define	SBC_HSK_OFS_DUO2	0x04000
     76 
     77 static int	sbc_obio_match(struct device *, struct cfdata *, void *);
     78 static void	sbc_obio_attach(struct device *, struct device *, void *);
     79 
     80 void	sbc_intr_enable(struct ncr5380_softc *);
     81 void	sbc_intr_disable(struct ncr5380_softc *);
     82 void	sbc_obio_clrintr(struct ncr5380_softc *);
     83 
     84 CFATTACH_DECL(sbc_obio, sizeof(struct sbc_softc),
     85     sbc_obio_match, sbc_obio_attach, NULL, NULL);
     86 
     87 static int
     88 sbc_obio_match(struct device *parent, struct cfdata *cf, void *aux)
     89 {
     90 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
     91 
     92 	switch (current_mac_model->machineid) {
     93 	case MACH_MACIIFX:	/* Note: the IIfx isn't (yet) supported. */
     94 		if (oa->oa_addr == 0)
     95 			return 1;
     96 		break;
     97 
     98 	case MACH_MACPB210:
     99 	case MACH_MACPB230:
    100 	case MACH_MACPB250:
    101 	case MACH_MACPB270:
    102 	case MACH_MACPB280:
    103 	case MACH_MACPB280C:
    104 		if (oa->oa_addr == 1)
    105 			return 1;
    106 		/*FALLTHROUGH*/
    107 	default:
    108 		if (oa->oa_addr == 0 && mac68k_machine.scsi80)
    109 			return 1;
    110 	}
    111 	return 0;
    112 }
    113 
    114 static void
    115 sbc_obio_attach(struct device *parent, struct device *self, void *aux)
    116 {
    117 	struct sbc_softc *sc = (struct sbc_softc *) self;
    118 	struct ncr5380_softc *ncr_sc = (struct ncr5380_softc *) sc;
    119 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    120 	char bits[64];
    121 	extern vaddr_t SCSIBase;
    122 
    123 	/* Pull in the options flags. */
    124 	sc->sc_options = ((device_cfdata(&ncr_sc->sc_dev)->cf_flags |
    125 			   sbc_options) & 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 (oa->oa_addr == 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 	 * Initialize fields used by the MI code
    166 	 */
    167 	ncr_sc->sci_r0 = &sc->sc_regs->sci_pr0.sci_reg;
    168 	ncr_sc->sci_r1 = &sc->sc_regs->sci_pr1.sci_reg;
    169 	ncr_sc->sci_r2 = &sc->sc_regs->sci_pr2.sci_reg;
    170 	ncr_sc->sci_r3 = &sc->sc_regs->sci_pr3.sci_reg;
    171 	ncr_sc->sci_r4 = &sc->sc_regs->sci_pr4.sci_reg;
    172 	ncr_sc->sci_r5 = &sc->sc_regs->sci_pr5.sci_reg;
    173 	ncr_sc->sci_r6 = &sc->sc_regs->sci_pr6.sci_reg;
    174 	ncr_sc->sci_r7 = &sc->sc_regs->sci_pr7.sci_reg;
    175 
    176 	ncr_sc->sc_rev = NCR_VARIANT_NCR5380;
    177 
    178 	/*
    179 	 * MD function pointers used by the MI code.
    180 	 */
    181 	if (sc->sc_options & SBC_PDMA) {
    182 		ncr_sc->sc_pio_out   = sbc_pdma_out;
    183 		ncr_sc->sc_pio_in    = sbc_pdma_in;
    184 	} else {
    185 		ncr_sc->sc_pio_out   = ncr5380_pio_out;
    186 		ncr_sc->sc_pio_in    = ncr5380_pio_in;
    187 	}
    188 	ncr_sc->sc_dma_alloc = NULL;
    189 	ncr_sc->sc_dma_free  = NULL;
    190 	ncr_sc->sc_dma_poll  = NULL;
    191 	ncr_sc->sc_intr_on   = NULL;
    192 	ncr_sc->sc_intr_off  = NULL;
    193 	ncr_sc->sc_dma_setup = NULL;
    194 	ncr_sc->sc_dma_start = NULL;
    195 	ncr_sc->sc_dma_eop   = NULL;
    196 	ncr_sc->sc_dma_stop  = NULL;
    197 	ncr_sc->sc_flags = 0;
    198 	ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
    199 
    200 	if (sc->sc_options & SBC_INTR) {
    201 		ncr_sc->sc_dma_alloc = sbc_dma_alloc;
    202 		ncr_sc->sc_dma_free  = sbc_dma_free;
    203 		ncr_sc->sc_dma_poll  = sbc_dma_poll;
    204 		ncr_sc->sc_dma_setup = sbc_dma_setup;
    205 		ncr_sc->sc_dma_start = sbc_dma_start;
    206 		ncr_sc->sc_dma_eop   = sbc_dma_eop;
    207 		ncr_sc->sc_dma_stop  = sbc_dma_stop;
    208 		via2_register_irq(VIA2_SCSIDRQ, sbc_drq_intr, ncr_sc);
    209 	}
    210 
    211 	via2_register_irq(VIA2_SCSIIRQ, sbc_irq_intr, ncr_sc);
    212 	sc->sc_clrintr = sbc_obio_clrintr;
    213 
    214 	if ((sc->sc_options & SBC_RESELECT) == 0)
    215 		ncr_sc->sc_no_disconnect = 0xff;
    216 
    217 	if (sc->sc_options)
    218 		printf(": options=%s", bitmask_snprintf(sc->sc_options,
    219 		    SBC_OPTIONS_BITS, bits, sizeof(bits)));
    220 	printf("\n");
    221 
    222 	if (sc->sc_options & (SBC_INTR|SBC_RESELECT)) {
    223 		/* Enable SCSI interrupts through VIA2 */
    224 		sbc_intr_enable(ncr_sc);
    225 	}
    226 
    227 #ifdef SBC_DEBUG
    228 	if (sbc_debug)
    229 		printf("%s: softc=%p regs=%p\n", ncr_sc->sc_dev.dv_xname,
    230 		    sc, sc->sc_regs);
    231 #endif
    232 
    233 	ncr_sc->sc_channel.chan_id = 7;
    234 	ncr_sc->sc_adapter.adapt_minphys = minphys;
    235 
    236 	/*
    237 	 *  Initialize the SCSI controller itself.
    238 	 */
    239 	ncr5380_attach(ncr_sc);
    240 }
    241 
    242 /*
    243  * Interrupt support routines.
    244  */
    245 void
    246 sbc_intr_enable(struct ncr5380_softc *ncr_sc)
    247 {
    248 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    249 	int s, flags;
    250 
    251 	flags = V2IF_SCSIIRQ;
    252 	if (sc->sc_options & SBC_INTR)
    253 		flags |= V2IF_SCSIDRQ;
    254 
    255 	s = splhigh();
    256 	if (VIA2 == VIA2OFF)
    257 		via2_reg(vIER) = 0x80 | flags;
    258 	else
    259 		via2_reg(rIER) = 0x80 | flags;
    260 	splx(s);
    261 }
    262 
    263 void
    264 sbc_intr_disable(struct ncr5380_softc *ncr_sc)
    265 {
    266 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    267 	int s, flags;
    268 
    269 	flags = V2IF_SCSIIRQ;
    270 	if (sc->sc_options & SBC_INTR)
    271 		flags |= V2IF_SCSIDRQ;
    272 
    273 	s = splhigh();
    274 	if (VIA2 == VIA2OFF)
    275 		via2_reg(vIER) = flags;
    276 	else
    277 		via2_reg(rIER) = flags;
    278 	splx(s);
    279 }
    280 
    281 void
    282 sbc_obio_clrintr(struct ncr5380_softc *ncr_sc)
    283 {
    284 	struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
    285 	int flags;
    286 
    287 	flags = V2IF_SCSIIRQ;
    288 	if (sc->sc_options & SBC_INTR)
    289 		flags |= V2IF_SCSIDRQ;
    290 
    291 	if (VIA2 == VIA2OFF)
    292 		via2_reg(vIFR) = 0x80 | flags;
    293 	else
    294 		via2_reg(rIFR) = 0x80 | flags;
    295 }
    296