From patchwork Sun May 31 18:35:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 478718 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 3029C14010F for ; Mon, 1 Jun 2015 05:03:49 +1000 (AEST) Received: from localhost ([::1]:43146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yz8WR-0004sd-DY for incoming@patchwork.ozlabs.org; Sun, 31 May 2015 15:03:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yz85g-0007Iv-Aw for qemu-devel@nongnu.org; Sun, 31 May 2015 14:36:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yz85b-00050u-Ul for qemu-devel@nongnu.org; Sun, 31 May 2015 14:36:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yz85b-0004zp-Gb for qemu-devel@nongnu.org; Sun, 31 May 2015 14:36:03 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 26F1C2E6DB4; Sun, 31 May 2015 18:36:03 +0000 (UTC) Received: from redhat.com (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t4VIa0Iu016783; Sun, 31 May 2015 14:36:00 -0400 Date: Sun, 31 May 2015 20:35:59 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1433097192-8988-27-git-send-email-mst@redhat.com> References: <1433097192-8988-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1433097192-8988-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini Subject: [Qemu-devel] [PULL 26/57] pc: Generate init functions with a macro 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 From: Eduardo Habkost All pc-i440fx and pc-q35 init functions simply call the corresponding compat function and then call the main init function. Use a macro to generate that code. Signed-off-by: Eduardo Habkost Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/pc_piix.c | 154 +++++++++++++++++------------------------------------- hw/i386/pc_q35.c | 92 ++++++++++---------------------- 2 files changed, 76 insertions(+), 170 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 01f938f..e77486c 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -413,18 +413,6 @@ static void pc_compat_1_2(MachineState *machine) x86_cpu_compat_kvm_no_autoenable(FEAT_KVM, 1 << KVM_FEATURE_PV_EOI); } -static void pc_init_pci_2_3(MachineState *machine) -{ - pc_compat_2_3(machine); - pc_init1(machine); -} - -static void pc_init_pci_2_2(MachineState *machine) -{ - pc_compat_2_2(machine); - pc_init1(machine); -} - /* PC compat function for pc-0.10 to pc-0.13 */ static void pc_compat_0_13(MachineState *machine) { @@ -432,62 +420,6 @@ static void pc_compat_0_13(MachineState *machine) kvmclock_enabled = false; } -static void pc_init_pci_2_1(MachineState *machine) -{ - pc_compat_2_1(machine); - pc_init1(machine); -} - -static void pc_init_pci_2_0(MachineState *machine) -{ - pc_compat_2_0(machine); - pc_init1(machine); -} - -static void pc_init_pci_1_7(MachineState *machine) -{ - pc_compat_1_7(machine); - pc_init1(machine); -} - -static void pc_init_pci_1_6(MachineState *machine) -{ - pc_compat_1_6(machine); - pc_init1(machine); -} - -static void pc_init_pci_1_5(MachineState *machine) -{ - pc_compat_1_5(machine); - pc_init1(machine); -} - -static void pc_init_pci_1_4(MachineState *machine) -{ - pc_compat_1_4(machine); - pc_init1(machine); -} - -static void pc_init_pci_1_3(MachineState *machine) -{ - pc_compat_1_3(machine); - pc_init1(machine); -} - -/* PC machine init function for pc-0.14 to pc-1.2 */ -static void pc_init_pci_1_2(MachineState *machine) -{ - pc_compat_1_2(machine); - pc_init1(machine); -} - -/* PC init function for pc-0.10 to pc-0.13 */ -static void pc_init_pci_no_kvmclock(MachineState *machine) -{ - pc_compat_0_13(machine); - pc_init1(machine); -} - static void pc_init_isa(MachineState *machine) { pci_enabled = false; @@ -520,6 +452,16 @@ static void pc_xen_hvm_init(MachineState *machine) } #endif +#define DEFINE_I440FX_MACHINE(suffix, name, compatfn, optionfn) \ + static void pc_init_##suffix(MachineState *machine) \ + { \ + void (*compat)(MachineState *m) = (compatfn); \ + if (compat) { \ + compat(machine); \ + } \ + pc_init1(machine); \ + } \ + DEFINE_PC_MACHINE(suffix, name, pc_init_##suffix, optionfn) static void pc_i440fx_machine_options(MachineClass *m) { @@ -538,8 +480,8 @@ static void pc_i440fx_2_4_machine_options(MachineClass *m) m->is_default = 1; } -DEFINE_PC_MACHINE(v2_4, "pc-i440fx-2.4", pc_init1, - pc_i440fx_2_4_machine_options) +DEFINE_I440FX_MACHINE(v2_4, "pc-i440fx-2.4", NULL, + pc_i440fx_2_4_machine_options) static void pc_i440fx_2_3_machine_options(MachineClass *m) @@ -550,8 +492,8 @@ static void pc_i440fx_2_3_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_2_3); } -DEFINE_PC_MACHINE(v2_3, "pc-i440fx-2.3", pc_init_pci_2_3, - pc_i440fx_2_3_machine_options); +DEFINE_I440FX_MACHINE(v2_3, "pc-i440fx-2.3", pc_compat_2_3, + pc_i440fx_2_3_machine_options); static void pc_i440fx_2_2_machine_options(MachineClass *m) @@ -560,8 +502,8 @@ static void pc_i440fx_2_2_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_2_2); } -DEFINE_PC_MACHINE(v2_2, "pc-i440fx-2.2", pc_init_pci_2_2, - pc_i440fx_2_2_machine_options); +DEFINE_I440FX_MACHINE(v2_2, "pc-i440fx-2.2", pc_compat_2_2, + pc_i440fx_2_2_machine_options); static void pc_i440fx_2_1_machine_options(MachineClass *m) @@ -571,8 +513,8 @@ static void pc_i440fx_2_1_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_2_1); } -DEFINE_PC_MACHINE(v2_1, "pc-i440fx-2.1", pc_init_pci_2_1, - pc_i440fx_2_1_machine_options); +DEFINE_I440FX_MACHINE(v2_1, "pc-i440fx-2.1", pc_compat_2_1, + pc_i440fx_2_1_machine_options); @@ -582,8 +524,8 @@ static void pc_i440fx_2_0_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_2_0); } -DEFINE_PC_MACHINE(v2_0, "pc-i440fx-2.0", pc_init_pci_2_0, - pc_i440fx_2_0_machine_options); +DEFINE_I440FX_MACHINE(v2_0, "pc-i440fx-2.0", pc_compat_2_0, + pc_i440fx_2_0_machine_options); static void pc_i440fx_1_7_machine_options(MachineClass *m) @@ -593,8 +535,8 @@ static void pc_i440fx_1_7_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_7); } -DEFINE_PC_MACHINE(v1_7, "pc-i440fx-1.7", pc_init_pci_1_7, - pc_i440fx_1_7_machine_options); +DEFINE_I440FX_MACHINE(v1_7, "pc-i440fx-1.7", pc_compat_1_7, + pc_i440fx_1_7_machine_options); static void pc_i440fx_1_6_machine_options(MachineClass *m) @@ -603,8 +545,8 @@ static void pc_i440fx_1_6_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_6); } -DEFINE_PC_MACHINE(v1_6, "pc-i440fx-1.6", pc_init_pci_1_6, - pc_i440fx_1_6_machine_options); +DEFINE_I440FX_MACHINE(v1_6, "pc-i440fx-1.6", pc_compat_1_6, + pc_i440fx_1_6_machine_options); static void pc_i440fx_1_5_machine_options(MachineClass *m) @@ -613,8 +555,8 @@ static void pc_i440fx_1_5_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_5); } -DEFINE_PC_MACHINE(v1_5, "pc-i440fx-1.5", pc_init_pci_1_5, - pc_i440fx_1_5_machine_options); +DEFINE_I440FX_MACHINE(v1_5, "pc-i440fx-1.5", pc_compat_1_5, + pc_i440fx_1_5_machine_options); static void pc_i440fx_1_4_machine_options(MachineClass *m) @@ -624,8 +566,8 @@ static void pc_i440fx_1_4_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_4); } -DEFINE_PC_MACHINE(v1_4, "pc-i440fx-1.4", pc_init_pci_1_4, - pc_i440fx_1_4_machine_options); +DEFINE_I440FX_MACHINE(v1_4, "pc-i440fx-1.4", pc_compat_1_4, + pc_i440fx_1_4_machine_options); #define PC_COMPAT_1_3 \ @@ -655,8 +597,8 @@ static void pc_i440fx_1_3_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_3); } -DEFINE_PC_MACHINE(v1_3, "pc-1.3", pc_init_pci_1_3, - pc_i440fx_1_3_machine_options); +DEFINE_I440FX_MACHINE(v1_3, "pc-1.3", pc_compat_1_3, + pc_i440fx_1_3_machine_options); #define PC_COMPAT_1_2 \ @@ -693,8 +635,8 @@ static void pc_i440fx_1_2_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_2); } -DEFINE_PC_MACHINE(v1_2, "pc-1.2", pc_init_pci_1_2, - pc_i440fx_1_2_machine_options); +DEFINE_I440FX_MACHINE(v1_2, "pc-1.2", pc_compat_1_2, + pc_i440fx_1_2_machine_options); #define PC_COMPAT_1_1 \ @@ -735,8 +677,8 @@ static void pc_i440fx_1_1_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_1); } -DEFINE_PC_MACHINE(v1_1, "pc-1.1", pc_init_pci_1_2, - pc_i440fx_1_1_machine_options); +DEFINE_I440FX_MACHINE(v1_1, "pc-1.1", pc_compat_1_2, + pc_i440fx_1_1_machine_options); #define PC_COMPAT_1_0 \ @@ -766,8 +708,8 @@ static void pc_i440fx_1_0_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_0); } -DEFINE_PC_MACHINE(v1_0, "pc-1.0", pc_init_pci_1_2, - pc_i440fx_1_0_machine_options); +DEFINE_I440FX_MACHINE(v1_0, "pc-1.0", pc_compat_1_2, + pc_i440fx_1_0_machine_options); #define PC_COMPAT_0_15 \ @@ -780,8 +722,8 @@ static void pc_i440fx_0_15_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_0_15); } -DEFINE_PC_MACHINE(v0_15, "pc-0.15", pc_init_pci_1_2, - pc_i440fx_0_15_machine_options); +DEFINE_I440FX_MACHINE(v0_15, "pc-0.15", pc_compat_1_2, + pc_i440fx_0_15_machine_options); #define PC_COMPAT_0_14 \ @@ -819,8 +761,8 @@ static void pc_i440fx_0_14_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_0_14); } -DEFINE_PC_MACHINE(v0_14, "pc-0.14", pc_init_pci_1_2, - pc_i440fx_0_14_machine_options); +DEFINE_I440FX_MACHINE(v0_14, "pc-0.14", pc_compat_1_2, + pc_i440fx_0_14_machine_options); #define PC_COMPAT_0_13 \ @@ -854,8 +796,8 @@ static void pc_i440fx_0_13_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_0_13); } -DEFINE_PC_MACHINE(v0_13, "pc-0.13", pc_init_pci_no_kvmclock, - pc_i440fx_0_13_machine_options); +DEFINE_I440FX_MACHINE(v0_13, "pc-0.13", pc_compat_0_13, + pc_i440fx_0_13_machine_options); #define PC_COMPAT_0_12 \ @@ -889,8 +831,8 @@ static void pc_i440fx_0_12_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_0_12); } -DEFINE_PC_MACHINE(v0_12, "pc-0.12", pc_init_pci_no_kvmclock, - pc_i440fx_0_12_machine_options); +DEFINE_I440FX_MACHINE(v0_12, "pc-0.12", pc_compat_0_13, + pc_i440fx_0_12_machine_options); #define PC_COMPAT_0_11 \ @@ -920,8 +862,8 @@ static void pc_i440fx_0_11_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_0_11); } -DEFINE_PC_MACHINE(v0_11, "pc-0.11", pc_init_pci_no_kvmclock, - pc_i440fx_0_11_machine_options); +DEFINE_I440FX_MACHINE(v0_11, "pc-0.11", pc_compat_0_13, + pc_i440fx_0_11_machine_options); #define PC_COMPAT_0_10 \ @@ -955,8 +897,8 @@ static void pc_i440fx_0_10_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_0_10); } -DEFINE_PC_MACHINE(v0_10, "pc-0.10", pc_init_pci_no_kvmclock, - pc_i440fx_0_10_machine_options); +DEFINE_I440FX_MACHINE(v0_10, "pc-0.10", pc_compat_0_13, + pc_i440fx_0_10_machine_options); static void isapc_machine_options(MachineClass *m) diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 6a9fe58..68b4867 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -366,53 +366,17 @@ static void pc_compat_1_4(MachineState *machine) x86_cpu_compat_set_features("Westmere", FEAT_1_ECX, 0, CPUID_EXT_PCLMULQDQ); } -static void pc_q35_init_2_3(MachineState *machine) -{ - pc_compat_2_3(machine); - pc_q35_init(machine); -} - -static void pc_q35_init_2_2(MachineState *machine) -{ - pc_compat_2_2(machine); - pc_q35_init(machine); -} - -static void pc_q35_init_2_1(MachineState *machine) -{ - pc_compat_2_1(machine); - pc_q35_init(machine); -} - -static void pc_q35_init_2_0(MachineState *machine) -{ - pc_compat_2_0(machine); - pc_q35_init(machine); -} +#define DEFINE_Q35_MACHINE(suffix, name, compatfn, optionfn) \ + static void pc_init_##suffix(MachineState *machine) \ + { \ + void (*compat)(MachineState *m) = (compatfn); \ + if (compat) { \ + compat(machine); \ + } \ + pc_q35_init(machine); \ + } \ + DEFINE_PC_MACHINE(suffix, name, pc_init_##suffix, optionfn) -static void pc_q35_init_1_7(MachineState *machine) -{ - pc_compat_1_7(machine); - pc_q35_init(machine); -} - -static void pc_q35_init_1_6(MachineState *machine) -{ - pc_compat_1_6(machine); - pc_q35_init(machine); -} - -static void pc_q35_init_1_5(MachineState *machine) -{ - pc_compat_1_5(machine); - pc_q35_init(machine); -} - -static void pc_q35_init_1_4(MachineState *machine) -{ - pc_compat_1_4(machine); - pc_q35_init(machine); -} static void pc_q35_machine_options(MachineClass *m) { @@ -431,8 +395,8 @@ static void pc_q35_2_4_machine_options(MachineClass *m) m->alias = "q35"; } -DEFINE_PC_MACHINE(v2_4, "pc-q35-2.4", pc_q35_init, - pc_q35_2_4_machine_options); +DEFINE_Q35_MACHINE(v2_4, "pc-q35-2.4", NULL, + pc_q35_2_4_machine_options); static void pc_q35_2_3_machine_options(MachineClass *m) @@ -442,8 +406,8 @@ static void pc_q35_2_3_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_2_3); } -DEFINE_PC_MACHINE(v2_3, "pc-q35-2.3", pc_q35_init_2_3, - pc_q35_2_3_machine_options); +DEFINE_Q35_MACHINE(v2_3, "pc-q35-2.3", pc_compat_2_3, + pc_q35_2_3_machine_options); static void pc_q35_2_2_machine_options(MachineClass *m) @@ -452,8 +416,8 @@ static void pc_q35_2_2_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_2_2); } -DEFINE_PC_MACHINE(v2_2, "pc-q35-2.2", pc_q35_init_2_2, - pc_q35_2_2_machine_options); +DEFINE_Q35_MACHINE(v2_2, "pc-q35-2.2", pc_compat_2_2, + pc_q35_2_2_machine_options); static void pc_q35_2_1_machine_options(MachineClass *m) @@ -463,8 +427,8 @@ static void pc_q35_2_1_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_2_1); } -DEFINE_PC_MACHINE(v2_1, "pc-q35-2.1", pc_q35_init_2_1, - pc_q35_2_1_machine_options); +DEFINE_Q35_MACHINE(v2_1, "pc-q35-2.1", pc_compat_2_1, + pc_q35_2_1_machine_options); static void pc_q35_2_0_machine_options(MachineClass *m) @@ -473,8 +437,8 @@ static void pc_q35_2_0_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_2_0); } -DEFINE_PC_MACHINE(v2_0, "pc-q35-2.0", pc_q35_init_2_0, - pc_q35_2_0_machine_options); +DEFINE_Q35_MACHINE(v2_0, "pc-q35-2.0", pc_compat_2_0, + pc_q35_2_0_machine_options); static void pc_q35_1_7_machine_options(MachineClass *m) @@ -484,8 +448,8 @@ static void pc_q35_1_7_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_7); } -DEFINE_PC_MACHINE(v1_7, "pc-q35-1.7", pc_q35_init_1_7, - pc_q35_1_7_machine_options); +DEFINE_Q35_MACHINE(v1_7, "pc-q35-1.7", pc_compat_1_7, + pc_q35_1_7_machine_options); static void pc_q35_1_6_machine_options(MachineClass *m) @@ -494,8 +458,8 @@ static void pc_q35_1_6_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_6); } -DEFINE_PC_MACHINE(v1_6, "pc-q35-1.6", pc_q35_init_1_6, - pc_q35_1_6_machine_options); +DEFINE_Q35_MACHINE(v1_6, "pc-q35-1.6", pc_compat_1_6, + pc_q35_1_6_machine_options); static void pc_q35_1_5_machine_options(MachineClass *m) @@ -504,8 +468,8 @@ static void pc_q35_1_5_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_5); } -DEFINE_PC_MACHINE(v1_5, "pc-q35-1.5", pc_q35_init_1_5, - pc_q35_1_5_machine_options); +DEFINE_Q35_MACHINE(v1_5, "pc-q35-1.5", pc_compat_1_5, + pc_q35_1_5_machine_options); static void pc_q35_1_4_machine_options(MachineClass *m) @@ -515,5 +479,5 @@ static void pc_q35_1_4_machine_options(MachineClass *m) SET_MACHINE_COMPAT(m, PC_COMPAT_1_4); } -DEFINE_PC_MACHINE(v1_4, "pc-q35-1.4", pc_q35_init_1_4, - pc_q35_1_4_machine_options); +DEFINE_Q35_MACHINE(v1_4, "pc-q35-1.4", pc_compat_1_4, + pc_q35_1_4_machine_options);