Patchwork [v2,18/27] qdev: make the non-legacy pci address property accept an integer

login
register
mail settings
Submitter Paolo Bonzini
Date Feb. 4, 2012, 8:02 a.m.
Message ID <1328342577-25732-19-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/139542/
State New
Headers show

Comments

Paolo Bonzini - Feb. 4, 2012, 8:02 a.m.
PCI addresses are set with qdev_prop_uint32.  Thus we make the QOM
property accept a device and function encoded in an 8-bit integer,
instead of the magic dd.f hex string.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev-properties.c |   28 +++++++++-------------------
 1 files changed, 9 insertions(+), 19 deletions(-)
Anthony Liguori - Feb. 6, 2012, 2:33 p.m.
On 02/04/2012 02:02 AM, Paolo Bonzini wrote:
> PCI addresses are set with qdev_prop_uint32.  Thus we make the QOM
> property accept a device and function encoded in an 8-bit integer,
> instead of the magic dd.f hex string.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   hw/qdev-properties.c |   28 +++++++++-------------------
>   1 files changed, 9 insertions(+), 19 deletions(-)
>
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 42b9b24..9a67cc5 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -999,30 +999,20 @@ static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t
>       }
>   }
>
> -static void get_pci_devfn(Object *obj, Visitor *v, void *opaque,
> -                          const char *name, Error **errp)
> -{
> -    DeviceState *dev = DEVICE(obj);
> -    Property *prop = opaque;
> -    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
> -    char buffer[32];
> -    char *p = buffer;
> -
> -    buffer[0] = 0;
> -    if (*ptr != -1) {
> -        snprintf(buffer, sizeof(buffer), "%02x.%x", *ptr>>  3, *ptr&  7);
> -    }
> -    visit_type_str(v,&p, name, errp);
> -}
> -
>   PropertyInfo qdev_prop_pci_devfn = {
> -    .name  = "pci-devfn",
> +    .name  = "int32",
> +    .legacy_name  = "pci-devfn",
>       .type  = PROP_TYPE_UINT32,
>       .size  = sizeof(uint32_t),
>       .parse = parse_pci_devfn,
>       .print = print_pci_devfn,
> -    .get   = get_pci_devfn,
> -    .set   = set_generic,
> +    .get   = get_int32,
> +    .set   = set_int32,
> +    /* FIXME: this should be -1...255, but the address is stored
> +     * into an uint32_t rather than int32_t.
> +     */
> +    .min   = 0,
> +    .max   = 0xFFFFFFFFULL,
>   };
>
>   /* --- public helpers --- */

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 42b9b24..9a67cc5 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -999,30 +999,20 @@  static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t
     }
 }
 
-static void get_pci_devfn(Object *obj, Visitor *v, void *opaque,
-                          const char *name, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
-    char buffer[32];
-    char *p = buffer;
-
-    buffer[0] = 0;
-    if (*ptr != -1) {
-        snprintf(buffer, sizeof(buffer), "%02x.%x", *ptr >> 3, *ptr & 7);
-    }
-    visit_type_str(v, &p, name, errp);
-}
-
 PropertyInfo qdev_prop_pci_devfn = {
-    .name  = "pci-devfn",
+    .name  = "int32",
+    .legacy_name  = "pci-devfn",
     .type  = PROP_TYPE_UINT32,
     .size  = sizeof(uint32_t),
     .parse = parse_pci_devfn,
     .print = print_pci_devfn,
-    .get   = get_pci_devfn,
-    .set   = set_generic,
+    .get   = get_int32,
+    .set   = set_int32,
+    /* FIXME: this should be -1...255, but the address is stored
+     * into an uint32_t rather than int32_t.
+     */
+    .min   = 0,
+    .max   = 0xFFFFFFFFULL,
 };
 
 /* --- public helpers --- */