ssl.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 "line.h"
  15. #include "ssl.h"
  16. #include "chan_kern.h"
  17. #include "user_util.h"
  18. #include "kern_util.h"
  19. #include "kern.h"
  20. #include "init.h"
  21. #include "irq_user.h"
  22. #include "mconsole_kern.h"
  23. static const int ssl_version = 1;
  24. /* Referenced only by tty_driver below - presumably it's locked correctly
  25. * by the tty driver.
  26. */
  27. static struct tty_driver *ssl_driver;
  28. #define NR_PORTS 64
  29. static void ssl_announce(char *dev_name, int dev)
  30. {
  31. printk(KERN_INFO "Serial line %d assigned device '%s'\n", dev,
  32. dev_name);
  33. }
  34. /* Almost const, except that xterm_title may be changed in an initcall */
  35. static struct chan_opts opts = {
  36. .announce = ssl_announce,
  37. .xterm_title = "Serial Line #%d",
  38. .raw = 1,
  39. .tramp_stack = 0,
  40. .in_kernel = 1,
  41. };
  42. static int ssl_config(char *str, char **error_out);
  43. static int ssl_get_config(char *dev, char *str, int size, char **error_out);
  44. static int ssl_remove(int n, char **error_out);
  45. /* Const, except for .mc.list */
  46. static struct line_driver driver = {
  47. .name = "UML serial line",
  48. .device_name = "ttyS",
  49. .major = TTY_MAJOR,
  50. .minor_start = 64,
  51. .type = TTY_DRIVER_TYPE_SERIAL,
  52. .subtype = 0,
  53. .read_irq = SSL_IRQ,
  54. .read_irq_name = "ssl",
  55. .write_irq = SSL_WRITE_IRQ,
  56. .write_irq_name = "ssl-write",
  57. .mc = {
  58. .list = LIST_HEAD_INIT(driver.mc.list),
  59. .name = "ssl",
  60. .config = ssl_config,
  61. .get_config = ssl_get_config,
  62. .id = line_id,
  63. .remove = ssl_remove,
  64. },
  65. };
  66. /* The array is initialized by line_init, at initcall time. The
  67. * elements are locked individually as needed.
  68. */
  69. static struct line serial_lines[NR_PORTS] =
  70. { [0 ... NR_PORTS - 1] = LINE_INIT(CONFIG_SSL_CHAN, &driver) };
  71. static int ssl_config(char *str, char **error_out)
  72. {
  73. return line_config(serial_lines, ARRAY_SIZE(serial_lines), str, &opts,
  74. error_out);
  75. }
  76. static int ssl_get_config(char *dev, char *str, int size, char **error_out)
  77. {
  78. return line_get_config(dev, serial_lines, ARRAY_SIZE(serial_lines), str,
  79. size, error_out);
  80. }
  81. static int ssl_remove(int n, char **error_out)
  82. {
  83. return line_remove(serial_lines, ARRAY_SIZE(serial_lines), n,
  84. error_out);
  85. }
  86. static int ssl_open(struct tty_struct *tty, struct file *filp)
  87. {
  88. return line_open(serial_lines, tty);
  89. }
  90. #if 0
  91. static void ssl_flush_buffer(struct tty_struct *tty)
  92. {
  93. return;
  94. }
  95. static void ssl_stop(struct tty_struct *tty)
  96. {
  97. printk(KERN_ERR "Someone should implement ssl_stop\n");
  98. }
  99. static void ssl_start(struct tty_struct *tty)
  100. {
  101. printk(KERN_ERR "Someone should implement ssl_start\n");
  102. }
  103. void ssl_hangup(struct tty_struct *tty)
  104. {
  105. }
  106. #endif
  107. static const struct tty_operations ssl_ops = {
  108. .open = ssl_open,
  109. .close = line_close,
  110. .write = line_write,
  111. .put_char = line_put_char,
  112. .write_room = line_write_room,
  113. .chars_in_buffer = line_chars_in_buffer,
  114. .flush_buffer = line_flush_buffer,
  115. .flush_chars = line_flush_chars,
  116. .set_termios = line_set_termios,
  117. .ioctl = line_ioctl,
  118. .throttle = line_throttle,
  119. .unthrottle = line_unthrottle,
  120. #if 0
  121. .stop = ssl_stop,
  122. .start = ssl_start,
  123. .hangup = ssl_hangup,
  124. #endif
  125. };
  126. /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
  127. * by being an initcall and exitcall, respectively.
  128. */
  129. static int ssl_init_done = 0;
  130. static void ssl_console_write(struct console *c, const char *string,
  131. unsigned len)
  132. {
  133. struct line *line = &serial_lines[c->index];
  134. unsigned long flags;
  135. spin_lock_irqsave(&line->lock, flags);
  136. console_write_chan(&line->chan_list, string, len);
  137. spin_unlock_irqrestore(&line->lock, flags);
  138. }
  139. static struct tty_driver *ssl_console_device(struct console *c, int *index)
  140. {
  141. *index = c->index;
  142. return ssl_driver;
  143. }
  144. static int ssl_console_setup(struct console *co, char *options)
  145. {
  146. struct line *line = &serial_lines[co->index];
  147. return console_open_chan(line, co);
  148. }
  149. /* No locking for register_console call - relies on single-threaded initcalls */
  150. static struct console ssl_cons = {
  151. .name = "ttyS",
  152. .write = ssl_console_write,
  153. .device = ssl_console_device,
  154. .setup = ssl_console_setup,
  155. .flags = CON_PRINTBUFFER,
  156. .index = -1,
  157. };
  158. static int ssl_init(void)
  159. {
  160. char *new_title;
  161. printk(KERN_INFO "Initializing software serial port version %d\n",
  162. ssl_version);
  163. ssl_driver = register_lines(&driver, &ssl_ops, serial_lines,
  164. ARRAY_SIZE(serial_lines));
  165. lines_init(serial_lines, ARRAY_SIZE(serial_lines), &opts);
  166. new_title = add_xterm_umid(opts.xterm_title);
  167. if (new_title != NULL)
  168. opts.xterm_title = new_title;
  169. ssl_init_done = 1;
  170. register_console(&ssl_cons);
  171. return 0;
  172. }
  173. late_initcall(ssl_init);
  174. static void ssl_exit(void)
  175. {
  176. if (!ssl_init_done)
  177. return;
  178. close_lines(serial_lines, ARRAY_SIZE(serial_lines));
  179. }
  180. __uml_exitcall(ssl_exit);
  181. static int ssl_chan_setup(char *str)
  182. {
  183. char *error;
  184. int ret;
  185. ret = line_setup(serial_lines, ARRAY_SIZE(serial_lines), str, &error);
  186. if(ret < 0)
  187. printk(KERN_ERR "Failed to set up serial line with "
  188. "configuration string \"%s\" : %s\n", str, error);
  189. return 1;
  190. }
  191. __setup("ssl", ssl_chan_setup);
  192. __channel_help(ssl_chan_setup, "ssl");