Home | History | Annotate | Line # | Download | only in dev
afsc.c revision 1.44
      1 /*	$NetBSD: afsc.c,v 1.44 2012/10/27 17:17:26 chs Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1982, 1990 The Regents of the University of California.
      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  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)dma.c
     32  */
     33 
     34 /*
     35  * Copyright (c) 1994 Michael L. Hitch
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  *
     46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     51  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     52  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     53  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     54  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     55  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     56  *
     57  *	@(#)dma.c
     58  */
     59 
     60 #include <sys/cdefs.h>
     61 __KERNEL_RCSID(0, "$NetBSD: afsc.c,v 1.44 2012/10/27 17:17:26 chs Exp $");
     62 
     63 #include <sys/param.h>
     64 #include <sys/systm.h>
     65 #include <sys/kernel.h>
     66 #include <sys/device.h>
     67 
     68 #include <dev/scsipi/scsi_all.h>
     69 #include <dev/scsipi/scsipi_all.h>
     70 #include <dev/scsipi/scsiconf.h>
     71 #include <machine/cpu.h>
     72 #include <amiga/amiga/custom.h>
     73 #include <amiga/amiga/cc.h>
     74 #include <amiga/amiga/device.h>
     75 #include <amiga/amiga/isr.h>
     76 #include <amiga/dev/siopreg.h>
     77 #include <amiga/dev/siopvar.h>
     78 #include <amiga/dev/zbusvar.h>
     79 
     80 #ifdef __powerpc__
     81 #define badaddr(a)      badaddr_read(a, 2, NULL)
     82 #endif
     83 
     84 void afscattach(device_t, device_t, void *);
     85 int afscmatch(device_t, cfdata_t, void *);
     86 int afsc_dmaintr(void *);
     87 #ifdef DEBUG
     88 void afsc_dump(void);
     89 #endif
     90 
     91 
     92 #ifdef DEBUG
     93 #endif
     94 
     95 CFATTACH_DECL_NEW(afsc, sizeof(struct siop_softc),
     96     afscmatch, afscattach, NULL, NULL);
     97 
     98 CFATTACH_DECL_NEW(aftsc, sizeof(struct siop_softc),
     99     afscmatch, afscattach, NULL, NULL);
    100 
    101 /*
    102  * if we are a Commodore Amiga A4091 or possibly an A4000T
    103  */
    104 int
    105 afscmatch(device_t parent, cfdata_t cf, void *aux)
    106 {
    107 	struct zbus_args *zap;
    108 	siop_regmap_p rp;
    109 	u_long temp, scratch;
    110 
    111 	zap = aux;
    112 	if (zap->manid == 514 && zap->prodid == 84)
    113 		return(1);		/* It's an A4091 SCSI card */
    114 	if (!is_a4000() || !matchname("afsc", aux))
    115 		return(0);		/* Not on an A4000 or not A4000T SCSI */
    116 	rp = ztwomap(0xdd0040);
    117 	if (badaddr((void *)__UNVOLATILE(&rp->siop_scratch)) ||
    118 	    badaddr((void *)__UNVOLATILE(&rp->siop_temp))) {
    119 		return(0);
    120 	}
    121 	scratch = rp->siop_scratch;
    122 	temp = rp->siop_temp;
    123 	rp->siop_scratch = 0xdeadbeef;
    124 	rp->siop_temp = 0xaaaa5555;
    125 	if (rp->siop_scratch != 0xdeadbeef || rp->siop_temp != 0xaaaa5555)
    126 		return(0);
    127 	rp->siop_scratch = scratch;
    128 	rp->siop_temp = temp;
    129 	if (rp->siop_scratch != scratch || rp->siop_temp != temp)
    130 		return(0);
    131 	return(1);
    132 }
    133 
    134 void
    135 afscattach(device_t parent, device_t self, void *aux)
    136 {
    137 	struct siop_softc *sc = device_private(self);
    138 	struct zbus_args *zap;
    139 	siop_regmap_p rp;
    140 	struct scsipi_adapter *adapt = &sc->sc_adapter;
    141 	struct scsipi_channel *chan = &sc->sc_channel;
    142 
    143 	printf("\n");
    144 
    145 	sc->sc_dev = self;
    146 	zap = aux;
    147 
    148 	if (zap->manid == 514 && zap->prodid == 84)
    149 		sc->sc_siopp = rp = (siop_regmap_p)((char *)zap->va +
    150 						    0x00800000);
    151 	else
    152 		sc->sc_siopp = rp = ztwomap(0xdd0040);
    153 
    154 	/*
    155 	 * CTEST7 = 80 [disable burst]
    156 	 */
    157 	sc->sc_clock_freq = 50;		/* Clock = 50 MHz */
    158 	sc->sc_ctest7 = SIOP_CTEST7_CDIS;
    159 	sc->sc_dcntl = SIOP_DCNTL_EA;
    160 
    161 	/*
    162 	 * Fill in the scsipi_adapter.
    163 	 */
    164 	memset(adapt, 0, sizeof(*adapt));
    165 	adapt->adapt_dev = self;
    166 	adapt->adapt_nchannels = 1;
    167 	adapt->adapt_openings = 7;
    168 	adapt->adapt_max_periph = 1;
    169 	adapt->adapt_request = siop_scsipi_request;
    170 	adapt->adapt_minphys = siop_minphys;
    171 
    172 	/*
    173 	 * Fill in the scsipi_channel.
    174 	 */
    175 	memset(chan, 0, sizeof(*chan));
    176 	chan->chan_adapter = adapt;
    177 	chan->chan_bustype = &scsi_bustype;
    178 	chan->chan_channel = 0;
    179 	chan->chan_ntargets = 8;
    180 	chan->chan_nluns = 8;
    181 	chan->chan_id = 7;
    182 
    183 	siopinitialize(sc);
    184 
    185 	sc->sc_isr.isr_intr = afsc_dmaintr;
    186 	sc->sc_isr.isr_arg = sc;
    187 	sc->sc_isr.isr_ipl = 2;
    188 	add_isr (&sc->sc_isr);
    189 
    190 	/*
    191 	 * attach all scsi units on us
    192 	 */
    193 	config_found(self, chan, scsiprint);
    194 }
    195 
    196 int
    197 afsc_dmaintr(void *arg)
    198 {
    199 	struct siop_softc *sc = arg;
    200 	siop_regmap_p rp;
    201 	u_char istat;
    202 
    203 	if (sc->sc_flags & SIOP_INTSOFF)
    204 		return (0);	/* interrupts are not active */
    205 	rp = sc->sc_siopp;
    206 	istat = rp->siop_istat;
    207 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
    208 		return(0);
    209 	/*
    210 	 * save interrupt status, DMA status, and SCSI status 0
    211 	 * (may need to deal with stacked interrupts?)
    212 	 */
    213 	sc->sc_sstat0 = rp->siop_sstat0;
    214 	sc->sc_istat = istat;
    215 	sc->sc_dstat = rp->siop_dstat;
    216 	siopintr(sc);
    217 	return(1);
    218 }
    219 
    220 #ifdef DEBUG
    221 void
    222 afsc_dump(void)
    223 {
    224 	extern struct cfdriver afsc_cd;
    225 	struct siop_softc *sc;
    226 	int i;
    227 
    228 	for (i = 0; i < afsc_cd.cd_ndevs; ++i) {
    229 		sc = device_lookup_private(&afsc_cd, i);
    230 		if (sc != NULL)
    231 			siop_dump(sc);
    232 	}
    233 }
    234 #endif
    235