[NETFILTER]: PPTP conntrack: simplify expectation handling
[hh.org.git] / arch / arm26 / kernel / dma.c
blob80b5a774d90509bb726105f41214827b78e88de4
1 /*
2 * linux/arch/arm26/kernel/dma.c
4 * Copyright (C) 1995-2000 Russell King
5 * 2003 Ian Molton
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Front-end to the DMA handling. This handles the allocation/freeing
12 * of DMA channels, and provides a unified interface to the machines
13 * DMA facilities.
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/sched.h>
18 #include <linux/mman.h>
19 #include <linux/init.h>
20 #include <linux/spinlock.h>
21 #include <linux/errno.h>
23 #include <asm/dma.h>
25 DEFINE_SPINLOCK(dma_spin_lock);
27 static dma_t dma_chan[MAX_DMA_CHANNELS];
30 * Get dma list for /proc/dma
32 int get_dma_list(char *buf)
34 dma_t *dma;
35 char *p = buf;
36 int i;
38 for (i = 0, dma = dma_chan; i < MAX_DMA_CHANNELS; i++, dma++)
39 if (dma->lock)
40 p += sprintf(p, "%2d: %14s %s\n", i,
41 dma->d_ops->type, dma->device_id);
43 return p - buf;
47 * Request DMA channel
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;
54 int ret;
56 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
57 goto bad_dma;
59 if (xchg(&dma->lock, 1) != 0)
60 goto busy;
62 dma->device_id = device_id;
63 dma->active = 0;
64 dma->invalid = 1;
66 ret = 0;
67 if (dma->d_ops->request)
68 ret = dma->d_ops->request(channel, dma);
70 if (ret)
71 xchg(&dma->lock, 0);
73 return ret;
75 bad_dma:
76 printk(KERN_ERR "dma: trying to allocate DMA%d\n", channel);
77 return -EINVAL;
79 busy:
80 return -EBUSY;
84 * Free DMA 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)
93 goto bad_dma;
95 if (dma->active) {
96 printk(KERN_ERR "dma%d: freeing active DMA\n", channel);
97 dma->d_ops->disable(channel, dma);
98 dma->active = 0;
101 if (xchg(&dma->lock, 0) != 0) {
102 if (dma->d_ops->free)
103 dma->d_ops->free(channel, dma);
104 return;
107 printk(KERN_ERR "dma%d: trying to free free DMA\n", channel);
108 return;
110 bad_dma:
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;
120 if (dma->active)
121 printk(KERN_ERR "dma%d: altering DMA SG while "
122 "DMA active\n", channel);
124 dma->sg = sg;
125 dma->sgcount = nr_sg;
126 dma->using_sg = 1;
127 dma->invalid = 1;
130 /* Set DMA address
132 * Copy address to the structure, and set the invalid bit
134 void set_dma_addr (dmach_t channel, unsigned long physaddr)
136 dma_t *dma = dma_chan + channel;
138 if (dma->active)
139 printk(KERN_ERR "dma%d: altering DMA address while "
140 "DMA active\n", channel);
142 dma->sg = &dma->buf;
143 dma->sgcount = 1;
144 dma->buf.__address = (char *)physaddr;//FIXME - not pretty
145 dma->using_sg = 0;
146 dma->invalid = 1;
149 /* Set DMA byte count
151 * Copy address to the structure, and set the invalid bit
153 void set_dma_count (dmach_t channel, unsigned long count)
155 dma_t *dma = dma_chan + channel;
157 if (dma->active)
158 printk(KERN_ERR "dma%d: altering DMA count while "
159 "DMA active\n", channel);
161 dma->sg = &dma->buf;
162 dma->sgcount = 1;
163 dma->buf.length = count;
164 dma->using_sg = 0;
165 dma->invalid = 1;
168 /* Set DMA direction mode
170 void set_dma_mode (dmach_t channel, dmamode_t mode)
172 dma_t *dma = dma_chan + channel;
174 if (dma->active)
175 printk(KERN_ERR "dma%d: altering DMA mode while "
176 "DMA active\n", channel);
178 dma->dma_mode = mode;
179 dma->invalid = 1;
182 /* Enable DMA channel
184 void enable_dma (dmach_t channel)
186 dma_t *dma = dma_chan + channel;
188 if (!dma->lock)
189 goto free_dma;
191 if (dma->active == 0) {
192 dma->active = 1;
193 dma->d_ops->enable(channel, dma);
195 return;
197 free_dma:
198 printk(KERN_ERR "dma%d: trying to enable free DMA\n", channel);
199 BUG();
202 /* Disable DMA channel
204 void disable_dma (dmach_t channel)
206 dma_t *dma = dma_chan + channel;
208 if (!dma->lock)
209 goto free_dma;
211 if (dma->active == 1) {
212 dma->active = 0;
213 dma->d_ops->disable(channel, dma);
215 return;
217 free_dma:
218 printk(KERN_ERR "dma%d: trying to disable free DMA\n", channel);
219 BUG();
223 * Is the specified DMA channel active?
225 int dma_channel_active(dmach_t channel)
227 return dma_chan[channel].active;
230 void set_dma_page(dmach_t channel, char pagenr)
232 printk(KERN_ERR "dma%d: trying to set_dma_page\n", channel);
235 void set_dma_speed(dmach_t channel, int cycle_ns)
237 dma_t *dma = dma_chan + channel;
238 int ret = 0;
240 if (dma->d_ops->setspeed)
241 ret = dma->d_ops->setspeed(channel, dma, cycle_ns);
242 dma->speed = ret;
245 int get_dma_residue(dmach_t channel)
247 dma_t *dma = dma_chan + channel;
248 int ret = 0;
250 if (dma->d_ops->residue)
251 ret = dma->d_ops->residue(channel, dma);
253 return ret;
256 void __init init_dma(void)
258 arch_dma_init(dma_chan);
261 EXPORT_SYMBOL(request_dma);
262 EXPORT_SYMBOL(free_dma);
263 EXPORT_SYMBOL(enable_dma);
264 EXPORT_SYMBOL(disable_dma);
265 EXPORT_SYMBOL(set_dma_addr);
266 EXPORT_SYMBOL(set_dma_count);
267 EXPORT_SYMBOL(set_dma_mode);
268 EXPORT_SYMBOL(set_dma_page);
269 EXPORT_SYMBOL(get_dma_residue);
270 EXPORT_SYMBOL(set_dma_sg);
271 EXPORT_SYMBOL(set_dma_speed);
273 EXPORT_SYMBOL(dma_spin_lock);