qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: qemu-devel@nongnu.org, kraxel@redhat.com
Subject: Re: [Qemu-devel] [PATCHv7 1/3] qdev: add bit property type
Date: Mon, 11 Jan 2010 13:50:41 -0600	[thread overview]
Message-ID: <4B4B8111.901@codemonkey.ws> (raw)
In-Reply-To: <20100110115241.GB27013@redhat.com>

On 01/10/2010 05:52 AM, Michael S. Tsirkin wrote:
> This adds "bit" property type, which is a boolean stored in a 32 bit
> integer field, with legal values on and off.  Will be used by virtio for
> feature bits.
>
> Signed-off-by: Michael S. Tsirkin<mst@redhat.com>
> Acked-by: Gerd Hoffmann<kraxel@redhat.com>
>    

Applied.  Thanks.

Regards,

Anthony Liguori
> ---
>   hw/qdev-properties.c |   62 ++++++++++++++++++++++++++++++++++++++++++++-----
>   hw/qdev.h            |   11 +++++++++
>   2 files changed, 66 insertions(+), 7 deletions(-)
>
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 217ddc0..9e123ae 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -9,6 +9,59 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
>       return ptr;
>   }
>
> +static uint32_t qdev_get_prop_mask(Property *prop)
> +{
> +    assert(prop->info->type == PROP_TYPE_BIT);
> +    return 0x1<<  prop->bitnr;
> +}
> +
> +static void bit_prop_set(DeviceState *dev, Property *props, bool val)
> +{
> +    uint32_t *p = qdev_get_prop_ptr(dev, props);
> +    uint32_t mask = qdev_get_prop_mask(props);
> +    if (val)
> +        *p |= ~mask;
> +    else
> +        *p&= ~mask;
> +}
> +
> +static void qdev_prop_cpy(DeviceState *dev, Property *props, void *src)
> +{
> +    if (props->info->type == PROP_TYPE_BIT) {
> +        bool *defval = src;
> +        bit_prop_set(dev, props, *defval);
> +    } else {
> +        char *dst = qdev_get_prop_ptr(dev, props);
> +        memcpy(dst, src, props->info->size);
> +    }
> +}
> +
> +/* Bit */
> +static int parse_bit(DeviceState *dev, Property *prop, const char *str)
> +{
> +    if (!strncasecmp(str, "on", 2))
> +        bit_prop_set(dev, prop, true);
> +    else if (!strncasecmp(str, "off", 3))
> +        bit_prop_set(dev, prop, false);
> +    else
> +        return -1;
> +    return 0;
> +}
> +
> +static int print_bit(DeviceState *dev, Property *prop, char *dest, size_t len)
> +{
> +    uint8_t *p = qdev_get_prop_ptr(dev, prop);
> +    return snprintf(dest, len, (*p&  qdev_get_prop_mask(prop)) ? "on" : "off");
> +}
> +
> +PropertyInfo qdev_prop_bit = {
> +    .name  = "on/off",
> +    .type  = PROP_TYPE_BIT,
> +    .size  = sizeof(uint32_t),
> +    .parse = parse_bit,
> +    .print = print_bit,
> +};
> +
>   /* --- 8bit integer --- */
>
>   static int parse_uint8(DeviceState *dev, Property *prop, const char *str)
> @@ -511,7 +564,6 @@ 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)
>   {
>       Property *prop;
> -    void *dst;
>
>       prop = qdev_prop_find(dev, name);
>       if (!prop) {
> @@ -524,8 +576,7 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
>                   __FUNCTION__, dev->info->name, name);
>           abort();
>       }
> -    dst = qdev_get_prop_ptr(dev, prop);
> -    memcpy(dst, src, prop->info->size);
> +    qdev_prop_cpy(dev, prop, src);
>   }
>
>   void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value)
> @@ -585,14 +636,11 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
>
>   void qdev_prop_set_defaults(DeviceState *dev, Property *props)
>   {
> -    char *dst;
> -
>       if (!props)
>           return;
>       while (props->name) {
>           if (props->defval) {
> -            dst = qdev_get_prop_ptr(dev, props);
> -            memcpy(dst, props->defval, props->info->size);
> +            qdev_prop_cpy(dev, props, props->defval);
>           }
>           props++;
>       }
> diff --git a/hw/qdev.h b/hw/qdev.h
> index bbcdba1..07b9603 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -64,6 +64,7 @@ struct Property {
>       const char   *name;
>       PropertyInfo *info;
>       int          offset;
> +    int          bitnr;
>       void         *defval;
>   };
>
> @@ -82,6 +83,7 @@ enum PropertyType {
>       PROP_TYPE_NETDEV,
>       PROP_TYPE_VLAN,
>       PROP_TYPE_PTR,
> +    PROP_TYPE_BIT,
>   };
>
>   struct PropertyInfo {
> @@ -173,6 +175,7 @@ void do_device_del(Monitor *mon, const QDict *qdict);
>
>   /*** qdev-properties.c ***/
>
> +extern PropertyInfo qdev_prop_bit;
>   extern PropertyInfo qdev_prop_uint8;
>   extern PropertyInfo qdev_prop_uint16;
>   extern PropertyInfo qdev_prop_uint32;
> @@ -202,6 +205,14 @@ extern PropertyInfo qdev_prop_pci_devfn;
>               + type_check(_type,typeof_field(_state, _field)),           \
>           .defval    = (_type[]) { _defval },                             \
>           }
> +#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) {  \
> +        .name      = (_name),                                    \
> +        .info      =&(qdev_prop_bit),                           \
> +        .bitnr    = (_bit),                                      \
> +        .offset    = offsetof(_state, _field)                    \
> +            + type_check(uint32_t,typeof_field(_state, _field)), \
> +        .defval    = (bool[]) { (_defval) },                     \
> +        }
>
>   #define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
>       DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
>    

  reply	other threads:[~2010-01-11 19:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1263124239.git.mst@redhat.com>
2010-01-10 11:52 ` [Qemu-devel] [PATCHv7 1/3] qdev: add bit property type Michael S. Tsirkin
2010-01-11 19:50   ` Anthony Liguori [this message]
2010-01-10 11:52 ` [Qemu-devel] [PATCHv7 2/3] virtio: rename features -> guest_features Michael S. Tsirkin
2010-01-10 11:52 ` [Qemu-devel] [PATCHv7 3/3] virtio: add features as qdev properties Michael S. Tsirkin
2010-01-12 17:05   ` [Qemu-devel] " Gerd Hoffmann
2010-01-12 18:50     ` Michael S. Tsirkin
2010-01-12 18:09   ` [Qemu-devel] " Christoph Hellwig
2010-01-12 18:52     ` Michael S. Tsirkin
2010-01-12 19:50     ` Michael S. Tsirkin
2010-01-12 22:06       ` Christoph Hellwig
2010-01-13 10:43         ` Michael S. Tsirkin

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=4B4B8111.901@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=kraxel@redhat.com \
    --cc=mst@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).