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