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 */
65 static inline void print_sys_reg_instr(const struct sys_reg_params
*p
)
67 /* Look, we even formatted it for you to paste into the table! */
68 kvm_pr_unimpl(" { Op0(%2u), Op1(%2u), CRn(%2u), CRm(%2u), Op2(%2u), func_%s },\n",
69 p
->Op0
, p
->Op1
, p
->CRn
, p
->CRm
, p
->Op2
, p
->is_write
? "write" : "read");
72 static inline bool ignore_write(struct kvm_vcpu
*vcpu
,
73 const struct sys_reg_params
*p
)
78 static inline bool read_zero(struct kvm_vcpu
*vcpu
,
79 struct sys_reg_params
*p
)
86 static inline void reset_unknown(struct kvm_vcpu
*vcpu
,
87 const struct sys_reg_desc
*r
)
90 BUG_ON(r
->reg
>= NR_SYS_REGS
);
91 __vcpu_sys_reg(vcpu
, r
->reg
) = 0x1de7ec7edbadc0deULL
;
94 static inline void reset_val(struct kvm_vcpu
*vcpu
, const struct sys_reg_desc
*r
)
97 BUG_ON(r
->reg
>= NR_SYS_REGS
);
98 __vcpu_sys_reg(vcpu
, r
->reg
) = r
->val
;
101 static inline bool sysreg_hidden_from_guest(const struct kvm_vcpu
*vcpu
,
102 const struct sys_reg_desc
*r
)
104 if (likely(!r
->visibility
))
107 return r
->visibility(vcpu
, r
) & REG_HIDDEN_GUEST
;
110 static inline bool sysreg_hidden_from_user(const struct kvm_vcpu
*vcpu
,
111 const struct sys_reg_desc
*r
)
113 if (likely(!r
->visibility
))
116 return r
->visibility(vcpu
, r
) & REG_HIDDEN_USER
;
119 static inline int cmp_sys_reg(const struct sys_reg_desc
*i1
,
120 const struct sys_reg_desc
*i2
)
127 if (i1
->Op0
!= i2
->Op0
)
128 return i1
->Op0
- i2
->Op0
;
129 if (i1
->Op1
!= i2
->Op1
)
130 return i1
->Op1
- i2
->Op1
;
131 if (i1
->CRn
!= i2
->CRn
)
132 return i1
->CRn
- i2
->CRn
;
133 if (i1
->CRm
!= i2
->CRm
)
134 return i1
->CRm
- i2
->CRm
;
135 return i1
->Op2
- i2
->Op2
;
138 const struct sys_reg_desc
*find_reg_by_id(u64 id
,
139 struct sys_reg_params
*params
,
140 const struct sys_reg_desc table
[],
143 #define Op0(_x) .Op0 = _x
144 #define Op1(_x) .Op1 = _x
145 #define CRn(_x) .CRn = _x
146 #define CRm(_x) .CRm = _x
147 #define Op2(_x) .Op2 = _x
149 #define SYS_DESC(reg) \
151 Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
152 CRn(sys_reg_CRn(reg)), CRm(sys_reg_CRm(reg)), \
153 Op2(sys_reg_Op2(reg))
155 #endif /* __ARM64_KVM_SYS_REGS_LOCAL_H__ */