Home | History | Annotate | Line # | Download | only in dev
ahsc.c revision 1.26
      1 /*	$NetBSD: ahsc.c,v 1.26 2000/01/15 17:09:47 aymeric 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/cfdev.h>
     48 #include <amiga/amiga/device.h>
     49 #include <amiga/amiga/isr.h>
     50 #include <amiga/dev/dmavar.h>
     51 #include <amiga/dev/sbicreg.h>
     52 #include <amiga/dev/sbicvar.h>
     53 #include <amiga/dev/ahscreg.h>
     54 #include <amiga/dev/zbusvar.h>
     55 
     56 #include <machine/cpu.h>
     57 
     58 void ahscattach __P((struct device *, struct device *, void *));
     59 int ahscmatch __P((struct device *, struct cfdata *, void *));
     60 
     61 void ahsc_enintr __P((struct sbic_softc *));
     62 void ahsc_dmastop __P((struct sbic_softc *));
     63 int ahsc_dmanext __P((struct sbic_softc *));
     64 int ahsc_dmaintr __P((void *));
     65 int ahsc_dmago __P((struct sbic_softc *, char *, int, int));
     66 
     67 #ifdef DEBUG
     68 void ahsc_dump __P((void));
     69 #endif
     70 
     71 struct scsipi_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 cfattach ahsc_ca = {
     84 	sizeof(struct sbic_softc), ahscmatch, ahscattach
     85 };
     86 
     87 /*
     88  * if we are an A3000 we are here.
     89  */
     90 int
     91 ahscmatch(pdp, cfp, auxp)
     92 	struct device *pdp;
     93 	struct cfdata *cfp;
     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 	struct cfdev *cdp, *ecdp;
    112 
    113 	ecdp = &cfdev[ncfdev];
    114 
    115 	for (cdp = cfdev; cdp < ecdp; cdp++) {
    116 		if (cdp->rom.manid == 8738 &&
    117 		    cdp->rom.prodid == 35)
    118 				break;
    119 	}
    120 
    121 	sc = (struct sbic_softc *)dp;
    122 	sc->sc_cregs = rp = ztwomap(0xdd0000);
    123 	/*
    124 	 * disable ints and reset bank register
    125 	 */
    126 	rp->CNTR = CNTR_PDMD;
    127 	rp->DAWR = DAWR_AHSC;
    128 	sc->sc_enintr = ahsc_enintr;
    129 	sc->sc_dmago = ahsc_dmago;
    130 	sc->sc_dmanext = ahsc_dmanext;
    131 	sc->sc_dmastop = ahsc_dmastop;
    132 	sc->sc_dmacmd = 0;
    133 
    134 	/*
    135 	 * eveything is a valid dma address
    136 	 */
    137 	sc->sc_dmamask = 0;
    138 
    139 	if (cdp < ecdp) {
    140 		sc->sc_sbic.sbic_asr_p =  ((vu_char *)rp + 0x43);
    141 		sc->sc_sbic.sbic_value_p =  ((vu_char *)rp + 0x47);
    142 		printf(": modified for Apollo cpu board\n");
    143 	} else {
    144 		sc->sc_sbic.sbic_asr_p =  ((vu_char *)rp + 0x41);
    145 		sc->sc_sbic.sbic_value_p =  ((vu_char *)rp + 0x43);
    146 		printf("\n");
    147 	}
    148 
    149 	sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 143;
    150 
    151 	sc->sc_adapter.scsipi_cmd = sbic_scsicmd;
    152 	sc->sc_adapter.scsipi_minphys = sbic_minphys;
    153 
    154 	sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
    155 	sc->sc_link.adapter_softc = sc;
    156 	sc->sc_link.scsipi_scsi.adapter_target = 7;
    157 	sc->sc_link.adapter = &sc->sc_adapter;
    158 	sc->sc_link.device = &ahsc_scsidev;
    159 	sc->sc_link.openings = 2;
    160 	sc->sc_link.scsipi_scsi.max_target = 7;
    161 	sc->sc_link.scsipi_scsi.max_lun = 7;
    162 	sc->sc_link.type = BUS_SCSI;
    163 
    164 	sbicinit(sc);
    165 
    166 	sc->sc_isr.isr_intr = ahsc_dmaintr;
    167 	sc->sc_isr.isr_arg = sc;
    168 	sc->sc_isr.isr_ipl = 2;
    169 	add_isr (&sc->sc_isr);
    170 
    171 	/*
    172 	 * attach all scsi units on us
    173 	 */
    174 	config_found(dp, &sc->sc_link, scsiprint);
    175 }
    176 
    177 void
    178 ahsc_enintr(dev)
    179 	struct sbic_softc *dev;
    180 {
    181 	volatile struct sdmac *sdp;
    182 
    183 	sdp = dev->sc_cregs;
    184 
    185 	dev->sc_flags |= SBICF_INTR;
    186 	sdp->CNTR = CNTR_PDMD | CNTR_INTEN;
    187 }
    188 
    189 int
    190 ahsc_dmago(dev, addr, count, flags)
    191 	struct sbic_softc *dev;
    192 	char *addr;
    193 	int count, flags;
    194 {
    195 	volatile struct sdmac *sdp;
    196 
    197 	sdp = dev->sc_cregs;
    198 	/*
    199 	 * Set up the command word based on flags
    200 	 */
    201 	dev->sc_dmacmd = CNTR_PDMD | CNTR_INTEN;
    202 	if ((flags & DMAGO_READ) == 0)
    203 		dev->sc_dmacmd |= CNTR_DDIR;
    204 #ifdef DEBUG
    205 	if (ahsc_dmadebug & DDB_IO)
    206 		printf("ahsc_dmago: cmd %x\n", dev->sc_dmacmd);
    207 #endif
    208 
    209 	dev->sc_flags |= SBICF_INTR;
    210 	sdp->CNTR = dev->sc_dmacmd;
    211 	sdp->ACR = (u_int) dev->sc_cur->dc_addr;
    212 	sdp->ST_DMA = 1;
    213 
    214 	return(dev->sc_tcnt);
    215 }
    216 
    217 void
    218 ahsc_dmastop(dev)
    219 	struct sbic_softc *dev;
    220 {
    221 	volatile struct sdmac *sdp;
    222 	int s;
    223 
    224 	sdp = dev->sc_cregs;
    225 
    226 #ifdef DEBUG
    227 	if (ahsc_dmadebug & DDB_FOLLOW)
    228 		printf("ahsc_dmastop()\n");
    229 #endif
    230 	if (dev->sc_dmacmd) {
    231 		s = splbio();
    232 		if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    233 			/*
    234 			 * only FLUSH if terminal count not enabled,
    235 			 * and reading from peripheral
    236 			 */
    237 			sdp->FLUSH = 1;
    238 			while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    239 				;
    240 		}
    241 		/*
    242 		 * clear possible interrupt and stop dma
    243 		 */
    244 		sdp->CINT = 1;
    245 		sdp->SP_DMA = 1;
    246 		dev->sc_dmacmd = 0;
    247 		splx(s);
    248 	}
    249 }
    250 
    251 int
    252 ahsc_dmaintr(arg)
    253 	void *arg;
    254 {
    255 	struct sbic_softc *dev = arg;
    256 	volatile struct sdmac *sdp;
    257 	int stat, found;
    258 
    259 	sdp = dev->sc_cregs;
    260 	stat = sdp->ISTR;
    261 
    262 	if ((stat & (ISTR_INT_F|ISTR_INT_P)) == 0)
    263 		return (0);
    264 
    265 #ifdef DEBUG
    266 	if (ahsc_dmadebug & DDB_FOLLOW)
    267 		printf("%s: dmaintr 0x%x\n", dev->sc_dev.dv_xname, stat);
    268 #endif
    269 
    270 	/*
    271 	 * both, SCSI and DMA interrupts arrive here. I chose
    272 	 * arbitrarily that DMA interrupts should have higher
    273 	 * precedence than SCSI interrupts.
    274 	 */
    275 	found = 0;
    276 	if (stat & ISTR_E_INT) {
    277 		++found;
    278 
    279 		sdp->CINT = 1;	/* clear possible interrupt */
    280 
    281 		/*
    282 		 * check for SCSI ints in the same go and
    283 		 * eventually save an interrupt
    284 		 */
    285 	}
    286 
    287 	if (dev->sc_flags & SBICF_INTR && stat & ISTR_INTS)
    288 		found += sbicintr(dev);
    289 	return(found);
    290 }
    291 
    292 
    293 int
    294 ahsc_dmanext(dev)
    295 	struct sbic_softc *dev;
    296 {
    297 	volatile struct sdmac *sdp;
    298 
    299 	sdp = dev->sc_cregs;
    300 
    301 	if (dev->sc_cur > dev->sc_last) {
    302 		/* shouldn't happen !! */
    303 		printf("ahsc_dmanext at end !!!\n");
    304 		ahsc_dmastop(dev);
    305 		return(0);
    306 	}
    307 	if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) {
    308 		  /*
    309 		   * only FLUSH if terminal count not enabled,
    310 		   * and reading from peripheral
    311 		   */
    312 		sdp->FLUSH = 1;
    313 		while ((sdp->ISTR & ISTR_FE_FLG) == 0)
    314 			;
    315         }
    316 	/*
    317 	 * clear possible interrupt and stop dma
    318 	 */
    319 	sdp->CINT = 1;	/* clear possible interrupt */
    320 	sdp->SP_DMA = 1;	/* stop dma */
    321 	sdp->CNTR = dev->sc_dmacmd;
    322 	sdp->ACR = (u_int)dev->sc_cur->dc_addr;
    323 	sdp->ST_DMA = 1;
    324 
    325 	dev->sc_tcnt = dev->sc_cur->dc_count << 1;
    326 	return(dev->sc_tcnt);
    327 }
    328 
    329 #ifdef DEBUG
    330 void
    331 ahsc_dump()
    332 {
    333 	extern struct cfdriver ahsc_cd;
    334 	int i;
    335 
    336 	for (i = 0; i < ahsc_cd.cd_ndevs; ++i)
    337 		if (ahsc_cd.cd_devs[i])
    338 			sbic_dump(ahsc_cd.cd_devs[i]);
    339 }
    340 #endif
    341