diff options
author | Blue Swirl <blauwirbel@gmail.com> | 2009-07-21 11:10:41 +0000 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2009-07-21 11:10:41 +0000 |
commit | 5a053d1f2e75e6a87c483bb3ff5cc6cdf29e1569 (patch) | |
tree | cad650a6d28eea6c89d6d7062e1fe16e4824ff02 | |
parent | 636aa70ade7e9b96eb9382ba3a503043e83d876b (diff) |
qdev: add 64 bit type
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
-rw-r--r-- | hw/qdev-properties.c | 58 | ||||
-rw-r--r-- | hw/qdev.h | 4 |
2 files changed, 62 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 76699b08ba..4f35f06628 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -88,6 +88,59 @@ PropertyInfo qdev_prop_hex32 = { .print = print_hex32, }; +/* --- 64bit integer --- */ + +static int parse_uint64(DeviceState *dev, Property *prop, const char *str) +{ + uint64_t *ptr = qdev_get_prop_ptr(dev, prop); + const char *fmt; + + /* accept both hex and decimal */ + fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx64 : "%" PRIu64; + if (sscanf(str, fmt, ptr) != 1) + return -1; + return 0; +} + +static int print_uint64(DeviceState *dev, Property *prop, char *dest, size_t len) +{ + uint64_t *ptr = qdev_get_prop_ptr(dev, prop); + return snprintf(dest, len, "%" PRIu64, *ptr); +} + +PropertyInfo qdev_prop_uint64 = { + .name = "uint64", + .type = PROP_TYPE_UINT64, + .size = sizeof(uint64_t), + .parse = parse_uint64, + .print = print_uint64, +}; + +/* --- 64bit hex value --- */ + +static int parse_hex64(DeviceState *dev, Property *prop, const char *str) +{ + uint64_t *ptr = qdev_get_prop_ptr(dev, prop); + + if (sscanf(str, "%" PRIx64, ptr) != 1) + return -1; + 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 = { + .name = "hex64", + .type = PROP_TYPE_UINT64, + .size = sizeof(uint64_t), + .parse = parse_hex64, + .print = print_hex64, +}; + /* --- pointer --- */ static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len) @@ -224,6 +277,11 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value) qdev_prop_set(dev, name, &value, PROP_TYPE_UINT32); } +void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value) +{ + qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64); +} + void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) { qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); @@ -58,6 +58,7 @@ enum PropertyType { PROP_TYPE_UNSPEC = 0, PROP_TYPE_UINT16, PROP_TYPE_UINT32, + PROP_TYPE_UINT64, PROP_TYPE_TADDR, PROP_TYPE_MACADDR, PROP_TYPE_PTR, @@ -145,7 +146,9 @@ void do_info_qtree(Monitor *mon); extern PropertyInfo qdev_prop_uint16; extern PropertyInfo qdev_prop_uint32; +extern PropertyInfo qdev_prop_uint64; extern PropertyInfo qdev_prop_hex32; +extern PropertyInfo qdev_prop_hex64; extern PropertyInfo qdev_prop_ptr; extern PropertyInfo qdev_prop_macaddr; @@ -155,6 +158,7 @@ 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_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_uint64(DeviceState *dev, const char *name, uint64_t value); /* FIXME: Remove opaque pointer properties. */ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_set_defaults(DeviceState *dev, Property *props); |