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
{
23 bool is_32bit
; /* Only valid if is_aarch32 is true */
27 /* Sysreg string for debug */
30 /* MRS/MSR instruction which accesses it. */
37 /* Trapped access from guest, if non-NULL. */
38 bool (*access
)(struct kvm_vcpu
*,
39 struct sys_reg_params
*,
40 const struct sys_reg_desc
*);
42 /* Initialization for vcpu. */
43 void (*reset
)(struct kvm_vcpu
*, const struct sys_reg_desc
*);
45 /* Index into sys_reg[], or 0 if we don't need to save it. */
48 /* Value (usually reset value) */
51 /* Custom get/set_user functions, fallback to generic if NULL */
52 int (*get_user
)(struct kvm_vcpu
*vcpu
, const struct sys_reg_desc
*rd
,
53 const struct kvm_one_reg
*reg
, void __user
*uaddr
);
54 int (*set_user
)(struct kvm_vcpu
*vcpu
, const struct sys_reg_desc
*rd
,
55 const struct kvm_one_reg
*reg
, void __user
*uaddr
);
57 /* Return mask of REG_* runtime visibility overrides */
58 unsigned int (*visibility
)(const struct kvm_vcpu
*vcpu
,
59 const struct sys_reg_desc
*rd
);
62 #define REG_HIDDEN_USER (1 << 0) /* hidden from userspace ioctls */
63 #define REG_HIDDEN_GUEST (1 << 1) /* hidden from guest */
66 inline void print_sys_reg_msg(const struct sys_reg_params
*p
,
72 /* Look, we even formatted it for you to paste into the table! */
73 kvm_pr_unimpl("%pV { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
74 &(struct va_format
){ fmt
, &va
},
75 p
->Op0
, p
->Op1
, p
->CRn
, p
->CRm
, p
->Op2
, p
->is_write
? "write" : "read");
79 static inline void print_sys_reg_instr(const struct sys_reg_params
*p
)
81 /* GCC warns on an empty format string */
82 print_sys_reg_msg(p
, "%s", "");
85 static inline bool ignore_write(struct kvm_vcpu
*vcpu
,
86 const struct sys_reg_params
*p
)
91 static inline bool read_zero(struct kvm_vcpu
*vcpu
,
92 struct sys_reg_params
*p
)
99 static inline void reset_unknown(struct kvm_vcpu
*vcpu
,
100 const struct sys_reg_desc
*r
)
103 BUG_ON(r
->reg
>= NR_SYS_REGS
);
104 __vcpu_sys_reg(vcpu
, r
->reg
) = 0x1de7ec7edbadc0deULL
;
107 static inline void reset_val(struct kvm_vcpu
*vcpu
, const struct sys_reg_desc
*r
)
110 BUG_ON(r
->reg
>= NR_SYS_REGS
);
111 __vcpu_sys_reg(vcpu
, r
->reg
) = r
->val
;
114 static inline bool sysreg_hidden_from_guest(const struct kvm_vcpu
*vcpu
,
115 const struct sys_reg_desc
*r
)
117 if (likely(!r
->visibility
))
120 return r
->visibility(vcpu
, r
) & REG_HIDDEN_GUEST
;
123 static inline bool sysreg_hidden_from_user(const struct kvm_vcpu
*vcpu
,
124 const struct sys_reg_desc
*r
)
126 if (likely(!r
->visibility
))
129 return r
->visibility(vcpu
, r
) & REG_HIDDEN_USER
;
132 static inline int cmp_sys_reg(const struct sys_reg_desc
*i1
,
133 const struct sys_reg_desc
*i2
)
140 if (i1
->Op0
!= i2
->Op0
)
141 return i1
->Op0
- i2
->Op0
;
142 if (i1
->Op1
!= i2
->Op1
)
143 return i1
->Op1
- i2
->Op1
;
144 if (i1
->CRn
!= i2
->CRn
)
145 return i1
->CRn
- i2
->CRn
;
146 if (i1
->CRm
!= i2
->CRm
)
147 return i1
->CRm
- i2
->CRm
;
148 return i1
->Op2
- i2
->Op2
;
151 const struct sys_reg_desc
*find_reg_by_id(u64 id
,
152 struct sys_reg_params
*params
,
153 const struct sys_reg_desc table
[],
156 #define Op0(_x) .Op0 = _x
157 #define Op1(_x) .Op1 = _x
158 #define CRn(_x) .CRn = _x
159 #define CRm(_x) .CRm = _x
160 #define Op2(_x) .Op2 = _x
162 #define SYS_DESC(reg) \
164 Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
165 CRn(sys_reg_CRn(reg)), CRm(sys_reg_CRm(reg)), \
166 Op2(sys_reg_Op2(reg))
168 #endif /* __ARM64_KVM_SYS_REGS_LOCAL_H__ */