From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzOkz-0007PX-Se for qemu-devel@nongnu.org; Mon, 01 Jun 2015 08:23:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YzOkv-0007c5-Fh for qemu-devel@nongnu.org; Mon, 01 Jun 2015 08:23:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzOkv-0007c1-74 for qemu-devel@nongnu.org; Mon, 01 Jun 2015 08:23:49 -0400 Date: Mon, 1 Jun 2015 14:23:45 +0200 From: "Michael S. Tsirkin" Message-ID: <1433161230-29421-27-git-send-email-mst@redhat.com> References: <1433161230-29421-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1433161230-29421-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL v2 26/60] pc: Generate init functions with a macro List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini 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); -- MST