2009-07-15 15:43:31 +04:00
|
|
|
#include "qdev.h"
|
|
|
|
#include "qdev-addr.h"
|
|
|
|
#include "targphys.h"
|
|
|
|
|
|
|
|
/* --- target physical address --- */
|
|
|
|
|
|
|
|
static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2009-07-15 15:43:31 +04:00
|
|
|
|
|
|
|
*ptr = strtoull(str, NULL, 16);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int print_taddr(DeviceState *dev, Property *prop, char *dest, size_t len)
|
|
|
|
{
|
2009-10-02 01:12:16 +04:00
|
|
|
target_phys_addr_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2009-07-15 15:43:31 +04:00
|
|
|
return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
|
|
|
|
}
|
|
|
|
|
2011-12-18 20:05:09 +04:00
|
|
|
static void get_taddr(DeviceState *dev, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_taddr(DeviceState *dev, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
PropertyInfo qdev_prop_taddr = {
|
|
|
|
.name = "taddr",
|
|
|
|
.type = PROP_TYPE_TADDR,
|
2009-10-02 01:12:16 +04:00
|
|
|
.size = sizeof(target_phys_addr_t),
|
2009-07-15 15:43:31 +04:00
|
|
|
.parse = parse_taddr,
|
|
|
|
.print = print_taddr,
|
2011-12-18 20:05:09 +04:00
|
|
|
.get = get_taddr,
|
|
|
|
.set = set_taddr,
|
2009-07-15 15:43:31 +04:00
|
|
|
};
|
|
|
|
|
2009-10-02 01:12:16 +04:00
|
|
|
void qdev_prop_set_taddr(DeviceState *dev, const char *name, target_phys_addr_t value)
|
2009-07-15 15:43:31 +04:00
|
|
|
{
|
|
|
|
qdev_prop_set(dev, name, &value, PROP_TYPE_TADDR);
|
|
|
|
}
|