aboutsummaryrefslogtreecommitdiff
path: root/hw/core
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-01-01 22:57:15 +0000
committerPeter Maydell <peter.maydell@linaro.org>2021-01-01 22:57:15 +0000
commit41192db338588051f21501abc13743e62b0a5605 (patch)
tree683166575873af292daedaf30177919856ffbfc6 /hw/core
parent83734919c408ba02adb6ea616d68cd1a72837fbe (diff)
parentbdd5ce050d086e9f63874f1f36e9e39fa27a976c (diff)
Merge remote-tracking branch 'remotes/ehabkost-gl/tags/machine-next-pull-request' into staging
Machine queue, 2020-12-23 Cleanup: * qdev code cleanup (Eduardo Habkost) Bug fix: * hostmem: Free host_nodes list right after visited (Keqian Zhu) # gpg: Signature made Wed 23 Dec 2020 21:25:58 GMT # gpg: using RSA key 5A322FD5ABC4D3DBACCFD1AA2807936F984DC5A6 # gpg: issuer "ehabkost@redhat.com" # gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>" [full] # Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF D1AA 2807 936F 984D C5A6 * remotes/ehabkost-gl/tags/machine-next-pull-request: bugfix: hostmem: Free host_nodes list right after visited qdev: Avoid unnecessary DeviceState* variable at set_prop_arraylen() qdev: Rename qdev_get_prop_ptr() to object_field_prop_ptr() qdev: Move qdev_prop_tpm declaration to tpm_prop.h qdev: Make qdev_class_add_property() more flexible qdev: Make PropertyInfo.create return ObjectProperty* qdev: Move dev->realized check to qdev_property_set() qdev: Wrap getters and setters in separate helpers qdev: Add name argument to PropertyInfo.create method qdev: Add name parameter to qdev_class_add_property() qdev: Avoid using prop->name unnecessarily qdev: Get just property name at error_set_from_qdev_prop_error() sparc: Use DEFINE_PROP for nwindows property qdev: Reuse DEFINE_PROP in all DEFINE_PROP_* macros qdev: Move softmmu properties to qdev-properties-system.h Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/core')
-rw-r--r--hw/core/qdev-properties-system.c147
-rw-r--r--hw/core/qdev-properties.c253
2 files changed, 151 insertions, 249 deletions
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 7a9a1d6404..2760c21f11 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -12,6 +12,7 @@
#include "qemu/osdep.h"
#include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
#include "qapi/error.h"
#include "qapi/visitor.h"
#include "qapi/qapi-types-block.h"
@@ -61,7 +62,7 @@ static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
Property *prop = opaque;
- void **ptr = qdev_get_prop_ptr(obj, prop);
+ void **ptr = object_field_prop_ptr(obj, prop);
const char *value;
char *p;
@@ -87,17 +88,12 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name,
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- void **ptr = qdev_get_prop_ptr(obj, prop);
+ void **ptr = object_field_prop_ptr(obj, prop);
char *str;
BlockBackend *blk;
bool blk_created = false;
int ret;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, errp)) {
return;
}
@@ -140,7 +136,7 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name,
}
if (!blk) {
error_setg(errp, "Property '%s.%s' can't find value '%s'",
- object_get_typename(OBJECT(dev)), prop->name, str);
+ object_get_typename(OBJECT(dev)), name, str);
goto fail;
}
if (blk_attach_dev(blk, dev) < 0) {
@@ -185,7 +181,7 @@ static void release_drive(Object *obj, const char *name, void *opaque)
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- BlockBackend **ptr = qdev_get_prop_ptr(obj, prop);
+ BlockBackend **ptr = object_field_prop_ptr(obj, prop);
if (*ptr) {
AioContext *ctx = blk_get_aio_context(*ptr);
@@ -218,7 +214,7 @@ const PropertyInfo qdev_prop_drive_iothread = {
static void get_chr(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- CharBackend *be = qdev_get_prop_ptr(obj, opaque);
+ CharBackend *be = object_field_prop_ptr(obj, opaque);
char *p;
p = g_strdup(be->chr && be->chr->label ? be->chr->label : "");
@@ -229,17 +225,11 @@ static void get_chr(Object *obj, Visitor *v, const char *name, void *opaque,
static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- CharBackend *be = qdev_get_prop_ptr(obj, prop);
+ CharBackend *be = object_field_prop_ptr(obj, prop);
Chardev *s;
char *str;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, errp)) {
return;
}
@@ -261,10 +251,10 @@ static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
s = qemu_chr_find(str);
if (s == NULL) {
error_setg(errp, "Property '%s.%s' can't find value '%s'",
- object_get_typename(obj), prop->name, str);
+ object_get_typename(obj), name, str);
} else if (!qemu_chr_fe_init(be, s, errp)) {
error_prepend(errp, "Property '%s.%s' can't take value '%s': ",
- object_get_typename(obj), prop->name, str);
+ object_get_typename(obj), name, str);
}
g_free(str);
}
@@ -272,7 +262,7 @@ static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque,
static void release_chr(Object *obj, const char *name, void *opaque)
{
Property *prop = opaque;
- CharBackend *be = qdev_get_prop_ptr(obj, prop);
+ CharBackend *be = object_field_prop_ptr(obj, prop);
qemu_chr_fe_deinit(be, false);
}
@@ -296,7 +286,7 @@ static void get_mac(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
Property *prop = opaque;
- MACAddr *mac = qdev_get_prop_ptr(obj, prop);
+ MACAddr *mac = object_field_prop_ptr(obj, prop);
char buffer[2 * 6 + 5 + 1];
char *p = buffer;
@@ -310,18 +300,12 @@ static void get_mac(Object *obj, Visitor *v, const char *name, void *opaque,
static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- MACAddr *mac = qdev_get_prop_ptr(obj, prop);
+ MACAddr *mac = object_field_prop_ptr(obj, prop);
int i, pos;
char *str;
const char *p;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, errp)) {
return;
}
@@ -353,7 +337,7 @@ static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
return;
inval:
- error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+ error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
g_free(str);
}
@@ -379,7 +363,7 @@ static void get_netdev(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- NICPeers *peers_ptr = qdev_get_prop_ptr(obj, prop);
+ NICPeers *peers_ptr = object_field_prop_ptr(obj, prop);
char *p = g_strdup(peers_ptr->ncs[0] ? peers_ptr->ncs[0]->name : "");
visit_type_str(v, name, &p, errp);
@@ -389,19 +373,13 @@ static void get_netdev(Object *obj, Visitor *v, const char *name,
static void set_netdev(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- NICPeers *peers_ptr = qdev_get_prop_ptr(obj, prop);
+ NICPeers *peers_ptr = object_field_prop_ptr(obj, prop);
NetClientState **ncs = peers_ptr->ncs;
NetClientState *peers[MAX_QUEUE_NUM];
int queues, err = 0, i = 0;
char *str;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, errp)) {
return;
}
@@ -441,7 +419,7 @@ static void set_netdev(Object *obj, Visitor *v, const char *name,
peers_ptr->queues = queues;
out:
- error_set_from_qdev_prop_error(errp, err, obj, prop, str);
+ error_set_from_qdev_prop_error(errp, err, obj, name, str);
g_free(str);
}
@@ -458,7 +436,7 @@ static void get_audiodev(Object *obj, Visitor *v, const char* name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- QEMUSoundCard *card = qdev_get_prop_ptr(obj, prop);
+ QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
char *p = g_strdup(audio_get_id(card));
visit_type_str(v, name, &p, errp);
@@ -468,18 +446,12 @@ static void get_audiodev(Object *obj, Visitor *v, const char* name,
static void set_audiodev(Object *obj, Visitor *v, const char* name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- QEMUSoundCard *card = qdev_get_prop_ptr(obj, prop);
+ QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
AudioState *state;
int err = 0;
char *str;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, errp)) {
return;
}
@@ -493,7 +465,7 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
card->state = state;
out:
- error_set_from_qdev_prop_error(errp, err, obj, prop, str);
+ error_set_from_qdev_prop_error(errp, err, obj, name, str);
g_free(str);
}
@@ -577,15 +549,10 @@ static void set_blocksize(Object *obj, Visitor *v, const char *name,
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
+ uint32_t *ptr = object_field_prop_ptr(obj, prop);
uint64_t value;
Error *local_err = NULL;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_size(v, name, &value, errp)) {
return;
}
@@ -670,7 +637,7 @@ static void get_reserved_region(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- ReservedRegion *rr = qdev_get_prop_ptr(obj, prop);
+ ReservedRegion *rr = object_field_prop_ptr(obj, prop);
char buffer[64];
char *p = buffer;
int rc;
@@ -685,19 +652,13 @@ static void get_reserved_region(Object *obj, Visitor *v, const char *name,
static void set_reserved_region(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- ReservedRegion *rr = qdev_get_prop_ptr(obj, prop);
+ ReservedRegion *rr = object_field_prop_ptr(obj, prop);
Error *local_err = NULL;
const char *endptr;
char *str;
int ret;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
visit_type_str(v, name, &str, &local_err);
if (local_err) {
error_propagate(errp, local_err);
@@ -753,17 +714,11 @@ const PropertyInfo qdev_prop_reserved_region = {
static void set_pci_devfn(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- int32_t value, *ptr = qdev_get_prop_ptr(obj, prop);
+ int32_t value, *ptr = object_field_prop_ptr(obj, prop);
unsigned int slot, fn, n;
char *str;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, NULL)) {
if (!visit_type_int32(v, name, &value, errp)) {
return;
@@ -791,14 +746,14 @@ static void set_pci_devfn(Object *obj, Visitor *v, const char *name,
return;
invalid:
- error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+ error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
g_free(str);
}
static int print_pci_devfn(Object *obj, Property *prop, char *dest,
size_t len)
{
- int32_t *ptr = qdev_get_prop_ptr(obj, prop);
+ int32_t *ptr = object_field_prop_ptr(obj, prop);
if (*ptr == -1) {
return snprintf(dest, len, "<unset>");
@@ -822,7 +777,7 @@ static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- PCIHostDeviceAddress *addr = qdev_get_prop_ptr(obj, prop);
+ PCIHostDeviceAddress *addr = object_field_prop_ptr(obj, prop);
char buffer[] = "ffff:ff:ff.f";
char *p = buffer;
int rc = 0;
@@ -847,20 +802,14 @@ static void get_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- PCIHostDeviceAddress *addr = qdev_get_prop_ptr(obj, prop);
+ PCIHostDeviceAddress *addr = object_field_prop_ptr(obj, prop);
char *str, *p;
char *e;
unsigned long val;
unsigned long dom = 0, bus = 0;
unsigned int slot = 0, func = 0;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, errp)) {
return;
}
@@ -915,7 +864,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
return;
inval:
- error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+ error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
g_free(str);
}
@@ -944,7 +893,7 @@ static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- PCIExpLinkSpeed *p = qdev_get_prop_ptr(obj, prop);
+ PCIExpLinkSpeed *p = object_field_prop_ptr(obj, prop);
int speed;
switch (*p) {
@@ -965,23 +914,17 @@ static void get_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
abort();
}
- visit_type_enum(v, prop->name, &speed, prop->info->enum_table, errp);
+ visit_type_enum(v, name, &speed, prop->info->enum_table, errp);
}
static void set_prop_pcielinkspeed(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- PCIExpLinkSpeed *p = qdev_get_prop_ptr(obj, prop);
+ PCIExpLinkSpeed *p = object_field_prop_ptr(obj, prop);
int speed;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
- if (!visit_type_enum(v, prop->name, &speed, prop->info->enum_table,
+ if (!visit_type_enum(v, name, &speed, prop->info->enum_table,
errp)) {
return;
}
@@ -1020,7 +963,7 @@ static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- PCIExpLinkWidth *p = qdev_get_prop_ptr(obj, prop);
+ PCIExpLinkWidth *p = object_field_prop_ptr(obj, prop);
int width;
switch (*p) {
@@ -1050,23 +993,17 @@ static void get_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
abort();
}
- visit_type_enum(v, prop->name, &width, prop->info->enum_table, errp);
+ visit_type_enum(v, name, &width, prop->info->enum_table, errp);
}
static void set_prop_pcielinkwidth(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- PCIExpLinkWidth *p = qdev_get_prop_ptr(obj, prop);
+ PCIExpLinkWidth *p = object_field_prop_ptr(obj, prop);
int width;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
- if (!visit_type_enum(v, prop->name, &width, prop->info->enum_table,
+ if (!visit_type_enum(v, name, &width, prop->info->enum_table,
errp)) {
return;
}
@@ -1114,7 +1051,7 @@ static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
Property *prop = opaque;
- QemuUUID *uuid = qdev_get_prop_ptr(obj, prop);
+ QemuUUID *uuid = object_field_prop_ptr(obj, prop);
char buffer[UUID_FMT_LEN + 1];
char *p = buffer;
@@ -1128,16 +1065,10 @@ static void get_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- QemuUUID *uuid = qdev_get_prop_ptr(obj, prop);
+ QemuUUID *uuid = object_field_prop_ptr(obj, prop);
char *str;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, errp)) {
return;
}
@@ -1145,7 +1076,7 @@ static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
if (!strcmp(str, UUID_VALUE_AUTO)) {
qemu_uuid_generate(uuid);
} else if (qemu_uuid_parse(str, uuid) < 0) {
- error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
+ error_set_from_qdev_prop_error(errp, EINVAL, obj, name, str);
}
g_free(str);
}
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index a2eaa43831..50f40949f5 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -24,6 +24,19 @@ void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
}
}
+/* returns: true if property is allowed to be set, false otherwise */
+static bool qdev_prop_allow_set(Object *obj, const char *name,
+ Error **errp)
+{
+ DeviceState *dev = DEVICE(obj);
+
+ if (dev->realized) {
+ qdev_prop_set_after_realize(dev, name, errp);
+ return false;
+ }
+ return true;
+}
+
void qdev_prop_allow_set_link_before_realize(const Object *obj,
const char *name,
Object *val, Error **errp)
@@ -37,35 +50,68 @@ void qdev_prop_allow_set_link_before_realize(const Object *obj,
}
}
-void *qdev_get_prop_ptr(Object *obj, Property *prop)
+void *object_field_prop_ptr(Object *obj, Property *prop)
{
void *ptr = obj;
ptr += prop->offset;
return ptr;
}
+static void field_prop_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ Property *prop = opaque;
+ return prop->info->get(obj, v, name, opaque, errp);
+}
+
+/**
+ * field_prop_getter: Return getter function to be used for property
+ *
+ * Return value can be NULL if @info has no getter function.
+ */
+static ObjectPropertyAccessor *field_prop_getter(const PropertyInfo *info)
+{
+ return info->get ? field_prop_get : NULL;
+}
+
+static void field_prop_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ Property *prop = opaque;
+
+ if (!qdev_prop_allow_set(obj, name, errp)) {
+ return;
+ }
+
+ return prop->info->set(obj, v, name, opaque, errp);
+}
+
+/**
+ * field_prop_setter: Return setter function to be used for property
+ *
+ * Return value can be NULL if @info has not setter function.
+ */
+static ObjectPropertyAccessor *field_prop_setter(const PropertyInfo *info)
+{
+ return info->set ? field_prop_set : NULL;
+}
+
void qdev_propinfo_get_enum(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- int *ptr = qdev_get_prop_ptr(obj, prop);
+ int *ptr = object_field_prop_ptr(obj, prop);
- visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp);
+ visit_type_enum(v, name, ptr, prop->info->enum_table, errp);
}
void qdev_propinfo_set_enum(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- int *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ int *ptr = object_field_prop_ptr(obj, prop);
- visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp);
+ visit_type_enum(v, name, ptr, prop->info->enum_table, errp);
}
void qdev_propinfo_set_default_value_enum(ObjectProperty *op,
@@ -92,7 +138,7 @@ static uint32_t qdev_get_prop_mask(Property *prop)
static void bit_prop_set(Object *obj, Property *props, bool val)
{
- uint32_t *p = qdev_get_prop_ptr(obj, props);
+ uint32_t *p = object_field_prop_ptr(obj, props);
uint32_t mask = qdev_get_prop_mask(props);
if (val) {
*p |= mask;
@@ -105,7 +151,7 @@ static void prop_get_bit(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- uint32_t *p = qdev_get_prop_ptr(obj, prop);
+ uint32_t *p = object_field_prop_ptr(obj, prop);
bool value = (*p & qdev_get_prop_mask(prop)) != 0;
visit_type_bool(v, name, &value, errp);
@@ -114,15 +160,9 @@ static void prop_get_bit(Object *obj, Visitor *v, const char *name,
static void prop_set_bit(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
bool value;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_bool(v, name, &value, errp)) {
return;
}
@@ -152,7 +192,7 @@ static uint64_t qdev_get_prop_mask64(Property *prop)
static void bit64_prop_set(Object *obj, Property *props, bool val)
{
- uint64_t *p = qdev_get_prop_ptr(obj, props);
+ uint64_t *p = object_field_prop_ptr(obj, props);
uint64_t mask = qdev_get_prop_mask64(props);
if (val) {
*p |= mask;
@@ -165,7 +205,7 @@ static void prop_get_bit64(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- uint64_t *p = qdev_get_prop_ptr(obj, prop);
+ uint64_t *p = object_field_prop_ptr(obj, prop);
bool value = (*p & qdev_get_prop_mask64(prop)) != 0;
visit_type_bool(v, name, &value, errp);
@@ -174,15 +214,9 @@ static void prop_get_bit64(Object *obj, Visitor *v, const char *name,
static void prop_set_bit64(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
bool value;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_bool(v, name, &value, errp)) {
return;
}
@@ -203,7 +237,7 @@ static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
Property *prop = opaque;
- bool *ptr = qdev_get_prop_ptr(obj, prop);
+ bool *ptr = object_field_prop_ptr(obj, prop);
visit_type_bool(v, name, ptr, errp);
}
@@ -211,14 +245,8 @@ static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque,
static void set_bool(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- bool *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ bool *ptr = object_field_prop_ptr(obj, prop);
visit_type_bool(v, name, ptr, errp);
}
@@ -236,7 +264,7 @@ static void get_uint8(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
Property *prop = opaque;
- uint8_t *ptr = qdev_get_prop_ptr(obj, prop);
+ uint8_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_uint8(v, name, ptr, errp);
}
@@ -244,14 +272,8 @@ static void get_uint8(Object *obj, Visitor *v, const char *name, void *opaque,
static void set_uint8(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint8_t *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ uint8_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_uint8(v, name, ptr, errp);
}
@@ -281,7 +303,7 @@ static void get_uint16(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- uint16_t *ptr = qdev_get_prop_ptr(obj, prop);
+ uint16_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_uint16(v, name, ptr, errp);
}
@@ -289,14 +311,8 @@ static void get_uint16(Object *obj, Visitor *v, const char *name,
static void set_uint16(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint16_t *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ uint16_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_uint16(v, name, ptr, errp);
}
@@ -314,7 +330,7 @@ static void get_uint32(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
+ uint32_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_uint32(v, name, ptr, errp);
}
@@ -322,14 +338,8 @@ static void get_uint32(Object *obj, Visitor *v, const char *name,
static void set_uint32(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ uint32_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_uint32(v, name, ptr, errp);
}
@@ -338,7 +348,7 @@ void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- int32_t *ptr = qdev_get_prop_ptr(obj, prop);
+ int32_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_int32(v, name, ptr, errp);
}
@@ -346,14 +356,8 @@ void qdev_propinfo_get_int32(Object *obj, Visitor *v, const char *name,
static void set_int32(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- int32_t *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ int32_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_int32(v, name, ptr, errp);
}
@@ -378,7 +382,7 @@ static void get_uint64(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- uint64_t *ptr = qdev_get_prop_ptr(obj, prop);
+ uint64_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_uint64(v, name, ptr, errp);
}
@@ -386,14 +390,8 @@ static void get_uint64(Object *obj, Visitor *v, const char *name,
static void set_uint64(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint64_t *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ uint64_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_uint64(v, name, ptr, errp);
}
@@ -402,7 +400,7 @@ static void get_int64(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- int64_t *ptr = qdev_get_prop_ptr(obj, prop);
+ int64_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_int64(v, name, ptr, errp);
}
@@ -410,14 +408,8 @@ static void get_int64(Object *obj, Visitor *v, const char *name,
static void set_int64(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- int64_t *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ int64_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_int64(v, name, ptr, errp);
}
@@ -441,14 +433,14 @@ const PropertyInfo qdev_prop_int64 = {
static void release_string(Object *obj, const char *name, void *opaque)
{
Property *prop = opaque;
- g_free(*(char **)qdev_get_prop_ptr(obj, prop));
+ g_free(*(char **)object_field_prop_ptr(obj, prop));
}
static void get_string(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- char **ptr = qdev_get_prop_ptr(obj, prop);
+ char **ptr = object_field_prop_ptr(obj, prop);
if (!*ptr) {
char *str = (char *)"";
@@ -461,16 +453,10 @@ static void get_string(Object *obj, Visitor *v, const char *name,
static void set_string(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- char **ptr = qdev_get_prop_ptr(obj, prop);
+ char **ptr = object_field_prop_ptr(obj, prop);
char *str;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_str(v, name, &str, errp)) {
return;
}
@@ -502,7 +488,7 @@ void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
Property *prop = opaque;
- uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
+ uint32_t *ptr = object_field_prop_ptr(obj, prop);
uint64_t value = *ptr;
visit_type_size(v, name, &value, errp);
@@ -511,16 +497,10 @@ void qdev_propinfo_get_size32(Object *obj, Visitor *v, const char *name,
static void set_size32(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint32_t *ptr = qdev_get_prop_ptr(obj, prop);
+ uint32_t *ptr = object_field_prop_ptr(obj, prop);
uint64_t value;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
-
if (!visit_type_size(v, name, &value, errp)) {
return;
}
@@ -579,18 +559,13 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
* array-length field in the device struct, we have to create the
* array itself and dynamically add the corresponding properties.
*/
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint32_t *alenptr = qdev_get_prop_ptr(obj, prop);
- void **arrayptr = (void *)dev + prop->arrayoffset;
+ uint32_t *alenptr = object_field_prop_ptr(obj, prop);
+ void **arrayptr = (void *)obj + prop->arrayoffset;
void *eltptr;
const char *arrayname;
int i;
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
if (*alenptr) {
error_setg(errp, "array size property %s may not be set more than once",
name);
@@ -626,12 +601,12 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
* they get the right answer despite the array element not actually
* being inside the device struct.
*/
- arrayprop->prop.offset = eltptr - (void *)dev;
- assert(qdev_get_prop_ptr(obj, &arrayprop->prop) == eltptr);
+ arrayprop->prop.offset = eltptr - (void *)obj;
+ assert(object_field_prop_ptr(obj, &arrayprop->prop) == eltptr);
object_property_add(obj, propname,
arrayprop->prop.info->name,
- arrayprop->prop.info->get,
- arrayprop->prop.info->set,
+ field_prop_getter(arrayprop->prop.info),
+ field_prop_setter(arrayprop->prop.info),
array_element_release,
arrayprop);
}
@@ -679,21 +654,21 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
}
void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
- Property *prop, const char *value)
+ const char *name, const char *value)
{
switch (ret) {
case -EEXIST:
error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use",
- object_get_typename(obj), prop->name, value);
+ object_get_typename(obj), name, value);
break;
default:
case -EINVAL:
error_setg(errp, QERR_PROPERTY_VALUE_BAD,
- object_get_typename(obj), prop->name, value);
+ object_get_typename(obj), name, value);
break;
case -ENOENT:
error_setg(errp, "Property '%s.%s' can't find value '%s'",
- object_get_typename(obj), prop->name, value);
+ object_get_typename(obj), name, value);
break;
case 0:
break;
@@ -822,7 +797,7 @@ static void get_size(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
Property *prop = opaque;
- uint64_t *ptr = qdev_get_prop_ptr(obj, prop);
+ uint64_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_size(v, name, ptr, errp);
}
@@ -830,14 +805,8 @@ static void get_size(Object *obj, Visitor *v, const char *name, void *opaque,
static void set_size(Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp)
{
- DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
- uint64_t *ptr = qdev_get_prop_ptr(obj, prop);
-
- if (dev->realized) {
- qdev_prop_set_after_realize(dev, name, errp);
- return;
- }
+ uint64_t *ptr = object_field_prop_ptr(obj, prop);
visit_type_size(v, name, ptr, errp);
}
@@ -851,12 +820,13 @@ const PropertyInfo qdev_prop_size = {
/* --- object link property --- */
-static void create_link_property(ObjectClass *oc, Property *prop)
+static ObjectProperty *create_link_property(ObjectClass *oc, const char *name,
+ Property *prop)
{
- object_class_property_add_link(oc, prop->name, prop->link_type,
- prop->offset,
- qdev_prop_allow_set_link_before_realize,
- OBJ_PROP_LINK_STRONG);
+ return object_class_property_add_link(oc, name, prop->link_type,
+ prop->offset,
+ qdev_prop_allow_set_link_before_realize,
+ OBJ_PROP_LINK_STRONG);
}
const PropertyInfo qdev_prop_link = {
@@ -872,7 +842,8 @@ void qdev_property_add_static(DeviceState *dev, Property *prop)
assert(!prop->info->create);
op = object_property_add(obj, prop->name, prop->info->name,
- prop->info->get, prop->info->set,
+ field_prop_getter(prop->info),
+ field_prop_setter(prop->info),
prop->info->release,
prop);
@@ -887,26 +858,26 @@ void qdev_property_add_static(DeviceState *dev, Property *prop)
}
}
-static void qdev_class_add_property(DeviceClass *klass, Property *prop)
+static void qdev_class_add_property(DeviceClass *klass, const char *name,
+ Property *prop)
{
ObjectClass *oc = OBJECT_CLASS(klass);
+ ObjectProperty *op;
if (prop->info->create) {
- prop->info->create(oc, prop);
+ op = prop->info->create(oc, name, prop);
} else {
- ObjectProperty *op;
-
op = object_class_property_add(oc,
- prop->name, prop->info->name,
- prop->info->get, prop->info->set,
+ name, prop->info->name,
+ field_prop_getter(prop->info),
+ field_prop_setter(prop->info),
prop->info->release,
prop);
- if (prop->set_default) {
- prop->info->set_default_value(op, prop);
- }
}
- object_class_property_set_description(oc, prop->name,
- prop->info->description);
+ if (prop->set_default) {
+ prop->info->set_default_value(op, prop);
+ }
+ object_class_property_set_description(oc, name, prop->info->description);
}
/**
@@ -962,7 +933,7 @@ void device_class_set_props(DeviceClass *dc, Property *props)
dc->props_ = props;
for (prop = props; prop && prop->name; prop++) {
qdev_class_add_legacy_property(dc, prop);
- qdev_class_add_property(dc, prop);
+ qdev_class_add_property(dc, prop->name, prop);
}
}