From 07fcd59de63ab3917d0f28d876cb1d2dcbbeb2a8 Mon Sep 17 00:00:00 2001 From: Cao jin Date: Thu, 3 Mar 2016 17:24:12 +0800 Subject: [PATCH 01/21] pc-dimm: correct comment of MemoryHotplugState correct comment and remove an unused macro. commit adcb4ee6 already correct its type Signed-off-by: Cao jin Signed-off-by: Eduardo Habkost --- include/hw/mem/pc-dimm.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 218dfb0eda..8cdc3266b3 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -20,8 +20,6 @@ #include "sysemu/hostmem.h" #include "hw/qdev.h" -#define DEFAULT_PC_DIMMSIZE (1024*1024*1024) - #define TYPE_PC_DIMM "pc-dimm" #define PC_DIMM(obj) \ OBJECT_CHECK(PCDIMMDevice, (obj), TYPE_PC_DIMM) @@ -72,7 +70,7 @@ typedef struct PCDIMMDeviceClass { /** * MemoryHotplugState: - * @base: address in guest RAM address space where hotplug memory + * @base: address in guest physical address space where hotplug memory * address space begins. * @mr: hotplug memory address space container */ From 4aeae8768a18fd5d32714c06b05c1735080b542d Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Wed, 11 Nov 2015 18:33:42 -0200 Subject: [PATCH 02/21] vl: Use exit(1) when requested VGA interface is unavailable Instead of using exit(0), use exit(1) when an unavailable VGA interface is used in the command-line to indicate it's an error. Reviewed-by: Eric Blake Reviewed-by: Marcel Apfelbaum Signed-off-by: Eduardo Habkost --- vl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vl.c b/vl.c index a43a3bad18..edfb5b97f0 100644 --- a/vl.c +++ b/vl.c @@ -2027,28 +2027,28 @@ static void select_vgahw (const char *p) vga_interface_type = VGA_STD; } else { error_report("standard VGA not available"); - exit(0); + exit(1); } } else if (strstart(p, "cirrus", &opts)) { if (cirrus_vga_available()) { vga_interface_type = VGA_CIRRUS; } else { error_report("Cirrus VGA not available"); - exit(0); + exit(1); } } else if (strstart(p, "vmware", &opts)) { if (vmware_vga_available()) { vga_interface_type = VGA_VMWARE; } else { error_report("VMWare SVGA not available"); - exit(0); + exit(1); } } else if (strstart(p, "virtio", &opts)) { if (virtio_vga_available()) { vga_interface_type = VGA_VIRTIO; } else { error_report("Virtio VGA not available"); - exit(0); + exit(1); } } else if (strstart(p, "xenfb", &opts)) { vga_interface_type = VGA_XENFB; @@ -2057,21 +2057,21 @@ static void select_vgahw (const char *p) vga_interface_type = VGA_QXL; } else { error_report("QXL VGA not available"); - exit(0); + exit(1); } } else if (strstart(p, "tcx", &opts)) { if (tcx_vga_available()) { vga_interface_type = VGA_TCX; } else { error_report("TCX framebuffer not available"); - exit(0); + exit(1); } } else if (strstart(p, "cg3", &opts)) { if (cg3_vga_available()) { vga_interface_type = VGA_CG3; } else { error_report("CG3 framebuffer not available"); - exit(0); + exit(1); } } else if (!strstart(p, "none", &opts)) { invalid_vga: From 8c9a2b71de67742b40870da22abeccab57c81924 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Wed, 28 Oct 2015 19:19:58 -0200 Subject: [PATCH 03/21] vl: Table-based select_vgahw() Instead of implementing separate check functions for each vga interface type, add a table enumerating the possible VGA interfaces. Reviewed-by: Eric Blake Reviewed-by: Marcel Apfelbaum Signed-off-by: Eduardo Habkost --- include/sysemu/sysemu.h | 1 + vl.c | 115 ++++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 52 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 38fb3cad35..2033f8c067 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -146,6 +146,7 @@ extern int autostart; typedef enum { VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL, VGA_TCX, VGA_CG3, VGA_DEVICE, VGA_VIRTIO, + VGA_TYPE_MAX, } VGAInterfaceType; extern int vga_interface_type; diff --git a/vl.c b/vl.c index edfb5b97f0..ac5db24293 100644 --- a/vl.c +++ b/vl.c @@ -2017,63 +2017,74 @@ static bool virtio_vga_available(void) return object_class_by_name("virtio-vga"); } -static void select_vgahw (const char *p) +typedef struct VGAInterfaceInfo { + const char *opt_name; /* option name */ + const char *name; /* human-readable name */ + bool (*available)(void); +} VGAInterfaceInfo; + +static VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = { + [VGA_NONE] = { + .opt_name = "none", + }, + [VGA_STD] = { + .opt_name = "std", + .name = "standard VGA", + .available = vga_available, + }, + [VGA_CIRRUS] = { + .opt_name = "cirrus", + .name = "Cirrus VGA", + .available = cirrus_vga_available, + }, + [VGA_VMWARE] = { + .opt_name = "vmware", + .name = "VMWare SVGA", + .available = vmware_vga_available, + }, + [VGA_VIRTIO] = { + .opt_name = "virtio", + .name = "Virtio VGA", + .available = virtio_vga_available, + }, + [VGA_QXL] = { + .opt_name = "qxl", + .name = "QXL VGA", + .available = qxl_vga_available, + }, + [VGA_TCX] = { + .opt_name = "tcx", + .name = "TCX framebuffer", + .available = tcx_vga_available, + }, + [VGA_CG3] = { + .opt_name = "cg3", + .name = "CG3 framebuffer", + .available = cg3_vga_available, + }, + [VGA_XENFB] = { + .opt_name = "xenfb", + }, +}; + +static void select_vgahw(const char *p) { const char *opts; + int t; assert(vga_interface_type == VGA_NONE); - if (strstart(p, "std", &opts)) { - if (vga_available()) { - vga_interface_type = VGA_STD; - } else { - error_report("standard VGA not available"); - exit(1); + for (t = 0; t < VGA_TYPE_MAX; t++) { + VGAInterfaceInfo *ti = &vga_interfaces[t]; + if (ti->opt_name && strstart(p, ti->opt_name, &opts)) { + if (ti->available && !ti->available()) { + error_report("%s not available", ti->name); + exit(1); + } + vga_interface_type = t; + break; } - } else if (strstart(p, "cirrus", &opts)) { - if (cirrus_vga_available()) { - vga_interface_type = VGA_CIRRUS; - } else { - error_report("Cirrus VGA not available"); - exit(1); - } - } else if (strstart(p, "vmware", &opts)) { - if (vmware_vga_available()) { - vga_interface_type = VGA_VMWARE; - } else { - error_report("VMWare SVGA not available"); - exit(1); - } - } else if (strstart(p, "virtio", &opts)) { - if (virtio_vga_available()) { - vga_interface_type = VGA_VIRTIO; - } else { - error_report("Virtio VGA not available"); - exit(1); - } - } else if (strstart(p, "xenfb", &opts)) { - vga_interface_type = VGA_XENFB; - } else if (strstart(p, "qxl", &opts)) { - if (qxl_vga_available()) { - vga_interface_type = VGA_QXL; - } else { - error_report("QXL VGA not available"); - exit(1); - } - } else if (strstart(p, "tcx", &opts)) { - if (tcx_vga_available()) { - vga_interface_type = VGA_TCX; - } else { - error_report("TCX framebuffer not available"); - exit(1); - } - } else if (strstart(p, "cg3", &opts)) { - if (cg3_vga_available()) { - vga_interface_type = VGA_CG3; - } else { - error_report("CG3 framebuffer not available"); - exit(1); - } - } else if (!strstart(p, "none", &opts)) { + } + if (t == VGA_TYPE_MAX) { invalid_vga: error_report("unknown vga type: %s", p); exit(1); From c2c7b22db1dcb10b9ba9faa9cc82fb074a4db418 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Wed, 11 Nov 2015 18:55:56 -0200 Subject: [PATCH 04/21] vl: Replace *_vga_available() functions with class_names field Instead of requiring a separate function for each VGA interface, just enumerate the corresponding class names on struct VGAInterfaceInfo. Reviewed-by: Eric Blake Reviewed-by: Marcel Apfelbaum Signed-off-by: Eduardo Habkost --- vl.c | 70 ++++++++++++++++++++---------------------------------------- 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/vl.c b/vl.c index ac5db24293..d309ff725e 100644 --- a/vl.c +++ b/vl.c @@ -1981,46 +1981,12 @@ static const QEMUOption qemu_options[] = { { NULL }, }; -static bool vga_available(void) -{ - return object_class_by_name("VGA") || object_class_by_name("isa-vga"); -} - -static bool cirrus_vga_available(void) -{ - return object_class_by_name("cirrus-vga") - || object_class_by_name("isa-cirrus-vga"); -} - -static bool vmware_vga_available(void) -{ - return object_class_by_name("vmware-svga"); -} - -static bool qxl_vga_available(void) -{ - return object_class_by_name("qxl-vga"); -} - -static bool tcx_vga_available(void) -{ - return object_class_by_name("SUNW,tcx"); -} - -static bool cg3_vga_available(void) -{ - return object_class_by_name("cgthree"); -} - -static bool virtio_vga_available(void) -{ - return object_class_by_name("virtio-vga"); -} - typedef struct VGAInterfaceInfo { const char *opt_name; /* option name */ const char *name; /* human-readable name */ - bool (*available)(void); + /* Class names indicating that support is available. + * If no class is specified, the interface is always available */ + const char *class_names[2]; } VGAInterfaceInfo; static VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = { @@ -2030,43 +1996,53 @@ static VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = { [VGA_STD] = { .opt_name = "std", .name = "standard VGA", - .available = vga_available, + .class_names = { "VGA", "isa-vga" }, }, [VGA_CIRRUS] = { .opt_name = "cirrus", .name = "Cirrus VGA", - .available = cirrus_vga_available, + .class_names = { "cirrus-vga", "isa-cirrus-vga" }, }, [VGA_VMWARE] = { .opt_name = "vmware", .name = "VMWare SVGA", - .available = vmware_vga_available, + .class_names = { "vmware-svga" }, }, [VGA_VIRTIO] = { .opt_name = "virtio", .name = "Virtio VGA", - .available = virtio_vga_available, + .class_names = { "virtio-vga" }, }, [VGA_QXL] = { .opt_name = "qxl", .name = "QXL VGA", - .available = qxl_vga_available, + .class_names = { "qxl-vga" }, }, [VGA_TCX] = { .opt_name = "tcx", .name = "TCX framebuffer", - .available = tcx_vga_available, + .class_names = { "SUNW,tcx" }, }, [VGA_CG3] = { .opt_name = "cg3", .name = "CG3 framebuffer", - .available = cg3_vga_available, + .class_names = { "cgthree" }, }, [VGA_XENFB] = { .opt_name = "xenfb", }, }; +static bool vga_interface_available(VGAInterfaceType t) +{ + VGAInterfaceInfo *ti = &vga_interfaces[t]; + + assert(t < VGA_TYPE_MAX); + return !ti->class_names[0] || + object_class_by_name(ti->class_names[0]) || + object_class_by_name(ti->class_names[1]); +} + static void select_vgahw(const char *p) { const char *opts; @@ -2076,7 +2052,7 @@ static void select_vgahw(const char *p) for (t = 0; t < VGA_TYPE_MAX; t++) { VGAInterfaceInfo *ti = &vga_interfaces[t]; if (ti->opt_name && strstart(p, ti->opt_name, &opts)) { - if (ti->available && !ti->available()) { + if (!vga_interface_available(t)) { error_report("%s not available", ti->name); exit(1); } @@ -4492,9 +4468,9 @@ int main(int argc, char **argv, char **envp) if (default_vga) { if (machine_class->default_display) { vga_model = machine_class->default_display; - } else if (cirrus_vga_available()) { + } else if (vga_interface_available(VGA_CIRRUS)) { vga_model = "cirrus"; - } else if (vga_available()) { + } else if (vga_interface_available(VGA_STD)) { vga_model = "std"; } } From 7b7d2be50c9c0f125b0025024b7048df87ac36bb Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:17 -0300 Subject: [PATCH 05/21] vl: Add DT_COCOA DisplayType value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of reusing DT_SDL for Cocoa, use DT_COCOA to indicate that a Cocoa display was requested. configure already ensures CONFIG_COCOA and CONFIG_SDL are never set at the same time. The only case where DT_SDL is used outside a #ifdef CONFIG_SDL block is in the no_frame/alt_grab/ctrl_grab check. That means the only user-visible change is that we will start printing a warning if the SDL-specific options are used in Cocoa mode. This is a bugfix, because no_frame/alt_grab/ctrl_grab are not used by Cocoa code. Cc: Andreas Färber Cc: Peter Maydell Acked-by: Andreas Färber Signed-off-by: Eduardo Habkost --- include/sysemu/sysemu.h | 1 + vl.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 2033f8c067..90766da202 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -136,6 +136,7 @@ typedef enum DisplayType DT_DEFAULT, DT_CURSES, DT_SDL, + DT_COCOA, DT_GTK, DT_NOGRAPHIC, DT_NONE, diff --git a/vl.c b/vl.c index d309ff725e..a064a46a65 100644 --- a/vl.c +++ b/vl.c @@ -4237,8 +4237,10 @@ int main(int argc, char **argv, char **envp) if (display_type == DT_DEFAULT && !display_remote) { #if defined(CONFIG_GTK) display_type = DT_GTK; -#elif defined(CONFIG_SDL) || defined(CONFIG_COCOA) +#elif defined(CONFIG_SDL) display_type = DT_SDL; +#elif defined(CONFIG_COCOA) + display_type = DT_COCOA; #elif defined(CONFIG_VNC) vnc_parse("localhost:0,to=99,id=default", &error_abort); show_vnc_port = 1; @@ -4560,7 +4562,7 @@ int main(int argc, char **argv, char **envp) sdl_display_init(ds, full_screen, no_frame); break; #elif defined(CONFIG_COCOA) - case DT_SDL: + case DT_COCOA: cocoa_display_init(ds, full_screen); break; #endif From f8c75b2486d62bf1cbe824aa4c471118061bdcd3 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:18 -0300 Subject: [PATCH 06/21] vnc: Initialization stubs This reduces the number of CONFIG_VNC #ifdefs in the vl.c code. The only user-visible difference is that this will make QEMU complain about syntax when using "-display vnc" ("VNC requires a display argument vnc=") even if CONFIG_VNC is disabled. Signed-off-by: Eduardo Habkost --- include/ui/console.h | 20 +++++++++++++++++++- vl.c | 15 +-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index d5a88d93e8..6640348ee8 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -6,6 +6,8 @@ #include "qapi/qmp/qdict.h" #include "qemu/notify.h" #include "qapi-types.h" +#include "qemu/error-report.h" +#include "qapi/error.h" #ifdef CONFIG_OPENGL # include @@ -430,10 +432,10 @@ void cocoa_display_init(DisplayState *ds, int full_screen); void vnc_display_init(const char *id); void vnc_display_open(const char *id, Error **errp); void vnc_display_add_client(const char *id, int csock, bool skipauth); -char *vnc_display_local_addr(const char *id); #ifdef CONFIG_VNC int vnc_display_password(const char *id, const char *password); int vnc_display_pw_expire(const char *id, time_t expires); +char *vnc_display_local_addr(const char *id); QemuOpts *vnc_parse(const char *str, Error **errp); int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp); #else @@ -445,6 +447,22 @@ static inline int vnc_display_pw_expire(const char *id, time_t expires) { return -ENODEV; }; +static inline QemuOpts *vnc_parse(const char *str, Error **errp) +{ + error_setg(errp, "VNC support is disabled"); + return NULL; +} +static inline int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + error_setg(errp, "VNC support is disabled"); + return -1; +} +static inline char *vnc_display_local_addr(const char *id) +{ + /* This must never be called if CONFIG_VNC is disabled */ + error_report("VNC support is disabled"); + abort(); +} #endif /* curses.c */ diff --git a/vl.c b/vl.c index a064a46a65..a66d04ae4e 100644 --- a/vl.c +++ b/vl.c @@ -2148,7 +2148,6 @@ static DisplayType select_display(const char *p) exit(1); #endif } else if (strstart(p, "vnc", &opts)) { -#ifdef CONFIG_VNC if (*opts == '=') { Error *err = NULL; if (vnc_parse(opts + 1, &err) == NULL) { @@ -2159,10 +2158,6 @@ static DisplayType select_display(const char *p) error_report("VNC requires a display argument vnc="); exit(1); } -#else - error_report("VNC support is disabled"); - exit(1); -#endif } else if (strstart(p, "curses", &opts)) { #ifdef CONFIG_CURSES display = DT_CURSES; @@ -2966,9 +2961,7 @@ int main(int argc, char **argv, char **envp) const char *qtest_log = NULL; const char *pid_file = NULL; const char *incoming = NULL; -#ifdef CONFIG_VNC int show_vnc_port = 0; -#endif bool defconfig = true; bool userconfig = true; const char *log_mask = NULL; @@ -3715,17 +3708,12 @@ int main(int argc, char **argv, char **envp) break; case QEMU_OPTION_vnc: { -#ifdef CONFIG_VNC Error *local_err = NULL; if (vnc_parse(optarg, &local_err) == NULL) { error_report_err(local_err); exit(1); } -#else - error_report("VNC support is disabled"); - exit(1); -#endif break; } case QEMU_OPTION_no_acpi: @@ -4578,7 +4566,6 @@ int main(int argc, char **argv, char **envp) /* must be after terminal init, SDL library changes signal handlers */ os_setup_signal_handling(); -#ifdef CONFIG_VNC /* init remote displays */ qemu_opts_foreach(qemu_find_opts("vnc"), vnc_init_func, NULL, NULL); @@ -4587,7 +4574,7 @@ int main(int argc, char **argv, char **envp) printf("VNC server running on '%s'\n", ret); g_free(ret); } -#endif + #ifdef CONFIG_SPICE if (using_spice) { qemu_spice_display_init(); From 674ec686936fcde6977616dce2a68b42533ab2d7 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:19 -0300 Subject: [PATCH 07/21] curses: curses_display_init() stub One less #ifdef in vl.c. Signed-off-by: Eduardo Habkost --- include/ui/console.h | 9 +++++++++ vl.c | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 6640348ee8..f5fa9cbd7c 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -466,7 +466,16 @@ static inline char *vnc_display_local_addr(const char *id) #endif /* curses.c */ +#ifdef CONFIG_CURSES void curses_display_init(DisplayState *ds, int full_screen); +#else +static inline void curses_display_init(DisplayState *ds, int full_screen) +{ + /* This must never be called if CONFIG_CURSES is disabled */ + error_report("curses support is disabled"); + abort(); +} +#endif /* input.c */ int index_from_key(const char *key, size_t key_length); diff --git a/vl.c b/vl.c index a66d04ae4e..c852d105d9 100644 --- a/vl.c +++ b/vl.c @@ -4540,11 +4540,9 @@ int main(int argc, char **argv, char **envp) case DT_NOGRAPHIC: (void)ds; /* avoid warning if no display is configured */ break; -#if defined(CONFIG_CURSES) case DT_CURSES: curses_display_init(ds, full_screen); break; -#endif #if defined(CONFIG_SDL) case DT_SDL: sdl_display_init(ds, full_screen, no_frame); From 476db0814d8953e6c5f2dd0299249be3a751fc6a Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:20 -0300 Subject: [PATCH 08/21] sdl: Initialization stubs This reduces the number of CONFIG_SDL #ifdefs in vl.c. Signed-off-by: Eduardo Habkost --- include/ui/console.h | 16 ++++++++++++++++ vl.c | 6 ++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index f5fa9cbd7c..f3e749ddd5 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -422,8 +422,24 @@ void surface_gl_setup_viewport(ConsoleGLState *gls, #endif /* sdl.c */ +#ifdef CONFIG_SDL void sdl_display_early_init(int opengl); void sdl_display_init(DisplayState *ds, int full_screen, int no_frame); +#else +static inline void sdl_display_early_init(int opengl) +{ + /* This must never be called if CONFIG_SDL is disabled */ + error_report("SDL support is disabled"); + abort(); +} +static inline void sdl_display_init(DisplayState *ds, int full_screen, + int no_frame) +{ + /* This must never be called if CONFIG_SDL is disabled */ + error_report("SDL support is disabled"); + abort(); +} +#endif /* cocoa.m */ void cocoa_display_init(DisplayState *ds, int full_screen); diff --git a/vl.c b/vl.c index c852d105d9..d5df442701 100644 --- a/vl.c +++ b/vl.c @@ -4251,11 +4251,10 @@ int main(int argc, char **argv, char **envp) early_gtk_display_init(request_opengl); } #endif -#if defined(CONFIG_SDL) if (display_type == DT_SDL) { sdl_display_early_init(request_opengl); } -#endif + if (request_opengl == 1 && display_opengl == 0) { #if defined(CONFIG_OPENGL) error_report("OpenGL is not supported by the display"); @@ -4543,11 +4542,10 @@ int main(int argc, char **argv, char **envp) case DT_CURSES: curses_display_init(ds, full_screen); break; -#if defined(CONFIG_SDL) case DT_SDL: sdl_display_init(ds, full_screen, no_frame); break; -#elif defined(CONFIG_COCOA) +#if defined(CONFIG_COCOA) case DT_COCOA: cocoa_display_init(ds, full_screen); break; From e35ee7c1aa1f257d3e0e52422cf4bd79d3b68d58 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:21 -0300 Subject: [PATCH 09/21] cocoa: cocoa_display_init() stub One less #ifdef in vl.c. Signed-off-by: Eduardo Habkost --- include/ui/console.h | 9 +++++++++ vl.c | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index f3e749ddd5..7ac997f514 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -442,7 +442,16 @@ static inline void sdl_display_init(DisplayState *ds, int full_screen, #endif /* cocoa.m */ +#ifdef CONFIG_COCOA void cocoa_display_init(DisplayState *ds, int full_screen); +#else +static inline void cocoa_display_init(DisplayState *ds, int full_screen) +{ + /* This must never be called if CONFIG_COCOA is disabled */ + error_report("Cocoa support is disabled"); + abort(); +} +#endif /* vnc.c */ void vnc_display_init(const char *id); diff --git a/vl.c b/vl.c index d5df442701..064870561a 100644 --- a/vl.c +++ b/vl.c @@ -4545,11 +4545,9 @@ int main(int argc, char **argv, char **envp) case DT_SDL: sdl_display_init(ds, full_screen, no_frame); break; -#if defined(CONFIG_COCOA) case DT_COCOA: cocoa_display_init(ds, full_screen); break; -#endif #if defined(CONFIG_GTK) case DT_GTK: gtk_display_init(ds, full_screen, grab_on_hover); From 19a2c6269f2e81d3aecdddb4d77fb674f9ca8fa3 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:22 -0300 Subject: [PATCH 10/21] gtk: Initialization stubs This reduces the number of CONFIG_GTK #ifdefs in vl.c. Signed-off-by: Eduardo Habkost --- include/ui/console.h | 17 +++++++++++++++++ vl.c | 7 +------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 7ac997f514..52a5f65673 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -506,7 +506,24 @@ static inline void curses_display_init(DisplayState *ds, int full_screen) int index_from_key(const char *key, size_t key_length); /* gtk.c */ +#ifdef CONFIG_GTK void early_gtk_display_init(int opengl); void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover); +#else +static inline void gtk_display_init(DisplayState *ds, bool full_screen, + bool grab_on_hover) +{ + /* This must never be called if CONFIG_GTK is disabled */ + error_report("GTK support is disabled"); + abort(); +} + +static inline void early_gtk_display_init(int opengl) +{ + /* This must never be called if CONFIG_GTK is disabled */ + error_report("GTK support is disabled"); + abort(); +} +#endif #endif diff --git a/vl.c b/vl.c index 064870561a..6e8d25e741 100644 --- a/vl.c +++ b/vl.c @@ -148,9 +148,7 @@ int vga_interface_type = VGA_NONE; static int full_screen = 0; static int no_frame = 0; int no_quit = 0; -#ifdef CONFIG_GTK static bool grab_on_hover; -#endif CharDriverState *serial_hds[MAX_SERIAL_PORTS]; CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; @@ -4246,11 +4244,10 @@ int main(int argc, char **argv, char **envp) "ignoring option"); } -#if defined(CONFIG_GTK) if (display_type == DT_GTK) { early_gtk_display_init(request_opengl); } -#endif + if (display_type == DT_SDL) { sdl_display_early_init(request_opengl); } @@ -4548,11 +4545,9 @@ int main(int argc, char **argv, char **envp) case DT_COCOA: cocoa_display_init(ds, full_screen); break; -#if defined(CONFIG_GTK) case DT_GTK: gtk_display_init(ds, full_screen, grab_on_hover); break; -#endif default: break; } From 6f0c894c25e42454e9065fc4e5cc22c251cea30d Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:23 -0300 Subject: [PATCH 11/21] spice: Initialization stubs on qemu-spice.h This reduces the number of CONFIG_SPICE #ifdefs in vl.c. Cc: Gerd Hoffmann Reviewed-by: Gerd Hoffmann Signed-off-by: Eduardo Habkost --- include/ui/qemu-spice.h | 13 +++++++++++++ vl.c | 4 ---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/ui/qemu-spice.h b/include/ui/qemu-spice.h index aa2436355f..57ac91b921 100644 --- a/include/ui/qemu-spice.h +++ b/include/ui/qemu-spice.h @@ -51,6 +51,8 @@ static inline CharDriverState *qemu_chr_open_spice_port(const char *name) #else /* CONFIG_SPICE */ +#include "qemu/error-report.h" + #define using_spice 0 #define spice_displays 0 static inline int qemu_spice_set_passwd(const char *passwd, @@ -75,6 +77,17 @@ static inline int qemu_spice_display_add_client(int csock, int skipauth, return -1; } +static inline void qemu_spice_display_init(void) +{ + /* This must never be called if CONFIG_SPICE is disabled */ + error_report("spice support is disabled"); + abort(); +} + +static inline void qemu_spice_init(void) +{ +} + #endif /* CONFIG_SPICE */ static inline bool qemu_using_spice(Error **errp) diff --git a/vl.c b/vl.c index 6e8d25e741..8576556f81 100644 --- a/vl.c +++ b/vl.c @@ -4360,10 +4360,8 @@ int main(int argc, char **argv, char **envp) os_set_line_buffering(); -#ifdef CONFIG_SPICE /* spice needs the timers to be initialized by this point */ qemu_spice_init(); -#endif cpu_ticks_init(); if (icount_opts) { @@ -4564,11 +4562,9 @@ int main(int argc, char **argv, char **envp) g_free(ret); } -#ifdef CONFIG_SPICE if (using_spice) { qemu_spice_display_init(); } -#endif if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) { exit(1); From cf3dc71eb5141761c3aed0d936e390aeaa73a88b Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:24 -0300 Subject: [PATCH 12/21] milkymist: Move DT_NOGRAPHIC check outside milkymist_tmu2_create() DT_NOGRAPHIC handling will be moved to a MachineState field, and it will be easier to change milkymist_init() to check that field. Cc: Michael Walle Signed-off-by: Eduardo Habkost --- hw/lm32/milkymist-hw.h | 4 ---- hw/lm32/milkymist.c | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/hw/lm32/milkymist-hw.h b/hw/lm32/milkymist-hw.h index c8dfb4d2d4..f857d2846f 100644 --- a/hw/lm32/milkymist-hw.h +++ b/hw/lm32/milkymist-hw.h @@ -108,10 +108,6 @@ static inline DeviceState *milkymist_tmu2_create(hwaddr base, int nelements; int ver_major, ver_minor; - if (display_type == DT_NOGRAPHIC) { - return NULL; - } - /* check that GLX will work */ d = XOpenDisplay(NULL); if (d == NULL) { diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c index 96e6f4dc2e..694dac3b90 100644 --- a/hw/lm32/milkymist.c +++ b/hw/lm32/milkymist.c @@ -167,7 +167,9 @@ milkymist_init(MachineState *machine) milkymist_memcard_create(0x60004000); milkymist_ac97_create(0x60005000, irq[4], irq[5], irq[6], irq[7]); milkymist_pfpu_create(0x60006000, irq[8]); - milkymist_tmu2_create(0x60007000, irq[9]); + if (display_type != DT_NOGRAPHIC) { + milkymist_tmu2_create(0x60007000, irq[9]); + } milkymist_minimac2_create(0x60008000, 0x30000000, irq[10], irq[11]); milkymist_softusb_create(0x6000f000, irq[15], 0x20000000, 0x1000, 0x20020000, 0x2000); From cfc58cf37362a931990efc75f3f580dfec49ac1e Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:25 -0300 Subject: [PATCH 13/21] vl: Replace DT_NOGRAPHIC with machine option All DisplayType values are just UI options that don't affect any hardware emulation code, except for DT_NOGRAPHIC. Replace DT_NOGRAPHIC with DT_NONE plus a new "-machine graphics=on|off" option, so hardware emulation code don't need to use the display_type variable. Cc: Michael Walle Cc: Blue Swirl Cc: Mark Cave-Ayland Signed-off-by: Eduardo Habkost --- hw/core/machine.c | 21 +++++++++++++++++++++ hw/lm32/milkymist.c | 2 +- hw/nvram/fw_cfg.c | 6 ++++-- hw/sparc/sun4m.c | 2 +- include/hw/boards.h | 1 + include/sysemu/sysemu.h | 1 - vl.c | 13 +++++++------ 7 files changed, 35 insertions(+), 11 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 6dbbc85b97..0bb96ad457 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -257,6 +257,20 @@ static void machine_set_usb(Object *obj, bool value, Error **errp) ms->usb_disabled = !value; } +static bool machine_get_graphics(Object *obj, Error **errp) +{ + MachineState *ms = MACHINE(obj); + + return ms->enable_graphics; +} + +static void machine_set_graphics(Object *obj, bool value, Error **errp) +{ + MachineState *ms = MACHINE(obj); + + ms->enable_graphics = value; +} + static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj); @@ -382,6 +396,7 @@ static void machine_initfn(Object *obj) ms->kvm_shadow_mem = -1; ms->dump_guest_core = true; ms->mem_merge = true; + ms->enable_graphics = true; object_property_add_str(obj, "accel", machine_get_accel, machine_set_accel, NULL); @@ -460,6 +475,12 @@ static void machine_initfn(Object *obj) object_property_set_description(obj, "usb", "Set on/off to enable/disable usb", NULL); + object_property_add_bool(obj, "graphics", + machine_get_graphics, + machine_set_graphics, NULL); + object_property_set_description(obj, "graphics", + "Set on/off to enable/disable graphics emulation", + NULL); object_property_add_bool(obj, "igd-passthru", machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru, NULL); diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c index 694dac3b90..1abdf6e2e6 100644 --- a/hw/lm32/milkymist.c +++ b/hw/lm32/milkymist.c @@ -167,7 +167,7 @@ milkymist_init(MachineState *machine) milkymist_memcard_create(0x60004000); milkymist_ac97_create(0x60005000, irq[4], irq[5], irq[6], irq[7]); milkymist_pfpu_create(0x60006000, irq[8]); - if (display_type != DT_NOGRAPHIC) { + if (machine->enable_graphics) { milkymist_tmu2_create(0x60007000, irq[9]); } milkymist_minimac2_create(0x60008000, 0x30000000, irq[10], irq[11]); diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 999f480280..cdbdfb5320 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -25,6 +25,7 @@ #include "hw/hw.h" #include "sysemu/sysemu.h" #include "sysemu/dma.h" +#include "hw/boards.h" #include "hw/isa/isa.h" #include "hw/nvram/fw_cfg.h" #include "hw/sysbus.h" @@ -868,16 +869,17 @@ static void fw_cfg_machine_ready(struct Notifier *n, void *data) static void fw_cfg_init1(DeviceState *dev) { FWCfgState *s = FW_CFG(dev); + MachineState *machine = MACHINE(qdev_get_machine()); assert(!object_resolve_path(FW_CFG_PATH, NULL)); - object_property_add_child(qdev_get_machine(), FW_CFG_NAME, OBJECT(s), NULL); + object_property_add_child(OBJECT(machine), FW_CFG_NAME, OBJECT(s), NULL); qdev_init_nofail(dev); fw_cfg_add_bytes(s, FW_CFG_SIGNATURE, (char *)"QEMU", 4); fw_cfg_add_bytes(s, FW_CFG_UUID, qemu_uuid, 16); - fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)(display_type == DT_NOGRAPHIC)); + fw_cfg_add_i16(s, FW_CFG_NOGRAPHIC, (uint16_t)!machine->enable_graphics); fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu); fw_cfg_bootsplash(s); diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c index 7bfc00abc2..478fda8209 100644 --- a/hw/sparc/sun4m.c +++ b/hw/sparc/sun4m.c @@ -1000,7 +1000,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus); slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[14], - display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1); + !machine->enable_graphics, ESCC_CLOCK, 1); /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */ escc_init(hwdef->serial_base, slavio_irq[15], slavio_irq[15], diff --git a/include/hw/boards.h b/include/hw/boards.h index 8d4fe56b5f..f968a256dc 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -154,6 +154,7 @@ struct MachineState { bool iommu; bool suppress_vmdesc; bool enforce_config_section; + bool enable_graphics; ram_addr_t ram_size; ram_addr_t maxram_size; diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 90766da202..6076b80048 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -138,7 +138,6 @@ typedef enum DisplayType DT_SDL, DT_COCOA, DT_GTK, - DT_NOGRAPHIC, DT_NONE, } DisplayType; diff --git a/vl.c b/vl.c index 8576556f81..35ed954780 100644 --- a/vl.c +++ b/vl.c @@ -2962,6 +2962,7 @@ int main(int argc, char **argv, char **envp) int show_vnc_port = 0; bool defconfig = true; bool userconfig = true; + bool nographic = false; const char *log_mask = NULL; const char *log_file = NULL; char *trace_file = NULL; @@ -3206,7 +3207,10 @@ int main(int argc, char **argv, char **envp) display_type = select_display(optarg); break; case QEMU_OPTION_nographic: - display_type = DT_NOGRAPHIC; + olist = qemu_find_opts("machine"); + qemu_opts_parse_noisily(olist, "graphics=off", false); + nographic = true; + display_type = DT_NONE; break; case QEMU_OPTION_curses: #ifdef CONFIG_CURSES @@ -4167,7 +4171,7 @@ int main(int argc, char **argv, char **envp) * -nographic _and_ redirects all ports explicitly - this is valid * usage, -nographic is just a no-op in this case. */ - if (display_type == DT_NOGRAPHIC + if (nographic && (default_parallel || default_serial || default_monitor || default_virtcon)) { error_report("-nographic cannot be used with -daemonize"); @@ -4181,7 +4185,7 @@ int main(int argc, char **argv, char **envp) #endif } - if (display_type == DT_NOGRAPHIC) { + if (nographic) { if (default_parallel) add_device_config(DEV_PARALLEL, "null"); if (default_serial && default_monitor) { @@ -4531,9 +4535,6 @@ int main(int argc, char **argv, char **envp) /* init local displays */ switch (display_type) { - case DT_NOGRAPHIC: - (void)ds; /* avoid warning if no display is configured */ - break; case DT_CURSES: curses_display_init(ds, full_screen); break; From d29345d011114b90f0a6871fb0d46a7741c6c33c Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:26 -0300 Subject: [PATCH 14/21] vl: Make display_type a local variable Now display_type is only used inside main(), and don't need to be a global variable. Signed-off-by: Eduardo Habkost --- include/sysemu/sysemu.h | 1 - vl.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 6076b80048..7e9f93ebb1 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -155,7 +155,6 @@ extern int vga_interface_type; extern int graphic_width; extern int graphic_height; extern int graphic_depth; -extern DisplayType display_type; extern int display_opengl; extern const char *keyboard_layout; extern int win2k_install_hack; diff --git a/vl.c b/vl.c index 35ed954780..0d10ceb011 100644 --- a/vl.c +++ b/vl.c @@ -129,7 +129,6 @@ static const char *data_dir[16]; static int data_dir_idx; const char *bios_name = NULL; enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; -DisplayType display_type = DT_DEFAULT; int request_opengl = -1; int display_opengl; static int display_remote; @@ -2963,6 +2962,7 @@ int main(int argc, char **argv, char **envp) bool defconfig = true; bool userconfig = true; bool nographic = false; + DisplayType display_type = DT_DEFAULT; const char *log_mask = NULL; const char *log_file = NULL; char *trace_file = NULL; From 0cb48c4678af6e1fedbb48c52e5baa01f7266f54 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:27 -0300 Subject: [PATCH 15/21] vl: Move DisplayType typedef to vl.c Now the type is only used inside vl.c and doesn't need to be in a header file. Signed-off-by: Eduardo Habkost --- include/sysemu/sysemu.h | 10 ---------- vl.c | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 7e9f93ebb1..618169c4d5 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -131,16 +131,6 @@ void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name, int qemu_loadvm_state(QEMUFile *f); -typedef enum DisplayType -{ - DT_DEFAULT, - DT_CURSES, - DT_SDL, - DT_COCOA, - DT_GTK, - DT_NONE, -} DisplayType; - extern int autostart; typedef enum { diff --git a/vl.c b/vl.c index 0d10ceb011..aaf9134f72 100644 --- a/vl.c +++ b/vl.c @@ -2077,6 +2077,15 @@ static void select_vgahw(const char *p) } } +typedef enum DisplayType { + DT_DEFAULT, + DT_CURSES, + DT_SDL, + DT_COCOA, + DT_GTK, + DT_NONE, +} DisplayType; + static DisplayType select_display(const char *p) { const char *opts; From 1f0dfe02d47b14b04f2643828e2ee11665e1eb24 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Tue, 19 Apr 2016 16:55:28 -0300 Subject: [PATCH 16/21] vl: Make display_remote a local variable The variable is used only inside main(), so it can be local. Signed-off-by: Eduardo Habkost --- vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vl.c b/vl.c index aaf9134f72..a44e155713 100644 --- a/vl.c +++ b/vl.c @@ -131,7 +131,6 @@ const char *bios_name = NULL; enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; int request_opengl = -1; int display_opengl; -static int display_remote; const char* keyboard_layout = NULL; ram_addr_t ram_size; const char *mem_path = NULL; @@ -2972,6 +2971,7 @@ int main(int argc, char **argv, char **envp) bool userconfig = true; bool nographic = false; DisplayType display_type = DT_DEFAULT; + int display_remote = 0; const char *log_mask = NULL; const char *log_file = NULL; char *trace_file = NULL; From 16714b16806979d7f9f245b2b4c13966e4fa1c2e Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Thu, 28 Jan 2016 13:11:04 -0200 Subject: [PATCH 17/21] vl: Simplify global property registration There's no need to use qdev_prop_register_global_list() and an array, if we are registering a single GlobalProperty struct. Use qdev_prop_register_global() instead. Reviewed-by: Igor Mammedov Signed-off-by: Eduardo Habkost --- vl.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/vl.c b/vl.c index a44e155713..88618624f8 100644 --- a/vl.c +++ b/vl.c @@ -888,16 +888,13 @@ static void configure_rtc(QemuOpts *opts) value = qemu_opt_get(opts, "driftfix"); if (value) { if (!strcmp(value, "slew")) { - static GlobalProperty slew_lost_ticks[] = { - { - .driver = "mc146818rtc", - .property = "lost_tick_policy", - .value = "slew", - }, - { /* end of list */ } + static GlobalProperty slew_lost_ticks = { + .driver = "mc146818rtc", + .property = "lost_tick_policy", + .value = "slew", }; - qdev_prop_register_global_list(slew_lost_ticks); + qdev_prop_register_global(&slew_lost_ticks); } else if (!strcmp(value, "none")) { /* discard is default */ } else { @@ -3626,16 +3623,13 @@ int main(int argc, char **argv, char **envp) win2k_install_hack = 1; break; case QEMU_OPTION_rtc_td_hack: { - static GlobalProperty slew_lost_ticks[] = { - { - .driver = "mc146818rtc", - .property = "lost_tick_policy", - .value = "slew", - }, - { /* end of list */ } + static GlobalProperty slew_lost_ticks = { + .driver = "mc146818rtc", + .property = "lost_tick_policy", + .value = "slew", }; - qdev_prop_register_global_list(slew_lost_ticks); + qdev_prop_register_global(&slew_lost_ticks); break; } case QEMU_OPTION_acpitable: @@ -3682,18 +3676,15 @@ int main(int argc, char **argv, char **envp) break; } case QEMU_OPTION_no_kvm_pit_reinjection: { - static GlobalProperty kvm_pit_lost_tick_policy[] = { - { - .driver = "kvm-pit", - .property = "lost_tick_policy", - .value = "discard", - }, - { /* end of list */ } + static GlobalProperty kvm_pit_lost_tick_policy = { + .driver = "kvm-pit", + .property = "lost_tick_policy", + .value = "discard", }; error_report("warning: deprecated, replaced by " "-global kvm-pit.lost_tick_policy=discard"); - qdev_prop_register_global_list(kvm_pit_lost_tick_policy); + qdev_prop_register_global(&kvm_pit_lost_tick_policy); break; } case QEMU_OPTION_usb: From bacc344c548ce165a0001276ece56ee4b0bddae3 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Thu, 28 Jan 2016 11:58:08 +0100 Subject: [PATCH 18/21] machine: add properties to compat_props incrementaly Switch to adding compat properties incrementaly instead of completly overwriting compat_props per machine type. That removes data duplication which we have due to nested [PC|SPAPR]_COMPAT_* macros. It also allows to set default device properties from default foo_machine_options() hook, which will be used in following patch for putting VMGENID device as a function if ISA bridge on pc/q35 machines. Suggested-by: Eduardo Habkost Signed-off-by: Igor Mammedov Acked-by: Cornelia Huck Reviewed-by: Eduardo Habkost [ehabkost: Fixed CCW_COMPAT_* and PC_COMPAT_0_* defines] Signed-off-by: Eduardo Habkost --- hw/arm/virt.c | 4 ---- hw/core/machine.c | 10 ++++++++++ hw/i386/pc_piix.c | 13 ------------- hw/ppc/spapr.c | 4 ---- hw/s390x/s390-virtio-ccw.c | 1 - include/hw/boards.h | 11 +++++++++-- include/hw/i386/pc.h | 9 --------- vl.c | 6 +++++- 8 files changed, 24 insertions(+), 34 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index fe6b11d24e..e77ed88afb 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1418,13 +1418,9 @@ static void virt_2_6_instance_init(Object *obj) static void virt_2_6_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); - static GlobalProperty compat_props[] = { - { /* end of list */ } - }; mc->desc = "QEMU 2.6 ARM Virtual Machine"; mc->alias = "virt"; - mc->compat_props = compat_props; } static const TypeInfo machvirt_info = { diff --git a/hw/core/machine.c b/hw/core/machine.c index 0bb96ad457..ccdd5fa3e7 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -571,6 +571,15 @@ bool machine_mem_merge(MachineState *machine) return machine->mem_merge; } +static void machine_class_finalize(ObjectClass *klass, void *data) +{ + MachineClass *mc = MACHINE_CLASS(klass); + + if (mc->compat_props) { + g_array_free(mc->compat_props, true); + } +} + static const TypeInfo machine_info = { .name = TYPE_MACHINE, .parent = TYPE_OBJECT, @@ -578,6 +587,7 @@ static const TypeInfo machine_info = { .class_size = sizeof(MachineClass), .class_init = machine_class_init, .class_base_init = machine_class_base_init, + .class_finalize = machine_class_finalize, .instance_size = sizeof(MachineState), .instance_init = machine_initfn, .instance_finalize = machine_finalize, diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 7f50116bc7..32918bb294 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -582,7 +582,6 @@ DEFINE_I440FX_MACHINE(v1_4, "pc-i440fx-1.4", pc_compat_1_4, #define PC_COMPAT_1_3 \ - PC_COMPAT_1_4 \ {\ .driver = "usb-tablet",\ .property = "usb_version",\ @@ -614,7 +613,6 @@ DEFINE_I440FX_MACHINE(v1_3, "pc-1.3", pc_compat_1_3, #define PC_COMPAT_1_2 \ - PC_COMPAT_1_3 \ {\ .driver = "nec-usb-xhci",\ .property = "msi",\ @@ -653,7 +651,6 @@ DEFINE_I440FX_MACHINE(v1_2, "pc-1.2", pc_compat_1_2, #define PC_COMPAT_1_1 \ - PC_COMPAT_1_2 \ {\ .driver = "virtio-scsi-pci",\ .property = "hotplug",\ @@ -696,7 +693,6 @@ DEFINE_I440FX_MACHINE(v1_1, "pc-1.1", pc_compat_1_2, #define PC_COMPAT_1_0 \ - PC_COMPAT_1_1 \ {\ .driver = TYPE_ISA_FDC,\ .property = "check_media_rate",\ @@ -726,14 +722,10 @@ DEFINE_I440FX_MACHINE(v1_0, "pc-1.0", pc_compat_1_2, pc_i440fx_1_0_machine_options); -#define PC_COMPAT_0_15 \ - PC_COMPAT_1_0 - static void pc_i440fx_0_15_machine_options(MachineClass *m) { pc_i440fx_1_0_machine_options(m); m->hw_version = "0.15"; - SET_MACHINE_COMPAT(m, PC_COMPAT_0_15); } DEFINE_I440FX_MACHINE(v0_15, "pc-0.15", pc_compat_1_2, @@ -741,7 +733,6 @@ DEFINE_I440FX_MACHINE(v0_15, "pc-0.15", pc_compat_1_2, #define PC_COMPAT_0_14 \ - PC_COMPAT_0_15 \ {\ .driver = "virtio-blk-pci",\ .property = "event_idx",\ @@ -780,7 +771,6 @@ DEFINE_I440FX_MACHINE(v0_14, "pc-0.14", pc_compat_1_2, #define PC_COMPAT_0_13 \ - PC_COMPAT_0_14 \ {\ .driver = TYPE_PCI_DEVICE,\ .property = "command_serr_enable",\ @@ -817,7 +807,6 @@ DEFINE_I440FX_MACHINE(v0_13, "pc-0.13", pc_compat_0_13, #define PC_COMPAT_0_12 \ - PC_COMPAT_0_13 \ {\ .driver = "virtio-serial-pci",\ .property = "max_ports",\ @@ -852,7 +841,6 @@ DEFINE_I440FX_MACHINE(v0_12, "pc-0.12", pc_compat_0_13, #define PC_COMPAT_0_11 \ - PC_COMPAT_0_12 \ {\ .driver = "virtio-blk-pci",\ .property = "vectors",\ @@ -883,7 +871,6 @@ DEFINE_I440FX_MACHINE(v0_11, "pc-0.11", pc_compat_0_13, #define PC_COMPAT_0_10 \ - PC_COMPAT_0_11 \ {\ .driver = "virtio-blk-pci",\ .property = "class",\ diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index de1de1d067..add68acfef 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2387,7 +2387,6 @@ DEFINE_SPAPR_MACHINE(2_5, "2.5", false); * pseries-2.4 */ #define SPAPR_COMPAT_2_4 \ - SPAPR_COMPAT_2_5 \ HW_COMPAT_2_4 static void spapr_machine_2_4_instance_options(MachineState *machine) @@ -2410,7 +2409,6 @@ DEFINE_SPAPR_MACHINE(2_4, "2.4", false); * pseries-2.3 */ #define SPAPR_COMPAT_2_3 \ - SPAPR_COMPAT_2_4 \ HW_COMPAT_2_3 \ {\ .driver = "spapr-pci-host-bridge",\ @@ -2438,7 +2436,6 @@ DEFINE_SPAPR_MACHINE(2_3, "2.3", false); */ #define SPAPR_COMPAT_2_2 \ - SPAPR_COMPAT_2_3 \ HW_COMPAT_2_2 \ {\ .driver = TYPE_SPAPR_PCI_HOST_BRIDGE,\ @@ -2463,7 +2460,6 @@ DEFINE_SPAPR_MACHINE(2_2, "2.2", false); * pseries-2.1 */ #define SPAPR_COMPAT_2_1 \ - SPAPR_COMPAT_2_2 \ HW_COMPAT_2_1 static void spapr_machine_2_1_instance_options(MachineState *machine) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 18bbbfbbe2..95ff5e35ae 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -330,7 +330,6 @@ static const TypeInfo ccw_machine_info = { HW_COMPAT_2_5 #define CCW_COMPAT_2_4 \ - CCW_COMPAT_2_5 \ HW_COMPAT_2_4 \ {\ .driver = TYPE_S390_SKEYS,\ diff --git a/include/hw/boards.h b/include/hw/boards.h index f968a256dc..d268bd00a9 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -114,7 +114,7 @@ struct MachineClass { const char *default_machine_opts; const char *default_boot_order; const char *default_display; - GlobalProperty *compat_props; + GArray *compat_props; const char *hw_version; ram_addr_t default_ram_size; bool option_rom_has_mr; @@ -186,11 +186,18 @@ struct MachineState { #define SET_MACHINE_COMPAT(m, COMPAT) \ do { \ + int i; \ static GlobalProperty props[] = { \ COMPAT \ { /* end of list */ } \ }; \ - (m)->compat_props = props; \ + if (!m->compat_props) { \ + m->compat_props = g_array_new(false, false, sizeof(void *)); \ + } \ + for (i = 0; props[i].driver != NULL; i++) { \ + GlobalProperty *prop = &props[i]; \ + g_array_append_val(m->compat_props, prop); \ + } \ } while (0) #endif diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 96f0b66c77..367b6dbf0e 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -360,7 +360,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); HW_COMPAT_2_5 #define PC_COMPAT_2_4 \ - PC_COMPAT_2_5 \ HW_COMPAT_2_4 \ {\ .driver = "Haswell-" TYPE_X86_CPU,\ @@ -431,7 +430,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); #define PC_COMPAT_2_3 \ - PC_COMPAT_2_4 \ HW_COMPAT_2_3 \ {\ .driver = TYPE_X86_CPU,\ @@ -512,7 +510,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); }, #define PC_COMPAT_2_2 \ - PC_COMPAT_2_3 \ HW_COMPAT_2_2 \ {\ .driver = "kvm64" "-" TYPE_X86_CPU,\ @@ -606,7 +603,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); }, #define PC_COMPAT_2_1 \ - PC_COMPAT_2_2 \ HW_COMPAT_2_1 \ {\ .driver = "coreduo" "-" TYPE_X86_CPU,\ @@ -620,7 +616,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); }, #define PC_COMPAT_2_0 \ - PC_COMPAT_2_1 \ {\ .driver = "virtio-scsi-pci",\ .property = "any_layout",\ @@ -680,7 +675,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); }, #define PC_COMPAT_1_7 \ - PC_COMPAT_2_0 \ {\ .driver = TYPE_USB_DEVICE,\ .property = "msos-desc",\ @@ -698,7 +692,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); }, #define PC_COMPAT_1_6 \ - PC_COMPAT_1_7 \ {\ .driver = "e1000",\ .property = "mitigation",\ @@ -722,7 +715,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); }, #define PC_COMPAT_1_5 \ - PC_COMPAT_1_6 \ {\ .driver = "Conroe-" TYPE_X86_CPU,\ .property = "model",\ @@ -766,7 +758,6 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); }, #define PC_COMPAT_1_4 \ - PC_COMPAT_1_5 \ {\ .driver = "scsi-hd",\ .property = "discard_granularity",\ diff --git a/vl.c b/vl.c index 88618624f8..0228843822 100644 --- a/vl.c +++ b/vl.c @@ -4473,7 +4473,11 @@ int main(int argc, char **argv, char **envp) } if (machine_class->compat_props) { - qdev_prop_register_global_list(machine_class->compat_props); + GlobalProperty *p; + for (i = 0; i < machine_class->compat_props->len; i++) { + p = g_array_index(machine_class->compat_props, GlobalProperty *, i); + qdev_prop_register_global(p); + } } qemu_add_globals(); From 7b1ee0f2b732029c7826125f6b6eb6e1e2d4fd22 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Thu, 12 May 2016 11:09:59 -0300 Subject: [PATCH 19/21] vl: Use &error_fatal when parsing VNC options Signed-off-by: Eduardo Habkost --- vl.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/vl.c b/vl.c index 0228843822..bc229030f6 100644 --- a/vl.c +++ b/vl.c @@ -2151,11 +2151,7 @@ static DisplayType select_display(const char *p) #endif } else if (strstart(p, "vnc", &opts)) { if (*opts == '=') { - Error *err = NULL; - if (vnc_parse(opts + 1, &err) == NULL) { - error_report_err(err); - exit(1); - } + vnc_parse(opts + 1, &error_fatal); } else { error_report("VNC requires a display argument vnc="); exit(1); @@ -3709,15 +3705,8 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_vnc: - { - Error *local_err = NULL; - - if (vnc_parse(optarg, &local_err) == NULL) { - error_report_err(local_err); - exit(1); - } + vnc_parse(optarg, &error_fatal); break; - } case QEMU_OPTION_no_acpi: acpi_enabled = 0; break; From 822ac12df0387b2d2eb1ff8fc6cddb46aa0c3867 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Thu, 12 May 2016 11:10:00 -0300 Subject: [PATCH 20/21] vl: Use &error_fatal when parsing monitor options Signed-off-by: Eduardo Habkost --- vl.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/vl.c b/vl.c index bc229030f6..b1562d8280 100644 --- a/vl.c +++ b/vl.c @@ -2404,7 +2404,6 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) static void monitor_parse(const char *optarg, const char *mode, bool pretty) { static int monitor_device_index = 0; - Error *local_err = NULL; QemuOpts *opts; const char *p; char label[32]; @@ -2425,11 +2424,7 @@ static void monitor_parse(const char *optarg, const char *mode, bool pretty) } } - opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &local_err); - if (!opts) { - error_report_err(local_err); - exit(1); - } + opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); qemu_opt_set(opts, "mode", mode, &error_abort); qemu_opt_set(opts, "chardev", label, &error_abort); qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); From e8f2d2722eb84a809697e82c762d39c8c13f22f6 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Thu, 12 May 2016 11:10:04 -0300 Subject: [PATCH 21/21] Use &error_fatal when initializing crypto on qemu-{img,io,nbd} In addition to making the code simpler, this will replace the long error messages: cannot initialize crypto: Unable to initialize GNUTLS library: [...] cannot initialize crypto: Unable to initialize gcrypt with shorter messages: Unable to initialize GNUTLS library: [...] Unable to initialize gcrypt Signed-off-by: Eduardo Habkost --- qemu-img.c | 5 +---- qemu-io.c | 5 +---- qemu-nbd.c | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 47923663be..7ed8ef21cb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3492,10 +3492,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - if (qcrypto_init(&local_error) < 0) { - error_reportf_err(local_error, "cannot initialize crypto: "); - exit(1); - } + qcrypto_init(&error_fatal); module_call_init(MODULE_INIT_QOM); bdrv_init(); diff --git a/qemu-io.c b/qemu-io.c index 5ef3ef7f35..d977a6e553 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -466,10 +466,7 @@ int main(int argc, char **argv) progname = basename(argv[0]); qemu_init_exec_dir(argv[0]); - if (qcrypto_init(&local_error) < 0) { - error_reportf_err(local_error, "cannot initialize crypto: "); - exit(1); - } + qcrypto_init(&error_fatal); module_call_init(MODULE_INIT_QOM); qemu_add_opts(&qemu_object_opts); diff --git a/qemu-nbd.c b/qemu-nbd.c index d59b187780..6554f0ab65 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -527,10 +527,7 @@ int main(int argc, char **argv) sa_sigterm.sa_handler = termsig_handler; sigaction(SIGTERM, &sa_sigterm, NULL); - if (qcrypto_init(&local_err) < 0) { - error_reportf_err(local_err, "cannot initialize crypto: "); - exit(1); - } + qcrypto_init(&error_fatal); module_call_init(MODULE_INIT_QOM); qemu_add_opts(&qemu_object_opts);