net: tap: using bool instead of bitfield
[qemu.git] / hw / qdev-addr.c
blobb4388f6a663046db59871e6789cd4891bc6b73d0
1 #include "qdev.h"
2 #include "qdev-addr.h"
3 #include "exec/hwaddr.h"
4 #include "qapi/visitor.h"
6 /* --- target physical address --- */
8 static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
10 hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
12 *ptr = strtoull(str, NULL, 16);
13 return 0;
16 static int print_taddr(DeviceState *dev, Property *prop, char *dest, size_t len)
18 hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
19 return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
22 static void get_taddr(Object *obj, Visitor *v, void *opaque,
23 const char *name, Error **errp)
25 DeviceState *dev = DEVICE(obj);
26 Property *prop = opaque;
27 hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
28 int64_t value;
30 value = *ptr;
31 visit_type_int64(v, &value, name, errp);
34 static void set_taddr(Object *obj, Visitor *v, void *opaque,
35 const char *name, Error **errp)
37 DeviceState *dev = DEVICE(obj);
38 Property *prop = opaque;
39 hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
40 Error *local_err = NULL;
41 int64_t value;
43 if (dev->realized) {
44 error_set(errp, QERR_PERMISSION_DENIED);
45 return;
48 visit_type_int64(v, &value, name, &local_err);
49 if (local_err) {
50 error_propagate(errp, local_err);
51 return;
53 if ((uint64_t)value <= (uint64_t) ~(hwaddr)0) {
54 *ptr = value;
55 } else {
56 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
57 dev->id?:"", name, value, (uint64_t) 0,
58 (uint64_t) ~(hwaddr)0);
63 PropertyInfo qdev_prop_taddr = {
64 .name = "taddr",
65 .parse = parse_taddr,
66 .print = print_taddr,
67 .get = get_taddr,
68 .set = set_taddr,
71 void qdev_prop_set_taddr(DeviceState *dev, const char *name, hwaddr value)
73 Error *errp = NULL;
74 object_property_set_int(OBJECT(dev), value, name, &errp);
75 assert(!errp);