2012-10-24 10:43:34 +04:00
|
|
|
#include "net/net.h"
|
2009-07-15 15:43:31 +04:00
|
|
|
#include "qdev.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/blockdev.h"
|
block: Geometry and translation hints are now useless, purge them
There are two producers of these hints: drive_init() on behalf of
-drive, and hd_geometry_guess().
The only consumer of the hint is hd_geometry_guess().
The callers of hd_geometry_guess() call it only when drive_init()
didn't set the hints. Therefore, drive_init()'s hints are never used.
Thus, hd_geometry_guess() only ever sees hints it produced itself in a
prior call. Only the first call computes something, subsequent calls
just repeat the first call's results. However, hd_geometry_guess() is
never called more than once: the device models don't, and the block
device is destroyed on unplug. Thus, dropping the repeat feature
doesn't break anything now.
If a block device wasn't destroyed on unplug and could be reused with
a new device, then repeating old results would be wrong. Thus,
dropping the repeat feature prevents future breakage.
This renders the hints unused. Purge them from the block layer.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-07-10 13:12:50 +04:00
|
|
|
#include "hw/block-common.h"
|
2012-07-24 19:35:09 +04:00
|
|
|
#include "net/hub.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/visitor.h"
|
2012-12-17 21:20:05 +04:00
|
|
|
#include "char/char.h"
|
2009-07-15 15:43:31 +04:00
|
|
|
|
|
|
|
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
|
|
|
|
{
|
|
|
|
void *ptr = dev;
|
|
|
|
ptr += prop->offset;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2012-07-10 13:12:46 +04:00
|
|
|
static void get_enum(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
int *ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
|
|
|
|
visit_type_enum(v, ptr, prop->info->enum_table,
|
|
|
|
prop->info->name, prop->name, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_enum(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
int *ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visit_type_enum(v, ptr, prop->info->enum_table,
|
|
|
|
prop->info->name, prop->name, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bit */
|
|
|
|
|
2010-01-10 14:52:41 +03:00
|
|
|
static uint32_t qdev_get_prop_mask(Property *prop)
|
|
|
|
{
|
2012-02-03 01:51:09 +04:00
|
|
|
assert(prop->info == &qdev_prop_bit);
|
2010-01-10 14:52:41 +03:00
|
|
|
return 0x1 << prop->bitnr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bit_prop_set(DeviceState *dev, Property *props, bool val)
|
|
|
|
{
|
|
|
|
uint32_t *p = qdev_get_prop_ptr(dev, props);
|
|
|
|
uint32_t mask = qdev_get_prop_mask(props);
|
2012-12-05 20:49:10 +04:00
|
|
|
if (val) {
|
2010-01-12 22:16:59 +03:00
|
|
|
*p |= mask;
|
2012-12-05 20:49:10 +04:00
|
|
|
} else {
|
2010-01-10 14:52:41 +03:00
|
|
|
*p &= ~mask;
|
2012-12-05 20:49:10 +04:00
|
|
|
}
|
2010-01-10 14:52:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int print_bit(DeviceState *dev, Property *prop, char *dest, size_t len)
|
|
|
|
{
|
2011-01-11 01:11:40 +03:00
|
|
|
uint32_t *p = qdev_get_prop_ptr(dev, prop);
|
2010-01-10 14:52:41 +03:00
|
|
|
return snprintf(dest, len, (*p & qdev_get_prop_mask(prop)) ? "on" : "off");
|
|
|
|
}
|
|
|
|
|
2012-01-30 18:55:55 +04:00
|
|
|
static void get_bit(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;
|
|
|
|
uint32_t *p = qdev_get_prop_ptr(dev, prop);
|
|
|
|
bool value = (*p & qdev_get_prop_mask(prop)) != 0;
|
|
|
|
|
|
|
|
visit_type_bool(v, &value, name, errp);
|
|
|
|
}
|
|
|
|
|
2012-01-30 18:55:55 +04:00
|
|
|
static void set_bit(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;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visit_type_bool(v, &value, name, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bit_prop_set(dev, prop, value);
|
|
|
|
}
|
|
|
|
|
2010-01-10 14:52:41 +03:00
|
|
|
PropertyInfo qdev_prop_bit = {
|
2011-12-18 20:05:10 +04:00
|
|
|
.name = "boolean",
|
|
|
|
.legacy_name = "on/off",
|
2010-01-10 14:52:41 +03:00
|
|
|
.print = print_bit,
|
2011-12-18 20:05:09 +04:00
|
|
|
.get = get_bit,
|
|
|
|
.set = set_bit,
|
2010-01-10 14:52:41 +03:00
|
|
|
};
|
|
|
|
|
2009-09-30 00:48:25 +04:00
|
|
|
/* --- 8bit integer --- */
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
static void get_uint8(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
2011-12-18 20:05:09 +04:00
|
|
|
{
|
2012-01-30 18:55:55 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2011-12-18 20:05:09 +04:00
|
|
|
Property *prop = opaque;
|
2012-02-22 22:26:37 +04:00
|
|
|
uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
visit_type_uint8(v, ptr, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
static void set_uint8(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
2011-12-18 20:05:09 +04:00
|
|
|
{
|
2012-01-30 18:55:55 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2011-12-18 20:05:09 +04:00
|
|
|
Property *prop = opaque;
|
2012-04-12 17:32:26 +04:00
|
|
|
uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-12 17:32:26 +04:00
|
|
|
visit_type_uint8(v, ptr, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2009-09-30 00:48:25 +04:00
|
|
|
PropertyInfo qdev_prop_uint8 = {
|
|
|
|
.name = "uint8",
|
2012-02-22 22:26:37 +04:00
|
|
|
.get = get_uint8,
|
|
|
|
.set = set_uint8,
|
2009-09-30 00:48:25 +04:00
|
|
|
};
|
|
|
|
|
2011-10-07 11:19:52 +04:00
|
|
|
/* --- 8bit hex value --- */
|
|
|
|
|
|
|
|
static int parse_hex8(DeviceState *dev, Property *prop, const char *str)
|
|
|
|
{
|
|
|
|
uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
char *end;
|
|
|
|
|
2012-02-09 13:07:38 +04:00
|
|
|
if (str[0] != '0' || str[1] != 'x') {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-10-07 11:19:52 +04:00
|
|
|
*ptr = strtoul(str, &end, 16);
|
|
|
|
if ((*end != '\0') || (end == str)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int print_hex8(DeviceState *dev, Property *prop, char *dest, size_t len)
|
|
|
|
{
|
|
|
|
uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
return snprintf(dest, len, "0x%" PRIx8, *ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_hex8 = {
|
2011-12-18 20:05:10 +04:00
|
|
|
.name = "uint8",
|
|
|
|
.legacy_name = "hex8",
|
2011-10-07 11:19:52 +04:00
|
|
|
.parse = parse_hex8,
|
|
|
|
.print = print_hex8,
|
2012-02-22 22:26:37 +04:00
|
|
|
.get = get_uint8,
|
|
|
|
.set = set_uint8,
|
2011-10-07 11:19:52 +04:00
|
|
|
};
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
/* --- 16bit integer --- */
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
static void get_uint16(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
2011-12-18 20:05:09 +04:00
|
|
|
{
|
2012-01-30 18:55:55 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2011-12-18 20:05:09 +04:00
|
|
|
Property *prop = opaque;
|
2012-02-22 22:26:37 +04:00
|
|
|
uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
visit_type_uint16(v, ptr, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
static void set_uint16(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
2011-12-18 20:05:09 +04:00
|
|
|
{
|
2012-01-30 18:55:55 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2011-12-18 20:05:09 +04:00
|
|
|
Property *prop = opaque;
|
2012-04-12 17:32:26 +04:00
|
|
|
uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-12 17:32:26 +04:00
|
|
|
visit_type_uint16(v, ptr, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
PropertyInfo qdev_prop_uint16 = {
|
|
|
|
.name = "uint16",
|
2012-02-22 22:26:37 +04:00
|
|
|
.get = get_uint16,
|
|
|
|
.set = set_uint16,
|
2009-07-15 15:43:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* --- 32bit integer --- */
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
static void get_uint32(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
2012-04-12 17:32:26 +04:00
|
|
|
uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2012-02-22 22:26:37 +04:00
|
|
|
|
2012-04-12 17:32:26 +04:00
|
|
|
visit_type_uint32(v, ptr, name, errp);
|
2012-02-22 22:26:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_uint32(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
2012-04-12 17:32:26 +04:00
|
|
|
uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2012-02-22 22:26:37 +04:00
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-12 17:32:26 +04:00
|
|
|
visit_type_uint32(v, ptr, name, errp);
|
2012-02-22 22:26:37 +04:00
|
|
|
}
|
|
|
|
|
2012-01-30 18:55:55 +04:00
|
|
|
static void get_int32(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;
|
|
|
|
int32_t *ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
visit_type_int32(v, ptr, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2012-01-30 18:55:55 +04:00
|
|
|
static void set_int32(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-04-12 17:32:26 +04:00
|
|
|
int32_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-12 17:32:26 +04:00
|
|
|
visit_type_int32(v, ptr, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
PropertyInfo qdev_prop_uint32 = {
|
|
|
|
.name = "uint32",
|
2012-02-22 22:26:37 +04:00
|
|
|
.get = get_uint32,
|
|
|
|
.set = set_uint32,
|
2009-07-15 15:43:31 +04:00
|
|
|
};
|
|
|
|
|
2009-09-10 13:43:25 +04:00
|
|
|
PropertyInfo qdev_prop_int32 = {
|
|
|
|
.name = "int32",
|
2011-12-18 20:05:09 +04:00
|
|
|
.get = get_int32,
|
|
|
|
.set = set_int32,
|
2009-09-10 13:43:25 +04:00
|
|
|
};
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
/* --- 32bit hex value --- */
|
|
|
|
|
|
|
|
static int parse_hex32(DeviceState *dev, Property *prop, const char *str)
|
|
|
|
{
|
|
|
|
uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2010-06-18 20:27:03 +04:00
|
|
|
char *end;
|
2009-07-15 15:43:31 +04:00
|
|
|
|
2012-02-09 13:07:38 +04:00
|
|
|
if (str[0] != '0' || str[1] != 'x') {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-06-18 20:27:03 +04:00
|
|
|
*ptr = strtoul(str, &end, 16);
|
|
|
|
if ((*end != '\0') || (end == str)) {
|
2010-02-26 17:50:50 +03:00
|
|
|
return -EINVAL;
|
2010-06-18 20:27:03 +04:00
|
|
|
}
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int print_hex32(DeviceState *dev, Property *prop, char *dest, size_t len)
|
|
|
|
{
|
|
|
|
uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
return snprintf(dest, len, "0x%" PRIx32, *ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_hex32 = {
|
2011-12-18 20:05:10 +04:00
|
|
|
.name = "uint32",
|
|
|
|
.legacy_name = "hex32",
|
2009-07-15 15:43:31 +04:00
|
|
|
.parse = parse_hex32,
|
|
|
|
.print = print_hex32,
|
2012-02-22 22:26:37 +04:00
|
|
|
.get = get_uint32,
|
|
|
|
.set = set_uint32,
|
2009-07-15 15:43:31 +04:00
|
|
|
};
|
|
|
|
|
2009-07-21 15:10:41 +04:00
|
|
|
/* --- 64bit integer --- */
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
static void get_uint64(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
2011-12-18 20:05:09 +04:00
|
|
|
{
|
2012-01-30 18:55:55 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2011-12-18 20:05:09 +04:00
|
|
|
Property *prop = opaque;
|
2012-02-22 22:26:37 +04:00
|
|
|
uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
visit_type_uint64(v, ptr, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
static void set_uint64(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
2011-12-18 20:05:09 +04:00
|
|
|
{
|
2012-01-30 18:55:55 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
2011-12-18 20:05:09 +04:00
|
|
|
Property *prop = opaque;
|
2012-02-22 22:26:37 +04:00
|
|
|
uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2011-12-18 20:05:09 +04:00
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
visit_type_uint64(v, ptr, name, errp);
|
2011-12-18 20:05:09 +04:00
|
|
|
}
|
|
|
|
|
2009-07-21 15:10:41 +04:00
|
|
|
PropertyInfo qdev_prop_uint64 = {
|
|
|
|
.name = "uint64",
|
2012-02-22 22:26:37 +04:00
|
|
|
.get = get_uint64,
|
|
|
|
.set = set_uint64,
|
2009-07-21 15:10:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* --- 64bit hex value --- */
|
|
|
|
|
|
|
|
static int parse_hex64(DeviceState *dev, Property *prop, const char *str)
|
|
|
|
{
|
|
|
|
uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2010-06-18 20:27:03 +04:00
|
|
|
char *end;
|
2009-07-21 15:10:41 +04:00
|
|
|
|
2012-02-09 13:07:38 +04:00
|
|
|
if (str[0] != '0' || str[1] != 'x') {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-06-18 20:27:03 +04:00
|
|
|
*ptr = strtoull(str, &end, 16);
|
|
|
|
if ((*end != '\0') || (end == str)) {
|
2010-02-26 17:50:50 +03:00
|
|
|
return -EINVAL;
|
2010-06-18 20:27:03 +04:00
|
|
|
}
|
|
|
|
|
2009-07-21 15:10:41 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int print_hex64(DeviceState *dev, Property *prop, char *dest, size_t len)
|
|
|
|
{
|
|
|
|
uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
return snprintf(dest, len, "0x%" PRIx64, *ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_hex64 = {
|
2011-12-18 20:05:10 +04:00
|
|
|
.name = "uint64",
|
|
|
|
.legacy_name = "hex64",
|
2009-07-21 15:10:41 +04:00
|
|
|
.parse = parse_hex64,
|
|
|
|
.print = print_hex64,
|
2012-02-22 22:26:37 +04:00
|
|
|
.get = get_uint64,
|
|
|
|
.set = set_uint64,
|
2009-07-21 15:10:41 +04:00
|
|
|
};
|
|
|
|
|
2009-10-12 15:45:47 +04:00
|
|
|
/* --- string --- */
|
|
|
|
|
2012-02-02 16:08:48 +04:00
|
|
|
static void release_string(Object *obj, const char *name, void *opaque)
|
2010-06-01 22:32:31 +04:00
|
|
|
{
|
2012-02-02 16:08:48 +04:00
|
|
|
Property *prop = opaque;
|
|
|
|
g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj), prop));
|
2010-06-01 22:32:31 +04:00
|
|
|
}
|
|
|
|
|
2012-12-05 20:49:10 +04:00
|
|
|
static int print_string(DeviceState *dev, Property *prop, char *dest,
|
|
|
|
size_t len)
|
2009-10-12 15:45:47 +04:00
|
|
|
{
|
|
|
|
char **ptr = qdev_get_prop_ptr(dev, prop);
|
2012-12-05 20:49:10 +04:00
|
|
|
if (!*ptr) {
|
2009-10-12 15:45:47 +04:00
|
|
|
return snprintf(dest, len, "<null>");
|
2012-12-05 20:49:10 +04:00
|
|
|
}
|
2009-10-12 15:45:47 +04:00
|
|
|
return snprintf(dest, len, "\"%s\"", *ptr);
|
|
|
|
}
|
|
|
|
|
2012-01-30 18:55:55 +04:00
|
|
|
static void get_string(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;
|
|
|
|
char **ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
|
|
|
|
if (!*ptr) {
|
|
|
|
char *str = (char *)"";
|
|
|
|
visit_type_str(v, &str, name, errp);
|
|
|
|
} else {
|
|
|
|
visit_type_str(v, ptr, name, errp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-30 18:55:55 +04:00
|
|
|
static void set_string(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;
|
|
|
|
char **ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
Error *local_err = NULL;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visit_type_str(v, &str, name, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*ptr) {
|
|
|
|
g_free(*ptr);
|
|
|
|
}
|
|
|
|
*ptr = str;
|
|
|
|
}
|
|
|
|
|
2009-10-12 15:45:47 +04:00
|
|
|
PropertyInfo qdev_prop_string = {
|
|
|
|
.name = "string",
|
|
|
|
.print = print_string,
|
2012-02-02 16:08:48 +04:00
|
|
|
.release = release_string,
|
2011-12-18 20:05:09 +04:00
|
|
|
.get = get_string,
|
|
|
|
.set = set_string,
|
2009-10-12 15:45:47 +04:00
|
|
|
};
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
/* --- pointer --- */
|
|
|
|
|
2010-02-19 13:47:06 +03:00
|
|
|
/* Not a proper property, just for dirty hacks. TODO Remove it! */
|
2009-07-15 15:43:31 +04:00
|
|
|
PropertyInfo qdev_prop_ptr = {
|
|
|
|
.name = "ptr",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --- mac address --- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* accepted syntax versions:
|
|
|
|
* 01:02:03:04:05:06
|
|
|
|
* 01-02-03-04-05-06
|
|
|
|
*/
|
2012-02-02 20:08:47 +04:00
|
|
|
static void get_mac(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
2009-07-15 15:43:31 +04:00
|
|
|
{
|
2012-02-02 20:08:47 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
2009-10-21 17:25:23 +04:00
|
|
|
MACAddr *mac = qdev_get_prop_ptr(dev, prop);
|
2012-02-02 20:08:47 +04:00
|
|
|
char buffer[2 * 6 + 5 + 1];
|
|
|
|
char *p = buffer;
|
|
|
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
|
mac->a[0], mac->a[1], mac->a[2],
|
|
|
|
mac->a[3], mac->a[4], mac->a[5]);
|
|
|
|
|
|
|
|
visit_type_str(v, &p, name, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_mac(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
MACAddr *mac = qdev_get_prop_ptr(dev, prop);
|
|
|
|
Error *local_err = NULL;
|
2009-07-15 15:43:31 +04:00
|
|
|
int i, pos;
|
2012-02-02 20:08:47 +04:00
|
|
|
char *str, *p;
|
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visit_type_str(v, &str, name, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2009-07-15 15:43:31 +04:00
|
|
|
|
|
|
|
for (i = 0, pos = 0; i < 6; i++, pos += 3) {
|
2012-12-05 20:49:10 +04:00
|
|
|
if (!qemu_isxdigit(str[pos])) {
|
2012-02-02 20:08:47 +04:00
|
|
|
goto inval;
|
2012-12-05 20:49:10 +04:00
|
|
|
}
|
|
|
|
if (!qemu_isxdigit(str[pos+1])) {
|
2012-02-02 20:08:47 +04:00
|
|
|
goto inval;
|
2012-12-05 20:49:10 +04:00
|
|
|
}
|
2009-10-21 17:25:23 +04:00
|
|
|
if (i == 5) {
|
2012-12-05 20:49:10 +04:00
|
|
|
if (str[pos+2] != '\0') {
|
2012-02-02 20:08:47 +04:00
|
|
|
goto inval;
|
2012-12-05 20:49:10 +04:00
|
|
|
}
|
2009-10-21 17:25:23 +04:00
|
|
|
} else {
|
2012-12-05 20:49:10 +04:00
|
|
|
if (str[pos+2] != ':' && str[pos+2] != '-') {
|
2012-02-02 20:08:47 +04:00
|
|
|
goto inval;
|
2012-12-05 20:49:10 +04:00
|
|
|
}
|
2009-10-21 17:25:23 +04:00
|
|
|
}
|
|
|
|
mac->a[i] = strtol(str+pos, &p, 16);
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|
2012-05-18 15:14:13 +04:00
|
|
|
g_free(str);
|
2012-02-02 20:08:47 +04:00
|
|
|
return;
|
2009-10-21 17:25:23 +04:00
|
|
|
|
2012-02-02 20:08:47 +04:00
|
|
|
inval:
|
|
|
|
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
|
2012-05-18 15:14:13 +04:00
|
|
|
g_free(str);
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_macaddr = {
|
2009-10-21 17:25:23 +04:00
|
|
|
.name = "macaddr",
|
2012-02-02 20:08:47 +04:00
|
|
|
.get = get_mac,
|
|
|
|
.set = set_mac,
|
2009-07-15 15:43:31 +04:00
|
|
|
};
|
|
|
|
|
2012-01-23 23:15:11 +04:00
|
|
|
/* --- lost tick policy --- */
|
|
|
|
|
2012-02-03 01:09:44 +04:00
|
|
|
static const char *lost_tick_policy_table[LOST_TICK_MAX+1] = {
|
|
|
|
[LOST_TICK_DISCARD] = "discard",
|
|
|
|
[LOST_TICK_DELAY] = "delay",
|
|
|
|
[LOST_TICK_MERGE] = "merge",
|
|
|
|
[LOST_TICK_SLEW] = "slew",
|
|
|
|
[LOST_TICK_MAX] = NULL,
|
2012-01-23 23:15:11 +04:00
|
|
|
};
|
|
|
|
|
2012-02-03 01:09:44 +04:00
|
|
|
QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
|
|
|
|
|
2012-01-23 23:15:11 +04:00
|
|
|
PropertyInfo qdev_prop_losttickpolicy = {
|
2012-02-03 01:09:44 +04:00
|
|
|
.name = "LostTickPolicy",
|
|
|
|
.enum_table = lost_tick_policy_table,
|
|
|
|
.get = get_enum,
|
|
|
|
.set = set_enum,
|
2012-01-23 23:15:11 +04:00
|
|
|
};
|
|
|
|
|
2012-07-10 13:12:47 +04:00
|
|
|
/* --- BIOS CHS translation */
|
|
|
|
|
|
|
|
static const char *bios_chs_trans_table[] = {
|
|
|
|
[BIOS_ATA_TRANSLATION_AUTO] = "auto",
|
|
|
|
[BIOS_ATA_TRANSLATION_NONE] = "none",
|
|
|
|
[BIOS_ATA_TRANSLATION_LBA] = "lba",
|
|
|
|
};
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_bios_chs_trans = {
|
|
|
|
.name = "bios-chs-trans",
|
|
|
|
.enum_table = bios_chs_trans_table,
|
|
|
|
.get = get_enum,
|
|
|
|
.set = set_enum,
|
|
|
|
};
|
|
|
|
|
2009-07-15 15:59:22 +04:00
|
|
|
/* --- pci address --- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bus-local address, i.e. "$slot" or "$slot.$fn"
|
|
|
|
*/
|
2012-02-09 12:53:32 +04:00
|
|
|
static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
2009-07-15 15:59:22 +04:00
|
|
|
{
|
2012-02-09 12:53:32 +04:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
2012-04-12 17:32:26 +04:00
|
|
|
int32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
|
2009-07-15 15:59:22 +04:00
|
|
|
unsigned int slot, fn, n;
|
2012-02-09 12:53:32 +04:00
|
|
|
Error *local_err = NULL;
|
2012-05-18 15:14:13 +04:00
|
|
|
char *str;
|
2012-02-09 12:53:32 +04:00
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visit_type_str(v, &str, name, &local_err);
|
|
|
|
if (local_err) {
|
2012-04-28 06:32:42 +04:00
|
|
|
error_free(local_err);
|
2012-04-12 17:32:26 +04:00
|
|
|
local_err = NULL;
|
|
|
|
visit_type_int32(v, &value, name, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
} else if (value < -1 || value > 255) {
|
|
|
|
error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null",
|
|
|
|
"pci_devfn");
|
|
|
|
} else {
|
|
|
|
*ptr = value;
|
|
|
|
}
|
|
|
|
return;
|
2012-02-09 12:53:32 +04:00
|
|
|
}
|
2009-07-15 15:59:22 +04:00
|
|
|
|
|
|
|
if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) {
|
|
|
|
fn = 0;
|
|
|
|
if (sscanf(str, "%x%n", &slot, &n) != 1) {
|
2012-02-09 12:53:32 +04:00
|
|
|
goto invalid;
|
2009-07-15 15:59:22 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-09 12:53:32 +04:00
|
|
|
if (str[n] != '\0' || fn > 7 || slot > 31) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
2009-07-15 15:59:22 +04:00
|
|
|
*ptr = slot << 3 | fn;
|
2012-05-18 15:14:13 +04:00
|
|
|
g_free(str);
|
2012-02-09 12:53:32 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
|
2012-05-18 15:14:13 +04:00
|
|
|
g_free(str);
|
2009-07-15 15:59:22 +04:00
|
|
|
}
|
|
|
|
|
2012-12-05 20:49:10 +04:00
|
|
|
static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest,
|
|
|
|
size_t len)
|
2009-07-15 15:59:22 +04:00
|
|
|
{
|
2012-03-04 23:38:27 +04:00
|
|
|
int32_t *ptr = qdev_get_prop_ptr(dev, prop);
|
2009-07-15 15:59:22 +04:00
|
|
|
|
2009-08-28 23:12:16 +04:00
|
|
|
if (*ptr == -1) {
|
2009-07-15 15:59:22 +04:00
|
|
|
return snprintf(dest, len, "<unset>");
|
|
|
|
} else {
|
|
|
|
return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_pci_devfn = {
|
2012-02-02 20:12:19 +04:00
|
|
|
.name = "int32",
|
|
|
|
.legacy_name = "pci-devfn",
|
2009-07-15 15:59:22 +04:00
|
|
|
.print = print_pci_devfn,
|
2012-02-02 20:12:19 +04:00
|
|
|
.get = get_int32,
|
2012-02-09 12:53:32 +04:00
|
|
|
.set = set_pci_devfn,
|
2009-07-15 15:59:22 +04:00
|
|
|
};
|
|
|
|
|
2012-03-14 19:57:05 +04:00
|
|
|
/* --- blocksize --- */
|
|
|
|
|
|
|
|
static void set_blocksize(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
2012-02-22 22:26:37 +04:00
|
|
|
uint16_t value, *ptr = qdev_get_prop_ptr(dev, prop);
|
2012-03-14 19:57:05 +04:00
|
|
|
Error *local_err = NULL;
|
2012-04-12 17:32:26 +04:00
|
|
|
const int64_t min = 512;
|
|
|
|
const int64_t max = 32768;
|
2012-03-14 19:57:05 +04:00
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:26:37 +04:00
|
|
|
visit_type_uint16(v, &value, name, &local_err);
|
2012-03-14 19:57:05 +04:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2012-04-12 17:32:26 +04:00
|
|
|
if (value < min || value > max) {
|
2012-03-14 19:57:05 +04:00
|
|
|
error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
|
2012-04-12 17:32:26 +04:00
|
|
|
dev->id?:"", name, (int64_t)value, min, max);
|
2012-03-14 19:57:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We rely on power-of-2 blocksizes for bitmasks */
|
|
|
|
if ((value & (value - 1)) != 0) {
|
|
|
|
error_set(errp, QERR_PROPERTY_VALUE_NOT_POWER_OF_2,
|
2012-02-22 22:26:37 +04:00
|
|
|
dev->id?:"", name, (int64_t)value);
|
2012-03-14 19:57:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ptr = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_blocksize = {
|
|
|
|
.name = "blocksize",
|
2012-02-22 22:26:37 +04:00
|
|
|
.get = get_uint16,
|
2012-03-14 19:57:05 +04:00
|
|
|
.set = set_blocksize,
|
|
|
|
};
|
|
|
|
|
2012-06-21 19:36:23 +04:00
|
|
|
/* --- pci host address --- */
|
|
|
|
|
|
|
|
static void get_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
char buffer[] = "xxxx:xx:xx.x";
|
|
|
|
char *p = buffer;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%d",
|
|
|
|
addr->domain, addr->bus, addr->slot, addr->function);
|
|
|
|
assert(rc == sizeof(buffer) - 1);
|
|
|
|
|
|
|
|
visit_type_str(v, &p, name, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse [<domain>:]<bus>:<slot>.<func>
|
|
|
|
* if <domain> is not supplied, it's assumed to be 0.
|
|
|
|
*/
|
|
|
|
static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
|
|
|
|
const char *name, Error **errp)
|
|
|
|
{
|
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
Property *prop = opaque;
|
|
|
|
PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
Error *local_err = NULL;
|
|
|
|
char *str, *p;
|
|
|
|
char *e;
|
|
|
|
unsigned long val;
|
|
|
|
unsigned long dom = 0, bus = 0;
|
|
|
|
unsigned int slot = 0, func = 0;
|
|
|
|
|
|
|
|
if (dev->state != DEV_STATE_CREATED) {
|
|
|
|
error_set(errp, QERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
visit_type_str(v, &str, name, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = str;
|
|
|
|
val = strtoul(p, &e, 16);
|
|
|
|
if (e == p || *e != ':') {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
bus = val;
|
|
|
|
|
|
|
|
p = e + 1;
|
|
|
|
val = strtoul(p, &e, 16);
|
|
|
|
if (e == p) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
if (*e == ':') {
|
|
|
|
dom = bus;
|
|
|
|
bus = val;
|
|
|
|
p = e + 1;
|
|
|
|
val = strtoul(p, &e, 16);
|
|
|
|
if (e == p) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
slot = val;
|
|
|
|
|
|
|
|
if (*e != '.') {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
p = e + 1;
|
|
|
|
val = strtoul(p, &e, 10);
|
|
|
|
if (e == p) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
func = val;
|
|
|
|
|
|
|
|
if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*e) {
|
|
|
|
goto inval;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr->domain = dom;
|
|
|
|
addr->bus = bus;
|
|
|
|
addr->slot = slot;
|
|
|
|
addr->function = func;
|
|
|
|
|
|
|
|
g_free(str);
|
|
|
|
return;
|
|
|
|
|
|
|
|
inval:
|
|
|
|
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo qdev_prop_pci_host_devaddr = {
|
|
|
|
.name = "pci-host-devaddr",
|
|
|
|
.get = get_pci_host_devaddr,
|
|
|
|
.set = set_pci_host_devaddr,
|
|
|
|
};
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
/* --- public helpers --- */
|
|
|
|
|
|
|
|
static Property *qdev_prop_walk(Property *props, const char *name)
|
|
|
|
{
|
2012-12-05 20:49:10 +04:00
|
|
|
if (!props) {
|
2009-07-15 15:43:31 +04:00
|
|
|
return NULL;
|
2012-12-05 20:49:10 +04:00
|
|
|
}
|
2009-07-15 15:43:31 +04:00
|
|
|
while (props->name) {
|
2012-12-05 20:49:10 +04:00
|
|
|
if (strcmp(props->name, name) == 0) {
|
2009-07-15 15:43:31 +04:00
|
|
|
return props;
|
2012-12-05 20:49:10 +04:00
|
|
|
}
|
2009-07-15 15:43:31 +04:00
|
|
|
props++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property *qdev_prop_find(DeviceState *dev, const char *name)
|
|
|
|
{
|
2012-03-28 20:12:47 +04:00
|
|
|
ObjectClass *class;
|
2009-07-15 15:43:31 +04:00
|
|
|
Property *prop;
|
|
|
|
|
|
|
|
/* device properties */
|
2012-03-28 20:12:47 +04:00
|
|
|
class = object_get_class(OBJECT(dev));
|
|
|
|
do {
|
|
|
|
prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name);
|
|
|
|
if (prop) {
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
class = object_class_get_parent(class);
|
|
|
|
} while (class != object_class_by_name(TYPE_DEVICE));
|
2009-07-15 15:43:31 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-18 20:05:07 +04:00
|
|
|
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
|
|
|
|
Property *prop, const char *value)
|
|
|
|
{
|
|
|
|
switch (ret) {
|
|
|
|
case -EEXIST:
|
|
|
|
error_set(errp, QERR_PROPERTY_VALUE_IN_USE,
|
2011-12-04 21:17:51 +04:00
|
|
|
object_get_typename(OBJECT(dev)), prop->name, value);
|
2011-12-18 20:05:07 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case -EINVAL:
|
|
|
|
error_set(errp, QERR_PROPERTY_VALUE_BAD,
|
2011-12-04 21:17:51 +04:00
|
|
|
object_get_typename(OBJECT(dev)), prop->name, value);
|
2011-12-18 20:05:07 +04:00
|
|
|
break;
|
|
|
|
case -ENOENT:
|
|
|
|
error_set(errp, QERR_PROPERTY_VALUE_NOT_FOUND,
|
2011-12-04 21:17:51 +04:00
|
|
|
object_get_typename(OBJECT(dev)), prop->name, value);
|
2011-12-18 20:05:07 +04:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
|
|
|
|
{
|
2012-02-02 12:47:13 +04:00
|
|
|
char *legacy_name;
|
|
|
|
Error *err = NULL;
|
2009-07-15 15:43:31 +04:00
|
|
|
|
2012-02-02 12:47:13 +04:00
|
|
|
legacy_name = g_strdup_printf("legacy-%s", name);
|
|
|
|
if (object_property_get_type(OBJECT(dev), legacy_name, NULL)) {
|
2012-02-09 13:12:08 +04:00
|
|
|
object_property_parse(OBJECT(dev), value, legacy_name, &err);
|
2012-02-02 12:47:13 +04:00
|
|
|
} else {
|
2012-02-09 13:12:08 +04:00
|
|
|
object_property_parse(OBJECT(dev), value, name, &err);
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|
2012-02-02 12:47:13 +04:00
|
|
|
g_free(legacy_name);
|
|
|
|
|
|
|
|
if (err) {
|
2011-12-18 20:05:07 +04:00
|
|
|
qerror_report_err(err);
|
|
|
|
error_free(err);
|
2009-12-16 16:22:11 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|
|
|
|
|
2010-06-23 11:15:29 +04:00
|
|
|
void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
|
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
object_property_set_bool(OBJECT(dev), value, name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2010-06-23 11:15:29 +04:00
|
|
|
}
|
|
|
|
|
2009-09-30 00:48:25 +04:00
|
|
|
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
|
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
object_property_set_int(OBJECT(dev), value, name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2009-09-30 00:48:25 +04:00
|
|
|
}
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
|
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
object_property_set_int(OBJECT(dev), value, name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value)
|
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
object_property_set_int(OBJECT(dev), value, name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|
|
|
|
|
2009-09-10 13:43:25 +04:00
|
|
|
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value)
|
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
object_property_set_int(OBJECT(dev), value, name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2009-09-10 13:43:25 +04:00
|
|
|
}
|
|
|
|
|
2009-07-21 15:10:41 +04:00
|
|
|
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
|
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
object_property_set_int(OBJECT(dev), value, name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2009-07-21 15:10:41 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:26:17 +04:00
|
|
|
void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value)
|
2010-06-01 22:32:30 +04:00
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
object_property_set_str(OBJECT(dev), value, name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2010-06-01 22:32:30 +04:00
|
|
|
}
|
|
|
|
|
2009-10-21 17:25:23 +04:00
|
|
|
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
|
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Error *errp = NULL;
|
|
|
|
char str[2 * 6 + 5 + 1];
|
|
|
|
snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
|
value[0], value[1], value[2], value[3], value[4], value[5]);
|
|
|
|
|
|
|
|
object_property_set_str(OBJECT(dev), str, name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2009-10-21 17:25:23 +04:00
|
|
|
}
|
|
|
|
|
2012-02-02 15:51:44 +04:00
|
|
|
void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
|
2012-01-23 23:15:11 +04:00
|
|
|
{
|
2012-02-02 15:51:44 +04:00
|
|
|
Property *prop;
|
|
|
|
Error *errp = NULL;
|
|
|
|
|
|
|
|
prop = qdev_prop_find(dev, name);
|
|
|
|
object_property_set_str(OBJECT(dev), prop->info->enum_table[value],
|
|
|
|
name, &errp);
|
2012-02-14 13:19:53 +04:00
|
|
|
assert_no_error(errp);
|
2012-01-23 23:15:11 +04:00
|
|
|
}
|
|
|
|
|
2009-07-15 15:43:31 +04:00
|
|
|
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
|
|
|
|
{
|
2012-02-02 19:58:31 +04:00
|
|
|
Property *prop;
|
|
|
|
void **ptr;
|
|
|
|
|
|
|
|
prop = qdev_prop_find(dev, name);
|
|
|
|
assert(prop && prop->info == &qdev_prop_ptr);
|
|
|
|
ptr = qdev_get_prop_ptr(dev, prop);
|
|
|
|
*ptr = value;
|
2009-07-15 15:43:31 +04:00
|
|
|
}
|
|
|
|
|
2012-12-05 20:49:10 +04:00
|
|
|
static QTAILQ_HEAD(, GlobalProperty) global_props =
|
|
|
|
QTAILQ_HEAD_INITIALIZER(global_props);
|
2009-07-15 15:48:21 +04:00
|
|
|
|
2012-12-05 20:49:11 +04:00
|
|
|
void qdev_prop_register_global(GlobalProperty *prop)
|
2009-07-15 15:48:21 +04:00
|
|
|
{
|
2009-12-08 15:11:33 +03:00
|
|
|
QTAILQ_INSERT_TAIL(&global_props, prop, next);
|
2009-07-15 15:48:21 +04:00
|
|
|
}
|
|
|
|
|
2009-12-08 15:11:33 +03:00
|
|
|
void qdev_prop_register_global_list(GlobalProperty *props)
|
2009-07-15 15:48:21 +04:00
|
|
|
{
|
2009-12-08 15:11:33 +03:00
|
|
|
int i;
|
2009-07-15 15:48:21 +04:00
|
|
|
|
2009-12-08 15:11:33 +03:00
|
|
|
for (i = 0; props[i].driver != NULL; i++) {
|
|
|
|
qdev_prop_register_global(props+i);
|
2009-07-15 15:48:21 +04:00
|
|
|
}
|
2009-12-08 15:11:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void qdev_prop_set_globals(DeviceState *dev)
|
|
|
|
{
|
2012-03-28 20:12:47 +04:00
|
|
|
ObjectClass *class = object_get_class(OBJECT(dev));
|
|
|
|
|
|
|
|
do {
|
|
|
|
GlobalProperty *prop;
|
|
|
|
QTAILQ_FOREACH(prop, &global_props, next) {
|
|
|
|
if (strcmp(object_class_get_name(class), prop->driver) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-07-15 15:48:21 +04:00
|
|
|
}
|
2012-03-28 20:12:47 +04:00
|
|
|
class = object_class_get_parent(class);
|
|
|
|
} while (class);
|
2009-07-15 15:48:21 +04:00
|
|
|
}
|