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
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/sched.h>
17 #include <linux/mman.h>
18 #include <linux/init.h>
19 #include <linux/spinlock.h>
23 #include <asm/mach/dma.h>
25 spinlock_t dma_spin_lock = SPIN_LOCK_UNLOCKED;
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)
40 for (i = 0, dma = dma_chan; i < MAX_DMA_CHANNELS; i++, dma++)
42 p += sprintf(p, "%2d: %14s %s\n", i,
43 dma->d_ops->type, dma->device_id);
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;
58 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
61 if (xchg(&dma->lock, 1) != 0)
64 dma->device_id = device_id;
69 if (dma->d_ops->request)
70 ret = dma->d_ops->request(channel, dma);
78 printk(KERN_ERR "dma: trying to allocate DMA%d\n", 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)
98 printk(KERN_ERR "dma%d: freeing active DMA\n", channel);
99 dma->d_ops->disable(channel, dma);
103 if (xchg(&dma->lock, 0) != 0) {
104 if (dma->d_ops->free)
105 dma->d_ops->free(channel, dma);
109 printk(KERN_ERR "dma%d: trying to free free DMA\n", channel);
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;
123 dma->sgcount = nr_sg;
130 * Copy address to the structure, and set the invalid bit
132 void set_dma_addr (dmach_t channel, unsigned long physaddr)
134 dma_t *dma = dma_chan + channel;
137 printk(KERN_ERR "dma%d: altering DMA address while "
138 "DMA active\n", channel);
142 dma->buf.address = bus_to_virt(physaddr);
147 /* Set DMA byte count
149 * Copy address to the structure, and set the invalid bit
151 void set_dma_count (dmach_t channel, unsigned long count)
153 dma_t *dma = dma_chan + channel;
156 printk(KERN_ERR "dma%d: altering DMA count while "
157 "DMA active\n", channel);
161 dma->buf.length = count;
166 /* Set DMA direction mode
168 void set_dma_mode (dmach_t channel, dmamode_t mode)
170 dma_t *dma = dma_chan + channel;
173 printk(KERN_ERR "dma%d: altering DMA mode while "
174 "DMA active\n", channel);
176 dma->dma_mode = mode;
180 /* Enable DMA channel
182 void enable_dma (dmach_t channel)
184 dma_t *dma = dma_chan + channel;
189 if (dma->active == 0) {
191 dma->d_ops->enable(channel, dma);
196 printk(KERN_ERR "dma%d: trying to enable free DMA\n", channel);
200 /* Disable DMA channel
202 void disable_dma (dmach_t channel)
204 dma_t *dma = dma_chan + channel;
209 if (dma->active == 1) {
211 dma->d_ops->disable(channel, dma);
216 printk(KERN_ERR "dma%d: trying to disable free DMA\n", channel);
220 void set_dma_page(dmach_t channel, char pagenr)
222 printk(KERN_ERR "dma%d: trying to set_dma_page\n", channel);
225 void set_dma_speed(dmach_t channel, int cycle_ns)
227 dma_t *dma = dma_chan + channel;
230 if (dma->d_ops->setspeed)
231 ret = dma->d_ops->setspeed(channel, dma, cycle_ns);
235 int get_dma_residue(dmach_t channel)
237 dma_t *dma = dma_chan + channel;
240 if (dma->d_ops->residue)
241 ret = dma->d_ops->residue(channel, dma);
246 void __init init_dma(void)
248 arch_dma_init(dma_chan);
253 int request_dma(dmach_t channel, const char *device_id)
258 int get_dma_residue(dmach_t channel)
263 #define GLOBAL_ALIAS(_a,_b) asm (".set " #_a "," #_b "; .globl " #_a)
264 GLOBAL_ALIAS(disable_dma, get_dma_residue);
265 GLOBAL_ALIAS(enable_dma, get_dma_residue);
266 GLOBAL_ALIAS(free_dma, get_dma_residue);
267 GLOBAL_ALIAS(get_dma_list, get_dma_residue);
268 GLOBAL_ALIAS(set_dma_mode, get_dma_residue);
269 GLOBAL_ALIAS(set_dma_page, get_dma_residue);
270 GLOBAL_ALIAS(set_dma_count, get_dma_residue);
271 GLOBAL_ALIAS(set_dma_addr, get_dma_residue);
272 GLOBAL_ALIAS(set_dma_sg, get_dma_residue);
273 GLOBAL_ALIAS(set_dma_speed, get_dma_residue);
274 GLOBAL_ALIAS(init_dma, get_dma_residue);
278 EXPORT_SYMBOL(request_dma);
279 EXPORT_SYMBOL(free_dma);
280 EXPORT_SYMBOL(enable_dma);
281 EXPORT_SYMBOL(disable_dma);
282 EXPORT_SYMBOL(set_dma_addr);
283 EXPORT_SYMBOL(set_dma_count);
284 EXPORT_SYMBOL(set_dma_mode);
285 EXPORT_SYMBOL(set_dma_page);
286 EXPORT_SYMBOL(get_dma_residue);
287 EXPORT_SYMBOL(set_dma_sg);
288 EXPORT_SYMBOL(set_dma_speed);