[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / arm / kernel / dma.c
blob2b78838842346da390e8547cd37035184376d506
1 /*
2 * linux/arch/arm/kernel/dma.c
4 * Copyright (C) 1995-2000 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Front-end to the DMA handling. This handles the allocation/freeing
11 * of DMA channels, and provides a unified interface to the machines
12 * DMA facilities.
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/mman.h>
17 #include <linux/init.h>
18 #include <linux/spinlock.h>
19 #include <linux/errno.h>
21 #include <asm/dma.h>
23 #include <asm/mach/dma.h>
25 DEFINE_SPINLOCK(dma_spin_lock);
27 #if MAX_DMA_CHANNELS > 0
29 static dma_t dma_chan[MAX_DMA_CHANNELS];
32 * Get dma list for /proc/dma
34 int get_dma_list(char *buf)
36 dma_t *dma;
37 char *p = buf;
38 int i;
40 for (i = 0, dma = dma_chan; i < MAX_DMA_CHANNELS; i++, dma++)
41 if (dma->lock)
42 p += sprintf(p, "%2d: %14s %s\n", i,
43 dma->d_ops->type, dma->device_id);
45 return p - buf;
49 * Request DMA channel
51 * On certain platforms, we have to allocate an interrupt as well...
53 int request_dma(dmach_t channel, const char *device_id)
55 dma_t *dma = dma_chan + channel;
56 int ret;
58 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
59 goto bad_dma;
61 if (xchg(&dma->lock, 1) != 0)
62 goto busy;
64 dma->device_id = device_id;
65 dma->active = 0;
66 dma->invalid = 1;
68 ret = 0;
69 if (dma->d_ops->request)
70 ret = dma->d_ops->request(channel, dma);
72 if (ret)
73 xchg(&dma->lock, 0);
75 return ret;
77 bad_dma:
78 printk(KERN_ERR "dma: trying to allocate DMA%d\n", channel);
79 return -EINVAL;
81 busy:
82 return -EBUSY;
86 * Free DMA channel
88 * On certain platforms, we have to free interrupt as well...
90 void free_dma(dmach_t channel)
92 dma_t *dma = dma_chan + channel;
94 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
95 goto bad_dma;
97 if (dma->active) {
98 printk(KERN_ERR "dma%d: freeing active DMA\n", channel);
99 dma->d_ops->disable(channel, dma);
100 dma->active = 0;
103 if (xchg(&dma->lock, 0) != 0) {
104 if (dma->d_ops->free)
105 dma->d_ops->free(channel, dma);
106 return;
109 printk(KERN_ERR "dma%d: trying to free free DMA\n", channel);
110 return;
112 bad_dma:
113 printk(KERN_ERR "dma: trying to free DMA%d\n", channel);
116 /* Set DMA Scatter-Gather list
118 void set_dma_sg (dmach_t channel, struct scatterlist *sg, int nr_sg)
120 dma_t *dma = dma_chan + channel;
122 if (dma->active)
123 printk(KERN_ERR "dma%d: altering DMA SG while "
124 "DMA active\n", channel);
126 dma->sg = sg;
127 dma->sgcount = nr_sg;
128 dma->using_sg = 1;
129 dma->invalid = 1;
132 /* Set DMA address
134 * Copy address to the structure, and set the invalid bit
136 void set_dma_addr (dmach_t channel, unsigned long physaddr)
138 dma_t *dma = dma_chan + channel;
140 if (dma->active)
141 printk(KERN_ERR "dma%d: altering DMA address while "
142 "DMA active\n", channel);
144 dma->sg = &dma->buf;
145 dma->sgcount = 1;
146 dma->buf.__address = bus_to_virt(physaddr);
147 dma->using_sg = 0;
148 dma->invalid = 1;
151 /* Set DMA byte count
153 * Copy address to the structure, and set the invalid bit
155 void set_dma_count (dmach_t channel, unsigned long count)
157 dma_t *dma = dma_chan + channel;
159 if (dma->active)
160 printk(KERN_ERR "dma%d: altering DMA count while "
161 "DMA active\n", channel);
163 dma->sg = &dma->buf;
164 dma->sgcount = 1;
165 dma->buf.length = count;
166 dma->using_sg = 0;
167 dma->invalid = 1;
170 /* Set DMA direction mode
172 void set_dma_mode (dmach_t channel, dmamode_t mode)
174 dma_t *dma = dma_chan + channel;
176 if (dma->active)
177 printk(KERN_ERR "dma%d: altering DMA mode while "
178 "DMA active\n", channel);
180 dma->dma_mode = mode;
181 dma->invalid = 1;
184 /* Enable DMA channel
186 void enable_dma (dmach_t channel)
188 dma_t *dma = dma_chan + channel;
190 if (!dma->lock)
191 goto free_dma;
193 if (dma->active == 0) {
194 dma->active = 1;
195 dma->d_ops->enable(channel, dma);
197 return;
199 free_dma:
200 printk(KERN_ERR "dma%d: trying to enable free DMA\n", channel);
201 BUG();
204 /* Disable DMA channel
206 void disable_dma (dmach_t channel)
208 dma_t *dma = dma_chan + channel;
210 if (!dma->lock)
211 goto free_dma;
213 if (dma->active == 1) {
214 dma->active = 0;
215 dma->d_ops->disable(channel, dma);
217 return;
219 free_dma:
220 printk(KERN_ERR "dma%d: trying to disable free DMA\n", channel);
221 BUG();
225 * Is the specified DMA channel active?
227 int dma_channel_active(dmach_t channel)
229 return dma_chan[channel].active;
232 void set_dma_page(dmach_t channel, char pagenr)
234 printk(KERN_ERR "dma%d: trying to set_dma_page\n", channel);
237 void set_dma_speed(dmach_t channel, int cycle_ns)
239 dma_t *dma = dma_chan + channel;
240 int ret = 0;
242 if (dma->d_ops->setspeed)
243 ret = dma->d_ops->setspeed(channel, dma, cycle_ns);
244 dma->speed = ret;
247 int get_dma_residue(dmach_t channel)
249 dma_t *dma = dma_chan + channel;
250 int ret = 0;
252 if (dma->d_ops->residue)
253 ret = dma->d_ops->residue(channel, dma);
255 return ret;
258 void __init init_dma(void)
260 arch_dma_init(dma_chan);
263 #else
265 int request_dma(dmach_t channel, const char *device_id)
267 return -EINVAL;
270 int get_dma_residue(dmach_t channel)
272 return 0;
275 #define GLOBAL_ALIAS(_a,_b) asm (".set " #_a "," #_b "; .globl " #_a)
276 GLOBAL_ALIAS(disable_dma, get_dma_residue);
277 GLOBAL_ALIAS(enable_dma, get_dma_residue);
278 GLOBAL_ALIAS(free_dma, get_dma_residue);
279 GLOBAL_ALIAS(get_dma_list, get_dma_residue);
280 GLOBAL_ALIAS(set_dma_mode, get_dma_residue);
281 GLOBAL_ALIAS(set_dma_page, get_dma_residue);
282 GLOBAL_ALIAS(set_dma_count, get_dma_residue);
283 GLOBAL_ALIAS(set_dma_addr, get_dma_residue);
284 GLOBAL_ALIAS(set_dma_sg, get_dma_residue);
285 GLOBAL_ALIAS(set_dma_speed, get_dma_residue);
286 GLOBAL_ALIAS(init_dma, get_dma_residue);
288 #endif
290 EXPORT_SYMBOL(request_dma);
291 EXPORT_SYMBOL(free_dma);
292 EXPORT_SYMBOL(enable_dma);
293 EXPORT_SYMBOL(disable_dma);
294 EXPORT_SYMBOL(set_dma_addr);
295 EXPORT_SYMBOL(set_dma_count);
296 EXPORT_SYMBOL(set_dma_mode);
297 EXPORT_SYMBOL(set_dma_page);
298 EXPORT_SYMBOL(get_dma_residue);
299 EXPORT_SYMBOL(set_dma_sg);
300 EXPORT_SYMBOL(set_dma_speed);
302 EXPORT_SYMBOL(dma_spin_lock);