Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
target/riscv/kvm.c: add kvmconfig_get_cfg_addr() helper
There are 2 places in which we need to get a pointer to a certain
property of the cpu->cfg struct based on property offset. Next patch
will add a couple more.

Create a helper to avoid repeating this code over and over.

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20230706101738.460804-20-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
  • Loading branch information
danielhb authored and alistair23 committed Jul 10, 2023
1 parent df81729 commit a1be1d9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions target/riscv/kvm.c
Expand Up @@ -215,20 +215,23 @@ static KVMCPUConfig kvm_multi_ext_cfgs[] = {
KVM_EXT_CFG("svpbmt", ext_svpbmt, KVM_RISCV_ISA_EXT_SVPBMT),
};

static void *kvmconfig_get_cfg_addr(RISCVCPU *cpu, KVMCPUConfig *kvmcfg)
{
return (void *)&cpu->cfg + kvmcfg->offset;
}

static void kvm_cpu_cfg_set(RISCVCPU *cpu, KVMCPUConfig *multi_ext,
uint32_t val)
{
int cpu_cfg_offset = multi_ext->offset;
bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset;
bool *ext_enabled = kvmconfig_get_cfg_addr(cpu, multi_ext);

*ext_enabled = val;
}

static uint32_t kvm_cpu_cfg_get(RISCVCPU *cpu,
KVMCPUConfig *multi_ext)
{
int cpu_cfg_offset = multi_ext->offset;
bool *ext_enabled = (void *)&cpu->cfg + cpu_cfg_offset;
bool *ext_enabled = kvmconfig_get_cfg_addr(cpu, multi_ext);

return *ext_enabled;
}
Expand Down

0 comments on commit a1be1d9

Please sign in to comment.