• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Original code:
3  * Copyright (C) 2012 - Virtual Open Systems and Columbia University
4  * Author: Christoffer Dall <c.dall@virtualopensystems.com>
5  *
6  * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <asm/kvm_hyp.h>
22 
cp15_64(struct kvm_cpu_context * ctxt,int idx)23 static u64 *cp15_64(struct kvm_cpu_context *ctxt, int idx)
24 {
25 	return (u64 *)(ctxt->cp15 + idx);
26 }
27 
__sysreg_save_state(struct kvm_cpu_context * ctxt)28 void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
29 {
30 	ctxt->cp15[c0_MPIDR]		= read_sysreg(VMPIDR);
31 	ctxt->cp15[c0_CSSELR]		= read_sysreg(CSSELR);
32 	ctxt->cp15[c1_SCTLR]		= read_sysreg(SCTLR);
33 	ctxt->cp15[c1_CPACR]		= read_sysreg(CPACR);
34 	*cp15_64(ctxt, c2_TTBR0)	= read_sysreg(TTBR0);
35 	*cp15_64(ctxt, c2_TTBR1)	= read_sysreg(TTBR1);
36 	ctxt->cp15[c2_TTBCR]		= read_sysreg(TTBCR);
37 	ctxt->cp15[c3_DACR]		= read_sysreg(DACR);
38 	ctxt->cp15[c5_DFSR]		= read_sysreg(DFSR);
39 	ctxt->cp15[c5_IFSR]		= read_sysreg(IFSR);
40 	ctxt->cp15[c5_ADFSR]		= read_sysreg(ADFSR);
41 	ctxt->cp15[c5_AIFSR]		= read_sysreg(AIFSR);
42 	ctxt->cp15[c6_DFAR]		= read_sysreg(DFAR);
43 	ctxt->cp15[c6_IFAR]		= read_sysreg(IFAR);
44 	*cp15_64(ctxt, c7_PAR)		= read_sysreg(PAR);
45 	ctxt->cp15[c10_PRRR]		= read_sysreg(PRRR);
46 	ctxt->cp15[c10_NMRR]		= read_sysreg(NMRR);
47 	ctxt->cp15[c10_AMAIR0]		= read_sysreg(AMAIR0);
48 	ctxt->cp15[c10_AMAIR1]		= read_sysreg(AMAIR1);
49 	ctxt->cp15[c12_VBAR]		= read_sysreg(VBAR);
50 	ctxt->cp15[c13_CID]		= read_sysreg(CID);
51 	ctxt->cp15[c13_TID_URW]		= read_sysreg(TID_URW);
52 	ctxt->cp15[c13_TID_URO]		= read_sysreg(TID_URO);
53 	ctxt->cp15[c13_TID_PRIV]	= read_sysreg(TID_PRIV);
54 	ctxt->cp15[c14_CNTKCTL]		= read_sysreg(CNTKCTL);
55 }
56 
__sysreg_restore_state(struct kvm_cpu_context * ctxt)57 void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
58 {
59 	write_sysreg(ctxt->cp15[c0_MPIDR],	VMPIDR);
60 	write_sysreg(ctxt->cp15[c0_CSSELR],	CSSELR);
61 	write_sysreg(ctxt->cp15[c1_SCTLR],	SCTLR);
62 	write_sysreg(ctxt->cp15[c1_CPACR],	CPACR);
63 	write_sysreg(*cp15_64(ctxt, c2_TTBR0),	TTBR0);
64 	write_sysreg(*cp15_64(ctxt, c2_TTBR1),	TTBR1);
65 	write_sysreg(ctxt->cp15[c2_TTBCR],	TTBCR);
66 	write_sysreg(ctxt->cp15[c3_DACR],	DACR);
67 	write_sysreg(ctxt->cp15[c5_DFSR],	DFSR);
68 	write_sysreg(ctxt->cp15[c5_IFSR],	IFSR);
69 	write_sysreg(ctxt->cp15[c5_ADFSR],	ADFSR);
70 	write_sysreg(ctxt->cp15[c5_AIFSR],	AIFSR);
71 	write_sysreg(ctxt->cp15[c6_DFAR],	DFAR);
72 	write_sysreg(ctxt->cp15[c6_IFAR],	IFAR);
73 	write_sysreg(*cp15_64(ctxt, c7_PAR),	PAR);
74 	write_sysreg(ctxt->cp15[c10_PRRR],	PRRR);
75 	write_sysreg(ctxt->cp15[c10_NMRR],	NMRR);
76 	write_sysreg(ctxt->cp15[c10_AMAIR0],	AMAIR0);
77 	write_sysreg(ctxt->cp15[c10_AMAIR1],	AMAIR1);
78 	write_sysreg(ctxt->cp15[c12_VBAR],	VBAR);
79 	write_sysreg(ctxt->cp15[c13_CID],	CID);
80 	write_sysreg(ctxt->cp15[c13_TID_URW],	TID_URW);
81 	write_sysreg(ctxt->cp15[c13_TID_URO],	TID_URO);
82 	write_sysreg(ctxt->cp15[c13_TID_PRIV],	TID_PRIV);
83 	write_sysreg(ctxt->cp15[c14_CNTKCTL],	CNTKCTL);
84 }
85