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