Linux Audio

Check our new training course

Loading...
v5.4
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  4 * Authors: Christoffer Dall <c.dall@virtualopensystems.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
  5 */
  6
  7#ifndef __ARM_KVM_COPROC_LOCAL_H__
  8#define __ARM_KVM_COPROC_LOCAL_H__
  9
 10struct coproc_params {
 11	unsigned long CRn;
 12	unsigned long CRm;
 13	unsigned long Op1;
 14	unsigned long Op2;
 15	unsigned long Rt1;
 16	unsigned long Rt2;
 17	bool is_64bit;
 18	bool is_write;
 19};
 20
 21struct coproc_reg {
 22	/* MRC/MCR/MRRC/MCRR instruction which accesses it. */
 23	unsigned long CRn;
 24	unsigned long CRm;
 25	unsigned long Op1;
 26	unsigned long Op2;
 27
 28	bool is_64bit;
 29
 30	/* Trapped access from guest, if non-NULL. */
 31	bool (*access)(struct kvm_vcpu *,
 32		       const struct coproc_params *,
 33		       const struct coproc_reg *);
 34
 35	/* Initialization for vcpu. */
 36	void (*reset)(struct kvm_vcpu *, const struct coproc_reg *);
 37
 38	/* Index into vcpu_cp15(vcpu, ...), or 0 if we don't need to save it. */
 39	unsigned long reg;
 40
 41	/* Value (usually reset value) */
 42	u64 val;
 43};
 44
 45static inline void print_cp_instr(const struct coproc_params *p)
 46{
 47	/* Look, we even formatted it for you to paste into the table! */
 48	if (p->is_64bit) {
 49		kvm_pr_unimpl(" { CRm64(%2lu), Op1(%2lu), is64, func_%s },\n",
 50			      p->CRn, p->Op1, p->is_write ? "write" : "read");
 51	} else {
 52		kvm_pr_unimpl(" { CRn(%2lu), CRm(%2lu), Op1(%2lu), Op2(%2lu), is32,"
 53			      " func_%s },\n",
 54			      p->CRn, p->CRm, p->Op1, p->Op2,
 55			      p->is_write ? "write" : "read");
 56	}
 57}
 58
 59static inline bool ignore_write(struct kvm_vcpu *vcpu,
 60				const struct coproc_params *p)
 61{
 62	return true;
 63}
 64
 65static inline bool read_zero(struct kvm_vcpu *vcpu,
 66			     const struct coproc_params *p)
 67{
 68	*vcpu_reg(vcpu, p->Rt1) = 0;
 69	return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 70}
 71
 72/* Reset functions */
 73static inline void reset_unknown(struct kvm_vcpu *vcpu,
 74				 const struct coproc_reg *r)
 75{
 76	BUG_ON(!r->reg);
 77	BUG_ON(r->reg >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
 78	vcpu_cp15(vcpu, r->reg) = 0xdecafbad;
 79}
 80
 81static inline void reset_val(struct kvm_vcpu *vcpu, const struct coproc_reg *r)
 82{
 83	BUG_ON(!r->reg);
 84	BUG_ON(r->reg >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
 85	vcpu_cp15(vcpu, r->reg) = r->val;
 86}
 87
 88static inline void reset_unknown64(struct kvm_vcpu *vcpu,
 89				   const struct coproc_reg *r)
 90{
 91	BUG_ON(!r->reg);
 92	BUG_ON(r->reg + 1 >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
 93
 94	vcpu_cp15(vcpu, r->reg) = 0xdecafbad;
 95	vcpu_cp15(vcpu, r->reg+1) = 0xd0c0ffee;
 96}
 97
 98static inline int cmp_reg(const struct coproc_reg *i1,
 99			  const struct coproc_reg *i2)
100{
101	BUG_ON(i1 == i2);
102	if (!i1)
103		return 1;
104	else if (!i2)
105		return -1;
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;
115}
116
117
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
125
126bool access_vm_reg(struct kvm_vcpu *vcpu,
127		   const struct coproc_params *p,
128		   const struct coproc_reg *r);
129
130#endif /* __ARM_KVM_COPROC_LOCAL_H__ */
v4.6
 
  1/*
  2 * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  3 * Authors: Christoffer Dall <c.dall@virtualopensystems.com>
  4 *
  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.
  8 *
  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.
 13 *
 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.
 17 */
 18
 19#ifndef __ARM_KVM_COPROC_LOCAL_H__
 20#define __ARM_KVM_COPROC_LOCAL_H__
 21
 22struct coproc_params {
 23	unsigned long CRn;
 24	unsigned long CRm;
 25	unsigned long Op1;
 26	unsigned long Op2;
 27	unsigned long Rt1;
 28	unsigned long Rt2;
 29	bool is_64bit;
 30	bool is_write;
 31};
 32
 33struct coproc_reg {
 34	/* MRC/MCR/MRRC/MCRR instruction which accesses it. */
 35	unsigned long CRn;
 36	unsigned long CRm;
 37	unsigned long Op1;
 38	unsigned long Op2;
 39
 40	bool is_64bit;
 41
 42	/* Trapped access from guest, if non-NULL. */
 43	bool (*access)(struct kvm_vcpu *,
 44		       const struct coproc_params *,
 45		       const struct coproc_reg *);
 46
 47	/* Initialization for vcpu. */
 48	void (*reset)(struct kvm_vcpu *, const struct coproc_reg *);
 49
 50	/* Index into vcpu_cp15(vcpu, ...), or 0 if we don't need to save it. */
 51	unsigned long reg;
 52
 53	/* Value (usually reset value) */
 54	u64 val;
 55};
 56
 57static inline void print_cp_instr(const struct coproc_params *p)
 58{
 59	/* Look, we even formatted it for you to paste into the table! */
 60	if (p->is_64bit) {
 61		kvm_pr_unimpl(" { CRm64(%2lu), Op1(%2lu), is64, func_%s },\n",
 62			      p->CRn, p->Op1, p->is_write ? "write" : "read");
 63	} else {
 64		kvm_pr_unimpl(" { CRn(%2lu), CRm(%2lu), Op1(%2lu), Op2(%2lu), is32,"
 65			      " func_%s },\n",
 66			      p->CRn, p->CRm, p->Op1, p->Op2,
 67			      p->is_write ? "write" : "read");
 68	}
 69}
 70
 71static inline bool ignore_write(struct kvm_vcpu *vcpu,
 72				const struct coproc_params *p)
 73{
 74	return true;
 75}
 76
 77static inline bool read_zero(struct kvm_vcpu *vcpu,
 78			     const struct coproc_params *p)
 79{
 80	*vcpu_reg(vcpu, p->Rt1) = 0;
 81	return true;
 82}
 83
 84static inline bool write_to_read_only(struct kvm_vcpu *vcpu,
 85				      const struct coproc_params *params)
 86{
 87	kvm_debug("CP15 write to read-only register at: %08lx\n",
 88		  *vcpu_pc(vcpu));
 89	print_cp_instr(params);
 90	return false;
 91}
 92
 93static inline bool read_from_write_only(struct kvm_vcpu *vcpu,
 94					const struct coproc_params *params)
 95{
 96	kvm_debug("CP15 read to write-only register at: %08lx\n",
 97		  *vcpu_pc(vcpu));
 98	print_cp_instr(params);
 99	return false;
100}
101
102/* Reset functions */
103static inline void reset_unknown(struct kvm_vcpu *vcpu,
104				 const struct coproc_reg *r)
105{
106	BUG_ON(!r->reg);
107	BUG_ON(r->reg >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
108	vcpu_cp15(vcpu, r->reg) = 0xdecafbad;
109}
110
111static inline void reset_val(struct kvm_vcpu *vcpu, const struct coproc_reg *r)
112{
113	BUG_ON(!r->reg);
114	BUG_ON(r->reg >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
115	vcpu_cp15(vcpu, r->reg) = r->val;
116}
117
118static inline void reset_unknown64(struct kvm_vcpu *vcpu,
119				   const struct coproc_reg *r)
120{
121	BUG_ON(!r->reg);
122	BUG_ON(r->reg + 1 >= ARRAY_SIZE(vcpu->arch.ctxt.cp15));
123
124	vcpu_cp15(vcpu, r->reg) = 0xdecafbad;
125	vcpu_cp15(vcpu, r->reg+1) = 0xd0c0ffee;
126}
127
128static inline int cmp_reg(const struct coproc_reg *i1,
129			  const struct coproc_reg *i2)
130{
131	BUG_ON(i1 == i2);
132	if (!i1)
133		return 1;
134	else if (!i2)
135		return -1;
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_64bit - i1->is_64bit;
145}
146
147
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_64bit = true
154#define is32		.is_64bit = false
155
156bool access_vm_reg(struct kvm_vcpu *vcpu,
157		   const struct coproc_params *p,
158		   const struct coproc_reg *r);
159
160#endif /* __ARM_KVM_COPROC_LOCAL_H__ */