2 * Copyright (C) 2000, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
8 #include "linux/tty_driver.h"
9 #include "linux/major.h"
11 #include "linux/init.h"
12 #include "linux/console.h"
13 #include "asm/termbits.h"
17 #include "chan_kern.h"
18 #include "user_util.h"
19 #include "kern_util.h"
23 #include "mconsole_kern.h"
25 static const int ssl_version
= 1;
27 /* Referenced only by tty_driver below - presumably it's locked correctly
31 static struct tty_driver
*ssl_driver
;
35 static void ssl_announce(char *dev_name
, int dev
)
37 printk(KERN_INFO
"Serial line %d assigned device '%s'\n", dev
,
41 static struct chan_opts opts
= {
42 .announce
= ssl_announce
,
43 .xterm_title
= "Serial Line #%d",
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
);
53 static struct line_driver driver
= {
54 .name
= "UML serial line",
55 .device_name
= "ttyS",
58 .type
= TTY_DRIVER_TYPE_SERIAL
,
61 .read_irq_name
= "ssl",
62 .write_irq
= SSL_WRITE_IRQ
,
63 .write_irq_name
= "ssl-write",
64 .symlink_from
= "serial",
69 .get_config
= ssl_get_config
,
75 /* The array is initialized by line_init, which is an initcall. The
76 * individual elements are protected by individual semaphores.
78 static struct line serial_lines
[NR_PORTS
] =
79 { [0 ... NR_PORTS
- 1] = LINE_INIT(CONFIG_SSL_CHAN
, &driver
) };
81 static struct lines lines
= LINES_INIT(NR_PORTS
);
83 static int ssl_config(char *str
)
85 return line_config(serial_lines
, ARRAY_SIZE(serial_lines
), str
, &opts
);
88 static int ssl_get_config(char *dev
, char *str
, int size
, char **error_out
)
90 return line_get_config(dev
, serial_lines
, ARRAY_SIZE(serial_lines
), str
,
94 static int ssl_remove(int n
)
96 return line_remove(serial_lines
, ARRAY_SIZE(serial_lines
), n
);
99 static int ssl_open(struct tty_struct
*tty
, struct file
*filp
)
101 return line_open(serial_lines
, tty
);
105 static void ssl_flush_buffer(struct tty_struct
*tty
)
110 static void ssl_stop(struct tty_struct
*tty
)
112 printk(KERN_ERR
"Someone should implement ssl_stop\n");
115 static void ssl_start(struct tty_struct
*tty
)
117 printk(KERN_ERR
"Someone should implement ssl_start\n");
120 void ssl_hangup(struct tty_struct
*tty
)
125 static const struct tty_operations ssl_ops
= {
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
,
136 .throttle
= line_throttle
,
137 .unthrottle
= line_unthrottle
,
141 .hangup
= ssl_hangup
,
145 /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
146 * by being an initcall and exitcall, respectively.
148 static int ssl_init_done
= 0;
150 static void ssl_console_write(struct console
*c
, const char *string
,
153 struct line
*line
= &serial_lines
[c
->index
];
156 spin_lock_irqsave(&line
->lock
, flags
);
157 console_write_chan(&line
->chan_list
, string
, len
);
158 spin_unlock_irqrestore(&line
->lock
, flags
);
161 static struct tty_driver
*ssl_console_device(struct console
*c
, int *index
)
167 static int ssl_console_setup(struct console
*co
, char *options
)
169 struct line
*line
= &serial_lines
[co
->index
];
171 return console_open_chan(line
, co
, &opts
);
174 static struct console ssl_cons
= {
176 .write
= ssl_console_write
,
177 .device
= ssl_console_device
,
178 .setup
= ssl_console_setup
,
179 .flags
= CON_PRINTBUFFER
,
183 static int ssl_init(void)
187 printk(KERN_INFO
"Initializing software serial port version %d\n",
189 ssl_driver
= line_register_devfs(&lines
, &driver
, &ssl_ops
,
191 ARRAY_SIZE(serial_lines
));
193 lines_init(serial_lines
, ARRAY_SIZE(serial_lines
), &opts
);
195 new_title
= add_xterm_umid(opts
.xterm_title
);
196 if (new_title
!= NULL
)
197 opts
.xterm_title
= new_title
;
200 register_console(&ssl_cons
);
203 late_initcall(ssl_init
);
205 static void ssl_exit(void)
209 close_lines(serial_lines
, ARRAY_SIZE(serial_lines
));
211 __uml_exitcall(ssl_exit
);
213 static int ssl_chan_setup(char *str
)
215 return line_setup(serial_lines
, ARRAY_SIZE(serial_lines
), str
);
218 __setup("ssl", ssl_chan_setup
);
219 __channel_help(ssl_chan_setup
, "ssl");