OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [kernel/] [dma.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* $Id: dma.c,v 1.1.1.1 2001-09-10 07:44:45 simons Exp $
2
 * linux/kernel/dma.c: A DMA channel allocator. Inspired by linux/kernel/irq.c.
3
 *
4
 * Written by Hennus Bergman, 1992.
5
 *
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]
11
 */
12
 
13
#include <linux/kernel.h>
14
#include <linux/errno.h>
15
#include <asm/dma.h>
16
#include <asm/system.h>
17
 
18
 
19
/* A note on resource allocation:
20
 *
21
 * All drivers needing DMA channels, should allocate and release them
22
 * through the public routines `request_dma()' and `free_dma()'.
23
 *
24
 * In order to avoid problems, all processes should allocate resources in
25
 * the same sequence and release them in the reverse order.
26
 *
27
 * So, when allocating DMAs and IRQs, first allocate the IRQ, then the DMA.
28
 * When releasing them, first release the DMA, then release the IRQ.
29
 * If you don't, you may cause allocation requests to fail unnecessarily.
30
 * This doesn't really matter now, but it will once we get real semaphores
31
 * in the kernel.
32
 */
33
 
34
 
35
 
36
/* Channel n is busy iff dma_chan_busy[n].lock != 0.
37
 * DMA0 used to be reserved for DRAM refresh, but apparently not any more...
38
 * DMA4 is reserved for cascading.
39
 */
40
 
41
struct dma_chan {
42
        int  lock;
43
        const char *device_id;
44
};
45
 
46
static struct dma_chan dma_chan_busy[MAX_DMA_CHANNELS] = {
47
        { 0, 0 },
48
#ifdef CONFIG_M5307
49
        { 0, 0 },
50
        { 0, 0 },
51
#endif
52
#ifndef CONFIG_UCLINUX
53
        { 0, 0 },
54
        { 0, 0 },
55
        { 1, "cascade" },
56
        { 0, 0 },
57
        { 0, 0 },
58
#endif
59
        { 0, 0 }
60
};
61
 
62
int get_dma_list(char *buf)
63
{
64
        int i, len = 0;
65
 
66
        for (i = 0 ; i < MAX_DMA_CHANNELS ; i++) {
67
                if (dma_chan_busy[i].lock) {
68
                    len += sprintf(buf+len, "%2d: %s\n",
69
                                   i,
70
                                   dma_chan_busy[i].device_id);
71
                }
72
        }
73
        return len;
74
} /* get_dma_list */
75
 
76
 
77
int request_dma(unsigned int dmanr, const char * device_id)
78
{
79
        if (dmanr >= MAX_DMA_CHANNELS)
80
                return -EINVAL;
81
 
82
        if (xchg(&dma_chan_busy[dmanr].lock, 1) != 0)
83
                return -EBUSY;
84
 
85
        dma_chan_busy[dmanr].device_id = device_id;
86
 
87
        /* old flag was 0, now contains 1 to indicate busy */
88
        return 0;
89
} /* request_dma */
90
 
91
 
92
void free_dma(unsigned int dmanr)
93
{
94
        if (dmanr >= MAX_DMA_CHANNELS) {
95
                printk("Trying to free DMA%d\n", dmanr);
96
                return;
97
        }
98
 
99
        if (xchg(&dma_chan_busy[dmanr].lock, 0) == 0) {
100
                printk("Trying to free free DMA%d\n", dmanr);
101
                return;
102
        }
103
 
104
} /* free_dma */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.