qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel@redhat.com>,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 04/21] vl: Replace *_vga_available() functions with class_names field
Date: Fri, 20 May 2016 17:28:24 -0300	[thread overview]
Message-ID: <1463776121-13529-5-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1463776121-13529-1-git-send-email-ehabkost@redhat.com>

Instead of requiring a separate function for each VGA interface,
just enumerate the corresponding class names on struct
VGAInterfaceInfo.

Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 vl.c | 70 +++++++++++++++++++++++---------------------------------------------
 1 file changed, 23 insertions(+), 47 deletions(-)

diff --git a/vl.c b/vl.c
index ac5db24..d309ff7 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";
         }
     }
-- 
2.5.5

  parent reply	other threads:[~2016-05-20 22:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-20 20:28 [Qemu-devel] [PULL 00/21] Machine Core queue, 2016-05-20 Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 01/21] pc-dimm: correct comment of MemoryHotplugState Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 02/21] vl: Use exit(1) when requested VGA interface is unavailable Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 03/21] vl: Table-based select_vgahw() Eduardo Habkost
2016-05-20 20:28 ` Eduardo Habkost [this message]
2016-05-20 20:28 ` [Qemu-devel] [PULL 05/21] vl: Add DT_COCOA DisplayType value Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 06/21] vnc: Initialization stubs Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 07/21] curses: curses_display_init() stub Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 08/21] sdl: Initialization stubs Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 09/21] cocoa: cocoa_display_init() stub Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 10/21] gtk: Initialization stubs Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 11/21] spice: Initialization stubs on qemu-spice.h Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 12/21] milkymist: Move DT_NOGRAPHIC check outside milkymist_tmu2_create() Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 13/21] vl: Replace DT_NOGRAPHIC with machine option Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 14/21] vl: Make display_type a local variable Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 15/21] vl: Move DisplayType typedef to vl.c Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 16/21] vl: Make display_remote a local variable Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 17/21] vl: Simplify global property registration Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 18/21] machine: add properties to compat_props incrementaly Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 19/21] vl: Use &error_fatal when parsing VNC options Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 20/21] vl: Use &error_fatal when parsing monitor options Eduardo Habkost
2016-05-20 20:28 ` [Qemu-devel] [PULL 21/21] Use &error_fatal when initializing crypto on qemu-{img, io, nbd} Eduardo Habkost
2016-05-23 10:27 ` [Qemu-devel] [PULL 00/21] Machine Core queue, 2016-05-20 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463776121-13529-5-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).