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/init.h>
16 #include <linux/spinlock.h>
17 #include <linux/errno.h>
21 #include <asm/mach/dma.h>
23 DEFINE_SPINLOCK(dma_spin_lock);
25 #if MAX_DMA_CHANNELS > 0
27 static dma_t dma_chan[MAX_DMA_CHANNELS];
30 * Get dma list for /proc/dma
32 int get_dma_list(char *buf)
38 for (i = 0, dma = dma_chan; i < MAX_DMA_CHANNELS; i++, dma++)
40 p += sprintf(p, "%2d: %14s %s\n", i,
41 dma->d_ops->type, dma->device_id);
49 * On certain platforms, we have to allocate an interrupt as well...
51 int request_dma(dmach_t channel, const char *device_id)
53 dma_t *dma = dma_chan + channel;
56 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
59 if (xchg(&dma->lock, 1) != 0)
62 dma->device_id = device_id;
67 if (dma->d_ops->request)
68 ret = dma->d_ops->request(channel, dma);
76 printk(KERN_ERR "dma: trying to allocate DMA%d\n", channel);
86 * On certain platforms, we have to free interrupt as well...
88 void free_dma(dmach_t channel)
90 dma_t *dma = dma_chan + channel;
92 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
96 printk(KERN_ERR "dma%d: freeing active DMA\n", channel);
97 dma->d_ops->disable(channel, dma);
101 if (xchg(&dma->lock, 0) != 0) {
102 if (dma->d_ops->free)
103 dma->d_ops->free(channel, dma);
107 printk(KERN_ERR "dma%d: trying to free free DMA\n", channel);
111 printk(KERN_ERR "dma: trying to free DMA%d\n", channel);
114 /* Set DMA Scatter-Gather list
116 void set_dma_sg (dmach_t channel, struct scatterlist *sg, int nr_sg)
118 dma_t *dma = dma_chan + channel;
121 printk(KERN_ERR "dma%d: altering DMA SG while "
122 "DMA active\n", channel);
125 dma->sgcount = nr_sg;
131 * Copy address to the structure, and set the invalid bit
133 void __set_dma_addr (dmach_t channel, void *addr)
135 dma_t *dma = dma_chan + channel;
138 printk(KERN_ERR "dma%d: altering DMA address while "
139 "DMA active\n", channel);
146 /* Set DMA byte count
148 * Copy address to the structure, and set the invalid bit
150 void set_dma_count (dmach_t channel, unsigned long count)
152 dma_t *dma = dma_chan + channel;
155 printk(KERN_ERR "dma%d: altering DMA count while "
156 "DMA active\n", channel);
163 /* Set DMA direction mode
165 void set_dma_mode (dmach_t channel, dmamode_t mode)
167 dma_t *dma = dma_chan + channel;
170 printk(KERN_ERR "dma%d: altering DMA mode while "
171 "DMA active\n", channel);
173 dma->dma_mode = mode;
177 /* Enable DMA channel
179 void enable_dma (dmach_t channel)
181 dma_t *dma = dma_chan + channel;
186 if (dma->active == 0) {
188 dma->d_ops->enable(channel, dma);
193 printk(KERN_ERR "dma%d: trying to enable free DMA\n", channel);
197 /* Disable DMA channel
199 void disable_dma (dmach_t channel)
201 dma_t *dma = dma_chan + channel;
206 if (dma->active == 1) {
208 dma->d_ops->disable(channel, dma);
213 printk(KERN_ERR "dma%d: trying to disable free DMA\n", channel);
218 * Is the specified DMA channel active?
220 int dma_channel_active(dmach_t channel)
222 return dma_chan[channel].active;
225 void set_dma_page(dmach_t channel, char pagenr)
227 printk(KERN_ERR "dma%d: trying to set_dma_page\n", channel);
230 void set_dma_speed(dmach_t channel, int cycle_ns)
232 dma_t *dma = dma_chan + channel;
235 if (dma->d_ops->setspeed)
236 ret = dma->d_ops->setspeed(channel, dma, cycle_ns);
240 int get_dma_residue(dmach_t channel)
242 dma_t *dma = dma_chan + channel;
245 if (dma->d_ops->residue)
246 ret = dma->d_ops->residue(channel, dma);
251 static int __init init_dma(void)
253 arch_dma_init(dma_chan);
257 core_initcall(init_dma);
261 int request_dma(dmach_t channel, const char *device_id)
266 int get_dma_residue(dmach_t channel)
271 #define GLOBAL_ALIAS(_a,_b) asm (".set " #_a "," #_b "; .globl " #_a)
272 GLOBAL_ALIAS(disable_dma, get_dma_residue);
273 GLOBAL_ALIAS(enable_dma, get_dma_residue);
274 GLOBAL_ALIAS(free_dma, get_dma_residue);
275 GLOBAL_ALIAS(get_dma_list, get_dma_residue);
276 GLOBAL_ALIAS(set_dma_mode, get_dma_residue);
277 GLOBAL_ALIAS(set_dma_page, get_dma_residue);
278 GLOBAL_ALIAS(set_dma_count, get_dma_residue);
279 GLOBAL_ALIAS(__set_dma_addr, get_dma_residue);
280 GLOBAL_ALIAS(set_dma_sg, get_dma_residue);
281 GLOBAL_ALIAS(set_dma_speed, get_dma_residue);
285 EXPORT_SYMBOL(request_dma);
286 EXPORT_SYMBOL(free_dma);
287 EXPORT_SYMBOL(enable_dma);
288 EXPORT_SYMBOL(disable_dma);
289 EXPORT_SYMBOL(__set_dma_addr);
290 EXPORT_SYMBOL(set_dma_count);
291 EXPORT_SYMBOL(set_dma_mode);
292 EXPORT_SYMBOL(set_dma_page);
293 EXPORT_SYMBOL(get_dma_residue);
294 EXPORT_SYMBOL(set_dma_sg);
295 EXPORT_SYMBOL(set_dma_speed);
297 EXPORT_SYMBOL(dma_spin_lock);