From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Jia Liu" <proljc@gmail.com>,
"Anthony Green" <green@moxielogic.com>,
"Alexander Graf" <agraf@suse.de>,
"Michael Walle" <michael@walle.cc>,
"open list:PowerPC" <qemu-ppc@nongnu.org>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Guan Xuetao" <gxt@mprc.pku.edu.cn>,
"Andreas Färber" <afaerber@suse.de>,
"Aurelien Jarno" <aurelien@aurel32.net>
Subject: [Qemu-devel] [PULL for-2.0-rc0 25/58] cpu: Factor out cpu_generic_init()
Date: Thu, 13 Mar 2014 15:54:28 +0100 [thread overview]
Message-ID: <1394722501-32326-26-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1394722501-32326-1-git-send-email-afaerber@suse.de>
All targets using it gain the ability to set -cpu name,key=value,...
options via the default TYPE_CPU CPUClass::parse_features() implementation.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
include/qom/cpu.h | 11 +++++++++++
qom/cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++
target-arm/helper.c | 14 +-------------
target-cris/cpu.c | 13 +------------
target-lm32/helper.c | 13 +------------
target-moxie/cpu.c | 13 +------------
target-openrisc/cpu.c | 13 +------------
target-ppc/translate_init.c | 21 +--------------------
target-sh4/cpu.c | 13 +------------
target-unicore32/helper.c | 13 +++----------
10 files changed, 62 insertions(+), 103 deletions(-)
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 3703b68..f5b0d7a 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -352,6 +352,17 @@ void cpu_reset(CPUState *cpu);
ObjectClass *cpu_class_by_name(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.
+ *
+ * Returns: A #CPUState or %NULL if an error occurred.
+ */
+CPUState *cpu_generic_init(const char *typename, const char *cpu_model);
+
+/**
* cpu_has_work:
* @cpu: The vCPU to check.
*
diff --git a/qom/cpu.c b/qom/cpu.c
index 4aa0bf8..611ddf1 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -23,6 +23,7 @@
#include "sysemu/kvm.h"
#include "qemu/notify.h"
#include "qemu/log.h"
+#include "qemu/error-report.h"
#include "sysemu/sysemu.h"
bool cpu_exists(int64_t id)
@@ -39,6 +40,46 @@ bool cpu_exists(int64_t id)
return false;
}
+CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
+{
+ char *str, *name, *featurestr;
+ CPUState *cpu;
+ ObjectClass *oc;
+ CPUClass *cc;
+ Error *err = NULL;
+
+ str = g_strdup(cpu_model);
+ name = strtok(str, ",");
+
+ oc = cpu_class_by_name(typename, name);
+ if (oc == NULL) {
+ g_free(str);
+ return NULL;
+ }
+
+ cpu = CPU(object_new(object_class_get_name(oc)));
+ cc = CPU_GET_CLASS(cpu);
+
+ featurestr = strtok(NULL, ",");
+ cc->parse_features(cpu, featurestr, &err);
+ g_free(str);
+ if (err != NULL) {
+ goto out;
+ }
+
+ object_property_set_bool(OBJECT(cpu), true, "realized", &err);
+
+out:
+ if (err != NULL) {
+ error_report("%s", error_get_pretty(err));
+ error_free(err);
+ object_unref(OBJECT(cpu));
+ return NULL;
+ }
+
+ return cpu;
+}
+
bool cpu_paging_enabled(const CPUState *cpu)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
diff --git a/target-arm/helper.c b/target-arm/helper.c
index a40f60f..f64be6f 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -2186,19 +2186,7 @@ void register_cp_regs_for_features(ARMCPU *cpu)
ARMCPU *cpu_arm_init(const char *cpu_model)
{
- ARMCPU *cpu;
- ObjectClass *oc;
-
- oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
- if (!oc) {
- return NULL;
- }
- cpu = ARM_CPU(object_new(object_class_get_name(oc)));
-
- /* TODO this should be set centrally, once possible */
- object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
- return cpu;
+ return ARM_CPU(cpu_generic_init(TYPE_ARM_CPU, cpu_model));
}
void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
diff --git a/target-cris/cpu.c b/target-cris/cpu.c
index 07da845..12c90ee 100644
--- a/target-cris/cpu.c
+++ b/target-cris/cpu.c
@@ -89,18 +89,7 @@ static ObjectClass *cris_cpu_class_by_name(const char *cpu_model)
CRISCPU *cpu_cris_init(const char *cpu_model)
{
- CRISCPU *cpu;
- ObjectClass *oc;
-
- oc = cris_cpu_class_by_name(cpu_model);
- if (oc == NULL) {
- return NULL;
- }
- cpu = CRIS_CPU(object_new(object_class_get_name(oc)));
-
- object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
- return cpu;
+ return CRIS_CPU(cpu_generic_init(TYPE_CRIS_CPU, cpu_model));
}
/* Sort alphabetically by VR. */
diff --git a/target-lm32/helper.c b/target-lm32/helper.c
index eecb9f6..e813e7d 100644
--- a/target-lm32/helper.c
+++ b/target-lm32/helper.c
@@ -182,18 +182,7 @@ void lm32_cpu_do_interrupt(CPUState *cs)
LM32CPU *cpu_lm32_init(const char *cpu_model)
{
- LM32CPU *cpu;
- ObjectClass *oc;
-
- oc = cpu_class_by_name(TYPE_LM32_CPU, cpu_model);
- if (oc == NULL) {
- return NULL;
- }
- cpu = LM32_CPU(object_new(object_class_get_name(oc)));
-
- object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
- return cpu;
+ return LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
}
/* Some soc ignores the MSB on the address bus. Thus creating a shadow memory
diff --git a/target-moxie/cpu.c b/target-moxie/cpu.c
index 88b0d35..32c6104 100644
--- a/target-moxie/cpu.c
+++ b/target-moxie/cpu.c
@@ -136,18 +136,7 @@ static const MoxieCPUInfo moxie_cpus[] = {
MoxieCPU *cpu_moxie_init(const char *cpu_model)
{
- MoxieCPU *cpu;
- ObjectClass *oc;
-
- oc = moxie_cpu_class_by_name(cpu_model);
- if (oc == NULL) {
- return NULL;
- }
- cpu = MOXIE_CPU(object_new(object_class_get_name(oc)));
-
- object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
- return cpu;
+ return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
}
static void cpu_register(const MoxieCPUInfo *info)
diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index 83fed5e..0b2ffb2 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -208,18 +208,7 @@ static void openrisc_cpu_register_types(void)
OpenRISCCPU *cpu_openrisc_init(const char *cpu_model)
{
- OpenRISCCPU *cpu;
- ObjectClass *oc;
-
- oc = openrisc_cpu_class_by_name(cpu_model);
- if (oc == NULL) {
- return NULL;
- }
- cpu = OPENRISC_CPU(object_new(object_class_get_name(oc)));
-
- object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
- return cpu;
+ return OPENRISC_CPU(cpu_generic_init(TYPE_OPENRISC_CPU, cpu_model));
}
/* Sort alphabetically by type name, except for "any". */
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 548ce09..0418f06 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -8220,26 +8220,7 @@ static ObjectClass *ppc_cpu_class_by_name(const char *name)
PowerPCCPU *cpu_ppc_init(const char *cpu_model)
{
- PowerPCCPU *cpu;
- ObjectClass *oc;
- Error *err = NULL;
-
- oc = ppc_cpu_class_by_name(cpu_model);
- if (oc == NULL) {
- return NULL;
- }
-
- cpu = POWERPC_CPU(object_new(object_class_get_name(oc)));
-
- object_property_set_bool(OBJECT(cpu), true, "realized", &err);
- if (err != NULL) {
- error_report("%s", error_get_pretty(err));
- error_free(err);
- object_unref(OBJECT(cpu));
- return NULL;
- }
-
- return cpu;
+ return POWERPC_CPU(cpu_generic_init(TYPE_POWERPC_CPU, cpu_model));
}
/* Sort by PVR, ordering special case "host" last. */
diff --git a/target-sh4/cpu.c b/target-sh4/cpu.c
index 61b82f5..8e7bcd2 100644
--- a/target-sh4/cpu.c
+++ b/target-sh4/cpu.c
@@ -148,18 +148,7 @@ static ObjectClass *superh_cpu_class_by_name(const char *cpu_model)
SuperHCPU *cpu_sh4_init(const char *cpu_model)
{
- SuperHCPU *cpu;
- ObjectClass *oc;
-
- oc = superh_cpu_class_by_name(cpu_model);
- if (oc == NULL) {
- return NULL;
- }
- cpu = SUPERH_CPU(object_new(object_class_get_name(oc)));
-
- object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
- return cpu;
+ return SUPERH_CPU(cpu_generic_init(TYPE_SUPERH_CPU, cpu_model));
}
static void sh7750r_cpu_initfn(Object *obj)
diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index 9bf4fea..a1f86b0 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -28,19 +28,12 @@
CPUUniCore32State *uc32_cpu_init(const char *cpu_model)
{
UniCore32CPU *cpu;
- CPUUniCore32State *env;
- ObjectClass *oc;
- oc = cpu_class_by_name(TYPE_UNICORE32_CPU, cpu_model);
- if (oc == NULL) {
+ cpu = UNICORE32_CPU(cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model));
+ if (cpu == NULL) {
return NULL;
}
- cpu = UNICORE32_CPU(object_new(object_class_get_name(oc)));
- env = &cpu->env;
-
- object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
- return env;
+ return &cpu->env;
}
uint32_t HELPER(clo)(uint32_t x)
--
1.8.4.5
next prev parent reply other threads:[~2014-03-13 14:55 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-13 14:54 [Qemu-devel] [PULL for-2.0-rc0 00/58] QOM CPUState patch queue 2014-03-13 Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 01/58] cpu: Don't clear cpu->exit_request on reset Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 02/58] target-alpha: Clean up ENV_GET_CPU() usage Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 03/58] target-arm: " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 04/58] target-i386: " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 05/58] target-ppc: " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 06/58] target-s390x: " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 07/58] target-sparc: " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 08/58] target-unicore32: " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 09/58] target-xtensa: " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 10/58] cpu: Turn cpu_has_work() into a CPUClass hook Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 11/58] target-i386: Rename cpu_x86_register() to x86_cpu_load_def() Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 12/58] target-i386: Call x86_cpu_load_def() earlier Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 13/58] target-i386: Rename x86_def_t to X86CPUDefinition Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 14/58] target-i386: Don't declare variables in the middle of blocks Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 15/58] target-i386: Make kvm_default_features an array Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 16/58] target-i386: Introduce x86_cpu_compat_disable_kvm_features() Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 17/58] target-i386: Enable x2apic by default on KVM Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 18/58] target-i386: Prepare CPUClass::class_by_name for X86CPU Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 19/58] target-i386: X86CPU model subclasses Andreas Färber
2014-03-13 18:19 ` Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 20/58] cpu: Introduce CPUClass::parse_features() hook Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 21/58] target-sparc: Use error_report() for CPU error reporting Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 22/58] target-sparc: Implement CPUClass::parse_features() for SPARCCPU Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 23/58] target-sparc: Defer SPARCCPU feature inference to QOM realize Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 24/58] cpu: Implement CPUClass::parse_features() for the rest of CPUs Andreas Färber
2014-03-13 14:54 ` Andreas Färber [this message]
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 26/58] target-m68k: Remove custom qemu_assert() function Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 27/58] cpu: Turn cpu_handle_mmu_fault() into a CPUClass hook Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 28/58] cpu: Move mem_io_{pc, vaddr} fields from CPU_COMMON to CPUState Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 29/58] cpu: Move can_do_io field " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 30/58] cpu: Move icount_extra " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 31/58] cpu: Move icount_decr " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 32/58] cpu: Move tb_jmp_cache " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 33/58] cpu: Move jmp_env " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 34/58] cpu: Move exception_index " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 35/58] cpu: Move opaque " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 36/58] cpu: Move watchpoint fields " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 37/58] cpu: Move breakpoints field " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 38/58] exec: Change tlb_fill() argument " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 39/58] cpu-exec: Change cpu_loop_exit() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 40/58] translate-all: Change cpu_restore_state() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 41/58] translate-all: Change cpu_restore_state_from_tb() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 42/58] translate-all: Change tb_check_watchpoint() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 43/58] translate-all: Change cpu_io_recompile() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 44/58] translate-all: Change tb_gen_code() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 45/58] translate-all: Change tb_flush_jmp_cache() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 46/58] target-ppc: Use PowerPCCPU in PowerPCCPUClass::handle_mmu_fault hook Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 47/58] exec: Change cpu_watchpoint_{insert, remove{, _by_ref, _all}} argument Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 48/58] exec: Change cpu_breakpoint_{insert, " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 49/58] cpu-exec: Change cpu_resume_from_signal() argument to CPUState Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 50/58] cputlb: Change tlb_unprotect_code_phys() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 51/58] exec: Change memory_region_section_get_iotlb() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 52/58] exec: Change cpu_abort() " Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 53/58] target-cris: Replace DisasContext::env field with CRISCPU Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 54/58] target-microblaze: Replace DisasContext::env field with MicroBlazeCPU Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 55/58] cputlb: Change tlb_flush_page() argument to CPUState Andreas Färber
2014-03-13 14:54 ` [Qemu-devel] [PULL for-2.0-rc0 56/58] cputlb: Change tlb_flush() " Andreas Färber
2014-03-17 16:13 ` [Qemu-devel] [PATCH]: exec: fix cpu rework fallout (was cputlb: Change tlb_flush() argument to CPUState) Christian Borntraeger
2014-03-17 19:37 ` Andreas Färber
2014-03-13 14:55 ` [Qemu-devel] [PULL for-2.0-rc0 57/58] cputlb: Change tlb_set_page() argument to CPUState Andreas Färber
2014-03-13 14:55 ` [Qemu-devel] [PULL for-2.0-rc0 58/58] user-exec: Change exception_action() " Andreas Färber
2014-03-13 15:29 ` [Qemu-devel] [PULL for-2.0-rc0 00/58] QOM CPUState patch queue 2014-03-13 Christian Borntraeger
2014-03-13 17:10 ` Peter Maydell
2014-03-13 18:44 ` Andreas Färber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394722501-32326-26-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aurelien@aurel32.net \
--cc=edgar.iglesias@gmail.com \
--cc=green@moxielogic.com \
--cc=gxt@mprc.pku.edu.cn \
--cc=michael@walle.cc \
--cc=peter.maydell@linaro.org \
--cc=proljc@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).