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
41DEFINE_SPINLOCK(dma_spin_lock);
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
65
66
67
68
69
70int request_dma(unsigned int dmanr, const char * device_id)
71{
72 if (dmanr >= MAX_DMA_CHANNELS)
73 return -EINVAL;
74
75 if (xchg(&dma_chan_busy[dmanr].lock, 1) != 0)
76 return -EBUSY;
77
78 dma_chan_busy[dmanr].device_id = device_id;
79
80
81 return 0;
82}
83
84
85
86
87
88void free_dma(unsigned int dmanr)
89{
90 if (dmanr >= MAX_DMA_CHANNELS) {
91 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
92 return;
93 }
94
95 if (xchg(&dma_chan_busy[dmanr].lock, 0) == 0) {
96 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
97 return;
98 }
99
100}
101
102#else
103
104int request_dma(unsigned int dmanr, const char *device_id)
105{
106 return -EINVAL;
107}
108
109void free_dma(unsigned int dmanr)
110{
111}
112
113#endif
114
115#ifdef CONFIG_PROC_FS
116
117#ifdef MAX_DMA_CHANNELS
118static int proc_dma_show(struct seq_file *m, void *v)
119{
120 int i;
121
122 for (i = 0 ; i < MAX_DMA_CHANNELS ; i++) {
123 if (dma_chan_busy[i].lock) {
124 seq_printf(m, "%2d: %s\n", i,
125 dma_chan_busy[i].device_id);
126 }
127 }
128 return 0;
129}
130#else
131static int proc_dma_show(struct seq_file *m, void *v)
132{
133 seq_puts(m, "No DMA\n");
134 return 0;
135}
136#endif
137
138static int proc_dma_open(struct inode *inode, struct file *file)
139{
140 return single_open(file, proc_dma_show, NULL);
141}
142
143static const struct file_operations proc_dma_operations = {
144 .open = proc_dma_open,
145 .read = seq_read,
146 .llseek = seq_lseek,
147 .release = single_release,
148};
149
150static int __init proc_dma_init(void)
151{
152 proc_create("dma", 0, NULL, &proc_dma_operations);
153 return 0;
154}
155
156__initcall(proc_dma_init);
157#endif
158
159EXPORT_SYMBOL(request_dma);
160EXPORT_SYMBOL(free_dma);
161EXPORT_SYMBOL(dma_spin_lock);
162