This source file includes following definitions.
- request_dma
- free_dma
- request_dma
- free_dma
- proc_dma_show
- proc_dma_show
- proc_dma_init
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/export.h>
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/spinlock.h>
17 #include <linux/string.h>
18 #include <linux/seq_file.h>
19 #include <linux/proc_fs.h>
20 #include <linux/init.h>
21 #include <asm/dma.h>
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 DEFINE_SPINLOCK(dma_spin_lock);
42
43
44
45
46
47 #ifdef MAX_DMA_CHANNELS
48
49
50
51
52
53
54
55 struct dma_chan {
56 int lock;
57 const char *device_id;
58 };
59
60 static struct dma_chan dma_chan_busy[MAX_DMA_CHANNELS] = {
61 [4] = { 1, "cascade" },
62 };
63
64
65
66
67
68
69
70 int 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
88 void 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
104 int request_dma(unsigned int dmanr, const char *device_id)
105 {
106 return -EINVAL;
107 }
108
109 void free_dma(unsigned int dmanr)
110 {
111 }
112
113 #endif
114
115 #ifdef CONFIG_PROC_FS
116
117 #ifdef MAX_DMA_CHANNELS
118 static 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
131 static 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
138 static int __init proc_dma_init(void)
139 {
140 proc_create_single("dma", 0, NULL, proc_dma_show);
141 return 0;
142 }
143
144 __initcall(proc_dma_init);
145 #endif
146
147 EXPORT_SYMBOL(request_dma);
148 EXPORT_SYMBOL(free_dma);
149 EXPORT_SYMBOL(dma_spin_lock);