linux-user: stack_base is now mandatory on all targets
[qemu.git] / hw / qdev-addr.c
1 #include "qdev.h"
2 #include "qdev-addr.h"
3 #include "targphys.h"
4
5 /* --- target physical address --- */
6
7 static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
8 {
9 target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
10
11 *ptr = strtoull(str, NULL, 16);
12 return 0;
13 }
14
15 static int print_taddr(DeviceState *dev, Property *prop, char *dest, size_t len)
16 {
17 target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
18 return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
19 }
20
21 static void get_taddr(DeviceState *dev, Visitor *v, void *opaque,
22 const char *name, Error **errp)
23 {
24 Property *prop = opaque;
25 target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
26 int64_t value;
27
28 value = *ptr;
29 visit_type_int(v, &value, name, errp);
30 }
31
32 static void set_taddr(DeviceState *dev, Visitor *v, void *opaque,
33 const char *name, Error **errp)
34 {
35 Property *prop = opaque;
36 target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
37 Error *local_err = NULL;
38 int64_t value;
39
40 if (dev->state != DEV_STATE_CREATED) {
41 error_set(errp, QERR_PERMISSION_DENIED);
42 return;
43 }
44
45 visit_type_int(v, &value, name, &local_err);
46 if (local_err) {
47 error_propagate(errp, local_err);
48 return;
49 }
50 if ((uint64_t)value <= (uint64_t) ~(target_phys_addr_t)0) {
51 *ptr = value;
52 } else {
53 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
54 dev->id?:"", name, value, (uint64_t) 0,
55 (uint64_t) ~(target_phys_addr_t)0);
56 }
57 }
58
59
60 PropertyInfo qdev_prop_taddr = {
61 .name = "taddr",
62 .type = PROP_TYPE_TADDR,
63 .size = sizeof(target_phys_addr_t),
64 .parse = parse_taddr,
65 .print = print_taddr,
66 .get = get_taddr,
67 .set = set_taddr,
68 };
69
70 void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value)
71 {
72 qdev_prop_set(dev, name, &value, PROP_TYPE_TADDR);
73 }