[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 17/18] target/riscv/kvm.c: add kvmconfig_get_cfg_addr() helper
From: |
Daniel Henrique Barboza |
Subject: |
[PATCH v2 17/18] target/riscv/kvm.c: add kvmconfig_get_cfg_addr() helper |
Date: |
Tue, 13 Jun 2023 17:58:56 -0300 |
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>
---
target/riscv/kvm.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
index 0b6dff70de..3a9f7b0722 100644
--- a/target/riscv/kvm.c
+++ b/target/riscv/kvm.c
@@ -222,11 +222,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;
}
@@ -234,8 +238,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;
}
--
2.40.1
- Re: [PATCH v2 11/18] target/riscv/cpu: add misa_ext_infos[], (continued)
- [PATCH v2 12/18] target/riscv: add KVM specific MISA properties, Daniel Henrique Barboza, 2023/06/13
- [PATCH v2 13/18] target/riscv/kvm.c: update KVM MISA bits, Daniel Henrique Barboza, 2023/06/13
- [PATCH v2 14/18] target/riscv/kvm.c: add multi-letter extension KVM properties, Daniel Henrique Barboza, 2023/06/13
- [PATCH v2 15/18] target/riscv: make riscv_isa_string_ext() KVM compatible, Daniel Henrique Barboza, 2023/06/13
- [PATCH v2 16/18] target/riscv: update multi-letter extension KVM properties, Daniel Henrique Barboza, 2023/06/13
- [PATCH v2 17/18] target/riscv/kvm.c: add kvmconfig_get_cfg_addr() helper,
Daniel Henrique Barboza <=
- [PATCH v2 18/18] target/riscv/kvm.c: read/write (cbom|cboz)_blocksize in KVM, Daniel Henrique Barboza, 2023/06/13