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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [char/] [misc.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * linux/drivers/char/misc.c
3
 *
4
 * Generic misc open routine by Johan Myreen
5
 *
6
 * Based on code from Linus
7
 *
8
 * Teemu Rantanen's Microsoft Busmouse support and Derrick Cole's
9
 *   changes incorporated into 0.97pl4
10
 *   by Peter Cervasio (pete%q106fm.uucp@wupost.wustl.edu) (08SEP92)
11
 *   See busmouse.c for particulars.
12
 *
13
 * Made things a lot mode modular - easy to compile in just one or two
14
 * of the misc drivers, as they are now completely independent. Linus.
15
 *
16
 * Support for loadable modules. 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk>
17
 *
18
 * Fixed a failing symbol register to free the device registration
19
 *              Alan Cox <alan@lxorguk.ukuu.org.uk> 21-Jan-96
20
 *
21
 * Dynamic minors and /proc/mice by Alessandro Rubini. 26-Mar-96
22
 *
23
 * Renamed to misc and miscdevice to be more accurate. Alan Cox 26-Mar-96
24
 *
25
 * Handling of mouse minor numbers for kerneld:
26
 *  Idea by Jacques Gelinas <jack@solucorp.qc.ca>,
27
 *  adapted by Bjorn Ekwall <bj0rn@blox.se>
28
 *  corrected by Alan Cox <alan@lxorguk.ukuu.org.uk>
29
 *
30
 * Allow missing f_op->open, and allow console to be configured out,
31
 * by Kenneth Albanowski <kjahds@kjahds.com>
32
 */
33
 
34
#include <linux/config.h>
35
#include <linux/module.h>
36
 
37
#include <linux/fs.h>
38
#include <linux/errno.h>
39
#include <linux/miscdevice.h>
40
#include <linux/kernel.h>
41
#include <linux/major.h>
42
#include <linux/malloc.h>
43
#include <linux/proc_fs.h>
44
#include <linux/stat.h>
45
#ifdef CONFIG_APM
46
#include <linux/apm_bios.h>
47
#endif
48
 
49
#include <linux/tty.h> /* needed by selection.h */
50
#include "selection.h" /* export its symbols */
51
#ifdef CONFIG_KERNELD
52
#include <linux/kerneld.h>
53
#endif
54
 
55
/*
56
 * Head entry for the doubly linked miscdevice list
57
 */
58
static struct miscdevice misc_list = { 0, "head", NULL, &misc_list, &misc_list };
59
 
60
/*
61
 * Assigned numbers, used for dynamic minors
62
 */
63
#define DYNAMIC_MINORS 64 /* like dynamic majors used to do */
64
static unsigned char misc_minors[DYNAMIC_MINORS / 8];
65
 
66
#ifndef MODULE
67
extern int bus_mouse_init(void);
68
extern int psaux_init(void);
69
extern int ms_bus_mouse_init(void);
70
extern int atixl_busmouse_init(void);
71
extern int sun_mouse_init(void);
72
extern void watchdog_init(void);
73
extern void wdt_init(void);
74
extern void pcwatchdog_init(void);
75
extern int rtc_init(void);
76
extern int con_get_info(int *mode, int *shift, int *col, int *row,
77
                        struct tty_struct **tty);
78
 
79
#ifdef CONFIG_PROC_FS
80
static int proc_misc_read(char *buf, char **start, off_t offset, int len, int unused)
81
{
82
        struct miscdevice *p;
83
 
84
        len=0;
85
        for (p = misc_list.next; p != &misc_list; p = p->next)
86
                len += sprintf(buf+len, "%3i %s\n",p->minor, p->name ?: "");
87
        return len;
88
}
89
 
90
#endif /* PROC_FS */
91
#endif /* !MODULE */
92
 
93
static int misc_open(struct inode * inode, struct file * file)
94
{
95
        int minor = MINOR(inode->i_rdev);
96
        struct miscdevice *c = misc_list.next;
97
        file->f_op = NULL;
98
 
99
        while ((c != &misc_list) && (c->minor != minor))
100
                c = c->next;
101
        if (c == &misc_list) {
102
#ifdef CONFIG_KERNELD
103
                char modname[20];
104
                sprintf(modname, "char-major-%d-%d", MISC_MAJOR, minor);
105
                request_module(modname);
106
                c = misc_list.next;
107
                while ((c != &misc_list) && (c->minor != minor))
108
                        c = c->next;
109
                if (c == &misc_list)
110
#endif
111
                        return -ENODEV;
112
        }
113
 
114
        if ((file->f_op = c->fops))
115
                if (file->f_op->open)
116
                        return file->f_op->open(inode,file);
117
                else
118
                        return 0;
119
        else
120
                return -ENODEV;
121
}
122
 
123
static struct file_operations misc_fops = {
124
        NULL,           /* seek */
125
        NULL,           /* read */
126
        NULL,           /* write */
127
        NULL,           /* readdir */
128
        NULL,           /* select */
129
        NULL,           /* ioctl */
130
        NULL,           /* mmap */
131
        misc_open,
132
        NULL            /* release */
133
};
134
 
135
int misc_register(struct miscdevice * misc)
136
{
137
        if (misc->next || misc->prev)
138
                return -EBUSY;
139
        if (misc->minor == MISC_DYNAMIC_MINOR) {
140
                int i = DYNAMIC_MINORS;
141
                while (--i >= 0)
142
                        if ( (misc_minors[i>>3] & (1 << (i&7))) == 0)
143
                                break;
144
                if (i<0) return -EBUSY;
145
                misc->minor = i;
146
        }
147
        if (misc->minor < DYNAMIC_MINORS)
148
                misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
149
        MOD_INC_USE_COUNT;
150
        misc->next = &misc_list;
151
        misc->prev = misc_list.prev;
152
        misc->prev->next = misc;
153
        misc->next->prev = misc;
154
        return 0;
155
}
156
 
157
int misc_deregister(struct miscdevice * misc)
158
{
159
        int i = misc->minor;
160
        if (!misc->next || !misc->prev)
161
                return -EINVAL;
162
        MOD_DEC_USE_COUNT;
163
        misc->prev->next = misc->next;
164
        misc->next->prev = misc->prev;
165
        misc->next = NULL;
166
        misc->prev = NULL;
167
        if (i < DYNAMIC_MINORS && i>0) {
168
                misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
169
        }
170
        return 0;
171
}
172
 
173
#ifdef MODULE
174
 
175
#define misc_init init_module
176
 
177
void cleanup_module(void)
178
{
179
        unregister_chrdev(MISC_MAJOR, "misc");
180
}
181
 
182
#endif
183
 
184
static struct symbol_table misc_syms = {
185
/* Should this be surrounded with "#ifdef CONFIG_MODULES" ? */
186
#include <linux/symtab_begin.h>
187
        X(misc_register),
188
        X(misc_deregister),
189
#if !defined(MODULE) && defined(CONFIG_CONSOLE)
190
        X(set_selection),   /* used by the kmouse module, can only */
191
        X(paste_selection), /* be exported if misc.c is in linked in */
192
        X(con_get_info),
193
#endif
194
#include <linux/symtab_end.h>
195
};
196
 
197
#ifdef CONFIG_PROC_FS
198
static struct proc_dir_entry pde1 = {
199
                0, 4, "misc",
200
                S_IFREG | S_IRUGO, 1, 0, 0,
201
                0, NULL /* ops -- default to array */,
202
                &proc_misc_read /* get_info */,
203
        };
204
#endif
205
 
206
int misc_init(void)
207
{
208
#ifndef MODULE
209
#ifdef CONFIG_PROC_FS
210
        proc_register_dynamic(&proc_root, &pde1);
211
#endif /* PROC_FS */
212
#ifdef CONFIG_BUSMOUSE
213
        bus_mouse_init();
214
#endif
215
#if defined CONFIG_PSMOUSE
216
        psaux_init();
217
#endif
218
#ifdef CONFIG_MS_BUSMOUSE
219
        ms_bus_mouse_init();
220
#endif
221
#ifdef CONFIG_ATIXL_BUSMOUSE
222
        atixl_busmouse_init();
223
#endif
224
#ifdef CONFIG_AMIGAMOUSE
225
        amiga_mouse_init();
226
#endif
227
#ifdef CONFIG_ATARIMOUSE
228
        atari_mouse_init();
229
#endif
230
#ifdef CONFIG_SUN_MOUSE
231
        sun_mouse_init();
232
#endif
233
#ifdef CONFIG_SOFT_WATCHDOG
234
        watchdog_init();
235
#endif
236
#ifdef CONFIG_WDT
237
        wdt_init();
238
#endif
239
#ifdef CONFIG_PCWATCHDOG
240
        pcwatchdog_init();
241
#endif
242
#ifdef CONFIG_APM
243
        apm_bios_init();
244
#endif
245
#ifdef CONFIG_H8
246
        h8_init();
247
#endif
248
#ifdef CONFIG_RTC
249
        rtc_init();
250
#endif
251
#endif /* !MODULE */
252
        if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
253
          printk("unable to get major %d for misc devices\n",
254
                 MISC_MAJOR);
255
                return -EIO;
256
        }
257
 
258
        if(register_symtab(&misc_syms)!=0)
259
        {
260
                unregister_chrdev(MISC_MAJOR, "misc");
261
                return -EIO;
262
        }
263
        return 0;
264
}

powered by: WebSVN 2.1.0

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