]>
Commit | Line | Data |
---|---|---|
c7ce6c63 MZ |
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 | ||
f1c9cad7 | 21 | #include <asm/kvm_hyp.h> |
c7ce6c63 MZ |
22 | |
23 | static u64 *cp15_64(struct kvm_cpu_context *ctxt, int idx) | |
24 | { | |
25 | return (u64 *)(ctxt->cp15 + idx); | |
26 | } | |
27 | ||
28 | void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt) | |
29 | { | |
c7ce6c63 MZ |
30 | ctxt->cp15[c0_CSSELR] = read_sysreg(CSSELR); |
31 | ctxt->cp15[c1_SCTLR] = read_sysreg(SCTLR); | |
32 | ctxt->cp15[c1_CPACR] = read_sysreg(CPACR); | |
33 | *cp15_64(ctxt, c2_TTBR0) = read_sysreg(TTBR0); | |
34 | *cp15_64(ctxt, c2_TTBR1) = read_sysreg(TTBR1); | |
35 | ctxt->cp15[c2_TTBCR] = read_sysreg(TTBCR); | |
36 | ctxt->cp15[c3_DACR] = read_sysreg(DACR); | |
37 | ctxt->cp15[c5_DFSR] = read_sysreg(DFSR); | |
38 | ctxt->cp15[c5_IFSR] = read_sysreg(IFSR); | |
39 | ctxt->cp15[c5_ADFSR] = read_sysreg(ADFSR); | |
40 | ctxt->cp15[c5_AIFSR] = read_sysreg(AIFSR); | |
41 | ctxt->cp15[c6_DFAR] = read_sysreg(DFAR); | |
42 | ctxt->cp15[c6_IFAR] = read_sysreg(IFAR); | |
43 | *cp15_64(ctxt, c7_PAR) = read_sysreg(PAR); | |
44 | ctxt->cp15[c10_PRRR] = read_sysreg(PRRR); | |
45 | ctxt->cp15[c10_NMRR] = read_sysreg(NMRR); | |
46 | ctxt->cp15[c10_AMAIR0] = read_sysreg(AMAIR0); | |
47 | ctxt->cp15[c10_AMAIR1] = read_sysreg(AMAIR1); | |
48 | ctxt->cp15[c12_VBAR] = read_sysreg(VBAR); | |
49 | ctxt->cp15[c13_CID] = read_sysreg(CID); | |
50 | ctxt->cp15[c13_TID_URW] = read_sysreg(TID_URW); | |
51 | ctxt->cp15[c13_TID_URO] = read_sysreg(TID_URO); | |
52 | ctxt->cp15[c13_TID_PRIV] = read_sysreg(TID_PRIV); | |
53 | ctxt->cp15[c14_CNTKCTL] = read_sysreg(CNTKCTL); | |
54 | } | |
55 | ||
56 | void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt) | |
57 | { | |
58 | write_sysreg(ctxt->cp15[c0_MPIDR], VMPIDR); | |
59 | write_sysreg(ctxt->cp15[c0_CSSELR], CSSELR); | |
60 | write_sysreg(ctxt->cp15[c1_SCTLR], SCTLR); | |
61 | write_sysreg(ctxt->cp15[c1_CPACR], CPACR); | |
62 | write_sysreg(*cp15_64(ctxt, c2_TTBR0), TTBR0); | |
63 | write_sysreg(*cp15_64(ctxt, c2_TTBR1), TTBR1); | |
64 | write_sysreg(ctxt->cp15[c2_TTBCR], TTBCR); | |
65 | write_sysreg(ctxt->cp15[c3_DACR], DACR); | |
66 | write_sysreg(ctxt->cp15[c5_DFSR], DFSR); | |
67 | write_sysreg(ctxt->cp15[c5_IFSR], IFSR); | |
68 | write_sysreg(ctxt->cp15[c5_ADFSR], ADFSR); | |
69 | write_sysreg(ctxt->cp15[c5_AIFSR], AIFSR); | |
70 | write_sysreg(ctxt->cp15[c6_DFAR], DFAR); | |
71 | write_sysreg(ctxt->cp15[c6_IFAR], IFAR); | |
72 | write_sysreg(*cp15_64(ctxt, c7_PAR), PAR); | |
73 | write_sysreg(ctxt->cp15[c10_PRRR], PRRR); | |
74 | write_sysreg(ctxt->cp15[c10_NMRR], NMRR); | |
75 | write_sysreg(ctxt->cp15[c10_AMAIR0], AMAIR0); | |
76 | write_sysreg(ctxt->cp15[c10_AMAIR1], AMAIR1); | |
77 | write_sysreg(ctxt->cp15[c12_VBAR], VBAR); | |
78 | write_sysreg(ctxt->cp15[c13_CID], CID); | |
79 | write_sysreg(ctxt->cp15[c13_TID_URW], TID_URW); | |
80 | write_sysreg(ctxt->cp15[c13_TID_URO], TID_URO); | |
81 | write_sysreg(ctxt->cp15[c13_TID_PRIV], TID_PRIV); | |
82 | write_sysreg(ctxt->cp15[c14_CNTKCTL], CNTKCTL); | |
83 | } |