From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 01/20] qdev: Add support for uint8_t
Date: Fri, 11 Sep 2009 12:10:21 +0200 [thread overview]
Message-ID: <edefe782f15bcc2bc1f956b4be46b78962f7fc7b.1252662256.git.quintela@redhat.com> (raw)
In-Reply-To: <cover.1252662256.git.quintela@redhat.com>
In-Reply-To: <cover.1252662256.git.quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
hw/qdev-properties.c | 33 +++++++++++++++++++++++++++++++++
hw/qdev.h | 5 +++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 28b2716..57846e3 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -8,6 +8,34 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
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 --- */
static int parse_uint16(DeviceState *dev, Property *prop, const char *str)
@@ -380,6 +408,11 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
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)
{
qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16);
diff --git a/hw/qdev.h b/hw/qdev.h
index c2609b4..530394a 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -60,6 +60,7 @@ struct Property {
enum PropertyType {
PROP_TYPE_UNSPEC = 0,
+ PROP_TYPE_UINT8,
PROP_TYPE_UINT16,
PROP_TYPE_UINT32,
PROP_TYPE_INT32,
@@ -155,6 +156,7 @@ void do_info_qdm(Monitor *mon);
/*** qdev-properties.c ***/
+extern PropertyInfo qdev_prop_uint8;
extern PropertyInfo qdev_prop_uint16;
extern PropertyInfo qdev_prop_uint32;
extern PropertyInfo qdev_prop_int32;
@@ -181,6 +183,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
.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_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
@@ -212,6 +216,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
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_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_uint32(DeviceState *dev, const char *name, uint32_t value);
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
--
1.6.2.5
next prev parent reply other threads:[~2009-09-11 10:13 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-11 10:10 [Qemu-devel] [PATCH 00/20] VMState: port all i2c devices Juan Quintela
2009-09-11 10:10 ` Juan Quintela [this message]
2009-09-11 10:10 ` [Qemu-devel] [PATCH 02/20] i2c: addresses are load/save as uint8_t values, change types to reflect this Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 03/20] vmstate: port i2c_bus device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 04/20] vmstate: port i2c_slave device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 05/20] vmstate: add uint8 array Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 06/20] vmstate: create VMSTATE_I2C_SLAVE Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 07/20] vmstate: port wm8750 device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 08/20] vmstate: port max7310 device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 09/20] vmstate: create VMSTATE_STRUCT_POINTER Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 10/20] vmstate: port pxa2xx_i2c device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 11/20] vmstate: port ssd0303 device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 12/20] vmstate: create VMSTATE_INT16_ARRAY Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 13/20] tmp105: change len and alorm to uint8_t Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 14/20] vmstate: port wmp105 device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 15/20] twl92230: change pwrbtn_state to uint8_t Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 16/20] vmstate: port twl92230 device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 17/20] vmstate: add support for arrays of pointers Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 18/20] lm832x: make fields to have the same types that they are saved/loaded Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 19/20] vmstate: port lm832x device Juan Quintela
2009-09-11 10:10 ` [Qemu-devel] [PATCH 20/20] vmstate: remove i2c_slave_load/save Juan Quintela
2009-09-11 10:31 ` [Qemu-devel] [PATCH 00/20] VMState: port all i2c devices Juha.Riihimaki
2009-09-11 10:47 ` [Qemu-devel] " Juan Quintela
2009-09-12 17:49 ` Juha.Riihimaki
2009-09-13 22:35 ` Juan Quintela
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=edefe782f15bcc2bc1f956b4be46b78962f7fc7b.1252662256.git.quintela@redhat.com \
--to=quintela@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).