Home | History | Annotate | Line # | Download | only in dev
bzsc.c revision 1.2
      1  1.1  chopps /*
      2  1.1  chopps  * Copyright (c) 1995 Daniel Widenfalk
      3  1.1  chopps  * Copyright (c) 1994 Christian E. Hopps
      4  1.1  chopps  * Copyright (c) 1982, 1990 The Regents of the University of California.
      5  1.1  chopps  * All rights reserved.
      6  1.1  chopps  *
      7  1.1  chopps  * Redistribution and use in source and binary forms, with or without
      8  1.1  chopps  * modification, are permitted provided that the following conditions
      9  1.1  chopps  * are met:
     10  1.1  chopps  * 1. Redistributions of source code must retain the above copyright
     11  1.1  chopps  *    notice, this list of conditions and the following disclaimer.
     12  1.1  chopps  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  chopps  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  chopps  *    documentation and/or other materials provided with the distribution.
     15  1.1  chopps  * 3. All advertising materials mentioning features or use of this software
     16  1.1  chopps  *    must display the following acknowledgement:
     17  1.1  chopps  *	This product includes software developed by the University of
     18  1.1  chopps  *	California, Berkeley and its contributors.
     19  1.1  chopps  * 4. Neither the name of the University nor the names of its contributors
     20  1.1  chopps  *    may be used to endorse or promote products derived from this software
     21  1.1  chopps  *    without specific prior written permission.
     22  1.1  chopps  *
     23  1.1  chopps  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  chopps  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  chopps  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  chopps  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  chopps  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  chopps  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  chopps  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  chopps  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  chopps  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  chopps  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  chopps  * SUCH DAMAGE.
     34  1.1  chopps  *
     35  1.1  chopps  *	@(#)dma.c
     36  1.1  chopps  */
     37  1.1  chopps 
     38  1.1  chopps #include <sys/param.h>
     39  1.1  chopps #include <sys/systm.h>
     40  1.1  chopps #include <sys/kernel.h>
     41  1.1  chopps #include <sys/device.h>
     42  1.1  chopps #include <scsi/scsi_all.h>
     43  1.1  chopps #include <scsi/scsiconf.h>
     44  1.1  chopps #include <vm/vm.h>
     45  1.1  chopps #include <vm/vm_kern.h>
     46  1.1  chopps #include <vm/vm_page.h>
     47  1.1  chopps #include <machine/pmap.h>
     48  1.1  chopps #include <amiga/amiga/custom.h>
     49  1.1  chopps #include <amiga/amiga/cc.h>
     50  1.1  chopps #include <amiga/amiga/device.h>
     51  1.1  chopps #include <amiga/amiga/isr.h>
     52  1.1  chopps #include <amiga/dev/sfasreg.h>
     53  1.1  chopps #include <amiga/dev/sfasvar.h>
     54  1.1  chopps #include <amiga/dev/zbusvar.h>
     55  1.1  chopps #include <amiga/dev/bzscreg.h>
     56  1.1  chopps #include <amiga/dev/bzscvar.h>
     57  1.1  chopps 
     58  1.1  chopps int  bzscprint  __P((void *auxp, char *));
     59  1.1  chopps void bzscattach __P((struct device *, struct device *, void *));
     60  1.1  chopps int  bzscmatch  __P((struct device *, struct cfdata *, void *));
     61  1.1  chopps 
     62  1.1  chopps struct scsi_adapter bzsc_scsiswitch = {
     63  1.1  chopps 	sfas_scsicmd,
     64  1.1  chopps 	sfas_minphys,
     65  1.1  chopps 	0,			/* no lun support */
     66  1.1  chopps 	0,			/* no lun support */
     67  1.1  chopps };
     68  1.1  chopps 
     69  1.1  chopps struct scsi_device bzsc_scsidev = {
     70  1.1  chopps 	NULL,		/* use default error handler */
     71  1.1  chopps 	NULL,		/* do not have a start functio */
     72  1.1  chopps 	NULL,		/* have no async handler */
     73  1.1  chopps 	NULL,		/* Use default done routine */
     74  1.1  chopps };
     75  1.1  chopps 
     76  1.1  chopps 
     77  1.1  chopps struct cfdriver bzsccd = {
     78  1.1  chopps 	NULL, "bzsc", (cfmatch_t)bzscmatch, bzscattach,
     79  1.1  chopps 	DV_DULL, sizeof(struct bzsc_softc), NULL, 0 };
     80  1.1  chopps 
     81  1.1  chopps int bzsc_intr		__P((struct sfas_softc *dev));
     82  1.1  chopps int bzsc_setup_dma	__P((struct sfas_softc *sc, void *ptr, int len,
     83  1.1  chopps 			     int mode));
     84  1.1  chopps int bzsc_build_dma_chain __P((struct sfas_softc *sc,
     85  1.1  chopps 				struct sfas_dma_chain *chain, void *p, int l));
     86  1.1  chopps int bzsc_need_bump	__P((struct sfas_softc *sc, void *ptr, int len));
     87  1.1  chopps void bzsc_led_dummy	__P((struct sfas_softc *sc));
     88  1.1  chopps 
     89  1.1  chopps /*
     90  1.1  chopps  * if we are an Advanced Systems & Software FastlaneZ3
     91  1.1  chopps  */
     92  1.1  chopps int bzscmatch(struct device *pdp, struct cfdata *cdp,	void *auxp)
     93  1.1  chopps {
     94  1.1  chopps   struct zbus_args *zap;
     95  1.1  chopps 
     96  1.1  chopps   if (!is_a1200())
     97  1.1  chopps     return(0);
     98  1.1  chopps 
     99  1.1  chopps   zap = auxp;
    100  1.1  chopps   if (zap->manid == 0x2140 && zap->prodid == 11)
    101  1.1  chopps     return(1);
    102  1.1  chopps 
    103  1.1  chopps   return(0);
    104  1.1  chopps }
    105  1.1  chopps 
    106  1.1  chopps void bzscattach(struct device *pdp, struct device *dp, void *auxp)
    107  1.1  chopps {
    108  1.1  chopps 	struct bzsc_softc *sc;
    109  1.1  chopps 	struct zbus_args  *zap;
    110  1.1  chopps 	bzsc_regmap_p	   rp;
    111  1.1  chopps 	u_int		  *pte, page;
    112  1.1  chopps 	vu_char		  *fas;
    113  1.1  chopps 
    114  1.1  chopps 	zap = auxp;
    115  1.1  chopps 	fas = (vu_char *)(((char *)zap->va)+0x10000);
    116  1.1  chopps 
    117  1.1  chopps 	sc = (struct bzsc_softc *)dp;
    118  1.1  chopps 	rp = &sc->sc_regmap;
    119  1.1  chopps 
    120  1.1  chopps 	rp->FAS216.sfas_tc_low   = &fas[0x00];
    121  1.1  chopps 	rp->FAS216.sfas_tc_mid   = &fas[0x02];
    122  1.1  chopps 	rp->FAS216.sfas_fifo     = &fas[0x04];
    123  1.1  chopps 	rp->FAS216.sfas_command  = &fas[0x06];
    124  1.1  chopps 	rp->FAS216.sfas_dest_id  = &fas[0x08];
    125  1.1  chopps 	rp->FAS216.sfas_timeout  = &fas[0x0A];
    126  1.1  chopps 	rp->FAS216.sfas_syncper  = &fas[0x0C];
    127  1.1  chopps 	rp->FAS216.sfas_syncoff  = &fas[0x0E];
    128  1.1  chopps 	rp->FAS216.sfas_config1  = &fas[0x10];
    129  1.1  chopps 	rp->FAS216.sfas_clkconv  = &fas[0x12];
    130  1.1  chopps 	rp->FAS216.sfas_test     = &fas[0x14];
    131  1.1  chopps 	rp->FAS216.sfas_config2  = &fas[0x16];
    132  1.1  chopps 	rp->FAS216.sfas_config3  = &fas[0x18];
    133  1.1  chopps 	rp->FAS216.sfas_tc_high  = &fas[0x1C];
    134  1.1  chopps 	rp->FAS216.sfas_fifo_bot = &fas[0x1E];
    135  1.1  chopps 	rp->cclkaddr		 = &fas[0x21];
    136  1.1  chopps 	rp->epowaddr		 = &fas[0x31];
    137  1.1  chopps 
    138  1.1  chopps 	sc->sc_softc.sc_fas  = (sfas_regmap_p)rp;
    139  1.1  chopps 	sc->sc_softc.sc_spec = 0;
    140  1.1  chopps 
    141  1.1  chopps 	sc->sc_softc.sc_led  = bzsc_led_dummy;
    142  1.1  chopps 
    143  1.1  chopps 	sc->sc_softc.sc_setup_dma	= bzsc_setup_dma;
    144  1.1  chopps 	sc->sc_softc.sc_build_dma_chain = bzsc_build_dma_chain;
    145  1.1  chopps 	sc->sc_softc.sc_need_bump	= bzsc_need_bump;
    146  1.1  chopps 
    147  1.1  chopps 	sc->sc_softc.sc_clock_freq   = 40; /* BlizzardII 1230 runs at 40MHz? */
    148  1.1  chopps 	sc->sc_softc.sc_timeout      = 250; /* Set default timeout to 250ms */
    149  1.1  chopps 	sc->sc_softc.sc_config_flags = 0;
    150  1.1  chopps 	sc->sc_softc.sc_host_id      = 7;
    151  1.1  chopps 
    152  1.1  chopps 	sc->sc_softc.sc_bump_sz = NBPG;
    153  1.1  chopps 	sc->sc_softc.sc_bump_pa = 0x0;
    154  1.1  chopps 
    155  1.1  chopps 	sfasinitialize((struct sfas_softc *)sc);
    156  1.1  chopps 
    157  1.1  chopps 	sc->sc_softc.sc_link.adapter_softc = sc;
    158  1.1  chopps 	sc->sc_softc.sc_link.adapter_target = sc->sc_softc.sc_host_id;
    159  1.1  chopps 	sc->sc_softc.sc_link.adapter = &bzsc_scsiswitch;
    160  1.1  chopps 	sc->sc_softc.sc_link.device = &bzsc_scsidev;
    161  1.1  chopps 	sc->sc_softc.sc_link.openings = 1;
    162  1.1  chopps 
    163  1.1  chopps 	printf("\n");
    164  1.1  chopps 
    165  1.1  chopps 	sc->sc_softc.sc_isr.isr_intr = bzsc_intr;
    166  1.1  chopps 	sc->sc_softc.sc_isr.isr_arg = &sc->sc_softc;
    167  1.1  chopps 	sc->sc_softc.sc_isr.isr_ipl = 2;
    168  1.1  chopps 	add_isr(&sc->sc_softc.sc_isr);
    169  1.1  chopps 
    170  1.1  chopps 	/* attach all scsi units on us */
    171  1.1  chopps 	config_found(dp, &sc->sc_softc.sc_link, bzscprint);
    172  1.1  chopps }
    173  1.1  chopps 
    174  1.1  chopps /* print diag if pnp is NULL else just extra */
    175  1.1  chopps int bzscprint(void *auxp, char *pnp)
    176  1.1  chopps {
    177  1.1  chopps 	if (pnp == NULL)
    178  1.1  chopps 		return(UNCONF);
    179  1.1  chopps 
    180  1.1  chopps 	return(QUIET);
    181  1.1  chopps }
    182  1.1  chopps 
    183  1.1  chopps int bzsc_intr(struct sfas_softc *dev)
    184  1.1  chopps {
    185  1.1  chopps 	bzsc_regmap_p	rp;
    186  1.1  chopps 	int		quickints;
    187  1.1  chopps 
    188  1.1  chopps 	rp = (bzsc_regmap_p)dev->sc_fas;
    189  1.1  chopps 
    190  1.1  chopps 	if (!(*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING))
    191  1.1  chopps 		return(0);
    192  1.1  chopps 
    193  1.1  chopps 	quickints = 16;
    194  1.1  chopps 	do {
    195  1.1  chopps 		dev->sc_status = *rp->FAS216.sfas_status;
    196  1.1  chopps 		dev->sc_interrupt = *rp->FAS216.sfas_interrupt;
    197  1.1  chopps 
    198  1.1  chopps 		if (dev->sc_interrupt & SFAS_INT_RESELECTED) {
    199  1.1  chopps 			dev->sc_resel[0] = *rp->FAS216.sfas_fifo;
    200  1.1  chopps 			dev->sc_resel[1] = *rp->FAS216.sfas_fifo;
    201  1.1  chopps 		}
    202  1.1  chopps 		sfasintr(dev);
    203  1.1  chopps 	} while((*rp->FAS216.sfas_status & SFAS_STAT_INTERRUPT_PENDING) &&
    204  1.1  chopps 		--quickints);
    205  1.1  chopps 
    206  1.1  chopps 	return(1);
    207  1.1  chopps }
    208  1.1  chopps 
    209  1.1  chopps /* --------- */
    210  1.1  chopps void bzsc_set_dma_adr(struct sfas_softc *sc, void *ptr, int mode)
    211  1.1  chopps {
    212  1.1  chopps 	bzsc_regmap_p	rp;
    213  1.1  chopps 	unsigned long	p;
    214  1.1  chopps 
    215  1.1  chopps 	rp = (bzsc_regmap_p)sc->sc_fas;
    216  1.1  chopps 
    217  1.1  chopps 	p = ((unsigned long)p)>>1;
    218  1.1  chopps 
    219  1.1  chopps 	if (mode == SFAS_DMA_WRITE)
    220  1.1  chopps 		p |= BZSC_DMA_WRITE;
    221  1.1  chopps 	else
    222  1.2  chopps 		p |= BZSC_DMA_READ;
    223  1.1  chopps 
    224  1.1  chopps 	*rp->epowaddr = (u_char)(p>>24) & 0xFF;
    225  1.1  chopps 	*rp->cclkaddr = (u_char)(p>>16) & 0xFF;
    226  1.1  chopps 	*rp->cclkaddr = (u_char)(p>> 8) & 0xFF;
    227  1.1  chopps 	*rp->cclkaddr = (u_char)(p    ) & 0xFF;
    228  1.1  chopps }
    229  1.1  chopps 
    230  1.1  chopps /* Set DMA transfer counter */
    231  1.1  chopps void bzsc_set_dma_tc(struct sfas_softc *sc, unsigned int len)
    232  1.1  chopps {
    233  1.1  chopps 	*sc->sc_fas->sfas_tc_low  = len; len >>= 8;
    234  1.1  chopps 	*sc->sc_fas->sfas_tc_mid  = len; len >>= 8;
    235  1.1  chopps 	*sc->sc_fas->sfas_tc_high = len;
    236  1.1  chopps }
    237  1.1  chopps 
    238  1.1  chopps /* Initialize DMA for transfer */
    239  1.1  chopps int bzsc_setup_dma(struct sfas_softc *sc, void *ptr, int len, int mode)
    240  1.1  chopps {
    241  1.1  chopps 	int	retval;
    242  1.1  chopps 
    243  1.1  chopps 	retval = 0;
    244  1.1  chopps 
    245  1.1  chopps 	switch(mode) {
    246  1.1  chopps 	case SFAS_DMA_READ:
    247  1.1  chopps 	case SFAS_DMA_WRITE:
    248  1.1  chopps 		bzsc_set_dma_adr(sc, ptr, mode);
    249  1.1  chopps 		bzsc_set_dma_tc(sc, len);
    250  1.1  chopps 		break;
    251  1.1  chopps 	case SFAS_DMA_CLEAR:
    252  1.1  chopps 	default:
    253  1.1  chopps 		retval = (*sc->sc_fas->sfas_tc_high << 16) |
    254  1.1  chopps 			 (*sc->sc_fas->sfas_tc_mid  <<  8) |
    255  1.1  chopps 			  *sc->sc_fas->sfas_tc_low;
    256  1.1  chopps 
    257  1.1  chopps 		bzsc_set_dma_tc(sc, 0);
    258  1.1  chopps 		break;
    259  1.1  chopps 	}
    260  1.1  chopps 
    261  1.1  chopps 	return(retval);
    262  1.1  chopps }
    263  1.1  chopps 
    264  1.1  chopps /* Check if address and len is ok for DMA transfer */
    265  1.1  chopps int bzsc_need_bump(struct sfas_softc *sc, void *ptr, int len)
    266  1.1  chopps {
    267  1.1  chopps 	int	p;
    268  1.1  chopps 
    269  1.1  chopps 	p = (int)p & 0x03;
    270  1.1  chopps 
    271  1.1  chopps 	if (p) {
    272  1.1  chopps 		p = 4-p;
    273  1.1  chopps 
    274  1.1  chopps 		if (len < 256)
    275  1.1  chopps 			p = len;
    276  1.1  chopps 	}
    277  1.1  chopps 
    278  1.1  chopps 	return(p);
    279  1.1  chopps }
    280  1.1  chopps 
    281  1.1  chopps /* Interrupt driven routines */
    282  1.1  chopps int bzsc_build_dma_chain(struct sfas_softc *sc, struct sfas_dma_chain *chain,
    283  1.1  chopps 			   void *p, int l)
    284  1.1  chopps {
    285  1.1  chopps 	int	n;
    286  1.1  chopps 
    287  1.1  chopps 	if (!l)
    288  1.1  chopps 		return(0);
    289  1.1  chopps 
    290  1.1  chopps #define set_link(n, p, l, f)\
    291  1.1  chopps do { chain[n].ptr = (p); chain[n].len = (l); chain[n++].flg = (f); } while(0)
    292  1.1  chopps 
    293  1.1  chopps 	n = 0;
    294  1.1  chopps 
    295  1.1  chopps 	if (l < 512)
    296  1.1  chopps 		set_link(n, (vm_offset_t)p, l, SFAS_CHAIN_BUMP);
    297  1.1  chopps 	else if (
    298  1.1  chopps #ifdef M68040
    299  1.1  chopps 		 (cpu040 && ((vm_offset_t)p >= 0xFFFC0000)) &&
    300  1.1  chopps #endif
    301  1.1  chopps 		 ((vm_offset_t)p >= 0xFF000000)) {
    302  1.1  chopps 		int	len;
    303  1.1  chopps 
    304  1.1  chopps 		while(l) {
    305  1.1  chopps 			len = ((l > sc->sc_bump_sz) ? sc->sc_bump_sz : l);
    306  1.1  chopps 
    307  1.1  chopps 			set_link(n, (vm_offset_t)p, len, SFAS_CHAIN_BUMP);
    308  1.1  chopps 
    309  1.1  chopps 			p += len;
    310  1.1  chopps 			l -= len;
    311  1.1  chopps 		}
    312  1.1  chopps 	} else  {
    313  1.1  chopps 		char		*ptr;
    314  1.1  chopps 		vm_offset_t	 pa, lastpa;
    315  1.1  chopps 		int		 len,  prelen,  postlen, max_t;
    316  1.1  chopps 
    317  1.1  chopps 		ptr = p;
    318  1.1  chopps 		len = l;
    319  1.1  chopps 
    320  1.1  chopps 		pa = kvtop(ptr);
    321  1.1  chopps 		prelen = ((int)ptr & 0x03);
    322  1.1  chopps 
    323  1.1  chopps 		if (prelen) {
    324  1.1  chopps 			prelen = 4-prelen;
    325  1.1  chopps 			set_link(n, (vm_offset_t)ptr, prelen, SFAS_CHAIN_BUMP);
    326  1.1  chopps 			ptr += prelen;
    327  1.1  chopps 			len -= prelen;
    328  1.1  chopps 		}
    329  1.1  chopps 
    330  1.1  chopps 		lastpa = 0;
    331  1.1  chopps 		while(len > 3) {
    332  1.1  chopps 			pa = kvtop(ptr);
    333  1.1  chopps 			max_t = NBPG - (pa & PGOFSET);
    334  1.1  chopps 			if (max_t > len)
    335  1.1  chopps 				max_t = len;
    336  1.1  chopps 
    337  1.1  chopps 			max_t &= ~3;
    338  1.1  chopps 
    339  1.1  chopps 			if (lastpa == pa)
    340  1.1  chopps 				sc->sc_chain[n-1].len += max_t;
    341  1.1  chopps 			else
    342  1.1  chopps 				set_link(n, pa, max_t, SFAS_CHAIN_DMA);
    343  1.1  chopps 
    344  1.1  chopps 			lastpa = pa+max_t;
    345  1.1  chopps 
    346  1.1  chopps 			ptr += max_t;
    347  1.1  chopps 			len -= max_t;
    348  1.1  chopps 		}
    349  1.1  chopps 
    350  1.1  chopps 		if (len)
    351  1.1  chopps 			set_link(n, (vm_offset_t)ptr, len, SFAS_CHAIN_BUMP);
    352  1.1  chopps 	}
    353  1.1  chopps 
    354  1.1  chopps 	return(n);
    355  1.1  chopps }
    356  1.1  chopps 
    357  1.1  chopps /* Turn on led */
    358  1.1  chopps void bzsc_led_dummy(struct sfas_softc *sc)
    359  1.1  chopps {
    360  1.1  chopps }
    361