xref: /OK3568_Linux_fs/kernel/arch/alpha/include/asm/dma.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * include/asm-alpha/dma.h
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This is essentially the same as the i386 DMA stuff, as the AlphaPCs
6*4882a593Smuzhiyun  * use ISA-compatible dma.  The only extension is support for high-page
7*4882a593Smuzhiyun  * registers that allow to set the top 8 bits of a 32-bit DMA address.
8*4882a593Smuzhiyun  * This register should be written last when setting up a DMA address
9*4882a593Smuzhiyun  * as this will also enable DMA across 64 KB boundaries.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /* $Id: dma.h,v 1.7 1992/12/14 00:29:34 root Exp root $
13*4882a593Smuzhiyun  * linux/include/asm/dma.h: Defines for using and allocating dma channels.
14*4882a593Smuzhiyun  * Written by Hennus Bergman, 1992.
15*4882a593Smuzhiyun  * High DMA channel support & info by Hannu Savolainen
16*4882a593Smuzhiyun  * and John Boyd, Nov. 1992.
17*4882a593Smuzhiyun  */
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #ifndef _ASM_DMA_H
20*4882a593Smuzhiyun #define _ASM_DMA_H
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include <linux/spinlock.h>
23*4882a593Smuzhiyun #include <asm/io.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #define dma_outb	outb
26*4882a593Smuzhiyun #define dma_inb		inb
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun  * NOTES about DMA transfers:
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  *  controller 1: channels 0-3, byte operations, ports 00-1F
32*4882a593Smuzhiyun  *  controller 2: channels 4-7, word operations, ports C0-DF
33*4882a593Smuzhiyun  *
34*4882a593Smuzhiyun  *  - ALL registers are 8 bits only, regardless of transfer size
35*4882a593Smuzhiyun  *  - channel 4 is not used - cascades 1 into 2.
36*4882a593Smuzhiyun  *  - channels 0-3 are byte - addresses/counts are for physical bytes
37*4882a593Smuzhiyun  *  - channels 5-7 are word - addresses/counts are for physical words
38*4882a593Smuzhiyun  *  - transfers must not cross physical 64K (0-3) or 128K (5-7) boundaries
39*4882a593Smuzhiyun  *  - transfer count loaded to registers is 1 less than actual count
40*4882a593Smuzhiyun  *  - controller 2 offsets are all even (2x offsets for controller 1)
41*4882a593Smuzhiyun  *  - page registers for 5-7 don't use data bit 0, represent 128K pages
42*4882a593Smuzhiyun  *  - page registers for 0-3 use bit 0, represent 64K pages
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  * DMA transfers are limited to the lower 16MB of _physical_ memory.
45*4882a593Smuzhiyun  * Note that addresses loaded into registers must be _physical_ addresses,
46*4882a593Smuzhiyun  * not logical addresses (which may differ if paging is active).
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  *  Address mapping for channels 0-3:
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  *   A23 ... A16 A15 ... A8  A7 ... A0    (Physical addresses)
51*4882a593Smuzhiyun  *    |  ...  |   |  ... |   |  ... |
52*4882a593Smuzhiyun  *    |  ...  |   |  ... |   |  ... |
53*4882a593Smuzhiyun  *    |  ...  |   |  ... |   |  ... |
54*4882a593Smuzhiyun  *   P7  ...  P0  A7 ... A0  A7 ... A0
55*4882a593Smuzhiyun  * |    Page    | Addr MSB | Addr LSB |   (DMA registers)
56*4882a593Smuzhiyun  *
57*4882a593Smuzhiyun  *  Address mapping for channels 5-7:
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  *   A23 ... A17 A16 A15 ... A9 A8 A7 ... A1 A0    (Physical addresses)
60*4882a593Smuzhiyun  *    |  ...  |   \   \   ... \  \  \  ... \  \
61*4882a593Smuzhiyun  *    |  ...  |    \   \   ... \  \  \  ... \  (not used)
62*4882a593Smuzhiyun  *    |  ...  |     \   \   ... \  \  \  ... \
63*4882a593Smuzhiyun  *   P7  ...  P1 (0) A7 A6  ... A0 A7 A6 ... A0
64*4882a593Smuzhiyun  * |      Page      |  Addr MSB   |  Addr LSB  |   (DMA registers)
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  * Again, channels 5-7 transfer _physical_ words (16 bits), so addresses
67*4882a593Smuzhiyun  * and counts _must_ be word-aligned (the lowest address bit is _ignored_ at
68*4882a593Smuzhiyun  * the hardware level, so odd-byte transfers aren't possible).
69*4882a593Smuzhiyun  *
70*4882a593Smuzhiyun  * Transfer count (_not # bytes_) is limited to 64K, represented as actual
71*4882a593Smuzhiyun  * count - 1 : 64K => 0xFFFF, 1 => 0x0000.  Thus, count is always 1 or more,
72*4882a593Smuzhiyun  * and up to 128K bytes may be transferred on channels 5-7 in one operation.
73*4882a593Smuzhiyun  *
74*4882a593Smuzhiyun  */
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun #define MAX_DMA_CHANNELS	8
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /*
79*4882a593Smuzhiyun   ISA DMA limitations on Alpha platforms,
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun   These may be due to SIO (PCI<->ISA bridge) chipset limitation, or
82*4882a593Smuzhiyun   just a wiring limit.
83*4882a593Smuzhiyun */
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun /* The maximum address for ISA DMA transfer on Alpha XL, due to an
86*4882a593Smuzhiyun    hardware SIO limitation, is 64MB.
87*4882a593Smuzhiyun */
88*4882a593Smuzhiyun #define ALPHA_XL_MAX_ISA_DMA_ADDRESS		0x04000000UL
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* The maximum address for ISA DMA transfer on RUFFIAN,
91*4882a593Smuzhiyun    due to an hardware SIO limitation, is 16MB.
92*4882a593Smuzhiyun */
93*4882a593Smuzhiyun #define ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS	0x01000000UL
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /* The maximum address for ISA DMA transfer on SABLE, and some ALCORs,
96*4882a593Smuzhiyun    due to an hardware SIO chip limitation, is 2GB.
97*4882a593Smuzhiyun */
98*4882a593Smuzhiyun #define ALPHA_SABLE_MAX_ISA_DMA_ADDRESS		0x80000000UL
99*4882a593Smuzhiyun #define ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS		0x80000000UL
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /*
102*4882a593Smuzhiyun   Maximum address for all the others is the complete 32-bit bus
103*4882a593Smuzhiyun   address space.
104*4882a593Smuzhiyun */
105*4882a593Smuzhiyun #define ALPHA_MAX_ISA_DMA_ADDRESS		0x100000000UL
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun #ifdef CONFIG_ALPHA_GENERIC
108*4882a593Smuzhiyun # define MAX_ISA_DMA_ADDRESS		(alpha_mv.max_isa_dma_address)
109*4882a593Smuzhiyun #else
110*4882a593Smuzhiyun # if defined(CONFIG_ALPHA_XL)
111*4882a593Smuzhiyun #  define MAX_ISA_DMA_ADDRESS		ALPHA_XL_MAX_ISA_DMA_ADDRESS
112*4882a593Smuzhiyun # elif defined(CONFIG_ALPHA_RUFFIAN)
113*4882a593Smuzhiyun #  define MAX_ISA_DMA_ADDRESS		ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS
114*4882a593Smuzhiyun # elif defined(CONFIG_ALPHA_SABLE)
115*4882a593Smuzhiyun #  define MAX_ISA_DMA_ADDRESS		ALPHA_SABLE_MAX_ISA_DMA_ADDRESS
116*4882a593Smuzhiyun # elif defined(CONFIG_ALPHA_ALCOR)
117*4882a593Smuzhiyun #  define MAX_ISA_DMA_ADDRESS		ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS
118*4882a593Smuzhiyun # else
119*4882a593Smuzhiyun #  define MAX_ISA_DMA_ADDRESS		ALPHA_MAX_ISA_DMA_ADDRESS
120*4882a593Smuzhiyun # endif
121*4882a593Smuzhiyun #endif
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun /* If we have the iommu, we don't have any address limitations on DMA.
124*4882a593Smuzhiyun    Otherwise (Nautilus, RX164), we have to have 0-16 Mb DMA zone
125*4882a593Smuzhiyun    like i386. */
126*4882a593Smuzhiyun #define MAX_DMA_ADDRESS		(alpha_mv.mv_pci_tbi ?	\
127*4882a593Smuzhiyun 				 ~0UL : IDENT_ADDR + 0x01000000)
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun /* 8237 DMA controllers */
130*4882a593Smuzhiyun #define IO_DMA1_BASE	0x00	/* 8 bit slave DMA, channels 0..3 */
131*4882a593Smuzhiyun #define IO_DMA2_BASE	0xC0	/* 16 bit master DMA, ch 4(=slave input)..7 */
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /* DMA controller registers */
134*4882a593Smuzhiyun #define DMA1_CMD_REG		0x08	/* command register (w) */
135*4882a593Smuzhiyun #define DMA1_STAT_REG		0x08	/* status register (r) */
136*4882a593Smuzhiyun #define DMA1_REQ_REG            0x09    /* request register (w) */
137*4882a593Smuzhiyun #define DMA1_MASK_REG		0x0A	/* single-channel mask (w) */
138*4882a593Smuzhiyun #define DMA1_MODE_REG		0x0B	/* mode register (w) */
139*4882a593Smuzhiyun #define DMA1_CLEAR_FF_REG	0x0C	/* clear pointer flip-flop (w) */
140*4882a593Smuzhiyun #define DMA1_TEMP_REG           0x0D    /* Temporary Register (r) */
141*4882a593Smuzhiyun #define DMA1_RESET_REG		0x0D	/* Master Clear (w) */
142*4882a593Smuzhiyun #define DMA1_CLR_MASK_REG       0x0E    /* Clear Mask */
143*4882a593Smuzhiyun #define DMA1_MASK_ALL_REG       0x0F    /* all-channels mask (w) */
144*4882a593Smuzhiyun #define DMA1_EXT_MODE_REG	(0x400 | DMA1_MODE_REG)
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun #define DMA2_CMD_REG		0xD0	/* command register (w) */
147*4882a593Smuzhiyun #define DMA2_STAT_REG		0xD0	/* status register (r) */
148*4882a593Smuzhiyun #define DMA2_REQ_REG            0xD2    /* request register (w) */
149*4882a593Smuzhiyun #define DMA2_MASK_REG		0xD4	/* single-channel mask (w) */
150*4882a593Smuzhiyun #define DMA2_MODE_REG		0xD6	/* mode register (w) */
151*4882a593Smuzhiyun #define DMA2_CLEAR_FF_REG	0xD8	/* clear pointer flip-flop (w) */
152*4882a593Smuzhiyun #define DMA2_TEMP_REG           0xDA    /* Temporary Register (r) */
153*4882a593Smuzhiyun #define DMA2_RESET_REG		0xDA	/* Master Clear (w) */
154*4882a593Smuzhiyun #define DMA2_CLR_MASK_REG       0xDC    /* Clear Mask */
155*4882a593Smuzhiyun #define DMA2_MASK_ALL_REG       0xDE    /* all-channels mask (w) */
156*4882a593Smuzhiyun #define DMA2_EXT_MODE_REG	(0x400 | DMA2_MODE_REG)
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun #define DMA_ADDR_0              0x00    /* DMA address registers */
159*4882a593Smuzhiyun #define DMA_ADDR_1              0x02
160*4882a593Smuzhiyun #define DMA_ADDR_2              0x04
161*4882a593Smuzhiyun #define DMA_ADDR_3              0x06
162*4882a593Smuzhiyun #define DMA_ADDR_4              0xC0
163*4882a593Smuzhiyun #define DMA_ADDR_5              0xC4
164*4882a593Smuzhiyun #define DMA_ADDR_6              0xC8
165*4882a593Smuzhiyun #define DMA_ADDR_7              0xCC
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun #define DMA_CNT_0               0x01    /* DMA count registers */
168*4882a593Smuzhiyun #define DMA_CNT_1               0x03
169*4882a593Smuzhiyun #define DMA_CNT_2               0x05
170*4882a593Smuzhiyun #define DMA_CNT_3               0x07
171*4882a593Smuzhiyun #define DMA_CNT_4               0xC2
172*4882a593Smuzhiyun #define DMA_CNT_5               0xC6
173*4882a593Smuzhiyun #define DMA_CNT_6               0xCA
174*4882a593Smuzhiyun #define DMA_CNT_7               0xCE
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun #define DMA_PAGE_0              0x87    /* DMA page registers */
177*4882a593Smuzhiyun #define DMA_PAGE_1              0x83
178*4882a593Smuzhiyun #define DMA_PAGE_2              0x81
179*4882a593Smuzhiyun #define DMA_PAGE_3              0x82
180*4882a593Smuzhiyun #define DMA_PAGE_5              0x8B
181*4882a593Smuzhiyun #define DMA_PAGE_6              0x89
182*4882a593Smuzhiyun #define DMA_PAGE_7              0x8A
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun #define DMA_HIPAGE_0		(0x400 | DMA_PAGE_0)
185*4882a593Smuzhiyun #define DMA_HIPAGE_1		(0x400 | DMA_PAGE_1)
186*4882a593Smuzhiyun #define DMA_HIPAGE_2		(0x400 | DMA_PAGE_2)
187*4882a593Smuzhiyun #define DMA_HIPAGE_3		(0x400 | DMA_PAGE_3)
188*4882a593Smuzhiyun #define DMA_HIPAGE_4		(0x400 | DMA_PAGE_4)
189*4882a593Smuzhiyun #define DMA_HIPAGE_5		(0x400 | DMA_PAGE_5)
190*4882a593Smuzhiyun #define DMA_HIPAGE_6		(0x400 | DMA_PAGE_6)
191*4882a593Smuzhiyun #define DMA_HIPAGE_7		(0x400 | DMA_PAGE_7)
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun #define DMA_MODE_READ	0x44	/* I/O to memory, no autoinit, increment, single mode */
194*4882a593Smuzhiyun #define DMA_MODE_WRITE	0x48	/* memory to I/O, no autoinit, increment, single mode */
195*4882a593Smuzhiyun #define DMA_MODE_CASCADE 0xC0   /* pass thru DREQ->HRQ, DACK<-HLDA only */
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun #define DMA_AUTOINIT	0x10
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun extern spinlock_t  dma_spin_lock;
200*4882a593Smuzhiyun 
claim_dma_lock(void)201*4882a593Smuzhiyun static __inline__ unsigned long claim_dma_lock(void)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun 	unsigned long flags;
204*4882a593Smuzhiyun 	spin_lock_irqsave(&dma_spin_lock, flags);
205*4882a593Smuzhiyun 	return flags;
206*4882a593Smuzhiyun }
207*4882a593Smuzhiyun 
release_dma_lock(unsigned long flags)208*4882a593Smuzhiyun static __inline__ void release_dma_lock(unsigned long flags)
209*4882a593Smuzhiyun {
210*4882a593Smuzhiyun 	spin_unlock_irqrestore(&dma_spin_lock, flags);
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun /* enable/disable a specific DMA channel */
enable_dma(unsigned int dmanr)214*4882a593Smuzhiyun static __inline__ void enable_dma(unsigned int dmanr)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun 	if (dmanr<=3)
217*4882a593Smuzhiyun 		dma_outb(dmanr,  DMA1_MASK_REG);
218*4882a593Smuzhiyun 	else
219*4882a593Smuzhiyun 		dma_outb(dmanr & 3,  DMA2_MASK_REG);
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun 
disable_dma(unsigned int dmanr)222*4882a593Smuzhiyun static __inline__ void disable_dma(unsigned int dmanr)
223*4882a593Smuzhiyun {
224*4882a593Smuzhiyun 	if (dmanr<=3)
225*4882a593Smuzhiyun 		dma_outb(dmanr | 4,  DMA1_MASK_REG);
226*4882a593Smuzhiyun 	else
227*4882a593Smuzhiyun 		dma_outb((dmanr & 3) | 4,  DMA2_MASK_REG);
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun /* Clear the 'DMA Pointer Flip Flop'.
231*4882a593Smuzhiyun  * Write 0 for LSB/MSB, 1 for MSB/LSB access.
232*4882a593Smuzhiyun  * Use this once to initialize the FF to a known state.
233*4882a593Smuzhiyun  * After that, keep track of it. :-)
234*4882a593Smuzhiyun  * --- In order to do that, the DMA routines below should ---
235*4882a593Smuzhiyun  * --- only be used while interrupts are disabled! ---
236*4882a593Smuzhiyun  */
clear_dma_ff(unsigned int dmanr)237*4882a593Smuzhiyun static __inline__ void clear_dma_ff(unsigned int dmanr)
238*4882a593Smuzhiyun {
239*4882a593Smuzhiyun 	if (dmanr<=3)
240*4882a593Smuzhiyun 		dma_outb(0,  DMA1_CLEAR_FF_REG);
241*4882a593Smuzhiyun 	else
242*4882a593Smuzhiyun 		dma_outb(0,  DMA2_CLEAR_FF_REG);
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun /* set mode (above) for a specific DMA channel */
set_dma_mode(unsigned int dmanr,char mode)246*4882a593Smuzhiyun static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
247*4882a593Smuzhiyun {
248*4882a593Smuzhiyun 	if (dmanr<=3)
249*4882a593Smuzhiyun 		dma_outb(mode | dmanr,  DMA1_MODE_REG);
250*4882a593Smuzhiyun 	else
251*4882a593Smuzhiyun 		dma_outb(mode | (dmanr&3),  DMA2_MODE_REG);
252*4882a593Smuzhiyun }
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun /* set extended mode for a specific DMA channel */
set_dma_ext_mode(unsigned int dmanr,char ext_mode)255*4882a593Smuzhiyun static __inline__ void set_dma_ext_mode(unsigned int dmanr, char ext_mode)
256*4882a593Smuzhiyun {
257*4882a593Smuzhiyun 	if (dmanr<=3)
258*4882a593Smuzhiyun 		dma_outb(ext_mode | dmanr,  DMA1_EXT_MODE_REG);
259*4882a593Smuzhiyun 	else
260*4882a593Smuzhiyun 		dma_outb(ext_mode | (dmanr&3),  DMA2_EXT_MODE_REG);
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun /* Set only the page register bits of the transfer address.
264*4882a593Smuzhiyun  * This is used for successive transfers when we know the contents of
265*4882a593Smuzhiyun  * the lower 16 bits of the DMA current address register.
266*4882a593Smuzhiyun  */
set_dma_page(unsigned int dmanr,unsigned int pagenr)267*4882a593Smuzhiyun static __inline__ void set_dma_page(unsigned int dmanr, unsigned int pagenr)
268*4882a593Smuzhiyun {
269*4882a593Smuzhiyun 	switch(dmanr) {
270*4882a593Smuzhiyun 		case 0:
271*4882a593Smuzhiyun 			dma_outb(pagenr, DMA_PAGE_0);
272*4882a593Smuzhiyun 			dma_outb((pagenr >> 8), DMA_HIPAGE_0);
273*4882a593Smuzhiyun 			break;
274*4882a593Smuzhiyun 		case 1:
275*4882a593Smuzhiyun 			dma_outb(pagenr, DMA_PAGE_1);
276*4882a593Smuzhiyun 			dma_outb((pagenr >> 8), DMA_HIPAGE_1);
277*4882a593Smuzhiyun 			break;
278*4882a593Smuzhiyun 		case 2:
279*4882a593Smuzhiyun 			dma_outb(pagenr, DMA_PAGE_2);
280*4882a593Smuzhiyun 			dma_outb((pagenr >> 8), DMA_HIPAGE_2);
281*4882a593Smuzhiyun 			break;
282*4882a593Smuzhiyun 		case 3:
283*4882a593Smuzhiyun 			dma_outb(pagenr, DMA_PAGE_3);
284*4882a593Smuzhiyun 			dma_outb((pagenr >> 8), DMA_HIPAGE_3);
285*4882a593Smuzhiyun 			break;
286*4882a593Smuzhiyun 		case 5:
287*4882a593Smuzhiyun 			dma_outb(pagenr & 0xfe, DMA_PAGE_5);
288*4882a593Smuzhiyun 			dma_outb((pagenr >> 8), DMA_HIPAGE_5);
289*4882a593Smuzhiyun 			break;
290*4882a593Smuzhiyun 		case 6:
291*4882a593Smuzhiyun 			dma_outb(pagenr & 0xfe, DMA_PAGE_6);
292*4882a593Smuzhiyun 			dma_outb((pagenr >> 8), DMA_HIPAGE_6);
293*4882a593Smuzhiyun 			break;
294*4882a593Smuzhiyun 		case 7:
295*4882a593Smuzhiyun 			dma_outb(pagenr & 0xfe, DMA_PAGE_7);
296*4882a593Smuzhiyun 			dma_outb((pagenr >> 8), DMA_HIPAGE_7);
297*4882a593Smuzhiyun 			break;
298*4882a593Smuzhiyun 	}
299*4882a593Smuzhiyun }
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun /* Set transfer address & page bits for specific DMA channel.
303*4882a593Smuzhiyun  * Assumes dma flipflop is clear.
304*4882a593Smuzhiyun  */
set_dma_addr(unsigned int dmanr,unsigned int a)305*4882a593Smuzhiyun static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)
306*4882a593Smuzhiyun {
307*4882a593Smuzhiyun 	if (dmanr <= 3)  {
308*4882a593Smuzhiyun 	    dma_outb( a & 0xff, ((dmanr&3)<<1) + IO_DMA1_BASE );
309*4882a593Smuzhiyun             dma_outb( (a>>8) & 0xff, ((dmanr&3)<<1) + IO_DMA1_BASE );
310*4882a593Smuzhiyun 	}  else  {
311*4882a593Smuzhiyun 	    dma_outb( (a>>1) & 0xff, ((dmanr&3)<<2) + IO_DMA2_BASE );
312*4882a593Smuzhiyun 	    dma_outb( (a>>9) & 0xff, ((dmanr&3)<<2) + IO_DMA2_BASE );
313*4882a593Smuzhiyun 	}
314*4882a593Smuzhiyun 	set_dma_page(dmanr, a>>16);	/* set hipage last to enable 32-bit mode */
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun /* Set transfer size (max 64k for DMA1..3, 128k for DMA5..7) for
319*4882a593Smuzhiyun  * a specific DMA channel.
320*4882a593Smuzhiyun  * You must ensure the parameters are valid.
321*4882a593Smuzhiyun  * NOTE: from a manual: "the number of transfers is one more
322*4882a593Smuzhiyun  * than the initial word count"! This is taken into account.
323*4882a593Smuzhiyun  * Assumes dma flip-flop is clear.
324*4882a593Smuzhiyun  * NOTE 2: "count" represents _bytes_ and must be even for channels 5-7.
325*4882a593Smuzhiyun  */
set_dma_count(unsigned int dmanr,unsigned int count)326*4882a593Smuzhiyun static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
327*4882a593Smuzhiyun {
328*4882a593Smuzhiyun         count--;
329*4882a593Smuzhiyun 	if (dmanr <= 3)  {
330*4882a593Smuzhiyun 	    dma_outb( count & 0xff, ((dmanr&3)<<1) + 1 + IO_DMA1_BASE );
331*4882a593Smuzhiyun 	    dma_outb( (count>>8) & 0xff, ((dmanr&3)<<1) + 1 + IO_DMA1_BASE );
332*4882a593Smuzhiyun         } else {
333*4882a593Smuzhiyun 	    dma_outb( (count>>1) & 0xff, ((dmanr&3)<<2) + 2 + IO_DMA2_BASE );
334*4882a593Smuzhiyun 	    dma_outb( (count>>9) & 0xff, ((dmanr&3)<<2) + 2 + IO_DMA2_BASE );
335*4882a593Smuzhiyun         }
336*4882a593Smuzhiyun }
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun /* Get DMA residue count. After a DMA transfer, this
340*4882a593Smuzhiyun  * should return zero. Reading this while a DMA transfer is
341*4882a593Smuzhiyun  * still in progress will return unpredictable results.
342*4882a593Smuzhiyun  * If called before the channel has been used, it may return 1.
343*4882a593Smuzhiyun  * Otherwise, it returns the number of _bytes_ left to transfer.
344*4882a593Smuzhiyun  *
345*4882a593Smuzhiyun  * Assumes DMA flip-flop is clear.
346*4882a593Smuzhiyun  */
get_dma_residue(unsigned int dmanr)347*4882a593Smuzhiyun static __inline__ int get_dma_residue(unsigned int dmanr)
348*4882a593Smuzhiyun {
349*4882a593Smuzhiyun 	unsigned int io_port = (dmanr<=3)? ((dmanr&3)<<1) + 1 + IO_DMA1_BASE
350*4882a593Smuzhiyun 					 : ((dmanr&3)<<2) + 2 + IO_DMA2_BASE;
351*4882a593Smuzhiyun 
352*4882a593Smuzhiyun 	/* using short to get 16-bit wrap around */
353*4882a593Smuzhiyun 	unsigned short count;
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun 	count = 1 + dma_inb(io_port);
356*4882a593Smuzhiyun 	count += dma_inb(io_port) << 8;
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun 	return (dmanr<=3)? count : (count<<1);
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun /* These are in kernel/dma.c: */
363*4882a593Smuzhiyun extern int request_dma(unsigned int dmanr, const char * device_id);	/* reserve a DMA channel */
364*4882a593Smuzhiyun extern void free_dma(unsigned int dmanr);	/* release it again */
365*4882a593Smuzhiyun #define KERNEL_HAVE_CHECK_DMA
366*4882a593Smuzhiyun extern int check_dma(unsigned int dmanr);
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun /* From PCI */
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun #ifdef CONFIG_PCI
371*4882a593Smuzhiyun extern int isa_dma_bridge_buggy;
372*4882a593Smuzhiyun #else
373*4882a593Smuzhiyun #define isa_dma_bridge_buggy 	(0)
374*4882a593Smuzhiyun #endif
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun #endif /* _ASM_DMA_H */
378