stdio_console.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/config.h"
  6. #include "linux/posix_types.h"
  7. #include "linux/tty.h"
  8. #include "linux/tty_flip.h"
  9. #include "linux/types.h"
  10. #include "linux/major.h"
  11. #include "linux/kdev_t.h"
  12. #include "linux/console.h"
  13. #include "linux/string.h"
  14. #include "linux/sched.h"
  15. #include "linux/list.h"
  16. #include "linux/init.h"
  17. #include "linux/interrupt.h"
  18. #include "linux/slab.h"
  19. #include "linux/hardirq.h"
  20. #include "asm/current.h"
  21. #include "asm/irq.h"
  22. #include "stdio_console.h"
  23. #include "line.h"
  24. #include "chan_kern.h"
  25. #include "user_util.h"
  26. #include "kern_util.h"
  27. #include "irq_user.h"
  28. #include "mconsole_kern.h"
  29. #include "init.h"
  30. #define MAX_TTYS (16)
  31. /* ----------------------------------------------------------------------------- */
  32. /* Referenced only by tty_driver below - presumably it's locked correctly
  33. * by the tty driver.
  34. */
  35. static struct tty_driver *console_driver;
  36. void stdio_announce(char *dev_name, int dev)
  37. {
  38. printk(KERN_INFO "Virtual console %d assigned device '%s'\n", dev,
  39. dev_name);
  40. }
  41. static struct chan_opts opts = {
  42. .announce = stdio_announce,
  43. .xterm_title = "Virtual Console #%d",
  44. .raw = 1,
  45. .tramp_stack = 0,
  46. .in_kernel = 1,
  47. };
  48. static int con_config(char *str);
  49. static int con_get_config(char *dev, char *str, int size, char **error_out);
  50. static int con_remove(int n);
  51. static struct line_driver driver = {
  52. .name = "UML console",
  53. .device_name = "tty",
  54. .devfs_name = "vc/",
  55. .major = TTY_MAJOR,
  56. .minor_start = 0,
  57. .type = TTY_DRIVER_TYPE_CONSOLE,
  58. .subtype = SYSTEM_TYPE_CONSOLE,
  59. .read_irq = CONSOLE_IRQ,
  60. .read_irq_name = "console",
  61. .write_irq = CONSOLE_WRITE_IRQ,
  62. .write_irq_name = "console-write",
  63. .symlink_from = "ttys",
  64. .symlink_to = "vc",
  65. .mc = {
  66. .name = "con",
  67. .config = con_config,
  68. .get_config = con_get_config,
  69. .id = line_id,
  70. .remove = con_remove,
  71. },
  72. };
  73. static struct lines console_lines = LINES_INIT(MAX_TTYS);
  74. /* The array is initialized by line_init, which is an initcall. The
  75. * individual elements are protected by individual semaphores.
  76. */
  77. struct line vts[MAX_TTYS] = { LINE_INIT(CONFIG_CON_ZERO_CHAN, &driver),
  78. [ 1 ... MAX_TTYS - 1 ] =
  79. LINE_INIT(CONFIG_CON_CHAN, &driver) };
  80. static int con_config(char *str)
  81. {
  82. return line_config(vts, ARRAY_SIZE(vts), str, &opts);
  83. }
  84. static int con_get_config(char *dev, char *str, int size, char **error_out)
  85. {
  86. return line_get_config(dev, vts, ARRAY_SIZE(vts), str, size, error_out);
  87. }
  88. static int con_remove(int n)
  89. {
  90. return line_remove(vts, ARRAY_SIZE(vts), n);
  91. }
  92. static int con_open(struct tty_struct *tty, struct file *filp)
  93. {
  94. return line_open(vts, tty);
  95. }
  96. static int con_init_done = 0;
  97. static struct tty_operations console_ops = {
  98. .open = con_open,
  99. .close = line_close,
  100. .write = line_write,
  101. .put_char = line_put_char,
  102. .write_room = line_write_room,
  103. .chars_in_buffer = line_chars_in_buffer,
  104. .flush_buffer = line_flush_buffer,
  105. .flush_chars = line_flush_chars,
  106. .set_termios = line_set_termios,
  107. .ioctl = line_ioctl,
  108. .throttle = line_throttle,
  109. .unthrottle = line_unthrottle,
  110. };
  111. static void uml_console_write(struct console *console, const char *string,
  112. unsigned len)
  113. {
  114. struct line *line = &vts[console->index];
  115. unsigned long flags;
  116. spin_lock_irqsave(&line->lock, flags);
  117. console_write_chan(&line->chan_list, string, len);
  118. spin_unlock_irqrestore(&line->lock, flags);
  119. }
  120. static struct tty_driver *uml_console_device(struct console *c, int *index)
  121. {
  122. *index = c->index;
  123. return console_driver;
  124. }
  125. static int uml_console_setup(struct console *co, char *options)
  126. {
  127. struct line *line = &vts[co->index];
  128. return console_open_chan(line, co, &opts);
  129. }
  130. static struct console stdiocons = {
  131. .name = "tty",
  132. .write = uml_console_write,
  133. .device = uml_console_device,
  134. .setup = uml_console_setup,
  135. .flags = CON_PRINTBUFFER,
  136. .index = -1,
  137. .data = &vts,
  138. };
  139. int stdio_init(void)
  140. {
  141. char *new_title;
  142. console_driver = line_register_devfs(&console_lines, &driver,
  143. &console_ops, vts,
  144. ARRAY_SIZE(vts));
  145. if (console_driver == NULL)
  146. return -1;
  147. printk(KERN_INFO "Initialized stdio console driver\n");
  148. lines_init(vts, ARRAY_SIZE(vts), &opts);
  149. new_title = add_xterm_umid(opts.xterm_title);
  150. if(new_title != NULL)
  151. opts.xterm_title = new_title;
  152. con_init_done = 1;
  153. register_console(&stdiocons);
  154. return 0;
  155. }
  156. late_initcall(stdio_init);
  157. static void console_exit(void)
  158. {
  159. if (!con_init_done)
  160. return;
  161. close_lines(vts, ARRAY_SIZE(vts));
  162. }
  163. __uml_exitcall(console_exit);
  164. static int console_chan_setup(char *str)
  165. {
  166. return line_setup(vts, ARRAY_SIZE(vts), str);
  167. }
  168. __setup("con", console_chan_setup);
  169. __channel_help(console_chan_setup, "con");