Make HZ_TO_STD macro name lowercase.
[linux-2.6/linux-mips.git] / kernel / dma.c
blob983dedb605afd9ffcbe6cf6a3d4145a22c2647c9
1 /* $Id: dma.c,v 1.7 1994/12/28 03:35:33 root Exp root $
2 * linux/kernel/dma.c: A DMA channel allocator. Inspired by linux/kernel/irq.c.
4 * Written by Hennus Bergman, 1992.
6 * 1994/12/26: Changes by Alex Nash to fix a minor bug in /proc/dma.
7 * In the previous version the reported device could end up being wrong,
8 * if a device requested a DMA channel that was already in use.
9 * [It also happened to remove the sizeof(char *) == sizeof(int)
10 * assumption introduced because of those /proc/dma patches. -- Hennus]
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/spinlock.h>
16 #include <asm/dma.h>
17 #include <asm/system.h>
21 /* A note on resource allocation:
23 * All drivers needing DMA channels, should allocate and release them
24 * through the public routines `request_dma()' and `free_dma()'.
26 * In order to avoid problems, all processes should allocate resources in
27 * the same sequence and release them in the reverse order.
29 * So, when allocating DMAs and IRQs, first allocate the IRQ, then the DMA.
30 * When releasing them, first release the DMA, then release the IRQ.
31 * If you don't, you may cause allocation requests to fail unnecessarily.
32 * This doesn't really matter now, but it will once we get real semaphores
33 * in the kernel.
37 spinlock_t dma_spin_lock = SPIN_LOCK_UNLOCKED;
40 * If our port doesn't define this it has no PC like DMA
43 #ifdef MAX_DMA_CHANNELS
46 /* Channel n is busy iff dma_chan_busy[n].lock != 0.
47 * DMA0 used to be reserved for DRAM refresh, but apparently not any more...
48 * DMA4 is reserved for cascading.
51 struct dma_chan {
52 int lock;
53 const char *device_id;
56 static struct dma_chan dma_chan_busy[MAX_DMA_CHANNELS] = {
57 { 0, 0 },
58 { 0, 0 },
59 { 0, 0 },
60 { 0, 0 },
61 { 1, "cascade" },
62 { 0, 0 },
63 { 0, 0 },
64 { 0, 0 }
67 int get_dma_list(char *buf)
69 int i, len = 0;
71 for (i = 0 ; i < MAX_DMA_CHANNELS ; i++) {
72 if (dma_chan_busy[i].lock) {
73 len += sprintf(buf+len, "%2d: %s\n",
75 dma_chan_busy[i].device_id);
78 return len;
79 } /* get_dma_list */
82 int request_dma(unsigned int dmanr, const char * device_id)
84 if (dmanr >= MAX_DMA_CHANNELS)
85 return -EINVAL;
87 if (xchg(&dma_chan_busy[dmanr].lock, 1) != 0)
88 return -EBUSY;
90 dma_chan_busy[dmanr].device_id = device_id;
92 /* old flag was 0, now contains 1 to indicate busy */
93 return 0;
94 } /* request_dma */
97 void free_dma(unsigned int dmanr)
99 if (dmanr >= MAX_DMA_CHANNELS) {
100 printk("Trying to free DMA%d\n", dmanr);
101 return;
104 if (xchg(&dma_chan_busy[dmanr].lock, 0) == 0) {
105 printk("Trying to free free DMA%d\n", dmanr);
106 return;
109 } /* free_dma */
111 #else
113 int request_dma(unsigned int dmanr, const char *device_id)
115 return -EINVAL;
118 int free_dma(unsigned int dmanr)
120 return -EINVAL;
123 int get_dma_list(char *buf)
125 strcpy(buf, "No DMA\n");
126 return 7;
128 #endif