1 // SPDX-License-Identifier: GPL-2.0
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>
18 #include "mconsole_kern.h"
20 static const int ssl_version = 1;
24 static void ssl_announce(char *dev_name, int dev)
26 printk(KERN_INFO "Serial line %d assigned device '%s'\n", dev,
30 /* Almost const, except that xterm_title may be changed in an initcall */
31 static struct chan_opts opts = {
32 .announce = ssl_announce,
33 .xterm_title = "Serial Line #%d",
37 static int ssl_config(char *str, char **error_out);
38 static int ssl_get_config(char *dev, char *str, int size, char **error_out);
39 static int ssl_remove(int n, char **error_out);
42 /* Const, except for .mc.list */
43 static struct line_driver driver = {
44 .name = "UML serial line",
45 .device_name = "ttyS",
48 .type = TTY_DRIVER_TYPE_SERIAL,
50 .read_irq_name = "ssl",
51 .write_irq_name = "ssl-write",
53 .list = LIST_HEAD_INIT(driver.mc.list),
56 .get_config = ssl_get_config,
62 /* The array is initialized by line_init, at initcall time. The
63 * elements are locked individually as needed.
65 static char *conf[NR_PORTS];
66 static char *def_conf = CONFIG_SSL_CHAN;
67 static struct line serial_lines[NR_PORTS];
69 static int ssl_config(char *str, char **error_out)
71 return line_config(serial_lines, ARRAY_SIZE(serial_lines), str, &opts,
75 static int ssl_get_config(char *dev, char *str, int size, char **error_out)
77 return line_get_config(dev, serial_lines, ARRAY_SIZE(serial_lines), str,
81 static int ssl_remove(int n, char **error_out)
83 return line_remove(serial_lines, ARRAY_SIZE(serial_lines), n,
87 static int ssl_install(struct tty_driver *driver, struct tty_struct *tty)
89 return line_install(driver, tty, &serial_lines[tty->index]);
92 static const struct tty_operations ssl_ops = {
96 .write_room = line_write_room,
97 .chars_in_buffer = line_chars_in_buffer,
98 .flush_buffer = line_flush_buffer,
99 .flush_chars = line_flush_chars,
100 .throttle = line_throttle,
101 .unthrottle = line_unthrottle,
102 .install = ssl_install,
103 .hangup = line_hangup,
106 /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
107 * by being an initcall and exitcall, respectively.
109 static int ssl_init_done;
111 static void ssl_console_write(struct console *c, const char *string,
114 struct line *line = &serial_lines[c->index];
117 spin_lock_irqsave(&line->lock, flags);
118 console_write_chan(line->chan_out, string, len);
119 spin_unlock_irqrestore(&line->lock, flags);
122 static struct tty_driver *ssl_console_device(struct console *c, int *index)
125 return driver.driver;
128 static int ssl_console_setup(struct console *co, char *options)
130 struct line *line = &serial_lines[co->index];
132 return console_open_chan(line, co);
135 /* No locking for register_console call - relies on single-threaded initcalls */
136 static struct console ssl_cons = {
138 .write = ssl_console_write,
139 .device = ssl_console_device,
140 .setup = ssl_console_setup,
141 .flags = CON_PRINTBUFFER|CON_ANYTIME,
145 static int ssl_init(void)
151 printk(KERN_INFO "Initializing software serial port version %d\n",
154 err = register_lines(&driver, &ssl_ops, serial_lines,
155 ARRAY_SIZE(serial_lines));
159 new_title = add_xterm_umid(opts.xterm_title);
160 if (new_title != NULL)
161 opts.xterm_title = new_title;
163 for (i = 0; i < NR_PORTS; i++) {
168 if (setup_one_line(serial_lines, i, s, &opts, &error))
169 printk(KERN_ERR "setup_one_line failed for "
170 "device %d : %s\n", i, error);
174 register_console(&ssl_cons);
177 late_initcall(ssl_init);
179 static void ssl_exit(void)
183 close_lines(serial_lines, ARRAY_SIZE(serial_lines));
185 __uml_exitcall(ssl_exit);
187 static int ssl_chan_setup(char *str)
189 line_setup(conf, NR_PORTS, &def_conf, str, "serial line");
193 __setup("ssl", ssl_chan_setup);
194 __channel_help(ssl_chan_setup, "ssl");
196 static int ssl_non_raw_setup(char *str)
201 __setup("ssl-non-raw", ssl_non_raw_setup);
202 __channel_help(ssl_non_raw_setup, "set serial lines to non-raw mode");