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