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