From patchwork Wed Nov 11 21:27:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 543103 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 573F91402D1 for ; Thu, 12 Nov 2015 08:28:47 +1100 (AEDT) Received: from localhost ([::1]:43090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zwcwf-0000Dt-Bl for incoming@patchwork.ozlabs.org; Wed, 11 Nov 2015 16:28:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zwcw6-0007dx-4z for qemu-devel@nongnu.org; Wed, 11 Nov 2015 16:28:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zwcw5-00006W-3a for qemu-devel@nongnu.org; Wed, 11 Nov 2015 16:28:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43989) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zwcw4-00006Q-TM for qemu-devel@nongnu.org; Wed, 11 Nov 2015 16:28:09 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id A43F568E for ; Wed, 11 Nov 2015 21:28:08 +0000 (UTC) Received: from localhost (ovpn-113-50.phx2.redhat.com [10.3.113.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tABLS5J7029137; Wed, 11 Nov 2015 16:28:06 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 11 Nov 2015 19:27:53 -0200 Message-Id: <1447277273-26151-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1447277273-26151-1-git-send-email-ehabkost@redhat.com> References: <1447277273-26151-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini Subject: [Qemu-devel] [PATCH 2/2] vl: Replace *_vga_available() functions with class_names field X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Instead of requiring a separate function for each VGA interface, just enumerate the corresponding class names on struct VGAInterfaceInfo. Signed-off-by: Eduardo Habkost Reviewed-by: Eric Blake --- vl.c | 70 +++++++++++++++++++++++--------------------------------------------- 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/vl.c b/vl.c index a5dd9a6..c899adf 100644 --- a/vl.c +++ b/vl.c @@ -1965,46 +1965,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] = { @@ -2014,43 +1980,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; @@ -2059,7 +2035,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); } @@ -4503,9 +4479,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"; } }