aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-16 20:23:27 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-01-16 20:23:27 +0000
commit2796dae08aad498fa54a131ce23d15b346df85ac (patch)
tree5d3eb2885b20f7b94732af7fcd709112b842629e
parent5403281aeb49acd985de45a585162abf749497dd (diff)
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. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6352 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--console.c42
-rw-r--r--console.h3
-rw-r--r--qemu-char.c4
-rw-r--r--vl.c64
4 files changed, 85 insertions, 28 deletions
diff --git a/console.c b/console.c
index 3950d20064..f69fd1b098 100644
--- a/console.c
+++ b/console.c
@@ -1285,17 +1285,17 @@ void console_color_init(DisplayState *ds)
}
}
-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 @@ CharDriverState *text_console_init(DisplayState *ds, const char *p)
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 @@ CharDriverState *text_console_init(DisplayState *ds, const char *p)
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();
diff --git a/console.h b/console.h
index 3ac0afac3f..383ea1a396 100644
--- a/console.h
+++ b/console.h
@@ -265,7 +265,8 @@ void vga_hw_text_update(console_ch_t *chardata);
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);
diff --git a/qemu-char.c b/qemu-char.c
index 1e2fda5659..02d4049d0c 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2128,10 +2128,10 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename)
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();
diff --git a/vl.c b/vl.c
index ae2d127717..9470bcef73 100644
--- a/vl.c
+++ b/vl.c
@@ -5461,6 +5461,48 @@ int main(int argc, char **argv, char **envp)
}
}
+ for(i = 0; i < MAX_SERIAL_PORTS; i++) {
+ const char *devname = serial_devices[i];
+ if (devname && strcmp(devname, "none")) {
+ char label[32];
+ snprintf(label, sizeof(label), "serial%d", i);
+ serial_hds[i] = qemu_chr_open(label, devname);
+ if (!serial_hds[i]) {
+ fprintf(stderr, "qemu: could not open serial device '%s'\n",
+ devname);
+ exit(1);
+ }
+ }
+ }
+
+ for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
+ const char *devname = parallel_devices[i];
+ if (devname && strcmp(devname, "none")) {
+ char label[32];
+ snprintf(label, sizeof(label), "parallel%d", i);
+ parallel_hds[i] = qemu_chr_open(label, devname);
+ if (!parallel_hds[i]) {
+ fprintf(stderr, "qemu: could not open parallel device '%s'\n",
+ devname);
+ exit(1);
+ }
+ }
+ }
+
+ for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
+ const char *devname = virtio_consoles[i];
+ if (devname && strcmp(devname, "none")) {
+ char label[32];
+ snprintf(label, sizeof(label), "virtcon%d", i);
+ virtcon_hds[i] = qemu_chr_open(label, devname);
+ if (!virtcon_hds[i]) {
+ fprintf(stderr, "qemu: could not open virtio console '%s'\n",
+ devname);
+ exit(1);
+ }
+ }
+ }
+
machine->init(ram_size, vga_ram_size, boot_devices,
kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
@@ -5529,6 +5571,8 @@ int main(int argc, char **argv, char **envp)
dcl = dcl->next;
}
+ text_consoles_set_display(display_state);
+
if (monitor_device) {
monitor_hd = qemu_chr_open("monitor", monitor_device);
if (!monitor_hd) {
@@ -5543,12 +5587,6 @@ int main(int argc, char **argv, char **envp)
if (devname && strcmp(devname, "none")) {
char label[32];
snprintf(label, sizeof(label), "serial%d", i);
- serial_hds[i] = qemu_chr_open(label, devname);
- if (!serial_hds[i]) {
- fprintf(stderr, "qemu: could not open serial device '%s'\n",
- devname);
- exit(1);
- }
if (strstart(devname, "vc", 0))
qemu_chr_printf(serial_hds[i], "serial%d console\r\n", i);
}
@@ -5559,12 +5597,6 @@ int main(int argc, char **argv, char **envp)
if (devname && strcmp(devname, "none")) {
char label[32];
snprintf(label, sizeof(label), "parallel%d", i);
- parallel_hds[i] = qemu_chr_open(label, devname);
- if (!parallel_hds[i]) {
- fprintf(stderr, "qemu: could not open parallel device '%s'\n",
- devname);
- exit(1);
- }
if (strstart(devname, "vc", 0))
qemu_chr_printf(parallel_hds[i], "parallel%d console\r\n", i);
}
@@ -5572,15 +5604,9 @@ int main(int argc, char **argv, char **envp)
for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
const char *devname = virtio_consoles[i];
- if (devname && strcmp(devname, "none")) {
+ if (virtcon_hds[i] && devname) {
char label[32];
snprintf(label, sizeof(label), "virtcon%d", i);
- virtcon_hds[i] = qemu_chr_open(label, devname);
- if (!virtcon_hds[i]) {
- fprintf(stderr, "qemu: could not open virtio console '%s'\n",
- devname);
- exit(1);
- }
if (strstart(devname, "vc", 0))
qemu_chr_printf(virtcon_hds[i], "virtio console%d\r\n", i);
}