Skip to contentSkip to conversation

hw/mips: Cleanup in preparation of heterogenous prototype

PATCH Applied Philippe Mathieu-Daudé 2 participants 6 messages Oct 9, 2023 – Oct 16, 2023

lore
Share & tools
lore
#0 lore raw

cover hw/mips: Cleanup in preparation of heterogenous prototype

Prepare few MIPS hardware to be integrated in a heterogeneous machine:
- Restrict MIPS-specific HW declaration to target/mips/
- Replace MIPSCPU by ArchCPU in common HW

Philippe Mathieu-Daudé (3):
hw/mips: Merge 'hw/mips/cpudevs.h' with 'target/mips/cpu.h' hw/misc/mips_itu: Declare itc_reconfigure() in 'hw/misc/mips_itu.h' hw/misc/mips_itu: Make MIPSITUState target agnostic

 include/hw/mips/cpudevs.h           | 14 --------------
 include/hw/misc/mips_itu.h          |  4 +++-
 target/mips/cpu.h                   |  7 +++----
 hw/mips/cps.c                       |  1 -
 hw/mips/fuloong2e.c                 |  1 -
 hw/mips/jazz.c                      |  1 -
 hw/mips/loongson3_virt.c            |  1 -
 hw/mips/malta.c                     |  1 -
 hw/mips/mips_int.c                  |  1 -
 hw/mips/mipssim.c                   |  1 -
 hw/misc/mips_itu.c                  |  4 ++--
 target/mips/sysemu/cp0_timer.c      |  1 -
 target/mips/tcg/sysemu/cp0_helper.c |  1 +
 target/mips/tcg/sysemu/tlb_helper.c |  1 -
 14 files changed, 9 insertions(+), 30 deletions(-)
 delete mode 100644 include/hw/mips/cpudevs.h
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/3 hw/mips: Merge 'hw/mips/cpudevs.h' with 'target/mips/cpu.h'

"hw/mips/cpudevs.h" contains declarations which are specific to the MIPS architecture; it doesn't make sense for these to be called from a non-MIPS architecture. Move the declarations to "target/mips/cpu.h".

---
 include/hw/mips/cpudevs.h           | 14 --------------
 target/mips/cpu.h                   |  4 +++-
 hw/mips/cps.c                       |  1 -
 hw/mips/fuloong2e.c                 |  1 -
 hw/mips/jazz.c                      |  1 -
 hw/mips/loongson3_virt.c            |  1 -
 hw/mips/malta.c                     |  1 -
 hw/mips/mips_int.c                  |  1 -
 hw/mips/mipssim.c                   |  1 -
 target/mips/sysemu/cp0_timer.c      |  1 -
 target/mips/tcg/sysemu/tlb_helper.c |  1 -
 11 files changed, 3 insertions(+), 24 deletions(-)
 delete mode 100644 include/hw/mips/cpudevs.h
include/hw/mips/cpudevs.h deleted +0 -14
deleted file mode 100644
index f7c9728fa9..0000000000
@@ -1,14 +0,0 @@
-#ifndef HW_MIPS_CPUDEVS_H
-#define HW_MIPS_CPUDEVS_H
-
-#include "target/mips/cpu-qom.h"
-
-/* Definitions for MIPS CPU internal devices.  */
-
-/* mips_int.c */
-void cpu_mips_irq_init_cpu(MIPSCPU *cpu);
-
-/* mips_timer.c */
-void cpu_mips_clock_init(MIPSCPU *cpu);
-
-#endif
target/mips/cpu.h +3 -1
index 67f8e8b988..fb44defc93 100644
@@ -1345,8 +1345,10 @@ uint64_t cpu_mips_phys_to_kseg1(void *opaque, uint64_t addr);
 
 #if !defined(CONFIG_USER_ONLY)
 
-/* mips_int.c */
+/* HW declaration specific to the MIPS target */
 void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level);
+void cpu_mips_irq_init_cpu(MIPSCPU *cpu);
+void cpu_mips_clock_init(MIPSCPU *cpu);
 
 /* mips_itu.c */
 void itc_reconfigure(struct MIPSITUState *tag);
hw/mips/cps.c +0 -1
index 2b5269ebf1..b6612c1762 100644
@@ -24,7 +24,6 @@
 #include "hw/mips/mips.h"
 #include "hw/qdev-clock.h"
 #include "hw/qdev-properties.h"
-#include "hw/mips/cpudevs.h"
 #include "sysemu/kvm.h"
 #include "sysemu/reset.h"
 
hw/mips/fuloong2e.c +0 -1
index c6109633fe..97b2c8ed8e 100644
@@ -30,7 +30,6 @@
 #include "hw/block/flash.h"
 #include "hw/mips/mips.h"
 #include "hw/mips/bootloader.h"
-#include "hw/mips/cpudevs.h"
 #include "hw/pci/pci.h"
 #include "hw/loader.h"
 #include "hw/ide/pci.h"
hw/mips/jazz.c +0 -1
index c32d2b0b0a..86dfe05ea8 100644
@@ -26,7 +26,6 @@
 #include "qemu/datadir.h"
 #include "hw/clock.h"
 #include "hw/mips/mips.h"
-#include "hw/mips/cpudevs.h"
 #include "hw/intc/i8259.h"
 #include "hw/dma/i8257.h"
 #include "hw/char/serial.h"
hw/mips/loongson3_virt.c +0 -1
index b74b358874..33eae01eca 100644
@@ -32,7 +32,6 @@
 #include "hw/char/serial.h"
 #include "hw/intc/loongson_liointc.h"
 #include "hw/mips/mips.h"
-#include "hw/mips/cpudevs.h"
 #include "hw/mips/fw_cfg.h"
 #include "hw/mips/loongson3_bootp.h"
 #include "hw/misc/unimp.h"
hw/mips/malta.c +0 -1
index dac27fad9d..b0110c4da6 100644
@@ -37,7 +37,6 @@
 #include "hw/block/flash.h"
 #include "hw/mips/mips.h"
 #include "hw/mips/bootloader.h"
-#include "hw/mips/cpudevs.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bus.h"
 #include "qemu/log.h"
hw/mips/mips_int.c +0 -1
index 73437cd90f..6c32e466a3 100644
@@ -23,7 +23,6 @@
 #include "qemu/osdep.h"
 #include "qemu/main-loop.h"
 #include "hw/irq.h"
-#include "hw/mips/cpudevs.h"
 #include "sysemu/kvm.h"
 #include "kvm_mips.h"
 
hw/mips/mipssim.c +0 -1
index 2f951f7fc6..4f743f37eb 100644
@@ -30,7 +30,6 @@
 #include "qemu/datadir.h"
 #include "hw/clock.h"
 #include "hw/mips/mips.h"
-#include "hw/mips/cpudevs.h"
 #include "hw/char/serial.h"
 #include "hw/isa/isa.h"
 #include "net/net.h"
target/mips/sysemu/cp0_timer.c +0 -1
index 9d2bcb0dea..62de502caa 100644
@@ -22,7 +22,6 @@
 
 #include "qemu/osdep.h"
 #include "hw/irq.h"
-#include "hw/mips/cpudevs.h"
 #include "qemu/timer.h"
 #include "sysemu/kvm.h"
 #include "internal.h"
target/mips/tcg/sysemu/tlb_helper.c +0 -1
index 7dbc2e24c4..4ede904800 100644
@@ -24,7 +24,6 @@
 #include "exec/exec-all.h"
 #include "exec/cpu_ldst.h"
 #include "exec/log.h"
-#include "hw/mips/cpudevs.h"
 #include "exec/helper-proto.h"
 
 /* TLB management */
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/3 hw/misc/mips_itu: Declare itc_reconfigure() in 'hw/misc/mips_itu.h'

In reply to Philippe Mathieu-Daudé

We already provide "hw/misc/mips_itu.h" to declare prototype related to MIPSITUState. Move itc_reconfigure() declaration there.

---
 include/hw/misc/mips_itu.h          | 2 ++
 target/mips/cpu.h                   | 3 ---
 target/mips/tcg/sysemu/cp0_helper.c | 1 +
 3 files changed, 3 insertions(+), 3 deletions(-)
include/hw/misc/mips_itu.h +2 -0
index 35218b2d14..a413789151 100644
@@ -79,4 +79,6 @@ struct MIPSITUState {
 /* Get ITC Configuration Tag memory region. */
 MemoryRegion *mips_itu_get_tag_region(MIPSITUState *itu);
 
+void itc_reconfigure(struct MIPSITUState *tag);
+
 #endif /* MIPS_ITU_H */
target/mips/cpu.h +0 -3
index fb44defc93..5fddceff3a 100644
@@ -1350,9 +1350,6 @@ void cpu_mips_soft_irq(CPUMIPSState *env, int irq, int level);
 void cpu_mips_irq_init_cpu(MIPSCPU *cpu);
 void cpu_mips_clock_init(MIPSCPU *cpu);
 
-/* mips_itu.c */
-void itc_reconfigure(struct MIPSITUState *tag);
-
 #endif /* !CONFIG_USER_ONLY */
 
 /* helper.c */
target/mips/tcg/sysemu/cp0_helper.c +1 -0
index 5da1124589..d349548743 100644
@@ -28,6 +28,7 @@
 #include "qemu/host-utils.h"
 #include "exec/helper-proto.h"
 #include "exec/exec-all.h"
+#include "hw/misc/mips_itu.h"
 
 
 /* SMP helpers.  */
Signature · 1 line
2.41.0
#3 lore raw

PATCH 3/3 hw/misc/mips_itu: Make MIPSITUState target agnostic

In reply to Philippe Mathieu-Daudé

When prototyping a heterogenous machine including the ITU, we get:

include/hw/misc/mips_itu.h:76:5: error: unknown type name 'MIPSCPU'

      MIPSCPU *cpu0;
      ^

MIPSCPU is declared in the target specific "cpu.h" header, but we don't want to include it, because "cpu.h" is target specific and its inclusion taints all files including "mips_itu.h", which become target specific too. We can however use the 'ArchCPU *' type in the public header. By keeping the TYPE_MIPS_CPU QOM type check in the link property declaration, QOM core code will still check the property is a correct MIPS CPU.

TYPE_MIPS_ITU is still built per-(MIPS)target, but its header can now be included by other targets.

---
 include/hw/misc/mips_itu.h | 2 +-
 hw/misc/mips_itu.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/hw/misc/mips_itu.h +1 -1
index a413789151..5caed6cc36 100644
@@ -73,7 +73,7 @@ struct MIPSITUState {
 
     /* SAAR */
     uint64_t *saar;
-    MIPSCPU *cpu0;
+    ArchCPU *cpu0;
 };
 
 /* Get ITC Configuration Tag memory region. */
hw/misc/mips_itu.c +2 -2
index 0eda302db4..5a83ccc4e8 100644
@@ -532,7 +532,7 @@ static void mips_itu_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    env = &s->cpu0->env;
+    env = &MIPS_CPU(s->cpu0)->env;
     if (env->saarp) {
         s->saar = env->CP0_SAAR;
     }
@@ -563,7 +563,7 @@ static Property mips_itu_properties[] = {
                       ITC_FIFO_NUM_MAX),
     DEFINE_PROP_UINT32("num-semaphores", MIPSITUState, num_semaphores,
                       ITC_SEMAPH_NUM_MAX),
-    DEFINE_PROP_LINK("cpu[0]", MIPSITUState, cpu0, TYPE_MIPS_CPU, MIPSCPU *),
+    DEFINE_PROP_LINK("cpu[0]", MIPSITUState, cpu0, TYPE_MIPS_CPU, ArchCPU *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.41.0
Reviewed-by on the v1 series
#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Prepare few MIPS hardware to be integrated in a heterogeneous machine:
- Restrict MIPS-specific HW declaration to target/mips/
- Replace MIPSCPU by ArchCPU in common HW

Philippe Mathieu-Daudé (3):
hw/mips: Merge 'hw/mips/cpudevs.h' with 'target/mips/cpu.h' hw/misc/mips_itu: Declare itc_reconfigure() in 'hw/misc/mips_itu.h' hw/misc/mips_itu: Make MIPSITUState target agnostic

r~

#5 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

Philippe Mathieu-Daudé (3):
hw/mips: Merge 'hw/mips/cpudevs.h' with 'target/mips/cpu.h' hw/misc/mips_itu: Declare itc_reconfigure() in 'hw/misc/mips_itu.h' hw/misc/mips_itu: Make MIPSITUState target agnostic

Queued to mips-next.