forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/arch/powerpc/kvm/book3s_hv_interrupts.S
....@@ -1,16 +1,5 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
2
- * This program is free software; you can redistribute it and/or modify
3
- * it under the terms of the GNU General Public License, version 2, as
4
- * published by the Free Software Foundation.
5
- *
6
- * This program is distributed in the hope that it will be useful,
7
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
8
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
- * GNU General Public License for more details.
10
- *
11
- * You should have received a copy of the GNU General Public License
12
- * along with this program; if not, write to the Free Software
13
- * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
143 *
154 * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
165 *
....@@ -64,63 +53,21 @@
6453 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
6554
6655 /* Save host PMU registers */
67
-BEGIN_FTR_SECTION
68
- /* Work around P8 PMAE bug */
69
- li r3, -1
70
- clrrdi r3, r3, 10
71
- mfspr r8, SPRN_MMCR2
72
- mtspr SPRN_MMCR2, r3 /* freeze all counters using MMCR2 */
73
- isync
74
-END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
75
- li r3, 1
76
- sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
77
- mfspr r7, SPRN_MMCR0 /* save MMCR0 */
78
- mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
79
- mfspr r6, SPRN_MMCRA
80
- /* Clear MMCRA in order to disable SDAR updates */
81
- li r5, 0
82
- mtspr SPRN_MMCRA, r5
83
- isync
84
- lbz r5, PACA_PMCINUSE(r13) /* is the host using the PMU? */
85
- cmpwi r5, 0
86
- beq 31f /* skip if not */
87
- mfspr r5, SPRN_MMCR1
88
- mfspr r9, SPRN_SIAR
89
- mfspr r10, SPRN_SDAR
90
- std r7, HSTATE_MMCR0(r13)
91
- std r5, HSTATE_MMCR1(r13)
92
- std r6, HSTATE_MMCRA(r13)
93
- std r9, HSTATE_SIAR(r13)
94
- std r10, HSTATE_SDAR(r13)
95
-BEGIN_FTR_SECTION
96
- mfspr r9, SPRN_SIER
97
- std r8, HSTATE_MMCR2(r13)
98
- std r9, HSTATE_SIER(r13)
99
-END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
100
- mfspr r3, SPRN_PMC1
101
- mfspr r5, SPRN_PMC2
102
- mfspr r6, SPRN_PMC3
103
- mfspr r7, SPRN_PMC4
104
- mfspr r8, SPRN_PMC5
105
- mfspr r9, SPRN_PMC6
106
- stw r3, HSTATE_PMC1(r13)
107
- stw r5, HSTATE_PMC2(r13)
108
- stw r6, HSTATE_PMC3(r13)
109
- stw r7, HSTATE_PMC4(r13)
110
- stw r8, HSTATE_PMC5(r13)
111
- stw r9, HSTATE_PMC6(r13)
112
-31:
56
+ bl kvmhv_save_host_pmu
11357
11458 /*
11559 * Put whatever is in the decrementer into the
11660 * hypervisor decrementer.
61
+ * Because of a hardware deviation in P8 and P9,
62
+ * we need to set LPCR[HDICE] before writing HDEC.
11763 */
118
-BEGIN_FTR_SECTION
11964 ld r5, HSTATE_KVM_VCORE(r13)
12065 ld r6, VCORE_KVM(r5)
12166 ld r9, KVM_HOST_LPCR(r6)
122
- andis. r9, r9, LPCR_LD@h
123
-END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
67
+ ori r8, r9, LPCR_HDICE
68
+ mtspr SPRN_LPCR, r8
69
+ isync
70
+ andis. r0, r9, LPCR_LD@h
12471 mfspr r8,SPRN_DEC
12572 mftb r7
12673 BEGIN_FTR_SECTION
....@@ -161,3 +108,59 @@
161108 ld r0, PPC_LR_STKOFF(r1)
162109 mtlr r0
163110 blr
111
+
112
+_GLOBAL(kvmhv_save_host_pmu)
113
+BEGIN_FTR_SECTION
114
+ /* Work around P8 PMAE bug */
115
+ li r3, -1
116
+ clrrdi r3, r3, 10
117
+ mfspr r8, SPRN_MMCR2
118
+ mtspr SPRN_MMCR2, r3 /* freeze all counters using MMCR2 */
119
+ isync
120
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
121
+ li r3, 1
122
+ sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
123
+ mfspr r7, SPRN_MMCR0 /* save MMCR0 */
124
+ mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
125
+ mfspr r6, SPRN_MMCRA
126
+ /* Clear MMCRA in order to disable SDAR updates */
127
+ li r5, 0
128
+ mtspr SPRN_MMCRA, r5
129
+ isync
130
+ lbz r5, PACA_PMCINUSE(r13) /* is the host using the PMU? */
131
+ cmpwi r5, 0
132
+ beq 31f /* skip if not */
133
+ mfspr r5, SPRN_MMCR1
134
+ mfspr r9, SPRN_SIAR
135
+ mfspr r10, SPRN_SDAR
136
+ std r7, HSTATE_MMCR0(r13)
137
+ std r5, HSTATE_MMCR1(r13)
138
+ std r6, HSTATE_MMCRA(r13)
139
+ std r9, HSTATE_SIAR(r13)
140
+ std r10, HSTATE_SDAR(r13)
141
+BEGIN_FTR_SECTION
142
+ mfspr r9, SPRN_SIER
143
+ std r8, HSTATE_MMCR2(r13)
144
+ std r9, HSTATE_SIER(r13)
145
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
146
+BEGIN_FTR_SECTION
147
+ mfspr r5, SPRN_MMCR3
148
+ mfspr r6, SPRN_SIER2
149
+ mfspr r7, SPRN_SIER3
150
+ std r5, HSTATE_MMCR3(r13)
151
+ std r6, HSTATE_SIER2(r13)
152
+ std r7, HSTATE_SIER3(r13)
153
+END_FTR_SECTION_IFSET(CPU_FTR_ARCH_31)
154
+ mfspr r3, SPRN_PMC1
155
+ mfspr r5, SPRN_PMC2
156
+ mfspr r6, SPRN_PMC3
157
+ mfspr r7, SPRN_PMC4
158
+ mfspr r8, SPRN_PMC5
159
+ mfspr r9, SPRN_PMC6
160
+ stw r3, HSTATE_PMC1(r13)
161
+ stw r5, HSTATE_PMC2(r13)
162
+ stw r6, HSTATE_PMC3(r13)
163
+ stw r7, HSTATE_PMC4(r13)
164
+ stw r8, HSTATE_PMC5(r13)
165
+ stw r9, HSTATE_PMC6(r13)
166
+31: blr