Commit 2796dae08aad498fa54a131ce23d15b346df85ac

Authored by aliguori
1 parent 5403281a

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
console.c
... ... @@ -1285,17 +1285,17 @@ void console_color_init(DisplayState *ds)
1285 1285 }
1286 1286 }
1287 1287  
1288   -CharDriverState *text_console_init(DisplayState *ds, const char *p)
  1288 +static int n_text_consoles;
  1289 +static CharDriverState *text_consoles[128];
  1290 +static char *text_console_strs[128];
  1291 +
  1292 +static void text_console_do_init(CharDriverState *chr, DisplayState *ds, const char *p)
1289 1293 {
1290   - CharDriverState *chr;
1291 1294 TextConsole *s;
1292 1295 unsigned width;
1293 1296 unsigned height;
1294 1297 static int color_inited;
1295 1298  
1296   - chr = qemu_mallocz(sizeof(CharDriverState));
1297   - if (!chr)
1298   - return NULL;
1299 1299 s = new_console(ds, (p == 0) ? TEXT_CONSOLE : TEXT_CONSOLE_FIXED_SIZE);
1300 1300 if (!s) {
1301 1301 free(chr);
... ... @@ -1352,7 +1352,6 @@ CharDriverState *text_console_init(DisplayState *ds, const char *p)
1352 1352 s->t_attrib_default.unvisible = 0;
1353 1353 s->t_attrib_default.fgcol = COLOR_WHITE;
1354 1354 s->t_attrib_default.bgcol = COLOR_BLACK;
1355   -
1356 1355 /* set current text attributes to default */
1357 1356 s->t_attrib = s->t_attrib_default;
1358 1357 text_console_resize(s);
... ... @@ -1362,6 +1361,37 @@ CharDriverState *text_console_init(DisplayState *ds, const char *p)
1362 1361 return chr;
1363 1362 }
1364 1363  
  1364 +CharDriverState *text_console_init(const char *p)
  1365 +{
  1366 + CharDriverState *chr;
  1367 +
  1368 + chr = qemu_mallocz(sizeof(CharDriverState));
  1369 + if (!chr)
  1370 + return NULL;
  1371 +
  1372 + if (n_text_consoles == 128) {
  1373 + fprintf(stderr, "Too many text consoles\n");
  1374 + exit(1);
  1375 + }
  1376 + text_consoles[n_text_consoles] = chr;
  1377 + text_console_strs[n_text_consoles] = p ? qemu_strdup(p) : NULL;
  1378 + n_text_consoles++;
  1379 +
  1380 + return chr;
  1381 +}
  1382 +
  1383 +void text_consoles_set_display(DisplayState *ds)
  1384 +{
  1385 + int i;
  1386 +
  1387 + for (i = 0; i < n_text_consoles; i++) {
  1388 + text_console_do_init(text_consoles[i], ds, text_console_strs[i]);
  1389 + qemu_free(text_console_strs[i]);
  1390 + }
  1391 +
  1392 + n_text_consoles = 0;
  1393 +}
  1394 +
1365 1395 void qemu_console_resize(DisplayState *ds, int width, int height)
1366 1396 {
1367 1397 TextConsole *s = get_graphic_console();
... ...
console.h
... ... @@ -265,7 +265,8 @@ void vga_hw_text_update(console_ch_t *chardata);
265 265  
266 266 int is_graphic_console(void);
267 267 int is_fixedsize_console(void);
268   -CharDriverState *text_console_init(DisplayState *ds, const char *p);
  268 +CharDriverState *text_console_init(const char *p);
  269 +void text_consoles_set_display(DisplayState *ds);
269 270 void console_select(unsigned int index);
270 271 void console_color_init(DisplayState *ds);
271 272 void qemu_console_resize(DisplayState *ds, int width, int height);
... ...
qemu-char.c
... ... @@ -2128,10 +2128,10 @@ CharDriverState *qemu_chr_open(const char *label, const char *filename)
2128 2128 CharDriverState *chr;
2129 2129  
2130 2130 if (!strcmp(filename, "vc")) {
2131   - chr = text_console_init(get_displaystate(), 0);
  2131 + chr = text_console_init(0);
2132 2132 } else
2133 2133 if (strstart(filename, "vc:", &p)) {
2134   - chr = text_console_init(get_displaystate(), p);
  2134 + chr = text_console_init(p);
2135 2135 } else
2136 2136 if (!strcmp(filename, "null")) {
2137 2137 chr = qemu_chr_open_null();
... ...
... ... @@ -5461,6 +5461,48 @@ int main(int argc, char **argv, char **envp)
5461 5461 }
5462 5462 }
5463 5463  
  5464 + for(i = 0; i < MAX_SERIAL_PORTS; i++) {
  5465 + const char *devname = serial_devices[i];
  5466 + if (devname && strcmp(devname, "none")) {
  5467 + char label[32];
  5468 + snprintf(label, sizeof(label), "serial%d", i);
  5469 + serial_hds[i] = qemu_chr_open(label, devname);
  5470 + if (!serial_hds[i]) {
  5471 + fprintf(stderr, "qemu: could not open serial device '%s'\n",
  5472 + devname);
  5473 + exit(1);
  5474 + }
  5475 + }
  5476 + }
  5477 +
  5478 + for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
  5479 + const char *devname = parallel_devices[i];
  5480 + if (devname && strcmp(devname, "none")) {
  5481 + char label[32];
  5482 + snprintf(label, sizeof(label), "parallel%d", i);
  5483 + parallel_hds[i] = qemu_chr_open(label, devname);
  5484 + if (!parallel_hds[i]) {
  5485 + fprintf(stderr, "qemu: could not open parallel device '%s'\n",
  5486 + devname);
  5487 + exit(1);
  5488 + }
  5489 + }
  5490 + }
  5491 +
  5492 + for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
  5493 + const char *devname = virtio_consoles[i];
  5494 + if (devname && strcmp(devname, "none")) {
  5495 + char label[32];
  5496 + snprintf(label, sizeof(label), "virtcon%d", i);
  5497 + virtcon_hds[i] = qemu_chr_open(label, devname);
  5498 + if (!virtcon_hds[i]) {
  5499 + fprintf(stderr, "qemu: could not open virtio console '%s'\n",
  5500 + devname);
  5501 + exit(1);
  5502 + }
  5503 + }
  5504 + }
  5505 +
5464 5506 machine->init(ram_size, vga_ram_size, boot_devices,
5465 5507 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
5466 5508  
... ... @@ -5529,6 +5571,8 @@ int main(int argc, char **argv, char **envp)
5529 5571 dcl = dcl->next;
5530 5572 }
5531 5573  
  5574 + text_consoles_set_display(display_state);
  5575 +
5532 5576 if (monitor_device) {
5533 5577 monitor_hd = qemu_chr_open("monitor", monitor_device);
5534 5578 if (!monitor_hd) {
... ... @@ -5543,12 +5587,6 @@ int main(int argc, char **argv, char **envp)
5543 5587 if (devname && strcmp(devname, "none")) {
5544 5588 char label[32];
5545 5589 snprintf(label, sizeof(label), "serial%d", i);
5546   - serial_hds[i] = qemu_chr_open(label, devname);
5547   - if (!serial_hds[i]) {
5548   - fprintf(stderr, "qemu: could not open serial device '%s'\n",
5549   - devname);
5550   - exit(1);
5551   - }
5552 5590 if (strstart(devname, "vc", 0))
5553 5591 qemu_chr_printf(serial_hds[i], "serial%d console\r\n", i);
5554 5592 }
... ... @@ -5559,12 +5597,6 @@ int main(int argc, char **argv, char **envp)
5559 5597 if (devname && strcmp(devname, "none")) {
5560 5598 char label[32];
5561 5599 snprintf(label, sizeof(label), "parallel%d", i);
5562   - parallel_hds[i] = qemu_chr_open(label, devname);
5563   - if (!parallel_hds[i]) {
5564   - fprintf(stderr, "qemu: could not open parallel device '%s'\n",
5565   - devname);
5566   - exit(1);
5567   - }
5568 5600 if (strstart(devname, "vc", 0))
5569 5601 qemu_chr_printf(parallel_hds[i], "parallel%d console\r\n", i);
5570 5602 }
... ... @@ -5572,15 +5604,9 @@ int main(int argc, char **argv, char **envp)
5572 5604  
5573 5605 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
5574 5606 const char *devname = virtio_consoles[i];
5575   - if (devname && strcmp(devname, "none")) {
  5607 + if (virtcon_hds[i] && devname) {
5576 5608 char label[32];
5577 5609 snprintf(label, sizeof(label), "virtcon%d", i);
5578   - virtcon_hds[i] = qemu_chr_open(label, devname);
5579   - if (!virtcon_hds[i]) {
5580   - fprintf(stderr, "qemu: could not open virtio console '%s'\n",
5581   - devname);
5582   - exit(1);
5583   - }
5584 5610 if (strstart(devname, "vc", 0))
5585 5611 qemu_chr_printf(virtcon_hds[i], "virtio console%d\r\n", i);
5586 5612 }
... ...