ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-parisc / dma.h
1 /* $Id: dma.h,v 1.2 1999/04/27 00:46:18 deller Exp $
2  * linux/include/asm/dma.h: Defines for using and allocating dma channels.
3  * Written by Hennus Bergman, 1992.
4  * High DMA channel support & info by Hannu Savolainen
5  * and John Boyd, Nov. 1992.
6  * (c) Copyright 2000, Grant Grundler
7  */
8
9 #ifndef _ASM_DMA_H
10 #define _ASM_DMA_H
11
12 #include <linux/config.h>
13 #include <asm/io.h>             /* need byte IO */
14 #include <asm/system.h> 
15
16 #define dma_outb        outb
17 #define dma_inb         inb
18
19 /*
20 ** DMA_CHUNK_SIZE is used by the SCSI mid-layer to break up
21 ** (or rather not merge) DMA's into managable chunks.
22 ** On parisc, this is more of the software/tuning constraint
23 ** rather than the HW. I/O MMU allocation alogorithms can be
24 ** faster with smaller size is (to some degree).
25 */
26 #define DMA_CHUNK_SIZE  (BITS_PER_LONG*PAGE_SIZE)
27
28 /* The maximum address that we can perform a DMA transfer to on this platform
29 ** New dynamic DMA interfaces should obsolete this....
30 */
31 #define MAX_DMA_ADDRESS (~0UL)
32
33 /*
34 ** We don't have DMA channels... well V-class does but the
35 ** Dynamic DMA Mapping interface will support them... right? :^)
36 ** Note: this is not relevant right now for PA-RISC, but we cannot 
37 ** leave this as undefined because some things (e.g. sound)
38 ** won't compile :-(
39 */
40 #define MAX_DMA_CHANNELS 8
41 #define DMA_MODE_READ    1
42 #define DMA_MODE_WRITE   2
43 #define DMA_AUTOINIT     0x10
44
45 /* 8237 DMA controllers */
46 #define IO_DMA1_BASE    0x00    /* 8 bit slave DMA, channels 0..3 */
47 #define IO_DMA2_BASE    0xC0    /* 16 bit master DMA, ch 4(=slave input)..7 */
48
49 /* DMA controller registers */
50 #define DMA1_CMD_REG            0x08    /* command register (w) */
51 #define DMA1_STAT_REG           0x08    /* status register (r) */
52 #define DMA1_REQ_REG            0x09    /* request register (w) */
53 #define DMA1_MASK_REG           0x0A    /* single-channel mask (w) */
54 #define DMA1_MODE_REG           0x0B    /* mode register (w) */
55 #define DMA1_CLEAR_FF_REG       0x0C    /* clear pointer flip-flop (w) */
56 #define DMA1_TEMP_REG           0x0D    /* Temporary Register (r) */
57 #define DMA1_RESET_REG          0x0D    /* Master Clear (w) */
58 #define DMA1_CLR_MASK_REG       0x0E    /* Clear Mask */
59 #define DMA1_MASK_ALL_REG       0x0F    /* all-channels mask (w) */
60 #define DMA1_EXT_MODE_REG       (0x400 | DMA1_MODE_REG)
61
62 #define DMA2_CMD_REG            0xD0    /* command register (w) */
63 #define DMA2_STAT_REG           0xD0    /* status register (r) */
64 #define DMA2_REQ_REG            0xD2    /* request register (w) */
65 #define DMA2_MASK_REG           0xD4    /* single-channel mask (w) */
66 #define DMA2_MODE_REG           0xD6    /* mode register (w) */
67 #define DMA2_CLEAR_FF_REG       0xD8    /* clear pointer flip-flop (w) */
68 #define DMA2_TEMP_REG           0xDA    /* Temporary Register (r) */
69 #define DMA2_RESET_REG          0xDA    /* Master Clear (w) */
70 #define DMA2_CLR_MASK_REG       0xDC    /* Clear Mask */
71 #define DMA2_MASK_ALL_REG       0xDE    /* all-channels mask (w) */
72 #define DMA2_EXT_MODE_REG       (0x400 | DMA2_MODE_REG)
73
74 extern spinlock_t dma_spin_lock;
75
76 static __inline__ unsigned long claim_dma_lock(void)
77 {
78         unsigned long flags;
79         spin_lock_irqsave(&dma_spin_lock, flags);
80         return flags;
81 }
82
83 static __inline__ void release_dma_lock(unsigned long flags)
84 {
85         spin_unlock_irqrestore(&dma_spin_lock, flags);
86 }
87
88
89 /* Get DMA residue count. After a DMA transfer, this
90  * should return zero. Reading this while a DMA transfer is
91  * still in progress will return unpredictable results.
92  * If called before the channel has been used, it may return 1.
93  * Otherwise, it returns the number of _bytes_ left to transfer.
94  *
95  * Assumes DMA flip-flop is clear.
96  */
97 static __inline__ int get_dma_residue(unsigned int dmanr)
98 {
99         unsigned int io_port = (dmanr<=3)? ((dmanr&3)<<1) + 1 + IO_DMA1_BASE
100                                          : ((dmanr&3)<<2) + 2 + IO_DMA2_BASE;
101
102         /* using short to get 16-bit wrap around */
103         unsigned short count;
104
105         count = 1 + dma_inb(io_port);
106         count += dma_inb(io_port) << 8;
107         
108         return (dmanr<=3)? count : (count<<1);
109 }
110
111 /* enable/disable a specific DMA channel */
112 static __inline__ void enable_dma(unsigned int dmanr)
113 {
114 #ifdef CONFIG_SUPERIO
115         if (dmanr<=3)
116                 dma_outb(dmanr,  DMA1_MASK_REG);
117         else
118                 dma_outb(dmanr & 3,  DMA2_MASK_REG);
119 #endif
120 }
121
122 static __inline__ void disable_dma(unsigned int dmanr)
123 {
124 #ifdef CONFIG_SUPERIO
125         if (dmanr<=3)
126                 dma_outb(dmanr | 4,  DMA1_MASK_REG);
127         else
128                 dma_outb((dmanr & 3) | 4,  DMA2_MASK_REG);
129 #endif
130 }
131
132 /* reserve a DMA channel */
133 #define request_dma(dmanr, device_id)   (0)
134
135 /* Clear the 'DMA Pointer Flip Flop'.
136  * Write 0 for LSB/MSB, 1 for MSB/LSB access.
137  * Use this once to initialize the FF to a known state.
138  * After that, keep track of it. :-)
139  * --- In order to do that, the DMA routines below should ---
140  * --- only be used while holding the DMA lock ! ---
141  */
142 static __inline__ void clear_dma_ff(unsigned int dmanr)
143 {
144 }
145
146 /* set mode (above) for a specific DMA channel */
147 static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
148 {
149 }
150
151 /* Set only the page register bits of the transfer address.
152  * This is used for successive transfers when we know the contents of
153  * the lower 16 bits of the DMA current address register, but a 64k boundary
154  * may have been crossed.
155  */
156 static __inline__ void set_dma_page(unsigned int dmanr, char pagenr)
157 {
158 }
159
160
161 /* Set transfer address & page bits for specific DMA channel.
162  * Assumes dma flipflop is clear.
163  */
164 static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)
165 {
166 }
167
168
169 /* Set transfer size (max 64k for DMA1..3, 128k for DMA5..7) for
170  * a specific DMA channel.
171  * You must ensure the parameters are valid.
172  * NOTE: from a manual: "the number of transfers is one more
173  * than the initial word count"! This is taken into account.
174  * Assumes dma flip-flop is clear.
175  * NOTE 2: "count" represents _bytes_ and must be even for channels 5-7.
176  */
177 static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
178 {
179 }
180
181
182 #define free_dma(dmanr)
183
184 #ifdef CONFIG_PCI
185 extern int isa_dma_bridge_buggy;
186 #else
187 #define isa_dma_bridge_buggy    (0)
188 #endif
189
190 #endif /* _ASM_DMA_H */