2 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
3 * Authors: Christoffer Dall <c.dall@virtualopensystems.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef __ARM_KVM_COPROC_LOCAL_H__
20 #define __ARM_KVM_COPROC_LOCAL_H__
22 struct coproc_params
{
34 /* MRC/MCR/MRRC/MCRR instruction which accesses it. */
42 /* Trapped access from guest, if non-NULL. */
43 bool (*access
)(struct kvm_vcpu
*,
44 const struct coproc_params
*,
45 const struct coproc_reg
*);
47 /* Initialization for vcpu. */
48 void (*reset
)(struct kvm_vcpu
*, const struct coproc_reg
*);
50 /* Index into vcpu->arch.cp15[], or 0 if we don't need to save it. */
53 /* Value (usually reset value) */
57 static inline void print_cp_instr(const struct coproc_params
*p
)
59 /* Look, we even formatted it for you to paste into the table! */
61 kvm_pr_unimpl(" { CRm64(%2lu), Op1(%2lu), is64, func_%s },\n",
62 p
->CRn
, p
->Op1
, p
->is_write
? "write" : "read");
64 kvm_pr_unimpl(" { CRn(%2lu), CRm(%2lu), Op1(%2lu), Op2(%2lu), is32,"
66 p
->CRn
, p
->CRm
, p
->Op1
, p
->Op2
,
67 p
->is_write
? "write" : "read");
71 static inline bool ignore_write(struct kvm_vcpu
*vcpu
,
72 const struct coproc_params
*p
)
77 static inline bool read_zero(struct kvm_vcpu
*vcpu
,
78 const struct coproc_params
*p
)
80 *vcpu_reg(vcpu
, p
->Rt1
) = 0;
84 static inline bool write_to_read_only(struct kvm_vcpu
*vcpu
,
85 const struct coproc_params
*params
)
87 kvm_debug("CP15 write to read-only register at: %08lx\n",
89 print_cp_instr(params
);
93 static inline bool read_from_write_only(struct kvm_vcpu
*vcpu
,
94 const struct coproc_params
*params
)
96 kvm_debug("CP15 read to write-only register at: %08lx\n",
98 print_cp_instr(params
);
102 /* Reset functions */
103 static inline void reset_unknown(struct kvm_vcpu
*vcpu
,
104 const struct coproc_reg
*r
)
107 BUG_ON(r
->reg
>= ARRAY_SIZE(vcpu
->arch
.cp15
));
108 vcpu
->arch
.cp15
[r
->reg
] = 0xdecafbad;
111 static inline void reset_val(struct kvm_vcpu
*vcpu
, const struct coproc_reg
*r
)
114 BUG_ON(r
->reg
>= ARRAY_SIZE(vcpu
->arch
.cp15
));
115 vcpu
->arch
.cp15
[r
->reg
] = r
->val
;
118 static inline void reset_unknown64(struct kvm_vcpu
*vcpu
,
119 const struct coproc_reg
*r
)
122 BUG_ON(r
->reg
+ 1 >= ARRAY_SIZE(vcpu
->arch
.cp15
));
124 vcpu
->arch
.cp15
[r
->reg
] = 0xdecafbad;
125 vcpu
->arch
.cp15
[r
->reg
+1] = 0xd0c0ffee;
128 static inline int cmp_reg(const struct coproc_reg
*i1
,
129 const struct coproc_reg
*i2
)
136 if (i1
->CRn
!= i2
->CRn
)
137 return i1
->CRn
- i2
->CRn
;
138 if (i1
->CRm
!= i2
->CRm
)
139 return i1
->CRm
- i2
->CRm
;
140 if (i1
->Op1
!= i2
->Op1
)
141 return i1
->Op1
- i2
->Op1
;
142 if (i1
->Op2
!= i2
->Op2
)
143 return i1
->Op2
- i2
->Op2
;
144 return i2
->is_64
- i1
->is_64
;
148 #define CRn(_x) .CRn = _x
149 #define CRm(_x) .CRm = _x
150 #define CRm64(_x) .CRn = _x, .CRm = 0
151 #define Op1(_x) .Op1 = _x
152 #define Op2(_x) .Op2 = _x
153 #define is64 .is_64 = true
154 #define is32 .is_64 = false
156 bool access_vm_reg(struct kvm_vcpu
*vcpu
,
157 const struct coproc_params
*p
,
158 const struct coproc_reg
*r
);
160 #endif /* __ARM_KVM_COPROC_LOCAL_H__ */