Skip to contentSkip to conversation

hw/rtc/m48t59: Simplify m48t59_init()

PATCH Applied Philippe Mathieu-Daudé 4 participants 10 messages Sep 14, 2020 – Oct 12, 2020

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/rtc/m48t59: Simplify m48t59_init()

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
include/hw/rtc/m48t59.h +1 -1
index 04abedf3b2b..62297ee0db1 100644
@@ -50,7 +50,7 @@ struct NvramClass {
 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,
+                   uint16_t size, int base_year,
                    int type);
 
 #endif /* HW_M48T59_H */
hw/ppc/ppc405_boards.c +1 -1
index 6198ec1035b..93ffee801a3 100644
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
     /* Register FPGA */
     ref405ep_fpga_init(sysmem, 0xF0300000);
     /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    m48t59_init(NULL, 0xF0000000, 8192, 1968, 8);
     /* Load kernel */
     linux_boot = (kernel_filename != NULL);
     if (linux_boot) {
hw/rtc/m48t59.c +2 -8
index 6525206976b..2d6a095c4e4 100644
@@ -566,7 +566,7 @@ const MemoryRegionOps m48t59_io_ops = {
 
 /* Initialisation routine */
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
+                   uint16_t size, int base_year,
                    int model)
 {
     DeviceState *dev;
@@ -584,13 +584,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
         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);
-        }
+        sysbus_mmio_map(s, 0, mem_base);
 
         return NVRAM(s);
     }
hw/sparc/sun4m.c +1 -1
index 947b69d1597..56a0d38f274 100644
@@ -970,7 +970,7 @@ 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 = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
hw/sparc64/sun4u.c +1 -1
index b4aabfc076f..1cc57b030a7 100644
@@ -675,7 +675,7 @@ 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);
+    nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
     s = SYS_BUS_DEVICE(nvram);
     memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                 sysbus_mmio_get_region(s, 0));
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Philippe Mathieu-Daudé

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

Quoted 8 lines
---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)

ppc part

Quoted 81 lines
include/hw/rtc/m48t59.h +1 -1
index 04abedf3b2b..62297ee0db1 100644
@@ -50,7 +50,7 @@ struct NvramClass {
 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,
+                   uint16_t size, int base_year,
                    int type);
 
 #endif /* HW_M48T59_H */
hw/ppc/ppc405_boards.c +1 -1
index 6198ec1035b..93ffee801a3 100644
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
     /* Register FPGA */
     ref405ep_fpga_init(sysmem, 0xF0300000);
     /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    m48t59_init(NULL, 0xF0000000, 8192, 1968, 8);
     /* Load kernel */
     linux_boot = (kernel_filename != NULL);
     if (linux_boot) {
hw/rtc/m48t59.c +2 -8
index 6525206976b..2d6a095c4e4 100644
@@ -566,7 +566,7 @@ const MemoryRegionOps m48t59_io_ops = {
 
 /* Initialisation routine */
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
+                   uint16_t size, int base_year,
                    int model)
 {
     DeviceState *dev;
@@ -584,13 +584,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
         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);
-        }
+        sysbus_mmio_map(s, 0, mem_base);
 
         return NVRAM(s);
     }
hw/sparc/sun4m.c +1 -1
index 947b69d1597..56a0d38f274 100644
@@ -970,7 +970,7 @@ 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 = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
hw/sparc64/sun4u.c +1 -1
index b4aabfc076f..1cc57b030a7 100644
@@ -675,7 +675,7 @@ 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);
+    nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
     s = SYS_BUS_DEVICE(nvram);
     memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                 sysbus_mmio_get_region(s, 0));
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw
Quoted 15 lines · David Gibson
Quoted 5 lines · Philippe Mathieu-Daudé

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

Quoted 8 lines
---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
Quoted 2 lines

ppc part

Thanks!

Can this go via qemu-trivial@?

Quoted 83 lines
Quoted 82 lines
include/hw/rtc/m48t59.h +1 -1
index 04abedf3b2b..62297ee0db1 100644
@@ -50,7 +50,7 @@ struct NvramClass {
 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,
+                   uint16_t size, int base_year,
                    int type);
 
 #endif /* HW_M48T59_H */
hw/ppc/ppc405_boards.c +1 -1
index 6198ec1035b..93ffee801a3 100644
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
     /* Register FPGA */
     ref405ep_fpga_init(sysmem, 0xF0300000);
     /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    m48t59_init(NULL, 0xF0000000, 8192, 1968, 8);
     /* Load kernel */
     linux_boot = (kernel_filename != NULL);
     if (linux_boot) {
hw/rtc/m48t59.c +2 -8
index 6525206976b..2d6a095c4e4 100644
@@ -566,7 +566,7 @@ const MemoryRegionOps m48t59_io_ops = {
 
 /* Initialisation routine */
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
+                   uint16_t size, int base_year,
                    int model)
 {
     DeviceState *dev;
@@ -584,13 +584,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
         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);
-        }
+        sysbus_mmio_map(s, 0, mem_base);
 
         return NVRAM(s);
     }
hw/sparc/sun4m.c +1 -1
index 947b69d1597..56a0d38f274 100644
@@ -970,7 +970,7 @@ 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 = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
hw/sparc64/sun4u.c +1 -1
index b4aabfc076f..1cc57b030a7 100644
@@ -675,7 +675,7 @@ 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);
+    nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
     s = SYS_BUS_DEVICE(nvram);
     memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                 sysbus_mmio_get_region(s, 0));
#3 lore raw

Le 24/09/2020 à 16:53, Philippe Mathieu-Daudé a écrit :

Quoted 16 lines · David Gibson
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 13 lines

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
Quoted 6 lines
Quoted 2 lines

ppc part

Thanks!

Can this go via qemu-trivial@?

Yes, but more reviewers would help. Mark?

Thanks,
Laurent

#4 lore raw
Quoted 17 lines · Laurent Vivier

Le 24/09/2020 à 16:53, Philippe Mathieu-Daudé a écrit :

Quoted 16 lines · David Gibson
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 13 lines

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

ppc part

Thanks!

Can this go via qemu-trivial@?

Yes, but more reviewers would help. Mark?

Or Artyom :)

Quoted 4 lines

Thanks,
Laurent

#5 lore raw
In reply to Laurent Vivier
Quoted 17 lines · Laurent Vivier

Le 24/09/2020 à 16:53, Philippe Mathieu-Daudé a écrit :

Quoted 16 lines · David Gibson
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 13 lines

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

ppc part

Thanks!

Can this go via qemu-trivial@?

Yes, but more reviewers would help. Mark?

Ooof sorry I missed this one. Let me take a quick look now...

ATB,

Mark.

Reviewed-by on v1 1/1
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 86 lines · Philippe Mathieu-Daudé

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
include/hw/rtc/m48t59.h +1 -1
index 04abedf3b2b..62297ee0db1 100644
@@ -50,7 +50,7 @@ struct NvramClass {
 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,
+                   uint16_t size, int base_year,
                    int type);
 
 #endif /* HW_M48T59_H */
hw/ppc/ppc405_boards.c +1 -1
index 6198ec1035b..93ffee801a3 100644
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
     /* Register FPGA */
     ref405ep_fpga_init(sysmem, 0xF0300000);
     /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    m48t59_init(NULL, 0xF0000000, 8192, 1968, 8);
     /* Load kernel */
     linux_boot = (kernel_filename != NULL);
     if (linux_boot) {
hw/rtc/m48t59.c +2 -8
index 6525206976b..2d6a095c4e4 100644
@@ -566,7 +566,7 @@ const MemoryRegionOps m48t59_io_ops = {
 
 /* Initialisation routine */
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
+                   uint16_t size, int base_year,
                    int model)
 {
     DeviceState *dev;
@@ -584,13 +584,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
         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);
-        }
+        sysbus_mmio_map(s, 0, mem_base);
 
         return NVRAM(s);
     }
hw/sparc/sun4m.c +1 -1
index 947b69d1597..56a0d38f274 100644
@@ -970,7 +970,7 @@ 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 = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
hw/sparc64/sun4u.c +0 -0
index b4aabfc076f..1cc57b030a7 100644

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

Quoted 8 lines
hw/sparc64/sun4u.c +1 -1
@@ -675,7 +675,7 @@ 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);
+    nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
     s = SYS_BUS_DEVICE(nvram);
     memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                 sysbus_mmio_get_region(s, 0));

Looks good to me. In fact, if you're working in this area there are a couple of other quick wins here too:

- Remove m48t59_init() and replace with QOM/qdev properties

- Remove m48t59_init_isa() as this seems to be unused, along with the associated complexity of handling the m48txx_isa_info[] array

Anyhow:

ATB,

Mark.

#7 lore raw
Quoted 100 lines · Mark Cave-Ayland
Quoted 86 lines · Philippe Mathieu-Daudé

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
include/hw/rtc/m48t59.h +1 -1
index 04abedf3b2b..62297ee0db1 100644
@@ -50,7 +50,7 @@ struct NvramClass {
 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,
+                   uint16_t size, int base_year,
                    int type);
 
 #endif /* HW_M48T59_H */
hw/ppc/ppc405_boards.c +1 -1
index 6198ec1035b..93ffee801a3 100644
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
     /* Register FPGA */
     ref405ep_fpga_init(sysmem, 0xF0300000);
     /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    m48t59_init(NULL, 0xF0000000, 8192, 1968, 8);
     /* Load kernel */
     linux_boot = (kernel_filename != NULL);
     if (linux_boot) {
hw/rtc/m48t59.c +2 -8
index 6525206976b..2d6a095c4e4 100644
@@ -566,7 +566,7 @@ const MemoryRegionOps m48t59_io_ops = {
 
 /* Initialisation routine */
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
+                   uint16_t size, int base_year,
                    int model)
 {
     DeviceState *dev;
@@ -584,13 +584,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
         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);
-        }
+        sysbus_mmio_map(s, 0, mem_base);
 
         return NVRAM(s);
     }
hw/sparc/sun4m.c +1 -1
index 947b69d1597..56a0d38f274 100644
@@ -970,7 +970,7 @@ 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 = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
hw/sparc64/sun4u.c +0 -0
index b4aabfc076f..1cc57b030a7 100644

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

Quoted 8 lines
hw/sparc64/sun4u.c +1 -1
@@ -675,7 +675,7 @@ 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);
+    nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
     s = SYS_BUS_DEVICE(nvram);
     memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                 sysbus_mmio_get_region(s, 0));

Looks good to me. In fact, if you're working in this area there are a couple of other quick wins here too:

Quoted 4 lines

- Remove m48t59_init() and replace with QOM/qdev properties

- Remove m48t59_init_isa() as this seems to be unused, along with the associated complexity of handling the m48txx_isa_info[] array

OK.

Quoted 4 lines

Anyhow:

Thanks!

Quoted 6 lines

ATB,

Mark.

#8 lore raw
In reply to Philippe Mathieu-Daudé

Le 14/09/2020 à 12:24, Philippe Mathieu-Daudé a écrit :

Quoted 87 lines

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
include/hw/rtc/m48t59.h +1 -1
index 04abedf3b2b..62297ee0db1 100644
@@ -50,7 +50,7 @@ struct NvramClass {
 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,
+                   uint16_t size, int base_year,
                    int type);
 
 #endif /* HW_M48T59_H */
hw/ppc/ppc405_boards.c +1 -1
index 6198ec1035b..93ffee801a3 100644
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
     /* Register FPGA */
     ref405ep_fpga_init(sysmem, 0xF0300000);
     /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    m48t59_init(NULL, 0xF0000000, 8192, 1968, 8);
     /* Load kernel */
     linux_boot = (kernel_filename != NULL);
     if (linux_boot) {
hw/rtc/m48t59.c +2 -8
index 6525206976b..2d6a095c4e4 100644
@@ -566,7 +566,7 @@ const MemoryRegionOps m48t59_io_ops = {
 
 /* Initialisation routine */
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
+                   uint16_t size, int base_year,
                    int model)
 {
     DeviceState *dev;
@@ -584,13 +584,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
         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);
-        }
+        sysbus_mmio_map(s, 0, mem_base);
 
         return NVRAM(s);
     }
hw/sparc/sun4m.c +1 -1
index 947b69d1597..56a0d38f274 100644
@@ -970,7 +970,7 @@ 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 = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
hw/sparc64/sun4u.c +0 -0
index b4aabfc076f..1cc57b030a7 100644

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

Quoted 8 lines
hw/sparc64/sun4u.c +1 -1
@@ -675,7 +675,7 @@ 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);
+    nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);
     s = SYS_BUS_DEVICE(nvram);
     memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                 sysbus_mmio_get_region(s, 0));

Applied to my trivial-patches branch.

Thanks,
Laurent

#9 lore raw

Le 30/09/2020 à 13:25, Laurent Vivier a écrit :

Quoted 47 lines

Le 14/09/2020 à 12:24, Philippe Mathieu-Daudé a écrit :

Quoted 46 lines

As the 'io_base' argument of m48t59_init() is unused (set to 0), remove it to simplify.
To create a device on the ISA bus, m48t59_init_isa() is the preferred function to use.

---
 include/hw/rtc/m48t59.h |  2 +-
 hw/ppc/ppc405_boards.c  |  2 +-
 hw/rtc/m48t59.c         | 10 ++--------
 hw/sparc/sun4m.c        |  2 +-
 hw/sparc64/sun4u.c      |  2 +-
 5 files changed, 6 insertions(+), 12 deletions(-)
include/hw/rtc/m48t59.h +1 -1
index 04abedf3b2b..62297ee0db1 100644
@@ -50,7 +50,7 @@ struct NvramClass {
 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,
+                   uint16_t size, int base_year,
                    int type);
 
 #endif /* HW_M48T59_H */
hw/ppc/ppc405_boards.c +1 -1
index 6198ec1035b..93ffee801a3 100644
@@ -227,7 +227,7 @@ static void ref405ep_init(MachineState *machine)
     /* Register FPGA */
     ref405ep_fpga_init(sysmem, 0xF0300000);
     /* Register NVRAM */
-    m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
+    m48t59_init(NULL, 0xF0000000, 8192, 1968, 8);
     /* Load kernel */
     linux_boot = (kernel_filename != NULL);
     if (linux_boot) {
hw/rtc/m48t59.c +0 -0
index 6525206976b..2d6a095c4e4 100644
@@ -566,7 +566,7 @@ const MemoryRegionOps m48t59_io_ops = {
 
Quoted 16 lines
Quoted 8 lines
hw/rtc/m48t59.c +1 -1
 /* Initialisation routine */
 Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
-                   uint32_t io_base, uint16_t size, int base_year,
+                   uint16_t size, int base_year,
                    int model)
 {
     DeviceState *dev;

hw/rtc/m48t59.c Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base, · line 591

Quoted 8 lines
hw/rtc/m48t59.c +0 -5
@@ -584,13 +584,7 @@ Nvram *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
         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) {

You can't remove the "if ()"...

Quoted 26 lines
Quoted 26 lines
hw/rtc/m48t59.c +1 -2
-            sysbus_mmio_map(s, 0, mem_base);
-        }
+        sysbus_mmio_map(s, 0, mem_base);
 
         return NVRAM(s);
     }
hw/sparc/sun4m.c +1 -1
index 947b69d1597..56a0d38f274 100644
@@ -970,7 +970,7 @@ 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 = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0x2000, 1968, 8);
 
     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
 
hw/sparc64/sun4u.c +0 -0
index b4aabfc076f..1cc57b030a7 100644
@@ -675,7 +675,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     pci_ide_create_devs(pci_dev);
 
Quoted 3 lines

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

Quoted 3 lines
hw/sparc64/sun4u.c +1 -1
     /* Map NVRAM into I/O (ebus) space */
-    nvram = m48t59_init(NULL, 0, 0, NVRAM_SIZE, 1968, 59);
+    nvram = m48t59_init(NULL, 0, NVRAM_SIZE, 1968, 59);

... because mem_base is 0 here.

Quoted 6 lines

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

Quoted 4 lines
hw/sparc64/sun4u.c +0 -0
     s = SYS_BUS_DEVICE(nvram);
     memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
                                 sysbus_mmio_get_region(s, 0));

Applied to my trivial-patches branch.

I'm removing it from my branch because it breaks check-qtest-sparc64:

Running test qtest-sparc64: endianness-test
qemu-system-sparc64: ../../../Projects/qemu/softmmu/memory.c:2398:
memory_region_add_subregion_common: Assertion `!subregion->container' failed.

Thanks,
Laurent