1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2024b246eSLinus Torvalds /*
3024b246eSLinus Torvalds * include/asm-alpha/dma.h
4024b246eSLinus Torvalds *
5024b246eSLinus Torvalds * This is essentially the same as the i386 DMA stuff, as the AlphaPCs
6024b246eSLinus Torvalds * use ISA-compatible dma. The only extension is support for high-page
7024b246eSLinus Torvalds * registers that allow to set the top 8 bits of a 32-bit DMA address.
8024b246eSLinus Torvalds * This register should be written last when setting up a DMA address
9024b246eSLinus Torvalds * as this will also enable DMA across 64 KB boundaries.
10024b246eSLinus Torvalds */
11024b246eSLinus Torvalds
12024b246eSLinus Torvalds /* $Id: dma.h,v 1.7 1992/12/14 00:29:34 root Exp root $
13024b246eSLinus Torvalds * linux/include/asm/dma.h: Defines for using and allocating dma channels.
14024b246eSLinus Torvalds * Written by Hennus Bergman, 1992.
15024b246eSLinus Torvalds * High DMA channel support & info by Hannu Savolainen
16024b246eSLinus Torvalds * and John Boyd, Nov. 1992.
17024b246eSLinus Torvalds */
18024b246eSLinus Torvalds
19024b246eSLinus Torvalds #ifndef _ASM_DMA_H
20024b246eSLinus Torvalds #define _ASM_DMA_H
21024b246eSLinus Torvalds
22024b246eSLinus Torvalds #include <linux/spinlock.h>
23024b246eSLinus Torvalds #include <asm/io.h>
24024b246eSLinus Torvalds
25024b246eSLinus Torvalds #define dma_outb outb
26024b246eSLinus Torvalds #define dma_inb inb
27024b246eSLinus Torvalds
28024b246eSLinus Torvalds /*
29024b246eSLinus Torvalds * NOTES about DMA transfers:
30024b246eSLinus Torvalds *
31024b246eSLinus Torvalds * controller 1: channels 0-3, byte operations, ports 00-1F
32024b246eSLinus Torvalds * controller 2: channels 4-7, word operations, ports C0-DF
33024b246eSLinus Torvalds *
34024b246eSLinus Torvalds * - ALL registers are 8 bits only, regardless of transfer size
35024b246eSLinus Torvalds * - channel 4 is not used - cascades 1 into 2.
36024b246eSLinus Torvalds * - channels 0-3 are byte - addresses/counts are for physical bytes
37024b246eSLinus Torvalds * - channels 5-7 are word - addresses/counts are for physical words
38024b246eSLinus Torvalds * - transfers must not cross physical 64K (0-3) or 128K (5-7) boundaries
39024b246eSLinus Torvalds * - transfer count loaded to registers is 1 less than actual count
40024b246eSLinus Torvalds * - controller 2 offsets are all even (2x offsets for controller 1)
41024b246eSLinus Torvalds * - page registers for 5-7 don't use data bit 0, represent 128K pages
42024b246eSLinus Torvalds * - page registers for 0-3 use bit 0, represent 64K pages
43024b246eSLinus Torvalds *
44024b246eSLinus Torvalds * DMA transfers are limited to the lower 16MB of _physical_ memory.
45024b246eSLinus Torvalds * Note that addresses loaded into registers must be _physical_ addresses,
46024b246eSLinus Torvalds * not logical addresses (which may differ if paging is active).
47024b246eSLinus Torvalds *
48024b246eSLinus Torvalds * Address mapping for channels 0-3:
49024b246eSLinus Torvalds *
50024b246eSLinus Torvalds * A23 ... A16 A15 ... A8 A7 ... A0 (Physical addresses)
51024b246eSLinus Torvalds * | ... | | ... | | ... |
52024b246eSLinus Torvalds * | ... | | ... | | ... |
53024b246eSLinus Torvalds * | ... | | ... | | ... |
54024b246eSLinus Torvalds * P7 ... P0 A7 ... A0 A7 ... A0
55024b246eSLinus Torvalds * | Page | Addr MSB | Addr LSB | (DMA registers)
56024b246eSLinus Torvalds *
57024b246eSLinus Torvalds * Address mapping for channels 5-7:
58024b246eSLinus Torvalds *
59024b246eSLinus Torvalds * A23 ... A17 A16 A15 ... A9 A8 A7 ... A1 A0 (Physical addresses)
60024b246eSLinus Torvalds * | ... | \ \ ... \ \ \ ... \ \
61024b246eSLinus Torvalds * | ... | \ \ ... \ \ \ ... \ (not used)
62024b246eSLinus Torvalds * | ... | \ \ ... \ \ \ ... \
63024b246eSLinus Torvalds * P7 ... P1 (0) A7 A6 ... A0 A7 A6 ... A0
64024b246eSLinus Torvalds * | Page | Addr MSB | Addr LSB | (DMA registers)
65024b246eSLinus Torvalds *
66024b246eSLinus Torvalds * Again, channels 5-7 transfer _physical_ words (16 bits), so addresses
67024b246eSLinus Torvalds * and counts _must_ be word-aligned (the lowest address bit is _ignored_ at
68024b246eSLinus Torvalds * the hardware level, so odd-byte transfers aren't possible).
69024b246eSLinus Torvalds *
70024b246eSLinus Torvalds * Transfer count (_not # bytes_) is limited to 64K, represented as actual
71024b246eSLinus Torvalds * count - 1 : 64K => 0xFFFF, 1 => 0x0000. Thus, count is always 1 or more,
72024b246eSLinus Torvalds * and up to 128K bytes may be transferred on channels 5-7 in one operation.
73024b246eSLinus Torvalds *
74024b246eSLinus Torvalds */
75024b246eSLinus Torvalds
76024b246eSLinus Torvalds #define MAX_DMA_CHANNELS 8
77024b246eSLinus Torvalds
78024b246eSLinus Torvalds /*
79024b246eSLinus Torvalds ISA DMA limitations on Alpha platforms,
80024b246eSLinus Torvalds
81024b246eSLinus Torvalds These may be due to SIO (PCI<->ISA bridge) chipset limitation, or
82024b246eSLinus Torvalds just a wiring limit.
83024b246eSLinus Torvalds */
84024b246eSLinus Torvalds
85024b246eSLinus Torvalds /* The maximum address for ISA DMA transfer on RUFFIAN,
86024b246eSLinus Torvalds due to an hardware SIO limitation, is 16MB.
87024b246eSLinus Torvalds */
88024b246eSLinus Torvalds #define ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS 0x01000000UL
89024b246eSLinus Torvalds
90024b246eSLinus Torvalds /* The maximum address for ISA DMA transfer on SABLE, and some ALCORs,
91024b246eSLinus Torvalds due to an hardware SIO chip limitation, is 2GB.
92024b246eSLinus Torvalds */
93024b246eSLinus Torvalds #define ALPHA_SABLE_MAX_ISA_DMA_ADDRESS 0x80000000UL
94024b246eSLinus Torvalds #define ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS 0x80000000UL
95024b246eSLinus Torvalds
96024b246eSLinus Torvalds /*
97024b246eSLinus Torvalds Maximum address for all the others is the complete 32-bit bus
98024b246eSLinus Torvalds address space.
99024b246eSLinus Torvalds */
100024b246eSLinus Torvalds #define ALPHA_MAX_ISA_DMA_ADDRESS 0x100000000UL
101024b246eSLinus Torvalds
102024b246eSLinus Torvalds #ifdef CONFIG_ALPHA_GENERIC
103024b246eSLinus Torvalds # define MAX_ISA_DMA_ADDRESS (alpha_mv.max_isa_dma_address)
104024b246eSLinus Torvalds #else
105*430ad3f0SArnd Bergmann # if defined(CONFIG_ALPHA_RUFFIAN)
106024b246eSLinus Torvalds # define MAX_ISA_DMA_ADDRESS ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS
107024b246eSLinus Torvalds # elif defined(CONFIG_ALPHA_SABLE)
108024b246eSLinus Torvalds # define MAX_ISA_DMA_ADDRESS ALPHA_SABLE_MAX_ISA_DMA_ADDRESS
109024b246eSLinus Torvalds # elif defined(CONFIG_ALPHA_ALCOR)
110024b246eSLinus Torvalds # define MAX_ISA_DMA_ADDRESS ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS
111024b246eSLinus Torvalds # else
112024b246eSLinus Torvalds # define MAX_ISA_DMA_ADDRESS ALPHA_MAX_ISA_DMA_ADDRESS
113024b246eSLinus Torvalds # endif
114024b246eSLinus Torvalds #endif
115024b246eSLinus Torvalds
116024b246eSLinus Torvalds /* If we have the iommu, we don't have any address limitations on DMA.
117024b246eSLinus Torvalds Otherwise (Nautilus, RX164), we have to have 0-16 Mb DMA zone
118024b246eSLinus Torvalds like i386. */
119024b246eSLinus Torvalds #define MAX_DMA_ADDRESS (alpha_mv.mv_pci_tbi ? \
120024b246eSLinus Torvalds ~0UL : IDENT_ADDR + 0x01000000)
121024b246eSLinus Torvalds
122024b246eSLinus Torvalds /* 8237 DMA controllers */
123024b246eSLinus Torvalds #define IO_DMA1_BASE 0x00 /* 8 bit slave DMA, channels 0..3 */
124024b246eSLinus Torvalds #define IO_DMA2_BASE 0xC0 /* 16 bit master DMA, ch 4(=slave input)..7 */
125024b246eSLinus Torvalds
126024b246eSLinus Torvalds /* DMA controller registers */
127024b246eSLinus Torvalds #define DMA1_CMD_REG 0x08 /* command register (w) */
128024b246eSLinus Torvalds #define DMA1_STAT_REG 0x08 /* status register (r) */
129024b246eSLinus Torvalds #define DMA1_REQ_REG 0x09 /* request register (w) */
130024b246eSLinus Torvalds #define DMA1_MASK_REG 0x0A /* single-channel mask (w) */
131024b246eSLinus Torvalds #define DMA1_MODE_REG 0x0B /* mode register (w) */
132024b246eSLinus Torvalds #define DMA1_CLEAR_FF_REG 0x0C /* clear pointer flip-flop (w) */
133024b246eSLinus Torvalds #define DMA1_TEMP_REG 0x0D /* Temporary Register (r) */
134024b246eSLinus Torvalds #define DMA1_RESET_REG 0x0D /* Master Clear (w) */
135024b246eSLinus Torvalds #define DMA1_CLR_MASK_REG 0x0E /* Clear Mask */
136024b246eSLinus Torvalds #define DMA1_MASK_ALL_REG 0x0F /* all-channels mask (w) */
137024b246eSLinus Torvalds #define DMA1_EXT_MODE_REG (0x400 | DMA1_MODE_REG)
138024b246eSLinus Torvalds
139024b246eSLinus Torvalds #define DMA2_CMD_REG 0xD0 /* command register (w) */
140024b246eSLinus Torvalds #define DMA2_STAT_REG 0xD0 /* status register (r) */
141024b246eSLinus Torvalds #define DMA2_REQ_REG 0xD2 /* request register (w) */
142024b246eSLinus Torvalds #define DMA2_MASK_REG 0xD4 /* single-channel mask (w) */
143024b246eSLinus Torvalds #define DMA2_MODE_REG 0xD6 /* mode register (w) */
144024b246eSLinus Torvalds #define DMA2_CLEAR_FF_REG 0xD8 /* clear pointer flip-flop (w) */
145024b246eSLinus Torvalds #define DMA2_TEMP_REG 0xDA /* Temporary Register (r) */
146024b246eSLinus Torvalds #define DMA2_RESET_REG 0xDA /* Master Clear (w) */
147024b246eSLinus Torvalds #define DMA2_CLR_MASK_REG 0xDC /* Clear Mask */
148024b246eSLinus Torvalds #define DMA2_MASK_ALL_REG 0xDE /* all-channels mask (w) */
149024b246eSLinus Torvalds #define DMA2_EXT_MODE_REG (0x400 | DMA2_MODE_REG)
150024b246eSLinus Torvalds
151024b246eSLinus Torvalds #define DMA_ADDR_0 0x00 /* DMA address registers */
152024b246eSLinus Torvalds #define DMA_ADDR_1 0x02
153024b246eSLinus Torvalds #define DMA_ADDR_2 0x04
154024b246eSLinus Torvalds #define DMA_ADDR_3 0x06
155024b246eSLinus Torvalds #define DMA_ADDR_4 0xC0
156024b246eSLinus Torvalds #define DMA_ADDR_5 0xC4
157024b246eSLinus Torvalds #define DMA_ADDR_6 0xC8
158024b246eSLinus Torvalds #define DMA_ADDR_7 0xCC
159024b246eSLinus Torvalds
160024b246eSLinus Torvalds #define DMA_CNT_0 0x01 /* DMA count registers */
161024b246eSLinus Torvalds #define DMA_CNT_1 0x03
162024b246eSLinus Torvalds #define DMA_CNT_2 0x05
163024b246eSLinus Torvalds #define DMA_CNT_3 0x07
164024b246eSLinus Torvalds #define DMA_CNT_4 0xC2
165024b246eSLinus Torvalds #define DMA_CNT_5 0xC6
166024b246eSLinus Torvalds #define DMA_CNT_6 0xCA
167024b246eSLinus Torvalds #define DMA_CNT_7 0xCE
168024b246eSLinus Torvalds
169024b246eSLinus Torvalds #define DMA_PAGE_0 0x87 /* DMA page registers */
170024b246eSLinus Torvalds #define DMA_PAGE_1 0x83
171024b246eSLinus Torvalds #define DMA_PAGE_2 0x81
172024b246eSLinus Torvalds #define DMA_PAGE_3 0x82
173024b246eSLinus Torvalds #define DMA_PAGE_5 0x8B
174024b246eSLinus Torvalds #define DMA_PAGE_6 0x89
175024b246eSLinus Torvalds #define DMA_PAGE_7 0x8A
176024b246eSLinus Torvalds
177024b246eSLinus Torvalds #define DMA_HIPAGE_0 (0x400 | DMA_PAGE_0)
178024b246eSLinus Torvalds #define DMA_HIPAGE_1 (0x400 | DMA_PAGE_1)
179024b246eSLinus Torvalds #define DMA_HIPAGE_2 (0x400 | DMA_PAGE_2)
180024b246eSLinus Torvalds #define DMA_HIPAGE_3 (0x400 | DMA_PAGE_3)
181024b246eSLinus Torvalds #define DMA_HIPAGE_4 (0x400 | DMA_PAGE_4)
182024b246eSLinus Torvalds #define DMA_HIPAGE_5 (0x400 | DMA_PAGE_5)
183024b246eSLinus Torvalds #define DMA_HIPAGE_6 (0x400 | DMA_PAGE_6)
184024b246eSLinus Torvalds #define DMA_HIPAGE_7 (0x400 | DMA_PAGE_7)
185024b246eSLinus Torvalds
186024b246eSLinus Torvalds #define DMA_MODE_READ 0x44 /* I/O to memory, no autoinit, increment, single mode */
187024b246eSLinus Torvalds #define DMA_MODE_WRITE 0x48 /* memory to I/O, no autoinit, increment, single mode */
188024b246eSLinus Torvalds #define DMA_MODE_CASCADE 0xC0 /* pass thru DREQ->HRQ, DACK<-HLDA only */
189024b246eSLinus Torvalds
190024b246eSLinus Torvalds #define DMA_AUTOINIT 0x10
191024b246eSLinus Torvalds
192024b246eSLinus Torvalds extern spinlock_t dma_spin_lock;
193024b246eSLinus Torvalds
claim_dma_lock(void)194024b246eSLinus Torvalds static __inline__ unsigned long claim_dma_lock(void)
195024b246eSLinus Torvalds {
196024b246eSLinus Torvalds unsigned long flags;
197024b246eSLinus Torvalds spin_lock_irqsave(&dma_spin_lock, flags);
198024b246eSLinus Torvalds return flags;
199024b246eSLinus Torvalds }
200024b246eSLinus Torvalds
release_dma_lock(unsigned long flags)201024b246eSLinus Torvalds static __inline__ void release_dma_lock(unsigned long flags)
202024b246eSLinus Torvalds {
203024b246eSLinus Torvalds spin_unlock_irqrestore(&dma_spin_lock, flags);
204024b246eSLinus Torvalds }
205024b246eSLinus Torvalds
206024b246eSLinus Torvalds /* enable/disable a specific DMA channel */
enable_dma(unsigned int dmanr)207024b246eSLinus Torvalds static __inline__ void enable_dma(unsigned int dmanr)
208024b246eSLinus Torvalds {
209024b246eSLinus Torvalds if (dmanr<=3)
210024b246eSLinus Torvalds dma_outb(dmanr, DMA1_MASK_REG);
211024b246eSLinus Torvalds else
212024b246eSLinus Torvalds dma_outb(dmanr & 3, DMA2_MASK_REG);
213024b246eSLinus Torvalds }
214024b246eSLinus Torvalds
disable_dma(unsigned int dmanr)215024b246eSLinus Torvalds static __inline__ void disable_dma(unsigned int dmanr)
216024b246eSLinus Torvalds {
217024b246eSLinus Torvalds if (dmanr<=3)
218024b246eSLinus Torvalds dma_outb(dmanr | 4, DMA1_MASK_REG);
219024b246eSLinus Torvalds else
220024b246eSLinus Torvalds dma_outb((dmanr & 3) | 4, DMA2_MASK_REG);
221024b246eSLinus Torvalds }
222024b246eSLinus Torvalds
223024b246eSLinus Torvalds /* Clear the 'DMA Pointer Flip Flop'.
224024b246eSLinus Torvalds * Write 0 for LSB/MSB, 1 for MSB/LSB access.
225024b246eSLinus Torvalds * Use this once to initialize the FF to a known state.
226024b246eSLinus Torvalds * After that, keep track of it. :-)
227024b246eSLinus Torvalds * --- In order to do that, the DMA routines below should ---
228024b246eSLinus Torvalds * --- only be used while interrupts are disabled! ---
229024b246eSLinus Torvalds */
clear_dma_ff(unsigned int dmanr)230024b246eSLinus Torvalds static __inline__ void clear_dma_ff(unsigned int dmanr)
231024b246eSLinus Torvalds {
232024b246eSLinus Torvalds if (dmanr<=3)
233024b246eSLinus Torvalds dma_outb(0, DMA1_CLEAR_FF_REG);
234024b246eSLinus Torvalds else
235024b246eSLinus Torvalds dma_outb(0, DMA2_CLEAR_FF_REG);
236024b246eSLinus Torvalds }
237024b246eSLinus Torvalds
238024b246eSLinus Torvalds /* set mode (above) for a specific DMA channel */
set_dma_mode(unsigned int dmanr,char mode)239024b246eSLinus Torvalds static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
240024b246eSLinus Torvalds {
241024b246eSLinus Torvalds if (dmanr<=3)
242024b246eSLinus Torvalds dma_outb(mode | dmanr, DMA1_MODE_REG);
243024b246eSLinus Torvalds else
244024b246eSLinus Torvalds dma_outb(mode | (dmanr&3), DMA2_MODE_REG);
245024b246eSLinus Torvalds }
246024b246eSLinus Torvalds
247024b246eSLinus Torvalds /* set extended mode for a specific DMA channel */
set_dma_ext_mode(unsigned int dmanr,char ext_mode)248024b246eSLinus Torvalds static __inline__ void set_dma_ext_mode(unsigned int dmanr, char ext_mode)
249024b246eSLinus Torvalds {
250024b246eSLinus Torvalds if (dmanr<=3)
251024b246eSLinus Torvalds dma_outb(ext_mode | dmanr, DMA1_EXT_MODE_REG);
252024b246eSLinus Torvalds else
253024b246eSLinus Torvalds dma_outb(ext_mode | (dmanr&3), DMA2_EXT_MODE_REG);
254024b246eSLinus Torvalds }
255024b246eSLinus Torvalds
256024b246eSLinus Torvalds /* Set only the page register bits of the transfer address.
257024b246eSLinus Torvalds * This is used for successive transfers when we know the contents of
258024b246eSLinus Torvalds * the lower 16 bits of the DMA current address register.
259024b246eSLinus Torvalds */
set_dma_page(unsigned int dmanr,unsigned int pagenr)260024b246eSLinus Torvalds static __inline__ void set_dma_page(unsigned int dmanr, unsigned int pagenr)
261024b246eSLinus Torvalds {
262024b246eSLinus Torvalds switch(dmanr) {
263024b246eSLinus Torvalds case 0:
264024b246eSLinus Torvalds dma_outb(pagenr, DMA_PAGE_0);
265024b246eSLinus Torvalds dma_outb((pagenr >> 8), DMA_HIPAGE_0);
266024b246eSLinus Torvalds break;
267024b246eSLinus Torvalds case 1:
268024b246eSLinus Torvalds dma_outb(pagenr, DMA_PAGE_1);
269024b246eSLinus Torvalds dma_outb((pagenr >> 8), DMA_HIPAGE_1);
270024b246eSLinus Torvalds break;
271024b246eSLinus Torvalds case 2:
272024b246eSLinus Torvalds dma_outb(pagenr, DMA_PAGE_2);
273024b246eSLinus Torvalds dma_outb((pagenr >> 8), DMA_HIPAGE_2);
274024b246eSLinus Torvalds break;
275024b246eSLinus Torvalds case 3:
276024b246eSLinus Torvalds dma_outb(pagenr, DMA_PAGE_3);
277024b246eSLinus Torvalds dma_outb((pagenr >> 8), DMA_HIPAGE_3);
278024b246eSLinus Torvalds break;
279024b246eSLinus Torvalds case 5:
280024b246eSLinus Torvalds dma_outb(pagenr & 0xfe, DMA_PAGE_5);
281024b246eSLinus Torvalds dma_outb((pagenr >> 8), DMA_HIPAGE_5);
282024b246eSLinus Torvalds break;
283024b246eSLinus Torvalds case 6:
284024b246eSLinus Torvalds dma_outb(pagenr & 0xfe, DMA_PAGE_6);
285024b246eSLinus Torvalds dma_outb((pagenr >> 8), DMA_HIPAGE_6);
286024b246eSLinus Torvalds break;
287024b246eSLinus Torvalds case 7:
288024b246eSLinus Torvalds dma_outb(pagenr & 0xfe, DMA_PAGE_7);
289024b246eSLinus Torvalds dma_outb((pagenr >> 8), DMA_HIPAGE_7);
290024b246eSLinus Torvalds break;
291024b246eSLinus Torvalds }
292024b246eSLinus Torvalds }
293024b246eSLinus Torvalds
294024b246eSLinus Torvalds
295024b246eSLinus Torvalds /* Set transfer address & page bits for specific DMA channel.
296024b246eSLinus Torvalds * Assumes dma flipflop is clear.
297024b246eSLinus Torvalds */
set_dma_addr(unsigned int dmanr,unsigned int a)298024b246eSLinus Torvalds static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)
299024b246eSLinus Torvalds {
300024b246eSLinus Torvalds if (dmanr <= 3) {
301024b246eSLinus Torvalds dma_outb( a & 0xff, ((dmanr&3)<<1) + IO_DMA1_BASE );
302024b246eSLinus Torvalds dma_outb( (a>>8) & 0xff, ((dmanr&3)<<1) + IO_DMA1_BASE );
303024b246eSLinus Torvalds } else {
304024b246eSLinus Torvalds dma_outb( (a>>1) & 0xff, ((dmanr&3)<<2) + IO_DMA2_BASE );
305024b246eSLinus Torvalds dma_outb( (a>>9) & 0xff, ((dmanr&3)<<2) + IO_DMA2_BASE );
306024b246eSLinus Torvalds }
307024b246eSLinus Torvalds set_dma_page(dmanr, a>>16); /* set hipage last to enable 32-bit mode */
308024b246eSLinus Torvalds }
309024b246eSLinus Torvalds
310024b246eSLinus Torvalds
311024b246eSLinus Torvalds /* Set transfer size (max 64k for DMA1..3, 128k for DMA5..7) for
312024b246eSLinus Torvalds * a specific DMA channel.
313024b246eSLinus Torvalds * You must ensure the parameters are valid.
314024b246eSLinus Torvalds * NOTE: from a manual: "the number of transfers is one more
315024b246eSLinus Torvalds * than the initial word count"! This is taken into account.
316024b246eSLinus Torvalds * Assumes dma flip-flop is clear.
317024b246eSLinus Torvalds * NOTE 2: "count" represents _bytes_ and must be even for channels 5-7.
318024b246eSLinus Torvalds */
set_dma_count(unsigned int dmanr,unsigned int count)319024b246eSLinus Torvalds static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
320024b246eSLinus Torvalds {
321024b246eSLinus Torvalds count--;
322024b246eSLinus Torvalds if (dmanr <= 3) {
323024b246eSLinus Torvalds dma_outb( count & 0xff, ((dmanr&3)<<1) + 1 + IO_DMA1_BASE );
324024b246eSLinus Torvalds dma_outb( (count>>8) & 0xff, ((dmanr&3)<<1) + 1 + IO_DMA1_BASE );
325024b246eSLinus Torvalds } else {
326024b246eSLinus Torvalds dma_outb( (count>>1) & 0xff, ((dmanr&3)<<2) + 2 + IO_DMA2_BASE );
327024b246eSLinus Torvalds dma_outb( (count>>9) & 0xff, ((dmanr&3)<<2) + 2 + IO_DMA2_BASE );
328024b246eSLinus Torvalds }
329024b246eSLinus Torvalds }
330024b246eSLinus Torvalds
331024b246eSLinus Torvalds
332024b246eSLinus Torvalds /* Get DMA residue count. After a DMA transfer, this
333024b246eSLinus Torvalds * should return zero. Reading this while a DMA transfer is
334024b246eSLinus Torvalds * still in progress will return unpredictable results.
335024b246eSLinus Torvalds * If called before the channel has been used, it may return 1.
336024b246eSLinus Torvalds * Otherwise, it returns the number of _bytes_ left to transfer.
337024b246eSLinus Torvalds *
338024b246eSLinus Torvalds * Assumes DMA flip-flop is clear.
339024b246eSLinus Torvalds */
get_dma_residue(unsigned int dmanr)340024b246eSLinus Torvalds static __inline__ int get_dma_residue(unsigned int dmanr)
341024b246eSLinus Torvalds {
342024b246eSLinus Torvalds unsigned int io_port = (dmanr<=3)? ((dmanr&3)<<1) + 1 + IO_DMA1_BASE
343024b246eSLinus Torvalds : ((dmanr&3)<<2) + 2 + IO_DMA2_BASE;
344024b246eSLinus Torvalds
345024b246eSLinus Torvalds /* using short to get 16-bit wrap around */
346024b246eSLinus Torvalds unsigned short count;
347024b246eSLinus Torvalds
348024b246eSLinus Torvalds count = 1 + dma_inb(io_port);
349024b246eSLinus Torvalds count += dma_inb(io_port) << 8;
350024b246eSLinus Torvalds
351024b246eSLinus Torvalds return (dmanr<=3)? count : (count<<1);
352024b246eSLinus Torvalds }
353024b246eSLinus Torvalds
354024b246eSLinus Torvalds
355024b246eSLinus Torvalds /* These are in kernel/dma.c: */
356024b246eSLinus Torvalds extern int request_dma(unsigned int dmanr, const char * device_id); /* reserve a DMA channel */
357024b246eSLinus Torvalds extern void free_dma(unsigned int dmanr); /* release it again */
358024b246eSLinus Torvalds #define KERNEL_HAVE_CHECK_DMA
359024b246eSLinus Torvalds extern int check_dma(unsigned int dmanr);
360024b246eSLinus Torvalds
361024b246eSLinus Torvalds #endif /* _ASM_DMA_H */
362