Skip to contentSkip to conversation

m48t59: remove legacy init functions

PATCH In review BALATON Zoltan via 3 participants 12 messages Oct 17, 2020 – Oct 18, 2020

lore
Share & tools
lore
#8 lore raw

PATCH 5/6 ppc405_boards: use qdev instead of legacy m48t59_init() function

In reply to BALATON Zoltan via
---
 hw/ppc/ppc405_boards.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/ppc/ppc405_boards.c +2 -1
index 6198ec1035..7a11a38831 100644
@@ -28,6 +28,7 @@
 #include "qemu-common.h"
 #include "cpu.h"
 #include "hw/ppc/ppc.h"
+#include "hw/sysbus.h"
 #include "ppc405.h"
 #include "hw/rtc/m48t59.h"
 #include "hw/block/flash.h"
@@ -227,7 +228,7 @@ static void ref405ep_init(MachineState *machine)
     /* Register FPGA */
     ref405ep_fpga_init(sysmem, 0xF0300000);
     /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    sysbus_create_simple("sysbus-m48t08", 0xF0000000, NULL);
     /* Load kernel */
     linux_boot = (kernel_filename != NULL);
     if (linux_boot) {
Signature · 1 line
2.21.3
#2 lore raw

PATCH 2/6 mt48t59: Set default value of base-year property to 1968

In reply to BALATON Zoltan via

All instances set this value explicitely so make it the default to make it simpler to create instances without setting property.

---
 hw/rtc/m48t59.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rtc/m48t59.c +1 -1
index 6525206976..3108cf3d3f 100644
@@ -655,7 +655,7 @@ static void m48txx_sysbus_toggle_lock(Nvram *obj, int lock)
 }
 
 static Property m48t59_sysbus_properties[] = {
-    DEFINE_PROP_INT32("base-year", M48txxSysBusState, state.base_year, 0),
+    DEFINE_PROP_INT32("base-year", M48txxSysBusState, state.base_year, 1968),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.21.3
#6 lore raw

PATCH 4/6 sun4u: use qdev instead of legacy m48t59_init() function

In reply to BALATON Zoltan via
---
 hw/sparc64/sun4u.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/sparc64/sun4u.c +4 -2
index ad5ca2472a..a89ebed6f0 100644
@@ -671,10 +671,12 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     pci_ide_create_devs(pci_dev);
 
     /* Map NVRAM into I/O (ebus) space */
-    nvram = m48t59_init(NULL, 0, 0, NVRAM_SIZE, 1968, 59);
-    s = SYS_BUS_DEVICE(nvram);
+    dev = qdev_new("sysbus-m48t59");
+    s = SYS_BUS_DEVICE(dev);
+    sysbus_realize_and_unref(s, &error_fatal);
     memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                 sysbus_mmio_get_region(s, 0));
+    nvram = NVRAM(dev);
  
     initrd_size = 0;
     initrd_addr = 0;
Signature · 1 line
2.21.3
#10 lore raw

PATCH 6/6 m48t59: remove legacy m48t59_init() function

In reply to BALATON Zoltan via

From: Mark Cave-Ayland <[email protected]>

Now that all of the callers of this function have been switched to use qdev properties, this legacy init function can now be removed.

---
 hw/rtc/m48t59.c         | 35 -----------------------------------
 include/hw/rtc/m48t59.h |  4 ----
 2 files changed, 39 deletions(-)
hw/rtc/m48t59.c +0 -35
index 3108cf3d3f..e74716c491 100644
@@ -564,41 +564,6 @@ const MemoryRegionOps m48t59_io_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-/* Initialisation routine */
-Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
-                   int model)
-{
-    DeviceState *dev;
-    SysBusDevice *s;
-    int i;
-
-    for (i = 0; i < ARRAY_SIZE(m48txx_sysbus_info); i++) {
-        if (m48txx_sysbus_info[i].size != size ||
-            m48txx_sysbus_info[i].model != model) {
-            continue;
-        }
-
-        dev = qdev_new(m48txx_sysbus_info[i].bus_name);
-        qdev_prop_set_int32(dev, "base-year", base_year);
-        s = SYS_BUS_DEVICE(dev);
-        sysbus_realize_and_unref(s, &error_fatal);
-        sysbus_connect_irq(s, 0, IRQ);
-        if (io_base != 0) {
-            memory_region_add_subregion(get_system_io(), io_base,
-                                        sysbus_mmio_get_region(s, 1));
-        }
-        if (mem_base != 0) {
-            sysbus_mmio_map(s, 0, mem_base);
-        }
-
-        return NVRAM(s);
-    }
-
-    assert(false);
-    return NULL;
-}
-
 void m48t59_realize_common(M48t59State *s, Error **errp)
 {
     s->buffer = g_malloc0(s->size);
include/hw/rtc/m48t59.h +0 -4
index 9defe578d1..d9b45eb161 100644
@@ -47,8 +47,4 @@ struct NvramClass {
     void (*toggle_lock)(Nvram *obj, int lock);
 };
 
-Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
-                   int type);
-
 #endif /* HW_M48T59_H */
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/6 m48t59-isa: remove legacy m48t59_init_isa() function

In reply to BALATON Zoltan via

From: Mark Cave-Ayland <[email protected]>

This function is no longer used within the codebase.

---
 hw/rtc/m48t59-isa.c     | 25 -------------------------
 include/hw/rtc/m48t59.h |  2 --
 2 files changed, 27 deletions(-)
hw/rtc/m48t59-isa.c +0 -25
index cae315e488..dc21fb10a5 100644
@@ -58,31 +58,6 @@ static M48txxInfo m48txx_isa_info[] = {
     }
 };
 
-Nvram *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
-                       int base_year, int model)
-{
-    ISADevice *isa_dev;
-    DeviceState *dev;
-    int i;
-
-    for (i = 0; i < ARRAY_SIZE(m48txx_isa_info); i++) {
-        if (m48txx_isa_info[i].size != size ||
-            m48txx_isa_info[i].model != model) {
-            continue;
-        }
-
-        isa_dev = isa_new(m48txx_isa_info[i].bus_name);
-        dev = DEVICE(isa_dev);
-        qdev_prop_set_uint32(dev, "iobase", io_base);
-        qdev_prop_set_int32(dev, "base-year", base_year);
-        isa_realize_and_unref(isa_dev, bus, &error_fatal);
-        return NVRAM(dev);
-    }
-
-    assert(false);
-    return NULL;
-}
-
 static uint32_t m48txx_isa_read(Nvram *obj, uint32_t addr)
 {
     M48txxISAState *d = M48TXX_ISA(obj);
include/hw/rtc/m48t59.h +0 -2
index 04abedf3b2..9defe578d1 100644
@@ -47,8 +47,6 @@ struct NvramClass {
     void (*toggle_lock)(Nvram *obj, int lock);
 };
 
-Nvram *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
-                       int base_year, int type);
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
                    uint32_t io_base, uint16_t size, int base_year,
                    int type);
Signature · 1 line
2.21.3
#0 lore raw

cover m48t59: remove legacy init functions

This is inspired by Mark's series:

https://lists.nongnu.org/archive/html/qemu-ppc/2020-10/msg00251.html

and implements what I've suggested in review of that series to simplify it and avoid code churn if implementing my suggestion later.

Regards,
BALATON Zoltan

BALATON Zoltan (4):
mt48t59: Set default value of base-year property to 1968
sun4m: use qdev instead of legacy m48t59_init() function
sun4u: use qdev instead of legacy m48t59_init() function
ppc405_boards: use qdev instead of legacy m48t59_init() function

Mark Cave-Ayland (2):
m48t59-isa: remove legacy m48t59_init_isa() function
m48t59: remove legacy m48t59_init() function

 hw/ppc/ppc405_boards.c  |  3 ++-
 hw/rtc/m48t59-isa.c     | 25 -------------------------
 hw/rtc/m48t59.c         | 37 +------------------------------------
 hw/sparc/sun4m.c        |  5 +++--
 hw/sparc64/sun4u.c      |  6 ++++--
 include/hw/rtc/m48t59.h |  6 ------
 6 files changed, 10 insertions(+), 72 deletions(-)
Signature · 1 line
2.21.3
#4 lore raw

PATCH 3/6 sun4m: use qdev instead of legacy m48t59_init() function

Also declare nvram variable with the correct type.

---
 hw/sparc/sun4m.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/sparc/sun4m.c +3 -2
index 54a2b2f9ef..7f1a48440c 100644
@@ -837,7 +837,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
 {
     DeviceState *slavio_intctl;
     unsigned int i;
-    void *nvram;
+    Nvram *nvram;
     qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
     qemu_irq fdc_tc;
     unsigned long kernel_size;
@@ -966,7 +966,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
         create_unimplemented_device("SUNW,sx", hwdef->sx_base, 0x2000);
     }
 
-    nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 1968, 8);
+    nvram = NVRAM(sysbus_create_simple("sysbus-m48t08", hwdef->nvram_base,
+                                       slavio_irq[0]));
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
Signature · 1 line
2.21.3
Reviewed-by on v1 2/6
#3 lore raw

Re: [PATCH 2/6] mt48t59: Set default value of base-year property to 1968

In reply to BALATON Zoltan via
Quoted 1 line · BALATON Zoltan via

All instances set this value explicitely so make it the default to

Typo explicitely -> explicitly.

Quoted 3 lines

make it simpler to create instances without setting property.

Quoted 18 lines
---
  hw/rtc/m48t59.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/rtc/m48t59.c +1 -1
index 6525206976..3108cf3d3f 100644
@@ -655,7 +655,7 @@ static void m48txx_sysbus_toggle_lock(Nvram *obj, int lock)
  }
 
  static Property m48t59_sysbus_properties[] = {
-    DEFINE_PROP_INT32("base-year", M48txxSysBusState, state.base_year, 0),
+    DEFINE_PROP_INT32("base-year", M48txxSysBusState, state.base_year, 1968),
      DEFINE_PROP_END_OF_LIST(),
  };
 
Reviewed-by on v1 5/6
#9 lore raw

Re: [PATCH 5/6] ppc405_boards: use qdev instead of legacy m48t59_init() function

In reply to BALATON Zoltan via
Quoted 4 lines · BALATON Zoltan via
---
  hw/ppc/ppc405_boards.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 23 lines
hw/ppc/ppc405_boards.c +2 -1
index 6198ec1035..7a11a38831 100644
@@ -28,6 +28,7 @@
  #include "qemu-common.h"
  #include "cpu.h"
  #include "hw/ppc/ppc.h"
+#include "hw/sysbus.h"
  #include "ppc405.h"
  #include "hw/rtc/m48t59.h"
  #include "hw/block/flash.h"
@@ -227,7 +228,7 @@ static void ref405ep_init(MachineState *machine)
      /* Register FPGA */
      ref405ep_fpga_init(sysmem, 0xF0300000);
      /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    sysbus_create_simple("sysbus-m48t08", 0xF0000000, NULL);
      /* Load kernel */
      linux_boot = (kernel_filename != NULL);
      if (linux_boot) {
Reviewed-by on v1 3/6
#5 lore raw

Re: [PATCH 3/6] sun4m: use qdev instead of legacy m48t59_init() function

In reply to BALATON Zoltan via
Quoted 3 lines · BALATON Zoltan via

Also declare nvram variable with the correct type.

Quoted 28 lines
---
  hw/sparc/sun4m.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/sparc/sun4m.c +3 -2
index 54a2b2f9ef..7f1a48440c 100644
@@ -837,7 +837,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
  {
      DeviceState *slavio_intctl;
      unsigned int i;
-    void *nvram;
+    Nvram *nvram;
      qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
      qemu_irq fdc_tc;
      unsigned long kernel_size;
@@ -966,7 +966,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
          create_unimplemented_device("SUNW,sx", hwdef->sx_base, 0x2000);
      }
 
-    nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 1968, 8);
+    nvram = NVRAM(sysbus_create_simple("sysbus-m48t08", hwdef->nvram_base,
+                                       slavio_irq[0]));
 
      slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
Reviewed-by on v1 4/6
#7 lore raw

Re: [PATCH 4/6] sun4u: use qdev instead of legacy m48t59_init() function

In reply to BALATON Zoltan via
Quoted 10 lines · BALATON Zoltan via
---
  hw/sparc64/sun4u.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
hw/sparc64/sun4u.c +0 -0
index ad5ca2472a..a89ebed6f0 100644

hw/sparc64/sun4u.c static void sun4uv_init(MemoryRegion *address_space_mem, · line 676

Quoted 8 lines
hw/sparc64/sun4u.c +3 -2
@@ -671,10 +671,12 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
      pci_ide_create_devs(pci_dev);
 
      /* Map NVRAM into I/O (ebus) space */
-    nvram = m48t59_init(NULL, 0, 0, NVRAM_SIZE, 1968, 59);
-    s = SYS_BUS_DEVICE(nvram);
+    dev = qdev_new("sysbus-m48t59");
+    s = SYS_BUS_DEVICE(dev);
+    sysbus_realize_and_unref(s, &error_fatal);

I'd use &error_abort here (so if that ever happens, it is easier to debug it), otherwise:

Quoted 7 lines
hw/sparc64/sun4u.c +1 -0
      memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                  sysbus_mmio_get_region(s, 0));
+    nvram = NVRAM(dev);
 
      initrd_size = 0;
      initrd_addr = 0;
#11 lore raw
In reply to BALATON Zoltan via
Quoted 20 lines · BALATON Zoltan via

This is inspired by Mark's series:

https://lists.nongnu.org/archive/html/qemu-ppc/2020-10/msg00251.html

and implements what I've suggested in review of that series to simplify it and avoid code churn if implementing my suggestion later.

Regards,
BALATON Zoltan

BALATON Zoltan (4):
mt48t59: Set default value of base-year property to 1968
sun4m: use qdev instead of legacy m48t59_init() function
sun4u: use qdev instead of legacy m48t59_init() function
ppc405_boards: use qdev instead of legacy m48t59_init() function

Mark Cave-Ayland (2):

   m48t59-isa: remove legacy m48t59_init_isa() function
   m48t59: remove legacy m48t59_init() function
Quoted 7 lines
  hw/ppc/ppc405_boards.c  |  3 ++-
  hw/rtc/m48t59-isa.c     | 25 -------------------------
  hw/rtc/m48t59.c         | 37 +------------------------------------
  hw/sparc/sun4m.c        |  5 +++--
  hw/sparc64/sun4u.c      |  6 ++++--
  include/hw/rtc/m48t59.h |  6 ------
  6 files changed, 10 insertions(+), 72 deletions(-)

Unfortunately this arrived too late - I'd already finished the tagging and local testing, but didn't get a chance to do the final PR before having to head out yesterday.

I think most people here agree that this code could be improved, but I'm not clear that this is the right solution given that Artyom has already pointed out that 40p uses 1900 as the base year. There would also be an overlap with the ideas that Philippe has expressed in this thread which would cause more code churn later, so if this is something that interests you I would suggest starting a separate thread to gain consensus as to the desired solution first before working on an updated series.

ATB,

Mark.