Patchwork [v2,13/30] misc/ivshmem: QOM Upcast Sweep

login
register
mail settings
Submitter Peter Crosthwaite
Date June 24, 2013, 6:59 a.m.
Message ID <754a2c1bb8f9b99e5e8866950feced91b2334fe9.1372055322.git.peter.crosthwaite@xilinx.com>
Download mbox | patch
Permalink /patch/253671/
State New
Headers show

Comments

Peter Crosthwaite - June 24, 2013, 6:59 a.m.
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

Define and use standard QOM cast macro. Remove usages of DO_UPCAST
and direct -> style upcasting.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/misc/ivshmem.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
Andreas Färber - June 30, 2013, 9:18 a.m.
Am 24.06.2013 08:59, schrieb peter.crosthwaite@xilinx.com:
> From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> 
> Define and use standard QOM cast macro. Remove usages of DO_UPCAST
> and direct -> style upcasting.
> 
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> ---
> 
>  hw/misc/ivshmem.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index 5658f73..fd40caf 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -48,6 +48,10 @@
>  #define IVSHMEM_DPRINTF(fmt, ...)
>  #endif
>  
> +#define TYPE_IVSHMEM "ivshmem"
> +#define IVSHMEM(obj) \
> +    OBJECT_CHECK(IVShmemState, (obj), TYPE_IVSHMEM)
> +
>  typedef struct Peer {
>      int nb_eventfds;
>      EventNotifier *eventfds;
> @@ -341,7 +345,7 @@ static void create_shared_memory_BAR(IVShmemState *s, int fd) {
>  
>      memory_region_init_ram_ptr(&s->ivshmem, "ivshmem.bar2",
>                                 s->ivshmem_size, ptr);
> -    vmstate_register_ram(&s->ivshmem, &s->dev.qdev);
> +    vmstate_register_ram(&s->ivshmem, DEVICE(&s->dev));

DEVICE(s)

>      memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
>  
>      /* region for shared memory */
> @@ -469,7 +473,7 @@ static void ivshmem_read(void *opaque, const uint8_t * buf, int flags)
>                                                              incoming_fd, 0);
>          memory_region_init_ram_ptr(&s->ivshmem,
>                                     "ivshmem.bar2", s->ivshmem_size, map_ptr);
> -        vmstate_register_ram(&s->ivshmem, &s->dev.qdev);
> +        vmstate_register_ram(&s->ivshmem, DEVICE(&s->dev));

DEVICE(s)

Renaming the parent field showed that there are still some s->dev
accesses missed in this patch. Applying anyway to qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next

IMO such casting cleanup patches make the most sense when they are
complete in removing all accesses to the parent field and proving that
by renaming the parent field with the only remaining usage being in
VMSTATE_PCI(). We won't be able to drop DO_UPCAST() since it's being
used outside QOM in the block layer for instance. I'm hoping we can
squash a fixup so that we don't need to touch each device twice.

Regards,
Andreas

>  
>          IVSHMEM_DPRINTF("guest h/w addr = %" PRIu64 ", size = %" PRIu64 "\n",
>                           s->ivshmem_offset, s->ivshmem_size);
> @@ -534,7 +538,7 @@ static void ivshmem_use_msix(IVShmemState * s)
>  
>  static void ivshmem_reset(DeviceState *d)
>  {
> -    IVShmemState *s = DO_UPCAST(IVShmemState, dev.qdev, d);
> +    IVShmemState *s = IVSHMEM(d);
>  
>      s->intrstatus = 0;
>      ivshmem_use_msix(s);
> @@ -648,7 +652,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
>          s->ivshmem_size = ivshmem_get_size(s);
>      }
>  
> -    register_savevm(&s->dev.qdev, "ivshmem", 0, 0, ivshmem_save, ivshmem_load,
> +    register_savevm(DEVICE(dev), "ivshmem", 0, 0, ivshmem_save, ivshmem_load,
>                                                                          dev);
>  
>      /* IRQFD requires MSI */
> @@ -780,10 +784,10 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
>  
>      memory_region_destroy(&s->ivshmem_mmio);
>      memory_region_del_subregion(&s->bar, &s->ivshmem);
> -    vmstate_unregister_ram(&s->ivshmem, &s->dev.qdev);
> +    vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
>      memory_region_destroy(&s->ivshmem);
>      memory_region_destroy(&s->bar);
> -    unregister_savevm(&dev->qdev, "ivshmem", s);
> +    unregister_savevm(DEVICE(dev), "ivshmem", s);
>  }
>  
>  static Property ivshmem_properties[] = {
> @@ -813,7 +817,7 @@ static void ivshmem_class_init(ObjectClass *klass, void *data)
>  }
>  
>  static const TypeInfo ivshmem_info = {
> -    .name          = "ivshmem",
> +    .name          = TYPE_IVSHMEM,
>      .parent        = TYPE_PCI_DEVICE,
>      .instance_size = sizeof(IVShmemState),
>      .class_init    = ivshmem_class_init,
>

Patch

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 5658f73..fd40caf 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -48,6 +48,10 @@ 
 #define IVSHMEM_DPRINTF(fmt, ...)
 #endif
 
+#define TYPE_IVSHMEM "ivshmem"
+#define IVSHMEM(obj) \
+    OBJECT_CHECK(IVShmemState, (obj), TYPE_IVSHMEM)
+
 typedef struct Peer {
     int nb_eventfds;
     EventNotifier *eventfds;
@@ -341,7 +345,7 @@  static void create_shared_memory_BAR(IVShmemState *s, int fd) {
 
     memory_region_init_ram_ptr(&s->ivshmem, "ivshmem.bar2",
                                s->ivshmem_size, ptr);
-    vmstate_register_ram(&s->ivshmem, &s->dev.qdev);
+    vmstate_register_ram(&s->ivshmem, DEVICE(&s->dev));
     memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
 
     /* region for shared memory */
@@ -469,7 +473,7 @@  static void ivshmem_read(void *opaque, const uint8_t * buf, int flags)
                                                             incoming_fd, 0);
         memory_region_init_ram_ptr(&s->ivshmem,
                                    "ivshmem.bar2", s->ivshmem_size, map_ptr);
-        vmstate_register_ram(&s->ivshmem, &s->dev.qdev);
+        vmstate_register_ram(&s->ivshmem, DEVICE(&s->dev));
 
         IVSHMEM_DPRINTF("guest h/w addr = %" PRIu64 ", size = %" PRIu64 "\n",
                          s->ivshmem_offset, s->ivshmem_size);
@@ -534,7 +538,7 @@  static void ivshmem_use_msix(IVShmemState * s)
 
 static void ivshmem_reset(DeviceState *d)
 {
-    IVShmemState *s = DO_UPCAST(IVShmemState, dev.qdev, d);
+    IVShmemState *s = IVSHMEM(d);
 
     s->intrstatus = 0;
     ivshmem_use_msix(s);
@@ -648,7 +652,7 @@  static int pci_ivshmem_init(PCIDevice *dev)
         s->ivshmem_size = ivshmem_get_size(s);
     }
 
-    register_savevm(&s->dev.qdev, "ivshmem", 0, 0, ivshmem_save, ivshmem_load,
+    register_savevm(DEVICE(dev), "ivshmem", 0, 0, ivshmem_save, ivshmem_load,
                                                                         dev);
 
     /* IRQFD requires MSI */
@@ -780,10 +784,10 @@  static void pci_ivshmem_uninit(PCIDevice *dev)
 
     memory_region_destroy(&s->ivshmem_mmio);
     memory_region_del_subregion(&s->bar, &s->ivshmem);
-    vmstate_unregister_ram(&s->ivshmem, &s->dev.qdev);
+    vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
     memory_region_destroy(&s->ivshmem);
     memory_region_destroy(&s->bar);
-    unregister_savevm(&dev->qdev, "ivshmem", s);
+    unregister_savevm(DEVICE(dev), "ivshmem", s);
 }
 
 static Property ivshmem_properties[] = {
@@ -813,7 +817,7 @@  static void ivshmem_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo ivshmem_info = {
-    .name          = "ivshmem",
+    .name          = TYPE_IVSHMEM,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(IVShmemState),
     .class_init    = ivshmem_class_init,