Skip to contentSkip to conversation

Trivial cleanups

PATCH Superseded Bernhard Beschow 4 participants 12 messages May 13, 2023 – May 18, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Trivial cleanups

This series:
* Removes dead code from omap_uart and i82378
* Resolves redundant code in the i8254 timer devices
* Replaces string literals by macro usage for TYPE_ISA_PARALLEL devices

Bernhard Beschow (4):
hw/timer/i8254_common: Share "iobase" property via base class hw/arm/omap: Remove unused omap_uart_attach() hw/char/parallel: Export TYPE_ISA_PARALLEL macro hw/isa/i82378: Remove unused "io" attribute

 include/hw/arm/omap.h      | 1 -
 include/hw/char/parallel.h | 2 ++
 hw/char/omap_uart.c        | 9 ---------
 hw/char/parallel-isa.c     | 2 +-
 hw/char/parallel.c         | 1 -
 hw/i386/kvm/i8254.c        | 1 -
 hw/isa/i82378.c            | 1 -
 hw/isa/isa-superio.c       | 3 ++-
 hw/timer/i8254.c           | 6 ------
 hw/timer/i8254_common.c    | 6 ++++++
 10 files changed, 11 insertions(+), 21 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/4 hw/timer/i8254_common: Share "iobase" property via base class

Both TYPE_KVM_I8254 and TYPE_I8254 have their own but same implementation of the "iobase" property. The storage for the property already resides in PITCommonState, so also move the property definition there.

---
 hw/i386/kvm/i8254.c     | 1 -
 hw/timer/i8254.c        | 6 ------
 hw/timer/i8254_common.c | 6 ++++++
 3 files changed, 6 insertions(+), 7 deletions(-)
hw/i386/kvm/i8254.c +0 -1
index 191a26fa57..6a7383d877 100644
@@ -301,7 +301,6 @@ static void kvm_pit_realizefn(DeviceState *dev, Error **errp)
 }
 
 static Property kvm_pit_properties[] = {
-    DEFINE_PROP_UINT32("iobase", PITCommonState, iobase,  -1),
     DEFINE_PROP_LOSTTICKPOLICY("lost_tick_policy", KVMPITState,
                                lost_tick_policy, LOST_TICK_POLICY_DELAY),
     DEFINE_PROP_END_OF_LIST(),
hw/timer/i8254.c +0 -6
index c8388ea432..c235496fc9 100644
@@ -350,11 +350,6 @@ static void pit_realizefn(DeviceState *dev, Error **errp)
     pc->parent_realize(dev, errp);
 }
 
-static Property pit_properties[] = {
-    DEFINE_PROP_UINT32("iobase", PITCommonState, iobase,  -1),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void pit_class_initfn(ObjectClass *klass, void *data)
 {
     PITClass *pc = PIT_CLASS(klass);
@@ -366,7 +361,6 @@ static void pit_class_initfn(ObjectClass *klass, void *data)
     k->get_channel_info = pit_get_channel_info_common;
     k->post_load = pit_post_load;
     dc->reset = pit_reset;
-    device_class_set_props(dc, pit_properties);
 }
 
 static const TypeInfo pit_info = {
hw/timer/i8254_common.c +6 -0
index 050875b497..e4093e2904 100644
@@ -240,6 +240,11 @@ static const VMStateDescription vmstate_pit_common = {
     }
 };
 
+static Property pit_common_properties[] = {
+    DEFINE_PROP_UINT32("iobase", PITCommonState, iobase,  -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void pit_common_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -252,6 +257,7 @@ static void pit_common_class_init(ObjectClass *klass, void *data)
      * done by board code.
      */
     dc->user_creatable = false;
+    device_class_set_props(dc, pit_common_properties);
 }
 
 static const TypeInfo pit_common_type = {
Signature · 1 line
2.40.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] hw/timer/i8254_common: Share "iobase" property via base class

Quoted 64 lines · Bernhard Beschow

Both TYPE_KVM_I8254 and TYPE_I8254 have their own but same implementation of the "iobase" property. The storage for the property already resides in PITCommonState, so also move the property definition there.

---
  hw/i386/kvm/i8254.c     | 1 -
  hw/timer/i8254.c        | 6 ------
  hw/timer/i8254_common.c | 6 ++++++
  3 files changed, 6 insertions(+), 7 deletions(-)
hw/i386/kvm/i8254.c +0 -1
index 191a26fa57..6a7383d877 100644
@@ -301,7 +301,6 @@ static void kvm_pit_realizefn(DeviceState *dev, Error **errp)
  }
 
  static Property kvm_pit_properties[] = {
-    DEFINE_PROP_UINT32("iobase", PITCommonState, iobase,  -1),
      DEFINE_PROP_LOSTTICKPOLICY("lost_tick_policy", KVMPITState,
                                 lost_tick_policy, LOST_TICK_POLICY_DELAY),
      DEFINE_PROP_END_OF_LIST(),
hw/timer/i8254.c +0 -6
index c8388ea432..c235496fc9 100644
@@ -350,11 +350,6 @@ static void pit_realizefn(DeviceState *dev, Error **errp)
      pc->parent_realize(dev, errp);
  }
 
-static Property pit_properties[] = {
-    DEFINE_PROP_UINT32("iobase", PITCommonState, iobase,  -1),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
  static void pit_class_initfn(ObjectClass *klass, void *data)
  {
      PITClass *pc = PIT_CLASS(klass);
@@ -366,7 +361,6 @@ static void pit_class_initfn(ObjectClass *klass, void *data)
      k->get_channel_info = pit_get_channel_info_common;
      k->post_load = pit_post_load;
      dc->reset = pit_reset;
-    device_class_set_props(dc, pit_properties);
  }
 
  static const TypeInfo pit_info = {
hw/timer/i8254_common.c +5 -0
index 050875b497..e4093e2904 100644
@@ -240,6 +240,11 @@ static const VMStateDescription vmstate_pit_common = {
      }
  };
 
+static Property pit_common_properties[] = {
+    DEFINE_PROP_UINT32("iobase", PITCommonState, iobase,  -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
  static void pit_common_class_init(ObjectClass *klass, void *data)
  {
      DeviceClass *dc = DEVICE_CLASS(klass);

hw/timer/i8254_common.c static void pit_common_class_init(ObjectClass *klass, void *data) · line 263

Quoted 7 lines
hw/timer/i8254_common.c +1 -0
@@ -252,6 +257,7 @@ static void pit_common_class_init(ObjectClass *klass, void *data)
       * done by board code.
       */
      dc->user_creatable = false;
+    device_class_set_props(dc, pit_common_properties);
  }
 
  static const TypeInfo pit_common_type = {

ATB,

Mark.

Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] hw/timer/i8254_common: Share "iobase" property via base class

In reply to Bernhard Beschow
Quoted 10 lines · Bernhard Beschow

Both TYPE_KVM_I8254 and TYPE_I8254 have their own but same implementation of the "iobase" property. The storage for the property already resides in PITCommonState, so also move the property definition there.

---
  hw/i386/kvm/i8254.c     | 1 -
  hw/timer/i8254.c        | 6 ------
  hw/timer/i8254_common.c | 6 ++++++
  3 files changed, 6 insertions(+), 7 deletions(-)
#4 lore raw

PATCH 2/4 hw/arm/omap: Remove unused omap_uart_attach()

In reply to Bernhard Beschow

The function is unused since commit bdad3654d3c55f478e538037d9eccd204e5fc8ee ('hw/arm/nseries: Remove invalid/unnecessary n8x0_uart_setup()').

---
 include/hw/arm/omap.h | 1 -
 hw/char/omap_uart.c   | 9 ---------
 2 files changed, 10 deletions(-)
include/hw/arm/omap.h +0 -1
index c275d9b681..067e9419f7 100644
@@ -724,7 +724,6 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,
                 qemu_irq txdma, qemu_irq rxdma,
                 const char *label, Chardev *chr);
 void omap_uart_reset(struct omap_uart_s *s);
-void omap_uart_attach(struct omap_uart_s *s, Chardev *chr);
 
 struct omap_mpuio_s;
 qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s);
hw/char/omap_uart.c +0 -9
index 1c890b9201..6848bddb4e 100644
@@ -175,12 +175,3 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,
 
     return s;
 }
-
-void omap_uart_attach(struct omap_uart_s *s, Chardev *chr)
-{
-    /* TODO: Should reuse or destroy current s->serial */
-    s->serial = serial_mm_init(get_system_memory(), s->base, 2, s->irq,
-                               omap_clk_getrate(s->fclk) / 16,
-                               chr ?: qemu_chr_new("null", "null", NULL),
-                               DEVICE_NATIVE_ENDIAN);
-}
Signature · 1 line
2.40.1
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] hw/arm/omap: Remove unused omap_uart_attach()

Quoted 29 lines · Bernhard Beschow

The function is unused since commit bdad3654d3c55f478e538037d9eccd204e5fc8ee ('hw/arm/nseries: Remove invalid/unnecessary n8x0_uart_setup()').

---
  include/hw/arm/omap.h | 1 -
  hw/char/omap_uart.c   | 9 ---------
  2 files changed, 10 deletions(-)
include/hw/arm/omap.h +0 -1
index c275d9b681..067e9419f7 100644
@@ -724,7 +724,6 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,
                  qemu_irq txdma, qemu_irq rxdma,
                  const char *label, Chardev *chr);
  void omap_uart_reset(struct omap_uart_s *s);
-void omap_uart_attach(struct omap_uart_s *s, Chardev *chr);
 
  struct omap_mpuio_s;
  qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s);
hw/char/omap_uart.c +0 -0
index 1c890b9201..6848bddb4e 100644
@@ -175,12 +175,3 @@ struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,
 
      return s;

hw/char/omap_uart.c struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem, · line 186

Quoted 10 lines
hw/char/omap_uart.c +0 -9
  }
-
-void omap_uart_attach(struct omap_uart_s *s, Chardev *chr)
-{
-    /* TODO: Should reuse or destroy current s->serial */
-    s->serial = serial_mm_init(get_system_memory(), s->base, 2, s->irq,
-                               omap_clk_getrate(s->fclk) / 16,
-                               chr ?: qemu_chr_new("null", "null", NULL),
-                               DEVICE_NATIVE_ENDIAN);
-}

A quick grep agrees, so:

ATB,

Mark.

Reviewed-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] hw/arm/omap: Remove unused omap_uart_attach()

In reply to Bernhard Beschow
Quoted 9 lines · Bernhard Beschow

The function is unused since commit bdad3654d3c55f478e538037d9eccd204e5fc8ee ('hw/arm/nseries: Remove invalid/unnecessary n8x0_uart_setup()').

---
  include/hw/arm/omap.h | 1 -
  hw/char/omap_uart.c   | 9 ---------
  2 files changed, 10 deletions(-)
#7 lore raw

PATCH 3/4 hw/char/parallel: Export TYPE_ISA_PARALLEL macro

In reply to Bernhard Beschow

Rather than using a string literal which is prone to typos let's use a macro instead which is caught by the compiler if mistyped.

---
 include/hw/char/parallel.h | 2 ++
 hw/char/parallel-isa.c     | 2 +-
 hw/char/parallel.c         | 1 -
 hw/isa/isa-superio.c       | 3 ++-
 4 files changed, 5 insertions(+), 3 deletions(-)
include/hw/char/parallel.h +2 -0
index 0a23c0f57e..29d2876d00 100644
@@ -4,6 +4,8 @@
 #include "hw/isa/isa.h"
 #include "chardev/char.h"
 
+#define TYPE_ISA_PARALLEL "isa-parallel"
+
 void parallel_hds_isa_init(ISABus *bus, int n);
 
 bool parallel_mm_init(MemoryRegion *address_space,
hw/char/parallel-isa.c +1 -1
index 1ccbb96e70..547ae69304 100644
@@ -21,7 +21,7 @@ static void parallel_init(ISABus *bus, int index, Chardev *chr)
     DeviceState *dev;
     ISADevice *isadev;
 
-    isadev = isa_new("isa-parallel");
+    isadev = isa_new(TYPE_ISA_PARALLEL);
     dev = DEVICE(isadev);
     qdev_prop_set_uint32(dev, "index", index);
     qdev_prop_set_chr(dev, "chardev", chr);
hw/char/parallel.c +0 -1
index af551e7864..3d32589bb3 100644
@@ -93,7 +93,6 @@ typedef struct ParallelState {
     PortioList portio_list;
 } ParallelState;
 
-#define TYPE_ISA_PARALLEL "isa-parallel"
 OBJECT_DECLARE_SIMPLE_TYPE(ISAParallelState, ISA_PARALLEL)
 
 struct ISAParallelState {
hw/isa/isa-superio.c +2 -1
index c81bfe58ef..53b80de0ce 100644
@@ -20,6 +20,7 @@
 #include "hw/isa/superio.h"
 #include "hw/qdev-properties.h"
 #include "hw/input/i8042.h"
+#include "hw/char/parallel.h"
 #include "hw/char/serial.h"
 #include "trace.h"
 
@@ -51,7 +52,7 @@ static void isa_superio_realize(DeviceState *dev, Error **errp)
             } else {
                 name = g_strdup_printf("parallel%d", i);
             }
-            isa = isa_new("isa-parallel");
+            isa = isa_new(TYPE_ISA_PARALLEL);
             d = DEVICE(isa);
             qdev_prop_set_uint32(d, "index", i);
             if (k->parallel.get_iobase) {
Signature · 1 line
2.40.1
#8 lore raw

Re: [PATCH 3/4] hw/char/parallel: Export TYPE_ISA_PARALLEL macro

Quoted 16 lines · Bernhard Beschow

Rather than using a string literal which is prone to typos let's use a macro instead which is caught by the compiler if mistyped.

---
  include/hw/char/parallel.h | 2 ++
  hw/char/parallel-isa.c     | 2 +-
  hw/char/parallel.c         | 1 -
  hw/isa/isa-superio.c       | 3 ++-
  4 files changed, 5 insertions(+), 3 deletions(-)
include/hw/char/parallel.h +0 -0
index 0a23c0f57e..29d2876d00 100644

include/hw/char/parallel.h line 8

Quoted 5 lines
include/hw/char/parallel.h +2 -0
@@ -4,6 +4,8 @@
  #include "hw/isa/isa.h"
  #include "chardev/char.h"
 
+#define TYPE_ISA_PARALLEL "isa-parallel"
+

We don't really want to separate the QOM TYPE_* constant macro and the OBJECT_* declaration macro.

It looks like the real issue is that ParallelState should be in include/hw/char/parallel.h, and ISAParallelState along with its QOM macros should be in a new include/hw/char/parallel-isa.h header.

Once that is done then using the TYPE_ISA_PARALLEL QOM macro will "just work".

Quoted 41 lines
include/hw/char/parallel.h +0 -0
  void parallel_hds_isa_init(ISABus *bus, int n);
 
  bool parallel_mm_init(MemoryRegion *address_space,
hw/char/parallel-isa.c +1 -1
index 1ccbb96e70..547ae69304 100644
@@ -21,7 +21,7 @@ static void parallel_init(ISABus *bus, int index, Chardev *chr)
      DeviceState *dev;
      ISADevice *isadev;
 
-    isadev = isa_new("isa-parallel");
+    isadev = isa_new(TYPE_ISA_PARALLEL);
      dev = DEVICE(isadev);
      qdev_prop_set_uint32(dev, "index", index);
      qdev_prop_set_chr(dev, "chardev", chr);
hw/char/parallel.c +0 -1
index af551e7864..3d32589bb3 100644
@@ -93,7 +93,6 @@ typedef struct ParallelState {
      PortioList portio_list;
  } ParallelState;
 
-#define TYPE_ISA_PARALLEL "isa-parallel"
  OBJECT_DECLARE_SIMPLE_TYPE(ISAParallelState, ISA_PARALLEL)
 
  struct ISAParallelState {
hw/isa/isa-superio.c +1 -0
index c81bfe58ef..53b80de0ce 100644
@@ -20,6 +20,7 @@
  #include "hw/isa/superio.h"
  #include "hw/qdev-properties.h"
  #include "hw/input/i8042.h"
+#include "hw/char/parallel.h"
  #include "hw/char/serial.h"
  #include "trace.h"
 

hw/isa/isa-superio.c static void isa_superio_realize(DeviceState *dev, Error **errp) · line 58

Quoted 8 lines
hw/isa/isa-superio.c +1 -1
@@ -51,7 +52,7 @@ static void isa_superio_realize(DeviceState *dev, Error **errp)
              } else {
                  name = g_strdup_printf("parallel%d", i);
              }
-            isa = isa_new("isa-parallel");
+            isa = isa_new(TYPE_ISA_PARALLEL);
              d = DEVICE(isa);
              qdev_prop_set_uint32(d, "index", i);
              if (k->parallel.get_iobase) {

ATB,

Mark.

#9 lore raw

PATCH 4/4 hw/isa/i82378: Remove unused "io" attribute

In reply to Bernhard Beschow

The attribute isn't used since commit 5c9736789b79ea49cd236ac326f0a414f63b1015 "i82378: Cleanup implementation".

---
 hw/isa/i82378.c | 1 -
 1 file changed, 1 deletion(-)
hw/isa/i82378.c +0 -1
index 5432ab5065..63e0857208 100644
@@ -34,7 +34,6 @@ struct I82378State {
 
     qemu_irq cpu_intr;
     qemu_irq *isa_irqs_in;
-    MemoryRegion io;
 };
 
 static const VMStateDescription vmstate_i82378 = {
Signature · 1 line
2.40.1
Reviewed-by on v1 4/4
#10 lore raw

Re: [PATCH 4/4] hw/isa/i82378: Remove unused "io" attribute

Quoted 13 lines · Bernhard Beschow

The attribute isn't used since commit 5c9736789b79ea49cd236ac326f0a414f63b1015 "i82378: Cleanup implementation".

---
  hw/isa/i82378.c | 1 -
  1 file changed, 1 deletion(-)
hw/isa/i82378.c +0 -0
index 5432ab5065..63e0857208 100644

hw/isa/i82378.c struct I82378State { · line 39

Quoted 7 lines
hw/isa/i82378.c +0 -1
@@ -34,7 +34,6 @@ struct I82378State {
 
      qemu_irq cpu_intr;
      qemu_irq *isa_irqs_in;
-    MemoryRegion io;
  };
 
  static const VMStateDescription vmstate_i82378 = {

ATB,

Mark.

Acked-by on the v1 series
#11 lore raw
In reply to Bernhard Beschow
Quoted 10 lines · Bernhard Beschow

This series:
* Removes dead code from omap_uart and i82378
* Resolves redundant code in the i8254 timer devices
* Replaces string literals by macro usage for TYPE_ISA_PARALLEL devices

Bernhard Beschow (4):
hw/timer/i8254_common: Share "iobase" property via base class hw/arm/omap: Remove unused omap_uart_attach() hw/char/parallel: Export TYPE_ISA_PARALLEL macro hw/isa/i82378: Remove unused "io" attribute

Quoted 15 lines
 include/hw/arm/omap.h      | 1 -
 include/hw/char/parallel.h | 2 ++
 hw/char/omap_uart.c        | 9 ---------
 hw/char/parallel-isa.c     | 2 +-
 hw/char/parallel.c         | 1 -
 hw/i386/kvm/i8254.c        | 1 -
 hw/isa/i82378.c            | 1 -
 hw/isa/isa-superio.c       | 3 ++-
 hw/timer/i8254.c           | 6 ------
 hw/timer/i8254_common.c    | 6 ++++++
 10 files changed, 11 insertions(+), 21 deletions(-)
Signature · 1 line
2.40.1