diff mbox series

[v3,2/5] qemu/target-info: Add %target_arch field to TargetInfo

Message ID 20250502214551.80401-3-philmd@linaro.org
State New
Headers show
Series hw/virtio: Build virtio-mem.c once | expand

Commit Message

Philippe Mathieu-Daudé May 2, 2025, 9:45 p.m. UTC
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/qemu/target-info-impl.h | 4 +++-
 target-info-stub.c              | 1 +
 target-info.c                   | 3 +++
 3 files changed, 7 insertions(+), 1 deletion(-)

Comments

Pierrick Bouvier May 4, 2025, 9:21 p.m. UTC | #1
On 5/2/25 2:45 PM, Philippe Mathieu-Daudé wrote:
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/qemu/target-info-impl.h | 4 +++-
>   target-info-stub.c              | 1 +
>   target-info.c                   | 3 +++
>   3 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/include/qemu/target-info-impl.h b/include/qemu/target-info-impl.h
> index 1b51cbcfe1b..83d584d7dba 100644
> --- a/include/qemu/target-info-impl.h
> +++ b/include/qemu/target-info-impl.h
> @@ -9,11 +9,13 @@
>   #ifndef QEMU_TARGET_INFO_IMPL_H
>   #define QEMU_TARGET_INFO_IMPL_H
>   
> -#include "qemu/target-info.h"
> +#include "qapi/qapi-types-common.h"
>   
>   typedef struct TargetInfo {
>       /* runtime equivalent of TARGET_NAME definition */
>       const char *target_name;
> +    /* related to TARGET_ARCH definition */
> +    SysEmuTarget target_arch;
>       /* runtime equivalent of TARGET_LONG_BITS definition */
>       unsigned long_bits;
>       /* runtime equivalent of CPU_RESOLVING_TYPE definition */
> diff --git a/target-info-stub.c b/target-info-stub.c
> index fecc0e71286..2e4407ff04b 100644
> --- a/target-info-stub.c
> +++ b/target-info-stub.c
> @@ -14,6 +14,7 @@
>   
>   static const TargetInfo target_info_stub = {
>       .target_name = TARGET_NAME,
> +    .target_arch = SYS_EMU_TARGET__MAX,

Time to suggest again to implement an ifdef with all TARGET_*, so we can 
get rid of this "not set" value.
It would solve all the issues with target_system_arch() function, 
without duplicating the enum SYS_EMU_TARGET itself.

The only compromise is this ifdef, that can be shrinked and eventually 
removed when we'll have implemented target_info for all configs.

>       .long_bits = TARGET_LONG_BITS,
>       .cpu_type = CPU_RESOLVING_TYPE,
>       .machine_typename = TYPE_MACHINE,
> diff --git a/target-info.c b/target-info.c
> index 8232d488870..5f6096606e4 100644
> --- a/target-info.c
> +++ b/target-info.c
> @@ -25,6 +25,9 @@ SysEmuTarget target_system_arch(void)
>   {
>       static SysEmuTarget system_arch = SYS_EMU_TARGET__MAX;
>   
> +    if (system_arch == SYS_EMU_TARGET__MAX) {
> +        system_arch = target_info()->target_arch;
> +    }
>       if (system_arch == SYS_EMU_TARGET__MAX) {
>           system_arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
>                                         &error_abort);
diff mbox series

Patch

diff --git a/include/qemu/target-info-impl.h b/include/qemu/target-info-impl.h
index 1b51cbcfe1b..83d584d7dba 100644
--- a/include/qemu/target-info-impl.h
+++ b/include/qemu/target-info-impl.h
@@ -9,11 +9,13 @@ 
 #ifndef QEMU_TARGET_INFO_IMPL_H
 #define QEMU_TARGET_INFO_IMPL_H
 
-#include "qemu/target-info.h"
+#include "qapi/qapi-types-common.h"
 
 typedef struct TargetInfo {
     /* runtime equivalent of TARGET_NAME definition */
     const char *target_name;
+    /* related to TARGET_ARCH definition */
+    SysEmuTarget target_arch;
     /* runtime equivalent of TARGET_LONG_BITS definition */
     unsigned long_bits;
     /* runtime equivalent of CPU_RESOLVING_TYPE definition */
diff --git a/target-info-stub.c b/target-info-stub.c
index fecc0e71286..2e4407ff04b 100644
--- a/target-info-stub.c
+++ b/target-info-stub.c
@@ -14,6 +14,7 @@ 
 
 static const TargetInfo target_info_stub = {
     .target_name = TARGET_NAME,
+    .target_arch = SYS_EMU_TARGET__MAX,
     .long_bits = TARGET_LONG_BITS,
     .cpu_type = CPU_RESOLVING_TYPE,
     .machine_typename = TYPE_MACHINE,
diff --git a/target-info.c b/target-info.c
index 8232d488870..5f6096606e4 100644
--- a/target-info.c
+++ b/target-info.c
@@ -25,6 +25,9 @@  SysEmuTarget target_system_arch(void)
 {
     static SysEmuTarget system_arch = SYS_EMU_TARGET__MAX;
 
+    if (system_arch == SYS_EMU_TARGET__MAX) {
+        system_arch = target_info()->target_arch;
+    }
     if (system_arch == SYS_EMU_TARGET__MAX) {
         system_arch = qapi_enum_parse(&SysEmuTarget_lookup, target_name(), -1,
                                       &error_abort);