From patchwork Mon Feb 13 14:28:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 93889 Delivered-To: patches@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1121373qgi; Mon, 13 Feb 2017 06:28:25 -0800 (PST) X-Received: by 10.99.55.91 with SMTP id g27mr27221064pgn.65.1486996105880; Mon, 13 Feb 2017 06:28:25 -0800 (PST) Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id z1si10205373pll.224.2017.02.13.06.28.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Feb 2017 06:28:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 Cc: patches@linaro.org, Eduardo Habkost Subject: [PATCH 1/4] cpu: add cpu_generic_new() 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> 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(-) -- 2.7.4 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); /** + * 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) CPUState *cpu_generic_init(const char *typename, const char *cpu_model) { + CPUState *cpu = cpu_generic_new(typename, cpu_model); + if (cpu) { + Error *err = NULL; + object_property_set_bool(OBJECT(cpu), true, "realized", &err); + + if (err != 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 = 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 != NULL) { - goto out; - } - - cpu = CPU(object_new(object_class_get_name(oc))); - object_property_set_bool(OBJECT(cpu), true, "realized", &err); - -out: - if (err != NULL) { error_report_err(err); - object_unref(OBJECT(cpu)); return NULL; } + cpu = CPU(object_new(object_class_get_name(oc))); + return cpu; }