Commit 993fbfdb1b1a8d9b3d32ed57afc70a7be1a5e9dc

Authored by Anthony Liguori
1 parent ec6bd8de

Refactor how display drivers are selected

My previous commit, f92f8afe,  broke -vnc (spotted by Glauber Costa).  This
is because it's necessary to tell when the no special display parameters have
been passed and default to SDL or VNC appropriately.

This refactors the display selection logic to be less complicated which has
the effect of fixing the regression mentioned above.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/fw_cfg.c
... ... @@ -277,7 +277,7 @@ void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
277 277 }
278 278 fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
279 279 fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16);
280   - fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)nographic);
  280 + fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC));
281 281 fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
282 282  
283 283 register_savevm("fw_cfg", -1, 1, fw_cfg_save, fw_cfg_load, s);
... ...
hw/sun4m.c
... ... @@ -505,7 +505,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
505 505 slavio_cpu_irq, smp_cpus);
506 506  
507 507 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
508   - nographic, ESCC_CLOCK, 1);
  508 + display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
509 509 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
510 510 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
511 511 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], slavio_irq[hwdef->ser_irq],
... ... @@ -1273,7 +1273,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1273 1273 sbi_cpu_irq, smp_cpus);
1274 1274  
1275 1275 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
1276   - nographic, ESCC_CLOCK, 1);
  1276 + display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
1277 1277 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1278 1278 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1279 1279 escc_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq], sbi_irq[hwdef->ser_irq],
... ... @@ -1476,7 +1476,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1476 1476 hwdef->nvram_size, 2);
1477 1477  
1478 1478 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
1479   - nographic, ESCC_CLOCK, 1);
  1479 + display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
1480 1480 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1481 1481 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1482 1482 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
... ...
qemu-char.c
... ... @@ -571,7 +571,7 @@ static void fd_chr_update_read_handler(CharDriverState *chr)
571 571 FDCharDriver *s = chr->opaque;
572 572  
573 573 if (s->fd_in >= 0) {
574   - if (nographic && s->fd_in == 0) {
  574 + if (display_type == DT_NOGRAPHIC && s->fd_in == 0) {
575 575 } else {
576 576 qemu_set_fd_handler2(s->fd_in, fd_chr_read_poll,
577 577 fd_chr_read, NULL, chr);
... ... @@ -584,7 +584,7 @@ static void fd_chr_close(struct CharDriverState *chr)
584 584 FDCharDriver *s = chr->opaque;
585 585  
586 586 if (s->fd_in >= 0) {
587   - if (nographic && s->fd_in == 0) {
  587 + if (display_type == DT_NOGRAPHIC && s->fd_in == 0) {
588 588 } else {
589 589 qemu_set_fd_handler2(s->fd_in, NULL, NULL, NULL, NULL);
590 590 }
... ... @@ -714,7 +714,7 @@ static void term_init(void)
714 714 tty.c_oflag |= OPOST;
715 715 tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
716 716 /* if graphical mode, we allow Ctrl-C handling */
717   - if (nographic)
  717 + if (display_type == DT_NOGRAPHIC)
718 718 tty.c_lflag &= ~ISIG;
719 719 tty.c_cflag &= ~(CSIZE|PARENB);
720 720 tty.c_cflag |= CS8;
... ...
sysemu.h
... ... @@ -86,6 +86,15 @@ int tap_win32_init(VLANState *vlan, const char *model,
86 86 /* SLIRP */
87 87 void do_info_slirp(Monitor *mon);
88 88  
  89 +typedef enum DisplayType
  90 +{
  91 + DT_DEFAULT,
  92 + DT_CURSES,
  93 + DT_SDL,
  94 + DT_VNC,
  95 + DT_NOGRAPHIC,
  96 +} DisplayType;
  97 +
89 98 extern int bios_size;
90 99 extern int cirrus_vga_enabled;
91 100 extern int std_vga_enabled;
... ... @@ -94,7 +103,7 @@ extern int xenfb_enabled;
94 103 extern int graphic_width;
95 104 extern int graphic_height;
96 105 extern int graphic_depth;
97   -extern int nographic;
  106 +extern DisplayType display_type;
98 107 extern const char *keyboard_layout;
99 108 extern int win2k_install_hack;
100 109 extern int rtc_td_hack;
... ...
... ... @@ -201,9 +201,7 @@ DriveInfo drives_table[MAX_DRIVES+1];
201 201 int nb_drives;
202 202 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
203 203 static DisplayState *display_state;
204   -int nographic;
205   -static int curses;
206   -static int sdl = 1;
  204 +DisplayType display_type = DT_DEFAULT;
207 205 const char* keyboard_layout = NULL;
208 206 int64_t ticks_per_sec;
209 207 ram_addr_t ram_size;
... ... @@ -4842,6 +4840,7 @@ int main(int argc, char **argv, char **envp)
4842 4840 const char *run_as = NULL;
4843 4841 #endif
4844 4842 CPUState *env;
  4843 + int show_vnc_port = 0;
4845 4844  
4846 4845 qemu_cache_utils_init(envp);
4847 4846  
... ... @@ -4882,8 +4881,6 @@ int main(int argc, char **argv, char **envp)
4882 4881 initrd_filename = NULL;
4883 4882 ram_size = 0;
4884 4883 snapshot = 0;
4885   - nographic = 0;
4886   - curses = 0;
4887 4884 kernel_filename = NULL;
4888 4885 kernel_cmdline = "";
4889 4886 cyls = heads = secs = 0;
... ... @@ -5075,11 +5072,11 @@ int main(int argc, char **argv, char **envp)
5075 5072 numa_add(optarg);
5076 5073 break;
5077 5074 case QEMU_OPTION_nographic:
5078   - nographic = 1;
  5075 + display_type = DT_NOGRAPHIC;
5079 5076 break;
5080 5077 #ifdef CONFIG_CURSES
5081 5078 case QEMU_OPTION_curses:
5082   - curses = 1;
  5079 + display_type = DT_CURSES;
5083 5080 break;
5084 5081 #endif
5085 5082 case QEMU_OPTION_portrait:
... ... @@ -5358,7 +5355,7 @@ int main(int argc, char **argv, char **envp)
5358 5355 no_quit = 1;
5359 5356 break;
5360 5357 case QEMU_OPTION_sdl:
5361   - sdl = 1;
  5358 + display_type = DT_SDL;
5362 5359 break;
5363 5360 #endif
5364 5361 case QEMU_OPTION_pidfile:
... ... @@ -5420,6 +5417,7 @@ int main(int argc, char **argv, char **envp)
5420 5417 }
5421 5418 break;
5422 5419 case QEMU_OPTION_vnc:
  5420 + display_type = DT_VNC;
5423 5421 vnc_display = optarg;
5424 5422 break;
5425 5423 #ifdef TARGET_I386
... ... @@ -5578,7 +5576,7 @@ int main(int argc, char **argv, char **envp)
5578 5576 exit(1);
5579 5577 }
5580 5578  
5581   - if (nographic) {
  5579 + if (display_type == DT_NOGRAPHIC) {
5582 5580 if (serial_device_index == 0)
5583 5581 serial_devices[0] = "stdio";
5584 5582 if (parallel_device_index == 0)
... ... @@ -5944,44 +5942,46 @@ int main(int argc, char **argv, char **envp)
5944 5942 dumb_display_init();
5945 5943 /* just use the first displaystate for the moment */
5946 5944 ds = display_state;
5947   - /* terminal init */
5948   - if (nographic) {
5949   - if (curses) {
5950   - fprintf(stderr, "fatal: -nographic can't be used with -curses\n");
5951   - exit(1);
5952   - }
5953   - } else {
  5945 +
  5946 + if (display_type == DT_DEFAULT) {
  5947 +#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
  5948 + display_type = DT_SDL;
  5949 +#else
  5950 + display_type = DT_VNC;
  5951 + vnc_display = "localhost:0,to=99";
  5952 + show_vnc_port = 1;
  5953 +#endif
  5954 + }
  5955 +
  5956 +
  5957 + switch (display_type) {
  5958 + case DT_NOGRAPHIC:
  5959 + break;
5954 5960 #if defined(CONFIG_CURSES)
5955   - if (curses) {
5956   - /* At the moment curses cannot be used with other displays */
5957   - curses_display_init(ds, full_screen);
5958   - } else
  5961 + case DT_CURSES:
  5962 + curses_display_init(ds, full_screen);
  5963 + break;
5959 5964 #endif
5960   -#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
5961   - if (sdl) {
5962 5965 #if defined(CONFIG_SDL)
5963   - sdl_display_init(ds, full_screen, no_frame);
  5966 + case DT_SDL:
  5967 + sdl_display_init(ds, full_screen, no_frame);
  5968 + break;
5964 5969 #elif defined(CONFIG_COCOA)
5965   - cocoa_display_init(ds, full_screen);
5966   -#endif
5967   - } else
  5970 + case DT_SDL:
  5971 + cocoa_display_init(ds, full_screen);
  5972 + break;
5968 5973 #endif
5969   - {
5970   - int print_port = 0;
5971   -
5972   - if (vnc_display == NULL) {
5973   - vnc_display = "localhost:0,to=99";
5974   - print_port = 1;
5975   - }
5976   -
5977   - vnc_display_init(ds);
5978   - if (vnc_display_open(ds, vnc_display) < 0)
5979   - exit(1);
  5974 + case DT_VNC:
  5975 + vnc_display_init(ds);
  5976 + if (vnc_display_open(ds, vnc_display) < 0)
  5977 + exit(1);
5980 5978  
5981   - if (print_port) {
5982   - printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
5983   - }
  5979 + if (show_vnc_port) {
  5980 + printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
5984 5981 }
  5982 + break;
  5983 + default:
  5984 + break;
5985 5985 }
5986 5986 dpy_resize(ds);
5987 5987  
... ... @@ -5994,7 +5994,7 @@ int main(int argc, char **argv, char **envp)
5994 5994 dcl = dcl->next;
5995 5995 }
5996 5996  
5997   - if (nographic || (vnc_display && !sdl)) {
  5997 + if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) {
5998 5998 nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
5999 5999 qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
6000 6000 }
... ...