Home | History | Annotate | Line # | Download | only in dev
atari5380.c revision 1.10
      1  1.10  thorpej /*	$NetBSD: atari5380.c,v 1.10 1996/03/17 01:26:42 thorpej Exp $	*/
      2   1.1      leo 
      3   1.1      leo /*
      4   1.1      leo  * Copyright (c) 1995 Leo Weppelman.
      5   1.1      leo  * All rights reserved.
      6   1.1      leo  *
      7   1.1      leo  * Redistribution and use in source and binary forms, with or without
      8   1.1      leo  * modification, are permitted provided that the following conditions
      9   1.1      leo  * are met:
     10   1.1      leo  * 1. Redistributions of source code must retain the above copyright
     11   1.1      leo  *    notice, this list of conditions and the following disclaimer.
     12   1.1      leo  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      leo  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      leo  *    documentation and/or other materials provided with the distribution.
     15   1.1      leo  * 3. All advertising materials mentioning features or use of this software
     16   1.1      leo  *    must display the following acknowledgement:
     17   1.1      leo  *      This product includes software developed by Leo Weppelman.
     18   1.1      leo  * 4. The name of the author may not be used to endorse or promote products
     19   1.1      leo  *    derived from this software without specific prior written permission
     20   1.1      leo  *
     21   1.1      leo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1      leo  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1      leo  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1      leo  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1      leo  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1      leo  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1      leo  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1      leo  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1      leo  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1      leo  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1      leo  */
     32   1.1      leo 
     33   1.1      leo #include <sys/param.h>
     34   1.1      leo #include <sys/systm.h>
     35   1.1      leo #include <sys/kernel.h>
     36   1.1      leo #include <sys/device.h>
     37   1.1      leo #include <sys/buf.h>
     38   1.1      leo #include <scsi/scsi_all.h>
     39   1.1      leo #include <scsi/scsi_message.h>
     40   1.1      leo #include <scsi/scsiconf.h>
     41   1.1      leo 
     42   1.1      leo /*
     43   1.1      leo  * Include the driver definitions
     44   1.1      leo  */
     45   1.1      leo #include <atari/dev/ncr5380reg.h>
     46   1.1      leo 
     47   1.1      leo #include <machine/stdarg.h>
     48   1.1      leo #include <machine/iomap.h>
     49   1.1      leo #include <machine/mfp.h>
     50   1.1      leo 
     51   1.1      leo #if defined(FALCON_SCSI)
     52   1.1      leo #include <machine/dma.h>
     53   1.1      leo #endif
     54   1.1      leo 
     55   1.1      leo /*
     56   1.1      leo  * Set the various driver options
     57   1.1      leo  */
     58   1.1      leo #define	NREQ		18	/* Size of issue queue			*/
     59   1.1      leo #define	AUTO_SENSE	1	/* Automatically issue a request-sense 	*/
     60   1.1      leo 
     61   1.2      leo #define	DRNAME		ncrscsi	/* used in various prints		*/
     62   1.1      leo #undef	DBG_SEL			/* Show the selection process		*/
     63   1.1      leo #undef	DBG_REQ			/* Show enqueued/ready requests		*/
     64   1.2      leo #undef	DBG_ERR_RET		/* Show requests with != 0 return code	*/
     65   1.1      leo #undef	DBG_NOWRITE		/* Do not allow writes to the targets	*/
     66   1.1      leo #undef	DBG_PIO			/* Show the polled-I/O process		*/
     67   1.1      leo #undef	DBG_INF			/* Show information transfer process	*/
     68   1.1      leo #define	DBG_NOSTATIC		/* No static functions, all in DDB trace*/
     69   1.7      leo #define	DBG_PID		25	/* Keep track of driver			*/
     70   1.1      leo #define	REAL_DMA		/* Use DMA if sensible			*/
     71   1.1      leo #if defined(FALCON_SCSI)
     72   1.1      leo #define	REAL_DMA_POLL	1	/* 1: Poll for end of DMA-transfer	*/
     73   1.1      leo #else
     74   1.1      leo #define	REAL_DMA_POLL	0	/* 1: Poll for end of DMA-transfer	*/
     75   1.1      leo #endif
     76   1.1      leo #undef	USE_PDMA		/* Use special pdma-transfer function	*/
     77   1.4      leo #define MIN_PHYS	65536	/*BARF!!!!*/
     78   1.1      leo 
     79   1.1      leo /*
     80   1.8      leo  * Include more driver definitions
     81   1.8      leo  */
     82   1.8      leo #include <atari/dev/ncr5380var.h>
     83   1.8      leo 
     84   1.8      leo 
     85   1.8      leo /*
     86   1.8      leo  * This is crap, but because the interrupts now run at MFP spl-level (6),
     87   1.8      leo  * splbio() is not enough at some places. The code should be checked to
     88   1.8      leo  * find out where splhigh() is needed and where splbio() should be used.
     89   1.8      leo  * Now that I use this interrupt sceme, the spl values are fake!
     90   1.8      leo  */
     91   1.8      leo #undef splbio()
     92   1.8      leo #define splbio()	splhigh()
     93   1.8      leo 
     94   1.8      leo /*
     95   1.1      leo  * The atari specific driver options
     96   1.1      leo  */
     97   1.1      leo #undef	NO_TTRAM_DMA		/* Do not use DMA to TT-ram. This	*/
     98   1.1      leo 				/*    fails on older atari's		*/
     99   1.1      leo #define	ENABLE_NCR5380(sc)	cur_softc = sc;
    100   1.1      leo 
    101   1.9      leo static u_char	*alloc_bounceb __P((u_long));
    102   1.9      leo static void	free_bounceb __P((u_char *));
    103  1.10  thorpej static int	machine_match __P((struct device *, void *, void *,
    104   1.9      leo 							struct cfdriver *));
    105   1.9      leo        void	scsi_ctrl __P((int));
    106   1.9      leo        void	scsi_dma __P((int));
    107   1.9      leo 
    108   1.3      leo /*
    109   1.3      leo  * Functions that do nothing on the atari
    110   1.3      leo  */
    111   1.3      leo #define	pdma_ready()		0
    112   1.1      leo 
    113   1.1      leo #if defined(TT_SCSI)
    114   1.1      leo /*
    115   1.1      leo  * Define all the things we need of the DMA-controller
    116   1.1      leo  */
    117   1.1      leo #define	SCSI_DMA	((struct scsi_dma *)AD_SCSI_DMA)
    118   1.1      leo #define	SCSI_5380	((struct scsi_5380 *)AD_NCR5380)
    119   1.1      leo 
    120   1.1      leo struct scsi_dma {
    121   1.1      leo 	volatile u_char		s_dma_ptr[8];	/* use only the odd bytes */
    122   1.1      leo 	volatile u_char		s_dma_cnt[8];	/* use only the odd bytes */
    123   1.1      leo 	volatile u_char		s_dma_res[4];	/* data residue register  */
    124   1.1      leo 	volatile u_char		s_dma_gap;	/* not used		  */
    125   1.1      leo 	volatile u_char		s_dma_ctrl;	/* control register	  */
    126   1.1      leo };
    127   1.1      leo 
    128   1.1      leo #define	set_scsi_dma(addr, val)	(void)(					\
    129   1.1      leo 	{								\
    130   1.1      leo 	u_char	*address = (u_char*)addr+1;				\
    131   1.1      leo 	u_long	nval	 = (u_long)val;					\
    132   1.1      leo 	__asm("movepl	%0, %1@(0)": :"d" (nval), "a" (address));	\
    133   1.1      leo 	})
    134   1.1      leo 
    135   1.1      leo #define	get_scsi_dma(addr, res)	(					\
    136   1.1      leo 	{								\
    137   1.1      leo 	u_char	*address = (u_char*)addr+1;				\
    138   1.1      leo 	u_long	nval;							\
    139   1.1      leo 	__asm("movepl	%1@(0), %0": "=d" (nval) : "a" (address));	\
    140   1.1      leo 	res = (u_long)nval;						\
    141   1.1      leo 	})
    142   1.1      leo 
    143   1.1      leo /*
    144   1.1      leo  * Defines for TT-DMA control register
    145   1.1      leo  */
    146   1.1      leo #define	SD_BUSERR	0x80		/* 1 = transfer caused bus error*/
    147   1.1      leo #define	SD_ZERO		0x40		/* 1 = byte counter is zero	*/
    148   1.1      leo #define	SD_ENABLE	0x02		/* 1 = Enable DMA		*/
    149   1.1      leo #define	SD_OUT		0x01		/* Direction: memory to SCSI	*/
    150   1.1      leo #define	SD_IN		0x00		/* Direction: SCSI to memory	*/
    151   1.1      leo 
    152   1.1      leo /*
    153   1.1      leo  * Define the 5380 register set
    154   1.1      leo  */
    155   1.1      leo struct scsi_5380 {
    156   1.1      leo 	volatile u_char	scsi_5380[16];	/* use only the odd bytes	*/
    157   1.1      leo };
    158   1.1      leo #endif /* TT_SCSI */
    159   1.1      leo 
    160   1.1      leo /**********************************************
    161   1.1      leo  * Variables present for both TT and Falcon.  *
    162   1.1      leo  **********************************************/
    163   1.1      leo 
    164   1.1      leo /*
    165   1.1      leo  * Softc of currently active controller (a bit of fake; we only have one)
    166   1.1      leo  */
    167   1.1      leo static struct ncr_softc	*cur_softc;
    168   1.1      leo 
    169   1.1      leo #if defined(TT_SCSI) && !defined(FALCON_SCSI)
    170   1.1      leo /*
    171   1.1      leo  * We can be more efficient for some functions when only TT_SCSI is selected
    172   1.1      leo  */
    173   1.1      leo #define	GET_5380_REG(rnum)	SCSI_5380->scsi_5380[(rnum << 1) | 1]
    174   1.1      leo #define	SET_5380_REG(rnum,val)	(SCSI_5380->scsi_5380[(rnum << 1) | 1] = val)
    175   1.1      leo 
    176   1.1      leo #define scsi_mach_init(sc)	scsi_tt_init(sc)
    177   1.1      leo #define scsi_ienable()		scsi_tt_ienable()
    178   1.1      leo #define scsi_idisable()		scsi_tt_idisable()
    179   1.1      leo #define	scsi_clr_ipend()	scsi_tt_clr_ipend()
    180   1.7      leo #define scsi_ipending()		(GET_5380_REG(NCR5380_DMSTAT) & SC_IRQ_SET)
    181   1.1      leo #define scsi_dma_setup(r,p,m)	scsi_tt_dmasetup(r, p, m)
    182   1.1      leo #define wrong_dma_range(r,d)	tt_wrong_dma_range(r, d)
    183   1.1      leo #define poll_edma(reqp)		tt_poll_edma(reqp)
    184   1.1      leo #define get_dma_result(r, b)	tt_get_dma_result(r, b)
    185   1.1      leo 
    186   1.1      leo #define fair_to_keep_dma()	1
    187   1.1      leo #define claimed_dma()		1
    188   1.1      leo #define reconsider_dma()
    189   1.1      leo 
    190   1.1      leo #endif /* defined(TT_SCSI) && !defined(FALCON_SCSI) */
    191   1.1      leo 
    192   1.1      leo #if defined(TT_SCSI)
    193   1.1      leo 
    194   1.1      leo /*
    195   1.9      leo  * Prototype functions defined below
    196   1.9      leo  */
    197   1.9      leo #ifdef NO_TTRAM_DMA
    198   1.9      leo static int tt_wrong_dma_range __P((SC_REQ *, struct dma_chain *));
    199   1.9      leo #endif
    200   1.9      leo static void	scsi_tt_init __P((struct ncr_softc *));
    201   1.9      leo static u_char	get_tt_5380_reg __P((u_short));
    202   1.9      leo static void	set_tt_5380_reg __P((u_short, u_short));
    203   1.9      leo static void	scsi_tt_dmasetup __P((SC_REQ *, u_int, u_char));
    204   1.9      leo static int	tt_poll_edma __P((SC_REQ *));
    205   1.9      leo static u_char	*ptov __P((SC_REQ *, u_long*));
    206   1.9      leo static int	tt_get_dma_result __P((SC_REQ *, u_long *));
    207   1.9      leo        void	scsi_tt_ienable __P((void));
    208   1.9      leo        void	scsi_tt_idisable __P((void));
    209   1.9      leo        void	scsi_tt_clr_ipend __P((void));
    210   1.9      leo 
    211   1.9      leo /*
    212   1.1      leo  * Define these too, so we can use them locally...
    213   1.1      leo  */
    214   1.1      leo #define	GET_TT_REG(rnum)	SCSI_5380->scsi_5380[(rnum << 1) | 1]
    215   1.1      leo #define	SET_TT_REG(rnum,val)	(SCSI_5380->scsi_5380[(rnum << 1) | 1] = val)
    216   1.1      leo 
    217   1.1      leo #ifdef NO_TTRAM_DMA
    218   1.9      leo static int
    219   1.9      leo tt_wrong_dma_range(reqp, dm)
    220   1.1      leo SC_REQ			*reqp;
    221   1.1      leo struct dma_chain	*dm;
    222   1.1      leo {
    223   1.1      leo 	if (dm->dm_addr & 0xff000000) {
    224   1.1      leo 		reqp->dr_flag |= DRIVER_BOUNCING;
    225   1.1      leo 		return(1);
    226   1.1      leo 	}
    227   1.1      leo 	return(0);
    228   1.1      leo }
    229   1.1      leo #else
    230   1.1      leo #define	tt_wrong_dma_range(reqp, dm)	0
    231   1.1      leo #endif
    232   1.1      leo 
    233   1.9      leo static void
    234   1.9      leo scsi_tt_init(struct ncr_softc *sc)
    235   1.1      leo {
    236   1.1      leo 	/*
    237   1.1      leo 	 * Enable SCSI-related interrupts
    238   1.1      leo 	 */
    239   1.1      leo 	MFP2->mf_aer  |= 0x80;		/* SCSI IRQ goes HIGH!!!!!	*/
    240   1.1      leo 
    241   1.1      leo 	MFP2->mf_ierb |= IB_SCDM;	/* SCSI-dma interrupts		*/
    242   1.1      leo 	MFP2->mf_iprb &= ~IB_SCDM;
    243   1.1      leo 	MFP2->mf_imrb |= IB_SCDM;
    244   1.1      leo 
    245   1.1      leo 	MFP2->mf_iera |= IA_SCSI;	/* SCSI-5380 interrupts		*/
    246   1.1      leo 	MFP2->mf_ipra &= ~IA_SCSI;
    247   1.1      leo 	MFP2->mf_imra |= IA_SCSI;
    248   1.1      leo 
    249   1.1      leo 	/*
    250   1.1      leo 	 * LWP: DMA transfers to TT-ram causes data to be garbeled
    251   1.1      leo 	 * without notice on some revisons of the TT-mainboard.
    252   1.1      leo 	 * When program's generate misterious Segmentations faults,
    253   1.1      leo 	 * try turning on NO_TTRAM_DMA.
    254   1.1      leo 	 */
    255   1.1      leo #ifdef NO_TTRAM_DMA
    256   1.1      leo 	printf(": DMA to TT-RAM is disabled!");
    257   1.1      leo #endif
    258   1.1      leo }
    259   1.1      leo 
    260   1.9      leo static u_char
    261   1.9      leo get_tt_5380_reg(u_short rnum)
    262   1.1      leo {
    263   1.1      leo 	return(SCSI_5380->scsi_5380[(rnum << 1) | 1]);
    264   1.1      leo }
    265   1.1      leo 
    266   1.9      leo static void
    267   1.9      leo set_tt_5380_reg(u_short rnum, u_short val)
    268   1.1      leo {
    269   1.1      leo 	SCSI_5380->scsi_5380[(rnum << 1) | 1] = val;
    270   1.1      leo }
    271   1.1      leo 
    272   1.9      leo extern __inline__ void
    273   1.9      leo scsi_tt_ienable(void)
    274   1.1      leo {
    275   1.1      leo 	int	sps = splbio();
    276   1.1      leo 	MFP2->mf_ierb |= IB_SCDM;
    277   1.1      leo 	MFP2->mf_iera |= IA_SCSI;
    278   1.1      leo 	splx(sps);
    279   1.1      leo }
    280   1.1      leo 
    281   1.9      leo extern __inline__ void
    282   1.9      leo scsi_tt_idisable(void)
    283   1.1      leo {
    284   1.1      leo 	int	sps = splbio();
    285   1.1      leo 	MFP2->mf_ierb &= ~IB_SCDM;
    286   1.1      leo 	MFP2->mf_iera &= ~IA_SCSI;
    287   1.1      leo 	splx(sps);
    288   1.1      leo }
    289   1.1      leo 
    290   1.9      leo extern __inline__ void
    291   1.9      leo scsi_tt_clr_ipend(void)
    292   1.1      leo {
    293   1.1      leo 	int	tmp;
    294   1.1      leo 
    295   1.1      leo 	SCSI_DMA->s_dma_ctrl = 0;
    296   1.1      leo 	tmp = GET_TT_REG(NCR5380_IRCV);
    297   1.1      leo }
    298   1.1      leo 
    299   1.9      leo static void
    300   1.9      leo scsi_tt_dmasetup(SC_REQ *reqp, u_int phase, u_char	mode)
    301   1.1      leo {
    302   1.1      leo 	if (PH_IN(phase)) {
    303   1.1      leo 		SCSI_DMA->s_dma_ctrl = SD_IN;
    304   1.1      leo 		set_scsi_dma(&(SCSI_DMA->s_dma_ptr), reqp->dm_cur->dm_addr);
    305   1.1      leo 		set_scsi_dma(&(SCSI_DMA->s_dma_cnt), reqp->dm_cur->dm_count);
    306   1.1      leo 		SET_TT_REG(NCR5380_ICOM, 0);
    307   1.1      leo 		SET_TT_REG(NCR5380_MODE, mode);
    308   1.1      leo 		SCSI_DMA->s_dma_ctrl = SD_ENABLE;
    309   1.1      leo 		SET_TT_REG(NCR5380_IRCV, 0);
    310   1.1      leo 	}
    311   1.1      leo 	else {
    312   1.1      leo 		SCSI_DMA->s_dma_ctrl = SD_OUT;
    313   1.1      leo 		set_scsi_dma(&(SCSI_DMA->s_dma_ptr), reqp->dm_cur->dm_addr);
    314   1.1      leo 		set_scsi_dma(&(SCSI_DMA->s_dma_cnt), reqp->dm_cur->dm_count);
    315   1.1      leo 		SET_TT_REG(NCR5380_MODE, mode);
    316   1.1      leo 		SET_TT_REG(NCR5380_ICOM, SC_ADTB);
    317   1.1      leo 		SET_TT_REG(NCR5380_DMSTAT, 0);
    318   1.1      leo 		SCSI_DMA->s_dma_ctrl = SD_ENABLE|SD_OUT;
    319   1.1      leo 	}
    320   1.1      leo }
    321   1.1      leo 
    322   1.1      leo static int
    323   1.8      leo tt_poll_edma(SC_REQ *reqp)
    324   1.1      leo {
    325   1.1      leo 	u_char	dmstat, dmastat;
    326   1.1      leo 	int	timeout = 9000; /* XXX */
    327   1.1      leo 
    328   1.1      leo 	/*
    329   1.1      leo 	 * We wait here until the DMA has finished. This can be
    330   1.1      leo 	 * achieved by checking the following conditions:
    331   1.1      leo 	 *   - 5380:
    332   1.1      leo 	 *	- End of DMA flag is set
    333   1.1      leo 	 *	- We lost BSY (error!!)
    334   1.1      leo 	 *	- A phase mismatch has occured (partial transfer)
    335   1.1      leo 	 *   - DMA-controller:
    336   1.1      leo 	 *	- A bus error occurred (Kernel error!!)
    337   1.1      leo 	 *	- All bytes are transferred
    338   1.1      leo 	 * If one of the terminating conditions was met, we call
    339   1.1      leo 	 * 'dma_ready' to check errors and perform the bookkeeping.
    340   1.1      leo 	 */
    341   1.1      leo 
    342   1.1      leo 	for (;;) {
    343   1.1      leo 		delay(20);
    344   1.1      leo 		if (--timeout <= 0) {
    345   1.1      leo 			ncr_tprint(reqp, "timeout on polled transfer\n");
    346   1.1      leo 			reqp->xs->error = XS_DRIVER_STUFFUP;
    347   1.1      leo 			return(0);
    348   1.1      leo 		}
    349   1.1      leo 		dmstat  = GET_TT_REG(NCR5380_DMSTAT);
    350   1.1      leo 		dmastat = SCSI_DMA->s_dma_ctrl;
    351   1.1      leo 		if (dmstat & (SC_END_DMA|SC_BSY_ERR|SC_IRQ_SET))
    352   1.1      leo 			break;
    353   1.1      leo 		if (!(dmstat & SC_PHS_MTCH))
    354   1.1      leo 			break;
    355   1.1      leo 		if (dmastat & (SD_BUSERR|SD_ZERO))
    356   1.1      leo 			break;
    357   1.1      leo 	}
    358   1.1      leo 	return(1);
    359   1.1      leo }
    360   1.1      leo 
    361   1.2      leo /*
    362   1.2      leo  * Convert physical DMA address to a virtual address.
    363   1.2      leo  */
    364   1.2      leo static u_char *
    365   1.8      leo ptov(SC_REQ *reqp, u_long *phaddr)
    366   1.2      leo {
    367   1.2      leo 	struct dma_chain	*dm;
    368   1.2      leo 	u_char			*vaddr;
    369   1.2      leo 
    370   1.2      leo 	dm = reqp->dm_chain;
    371   1.2      leo 	vaddr = reqp->xdata_ptr;
    372   1.2      leo 	for(; dm < reqp->dm_cur; dm++)
    373   1.2      leo 		vaddr += dm->dm_count;
    374   1.2      leo 	vaddr += (u_long)phaddr - dm->dm_addr;
    375   1.2      leo 	return(vaddr);
    376   1.2      leo }
    377   1.2      leo 
    378   1.1      leo static int
    379   1.8      leo tt_get_dma_result(SC_REQ *reqp, u_long *bytes_left)
    380   1.1      leo {
    381   1.1      leo 	int	dmastat, dmstat;
    382   1.1      leo 	u_char	*byte_p;
    383   1.1      leo 	u_long	leftover;
    384   1.1      leo 
    385   1.1      leo 	dmastat = SCSI_DMA->s_dma_ctrl;
    386   1.1      leo 	dmstat  = GET_TT_REG(NCR5380_DMSTAT);
    387   1.1      leo 	get_scsi_dma(SCSI_DMA->s_dma_cnt, leftover);
    388   1.1      leo 	get_scsi_dma(SCSI_DMA->s_dma_ptr, (u_long)byte_p);
    389   1.1      leo 
    390   1.1      leo 	if (dmastat & SD_BUSERR) {
    391   1.1      leo 		/*
    392   1.1      leo 		 * The DMA-controller seems to access 8 bytes beyond
    393   1.1      leo 		 * it's limits on output. Therefore check also the byte
    394   1.1      leo 		 * count. If it's zero, ignore the bus error.
    395   1.1      leo 		 */
    396   1.1      leo 		if (leftover != 0) {
    397   1.1      leo 			ncr_tprint(reqp,
    398   1.1      leo 				"SCSI-DMA buserror - accessing 0x%x\n", byte_p);
    399   1.1      leo 			reqp->xs->error = XS_DRIVER_STUFFUP;
    400   1.1      leo 		}
    401   1.1      leo 	}
    402   1.1      leo 
    403   1.1      leo 	/*
    404   1.1      leo 	 * We handle the following special condition below:
    405   1.1      leo 	 *  -- The device disconnects in the middle of a write operation --
    406   1.1      leo 	 * In this case, the 5380 has already pre-fetched the next byte from
    407   1.1      leo 	 * the DMA-controller before the phase mismatch occurs. Therefore,
    408   1.1      leo 	 * leftover is 1 too low.
    409   1.1      leo 	 * This does not always happen! Therefore, we only do this when
    410   1.1      leo 	 * leftover is odd. This assumes that DMA transfers are _even_! This
    411   1.1      leo 	 * is normally the case on disks and types but might not always be.
    412   1.1      leo 	 * XXX: Check if ACK is consistently high on these occasions LWP
    413   1.1      leo 	 */
    414   1.1      leo 	if ((leftover & 1) && !(dmstat & SC_PHS_MTCH) && PH_OUT(reqp->phase))
    415   1.1      leo 		leftover++;
    416   1.1      leo 
    417   1.1      leo 	/*
    418   1.1      leo 	 * Check if there are some 'restbytes' left in the DMA-controller.
    419   1.1      leo 	 */
    420   1.1      leo 	if (((u_long)byte_p & 3) && PH_IN(reqp->phase)) {
    421   1.1      leo 		u_char	*p, *q;
    422   1.1      leo 
    423   1.8      leo 		p = ptov(reqp, (u_long *)((u_long)byte_p & ~3));
    424   1.1      leo 		q = (u_char*)&(SCSI_DMA->s_dma_res);
    425   1.2      leo 		switch ((u_long)byte_p & 3) {
    426   1.1      leo 			case 3: *p++ = *q++;
    427   1.1      leo 			case 2: *p++ = *q++;
    428   1.1      leo 			case 1: *p++ = *q++;
    429   1.1      leo 		}
    430   1.1      leo 	}
    431   1.1      leo 	*bytes_left = leftover;
    432   1.1      leo 	return ((dmastat & (SD_BUSERR|SD_ZERO)) ? 1 : 0);
    433   1.1      leo }
    434   1.1      leo 
    435   1.1      leo #endif /* defined(TT_SCSI) */
    436   1.1      leo 
    437   1.1      leo #if defined(FALCON_SCSI) && !defined(TT_SCSI)
    438   1.1      leo 
    439   1.1      leo #define	GET_5380_REG(rnum)	get_falcon_5380_reg(rnum)
    440   1.1      leo #define	SET_5380_REG(rnum,val)	set_falcon_5380_reg(rnum, val)
    441   1.1      leo #define scsi_mach_init(sc)	scsi_falcon_init(sc)
    442   1.1      leo #define scsi_ienable()		scsi_falcon_ienable()
    443   1.1      leo #define scsi_idisable()		scsi_falcon_idisable()
    444   1.1      leo #define	scsi_clr_ipend()	scsi_falcon_clr_ipend()
    445   1.7      leo #define	scsi_ipending()		scsi_falcon_ipending()
    446   1.1      leo #define scsi_dma_setup(r,p,m)	scsi_falcon_dmasetup(r, p, m)
    447   1.1      leo #define wrong_dma_range(r,d)	falcon_wrong_dma_range(r, d)
    448   1.1      leo #define poll_edma(reqp)		falcon_poll_edma(reqp)
    449   1.1      leo #define get_dma_result(r, b)	falcon_get_dma_result(r, b)
    450   1.1      leo 
    451   1.1      leo #define fair_to_keep_dma()	(!st_dmawanted())
    452   1.1      leo #define claimed_dma()		falcon_claimed_dma()
    453   1.1      leo #define reconsider_dma()	falcon_reconsider_dma()
    454   1.1      leo 
    455   1.1      leo #endif /* defined(FALCON_SCSI) && !defined(TT_SCSI) */
    456   1.1      leo 
    457   1.1      leo #if defined(FALCON_SCSI)
    458   1.1      leo 
    459   1.9      leo /*
    460   1.9      leo  * Prototype functions defined below
    461   1.9      leo  */
    462   1.9      leo static void	fscsi_int __P((void));
    463   1.9      leo static void	scsi_falcon_init __P((struct ncr_softc *));
    464   1.9      leo static u_char	get_falcon_5380_reg __P((u_short));
    465   1.9      leo static void	set_falcon_5380_reg __P((u_short, u_short));
    466   1.9      leo static int	falcon_wrong_dma_range __P((SC_REQ *, struct dma_chain *));
    467   1.9      leo static void	fal1_dma __P((u_int, u_int, SC_REQ *));
    468   1.9      leo static void	scsi_falcon_dmasetup __P((SC_REQ  *, u_int, u_char));
    469   1.9      leo static int	falcon_poll_edma __P((SC_REQ  *));
    470   1.9      leo static int	falcon_get_dma_result __P((SC_REQ  *, u_long *));
    471   1.9      leo        void	scsi_falcon_ienable __P((void));
    472   1.9      leo        void	scsi_falcon_idisable __P((void));
    473   1.9      leo        void	scsi_falcon_clr_ipend __P((void));
    474   1.9      leo        int scsi_falcon_ipending __P((void));
    475   1.9      leo        int falcon_claimed_dma __P((void));
    476   1.9      leo        void falcon_reconsider_dma __P((void));
    477   1.1      leo 
    478   1.9      leo static void
    479   1.9      leo scsi_falcon_init(sc)
    480   1.1      leo struct ncr_softc	*sc;
    481   1.1      leo {
    482   1.1      leo 	/*
    483   1.1      leo 	 * Enable disk related interrupts
    484   1.1      leo 	 */
    485   1.1      leo 	MFP->mf_ierb  |= IB_DINT;
    486   1.1      leo 	MFP->mf_iprb  &= ~IB_DINT;
    487   1.1      leo 	MFP->mf_imrb  |= IB_DINT;
    488   1.1      leo }
    489   1.1      leo 
    490   1.9      leo static u_char
    491   1.9      leo get_falcon_5380_reg(rnum)
    492   1.1      leo u_short	rnum;
    493   1.1      leo {
    494   1.1      leo 	DMA->dma_mode = DMA_SCSI + rnum;
    495   1.1      leo 	return(DMA->dma_data);
    496   1.1      leo }
    497   1.1      leo 
    498   1.9      leo static void
    499   1.9      leo set_falcon_5380_reg(rnum, val)
    500   1.1      leo u_short	rnum, val;
    501   1.1      leo {
    502   1.1      leo 	DMA->dma_mode = DMA_SCSI + rnum;
    503   1.1      leo 	DMA->dma_data = val;
    504   1.1      leo }
    505   1.1      leo 
    506   1.9      leo extern __inline__ void
    507   1.9      leo scsi_falcon_ienable()
    508   1.1      leo {
    509   1.1      leo 	MFP->mf_ierb  |= IB_DINT;
    510   1.1      leo }
    511   1.1      leo 
    512   1.9      leo extern __inline__ void
    513   1.9      leo scsi_falcon_idisable()
    514   1.1      leo {
    515   1.1      leo 	MFP->mf_ierb  &= ~IB_DINT;
    516   1.1      leo }
    517   1.1      leo 
    518   1.9      leo extern __inline__ void
    519   1.9      leo scsi_falcon_clr_ipend()
    520   1.1      leo {
    521   1.1      leo 	int	tmp;
    522   1.1      leo 
    523   1.1      leo 	tmp = get_falcon_5380_reg(NCR5380_IRCV);
    524   1.1      leo }
    525   1.1      leo 
    526   1.9      leo extern __inline__ int
    527   1.9      leo scsi_falcon_ipending()
    528   1.7      leo {
    529   1.7      leo 	return(!(MFP->mf_gpip & IO_DINT)
    530   1.7      leo 		&& (get_falcon_5380_reg(NCR5380_DMSTAT) & SC_IRQ_SET));
    531   1.7      leo }
    532   1.7      leo 
    533   1.9      leo static int
    534   1.9      leo falcon_wrong_dma_range(reqp, dm)
    535   1.1      leo SC_REQ			*reqp;
    536   1.1      leo struct dma_chain	*dm;
    537   1.1      leo {
    538   1.1      leo 	/*
    539   1.1      leo 	 * Do not allow chains yet! See also comment with
    540   1.1      leo 	 * falcon_poll_edma() !!!
    541   1.1      leo 	 */
    542   1.1      leo 	if (((dm - reqp->dm_chain) > 0) || (dm->dm_addr & 0xff000000)) {
    543   1.1      leo 		reqp->dr_flag |= DRIVER_BOUNCING;
    544   1.1      leo 		return(1);
    545   1.1      leo 	}
    546   1.2      leo 	/*
    547   1.2      leo 	 * Never allow DMA to happen on a Falcon when the transfer
    548   1.2      leo 	 * size is no multiple of 512. This is the transfer unit of the
    549   1.2      leo 	 * ST DMA-controller.
    550   1.2      leo 	 */
    551   1.2      leo 	if(dm->dm_count & 511)
    552   1.2      leo 		return(1);
    553   1.1      leo 	return(0);
    554   1.1      leo }
    555   1.1      leo 
    556   1.1      leo static	int falcon_lock = 0;
    557   1.1      leo 
    558   1.9      leo extern __inline__ int
    559   1.9      leo falcon_claimed_dma()
    560   1.1      leo {
    561   1.1      leo 	if (!(falcon_lock & DMA_LOCK_GRANT)) {
    562   1.1      leo 		if (falcon_lock) {
    563   1.1      leo 			/*
    564   1.1      leo 			 * DMA access is being claimed.
    565   1.1      leo 			 */
    566   1.1      leo 			return(0);
    567   1.1      leo 		}
    568   1.9      leo 		if (!st_dmagrab((dma_farg)fscsi_int, (dma_farg)run_main,
    569   1.9      leo 						&connected,&falcon_lock,1))
    570   1.1      leo 			return(0);
    571   1.1      leo 	}
    572   1.1      leo 	return(1);
    573   1.1      leo }
    574   1.1      leo 
    575   1.9      leo extern __inline__ void
    576   1.9      leo falcon_reconsider_dma()
    577   1.1      leo {
    578   1.1      leo 	if (falcon_lock && (connected == NULL) && (discon_q == NULL)) {
    579   1.1      leo 		/*
    580   1.1      leo 		 * No need to keep DMA locked by us as we are not currently
    581   1.1      leo 		 * connected and no disconnected jobs are pending.
    582   1.1      leo 		 */
    583   1.1      leo 		st_dmafree(&connected, &falcon_lock);
    584   1.1      leo 	}
    585   1.1      leo 
    586   1.1      leo 	if (!falcon_lock && (issue_q != NULL)) {
    587   1.1      leo 		/*
    588   1.1      leo 		 * We must (re)claim DMA access as there are jobs
    589   1.1      leo 		 * waiting in the issue queue.
    590   1.1      leo 		 */
    591   1.9      leo 		st_dmagrab((dma_farg)fscsi_int, (dma_farg)run_main,
    592   1.9      leo 						&connected, &falcon_lock, 0);
    593   1.1      leo 	}
    594   1.1      leo }
    595   1.1      leo 
    596   1.9      leo static void
    597   1.9      leo fal1_dma(dir, nsects, reqp)
    598   1.1      leo u_int	dir, nsects;
    599   1.1      leo SC_REQ	*reqp;
    600   1.1      leo {
    601   1.1      leo 	dir <<= 8;
    602   1.1      leo 	st_dmaaddr_set((caddr_t)reqp->dm_cur->dm_addr);
    603   1.1      leo 	DMA->dma_mode = 0x90 | dir;
    604   1.1      leo 	DMA->dma_mode = 0x90 | (dir ^ DMA_WRBIT);
    605   1.1      leo 	DMA->dma_mode = 0x90 | dir;
    606   1.1      leo 	DMA->dma_data = nsects;
    607   1.7      leo 	delay(2);	/* _really_ needed (Thomas Gerner) */
    608   1.1      leo 	DMA->dma_mode = 0x10 | dir;
    609   1.1      leo }
    610   1.1      leo 
    611   1.9      leo static void
    612   1.9      leo scsi_falcon_dmasetup(reqp, phase, mode)
    613   1.1      leo SC_REQ	*reqp;
    614   1.1      leo u_int	phase;
    615   1.1      leo u_char	mode;
    616   1.1      leo {
    617   1.1      leo 	int	nsects = reqp->dm_cur->dm_count / 512; /* XXX */
    618   1.1      leo 
    619   1.1      leo 	/*
    620   1.1      leo 	 * XXX: We should probably clear the fifo before putting the
    621   1.1      leo 	 *      5380 into DMA-mode.
    622   1.1      leo 	 */
    623   1.1      leo 	if (PH_IN(phase)) {
    624   1.1      leo 		set_falcon_5380_reg(NCR5380_ICOM, 0);
    625   1.1      leo 		set_falcon_5380_reg(NCR5380_MODE, mode);
    626   1.1      leo 		set_falcon_5380_reg(NCR5380_IRCV, 0);
    627   1.1      leo 		fal1_dma(0, nsects, reqp);
    628   1.1      leo 	}
    629   1.1      leo 	else {
    630   1.1      leo 		set_falcon_5380_reg(NCR5380_MODE, mode);
    631   1.1      leo 		set_falcon_5380_reg(NCR5380_ICOM, SC_ADTB);
    632   1.1      leo 		set_falcon_5380_reg(NCR5380_DMSTAT, 0);
    633   1.1      leo 		fal1_dma(1, nsects, reqp);
    634   1.1      leo 	}
    635   1.1      leo }
    636   1.1      leo 
    637   1.1      leo /*
    638   1.1      leo  * Falcon SCSI interrupt. _Always_ called at spl1!
    639   1.1      leo  */
    640   1.9      leo static void
    641   1.9      leo fscsi_int()
    642   1.1      leo {
    643   1.1      leo 	int	itype;
    644   1.1      leo 	int	dma_done;
    645   1.1      leo 
    646   1.7      leo 	if (scsi_falcon_ipending()) {
    647   1.1      leo 		scsi_falcon_idisable();
    648   1.1      leo 		ncr_ctrl_intr(cur_softc);
    649   1.1      leo 	}
    650   1.1      leo }
    651   1.1      leo 
    652   1.1      leo static int
    653   1.1      leo falcon_poll_edma(reqp)
    654   1.1      leo SC_REQ	*reqp;
    655   1.1      leo {
    656   1.1      leo 	int	timeout = 9000; /* XXX */
    657   1.1      leo 
    658   1.1      leo 	/*
    659   1.1      leo 	 * Because of the Falcon hardware, it is impossible to reach
    660   1.1      leo 	 * the 5380 while doing DMA-transfers. So we have to rely on
    661   1.1      leo 	 * the interrupt line to determine if DMA-has finished. the
    662   1.1      leo 	 * DMA-controller itself will never fire an interrupt. This means
    663   1.1      leo 	 * that 'broken-up' DMA transfers are not (yet) possible on the
    664   1.1      leo 	 * Falcon.
    665   1.1      leo 	 */
    666   1.1      leo 	for (;;) {
    667   1.1      leo 		delay(20);
    668   1.1      leo 		if (--timeout <= 0) {
    669   1.1      leo 			ncr_tprint(reqp, "Timeout on polled transfer\n");
    670   1.1      leo 			reqp->xs->error = XS_DRIVER_STUFFUP;
    671   1.1      leo 			return(0);
    672   1.1      leo 		}
    673   1.1      leo 		if (!(MFP->mf_gpip & IO_DINT))
    674   1.1      leo 			break;
    675   1.1      leo 	}
    676   1.1      leo 	return(1);
    677   1.1      leo }
    678   1.1      leo 
    679   1.1      leo static int
    680   1.1      leo falcon_get_dma_result(reqp, bytes_left)
    681   1.1      leo SC_REQ	*reqp;
    682   1.1      leo u_long	*bytes_left;
    683   1.1      leo {
    684   1.1      leo 	int	rv = 0;
    685   1.1      leo 	int	st_dmastat;
    686   1.1      leo 	u_long	bytes_done;
    687   1.1      leo 
    688   1.1      leo 	/*
    689   1.1      leo 	 * Select sector counter register first (See Atari docu.)
    690   1.1      leo 	 */
    691   1.1      leo 	DMA->dma_mode = 0x90;
    692   1.1      leo 	if (!(st_dmastat = DMA->dma_stat) & 0x01) {
    693   1.1      leo 		/*
    694   1.1      leo 		 * Misc. DMA-error according to Atari...
    695   1.1      leo 		 */
    696   1.1      leo 		ncr_tprint(reqp, "Unknow ST-SCSI error near 0x%x\n",
    697   1.1      leo 							st_dmaaddr_get());
    698   1.1      leo 		reqp->xs->error = XS_DRIVER_STUFFUP;
    699   1.1      leo 		rv = 1;
    700   1.1      leo 	}
    701   1.1      leo 	if (st_dmastat & 0x02) {
    702   1.1      leo 		/*
    703   1.1      leo 		 * Bytecount not zero.... As the fifo loads in 16 byte
    704   1.1      leo 		 * chunks, check if bytes are stuck in fifo.
    705   1.1      leo 		 * As we don't use DMA on chunks less than 512 bytes
    706   1.1      leo 		 * on the Falcon, report any residual not a multiple of
    707   1.1      leo 		 * 512 as an error...
    708   1.1      leo 		 */
    709   1.1      leo 		bytes_done = st_dmaaddr_get() - reqp->dm_cur->dm_addr;
    710   1.1      leo 		if (bytes_done & 511) {
    711   1.1      leo 			ncr_tprint(reqp, "Some bytes stuck in fifo\n");
    712   1.1      leo 			bytes_done &= ~511;
    713   1.1      leo 			reqp->xs->error = XS_DRIVER_STUFFUP;
    714   1.1      leo 		}
    715   1.1      leo 		*bytes_left = reqp->dm_cur->dm_count - bytes_done;
    716   1.1      leo 	}
    717   1.1      leo 	else {
    718   1.1      leo 		*bytes_left = 0;
    719   1.1      leo 		rv = 1;
    720   1.1      leo 	}
    721   1.1      leo 	return(rv);
    722   1.1      leo }
    723   1.1      leo 
    724   1.1      leo #endif /* defined(FALCON_SCSI) */
    725   1.1      leo 
    726   1.1      leo #if defined(TT_SCSI) && defined(FALCON_SCSI)
    727   1.1      leo /*
    728   1.1      leo  * Define some functions to support _both_ TT and Falcon SCSI
    729   1.1      leo  */
    730   1.1      leo 
    731   1.1      leo /*
    732   1.9      leo  * The prototypes first...
    733   1.9      leo  */
    734   1.9      leo static void	scsi_mach_init __P((struct ncr_softc *));
    735   1.9      leo        void	scsi_ienable __P((void));
    736   1.9      leo        void	scsi_idisable __P((void));
    737   1.9      leo        void	scsi_clr_ipend __P((void));
    738   1.9      leo        int	scsi_ipending __P((void));
    739   1.9      leo        void	scsi_dma_setup __P((SC_REQ *, u_int, u_char));
    740   1.9      leo        int	wrong_dma_range __P((SC_REQ *, struct dma_chain *));
    741   1.9      leo        int	poll_edma __P((SC_REQ *));
    742   1.9      leo        int	get_dma_result __P((SC_REQ *, u_long *));
    743   1.9      leo 
    744   1.9      leo /*
    745   1.1      leo  * Register access will be done through the following 2 function pointers.
    746   1.1      leo  */
    747   1.9      leo static u_char	(*get_5380_reg) __P((u_short));
    748   1.9      leo static void	(*set_5380_reg) __P((u_short, u_short));
    749   1.1      leo 
    750   1.1      leo #define	GET_5380_REG	(*get_5380_reg)
    751   1.1      leo #define	SET_5380_REG	(*set_5380_reg)
    752   1.1      leo 
    753   1.9      leo static void
    754   1.9      leo scsi_mach_init(sc)
    755   1.1      leo struct ncr_softc	*sc;
    756   1.1      leo {
    757   1.1      leo 	if (machineid & ATARI_FALCON) {
    758   1.1      leo 		get_5380_reg = get_falcon_5380_reg;
    759   1.1      leo 		set_5380_reg = set_falcon_5380_reg;
    760   1.1      leo 		scsi_falcon_init(sc);
    761   1.1      leo 	}
    762   1.1      leo 	else {
    763   1.1      leo 		get_5380_reg = get_tt_5380_reg;
    764   1.1      leo 		set_5380_reg = set_tt_5380_reg;
    765   1.1      leo 		scsi_tt_init(sc);
    766   1.1      leo 	}
    767   1.1      leo }
    768   1.1      leo 
    769   1.9      leo extern __inline__ void
    770   1.9      leo scsi_ienable()
    771   1.1      leo {
    772   1.1      leo 	if (machineid & ATARI_FALCON)
    773   1.1      leo 		scsi_falcon_ienable();
    774   1.1      leo 	else scsi_tt_ienable();
    775   1.1      leo }
    776   1.1      leo 
    777   1.9      leo extern __inline__ void
    778   1.9      leo scsi_idisable()
    779   1.1      leo {
    780   1.1      leo 	if (machineid & ATARI_FALCON)
    781   1.1      leo 		scsi_falcon_idisable();
    782   1.1      leo 	else scsi_tt_idisable();
    783   1.1      leo }
    784   1.1      leo 
    785   1.9      leo extern __inline__ void
    786   1.9      leo scsi_clr_ipend()
    787   1.1      leo {
    788   1.1      leo 	if (machineid & ATARI_FALCON)
    789   1.1      leo 		scsi_falcon_clr_ipend();
    790   1.1      leo 	else scsi_tt_clr_ipend();
    791   1.7      leo }
    792   1.7      leo 
    793   1.9      leo extern __inline__ int
    794   1.9      leo scsi_ipending()
    795   1.7      leo {
    796   1.7      leo 	if (machineid & ATARI_FALCON)
    797   1.7      leo 		return(scsi_falcon_ipending());
    798   1.7      leo 	else return (GET_TT_REG(NCR5380_DMSTAT) & SC_IRQ_SET);
    799   1.1      leo }
    800   1.1      leo 
    801   1.9      leo extern __inline__ void
    802   1.9      leo scsi_dma_setup(reqp, phase, mbase)
    803   1.1      leo SC_REQ	*reqp;
    804   1.1      leo u_int	phase;
    805   1.1      leo u_char	mbase;
    806   1.1      leo {
    807   1.1      leo 	if (machineid & ATARI_FALCON)
    808   1.1      leo 		scsi_falcon_dmasetup(reqp, phase, mbase);
    809   1.1      leo 	else scsi_tt_dmasetup(reqp, phase, mbase);
    810   1.1      leo }
    811   1.1      leo 
    812   1.9      leo extern __inline__ int
    813   1.9      leo wrong_dma_range(reqp, dm)
    814   1.1      leo SC_REQ			*reqp;
    815   1.1      leo struct dma_chain	*dm;
    816   1.1      leo {
    817   1.1      leo 	if (machineid & ATARI_FALCON)
    818   1.1      leo 		return(falcon_wrong_dma_range(reqp, dm));
    819   1.1      leo 	else return(tt_wrong_dma_range(reqp, dm));
    820   1.1      leo }
    821   1.1      leo 
    822   1.9      leo extern __inline__ int
    823   1.9      leo poll_edma(reqp)
    824   1.1      leo SC_REQ	*reqp;
    825   1.1      leo {
    826   1.1      leo 	if (machineid & ATARI_FALCON)
    827   1.1      leo 		return(falcon_poll_edma(reqp));
    828   1.1      leo 	else return(tt_poll_edma(reqp));
    829   1.1      leo }
    830   1.1      leo 
    831   1.9      leo extern __inline__ int
    832   1.9      leo get_dma_result(reqp, bytes_left)
    833   1.1      leo SC_REQ	*reqp;
    834   1.1      leo u_long	*bytes_left;
    835   1.1      leo {
    836   1.1      leo 	if (machineid & ATARI_FALCON)
    837   1.1      leo 		return(falcon_get_dma_result(reqp, bytes_left));
    838   1.1      leo 	else return(tt_get_dma_result(reqp, bytes_left));
    839   1.1      leo }
    840   1.1      leo 
    841   1.1      leo /*
    842   1.1      leo  * Locking stuff. All turns into NOP's on the TT.
    843   1.1      leo  */
    844   1.1      leo #define	fair_to_keep_dma()	((machineid & ATARI_FALCON) ?		\
    845   1.1      leo 						!st_dmawanted() : 1)
    846   1.1      leo #define	claimed_dma()		((machineid & ATARI_FALCON) ?		\
    847   1.1      leo 						falcon_claimed_dma() : 1)
    848   1.1      leo #define reconsider_dma()	{					\
    849   1.1      leo 					if(machineid & ATARI_FALCON)	\
    850   1.1      leo 						falcon_reconsider_dma();\
    851   1.1      leo 				}
    852   1.1      leo #endif /* defined(TT_SCSI) && defined(FALCON_SCSI) */
    853   1.1      leo 
    854   1.1      leo /**********************************************
    855   1.1      leo  * Functions present for both TT and Falcon.  *
    856   1.1      leo  **********************************************/
    857   1.1      leo /*
    858   1.1      leo  * Our autoconfig matching function
    859   1.1      leo  */
    860   1.1      leo static int
    861  1.10  thorpej machine_match(struct device *pdp, void *match, void *auxp,
    862   1.8      leo 						struct cfdriver *cd)
    863   1.1      leo {
    864  1.10  thorpej 	struct cfdata *cdp = match;
    865  1.10  thorpej 
    866   1.1      leo 	if (strcmp(auxp, cd->cd_name))
    867   1.1      leo 		return(0);
    868   1.1      leo 	if (cdp->cf_unit != 0)	/* Only one unit	*/
    869   1.1      leo 		return(0);
    870   1.1      leo 	return(1);
    871   1.1      leo }
    872   1.1      leo 
    873   1.1      leo /*
    874   1.1      leo  * Bounce buffer (de)allocation. Those buffers are gotten from the ST-mem
    875   1.1      leo  * pool. Allocation here is both contiguous and in the lower 16Mb of
    876   1.1      leo  * the address space. Thus being DMA-able for all controllers.
    877   1.1      leo  */
    878   1.1      leo static u_char *
    879   1.8      leo alloc_bounceb(u_long len)
    880   1.1      leo {
    881   1.1      leo 	u_long	tmp;
    882   1.1      leo 
    883   1.1      leo 	return((u_char *)alloc_stmem(len, &tmp));
    884   1.1      leo }
    885   1.1      leo 
    886   1.1      leo static void
    887   1.8      leo free_bounceb(u_char *bounceb)
    888   1.1      leo {
    889   1.1      leo 	free_stmem(bounceb);
    890   1.1      leo }
    891   1.1      leo 
    892   1.1      leo /*
    893   1.1      leo  * 5380 interrupt.
    894   1.1      leo  */
    895   1.8      leo void
    896   1.8      leo scsi_ctrl(int sr)
    897   1.1      leo {
    898   1.1      leo 	if (GET_5380_REG(NCR5380_DMSTAT) & SC_IRQ_SET) {
    899   1.1      leo 		scsi_idisable();
    900   1.1      leo 		if (!BASEPRI(sr))
    901   1.1      leo 			add_sicallback(ncr_ctrl_intr, cur_softc, 0);
    902   1.1      leo 		else {
    903   1.1      leo 			spl1();
    904   1.1      leo 			ncr_ctrl_intr(cur_softc);
    905   1.1      leo 		}
    906   1.1      leo 	}
    907   1.1      leo }
    908   1.1      leo 
    909   1.1      leo /*
    910   1.1      leo  * DMA controller interrupt
    911   1.1      leo  */
    912   1.8      leo void
    913   1.8      leo scsi_dma(int sr)
    914   1.1      leo {
    915   1.1      leo 	SC_REQ	*reqp;
    916   1.1      leo 
    917   1.1      leo 	if ((reqp = connected) && (reqp->dr_flag & DRIVER_IN_DMA)) {
    918   1.1      leo 		scsi_idisable();
    919   1.1      leo 		if (!BASEPRI(sr))
    920   1.1      leo 			add_sicallback(ncr_dma_intr, cur_softc, 0);
    921   1.1      leo 		else {
    922   1.1      leo 			spl1();
    923   1.1      leo 			ncr_dma_intr(cur_softc);
    924   1.1      leo 		}
    925   1.1      leo 	}
    926   1.1      leo }
    927   1.1      leo 
    928   1.1      leo /*
    929   1.1      leo  * Last but not least... Include the general driver code
    930   1.1      leo  */
    931   1.6  mycroft #include <atari/dev/ncr5380.c>
    932