hv: vfdt: Add API to set the vcpu ISA string

RISC-V vcpu capability is represented by an ISA extension string.
Add API to adjust this string for virtual FDT.

Tracked-On: #8841
Signed-off-by: Yifan Liu <yifan1.liu@intel.com>
Acked-by: Wang Yu1 <yu1.wang@intel.com>
This commit is contained in:
Yifan Liu
2025-11-04 09:53:04 +00:00
committed by acrnsi-robot
parent fd1dcf3f25
commit 9dd94da83f

View File

@@ -15,6 +15,7 @@
#include <cpu.h>
#include <per_cpu.h>
#include <vfdt.h>
#include <libfdt.h>
#include <asm/guest/vcpu_priv.h>
@@ -91,7 +92,32 @@ void arch_vm_prepare_bsp(struct acrn_vcpu *vcpu)
void arch_trigger_level_intr(__unused struct acrn_vm *vm,
__unused uint32_t irq, __unused bool assert) {}
static void fdt_set_hart_isa_str_all(void *fdt, const char *isa_str)
{
int cpus_off, cpu, ret, len;
const char *val;
cpus_off = fdt_path_offset(fdt, "/cpus");
if (cpus_off > 0) {
fdt_for_each_subnode(cpu, fdt, cpus_off) {
val = (const char *)fdt_getprop(fdt, cpu, "device_type", &len);
if ((len > 0) && (strncmp(val, "cpu", 3) == 0)) {
ret = fdt_setprop_string(fdt, cpu, "riscv,isa", isa_str);
if (ret < 0) {
pr_err("Failed to set hart isa string: %d", ret);
}
}
}
}
}
void arch_init_service_vm_vfdt(struct acrn_vm *vm)
{
(void)vm;
/* TODO: For now hardcode the isa string.
*
* To do it formally, get isa string from host, remove extensions
* that we do not support (such as "h") and pass to vm.
*/
const char *isa_str = "rv64imafdc_zicsr_zifencei_sstc";
fdt_set_hart_isa_str_all(vm_get_vfdt(vm), isa_str);
}