Remove all inclusions of <linux/config.h>
[pandora-kernel.git] / arch / um / drivers / ssl.c
1 /* 
2  * Copyright (C) 2000, 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include "linux/fs.h"
7 #include "linux/tty.h"
8 #include "linux/tty_driver.h"
9 #include "linux/major.h"
10 #include "linux/mm.h"
11 #include "linux/init.h"
12 #include "linux/console.h"
13 #include "asm/termbits.h"
14 #include "asm/irq.h"
15 #include "line.h"
16 #include "ssl.h"
17 #include "chan_kern.h"
18 #include "user_util.h"
19 #include "kern_util.h"
20 #include "kern.h"
21 #include "init.h"
22 #include "irq_user.h"
23 #include "mconsole_kern.h"
24
25 static const int ssl_version = 1;
26
27 /* Referenced only by tty_driver below - presumably it's locked correctly
28  * by the tty driver.
29  */
30
31 static struct tty_driver *ssl_driver;
32
33 #define NR_PORTS 64
34
35 static void ssl_announce(char *dev_name, int dev)
36 {
37         printk(KERN_INFO "Serial line %d assigned device '%s'\n", dev,
38                dev_name);
39 }
40
41 static struct chan_opts opts = {
42         .announce       = ssl_announce,
43         .xterm_title    = "Serial Line #%d",
44         .raw            = 1,
45         .tramp_stack    = 0,
46         .in_kernel      = 1,
47 };
48
49 static int ssl_config(char *str);
50 static int ssl_get_config(char *dev, char *str, int size, char **error_out);
51 static int ssl_remove(int n);
52
53 static struct line_driver driver = {
54         .name                   = "UML serial line",
55         .device_name            = "ttyS",
56         .major                  = TTY_MAJOR,
57         .minor_start            = 64,
58         .type                   = TTY_DRIVER_TYPE_SERIAL,
59         .subtype                = 0,
60         .read_irq               = SSL_IRQ,
61         .read_irq_name          = "ssl",
62         .write_irq              = SSL_WRITE_IRQ,
63         .write_irq_name         = "ssl-write",
64         .symlink_from           = "serial",
65         .symlink_to             = "tts",
66         .mc  = {
67                 .name           = "ssl",
68                 .config         = ssl_config,
69                 .get_config     = ssl_get_config,
70                 .id             = line_id,
71                 .remove         = ssl_remove,
72         },
73 };
74
75 /* The array is initialized by line_init, which is an initcall.  The 
76  * individual elements are protected by individual semaphores.
77  */
78 static struct line serial_lines[NR_PORTS] =
79         { [0 ... NR_PORTS - 1] = LINE_INIT(CONFIG_SSL_CHAN, &driver) };
80
81 static struct lines lines = LINES_INIT(NR_PORTS);
82
83 static int ssl_config(char *str)
84 {
85         return line_config(serial_lines, ARRAY_SIZE(serial_lines), str, &opts);
86 }
87
88 static int ssl_get_config(char *dev, char *str, int size, char **error_out)
89 {
90         return line_get_config(dev, serial_lines, ARRAY_SIZE(serial_lines), str,
91                                size, error_out);
92 }
93
94 static int ssl_remove(int n)
95 {
96         return line_remove(serial_lines, ARRAY_SIZE(serial_lines), n);
97 }
98
99 static int ssl_open(struct tty_struct *tty, struct file *filp)
100 {
101         return line_open(serial_lines, tty);
102 }
103
104 #if 0
105 static void ssl_flush_buffer(struct tty_struct *tty)
106 {
107         return;
108 }
109
110 static void ssl_stop(struct tty_struct *tty)
111 {
112         printk(KERN_ERR "Someone should implement ssl_stop\n");
113 }
114
115 static void ssl_start(struct tty_struct *tty)
116 {
117         printk(KERN_ERR "Someone should implement ssl_start\n");
118 }
119
120 void ssl_hangup(struct tty_struct *tty)
121 {
122 }
123 #endif
124
125 static const struct tty_operations ssl_ops = {
126         .open                   = ssl_open,
127         .close                  = line_close,
128         .write                  = line_write,
129         .put_char               = line_put_char,
130         .write_room             = line_write_room,
131         .chars_in_buffer        = line_chars_in_buffer,
132         .flush_buffer           = line_flush_buffer,
133         .flush_chars            = line_flush_chars,
134         .set_termios            = line_set_termios,
135         .ioctl                  = line_ioctl,
136         .throttle               = line_throttle,
137         .unthrottle             = line_unthrottle,
138 #if 0
139         .stop                   = ssl_stop,
140         .start                  = ssl_start,
141         .hangup                 = ssl_hangup,
142 #endif
143 };
144
145 /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
146  * by being an initcall and exitcall, respectively.
147  */
148 static int ssl_init_done = 0;
149
150 static void ssl_console_write(struct console *c, const char *string,
151                               unsigned len)
152 {
153         struct line *line = &serial_lines[c->index];
154         unsigned long flags;
155
156         spin_lock_irqsave(&line->lock, flags);
157         console_write_chan(&line->chan_list, string, len);
158         spin_unlock_irqrestore(&line->lock, flags);
159 }
160
161 static struct tty_driver *ssl_console_device(struct console *c, int *index)
162 {
163         *index = c->index;
164         return ssl_driver;
165 }
166
167 static int ssl_console_setup(struct console *co, char *options)
168 {
169         struct line *line = &serial_lines[co->index];
170
171         return console_open_chan(line, co, &opts);
172 }
173
174 static struct console ssl_cons = {
175         .name           = "ttyS",
176         .write          = ssl_console_write,
177         .device         = ssl_console_device,
178         .setup          = ssl_console_setup,
179         .flags          = CON_PRINTBUFFER,
180         .index          = -1,
181 };
182
183 static int ssl_init(void)
184 {
185         char *new_title;
186
187         printk(KERN_INFO "Initializing software serial port version %d\n",
188                ssl_version);
189         ssl_driver = line_register_devfs(&lines, &driver, &ssl_ops,
190                                          serial_lines,
191                                          ARRAY_SIZE(serial_lines));
192
193         lines_init(serial_lines, ARRAY_SIZE(serial_lines), &opts);
194
195         new_title = add_xterm_umid(opts.xterm_title);
196         if (new_title != NULL)
197                 opts.xterm_title = new_title;
198
199         ssl_init_done = 1;
200         register_console(&ssl_cons);
201         return 0;
202 }
203 late_initcall(ssl_init);
204
205 static void ssl_exit(void)
206 {
207         if (!ssl_init_done)
208                 return;
209         close_lines(serial_lines, ARRAY_SIZE(serial_lines));
210 }
211 __uml_exitcall(ssl_exit);
212
213 static int ssl_chan_setup(char *str)
214 {
215         return line_setup(serial_lines, ARRAY_SIZE(serial_lines), str);
216 }
217
218 __setup("ssl", ssl_chan_setup);
219 __channel_help(ssl_chan_setup, "ssl");