Skip to contentSkip to conversation

[6352] Fix character devices after DisplayState refactoring

Qemu-devel Anthony Liguori 6 participants 8 messages Jan 16, 2009 – Jan 19, 2009

lore
Share & tools
lore
#0 lore raw

Revision: 6352

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6352
Author:   aliguori
Date:     2009-01-16 20:23:27 +0000 (Fri, 16 Jan 2009)

Log Message:
-----------
Fix character devices after DisplayState refactoring

The DisplayState refactoring changed the machine init function to create a DisplayState for each VGA device instead of being passed an existing DisplayState. This change is critical to enable multiple graphics device support.

Unfortunately, the serial/parallel/console code is structured today to run before machine init to fill out the CharDriverState table which the machine init function uses to determine whether to create the required devices.

Since a 'vc' is a type of CharDriverState, the CharDriverState code requires that a DisplayState exist before it runs creating a circular dependency.

To fix this, this splits the creation of the initial CharDriverState from the initialization of the text console. We can then in a second step associate a DisplayState with all TextConsoles. This allows us to create the CharDriverState's first, machine init, then associate the TextConsoles with a DisplayState.

This code screams for more cleanup.

Modified Paths:
--------------
trunk/console.c
trunk/console.h
trunk/qemu-char.c
trunk/vl.c

Modified: trunk/console.c
===================================================================

console.c +36 -6
@@ -1285,17 +1285,17 @@
     }
 }
 
-CharDriverState *text_console_init(DisplayState *ds, const char *p)
+static int n_text_consoles;
+static CharDriverState *text_consoles[128];
+static char *text_console_strs[128];
+
+static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const char *p)
 {
-    CharDriverState *chr;
     TextConsole *s;
     unsigned width;
     unsigned height;
     static int color_inited;
 
-    chr = qemu_mallocz(sizeof(CharDriverState));
-    if (!chr)
-        return NULL;
     s = new_console(ds, (p == 0) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
     if (!s) {
         free(chr);
@@ -1352,7 +1352,6 @@
     s->t_attrib_default.unvisible = 0;
     s->t_attrib_default.fgcol = COLOR_WHITE;
     s->t_attrib_default.bgcol = COLOR_BLACK;
-
     /* set current text attributes to default */
     s->t_attrib = s->t_attrib_default;
     text_console_resize(s);
@@ -1362,6 +1361,37 @@
     return chr;
 }
 
+CharDriverState *text_console_init(const char *p)
+{
+    CharDriverState *chr;
+
+    chr = qemu_mallocz(sizeof(CharDriverState));
+    if (!chr)
+        return NULL;
+
+    if (n_text_consoles == 128) {
+        fprintf(stderr, "Too many text consoles\n");
+        exit(1);
+    }
+    text_consoles[n_text_consoles] = chr;
+    text_console_strs[n_text_consoles] = p ? qemu_strdup(p) : NULL;
+    n_text_consoles++;
+
+    return chr;
+}
+
+void text_consoles_set_display(DisplayState *ds)
+{
+    int i;
+
+    for (i = 0; i < n_text_consoles; i++) {
+        text_console_do_init(text_consoles[i], ds, text_console_strs[i]);
+        qemu_free(text_console_strs[i]);
+    }
+
+    n_text_consoles = 0;
+}
+
 void qemu_console_resize(DisplayState *ds, int width, int height)
 {
     TextConsole *s = get_graphic_console();

Modified: trunk/console.h
===================================================================

console.h +2 -1
@@ -265,7 +265,8 @@
 
 int is_graphic_console(void);
 int is_fixedsize_console(void);
-CharDriverState *text_console_init(DisplayState *ds, const char *p);
+CharDriverState *text_console_init(const char *p);
+void text_consoles_set_display(DisplayState *ds);
 void console_select(unsigned int index);
 void console_color_init(DisplayState *ds);
 void qemu_console_resize(DisplayState *ds, int width, int height);

Modified: trunk/qemu-char.c
===================================================================

qemu-char.c +2 -2
@@ -2128,10 +2128,10 @@
     CharDriverState *chr;
 
     if (!strcmp(filename, "vc")) {
-        chr = text_console_init(get_displaystate(), 0);
+        chr = text_console_init(0);
     } else
     if (strstart(filename, "vc:", &p)) {
-        chr = text_console_init(get_displaystate(), p);
+        chr = text_console_init(p);
     } else
     if (!strcmp(filename, "null")) {
         chr = qemu_chr_open_null();

Modified: trunk/vl.c
===================================================================

vl.c +45 -19

96 lines not on this page · raw message

#1 lore raw
Quoted 21 lines · Anthony Liguori

Revision: 6352

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6352
Author:   aliguori
Date:     2009-01-16 20:23:27 +0000 (Fri, 16 Jan 2009)

Log Message:
-----------
Fix character devices after DisplayState refactoring

The DisplayState refactoring changed the machine init function to create a DisplayState for each VGA device instead of being passed an existing DisplayState. This change is critical to enable multiple graphics device support.

Unfortunately, the serial/parallel/console code is structured today to run before machine init to fill out the CharDriverState table which the machine init function uses to determine whether to create the required devices.

Since a 'vc' is a type of CharDriverState, the CharDriverState code requires that a DisplayState exist before it runs creating a circular dependency.

Quoted 7 lines

To fix this, this splits the creation of the initial CharDriverState from the initialization of the text console. We can then in a second step associate a DisplayState with all TextConsoles. This allows us to create the CharDriverState's first, machine init, then associate the TextConsoles with a DisplayState.

This code screams for more cleanup.

...and a fix to make the monitor show up on the second vc again. Any immediate idea what went wrong?

Jan

#2 lore raw
Quoted 29 lines · Jan Kiszka
Quoted 27 lines · Anthony Liguori

Revision: 6352

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6352
Author:   aliguori
Date:     2009-01-16 20:23:27 +0000 (Fri, 16 Jan 2009)

Log Message:
-----------
Fix character devices after DisplayState refactoring

The DisplayState refactoring changed the machine init function to create a DisplayState for each VGA device instead of being passed an existing DisplayState. This change is critical to enable multiple graphics device support.

Unfortunately, the serial/parallel/console code is structured today to run before machine init to fill out the CharDriverState table which the machine init function uses to determine whether to create the required devices.

Since a 'vc' is a type of CharDriverState, the CharDriverState code requires that a DisplayState exist before it runs creating a circular dependency.

To fix this, this splits the creation of the initial CharDriverState from the initialization of the text console. We can then in a second step associate a DisplayState with all TextConsoles. This allows us to create the CharDriverState's first, machine init, then associate the TextConsoles with a DisplayState.

Quoted 4 lines
Quoted 2 lines

This code screams for more cleanup.

...and a fix to make the monitor show up on the second vc again.

Just got that one.

Quoted 2 lines

Any immediate idea what went wrong?

Not enough testing.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#3 lore raw
In reply to Anthony Liguori
Quoted 3 lines · Anthony Liguori

Log Message:
-----------
Fix character devices after DisplayState refactoring

FWIW, I've noticed that malta_fpga_init segfaults when calling qemu_chr_printf() right after calling qemu_chr_open().

Cheers,

Signature · 1 line
Stuart Brady
#4 lore raw
In reply to Anthony Liguori
Quoted 31 lines · Anthony Liguori

Revision: 6352
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6352
Author: aliguori
Date: 2009-01-16 20:23:27 +0000 (Fri, 16 Jan 2009)

Log Message:
-----------
Fix character devices after DisplayState refactoring

The DisplayState refactoring changed the machine init function to create a DisplayState for each VGA device instead of being passed an existing DisplayState. This change is critical to enable multiple graphics device support.

Unfortunately, the serial/parallel/console code is structured today to run before machine init to fill out the CharDriverState table which the machine
init function uses to determine whether to create the required devices.

Since a 'vc' is a type of CharDriverState, the CharDriverState code requires
that a DisplayState exist before it runs creating a circular dependency.

To fix this, this splits the creation of the initial CharDriverState from the initialization of the text console. We can then in a second step associate
a DisplayState with all TextConsoles. This allows us to create the CharDriverState's first, machine init, then associate the TextConsoles with
a DisplayState.

Quoted 1 line

This code screams for more cleanup.

Yes, it screams for more cleanups.

MIPS Malta also no longer works, same reason as for the serial code:

Malta creates a character device during machine init and writes some characters to it.
This is now impossible because qemu_chr_printf can no longer be called before text_consoles_set_display was called.

Regards
Stefan Weil

#5 lore raw
Quoted 34 lines · Stefan Weil
Quoted 31 lines · Anthony Liguori

Revision: 6352
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6352
Author: aliguori
Date: 2009-01-16 20:23:27 +0000 (Fri, 16 Jan 2009)

Log Message:
-----------
Fix character devices after DisplayState refactoring

The DisplayState refactoring changed the machine init function to create a DisplayState for each VGA device instead of being passed an existing DisplayState. This change is critical to enable multiple graphics device support.

Unfortunately, the serial/parallel/console code is structured today to run before machine init to fill out the CharDriverState table which the machine
init function uses to determine whether to create the required devices.

Since a 'vc' is a type of CharDriverState, the CharDriverState code requires
that a DisplayState exist before it runs creating a circular dependency.

To fix this, this splits the creation of the initial CharDriverState from the initialization of the text console. We can then in a second step associate
a DisplayState with all TextConsoles. This allows us to create the CharDriverState's first, machine init, then associate the TextConsoles with
a DisplayState.

Quoted 1 line

This code screams for more cleanup.

Quoted 9 lines

Yes, it screams for more cleanups.

MIPS Malta also no longer works, same reason as for the serial code:

Malta creates a character device during machine init and writes some characters to it.
This is now impossible because qemu_chr_printf can no longer be called before text_consoles_set_display was called.

I have committed a fix in revision 6365. It is a bit ugly, don't hesistate to commit a better fix.

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net
#6 lore raw
In reply to Anthony Liguori
Quoted 21 lines · Anthony Liguori

Revision: 6352

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6352
Author:   aliguori
Date:     2009-01-16 20:23:27 +0000 (Fri, 16 Jan 2009)

Log Message:
-----------
Fix character devices after DisplayState refactoring

The DisplayState refactoring changed the machine init function to create a DisplayState for each VGA device instead of being passed an existing DisplayState. This change is critical to enable multiple graphics device support.

Unfortunately, the serial/parallel/console code is structured today to run before machine init to fill out the CharDriverState table which the machine init function uses to determine whether to create the required devices.

Since a 'vc' is a type of CharDriverState, the CharDriverState code requires that a DisplayState exist before it runs creating a circular dependency.

Quoted 8 lines

To fix this, this splits the creation of the initial CharDriverState from the initialization of the text console. We can then in a second step associate a DisplayState with all TextConsoles. This allows us to create the CharDriverState's first, machine init, then associate the TextConsoles with a DisplayState.

This code screams for more cleanup.

I am sorry for this.

While I was testing the patch series I was expecting many rendering issues or console switching issues: once I saw that both the serial and parallel port consoles were present I didn't check they were actually working.

#7 lore raw
Quoted 30 lines · Stefano Stabellini
Quoted 27 lines · Anthony Liguori

Revision: 6352

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6352
Author:   aliguori
Date:     2009-01-16 20:23:27 +0000 (Fri, 16 Jan 2009)

Log Message:
-----------
Fix character devices after DisplayState refactoring

The DisplayState refactoring changed the machine init function to create a DisplayState for each VGA device instead of being passed an existing DisplayState. This change is critical to enable multiple graphics device support.

Unfortunately, the serial/parallel/console code is structured today to run before machine init to fill out the CharDriverState table which the machine init function uses to determine whether to create the required devices.

Since a 'vc' is a type of CharDriverState, the CharDriverState code requires that a DisplayState exist before it runs creating a circular dependency.

To fix this, this splits the creation of the initial CharDriverState from the initialization of the text console. We can then in a second step associate a DisplayState with all TextConsoles. This allows us to create the CharDriverState's first, machine init, then associate the TextConsoles with a DisplayState.

Quoted 6 lines
Quoted 3 lines

This code screams for more cleanup.

I am sorry for this.

No worries. What I meant about more cleanup was that this patch series demonstrated a fundamental flaw in the CharDriverState abstraction. That is, we really ought to separate the creation of a CharDriverState front-end from the creation of the back-end.

We should then attach a front-end to a back-end. This would make it easy to dynamically change the back-end of any given CharDriverState which is something I've liked to see for a while now.

Regards,

Anthony Liguori

Quoted 8 lines

While I was testing the patch series I was expecting many rendering issues or console switching issues: once I saw that both the serial and parallel port consoles were present I didn't check they were actually working.