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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [kernel/] [resource.c] - Blame information for rev 1775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *      linux/kernel/resource.c
3
 *
4
 * Copyright (C) 1995   Linus Torvalds
5
 *                      David Hinds
6
 *
7
 * Kernel io-region resource management
8
 */
9
 
10
/*
11
 * Revisions for CONFIG_REDUCED_MEMORY by Kenneth Albanowski <kjahds@kjahds.com>,
12
 * Copyright (C) 1997, 1998 The Silver Hammer Group, Ltd.
13
 */
14
 
15
#include <linux/sched.h>
16
#include <linux/kernel.h>
17
#include <linux/errno.h>
18
#include <linux/types.h>
19
#include <linux/ioport.h>
20
 
21
#ifdef CONFIG_REDUCED_MEMORY
22
#define IOTABLE_SIZE 1 /* Originally 128 */
23
#else /* !CONFIG_REDUCED_MEMORY */
24
#define IOTABLE_SIZE 128
25
#endif /* !CONFIG_REDUCED_MEMORY */
26
 
27
typedef struct resource_entry_t {
28
        u_long from, num;
29
        const char *name;
30
        struct resource_entry_t *next;
31
} resource_entry_t;
32
 
33
static resource_entry_t iolist = { 0, 0, "", NULL };
34
 
35
static resource_entry_t iotable[IOTABLE_SIZE];
36
 
37
/*
38
 * This generates the report for /proc/ioports
39
 */
40
int get_ioport_list(char *buf)
41
{
42
        resource_entry_t *p;
43
        int len = 0;
44
 
45
        for (p = iolist.next; (p) && (len < 4000); p = p->next)
46
                len += sprintf(buf+len, "%04lx-%04lx : %s\n",
47
                           p->from, p->from+p->num-1, p->name);
48
        if (p)
49
                len += sprintf(buf+len, "4K limit reached!\n");
50
        return len;
51
}
52
 
53
/*
54
 * The workhorse function: find where to put a new entry
55
 */
56
static resource_entry_t *find_gap(resource_entry_t *root,
57
                                  u_long from, u_long num)
58
{
59
        unsigned long flags;
60
        resource_entry_t *p;
61
 
62
        if (from > from+num-1)
63
                return NULL;
64
        save_flags(flags);
65
        cli();
66
        for (p = root; ; p = p->next) {
67
                if ((p != root) && (p->from+p->num-1 >= from)) {
68
                        p = NULL;
69
                        break;
70
                }
71
                if ((p->next == NULL) || (p->next->from > from+num-1))
72
                        break;
73
        }
74
        restore_flags(flags);
75
        return p;
76
}
77
 
78
/*
79
 * Call this from the device driver to register the ioport region.
80
 */
81
void request_region(unsigned int from, unsigned int num, const char *name)
82
{
83
        resource_entry_t *p;
84
        int i;
85
 
86
        for (i = 0; i < IOTABLE_SIZE; i++)
87
                if (iotable[i].num == 0)
88
                        break;
89
        if (i == IOTABLE_SIZE)
90
                printk("warning: ioport table is full\n");
91
        else {
92
                p = find_gap(&iolist, from, num);
93
                if (p == NULL)
94
                        return;
95
                iotable[i].name = name;
96
                iotable[i].from = from;
97
                iotable[i].num = num;
98
                iotable[i].next = p->next;
99
                p->next = &iotable[i];
100
                return;
101
        }
102
}
103
 
104
/*
105
 * Call this when the device driver is unloaded
106
 */
107
void release_region(unsigned int from, unsigned int num)
108
{
109
        resource_entry_t *p, *q;
110
 
111
        for (p = &iolist; ; p = q) {
112
                q = p->next;
113
                if (q == NULL)
114
                        break;
115
                if ((q->from == from) && (q->num == num)) {
116
                        q->num = 0;
117
                        p->next = q->next;
118
                        return;
119
                }
120
        }
121
}
122
 
123
/*
124
 * Call this to check the ioport region before probing
125
 */
126
int check_region(unsigned int from, unsigned int num)
127
{
128
        return (find_gap(&iolist, from, num) == NULL) ? -EBUSY : 0;
129
}
130
 
131
/* Called from init/main.c to reserve IO ports. */
132
void reserve_setup(char *str, int *ints)
133
{
134
        int i;
135
 
136
        for (i = 1; i < ints[0]; i += 2)
137
                request_region(ints[i], ints[i+1], "reserved");
138
}

powered by: WebSVN 2.1.0

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