ssl.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. static struct chan_opts opts = {
  35. .announce = ssl_announce,
  36. .xterm_title = "Serial Line #%d",
  37. .raw = 1,
  38. .tramp_stack = 0,
  39. .in_kernel = 1,
  40. };
  41. static int ssl_config(char *str);
  42. static int ssl_get_config(char *dev, char *str, int size, char **error_out);
  43. static int ssl_remove(int n);
  44. static struct line_driver driver = {
  45. .name = "UML serial line",
  46. .device_name = "ttyS",
  47. .major = TTY_MAJOR,
  48. .minor_start = 64,
  49. .type = TTY_DRIVER_TYPE_SERIAL,
  50. .subtype = 0,
  51. .read_irq = SSL_IRQ,
  52. .read_irq_name = "ssl",
  53. .write_irq = SSL_WRITE_IRQ,
  54. .write_irq_name = "ssl-write",
  55. .symlink_from = "serial",
  56. .symlink_to = "tts",
  57. .mc = {
  58. .name = "ssl",
  59. .config = ssl_config,
  60. .get_config = ssl_get_config,
  61. .id = line_id,
  62. .remove = ssl_remove,
  63. },
  64. };
  65. /* The array is initialized by line_init, which is an initcall. The
  66. * individual elements are protected by individual semaphores.
  67. */
  68. static struct line serial_lines[NR_PORTS] =
  69. { [0 ... NR_PORTS - 1] = LINE_INIT(CONFIG_SSL_CHAN, &driver) };
  70. static struct lines lines = LINES_INIT(NR_PORTS);
  71. static int ssl_config(char *str)
  72. {
  73. return line_config(serial_lines, ARRAY_SIZE(serial_lines), str, &opts);
  74. }
  75. static int ssl_get_config(char *dev, char *str, int size, char **error_out)
  76. {
  77. return line_get_config(dev, serial_lines, ARRAY_SIZE(serial_lines), str,
  78. size, error_out);
  79. }
  80. static int ssl_remove(int n)
  81. {
  82. return line_remove(serial_lines, ARRAY_SIZE(serial_lines), n);
  83. }
  84. static int ssl_open(struct tty_struct *tty, struct file *filp)
  85. {
  86. return line_open(serial_lines, tty);
  87. }
  88. #if 0
  89. static void ssl_flush_buffer(struct tty_struct *tty)
  90. {
  91. return;
  92. }
  93. static void ssl_stop(struct tty_struct *tty)
  94. {
  95. printk(KERN_ERR "Someone should implement ssl_stop\n");
  96. }
  97. static void ssl_start(struct tty_struct *tty)
  98. {
  99. printk(KERN_ERR "Someone should implement ssl_start\n");
  100. }
  101. void ssl_hangup(struct tty_struct *tty)
  102. {
  103. }
  104. #endif
  105. static const struct tty_operations ssl_ops = {
  106. .open = ssl_open,
  107. .close = line_close,
  108. .write = line_write,
  109. .put_char = line_put_char,
  110. .write_room = line_write_room,
  111. .chars_in_buffer = line_chars_in_buffer,
  112. .flush_buffer = line_flush_buffer,
  113. .flush_chars = line_flush_chars,
  114. .set_termios = line_set_termios,
  115. .ioctl = line_ioctl,
  116. .throttle = line_throttle,
  117. .unthrottle = line_unthrottle,
  118. #if 0
  119. .stop = ssl_stop,
  120. .start = ssl_start,
  121. .hangup = ssl_hangup,
  122. #endif
  123. };
  124. /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
  125. * by being an initcall and exitcall, respectively.
  126. */
  127. static int ssl_init_done = 0;
  128. static void ssl_console_write(struct console *c, const char *string,
  129. unsigned len)
  130. {
  131. struct line *line = &serial_lines[c->index];
  132. unsigned long flags;
  133. spin_lock_irqsave(&line->lock, flags);
  134. console_write_chan(&line->chan_list, string, len);
  135. spin_unlock_irqrestore(&line->lock, flags);
  136. }
  137. static struct tty_driver *ssl_console_device(struct console *c, int *index)
  138. {
  139. *index = c->index;
  140. return ssl_driver;
  141. }
  142. static int ssl_console_setup(struct console *co, char *options)
  143. {
  144. struct line *line = &serial_lines[co->index];
  145. return console_open_chan(line, co, &opts);
  146. }
  147. static struct console ssl_cons = {
  148. .name = "ttyS",
  149. .write = ssl_console_write,
  150. .device = ssl_console_device,
  151. .setup = ssl_console_setup,
  152. .flags = CON_PRINTBUFFER,
  153. .index = -1,
  154. };
  155. static int ssl_init(void)
  156. {
  157. char *new_title;
  158. printk(KERN_INFO "Initializing software serial port version %d\n",
  159. ssl_version);
  160. ssl_driver = line_register_devfs(&lines, &driver, &ssl_ops,
  161. serial_lines,
  162. ARRAY_SIZE(serial_lines));
  163. lines_init(serial_lines, ARRAY_SIZE(serial_lines), &opts);
  164. new_title = add_xterm_umid(opts.xterm_title);
  165. if (new_title != NULL)
  166. opts.xterm_title = new_title;
  167. ssl_init_done = 1;
  168. register_console(&ssl_cons);
  169. return 0;
  170. }
  171. late_initcall(ssl_init);
  172. static void ssl_exit(void)
  173. {
  174. if (!ssl_init_done)
  175. return;
  176. close_lines(serial_lines, ARRAY_SIZE(serial_lines));
  177. }
  178. __uml_exitcall(ssl_exit);
  179. static int ssl_chan_setup(char *str)
  180. {
  181. return line_setup(serial_lines, ARRAY_SIZE(serial_lines), str);
  182. }
  183. __setup("ssl", ssl_chan_setup);
  184. __channel_help(ssl_chan_setup, "ssl");