提交 c7cc172d 编写于 作者: J Juan Quintela 提交者: Anthony Liguori

qdev: Add support for uint8_t

Signed-off-by: NJuan Quintela <quintela@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 6680f01c
...@@ -8,6 +8,34 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) ...@@ -8,6 +8,34 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
return ptr; return ptr;
} }
/* --- 8bit integer --- */
static int parse_uint8(DeviceState *dev, Property *prop, const char *str)
{
uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
const char *fmt;
/* accept both hex and decimal */
fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx8 : "%" PRIu8;
if (sscanf(str, fmt, ptr) != 1)
return -1;
return 0;
}
static int print_uint8(DeviceState *dev, Property *prop, char *dest, size_t len)
{
uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
return snprintf(dest, len, "%" PRIu8, *ptr);
}
PropertyInfo qdev_prop_uint8 = {
.name = "uint8",
.type = PROP_TYPE_UINT8,
.size = sizeof(uint8_t),
.parse = parse_uint8,
.print = print_uint8,
};
/* --- 16bit integer --- */ /* --- 16bit integer --- */
static int parse_uint16(DeviceState *dev, Property *prop, const char *str) static int parse_uint16(DeviceState *dev, Property *prop, const char *str)
...@@ -391,6 +419,11 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT ...@@ -391,6 +419,11 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
memcpy(dst, src, prop->info->size); memcpy(dst, src, prop->info->size);
} }
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
{
qdev_prop_set(dev, name, &value, PROP_TYPE_UINT8);
}
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value) void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
{ {
qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16); qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16);
......
...@@ -60,6 +60,7 @@ struct Property { ...@@ -60,6 +60,7 @@ struct Property {
enum PropertyType { enum PropertyType {
PROP_TYPE_UNSPEC = 0, PROP_TYPE_UNSPEC = 0,
PROP_TYPE_UINT8,
PROP_TYPE_UINT16, PROP_TYPE_UINT16,
PROP_TYPE_UINT32, PROP_TYPE_UINT32,
PROP_TYPE_INT32, PROP_TYPE_INT32,
...@@ -155,6 +156,7 @@ void do_info_qdm(Monitor *mon); ...@@ -155,6 +156,7 @@ void do_info_qdm(Monitor *mon);
/*** qdev-properties.c ***/ /*** qdev-properties.c ***/
extern PropertyInfo qdev_prop_uint8;
extern PropertyInfo qdev_prop_uint16; extern PropertyInfo qdev_prop_uint16;
extern PropertyInfo qdev_prop_uint32; extern PropertyInfo qdev_prop_uint32;
extern PropertyInfo qdev_prop_int32; extern PropertyInfo qdev_prop_int32;
...@@ -181,6 +183,8 @@ extern PropertyInfo qdev_prop_pci_devfn; ...@@ -181,6 +183,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
.defval = (_type[]) { _defval }, \ .defval = (_type[]) { _defval }, \
} }
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \ #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
...@@ -212,6 +216,7 @@ extern PropertyInfo qdev_prop_pci_devfn; ...@@ -212,6 +216,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop); void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type); void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册