[PATCH v2 2/4] target/loongarch: Add cpu feature flags

Song Gao posted 4 patches 1 year, 1 month ago
Maintainers: Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Song Gao <gaosong@loongson.cn>
There is a newer version of this series
[PATCH v2 2/4] target/loongarch: Add cpu feature flags
Posted by Song Gao 1 year, 1 month ago
CPULoongArchState adds cpu feature flags features.
Intrduce loongarch_feature() to check feature and
set_feature() to set feature.

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 target/loongarch/cpu.c |  4 ++++
 target/loongarch/cpu.h | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index ef6922e812..87fcd08110 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -366,6 +366,10 @@ static void loongarch_la464_initfn(Object *obj)
     CPULoongArchState *env = &cpu->env;
     int i;
 
+    env->features = 0;
+    set_feature(env, CPU_FEATURE_LSX);
+    set_feature(env, CPU_FEATURE_LASX);
+
     for (i = 0; i < 21; i++) {
         env->cpucfg[i] = 0x0;
     }
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 8b54cf109c..b98064945a 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -295,6 +295,8 @@ typedef struct CPUArchState {
     uint64_t lladdr; /* LL virtual address compared against SC */
     uint64_t llval;
 
+    uint64_t features;
+
     /* LoongArch CSRs */
     uint64_t CSR_CRMD;
     uint64_t CSR_PRMD;
@@ -364,6 +366,36 @@ typedef struct CPUArchState {
 #endif
 } CPULoongArchState;
 
+/*
+ * See arch/loongarch/include/asm/cpu.h
+ * and arch/loongarch/include/uapi/asm/hwcap.h
+ */
+enum loongarch_features {
+    CPU_FEATURE_CPUCFG,
+    CPU_FEATURE_LAM,
+    CPU_FEATURE_UAL,
+    CPU_FEATURE_FPU,
+    CPU_FEATURE_LSX,
+    CPU_FEATURE_LASX,
+    CPU_FEATURE_CRC32,
+    CPU_FEATURE_COMPLEX,
+    CPU_FEATURE_CRYPTO,
+    CPU_FEATURE_LVZ,
+    CPU_FEATURE_LBT_X86,
+    CPU_FEATURE_LBT_ARM,
+    CPU_FEATURE_LBT_MIPS,
+};
+
+static inline int loongarch_feature(CPULoongArchState *env, int feature)
+{
+    return (env->features & (1ULL << feature)) != 0;
+}
+
+static inline void set_feature(CPULoongArchState *env, int feature)
+{
+    env->features |= 1ULL << feature;
+}
+
 /**
  * LoongArchCPU:
  * @env: #CPULoongArchState
-- 
2.25.1
Re: [PATCH v2 2/4] target/loongarch: Add cpu feature flags
Posted by maobibo 1 year, 1 month ago

在 2023/10/19 下午8:58, Song Gao 写道:
> CPULoongArchState adds cpu feature flags features.
> Intrduce loongarch_feature() to check feature and
> set_feature() to set feature.
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
>   target/loongarch/cpu.c |  4 ++++
>   target/loongarch/cpu.h | 32 ++++++++++++++++++++++++++++++++
>   2 files changed, 36 insertions(+)
> 
> diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
> index ef6922e812..87fcd08110 100644
> --- a/target/loongarch/cpu.c
> +++ b/target/loongarch/cpu.c
> @@ -366,6 +366,10 @@ static void loongarch_la464_initfn(Object *obj)
>       CPULoongArchState *env = &cpu->env;
>       int i;
>   
> +    env->features = 0;
> +    set_feature(env, CPU_FEATURE_LSX);
> +    set_feature(env, CPU_FEATURE_LASX);
> +
>       for (i = 0; i < 21; i++) {
>           env->cpucfg[i] = 0x0;
>       }
> diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
> index 8b54cf109c..b98064945a 100644
> --- a/target/loongarch/cpu.h
> +++ b/target/loongarch/cpu.h
> @@ -295,6 +295,8 @@ typedef struct CPUArchState {
>       uint64_t lladdr; /* LL virtual address compared against SC */
>       uint64_t llval;
>   
> +    uint64_t features;
Like what Richard says, it is not necessary to use features here,
cpucfg2 can be used directly.

> +
>       /* LoongArch CSRs */
>       uint64_t CSR_CRMD;
>       uint64_t CSR_PRMD;
> @@ -364,6 +366,36 @@ typedef struct CPUArchState {
>   #endif
>   } CPULoongArchState;
>   
> +/*
> + * See arch/loongarch/include/asm/cpu.h
> + * and arch/loongarch/include/uapi/asm/hwcap.h
> + */
> +enum loongarch_features {
> +    CPU_FEATURE_CPUCFG,
> +    CPU_FEATURE_LAM,
> +    CPU_FEATURE_UAL,
> +    CPU_FEATURE_FPU,
> +    CPU_FEATURE_LSX,
> +    CPU_FEATURE_LASX,
> +    CPU_FEATURE_CRC32,
> +    CPU_FEATURE_COMPLEX,
> +    CPU_FEATURE_CRYPTO,
> +    CPU_FEATURE_LVZ,
> +    CPU_FEATURE_LBT_X86,
> +    CPU_FEATURE_LBT_ARM,
> +    CPU_FEATURE_LBT_MIPS,
> +};
Suggest to only list features which can be set on/off from QEMU command 
line.

Regards
Bibo, Mao
> +
> +static inline int loongarch_feature(CPULoongArchState *env, int feature)
> +{
> +    return (env->features & (1ULL << feature)) != 0;
> +}
> +
> +static inline void set_feature(CPULoongArchState *env, int feature)
> +{
> +    env->features |= 1ULL << feature;
> +}
> +
>   /**
>    * LoongArchCPU:
>    * @env: #CPULoongArchState
> 


Re: [PATCH v2 2/4] target/loongarch: Add cpu feature flags
Posted by gaosong 1 year, 1 month ago
在 2023/10/20 下午4:05, maobibo 写道:
>
>
> 在 2023/10/19 下午8:58, Song Gao 写道:
>> CPULoongArchState adds cpu feature flags features.
>> Intrduce loongarch_feature() to check feature and
>> set_feature() to set feature.
>>
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> ---
>>   target/loongarch/cpu.c |  4 ++++
>>   target/loongarch/cpu.h | 32 ++++++++++++++++++++++++++++++++
>>   2 files changed, 36 insertions(+)
>>
>> diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
>> index ef6922e812..87fcd08110 100644
>> --- a/target/loongarch/cpu.c
>> +++ b/target/loongarch/cpu.c
>> @@ -366,6 +366,10 @@ static void loongarch_la464_initfn(Object *obj)
>>       CPULoongArchState *env = &cpu->env;
>>       int i;
>>   +    env->features = 0;
>> +    set_feature(env, CPU_FEATURE_LSX);
>> +    set_feature(env, CPU_FEATURE_LASX);
>> +
>>       for (i = 0; i < 21; i++) {
>>           env->cpucfg[i] = 0x0;
>>       }
>> diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
>> index 8b54cf109c..b98064945a 100644
>> --- a/target/loongarch/cpu.h
>> +++ b/target/loongarch/cpu.h
>> @@ -295,6 +295,8 @@ typedef struct CPUArchState {
>>       uint64_t lladdr; /* LL virtual address compared against SC */
>>       uint64_t llval;
>>   +    uint64_t features;
> Like what Richard says, it is not necessary to use features here,
> cpucfg2 can be used directly.
>
Agreed,  I dropped this patch on v3.

Thanks.
Song Gao