qemu-e2k/hw/qdev-addr.c
Andreas Färber 7983c8a335 qdev: Fold state enum into bool realized
Whether the device was initialized or not is QOM-level information and
currently unused. Drop it from device. This leaves the boolean state of
whether or not DeviceClass::init was called or not, a.k.a. "realized".

Suggested-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2013-01-15 18:26:30 -06:00

78 lines
1.9 KiB
C

#include "qdev.h"
#include "qdev-addr.h"
#include "exec/hwaddr.h"
#include "qapi/visitor.h"
/* --- target physical address --- */
static int parse_taddr(DeviceState *dev, Property *prop, const char *str)
{
hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
*ptr = strtoull(str, NULL, 16);
return 0;
}
static int print_taddr(DeviceState *dev, Property *prop, char *dest, size_t len)
{
hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
return snprintf(dest, len, "0x" TARGET_FMT_plx, *ptr);
}
static void get_taddr(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
int64_t value;
value = *ptr;
visit_type_int64(v, &value, name, errp);
}
static void set_taddr(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
hwaddr *ptr = qdev_get_prop_ptr(dev, prop);
Error *local_err = NULL;
int64_t value;
if (dev->realized) {
error_set(errp, QERR_PERMISSION_DENIED);
return;
}
visit_type_int64(v, &value, name, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
if ((uint64_t)value <= (uint64_t) ~(hwaddr)0) {
*ptr = value;
} else {
error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
dev->id?:"", name, value, (uint64_t) 0,
(uint64_t) ~(hwaddr)0);
}
}
PropertyInfo qdev_prop_taddr = {
.name = "taddr",
.parse = parse_taddr,
.print = print_taddr,
.get = get_taddr,
.set = set_taddr,
};
void qdev_prop_set_taddr(DeviceState *dev, const char *name, hwaddr value)
{
Error *errp = NULL;
object_property_set_int(OBJECT(dev), value, name, &errp);
assert(!errp);
}