aboutsummaryrefslogtreecommitdiff
path: root/target/riscv
diff options
context:
space:
mode:
authorDaniel Henrique Barboza <dbarboza@ventanamicro.com>2023-07-06 07:17:37 -0300
committerAlistair Francis <alistair.francis@wdc.com>2023-07-10 22:29:20 +1000
commita1be1d9a77a8170822258663e5fb0580f5252536 (patch)
tree9542f90a3cfc42bdcf3295d2b7784d9221ce6b65 /target/riscv
parentdf817297d7a5397a3383207b0e0174b464cf42ab (diff)
downloadqemu-a1be1d9a77a8170822258663e5fb0580f5252536.zip
qemu-a1be1d9a77a8170822258663e5fb0580f5252536.tar.gz
qemu-a1be1d9a77a8170822258663e5fb0580f5252536.tar.bz2
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>
Diffstat (limited to 'target/riscv')
-rw-r--r--target/riscv/kvm.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
index 4d7476c..fd22ef4 100644
--- a/target/riscv/kvm.c
+++ b/target/riscv/kvm.c
@@ -215,11 +215,15 @@ 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;
}
@@ -227,8 +231,7 @@ static void kvm_cpu_cfg_set(RISCVCPU *cpu, KVMCPUConfig *multi_ext,
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;
}