Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / arch / um / drivers / stdio_console.c
blob4803c3e071b00911545c1dcc4875c5cdf365d471
1 /*
2 * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include "linux/config.h"
7 #include "linux/posix_types.h"
8 #include "linux/tty.h"
9 #include "linux/tty_flip.h"
10 #include "linux/types.h"
11 #include "linux/major.h"
12 #include "linux/kdev_t.h"
13 #include "linux/console.h"
14 #include "linux/string.h"
15 #include "linux/sched.h"
16 #include "linux/list.h"
17 #include "linux/init.h"
18 #include "linux/interrupt.h"
19 #include "linux/slab.h"
20 #include "asm/current.h"
21 #include "asm/softirq.h"
22 #include "asm/hardirq.h"
23 #include "asm/irq.h"
24 #include "stdio_console.h"
25 #include "line.h"
26 #include "chan_kern.h"
27 #include "user_util.h"
28 #include "kern_util.h"
29 #include "irq_user.h"
30 #include "init.h"
31 #include "2_5compat.h"
33 #define MAX_TTYS (8)
35 /* Referenced only by tty_driver below - presumably it's locked correctly
36 * by the tty driver.
39 static struct tty_driver console_driver;
41 static int console_refcount = 0;
43 static struct chan_ops init_console_ops = {
44 init : NULL,
45 open : NULL,
46 close : NULL,
47 read : NULL,
48 write : NULL,
49 console_write : generic_write,
50 window_size : NULL,
51 free : NULL,
52 winch: 0,
55 static struct chan init_console_chan = {
56 list : { },
57 primary : 1,
58 input : 0,
59 output : 1,
60 opened : 1,
61 fd : 1,
62 pri : INIT_STATIC,
63 ops : &init_console_ops,
64 data : NULL
67 void stdio_announce(char *dev_name, int dev)
69 printk(KERN_INFO "Virtual console %d assigned device '%s'\n", dev,
70 dev_name);
73 static struct chan_opts opts = {
74 announce: stdio_announce,
75 xterm_title: "Virtual Console #%d",
76 raw: 1,
77 tramp_stack : 0,
78 in_kernel : 1,
81 static struct line_driver driver = {
82 name : "UML console",
83 devfs_name : "vc/%d",
84 major : TTY_MAJOR,
85 minor_start : 0,
86 type : TTY_DRIVER_TYPE_CONSOLE,
87 subtype : SYSTEM_TYPE_CONSOLE,
88 read_irq : CONSOLE_IRQ,
89 read_irq_name : "console",
90 write_irq : CONSOLE_WRITE_IRQ,
91 write_irq_name : "console-write",
92 symlink_from : "ttys",
93 symlink_to : "vc",
96 static struct lines console_lines = LINES_INIT(MAX_TTYS);
98 /* The array is initialized by line_init, which is an initcall. The
99 * individual elements are protected by individual semaphores.
101 struct line vts[MAX_TTYS] = { LINE_INIT(CONFIG_CON_ZERO_CHAN, &driver),
102 [ 1 ... MAX_TTYS - 1 ] =
103 LINE_INIT(CONFIG_CON_CHAN, &driver) };
105 static int open_console(struct tty_struct *tty)
107 return(line_open(vts, tty, &opts));
110 static int con_open(struct tty_struct *tty, struct file *filp)
112 return(open_console(tty));
115 static void con_close(struct tty_struct *tty, struct file *filp)
117 line_close(vts, tty);
120 static int con_write(struct tty_struct *tty, int from_user,
121 const unsigned char *buf, int count)
123 return(line_write(vts, tty, buf, count));
126 static void set_termios(struct tty_struct *tty, struct termios * old)
130 static int chars_in_buffer(struct tty_struct *tty)
132 return(0);
135 static int con_init_done = 0;
137 int stdio_init(void)
139 char *new_title;
141 printk(KERN_INFO "Initializing stdio console driver\n");
143 line_register_devfs(&console_lines, &driver, &console_driver, vts,
144 sizeof(vts)/sizeof(vts[0]));
146 lines_init(vts, sizeof(vts)/sizeof(vts[0]));
148 new_title = add_xterm_umid(opts.xterm_title);
149 if(new_title != NULL) opts.xterm_title = new_title;
151 open_console(NULL);
152 con_init_done = 1;
153 return(0);
156 __initcall(stdio_init);
158 static void console_write(struct console *console, const char *string,
159 unsigned len)
161 if(con_init_done) down(&vts[console->index].sem);
162 console_write_chan(&vts[console->index].chan_list, string, len);
163 if(con_init_done) up(&vts[console->index].sem);
166 static struct tty_driver console_driver = {
167 refcount : &console_refcount,
168 open : con_open,
169 close : con_close,
170 write : con_write,
171 chars_in_buffer : chars_in_buffer,
172 set_termios : set_termios
175 static kdev_t console_device(struct console *c)
177 return mk_kdev(TTY_MAJOR, c->index);
180 static int console_setup(struct console *co, char *options)
182 return(0);
185 static struct console stdiocons = INIT_CONSOLE("tty", console_write,
186 console_device, console_setup,
187 CON_PRINTBUFFER);
189 void stdio_console_init(void)
191 INIT_LIST_HEAD(&vts[0].chan_list);
192 list_add(&init_console_chan.list, &vts[0].chan_list);
193 register_console(&stdiocons);
196 static int console_chan_setup(char *str)
198 line_setup(vts, sizeof(vts)/sizeof(vts[0]), str);
199 return(1);
202 __setup("con", console_chan_setup);
203 __channel_help(console_chan_setup, "con");
205 static void console_exit(void)
207 if(!con_init_done) return;
208 close_lines(vts, sizeof(vts)/sizeof(vts[0]));
211 __uml_exitcall(console_exit);
214 * Overrides for Emacs so that we follow Linus's tabbing style.
215 * Emacs will notice this stuff at the end of the file and automatically
216 * adjust the settings for this buffer only. This must remain at the end
217 * of the file.
218 * ---------------------------------------------------------------------------
219 * Local variables:
220 * c-file-style: "linux"
221 * End: