diff mbox

[v1,07/22] qdev: Add qdev property type for AddressSpaces

Message ID 1387181170-23267-8-git-send-email-edgar.iglesias@gmail.com
State New
Headers show

Commit Message

Edgar E. Iglesias Dec. 16, 2013, 8:05 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 |   46 ++++++++++++++++++++++++++++++++++++++
 include/hw/qdev-properties.h     |    5 +++++
 2 files changed, 51 insertions(+)
diff mbox

Patch

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 729efa8..f78bd50 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -170,6 +170,42 @@  PropertyInfo qdev_prop_chr = {
     .release = release_chr,
 };
 
+/* --- AddressSpace --- */
+
+static int parse_address_space(DeviceState *dev, const char *name, void **ptr)
+{
+    AddressSpace *as = address_space_find_by_name(name);
+    if (as == NULL) {
+        return -ENOENT;
+    }
+    *ptr = as;
+    return 0;
+}
+
+static const char *print_address_space(void *ptr)
+{
+    AddressSpace *as = ptr;
+    return as->name;
+}
+
+static void get_address_space(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    get_pointer(obj, v, opaque, print_address_space, name, errp);
+}
+
+static void set_address_space(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    set_pointer(obj, v, opaque, parse_address_space, name, errp);
+}
+
+PropertyInfo qdev_prop_address_space = {
+    .name  = "address_space",
+    .get   = get_address_space,
+    .set   = set_address_space,
+};
+
 /* --- netdev device --- */
 
 static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
@@ -369,6 +405,16 @@  void qdev_prop_set_netdev(DeviceState *dev, const char *name,
     assert_no_error(errp);
 }
 
+void qdev_prop_set_address_space(DeviceState *dev, const char *name,
+                                 AddressSpace *value)
+{
+    Error *errp = NULL;
+    assert(!value || value->name);
+    object_property_set_str(OBJECT(dev),
+                            value ? value->name : "", name, &errp);
+    assert_no_error(errp);
+}
+
 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
 {
     qdev_prop_set_macaddr(dev, "mac", nd->macaddr.a);
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 692f82e..0e1076d 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;
@@ -124,6 +125,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)             \
@@ -160,6 +163,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;