stdio_console.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /* Set in an initcall, checked in an exitcall */
  81. static int con_init_done = 0;
  82. static int con_install(struct tty_driver *driver, struct tty_struct *tty)
  83. {
  84. return line_install(driver, tty, &vts[tty->index]);
  85. }
  86. static const struct tty_operations console_ops = {
  87. .open = line_open,
  88. .install = con_install,
  89. .close = line_close,
  90. .write = line_write,
  91. .put_char = line_put_char,
  92. .write_room = line_write_room,
  93. .chars_in_buffer = line_chars_in_buffer,
  94. .flush_buffer = line_flush_buffer,
  95. .flush_chars = line_flush_chars,
  96. .set_termios = line_set_termios,
  97. .throttle = line_throttle,
  98. .unthrottle = line_unthrottle,
  99. .hangup = line_hangup,
  100. };
  101. static void uml_console_write(struct console *console, const char *string,
  102. unsigned len)
  103. {
  104. struct line *line = &vts[console->index];
  105. unsigned long flags;
  106. spin_lock_irqsave(&line->lock, flags);
  107. console_write_chan(line->chan_out, string, len);
  108. spin_unlock_irqrestore(&line->lock, flags);
  109. }
  110. static struct tty_driver *uml_console_device(struct console *c, int *index)
  111. {
  112. *index = c->index;
  113. return driver.driver;
  114. }
  115. static int uml_console_setup(struct console *co, char *options)
  116. {
  117. struct line *line = &vts[co->index];
  118. return console_open_chan(line, co);
  119. }
  120. /* No locking for register_console call - relies on single-threaded initcalls */
  121. static struct console stdiocons = {
  122. .name = "tty",
  123. .write = uml_console_write,
  124. .device = uml_console_device,
  125. .setup = uml_console_setup,
  126. .flags = CON_PRINTBUFFER|CON_ANYTIME,
  127. .index = -1,
  128. };
  129. static int stdio_init(void)
  130. {
  131. char *new_title;
  132. int err;
  133. int i;
  134. err = register_lines(&driver, &console_ops, vts,
  135. ARRAY_SIZE(vts));
  136. if (err)
  137. return err;
  138. printk(KERN_INFO "Initialized stdio console driver\n");
  139. new_title = add_xterm_umid(opts.xterm_title);
  140. if(new_title != NULL)
  141. opts.xterm_title = new_title;
  142. for (i = 0; i < MAX_TTYS; i++) {
  143. char *error;
  144. char *s = vt_conf[i];
  145. if (!s)
  146. s = def_conf;
  147. if (!s)
  148. s = i ? CONFIG_CON_CHAN : CONFIG_CON_ZERO_CHAN;
  149. if (setup_one_line(vts, i, s, &opts, &error))
  150. printk(KERN_ERR "setup_one_line failed for "
  151. "device %d : %s\n", i, error);
  152. }
  153. con_init_done = 1;
  154. register_console(&stdiocons);
  155. return 0;
  156. }
  157. late_initcall(stdio_init);
  158. static void console_exit(void)
  159. {
  160. if (!con_init_done)
  161. return;
  162. close_lines(vts, ARRAY_SIZE(vts));
  163. }
  164. __uml_exitcall(console_exit);
  165. static int console_chan_setup(char *str)
  166. {
  167. line_setup(vt_conf, MAX_TTYS, &def_conf, str, "console");
  168. return 1;
  169. }
  170. __setup("con", console_chan_setup);
  171. __channel_help(console_chan_setup, "con");