debuggers.hg

view xenolinux-2.4.21-sparse/arch/xeno/drivers/console/console.c @ 653:3a237a10a0c6

bitkeeper revision 1.344 (3f12be53t1VivuAfELH_J3XUhJ2Frg)

more console stuff
author iap10@labyrinth.cl.cam.ac.uk
date Mon Jul 14 14:29:39 2003 +0000 (2003-07-14)
parents 6be2874c3f07
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 #define XENO_TTY_MINOR 123
29 /*** useful function for console debugging -- goes straight to Xen ****/
31 asmlinkage int xprintk(const char *fmt, ...)
32 {
33 va_list args;
34 unsigned long flags;
35 int printed_len;
36 static char printk_buf[1024];
38 /* Emit the output into the temporary buffer */
39 va_start(args, fmt);
40 printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
41 va_end(args);
43 // Useful Hack if things are going wrong very early in the day
44 (void)HYPERVISOR_console_write(printk_buf, sizeof(printk_buf));
45 }
49 /******************** Kernel console driver ********************************/
51 static void xen_console_write(struct console *co, const char *s, unsigned count)
52 {
53 #define STRLEN 256
54 static char str[STRLEN];
55 static int pos = 0;
56 int len;
58 /* We buffer output until we see a newline, or until the buffer is full. */
59 while ( count != 0 )
60 {
61 len = ((STRLEN - pos) > count) ? count : STRLEN - pos;
62 memcpy(str + pos, s, len);
63 pos += len;
64 s += len;
65 count -= len;
66 if ( (pos == STRLEN) || (str[pos-1] == '\n') )
67 {
68 (void)HYPERVISOR_console_write(str, pos);
69 pos = 0;
70 }
71 }
72 }
74 static kdev_t xen_console_device(struct console *c)
75 {
76 /*
77 * This is the magic that binds our "struct console" to our
78 * "tty_struct", defined below.
79 */
80 return MKDEV(TTY_MAJOR, XENO_TTY_MINOR);
81 }
83 static struct console xen_console_info = {
84 name: "xencons", /* Used to be xen_console, but we're only
85 actually allowed 8 charcters including
86 the terminator... */
87 write: xen_console_write,
88 device: xen_console_device,
89 flags: CON_PRINTBUFFER,
90 index: -1,
91 };
93 void xen_console_init(void)
94 {
95 xprintk("xen_console_init\n");
96 register_console(&xen_console_info);
97 }
100 /******************** Initial /dev/console *********************************/
103 static struct tty_driver xeno_console_driver;
104 static int xeno_console_refcount;
105 static struct tty_struct *xeno_console_table[1];
106 static struct termios *xeno_console_termios[1];
107 static struct termios *xeno_console_termios_locked[1];
109 static int xeno_console_write_room(struct tty_struct *tty)
110 {
111 return INT_MAX;
112 }
114 static int xeno_console_chars_in_buffer(struct tty_struct *tty)
115 {
116 return 0;
117 }
119 static inline int xeno_console_xmit(int ch)
120 {
121 char _ch = ch;
122 xen_console_write(NULL, &_ch, 1);
123 return 1;
124 }
126 static int xeno_console_write(struct tty_struct *tty, int from_user,
127 const u_char * buf, int count)
128 {
129 int i;
131 if ( from_user && verify_area(VERIFY_READ, buf, count) )
132 {
133 return -EINVAL;
134 }
136 for ( i = 0; i < count; i++ )
137 {
138 char ch;
139 if ( from_user )
140 {
141 __get_user(ch, buf + i);
142 }
143 else
144 {
145 ch = buf[i];
146 }
147 xeno_console_xmit(ch);
148 }
149 return i;
150 }
152 static void xeno_console_put_char(struct tty_struct *tty, u_char ch)
153 {
154 xeno_console_xmit(ch);
155 }
157 static int xeno_console_open(struct tty_struct *tty, struct file *filp)
158 {
159 int line;
161 MOD_INC_USE_COUNT;
162 line = MINOR(tty->device) - tty->driver.minor_start;
163 if ( line )
164 {
165 MOD_DEC_USE_COUNT;
166 return -ENODEV;
167 }
169 tty->driver_data = NULL;
171 return 0;
172 }
174 static void xeno_console_close(struct tty_struct *tty, struct file *filp)
175 {
176 MOD_DEC_USE_COUNT;
177 }
179 int __init xeno_con_init(void)
180 {
181 memset(&xeno_console_driver, 0, sizeof(struct tty_driver));
182 xeno_console_driver.magic = TTY_DRIVER_MAGIC;
183 xeno_console_driver.driver_name = "xeno_console";
184 xeno_console_driver.name = "xencon";
185 xeno_console_driver.major = TTY_MAJOR;
186 xeno_console_driver.minor_start = XENO_TTY_MINOR;
187 xeno_console_driver.num = 1;
188 xeno_console_driver.type = TTY_DRIVER_TYPE_SERIAL;
189 xeno_console_driver.subtype = SERIAL_TYPE_NORMAL;
190 xeno_console_driver.init_termios = tty_std_termios;
191 xeno_console_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
192 xeno_console_driver.refcount = &xeno_console_refcount;
193 xeno_console_driver.table = xeno_console_table;
194 xeno_console_driver.termios = xeno_console_termios;
195 xeno_console_driver.termios_locked = xeno_console_termios_locked;
196 /* Functions */
197 xeno_console_driver.open = xeno_console_open;
198 xeno_console_driver.close = xeno_console_close;
199 xeno_console_driver.write = xeno_console_write;
200 xeno_console_driver.write_room = xeno_console_write_room;
201 xeno_console_driver.put_char = xeno_console_put_char;
202 xeno_console_driver.chars_in_buffer = xeno_console_chars_in_buffer;
204 if ( tty_register_driver(&xeno_console_driver) )
205 {
206 printk(KERN_ERR "Couldn't register Xeno console driver\n");
207 }
208 else
209 {
210 printk("Xeno console successfully installed\n");
211 }
213 return 0;
214 }
216 void __exit xeno_con_fini(void)
217 {
218 int ret;
220 ret = tty_unregister_driver(&xeno_console_driver);
221 if ( ret != 0 )
222 {
223 printk(KERN_ERR "Unable to unregister Xeno console driver: %d\n", ret);
224 }
225 }
227 module_init(xeno_con_init);
228 module_exit(xeno_con_fini);