ssl.c 5.3 KB

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