ssl.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright (C) 2000, 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/config.h"
  6. #include "linux/fs.h"
  7. #include "linux/tty.h"
  8. #include "linux/tty_driver.h"
  9. #include "linux/major.h"
  10. #include "linux/mm.h"
  11. #include "linux/init.h"
  12. #include "linux/console.h"
  13. #include "asm/termbits.h"
  14. #include "asm/irq.h"
  15. #include "line.h"
  16. #include "ssl.h"
  17. #include "chan_kern.h"
  18. #include "user_util.h"
  19. #include "kern_util.h"
  20. #include "kern.h"
  21. #include "init.h"
  22. #include "irq_user.h"
  23. #include "mconsole_kern.h"
  24. static int ssl_version = 1;
  25. /* Referenced only by tty_driver below - presumably it's locked correctly
  26. * by the tty driver.
  27. */
  28. static struct tty_driver *ssl_driver;
  29. #define NR_PORTS 64
  30. void ssl_announce(char *dev_name, int dev)
  31. {
  32. printk(KERN_INFO "Serial line %d assigned device '%s'\n", dev,
  33. dev_name);
  34. }
  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);
  43. static int ssl_get_config(char *dev, char *str, int size, char **error_out);
  44. static int ssl_remove(int n);
  45. static struct line_driver driver = {
  46. .name = "UML serial line",
  47. .device_name = "ttyS",
  48. .devfs_name = "tts/",
  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. .symlink_from = "serial",
  58. .symlink_to = "tts",
  59. .mc = {
  60. .name = "ssl",
  61. .config = ssl_config,
  62. .get_config = ssl_get_config,
  63. .id = line_id,
  64. .remove = ssl_remove,
  65. },
  66. };
  67. /* The array is initialized by line_init, which is an initcall. The
  68. * individual elements are protected by individual semaphores.
  69. */
  70. static struct line serial_lines[NR_PORTS] =
  71. { [0 ... NR_PORTS - 1] = LINE_INIT(CONFIG_SSL_CHAN, &driver) };
  72. static struct lines lines = LINES_INIT(NR_PORTS);
  73. static int ssl_config(char *str)
  74. {
  75. return(line_config(serial_lines,
  76. sizeof(serial_lines)/sizeof(serial_lines[0]), str));
  77. }
  78. static int ssl_get_config(char *dev, char *str, int size, char **error_out)
  79. {
  80. return(line_get_config(dev, serial_lines,
  81. sizeof(serial_lines)/sizeof(serial_lines[0]),
  82. str, size, error_out));
  83. }
  84. static int ssl_remove(int n)
  85. {
  86. return line_remove(serial_lines,
  87. sizeof(serial_lines)/sizeof(serial_lines[0]), n);
  88. }
  89. int ssl_open(struct tty_struct *tty, struct file *filp)
  90. {
  91. return line_open(serial_lines, tty, &opts);
  92. }
  93. #if 0
  94. static void ssl_flush_buffer(struct tty_struct *tty)
  95. {
  96. return;
  97. }
  98. static void ssl_throttle(struct tty_struct * tty)
  99. {
  100. printk(KERN_ERR "Someone should implement ssl_throttle\n");
  101. }
  102. static void ssl_unthrottle(struct tty_struct * tty)
  103. {
  104. printk(KERN_ERR "Someone should implement ssl_unthrottle\n");
  105. }
  106. static void ssl_stop(struct tty_struct *tty)
  107. {
  108. printk(KERN_ERR "Someone should implement ssl_stop\n");
  109. }
  110. static void ssl_start(struct tty_struct *tty)
  111. {
  112. printk(KERN_ERR "Someone should implement ssl_start\n");
  113. }
  114. void ssl_hangup(struct tty_struct *tty)
  115. {
  116. }
  117. #endif
  118. static struct tty_operations ssl_ops = {
  119. .open = ssl_open,
  120. .close = line_close,
  121. .write = line_write,
  122. .put_char = line_put_char,
  123. .write_room = line_write_room,
  124. .chars_in_buffer = line_chars_in_buffer,
  125. .flush_buffer = line_flush_buffer,
  126. .flush_chars = line_flush_chars,
  127. .set_termios = line_set_termios,
  128. .ioctl = line_ioctl,
  129. #if 0
  130. .throttle = ssl_throttle,
  131. .unthrottle = ssl_unthrottle,
  132. .stop = ssl_stop,
  133. .start = ssl_start,
  134. .hangup = ssl_hangup,
  135. #endif
  136. };
  137. /* Changed by ssl_init and referenced by ssl_exit, which are both serialized
  138. * by being an initcall and exitcall, respectively.
  139. */
  140. static int ssl_init_done = 0;
  141. static void ssl_console_write(struct console *c, const char *string,
  142. unsigned len)
  143. {
  144. struct line *line = &serial_lines[c->index];
  145. unsigned long flags;
  146. spin_lock_irqsave(&line->lock, flags);
  147. console_write_chan(&line->chan_list, string, len);
  148. spin_unlock_irqrestore(&line->lock, flags);
  149. }
  150. static struct tty_driver *ssl_console_device(struct console *c, int *index)
  151. {
  152. *index = c->index;
  153. return ssl_driver;
  154. }
  155. static int ssl_console_setup(struct console *co, char *options)
  156. {
  157. struct line *line = &serial_lines[co->index];
  158. return console_open_chan(line,co,&opts);
  159. }
  160. static struct console ssl_cons = {
  161. .name = "ttyS",
  162. .write = ssl_console_write,
  163. .device = ssl_console_device,
  164. .setup = ssl_console_setup,
  165. .flags = CON_PRINTBUFFER,
  166. .index = -1,
  167. };
  168. int ssl_init(void)
  169. {
  170. char *new_title;
  171. printk(KERN_INFO "Initializing software serial port version %d\n",
  172. ssl_version);
  173. ssl_driver = line_register_devfs(&lines, &driver, &ssl_ops,
  174. serial_lines, ARRAY_SIZE(serial_lines));
  175. lines_init(serial_lines, sizeof(serial_lines)/sizeof(serial_lines[0]));
  176. new_title = add_xterm_umid(opts.xterm_title);
  177. if (new_title != NULL)
  178. opts.xterm_title = new_title;
  179. ssl_init_done = 1;
  180. register_console(&ssl_cons);
  181. return(0);
  182. }
  183. late_initcall(ssl_init);
  184. static void ssl_exit(void)
  185. {
  186. if (!ssl_init_done)
  187. return;
  188. close_lines(serial_lines,
  189. sizeof(serial_lines)/sizeof(serial_lines[0]));
  190. }
  191. __uml_exitcall(ssl_exit);
  192. static int ssl_chan_setup(char *str)
  193. {
  194. return(line_setup(serial_lines,
  195. sizeof(serial_lines)/sizeof(serial_lines[0]),
  196. str, 1));
  197. }
  198. __setup("ssl", ssl_chan_setup);
  199. __channel_help(ssl_chan_setup, "ssl");