Home | History | Annotate | Line # | Download | only in dev
cbiiisc.c revision 1.15.64.1
      1 /*	$NetBSD: cbiiisc.c,v 1.15.64.1 2008/06/29 09:32:53 mjf 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,1998 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: cbiiisc.c,v 1.15.64.1 2008/06/29 09:32:53 mjf 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 <uvm/uvm_extern.h>
     69 
     70 #include <dev/scsipi/scsi_all.h>
     71 #include <dev/scsipi/scsipi_all.h>
     72 #include <dev/scsipi/scsiconf.h>
     73 #include <amiga/amiga/custom.h>
     74 #include <amiga/amiga/cc.h>
     75 #include <amiga/amiga/device.h>
     76 #include <amiga/amiga/isr.h>
     77 
     78 #define ARCH_720			/* This is for a 53c770 */
     79 
     80 #include <amiga/dev/siopreg.h>
     81 #include <amiga/dev/siopvar.h>
     82 #include <amiga/dev/zbusvar.h>
     83 
     84 void cbiiiscattach(struct device *, struct device *, void *);
     85 int  cbiiiscmatch(struct device *, struct cfdata *, void *);
     86 int  cbiiisc_dmaintr(void *);
     87 #ifdef DEBUG
     88 void cbiiisc_dump(void);
     89 #endif
     90 
     91 #ifdef DEBUG
     92 #endif
     93 
     94 CFATTACH_DECL(cbiiisc, sizeof(struct siop_softc),
     95     cbiiiscmatch, cbiiiscattach, NULL, NULL);
     96 
     97 /*
     98  * if we are a CyberStorm MK III SCSI
     99  */
    100 int
    101 cbiiiscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
    102 {
    103 	struct zbus_args *zap;
    104 
    105 	zap = auxp;
    106 	if (zap->manid == 8512 && zap->prodid == 100)
    107 		return(1);
    108 	return(0);
    109 }
    110 
    111 void
    112 cbiiiscattach(struct device *pdp, struct device *dp, void *auxp)
    113 {
    114 	struct siop_softc *sc = (struct siop_softc *)dp;
    115 	struct zbus_args *zap;
    116 	siop_regmap_p rp;
    117         struct scsipi_adapter *adapt = &sc->sc_adapter;
    118         struct scsipi_channel *chan = &sc->sc_channel;
    119 
    120 	printf("\n");
    121 
    122 	zap = auxp;
    123 
    124 	sc->sc_siopp = rp = ztwomap(0xf40000);
    125 	/* siopng_dump_registers(sc); */
    126 
    127 	/*
    128 	 * CTEST7 = 00
    129 	 */
    130 	sc->sc_clock_freq = 50;		/* Clock = 50 MHz >> */
    131 	sc->sc_ctest7 = 0x00;
    132 	sc->sc_dcntl = 0x20;		/* XXX ?? */
    133 
    134 	alloc_sicallback();
    135 
    136         /*
    137          * Fill in the scsipi_adapter.
    138          */
    139         memset(adapt, 0, sizeof(*adapt));
    140         adapt->adapt_dev = &sc->sc_dev;
    141         adapt->adapt_nchannels = 1;
    142         adapt->adapt_openings = 7;
    143         adapt->adapt_max_periph = 1;
    144         adapt->adapt_request = siopng_scsipi_request;
    145         adapt->adapt_minphys = siopng_minphys;
    146 
    147         /*
    148          * Fill in the scsipi_channel.
    149          */
    150         memset(chan, 0, sizeof(*chan));
    151         chan->chan_adapter = adapt;
    152         chan->chan_bustype = &scsi_bustype;
    153         chan->chan_channel = 0;
    154         chan->chan_ntargets = 16;
    155         chan->chan_nluns = 8;
    156         chan->chan_id = 7;
    157 
    158 	siopnginitialize(sc);
    159 
    160 	if (sc->sc_channel.chan_ntargets < 0)
    161 		return;
    162 
    163 	sc->sc_isr.isr_intr = cbiiisc_dmaintr;
    164 	sc->sc_isr.isr_arg = sc;
    165 	sc->sc_isr.isr_ipl = 2;		/* ?? */
    166 	add_isr(&sc->sc_isr);
    167 
    168 	/*
    169 	 * attach all scsi units on us
    170 	 */
    171 	config_found(dp, chan, scsiprint);
    172 }
    173 
    174 int
    175 cbiiisc_dmaintr(void *arg)
    176 {
    177 	struct siop_softc *sc = arg;
    178 	siop_regmap_p rp;
    179 	int istat;
    180 
    181 	if (sc->sc_flags & SIOP_INTSOFF)
    182 		return (0);	/* interrupts are not active */
    183 	rp = sc->sc_siopp;
    184 	istat = rp->siop_istat;
    185 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
    186 		return(0);
    187 	/*
    188 	 * save interrupt status, DMA status, and SCSI status 0
    189 	 * (may need to deal with stacked interrupts?)
    190 	 */
    191 	sc->sc_sist = rp->siop_sist;
    192 	sc->sc_istat = istat;
    193 	sc->sc_dstat = rp->siop_dstat;
    194 	siopngintr(sc);
    195 	return(1);
    196 }
    197 
    198 #ifdef DEBUG
    199 void
    200 cbiiisc_dump(void)
    201 {
    202 	extern struct cfdriver cbiiisc_cd;
    203 	struct siop_softc *sc;
    204 	int i;
    205 
    206 	for (i = 0; i < cbiiisc_cd.cd_ndevs; ++i) {
    207 		sc = device_lookup_private(&cbiiisc_cd, i);
    208 		if (sc != NULL)
    209 			siopng_dump(sc);
    210 	}
    211 }
    212 #endif
    213