ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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/config.h"
7 #include "linux/fs.h"
8 #include "linux/tty.h"
9 #include "linux/tty_driver.h"
10 #include "linux/major.h"
11 #include "linux/mm.h"
12 #include "linux/init.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 #include "2_5compat.h"
25
26 static int ssl_version = 1;
27
28 /* Referenced only by tty_driver below - presumably it's locked correctly
29  * by the tty driver.
30  */
31
32 static struct tty_driver *ssl_driver;
33
34 #define NR_PORTS 64
35
36 void ssl_announce(char *dev_name, int dev)
37 {
38         printk(KERN_INFO "Serial line %d assigned device '%s'\n", dev,
39                dev_name);
40 }
41
42 static struct chan_opts opts = {
43         .announce       = ssl_announce,
44         .xterm_title    = "Serial Line #%d",
45         .raw            = 1,
46         .tramp_stack    = 0,
47         .in_kernel      = 1,
48 };
49
50 static int ssl_config(char *str);
51 static int ssl_get_config(char *dev, char *str, int size, char **error_out);
52 static int ssl_remove(char *str);
53
54 static struct line_driver driver = {
55         .name                   = "UML serial line",
56         .devfs_name             = "tts/%d",
57         .major                  = TTYAUX_MAJOR,
58         .minor_start            = 64,
59         .type                   = TTY_DRIVER_TYPE_SERIAL,
60         .subtype                = 0,
61         .read_irq               = SSL_IRQ,
62         .read_irq_name          = "ssl",
63         .write_irq              = SSL_WRITE_IRQ,
64         .write_irq_name         = "ssl-write",
65         .symlink_from           = "serial",
66         .symlink_to             = "tts",
67         .mc  = {
68                 .name           = "ssl",
69                 .config         = ssl_config,
70                 .get_config     = ssl_get_config,
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, 
86                            sizeof(serial_lines)/sizeof(serial_lines[0]), str));
87 }
88
89 static int ssl_get_config(char *dev, char *str, int size, char **error_out)
90 {
91         return(line_get_config(dev, serial_lines, 
92                                sizeof(serial_lines)/sizeof(serial_lines[0]), 
93                                str, size, error_out));
94 }
95
96 static int ssl_remove(char *str)
97 {
98         return(line_remove(serial_lines, 
99                            sizeof(serial_lines)/sizeof(serial_lines[0]), str));
100 }
101
102 int ssl_open(struct tty_struct *tty, struct file *filp)
103 {
104         return(line_open(serial_lines, tty, &opts));
105 }
106
107 static void ssl_close(struct tty_struct *tty, struct file * filp)
108 {
109         line_close(serial_lines, tty);
110 }
111
112 static int ssl_write(struct tty_struct * tty, int from_user,
113                      const unsigned char *buf, int count)
114 {
115         return(line_write(serial_lines, tty, from_user, buf, count));
116 }
117
118 static void ssl_put_char(struct tty_struct *tty, unsigned char ch)
119 {
120         line_write(serial_lines, tty, 0, &ch, sizeof(ch));
121 }
122
123 static void ssl_flush_chars(struct tty_struct *tty)
124 {
125         return;
126 }
127
128 static int ssl_chars_in_buffer(struct tty_struct *tty)
129 {
130         return(0);
131 }
132
133 static void ssl_flush_buffer(struct tty_struct *tty)
134 {
135         return;
136 }
137
138 static int ssl_ioctl(struct tty_struct *tty, struct file * file,
139                      unsigned int cmd, unsigned long arg)
140 {
141         int ret;
142
143         ret = 0;
144         switch(cmd){
145         case TCGETS:
146         case TCSETS:
147         case TCFLSH:
148         case TCSETSF:
149         case TCSETSW:
150         case TCGETA:
151         case TIOCMGET:
152                 ret = -ENOIOCTLCMD;
153                 break;
154         default:
155                 printk(KERN_ERR 
156                        "Unimplemented ioctl in ssl_ioctl : 0x%x\n", cmd);
157                 ret = -ENOIOCTLCMD;
158                 break;
159         }
160         return(ret);
161 }
162
163 static void ssl_throttle(struct tty_struct * tty)
164 {
165         printk(KERN_ERR "Someone should implement ssl_throttle\n");
166 }
167
168 static void ssl_unthrottle(struct tty_struct * tty)
169 {
170         printk(KERN_ERR "Someone should implement ssl_unthrottle\n");
171 }
172
173 static void ssl_set_termios(struct tty_struct *tty, 
174                             struct termios *old_termios)
175 {
176 }
177
178 static void ssl_stop(struct tty_struct *tty)
179 {
180         printk(KERN_ERR "Someone should implement ssl_stop\n");
181 }
182
183 static void ssl_start(struct tty_struct *tty)
184 {
185         printk(KERN_ERR "Someone should implement ssl_start\n");
186 }
187
188 void ssl_hangup(struct tty_struct *tty)
189 {
190 }
191
192 static struct tty_operations ssl_ops = {
193         .open                   = ssl_open,
194         .close                  = ssl_close,
195         .write                  = ssl_write,
196         .put_char               = ssl_put_char,
197         .flush_chars            = ssl_flush_chars,
198         .chars_in_buffer        = ssl_chars_in_buffer,
199         .flush_buffer           = ssl_flush_buffer,
200         .ioctl                  = ssl_ioctl,
201         .throttle               = ssl_throttle,
202         .unthrottle             = ssl_unthrottle,
203         .set_termios            = ssl_set_termios,
204         .stop                   = ssl_stop,
205         .start                  = ssl_start,
206         .hangup                 = ssl_hangup,
207         .write_room             = line_write_room,
208 };
209
210 /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
211  * by being an initcall and exitcall, respectively.
212  */
213 static int ssl_init_done = 0;
214
215 int ssl_init(void)
216 {
217         char *new_title;
218
219         printk(KERN_INFO "Initializing software serial port version %d\n", 
220                ssl_version);
221
222         ssl_driver = line_register_devfs(&lines, &driver, &ssl_ops,
223                 serial_lines, sizeof(serial_lines)/sizeof(serial_lines[0]));
224
225         lines_init(serial_lines, sizeof(serial_lines)/sizeof(serial_lines[0]));
226
227         new_title = add_xterm_umid(opts.xterm_title);
228         if(new_title != NULL) opts.xterm_title = new_title;
229
230         ssl_init_done = 1;
231         return(0);
232 }
233
234 __initcall(ssl_init);
235
236 static int ssl_chan_setup(char *str)
237 {
238         line_setup(serial_lines, sizeof(serial_lines)/sizeof(serial_lines[0]),
239                    str, 1);
240         return(1);
241 }
242
243 __setup("ssl", ssl_chan_setup);
244 __channel_help(ssl_chan_setup, "ssl");
245
246 static void ssl_exit(void)
247 {
248         if(!ssl_init_done) return;
249         close_lines(serial_lines, 
250                     sizeof(serial_lines)/sizeof(serial_lines[0]));
251 }
252
253 __uml_exitcall(ssl_exit);
254
255 /*
256  * Overrides for Emacs so that we follow Linus's tabbing style.
257  * Emacs will notice this stuff at the end of the file and automatically
258  * adjust the settings for this buffer only.  This must remain at the end
259  * of the file.
260  * ---------------------------------------------------------------------------
261  * Local variables:
262  * c-file-style: "linux"
263  * End:
264  */