stdio_console.c 4.8 KB

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