1 /* $Id: streamable.c,v 1.1.1.1 2005/04/11 02:50:38 jack Exp $
3 * streamable.c: streamable devices. /dev/gfx
4 * (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 * Major 10 is the streams clone device. The IRIX Xsgi server just
7 * opens /dev/gfx and closes it inmediately.
12 #include <linux/miscdevice.h>
13 #include <linux/sched.h>
14 #include <linux/kbd_kern.h>
15 #include <linux/vt_kern.h>
16 #include <linux/smp_lock.h>
17 #include <asm/uaccess.h>
18 #include <asm/shmiq.h>
19 #include <asm/keyboard.h>
23 extern struct kbd_struct kbd_table [MAX_NR_CONSOLES];
25 /* console number where forwarding is enabled */
28 /* To which shmiq this keyboard is assigned */
29 int kbd_assigned_device;
31 /* previous kbd_mode for the forward_chars terminal */
34 /* Fetchs the strioctl information from user space for I_STR ioctls */
36 get_sioc (struct strioctl *sioc, unsigned long arg)
40 v = verify_area (VERIFY_WRITE, (void *) arg, sizeof (struct strioctl));
43 if (copy_from_user (sioc, (void *) arg, sizeof (struct strioctl)))
46 v = verify_area (VERIFY_WRITE, (void *) sioc->ic_dp, sioc->ic_len);
54 sgi_gfx_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
56 printk ("GFX: ioctl 0x%x %ld called\n", cmd, arg);
61 struct file_operations sgi_gfx_fops = {
65 static struct miscdevice dev_gfx = {
66 SGI_GFX_MINOR, "sgi-gfx", &sgi_gfx_fops
69 /* /dev/input/keyboard streams device */
70 static idevDesc sgi_kbd_desc = {
71 "keyboard", /* devName */
72 "KEYBOARD", /* devType */
79 IDEV_HAS_KEYMAP | IDEV_HAS_PCKBD
83 sgi_kbd_sioc (idevInfo *dinfo, int cmd, int size, char *data, int *found)
92 case IDEVGETDEVICEDESC:
93 if (size >= sizeof (idevDesc)){
94 if (copy_to_user (data, &sgi_kbd_desc, sizeof (sgi_kbd_desc)))
100 case IDEVGETKEYMAPDESC:
101 if (size >= sizeof (idevKeymapDesc)){
102 if (copy_to_user (data, "US", 3))
113 sgi_keyb_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
115 struct strioctl sioc;
118 /* IRIX calls I_PUSH on the opened device, go figure */
123 v = get_sioc (&sioc, arg);
127 /* Why like this? Because this is a sample piece of code
128 * that can be copied into other drivers and shows how to
129 * call a stock IRIX xxx_wioctl routine
131 * The NULL is supposed to be a idevInfo, right now we
132 * do not support this in our kernel.
134 return sgi_kbd_sioc (NULL, sioc.ic_cmd, sioc.ic_len, sioc.ic_dp, &f);
137 if (cmd == SHMIQ_ON){
138 kbd_assigned_device = arg;
139 forward_chars = fg_console + 1;
140 kbd_prev_mode = kbd_table [fg_console].kbdmode;
142 kbd_table [fg_console].kbdmode = VC_RAW;
143 } else if (cmd == SHMIQ_OFF && forward_chars){
144 kbd_table [forward_chars-1].kbdmode = kbd_prev_mode;
152 kbd_forward_char (int ch)
154 static struct shmqevent ev;
156 ev.data.flags = (ch & 0200) ? 0 : 1;
158 ev.data.device = kbd_assigned_device + 0x11;
159 shmiq_push_event (&ev);
163 sgi_keyb_open (struct inode *inode, struct file *file)
165 /* Nothing, but required by the misc driver */
169 struct file_operations sgi_keyb_fops = {
170 ioctl: sgi_keyb_ioctl,
174 static struct miscdevice dev_input_keyboard = {
175 SGI_STREAMS_KEYBOARD, "streams-keyboard", &sgi_keyb_fops
178 /* /dev/input/mouse streams device */
179 #define MOUSE_VALUATORS 2
180 static idevDesc sgi_mouse_desc = {
181 "mouse", /* devName */
182 "MOUSE", /* devType */
184 MOUSE_VALUATORS, /* nValuators */
192 static idevValuatorDesc mouse_default_valuator = {
196 65000, /* hwMaxVal */
197 IDEV_EITHER, /* possibleModes */
198 IDEV_ABSOLUTE, /* default mode */
199 200, /* resolution */
204 static int mouse_opened;
205 static idevValuatorDesc mouse_valuators [MOUSE_VALUATORS];
208 sgi_mouse_open (struct inode *inode, struct file *file)
216 for (i = 0; i < MOUSE_VALUATORS; i++)
217 mouse_valuators [i] = mouse_default_valuator;
222 sgi_mouse_close (struct inode *inode, struct file *filp)
231 sgi_mouse_sioc (idevInfo *dinfo, int cmd, int size, char *data, int *found)
239 case IDEVGETDEVICEDESC:
240 if (size >= sizeof (idevDesc)){
241 if (copy_to_user (data, &sgi_mouse_desc, sizeof (sgi_mouse_desc)))
247 case IDEVGETVALUATORDESC: {
248 idevGetSetValDesc request, *ureq = (idevGetSetValDesc *) data;
250 if (size < sizeof (idevGetSetValDesc))
253 if (copy_from_user (&request, data, sizeof (request)))
255 if (request.valNum >= MOUSE_VALUATORS)
257 if (copy_to_user ((void *)&ureq->desc,
258 (void *)&mouse_valuators [request.valNum],
259 sizeof (idevValuatorDesc)))
269 sgi_mouse_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
271 struct strioctl sioc;
274 /* IRIX calls I_PUSH on the opened device, go figure */
280 v = get_sioc (&sioc, arg);
284 /* Why like this? Because this is a sample piece of code
285 * that can be copied into other drivers and shows how to
286 * call a stock IRIX xxx_wioctl routine
288 * The NULL is supposed to be a idevInfo, right now we
289 * do not support this in our kernel.
291 return sgi_mouse_sioc (NULL, sioc.ic_cmd, sioc.ic_len, sioc.ic_dp, &f);
300 struct file_operations sgi_mouse_fops = {
301 ioctl: sgi_mouse_ioctl,
302 open: sgi_mouse_open,
303 release: sgi_mouse_close,
306 /* /dev/input/mouse */
307 static struct miscdevice dev_input_mouse = {
308 SGI_STREAMS_KEYBOARD, "streams-mouse", &sgi_mouse_fops
312 streamable_init (void)
314 printk ("streamable misc devices registered (keyb:%d, gfx:%d)\n",
315 SGI_STREAMS_KEYBOARD, SGI_GFX_MINOR);
317 misc_register (&dev_gfx);
318 misc_register (&dev_input_keyboard);
319 misc_register (&dev_input_mouse);