qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	qemu-devel@nongnu.org, dunrong huang <riegamaths@gmail.com>,
	Stefan Weil <weil@mail.berlios.de>,
	Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>,
	Donald Dutile <ddutile@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	Juan Quintela <quintela@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Isaku Yamahata <yamahata@valinux.co.jp>,
	Anthony PERARD <anthony.perard@citrix.com>,
	Kusanagi Kouichi <slash@ac.auone-net.jp>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Stefan Weil <sw@weilnetz.de>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Jan Kiszka <jan.kiszka@web.de>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Kevin Wolf <kwolf@redhat.com>,
	David 'Digit' Turner <digit@google.com>,
	Christoph Egger <Christoph.Egger@amd.com>,
	Amit Shah <amit.shah@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/6] qdev: rework device properties.
Date: Fri, 19 Oct 2012 13:57:51 -0500	[thread overview]
Message-ID: <20121019185751.GZ16157@illuin> (raw)
In-Reply-To: <CAAu8pHv1x=uSZ_+D0DMmYAEvv3=AA8tbyXpopZvthM_yjqNAjQ@mail.gmail.com>

On Fri, Oct 19, 2012 at 05:18:46PM +0000, Blue Swirl wrote:
> On Wed, Oct 17, 2012 at 8:14 PM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> > On Wed, Jul 15, 2009 at 01:43:31PM +0200, Gerd Hoffmann wrote:
> > [...]
> >> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> >> new file mode 100644
> >> index 0000000..8b0d0ff
> >> --- /dev/null
> >> +++ b/hw/qdev-properties.c
> >> @@ -0,0 +1,246 @@
> >
> > Gerd, could you clarify what's the copyright/license of this file? (I
> > mean, at least the copyright/license of the initial version of the file
> > you wrote, below).
> >
> > I am CCing all other authors that touched the file (according to git
> > logs), so they can clarify what's the license they assumed for the file
> > and their contributions.
> 
> I can't remember what I assumed, but I'm fine with GPLv2+.
> 
> Furthermore, in my opinion, my changes were either trivial
> (446333cd5b5c985f6517dee7004e542ecacd21c,
> 73538c31a8f2d5aba3d82d8e60dadcb40d59061b,
> bc19fcaa1b6d2a89b96793c7e8890978fc477f51) or copied heavily from other
> existing code (5a053d1f2e75e6a87c483bb3ff5cc6cdf29e1569) so I think
> that my consent should not be required in case Gerd and others want to
> relicense in the future.
> 

Same goes for me (c08fb2ac)

> >
> >
> >
> >> +#include "qdev.h"
> >> +
> >> +void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
> >> +{
> >> +    void *ptr = dev;
> >> +    ptr += prop->offset;
> >> +    return ptr;
> >> +}
> >> +
> >> +/* --- 16bit integer --- */
> >> +
> >> +static int parse_uint16(DeviceState *dev, Property *prop, const char *str)
> >> +{
> >> +    uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
> >> +    const char *fmt;
> >> +
> >> +    /* accept both hex and decimal */
> >> +    fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx16 : "%" PRIu16;
> >> +    if (sscanf(str, fmt, ptr) != 1)
> >> +        return -1;
> >> +    return 0;
> >> +}
> >> +
> >> +static int print_uint16(DeviceState *dev, Property *prop, char *dest, size_t len)
> >> +{
> >> +    uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
> >> +    return snprintf(dest, len, "%" PRIu16, *ptr);
> >> +}
> >> +
> >> +PropertyInfo qdev_prop_uint16 = {
> >> +    .name  = "uint16",
> >> +    .type  = PROP_TYPE_UINT16,
> >> +    .size  = sizeof(uint16_t),
> >> +    .parse = parse_uint16,
> >> +    .print = print_uint16,
> >> +};
> >> +
> >> +/* --- 32bit integer --- */
> >> +
> >> +static int parse_uint32(DeviceState *dev, Property *prop, const char *str)
> >> +{
> >> +    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
> >> +    const char *fmt;
> >> +
> >> +    /* accept both hex and decimal */
> >> +    fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx32 : "%" PRIu32;
> >> +    if (sscanf(str, fmt, ptr) != 1)
> >> +        return -1;
> >> +    return 0;
> >> +}
> >> +
> >> +static int print_uint32(DeviceState *dev, Property *prop, char *dest, size_t len)
> >> +{
> >> +    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
> >> +    return snprintf(dest, len, "%" PRIu32, *ptr);
> >> +}
> >> +
> >> +PropertyInfo qdev_prop_uint32 = {
> >> +    .name  = "uint32",
> >> +    .type  = PROP_TYPE_UINT32,
> >> +    .size  = sizeof(uint32_t),
> >> +    .parse = parse_uint32,
> >> +    .print = print_uint32,
> >> +};
> >> +
> >> +/* --- 32bit hex value --- */
> >> +
> >> +static int parse_hex32(DeviceState *dev, Property *prop, const char *str)
> >> +{
> >> +    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
> >> +
> >> +    if (sscanf(str, "%" PRIx32, ptr) != 1)
> >> +        return -1;
> >> +    return 0;
> >> +}
> >> +
> >> +static int print_hex32(DeviceState *dev, Property *prop, char *dest, size_t len)
> >> +{
> >> +    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
> >> +    return snprintf(dest, len, "0x%" PRIx32, *ptr);
> >> +}
> >> +
> >> +PropertyInfo qdev_prop_hex32 = {
> >> +    .name  = "hex32",
> >> +    .type  = PROP_TYPE_UINT32,
> >> +    .size  = sizeof(uint32_t),
> >> +    .parse = parse_hex32,
> >> +    .print = print_hex32,
> >> +};
> >> +
> >> +/* --- pointer --- */
> >> +
> >> +static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
> >> +{
> >> +    void **ptr = qdev_get_prop_ptr(dev, prop);
> >> +    return snprintf(dest, len, "<%p>", *ptr);
> >> +}
> >> +
> >> +PropertyInfo qdev_prop_ptr = {
> >> +    .name  = "ptr",
> >> +    .type  = PROP_TYPE_PTR,
> >> +    .size  = sizeof(void*),
> >> +    .print = print_ptr,
> >> +};
> >> +
> >> +/* --- mac address --- */
> >> +
> >> +/*
> >> + * accepted syntax versions:
> >> + *   01:02:03:04:05:06
> >> + *   01-02-03-04-05-06
> >> + */
> >> +static int parse_mac(DeviceState *dev, Property *prop, const char *str)
> >> +{
> >> +    uint8_t *mac = qdev_get_prop_ptr(dev, prop);
> >> +    int i, pos;
> >> +    char *p;
> >> +
> >> +    for (i = 0, pos = 0; i < 6; i++, pos += 3) {
> >> +        if (!isxdigit(str[pos]))
> >> +            return -1;
> >> +        if (!isxdigit(str[pos+1]))
> >> +            return -1;
> >> +        if (i == 5 && str[pos+2] != '\0')
> >> +            return -1;
> >> +        if (str[pos+2] != ':' && str[pos+2] != '-')
> >> +            return -1;
> >> +        mac[i] = strtol(str+pos, &p, 16);
> >> +    }
> >> +    return 0;
> >> +}
> >> +
> >> +static int print_mac(DeviceState *dev, Property *prop, char *dest, size_t len)
> >> +{
> >> +    uint8_t *mac = qdev_get_prop_ptr(dev, prop);
> >> +    return snprintf(dest, len, "%02x:%02x:%02x:%02x:%02x:%02x",
> >> +                    mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
> >> +}
> >> +
> >> +PropertyInfo qdev_prop_macaddr = {
> >> +    .name  = "mac-addr",
> >> +    .type  = PROP_TYPE_MACADDR,
> >> +    .size  = 6,
> >> +    .parse = parse_mac,
> >> +    .print = print_mac,
> >> +};
> >> +
> >> +/* --- public helpers --- */
> >> +
> >> +static Property *qdev_prop_walk(Property *props, const char *name)
> >> +{
> >> +    if (!props)
> >> +        return NULL;
> >> +    while (props->name) {
> >> +        if (strcmp(props->name, name) == 0)
> >> +            return props;
> >> +        props++;
> >> +    }
> >> +    return NULL;
> >> +}
> >> +
> >> +static Property *qdev_prop_find(DeviceState *dev, const char *name)
> >> +{
> >> +    Property *prop;
> >> +
> >> +    /* device properties */
> >> +    prop = qdev_prop_walk(dev->info->props, name);
> >> +    if (prop)
> >> +        return prop;
> >> +
> >> +    /* bus properties */
> >> +    prop = qdev_prop_walk(dev->parent_bus->info->props, name);
> >> +    if (prop)
> >> +        return prop;
> >> +
> >> +    return NULL;
> >> +}
> >> +
> >> +int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
> >> +{
> >> +    Property *prop;
> >> +
> >> +    prop = qdev_prop_find(dev, name);
> >> +    if (!prop) {
> >> +        fprintf(stderr, "property \"%s.%s\" not found\n",
> >> +                dev->info->name, name);
> >> +        return -1;
> >> +    }
> >> +    if (!prop->info->parse) {
> >> +        fprintf(stderr, "property \"%s.%s\" has no parser\n",
> >> +                dev->info->name, name);
> >> +        return -1;
> >> +    }
> >> +    return prop->info->parse(dev, prop, 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) {
> >> +        fprintf(stderr, "%s: property \"%s.%s\" not found\n",
> >> +                __FUNCTION__, dev->info->name, name);
> >> +        abort();
> >> +    }
> >> +    if (prop->info->type != type) {
> >> +        fprintf(stderr, "%s: property \"%s.%s\" type mismatch\n",
> >> +                __FUNCTION__, dev->info->name, name);
> >> +        abort();
> >> +    }
> >> +    dst = qdev_get_prop_ptr(dev, prop);
> >> +    memcpy(dst, src, prop->info->size);
> >> +}
> >> +
> >> +void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value)
> >> +{
> >> +    qdev_prop_set(dev, name, &value, PROP_TYPE_UINT16);
> >> +}
> >> +
> >> +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_ptr(DeviceState *dev, const char *name, void *value)
> >> +{
> >> +    qdev_prop_set(dev, name, &value, PROP_TYPE_PTR);
> >> +}
> >> +
> >> +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);
> >> +        }
> >> +        props++;
> >> +    }
> >> +}
> >> +
> >
> > --
> > Eduardo
> 

  reply	other threads:[~2012-10-19 18:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-15 11:43 [Qemu-devel] [PATCH 0/6] qdev patches: properties, id=<tag>, more device info Gerd Hoffmann
2009-07-15 11:43 ` [Qemu-devel] [PATCH 1/6] qdev: rework device properties Gerd Hoffmann
2012-10-17 20:14   ` Eduardo Habkost
2012-10-17 21:05     ` Stefan Weil
2012-10-17 21:50       ` Eduardo Habkost
2012-10-18  8:07         ` Paolo Bonzini
2012-10-18  6:19     ` Gerd Hoffmann
2012-10-18  6:24     ` Christian Borntraeger
2012-10-18  6:32     ` Jan Kiszka
2012-10-19  7:25       ` Markus Armbruster
2012-10-19  7:23     ` Markus Armbruster
2012-10-19  8:30     ` Michael S. Tsirkin
2012-10-19 17:18     ` Blue Swirl
2012-10-19 18:57       ` Michael Roth [this message]
2012-10-22 10:45     ` Amit Shah
2012-10-23  3:14     ` Isaku Yamahata
2009-07-15 11:43 ` [Qemu-devel] [PATCH 2/6] qdev: factor out driver search to qdev_find_info() Gerd Hoffmann
2009-07-15 11:43 ` [Qemu-devel] [PATCH 3/6] qdev: add no_user, alias and desc Gerd Hoffmann
2009-07-15 11:43 ` [Qemu-devel] [PATCH 4/6] qdev: add user-specified identifier to devices Gerd Hoffmann
2009-07-15 11:43 ` [Qemu-devel] [PATCH 5/6] qdev: add id= support for pci nics Gerd Hoffmann
2009-07-15 11:43 ` [Qemu-devel] [PATCH 6/6] qdev: print device id in "info pci" Gerd Hoffmann

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=20121019185751.GZ16157@illuin \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=Christoph.Egger@amd.com \
    --cc=aliguori@us.ibm.com \
    --cc=amit.shah@redhat.com \
    --cc=anthony.perard@citrix.com \
    --cc=armbru@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=borntraeger@de.ibm.com \
    --cc=ddutile@redhat.com \
    --cc=digit@google.com \
    --cc=ehabkost@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jan.kiszka@web.de \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=riegamaths@gmail.com \
    --cc=slash@ac.auone-net.jp \
    --cc=stefanha@linux.vnet.ibm.com \
    --cc=sw@weilnetz.de \
    --cc=weil@mail.berlios.de \
    --cc=wuzhy@linux.vnet.ibm.com \
    --cc=yamahata@valinux.co.jp \
    /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).