Skip to contentSkip to conversation

arm: Spring header cleanups

PATCH In review Philippe Mathieu-Daudé 2 participants 18 messages Apr 2, 2025 – Apr 3, 2025

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover arm: Spring header cleanups

This series is more useful for heterogeneous emulation preparation than single binary, because it allows non-ARM hw/ code to configure ARM cores, so not using target-specific APIs. I figured some patches could be useful to Pierrick "build hw/arm once" series (in particular arm_cpu_has_feature).

Philippe Mathieu-Daudé (13):
target/arm/cpu-features: Include missing 'cpu.h' header target/arm/qmp: Include missing 'cpu.h' header target/arm/kvm: Include missing 'cpu-qom.h' header target/arm/hvf: Include missing 'cpu-qom.h' header
hw/arm: Remove unnecessary 'cpu.h' header
target/arm: Restrict inclusion of 'multiprocessing.h' target/arm: Move some definitions from 'cpu.h' to 'multiprocessing.h' hw/arm: Include missing 'target/arm/gtimer.h' header target/arm: Extract PSCI definitions to 'psci.h' target/arm: Extract feature definitions to 'cpu_has_feature.h' header target/arm: Add arm_cpu_has_feature() helper hw/arm/realview: Replace arm_feature() -> arm_cpu_has_feature() hw/arm/virt-acpi: Replace arm_feature() -> arm_cpu_has_feature()

 include/hw/arm/boot.h        |  3 +-
 target/arm/cpu-features.h    |  1 +
 target/arm/cpu.h             | 78 +-----------------------------------
 target/arm/cpu_has_feature.h | 67 +++++++++++++++++++++++++++++++
 target/arm/hvf_arm.h         |  2 +-
 target/arm/kvm_arm.h         |  1 +
 target/arm/multiprocessing.h | 18 +++++++++
 target/arm/psci.h            | 18 +++++++++
 hw/arm/aspeed_ast2600.c      |  1 +
 hw/arm/aspeed_ast27x0.c      |  2 +
 hw/arm/bananapi_m2u.c        |  1 +
 hw/arm/bcm2838.c             |  1 +
 hw/arm/boot.c                |  1 +
 hw/arm/exynos4210.c          |  3 +-
 hw/arm/fsl-imx8mp.c          |  1 +
 hw/arm/highbank.c            |  2 +-
 hw/arm/imx8mp-evk.c          |  1 +
 hw/arm/mcimx6ul-evk.c        |  1 +
 hw/arm/mcimx7d-sabre.c       |  1 +
 hw/arm/mps3r.c               |  2 +-
 hw/arm/npcm8xx.c             |  2 +
 hw/arm/orangepi.c            |  1 +
 hw/arm/realview.c            | 10 ++---
 hw/arm/sbsa-ref.c            |  2 +
 hw/arm/smmuv3.c              |  1 -
 hw/arm/virt-acpi-build.c     |  4 +-
 hw/arm/virt.c                |  1 +
 hw/arm/xlnx-versal-virt.c    |  1 +
 hw/arm/xlnx-zcu102.c         |  1 +
 hw/vmapple/vmapple.c         |  3 ++
 target/arm/arm-qmp-cmds.c    |  1 +
 target/arm/cpu.c             |  8 ++++
 target/arm/helper.c          |  1 +
 target/arm/hvf/hvf.c         |  1 +
 target/arm/kvm.c             |  1 +
 target/arm/tcg/op_helper.c   |  2 +
 target/arm/tcg/psci.c        |  1 +
 37 files changed, 156 insertions(+), 90 deletions(-)
 create mode 100644 target/arm/cpu_has_feature.h
 create mode 100644 target/arm/psci.h
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/13 target/arm/cpu-features: Include missing 'cpu.h' header

"target/arm/cpu-features.h" dereferences the ARMISARegisters structure, which is defined in "cpu.h". Include the latter to avoid when refactoring unrelated headers:

In file included from target/arm/internals.h:33:
target/arm/cpu-features.h:45:54: error: unknown type name 'ARMISARegisters'
45 | static inline bool isar_feature_aa32_thumb_div(const ARMISARegisters *id)
| ^
target/arm/cpu-features.h:47:12: error: use of undeclared identifier 'R_ID_ISAR0_DIVIDE_SHIFT'

     47 |     return FIELD_EX32(id->id_isar0, ID_ISAR0, DIVIDE) != 0;
        |            ^
---
 target/arm/cpu-features.h | 1 +
 1 file changed, 1 insertion(+)
target/arm/cpu-features.h +1 -0
index 525e4cee12f..4452e7c21e3 100644
@@ -22,6 +22,7 @@
 
 #include "hw/registerfields.h"
 #include "qemu/host-utils.h"
+#include "cpu.h"
 
 /*
  * Naming convention for isar_feature functions:
Signature · 1 line
2.47.1
#2 lore raw

PATCH 2/13 target/arm/qmp: Include missing 'cpu.h' header

In reply to Philippe Mathieu-Daudé

arm-qmp-cmds.c uses ARM_MAX_VQ, which is defined in "cpu.h". Include the latter to avoid when refactoring unrelated headers:

target/arm/arm-qmp-cmds.c:83:19: error: use of undeclared identifier 'ARM_MAX_VQ'

     83 | QEMU_BUILD_BUG_ON(ARM_MAX_VQ > 16);
        |                   ^
---
 target/arm/arm-qmp-cmds.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/arm-qmp-cmds.c +1 -0
index 883c0a0e8cc..d654be2a619 100644
@@ -30,6 +30,7 @@
 #include "qapi/qapi-commands-misc-target.h"
 #include "qobject/qdict.h"
 #include "qom/qom-qobject.h"
+#include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
 {
Signature · 1 line
2.47.1
#3 lore raw

PATCH 3/13 target/arm/kvm: Include missing 'cpu-qom.h' header

In reply to Philippe Mathieu-Daudé

ARMCPU typedef is declared in "cpu-qom.h". Include it in order to avoid when refactoring unrelated headers:

target/arm/kvm_arm.h:54:29: error: unknown type name 'ARMCPU'

     54 | bool write_list_to_kvmstate(ARMCPU *cpu, int level);
        |                             ^
---
 target/arm/kvm_arm.h | 1 +
 1 file changed, 1 insertion(+)
target/arm/kvm_arm.h +1 -0
index 05c3de8cd46..2db2f060e6a 100644
@@ -12,6 +12,7 @@
 #define QEMU_KVM_ARM_H
 
 #include "system/kvm.h"
+#include "target/arm/cpu-qom.h"
 
 #define KVM_ARM_VGIC_V2   (1 << 0)
 #define KVM_ARM_VGIC_V3   (1 << 1)
Signature · 1 line
2.47.1
#4 lore raw

PATCH 4/13 target/arm/hvf: Include missing 'cpu-qom.h' header

In reply to Philippe Mathieu-Daudé

ARMCPU typedef is declared in "cpu-qom.h". Include it in order to avoid when refactoring unrelated headers:

target/arm/hvf_arm.h:23:41: error: unknown type name 'ARMCPU'

     23 | void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu);
        |                                         ^
---
 target/arm/hvf_arm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/hvf_arm.h +1 -1
index 26c717b3826..ee5545f2d10 100644
@@ -11,7 +11,7 @@
 #ifndef QEMU_HVF_ARM_H
 #define QEMU_HVF_ARM_H
 
-#include "cpu.h"
+#include "target/arm/cpu-qom.h"
 
 /**
  * hvf_arm_init_debug() - initialize guest debug capabilities
Signature · 1 line
2.47.1
#5 lore raw

PATCH 5/13 hw/arm: Remove unnecessary 'cpu.h' header

In reply to Philippe Mathieu-Daudé
---
 hw/arm/exynos4210.c | 1 -
 hw/arm/highbank.c   | 1 -
 hw/arm/mps3r.c      | 1 -
 hw/arm/smmuv3.c     | 1 -
 4 files changed, 4 deletions(-)
hw/arm/exynos4210.c +0 -1
index b452470598b..04439364370 100644
@@ -24,7 +24,6 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "exec/tswap.h"
-#include "cpu.h"
 #include "hw/cpu/a9mpcore.h"
 #include "hw/irq.h"
 #include "system/blockdev.h"
hw/arm/highbank.c +0 -1
index ea3621e4f87..0caa08631ad 100644
@@ -35,7 +35,6 @@
 #include "hw/cpu/a15mpcore.h"
 #include "qemu/log.h"
 #include "qom/object.h"
-#include "cpu.h"
 #include "target/arm/cpu-qom.h"
 
 #define SMP_BOOT_ADDR           0x100
hw/arm/mps3r.c +0 -1
index e9abbf00b43..604f6845fde 100644
@@ -29,7 +29,6 @@
 #include "qapi/error.h"
 #include "qobject/qlist.h"
 #include "system/address-spaces.h"
-#include "cpu.h"
 #include "system/system.h"
 #include "hw/boards.h"
 #include "hw/or-irq.h"
hw/arm/smmuv3.c +0 -1
index 4362ae6aa1c..df3f5a707a9 100644
@@ -24,7 +24,6 @@
 #include "hw/qdev-properties.h"
 #include "hw/qdev-core.h"
 #include "hw/pci/pci.h"
-#include "cpu.h"
 #include "exec/target_page.h"
 #include "trace.h"
 #include "qemu/log.h"
Signature · 1 line
2.47.1
#6 lore raw

PATCH 6/13 target/arm: Restrict inclusion of 'multiprocessing.h'

In reply to Philippe Mathieu-Daudé

Only cpu.c requires "multiprocessing.h" definitions so far.

---
 target/arm/cpu.h | 1 -
 target/arm/cpu.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
target/arm/cpu.h +0 -1
index 88ed06987f3..768e784c3e9 100644
@@ -30,7 +30,6 @@
 #include "exec/gdbstub.h"
 #include "exec/page-protection.h"
 #include "qapi/qapi-types-common.h"
-#include "target/arm/multiprocessing.h"
 #include "target/arm/gtimer.h"
 
 #define EXCP_UDEF            1   /* undefined instruction */
target/arm/cpu.c +1 -0
index b1aa482c726..6f62745d7f6 100644
@@ -53,6 +53,7 @@
 #include "qemu/target_info-qom.h"
 #include "target/arm/cpu-qom.h"
 #include "target/arm/gtimer.h"
+#include "target/arm/multiprocessing.h"
 
 static void arm_cpu_set_pc(CPUState *cs, vaddr value)
 {
Signature · 1 line
2.47.1
#7 lore raw

PATCH 7/13 target/arm: Move some definitions from 'cpu.h' to 'multiprocessing.h'

In reply to Philippe Mathieu-Daudé

arm_build_mp_affinity() and affinity mask definitionss are related to multiprocessing. Move them to "multiprocessing.h", including this header when necessary.

---
 target/arm/cpu.h             | 17 -----------------
 target/arm/multiprocessing.h | 18 ++++++++++++++++++
 hw/arm/aspeed_ast2600.c      |  1 +
 hw/arm/aspeed_ast27x0.c      |  1 +
 hw/arm/exynos4210.c          |  1 +
 hw/arm/npcm8xx.c             |  1 +
 hw/arm/sbsa-ref.c            |  1 +
 hw/vmapple/vmapple.c         |  1 +
 target/arm/kvm.c             |  1 +
 9 files changed, 25 insertions(+), 17 deletions(-)
target/arm/cpu.h +0 -17
index 768e784c3e9..45a9551535e 100644
@@ -1158,23 +1158,6 @@ void gt_rme_post_el_change(ARMCPU *cpu, void *opaque);
 
 void arm_cpu_post_init(Object *obj);
 
-#define ARM_AFF0_SHIFT 0
-#define ARM_AFF0_MASK  (0xFFULL << ARM_AFF0_SHIFT)
-#define ARM_AFF1_SHIFT 8
-#define ARM_AFF1_MASK  (0xFFULL << ARM_AFF1_SHIFT)
-#define ARM_AFF2_SHIFT 16
-#define ARM_AFF2_MASK  (0xFFULL << ARM_AFF2_SHIFT)
-#define ARM_AFF3_SHIFT 32
-#define ARM_AFF3_MASK  (0xFFULL << ARM_AFF3_SHIFT)
-#define ARM_DEFAULT_CPUS_PER_CLUSTER 8
-
-#define ARM32_AFFINITY_MASK (ARM_AFF0_MASK | ARM_AFF1_MASK | ARM_AFF2_MASK)
-#define ARM64_AFFINITY_MASK \
-    (ARM_AFF0_MASK | ARM_AFF1_MASK | ARM_AFF2_MASK | ARM_AFF3_MASK)
-#define ARM64_AFFINITY_INVALID (~ARM64_AFFINITY_MASK)
-
-uint64_t arm_build_mp_affinity(int idx, uint8_t clustersz);
-
 #ifndef CONFIG_USER_ONLY
 extern const VMStateDescription vmstate_arm_cpu;
 
target/arm/multiprocessing.h +18 -0
index 81715d345c2..8eec79b11d8 100644
@@ -11,6 +11,24 @@
 
 #include "target/arm/cpu-qom.h"
 
+#define ARM_AFF0_SHIFT 0
+#define ARM_AFF0_MASK  (0xFFULL << ARM_AFF0_SHIFT)
+#define ARM_AFF1_SHIFT 8
+#define ARM_AFF1_MASK  (0xFFULL << ARM_AFF1_SHIFT)
+#define ARM_AFF2_SHIFT 16
+#define ARM_AFF2_MASK  (0xFFULL << ARM_AFF2_SHIFT)
+#define ARM_AFF3_SHIFT 32
+#define ARM_AFF3_MASK  (0xFFULL << ARM_AFF3_SHIFT)
+#define ARM_DEFAULT_CPUS_PER_CLUSTER 8
+
+#define ARM32_AFFINITY_MASK \
+            (ARM_AFF0_MASK|ARM_AFF1_MASK|ARM_AFF2_MASK)
+#define ARM64_AFFINITY_MASK \
+            (ARM_AFF0_MASK|ARM_AFF1_MASK|ARM_AFF2_MASK|ARM_AFF3_MASK)
+#define ARM64_AFFINITY_INVALID (~ARM64_AFFINITY_MASK)
+
+uint64_t arm_build_mp_affinity(int idx, uint8_t clustersz);
+
 uint64_t arm_cpu_mp_affinity(ARMCPU *cpu);
 
 #endif
hw/arm/aspeed_ast2600.c +1 -0
index 1f994ba26c6..4438402340b 100644
@@ -17,6 +17,7 @@
 #include "net/net.h"
 #include "system/system.h"
 #include "target/arm/cpu-qom.h"
+#include "target/arm/multiprocessing.h"
 
 #define ASPEED_SOC_IOMEM_SIZE       0x00200000
 #define ASPEED_SOC_DPMCU_SIZE       0x00040000
hw/arm/aspeed_ast27x0.c +1 -0
index dce7255a2c0..37bfeef304d 100644
@@ -22,6 +22,7 @@
 #include "hw/intc/arm_gicv3.h"
 #include "qobject/qlist.h"
 #include "qemu/log.h"
+#include "target/arm/multiprocessing.h"
 
 static const hwaddr aspeed_soc_ast2700_memmap[] = {
     [ASPEED_DEV_SRAM]      =  0x10000000,
hw/arm/exynos4210.c +1 -0
index 04439364370..01e6e2fb052 100644
@@ -36,6 +36,7 @@
 #include "hw/sd/sdhci.h"
 #include "hw/usb/hcd-ehci.h"
 #include "target/arm/cpu-qom.h"
+#include "target/arm/multiprocessing.h"
 
 #define EXYNOS4210_CHIPID_ADDR         0x10000000
 
hw/arm/npcm8xx.c +1 -0
index f182accc47c..3987e55355b 100644
@@ -29,6 +29,7 @@
 #include "qapi/error.h"
 #include "qemu/units.h"
 #include "system/system.h"
+#include "target/arm/multiprocessing.h"
 
 /*
  * This covers the whole MMIO space. We'll use this to catch any MMIO accesses
hw/arm/sbsa-ref.c +1 -0
index 112cbbf29e6..90fbb56ba7a 100644
@@ -52,6 +52,7 @@
 #include "qom/object.h"
 #include "target/arm/cpu-qom.h"
 #include "target/arm/gtimer.h"
+#include "target/arm/multiprocessing.h"
 
 #define RAMLIMIT_GB 8192
 #define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)
hw/vmapple/vmapple.c +1 -0
index fa117bf1511..9bb5b0553a2 100644
@@ -51,6 +51,7 @@
 #include "system/reset.h"
 #include "system/runstate.h"
 #include "system/system.h"
+#include "target/arm/multiprocessing.h"
 
 struct VMAppleMachineState {
     MachineState parent;
target/arm/kvm.c +1 -0
index 97de8c7e939..a28acdecf3e 100644
@@ -39,6 +39,7 @@
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/ghes.h"
 #include "target/arm/gtimer.h"
+#include "target/arm/multiprocessing.h"
 #include "migration/blocker.h"
 
 const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
Signature · 1 line
2.47.1
#8 lore raw

PATCH 8/13 hw/arm: Include missing 'target/arm/gtimer.h' header

In reply to Philippe Mathieu-Daudé
---
 hw/arm/aspeed_ast27x0.c    | 1 +
 hw/arm/bcm2838.c           | 1 +
 hw/arm/exynos4210.c        | 1 +
 hw/arm/fsl-imx8mp.c        | 1 +
 hw/arm/mps3r.c             | 1 +
 hw/arm/npcm8xx.c           | 1 +
 hw/vmapple/vmapple.c       | 1 +
 target/arm/tcg/op_helper.c | 1 +
 8 files changed, 8 insertions(+)
hw/arm/aspeed_ast27x0.c +1 -0
index 37bfeef304d..5c2481225dd 100644
@@ -22,6 +22,7 @@
 #include "hw/intc/arm_gicv3.h"
 #include "qobject/qlist.h"
 #include "qemu/log.h"
+#include "target/arm/gtimer.h"
 #include "target/arm/multiprocessing.h"
 
 static const hwaddr aspeed_soc_ast2700_memmap[] = {
hw/arm/bcm2838.c +1 -0
index ddb7c5f757a..38d9b785a75 100644
@@ -12,6 +12,7 @@
 #include "hw/arm/raspi_platform.h"
 #include "hw/sysbus.h"
 #include "hw/arm/bcm2838.h"
+#include "target/arm/gtimer.h"
 #include "trace.h"
 
 #define GIC400_MAINTENANCE_IRQ      9
hw/arm/exynos4210.c +1 -0
index 01e6e2fb052..ca40df3db75 100644
@@ -36,6 +36,7 @@
 #include "hw/sd/sdhci.h"
 #include "hw/usb/hcd-ehci.h"
 #include "target/arm/cpu-qom.h"
+#include "target/arm/gtimer.h"
 #include "target/arm/multiprocessing.h"
 
 #define EXYNOS4210_CHIPID_ADDR         0x10000000
hw/arm/fsl-imx8mp.c +1 -0
index 2cf5eeaf313..180feca9d80 100644
@@ -17,6 +17,7 @@
 #include "hw/boards.h"
 #include "system/system.h"
 #include "target/arm/cpu-qom.h"
+#include "target/arm/gtimer.h"
 #include "qapi/error.h"
 #include "qobject/qlist.h"
 
hw/arm/mps3r.c +1 -0
index 604f6845fde..37c0de28a92 100644
@@ -47,6 +47,7 @@
 #include "hw/ssi/pl022.h"
 #include "hw/timer/cmsdk-apb-dualtimer.h"
 #include "hw/watchdog/cmsdk-apb-watchdog.h"
+#include "target/arm/gtimer.h"
 
 /* Define the layout of RAM and ROM in a board */
 typedef struct RAMInfo {
hw/arm/npcm8xx.c +1 -0
index 3987e55355b..2f11bc53a86 100644
@@ -29,6 +29,7 @@
 #include "qapi/error.h"
 #include "qemu/units.h"
 #include "system/system.h"
+#include "target/arm/gtimer.h"
 #include "target/arm/multiprocessing.h"
 
 /*
hw/vmapple/vmapple.c +1 -0
index 9bb5b0553a2..25652b16f0c 100644
@@ -51,6 +51,7 @@
 #include "system/reset.h"
 #include "system/runstate.h"
 #include "system/system.h"
+#include "target/arm/gtimer.h"
 #include "target/arm/multiprocessing.h"
 
 struct VMAppleMachineState {
target/arm/tcg/op_helper.c +1 -0
index 38d49cbb9d8..005f84082af 100644
@@ -25,6 +25,7 @@
 #include "cpu-features.h"
 #include "exec/exec-all.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "target/arm/gtimer.h"
 #include "cpregs.h"
 
 #define SIGNBIT (uint32_t)0x80000000
Signature · 1 line
2.47.1
#9 lore raw

PATCH 9/13 target/arm: Extract PSCI definitions to 'psci.h'

In reply to Philippe Mathieu-Daudé

Extract PSCI definitions (which are not target specific) to the new "target/arm/psci.h", so code from hw/arm/ can use them without having to include the target specific "cpu.h" header.

---
 include/hw/arm/boot.h      |  3 ++-
 target/arm/cpu.h           |  6 ------
 target/arm/psci.h          | 18 ++++++++++++++++++
 hw/arm/bananapi_m2u.c      |  1 +
 hw/arm/boot.c              |  1 +
 hw/arm/highbank.c          |  1 +
 hw/arm/imx8mp-evk.c        |  1 +
 hw/arm/mcimx6ul-evk.c      |  1 +
 hw/arm/mcimx7d-sabre.c     |  1 +
 hw/arm/orangepi.c          |  1 +
 hw/arm/sbsa-ref.c          |  1 +
 hw/arm/virt-acpi-build.c   |  1 +
 hw/arm/virt.c              |  1 +
 hw/arm/xlnx-versal-virt.c  |  1 +
 hw/arm/xlnx-zcu102.c       |  1 +
 hw/vmapple/vmapple.c       |  1 +
 target/arm/helper.c        |  1 +
 target/arm/hvf/hvf.c       |  1 +
 target/arm/tcg/op_helper.c |  1 +
 target/arm/tcg/psci.c      |  1 +
 20 files changed, 37 insertions(+), 7 deletions(-)
 create mode 100644 target/arm/psci.h
include/hw/arm/boot.h +2 -1
index b12bf61ca81..648fdb88862 100644
@@ -12,6 +12,7 @@
 #define HW_ARM_BOOT_H
 
 #include "target/arm/cpu-qom.h"
+//#include "target/arm/psci.h"
 #include "qemu/notify.h"
 
 typedef enum {
@@ -100,7 +101,7 @@ struct arm_boot_info {
      * as the conduit specifies calls should go to (eg guest firmware booted
      * to EL3) then PSCI will not be enabled.
      */
-    int psci_conduit;
+    int psci_conduit;//
     /* Used internally by arm_boot.c */
     int is_linux;
     hwaddr initrd_start;
target/arm/cpu.h +0 -6
index 45a9551535e..e78a1668bba 100644
@@ -3104,12 +3104,6 @@ static inline bool bswap_code(bool sctlr_b)
 void cpu_get_tb_cpu_state(CPUARMState *env, vaddr *pc,
                           uint64_t *cs_base, uint32_t *flags);
 
-enum {
-    QEMU_PSCI_CONDUIT_DISABLED = 0,
-    QEMU_PSCI_CONDUIT_SMC = 1,
-    QEMU_PSCI_CONDUIT_HVC = 2,
-};
-
 #ifndef CONFIG_USER_ONLY
 /* Return the address space index to use for a memory access */
 static inline int arm_asidx_from_attrs(CPUState *cs, MemTxAttrs attrs)
target/arm/psci.h new file +18 -0
new file mode 100644
index 00000000000..8b868dfbb91
@@ -0,0 +1,18 @@
+/*
+ * ARM Power State Coordination Interface (PSCI) definitions
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef TARGET_ARM_PSCI_H
+#define TARGET_ARM_PSCI_H
+
+enum {
+    QEMU_PSCI_CONDUIT_DISABLED = 0,
+    QEMU_PSCI_CONDUIT_SMC = 1,
+    QEMU_PSCI_CONDUIT_HVC = 2,
+};
+
+#endif
hw/arm/bananapi_m2u.c +1 -0
index b750a575f72..61e01a38099 100644
@@ -27,6 +27,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/arm/allwinner-r40.h"
 #include "hw/arm/boot.h"
+#include "target/arm/psci.h"
 
 static struct arm_boot_info bpim2u_binfo;
 
hw/arm/boot.c +1 -0
index 79afb51b8a5..b81a850819b 100644
@@ -29,6 +29,7 @@
 #include "qemu/config-file.h"
 #include "qemu/option.h"
 #include "qemu/units.h"
+#include "target/arm/psci.h"
 
 /* Kernel boot protocol is specified in the kernel docs
  * Documentation/arm/Booting and Documentation/arm64/booting.txt
hw/arm/highbank.c +1 -0
index 0caa08631ad..16fb2508d30 100644
@@ -36,6 +36,7 @@
 #include "qemu/log.h"
 #include "qom/object.h"
 #include "target/arm/cpu-qom.h"
+#include "target/arm/psci.h"
 
 #define SMP_BOOT_ADDR           0x100
 #define SMP_BOOT_REG            0x40
hw/arm/imx8mp-evk.c +1 -0
index 6e64ec4ea54..c8a99b2c49e 100644
@@ -15,6 +15,7 @@
 #include "system/qtest.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
+#include "target/arm/psci.h"
 
 static void imx8mp_evk_init(MachineState *machine)
 {
hw/arm/mcimx6ul-evk.c +1 -0
index 86982cb0772..be5e50abf17 100644
@@ -18,6 +18,7 @@
 #include "hw/qdev-properties.h"
 #include "qemu/error-report.h"
 #include "system/qtest.h"
+#include "target/arm/psci.h"
 
 static void mcimx6ul_evk_init(MachineState *machine)
 {
hw/arm/mcimx7d-sabre.c +1 -0
index 33119610113..e0f25b92594 100644
@@ -20,6 +20,7 @@
 #include "hw/qdev-properties.h"
 #include "qemu/error-report.h"
 #include "system/qtest.h"
+#include "target/arm/psci.h"
 
 static void mcimx7d_sabre_init(MachineState *machine)
 {
hw/arm/orangepi.c +1 -0
index e0956880d11..99037a09a36 100644
@@ -26,6 +26,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/arm/allwinner-h3.h"
 #include "hw/arm/boot.h"
+#include "target/arm/psci.h"
 
 static struct arm_boot_info orangepi_binfo;
 
hw/arm/sbsa-ref.c +1 -0
index 90fbb56ba7a..1f592627c99 100644
@@ -53,6 +53,7 @@
 #include "target/arm/cpu-qom.h"
 #include "target/arm/gtimer.h"
 #include "target/arm/multiprocessing.h"
+#include "target/arm/psci.h"
 
 #define RAMLIMIT_GB 8192
 #define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)
hw/arm/virt-acpi-build.c +1 -0
index 3ac8f8e1786..da61af1d359 100644
@@ -59,6 +59,7 @@
 #include "hw/acpi/viot.h"
 #include "hw/virtio/virtio-acpi.h"
 #include "target/arm/multiprocessing.h"
+#include "target/arm/psci.h"
 
 #define ARM_SPI_BASE 32
 
hw/arm/virt.c +1 -0
index a96452f17a4..fe2dec9500f 100644
@@ -79,6 +79,7 @@
 #include "target/arm/internals.h"
 #include "target/arm/multiprocessing.h"
 #include "target/arm/gtimer.h"
+#include "target/arm/psci.h"
 #include "hw/mem/pc-dimm.h"
 #include "hw/mem/nvdimm.h"
 #include "hw/acpi/generic_event_device.h"
hw/arm/xlnx-versal-virt.c +1 -0
index e19c4d9ef58..94fad8e60f2 100644
@@ -21,6 +21,7 @@
 #include "hw/arm/xlnx-versal.h"
 #include "hw/arm/boot.h"
 #include "target/arm/multiprocessing.h"
+#include "target/arm/psci.h"
 #include "qom/object.h"
 
 #define TYPE_XLNX_VERSAL_VIRT_MACHINE MACHINE_TYPE_NAME("xlnx-versal-virt")
hw/arm/xlnx-zcu102.c +1 -0
index 88b1eafab4d..902ee65ca5f 100644
@@ -26,6 +26,7 @@
 #include "qom/object.h"
 #include "net/can_emu.h"
 #include "audio/audio.h"
+#include "target/arm/psci.h"
 
 struct XlnxZCU102 {
     MachineState parent_obj;
hw/vmapple/vmapple.c +1 -0
index 25652b16f0c..b73b6fb8115 100644
@@ -53,6 +53,7 @@
 #include "system/system.h"
 #include "target/arm/gtimer.h"
 #include "target/arm/multiprocessing.h"
+#include "target/arm/psci.h"
 
 struct VMAppleMachineState {
     MachineState parent;
target/arm/helper.c +1 -0
index 7fb6e886306..48238ae0b20 100644
@@ -34,6 +34,7 @@
 #endif
 #include "cpregs.h"
 #include "target/arm/gtimer.h"
+#include "target/arm/psci.h"
 
 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
 
target/arm/hvf/hvf.c +1 -0
index 34ca36fab55..f617e73feae 100644
@@ -33,6 +33,7 @@
 #include "target/arm/internals.h"
 #include "target/arm/multiprocessing.h"
 #include "target/arm/gtimer.h"
+#include "target/arm/psci.h"
 #include "trace.h"
 #include "migration/vmstate.h"
 
target/arm/tcg/op_helper.c +1 -0
index 005f84082af..6e9db2e77e2 100644
@@ -26,6 +26,7 @@
 #include "exec/exec-all.h"
 #include "accel/tcg/cpu-ldst.h"
 #include "target/arm/gtimer.h"
+#include "target/arm/psci.h"
 #include "cpregs.h"
 
 #define SIGNBIT (uint32_t)0x80000000
target/arm/tcg/psci.c +1 -0
index cabed43e8a8..0313cdd6ba2 100644
@@ -25,6 +25,7 @@
 #include "internals.h"
 #include "arm-powerctl.h"
 #include "target/arm/multiprocessing.h"
+#include "target/arm/psci.h"
 
 bool arm_is_psci_call(ARMCPU *cpu, int excp_type)
 {
Signature · 1 line
2.47.1
#10 lore raw

PATCH 10/13 target/arm: Extract feature definitions to 'cpu_has_feature.h' header

In reply to Philippe Mathieu-Daudé
---
 target/arm/cpu.h             | 54 +-----------------------------
 target/arm/cpu_has_feature.h | 65 ++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 53 deletions(-)
 create mode 100644 target/arm/cpu_has_feature.h
target/arm/cpu.h +1 -53
index e78a1668bba..a76874badc3 100644
@@ -30,6 +30,7 @@
 #include "exec/gdbstub.h"
 #include "exec/page-protection.h"
 #include "qapi/qapi-types-common.h"
+#include "target/arm/cpu_has_feature.h"
 #include "target/arm/gtimer.h"
 
 #define EXCP_UDEF            1   /* undefined instruction */
@@ -2379,59 +2380,6 @@ FIELD(MFAR, NS, 63, 1)
 
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(((ARMCPU *)0)->ccsidr) <= R_V7M_CSSELR_INDEX_MASK);
 
-/* If adding a feature bit which corresponds to a Linux ELF
- * HWCAP bit, remember to update the feature-bit-to-hwcap
- * mapping in linux-user/elfload.c:get_elf_hwcap().
- */
-enum arm_features {
-    ARM_FEATURE_AUXCR,  /* ARM1026 Auxiliary control register.  */
-    ARM_FEATURE_XSCALE, /* Intel XScale extensions.  */
-    ARM_FEATURE_IWMMXT, /* Intel iwMMXt extension.  */
-    ARM_FEATURE_V6,
-    ARM_FEATURE_V6K,
-    ARM_FEATURE_V7,
-    ARM_FEATURE_THUMB2,
-    ARM_FEATURE_PMSA,   /* no MMU; may have Memory Protection Unit */
-    ARM_FEATURE_NEON,
-    ARM_FEATURE_M, /* Microcontroller profile.  */
-    ARM_FEATURE_OMAPCP, /* OMAP specific CP15 ops handling.  */
-    ARM_FEATURE_THUMB2EE,
-    ARM_FEATURE_V7MP,    /* v7 Multiprocessing Extensions */
-    ARM_FEATURE_V7VE, /* v7 Virtualization Extensions (non-EL2 parts) */
-    ARM_FEATURE_V4T,
-    ARM_FEATURE_V5,
-    ARM_FEATURE_STRONGARM,
-    ARM_FEATURE_VAPA, /* cp15 VA to PA lookups */
-    ARM_FEATURE_GENERIC_TIMER,
-    ARM_FEATURE_MVFR, /* Media and VFP Feature Registers 0 and 1 */
-    ARM_FEATURE_DUMMY_C15_REGS, /* RAZ/WI all of cp15 crn=15 */
-    ARM_FEATURE_CACHE_TEST_CLEAN, /* 926/1026 style test-and-clean ops */
-    ARM_FEATURE_CACHE_DIRTY_REG, /* 1136/1176 cache dirty status register */
-    ARM_FEATURE_CACHE_BLOCK_OPS, /* v6 optional cache block operations */
-    ARM_FEATURE_MPIDR, /* has cp15 MPIDR */
-    ARM_FEATURE_LPAE, /* has Large Physical Address Extension */
-    ARM_FEATURE_V8,
-    ARM_FEATURE_AARCH64, /* supports 64 bit mode */
-    ARM_FEATURE_CBAR, /* has cp15 CBAR */
-    ARM_FEATURE_CBAR_RO, /* has cp15 CBAR and it is read-only */
-    ARM_FEATURE_EL2, /* has EL2 Virtualization support */
-    ARM_FEATURE_EL3, /* has EL3 Secure monitor support */
-    ARM_FEATURE_THUMB_DSP, /* DSP insns supported in the Thumb encodings */
-    ARM_FEATURE_PMU, /* has PMU support */
-    ARM_FEATURE_VBAR, /* has cp15 VBAR */
-    ARM_FEATURE_M_SECURITY, /* M profile Security Extension */
-    ARM_FEATURE_M_MAIN, /* M profile Main Extension */
-    ARM_FEATURE_V8_1M, /* M profile extras only in v8.1M and later */
-    /*
-     * ARM_FEATURE_BACKCOMPAT_CNTFRQ makes the CPU default cntfrq be 62.5MHz
-     * if the board doesn't set a value, instead of 1GHz. It is for backwards
-     * compatibility and used only with CPU definitions that were already
-     * in QEMU before we changed the default. It should not be set on any
-     * CPU types added in future.
-     */
-    ARM_FEATURE_BACKCOMPAT_CNTFRQ, /* 62.5MHz timer default */
-};
-
 static inline int arm_feature(CPUARMState *env, int feature)
 {
     return (env->features & (1ULL << feature)) != 0;
target/arm/cpu_has_feature.h new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.47.1
#11 lore raw

PATCH 11/13 target/arm: Add arm_cpu_has_feature() helper

In reply to Philippe Mathieu-Daudé

arm_cpu_has_feature() is equivalent of arm_feature(), however while the latter uses CPUARMState so is target-specific, the former doesn't and can be called by target-agnostic code in hw/.

---
 target/arm/cpu_has_feature.h | 2 ++
 target/arm/cpu.c             | 7 +++++++
 2 files changed, 9 insertions(+)
target/arm/cpu_has_feature.h +2 -0
index 2adfccd9208..352f9d75bed 100644
@@ -62,4 +62,6 @@ typedef enum arm_features {
     ARM_FEATURE_BACKCOMPAT_CNTFRQ, /* 62.5MHz timer default */
 } ArmCpuFeature;
 
+bool arm_cpu_has_feature(ARMCPU *cpu, ArmCpuFeature feature);
+
 #endif
target/arm/cpu.c +7 -0
index 6f62745d7f6..66a58916fcc 100644
@@ -55,6 +55,13 @@
 #include "target/arm/gtimer.h"
 #include "target/arm/multiprocessing.h"
 
+bool arm_cpu_has_feature(ARMCPU *cpu, ArmCpuFeature feature)
+{
+    CPUARMState *env = &cpu->env;
+
+    return arm_feature(env, feature);
+}
+
 static void arm_cpu_set_pc(CPUState *cs, vaddr value)
 {
     ARMCPU *cpu = ARM_CPU(cs);
Signature · 1 line
2.47.1
#12 lore raw

PATCH 12/13 hw/arm/realview: Replace arm_feature() -> arm_cpu_has_feature()

In reply to Philippe Mathieu-Daudé

By using arm_cpu_has_feature() instead of arm_feature() we don't need to include "cpu.h" anymore.

---
 hw/arm/realview.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
hw/arm/realview.c +4 -6
index f81d084eb80..48cfe05add0 100644
@@ -9,7 +9,6 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "cpu.h"
 #include "hw/sysbus.h"
 #include "hw/arm/boot.h"
 #include "hw/arm/primecell.h"
@@ -31,6 +30,7 @@
 #include "hw/sd/sd.h"
 #include "audio/audio.h"
 #include "target/arm/cpu-qom.h"
+#include "target/arm/cpu_has_feature.h"
 
 #define SMP_BOOT_ADDR 0xe0000000
 #define SMP_BOOTREG_ADDR 0x10000030
@@ -77,7 +77,6 @@ static void realview_init(MachineState *machine,
                           enum realview_board_type board_type)
 {
     ARMCPU *cpu = NULL;
-    CPUARMState *env;
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *ram_lo;
     MemoryRegion *ram_hi = g_new(MemoryRegion, 1);
@@ -138,16 +137,15 @@ static void realview_init(MachineState *machine,
         cpu_irq[n] = qdev_get_gpio_in(DEVICE(cpuobj), ARM_CPU_IRQ);
     }
     cpu = ARM_CPU(first_cpu);
-    env = &cpu->env;
-    if (arm_feature(env, ARM_FEATURE_V7)) {
+    if (arm_cpu_has_feature(cpu, ARM_FEATURE_V7)) {
         if (is_mpcore) {
             proc_id = 0x0c000000;
         } else {
             proc_id = 0x0e000000;
         }
-    } else if (arm_feature(env, ARM_FEATURE_V6K)) {
+    } else if (arm_cpu_has_feature(cpu, ARM_FEATURE_V6K)) {
         proc_id = 0x06000000;
-    } else if (arm_feature(env, ARM_FEATURE_V6)) {
+    } else if (arm_cpu_has_feature(cpu, ARM_FEATURE_V6)) {
         proc_id = 0x04000000;
     } else {
         proc_id = 0x02000000;
Signature · 1 line
2.47.1
#13 lore raw

PATCH 13/13 hw/arm/virt-acpi: Replace arm_feature() -> arm_cpu_has_feature()

In reply to Philippe Mathieu-Daudé

Using arm_cpu_has_feature() instead of arm_feature() remove a dependency on (the indirectly included) "cpu.h" header.

---
 hw/arm/virt-acpi-build.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/arm/virt-acpi-build.c +2 -1
index da61af1d359..ae28d958895 100644
@@ -58,6 +58,7 @@
 #include "hw/acpi/ghes.h"
 #include "hw/acpi/viot.h"
 #include "hw/virtio/virtio-acpi.h"
+#include "target/arm/cpu_has_feature.h"
 #include "target/arm/multiprocessing.h"
 #include "target/arm/psci.h"
 
@@ -697,7 +698,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
         ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(i));
         uint64_t physical_base_address = 0, gich = 0, gicv = 0;
         uint32_t vgic_interrupt = vms->virt ? ARCH_GIC_MAINT_IRQ : 0;
-        uint32_t pmu_interrupt = arm_feature(&armcpu->env, ARM_FEATURE_PMU) ?
+        uint32_t pmu_interrupt = arm_cpu_has_feature(armcpu, ARM_FEATURE_PMU) ?
                                              VIRTUAL_PMU_IRQ : 0;
 
         if (vms->gic_version == VIRT_GIC_VERSION_2) {
Signature · 1 line
2.47.1
Reviewed-by on the v1 series
#14 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé

This series is more useful for heterogeneous emulation preparation than single binary, because it allows non-ARM hw/ code to configure ARM cores, so not using target-specific APIs. I figured some patches could be useful to Pierrick "build hw/arm once" series (in particular arm_cpu_has_feature).

Quoted 15 lines

Philippe Mathieu-Daudé (13):
target/arm/cpu-features: Include missing 'cpu.h' header target/arm/qmp: Include missing 'cpu.h' header target/arm/kvm: Include missing 'cpu-qom.h' header target/arm/hvf: Include missing 'cpu-qom.h' header hw/arm: Remove unnecessary 'cpu.h' header
target/arm: Restrict inclusion of 'multiprocessing.h' target/arm: Move some definitions from 'cpu.h' to 'multiprocessing.h' hw/arm: Include missing 'target/arm/gtimer.h' header target/arm: Extract PSCI definitions to 'psci.h' target/arm: Extract feature definitions to 'cpu_has_feature.h' header target/arm: Add arm_cpu_has_feature() helper hw/arm/realview: Replace arm_feature() -> arm_cpu_has_feature() hw/arm/virt-acpi: Replace arm_feature() -> arm_cpu_has_feature()

#15 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé

This series is more useful for heterogeneous emulation preparation than single binary, because it allows non-ARM hw/ code to configure ARM cores, so not using target-specific APIs. I figured some patches could be useful to Pierrick "build hw/arm once" series (in particular arm_cpu_has_feature).

I'm ok with the cleanup part, as I sent a reviewed-by.

However, I'm not sure in which context non-ARM hw/ code will really need to do it. It would be better if we stick to mandatory changes for now, instead of anticipating future needs, which might be real or not. We can implement those changes only as part of a series that really needs it.

#16 lore raw
Quoted 8 lines · Pierrick Bouvier
Quoted 6 lines · Philippe Mathieu-Daudé

This series is more useful for heterogeneous emulation preparation than single binary, because it allows non-ARM hw/ code to configure ARM cores, so not using target-specific APIs. I figured some patches could be useful to Pierrick "build hw/arm once" series (in particular arm_cpu_has_feature).

Quoted 4 lines

I'm ok with the cleanup part, as I sent a reviewed-by.

However, I'm not sure in which context non-ARM hw/ code will really need to do it. It would be better if we stick to mandatory changes for now, instead of anticipating future needs, which might be real or not. We can implement those changes only as part of a series that really needs it.

I understand your view. I had to rebase these now old patches, and figured it will cost me less if I get them merged, rather than keeping rebasing them for 4 or 5 releases.

Single binary effort is just a milestone toward heterogeneous emulation.

#17 lore raw
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Pierrick Bouvier
Quoted 6 lines · Philippe Mathieu-Daudé

This series is more useful for heterogeneous emulation preparation than single binary, because it allows non-ARM hw/ code to configure ARM cores, so not using target-specific APIs. I figured some patches could be useful to Pierrick "build hw/arm once" series (in particular arm_cpu_has_feature).

Quoted 7 lines

I'm ok with the cleanup part, as I sent a reviewed-by.

However, I'm not sure in which context non-ARM hw/ code will really need to do it. It would be better if we stick to mandatory changes for now, instead of anticipating future needs, which might be real or not. We can implement those changes only as part of a series that really needs it.

Quoted 4 lines

I understand your view. I had to rebase these now old patches, and figured it will cost me less if I get them merged, rather than keeping rebasing them for 4 or 5 releases.

Sure, that's the best approach. For the reviewer, it's not obvious when you implemented this though, so the only question we can ask is "Why is that needed?".

Quoted 1 line

Single binary effort is just a milestone toward heterogeneous emulation.

Yes. That said, it does not change the fact that anticipating needs (i.e. not explicitely required to compile/execute right now) can detour us from the goal, whether it's the single binary, heterogeneous emulation, or any feature we want to add to QEMU.

In the context of this series, it's still not obvious for me why a piece of hardware not related to Arm would poke internal registers to detect if a feature is implemented or not. Thus, it's not obvious why we need to expose that now. If we don't have an answer to that, I suggest to postpone this part of the series until we get a real use case.

For the cleanup part, as I mentioned before, I'm totally ok with it.