From patchwork Tue Sep 29 20:48:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 34456 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1E78DB7BFF for ; Wed, 30 Sep 2009 07:02:20 +1000 (EST) Received: from localhost ([127.0.0.1]:39743 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Msjpx-0000tb-HX for incoming@patchwork.ozlabs.org; Tue, 29 Sep 2009 17:02:17 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Msjdg-000505-Kk for qemu-devel@nongnu.org; Tue, 29 Sep 2009 16:49:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsjdY-0004v9-Nd for qemu-devel@nongnu.org; Tue, 29 Sep 2009 16:49:34 -0400 Received: from [199.232.76.173] (port=55207 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsjdY-0004v1-2T for qemu-devel@nongnu.org; Tue, 29 Sep 2009 16:49:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1129) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MsjdX-0002OL-B5 for qemu-devel@nongnu.org; Tue, 29 Sep 2009 16:49:27 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8TKnQQb029534 for ; Tue, 29 Sep 2009 16:49:26 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8TKnHXf006885; Tue, 29 Sep 2009 16:49:25 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 29 Sep 2009 22:48:25 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 06/49] qdev: Add support for uint8_t X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Juan Quintela --- 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 2ecb58d..c4fb15c 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) @@ -391,6 +419,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 dfdad90..0a4d07a 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);