xref: /titanic_50/usr/src/uts/common/io/i8237A.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
28*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
29*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988, 1989 Intel Corp.			*/
32*7c478bd9Sstevel@tonic-gate /*	All Rights Reserved	*/
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * Set features for each architecture.  List of features:
38*7c478bd9Sstevel@tonic-gate  *	ADDR_32:	Address is 32 bits
39*7c478bd9Sstevel@tonic-gate  *	COUNT_24:	Count is 24 bits
40*7c478bd9Sstevel@tonic-gate  *	DMA_4CSCD:	DMA channel 4 is used for cascade of channels 0-3)
41*7c478bd9Sstevel@tonic-gate  *	DMA_INTR:	DMA interrupt is available (always with DMA_BUF_CHAIN)
42*7c478bd9Sstevel@tonic-gate  *	DMA_BUF_CHAIN:	DMA buffer chaining is available (always with DMA_INTR)
43*7c478bd9Sstevel@tonic-gate  *	MEM_TO_MEM:	Memory to memory transfers available
44*7c478bd9Sstevel@tonic-gate  *	NO_PROG_WIDTH:	Channel data width is NOT programmable
45*7c478bd9Sstevel@tonic-gate  *	SCATER_GATHER	Scatter-gather DMA is available (code not implemented)
46*7c478bd9Sstevel@tonic-gate  *	ISA_MODE	Standard ISA modes available
47*7c478bd9Sstevel@tonic-gate  *	EISA_EXT_MODE:	EISA extension modes available
48*7c478bd9Sstevel@tonic-gate  */
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate  * Address is 24 bits (default) with no carry between lo word and hi byte
52*7c478bd9Sstevel@tonic-gate  * Count is 16 bits (default)
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate #define	DMA_4CSCD
55*7c478bd9Sstevel@tonic-gate #define	NO_PROG_WIDTH
56*7c478bd9Sstevel@tonic-gate #define	ISA_MODE
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
59*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
60*7c478bd9Sstevel@tonic-gate #include <sys/disp.h>
61*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
62*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
63*7c478bd9Sstevel@tonic-gate #include <sys/dma_engine.h>
64*7c478bd9Sstevel@tonic-gate #include <sys/dma_i8237A.h>
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate #if defined(DEBUG)
67*7c478bd9Sstevel@tonic-gate #include <sys/promif.h>
68*7c478bd9Sstevel@tonic-gate static int i8237debug = 0;
69*7c478bd9Sstevel@tonic-gate #define	dprintf(x)	if (i8237debug) (void)prom_printf x
70*7c478bd9Sstevel@tonic-gate #else
71*7c478bd9Sstevel@tonic-gate #define	dprintf(x)
72*7c478bd9Sstevel@tonic-gate #endif	/* defined(DEBUG) */
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate extern int EISA_chaining;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate /*
78*7c478bd9Sstevel@tonic-gate  * data structures for maintaining the DMACs
79*7c478bd9Sstevel@tonic-gate  */
80*7c478bd9Sstevel@tonic-gate static kmutex_t dma_engine_lock;
81*7c478bd9Sstevel@tonic-gate static struct d37A_chan_reg_addr chan_addr[] = { D37A_BASE_REGS_VALUES };
82*7c478bd9Sstevel@tonic-gate static ushort_t d37A_chnl_path[] = {
83*7c478bd9Sstevel@tonic-gate 	DMAE_PATH_8,	/* first 4 DMA channels default to 8-bit xfers */
84*7c478bd9Sstevel@tonic-gate 	DMAE_PATH_8,
85*7c478bd9Sstevel@tonic-gate 	DMAE_PATH_8,
86*7c478bd9Sstevel@tonic-gate 	DMAE_PATH_8,
87*7c478bd9Sstevel@tonic-gate 	0,
88*7c478bd9Sstevel@tonic-gate 	DMAE_PATH_16,	/* last 3 DMA channels default to 16-bit xfers */
89*7c478bd9Sstevel@tonic-gate 	DMAE_PATH_16,
90*7c478bd9Sstevel@tonic-gate 	DMAE_PATH_16};
91*7c478bd9Sstevel@tonic-gate static ushort_t d37A_chnl_mode[] = {
92*7c478bd9Sstevel@tonic-gate 	DMAE_TRANS_SNGL, DMAE_TRANS_SNGL, DMAE_TRANS_SNGL, DMAE_TRANS_SNGL,
93*7c478bd9Sstevel@tonic-gate #ifdef DMA_4CSCD
94*7c478bd9Sstevel@tonic-gate 	DMAE_TRANS_CSCD,
95*7c478bd9Sstevel@tonic-gate #else 	/* !DMA_4CSCD */
96*7c478bd9Sstevel@tonic-gate 	DMAE_TRANS_SNGL,
97*7c478bd9Sstevel@tonic-gate #endif	/* !DMA_4CSCD */
98*7c478bd9Sstevel@tonic-gate 	DMAE_TRANS_SNGL, DMAE_TRANS_SNGL, DMAE_TRANS_SNGL};
99*7c478bd9Sstevel@tonic-gate #ifdef DMA_BUF_CHAIN
100*7c478bd9Sstevel@tonic-gate static ddi_dma_cookie_t *d37A_next_cookie[] =
101*7c478bd9Sstevel@tonic-gate 	{0, 0, 0, 0, 0, 0, 0, 0};
102*7c478bd9Sstevel@tonic-gate #endif	/* DMA_BUF_CHAIN */
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate #ifdef DMA_INTR
106*7c478bd9Sstevel@tonic-gate static uint_t d37A_intr(caddr_t);
107*7c478bd9Sstevel@tonic-gate #endif
108*7c478bd9Sstevel@tonic-gate static int d37A_set_mode(struct ddi_dmae_req *, int);
109*7c478bd9Sstevel@tonic-gate static int d37A_write_addr(ulong_t, int);
110*7c478bd9Sstevel@tonic-gate static ulong_t d37A_read_addr(int);
111*7c478bd9Sstevel@tonic-gate static int d37A_write_count(long, int);
112*7c478bd9Sstevel@tonic-gate static long d37A_read_count(int);
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate #ifdef DMA_BUF_CHAIN
115*7c478bd9Sstevel@tonic-gate static void dEISA_setchain(ddi_dma_cookie_t *cp, int chnl);
116*7c478bd9Sstevel@tonic-gate #endif
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate /*
119*7c478bd9Sstevel@tonic-gate  *  Routine: d37A_init()
120*7c478bd9Sstevel@tonic-gate  *  purpose: initializes the 8237A.
121*7c478bd9Sstevel@tonic-gate  *  caller:  dma_init()
122*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros, d37A_init()
123*7c478bd9Sstevel@tonic-gate  */
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
126*7c478bd9Sstevel@tonic-gate int
d37A_init(dev_info_t * dip)127*7c478bd9Sstevel@tonic-gate d37A_init(dev_info_t *dip)
128*7c478bd9Sstevel@tonic-gate {
129*7c478bd9Sstevel@tonic-gate #ifdef DMA_INTR
130*7c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t iblk_cookie = 0;
131*7c478bd9Sstevel@tonic-gate 	int	error;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 	if ((error = ddi_add_intr(dip, (uint_t)0, &iblk_cookie,
134*7c478bd9Sstevel@tonic-gate 	    (ddi_idevice_cookie_t *)0, d37A_intr, (caddr_t)NULL)) !=
135*7c478bd9Sstevel@tonic-gate 	    DDI_SUCCESS) {
136*7c478bd9Sstevel@tonic-gate 		if (error != DDI_INTR_NOTFOUND)
137*7c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN, "!d37A_init: cannot add dma intr\n");
138*7c478bd9Sstevel@tonic-gate 		EISA_chaining = 0;
139*7c478bd9Sstevel@tonic-gate 	}
140*7c478bd9Sstevel@tonic-gate 	mutex_init(&dma_engine_lock, NULL, MUTEX_DRIVER, (void *)iblk_cookie);
141*7c478bd9Sstevel@tonic-gate #else	/* !DMA_INTR */
142*7c478bd9Sstevel@tonic-gate 	mutex_init(&dma_engine_lock, NULL, MUTEX_DRIVER, NULL);
143*7c478bd9Sstevel@tonic-gate #endif	/* !DMA_INTR */
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate /*
149*7c478bd9Sstevel@tonic-gate  *  Routine: d37A_valid()
150*7c478bd9Sstevel@tonic-gate  *  purpose: validates the channel to be acquired.
151*7c478bd9Sstevel@tonic-gate  *  caller:  i_dmae_acquire()
152*7c478bd9Sstevel@tonic-gate  *  calls:
153*7c478bd9Sstevel@tonic-gate  */
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate int
d37A_dma_valid(int chnl)156*7c478bd9Sstevel@tonic-gate d37A_dma_valid(int chnl)
157*7c478bd9Sstevel@tonic-gate {
158*7c478bd9Sstevel@tonic-gate #ifdef DMA_4CSCD
159*7c478bd9Sstevel@tonic-gate 	if (chnl == 4)
160*7c478bd9Sstevel@tonic-gate 		return (0);
161*7c478bd9Sstevel@tonic-gate #endif	/* DMA_4CSCD */
162*7c478bd9Sstevel@tonic-gate 	return (1);
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate  *  Routine: d37A_release()
167*7c478bd9Sstevel@tonic-gate  *  purpose: resets the 8237A mode.
168*7c478bd9Sstevel@tonic-gate  *  caller:  i_dmae_free()
169*7c478bd9Sstevel@tonic-gate  *  calls:
170*7c478bd9Sstevel@tonic-gate  */
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate void
d37A_dma_release(int chnl)173*7c478bd9Sstevel@tonic-gate d37A_dma_release(int chnl)
174*7c478bd9Sstevel@tonic-gate {
175*7c478bd9Sstevel@tonic-gate #ifdef DMA_4CSCD
176*7c478bd9Sstevel@tonic-gate 	if (chnl == 4)
177*7c478bd9Sstevel@tonic-gate 		return;
178*7c478bd9Sstevel@tonic-gate #endif	/* DMA_4CSCD */
179*7c478bd9Sstevel@tonic-gate 	d37A_chnl_mode[chnl] = DMAE_TRANS_SNGL;
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate /*
183*7c478bd9Sstevel@tonic-gate  *  routine: d37A_dma_disable()
184*7c478bd9Sstevel@tonic-gate  *  purpose: Prevent the DMAC from responding to external hardware
185*7c478bd9Sstevel@tonic-gate  *		requests for DMA service on the given channel
186*7c478bd9Sstevel@tonic-gate  *  caller:  dma_disable()
187*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros
188*7c478bd9Sstevel@tonic-gate  */
189*7c478bd9Sstevel@tonic-gate void
d37A_dma_disable(int chnl)190*7c478bd9Sstevel@tonic-gate d37A_dma_disable(int chnl)
191*7c478bd9Sstevel@tonic-gate {
192*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_dma_disable: chnl=%d mask_reg=0x%x\n",
193*7c478bd9Sstevel@tonic-gate 	    chnl, chan_addr[chnl].mask_reg));
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].mask_reg, (chnl & 3) | DMA_SETMSK);
196*7c478bd9Sstevel@tonic-gate }
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate /*
200*7c478bd9Sstevel@tonic-gate  *  routine: d37A_dma_enable()
201*7c478bd9Sstevel@tonic-gate  *  purpose: Enable to DMAC to respond to hardware requests for DMA
202*7c478bd9Sstevel@tonic-gate  *		service on the specified channel.
203*7c478bd9Sstevel@tonic-gate  *  caller:  dma_enable()
204*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros
205*7c478bd9Sstevel@tonic-gate  */
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate void
d37A_dma_enable(int chnl)208*7c478bd9Sstevel@tonic-gate d37A_dma_enable(int chnl)
209*7c478bd9Sstevel@tonic-gate {
210*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_dma_enable: chnl=%d mask_reg=0x%x val=0x%x\n",
211*7c478bd9Sstevel@tonic-gate 	    chnl, chan_addr[chnl].mask_reg, chnl & 3));
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate /*	mutex_enter(&dma_engine_lock);	*/
214*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].mask_reg, chnl & 3);
215*7c478bd9Sstevel@tonic-gate /*	mutex_exit(&dma_engine_lock);	*/
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate /*
220*7c478bd9Sstevel@tonic-gate  *  routine: d37A_get_best_mode()
221*7c478bd9Sstevel@tonic-gate  *  purpose: stub routine - determine optimum transfer method
222*7c478bd9Sstevel@tonic-gate  *  caller:  dma_get_best_mode().
223*7c478bd9Sstevel@tonic-gate  *  calls:
224*7c478bd9Sstevel@tonic-gate  */
225*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
226*7c478bd9Sstevel@tonic-gate uchar_t
d37A_get_best_mode(struct ddi_dmae_req * dmaereqp)227*7c478bd9Sstevel@tonic-gate d37A_get_best_mode(struct ddi_dmae_req *dmaereqp)
228*7c478bd9Sstevel@tonic-gate {
229*7c478bd9Sstevel@tonic-gate 	return (DMAE_CYCLES_2);
230*7c478bd9Sstevel@tonic-gate }
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate #ifdef DMA_INTR
233*7c478bd9Sstevel@tonic-gate /*
234*7c478bd9Sstevel@tonic-gate  *  routine: d37A_intr()
235*7c478bd9Sstevel@tonic-gate  *  purpose: stub routine
236*7c478bd9Sstevel@tonic-gate  *  caller:
237*7c478bd9Sstevel@tonic-gate  *  calls:  dma_intr().
238*7c478bd9Sstevel@tonic-gate  */
239*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
240*7c478bd9Sstevel@tonic-gate static uint_t
d37A_intr(caddr_t arg)241*7c478bd9Sstevel@tonic-gate d37A_intr(caddr_t arg)
242*7c478bd9Sstevel@tonic-gate {
243*7c478bd9Sstevel@tonic-gate 	int chnl, istate, nstate;
244*7c478bd9Sstevel@tonic-gate 	uint_t mask;
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate 	if ((istate = (inb(EISA_DMAIS) & 0xef)) != 0) {
247*7c478bd9Sstevel@tonic-gate 		/* channel 4 can't interrupt */
248*7c478bd9Sstevel@tonic-gate 		chnl = 0;
249*7c478bd9Sstevel@tonic-gate 		nstate = istate;
250*7c478bd9Sstevel@tonic-gate 		mutex_enter(&dma_engine_lock);
251*7c478bd9Sstevel@tonic-gate 		do {
252*7c478bd9Sstevel@tonic-gate 			if (istate & 1) {
253*7c478bd9Sstevel@tonic-gate 				dEISA_setchain(d37A_next_cookie[chnl], chnl);
254*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
255*7c478bd9Sstevel@tonic-gate 				if (chnl < 4)
256*7c478bd9Sstevel@tonic-gate 					mask = inb(DMAC1_ALLMASK) >> (chnl);
257*7c478bd9Sstevel@tonic-gate 				else
258*7c478bd9Sstevel@tonic-gate 					mask = inb(DMAC2_ALLMASK) >> (chnl - 4);
259*7c478bd9Sstevel@tonic-gate 				if (mask & 1)
260*7c478bd9Sstevel@tonic-gate prom_printf("eisa: dma buffer chaining failure chnl %d!\n", chnl);
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
263*7c478bd9Sstevel@tonic-gate 			}
264*7c478bd9Sstevel@tonic-gate 			chnl++;
265*7c478bd9Sstevel@tonic-gate 			istate >>= 1;
266*7c478bd9Sstevel@tonic-gate 		} while (istate);
267*7c478bd9Sstevel@tonic-gate 		chnl = 0;
268*7c478bd9Sstevel@tonic-gate 		do {
269*7c478bd9Sstevel@tonic-gate 			if ((nstate & 1) && d37A_next_cookie[chnl])
270*7c478bd9Sstevel@tonic-gate 				d37A_next_cookie[chnl] = _dmae_nxcookie(chnl);
271*7c478bd9Sstevel@tonic-gate 			chnl++;
272*7c478bd9Sstevel@tonic-gate 			nstate >>= 1;
273*7c478bd9Sstevel@tonic-gate 		} while (nstate);
274*7c478bd9Sstevel@tonic-gate 		mutex_exit(&dma_engine_lock);
275*7c478bd9Sstevel@tonic-gate 		return (DDI_INTR_CLAIMED);
276*7c478bd9Sstevel@tonic-gate 	}
277*7c478bd9Sstevel@tonic-gate 	return (DDI_INTR_UNCLAIMED);
278*7c478bd9Sstevel@tonic-gate }
279*7c478bd9Sstevel@tonic-gate #endif	/* DMA_INTR */
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate #ifdef DMA_BUF_CHAIN
283*7c478bd9Sstevel@tonic-gate /*
284*7c478bd9Sstevel@tonic-gate  *  routine: dEISA_setchain()
285*7c478bd9Sstevel@tonic-gate  *  purpose: Set next buffer address/count from chain
286*7c478bd9Sstevel@tonic-gate  *  caller:  d37A_intr()
287*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros
288*7c478bd9Sstevel@tonic-gate  */
289*7c478bd9Sstevel@tonic-gate static void
dEISA_setchain(ddi_dma_cookie_t * cp,int chnl)290*7c478bd9Sstevel@tonic-gate dEISA_setchain(ddi_dma_cookie_t *cp, int chnl)
291*7c478bd9Sstevel@tonic-gate {
292*7c478bd9Sstevel@tonic-gate 	if (cp) {
293*7c478bd9Sstevel@tonic-gate 		dprintf(("dEISA_setchain: chnl=%d next_addr=%x count=%lx\n",
294*7c478bd9Sstevel@tonic-gate 		    chnl, cp->dmac_address, cp->dmac_size));
295*7c478bd9Sstevel@tonic-gate 		(void) d37A_write_addr(cp->dmac_address, chnl);
296*7c478bd9Sstevel@tonic-gate 		(void) d37A_write_count(cp->dmac_size, chnl);
297*7c478bd9Sstevel@tonic-gate 		outb(chan_addr[chnl].scm_reg, chnl | EISA_ENCM | EISA_CMOK);
298*7c478bd9Sstevel@tonic-gate 	} else {
299*7c478bd9Sstevel@tonic-gate 		/*
300*7c478bd9Sstevel@tonic-gate 		 *  clear chain enable bit
301*7c478bd9Sstevel@tonic-gate 		 */
302*7c478bd9Sstevel@tonic-gate 		outb(chan_addr[chnl].scm_reg, chnl);
303*7c478bd9Sstevel@tonic-gate 		dprintf(("dEISA_setchain: chnl=%d end\n", chnl));
304*7c478bd9Sstevel@tonic-gate 	}
305*7c478bd9Sstevel@tonic-gate }
306*7c478bd9Sstevel@tonic-gate #endif	/* DMA_BUF_CHAIN */
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate /*
310*7c478bd9Sstevel@tonic-gate  *  routine: d37A_prog_chan()
311*7c478bd9Sstevel@tonic-gate  *  purpose: program the Mode registers and the Base registers of a
312*7c478bd9Sstevel@tonic-gate  *		DMA channel for a subsequent hardware-initiated transfer.
313*7c478bd9Sstevel@tonic-gate  *  caller:  dma_prog_chan()
314*7c478bd9Sstevel@tonic-gate  *  calls:   d37A_write_addr(), d37A_write_count(), d37A macros.
315*7c478bd9Sstevel@tonic-gate  */
316*7c478bd9Sstevel@tonic-gate 
317*7c478bd9Sstevel@tonic-gate int
d37A_prog_chan(struct ddi_dmae_req * dmaereqp,ddi_dma_cookie_t * cp,int chnl)318*7c478bd9Sstevel@tonic-gate d37A_prog_chan(struct ddi_dmae_req *dmaereqp, ddi_dma_cookie_t *cp, int chnl)
319*7c478bd9Sstevel@tonic-gate {
320*7c478bd9Sstevel@tonic-gate 	if (d37A_chnl_mode[chnl] == DMAE_TRANS_CSCD) {
321*7c478bd9Sstevel@tonic-gate 		dprintf(("d37A_prog_chan err: chnl=%d in cascade mode\n",
322*7c478bd9Sstevel@tonic-gate 		    chnl));
323*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
324*7c478bd9Sstevel@tonic-gate 	}
325*7c478bd9Sstevel@tonic-gate #ifndef MEM_TO_MEM
326*7c478bd9Sstevel@tonic-gate 	if (dmaereqp && dmaereqp->der_dest == DMAE_DEST_MEM) {
327*7c478bd9Sstevel@tonic-gate dprintf(("d37A_prog_chan err: memory to memory mode not supported.\n"));
328*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
329*7c478bd9Sstevel@tonic-gate 	}
330*7c478bd9Sstevel@tonic-gate #endif	/* !MEM_TO_MEM */
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_prog_chan: chnl=%d dmaereq=%p\n",
333*7c478bd9Sstevel@tonic-gate 	    chnl, (void *)dmaereqp));
334*7c478bd9Sstevel@tonic-gate 
335*7c478bd9Sstevel@tonic-gate 	if (dmaereqp) {
336*7c478bd9Sstevel@tonic-gate 		switch (chnl) {
337*7c478bd9Sstevel@tonic-gate 		case DMAE_CH0:
338*7c478bd9Sstevel@tonic-gate 		case DMAE_CH1:
339*7c478bd9Sstevel@tonic-gate 		case DMAE_CH2:
340*7c478bd9Sstevel@tonic-gate 		case DMAE_CH3:
341*7c478bd9Sstevel@tonic-gate #ifdef NO_PROG_WIDTH
342*7c478bd9Sstevel@tonic-gate 			if (dmaereqp->der_path &&
343*7c478bd9Sstevel@tonic-gate 			    dmaereqp->der_path != DMAE_PATH_8) {
344*7c478bd9Sstevel@tonic-gate dprintf(("d37A_prog_chan err: chnl %d not programmed.\n", chnl));
345*7c478bd9Sstevel@tonic-gate 				return (DDI_FAILURE);
346*7c478bd9Sstevel@tonic-gate 			}
347*7c478bd9Sstevel@tonic-gate #endif	/* NO_PROG_WIDTH */
348*7c478bd9Sstevel@tonic-gate 			break;
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate #ifndef DMA_4CSCD
351*7c478bd9Sstevel@tonic-gate 		case DMAE_CH4:
352*7c478bd9Sstevel@tonic-gate #endif	/* !DMA_4CSCD */
353*7c478bd9Sstevel@tonic-gate 		case DMAE_CH5:
354*7c478bd9Sstevel@tonic-gate 		case DMAE_CH6:
355*7c478bd9Sstevel@tonic-gate 		case DMAE_CH7:
356*7c478bd9Sstevel@tonic-gate #ifdef NO_PROG_WIDTH
357*7c478bd9Sstevel@tonic-gate 			if (dmaereqp->der_path &&
358*7c478bd9Sstevel@tonic-gate 			    dmaereqp->der_path != DMAE_PATH_16) {
359*7c478bd9Sstevel@tonic-gate dprintf(("d37A_prog_chan err: chnl %d not programmed.\n", chnl));
360*7c478bd9Sstevel@tonic-gate 				return (DDI_FAILURE);
361*7c478bd9Sstevel@tonic-gate 			}
362*7c478bd9Sstevel@tonic-gate #endif	/* NO_PROG_WIDTH */
363*7c478bd9Sstevel@tonic-gate 			break;
364*7c478bd9Sstevel@tonic-gate 
365*7c478bd9Sstevel@tonic-gate 		default:
366*7c478bd9Sstevel@tonic-gate dprintf(("d37A_prog_chan err: chnl %d not programmed.\n", chnl));
367*7c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
368*7c478bd9Sstevel@tonic-gate 		}
369*7c478bd9Sstevel@tonic-gate 	} else
370*7c478bd9Sstevel@tonic-gate 		chnl &= 3;
371*7c478bd9Sstevel@tonic-gate 	mutex_enter(&dma_engine_lock);
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate 	d37A_dma_disable(chnl);
374*7c478bd9Sstevel@tonic-gate 	if (dmaereqp)
375*7c478bd9Sstevel@tonic-gate 		(void) d37A_set_mode(dmaereqp, chnl);
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 	if (cp) {
378*7c478bd9Sstevel@tonic-gate 		(void) d37A_write_addr(cp->dmac_address, chnl);
379*7c478bd9Sstevel@tonic-gate 		(void) d37A_write_count(cp->dmac_size, chnl);
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate #ifdef DMA_BUF_CHAIN
382*7c478bd9Sstevel@tonic-gate 		if (dmaereqp && dmaereqp->der_bufprocess == DMAE_BUF_CHAIN &&
383*7c478bd9Sstevel@tonic-gate 		    (d37A_next_cookie[chnl] = _dmae_nxcookie(chnl))) {
384*7c478bd9Sstevel@tonic-gate 			/*
385*7c478bd9Sstevel@tonic-gate 			 * i/o operation has more than 1 cookie
386*7c478bd9Sstevel@tonic-gate 			 * so enable dma buffer chaining
387*7c478bd9Sstevel@tonic-gate 			 */
388*7c478bd9Sstevel@tonic-gate 			drv_usecwait(10);
389*7c478bd9Sstevel@tonic-gate 			outb(chan_addr[chnl].scm_reg, chnl | EISA_ENCM);
390*7c478bd9Sstevel@tonic-gate 			drv_usecwait(15);
391*7c478bd9Sstevel@tonic-gate 			dEISA_setchain(d37A_next_cookie[chnl], chnl);
392*7c478bd9Sstevel@tonic-gate 			d37A_next_cookie[chnl] = _dmae_nxcookie(chnl);
393*7c478bd9Sstevel@tonic-gate 		}
394*7c478bd9Sstevel@tonic-gate #endif	/* DMA_BUF_CHAIN */
395*7c478bd9Sstevel@tonic-gate 	}
396*7c478bd9Sstevel@tonic-gate 	mutex_exit(&dma_engine_lock);
397*7c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
398*7c478bd9Sstevel@tonic-gate }
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate 
401*7c478bd9Sstevel@tonic-gate /*
402*7c478bd9Sstevel@tonic-gate  *  routine: d37A_dma_swsetup()
403*7c478bd9Sstevel@tonic-gate  *  purpose: program the Mode registers and the Base register for the
404*7c478bd9Sstevel@tonic-gate  *		specified channel.
405*7c478bd9Sstevel@tonic-gate  *  caller:  dma_swsetup()
406*7c478bd9Sstevel@tonic-gate  *  calls:   d37A_write_addr(), d37A_write_count(), d37A macros.
407*7c478bd9Sstevel@tonic-gate  */
408*7c478bd9Sstevel@tonic-gate 
409*7c478bd9Sstevel@tonic-gate int
d37A_dma_swsetup(struct ddi_dmae_req * dmaereqp,ddi_dma_cookie_t * cp,int chnl)410*7c478bd9Sstevel@tonic-gate d37A_dma_swsetup(struct ddi_dmae_req *dmaereqp, ddi_dma_cookie_t *cp, int chnl)
411*7c478bd9Sstevel@tonic-gate {
412*7c478bd9Sstevel@tonic-gate 	if (d37A_chnl_mode[chnl] == DMAE_TRANS_CSCD) {
413*7c478bd9Sstevel@tonic-gate 		dprintf(("d37A_dma_swsetup err: chnl %d not programmed\n",
414*7c478bd9Sstevel@tonic-gate 		    chnl));
415*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
416*7c478bd9Sstevel@tonic-gate 	}
417*7c478bd9Sstevel@tonic-gate 
418*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_dma_swsetup: chnl=%d dmaereq=%p.\n",
419*7c478bd9Sstevel@tonic-gate 	    chnl, (void *)dmaereqp));
420*7c478bd9Sstevel@tonic-gate 
421*7c478bd9Sstevel@tonic-gate 	/* MUST BE IN BLOCK MODE FOR SOFTWARE INITIATED REQUESTS */
422*7c478bd9Sstevel@tonic-gate 	if (dmaereqp->der_trans != DMAE_TRANS_BLCK)
423*7c478bd9Sstevel@tonic-gate 		dmaereqp->der_trans = DMAE_TRANS_BLCK;
424*7c478bd9Sstevel@tonic-gate 
425*7c478bd9Sstevel@tonic-gate 	switch (chnl) {
426*7c478bd9Sstevel@tonic-gate 	case DMAE_CH0:
427*7c478bd9Sstevel@tonic-gate 	case DMAE_CH1:
428*7c478bd9Sstevel@tonic-gate 	case DMAE_CH2:
429*7c478bd9Sstevel@tonic-gate 	case DMAE_CH3:
430*7c478bd9Sstevel@tonic-gate #ifdef NO_PROG_WIDTH
431*7c478bd9Sstevel@tonic-gate 		if (dmaereqp->der_path && dmaereqp->der_path != DMAE_PATH_8) {
432*7c478bd9Sstevel@tonic-gate dprintf(("d37A_dma_swsetup err: chnl %d not programmed.\n", chnl));
433*7c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
434*7c478bd9Sstevel@tonic-gate 		}
435*7c478bd9Sstevel@tonic-gate #endif	/* NO_PROG_WIDTH */
436*7c478bd9Sstevel@tonic-gate 		break;
437*7c478bd9Sstevel@tonic-gate 
438*7c478bd9Sstevel@tonic-gate #ifndef DMA_4CSCD
439*7c478bd9Sstevel@tonic-gate 	case DMAE_CH4:
440*7c478bd9Sstevel@tonic-gate #endif	/* !DMA_4CSCD */
441*7c478bd9Sstevel@tonic-gate 	case DMAE_CH5:
442*7c478bd9Sstevel@tonic-gate 	case DMAE_CH6:
443*7c478bd9Sstevel@tonic-gate 	case DMAE_CH7:
444*7c478bd9Sstevel@tonic-gate #ifdef NO_PROG_WIDTH
445*7c478bd9Sstevel@tonic-gate 		if (dmaereqp->der_path && dmaereqp->der_path != DMAE_PATH_16) {
446*7c478bd9Sstevel@tonic-gate dprintf(("d37A_dma_swsetup err: chnl %d not programmed.\n", chnl));
447*7c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
448*7c478bd9Sstevel@tonic-gate 		}
449*7c478bd9Sstevel@tonic-gate #endif	/* NO_PROG_WIDTH */
450*7c478bd9Sstevel@tonic-gate 		break;
451*7c478bd9Sstevel@tonic-gate 
452*7c478bd9Sstevel@tonic-gate 	default:
453*7c478bd9Sstevel@tonic-gate 		dprintf(("d37A_dma_swsetup err: chnl %d not set up.\n", chnl));
454*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
455*7c478bd9Sstevel@tonic-gate 	};
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate 	mutex_enter(&dma_engine_lock);
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate 	d37A_dma_disable(chnl);
460*7c478bd9Sstevel@tonic-gate 	(void) d37A_set_mode(dmaereqp, chnl);
461*7c478bd9Sstevel@tonic-gate 
462*7c478bd9Sstevel@tonic-gate 	(void) d37A_write_addr(cp->dmac_address, chnl);
463*7c478bd9Sstevel@tonic-gate 	(void) d37A_write_count(cp->dmac_size, chnl);
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate #ifdef DMA_BUF_CHAIN
466*7c478bd9Sstevel@tonic-gate 	if (dmaereqp->der_bufprocess == DMAE_BUF_CHAIN &&
467*7c478bd9Sstevel@tonic-gate 	    (d37A_next_cookie[chnl] = _dmae_nxcookie(chnl))) {
468*7c478bd9Sstevel@tonic-gate 		/*
469*7c478bd9Sstevel@tonic-gate 		 * i/o operation has more than 1 cookie
470*7c478bd9Sstevel@tonic-gate 		 * so enable dma buffer chaining
471*7c478bd9Sstevel@tonic-gate 		 */
472*7c478bd9Sstevel@tonic-gate 		outb(chan_addr[chnl].scm_reg, chnl | EISA_ENCM);
473*7c478bd9Sstevel@tonic-gate 		dEISA_setchain(d37A_next_cookie[chnl], chnl);
474*7c478bd9Sstevel@tonic-gate 		d37A_next_cookie[chnl] = _dmae_nxcookie(chnl);
475*7c478bd9Sstevel@tonic-gate 	}
476*7c478bd9Sstevel@tonic-gate #endif	/* DMA_BUF_CHAIN */
477*7c478bd9Sstevel@tonic-gate 	mutex_exit(&dma_engine_lock);
478*7c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
479*7c478bd9Sstevel@tonic-gate }
480*7c478bd9Sstevel@tonic-gate 
481*7c478bd9Sstevel@tonic-gate 
482*7c478bd9Sstevel@tonic-gate /*
483*7c478bd9Sstevel@tonic-gate  *  routine: d37A_dma_swstart()
484*7c478bd9Sstevel@tonic-gate  *  purpose: SW start transfer setup on the indicated channel.
485*7c478bd9Sstevel@tonic-gate  *  caller:  dma_swstart()
486*7c478bd9Sstevel@tonic-gate  *  calls:   d37A_dma_enable(), d37A macros
487*7c478bd9Sstevel@tonic-gate  */
488*7c478bd9Sstevel@tonic-gate 
489*7c478bd9Sstevel@tonic-gate void
d37A_dma_swstart(int chnl)490*7c478bd9Sstevel@tonic-gate d37A_dma_swstart(int chnl)
491*7c478bd9Sstevel@tonic-gate {
492*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_dma_swstart: chnl=%d\n", chnl));
493*7c478bd9Sstevel@tonic-gate 
494*7c478bd9Sstevel@tonic-gate 	mutex_enter(&dma_engine_lock);
495*7c478bd9Sstevel@tonic-gate 	d37A_dma_enable(chnl);
496*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].reqt_reg, DMA_SETMSK | chnl); /* set request bit */
497*7c478bd9Sstevel@tonic-gate 	mutex_exit(&dma_engine_lock);
498*7c478bd9Sstevel@tonic-gate }
499*7c478bd9Sstevel@tonic-gate 
500*7c478bd9Sstevel@tonic-gate 
501*7c478bd9Sstevel@tonic-gate /*
502*7c478bd9Sstevel@tonic-gate  *  routine: d37A_dma_stop()
503*7c478bd9Sstevel@tonic-gate  *  purpose: Stop any activity on the indicated channel.
504*7c478bd9Sstevel@tonic-gate  *  caller:  dma_stop()
505*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros
506*7c478bd9Sstevel@tonic-gate  */
507*7c478bd9Sstevel@tonic-gate 
508*7c478bd9Sstevel@tonic-gate void
d37A_dma_stop(int chnl)509*7c478bd9Sstevel@tonic-gate d37A_dma_stop(int chnl)
510*7c478bd9Sstevel@tonic-gate {
511*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_dma_stop: chnl=%d\n", chnl));
512*7c478bd9Sstevel@tonic-gate 
513*7c478bd9Sstevel@tonic-gate 	mutex_enter(&dma_engine_lock);
514*7c478bd9Sstevel@tonic-gate 	d37A_dma_disable(chnl);
515*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].reqt_reg, chnl & 3);    /* reset request bit */
516*7c478bd9Sstevel@tonic-gate 	mutex_exit(&dma_engine_lock);
517*7c478bd9Sstevel@tonic-gate }
518*7c478bd9Sstevel@tonic-gate 
519*7c478bd9Sstevel@tonic-gate 
520*7c478bd9Sstevel@tonic-gate /*
521*7c478bd9Sstevel@tonic-gate  *  routine: d37A_get_chan_stat()
522*7c478bd9Sstevel@tonic-gate  *  purpose: retrieve the Current Address and Count registers for the
523*7c478bd9Sstevel@tonic-gate  *		specified channel.
524*7c478bd9Sstevel@tonic-gate  *  caller:  dma_get_chan_stat()
525*7c478bd9Sstevel@tonic-gate  *  calls:   d37A_read_addr(), d37A_read_count().
526*7c478bd9Sstevel@tonic-gate  */
527*7c478bd9Sstevel@tonic-gate void
d37A_get_chan_stat(int chnl,ulong_t * addressp,int * countp)528*7c478bd9Sstevel@tonic-gate d37A_get_chan_stat(int chnl, ulong_t *addressp, int *countp)
529*7c478bd9Sstevel@tonic-gate {
530*7c478bd9Sstevel@tonic-gate 	ulong_t taddr;
531*7c478bd9Sstevel@tonic-gate 	int tcount;
532*7c478bd9Sstevel@tonic-gate 
533*7c478bd9Sstevel@tonic-gate 	mutex_enter(&dma_engine_lock);
534*7c478bd9Sstevel@tonic-gate 	taddr = d37A_read_addr(chnl);
535*7c478bd9Sstevel@tonic-gate 	tcount = d37A_read_count(chnl);
536*7c478bd9Sstevel@tonic-gate 	mutex_exit(&dma_engine_lock);
537*7c478bd9Sstevel@tonic-gate 	if (addressp)
538*7c478bd9Sstevel@tonic-gate 		*addressp = taddr;
539*7c478bd9Sstevel@tonic-gate 	if (countp)
540*7c478bd9Sstevel@tonic-gate 		*countp = tcount;
541*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_get_chan_stat: chnl=%d address=%lx count=%x\n",
542*7c478bd9Sstevel@tonic-gate 	    chnl, taddr, tcount));
543*7c478bd9Sstevel@tonic-gate }
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate 
546*7c478bd9Sstevel@tonic-gate /*
547*7c478bd9Sstevel@tonic-gate  *  routine: d37A_set_mode()
548*7c478bd9Sstevel@tonic-gate  *  purpose: program the Mode registers of the
549*7c478bd9Sstevel@tonic-gate  *		DMAC for a subsequent hardware-initiated transfer.
550*7c478bd9Sstevel@tonic-gate  *  caller:  d37A_prog_chan(), d37A_dma_swsetup
551*7c478bd9Sstevel@tonic-gate  *  calls:
552*7c478bd9Sstevel@tonic-gate  */
553*7c478bd9Sstevel@tonic-gate 
554*7c478bd9Sstevel@tonic-gate static int
d37A_set_mode(struct ddi_dmae_req * dmaereqp,int chnl)555*7c478bd9Sstevel@tonic-gate d37A_set_mode(struct ddi_dmae_req *dmaereqp, int chnl)
556*7c478bd9Sstevel@tonic-gate {
557*7c478bd9Sstevel@tonic-gate 	uchar_t mode = 0, emode = 0;
558*7c478bd9Sstevel@tonic-gate 
559*7c478bd9Sstevel@tonic-gate #ifdef ISA_MODE
560*7c478bd9Sstevel@tonic-gate #if defined(lint)
561*7c478bd9Sstevel@tonic-gate 	emode = emode;
562*7c478bd9Sstevel@tonic-gate #endif
563*7c478bd9Sstevel@tonic-gate 	mode = chnl & 3;
564*7c478bd9Sstevel@tonic-gate 
565*7c478bd9Sstevel@tonic-gate 	switch (dmaereqp->der_command) {
566*7c478bd9Sstevel@tonic-gate 	case DMAE_CMD_READ:
567*7c478bd9Sstevel@tonic-gate 		mode |= DMAMODE_READ;
568*7c478bd9Sstevel@tonic-gate 		break;
569*7c478bd9Sstevel@tonic-gate 	case DMAE_CMD_WRITE:
570*7c478bd9Sstevel@tonic-gate 		mode |= DMAMODE_WRITE;
571*7c478bd9Sstevel@tonic-gate 		break;
572*7c478bd9Sstevel@tonic-gate 	case DMAE_CMD_VRFY:
573*7c478bd9Sstevel@tonic-gate 		mode |= DMAMODE_VERF;
574*7c478bd9Sstevel@tonic-gate 		break;
575*7c478bd9Sstevel@tonic-gate 	case DMAE_CMD_TRAN:
576*7c478bd9Sstevel@tonic-gate 		mode |= 0x0C;	/* for Adaptec 1st party DMA on chnl 0 */
577*7c478bd9Sstevel@tonic-gate 		break;
578*7c478bd9Sstevel@tonic-gate 	default:
579*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
580*7c478bd9Sstevel@tonic-gate 	}
581*7c478bd9Sstevel@tonic-gate 
582*7c478bd9Sstevel@tonic-gate 	if (dmaereqp->der_bufprocess == DMAE_BUF_AUTO)
583*7c478bd9Sstevel@tonic-gate 		mode |= DMAMODE_AUTO;
584*7c478bd9Sstevel@tonic-gate 
585*7c478bd9Sstevel@tonic-gate 	if (dmaereqp->der_step == DMAE_STEP_DEC)
586*7c478bd9Sstevel@tonic-gate 		mode |= DMAMODE_DECR;
587*7c478bd9Sstevel@tonic-gate 
588*7c478bd9Sstevel@tonic-gate 	switch (dmaereqp->der_trans) {
589*7c478bd9Sstevel@tonic-gate 	case DMAE_TRANS_SNGL:
590*7c478bd9Sstevel@tonic-gate 		mode |= DMAMODE_SINGLE;
591*7c478bd9Sstevel@tonic-gate 		break;
592*7c478bd9Sstevel@tonic-gate 	case DMAE_TRANS_BLCK:
593*7c478bd9Sstevel@tonic-gate 		mode |= DMAMODE_BLOCK;
594*7c478bd9Sstevel@tonic-gate 		break;
595*7c478bd9Sstevel@tonic-gate 	case DMAE_TRANS_DMND:
596*7c478bd9Sstevel@tonic-gate 		break;
597*7c478bd9Sstevel@tonic-gate 	case DMAE_TRANS_CSCD:
598*7c478bd9Sstevel@tonic-gate 		mode |= DMAMODE_CASC;
599*7c478bd9Sstevel@tonic-gate 		break;
600*7c478bd9Sstevel@tonic-gate 	default:
601*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
602*7c478bd9Sstevel@tonic-gate 	}
603*7c478bd9Sstevel@tonic-gate 	d37A_chnl_mode[chnl] = dmaereqp->der_trans;
604*7c478bd9Sstevel@tonic-gate 
605*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_set_mode: chnl=%d mode_reg=0x%x mode=0x%x\n",
606*7c478bd9Sstevel@tonic-gate 	    chnl, chan_addr[chnl].mode_reg, mode));
607*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].mode_reg, mode);
608*7c478bd9Sstevel@tonic-gate #endif	/* ISA_MODE */
609*7c478bd9Sstevel@tonic-gate 
610*7c478bd9Sstevel@tonic-gate #ifdef EISA_EXT_MODE
611*7c478bd9Sstevel@tonic-gate 	emode = chnl & 3;
612*7c478bd9Sstevel@tonic-gate 	d37A_chnl_path[chnl] = dmaereqp->der_path;
613*7c478bd9Sstevel@tonic-gate 
614*7c478bd9Sstevel@tonic-gate 	switch (dmaereqp->der_path) {
615*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_8:
616*7c478bd9Sstevel@tonic-gate 		/* emode |= EISA_DMA_8; */
617*7c478bd9Sstevel@tonic-gate 		break;
618*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16:
619*7c478bd9Sstevel@tonic-gate 		emode |= EISA_DMA_16;
620*7c478bd9Sstevel@tonic-gate 		break;
621*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_32:
622*7c478bd9Sstevel@tonic-gate 		emode |= EISA_DMA_32;
623*7c478bd9Sstevel@tonic-gate 		break;
624*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16B:
625*7c478bd9Sstevel@tonic-gate 		emode |= EISA_DMA_16B;
626*7c478bd9Sstevel@tonic-gate 		break;
627*7c478bd9Sstevel@tonic-gate 	default:
628*7c478bd9Sstevel@tonic-gate 		switch (chnl) {
629*7c478bd9Sstevel@tonic-gate 		case DMAE_CH0:
630*7c478bd9Sstevel@tonic-gate 		case DMAE_CH1:
631*7c478bd9Sstevel@tonic-gate 		case DMAE_CH2:
632*7c478bd9Sstevel@tonic-gate 		case DMAE_CH3:
633*7c478bd9Sstevel@tonic-gate 			d37A_chnl_path[chnl] = DMAE_PATH_8;
634*7c478bd9Sstevel@tonic-gate 			/* emode |= EISA_DMA_8; */
635*7c478bd9Sstevel@tonic-gate 			break;
636*7c478bd9Sstevel@tonic-gate 		case DMAE_CH5:
637*7c478bd9Sstevel@tonic-gate 		case DMAE_CH6:
638*7c478bd9Sstevel@tonic-gate 		case DMAE_CH7:
639*7c478bd9Sstevel@tonic-gate 			d37A_chnl_path[chnl] = DMAE_PATH_16;
640*7c478bd9Sstevel@tonic-gate 			emode |= EISA_DMA_16;
641*7c478bd9Sstevel@tonic-gate 			break;
642*7c478bd9Sstevel@tonic-gate 		}
643*7c478bd9Sstevel@tonic-gate 	}
644*7c478bd9Sstevel@tonic-gate 	emode |= (dmaereqp->der_cycles & 3) << 4;
645*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].emode_reg, emode);
646*7c478bd9Sstevel@tonic-gate 
647*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_set_mode: chnl=%d em_reg=0x%x emode=0x%x\n",
648*7c478bd9Sstevel@tonic-gate 	    chnl, chan_addr[chnl].emode_reg, emode));
649*7c478bd9Sstevel@tonic-gate #endif	/* EISA_EXT_MODE */
650*7c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
651*7c478bd9Sstevel@tonic-gate }
652*7c478bd9Sstevel@tonic-gate 
653*7c478bd9Sstevel@tonic-gate 
654*7c478bd9Sstevel@tonic-gate /*
655*7c478bd9Sstevel@tonic-gate  *  routine: d37A_write_addr()
656*7c478bd9Sstevel@tonic-gate  *  purpose: write the 24- or 32-bit physical address into the Base Address
657*7c478bd9Sstevel@tonic-gate  *		Register for the indicated channel.
658*7c478bd9Sstevel@tonic-gate  *  caller:  d37A_prog_chan(), d37A_dma_swsetup().
659*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros
660*7c478bd9Sstevel@tonic-gate  */
661*7c478bd9Sstevel@tonic-gate 
662*7c478bd9Sstevel@tonic-gate static int
d37A_write_addr(ulong_t paddress,int chnl)663*7c478bd9Sstevel@tonic-gate d37A_write_addr(ulong_t paddress, int chnl)
664*7c478bd9Sstevel@tonic-gate {
665*7c478bd9Sstevel@tonic-gate 	uchar_t *adr_byte;
666*7c478bd9Sstevel@tonic-gate 
667*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_write_addr: chnl=%d address=%lx\n", chnl, paddress));
668*7c478bd9Sstevel@tonic-gate 
669*7c478bd9Sstevel@tonic-gate 	switch (d37A_chnl_path[chnl]) {
670*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_8:
671*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16B:
672*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_32:
673*7c478bd9Sstevel@tonic-gate 		/*
674*7c478bd9Sstevel@tonic-gate 		 * program DMA controller with byte address
675*7c478bd9Sstevel@tonic-gate 		 */
676*7c478bd9Sstevel@tonic-gate 		break;
677*7c478bd9Sstevel@tonic-gate 
678*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16:
679*7c478bd9Sstevel@tonic-gate 		/*
680*7c478bd9Sstevel@tonic-gate 		 * convert byte address to shifted word address
681*7c478bd9Sstevel@tonic-gate 		 */
682*7c478bd9Sstevel@tonic-gate 		paddress = (paddress & ~0x1ffff) | ((paddress & 0x1ffff) >> 1);
683*7c478bd9Sstevel@tonic-gate 		break;
684*7c478bd9Sstevel@tonic-gate 
685*7c478bd9Sstevel@tonic-gate 	default:
686*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
687*7c478bd9Sstevel@tonic-gate 	}
688*7c478bd9Sstevel@tonic-gate 	kpreempt_disable();	/* don't preempt thread while using flip-flop */
689*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].ff_reg, 0);	/* set flipflop */
690*7c478bd9Sstevel@tonic-gate 
691*7c478bd9Sstevel@tonic-gate 	adr_byte = (uchar_t *)&paddress;
692*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].addr_reg, adr_byte[0]);
693*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].addr_reg, adr_byte[1]);
694*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].page_reg, adr_byte[2]);
695*7c478bd9Sstevel@tonic-gate #ifdef ADDR_32
696*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].hpage_reg, adr_byte[3]);
697*7c478bd9Sstevel@tonic-gate #endif	/* ADDR_32 */
698*7c478bd9Sstevel@tonic-gate 
699*7c478bd9Sstevel@tonic-gate 	kpreempt_enable();
700*7c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
701*7c478bd9Sstevel@tonic-gate }
702*7c478bd9Sstevel@tonic-gate 
703*7c478bd9Sstevel@tonic-gate 
704*7c478bd9Sstevel@tonic-gate /*
705*7c478bd9Sstevel@tonic-gate  *  routine: d37A_read_addr()
706*7c478bd9Sstevel@tonic-gate  *  purpose: read the 24- or 32-bit physical address from the Current Address
707*7c478bd9Sstevel@tonic-gate  *		Register for the indicated channel.
708*7c478bd9Sstevel@tonic-gate  *  caller:  d37A_get_chan_stat().
709*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros
710*7c478bd9Sstevel@tonic-gate  */
711*7c478bd9Sstevel@tonic-gate 
712*7c478bd9Sstevel@tonic-gate static ulong_t
d37A_read_addr(int chnl)713*7c478bd9Sstevel@tonic-gate d37A_read_addr(int chnl)
714*7c478bd9Sstevel@tonic-gate {
715*7c478bd9Sstevel@tonic-gate 	ulong_t paddress = 0;
716*7c478bd9Sstevel@tonic-gate 	uchar_t *adr_byte;
717*7c478bd9Sstevel@tonic-gate 
718*7c478bd9Sstevel@tonic-gate 	kpreempt_disable();	/* don't preempt thread while using flip-flop */
719*7c478bd9Sstevel@tonic-gate 	adr_byte = (uchar_t *)&paddress;
720*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].ff_reg, 0);	/* set flipflop */
721*7c478bd9Sstevel@tonic-gate 
722*7c478bd9Sstevel@tonic-gate 	adr_byte[0] = inb(chan_addr[chnl].addr_reg);
723*7c478bd9Sstevel@tonic-gate 	adr_byte[1] = inb(chan_addr[chnl].addr_reg);
724*7c478bd9Sstevel@tonic-gate 	adr_byte[2] = inb(chan_addr[chnl].page_reg);
725*7c478bd9Sstevel@tonic-gate #ifdef ADDR_32
726*7c478bd9Sstevel@tonic-gate 	adr_byte[3] = inb(chan_addr[chnl].hpage_reg);
727*7c478bd9Sstevel@tonic-gate #endif	/* ADDR_32 */
728*7c478bd9Sstevel@tonic-gate 
729*7c478bd9Sstevel@tonic-gate 	kpreempt_enable();
730*7c478bd9Sstevel@tonic-gate 
731*7c478bd9Sstevel@tonic-gate 	switch (d37A_chnl_path[chnl]) {
732*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_8:
733*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16B:
734*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_32:
735*7c478bd9Sstevel@tonic-gate 		/*
736*7c478bd9Sstevel@tonic-gate 		 * return with byte address
737*7c478bd9Sstevel@tonic-gate 		 */
738*7c478bd9Sstevel@tonic-gate 		break;
739*7c478bd9Sstevel@tonic-gate 
740*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16:
741*7c478bd9Sstevel@tonic-gate 		/*
742*7c478bd9Sstevel@tonic-gate 		 * convert shifted word address to byte address
743*7c478bd9Sstevel@tonic-gate 		 */
744*7c478bd9Sstevel@tonic-gate 		paddress = (paddress & ~0x1ffff) | ((paddress & 0x0ffff) << 1);
745*7c478bd9Sstevel@tonic-gate 		break;
746*7c478bd9Sstevel@tonic-gate 
747*7c478bd9Sstevel@tonic-gate 	default:
748*7c478bd9Sstevel@tonic-gate 		return ((ulong_t)DDI_FAILURE);
749*7c478bd9Sstevel@tonic-gate 	}
750*7c478bd9Sstevel@tonic-gate 
751*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_read_addr: chnl=%d address=%lx.\n", chnl, paddress));
752*7c478bd9Sstevel@tonic-gate 	return (paddress);
753*7c478bd9Sstevel@tonic-gate }
754*7c478bd9Sstevel@tonic-gate 
755*7c478bd9Sstevel@tonic-gate 
756*7c478bd9Sstevel@tonic-gate /*
757*7c478bd9Sstevel@tonic-gate  *  routine: d37A_write_count()
758*7c478bd9Sstevel@tonic-gate  *  purpose: write the 16- or 24-bit count into the Base Count Register for
759*7c478bd9Sstevel@tonic-gate  *		the indicated channel.
760*7c478bd9Sstevel@tonic-gate  *  caller:  d37A_prog_chan(), d37A_dma_swsetup()
761*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros
762*7c478bd9Sstevel@tonic-gate  */
763*7c478bd9Sstevel@tonic-gate 
764*7c478bd9Sstevel@tonic-gate static int
d37A_write_count(long count,int chnl)765*7c478bd9Sstevel@tonic-gate d37A_write_count(long count, int chnl)
766*7c478bd9Sstevel@tonic-gate {
767*7c478bd9Sstevel@tonic-gate 	uchar_t *count_byte;
768*7c478bd9Sstevel@tonic-gate 
769*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_write_count: chnl=%d count=0x%lx\n", chnl, count));
770*7c478bd9Sstevel@tonic-gate 
771*7c478bd9Sstevel@tonic-gate 	switch (d37A_chnl_path[chnl]) {
772*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16:
773*7c478bd9Sstevel@tonic-gate 		/*
774*7c478bd9Sstevel@tonic-gate 		 * Convert byte count to word count
775*7c478bd9Sstevel@tonic-gate 		 */
776*7c478bd9Sstevel@tonic-gate 		count >>= 1;
777*7c478bd9Sstevel@tonic-gate 		/* FALLTHROUGH */
778*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_8:
779*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16B:
780*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_32:
781*7c478bd9Sstevel@tonic-gate 		--count;
782*7c478bd9Sstevel@tonic-gate 		break;
783*7c478bd9Sstevel@tonic-gate 
784*7c478bd9Sstevel@tonic-gate 	default:
785*7c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
786*7c478bd9Sstevel@tonic-gate 	}
787*7c478bd9Sstevel@tonic-gate 
788*7c478bd9Sstevel@tonic-gate 	kpreempt_disable();	/* don't preempt thread while using flip-flop */
789*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].ff_reg, 0);	/* set flipflop */
790*7c478bd9Sstevel@tonic-gate 
791*7c478bd9Sstevel@tonic-gate 	count_byte = (uchar_t *)&count;
792*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].cnt_reg, count_byte[0]);
793*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].cnt_reg, count_byte[1]);
794*7c478bd9Sstevel@tonic-gate #ifdef COUNT_24
795*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].hcnt_reg, count_byte[2]);
796*7c478bd9Sstevel@tonic-gate #endif	/* COUNT_24 */
797*7c478bd9Sstevel@tonic-gate 
798*7c478bd9Sstevel@tonic-gate 	kpreempt_enable();
799*7c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
800*7c478bd9Sstevel@tonic-gate }
801*7c478bd9Sstevel@tonic-gate 
802*7c478bd9Sstevel@tonic-gate 
803*7c478bd9Sstevel@tonic-gate /*
804*7c478bd9Sstevel@tonic-gate  *  routine: d37A_read_count()
805*7c478bd9Sstevel@tonic-gate  *  purpose: read the 16- or 24-bit count from the Current Count Register for
806*7c478bd9Sstevel@tonic-gate  *		the indicated channel
807*7c478bd9Sstevel@tonic-gate  *  caller:  d37A_get_chan_stat()
808*7c478bd9Sstevel@tonic-gate  *  calls:   d37A macros
809*7c478bd9Sstevel@tonic-gate  */
810*7c478bd9Sstevel@tonic-gate 
811*7c478bd9Sstevel@tonic-gate static long
d37A_read_count(int chnl)812*7c478bd9Sstevel@tonic-gate d37A_read_count(int chnl)
813*7c478bd9Sstevel@tonic-gate {
814*7c478bd9Sstevel@tonic-gate 	long count = 0;
815*7c478bd9Sstevel@tonic-gate 	uchar_t *count_byte;
816*7c478bd9Sstevel@tonic-gate 
817*7c478bd9Sstevel@tonic-gate 	kpreempt_disable();	/* don't preempt thread while using flip-flop */
818*7c478bd9Sstevel@tonic-gate 	count_byte = (uchar_t *)&count;
819*7c478bd9Sstevel@tonic-gate 	outb(chan_addr[chnl].ff_reg, 0);	/* set flipflop */
820*7c478bd9Sstevel@tonic-gate 
821*7c478bd9Sstevel@tonic-gate 	count_byte[0] = inb(chan_addr[chnl].cnt_reg);
822*7c478bd9Sstevel@tonic-gate 	count_byte[1] = inb(chan_addr[chnl].cnt_reg);
823*7c478bd9Sstevel@tonic-gate #ifdef COUNT_24
824*7c478bd9Sstevel@tonic-gate 	count_byte[2] = inb(chan_addr[chnl].hcnt_reg);
825*7c478bd9Sstevel@tonic-gate #endif	/* COUNT_24 */
826*7c478bd9Sstevel@tonic-gate 
827*7c478bd9Sstevel@tonic-gate #ifdef COUNT_24
828*7c478bd9Sstevel@tonic-gate 	if ((ulong_t)count == 0xffffff)
829*7c478bd9Sstevel@tonic-gate #else	/* !COUNT_24 */
830*7c478bd9Sstevel@tonic-gate 	if ((ulong_t)count == 0xffff)
831*7c478bd9Sstevel@tonic-gate #endif	/* !COUNT_24 */
832*7c478bd9Sstevel@tonic-gate 		count = -1;
833*7c478bd9Sstevel@tonic-gate 
834*7c478bd9Sstevel@tonic-gate 	kpreempt_enable();
835*7c478bd9Sstevel@tonic-gate 
836*7c478bd9Sstevel@tonic-gate 	switch (d37A_chnl_path[chnl]) {
837*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_8:
838*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16B:
839*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_32:
840*7c478bd9Sstevel@tonic-gate 		++count;
841*7c478bd9Sstevel@tonic-gate 		break;
842*7c478bd9Sstevel@tonic-gate 
843*7c478bd9Sstevel@tonic-gate 	case DMAE_PATH_16:
844*7c478bd9Sstevel@tonic-gate 		/*
845*7c478bd9Sstevel@tonic-gate 		 * Convert incremented word count to byte count
846*7c478bd9Sstevel@tonic-gate 		 */
847*7c478bd9Sstevel@tonic-gate 		count = (count + 1) << 1;
848*7c478bd9Sstevel@tonic-gate 		break;
849*7c478bd9Sstevel@tonic-gate 	}
850*7c478bd9Sstevel@tonic-gate 	dprintf(("d37A_read_count: chnl=%d count=0x%lx\n", chnl, count));
851*7c478bd9Sstevel@tonic-gate 	return (count);
852*7c478bd9Sstevel@tonic-gate }
853