1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/spinlock.h>
16#include <linux/string.h>
17#include <asm/dma.h>
18#include <asm/system.h>
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38spinlock_t dma_spin_lock = SPIN_LOCK_UNLOCKED;
39
40
41
42
43
44#ifdef MAX_DMA_CHANNELS
45
46
47
48
49
50
51
52struct dma_chan {
53 int lock;
54 const char *device_id;
55};
56
57static struct dma_chan dma_chan_busy[MAX_DMA_CHANNELS] = {
58 { 0, 0 },
59 { 0, 0 },
60 { 0, 0 },
61 { 0, 0 },
62 { 1, "cascade" },
63 { 0, 0 },
64 { 0, 0 },
65 { 0, 0 }
66};
67
68int get_dma_list(char *buf)
69{
70 int i, len = 0;
71
72 for (i = 0 ; i < MAX_DMA_CHANNELS ; i++) {
73 if (dma_chan_busy[i].lock) {
74 len += sprintf(buf+len, "%2d: %s\n",
75 i,
76 dma_chan_busy[i].device_id);
77 }
78 }
79 return len;
80}
81
82
83int request_dma(unsigned int dmanr, const char * device_id)
84{
85 if (dmanr >= MAX_DMA_CHANNELS)
86 return -EINVAL;
87
88 if (xchg(&dma_chan_busy[dmanr].lock, 1) != 0)
89 return -EBUSY;
90
91 dma_chan_busy[dmanr].device_id = device_id;
92
93
94 return 0;
95}
96
97
98void free_dma(unsigned int dmanr)
99{
100 if (dmanr >= MAX_DMA_CHANNELS) {
101 printk("Trying to free DMA%d\n", dmanr);
102 return;
103 }
104
105 if (xchg(&dma_chan_busy[dmanr].lock, 0) == 0) {
106 printk("Trying to free free DMA%d\n", dmanr);
107 return;
108 }
109
110}
111
112#else
113
114int request_dma(unsigned int dmanr, const char *device_id)
115{
116 return -EINVAL;
117}
118
119void free_dma(unsigned int dmanr)
120{
121}
122
123int get_dma_list(char *buf)
124{
125 strcpy(buf, "No DMA\n");
126 return 7;
127}
128#endif
129