Home | History | Annotate | Line # | Download | only in dev
ahsc.c revision 1.10
      1 /*	$NetBSD: ahsc.c,v 1.10 1995/09/04 13:04:40 chopps Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Christian E. Hopps
      5  * Copyright (c) 1982, 1990 The Regents of the University of California.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the University of
     19  *	California, Berkeley and its contributors.
     20  * 4. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  *	@(#)dma.c
     37  */
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/kernel.h>
     41 #include <sys/device.h>
     42 #include <scsi/scsi_all.h>
     43 #include <scsi/scsiconf.h>
     44 #include <amiga/amiga/custom.h>
     45 #include <amiga/amiga/cc.h>
     46 #include <amiga/amiga/device.h>
     47 #include <amiga/amiga/isr.h>
     48 #include <amiga/dev/dmavar.h>
     49 #include <amiga/dev/sbicreg.h>
     50 #include <amiga/dev/sbicvar.h>
     51 #include <amiga/dev/ahscreg.h>
     52 #include <amiga/dev/zbusvar.h>
     53 
     54 int ahscprint __P((void *auxp, char *));
     55 void ahscattach __P((struct device *, struct device *, void *));
     56 int ahscmatch __P((struct device *, struct cfdata *, void *));
     57 
     58 void ahsc_enintr __P((struct sbic_softc *));
     59 void ahsc_dmastop __P((struct sbic_softc *));
     60 int ahsc_dmanext __P((struct sbic_softc *));
     61 int ahsc_dmaintr __P((struct sbic_softc *));
     62 int ahsc_dmago __P((struct sbic_softc *, char *, int, int));
     63 
     64 struct scsi_adapter ahsc_scsiswitch = {
     65 	sbic_scsicmd,
     66 	sbic_minphys,
     67 	0,			/* no lun support */
     68 	0,			/* no lun support */
     69 };
     70 
     71 struct scsi_device ahsc_scsidev = {
     72 	NULL,		/* use default error handler */
     73 	NULL,		/* do not have a start functio */
     74 	NULL,		/* have no async handler */
     75 	NULL,		/* Use default done routine */
     76 };
     77 
     78 
     79 #ifdef DEBUG
     80 int	ahsc_dmadebug = 0;
     81 #endif
     82 
     83 struct cfdriver ahsccd = {
     84 	NULL, "ahsc", (cfmatch_t)ahscmatch, ahscattach,
     85 	DV_DULL, sizeof(struct sbic_softc), NULL, 0 };
     86 
     87 /*
     88  * if we are an A3000 we are here.
     89  */
     90 int
     91 ahscmatch(pdp, cdp, auxp)
     92 	struct device *pdp;
     93 	struct cfdata *cdp;
     94 	void *auxp;
     95 {
     96 	char *mbusstr;
     97 
     98 	mbusstr = auxp;
     99 	if (is_a3000() && matchname(auxp, "ahsc"))
    100 		return(1);
    101 	return(0);
    102 }
    103 
    104 void
    105 ahscattach(pdp, dp, auxp)
    106 	struct device *pdp, *dp;
    107 	void *auxp;
    108 {
    109 	volatile struct sdmac *rp;
    110 	struct sbic_softc *sc;
    111 
    112 	printf("\n");
    113 
    114 	sc = (struct sbic_softc *)dp;
    115 	sc->sc_cregs = rp = ztwomap(0xdd0000);
    116 	/*
    117 	 * disable ints and reset bank register
    118 	 */
    119 	rp->CNTR = CNTR_PDMD;
    120 	rp->DAWR = DAWR_AHSC;
    121 	sc->sc_enintr = ahsc_enintr;
    122 	sc->sc_dmago = ahsc_dmago;
    123 	sc->sc_dmanext = ahsc_dmanext;
    124 	sc->sc_dmastop = ahsc_dmastop;
    125 	sc->sc_dmacmd = 0;
    126 
    127 	/*
    128 	 * eveything is a valid dma address
    129 	 */
    130 	sc->sc_dmamask = 0;
    131 	sc->sc_sbicp = (sbic_regmap_p) ((int)rp + 0x41);
    132 	sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 143;
    133 
    134 	sc->sc_link.adapter_softc = sc;
    135 	sc->sc_link.adapter_target = 7;
    136 	sc->sc_link.adapter = &ahsc_scsiswitch;
    137 	sc->sc_link.device = &ahsc_scsidev;
    138 	sc->sc_link.openings = 2;
    139 
    140 	sbicinit(sc);
    141 
    142 	sc->sc_isr.isr_intr = ahsc_dmaintr;
    143 	sc->sc_isr.isr_arg = sc;
    144 	sc->sc_isr.isr_ipl = 2;
    145 	add_isr (&sc->sc_isr);
    146 
    147 	/*
    148 	 * attach all scsi units on us
    149 	 */
    150 	config_found(dp, &sc->sc_link, ahscprint);
    151 }
    152 
    153 /*
    154  * print diag if pnp is NULL else just extra
    155  */
    156 int
    157 ahscprint(auxp, pnp)
    158 	void *auxp;
    159 	char *pnp;
    160 {
    161 	if (pnp == NULL)
    162 		return(UNCONF);
    163 	return(QUIET);
    164 }
    165 
    166 
    167 void
    168 ahsc_enintr(dev)
    169 	struct sbic_softc *dev;
    170 {
    171 	volatile struct sdmac *sdp;
    172 
    173 	sdp = dev->sc_cregs;
    174 
    175 	dev->sc_flags |= SBICF_INTR;
    176 	sdp->CNTR = CNTR_PDMD | CNTR_INTEN;
    177 }
    178 
    179 int
    180 ahsc_dmago(dev, addr, count, flags)
    181 	struct sbic_softc *dev;
    182 	char *addr;
    183 	int count, flags;
    184 {
    185 	volatile struct sdmac *sdp;
    186 
    187 	sdp = dev->sc_cregs;
    188 	/*
    189 	 * Set up the command word based on flags
    190 	 */
    191 	dev->sc_dmacmd = CNTR_PDMD | CNTR_INTEN;
    192 	if ((flags & DMAGO_READ) == 0)
    193 		dev->sc_dmacmd |= CNTR_DDIR;
    194 #ifdef DEBUG
    195 	if (ahsc_dmadebug & DDB_IO)
    196 		printf("ahsc_dmago: cmd %x\n", dev->sc_dmacmd);
    197 #endif
    198 
    199 	dev->sc_flags |= SBICF_INTR;
    200 	sdp->CNTR = dev->sc_dmacmd;
    201 	sdp->ACR = (u_int) dev->sc_cur->dc_addr;
    202 	sdp->ST_DMA = 1;
    203 
    204 	return(dev->sc_tcnt);
    205 }
    206 
    207 void
    208 ahsc_dmastop(dev)
    209 	struct sbic_softc *dev;
    210 {
    211 	volatile struct sdmac *sdp;
    212 	int s;
    213 
    214 	sdp = dev->sc_cregs;
    215 
    216 #ifdef DEBUG
    217 	if (ahsc_dmadebug & DDB_FOLLOW)
    218 		printf("ahsc_dmastop()\n");
    219 #endif
    220 	if (dev->sc_dmacmd) {
    221 		s = splbio();
    222 		if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    223 			/*
    224 			 * only FLUSH if terminal count not enabled,
    225 			 * and reading from peripheral
    226 			 */
    227 			sdp->FLUSH = 1;
    228 			while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    229 				;
    230 		}
    231 		/*
    232 		 * clear possible interrupt and stop dma
    233 		 */
    234 		sdp->CINT = 1;
    235 		sdp->SP_DMA = 1;
    236 		dev->sc_dmacmd = 0;
    237 		splx(s);
    238 	}
    239 }
    240 
    241 int
    242 ahsc_dmaintr(dev)
    243 	struct sbic_softc *dev;
    244 {
    245 	volatile struct sdmac *sdp;
    246 	int stat, found;
    247 
    248 	sdp = dev->sc_cregs;
    249 	stat = sdp->ISTR;
    250 
    251 	if ((stat & (ISTR_INT_F|ISTR_INT_P)) == 0)
    252 		return (0);
    253 
    254 #ifdef DEBUG
    255 	if (ahsc_dmadebug & DDB_FOLLOW)
    256 		printf("%s: dmaintr 0x%x\n", dev->sc_dev.dv_xname, stat);
    257 #endif
    258 
    259 	/*
    260 	 * both, SCSI and DMA interrupts arrive here. I chose
    261 	 * arbitrarily that DMA interrupts should have higher
    262 	 * precedence than SCSI interrupts.
    263 	 */
    264 	found = 0;
    265 	if (stat & ISTR_E_INT) {
    266 		++found;
    267 
    268 		sdp->CINT = 1;	/* clear possible interrupt */
    269 
    270 		/*
    271 		 * check for SCSI ints in the same go and
    272 		 * eventually save an interrupt
    273 		 */
    274 	}
    275 
    276 	if (dev->sc_flags & SBICF_INTR && stat & ISTR_INTS)
    277 		found += sbicintr(dev);
    278 	return(found);
    279 }
    280 
    281 
    282 int
    283 ahsc_dmanext(dev)
    284 	struct sbic_softc *dev;
    285 {
    286 	volatile struct sdmac *sdp;
    287 	int i, stat;
    288 
    289 	sdp = dev->sc_cregs;
    290 
    291 	if (dev->sc_cur > dev->sc_last) {
    292 		/* shouldn't happen !! */
    293 		printf("ahsc_dmanext at end !!!\n");
    294 		ahsc_dmastop(dev);
    295 		return(0);
    296 	}
    297 	if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    298 		  /*
    299 		   * only FLUSH if terminal count not enabled,
    300 		   * and reading from peripheral
    301 		   */
    302 		sdp->FLUSH = 1;
    303 		while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    304 			;
    305         }
    306 	/*
    307 	 * clear possible interrupt and stop dma
    308 	 */
    309 	sdp->CINT = 1;	/* clear possible interrupt */
    310 	sdp->SP_DMA = 1;	/* stop dma */
    311 	sdp->CNTR = dev->sc_dmacmd;
    312 	sdp->ACR = (u_int)dev->sc_cur->dc_addr;
    313 	sdp->ST_DMA = 1;
    314 
    315 	dev->sc_tcnt = dev->sc_cur->dc_count << 1;
    316 	return(dev->sc_tcnt);
    317 }
    318 
    319 #ifdef DEBUG
    320 void
    321 ahsc_dump()
    322 {
    323 	int i;
    324 
    325 	for (i = 0; i < ahsccd.cd_ndevs; ++i)
    326 		if (ahsccd.cd_devs[i])
    327 			sbic_dump(ahsccd.cd_devs[i]);
    328 }
    329 #endif
    330