]> git.proxmox.com Git - qemu.git/blame - hw/qdev-addr.c
virtio-blk: hide VIRTIO_BLK_F_CONFIG_WCE from old machine types
[qemu.git] / hw / qdev-addr.c
CommitLineData
ee6847d1
GH
1#include "qdev.h"
2#include "qdev-addr.h"
3#include "targphys.h"
4
5/* --- target physical address --- */
6
7static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
8{
c227f099 9 target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
ee6847d1
GH
10
11 *ptr = strtoull(str, NULL, 16);
12 return 0;
13}
14
15static int print_taddr(DeviceState *dev, Property *prop, char *dest, size_t len)
16{
c227f099 17 target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
ee6847d1
GH
18 return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
19}
20
57c9fafe 21static void get_taddr(Object *obj, Visitor *v, void *opaque,
80e555c2
PB
22 const char *name, Error **errp)
23{
57c9fafe 24 DeviceState *dev = DEVICE(obj);
80e555c2
PB
25 Property *prop = opaque;
26 target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
27 int64_t value;
28
29 value = *ptr;
c08fb2ac 30 visit_type_int64(v, &value, name, errp);
80e555c2
PB
31}
32
57c9fafe 33static void set_taddr(Object *obj, Visitor *v, void *opaque,
80e555c2
PB
34 const char *name, Error **errp)
35{
57c9fafe 36 DeviceState *dev = DEVICE(obj);
80e555c2
PB
37 Property *prop = opaque;
38 target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
39 Error *local_err = NULL;
40 int64_t value;
41
42 if (dev->state != DEV_STATE_CREATED) {
43 error_set(errp, QERR_PERMISSION_DENIED);
44 return;
45 }
46
c08fb2ac 47 visit_type_int64(v, &value, name, &local_err);
80e555c2
PB
48 if (local_err) {
49 error_propagate(errp, local_err);
50 return;
51 }
52 if ((uint64_t)value <= (uint64_t) ~(target_phys_addr_t)0) {
53 *ptr = value;
54 } else {
55 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
56 dev->id?:"", name, value, (uint64_t) 0,
57 (uint64_t) ~(target_phys_addr_t)0);
58 }
59}
60
61
ee6847d1
GH
62PropertyInfo qdev_prop_taddr = {
63 .name = "taddr",
ee6847d1
GH
64 .parse = parse_taddr,
65 .print = print_taddr,
80e555c2
PB
66 .get = get_taddr,
67 .set = set_taddr,
ee6847d1
GH
68};
69
c227f099 70void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value)
ee6847d1 71{
9b170e60
PB
72 Error *errp = NULL;
73 object_property_set_int(OBJECT(dev), value, name, &errp);
74 assert(!errp);
75
ee6847d1 76}