diff mbox series

[v2,10/14] hw/arm: Prefer arm_feature(EL2) over object_property_find(has_el2)

Message ID 20240109180930.90793-11-philmd@linaro.org
State New
Headers show
Series hw/arm: Prefer arm_feature() over object_property_find() | expand

Commit Message

Philippe Mathieu-Daudé Jan. 9, 2024, 6:09 p.m. UTC
The "has_el2" property is added to ARMCPU when the
ARM_FEATURE_EL2 feature is available. Rather than
checking whether the QOM property is present, directly
check the feature.

Suggested-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/arm/vexpress.c  | 3 ++-
 hw/arm/virt.c      | 2 +-
 hw/cpu/a15mpcore.c | 6 ++++--
 3 files changed, 7 insertions(+), 4 deletions(-)

Comments

Philippe Mathieu-Daudé Jan. 9, 2024, 6:23 p.m. UTC | #1
On 9/1/24 19:09, Philippe Mathieu-Daudé wrote:
> The "has_el2" property is added to ARMCPU when the
> ARM_FEATURE_EL2 feature is available. Rather than
> checking whether the QOM property is present, directly
> check the feature.
> 
> Suggested-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/arm/vexpress.c  | 3 ++-
>   hw/arm/virt.c      | 2 +-
>   hw/cpu/a15mpcore.c | 6 ++++--
>   3 files changed, 7 insertions(+), 4 deletions(-)


> diff --git a/hw/cpu/a15mpcore.c b/hw/cpu/a15mpcore.c
> index cebfe142cf..1fa079b3b8 100644
> --- a/hw/cpu/a15mpcore.c
> +++ b/hw/cpu/a15mpcore.c
> @@ -73,9 +73,11 @@ static void a15mp_priv_realize(DeviceState *dev, Error **errp)
>               qdev_prop_set_bit(gicdev, "has-security-extensions", true);
>           }
>           /* Similarly for virtualization support */
> -        has_el2 = object_property_find(cpuobj, "has_el2") &&
> +        has_el2 = arm_feature(cpu_env(cpu), ARM_FEATURE_EL2);
> +        if (has_el2) {
>               object_property_get_bool(cpuobj, "has_el2", &error_abort);

Missing to be squashed on top:

-- >8 --
          if (has_el2) {
-            object_property_get_bool(cpuobj, "has_el2", &error_abort);
-            qdev_prop_set_bit(gicdev, "has-virtualization-extensions", 
true);
+            qdev_prop_set_bit(gicdev, "has-virtualization-extensions",
+                              object_property_get_bool(cpuobj, "has_el2",
+                                                       &error_abort));
          }
---

> -        qdev_prop_set_bit(gicdev, "has-virtualization-extensions", has_el2);
> +            qdev_prop_set_bit(gicdev, "has-virtualization-extensions", true);
> +        }
>       }
>   
>       if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) {
diff mbox series

Patch

diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index fd981f4c33..753a645c05 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -218,12 +218,13 @@  static void init_cpus(MachineState *ms, const char *cpu_type,
     /* Create the actual CPUs */
     for (n = 0; n < smp_cpus; n++) {
         Object *cpuobj = object_new(cpu_type);
+        ARMCPU *cpu = ARM_CPU(cpuobj);
 
         if (!secure) {
             object_property_set_bool(cpuobj, "has_el3", false, NULL);
         }
         if (!virt) {
-            if (object_property_find(cpuobj, "has_el2")) {
+            if (arm_feature(&cpu->env, ARM_FEATURE_EL2)) {
                 object_property_set_bool(cpuobj, "has_el2", false, NULL);
             }
         }
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 2793121cb4..35eb01a3dc 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2146,7 +2146,7 @@  static void machvirt_init(MachineState *machine)
             object_property_set_bool(cpuobj, "has_el3", false, NULL);
         }
 
-        if (!vms->virt && object_property_find(cpuobj, "has_el2")) {
+        if (!vms->virt &&  arm_feature(cpu_env(cs), ARM_FEATURE_EL2)) {
             object_property_set_bool(cpuobj, "has_el2", false, NULL);
         }
 
diff --git a/hw/cpu/a15mpcore.c b/hw/cpu/a15mpcore.c
index cebfe142cf..1fa079b3b8 100644
--- a/hw/cpu/a15mpcore.c
+++ b/hw/cpu/a15mpcore.c
@@ -73,9 +73,11 @@  static void a15mp_priv_realize(DeviceState *dev, Error **errp)
             qdev_prop_set_bit(gicdev, "has-security-extensions", true);
         }
         /* Similarly for virtualization support */
-        has_el2 = object_property_find(cpuobj, "has_el2") &&
+        has_el2 = arm_feature(cpu_env(cpu), ARM_FEATURE_EL2);
+        if (has_el2) {
             object_property_get_bool(cpuobj, "has_el2", &error_abort);
-        qdev_prop_set_bit(gicdev, "has-virtualization-extensions", has_el2);
+            qdev_prop_set_bit(gicdev, "has-virtualization-extensions", true);
+        }
     }
 
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) {