1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012,2013 - ARM Ltd
4 * Author: Marc Zyngier <marc.zyngier@arm.com>
6 * Derived from arch/arm/kvm/coproc.h
7 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
8 * Authors: Christoffer Dall <c.dall@virtualopensystems.com>
11 #ifndef __ARM64_KVM_SYS_REGS_LOCAL_H__
12 #define __ARM64_KVM_SYS_REGS_LOCAL_H__
14 struct sys_reg_params {
25 /* Sysreg string for debug */
34 /* MRS/MSR instruction which accesses it. */
41 /* Trapped access from guest, if non-NULL. */
42 bool (*access)(struct kvm_vcpu *,
43 struct sys_reg_params *,
44 const struct sys_reg_desc *);
46 /* Initialization for vcpu. */
47 void (*reset)(struct kvm_vcpu *, const struct sys_reg_desc *);
49 /* Index into sys_reg[], or 0 if we don't need to save it. */
52 /* Value (usually reset value) */
55 /* Custom get/set_user functions, fallback to generic if NULL */
56 int (*get_user)(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
57 const struct kvm_one_reg *reg, void __user *uaddr);
58 int (*set_user)(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
59 const struct kvm_one_reg *reg, void __user *uaddr);
61 /* Return mask of REG_* runtime visibility overrides */
62 unsigned int (*visibility)(const struct kvm_vcpu *vcpu,
63 const struct sys_reg_desc *rd);
66 #define REG_HIDDEN (1 << 0) /* hidden from userspace and guest */
67 #define REG_RAZ (1 << 1) /* RAZ from userspace and guest */
70 inline void print_sys_reg_msg(const struct sys_reg_params *p,
76 /* Look, we even formatted it for you to paste into the table! */
77 kvm_pr_unimpl("%pV { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
78 &(struct va_format){ fmt, &va },
79 p->Op0, p->Op1, p->CRn, p->CRm, p->Op2, p->is_write ? "write" : "read");
83 static inline void print_sys_reg_instr(const struct sys_reg_params *p)
85 /* GCC warns on an empty format string */
86 print_sys_reg_msg(p, "%s", "");
89 static inline bool ignore_write(struct kvm_vcpu *vcpu,
90 const struct sys_reg_params *p)
95 static inline bool read_zero(struct kvm_vcpu *vcpu,
96 struct sys_reg_params *p)
102 /* Reset functions */
103 static inline void reset_unknown(struct kvm_vcpu *vcpu,
104 const struct sys_reg_desc *r)
107 BUG_ON(r->reg >= NR_SYS_REGS);
108 __vcpu_sys_reg(vcpu, r->reg) = 0x1de7ec7edbadc0deULL;
111 static inline void reset_val(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
114 BUG_ON(r->reg >= NR_SYS_REGS);
115 __vcpu_sys_reg(vcpu, r->reg) = r->val;
118 static inline bool sysreg_hidden(const struct kvm_vcpu *vcpu,
119 const struct sys_reg_desc *r)
121 if (likely(!r->visibility))
124 return r->visibility(vcpu, r) & REG_HIDDEN;
127 static inline bool sysreg_visible_as_raz(const struct kvm_vcpu *vcpu,
128 const struct sys_reg_desc *r)
130 if (likely(!r->visibility))
133 return r->visibility(vcpu, r) & REG_RAZ;
136 static inline int cmp_sys_reg(const struct sys_reg_desc *i1,
137 const struct sys_reg_desc *i2)
144 if (i1->Op0 != i2->Op0)
145 return i1->Op0 - i2->Op0;
146 if (i1->Op1 != i2->Op1)
147 return i1->Op1 - i2->Op1;
148 if (i1->CRn != i2->CRn)
149 return i1->CRn - i2->CRn;
150 if (i1->CRm != i2->CRm)
151 return i1->CRm - i2->CRm;
152 return i1->Op2 - i2->Op2;
155 const struct sys_reg_desc *find_reg_by_id(u64 id,
156 struct sys_reg_params *params,
157 const struct sys_reg_desc table[],
160 #define AA32(_x) .aarch32_map = AA32_##_x
161 #define Op0(_x) .Op0 = _x
162 #define Op1(_x) .Op1 = _x
163 #define CRn(_x) .CRn = _x
164 #define CRm(_x) .CRm = _x
165 #define Op2(_x) .Op2 = _x
167 #define SYS_DESC(reg) \
169 Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
170 CRn(sys_reg_CRn(reg)), CRm(sys_reg_CRm(reg)), \
171 Op2(sys_reg_Op2(reg))
173 #endif /* __ARM64_KVM_SYS_REGS_LOCAL_H__ */