hw/qdev-properties.c: Improve diagnostic for setting property after realize
[qemu/agraf.git] / hw / qdev-addr.c
blob80a38bb01787146ebf8f838405483e77c84e10be
1 #include "hw/qdev.h"
2 #include "hw/qdev-addr.h"
3 #include "exec/hwaddr.h"
4 #include "qapi/qmp/qerror.h"
5 #include "qapi/visitor.h"
7 /* --- target physical address --- */
9 static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
11 hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
13 *ptr = strtoull(str, NULL, 16);
14 return 0;
17 static int print_taddr(DeviceState *dev, Property *prop, char *dest, size_t len)
19 hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
20 return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
23 static void get_taddr(Object *obj, Visitor *v, void *opaque,
24 const char *name, Error **errp)
26 DeviceState *dev = DEVICE(obj);
27 Property *prop = opaque;
28 hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
29 int64_t value;
31 value = *ptr;
32 visit_type_int64(v, &value, name, errp);
35 static void set_taddr(Object *obj, Visitor *v, void *opaque,
36 const char *name, Error **errp)
38 DeviceState *dev = DEVICE(obj);
39 Property *prop = opaque;
40 hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
41 Error *local_err = NULL;
42 int64_t value;
44 if (dev->realized) {
45 qdev_prop_set_after_realize(dev, name, errp);
46 return;
49 visit_type_int64(v, &value, name, &local_err);
50 if (local_err) {
51 error_propagate(errp, local_err);
52 return;
54 if ((uint64_t)value <= (uint64_t) ~(hwaddr)0) {
55 *ptr = value;
56 } else {
57 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
58 dev->id?:"", name, value, (uint64_t) 0,
59 (uint64_t) ~(hwaddr)0);
64 PropertyInfo qdev_prop_taddr = {
65 .name = "taddr",
66 .parse = parse_taddr,
67 .print = print_taddr,
68 .get = get_taddr,
69 .set = set_taddr,
72 void qdev_prop_set_taddr(DeviceState *dev, const char *name, hwaddr value)
74 Error *errp = NULL;
75 object_property_set_int(OBJECT(dev), value, name, &errp);
76 assert(!errp);