ssl.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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_open(struct tty_struct *tty, struct file *filp)
  78. {
  79. int err = line_open(serial_lines, tty);
  80. if (err)
  81. printk(KERN_ERR "Failed to open serial line %d, err = %d\n",
  82. tty->index, err);
  83. return err;
  84. }
  85. static const struct tty_operations ssl_ops = {
  86. .open = ssl_open,
  87. .close = line_close,
  88. .write = line_write,
  89. .put_char = line_put_char,
  90. .write_room = line_write_room,
  91. .chars_in_buffer = line_chars_in_buffer,
  92. .flush_buffer = line_flush_buffer,
  93. .flush_chars = line_flush_chars,
  94. .set_termios = line_set_termios,
  95. .throttle = line_throttle,
  96. .unthrottle = line_unthrottle,
  97. };
  98. /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
  99. * by being an initcall and exitcall, respectively.
  100. */
  101. static int ssl_init_done = 0;
  102. static void ssl_console_write(struct console *c, const char *string,
  103. unsigned len)
  104. {
  105. struct line *line = &serial_lines[c->index];
  106. unsigned long flags;
  107. spin_lock_irqsave(&line->lock, flags);
  108. console_write_chan(line->chan_out, string, len);
  109. spin_unlock_irqrestore(&line->lock, flags);
  110. }
  111. static struct tty_driver *ssl_console_device(struct console *c, int *index)
  112. {
  113. *index = c->index;
  114. return driver.driver;
  115. }
  116. static int ssl_console_setup(struct console *co, char *options)
  117. {
  118. struct line *line = &serial_lines[co->index];
  119. return console_open_chan(line, co);
  120. }
  121. /* No locking for register_console call - relies on single-threaded initcalls */
  122. static struct console ssl_cons = {
  123. .name = "ttyS",
  124. .write = ssl_console_write,
  125. .device = ssl_console_device,
  126. .setup = ssl_console_setup,
  127. .flags = CON_PRINTBUFFER|CON_ANYTIME,
  128. .index = -1,
  129. };
  130. static int ssl_init(void)
  131. {
  132. char *new_title;
  133. int err;
  134. int i;
  135. printk(KERN_INFO "Initializing software serial port version %d\n",
  136. ssl_version);
  137. err = register_lines(&driver, &ssl_ops, serial_lines,
  138. ARRAY_SIZE(serial_lines));
  139. if (err)
  140. return err;
  141. new_title = add_xterm_umid(opts.xterm_title);
  142. if (new_title != NULL)
  143. opts.xterm_title = new_title;
  144. for (i = 0; i < NR_PORTS; i++) {
  145. char *error;
  146. char *s = conf[i];
  147. if (!s)
  148. s = def_conf;
  149. if (setup_one_line(serial_lines, i, s, &opts, &error))
  150. printk(KERN_ERR "setup_one_line failed for "
  151. "device %d : %s\n", i, error);
  152. }
  153. ssl_init_done = 1;
  154. register_console(&ssl_cons);
  155. return 0;
  156. }
  157. late_initcall(ssl_init);
  158. static void ssl_exit(void)
  159. {
  160. if (!ssl_init_done)
  161. return;
  162. close_lines(serial_lines, ARRAY_SIZE(serial_lines));
  163. }
  164. __uml_exitcall(ssl_exit);
  165. static int ssl_chan_setup(char *str)
  166. {
  167. line_setup(conf, NR_PORTS, &def_conf, str, "serial line");
  168. return 1;
  169. }
  170. __setup("ssl", ssl_chan_setup);
  171. __channel_help(ssl_chan_setup, "ssl");