2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/qdev.h"
|
|
|
|
#include "hw/qdev-addr.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/hwaddr.h"
|
2013-02-04 14:37:52 +04:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/visitor.h"
|
2009-07-15 15:43:31 +04:00
|
|
|
|
|
|
|
/* --- target physical address --- */
|
|
|
|
|
|
|
|
static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
|
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr *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)
|
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
|
2009-07-15 15:43:31 +04:00
|
|
|
return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
|
|
|
|
}
|
|
|
|
|
2012-01-30 18:55:55 +04:00
|
|
|
static void get_taddr(Object *obj, Visitor *v, void *opaque,
|
2011-12-18 20:05:09 +04:00
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
2012-01-30 18:55:55 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2011-12-18 20:05:09 +04:00
|
|
|
Property *prop = opaque;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
int64_t value;
|
|
|
|
|
|
|
|
value = *ptr;
|
2012-02-22 22:26:37 +04:00
|
|
|
visit_type_int64(v, &value, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2012-01-30 18:55:55 +04:00
|
|
|
static void set_taddr(Object *obj, Visitor *v, void *opaque,
|
2011-12-18 20:05:09 +04:00
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
2012-01-30 18:55:55 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2011-12-18 20:05:09 +04:00
|
|
|
Property *prop = opaque;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
Error *local_err = NULL;
|
|
|
|
int64_t value;
|
|
|
|
|
2013-01-09 06:58:10 +04:00
|
|
|
if (dev->realized) {
|
2011-12-18 20:05:09 +04:00
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
visit_type_int64(v, &value, name, &local_err);
|
2011-12-18 20:05:09 +04:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2012-10-23 14:30:10 +04:00
|
|
|
if ((uint64_t)value <= (uint64_t) ~(hwaddr)0) {
|
2011-12-18 20:05:09 +04:00
|
|
|
*ptr = value;
|
|
|
|
} else {
|
|
|
|
error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
|
|
|
|
dev->id?:"", name, value, (uint64_t) 0,
|
2012-10-23 14:30:10 +04:00
|
|
|
(uint64_t) ~(hwaddr)0);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
PropertyInfo qdev_prop_taddr = {
|
|
|
|
.name = "taddr",
|
|
|
|
.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
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
void qdev_prop_set_taddr(DeviceState *dev, const char *name, hwaddr value)
|
2009-07-15 15:43:31 +04:00
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
object_property_set_int(OBJECT(dev), value, name, &errp);
|
|
|
|
assert(!errp);
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|