target/loongarch: Allow user enable/disable LSX/LASX features
Some users may not need LSX/LASX, this patch allows the user enable/disable LSX/LASX features. e.g '-cpu max,lsx=on,lasx=on' (default); '-cpu max,lsx=on,lasx=off' (enabled LSX); '-cpu max,lsx=off,lasx=on' (enabled LASX, LSX); '-cpu max,lsx=off' (disable LSX and LASX). Signed-off-by: Song Gao <gaosong@loongson.cn> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20231020084925.3457084-3-gaosong@loongson.cn>
This commit is contained in:
parent
d6f077321a
commit
464136ceb6
@ -443,6 +443,7 @@ static void loongarch_la464_initfn(Object *obj)
|
||||
env->cpucfg[20] = data;
|
||||
|
||||
env->CSR_ASID = FIELD_DP64(0, CSR_ASID, ASIDBITS, 0xa);
|
||||
loongarch_cpu_post_init(obj);
|
||||
}
|
||||
|
||||
static void loongarch_la132_initfn(Object *obj)
|
||||
@ -622,6 +623,72 @@ static const MemoryRegionOps loongarch_qemu_ops = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static bool loongarch_get_lsx(Object *obj, Error **errp)
|
||||
{
|
||||
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
|
||||
bool ret;
|
||||
|
||||
if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
|
||||
ret = true;
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void loongarch_set_lsx(Object *obj, bool value, Error **errp)
|
||||
{
|
||||
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
|
||||
|
||||
if (value) {
|
||||
cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 1);
|
||||
} else {
|
||||
cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 0);
|
||||
cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static bool loongarch_get_lasx(Object *obj, Error **errp)
|
||||
{
|
||||
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
|
||||
bool ret;
|
||||
|
||||
if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) {
|
||||
ret = true;
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void loongarch_set_lasx(Object *obj, bool value, Error **errp)
|
||||
{
|
||||
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
|
||||
|
||||
if (value) {
|
||||
if (!FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
|
||||
cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 1);
|
||||
}
|
||||
cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 1);
|
||||
} else {
|
||||
cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void loongarch_cpu_post_init(Object *obj)
|
||||
{
|
||||
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
|
||||
|
||||
if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
|
||||
object_property_add_bool(obj, "lsx", loongarch_get_lsx,
|
||||
loongarch_set_lsx);
|
||||
}
|
||||
if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) {
|
||||
object_property_add_bool(obj, "lasx", loongarch_get_lasx,
|
||||
loongarch_set_lasx);
|
||||
}
|
||||
}
|
||||
|
||||
static void loongarch_cpu_init(Object *obj)
|
||||
{
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
|
@ -486,4 +486,6 @@ void loongarch_cpu_list(void);
|
||||
#define LOONGARCH_CPU_TYPE_NAME(model) model LOONGARCH_CPU_TYPE_SUFFIX
|
||||
#define CPU_RESOLVING_TYPE TYPE_LOONGARCH_CPU
|
||||
|
||||
void loongarch_cpu_post_init(Object *obj);
|
||||
|
||||
#endif /* LOONGARCH_CPU_H */
|
||||
|
Loading…
Reference in New Issue
Block a user