1
2
3
4
5
6
7
8
9
10
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/spinlock.h>
16#include <linux/string.h>
17#include <linux/seq_file.h>
18#include <linux/proc_fs.h>
19#include <linux/init.h>
20#include <asm/dma.h>
21#include <asm/system.h>
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41spinlock_t dma_spin_lock = SPIN_LOCK_UNLOCKED;
42
43
44
45
46
47#ifdef MAX_DMA_CHANNELS
48
49
50
51
52
53
54
55struct dma_chan {
56 int lock;
57 const char *device_id;
58};
59
60static struct dma_chan dma_chan_busy[MAX_DMA_CHANNELS] = {
61 [4] = { 1, "cascade" },
62};
63
64
65int request_dma(unsigned int dmanr, const char * device_id)
66{
67 if (dmanr >= MAX_DMA_CHANNELS)
68 return -EINVAL;
69
70 if (xchg(&dma_chan_busy[dmanr].lock, 1) != 0)
71 return -EBUSY;
72
73 dma_chan_busy[dmanr].device_id = device_id;
74
75
76 return 0;
77}
78
79
80void free_dma(unsigned int dmanr)
81{
82 if (dmanr >= MAX_DMA_CHANNELS) {
83 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
84 return;
85 }
86
87 if (xchg(&dma_chan_busy[dmanr].lock, 0) == 0) {
88 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
89 return;
90 }
91
92}
93
94#else
95
96int request_dma(unsigned int dmanr, const char *device_id)
97{
98 return -EINVAL;
99}
100
101void free_dma(unsigned int dmanr)
102{
103}
104
105#endif
106
107#ifdef CONFIG_PROC_FS
108
109#ifdef MAX_DMA_CHANNELS
110static int proc_dma_show(struct seq_file *m, void *v)
111{
112 int i;
113
114 for (i = 0 ; i < MAX_DMA_CHANNELS ; i++) {
115 if (dma_chan_busy[i].lock) {
116 seq_printf(m, "%2d: %s\n", i,
117 dma_chan_busy[i].device_id);
118 }
119 }
120 return 0;
121}
122#else
123static int proc_dma_show(struct seq_file *m, void *v)
124{
125 seq_puts(m, "No DMA\n");
126 return 0;
127}
128#endif
129
130static int proc_dma_open(struct inode *inode, struct file *file)
131{
132 return single_open(file, proc_dma_show, NULL);
133}
134
135static struct file_operations proc_dma_operations = {
136 .open = proc_dma_open,
137 .read = seq_read,
138 .llseek = seq_lseek,
139 .release = single_release,
140};
141
142static int __init proc_dma_init(void)
143{
144 struct proc_dir_entry *e;
145
146 e = create_proc_entry("dma", 0, NULL);
147 if (e)
148 e->proc_fops = &proc_dma_operations;
149
150 return 0;
151}
152
153__initcall(proc_dma_init);
154#endif
155
156EXPORT_SYMBOL(request_dma);
157EXPORT_SYMBOL(free_dma);
158EXPORT_SYMBOL(dma_spin_lock);
159