qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC 10/20] cpu: introduce generic_cpu_init() & generic_cpu_create() functions
Date: Tue, 18 Dec 2012 18:04:03 -0200	[thread overview]
Message-ID: <1355861053-11460-11-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1355861053-11460-1-git-send-email-ehabkost@redhat.com>

Useful for architectures where cpu_init() is just creation of a CPU
object and a call to cpu_realize().

All the functions should need is the base CPU class name and cpu_model
string. Any target-specific behavior/information can later be provided
by the target-specific CPU class, if necessary.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/qemu/cpu.h | 24 ++++++++++++++++++++++++
 qom/cpu.c          | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 90bb27d..7461319 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -151,4 +151,28 @@ bool cpu_is_stopped(CPUState *cpu);
 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
 
 
+/* generic_cpu_create:
+ * @base_class_name: The name of the base CPU class
+ * @cpu_model: full CPU model string to be parsed
+ * @errp: pointer to Error pointer, where error information can be returned
+ *
+ * Generic target-independent function to create a CPU object. Caller
+ * should call cpu_realize() later.
+ *
+ * Any target-specific behavior can be set as CPUClass fields in the base class.
+ */
+CPUState *generic_cpu_create(const char *base_class_name,
+                             const char *cpu_model,
+                             Error **errp);
+
+/* generic_cpu_init:
+ * @base_class_name: The name of the base CPU class
+ * @cpu_model: full CPU model string to be parsed
+ *
+ * Generic target-independent cpu_init implementation. Any target-specific
+ * behavior can be set as CPUClass fields in the base class.
+ */
+CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model);
+
+
 #endif
diff --git a/qom/cpu.c b/qom/cpu.c
index a96f6ee..42cbe42 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/cpu.h"
+#include "qemu-error.h"
 #include "qemu-common.h"
 
 void cpu_reset(CPUState *cpu)
@@ -65,4 +66,41 @@ static void cpu_register_types(void)
     type_register_static(&cpu_type_info);
 }
 
+CPUState *generic_cpu_create(const char *base_class_name,
+                             const char *cpu_model,
+                             Error **errp)
+{
+    CPUState *cpu;
+
+    if (!object_class_by_name(cpu_model)) {
+        error_setg(errp, "Can't find CPU class for model: %s", cpu_model);
+        return NULL;
+    }
+
+    cpu = CPU(object_new(cpu_model));
+    cpu->cpu_model_str = cpu_model;
+    return cpu;
+}
+
+CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model)
+{
+    CPUState *cpu;
+    Error *err = NULL;
+
+    cpu = generic_cpu_create(base_class_name, cpu_model, &err);
+    if (err) {
+        goto error;
+    }
+
+    cpu_realize(cpu, &err);
+    if (err) {
+        goto error;
+    }
+
+    return cpu;
+error:
+    error_report("cpu_init: %s", error_get_pretty(err));
+    return NULL;
+}
+
 type_init(cpu_register_types)
-- 
1.7.11.7

  parent reply	other threads:[~2012-12-18 20:02 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 01/20] qemu-common.h: "use" env parameter in no-op version of qemu_init_vcpu() Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 02/20] cpu: introduce CPU_GET_ENV macros Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 03/20] cpu: make cpu_init return CPUState QOM object Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 04/20] cpu: replace trivial old_cpu_init functions Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 05/20] alpha: convert cpu_init to QOM Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 06/20] m68k: " Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 07/20] target-unicore32: " Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 08/20] cpu: move cpu_model_str to CPUState Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 09/20] cpu: introduce cpu_realize() Eduardo Habkost
2012-12-18 23:13   ` Andreas Färber
2012-12-18 20:04 ` Eduardo Habkost [this message]
2012-12-18 20:04 ` [Qemu-devel] [RFC 11/20] target-openrisc: implement CPU realize() method Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 12/20] hw/openrisc_sim.c: coding style/indentation fix Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 13/20] target-openrisc: replace cpu_openrisc_init() with generic_cpu_init() Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 14/20] target-arm: move final steps of cpu_arm_init() to realize function Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 15/20] target-arm: replace cpu_arm_init() with generic_cpu_init() Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 16/20] target-m68k: move final steps of cpu_m68k_init() to realize function Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 17/20] target-m68k: replace cpu_m68k_init() with generic_cpu_init() Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 18/20] target-unicore32: move final steps of uc32_cpu_init() to realize function Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 19/20] target-unicore32: replace uc32_cpu_init() with generic_cpu_init() Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 20/20] cpu: convert cpu_copy() to QOM Eduardo Habkost
2012-12-18 22:57 ` [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Andreas Färber
2012-12-19  0:08   ` Eduardo Habkost

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=1355861053-11460-11-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=qemu-devel@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).