From nobody Mon Apr 29 00:09:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148699693757688.24637413899927; Mon, 13 Feb 2017 06:42:17 -0800 (PST) Received: from localhost ([::1]:57295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdHpV-0003DK-Sb for importer@patchew.org; Mon, 13 Feb 2017 09:42:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60573) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdHcK-0008Hq-7w for qemu-devel@nongnu.org; Mon, 13 Feb 2017 09:28:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdHcI-0005Id-Ov for qemu-devel@nongnu.org; Mon, 13 Feb 2017 09:28:36 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48495) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdHcF-0005C4-3e; Mon, 13 Feb 2017 09:28:31 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1cdHc5-00014d-2h; Mon, 13 Feb 2017 14:28:21 +0000 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 14:28:16 +0000 Message-Id: <1486996099-15820-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486996099-15820-1-git-send-email-peter.maydell@linaro.org> References: <1486996099-15820-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 1/4] cpu: add cpu_generic_new() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Davidsaver Add a new API cpu_generic_new() which creates a QOM CPU object (including calling the CPU class parse_features method) but does not realize it, and reimplement cpu_generic_init() to simply call cpu_generic_new() and then immediately realize. the CPU. The motivation for this is that there is currently no way for board code to take advantage of the cpu_generic_init() convenience function if it needs to set QOM properties on the created CPU. Instead it has to do it all manually, which is prone to bugs like that fixed in commit 00909b585861 (where a board code forgot to call parse_features which meant that command line +feature,-feature flags were ignored). Signed-off-by: Michael Davidsaver [PMM: renamed new function to cpu_generic_new(), rewrote commit message] Signed-off-by: Peter Maydell --- include/qom/cpu.h | 17 +++++++++++++++++ qom/cpu.c | 27 ++++++++++++++++++--------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 45bcf21..e900586 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -599,11 +599,28 @@ void cpu_reset(CPUState *cpu); ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model= ); =20 /** + * cpu_generic_new: + * @typename: The CPU base type. + * @cpu_model: The model string including optional parameters. + * + * Instantiates a CPU, processes optional parameters but does not realize = it. + * This is the recommended way to create a CPU object which needs to be + * configured by then setting QOM properties on it. The configured CPU can + * then be realized in the usual way by calling + * object_property_set_bool(cpuobj, true, "realized", &err); + * + * Returns: A #CPUState or %NULL if an error occurred. + */ +CPUState *cpu_generic_new(const char *typename, const char *cpu_model); + +/** * cpu_generic_init: * @typename: The CPU base type. * @cpu_model: The model string including optional parameters. * * Instantiates a CPU, processes optional parameters and realizes the CPU. + * This is equivalent to calling cpu_generic_new() and then immediately + * realizing the CPU object. * * Returns: A #CPUState or %NULL if an error occurred. */ diff --git a/qom/cpu.c b/qom/cpu.c index 0e19b1a..a783aec 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -47,6 +47,22 @@ bool cpu_exists(int64_t id) =20 CPUState *cpu_generic_init(const char *typename, const char *cpu_model) { + CPUState *cpu =3D cpu_generic_new(typename, cpu_model); + if (cpu) { + Error *err =3D NULL; + object_property_set_bool(OBJECT(cpu), true, "realized", &err); + + if (err !=3D NULL) { + error_report_err(err); + object_unref(OBJECT(cpu)); + return NULL; + } + } + return cpu; +} + +CPUState *cpu_generic_new(const char *typename, const char *cpu_model) +{ char *str, *name, *featurestr; CPUState *cpu =3D NULL; ObjectClass *oc; @@ -70,19 +86,12 @@ CPUState *cpu_generic_init(const char *typename, const = char *cpu_model) cc->parse_features(object_class_get_name(oc), featurestr, &err); g_free(str); if (err !=3D NULL) { - goto out; - } - - cpu =3D CPU(object_new(object_class_get_name(oc))); - object_property_set_bool(OBJECT(cpu), true, "realized", &err); - -out: - if (err !=3D NULL) { error_report_err(err); - object_unref(OBJECT(cpu)); return NULL; } =20 + cpu =3D CPU(object_new(object_class_get_name(oc))); + return cpu; } =20 --=20 2.7.4 From nobody Mon Apr 29 00:09:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486997342744651.8883695478881; Mon, 13 Feb 2017 06:49:02 -0800 (PST) Received: from localhost ([::1]:57342 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdHw5-0000y1-Bu for importer@patchew.org; Mon, 13 Feb 2017 09:49:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdHcI-0008HH-Ms for qemu-devel@nongnu.org; Mon, 13 Feb 2017 09:28:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdHcH-0005HU-6Q for qemu-devel@nongnu.org; Mon, 13 Feb 2017 09:28:34 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48495) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdHcE-0005C4-A7; Mon, 13 Feb 2017 09:28:30 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1cdHc5-00014o-HG; Mon, 13 Feb 2017 14:28:21 +0000 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 14:28:17 +0000 Message-Id: <1486996099-15820-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486996099-15820-1-git-send-email-peter.maydell@linaro.org> References: <1486996099-15820-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 2/4] cpu: Clarify TODO comment in cpu_generic_new() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The TODO comment in cpu_generic_new() suggests that we want to move to having all callers do the parse_features work by hand. In fact the intention is that we would prefer to have this happen automatically via machine core work or similar common code changes. In the meantime boards should use the cpu_generic_new() wrapper rather than calling parse_features themselves, because this means we only need to change one place in future if we change how parse_features gets called. Signed-off-by: Peter Maydell --- Change based on email conversation with Eduardo...hopefully I have understood the intention here correctly. --- qom/cpu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qom/cpu.c b/qom/cpu.c index a783aec..eacce5e 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -80,8 +80,14 @@ CPUState *cpu_generic_new(const char *typename, const ch= ar *cpu_model) =20 cc =3D CPU_CLASS(oc); featurestr =3D strtok(NULL, ","); - /* TODO: all callers of cpu_generic_init() need to be converted to - * call parse_features() only once, before calling cpu_generic_init(). + /* TODO: we should really arrange to have parse_features() called + * only once, since it needs only to be called once per CPU class + * rather than once per instance of that class. Perhaps this would + * be done by changes to how machine core code works or by doing + * something in main(). In the meantime, board code should prefer + * to use this function rather than calling parse_features() + * manually, so that refactoring how we handle this is easier in + * future. */ cc->parse_features(object_class_get_name(oc), featurestr, &err); g_free(str); --=20 2.7.4 From nobody Mon Apr 29 00:09:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486996630312196.90250056341222; Mon, 13 Feb 2017 06:37:10 -0800 (PST) Received: from localhost ([::1]:57262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdHka-0006tY-0a for importer@patchew.org; Mon, 13 Feb 2017 09:37:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdHcM-0008KB-N5 for qemu-devel@nongnu.org; Mon, 13 Feb 2017 09:28:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdHcL-0005K9-8M for qemu-devel@nongnu.org; Mon, 13 Feb 2017 09:28:38 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48495) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdHcH-0005C4-I1; Mon, 13 Feb 2017 09:28:33 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1cdHc5-00014z-Va; Mon, 13 Feb 2017 14:28:21 +0000 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 14:28:18 +0000 Message-Id: <1486996099-15820-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486996099-15820-1-git-send-email-peter.maydell@linaro.org> References: <1486996099-15820-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 3/4] hw/arm/integrator: Use new cpu_generic_new() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use the new cpu_generic_new() function rather than doing the work of creating it and calling parse_features by hand. Signed-off-by: Peter Maydell --- hw/arm/integratorcp.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/hw/arm/integratorcp.c b/hw/arm/integratorcp.c index 5610ffc..beffaf4 100644 --- a/hw/arm/integratorcp.c +++ b/hw/arm/integratorcp.c @@ -577,42 +577,24 @@ static void integratorcp_init(MachineState *machine) const char *kernel_filename =3D machine->kernel_filename; const char *kernel_cmdline =3D machine->kernel_cmdline; const char *initrd_filename =3D machine->initrd_filename; - char **cpustr; - ObjectClass *cpu_oc; - CPUClass *cc; Object *cpuobj; ARMCPU *cpu; - const char *typename; MemoryRegion *address_space_mem =3D get_system_memory(); MemoryRegion *ram =3D g_new(MemoryRegion, 1); MemoryRegion *ram_alias =3D g_new(MemoryRegion, 1); qemu_irq pic[32]; DeviceState *dev, *sic, *icp; int i; - Error *err =3D NULL; =20 if (!cpu_model) { cpu_model =3D "arm926"; } =20 - cpustr =3D g_strsplit(cpu_model, ",", 2); - - cpu_oc =3D cpu_class_by_name(TYPE_ARM_CPU, cpustr[0]); - if (!cpu_oc) { + cpuobj =3D OBJECT(cpu_generic_new(TYPE_ARM_CPU, cpu_model)); + if (!cpuobj) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } - typename =3D object_class_get_name(cpu_oc); - - cc =3D CPU_CLASS(cpu_oc); - cc->parse_features(typename, cpustr[1], &err); - g_strfreev(cpustr); - if (err) { - error_report_err(err); - exit(1); - } - - cpuobj =3D object_new(typename); =20 /* By default ARM1176 CPUs have EL3 enabled. This board does not * currently support EL3 so the CPU EL3 property is disabled before --=20 2.7.4 From nobody Mon Apr 29 00:09:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486997198773245.01299043258382; Mon, 13 Feb 2017 06:46:38 -0800 (PST) Received: from localhost ([::1]:57325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdHtf-0007Qk-ON for importer@patchew.org; Mon, 13 Feb 2017 09:46:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdHcM-0008KA-Mf for qemu-devel@nongnu.org; Mon, 13 Feb 2017 09:28:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdHcL-0005K4-4D for qemu-devel@nongnu.org; Mon, 13 Feb 2017 09:28:38 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:48495) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdHcG-0005C4-Oe; Mon, 13 Feb 2017 09:28:32 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1cdHc6-00015A-Do; Mon, 13 Feb 2017 14:28:22 +0000 From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 14:28:19 +0000 Message-Id: <1486996099-15820-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486996099-15820-1-git-send-email-peter.maydell@linaro.org> References: <1486996099-15820-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 4/4] hw/arm/virt: Use new cpu_generic_new() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use the new cpu_generic_new() rather than calling parse_features by hand. Signed-off-by: Peter Maydell --- hw/arm/virt.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index f3440f2..bcb9a6d 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -172,7 +172,6 @@ static const char *valid_cpus[] =3D { static bool cpuname_valid(const char *cpu) { int i; - for (i =3D 0; i < ARRAY_SIZE(valid_cpus); i++) { if (strcmp(cpu, valid_cpus[i]) =3D=3D 0) { return true; @@ -1206,10 +1205,6 @@ static void machvirt_init(MachineState *machine) MemoryRegion *ram =3D g_new(MemoryRegion, 1); const char *cpu_model =3D machine->cpu_model; char **cpustr; - ObjectClass *oc; - const char *typename; - CPUClass *cc; - Error *err =3D NULL; bool firmware_loaded =3D bios_name || drive_get(IF_PFLASH, 0, 0); uint8_t clustersz; =20 @@ -1240,6 +1235,7 @@ static void machvirt_init(MachineState *machine) error_report("mach-virt: CPU %s not supported", cpustr[0]); exit(1); } + g_strfreev(cpustr); =20 /* If we have an EL3 boot ROM then the assumption is that it will * implement PSCI itself, so disable QEMU's internal implementation @@ -1309,24 +1305,8 @@ static void machvirt_init(MachineState *machine) =20 create_fdt(vms); =20 - oc =3D cpu_class_by_name(TYPE_ARM_CPU, cpustr[0]); - if (!oc) { - error_report("Unable to find CPU definition"); - exit(1); - } - typename =3D object_class_get_name(oc); - - /* convert -smp CPU options specified by the user into global props */ - cc =3D CPU_CLASS(oc); - cc->parse_features(typename, cpustr[1], &err); - g_strfreev(cpustr); - if (err) { - error_report_err(err); - exit(1); - } - for (n =3D 0; n < smp_cpus; n++) { - Object *cpuobj =3D object_new(typename); + Object *cpuobj =3D OBJECT(cpu_generic_new(TYPE_ARM_CPU, cpu_model)= ); if (!vmc->disallow_affinity_adjustment) { /* Adjust MPIDR like 64-bit KVM hosts, which incorporate the * GIC's target-list limitations. 32-bit KVM hosts currently --=20 2.7.4