1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <asm/kvm_hyp.h>
22
23static u64 *cp15_64(struct kvm_cpu_context *ctxt, int idx)
24{
25 return (u64 *)(ctxt->cp15 + idx);
26}
27
28void __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
57void __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