qdev-addr.c 2.0 KB
Newer Older
G
Gerd Hoffmann 已提交
1 2 3 4 5 6 7 8
#include "qdev.h"
#include "qdev-addr.h"
#include "targphys.h"

/* --- target physical address --- */

static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
{
A
Anthony Liguori 已提交
9
    target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
G
Gerd Hoffmann 已提交
10 11 12 13 14 15 16

    *ptr = strtoull(str, NULL, 16);
    return 0;
}

static int print_taddr(DeviceState *dev, Property *prop, char *dest, size_t len)
{
A
Anthony Liguori 已提交
17
    target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
G
Gerd Hoffmann 已提交
18 19 20
    return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
}

21
static void get_taddr(Object *obj, Visitor *v, void *opaque,
22 23
                      const char *name, Error **errp)
{
24
    DeviceState *dev = DEVICE(obj);
25 26 27 28 29 30 31 32
    Property *prop = opaque;
    target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
    int64_t value;

    value = *ptr;
    visit_type_int(v, &value, name, errp);
}

33
static void set_taddr(Object *obj, Visitor *v, void *opaque,
34 35
                      const char *name, Error **errp)
{
36
    DeviceState *dev = DEVICE(obj);
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    Property *prop = opaque;
    target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
    Error *local_err = NULL;
    int64_t value;

    if (dev->state != DEV_STATE_CREATED) {
        error_set(errp, QERR_PERMISSION_DENIED);
        return;
    }

    visit_type_int(v, &value, name, &local_err);
    if (local_err) {
        error_propagate(errp, local_err);
        return;
    }
    if ((uint64_t)value <= (uint64_t) ~(target_phys_addr_t)0) {
        *ptr = value;
    } else {
        error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
                  dev->id?:"", name, value, (uint64_t) 0,
                  (uint64_t) ~(target_phys_addr_t)0);
    }
}


G
Gerd Hoffmann 已提交
62 63 64
PropertyInfo qdev_prop_taddr = {
    .name  = "taddr",
    .type  = PROP_TYPE_TADDR,
A
Anthony Liguori 已提交
65
    .size  = sizeof(target_phys_addr_t),
G
Gerd Hoffmann 已提交
66 67
    .parse = parse_taddr,
    .print = print_taddr,
68 69
    .get   = get_taddr,
    .set   = set_taddr,
G
Gerd Hoffmann 已提交
70 71
};

A
Anthony Liguori 已提交
72
void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value)
G
Gerd Hoffmann 已提交
73
{
P
Paolo Bonzini 已提交
74 75 76 77
    Error *errp = NULL;
    object_property_set_int(OBJECT(dev), value, name, &errp);
    assert(!errp);

G
Gerd Hoffmann 已提交
78
}