1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
7 #ifndef __ARM_KVM_COPROC_LOCAL_H__
8 #define __ARM_KVM_COPROC_LOCAL_H__
10 struct coproc_params {
22 /* MRC/MCR/MRRC/MCRR instruction which accesses it. */
30 /* Trapped access from guest, if non-NULL. */
31 bool (*access)(struct kvm_vcpu *,
32 const struct coproc_params *,
33 const struct coproc_reg *);
35 /* Initialization for vcpu. */
36 void (*reset)(struct kvm_vcpu *, const struct coproc_reg *);
38 /* Index into vcpu_cp15(vcpu, ...), or 0 if we don't need to save it. */
41 /* Value (usually reset value) */
45 static inline void print_cp_instr(const struct coproc_params *p)
47 /* Look, we even formatted it for you to paste into the table! */
49 kvm_pr_unimpl(" { CRm64(%2lu), Op1(%2lu), is64, func_%s },\n",
50 p->CRn, p->Op1, p->is_write ? "write" : "read");
52 kvm_pr_unimpl(" { CRn(%2lu), CRm(%2lu), Op1(%2lu), Op2(%2lu), is32,"
54 p->CRn, p->CRm, p->Op1, p->Op2,
55 p->is_write ? "write" : "read");
59 static inline bool ignore_write(struct kvm_vcpu *vcpu,
60 const struct coproc_params *p)
65 static inline bool read_zero(struct kvm_vcpu *vcpu,
66 const struct coproc_params *p)
68 *vcpu_reg(vcpu, p->Rt1) = 0;
73 static inline void reset_unknown(struct kvm_vcpu *vcpu,
74 const struct coproc_reg *r)
77 BUG_ON(r->reg >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
78 vcpu_cp15(vcpu, r->reg) = 0xdecafbad;
81 static inline void reset_val(struct kvm_vcpu *vcpu, const struct coproc_reg *r)
84 BUG_ON(r->reg >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
85 vcpu_cp15(vcpu, r->reg) = r->val;
88 static inline void reset_unknown64(struct kvm_vcpu *vcpu,
89 const struct coproc_reg *r)
92 BUG_ON(r->reg + 1 >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
94 vcpu_cp15(vcpu, r->reg) = 0xdecafbad;
95 vcpu_cp15(vcpu, r->reg+1) = 0xd0c0ffee;
98 static inline int cmp_reg(const struct coproc_reg *i1,
99 const struct coproc_reg *i2)
106 if (i1->CRn != i2->CRn)
107 return i1->CRn - i2->CRn;
108 if (i1->CRm != i2->CRm)
109 return i1->CRm - i2->CRm;
110 if (i1->Op1 != i2->Op1)
111 return i1->Op1 - i2->Op1;
112 if (i1->Op2 != i2->Op2)
113 return i1->Op2 - i2->Op2;
114 return i2->is_64bit - i1->is_64bit;
118 #define CRn(_x) .CRn = _x
119 #define CRm(_x) .CRm = _x
120 #define CRm64(_x) .CRn = _x, .CRm = 0
121 #define Op1(_x) .Op1 = _x
122 #define Op2(_x) .Op2 = _x
123 #define is64 .is_64bit = true
124 #define is32 .is_64bit = false
126 bool access_vm_reg(struct kvm_vcpu *vcpu,
127 const struct coproc_params *p,
128 const struct coproc_reg *r);
130 #endif /* __ARM_KVM_COPROC_LOCAL_H__ */