um: switch line.c tty drivers to dynamic device creation
[firefly-linux-kernel-4.4.55.git] / arch / um / drivers / stdio_console.c
index 088776f01908e2eb5a27281cbac37b5927012881..32bd040138f090ec15341846fd58192d2cf4ab6e 100644 (file)
 
 #define MAX_TTYS (16)
 
-/* Referenced only by tty_driver below - presumably it's locked correctly
- * by the tty driver.
- */
-
-static struct tty_driver *console_driver;
-
 static void stdio_announce(char *dev_name, int dev)
 {
        printk(KERN_INFO "Virtual console %d assigned device '%s'\n", dev,
@@ -76,9 +70,9 @@ static struct line_driver driver = {
 /* The array is initialized by line_init, at initcall time.  The
  * elements are locked individually as needed.
  */
-static struct line vts[MAX_TTYS] = { LINE_INIT(CONFIG_CON_ZERO_CHAN, &driver),
-                                    [ 1 ... MAX_TTYS - 1 ] =
-                                    LINE_INIT(CONFIG_CON_CHAN, &driver) };
+static char *vt_conf[MAX_TTYS];
+static char *def_conf;
+static struct line vts[MAX_TTYS];
 
 static int con_config(char *str, char **error_out)
 {
@@ -137,7 +131,7 @@ static void uml_console_write(struct console *console, const char *string,
 static struct tty_driver *uml_console_device(struct console *c, int *index)
 {
        *index = c->index;
-       return console_driver;
+       return driver.driver;
 }
 
 static int uml_console_setup(struct console *co, char *options)
@@ -160,11 +154,25 @@ static struct console stdiocons = {
 static int stdio_init(void)
 {
        char *new_title;
-
-       console_driver = register_lines(&driver, &console_ops, vts,
+       int err;
+       int i;
+
+       for (i = 0; i < MAX_TTYS; i++) {
+               char *s = vt_conf[i];
+               if (!s)
+                       s = def_conf;
+               if (!s)
+                       s = i ? CONFIG_CON_CHAN : CONFIG_CON_ZERO_CHAN;
+               if (s && strcmp(s, "none") != 0)
+                       vts[i].init_str = s;
+               spin_lock_init(&vts[i].lock);
+               mutex_init(&vts[i].count_lock);
+               vts[i].driver = &driver;
+       }
+       err = register_lines(&driver, &console_ops, vts,
                                        ARRAY_SIZE(vts));
-       if (console_driver == NULL)
-               return -1;
+       if (err)
+               return err;
        printk(KERN_INFO "Initialized stdio console driver\n");
 
        new_title = add_xterm_umid(opts.xterm_title);
@@ -189,14 +197,7 @@ __uml_exitcall(console_exit);
 
 static int console_chan_setup(char *str)
 {
-       char *error;
-       int ret;
-
-       ret = line_setup(vts, ARRAY_SIZE(vts), str, &error);
-       if(ret < 0)
-               printk(KERN_ERR "Failed to set up console with "
-                      "configuration string \"%s\" : %s\n", str, error);
-
+       line_setup(vt_conf, MAX_TTYS, &def_conf, str, "console");
        return 1;
 }
 __setup("con", console_chan_setup);