Home | History | Annotate | Line # | Download | only in dev
atzsc.c revision 1.23.4.1
      1 /*	$NetBSD: atzsc.c,v 1.23.4.1 1999/01/19 07:24:19 cgd 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 <dev/scsipi/scsi_all.h>
     43 #include <dev/scsipi/scsipi_all.h>
     44 #include <dev/scsipi/scsiconf.h>
     45 #include <amiga/amiga/custom.h>
     46 #include <amiga/amiga/cc.h>
     47 #include <amiga/amiga/device.h>
     48 #include <amiga/amiga/isr.h>
     49 #include <amiga/dev/dmavar.h>
     50 #include <amiga/dev/sbicreg.h>
     51 #include <amiga/dev/sbicvar.h>
     52 #include <amiga/dev/atzscreg.h>
     53 #include <amiga/dev/zbusvar.h>
     54 
     55 void atzscattach __P((struct device *, struct device *, void *));
     56 int atzscmatch __P((struct device *, struct cfdata *, void *));
     57 
     58 void atzsc_enintr __P((struct sbic_softc *));
     59 void atzsc_dmastop __P((struct sbic_softc *));
     60 int atzsc_dmanext __P((struct sbic_softc *));
     61 int atzsc_dmaintr __P((void *));
     62 int atzsc_dmago __P((struct sbic_softc *, char *, int, int));
     63 
     64 #ifdef DEBUG
     65 void atzsc_dump __P((void));
     66 #endif
     67 
     68 struct scsipi_adapter atzsc_scsiswitch = {
     69 	sbic_scsicmd,
     70 	sbic_minphys,
     71 	0,			/* no lun support */
     72 	0,			/* no lun support */
     73 };
     74 
     75 struct scsipi_device atzsc_scsidev = {
     76 	NULL,		/* use default error handler */
     77 	NULL,		/* do not have a start functio */
     78 	NULL,		/* have no async handler */
     79 	NULL,		/* Use default done routine */
     80 };
     81 
     82 
     83 #ifdef DEBUG
     84 int	atzsc_dmadebug = 0;
     85 #endif
     86 
     87 struct cfattach atzsc_ca = {
     88 	sizeof(struct sbic_softc), atzscmatch, atzscattach
     89 };
     90 
     91 struct cfdriver atzsc_cd = {
     92 	NULL, "atzsc", DV_DULL, NULL, 0
     93 };
     94 
     95 /*
     96  * if we are an A3000 we are here.
     97  */
     98 int
     99 atzscmatch(pdp, cfp, auxp)
    100 	struct device *pdp;
    101 	struct cfdata *cfp;
    102 	void *auxp;
    103 {
    104 	struct zbus_args *zap;
    105 
    106 	zap = auxp;
    107 
    108 	/*
    109 	 * Check manufacturer and product id.
    110 	 * I was informed that older boards can be 2 also.
    111 	 */
    112 	if (zap->manid == 514 && (zap->prodid == 3 || zap->prodid == 2))
    113 		return(1);
    114 	else
    115 		return(0);
    116 }
    117 
    118 void
    119 atzscattach(pdp, dp, auxp)
    120 	struct device *pdp, *dp;
    121 	void *auxp;
    122 {
    123 	volatile struct sdmac *rp;
    124 	struct sbic_softc *sc;
    125 	struct zbus_args *zap;
    126 
    127 	zap = auxp;
    128 
    129 	sc = (struct sbic_softc *)dp;
    130 	sc->sc_cregs = rp = zap->va;
    131 	/*
    132 	 * disable ints and reset bank register
    133 	 */
    134 	rp->CNTR = CNTR_PDMD;
    135 	rp->DAWR = DAWR_ATZSC;
    136 	sc->sc_enintr = atzsc_enintr;
    137 	sc->sc_dmago = atzsc_dmago;
    138 	sc->sc_dmanext = atzsc_dmanext;
    139 	sc->sc_dmastop = atzsc_dmastop;
    140 	sc->sc_dmacmd = 0;
    141 
    142 	/*
    143 	 * only 24 bit mem.
    144 	 */
    145 	sc->sc_flags |= SBICF_BADDMA;
    146 	sc->sc_dmamask = ~0x00ffffff;
    147 #if 0
    148 	/*
    149 	 * If the users kva space is not ztwo try and allocate a bounce buffer.
    150 	 * XXX this needs to change if we move to multiple memory segments.
    151 	 */
    152 	if (kvtop(sc) & sc->sc_dmamask) {
    153 		sc->sc_dmabuffer = (char *)alloc_z2mem(MAXPHYS * 8); /* XXX */
    154 		if (isztwomem(sc->sc_dmabuffer))
    155 			printf(" bounce pa 0x%x", kvtop(sc->sc_dmabuffer));
    156 		else if (sc->sc_dmabuffer)
    157 			printf(" bounce pa 0x%x",
    158 			    PREP_DMA_MEM(sc->sc_dmabuffer));
    159 	}
    160 #endif
    161 	sc->sc_sbic.sbic_asr_p = (volatile unsigned char *)rp + 0x91;
    162 	sc->sc_sbic.sbic_value_p = (volatile unsigned char *)rp + 0x93;
    163 
    164 	sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 77;
    165 
    166 	printf(": dmamask 0x%lx\n", ~sc->sc_dmamask);
    167 
    168 	sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
    169 	sc->sc_link.adapter_softc = sc;
    170 	sc->sc_link.scsipi_scsi.adapter_target = 7;
    171 	sc->sc_link.adapter = &atzsc_scsiswitch;
    172 	sc->sc_link.device = &atzsc_scsidev;
    173 	sc->sc_link.openings = 2;
    174 	sc->sc_link.scsipi_scsi.max_target = 7;
    175 	sc->sc_link.type = BUS_SCSI;
    176 
    177 	sbicinit(sc);
    178 
    179 	sc->sc_isr.isr_intr = atzsc_dmaintr;
    180 	sc->sc_isr.isr_arg = sc;
    181 	sc->sc_isr.isr_ipl = 2;
    182 	add_isr (&sc->sc_isr);
    183 
    184 	/*
    185 	 * attach all scsi units on us
    186 	 */
    187 	config_found(dp, &sc->sc_link, scsiprint);
    188 }
    189 
    190 void
    191 atzsc_enintr(dev)
    192 	struct sbic_softc *dev;
    193 {
    194 	volatile struct sdmac *sdp;
    195 
    196 	sdp = dev->sc_cregs;
    197 
    198 	dev->sc_flags |= SBICF_INTR;
    199 	sdp->CNTR = CNTR_PDMD | CNTR_INTEN;
    200 }
    201 
    202 int
    203 atzsc_dmago(dev, addr, count, flags)
    204 	struct sbic_softc *dev;
    205 	char *addr;
    206 	int count, flags;
    207 {
    208 	volatile struct sdmac *sdp;
    209 
    210 	sdp = dev->sc_cregs;
    211 	/*
    212 	 * Set up the command word based on flags
    213 	 */
    214 	dev->sc_dmacmd = CNTR_PDMD | CNTR_INTEN;
    215 	if ((flags & DMAGO_READ) == 0)
    216 		dev->sc_dmacmd |= CNTR_DDIR;
    217 #ifdef DEBUG
    218 	if (atzsc_dmadebug & DDB_IO)
    219 		printf("atzsc_dmago: cmd %x\n", dev->sc_dmacmd);
    220 #endif
    221 
    222 	dev->sc_flags |= SBICF_INTR;
    223 	sdp->CNTR = dev->sc_dmacmd;
    224 	sdp->ACR = (u_int) dev->sc_cur->dc_addr;
    225 	sdp->ST_DMA = 1;
    226 
    227 	return(dev->sc_tcnt);
    228 }
    229 
    230 void
    231 atzsc_dmastop(dev)
    232 	struct sbic_softc *dev;
    233 {
    234 	volatile struct sdmac *sdp;
    235 	int s;
    236 
    237 	sdp = dev->sc_cregs;
    238 
    239 #ifdef DEBUG
    240 	if (atzsc_dmadebug & DDB_FOLLOW)
    241 		printf("atzsc_dmastop()\n");
    242 #endif
    243 	if (dev->sc_dmacmd) {
    244 		s = splbio();
    245 		if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    246 			/*
    247 			 * only FLUSH if terminal count not enabled,
    248 			 * and reading from peripheral
    249 			 */
    250 			sdp->FLUSH = 1;
    251 			while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    252 				;
    253 		}
    254 		/*
    255 		 * clear possible interrupt and stop dma
    256 		 */
    257 		sdp->CINT = 1;
    258 		sdp->SP_DMA = 1;
    259 		dev->sc_dmacmd = 0;
    260 		splx(s);
    261 	}
    262 }
    263 
    264 int
    265 atzsc_dmaintr(arg)
    266 	void *arg;
    267 {
    268 	struct sbic_softc *dev = arg;
    269 	volatile struct sdmac *sdp;
    270 	int stat, found;
    271 
    272 	sdp = dev->sc_cregs;
    273 	stat = sdp->ISTR;
    274 
    275 	if ((stat & (ISTR_INT_F|ISTR_INT_P)) == 0)
    276 		return (0);
    277 
    278 #ifdef DEBUG
    279 	if (atzsc_dmadebug & DDB_FOLLOW)
    280 		printf("%s: dmaintr 0x%x\n", dev->sc_dev.dv_xname, stat);
    281 #endif
    282 
    283 	/*
    284 	 * both, SCSI and DMA interrupts arrive here. I chose
    285 	 * arbitrarily that DMA interrupts should have higher
    286 	 * precedence than SCSI interrupts.
    287 	 */
    288 	found = 0;
    289 	if (stat & ISTR_E_INT) {
    290 		found++;
    291 
    292 		sdp->CINT = 1;	/* clear possible interrupt */
    293 
    294 		/*
    295 		 * check for SCSI ints in the same go and
    296 		 * eventually save an interrupt
    297 		 */
    298 	}
    299 
    300 	if (dev->sc_flags & SBICF_INTR && stat & ISTR_INTS)
    301 		found += sbicintr(dev);
    302 	return(found);
    303 }
    304 
    305 
    306 int
    307 atzsc_dmanext(dev)
    308 	struct sbic_softc *dev;
    309 {
    310 	volatile struct sdmac *sdp;
    311 
    312 	sdp = dev->sc_cregs;
    313 
    314 	if (dev->sc_cur > dev->sc_last) {
    315 		/* shouldn't happen !! */
    316 		printf("atzsc_dmanext at end !!!\n");
    317 		atzsc_dmastop(dev);
    318 		return(0);
    319 	}
    320 	if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    321 		  /*
    322 		   * only FLUSH if terminal count not enabled,
    323 		   * and reading from peripheral
    324 		   */
    325 		sdp->FLUSH = 1;
    326 		while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    327 			;
    328         }
    329 	/*
    330 	 * clear possible interrupt and stop dma
    331 	 */
    332 	sdp->CINT = 1;	/* clear possible interrupt */
    333 	sdp->SP_DMA = 1;	/* stop dma */
    334 	sdp->CNTR = dev->sc_dmacmd;
    335 	sdp->ACR = (u_int)dev->sc_cur->dc_addr;
    336 	sdp->ST_DMA = 1;
    337 
    338 	dev->sc_tcnt = dev->sc_cur->dc_count << 1;
    339 	return(dev->sc_tcnt);
    340 }
    341 
    342 #ifdef DEBUG
    343 void
    344 atzsc_dump()
    345 {
    346 	int i;
    347 
    348 	for (i = 0; i < atzsc_cd.cd_ndevs; ++i)
    349 		if (atzsc_cd.cd_devs[i])
    350 			sbic_dump(atzsc_cd.cd_devs[i]);
    351 }
    352 #endif
    353