[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 44/55] qdev: Introduce DEFINE_PROP_LINK
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 44/55] qdev: Introduce DEFINE_PROP_LINK |
Date: |
Fri, 14 Jul 2017 12:10:17 +0200 |
From: Fam Zheng <address@hidden>
This property can be used to replace the object_property_add_link in
device code, to add a link to other objects, which is a common pattern.
Signed-off-by: Fam Zheng <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/core/qdev-properties.c | 18 ++++++++++++++++++
include/hw/qdev-core.h | 1 +
include/hw/qdev-properties.h | 9 +++++++++
3 files changed, 28 insertions(+)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 113ce7d..5429c63 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1214,3 +1214,21 @@ PropertyInfo qdev_prop_size = {
.set = set_size,
.set_default_value = set_default_value_uint,
};
+
+/* --- object link property --- */
+
+static void create_link_property(Object *obj, Property *prop, Error **errp)
+{
+ Object **child = qdev_get_prop_ptr(DEVICE(obj), prop);
+
+ object_property_add_link(obj, prop->name, prop->link_type,
+ child,
+ qdev_prop_allow_set_link_before_realize,
+ OBJ_PROP_LINK_UNREF_ON_RELEASE,
+ errp);
+}
+
+PropertyInfo qdev_prop_link = {
+ .name = "link",
+ .create = create_link_property,
+};
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 33518ee..08d1d2c 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -233,6 +233,7 @@ struct Property {
int arrayoffset;
PropertyInfo *arrayinfo;
int arrayfieldsize;
+ const char *link_type;
};
struct PropertyInfo {
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 9edded2..876ba2e 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -30,6 +30,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
extern PropertyInfo qdev_prop_blocksize;
extern PropertyInfo qdev_prop_pci_host_devaddr;
extern PropertyInfo qdev_prop_arraylen;
+extern PropertyInfo qdev_prop_link;
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
.name = (_name), \
@@ -117,6 +118,14 @@ extern PropertyInfo qdev_prop_arraylen;
.arrayoffset = offsetof(_state, _arrayfield), \
}
+#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \
+ .name = (_name), \
+ .info = &(qdev_prop_link), \
+ .offset = offsetof(_state, _field) \
+ + type_check(_ptr_type, typeof_field(_state, _field)), \
+ .link_type = _type, \
+ }
+
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
--
1.8.3.1
- [Qemu-devel] [PULL v2 00/55] Misc patches for QEMU 2.10 soft freeze, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 22/55] Revert "exec.c: Fix breakpoint invalidation race", Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 43/55] qdev: Introduce PropertyInfo.create, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 42/55] qom: enforce readonly nature of link's check callback, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 45/55] qmp: Use ObjectProperty.type if present, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 44/55] qdev: Introduce DEFINE_PROP_LINK,
Paolo Bonzini <=
- [Qemu-devel] [PULL 23/55] mttcg/i386: Patch instruction using async_safe_* framework, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 46/55] qdev: Add const qualifier to PropertyInfo definitions, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 47/55] virtio-blk: Convert to DEFINE_PROP_LINK, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 49/55] virtio-rng: Convert to DEFINE_PROP_LINK, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 51/55] dimm: Convert to DEFINE_PROP_LINK, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 48/55] virtio-scsi: Convert to DEFINE_PROP_LINK, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 50/55] virtio-crypto: Convert to DEFINE_PROP_LINK, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 52/55] ivshmem: Convert to DEFINE_PROP_LINK, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 53/55] mips_cmgcr: Convert to DEFINE_PROP_LINK, Paolo Bonzini, 2017/07/14
- [Qemu-devel] [PULL 54/55] cpu: Convert to DEFINE_PROP_LINK, Paolo Bonzini, 2017/07/14