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>
18 #include <linux/scatterlist.h>
22 #include <asm/mach/dma.h>
24 DEFINE_SPINLOCK(dma_spin_lock
);
25 EXPORT_SYMBOL(dma_spin_lock
);
27 static dma_t
*dma_chan
[MAX_DMA_CHANNELS
];
29 static inline dma_t
*dma_channel(unsigned int chan
)
31 if (chan
>= MAX_DMA_CHANNELS
)
34 return dma_chan
[chan
];
37 int __init
isa_dma_add(unsigned int chan
, dma_t
*dma
)
42 sg_init_table(&dma
->buf
, 1);
53 * On certain platforms, we have to allocate an interrupt as well...
55 int request_dma(unsigned int chan
, const char *device_id
)
57 dma_t
*dma
= dma_channel(chan
);
63 if (xchg(&dma
->lock
, 1) != 0)
66 dma
->device_id
= device_id
;
71 if (dma
->d_ops
->request
)
72 ret
= dma
->d_ops
->request(chan
, dma
);
80 printk(KERN_ERR
"dma: trying to allocate DMA%d\n", chan
);
86 EXPORT_SYMBOL(request_dma
);
91 * On certain platforms, we have to free interrupt as well...
93 void free_dma(unsigned int chan
)
95 dma_t
*dma
= dma_channel(chan
);
101 printk(KERN_ERR
"dma%d: freeing active DMA\n", chan
);
102 dma
->d_ops
->disable(chan
, dma
);
106 if (xchg(&dma
->lock
, 0) != 0) {
107 if (dma
->d_ops
->free
)
108 dma
->d_ops
->free(chan
, dma
);
112 printk(KERN_ERR
"dma%d: trying to free free DMA\n", chan
);
116 printk(KERN_ERR
"dma: trying to free DMA%d\n", chan
);
118 EXPORT_SYMBOL(free_dma
);
120 /* Set DMA Scatter-Gather list
122 void set_dma_sg (unsigned int chan
, struct scatterlist
*sg
, int nr_sg
)
124 dma_t
*dma
= dma_channel(chan
);
127 printk(KERN_ERR
"dma%d: altering DMA SG while "
128 "DMA active\n", chan
);
131 dma
->sgcount
= nr_sg
;
134 EXPORT_SYMBOL(set_dma_sg
);
138 * Copy address to the structure, and set the invalid bit
140 void __set_dma_addr (unsigned int chan
, void *addr
)
142 dma_t
*dma
= dma_channel(chan
);
145 printk(KERN_ERR
"dma%d: altering DMA address while "
146 "DMA active\n", chan
);
152 EXPORT_SYMBOL(__set_dma_addr
);
154 /* Set DMA byte count
156 * Copy address to the structure, and set the invalid bit
158 void set_dma_count (unsigned int chan
, unsigned long count
)
160 dma_t
*dma
= dma_channel(chan
);
163 printk(KERN_ERR
"dma%d: altering DMA count while "
164 "DMA active\n", chan
);
170 EXPORT_SYMBOL(set_dma_count
);
172 /* Set DMA direction mode
174 void set_dma_mode (unsigned int chan
, unsigned int mode
)
176 dma_t
*dma
= dma_channel(chan
);
179 printk(KERN_ERR
"dma%d: altering DMA mode while "
180 "DMA active\n", chan
);
182 dma
->dma_mode
= mode
;
185 EXPORT_SYMBOL(set_dma_mode
);
187 /* Enable DMA channel
189 void enable_dma (unsigned int chan
)
191 dma_t
*dma
= dma_channel(chan
);
196 if (dma
->active
== 0) {
198 dma
->d_ops
->enable(chan
, dma
);
203 printk(KERN_ERR
"dma%d: trying to enable free DMA\n", chan
);
206 EXPORT_SYMBOL(enable_dma
);
208 /* Disable DMA channel
210 void disable_dma (unsigned int chan
)
212 dma_t
*dma
= dma_channel(chan
);
217 if (dma
->active
== 1) {
219 dma
->d_ops
->disable(chan
, dma
);
224 printk(KERN_ERR
"dma%d: trying to disable free DMA\n", chan
);
227 EXPORT_SYMBOL(disable_dma
);
230 * Is the specified DMA channel active?
232 int dma_channel_active(unsigned int chan
)
234 dma_t
*dma
= dma_channel(chan
);
237 EXPORT_SYMBOL(dma_channel_active
);
239 void set_dma_page(unsigned int chan
, char pagenr
)
241 printk(KERN_ERR
"dma%d: trying to set_dma_page\n", chan
);
243 EXPORT_SYMBOL(set_dma_page
);
245 void set_dma_speed(unsigned int chan
, int cycle_ns
)
247 dma_t
*dma
= dma_channel(chan
);
250 if (dma
->d_ops
->setspeed
)
251 ret
= dma
->d_ops
->setspeed(chan
, dma
, cycle_ns
);
254 EXPORT_SYMBOL(set_dma_speed
);
256 int get_dma_residue(unsigned int chan
)
258 dma_t
*dma
= dma_channel(chan
);
261 if (dma
->d_ops
->residue
)
262 ret
= dma
->d_ops
->residue(chan
, dma
);
266 EXPORT_SYMBOL(get_dma_residue
);