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,7 +277,7 @@ void *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
277 } 277 }
278 fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4); 278 fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (uint8_t *)"QEMU", 4);
279 fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16); 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 fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); 281 fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
282 282
283 register_savevm("fw_cfg", -1, 1, fw_cfg_save, fw_cfg_load, s); 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,7 +505,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
505 slavio_cpu_irq, smp_cpus); 505 slavio_cpu_irq, smp_cpus);
506 506
507 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq], 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 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device 509 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
510 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device 510 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
511 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], slavio_irq[hwdef->ser_irq], 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,7 +1273,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1273 sbi_cpu_irq, smp_cpus); 1273 sbi_cpu_irq, smp_cpus);
1274 1274
1275 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq], 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 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device 1277 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1278 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device 1278 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1279 escc_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq], sbi_irq[hwdef->ser_irq], 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,7 +1476,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1476 hwdef->nvram_size, 2); 1476 hwdef->nvram_size, 2);
1477 1477
1478 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq], 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 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device 1480 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1481 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device 1481 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1482 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], 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,7 +571,7 @@ static void fd_chr_update_read_handler(CharDriverState *chr)
571 FDCharDriver *s = chr->opaque; 571 FDCharDriver *s = chr->opaque;
572 572
573 if (s->fd_in >= 0) { 573 if (s->fd_in >= 0) {
574 - if (nographic && s->fd_in == 0) { 574 + if (display_type == DT_NOGRAPHIC && s->fd_in == 0) {
575 } else { 575 } else {
576 qemu_set_fd_handler2(s->fd_in, fd_chr_read_poll, 576 qemu_set_fd_handler2(s->fd_in, fd_chr_read_poll,
577 fd_chr_read, NULL, chr); 577 fd_chr_read, NULL, chr);
@@ -584,7 +584,7 @@ static void fd_chr_close(struct CharDriverState *chr) @@ -584,7 +584,7 @@ static void fd_chr_close(struct CharDriverState *chr)
584 FDCharDriver *s = chr->opaque; 584 FDCharDriver *s = chr->opaque;
585 585
586 if (s->fd_in >= 0) { 586 if (s->fd_in >= 0) {
587 - if (nographic && s->fd_in == 0) { 587 + if (display_type == DT_NOGRAPHIC && s->fd_in == 0) {
588 } else { 588 } else {
589 qemu_set_fd_handler2(s->fd_in, NULL, NULL, NULL, NULL); 589 qemu_set_fd_handler2(s->fd_in, NULL, NULL, NULL, NULL);
590 } 590 }
@@ -714,7 +714,7 @@ static void term_init(void) @@ -714,7 +714,7 @@ static void term_init(void)
714 tty.c_oflag |= OPOST; 714 tty.c_oflag |= OPOST;
715 tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN); 715 tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
716 /* if graphical mode, we allow Ctrl-C handling */ 716 /* if graphical mode, we allow Ctrl-C handling */
717 - if (nographic) 717 + if (display_type == DT_NOGRAPHIC)
718 tty.c_lflag &= ~ISIG; 718 tty.c_lflag &= ~ISIG;
719 tty.c_cflag &= ~(CSIZE|PARENB); 719 tty.c_cflag &= ~(CSIZE|PARENB);
720 tty.c_cflag |= CS8; 720 tty.c_cflag |= CS8;
sysemu.h
@@ -86,6 +86,15 @@ int tap_win32_init(VLANState *vlan, const char *model, @@ -86,6 +86,15 @@ int tap_win32_init(VLANState *vlan, const char *model,
86 /* SLIRP */ 86 /* SLIRP */
87 void do_info_slirp(Monitor *mon); 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 extern int bios_size; 98 extern int bios_size;
90 extern int cirrus_vga_enabled; 99 extern int cirrus_vga_enabled;
91 extern int std_vga_enabled; 100 extern int std_vga_enabled;
@@ -94,7 +103,7 @@ extern int xenfb_enabled; @@ -94,7 +103,7 @@ extern int xenfb_enabled;
94 extern int graphic_width; 103 extern int graphic_width;
95 extern int graphic_height; 104 extern int graphic_height;
96 extern int graphic_depth; 105 extern int graphic_depth;
97 -extern int nographic; 106 +extern DisplayType display_type;
98 extern const char *keyboard_layout; 107 extern const char *keyboard_layout;
99 extern int win2k_install_hack; 108 extern int win2k_install_hack;
100 extern int rtc_td_hack; 109 extern int rtc_td_hack;
@@ -201,9 +201,7 @@ DriveInfo drives_table[MAX_DRIVES+1]; @@ -201,9 +201,7 @@ DriveInfo drives_table[MAX_DRIVES+1];
201 int nb_drives; 201 int nb_drives;
202 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; 202 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
203 static DisplayState *display_state; 203 static DisplayState *display_state;
204 -int nographic;  
205 -static int curses;  
206 -static int sdl = 1; 204 +DisplayType display_type = DT_DEFAULT;
207 const char* keyboard_layout = NULL; 205 const char* keyboard_layout = NULL;
208 int64_t ticks_per_sec; 206 int64_t ticks_per_sec;
209 ram_addr_t ram_size; 207 ram_addr_t ram_size;
@@ -4842,6 +4840,7 @@ int main(int argc, char **argv, char **envp) @@ -4842,6 +4840,7 @@ int main(int argc, char **argv, char **envp)
4842 const char *run_as = NULL; 4840 const char *run_as = NULL;
4843 #endif 4841 #endif
4844 CPUState *env; 4842 CPUState *env;
  4843 + int show_vnc_port = 0;
4845 4844
4846 qemu_cache_utils_init(envp); 4845 qemu_cache_utils_init(envp);
4847 4846
@@ -4882,8 +4881,6 @@ int main(int argc, char **argv, char **envp) @@ -4882,8 +4881,6 @@ int main(int argc, char **argv, char **envp)
4882 initrd_filename = NULL; 4881 initrd_filename = NULL;
4883 ram_size = 0; 4882 ram_size = 0;
4884 snapshot = 0; 4883 snapshot = 0;
4885 - nographic = 0;  
4886 - curses = 0;  
4887 kernel_filename = NULL; 4884 kernel_filename = NULL;
4888 kernel_cmdline = ""; 4885 kernel_cmdline = "";
4889 cyls = heads = secs = 0; 4886 cyls = heads = secs = 0;
@@ -5075,11 +5072,11 @@ int main(int argc, char **argv, char **envp) @@ -5075,11 +5072,11 @@ int main(int argc, char **argv, char **envp)
5075 numa_add(optarg); 5072 numa_add(optarg);
5076 break; 5073 break;
5077 case QEMU_OPTION_nographic: 5074 case QEMU_OPTION_nographic:
5078 - nographic = 1; 5075 + display_type = DT_NOGRAPHIC;
5079 break; 5076 break;
5080 #ifdef CONFIG_CURSES 5077 #ifdef CONFIG_CURSES
5081 case QEMU_OPTION_curses: 5078 case QEMU_OPTION_curses:
5082 - curses = 1; 5079 + display_type = DT_CURSES;
5083 break; 5080 break;
5084 #endif 5081 #endif
5085 case QEMU_OPTION_portrait: 5082 case QEMU_OPTION_portrait:
@@ -5358,7 +5355,7 @@ int main(int argc, char **argv, char **envp) @@ -5358,7 +5355,7 @@ int main(int argc, char **argv, char **envp)
5358 no_quit = 1; 5355 no_quit = 1;
5359 break; 5356 break;
5360 case QEMU_OPTION_sdl: 5357 case QEMU_OPTION_sdl:
5361 - sdl = 1; 5358 + display_type = DT_SDL;
5362 break; 5359 break;
5363 #endif 5360 #endif
5364 case QEMU_OPTION_pidfile: 5361 case QEMU_OPTION_pidfile:
@@ -5420,6 +5417,7 @@ int main(int argc, char **argv, char **envp) @@ -5420,6 +5417,7 @@ int main(int argc, char **argv, char **envp)
5420 } 5417 }
5421 break; 5418 break;
5422 case QEMU_OPTION_vnc: 5419 case QEMU_OPTION_vnc:
  5420 + display_type = DT_VNC;
5423 vnc_display = optarg; 5421 vnc_display = optarg;
5424 break; 5422 break;
5425 #ifdef TARGET_I386 5423 #ifdef TARGET_I386
@@ -5578,7 +5576,7 @@ int main(int argc, char **argv, char **envp) @@ -5578,7 +5576,7 @@ int main(int argc, char **argv, char **envp)
5578 exit(1); 5576 exit(1);
5579 } 5577 }
5580 5578
5581 - if (nographic) { 5579 + if (display_type == DT_NOGRAPHIC) {
5582 if (serial_device_index == 0) 5580 if (serial_device_index == 0)
5583 serial_devices[0] = "stdio"; 5581 serial_devices[0] = "stdio";
5584 if (parallel_device_index == 0) 5582 if (parallel_device_index == 0)
@@ -5944,44 +5942,46 @@ int main(int argc, char **argv, char **envp) @@ -5944,44 +5942,46 @@ int main(int argc, char **argv, char **envp)
5944 dumb_display_init(); 5942 dumb_display_init();
5945 /* just use the first displaystate for the moment */ 5943 /* just use the first displaystate for the moment */
5946 ds = display_state; 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 #if defined(CONFIG_CURSES) 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 #endif 5964 #endif
5960 -#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)  
5961 - if (sdl) {  
5962 #if defined(CONFIG_SDL) 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 #elif defined(CONFIG_COCOA) 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 #endif 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 dpy_resize(ds); 5986 dpy_resize(ds);
5987 5987
@@ -5994,7 +5994,7 @@ int main(int argc, char **argv, char **envp) @@ -5994,7 +5994,7 @@ int main(int argc, char **argv, char **envp)
5994 dcl = dcl->next; 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 nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL); 5998 nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
5999 qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock)); 5999 qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
6000 } 6000 }