1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef _ASM_DMA_H
19#define _ASM_DMA_H
20
21#include <linux/spinlock.h>
22#include <asm/io.h>
23
24#define dma_outb outb
25#define dma_inb inb
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75#define MAX_DMA_CHANNELS 8
76
77
78
79
80
81
82
83
84
85
86
87#define ALPHA_XL_MAX_ISA_DMA_ADDRESS 0x04000000UL
88
89
90
91
92#define ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS 0x01000000UL
93
94
95
96
97#define ALPHA_SABLE_MAX_ISA_DMA_ADDRESS 0x80000000UL
98#define ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS 0x80000000UL
99
100
101
102
103
104#define ALPHA_MAX_ISA_DMA_ADDRESS 0x100000000UL
105
106#ifdef CONFIG_ALPHA_GENERIC
107# define MAX_ISA_DMA_ADDRESS (alpha_mv.max_isa_dma_address)
108#else
109# if defined(CONFIG_ALPHA_XL)
110# define MAX_ISA_DMA_ADDRESS ALPHA_XL_MAX_ISA_DMA_ADDRESS
111# elif defined(CONFIG_ALPHA_RUFFIAN)
112# define MAX_ISA_DMA_ADDRESS ALPHA_RUFFIAN_MAX_ISA_DMA_ADDRESS
113# elif defined(CONFIG_ALPHA_SABLE)
114# define MAX_ISA_DMA_ADDRESS ALPHA_SABLE_MAX_ISA_DMA_ADDRESS
115# elif defined(CONFIG_ALPHA_ALCOR)
116# define MAX_ISA_DMA_ADDRESS ALPHA_ALCOR_MAX_ISA_DMA_ADDRESS
117# else
118# define MAX_ISA_DMA_ADDRESS ALPHA_MAX_ISA_DMA_ADDRESS
119# endif
120#endif
121
122
123
124
125#define MAX_DMA_ADDRESS (alpha_mv.mv_pci_tbi ? \
126 ~0UL : IDENT_ADDR + 0x01000000)
127
128
129#define IO_DMA1_BASE 0x00
130#define IO_DMA2_BASE 0xC0
131
132
133#define DMA1_CMD_REG 0x08
134#define DMA1_STAT_REG 0x08
135#define DMA1_REQ_REG 0x09
136#define DMA1_MASK_REG 0x0A
137#define DMA1_MODE_REG 0x0B
138#define DMA1_CLEAR_FF_REG 0x0C
139#define DMA1_TEMP_REG 0x0D
140#define DMA1_RESET_REG 0x0D
141#define DMA1_CLR_MASK_REG 0x0E
142#define DMA1_MASK_ALL_REG 0x0F
143#define DMA1_EXT_MODE_REG (0x400 | DMA1_MODE_REG)
144
145#define DMA2_CMD_REG 0xD0
146#define DMA2_STAT_REG 0xD0
147#define DMA2_REQ_REG 0xD2
148#define DMA2_MASK_REG 0xD4
149#define DMA2_MODE_REG 0xD6
150#define DMA2_CLEAR_FF_REG 0xD8
151#define DMA2_TEMP_REG 0xDA
152#define DMA2_RESET_REG 0xDA
153#define DMA2_CLR_MASK_REG 0xDC
154#define DMA2_MASK_ALL_REG 0xDE
155#define DMA2_EXT_MODE_REG (0x400 | DMA2_MODE_REG)
156
157#define DMA_ADDR_0 0x00
158#define DMA_ADDR_1 0x02
159#define DMA_ADDR_2 0x04
160#define DMA_ADDR_3 0x06
161#define DMA_ADDR_4 0xC0
162#define DMA_ADDR_5 0xC4
163#define DMA_ADDR_6 0xC8
164#define DMA_ADDR_7 0xCC
165
166#define DMA_CNT_0 0x01
167#define DMA_CNT_1 0x03
168#define DMA_CNT_2 0x05
169#define DMA_CNT_3 0x07
170#define DMA_CNT_4 0xC2
171#define DMA_CNT_5 0xC6
172#define DMA_CNT_6 0xCA
173#define DMA_CNT_7 0xCE
174
175#define DMA_PAGE_0 0x87
176#define DMA_PAGE_1 0x83
177#define DMA_PAGE_2 0x81
178#define DMA_PAGE_3 0x82
179#define DMA_PAGE_5 0x8B
180#define DMA_PAGE_6 0x89
181#define DMA_PAGE_7 0x8A
182
183#define DMA_HIPAGE_0 (0x400 | DMA_PAGE_0)
184#define DMA_HIPAGE_1 (0x400 | DMA_PAGE_1)
185#define DMA_HIPAGE_2 (0x400 | DMA_PAGE_2)
186#define DMA_HIPAGE_3 (0x400 | DMA_PAGE_3)
187#define DMA_HIPAGE_4 (0x400 | DMA_PAGE_4)
188#define DMA_HIPAGE_5 (0x400 | DMA_PAGE_5)
189#define DMA_HIPAGE_6 (0x400 | DMA_PAGE_6)
190#define DMA_HIPAGE_7 (0x400 | DMA_PAGE_7)
191
192#define DMA_MODE_READ 0x44
193#define DMA_MODE_WRITE 0x48
194#define DMA_MODE_CASCADE 0xC0
195
196#define DMA_AUTOINIT 0x10
197
198extern spinlock_t dma_spin_lock;
199
200static __inline__ unsigned long claim_dma_lock(void)
201{
202 unsigned long flags;
203 spin_lock_irqsave(&dma_spin_lock, flags);
204 return flags;
205}
206
207static __inline__ void release_dma_lock(unsigned long flags)
208{
209 spin_unlock_irqrestore(&dma_spin_lock, flags);
210}
211
212
213static __inline__ void enable_dma(unsigned int dmanr)
214{
215 if (dmanr<=3)
216 dma_outb(dmanr, DMA1_MASK_REG);
217 else
218 dma_outb(dmanr & 3, DMA2_MASK_REG);
219}
220
221static __inline__ void disable_dma(unsigned int dmanr)
222{
223 if (dmanr<=3)
224 dma_outb(dmanr | 4, DMA1_MASK_REG);
225 else
226 dma_outb((dmanr & 3) | 4, DMA2_MASK_REG);
227}
228
229
230
231
232
233
234
235
236static __inline__ void clear_dma_ff(unsigned int dmanr)
237{
238 if (dmanr<=3)
239 dma_outb(0, DMA1_CLEAR_FF_REG);
240 else
241 dma_outb(0, DMA2_CLEAR_FF_REG);
242}
243
244
245static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
246{
247 if (dmanr<=3)
248 dma_outb(mode | dmanr, DMA1_MODE_REG);
249 else
250 dma_outb(mode | (dmanr&3), DMA2_MODE_REG);
251}
252
253
254static __inline__ void set_dma_ext_mode(unsigned int dmanr, char ext_mode)
255{
256 if (dmanr<=3)
257 dma_outb(ext_mode | dmanr, DMA1_EXT_MODE_REG);
258 else
259 dma_outb(ext_mode | (dmanr&3), DMA2_EXT_MODE_REG);
260}
261
262
263
264
265
266static __inline__ void set_dma_page(unsigned int dmanr, unsigned int pagenr)
267{
268 switch(dmanr) {
269 case 0:
270 dma_outb(pagenr, DMA_PAGE_0);
271 dma_outb((pagenr >> 8), DMA_HIPAGE_0);
272 break;
273 case 1:
274 dma_outb(pagenr, DMA_PAGE_1);
275 dma_outb((pagenr >> 8), DMA_HIPAGE_1);
276 break;
277 case 2:
278 dma_outb(pagenr, DMA_PAGE_2);
279 dma_outb((pagenr >> 8), DMA_HIPAGE_2);
280 break;
281 case 3:
282 dma_outb(pagenr, DMA_PAGE_3);
283 dma_outb((pagenr >> 8), DMA_HIPAGE_3);
284 break;
285 case 5:
286 dma_outb(pagenr & 0xfe, DMA_PAGE_5);
287 dma_outb((pagenr >> 8), DMA_HIPAGE_5);
288 break;
289 case 6:
290 dma_outb(pagenr & 0xfe, DMA_PAGE_6);
291 dma_outb((pagenr >> 8), DMA_HIPAGE_6);
292 break;
293 case 7:
294 dma_outb(pagenr & 0xfe, DMA_PAGE_7);
295 dma_outb((pagenr >> 8), DMA_HIPAGE_7);
296 break;
297 }
298}
299
300
301
302
303
304static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)
305{
306 if (dmanr <= 3) {
307 dma_outb( a & 0xff, ((dmanr&3)<<1) + IO_DMA1_BASE );
308 dma_outb( (a>>8) & 0xff, ((dmanr&3)<<1) + IO_DMA1_BASE );
309 } else {
310 dma_outb( (a>>1) & 0xff, ((dmanr&3)<<2) + IO_DMA2_BASE );
311 dma_outb( (a>>9) & 0xff, ((dmanr&3)<<2) + IO_DMA2_BASE );
312 }
313 set_dma_page(dmanr, a>>16);
314}
315
316
317
318
319
320
321
322
323
324
325static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
326{
327 count--;
328 if (dmanr <= 3) {
329 dma_outb( count & 0xff, ((dmanr&3)<<1) + 1 + IO_DMA1_BASE );
330 dma_outb( (count>>8) & 0xff, ((dmanr&3)<<1) + 1 + IO_DMA1_BASE );
331 } else {
332 dma_outb( (count>>1) & 0xff, ((dmanr&3)<<2) + 2 + IO_DMA2_BASE );
333 dma_outb( (count>>9) & 0xff, ((dmanr&3)<<2) + 2 + IO_DMA2_BASE );
334 }
335}
336
337
338
339
340
341
342
343
344
345
346static __inline__ int get_dma_residue(unsigned int dmanr)
347{
348 unsigned int io_port = (dmanr<=3)? ((dmanr&3)<<1) + 1 + IO_DMA1_BASE
349 : ((dmanr&3)<<2) + 2 + IO_DMA2_BASE;
350
351
352 unsigned short count;
353
354 count = 1 + dma_inb(io_port);
355 count += dma_inb(io_port) << 8;
356
357 return (dmanr<=3)? count : (count<<1);
358}
359
360
361
362extern int request_dma(unsigned int dmanr, const char * device_id);
363extern void free_dma(unsigned int dmanr);
364#define KERNEL_HAVE_CHECK_DMA
365extern int check_dma(unsigned int dmanr);
366
367
368
369#ifdef CONFIG_PCI
370extern int isa_dma_bridge_buggy;
371#else
372#define isa_dma_bridge_buggy (0)
373#endif
374
375
376#endif
377