diff mbox

[v4,19/22] qdev: Add qdev property type for AddressSpaces

Message ID 1391420690-23745-20-git-send-email-edgar.iglesias@gmail.com
State New
Headers show

Commit Message

Edgar E. Iglesias Feb. 3, 2014, 9:44 a.m. UTC
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 hw/core/qdev-properties-system.c |  8 ++++++
 hw/core/qdev-properties.c        | 54 ++++++++++++++++++++++++++++++++++++++++
 include/hw/qdev-properties.h     |  5 ++++
 stubs/Makefile.objs              |  1 +
 stubs/memory.c                   |  6 +++++
 5 files changed, 74 insertions(+)
 create mode 100644 stubs/memory.c
diff mbox

Patch

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 3f29b49..27c2899 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -365,6 +365,14 @@  void qdev_prop_set_netdev(DeviceState *dev, const char *name,
                             value ? value->name : "", name, &error_abort);
 }
 
+void qdev_prop_set_address_space(DeviceState *dev, const char *name,
+                                 AddressSpace *value)
+{
+    assert(!value || value->name);
+    object_property_set_str(OBJECT(dev),
+                            value ? value->name : "", name, &error_abort);
+}
+
 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
 {
     qdev_prop_set_macaddr(dev, "mac", nd->macaddr.a);
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index b949f0e..68e09e2 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1176,3 +1176,57 @@  PropertyInfo qdev_prop_size = {
     .get = get_size,
     .set = set_size,
 };
+
+/* --- AddressSpace --- */
+
+static int parse_address_space(DeviceState *dev, const char *name,
+                               AddressSpace **ptr)
+{
+    AddressSpace *as = address_space_find_by_name(name);
+    if (as == NULL) {
+        return -ENOENT;
+    }
+    *ptr = as;
+    return 0;
+}
+
+static void get_address_space(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    AddressSpace *as = qdev_get_prop_ptr(DEVICE(obj), opaque);
+    char *p = (char *) (as ? as->name : "");
+
+    visit_type_str(v, &p, name, errp);
+}
+
+static void set_address_space(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    Error *local_err = NULL;
+    AddressSpace **as = qdev_get_prop_ptr(dev, prop);
+    char *str;
+    int ret;
+
+    if (dev->realized) {
+        qdev_prop_set_after_realize(dev, name, errp);
+        return;
+    }
+
+    visit_type_str(v, &str, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    ret = parse_address_space(dev, str, as);
+    error_set_from_qdev_prop_error(errp, ret, dev, prop, str);
+    g_free(str);
+}
+
+PropertyInfo qdev_prop_address_space = {
+    .name  = "address_space",
+    .get   = get_address_space,
+    .set   = set_address_space,
+};
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 77c6f7c..020439f 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -19,6 +19,7 @@  extern PropertyInfo qdev_prop_size;
 extern PropertyInfo qdev_prop_string;
 extern PropertyInfo qdev_prop_chr;
 extern PropertyInfo qdev_prop_ptr;
+extern PropertyInfo qdev_prop_address_space;
 extern PropertyInfo qdev_prop_macaddr;
 extern PropertyInfo qdev_prop_losttickpolicy;
 extern PropertyInfo qdev_prop_bios_chs_trans;
@@ -141,6 +142,8 @@  extern PropertyInfo qdev_prop_arraylen;
 #define DEFINE_PROP_PTR(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
 
+#define DEFINE_PROP_ADDRESS_SPACE(_n, _s, _f)             \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_address_space, AddressSpace*)
 #define DEFINE_PROP_CHR(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
 #define DEFINE_PROP_STRING(_n, _s, _f)             \
@@ -177,6 +180,8 @@  void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
 void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
+void qdev_prop_set_address_space(DeviceState *dev, const char *name,
+                                 AddressSpace *value);
 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
 void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index df92fe5..9e1e5da 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -26,4 +26,5 @@  stub-obj-y += uuid.o
 stub-obj-y += vm-stop.o
 stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
+stub-obj-y += memory.o
 stub-obj-y += cpus.o
diff --git a/stubs/memory.c b/stubs/memory.c
new file mode 100644
index 0000000..b3b4736
--- /dev/null
+++ b/stubs/memory.c
@@ -0,0 +1,6 @@ 
+#include "exec/address-spaces.h"
+
+AddressSpace *address_space_find_by_name(const char *name)
+{
+    return NULL;
+}