Skip to content

Commit ea8eb87

Browse files
danielhbMichael Tokarev
authored andcommitted
target/riscv/kvm: turn u32/u64 reg functions into macros
This change is motivated by a future change w.r.t CSRs management. We want to handle them the same way as KVM extensions, i.e. a static array with KVMCPUConfig objs that will be read/write during init and so on. But to do that properly we must be able to declare a static array that hold KVM regs. C does not allow to init static arrays and use functions as initializers, e.g. we can't do: .kvm_reg_id = kvm_riscv_reg_id_ulong(...) When instantiating the array. We can do that with macros though, so our goal is turn kvm_riscv_reg_ulong() in a macro. It is cleaner to turn every other reg_id_*() function in macros, and ulong will end up using the macros for u32 and u64, so we'll start with them. Signed-off-by: Daniel Henrique Barboza <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]> Cc: [email protected] (cherry picked from commit b609610) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 04b8557 commit ea8eb87

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

target/riscv/kvm/kvm-cpu.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ void riscv_kvm_aplic_request(void *opaque, int irq, int level)
5858

5959
static bool cap_has_mp_state;
6060

61+
#define KVM_RISCV_REG_ID_U32(type, idx) (KVM_REG_RISCV | KVM_REG_SIZE_U32 | \
62+
type | idx)
63+
64+
#define KVM_RISCV_REG_ID_U64(type, idx) (KVM_REG_RISCV | KVM_REG_SIZE_U64 | \
65+
type | idx)
66+
6167
static uint64_t kvm_riscv_reg_id_ulong(CPURISCVState *env, uint64_t type,
6268
uint64_t idx)
6369
{
@@ -76,16 +82,6 @@ static uint64_t kvm_riscv_reg_id_ulong(CPURISCVState *env, uint64_t type,
7682
return id;
7783
}
7884

79-
static uint64_t kvm_riscv_reg_id_u32(uint64_t type, uint64_t idx)
80-
{
81-
return KVM_REG_RISCV | KVM_REG_SIZE_U32 | type | idx;
82-
}
83-
84-
static uint64_t kvm_riscv_reg_id_u64(uint64_t type, uint64_t idx)
85-
{
86-
return KVM_REG_RISCV | KVM_REG_SIZE_U64 | type | idx;
87-
}
88-
8985
static uint64_t kvm_encode_reg_size_id(uint64_t id, size_t size_b)
9086
{
9187
uint64_t size_ctz = __builtin_ctz(size_b);
@@ -119,12 +115,12 @@ static uint64_t kvm_riscv_vector_reg_id(RISCVCPU *cpu,
119115
kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CONFIG, \
120116
KVM_REG_RISCV_CONFIG_REG(name))
121117

122-
#define RISCV_TIMER_REG(name) kvm_riscv_reg_id_u64(KVM_REG_RISCV_TIMER, \
118+
#define RISCV_TIMER_REG(name) KVM_RISCV_REG_ID_U64(KVM_REG_RISCV_TIMER, \
123119
KVM_REG_RISCV_TIMER_REG(name))
124120

125-
#define RISCV_FP_F_REG(idx) kvm_riscv_reg_id_u32(KVM_REG_RISCV_FP_F, idx)
121+
#define RISCV_FP_F_REG(idx) KVM_RISCV_REG_ID_U32(KVM_REG_RISCV_FP_F, idx)
126122

127-
#define RISCV_FP_D_REG(idx) kvm_riscv_reg_id_u64(KVM_REG_RISCV_FP_D, idx)
123+
#define RISCV_FP_D_REG(idx) KVM_RISCV_REG_ID_U64(KVM_REG_RISCV_FP_D, idx)
128124

129125
#define RISCV_VECTOR_CSR_REG(env, name) \
130126
kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_VECTOR, \

0 commit comments

Comments
 (0)