diff mbox series

[RESEND,1/2] hw/vfio/pci-quirks: Resolve redundant property getters

Message ID 20220301225220.239065-2-shentey@gmail.com (mailing list archive)
State New, archived
Headers show
Series Resolve some redundant property accessors | expand

Commit Message

Bernhard Beschow March 1, 2022, 10:52 p.m. UTC
The QOM API already provides getters for uint64 and uint32 values, so reuse
them.

Signed-off-by: Bernhard Beschow <shentey@gmail.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/vfio/pci-quirks.c | 34 +++++++++-------------------------
 1 file changed, 9 insertions(+), 25 deletions(-)

Comments

Bernhard Beschow March 2, 2022, 10:49 a.m. UTC | #1
Am 1. März 2022 22:52:19 UTC schrieb Bernhard Beschow <shentey@gmail.com>:
>The QOM API already provides getters for uint64 and uint32 values, so reuse
>them.
>
>Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Meh, I accidently swapped Alistair's Reviewed-by into this patch while dropping it from the other. Please ignore and sorry for that.

Best regards,
Bernhard

>Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>---
> hw/vfio/pci-quirks.c | 34 +++++++++-------------------------
> 1 file changed, 9 insertions(+), 25 deletions(-)
>
>diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
>index 0cf69a8c6d..f0147a050a 100644
>--- a/hw/vfio/pci-quirks.c
>+++ b/hw/vfio/pci-quirks.c
>@@ -1565,22 +1565,6 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
>     return 0;
> }
> 
>-static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v,
>-                                     const char *name,
>-                                     void *opaque, Error **errp)
>-{
>-    uint64_t tgt = (uintptr_t) opaque;
>-    visit_type_uint64(v, name, &tgt, errp);
>-}
>-
>-static void vfio_pci_nvlink2_get_link_speed(Object *obj, Visitor *v,
>-                                                 const char *name,
>-                                                 void *opaque, Error **errp)
>-{
>-    uint32_t link_speed = (uint32_t)(uintptr_t) opaque;
>-    visit_type_uint32(v, name, &link_speed, errp);
>-}
>-
> int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
> {
>     int ret;
>@@ -1618,9 +1602,9 @@ int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
>                                nv2reg->size, p);
>     QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
> 
>-    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
>-                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
>-                        (void *) (uintptr_t) cap->tgt);
>+    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
>+                                   (uint64_t *) &cap->tgt,
>+                                   OBJ_PROP_FLAG_READ);
>     trace_vfio_pci_nvidia_gpu_setup_quirk(vdev->vbasedev.name, cap->tgt,
>                                           nv2reg->size);
> free_exit:
>@@ -1679,15 +1663,15 @@ int vfio_pci_nvlink2_init(VFIOPCIDevice *vdev, Error **errp)
>         QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
>     }
> 
>-    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
>-                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
>-                        (void *) (uintptr_t) captgt->tgt);
>+    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
>+                                   (uint64_t *) &captgt->tgt,
>+                                   OBJ_PROP_FLAG_READ);
>     trace_vfio_pci_nvlink2_setup_quirk_ssatgt(vdev->vbasedev.name, captgt->tgt,
>                                               atsdreg->size);
> 
>-    object_property_add(OBJECT(vdev), "nvlink2-link-speed", "uint32",
>-                        vfio_pci_nvlink2_get_link_speed, NULL, NULL,
>-                        (void *) (uintptr_t) capspeed->link_speed);
>+    object_property_add_uint32_ptr(OBJECT(vdev), "nvlink2-link-speed",
>+                                   &capspeed->link_speed,
>+                                   OBJ_PROP_FLAG_READ);
>     trace_vfio_pci_nvlink2_setup_quirk_lnkspd(vdev->vbasedev.name,
>                                               capspeed->link_speed);
> free_exit:
Bernhard Beschow March 21, 2022, 10:57 a.m. UTC | #2
Am 1. März 2022 22:52:19 UTC schrieb Bernhard Beschow <shentey@gmail.com>:
>The QOM API already provides getters for uint64 and uint32 values, so reuse
>them.
>
>Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>---
> hw/vfio/pci-quirks.c | 34 +++++++++-------------------------
> 1 file changed, 9 insertions(+), 25 deletions(-)
>
>diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
>index 0cf69a8c6d..f0147a050a 100644
>--- a/hw/vfio/pci-quirks.c
>+++ b/hw/vfio/pci-quirks.c
>@@ -1565,22 +1565,6 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
>     return 0;
> }
> 
>-static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v,
>-                                     const char *name,
>-                                     void *opaque, Error **errp)
>-{
>-    uint64_t tgt = (uintptr_t) opaque;
>-    visit_type_uint64(v, name, &tgt, errp);
>-}
>-
>-static void vfio_pci_nvlink2_get_link_speed(Object *obj, Visitor *v,
>-                                                 const char *name,
>-                                                 void *opaque, Error **errp)
>-{
>-    uint32_t link_speed = (uint32_t)(uintptr_t) opaque;
>-    visit_type_uint32(v, name, &link_speed, errp);
>-}
>-
> int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
> {
>     int ret;
>@@ -1618,9 +1602,9 @@ int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
>                                nv2reg->size, p);
>     QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
> 
>-    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
>-                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
>-                        (void *) (uintptr_t) cap->tgt);
>+    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
>+                                   (uint64_t *) &cap->tgt,
>+                                   OBJ_PROP_FLAG_READ);
>     trace_vfio_pci_nvidia_gpu_setup_quirk(vdev->vbasedev.name, cap->tgt,
>                                           nv2reg->size);
> free_exit:
>@@ -1679,15 +1663,15 @@ int vfio_pci_nvlink2_init(VFIOPCIDevice *vdev, Error **errp)
>         QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
>     }
> 
>-    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
>-                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
>-                        (void *) (uintptr_t) captgt->tgt);
>+    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
>+                                   (uint64_t *) &captgt->tgt,
>+                                   OBJ_PROP_FLAG_READ);
>     trace_vfio_pci_nvlink2_setup_quirk_ssatgt(vdev->vbasedev.name, captgt->tgt,
>                                               atsdreg->size);
> 
>-    object_property_add(OBJECT(vdev), "nvlink2-link-speed", "uint32",
>-                        vfio_pci_nvlink2_get_link_speed, NULL, NULL,
>-                        (void *) (uintptr_t) capspeed->link_speed);
>+    object_property_add_uint32_ptr(OBJECT(vdev), "nvlink2-link-speed",
>+                                   &capspeed->link_speed,
>+                                   OBJ_PROP_FLAG_READ);
>     trace_vfio_pci_nvlink2_setup_quirk_lnkspd(vdev->vbasedev.name,
>                                               capspeed->link_speed);
> free_exit:

Ping

@Alistair: When resending, I accidently added a Reviewed-by with your name here which I asked to be ignored *after* you re-acked patch 2/2. In case you intended to ack this patch as well your voice would be needed again.

Thanks,
Bernhard
Philippe Mathieu-Daudé March 21, 2022, 1:06 p.m. UTC | #3
On 21/3/22 11:57, Bernhard Beschow wrote:
> Am 1. März 2022 22:52:19 UTC schrieb Bernhard Beschow <shentey@gmail.com>:
>> The QOM API already provides getters for uint64 and uint32 values, so reuse
>> them.
>>
>> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> hw/vfio/pci-quirks.c | 34 +++++++++-------------------------
>> 1 file changed, 9 insertions(+), 25 deletions(-)
>>
>> diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
>> index 0cf69a8c6d..f0147a050a 100644
>> --- a/hw/vfio/pci-quirks.c
>> +++ b/hw/vfio/pci-quirks.c
>> @@ -1565,22 +1565,6 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
>>      return 0;
>> }
>>
>> -static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v,
>> -                                     const char *name,
>> -                                     void *opaque, Error **errp)
>> -{
>> -    uint64_t tgt = (uintptr_t) opaque;
>> -    visit_type_uint64(v, name, &tgt, errp);
>> -}
>> -
>> -static void vfio_pci_nvlink2_get_link_speed(Object *obj, Visitor *v,
>> -                                                 const char *name,
>> -                                                 void *opaque, Error **errp)
>> -{
>> -    uint32_t link_speed = (uint32_t)(uintptr_t) opaque;
>> -    visit_type_uint32(v, name, &link_speed, errp);
>> -}
>> -
>> int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
>> {
>>      int ret;
>> @@ -1618,9 +1602,9 @@ int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
>>                                 nv2reg->size, p);
>>      QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
>>
>> -    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
>> -                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
>> -                        (void *) (uintptr_t) cap->tgt);
>> +    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
>> +                                   (uint64_t *) &cap->tgt,
>> +                                   OBJ_PROP_FLAG_READ);
>>      trace_vfio_pci_nvidia_gpu_setup_quirk(vdev->vbasedev.name, cap->tgt,
>>                                            nv2reg->size);
>> free_exit:
>> @@ -1679,15 +1663,15 @@ int vfio_pci_nvlink2_init(VFIOPCIDevice *vdev, Error **errp)
>>          QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
>>      }
>>
>> -    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
>> -                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
>> -                        (void *) (uintptr_t) captgt->tgt);
>> +    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
>> +                                   (uint64_t *) &captgt->tgt,
>> +                                   OBJ_PROP_FLAG_READ);
>>      trace_vfio_pci_nvlink2_setup_quirk_ssatgt(vdev->vbasedev.name, captgt->tgt,
>>                                                atsdreg->size);
>>
>> -    object_property_add(OBJECT(vdev), "nvlink2-link-speed", "uint32",
>> -                        vfio_pci_nvlink2_get_link_speed, NULL, NULL,
>> -                        (void *) (uintptr_t) capspeed->link_speed);
>> +    object_property_add_uint32_ptr(OBJECT(vdev), "nvlink2-link-speed",
>> +                                   &capspeed->link_speed,
>> +                                   OBJ_PROP_FLAG_READ);
>>      trace_vfio_pci_nvlink2_setup_quirk_lnkspd(vdev->vbasedev.name,
>>                                                capspeed->link_speed);
>> free_exit:
> 
> Ping
> 
> @Alistair: When resending, I accidently added a Reviewed-by with your name here which I asked to be ignored *after* you re-acked patch 2/2. In case you intended to ack this patch as well your voice would be needed again.

FWIW I expect these patches to get merged via the qemu-trivial@ tree
once the 7.1 development window opens.
Bernhard Beschow March 23, 2022, 11:37 p.m. UTC | #4
Am 21. März 2022 13:06:29 UTC schrieb "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>:
>On 21/3/22 11:57, Bernhard Beschow wrote:
>> Am 1. März 2022 22:52:19 UTC schrieb Bernhard Beschow <shentey@gmail.com>:
>>> The QOM API already provides getters for uint64 and uint32 values, so reuse
>>> them.
>>>
>>> Signed-off-by: Bernhard Beschow <shentey@gmail.com>
>>> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>>> ---
>>> hw/vfio/pci-quirks.c | 34 +++++++++-------------------------
>>> 1 file changed, 9 insertions(+), 25 deletions(-)
>>>
>>> diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
>>> index 0cf69a8c6d..f0147a050a 100644
>>> --- a/hw/vfio/pci-quirks.c
>>> +++ b/hw/vfio/pci-quirks.c
>>> @@ -1565,22 +1565,6 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
>>>      return 0;
>>> }
>>>
>>> -static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v,
>>> -                                     const char *name,
>>> -                                     void *opaque, Error **errp)
>>> -{
>>> -    uint64_t tgt = (uintptr_t) opaque;
>>> -    visit_type_uint64(v, name, &tgt, errp);
>>> -}
>>> -
>>> -static void vfio_pci_nvlink2_get_link_speed(Object *obj, Visitor *v,
>>> -                                                 const char *name,
>>> -                                                 void *opaque, Error **errp)
>>> -{
>>> -    uint32_t link_speed = (uint32_t)(uintptr_t) opaque;
>>> -    visit_type_uint32(v, name, &link_speed, errp);
>>> -}
>>> -
>>> int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>>      int ret;
>>> @@ -1618,9 +1602,9 @@ int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
>>>                                 nv2reg->size, p);
>>>      QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
>>>
>>> -    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
>>> -                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
>>> -                        (void *) (uintptr_t) cap->tgt);
>>> +    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
>>> +                                   (uint64_t *) &cap->tgt,
>>> +                                   OBJ_PROP_FLAG_READ);
>>>      trace_vfio_pci_nvidia_gpu_setup_quirk(vdev->vbasedev.name, cap->tgt,
>>>                                            nv2reg->size);
>>> free_exit:
>>> @@ -1679,15 +1663,15 @@ int vfio_pci_nvlink2_init(VFIOPCIDevice *vdev, Error **errp)
>>>          QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
>>>      }
>>>
>>> -    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
>>> -                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
>>> -                        (void *) (uintptr_t) captgt->tgt);
>>> +    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
>>> +                                   (uint64_t *) &captgt->tgt,
>>> +                                   OBJ_PROP_FLAG_READ);
>>>      trace_vfio_pci_nvlink2_setup_quirk_ssatgt(vdev->vbasedev.name, captgt->tgt,
>>>                                                atsdreg->size);
>>>
>>> -    object_property_add(OBJECT(vdev), "nvlink2-link-speed", "uint32",
>>> -                        vfio_pci_nvlink2_get_link_speed, NULL, NULL,
>>> -                        (void *) (uintptr_t) capspeed->link_speed);
>>> +    object_property_add_uint32_ptr(OBJECT(vdev), "nvlink2-link-speed",
>>> +                                   &capspeed->link_speed,
>>> +                                   OBJ_PROP_FLAG_READ);
>>>      trace_vfio_pci_nvlink2_setup_quirk_lnkspd(vdev->vbasedev.name,
>>>                                                capspeed->link_speed);
>>> free_exit:
>> 
>> Ping
>> 
>> @Alistair: When resending, I accidently added a Reviewed-by with your name here which I asked to be ignored *after* you re-acked patch 2/2. In case you intended to ack this patch as well your voice would be needed again.
>
>FWIW I expect these patches to get merged via the qemu-trivial@ tree
>once the 7.1 development window opens.

Excellent!

Best regards,
Bernhard
diff mbox series

Patch

diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index 0cf69a8c6d..f0147a050a 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -1565,22 +1565,6 @@  static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
     return 0;
 }
 
-static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v,
-                                     const char *name,
-                                     void *opaque, Error **errp)
-{
-    uint64_t tgt = (uintptr_t) opaque;
-    visit_type_uint64(v, name, &tgt, errp);
-}
-
-static void vfio_pci_nvlink2_get_link_speed(Object *obj, Visitor *v,
-                                                 const char *name,
-                                                 void *opaque, Error **errp)
-{
-    uint32_t link_speed = (uint32_t)(uintptr_t) opaque;
-    visit_type_uint32(v, name, &link_speed, errp);
-}
-
 int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
 {
     int ret;
@@ -1618,9 +1602,9 @@  int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp)
                                nv2reg->size, p);
     QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
 
-    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
-                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
-                        (void *) (uintptr_t) cap->tgt);
+    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
+                                   (uint64_t *) &cap->tgt,
+                                   OBJ_PROP_FLAG_READ);
     trace_vfio_pci_nvidia_gpu_setup_quirk(vdev->vbasedev.name, cap->tgt,
                                           nv2reg->size);
 free_exit:
@@ -1679,15 +1663,15 @@  int vfio_pci_nvlink2_init(VFIOPCIDevice *vdev, Error **errp)
         QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next);
     }
 
-    object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64",
-                        vfio_pci_nvlink2_get_tgt, NULL, NULL,
-                        (void *) (uintptr_t) captgt->tgt);
+    object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt",
+                                   (uint64_t *) &captgt->tgt,
+                                   OBJ_PROP_FLAG_READ);
     trace_vfio_pci_nvlink2_setup_quirk_ssatgt(vdev->vbasedev.name, captgt->tgt,
                                               atsdreg->size);
 
-    object_property_add(OBJECT(vdev), "nvlink2-link-speed", "uint32",
-                        vfio_pci_nvlink2_get_link_speed, NULL, NULL,
-                        (void *) (uintptr_t) capspeed->link_speed);
+    object_property_add_uint32_ptr(OBJECT(vdev), "nvlink2-link-speed",
+                                   &capspeed->link_speed,
+                                   OBJ_PROP_FLAG_READ);
     trace_vfio_pci_nvlink2_setup_quirk_lnkspd(vdev->vbasedev.name,
                                               capspeed->link_speed);
 free_exit: