aboutsummaryrefslogtreecommitdiff
path: root/hw/qdev-properties.c
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2011-10-07 09:19:52 +0200
committerBlue Swirl <blauwirbel@gmail.com>2011-10-16 11:11:51 +0000
commit6835678c259976c87df6be09360c1be85da37538 (patch)
treec0266b0a39cb0d4339d0116c144851d8d9f82a36 /hw/qdev-properties.c
parentc17725f4730941fc06a512ef2aa6c2e9377347ad (diff)
qdev: Add HEX8 property
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Reviewed-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r--hw/qdev-properties.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index e0e54aa857..f0b811c806 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -93,6 +93,35 @@ PropertyInfo qdev_prop_uint8 = {
.print = print_uint8,
};
+/* --- 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;
+
+ *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 = {
+ .name = "hex8",
+ .type = PROP_TYPE_UINT8,
+ .size = sizeof(uint8_t),
+ .parse = parse_hex8,
+ .print = print_hex8,
+};
+
/* --- 16bit integer --- */
static int parse_uint16(DeviceState *dev, Property *prop, const char *str)