qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH v1 08/11] qom/cpu: Add Memory Region Property


From: Peter Crosthwaite
Subject: [Qemu-devel] [RFC PATCH v1 08/11] qom/cpu: Add Memory Region Property
Date: Mon, 2 Jun 2014 19:10:59 -0700

Which is used to construct a per-CPU address space. The Address space
is constructed ASAP from the MemoryRegion property setter itself.

Signed-off-by: Peter Crosthwaite <address@hidden>
---

 include/qom/cpu.h |  1 +
 qom/cpu.c         | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index df977c8..4f6a4ee 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -237,6 +237,7 @@ struct CPUState {
     int64_t icount_extra;
     sigjmp_buf jmp_env;
 
+    MemoryRegion *mr;
     AddressSpace *as;
     MemoryListener *tcg_as_listener;
 
diff --git a/qom/cpu.c b/qom/cpu.c
index fada2d4..433e627 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -25,6 +25,8 @@
 #include "qemu/log.h"
 #include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
+#include "exec/memory.h"
+#include "qapi/visitor.h"
 
 bool cpu_exists(int64_t id)
 {
@@ -303,12 +305,40 @@ static void cpu_common_realizefn(DeviceState *dev, Error 
**errp)
     }
 }
 
+static void cpu_set_mr(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    CPUState *cpu = CPU(obj);
+    Error *local_err = NULL;
+    char *path = NULL;
+
+    visit_type_str(v, &path, name, &local_err);
+
+    if (!local_err && strcmp(path, "") != 0) {
+        cpu->mr = MEMORY_REGION(object_resolve_link(obj, name, path,
+                                &local_err));
+    }
+
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    object_ref(OBJECT(cpu->mr));
+    cpu->as = address_space_init_shareable(cpu->mr, NULL);
+}
+
 static void cpu_common_initfn(Object *obj)
 {
     CPUState *cpu = CPU(obj);
     CPUClass *cc = CPU_GET_CLASS(obj);
 
     cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
+    object_property_add(obj, "mr", "link<" TYPE_MEMORY_REGION ">",
+                        NULL, /* FIXME: Implement the getter */
+                        cpu_set_mr,
+                        NULL, /* FIXME: Implement the cleanup */
+                        NULL, &error_abort);
 }
 
 static int64_t cpu_common_get_arch_id(CPUState *cpu)
-- 
2.0.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]