stdio_console.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. .ioctl = line_ioctl,
  101. .throttle = line_throttle,
  102. .unthrottle = line_unthrottle,
  103. };
  104. static void uml_console_write(struct console *console, const char *string,
  105. unsigned len)
  106. {
  107. struct line *line = &vts[console->index];
  108. unsigned long flags;
  109. spin_lock_irqsave(&line->lock, flags);
  110. console_write_chan(line->chan_out, string, len);
  111. spin_unlock_irqrestore(&line->lock, flags);
  112. }
  113. static struct tty_driver *uml_console_device(struct console *c, int *index)
  114. {
  115. *index = c->index;
  116. return driver.driver;
  117. }
  118. static int uml_console_setup(struct console *co, char *options)
  119. {
  120. struct line *line = &vts[co->index];
  121. return console_open_chan(line, co);
  122. }
  123. /* No locking for register_console call - relies on single-threaded initcalls */
  124. static struct console stdiocons = {
  125. .name = "tty",
  126. .write = uml_console_write,
  127. .device = uml_console_device,
  128. .setup = uml_console_setup,
  129. .flags = CON_PRINTBUFFER|CON_ANYTIME,
  130. .index = -1,
  131. };
  132. static int stdio_init(void)
  133. {
  134. char *new_title;
  135. int err;
  136. int i;
  137. err = register_lines(&driver, &console_ops, vts,
  138. ARRAY_SIZE(vts));
  139. if (err)
  140. return err;
  141. printk(KERN_INFO "Initialized stdio console driver\n");
  142. new_title = add_xterm_umid(opts.xterm_title);
  143. if(new_title != NULL)
  144. opts.xterm_title = new_title;
  145. for (i = 0; i < MAX_TTYS; i++) {
  146. char *error;
  147. char *s = vt_conf[i];
  148. if (!s)
  149. s = def_conf;
  150. if (!s)
  151. s = i ? CONFIG_CON_CHAN : CONFIG_CON_ZERO_CHAN;
  152. if (setup_one_line(vts, i, s, &opts, &error))
  153. printk(KERN_ERR "setup_one_line failed for "
  154. "device %d : %s\n", i, error);
  155. }
  156. con_init_done = 1;
  157. register_console(&stdiocons);
  158. return 0;
  159. }
  160. late_initcall(stdio_init);
  161. static void console_exit(void)
  162. {
  163. if (!con_init_done)
  164. return;
  165. close_lines(vts, ARRAY_SIZE(vts));
  166. }
  167. __uml_exitcall(console_exit);
  168. static int console_chan_setup(char *str)
  169. {
  170. line_setup(vt_conf, MAX_TTYS, &def_conf, str, "console");
  171. return 1;
  172. }
  173. __setup("con", console_chan_setup);
  174. __channel_help(console_chan_setup, "con");