ia64/xen-unstable

view old/xenolinux-2.4.16-sparse/arch/xeno/drivers/console/console.c @ 235:d7d0a23b2e07

bitkeeper revision 1.93 (3e5a4e6bkPheUp3x1uufN2MS3LAB7A)

Latest and Greatest version of XenoLinux based on the Linux-2.4.21-pre4
kernel.
author iap10@labyrinth.cl.cam.ac.uk
date Mon Feb 24 16:55:07 2003 +0000 (2003-02-24)
parents
children
line source
1 /******************************************************************************
2 * console.c
3 */
5 #include <linux/config.h>
6 #include <linux/module.h>
7 #include <linux/errno.h>
8 #include <linux/signal.h>
9 #include <linux/sched.h>
10 #include <linux/interrupt.h>
11 #include <linux/tty.h>
12 #include <linux/tty_flip.h>
13 #include <linux/serial.h>
14 #include <linux/major.h>
15 #include <linux/ptrace.h>
16 #include <linux/ioport.h>
17 #include <linux/mm.h>
18 #include <linux/slab.h>
19 #include <linux/init.h>
20 #include <linux/console.h>
22 #include <asm/io.h>
23 #include <asm/irq.h>
24 #include <asm/uaccess.h>
25 #include <asm/hypervisor.h>
27 /******************** Kernel console driver ********************************/
29 static void kconsole_write(struct console *co, const char *s, unsigned count)
30 {
31 #define STRLEN 256
32 static char str[STRLEN];
33 static int pos = 0;
34 int len;
36 /* We buffer output until we see a newline, or until the buffer is full. */
37 while ( count != 0 )
38 {
39 len = ((STRLEN - pos) > count) ? count : STRLEN - pos;
40 memcpy(str + pos, s, len);
41 pos += len;
42 s += len;
43 count -= len;
44 if ( (pos == STRLEN) || (str[pos-1] == '\n') )
45 {
46 (void)HYPERVISOR_console_write(str, pos);
47 pos = 0;
48 }
49 }
50 }
52 static kdev_t kconsole_device(struct console *c)
53 {
54 /*
55 * This is the magic that binds our "struct console" to our
56 * "tty_struct", defined below.
57 */
58 return MKDEV(TTY_MAJOR, 0);
59 }
61 static struct console kconsole_info = {
62 name: "xenocon",
63 write: kconsole_write,
64 device: kconsole_device,
65 flags: CON_PRINTBUFFER,
66 index: -1,
67 };
69 void xeno_console_init(void)
70 {
71 register_console(&kconsole_info);
72 }
75 /******************** Initial /dev/console *********************************/
78 static struct tty_driver console_driver;
79 static int console_refcount;
80 static struct tty_struct *console_table[1];
81 static struct termios *console_termios[1];
82 static struct termios *console_termios_locked[1];
84 static int console_write_room(struct tty_struct *tty)
85 {
86 return INT_MAX;
87 }
89 static int console_chars_in_buffer(struct tty_struct *tty)
90 {
91 return 0;
92 }
94 static inline int console_xmit(int ch)
95 {
96 char _ch = ch;
97 kconsole_write(NULL, &_ch, 1);
98 return 1;
99 }
101 static int console_write(struct tty_struct *tty, int from_user,
102 const u_char * buf, int count)
103 {
104 int i;
106 if ( from_user && verify_area(VERIFY_READ, buf, count) )
107 {
108 return -EINVAL;
109 }
111 for ( i = 0; i < count; i++ )
112 {
113 char ch;
114 if ( from_user )
115 {
116 __get_user(ch, buf + i);
117 }
118 else
119 {
120 ch = buf[i];
121 }
122 console_xmit(ch);
123 }
124 return i;
125 }
127 static void console_put_char(struct tty_struct *tty, u_char ch)
128 {
129 console_xmit(ch);
130 }
132 static int console_open(struct tty_struct *tty, struct file *filp)
133 {
134 int line;
136 MOD_INC_USE_COUNT;
137 line = MINOR(tty->device) - tty->driver.minor_start;
138 if ( line )
139 {
140 MOD_DEC_USE_COUNT;
141 return -ENODEV;
142 }
144 tty->driver_data = NULL;
146 return 0;
147 }
149 static void console_close(struct tty_struct *tty, struct file *filp)
150 {
151 MOD_DEC_USE_COUNT;
152 }
154 static int __init console_ini(void)
155 {
156 memset(&console_driver, 0, sizeof(struct tty_driver));
157 console_driver.magic = TTY_DRIVER_MAGIC;
158 console_driver.driver_name = "xeno_console";
159 console_driver.name = "console";
160 console_driver.major = TTY_MAJOR;
161 console_driver.minor_start = 0;
162 console_driver.num = 1;
163 console_driver.type = TTY_DRIVER_TYPE_SERIAL;
164 console_driver.subtype = SERIAL_TYPE_NORMAL;
165 console_driver.init_termios = tty_std_termios;
166 console_driver.flags = TTY_DRIVER_REAL_RAW;
167 console_driver.refcount = &console_refcount;
168 console_driver.table = console_table;
169 console_driver.termios = console_termios;
170 console_driver.termios_locked = console_termios_locked;
171 /* Functions */
172 console_driver.open = console_open;
173 console_driver.close = console_close;
174 console_driver.write = console_write;
175 console_driver.write_room = console_write_room;
176 console_driver.put_char = console_put_char;
177 console_driver.chars_in_buffer = console_chars_in_buffer;
179 if ( tty_register_driver(&console_driver) )
180 {
181 printk(KERN_ERR "Couldn't register Xeno console driver\n");
182 }
183 else
184 {
185 printk("Xeno console successfully installed\n");
186 }
188 return 0;
189 }
191 static void __exit console_fin(void)
192 {
193 int ret;
195 ret = tty_unregister_driver(&console_driver);
196 if ( ret != 0 )
197 {
198 printk(KERN_ERR "Unable to unregister Xeno console driver: %d\n", ret);
199 }
200 }
202 module_init(console_ini);
203 module_exit(console_fin);