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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [arch/] [armnommu/] [drivers/] [char/] [misc.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1622 jcastillo
/*
2
 * linux/arch/arm/drivers/char/mouse.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
 
31
#include <linux/config.h>
32
#include <linux/module.h>
33
 
34
#include <linux/fs.h>
35
#include <linux/errno.h>
36
#include <linux/miscdevice.h>
37
#include <linux/kernel.h>
38
#include <linux/major.h>
39
#include <linux/malloc.h>
40
#include <linux/proc_fs.h>
41
#include <linux/stat.h>
42
 
43
#include <linux/tty.h> /* needed by selection.h */
44
#include "vt_kern.h"
45
#include "selection.h" /* export its symbols */
46
#ifdef CONFIG_KERNELD
47
#include <linux/kerneld.h>
48
#endif
49
 
50
#include "mouse.h"
51
 
52
/*
53
 * Head entry for the doubly linked miscdevice list
54
 */
55
static struct miscdevice misc_list = { 0, "head", NULL, &misc_list, &misc_list };
56
 
57
/*
58
 * Assigned numbers, used for dynamic minors
59
 */
60
#define DYNAMIC_MINORS 64 /* like dynamic majors used to do */
61
static unsigned char misc_minors[DYNAMIC_MINORS / 8];
62
 
63
#ifndef MODULE
64
extern void watchdog_init(void);
65
extern int arch_mouse_init(void);
66
extern int con_get_info(int *mode, int *shift, int *col, int *row,
67
                        struct tty_struct **tty);
68
 
69
#ifdef CONFIG_PROC_FS
70
static int proc_misc_read(char *buf, char **start, off_t offset, int len, int unused)
71
{
72
        struct miscdevice *p;
73
 
74
        len=0;
75
        for (p = misc_list.next; p != &misc_list; p = p->next)
76
                len += sprintf(buf+len, "%3i %s\n",p->minor, p->name ?: "");
77
        return len;
78
}
79
 
80
#endif /* PROC_FS */
81
#endif /* !MODULE */
82
 
83
static int misc_open(struct inode * inode, struct file * file)
84
{
85
        int minor = MINOR(inode->i_rdev);
86
        struct miscdevice *c = misc_list.next;
87
        file->f_op = NULL;
88
 
89
        while ((c != &misc_list) && (c->minor != minor))
90
                c = c->next;
91
        if (c == &misc_list) {
92
#ifdef CONFIG_KERNELD
93
                char modname[20];
94
                sprintf(modname, "char-major-%d-%d", MISC_MAJOR, minor);
95
                request_module(modname);
96
                c = misc_list.next;
97
                while ((c != &misc_list) && (c->minor != minor))
98
                        c = c->next;
99
                if (c == &misc_list)
100
#endif
101
                        return -ENODEV;
102
        }
103
 
104
        if ((file->f_op = c->fops))
105
                return file->f_op->open(inode,file);
106
        else
107
                return -ENODEV;
108
}
109
 
110
static struct file_operations misc_fops = {
111
        NULL,           /* seek */
112
        NULL,           /* read */
113
        NULL,           /* write */
114
        NULL,           /* readdir */
115
        NULL,           /* select */
116
        NULL,           /* ioctl */
117
        NULL,           /* mmap */
118
        misc_open,
119
        NULL            /* release */
120
};
121
 
122
int misc_register(struct miscdevice * misc)
123
{
124
        if (misc->next || misc->prev)
125
                return -EBUSY;
126
        if (misc->minor == MISC_DYNAMIC_MINOR) {
127
                int i = DYNAMIC_MINORS;
128
                while (--i >= 0)
129
                        if ( (misc_minors[i>>3] & (1 << (i&7))) == 0)
130
                                break;
131
                if (i<0) return -EBUSY;
132
                misc->minor = i;
133
        }
134
        if (misc->minor < DYNAMIC_MINORS)
135
                misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
136
        MOD_INC_USE_COUNT;
137
        misc->next = &misc_list;
138
        misc->prev = misc_list.prev;
139
        misc->prev->next = misc;
140
        misc->next->prev = misc;
141
        return 0;
142
}
143
 
144
int misc_deregister(struct miscdevice * misc)
145
{
146
        int i = misc->minor;
147
        if (!misc->next || !misc->prev)
148
                return -EINVAL;
149
        MOD_DEC_USE_COUNT;
150
        misc->prev->next = misc->next;
151
        misc->next->prev = misc->prev;
152
        misc->next = NULL;
153
        misc->prev = NULL;
154
        if (i < DYNAMIC_MINORS && i>0) {
155
                misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
156
        }
157
        return 0;
158
}
159
 
160
#ifdef MODULE
161
 
162
#define misc_init init_module
163
 
164
void cleanup_module(void)
165
{
166
        unregister_chrdev(MISC_MAJOR, "misc");
167
}
168
 
169
#endif
170
 
171
static struct symbol_table misc_syms = {
172
/* Should this be surrounded with "#ifdef CONFIG_MODULES" ? */
173
#include <linux/symtab_begin.h>
174
        X(misc_register),
175
        X(misc_deregister),
176
#ifndef MODULE
177
        X(set_selection),   /* used by the kmouse module, can only */
178
        X(paste_selection), /* be exported if misc.c is in linked in */
179
        X(con_get_info),
180
#endif
181
#include <linux/symtab_end.h>
182
};
183
 
184
int misc_init(void)
185
{
186
#ifndef MODULE
187
#ifdef CONFIG_PROC_FS
188
        proc_register_dynamic(&proc_root, &(struct proc_dir_entry) {
189
                0, 4, "misc",
190
                S_IFREG | S_IRUGO, 1, 0, 0,
191
                0, NULL /* ops -- default to array */,
192
                &proc_misc_read /* get_info */,
193
        });
194
#endif /* PROC_FS */
195
#ifdef CONFIG_MOUSE
196
        misc_mouse_init();
197
#endif
198
#ifdef CONFIG_SOFT_WATCHDOG
199
        watchdog_init();
200
#endif
201
#endif /* !MODULE */
202
        if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
203
          printk("unable to get major %d for misc devices\n",
204
                 MISC_MAJOR);
205
                return -EIO;
206
        }
207
 
208
        if(register_symtab(&misc_syms)!=0)
209
        {
210
                unregister_chrdev(MISC_MAJOR, "misc");
211
                return -EIO;
212
        }
213
        return 0;
214
}

powered by: WebSVN 2.1.0

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