0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <linux/export.h>
0014 #include <linux/kernel.h>
0015 #include <linux/errno.h>
0016 #include <linux/spinlock.h>
0017 #include <linux/string.h>
0018 #include <linux/seq_file.h>
0019 #include <linux/proc_fs.h>
0020 #include <linux/init.h>
0021 #include <asm/dma.h>
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 DEFINE_SPINLOCK(dma_spin_lock);
0042
0043
0044
0045
0046
0047 #ifdef MAX_DMA_CHANNELS
0048
0049
0050
0051
0052
0053
0054
0055 struct dma_chan {
0056 int lock;
0057 const char *device_id;
0058 };
0059
0060 static struct dma_chan dma_chan_busy[MAX_DMA_CHANNELS] = {
0061 [4] = { 1, "cascade" },
0062 };
0063
0064
0065
0066
0067
0068
0069
0070 int request_dma(unsigned int dmanr, const char * device_id)
0071 {
0072 if (dmanr >= MAX_DMA_CHANNELS)
0073 return -EINVAL;
0074
0075 if (xchg(&dma_chan_busy[dmanr].lock, 1) != 0)
0076 return -EBUSY;
0077
0078 dma_chan_busy[dmanr].device_id = device_id;
0079
0080
0081 return 0;
0082 }
0083
0084
0085
0086
0087
0088 void free_dma(unsigned int dmanr)
0089 {
0090 if (dmanr >= MAX_DMA_CHANNELS) {
0091 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
0092 return;
0093 }
0094
0095 if (xchg(&dma_chan_busy[dmanr].lock, 0) == 0) {
0096 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
0097 return;
0098 }
0099
0100 }
0101
0102 #else
0103
0104 int request_dma(unsigned int dmanr, const char *device_id)
0105 {
0106 return -EINVAL;
0107 }
0108
0109 void free_dma(unsigned int dmanr)
0110 {
0111 }
0112
0113 #endif
0114
0115 #ifdef CONFIG_PROC_FS
0116
0117 #ifdef MAX_DMA_CHANNELS
0118 static int proc_dma_show(struct seq_file *m, void *v)
0119 {
0120 int i;
0121
0122 for (i = 0 ; i < MAX_DMA_CHANNELS ; i++) {
0123 if (dma_chan_busy[i].lock) {
0124 seq_printf(m, "%2d: %s\n", i,
0125 dma_chan_busy[i].device_id);
0126 }
0127 }
0128 return 0;
0129 }
0130 #else
0131 static int proc_dma_show(struct seq_file *m, void *v)
0132 {
0133 seq_puts(m, "No DMA\n");
0134 return 0;
0135 }
0136 #endif
0137
0138 static int __init proc_dma_init(void)
0139 {
0140 proc_create_single("dma", 0, NULL, proc_dma_show);
0141 return 0;
0142 }
0143
0144 __initcall(proc_dma_init);
0145 #endif
0146
0147 EXPORT_SYMBOL(request_dma);
0148 EXPORT_SYMBOL(free_dma);
0149 EXPORT_SYMBOL(dma_spin_lock);