ssl.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (C) 2000, 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <linux/fs.h>
  6. #include <linux/tty.h>
  7. #include <linux/tty_driver.h>
  8. #include <linux/major.h>
  9. #include <linux/mm.h>
  10. #include <linux/init.h>
  11. #include <linux/console.h>
  12. #include <asm/termbits.h>
  13. #include <asm/irq.h>
  14. #include "ssl.h"
  15. #include "chan.h"
  16. #include <init.h>
  17. #include <irq_user.h>
  18. #include "mconsole_kern.h"
  19. static const int ssl_version = 1;
  20. #define NR_PORTS 64
  21. static void ssl_announce(char *dev_name, int dev)
  22. {
  23. printk(KERN_INFO "Serial line %d assigned device '%s'\n", dev,
  24. dev_name);
  25. }
  26. /* Almost const, except that xterm_title may be changed in an initcall */
  27. static struct chan_opts opts = {
  28. .announce = ssl_announce,
  29. .xterm_title = "Serial Line #%d",
  30. .raw = 1,
  31. };
  32. static int ssl_config(char *str, char **error_out);
  33. static int ssl_get_config(char *dev, char *str, int size, char **error_out);
  34. static int ssl_remove(int n, char **error_out);
  35. /* Const, except for .mc.list */
  36. static struct line_driver driver = {
  37. .name = "UML serial line",
  38. .device_name = "ttyS",
  39. .major = TTY_MAJOR,
  40. .minor_start = 64,
  41. .type = TTY_DRIVER_TYPE_SERIAL,
  42. .subtype = 0,
  43. .read_irq = SSL_IRQ,
  44. .read_irq_name = "ssl",
  45. .write_irq = SSL_WRITE_IRQ,
  46. .write_irq_name = "ssl-write",
  47. .mc = {
  48. .list = LIST_HEAD_INIT(driver.mc.list),
  49. .name = "ssl",
  50. .config = ssl_config,
  51. .get_config = ssl_get_config,
  52. .id = line_id,
  53. .remove = ssl_remove,
  54. },
  55. };
  56. /* The array is initialized by line_init, at initcall time. The
  57. * elements are locked individually as needed.
  58. */
  59. static char *conf[NR_PORTS];
  60. static char *def_conf = CONFIG_SSL_CHAN;
  61. static struct line serial_lines[NR_PORTS];
  62. static int ssl_config(char *str, char **error_out)
  63. {
  64. return line_config(serial_lines, ARRAY_SIZE(serial_lines), str, &opts,
  65. error_out);
  66. }
  67. static int ssl_get_config(char *dev, char *str, int size, char **error_out)
  68. {
  69. return line_get_config(dev, serial_lines, ARRAY_SIZE(serial_lines), str,
  70. size, error_out);
  71. }
  72. static int ssl_remove(int n, char **error_out)
  73. {
  74. return line_remove(serial_lines, ARRAY_SIZE(serial_lines), n,
  75. error_out);
  76. }
  77. static int ssl_install(struct tty_driver *driver, struct tty_struct *tty)
  78. {
  79. return line_install(driver, tty, &serial_lines[tty->index]);
  80. }
  81. static const struct tty_operations ssl_ops = {
  82. .open = line_open,
  83. .close = line_close,
  84. .write = line_write,
  85. .put_char = line_put_char,
  86. .write_room = line_write_room,
  87. .chars_in_buffer = line_chars_in_buffer,
  88. .flush_buffer = line_flush_buffer,
  89. .flush_chars = line_flush_chars,
  90. .set_termios = line_set_termios,
  91. .throttle = line_throttle,
  92. .unthrottle = line_unthrottle,
  93. .install = ssl_install,
  94. .hangup = line_hangup,
  95. };
  96. /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
  97. * by being an initcall and exitcall, respectively.
  98. */
  99. static int ssl_init_done = 0;
  100. static void ssl_console_write(struct console *c, const char *string,
  101. unsigned len)
  102. {
  103. struct line *line = &serial_lines[c->index];
  104. unsigned long flags;
  105. spin_lock_irqsave(&line->lock, flags);
  106. console_write_chan(line->chan_out, string, len);
  107. spin_unlock_irqrestore(&line->lock, flags);
  108. }
  109. static struct tty_driver *ssl_console_device(struct console *c, int *index)
  110. {
  111. *index = c->index;
  112. return driver.driver;
  113. }
  114. static int ssl_console_setup(struct console *co, char *options)
  115. {
  116. struct line *line = &serial_lines[co->index];
  117. return console_open_chan(line, co);
  118. }
  119. /* No locking for register_console call - relies on single-threaded initcalls */
  120. static struct console ssl_cons = {
  121. .name = "ttyS",
  122. .write = ssl_console_write,
  123. .device = ssl_console_device,
  124. .setup = ssl_console_setup,
  125. .flags = CON_PRINTBUFFER|CON_ANYTIME,
  126. .index = -1,
  127. };
  128. static int ssl_init(void)
  129. {
  130. char *new_title;
  131. int err;
  132. int i;
  133. printk(KERN_INFO "Initializing software serial port version %d\n",
  134. ssl_version);
  135. err = register_lines(&driver, &ssl_ops, serial_lines,
  136. ARRAY_SIZE(serial_lines));
  137. if (err)
  138. return err;
  139. new_title = add_xterm_umid(opts.xterm_title);
  140. if (new_title != NULL)
  141. opts.xterm_title = new_title;
  142. for (i = 0; i < NR_PORTS; i++) {
  143. char *error;
  144. char *s = conf[i];
  145. if (!s)
  146. s = def_conf;
  147. if (setup_one_line(serial_lines, i, s, &opts, &error))
  148. printk(KERN_ERR "setup_one_line failed for "
  149. "device %d : %s\n", i, error);
  150. }
  151. ssl_init_done = 1;
  152. register_console(&ssl_cons);
  153. return 0;
  154. }
  155. late_initcall(ssl_init);
  156. static void ssl_exit(void)
  157. {
  158. if (!ssl_init_done)
  159. return;
  160. close_lines(serial_lines, ARRAY_SIZE(serial_lines));
  161. }
  162. __uml_exitcall(ssl_exit);
  163. static int ssl_chan_setup(char *str)
  164. {
  165. line_setup(conf, NR_PORTS, &def_conf, str, "serial line");
  166. return 1;
  167. }
  168. __setup("ssl", ssl_chan_setup);
  169. __channel_help(ssl_chan_setup, "ssl");