Home | History | Annotate | Line # | Download | only in dev
atzsc.c revision 1.1
      1 /*
      2  * Copyright (c) 1994 Christian E. Hopps
      3  * Copyright (c) 1982, 1990 The Regents of the University of California.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by the University of
     17  *	California, Berkeley and its contributors.
     18  * 4. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)dma.c
     35  *	$Id: atzsc.c,v 1.1 1994/05/08 05:52:56 chopps Exp $
     36  */
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/kernel.h>
     40 #include <sys/device.h>
     41 #include <scsi/scsi_all.h>
     42 #include <scsi/scsiconf.h>
     43 #include <amiga/amiga/custom.h>
     44 #include <amiga/amiga/cc.h>
     45 #include <amiga/amiga/device.h>
     46 #include <amiga/dev/dmavar.h>
     47 #include <amiga/dev/sbicreg.h>
     48 #include <amiga/dev/sbicvar.h>
     49 #include <amiga/dev/atzscreg.h>
     50 #include <amiga/dev/ztwobusvar.h>
     51 
     52 int atzscprint __P((void *auxp, char *));
     53 void atzscattach __P((struct device *, struct device *, void *));
     54 int atzscmatch __P((struct device *, struct cfdata *, void *));
     55 
     56 void atzsc_dmafree __P((struct sbic_softc *));
     57 void atzsc_dmastop __P((struct sbic_softc *));
     58 int atzsc_dmanext __P((struct sbic_softc *));
     59 int atzsc_dmaintr __P((void));
     60 int atzsc_dmago __P((struct sbic_softc *, char *, int, int));
     61 
     62 struct scsi_adapter atzsc_scsiswitch = {
     63 	sbic_scsicmd,
     64 	sbic_minphys,
     65 	0,			/* no lun support */
     66 	0,			/* no lun support */
     67 	sbic_adinfo,
     68 	"atzsc",
     69 };
     70 
     71 struct scsi_device atzsc_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 	"atzsc",
     77 	0,
     78 };
     79 
     80 
     81 #ifdef DEBUG
     82 void	atzsc_dmatimeout __P((void *));
     83 int	atzsc_dmadebug = 0;
     84 #endif
     85 
     86 struct cfdriver atzsccd = {
     87 	NULL, "atzsc", atzscmatch, atzscattach,
     88 	DV_DULL, sizeof(struct sbic_softc), NULL, 0 };
     89 
     90 /*
     91  * if we are an A3000 we are here.
     92  */
     93 int
     94 atzscmatch(pdp, cdp, auxp)
     95 	struct device *pdp;
     96 	struct cfdata *cdp;
     97 	void *auxp;
     98 {
     99 	struct ztwobus_args *zap;
    100 
    101 	zap = auxp;
    102 
    103 	/*
    104 	 * Check manufacturer and product id.
    105 	 * I was informed that older boards can be 2 also.
    106 	 */
    107 	if (zap->manid == 514 && (zap->prodid == 3 || zap->prodid == 2))
    108 		return(1);
    109 	else
    110 		return(0);
    111 }
    112 
    113 void
    114 atzscattach(pdp, dp, auxp)
    115 	struct device *pdp, *dp;
    116 	void *auxp;
    117 {
    118 	volatile struct sdmac *rp;
    119 	struct sbic_softc *sc;
    120 	struct ztwobus_args *zap;
    121 
    122 	zap = auxp;
    123 
    124 	sc = (struct sbic_softc *)dp;
    125 	sc->sc_cregs = rp = zap->va;
    126 	/*
    127 	 * disable ints and reset bank register
    128 	 */
    129 	rp->CNTR = CNTR_PDMD;
    130 	rp->DAWR = DAWR_ATZSC;
    131 	sc->sc_dmafree = atzsc_dmafree;
    132 	sc->sc_dmago = atzsc_dmago;
    133 	sc->sc_dmanext = atzsc_dmanext;
    134 	sc->sc_dmastop = atzsc_dmastop;
    135 	sc->sc_dmacmd = 0xFF000000;		/* only ztwomem */
    136 
    137 #ifdef DEBUG
    138 	/* make sure timeout is really not needed */
    139 	timeout(atzsc_dmatimeout, 0, 30 * hz);
    140 #endif
    141 	/*
    142 	 * eveything is a valid dma address
    143 	 */
    144 	sc->sc_dmamask = 0;
    145 	sc->sc_sbicp = (sbic_regmap_p) ((int)rp + 0x91);
    146 	sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 77;
    147 
    148 	sbicreset(sc);
    149 
    150 	sc->sc_link.adapter_softc = sc;
    151 	sc->sc_link.adapter_targ = 7;
    152 	sc->sc_link.adapter = &atzsc_scsiswitch;
    153 	sc->sc_link.device = &atzsc_scsidev;
    154 	TAILQ_INIT(&sc->sc_xslist);
    155 
    156 	custom.intreq = INTF_PORTS;
    157 	custom.intena = INTF_SETCLR | INTF_PORTS;
    158 
    159 	/*
    160 	 * attach all scsi units on us
    161 	 */
    162 	config_found(dp, &sc->sc_link, atzscprint);
    163 }
    164 
    165 /*
    166  * print diag if pnp is NULL else just extra
    167  */
    168 int
    169 atzscprint(auxp, pnp)
    170 	void *auxp;
    171 	char *pnp;
    172 {
    173 	if (pnp == NULL)
    174 		return(UNCONF);
    175 	return(QUIET);
    176 }
    177 
    178 
    179 void
    180 atzsc_dmafree(dev)
    181 	struct sbic_softc *dev;
    182 {
    183 	volatile struct sdmac *sdp;
    184 	int s;
    185 
    186 	sdp = dev->sc_cregs;
    187 
    188 	s = splbio();
    189 #ifdef DEBUG
    190 	dev->sc_dmatimo = 0;
    191 #endif
    192 	if (dev->sc_dmacmd) {
    193 		if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    194 			/*
    195 			 * only FLUSH if terminal count not enabled,
    196 			 * and reading from peripheral
    197 			 */
    198 			sdp->FLUSH = 1;
    199 			while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    200 				;
    201 		}
    202 		/*
    203 		 * clear possible interrupt and stop dma
    204 		 */
    205 		sdp->CINT = 1;
    206 		sdp->SP_DMA = 1;
    207 		dev->sc_dmacmd = 0;
    208 	}
    209 	/*
    210 	 * disable interrupts
    211 	 */
    212 	sdp->CNTR = CNTR_PDMD;	/* disable interrupts from dma/scsi */
    213 	dev->sc_flags &= ~SBICF_INTR;
    214 	splx(s);
    215 }
    216 
    217 int
    218 atzsc_dmago(dev, addr, count, flags)
    219 	struct sbic_softc *dev;
    220 	char *addr;
    221 	int count, flags;
    222 {
    223 	volatile struct sdmac *sdp;
    224 
    225 	sdp = dev->sc_cregs;
    226 	/*
    227 	 * Set up the command word based on flags
    228 	 */
    229 	dev->sc_dmacmd = CNTR_PDMD | CNTR_INTEN;
    230 	if ((flags & DMAGO_READ) == 0)
    231 		dev->sc_dmacmd |= CNTR_DDIR;
    232 #ifdef DEBUG
    233 	if (atzsc_dmadebug & DDB_IO)
    234 		printf("atzsc_dmago: cmd %x\n", dev->sc_dmacmd);
    235 	dev->sc_dmatimo = 1;
    236 #endif
    237 
    238 	dev->sc_flags |= SBICF_INTR;
    239 	sdp->CNTR = dev->sc_dmacmd;
    240 	sdp->ACR = (u_int) dev->sc_cur->dc_addr;
    241 	sdp->ST_DMA = 1;
    242 
    243 	return(dev->sc_tcnt);
    244 }
    245 
    246 void
    247 atzsc_dmastop(dev)
    248 	struct sbic_softc *dev;
    249 {
    250 	volatile struct sdmac *sdp;
    251 	int s;
    252 
    253 	sdp = dev->sc_cregs;
    254 
    255 #ifdef DEBUG
    256 	if (atzsc_dmadebug & DDB_FOLLOW)
    257 		printf("atzsc_dmastop()\n");
    258 	dev->sc_dmatimo = 0;
    259 #endif
    260 	if (dev->sc_dmacmd) {
    261 		s = splbio();
    262 		if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    263 			/*
    264 			 * only FLUSH if terminal count not enabled,
    265 			 * and reading from peripheral
    266 			 */
    267 			sdp->FLUSH = 1;
    268 			while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    269 				;
    270 		}
    271 		/*
    272 		 * clear possible interrupt and stop dma
    273 		 */
    274 		sdp->CINT = 1;
    275 		sdp->SP_DMA = 1;
    276 		dev->sc_dmacmd = 0;
    277 		splx(s);
    278 	}
    279 }
    280 
    281 int
    282 atzsc_dmaintr()
    283 {
    284 	volatile struct sdmac *sdp;
    285 	struct sbic_softc *dev;
    286 	int i, stat, found;
    287 
    288 	found = 0;
    289 	for (i = 0; i < atzsccd.cd_ndevs; i++) {
    290 		dev = atzsccd.cd_devs[i];
    291 		if (dev == NULL)
    292 			continue;
    293 		sdp = dev->sc_cregs;
    294 		stat = sdp->ISTR;
    295 
    296 		if ((stat & (ISTR_INT_F|ISTR_INT_P)) == 0)
    297 			continue;
    298 
    299 #ifdef DEBUG
    300 		if (atzsc_dmadebug & DDB_FOLLOW)
    301 			printf("atzsc_dmaintr (%d, 0x%x)\n", i, stat);
    302 #endif
    303 
    304 		/*
    305 		 * both, SCSI and DMA interrupts arrive here. I chose
    306 		 * arbitrarily that DMA interrupts should have higher
    307 		 * precedence than SCSI interrupts.
    308 		 */
    309 		if (stat & ISTR_E_INT) {
    310 			found++;
    311 
    312 			sdp->CINT = 1;	/* clear possible interrupt */
    313 
    314 			/*
    315 			 * check for SCSI ints in the same go and
    316 			 * eventually save an interrupt
    317 			 */
    318 		}
    319 
    320 		if (dev->sc_flags & SBICF_INTR && stat & ISTR_INTS)
    321 			found += sbicintr(i);
    322 	}
    323 	return(found);
    324 }
    325 
    326 
    327 int
    328 atzsc_dmanext(dev)
    329 	struct sbic_softc *dev;
    330 {
    331 	volatile struct sdmac *sdp;
    332 	int i, stat;
    333 
    334 	sdp = dev->sc_cregs;
    335 
    336 	if (dev->sc_cur > dev->sc_last) {
    337 		/* shouldn't happen !! */
    338 		printf("atzsc_dmanext at end !!!\n");
    339 		atzsc_dmastop(dev);
    340 		return(0);
    341 	}
    342 #ifdef DEBUG
    343 	dev->sc_dmatimo = 1;
    344 #endif
    345 	if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    346 		  /*
    347 		   * only FLUSH if terminal count not enabled,
    348 		   * and reading from peripheral
    349 		   */
    350 		sdp->FLUSH = 1;
    351 		while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    352 			;
    353         }
    354 	/*
    355 	 * clear possible interrupt and stop dma
    356 	 */
    357 	sdp->CINT = 1;	/* clear possible interrupt */
    358 	sdp->SP_DMA = 1;	/* stop dma */
    359 	sdp->CNTR = dev->sc_dmacmd;
    360 	sdp->ACR = (u_int)dev->sc_cur->dc_addr;
    361 	sdp->ST_DMA = 1;
    362 
    363 	dev->sc_tcnt = dev->sc_cur->dc_count << 1;
    364 	return(dev->sc_tcnt);
    365 }
    366 
    367 #ifdef DEBUG
    368 /*ARGSUSED*/
    369 void
    370 atzsc_dmatimeout(arg)
    371 	void *arg;
    372 {
    373 	struct sbic_softc *dev;
    374 	int i, s;
    375 
    376 	for (i = 0; i < atzsccd.cd_ndevs; i++) {
    377 		dev = atzsccd.cd_devs[i];
    378 		if (dev == NULL)
    379 			continue;
    380 
    381 		s = splbio();
    382 		if (dev->sc_dmatimo) {
    383 			if (dev->sc_dmatimo > 1)
    384 				printf("atzsc_dma%d: timeout #%d\n",
    385 				    dev->sc_dev.dv_unit, dev->sc_dmatimo - 1);
    386 			dev->sc_dmatimo++;
    387 		}
    388 		splx(s);
    389 	}
    390 	timeout(atzsc_dmatimeout, 0, 30 * hz);
    391 }
    392 #endif
    393