]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
0ebc4cda BH |
2 | /* |
3 | * This file contains the 64-bit "server" PowerPC variant | |
4 | * of the low level exception handling including exception | |
5 | * vectors, exception return, part of the slb and stab | |
6 | * handling and other fixed offset specific things. | |
7 | * | |
8 | * This file is meant to be #included from head_64.S due to | |
25985edc | 9 | * position dependent assembly. |
0ebc4cda BH |
10 | * |
11 | * Most of this originates from head_64.S and thus has the same | |
12 | * copyright history. | |
13 | * | |
14 | */ | |
15 | ||
7230c564 | 16 | #include <asm/hw_irq.h> |
8aa34ab8 | 17 | #include <asm/exception-64s.h> |
46f52210 | 18 | #include <asm/ptrace.h> |
7cba160a | 19 | #include <asm/cpuidle.h> |
da2bc464 | 20 | #include <asm/head-64.h> |
8aa34ab8 | 21 | |
0ebc4cda | 22 | /* |
57f26649 NP |
23 | * There are a few constraints to be concerned with. |
24 | * - Real mode exceptions code/data must be located at their physical location. | |
25 | * - Virtual mode exceptions must be mapped at their 0xc000... location. | |
26 | * - Fixed location code must not call directly beyond the __end_interrupts | |
27 | * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence | |
28 | * must be used. | |
29 | * - LOAD_HANDLER targets must be within first 64K of physical 0 / | |
30 | * virtual 0xc00... | |
31 | * - Conditional branch targets must be within +/-32K of caller. | |
32 | * | |
33 | * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and | |
34 | * therefore don't have to run in physically located code or rfid to | |
35 | * virtual mode kernel code. However on relocatable kernels they do have | |
36 | * to branch to KERNELBASE offset because the rest of the kernel (outside | |
37 | * the exception vectors) may be located elsewhere. | |
38 | * | |
39 | * Virtual exceptions correspond with physical, except their entry points | |
40 | * are offset by 0xc000000000000000 and also tend to get an added 0x4000 | |
41 | * offset applied. Virtual exceptions are enabled with the Alternate | |
42 | * Interrupt Location (AIL) bit set in the LPCR. However this does not | |
43 | * guarantee they will be delivered virtually. Some conditions (see the ISA) | |
44 | * cause exceptions to be delivered in real mode. | |
45 | * | |
46 | * It's impossible to receive interrupts below 0x300 via AIL. | |
47 | * | |
48 | * KVM: None of the virtual exceptions are from the guest. Anything that | |
49 | * escalated to HV=1 from HV=0 is delivered via real mode handlers. | |
50 | * | |
51 | * | |
0ebc4cda BH |
52 | * We layout physical memory as follows: |
53 | * 0x0000 - 0x00ff : Secondary processor spin code | |
57f26649 NP |
54 | * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors |
55 | * 0x1900 - 0x3fff : Real mode trampolines | |
56 | * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors | |
57 | * 0x5900 - 0x6fff : Relon mode trampolines | |
0ebc4cda | 58 | * 0x7000 - 0x7fff : FWNMI data area |
57f26649 NP |
59 | * 0x8000 - .... : Common interrupt handlers, remaining early |
60 | * setup code, rest of kernel. | |
e0319829 NP |
61 | * |
62 | * We could reclaim 0x4000-0x42ff for real mode trampolines if the space | |
63 | * is necessary. Until then it's more consistent to explicitly put VIRT_NONE | |
64 | * vectors there. | |
57f26649 NP |
65 | */ |
66 | OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900) | |
67 | OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x4000) | |
68 | OPEN_FIXED_SECTION(virt_vectors, 0x4000, 0x5900) | |
69 | OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000) | |
70 | #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) | |
71 | /* | |
72 | * Data area reserved for FWNMI option. | |
73 | * This address (0x7000) is fixed by the RPA. | |
74 | * pseries and powernv need to keep the whole page from | |
75 | * 0x7000 to 0x8000 free for use by the firmware | |
0ebc4cda | 76 | */ |
57f26649 NP |
77 | ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000) |
78 | OPEN_TEXT_SECTION(0x8000) | |
79 | #else | |
80 | OPEN_TEXT_SECTION(0x7000) | |
81 | #endif | |
82 | ||
83 | USE_FIXED_SECTION(real_vectors) | |
84 | ||
0ebc4cda BH |
85 | /* |
86 | * This is the start of the interrupt handlers for pSeries | |
87 | * This code runs with relocation off. | |
88 | * Code from here to __end_interrupts gets copied down to real | |
89 | * address 0x100 when we are running a relocatable kernel. | |
90 | * Therefore any relative branches in this section must only | |
91 | * branch to labels in this section. | |
92 | */ | |
0ebc4cda BH |
93 | .globl __start_interrupts |
94 | __start_interrupts: | |
95 | ||
e0319829 | 96 | /* No virt vectors corresponding with 0x0..0x100 */ |
1a6822d1 | 97 | EXC_VIRT_NONE(0x4000, 0x100) |
e0319829 | 98 | |
fb479e44 | 99 | |
948cf67c | 100 | #ifdef CONFIG_PPC_P7_NAP |
fb479e44 NP |
101 | /* |
102 | * If running native on arch 2.06 or later, check if we are waking up | |
ba6d334a BH |
103 | * from nap/sleep/winkle, and branch to idle handler. This tests SRR1 |
104 | * bits 46:47. A non-0 value indicates that we are coming from a power | |
105 | * saving state. The idle wakeup handler initially runs in real mode, | |
106 | * but we branch to the 0xc000... address so we can turn on relocation | |
107 | * with mtmsr. | |
948cf67c | 108 | */ |
fb479e44 NP |
109 | #define IDLETEST(n) \ |
110 | BEGIN_FTR_SECTION ; \ | |
111 | mfspr r10,SPRN_SRR1 ; \ | |
112 | rlwinm. r10,r10,47-31,30,31 ; \ | |
113 | beq- 1f ; \ | |
114 | cmpwi cr3,r10,2 ; \ | |
b51351e2 | 115 | BRANCH_TO_C000(r10, system_reset_idle_common) ; \ |
fb479e44 | 116 | 1: \ |
6de6638b | 117 | KVMTEST_PR(n) ; \ |
fb479e44 NP |
118 | END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) |
119 | #else | |
120 | #define IDLETEST NOTEST | |
121 | #endif | |
371fefd6 | 122 | |
1a6822d1 | 123 | EXC_REAL_BEGIN(system_reset, 0x100, 0x100) |
fb479e44 | 124 | SET_SCRATCH0(r13) |
c4f3b52c NP |
125 | /* |
126 | * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is | |
127 | * being used, so a nested NMI exception would corrupt it. | |
128 | */ | |
129 | EXCEPTION_PROLOG_PSERIES_NORI(PACA_EXNMI, system_reset_common, EXC_STD, | |
fb479e44 NP |
130 | IDLETEST, 0x100) |
131 | ||
1a6822d1 NP |
132 | EXC_REAL_END(system_reset, 0x100, 0x100) |
133 | EXC_VIRT_NONE(0x4100, 0x100) | |
6de6638b | 134 | TRAMP_KVM(PACA_EXNMI, 0x100) |
fb479e44 NP |
135 | |
136 | #ifdef CONFIG_PPC_P7_NAP | |
137 | EXC_COMMON_BEGIN(system_reset_idle_common) | |
9d292501 | 138 | mfspr r12,SPRN_SRR1 |
bf0153c1 | 139 | b pnv_powersave_wakeup |
371fefd6 PM |
140 | #endif |
141 | ||
0e789d96 NP |
142 | /* |
143 | * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does | |
144 | * the right thing. We do not want to reconcile because that goes | |
145 | * through irq tracing which we don't want in NMI. | |
146 | * | |
147 | * Save PACAIRQHAPPENED because some code will do a hard disable | |
148 | * (e.g., xmon). So we want to restore this back to where it was | |
149 | * when we return. DAR is unused in the stack, so save it there. | |
150 | */ | |
151 | #define ADD_RECONCILE_NMI \ | |
152 | li r10,IRQS_ALL_DISABLED; \ | |
153 | stb r10,PACAIRQSOFTMASK(r13); \ | |
154 | lbz r10,PACAIRQHAPPENED(r13); \ | |
155 | std r10,_DAR(r1) | |
156 | ||
a3d96f70 | 157 | EXC_COMMON_BEGIN(system_reset_common) |
c4f3b52c NP |
158 | /* |
159 | * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able | |
160 | * to recover, but nested NMI will notice in_nmi and not recover | |
161 | * because of the use of the NMI stack. in_nmi reentrancy is tested in | |
162 | * system_reset_exception. | |
163 | */ | |
164 | lhz r10,PACA_IN_NMI(r13) | |
165 | addi r10,r10,1 | |
166 | sth r10,PACA_IN_NMI(r13) | |
167 | li r10,MSR_RI | |
168 | mtmsrd r10,1 | |
aca79d2b | 169 | |
b1ee8a3d NP |
170 | mr r10,r1 |
171 | ld r1,PACA_NMI_EMERG_SP(r13) | |
172 | subi r1,r1,INT_FRAME_SIZE | |
173 | EXCEPTION_COMMON_NORET_STACK(PACA_EXNMI, 0x100, | |
174 | system_reset, system_reset_exception, | |
0e789d96 NP |
175 | ADD_NVGPRS;ADD_RECONCILE_NMI) |
176 | ||
177 | /* This (and MCE) can be simplified with mtmsrd L=1 */ | |
178 | /* Clear MSR_RI before setting SRR0 and SRR1. */ | |
179 | li r0,MSR_RI | |
180 | mfmsr r9 | |
181 | andc r9,r9,r0 | |
182 | mtmsrd r9,1 | |
c4f3b52c NP |
183 | |
184 | /* | |
0e789d96 | 185 | * MSR_RI is clear, now we can decrement paca->in_nmi. |
c4f3b52c NP |
186 | */ |
187 | lhz r10,PACA_IN_NMI(r13) | |
188 | subi r10,r10,1 | |
189 | sth r10,PACA_IN_NMI(r13) | |
190 | ||
0e789d96 NP |
191 | /* |
192 | * Restore soft mask settings. | |
193 | */ | |
194 | ld r10,_DAR(r1) | |
195 | stb r10,PACAIRQHAPPENED(r13) | |
196 | ld r10,SOFTE(r1) | |
197 | stb r10,PACAIRQSOFTMASK(r13) | |
198 | ||
199 | /* | |
200 | * Keep below code in synch with MACHINE_CHECK_HANDLER_WINDUP. | |
201 | * Should share common bits... | |
202 | */ | |
203 | ||
204 | /* Move original SRR0 and SRR1 into the respective regs */ | |
205 | ld r9,_MSR(r1) | |
206 | mtspr SPRN_SRR1,r9 | |
207 | ld r3,_NIP(r1) | |
208 | mtspr SPRN_SRR0,r3 | |
209 | ld r9,_CTR(r1) | |
210 | mtctr r9 | |
211 | ld r9,_XER(r1) | |
212 | mtxer r9 | |
213 | ld r9,_LINK(r1) | |
214 | mtlr r9 | |
215 | REST_GPR(0, r1) | |
216 | REST_8GPRS(2, r1) | |
217 | REST_GPR(10, r1) | |
218 | ld r11,_CCR(r1) | |
219 | mtcr r11 | |
220 | REST_GPR(11, r1) | |
221 | REST_2GPRS(12, r1) | |
222 | /* restore original r1. */ | |
223 | ld r1,GPR1(r1) | |
224 | RFI_TO_USER_OR_KERNEL | |
582baf44 NP |
225 | |
226 | #ifdef CONFIG_PPC_PSERIES | |
227 | /* | |
228 | * Vectors for the FWNMI option. Share common code. | |
229 | */ | |
230 | TRAMP_REAL_BEGIN(system_reset_fwnmi) | |
231 | SET_SCRATCH0(r13) /* save r13 */ | |
c4f3b52c NP |
232 | /* See comment at system_reset exception */ |
233 | EXCEPTION_PROLOG_PSERIES_NORI(PACA_EXNMI, system_reset_common, | |
234 | EXC_STD, NOTEST, 0x100) | |
582baf44 NP |
235 | #endif /* CONFIG_PPC_PSERIES */ |
236 | ||
0ebc4cda | 237 | |
1a6822d1 | 238 | EXC_REAL_BEGIN(machine_check, 0x200, 0x100) |
b01c8b54 PM |
239 | /* This is moved out of line as it can be patched by FW, but |
240 | * some code path might still want to branch into the original | |
241 | * vector | |
242 | */ | |
1707dd16 PM |
243 | SET_SCRATCH0(r13) /* save r13 */ |
244 | EXCEPTION_PROLOG_0(PACA_EXMC) | |
1e9b4507 | 245 | BEGIN_FTR_SECTION |
2513767d | 246 | b machine_check_powernv_early |
1e9b4507 | 247 | FTR_SECTION_ELSE |
1707dd16 | 248 | b machine_check_pSeries_0 |
1e9b4507 | 249 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) |
1a6822d1 NP |
250 | EXC_REAL_END(machine_check, 0x200, 0x100) |
251 | EXC_VIRT_NONE(0x4200, 0x100) | |
afcf0095 NP |
252 | TRAMP_REAL_BEGIN(machine_check_powernv_early) |
253 | BEGIN_FTR_SECTION | |
254 | EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200) | |
255 | /* | |
256 | * Register contents: | |
257 | * R13 = PACA | |
258 | * R9 = CR | |
259 | * Original R9 to R13 is saved on PACA_EXMC | |
260 | * | |
261 | * Switch to mc_emergency stack and handle re-entrancy (we limit | |
262 | * the nested MCE upto level 4 to avoid stack overflow). | |
263 | * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1 | |
264 | * | |
265 | * We use paca->in_mce to check whether this is the first entry or | |
266 | * nested machine check. We increment paca->in_mce to track nested | |
267 | * machine checks. | |
268 | * | |
269 | * If this is the first entry then set stack pointer to | |
270 | * paca->mc_emergency_sp, otherwise r1 is already pointing to | |
271 | * stack frame on mc_emergency stack. | |
272 | * | |
273 | * NOTE: We are here with MSR_ME=0 (off), which means we risk a | |
274 | * checkstop if we get another machine check exception before we do | |
275 | * rfid with MSR_ME=1. | |
1945bc45 NP |
276 | * |
277 | * This interrupt can wake directly from idle. If that is the case, | |
278 | * the machine check is handled then the idle wakeup code is called | |
279 | * to restore state. In that case, the POWER9 DD1 idle PACA workaround | |
280 | * is not applied in the early machine check code, which will cause | |
281 | * bugs. | |
afcf0095 NP |
282 | */ |
283 | mr r11,r1 /* Save r1 */ | |
284 | lhz r10,PACA_IN_MCE(r13) | |
285 | cmpwi r10,0 /* Are we in nested machine check */ | |
286 | bne 0f /* Yes, we are. */ | |
287 | /* First machine check entry */ | |
288 | ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */ | |
289 | 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ | |
290 | addi r10,r10,1 /* increment paca->in_mce */ | |
291 | sth r10,PACA_IN_MCE(r13) | |
292 | /* Limit nested MCE to level 4 to avoid stack overflow */ | |
ba41e1e1 | 293 | cmpwi r10,MAX_MCE_DEPTH |
afcf0095 NP |
294 | bgt 2f /* Check if we hit limit of 4 */ |
295 | std r11,GPR1(r1) /* Save r1 on the stack. */ | |
296 | std r11,0(r1) /* make stack chain pointer */ | |
297 | mfspr r11,SPRN_SRR0 /* Save SRR0 */ | |
298 | std r11,_NIP(r1) | |
299 | mfspr r11,SPRN_SRR1 /* Save SRR1 */ | |
300 | std r11,_MSR(r1) | |
301 | mfspr r11,SPRN_DAR /* Save DAR */ | |
302 | std r11,_DAR(r1) | |
303 | mfspr r11,SPRN_DSISR /* Save DSISR */ | |
304 | std r11,_DSISR(r1) | |
305 | std r9,_CCR(r1) /* Save CR in stackframe */ | |
306 | /* Save r9 through r13 from EXMC save area to stack frame. */ | |
307 | EXCEPTION_PROLOG_COMMON_2(PACA_EXMC) | |
308 | mfmsr r11 /* get MSR value */ | |
309 | ori r11,r11,MSR_ME /* turn on ME bit */ | |
310 | ori r11,r11,MSR_RI /* turn on RI bit */ | |
311 | LOAD_HANDLER(r12, machine_check_handle_early) | |
312 | 1: mtspr SPRN_SRR0,r12 | |
313 | mtspr SPRN_SRR1,r11 | |
222f20f1 | 314 | RFI_TO_KERNEL |
afcf0095 NP |
315 | b . /* prevent speculative execution */ |
316 | 2: | |
317 | /* Stack overflow. Stay on emergency stack and panic. | |
318 | * Keep the ME bit off while panic-ing, so that if we hit | |
319 | * another machine check we checkstop. | |
320 | */ | |
321 | addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */ | |
322 | ld r11,PACAKMSR(r13) | |
323 | LOAD_HANDLER(r12, unrecover_mce) | |
324 | li r10,MSR_ME | |
325 | andc r11,r11,r10 /* Turn off MSR_ME */ | |
326 | b 1b | |
327 | b . /* prevent speculative execution */ | |
328 | END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) | |
329 | ||
330 | TRAMP_REAL_BEGIN(machine_check_pSeries) | |
331 | .globl machine_check_fwnmi | |
332 | machine_check_fwnmi: | |
333 | SET_SCRATCH0(r13) /* save r13 */ | |
334 | EXCEPTION_PROLOG_0(PACA_EXMC) | |
335 | machine_check_pSeries_0: | |
336 | EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST_PR, 0x200) | |
337 | /* | |
83a980f7 NP |
338 | * MSR_RI is not enabled, because PACA_EXMC is being used, so a |
339 | * nested machine check corrupts it. machine_check_common enables | |
340 | * MSR_RI. | |
afcf0095 | 341 | */ |
83a980f7 | 342 | EXCEPTION_PROLOG_PSERIES_1_NORI(machine_check_common, EXC_STD) |
afcf0095 NP |
343 | |
344 | TRAMP_KVM_SKIP(PACA_EXMC, 0x200) | |
345 | ||
346 | EXC_COMMON_BEGIN(machine_check_common) | |
347 | /* | |
348 | * Machine check is different because we use a different | |
349 | * save area: PACA_EXMC instead of PACA_EXGEN. | |
350 | */ | |
351 | mfspr r10,SPRN_DAR | |
352 | std r10,PACA_EXMC+EX_DAR(r13) | |
353 | mfspr r10,SPRN_DSISR | |
354 | stw r10,PACA_EXMC+EX_DSISR(r13) | |
355 | EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC) | |
356 | FINISH_NAP | |
357 | RECONCILE_IRQ_STATE(r10, r11) | |
358 | ld r3,PACA_EXMC+EX_DAR(r13) | |
359 | lwz r4,PACA_EXMC+EX_DSISR(r13) | |
360 | /* Enable MSR_RI when finished with PACA_EXMC */ | |
361 | li r10,MSR_RI | |
362 | mtmsrd r10,1 | |
363 | std r3,_DAR(r1) | |
364 | std r4,_DSISR(r1) | |
365 | bl save_nvgprs | |
366 | addi r3,r1,STACK_FRAME_OVERHEAD | |
367 | bl machine_check_exception | |
368 | b ret_from_except | |
369 | ||
370 | #define MACHINE_CHECK_HANDLER_WINDUP \ | |
371 | /* Clear MSR_RI before setting SRR0 and SRR1. */\ | |
372 | li r0,MSR_RI; \ | |
373 | mfmsr r9; /* get MSR value */ \ | |
374 | andc r9,r9,r0; \ | |
375 | mtmsrd r9,1; /* Clear MSR_RI */ \ | |
376 | /* Move original SRR0 and SRR1 into the respective regs */ \ | |
377 | ld r9,_MSR(r1); \ | |
378 | mtspr SPRN_SRR1,r9; \ | |
379 | ld r3,_NIP(r1); \ | |
380 | mtspr SPRN_SRR0,r3; \ | |
381 | ld r9,_CTR(r1); \ | |
382 | mtctr r9; \ | |
383 | ld r9,_XER(r1); \ | |
384 | mtxer r9; \ | |
385 | ld r9,_LINK(r1); \ | |
386 | mtlr r9; \ | |
387 | REST_GPR(0, r1); \ | |
388 | REST_8GPRS(2, r1); \ | |
389 | REST_GPR(10, r1); \ | |
390 | ld r11,_CCR(r1); \ | |
391 | mtcr r11; \ | |
392 | /* Decrement paca->in_mce. */ \ | |
393 | lhz r12,PACA_IN_MCE(r13); \ | |
394 | subi r12,r12,1; \ | |
395 | sth r12,PACA_IN_MCE(r13); \ | |
396 | REST_GPR(11, r1); \ | |
397 | REST_2GPRS(12, r1); \ | |
398 | /* restore original r1. */ \ | |
399 | ld r1,GPR1(r1) | |
400 | ||
1945bc45 NP |
401 | #ifdef CONFIG_PPC_P7_NAP |
402 | /* | |
403 | * This is an idle wakeup. Low level machine check has already been | |
404 | * done. Queue the event then call the idle code to do the wake up. | |
405 | */ | |
406 | EXC_COMMON_BEGIN(machine_check_idle_common) | |
407 | bl machine_check_queue_event | |
408 | ||
409 | /* | |
410 | * We have not used any non-volatile GPRs here, and as a rule | |
411 | * most exception code including machine check does not. | |
412 | * Therefore PACA_NAPSTATELOST does not need to be set. Idle | |
413 | * wakeup will restore volatile registers. | |
414 | * | |
415 | * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce. | |
416 | * | |
417 | * Then decrement MCE nesting after finishing with the stack. | |
418 | */ | |
419 | ld r3,_MSR(r1) | |
420 | ||
421 | lhz r11,PACA_IN_MCE(r13) | |
422 | subi r11,r11,1 | |
423 | sth r11,PACA_IN_MCE(r13) | |
424 | ||
425 | /* Turn off the RI bit because SRR1 is used by idle wakeup code. */ | |
426 | /* Recoverability could be improved by reducing the use of SRR1. */ | |
427 | li r11,0 | |
428 | mtmsrd r11,1 | |
429 | ||
430 | b pnv_powersave_wakeup_mce | |
431 | #endif | |
afcf0095 NP |
432 | /* |
433 | * Handle machine check early in real mode. We come here with | |
434 | * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack. | |
435 | */ | |
436 | EXC_COMMON_BEGIN(machine_check_handle_early) | |
437 | std r0,GPR0(r1) /* Save r0 */ | |
438 | EXCEPTION_PROLOG_COMMON_3(0x200) | |
439 | bl save_nvgprs | |
440 | addi r3,r1,STACK_FRAME_OVERHEAD | |
441 | bl machine_check_early | |
442 | std r3,RESULT(r1) /* Save result */ | |
443 | ld r12,_MSR(r1) | |
1945bc45 | 444 | |
afcf0095 NP |
445 | #ifdef CONFIG_PPC_P7_NAP |
446 | /* | |
447 | * Check if thread was in power saving mode. We come here when any | |
448 | * of the following is true: | |
449 | * a. thread wasn't in power saving mode | |
450 | * b. thread was in power saving mode with no state loss, | |
451 | * supervisor state loss or hypervisor state loss. | |
452 | * | |
453 | * Go back to nap/sleep/winkle mode again if (b) is true. | |
454 | */ | |
1945bc45 NP |
455 | BEGIN_FTR_SECTION |
456 | rlwinm. r11,r12,47-31,30,31 | |
6102c005 | 457 | bne machine_check_idle_common |
1945bc45 | 458 | END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) |
afcf0095 | 459 | #endif |
1945bc45 | 460 | |
afcf0095 NP |
461 | /* |
462 | * Check if we are coming from hypervisor userspace. If yes then we | |
463 | * continue in host kernel in V mode to deliver the MC event. | |
464 | */ | |
465 | rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */ | |
466 | beq 5f | |
467 | andi. r11,r12,MSR_PR /* See if coming from user. */ | |
468 | bne 9f /* continue in V mode if we are. */ | |
469 | ||
470 | 5: | |
471 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER | |
472 | /* | |
473 | * We are coming from kernel context. Check if we are coming from | |
474 | * guest. if yes, then we can continue. We will fall through | |
475 | * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest. | |
476 | */ | |
477 | lbz r11,HSTATE_IN_GUEST(r13) | |
478 | cmpwi r11,0 /* Check if coming from guest */ | |
479 | bne 9f /* continue if we are. */ | |
480 | #endif | |
481 | /* | |
482 | * At this point we are not sure about what context we come from. | |
483 | * Queue up the MCE event and return from the interrupt. | |
484 | * But before that, check if this is an un-recoverable exception. | |
485 | * If yes, then stay on emergency stack and panic. | |
486 | */ | |
487 | andi. r11,r12,MSR_RI | |
488 | bne 2f | |
489 | 1: mfspr r11,SPRN_SRR0 | |
490 | LOAD_HANDLER(r10,unrecover_mce) | |
491 | mtspr SPRN_SRR0,r10 | |
492 | ld r10,PACAKMSR(r13) | |
493 | /* | |
494 | * We are going down. But there are chances that we might get hit by | |
495 | * another MCE during panic path and we may run into unstable state | |
496 | * with no way out. Hence, turn ME bit off while going down, so that | |
497 | * when another MCE is hit during panic path, system will checkstop | |
498 | * and hypervisor will get restarted cleanly by SP. | |
499 | */ | |
500 | li r3,MSR_ME | |
501 | andc r10,r10,r3 /* Turn off MSR_ME */ | |
502 | mtspr SPRN_SRR1,r10 | |
222f20f1 | 503 | RFI_TO_KERNEL |
afcf0095 NP |
504 | b . |
505 | 2: | |
506 | /* | |
507 | * Check if we have successfully handled/recovered from error, if not | |
508 | * then stay on emergency stack and panic. | |
509 | */ | |
510 | ld r3,RESULT(r1) /* Load result */ | |
511 | cmpdi r3,0 /* see if we handled MCE successfully */ | |
512 | ||
513 | beq 1b /* if !handled then panic */ | |
514 | /* | |
515 | * Return from MC interrupt. | |
516 | * Queue up the MCE event so that we can log it later, while | |
517 | * returning from kernel or opal call. | |
518 | */ | |
519 | bl machine_check_queue_event | |
520 | MACHINE_CHECK_HANDLER_WINDUP | |
222f20f1 | 521 | RFI_TO_USER_OR_KERNEL |
afcf0095 NP |
522 | 9: |
523 | /* Deliver the machine check to host kernel in V mode. */ | |
524 | MACHINE_CHECK_HANDLER_WINDUP | |
525 | b machine_check_pSeries | |
526 | ||
527 | EXC_COMMON_BEGIN(unrecover_mce) | |
528 | /* Invoke machine_check_exception to print MCE event and panic. */ | |
529 | addi r3,r1,STACK_FRAME_OVERHEAD | |
530 | bl machine_check_exception | |
531 | /* | |
532 | * We will not reach here. Even if we did, there is no way out. Call | |
533 | * unrecoverable_exception and die. | |
534 | */ | |
535 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
536 | bl unrecoverable_exception | |
537 | b 1b | |
538 | ||
0ebc4cda | 539 | |
1a6822d1 NP |
540 | EXC_REAL(data_access, 0x300, 0x80) |
541 | EXC_VIRT(data_access, 0x4300, 0x80, 0x300) | |
80795e6c NP |
542 | TRAMP_KVM_SKIP(PACA_EXGEN, 0x300) |
543 | ||
544 | EXC_COMMON_BEGIN(data_access_common) | |
545 | /* | |
546 | * Here r13 points to the paca, r9 contains the saved CR, | |
547 | * SRR0 and SRR1 are saved in r11 and r12, | |
548 | * r9 - r13 are saved in paca->exgen. | |
549 | */ | |
550 | mfspr r10,SPRN_DAR | |
551 | std r10,PACA_EXGEN+EX_DAR(r13) | |
552 | mfspr r10,SPRN_DSISR | |
553 | stw r10,PACA_EXGEN+EX_DSISR(r13) | |
554 | EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN) | |
555 | RECONCILE_IRQ_STATE(r10, r11) | |
556 | ld r12,_MSR(r1) | |
557 | ld r3,PACA_EXGEN+EX_DAR(r13) | |
558 | lwz r4,PACA_EXGEN+EX_DSISR(r13) | |
559 | li r5,0x300 | |
560 | std r3,_DAR(r1) | |
561 | std r4,_DSISR(r1) | |
562 | BEGIN_MMU_FTR_SECTION | |
563 | b do_hash_page /* Try to handle as hpte fault */ | |
564 | MMU_FTR_SECTION_ELSE | |
565 | b handle_page_fault | |
566 | ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) | |
567 | ||
0ebc4cda | 568 | |
1a6822d1 | 569 | EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80) |
673b189a | 570 | SET_SCRATCH0(r13) |
1707dd16 | 571 | EXCEPTION_PROLOG_0(PACA_EXSLB) |
da2bc464 | 572 | EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380) |
4d7cd3b9 | 573 | mr r12,r3 /* save r3 */ |
0ebc4cda | 574 | mfspr r3,SPRN_DAR |
4d7cd3b9 | 575 | mfspr r11,SPRN_SRR1 |
f0f558b1 | 576 | crset 4*cr6+eq |
442b6e8e | 577 | BRANCH_TO_COMMON(r10, slb_miss_common) |
1a6822d1 | 578 | EXC_REAL_END(data_access_slb, 0x380, 0x80) |
0ebc4cda | 579 | |
1a6822d1 | 580 | EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80) |
2b9af6e4 NP |
581 | SET_SCRATCH0(r13) |
582 | EXCEPTION_PROLOG_0(PACA_EXSLB) | |
583 | EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380) | |
4d7cd3b9 | 584 | mr r12,r3 /* save r3 */ |
2b9af6e4 | 585 | mfspr r3,SPRN_DAR |
4d7cd3b9 | 586 | mfspr r11,SPRN_SRR1 |
2b9af6e4 | 587 | crset 4*cr6+eq |
442b6e8e | 588 | BRANCH_TO_COMMON(r10, slb_miss_common) |
1a6822d1 | 589 | EXC_VIRT_END(data_access_slb, 0x4380, 0x80) |
2b9af6e4 NP |
590 | TRAMP_KVM_SKIP(PACA_EXSLB, 0x380) |
591 | ||
592 | ||
1a6822d1 NP |
593 | EXC_REAL(instruction_access, 0x400, 0x80) |
594 | EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400) | |
27ce77df NP |
595 | TRAMP_KVM(PACA_EXGEN, 0x400) |
596 | ||
597 | EXC_COMMON_BEGIN(instruction_access_common) | |
598 | EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN) | |
599 | RECONCILE_IRQ_STATE(r10, r11) | |
600 | ld r12,_MSR(r1) | |
601 | ld r3,_NIP(r1) | |
475b581f | 602 | andis. r4,r12,DSISR_SRR1_MATCH_64S@h |
27ce77df NP |
603 | li r5,0x400 |
604 | std r3,_DAR(r1) | |
605 | std r4,_DSISR(r1) | |
606 | BEGIN_MMU_FTR_SECTION | |
607 | b do_hash_page /* Try to handle as hpte fault */ | |
608 | MMU_FTR_SECTION_ELSE | |
609 | b handle_page_fault | |
610 | ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX) | |
611 | ||
0ebc4cda | 612 | |
1a6822d1 | 613 | EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80) |
673b189a | 614 | SET_SCRATCH0(r13) |
1707dd16 | 615 | EXCEPTION_PROLOG_0(PACA_EXSLB) |
da2bc464 | 616 | EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480) |
4d7cd3b9 | 617 | mr r12,r3 /* save r3 */ |
0ebc4cda | 618 | mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */ |
4d7cd3b9 | 619 | mfspr r11,SPRN_SRR1 |
f0f558b1 | 620 | crclr 4*cr6+eq |
442b6e8e | 621 | BRANCH_TO_COMMON(r10, slb_miss_common) |
1a6822d1 | 622 | EXC_REAL_END(instruction_access_slb, 0x480, 0x80) |
0ebc4cda | 623 | |
1a6822d1 | 624 | EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80) |
8d04631a NP |
625 | SET_SCRATCH0(r13) |
626 | EXCEPTION_PROLOG_0(PACA_EXSLB) | |
627 | EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480) | |
4d7cd3b9 | 628 | mr r12,r3 /* save r3 */ |
8d04631a | 629 | mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */ |
4d7cd3b9 | 630 | mfspr r11,SPRN_SRR1 |
8d04631a | 631 | crclr 4*cr6+eq |
442b6e8e | 632 | BRANCH_TO_COMMON(r10, slb_miss_common) |
1a6822d1 | 633 | EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80) |
8d04631a NP |
634 | TRAMP_KVM(PACA_EXSLB, 0x480) |
635 | ||
636 | ||
442b6e8e ME |
637 | /* |
638 | * This handler is used by the 0x380 and 0x480 SLB miss interrupts, as well as | |
639 | * the virtual mode 0x4380 and 0x4480 interrupts if AIL is enabled. | |
640 | */ | |
641 | EXC_COMMON_BEGIN(slb_miss_common) | |
8d04631a NP |
642 | /* |
643 | * r13 points to the PACA, r9 contains the saved CR, | |
4d7cd3b9 NP |
644 | * r12 contains the saved r3, |
645 | * r11 contain the saved SRR1, SRR0 is still ready for return | |
8d04631a NP |
646 | * r3 has the faulting address |
647 | * r9 - r13 are saved in paca->exslb. | |
8d04631a NP |
648 | * cr6.eq is set for a D-SLB miss, clear for a I-SLB miss |
649 | * We assume we aren't going to take any exceptions during this | |
650 | * procedure. | |
651 | */ | |
652 | mflr r10 | |
8d04631a NP |
653 | stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */ |
654 | std r10,PACA_EXSLB+EX_LR(r13) /* save LR */ | |
8d04631a | 655 | |
c7305645 NP |
656 | andi. r9,r11,MSR_PR // Check for exception from userspace |
657 | cmpdi cr4,r9,MSR_PR // And save the result in CR4 for later | |
658 | ||
4d7cd3b9 NP |
659 | /* |
660 | * Test MSR_RI before calling slb_allocate_realmode, because the | |
661 | * MSR in r11 gets clobbered. However we still want to allocate | |
662 | * SLB in case MSR_RI=0, to minimise the risk of getting stuck in | |
663 | * recursive SLB faults. So use cr5 for this, which is preserved. | |
664 | */ | |
665 | andi. r11,r11,MSR_RI /* check for unrecoverable exception */ | |
666 | cmpdi cr5,r11,MSR_RI | |
667 | ||
8d04631a | 668 | crset 4*cr0+eq |
4e003747 | 669 | #ifdef CONFIG_PPC_BOOK3S_64 |
8d04631a | 670 | BEGIN_MMU_FTR_SECTION |
fd88b945 | 671 | bl slb_allocate |
8d04631a NP |
672 | END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX) |
673 | #endif | |
674 | ||
675 | ld r10,PACA_EXSLB+EX_LR(r13) | |
8d04631a NP |
676 | lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */ |
677 | mtlr r10 | |
678 | ||
7c28f048 | 679 | beq- 8f /* if bad address, make full stack frame */ |
8d04631a | 680 | |
4d7cd3b9 | 681 | bne- cr5,2f /* if unrecoverable exception, oops */ |
8d04631a NP |
682 | |
683 | /* All done -- return from exception. */ | |
684 | ||
c7305645 NP |
685 | bne cr4,1f /* returning to kernel */ |
686 | ||
8d04631a NP |
687 | .machine push |
688 | .machine "power4" | |
689 | mtcrf 0x80,r9 | |
c7305645 | 690 | mtcrf 0x08,r9 /* MSR[PR] indication is in cr4 */ |
4d7cd3b9 | 691 | mtcrf 0x04,r9 /* MSR[RI] indication is in cr5 */ |
8d04631a NP |
692 | mtcrf 0x02,r9 /* I/D indication is in cr6 */ |
693 | mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */ | |
694 | .machine pop | |
695 | ||
fe5482c0 | 696 | RESTORE_CTR(r9, PACA_EXSLB) |
8d04631a | 697 | RESTORE_PPR_PACA(PACA_EXSLB, r9) |
4d7cd3b9 | 698 | mr r3,r12 |
8d04631a NP |
699 | ld r9,PACA_EXSLB+EX_R9(r13) |
700 | ld r10,PACA_EXSLB+EX_R10(r13) | |
701 | ld r11,PACA_EXSLB+EX_R11(r13) | |
702 | ld r12,PACA_EXSLB+EX_R12(r13) | |
703 | ld r13,PACA_EXSLB+EX_R13(r13) | |
c7305645 | 704 | RFI_TO_USER |
8d04631a | 705 | b . /* prevent speculative execution */ |
c7305645 NP |
706 | 1: |
707 | .machine push | |
708 | .machine "power4" | |
709 | mtcrf 0x80,r9 | |
710 | mtcrf 0x08,r9 /* MSR[PR] indication is in cr4 */ | |
711 | mtcrf 0x04,r9 /* MSR[RI] indication is in cr5 */ | |
712 | mtcrf 0x02,r9 /* I/D indication is in cr6 */ | |
713 | mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */ | |
714 | .machine pop | |
715 | ||
716 | RESTORE_CTR(r9, PACA_EXSLB) | |
717 | RESTORE_PPR_PACA(PACA_EXSLB, r9) | |
718 | mr r3,r12 | |
719 | ld r9,PACA_EXSLB+EX_R9(r13) | |
720 | ld r10,PACA_EXSLB+EX_R10(r13) | |
721 | ld r11,PACA_EXSLB+EX_R11(r13) | |
722 | ld r12,PACA_EXSLB+EX_R12(r13) | |
723 | ld r13,PACA_EXSLB+EX_R13(r13) | |
724 | RFI_TO_KERNEL | |
725 | b . /* prevent speculative execution */ | |
726 | ||
8d04631a | 727 | |
7c28f048 | 728 | 2: std r3,PACA_EXSLB+EX_DAR(r13) |
4d7cd3b9 | 729 | mr r3,r12 |
7c28f048 | 730 | mfspr r11,SPRN_SRR0 |
4d7cd3b9 | 731 | mfspr r12,SPRN_SRR1 |
8d04631a NP |
732 | LOAD_HANDLER(r10,unrecov_slb) |
733 | mtspr SPRN_SRR0,r10 | |
734 | ld r10,PACAKMSR(r13) | |
735 | mtspr SPRN_SRR1,r10 | |
222f20f1 | 736 | RFI_TO_KERNEL |
8d04631a NP |
737 | b . |
738 | ||
7c28f048 | 739 | 8: std r3,PACA_EXSLB+EX_DAR(r13) |
4d7cd3b9 | 740 | mr r3,r12 |
7c28f048 | 741 | mfspr r11,SPRN_SRR0 |
4d7cd3b9 | 742 | mfspr r12,SPRN_SRR1 |
8d04631a NP |
743 | LOAD_HANDLER(r10,bad_addr_slb) |
744 | mtspr SPRN_SRR0,r10 | |
745 | ld r10,PACAKMSR(r13) | |
746 | mtspr SPRN_SRR1,r10 | |
222f20f1 | 747 | RFI_TO_KERNEL |
8d04631a NP |
748 | b . |
749 | ||
750 | EXC_COMMON_BEGIN(unrecov_slb) | |
751 | EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB) | |
752 | RECONCILE_IRQ_STATE(r10, r11) | |
753 | bl save_nvgprs | |
754 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
755 | bl unrecoverable_exception | |
756 | b 1b | |
757 | ||
758 | EXC_COMMON_BEGIN(bad_addr_slb) | |
759 | EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB) | |
760 | RECONCILE_IRQ_STATE(r10, r11) | |
761 | ld r3, PACA_EXSLB+EX_DAR(r13) | |
762 | std r3, _DAR(r1) | |
763 | beq cr6, 2f | |
ada7507d | 764 | li r10, 0x481 /* fix trap number for I-SLB miss */ |
8d04631a NP |
765 | std r10, _TRAP(r1) |
766 | 2: bl save_nvgprs | |
767 | addi r3, r1, STACK_FRAME_OVERHEAD | |
768 | bl slb_miss_bad_addr | |
769 | b ret_from_except | |
770 | ||
1a6822d1 | 771 | EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100) |
b3e6b5df | 772 | .globl hardware_interrupt_hv; |
b3e6b5df | 773 | hardware_interrupt_hv: |
a5d4f3ad | 774 | BEGIN_FTR_SECTION |
da2bc464 | 775 | _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, |
b01c8b54 | 776 | EXC_HV, SOFTEN_TEST_HV) |
de56a948 | 777 | FTR_SECTION_ELSE |
da2bc464 | 778 | _MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, |
31a40e2b | 779 | EXC_STD, SOFTEN_TEST_PR) |
969391c5 | 780 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) |
1a6822d1 | 781 | EXC_REAL_END(hardware_interrupt, 0x500, 0x100) |
da2bc464 | 782 | |
1a6822d1 | 783 | EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100) |
c138e588 NP |
784 | .globl hardware_interrupt_relon_hv; |
785 | hardware_interrupt_relon_hv: | |
786 | BEGIN_FTR_SECTION | |
787 | _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_HV) | |
788 | FTR_SECTION_ELSE | |
789 | _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_PR) | |
790 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) | |
1a6822d1 | 791 | EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100) |
c138e588 | 792 | |
7ede5317 NP |
793 | TRAMP_KVM(PACA_EXGEN, 0x500) |
794 | TRAMP_KVM_HV(PACA_EXGEN, 0x500) | |
c138e588 NP |
795 | EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ) |
796 | ||
797 | ||
1a6822d1 NP |
798 | EXC_REAL(alignment, 0x600, 0x100) |
799 | EXC_VIRT(alignment, 0x4600, 0x100, 0x600) | |
da2bc464 | 800 | TRAMP_KVM(PACA_EXGEN, 0x600) |
f9aa6714 NP |
801 | EXC_COMMON_BEGIN(alignment_common) |
802 | mfspr r10,SPRN_DAR | |
803 | std r10,PACA_EXGEN+EX_DAR(r13) | |
804 | mfspr r10,SPRN_DSISR | |
805 | stw r10,PACA_EXGEN+EX_DSISR(r13) | |
806 | EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN) | |
807 | ld r3,PACA_EXGEN+EX_DAR(r13) | |
808 | lwz r4,PACA_EXGEN+EX_DSISR(r13) | |
809 | std r3,_DAR(r1) | |
810 | std r4,_DSISR(r1) | |
811 | bl save_nvgprs | |
812 | RECONCILE_IRQ_STATE(r10, r11) | |
813 | addi r3,r1,STACK_FRAME_OVERHEAD | |
814 | bl alignment_exception | |
815 | b ret_from_except | |
816 | ||
da2bc464 | 817 | |
1a6822d1 NP |
818 | EXC_REAL(program_check, 0x700, 0x100) |
819 | EXC_VIRT(program_check, 0x4700, 0x100, 0x700) | |
da2bc464 | 820 | TRAMP_KVM(PACA_EXGEN, 0x700) |
11e87346 | 821 | EXC_COMMON_BEGIN(program_check_common) |
265e60a1 CB |
822 | /* |
823 | * It's possible to receive a TM Bad Thing type program check with | |
824 | * userspace register values (in particular r1), but with SRR1 reporting | |
825 | * that we came from the kernel. Normally that would confuse the bad | |
826 | * stack logic, and we would report a bad kernel stack pointer. Instead | |
827 | * we switch to the emergency stack if we're taking a TM Bad Thing from | |
828 | * the kernel. | |
829 | */ | |
830 | li r10,MSR_PR /* Build a mask of MSR_PR .. */ | |
831 | oris r10,r10,0x200000@h /* .. and SRR1_PROGTM */ | |
832 | and r10,r10,r12 /* Mask SRR1 with that. */ | |
833 | srdi r10,r10,8 /* Shift it so we can compare */ | |
834 | cmpldi r10,(0x200000 >> 8) /* .. with an immediate. */ | |
835 | bne 1f /* If != go to normal path. */ | |
836 | ||
837 | /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */ | |
838 | andi. r10,r12,MSR_PR; /* Set CR0 correctly for label */ | |
839 | /* 3 in EXCEPTION_PROLOG_COMMON */ | |
840 | mr r10,r1 /* Save r1 */ | |
841 | ld r1,PACAEMERGSP(r13) /* Use emergency stack */ | |
842 | subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ | |
843 | b 3f /* Jump into the macro !! */ | |
844 | 1: EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN) | |
11e87346 NP |
845 | bl save_nvgprs |
846 | RECONCILE_IRQ_STATE(r10, r11) | |
847 | addi r3,r1,STACK_FRAME_OVERHEAD | |
848 | bl program_check_exception | |
849 | b ret_from_except | |
850 | ||
b01c8b54 | 851 | |
1a6822d1 NP |
852 | EXC_REAL(fp_unavailable, 0x800, 0x100) |
853 | EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800) | |
da2bc464 | 854 | TRAMP_KVM(PACA_EXGEN, 0x800) |
c78d9b97 NP |
855 | EXC_COMMON_BEGIN(fp_unavailable_common) |
856 | EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN) | |
857 | bne 1f /* if from user, just load it up */ | |
858 | bl save_nvgprs | |
859 | RECONCILE_IRQ_STATE(r10, r11) | |
860 | addi r3,r1,STACK_FRAME_OVERHEAD | |
861 | bl kernel_fp_unavailable_exception | |
862 | BUG_OPCODE | |
863 | 1: | |
864 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
865 | BEGIN_FTR_SECTION | |
866 | /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in | |
867 | * transaction), go do TM stuff | |
868 | */ | |
869 | rldicl. r0, r12, (64-MSR_TS_LG), (64-2) | |
870 | bne- 2f | |
871 | END_FTR_SECTION_IFSET(CPU_FTR_TM) | |
872 | #endif | |
873 | bl load_up_fpu | |
874 | b fast_exception_return | |
875 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
876 | 2: /* User process was in a transaction */ | |
877 | bl save_nvgprs | |
878 | RECONCILE_IRQ_STATE(r10, r11) | |
879 | addi r3,r1,STACK_FRAME_OVERHEAD | |
880 | bl fp_unavailable_tm | |
881 | b ret_from_except | |
882 | #endif | |
883 | ||
a5d4f3ad | 884 | |
cc437c1d | 885 | EXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x80) |
1a6822d1 | 886 | EXC_VIRT_MASKABLE(decrementer, 0x4900, 0x80, 0x900) |
39c0da57 NP |
887 | TRAMP_KVM(PACA_EXGEN, 0x900) |
888 | EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt) | |
889 | ||
a485c709 | 890 | |
1a6822d1 NP |
891 | EXC_REAL_HV(hdecrementer, 0x980, 0x80) |
892 | EXC_VIRT_HV(hdecrementer, 0x4980, 0x80, 0x980) | |
facc6d74 NP |
893 | TRAMP_KVM_HV(PACA_EXGEN, 0x980) |
894 | EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt) | |
895 | ||
a5d4f3ad | 896 | |
1a6822d1 NP |
897 | EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100) |
898 | EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00) | |
da2bc464 | 899 | TRAMP_KVM(PACA_EXGEN, 0xa00) |
ca243163 NP |
900 | #ifdef CONFIG_PPC_DOORBELL |
901 | EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception) | |
902 | #else | |
903 | EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception) | |
904 | #endif | |
905 | ||
0ebc4cda | 906 | |
1a6822d1 NP |
907 | EXC_REAL(trap_0b, 0xb00, 0x100) |
908 | EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00) | |
da2bc464 | 909 | TRAMP_KVM(PACA_EXGEN, 0xb00) |
341215dc NP |
910 | EXC_COMMON(trap_0b_common, 0xb00, unknown_exception) |
911 | ||
acd7d8ce NP |
912 | /* |
913 | * system call / hypercall (0xc00, 0x4c00) | |
914 | * | |
915 | * The system call exception is invoked with "sc 0" and does not alter HV bit. | |
916 | * There is support for kernel code to invoke system calls but there are no | |
917 | * in-tree users. | |
918 | * | |
919 | * The hypercall is invoked with "sc 1" and sets HV=1. | |
920 | * | |
921 | * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to | |
922 | * 0x4c00 virtual mode. | |
923 | * | |
924 | * Call convention: | |
925 | * | |
926 | * syscall register convention is in Documentation/powerpc/syscall64-abi.txt | |
927 | * | |
928 | * For hypercalls, the register convention is as follows: | |
929 | * r0 volatile | |
930 | * r1-2 nonvolatile | |
931 | * r3 volatile parameter and return value for status | |
932 | * r4-r10 volatile input and output value | |
933 | * r11 volatile hypercall number and output value | |
76fc0cfc | 934 | * r12 volatile input and output value |
acd7d8ce NP |
935 | * r13-r31 nonvolatile |
936 | * LR nonvolatile | |
937 | * CTR volatile | |
938 | * XER volatile | |
939 | * CR0-1 CR5-7 volatile | |
940 | * CR2-4 nonvolatile | |
941 | * Other registers nonvolatile | |
942 | * | |
943 | * The intersection of volatile registers that don't contain possible | |
76fc0cfc NP |
944 | * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry |
945 | * without saving, though xer is not a good idea to use, as hardware may | |
946 | * interpret some bits so it may be costly to change them. | |
acd7d8ce | 947 | */ |
bc355125 | 948 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
acd7d8ce NP |
949 | /* |
950 | * There is a little bit of juggling to get syscall and hcall | |
76fc0cfc NP |
951 | * working well. Save r13 in ctr to avoid using SPRG scratch |
952 | * register. | |
acd7d8ce NP |
953 | * |
954 | * Userspace syscalls have already saved the PPR, hcalls must save | |
955 | * it before setting HMT_MEDIUM. | |
956 | */ | |
bc355125 | 957 | #define SYSCALL_KVMTEST \ |
76fc0cfc | 958 | mtctr r13; \ |
bc355125 | 959 | GET_PACA(r13); \ |
76fc0cfc | 960 | std r10,PACA_EXGEN+EX_R10(r13); \ |
cc437c1d | 961 | INTERRUPT_TO_KERNEL; \ |
acd7d8ce | 962 | KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \ |
bc355125 | 963 | HMT_MEDIUM; \ |
76fc0cfc | 964 | mfctr r9; |
bc355125 PM |
965 | |
966 | #else | |
967 | #define SYSCALL_KVMTEST \ | |
acd7d8ce NP |
968 | HMT_MEDIUM; \ |
969 | mr r9,r13; \ | |
cc437c1d NP |
970 | GET_PACA(r13); \ |
971 | INTERRUPT_TO_KERNEL; | |
bc355125 PM |
972 | #endif |
973 | ||
fb479e44 NP |
974 | #define LOAD_SYSCALL_HANDLER(reg) \ |
975 | __LOAD_HANDLER(reg, system_call_common) | |
d807ad37 | 976 | |
acd7d8ce NP |
977 | /* |
978 | * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9, | |
979 | * and HMT_MEDIUM. | |
980 | */ | |
981 | #define SYSCALL_REAL \ | |
982 | mfspr r11,SPRN_SRR0 ; \ | |
d807ad37 NP |
983 | mfspr r12,SPRN_SRR1 ; \ |
984 | LOAD_SYSCALL_HANDLER(r10) ; \ | |
985 | mtspr SPRN_SRR0,r10 ; \ | |
986 | ld r10,PACAKMSR(r13) ; \ | |
987 | mtspr SPRN_SRR1,r10 ; \ | |
222f20f1 | 988 | RFI_TO_KERNEL ; \ |
d807ad37 NP |
989 | b . ; /* prevent speculative execution */ |
990 | ||
727f1361 | 991 | #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH |
5c2511bf ME |
992 | #define SYSCALL_FASTENDIAN_TEST \ |
993 | BEGIN_FTR_SECTION \ | |
994 | cmpdi r0,0x1ebe ; \ | |
995 | beq- 1f ; \ | |
996 | END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \ | |
997 | ||
acd7d8ce | 998 | #define SYSCALL_FASTENDIAN \ |
d807ad37 NP |
999 | /* Fast LE/BE switch system call */ \ |
1000 | 1: mfspr r12,SPRN_SRR1 ; \ | |
1001 | xori r12,r12,MSR_LE ; \ | |
1002 | mtspr SPRN_SRR1,r12 ; \ | |
acd7d8ce | 1003 | mr r13,r9 ; \ |
222f20f1 | 1004 | RFI_TO_USER ; /* return to userspace */ \ |
d807ad37 | 1005 | b . ; /* prevent speculative execution */ |
727f1361 ME |
1006 | #else |
1007 | #define SYSCALL_FASTENDIAN_TEST | |
1008 | #define SYSCALL_FASTENDIAN | |
1009 | #endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */ | |
d807ad37 NP |
1010 | |
1011 | #if defined(CONFIG_RELOCATABLE) | |
1012 | /* | |
1013 | * We can't branch directly so we do it via the CTR which | |
1014 | * is volatile across system calls. | |
1015 | */ | |
acd7d8ce NP |
1016 | #define SYSCALL_VIRT \ |
1017 | LOAD_SYSCALL_HANDLER(r10) ; \ | |
1018 | mtctr r10 ; \ | |
1019 | mfspr r11,SPRN_SRR0 ; \ | |
d807ad37 NP |
1020 | mfspr r12,SPRN_SRR1 ; \ |
1021 | li r10,MSR_RI ; \ | |
1022 | mtmsrd r10,1 ; \ | |
1023 | bctr ; | |
1024 | #else | |
1025 | /* We can branch directly */ | |
acd7d8ce NP |
1026 | #define SYSCALL_VIRT \ |
1027 | mfspr r11,SPRN_SRR0 ; \ | |
d807ad37 NP |
1028 | mfspr r12,SPRN_SRR1 ; \ |
1029 | li r10,MSR_RI ; \ | |
1030 | mtmsrd r10,1 ; /* Set RI (EE=0) */ \ | |
1031 | b system_call_common ; | |
1032 | #endif | |
1033 | ||
1a6822d1 | 1034 | EXC_REAL_BEGIN(system_call, 0xc00, 0x100) |
acd7d8ce NP |
1035 | SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */ |
1036 | SYSCALL_FASTENDIAN_TEST | |
1037 | SYSCALL_REAL | |
1038 | SYSCALL_FASTENDIAN | |
1a6822d1 | 1039 | EXC_REAL_END(system_call, 0xc00, 0x100) |
da2bc464 | 1040 | |
1a6822d1 | 1041 | EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100) |
acd7d8ce NP |
1042 | SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */ |
1043 | SYSCALL_FASTENDIAN_TEST | |
1044 | SYSCALL_VIRT | |
1045 | SYSCALL_FASTENDIAN | |
1a6822d1 | 1046 | EXC_VIRT_END(system_call, 0x4c00, 0x100) |
d807ad37 | 1047 | |
acd7d8ce NP |
1048 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
1049 | /* | |
1050 | * This is a hcall, so register convention is as above, with these | |
1051 | * differences: | |
1052 | * r13 = PACA | |
76fc0cfc NP |
1053 | * ctr = orig r13 |
1054 | * orig r10 saved in PACA | |
acd7d8ce NP |
1055 | */ |
1056 | TRAMP_KVM_BEGIN(do_kvm_0xc00) | |
1057 | /* | |
1058 | * Save the PPR (on systems that support it) before changing to | |
1059 | * HMT_MEDIUM. That allows the KVM code to save that value into the | |
1060 | * guest state (it is the guest's PPR value). | |
1061 | */ | |
76fc0cfc | 1062 | OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR) |
acd7d8ce | 1063 | HMT_MEDIUM |
76fc0cfc | 1064 | OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR) |
acd7d8ce | 1065 | mfctr r10 |
76fc0cfc | 1066 | SET_SCRATCH0(r10) |
acd7d8ce NP |
1067 | std r9,PACA_EXGEN+EX_R9(r13) |
1068 | mfcr r9 | |
acd7d8ce NP |
1069 | KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00) |
1070 | #endif | |
da2bc464 | 1071 | |
d807ad37 | 1072 | |
1a6822d1 NP |
1073 | EXC_REAL(single_step, 0xd00, 0x100) |
1074 | EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00) | |
da2bc464 | 1075 | TRAMP_KVM(PACA_EXGEN, 0xd00) |
bc6675c6 | 1076 | EXC_COMMON(single_step_common, 0xd00, single_step_exception) |
b01c8b54 | 1077 | |
1a6822d1 | 1078 | EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20) |
da0e7e62 | 1079 | EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00) |
f5c32c1d NP |
1080 | TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00) |
1081 | EXC_COMMON_BEGIN(h_data_storage_common) | |
1082 | mfspr r10,SPRN_HDAR | |
1083 | std r10,PACA_EXGEN+EX_DAR(r13) | |
1084 | mfspr r10,SPRN_HDSISR | |
1085 | stw r10,PACA_EXGEN+EX_DSISR(r13) | |
1086 | EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN) | |
1087 | bl save_nvgprs | |
1088 | RECONCILE_IRQ_STATE(r10, r11) | |
1089 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1090 | bl unknown_exception | |
1091 | b ret_from_except | |
f5c32c1d | 1092 | |
1707dd16 | 1093 | |
1a6822d1 | 1094 | EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20) |
da0e7e62 | 1095 | EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20) |
82517cab NP |
1096 | TRAMP_KVM_HV(PACA_EXGEN, 0xe20) |
1097 | EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception) | |
1098 | ||
1707dd16 | 1099 | |
1a6822d1 NP |
1100 | EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20) |
1101 | EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40) | |
031b4026 NP |
1102 | TRAMP_KVM_HV(PACA_EXGEN, 0xe40) |
1103 | EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt) | |
1104 | ||
1707dd16 | 1105 | |
e0319829 NP |
1106 | /* |
1107 | * hmi_exception trampoline is a special case. It jumps to hmi_exception_early | |
1108 | * first, and then eventaully from there to the trampoline to get into virtual | |
1109 | * mode. | |
1110 | */ | |
1a6822d1 | 1111 | __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early) |
852e5da9 | 1112 | __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60) |
1a6822d1 | 1113 | EXC_VIRT_NONE(0x4e60, 0x20) |
62f9b03b NP |
1114 | TRAMP_KVM_HV(PACA_EXGEN, 0xe60) |
1115 | TRAMP_REAL_BEGIN(hmi_exception_early) | |
1116 | EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60) | |
a4087a4d NP |
1117 | mr r10,r1 /* Save r1 */ |
1118 | ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */ | |
62f9b03b | 1119 | subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */ |
62f9b03b | 1120 | mfspr r11,SPRN_HSRR0 /* Save HSRR0 */ |
a4087a4d NP |
1121 | mfspr r12,SPRN_HSRR1 /* Save HSRR1 */ |
1122 | EXCEPTION_PROLOG_COMMON_1() | |
62f9b03b NP |
1123 | EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN) |
1124 | EXCEPTION_PROLOG_COMMON_3(0xe60) | |
1125 | addi r3,r1,STACK_FRAME_OVERHEAD | |
be5c5e84 | 1126 | BRANCH_LINK_TO_FAR(hmi_exception_realmode) /* Function call ABI */ |
5080332c MN |
1127 | cmpdi cr0,r3,0 |
1128 | ||
62f9b03b NP |
1129 | /* Windup the stack. */ |
1130 | /* Move original HSRR0 and HSRR1 into the respective regs */ | |
1131 | ld r9,_MSR(r1) | |
1132 | mtspr SPRN_HSRR1,r9 | |
1133 | ld r3,_NIP(r1) | |
1134 | mtspr SPRN_HSRR0,r3 | |
1135 | ld r9,_CTR(r1) | |
1136 | mtctr r9 | |
1137 | ld r9,_XER(r1) | |
1138 | mtxer r9 | |
1139 | ld r9,_LINK(r1) | |
1140 | mtlr r9 | |
1141 | REST_GPR(0, r1) | |
1142 | REST_8GPRS(2, r1) | |
1143 | REST_GPR(10, r1) | |
1144 | ld r11,_CCR(r1) | |
5080332c MN |
1145 | REST_2GPRS(12, r1) |
1146 | bne 1f | |
62f9b03b NP |
1147 | mtcr r11 |
1148 | REST_GPR(11, r1) | |
5080332c | 1149 | ld r1,GPR1(r1) |
222f20f1 | 1150 | HRFI_TO_USER_OR_KERNEL |
5080332c MN |
1151 | |
1152 | 1: mtcr r11 | |
1153 | REST_GPR(11, r1) | |
62f9b03b NP |
1154 | ld r1,GPR1(r1) |
1155 | ||
1156 | /* | |
1157 | * Go to virtual mode and pull the HMI event information from | |
1158 | * firmware. | |
1159 | */ | |
1160 | .globl hmi_exception_after_realmode | |
1161 | hmi_exception_after_realmode: | |
1162 | SET_SCRATCH0(r13) | |
1163 | EXCEPTION_PROLOG_0(PACA_EXGEN) | |
1164 | b tramp_real_hmi_exception | |
1165 | ||
5080332c MN |
1166 | EXC_COMMON_BEGIN(hmi_exception_common) |
1167 | EXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception, | |
1168 | ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON) | |
1707dd16 | 1169 | |
1a6822d1 NP |
1170 | EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20) |
1171 | EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80) | |
9bcb81bf NP |
1172 | TRAMP_KVM_HV(PACA_EXGEN, 0xe80) |
1173 | #ifdef CONFIG_PPC_DOORBELL | |
1174 | EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception) | |
1175 | #else | |
1176 | EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception) | |
1177 | #endif | |
1178 | ||
0ebc4cda | 1179 | |
1a6822d1 NP |
1180 | EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20) |
1181 | EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0) | |
74408776 NP |
1182 | TRAMP_KVM_HV(PACA_EXGEN, 0xea0) |
1183 | EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ) | |
1184 | ||
9baaef0a | 1185 | |
1a6822d1 NP |
1186 | EXC_REAL_NONE(0xec0, 0x20) |
1187 | EXC_VIRT_NONE(0x4ec0, 0x20) | |
1188 | EXC_REAL_NONE(0xee0, 0x20) | |
1189 | EXC_VIRT_NONE(0x4ee0, 0x20) | |
bda7fea2 | 1190 | |
0ebc4cda | 1191 | |
1a6822d1 NP |
1192 | EXC_REAL_OOL(performance_monitor, 0xf00, 0x20) |
1193 | EXC_VIRT_OOL(performance_monitor, 0x4f00, 0x20, 0xf00) | |
b1c7f150 NP |
1194 | TRAMP_KVM(PACA_EXGEN, 0xf00) |
1195 | EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception) | |
1196 | ||
0ebc4cda | 1197 | |
1a6822d1 NP |
1198 | EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20) |
1199 | EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20) | |
d1a0ca9c NP |
1200 | TRAMP_KVM(PACA_EXGEN, 0xf20) |
1201 | EXC_COMMON_BEGIN(altivec_unavailable_common) | |
1202 | EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN) | |
1203 | #ifdef CONFIG_ALTIVEC | |
1204 | BEGIN_FTR_SECTION | |
1205 | beq 1f | |
1206 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1207 | BEGIN_FTR_SECTION_NESTED(69) | |
1208 | /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in | |
1209 | * transaction), go do TM stuff | |
1210 | */ | |
1211 | rldicl. r0, r12, (64-MSR_TS_LG), (64-2) | |
1212 | bne- 2f | |
1213 | END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69) | |
1214 | #endif | |
1215 | bl load_up_altivec | |
1216 | b fast_exception_return | |
1217 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1218 | 2: /* User process was in a transaction */ | |
1219 | bl save_nvgprs | |
1220 | RECONCILE_IRQ_STATE(r10, r11) | |
1221 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1222 | bl altivec_unavailable_tm | |
1223 | b ret_from_except | |
1224 | #endif | |
1225 | 1: | |
1226 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) | |
1227 | #endif | |
1228 | bl save_nvgprs | |
1229 | RECONCILE_IRQ_STATE(r10, r11) | |
1230 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1231 | bl altivec_unavailable_exception | |
1232 | b ret_from_except | |
1233 | ||
0ebc4cda | 1234 | |
1a6822d1 NP |
1235 | EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20) |
1236 | EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40) | |
792cbddd NP |
1237 | TRAMP_KVM(PACA_EXGEN, 0xf40) |
1238 | EXC_COMMON_BEGIN(vsx_unavailable_common) | |
1239 | EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN) | |
1240 | #ifdef CONFIG_VSX | |
1241 | BEGIN_FTR_SECTION | |
1242 | beq 1f | |
1243 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1244 | BEGIN_FTR_SECTION_NESTED(69) | |
1245 | /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in | |
1246 | * transaction), go do TM stuff | |
1247 | */ | |
1248 | rldicl. r0, r12, (64-MSR_TS_LG), (64-2) | |
1249 | bne- 2f | |
1250 | END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69) | |
1251 | #endif | |
1252 | b load_up_vsx | |
1253 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
1254 | 2: /* User process was in a transaction */ | |
1255 | bl save_nvgprs | |
1256 | RECONCILE_IRQ_STATE(r10, r11) | |
1257 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1258 | bl vsx_unavailable_tm | |
1259 | b ret_from_except | |
1260 | #endif | |
1261 | 1: | |
1262 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) | |
1263 | #endif | |
1264 | bl save_nvgprs | |
1265 | RECONCILE_IRQ_STATE(r10, r11) | |
1266 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1267 | bl vsx_unavailable_exception | |
1268 | b ret_from_except | |
1269 | ||
da2bc464 | 1270 | |
1a6822d1 NP |
1271 | EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20) |
1272 | EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60) | |
1134713c NP |
1273 | TRAMP_KVM(PACA_EXGEN, 0xf60) |
1274 | EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception) | |
1275 | ||
da2bc464 | 1276 | |
1a6822d1 NP |
1277 | EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20) |
1278 | EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80) | |
14b0072c NP |
1279 | TRAMP_KVM_HV(PACA_EXGEN, 0xf80) |
1280 | EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception) | |
1281 | ||
da2bc464 | 1282 | |
1a6822d1 NP |
1283 | EXC_REAL_NONE(0xfa0, 0x20) |
1284 | EXC_VIRT_NONE(0x4fa0, 0x20) | |
1285 | EXC_REAL_NONE(0xfc0, 0x20) | |
1286 | EXC_VIRT_NONE(0x4fc0, 0x20) | |
1287 | EXC_REAL_NONE(0xfe0, 0x20) | |
1288 | EXC_VIRT_NONE(0x4fe0, 0x20) | |
1289 | ||
1290 | EXC_REAL_NONE(0x1000, 0x100) | |
1291 | EXC_VIRT_NONE(0x5000, 0x100) | |
1292 | EXC_REAL_NONE(0x1100, 0x100) | |
1293 | EXC_VIRT_NONE(0x5100, 0x100) | |
d0c0c9a1 | 1294 | |
0ebc4cda | 1295 | #ifdef CONFIG_CBE_RAS |
1a6822d1 NP |
1296 | EXC_REAL_HV(cbe_system_error, 0x1200, 0x100) |
1297 | EXC_VIRT_NONE(0x5200, 0x100) | |
da2bc464 | 1298 | TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200) |
ff1b3206 | 1299 | EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception) |
da2bc464 | 1300 | #else /* CONFIG_CBE_RAS */ |
1a6822d1 NP |
1301 | EXC_REAL_NONE(0x1200, 0x100) |
1302 | EXC_VIRT_NONE(0x5200, 0x100) | |
da2bc464 | 1303 | #endif |
b01c8b54 | 1304 | |
ff1b3206 | 1305 | |
1a6822d1 NP |
1306 | EXC_REAL(instruction_breakpoint, 0x1300, 0x100) |
1307 | EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300) | |
da2bc464 | 1308 | TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300) |
4e96dbbf NP |
1309 | EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception) |
1310 | ||
1a6822d1 NP |
1311 | EXC_REAL_NONE(0x1400, 0x100) |
1312 | EXC_VIRT_NONE(0x5400, 0x100) | |
da2bc464 | 1313 | |
1a6822d1 | 1314 | EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100) |
b92a66a6 | 1315 | mtspr SPRN_SPRG_HSCRATCH0,r13 |
1707dd16 | 1316 | EXCEPTION_PROLOG_0(PACA_EXGEN) |
630573c1 | 1317 | EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500) |
b92a66a6 MN |
1318 | |
1319 | #ifdef CONFIG_PPC_DENORMALISATION | |
1320 | mfspr r10,SPRN_HSRR1 | |
1321 | mfspr r11,SPRN_HSRR0 /* save HSRR0 */ | |
afcf0095 NP |
1322 | andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */ |
1323 | addi r11,r11,-4 /* HSRR0 is next instruction */ | |
1324 | bne+ denorm_assist | |
1325 | #endif | |
1e9b4507 | 1326 | |
f175c5ce | 1327 | KVMTEST_HV(0x1500) |
afcf0095 | 1328 | EXCEPTION_PROLOG_PSERIES_1(denorm_common, EXC_HV) |
1a6822d1 | 1329 | EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100) |
a74599a5 | 1330 | |
d7e89849 | 1331 | #ifdef CONFIG_PPC_DENORMALISATION |
1a6822d1 | 1332 | EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100) |
d7e89849 | 1333 | b exc_real_0x1500_denorm_exception_hv |
1a6822d1 | 1334 | EXC_VIRT_END(denorm_exception, 0x5500, 0x100) |
d7e89849 | 1335 | #else |
1a6822d1 | 1336 | EXC_VIRT_NONE(0x5500, 0x100) |
afcf0095 NP |
1337 | #endif |
1338 | ||
f175c5ce | 1339 | TRAMP_KVM_HV(PACA_EXGEN, 0x1500) |
b01c8b54 | 1340 | |
b92a66a6 | 1341 | #ifdef CONFIG_PPC_DENORMALISATION |
da2bc464 | 1342 | TRAMP_REAL_BEGIN(denorm_assist) |
b92a66a6 MN |
1343 | BEGIN_FTR_SECTION |
1344 | /* | |
1345 | * To denormalise we need to move a copy of the register to itself. | |
1346 | * For POWER6 do that here for all FP regs. | |
1347 | */ | |
1348 | mfmsr r10 | |
1349 | ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1) | |
1350 | xori r10,r10,(MSR_FE0|MSR_FE1) | |
1351 | mtmsrd r10 | |
1352 | sync | |
d7c67fb1 MN |
1353 | |
1354 | #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1 | |
1355 | #define FMR4(n) FMR2(n) ; FMR2(n+2) | |
1356 | #define FMR8(n) FMR4(n) ; FMR4(n+4) | |
1357 | #define FMR16(n) FMR8(n) ; FMR8(n+8) | |
1358 | #define FMR32(n) FMR16(n) ; FMR16(n+16) | |
1359 | FMR32(0) | |
1360 | ||
b92a66a6 MN |
1361 | FTR_SECTION_ELSE |
1362 | /* | |
1363 | * To denormalise we need to move a copy of the register to itself. | |
1364 | * For POWER7 do that here for the first 32 VSX registers only. | |
1365 | */ | |
1366 | mfmsr r10 | |
1367 | oris r10,r10,MSR_VSX@h | |
1368 | mtmsrd r10 | |
1369 | sync | |
d7c67fb1 MN |
1370 | |
1371 | #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1) | |
1372 | #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2) | |
1373 | #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4) | |
1374 | #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8) | |
1375 | #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16) | |
1376 | XVCPSGNDP32(0) | |
1377 | ||
b92a66a6 | 1378 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206) |
fb0fce3e MN |
1379 | |
1380 | BEGIN_FTR_SECTION | |
1381 | b denorm_done | |
1382 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) | |
1383 | /* | |
1384 | * To denormalise we need to move a copy of the register to itself. | |
1385 | * For POWER8 we need to do that for all 64 VSX registers | |
1386 | */ | |
1387 | XVCPSGNDP32(32) | |
1388 | denorm_done: | |
b92a66a6 MN |
1389 | mtspr SPRN_HSRR0,r11 |
1390 | mtcrf 0x80,r9 | |
1391 | ld r9,PACA_EXGEN+EX_R9(r13) | |
44e9309f | 1392 | RESTORE_PPR_PACA(PACA_EXGEN, r10) |
630573c1 PM |
1393 | BEGIN_FTR_SECTION |
1394 | ld r10,PACA_EXGEN+EX_CFAR(r13) | |
1395 | mtspr SPRN_CFAR,r10 | |
1396 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) | |
b92a66a6 MN |
1397 | ld r10,PACA_EXGEN+EX_R10(r13) |
1398 | ld r11,PACA_EXGEN+EX_R11(r13) | |
1399 | ld r12,PACA_EXGEN+EX_R12(r13) | |
1400 | ld r13,PACA_EXGEN+EX_R13(r13) | |
222f20f1 | 1401 | HRFI_TO_UNKNOWN |
b92a66a6 MN |
1402 | b . |
1403 | #endif | |
1404 | ||
d7e89849 NP |
1405 | EXC_COMMON_HV(denorm_common, 0x1500, unknown_exception) |
1406 | ||
1407 | ||
1408 | #ifdef CONFIG_CBE_RAS | |
1a6822d1 NP |
1409 | EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100) |
1410 | EXC_VIRT_NONE(0x5600, 0x100) | |
d7e89849 | 1411 | TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600) |
69a79344 | 1412 | EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception) |
d7e89849 | 1413 | #else /* CONFIG_CBE_RAS */ |
1a6822d1 NP |
1414 | EXC_REAL_NONE(0x1600, 0x100) |
1415 | EXC_VIRT_NONE(0x5600, 0x100) | |
d7e89849 NP |
1416 | #endif |
1417 | ||
69a79344 | 1418 | |
1a6822d1 NP |
1419 | EXC_REAL(altivec_assist, 0x1700, 0x100) |
1420 | EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700) | |
d7e89849 | 1421 | TRAMP_KVM(PACA_EXGEN, 0x1700) |
b51c079e NP |
1422 | #ifdef CONFIG_ALTIVEC |
1423 | EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception) | |
1424 | #else | |
1425 | EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception) | |
1426 | #endif | |
1427 | ||
d7e89849 NP |
1428 | |
1429 | #ifdef CONFIG_CBE_RAS | |
1a6822d1 NP |
1430 | EXC_REAL_HV(cbe_thermal, 0x1800, 0x100) |
1431 | EXC_VIRT_NONE(0x5800, 0x100) | |
d7e89849 | 1432 | TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800) |
3965f8ab | 1433 | EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception) |
d7e89849 | 1434 | #else /* CONFIG_CBE_RAS */ |
1a6822d1 NP |
1435 | EXC_REAL_NONE(0x1800, 0x100) |
1436 | EXC_VIRT_NONE(0x5800, 0x100) | |
d7e89849 NP |
1437 | #endif |
1438 | ||
75eb767e | 1439 | #ifdef CONFIG_PPC_WATCHDOG |
2104180a NP |
1440 | |
1441 | #define MASKED_DEC_HANDLER_LABEL 3f | |
1442 | ||
1443 | #define MASKED_DEC_HANDLER(_H) \ | |
1444 | 3: /* soft-nmi */ \ | |
1445 | std r12,PACA_EXGEN+EX_R12(r13); \ | |
1446 | GET_SCRATCH0(r10); \ | |
1447 | std r10,PACA_EXGEN+EX_R13(r13); \ | |
1448 | EXCEPTION_PROLOG_PSERIES_1(soft_nmi_common, _H) | |
1449 | ||
cc491f1d NP |
1450 | /* |
1451 | * Branch to soft_nmi_interrupt using the emergency stack. The emergency | |
1452 | * stack is one that is usable by maskable interrupts so long as MSR_EE | |
1453 | * remains off. It is used for recovery when something has corrupted the | |
1454 | * normal kernel stack, for example. The "soft NMI" must not use the process | |
1455 | * stack because we want irq disabled sections to avoid touching the stack | |
1456 | * at all (other than PMU interrupts), so use the emergency stack for this, | |
1457 | * and run it entirely with interrupts hard disabled. | |
1458 | */ | |
2104180a NP |
1459 | EXC_COMMON_BEGIN(soft_nmi_common) |
1460 | mr r10,r1 | |
1461 | ld r1,PACAEMERGSP(r13) | |
2104180a NP |
1462 | subi r1,r1,INT_FRAME_SIZE |
1463 | EXCEPTION_COMMON_NORET_STACK(PACA_EXGEN, 0x900, | |
1464 | system_reset, soft_nmi_interrupt, | |
1465 | ADD_NVGPRS;ADD_RECONCILE) | |
1466 | b ret_from_except | |
1467 | ||
75eb767e | 1468 | #else /* CONFIG_PPC_WATCHDOG */ |
2104180a NP |
1469 | #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */ |
1470 | #define MASKED_DEC_HANDLER(_H) | |
75eb767e | 1471 | #endif /* CONFIG_PPC_WATCHDOG */ |
d7e89849 | 1472 | |
0ebc4cda | 1473 | /* |
fe9e1d54 IM |
1474 | * An interrupt came in while soft-disabled. We set paca->irq_happened, then: |
1475 | * - If it was a decrementer interrupt, we bump the dec to max and and return. | |
1476 | * - If it was a doorbell we return immediately since doorbells are edge | |
1477 | * triggered and won't automatically refire. | |
0869b6fd MS |
1478 | * - If it was a HMI we return immediately since we handled it in realmode |
1479 | * and it won't refire. | |
fe9e1d54 IM |
1480 | * - else we hard disable and return. |
1481 | * This is called with r10 containing the value to OR to the paca field. | |
0ebc4cda | 1482 | */ |
7230c564 BH |
1483 | #define MASKED_INTERRUPT(_H) \ |
1484 | masked_##_H##interrupt: \ | |
1485 | std r11,PACA_EXGEN+EX_R11(r13); \ | |
1486 | lbz r11,PACAIRQHAPPENED(r13); \ | |
1487 | or r11,r11,r10; \ | |
1488 | stb r11,PACAIRQHAPPENED(r13); \ | |
fe9e1d54 IM |
1489 | cmpwi r10,PACA_IRQ_DEC; \ |
1490 | bne 1f; \ | |
7230c564 BH |
1491 | lis r10,0x7fff; \ |
1492 | ori r10,r10,0xffff; \ | |
1493 | mtspr SPRN_DEC,r10; \ | |
2104180a | 1494 | b MASKED_DEC_HANDLER_LABEL; \ |
e0c827c0 NP |
1495 | 1: andi. r10,r10,(PACA_IRQ_DBELL|PACA_IRQ_HMI); \ |
1496 | bne 2f; \ | |
fe9e1d54 | 1497 | mfspr r10,SPRN_##_H##SRR1; \ |
6e9a2f6e | 1498 | xori r10,r10,MSR_EE; /* clear MSR_EE */ \ |
7230c564 BH |
1499 | mtspr SPRN_##_H##SRR1,r10; \ |
1500 | 2: mtcrf 0x80,r9; \ | |
1501 | ld r9,PACA_EXGEN+EX_R9(r13); \ | |
1502 | ld r10,PACA_EXGEN+EX_R10(r13); \ | |
1503 | ld r11,PACA_EXGEN+EX_R11(r13); \ | |
c05f0be8 | 1504 | /* returns to kernel where r13 must be set up, so don't restore it */ \ |
222f20f1 | 1505 | ##_H##RFI_TO_KERNEL; \ |
2104180a NP |
1506 | b .; \ |
1507 | MASKED_DEC_HANDLER(_H) | |
57f26649 | 1508 | |
cc437c1d NP |
1509 | TRAMP_REAL_BEGIN(stf_barrier_fallback) |
1510 | std r9,PACA_EXRFI+EX_R9(r13) | |
1511 | std r10,PACA_EXRFI+EX_R10(r13) | |
1512 | sync | |
1513 | ld r9,PACA_EXRFI+EX_R9(r13) | |
1514 | ld r10,PACA_EXRFI+EX_R10(r13) | |
1515 | ori 31,31,0 | |
1516 | .rept 14 | |
1517 | b 1f | |
1518 | 1: | |
1519 | .endr | |
1520 | blr | |
1521 | ||
aa8a5e00 ME |
1522 | TRAMP_REAL_BEGIN(rfi_flush_fallback) |
1523 | SET_SCRATCH0(r13); | |
1524 | GET_PACA(r13); | |
1525 | std r9,PACA_EXRFI+EX_R9(r13) | |
1526 | std r10,PACA_EXRFI+EX_R10(r13) | |
1527 | std r11,PACA_EXRFI+EX_R11(r13) | |
1528 | std r12,PACA_EXRFI+EX_R12(r13) | |
1529 | std r8,PACA_EXRFI+EX_R13(r13) | |
1530 | mfctr r9 | |
1531 | ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13) | |
1532 | ld r11,PACA_L1D_FLUSH_SETS(r13) | |
1533 | ld r12,PACA_L1D_FLUSH_CONGRUENCE(r13) | |
1534 | /* | |
1535 | * The load adresses are at staggered offsets within cachelines, | |
1536 | * which suits some pipelines better (on others it should not | |
1537 | * hurt). | |
1538 | */ | |
1539 | addi r12,r12,8 | |
1540 | mtctr r11 | |
1541 | DCBT_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */ | |
1542 | ||
1543 | /* order ld/st prior to dcbt stop all streams with flushing */ | |
1544 | sync | |
1545 | 1: li r8,0 | |
1546 | .rept 8 /* 8-way set associative */ | |
1547 | ldx r11,r10,r8 | |
1548 | add r8,r8,r12 | |
1549 | xor r11,r11,r11 // Ensure r11 is 0 even if fallback area is not | |
1550 | add r8,r8,r11 // Add 0, this creates a dependency on the ldx | |
1551 | .endr | |
1552 | addi r10,r10,128 /* 128 byte cache line */ | |
1553 | bdnz 1b | |
1554 | ||
1555 | mtctr r9 | |
1556 | ld r9,PACA_EXRFI+EX_R9(r13) | |
1557 | ld r10,PACA_EXRFI+EX_R10(r13) | |
1558 | ld r11,PACA_EXRFI+EX_R11(r13) | |
1559 | ld r12,PACA_EXRFI+EX_R12(r13) | |
1560 | ld r8,PACA_EXRFI+EX_R13(r13) | |
1561 | GET_SCRATCH0(r13); | |
1562 | rfid | |
1563 | ||
1564 | TRAMP_REAL_BEGIN(hrfi_flush_fallback) | |
1565 | SET_SCRATCH0(r13); | |
1566 | GET_PACA(r13); | |
1567 | std r9,PACA_EXRFI+EX_R9(r13) | |
1568 | std r10,PACA_EXRFI+EX_R10(r13) | |
1569 | std r11,PACA_EXRFI+EX_R11(r13) | |
1570 | std r12,PACA_EXRFI+EX_R12(r13) | |
1571 | std r8,PACA_EXRFI+EX_R13(r13) | |
1572 | mfctr r9 | |
1573 | ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13) | |
1574 | ld r11,PACA_L1D_FLUSH_SETS(r13) | |
1575 | ld r12,PACA_L1D_FLUSH_CONGRUENCE(r13) | |
1576 | /* | |
1577 | * The load adresses are at staggered offsets within cachelines, | |
1578 | * which suits some pipelines better (on others it should not | |
1579 | * hurt). | |
1580 | */ | |
1581 | addi r12,r12,8 | |
1582 | mtctr r11 | |
1583 | DCBT_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */ | |
1584 | ||
1585 | /* order ld/st prior to dcbt stop all streams with flushing */ | |
1586 | sync | |
1587 | 1: li r8,0 | |
1588 | .rept 8 /* 8-way set associative */ | |
1589 | ldx r11,r10,r8 | |
1590 | add r8,r8,r12 | |
1591 | xor r11,r11,r11 // Ensure r11 is 0 even if fallback area is not | |
1592 | add r8,r8,r11 // Add 0, this creates a dependency on the ldx | |
1593 | .endr | |
1594 | addi r10,r10,128 /* 128 byte cache line */ | |
1595 | bdnz 1b | |
1596 | ||
1597 | mtctr r9 | |
1598 | ld r9,PACA_EXRFI+EX_R9(r13) | |
1599 | ld r10,PACA_EXRFI+EX_R10(r13) | |
1600 | ld r11,PACA_EXRFI+EX_R11(r13) | |
1601 | ld r12,PACA_EXRFI+EX_R12(r13) | |
1602 | ld r8,PACA_EXRFI+EX_R13(r13) | |
1603 | GET_SCRATCH0(r13); | |
1604 | hrfid | |
1605 | ||
57f26649 NP |
1606 | /* |
1607 | * Real mode exceptions actually use this too, but alternate | |
1608 | * instruction code patches (which end up in the common .text area) | |
1609 | * cannot reach these if they are put there. | |
1610 | */ | |
1611 | USE_FIXED_SECTION(virt_trampolines) | |
7230c564 BH |
1612 | MASKED_INTERRUPT() |
1613 | MASKED_INTERRUPT(H) | |
0ebc4cda | 1614 | |
4f6c11db | 1615 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
da2bc464 | 1616 | TRAMP_REAL_BEGIN(kvmppc_skip_interrupt) |
4f6c11db PM |
1617 | /* |
1618 | * Here all GPRs are unchanged from when the interrupt happened | |
1619 | * except for r13, which is saved in SPRG_SCRATCH0. | |
1620 | */ | |
1621 | mfspr r13, SPRN_SRR0 | |
1622 | addi r13, r13, 4 | |
1623 | mtspr SPRN_SRR0, r13 | |
1624 | GET_SCRATCH0(r13) | |
222f20f1 | 1625 | RFI_TO_KERNEL |
4f6c11db PM |
1626 | b . |
1627 | ||
da2bc464 | 1628 | TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt) |
4f6c11db PM |
1629 | /* |
1630 | * Here all GPRs are unchanged from when the interrupt happened | |
1631 | * except for r13, which is saved in SPRG_SCRATCH0. | |
1632 | */ | |
1633 | mfspr r13, SPRN_HSRR0 | |
1634 | addi r13, r13, 4 | |
1635 | mtspr SPRN_HSRR0, r13 | |
1636 | GET_SCRATCH0(r13) | |
222f20f1 | 1637 | HRFI_TO_KERNEL |
4f6c11db PM |
1638 | b . |
1639 | #endif | |
1640 | ||
0ebc4cda | 1641 | /* |
057b6d7e HB |
1642 | * Ensure that any handlers that get invoked from the exception prologs |
1643 | * above are below the first 64KB (0x10000) of the kernel image because | |
1644 | * the prologs assemble the addresses of these handlers using the | |
1645 | * LOAD_HANDLER macro, which uses an ori instruction. | |
0ebc4cda BH |
1646 | */ |
1647 | ||
1648 | /*** Common interrupt handlers ***/ | |
1649 | ||
0ebc4cda | 1650 | |
c1fb6816 MN |
1651 | /* |
1652 | * Relocation-on interrupts: A subset of the interrupts can be delivered | |
1653 | * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering | |
1654 | * it. Addresses are the same as the original interrupt addresses, but | |
1655 | * offset by 0xc000000000004000. | |
1656 | * It's impossible to receive interrupts below 0x300 via this mechanism. | |
1657 | * KVM: None of these traps are from the guest ; anything that escalated | |
1658 | * to HV=1 from HV=0 is delivered via real mode handlers. | |
1659 | */ | |
1660 | ||
1661 | /* | |
1662 | * This uses the standard macro, since the original 0x300 vector | |
1663 | * only has extra guff for STAB-based processors -- which never | |
1664 | * come here. | |
1665 | */ | |
da2bc464 | 1666 | |
57f26649 | 1667 | EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline) |
b1576fec | 1668 | b __ppc64_runlatch_on |
fe1952fc | 1669 | |
57f26649 | 1670 | USE_FIXED_SECTION(virt_trampolines) |
8ed8ab40 HB |
1671 | /* |
1672 | * The __end_interrupts marker must be past the out-of-line (OOL) | |
1673 | * handlers, so that they are copied to real address 0x100 when running | |
1674 | * a relocatable kernel. This ensures they can be reached from the short | |
1675 | * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch | |
1676 | * directly, without using LOAD_HANDLER(). | |
1677 | */ | |
1678 | .align 7 | |
1679 | .globl __end_interrupts | |
1680 | __end_interrupts: | |
57f26649 | 1681 | DEFINE_FIXED_SYMBOL(__end_interrupts) |
61383407 | 1682 | |
087aa036 | 1683 | #ifdef CONFIG_PPC_970_NAP |
7c8cb4b5 | 1684 | EXC_COMMON_BEGIN(power4_fixup_nap) |
087aa036 CG |
1685 | andc r9,r9,r10 |
1686 | std r9,TI_LOCAL_FLAGS(r11) | |
1687 | ld r10,_LINK(r1) /* make idle task do the */ | |
1688 | std r10,_NIP(r1) /* equivalent of a blr */ | |
1689 | blr | |
1690 | #endif | |
1691 | ||
57f26649 NP |
1692 | CLOSE_FIXED_SECTION(real_vectors); |
1693 | CLOSE_FIXED_SECTION(real_trampolines); | |
1694 | CLOSE_FIXED_SECTION(virt_vectors); | |
1695 | CLOSE_FIXED_SECTION(virt_trampolines); | |
1696 | ||
1697 | USE_TEXT_SECTION() | |
1698 | ||
0ebc4cda BH |
1699 | /* |
1700 | * Hash table stuff | |
1701 | */ | |
f4329f2e | 1702 | .balign IFETCH_ALIGN_BYTES |
6a3bab90 | 1703 | do_hash_page: |
4e003747 | 1704 | #ifdef CONFIG_PPC_BOOK3S_64 |
f23ab3ef | 1705 | lis r0,(DSISR_BAD_FAULT_64S|DSISR_DABRMATCH)@h |
398a719d BH |
1706 | ori r0,r0,DSISR_BAD_FAULT_64S@l |
1707 | and. r0,r4,r0 /* weird error? */ | |
0ebc4cda | 1708 | bne- handle_page_fault /* if not, try to insert a HPTE */ |
9778b696 | 1709 | CURRENT_THREAD_INFO(r11, r1) |
9c1e1052 PM |
1710 | lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */ |
1711 | andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */ | |
1712 | bne 77f /* then don't call hash_page now */ | |
0ebc4cda BH |
1713 | |
1714 | /* | |
1715 | * r3 contains the faulting address | |
106713a1 | 1716 | * r4 msr |
0ebc4cda | 1717 | * r5 contains the trap number |
aefa5688 | 1718 | * r6 contains dsisr |
0ebc4cda | 1719 | * |
7230c564 | 1720 | * at return r3 = 0 for success, 1 for page fault, negative for error |
0ebc4cda | 1721 | */ |
106713a1 | 1722 | mr r4,r12 |
aefa5688 | 1723 | ld r6,_DSISR(r1) |
106713a1 AK |
1724 | bl __hash_page /* build HPTE if possible */ |
1725 | cmpdi r3,0 /* see if __hash_page succeeded */ | |
0ebc4cda | 1726 | |
7230c564 | 1727 | /* Success */ |
0ebc4cda | 1728 | beq fast_exc_return_irq /* Return from exception on success */ |
0ebc4cda | 1729 | |
7230c564 BH |
1730 | /* Error */ |
1731 | blt- 13f | |
d89ba535 NR |
1732 | |
1733 | /* Reload DSISR into r4 for the DABR check below */ | |
1734 | ld r4,_DSISR(r1) | |
4e003747 | 1735 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
9c7cc234 | 1736 | |
0ebc4cda BH |
1737 | /* Here we have a page fault that hash_page can't handle. */ |
1738 | handle_page_fault: | |
d89ba535 NR |
1739 | 11: andis. r0,r4,DSISR_DABRMATCH@h |
1740 | bne- handle_dabr_fault | |
1741 | ld r4,_DAR(r1) | |
0ebc4cda BH |
1742 | ld r5,_DSISR(r1) |
1743 | addi r3,r1,STACK_FRAME_OVERHEAD | |
b1576fec | 1744 | bl do_page_fault |
0ebc4cda | 1745 | cmpdi r3,0 |
a546498f | 1746 | beq+ 12f |
b1576fec | 1747 | bl save_nvgprs |
0ebc4cda BH |
1748 | mr r5,r3 |
1749 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1750 | lwz r4,_DAR(r1) | |
b1576fec AB |
1751 | bl bad_page_fault |
1752 | b ret_from_except | |
0ebc4cda | 1753 | |
a546498f BH |
1754 | /* We have a data breakpoint exception - handle it */ |
1755 | handle_dabr_fault: | |
b1576fec | 1756 | bl save_nvgprs |
a546498f BH |
1757 | ld r4,_DAR(r1) |
1758 | ld r5,_DSISR(r1) | |
1759 | addi r3,r1,STACK_FRAME_OVERHEAD | |
b1576fec AB |
1760 | bl do_break |
1761 | 12: b ret_from_except_lite | |
a546498f | 1762 | |
0ebc4cda | 1763 | |
4e003747 | 1764 | #ifdef CONFIG_PPC_BOOK3S_64 |
0ebc4cda BH |
1765 | /* We have a page fault that hash_page could handle but HV refused |
1766 | * the PTE insertion | |
1767 | */ | |
b1576fec | 1768 | 13: bl save_nvgprs |
0ebc4cda BH |
1769 | mr r5,r3 |
1770 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1771 | ld r4,_DAR(r1) | |
b1576fec AB |
1772 | bl low_hash_fault |
1773 | b ret_from_except | |
caca285e | 1774 | #endif |
0ebc4cda | 1775 | |
9c1e1052 PM |
1776 | /* |
1777 | * We come here as a result of a DSI at a point where we don't want | |
1778 | * to call hash_page, such as when we are accessing memory (possibly | |
1779 | * user memory) inside a PMU interrupt that occurred while interrupts | |
1780 | * were soft-disabled. We want to invoke the exception handler for | |
1781 | * the access, or panic if there isn't a handler. | |
1782 | */ | |
b1576fec | 1783 | 77: bl save_nvgprs |
9c1e1052 PM |
1784 | mr r4,r3 |
1785 | addi r3,r1,STACK_FRAME_OVERHEAD | |
1786 | li r5,SIGSEGV | |
b1576fec AB |
1787 | bl bad_page_fault |
1788 | b ret_from_except | |
4e2bf01b ME |
1789 | |
1790 | /* | |
1791 | * Here we have detected that the kernel stack pointer is bad. | |
1792 | * R9 contains the saved CR, r13 points to the paca, | |
1793 | * r10 contains the (bad) kernel stack pointer, | |
1794 | * r11 and r12 contain the saved SRR0 and SRR1. | |
1795 | * We switch to using an emergency stack, save the registers there, | |
1796 | * and call kernel_bad_stack(), which panics. | |
1797 | */ | |
1798 | bad_stack: | |
1799 | ld r1,PACAEMERGSP(r13) | |
1800 | subi r1,r1,64+INT_FRAME_SIZE | |
1801 | std r9,_CCR(r1) | |
1802 | std r10,GPR1(r1) | |
1803 | std r11,_NIP(r1) | |
1804 | std r12,_MSR(r1) | |
1805 | mfspr r11,SPRN_DAR | |
1806 | mfspr r12,SPRN_DSISR | |
1807 | std r11,_DAR(r1) | |
1808 | std r12,_DSISR(r1) | |
1809 | mflr r10 | |
1810 | mfctr r11 | |
1811 | mfxer r12 | |
1812 | std r10,_LINK(r1) | |
1813 | std r11,_CTR(r1) | |
1814 | std r12,_XER(r1) | |
1815 | SAVE_GPR(0,r1) | |
1816 | SAVE_GPR(2,r1) | |
1817 | ld r10,EX_R3(r3) | |
1818 | std r10,GPR3(r1) | |
1819 | SAVE_GPR(4,r1) | |
1820 | SAVE_4GPRS(5,r1) | |
1821 | ld r9,EX_R9(r3) | |
1822 | ld r10,EX_R10(r3) | |
1823 | SAVE_2GPRS(9,r1) | |
1824 | ld r9,EX_R11(r3) | |
1825 | ld r10,EX_R12(r3) | |
1826 | ld r11,EX_R13(r3) | |
1827 | std r9,GPR11(r1) | |
1828 | std r10,GPR12(r1) | |
1829 | std r11,GPR13(r1) | |
1830 | BEGIN_FTR_SECTION | |
1831 | ld r10,EX_CFAR(r3) | |
1832 | std r10,ORIG_GPR3(r1) | |
1833 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) | |
1834 | SAVE_8GPRS(14,r1) | |
1835 | SAVE_10GPRS(22,r1) | |
1836 | lhz r12,PACA_TRAP_SAVE(r13) | |
1837 | std r12,_TRAP(r1) | |
1838 | addi r11,r1,INT_FRAME_SIZE | |
1839 | std r11,0(r1) | |
1840 | li r12,0 | |
1841 | std r12,0(r11) | |
1842 | ld r2,PACATOC(r13) | |
1843 | ld r11,exception_marker@toc(r2) | |
1844 | std r12,RESULT(r1) | |
1845 | std r11,STACK_FRAME_OVERHEAD-16(r1) | |
1846 | 1: addi r3,r1,STACK_FRAME_OVERHEAD | |
1847 | bl kernel_bad_stack | |
1848 | b 1b | |
15770a13 | 1849 | _ASM_NOKPROBE_SYMBOL(bad_stack); |
0f0c6ca1 | 1850 | |
a9af97aa NP |
1851 | /* |
1852 | * When doorbell is triggered from system reset wakeup, the message is | |
1853 | * not cleared, so it would fire again when EE is enabled. | |
1854 | * | |
1855 | * When coming from local_irq_enable, there may be the same problem if | |
1856 | * we were hard disabled. | |
1857 | * | |
1858 | * Execute msgclr to clear pending exceptions before handling it. | |
1859 | */ | |
1860 | h_doorbell_common_msgclr: | |
1861 | LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36)) | |
1862 | PPC_MSGCLR(3) | |
1863 | b h_doorbell_common | |
1864 | ||
1865 | doorbell_super_common_msgclr: | |
1866 | LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36)) | |
1867 | PPC_MSGCLRP(3) | |
1868 | b doorbell_super_common | |
1869 | ||
0f0c6ca1 NP |
1870 | /* |
1871 | * Called from arch_local_irq_enable when an interrupt needs | |
1872 | * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate | |
1873 | * which kind of interrupt. MSR:EE is already off. We generate a | |
1874 | * stackframe like if a real interrupt had happened. | |
1875 | * | |
1876 | * Note: While MSR:EE is off, we need to make sure that _MSR | |
1877 | * in the generated frame has EE set to 1 or the exception | |
1878 | * handler will not properly re-enable them. | |
b48bbb82 NP |
1879 | * |
1880 | * Note that we don't specify LR as the NIP (return address) for | |
1881 | * the interrupt because that would unbalance the return branch | |
1882 | * predictor. | |
0f0c6ca1 NP |
1883 | */ |
1884 | _GLOBAL(__replay_interrupt) | |
1885 | /* We are going to jump to the exception common code which | |
1886 | * will retrieve various register values from the PACA which | |
1887 | * we don't give a damn about, so we don't bother storing them. | |
1888 | */ | |
1889 | mfmsr r12 | |
3e23a12b | 1890 | LOAD_REG_ADDR(r11, replay_interrupt_return) |
0f0c6ca1 NP |
1891 | mfcr r9 |
1892 | ori r12,r12,MSR_EE | |
1893 | cmpwi r3,0x900 | |
1894 | beq decrementer_common | |
1895 | cmpwi r3,0x500 | |
e6c1203d NP |
1896 | BEGIN_FTR_SECTION |
1897 | beq h_virt_irq_common | |
1898 | FTR_SECTION_ELSE | |
0f0c6ca1 | 1899 | beq hardware_interrupt_common |
e6c1203d | 1900 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300) |
0f0c6ca1 | 1901 | BEGIN_FTR_SECTION |
d6f73fc6 | 1902 | cmpwi r3,0xa00 |
a9af97aa | 1903 | beq h_doorbell_common_msgclr |
0f0c6ca1 NP |
1904 | cmpwi r3,0xe60 |
1905 | beq hmi_exception_common | |
1906 | FTR_SECTION_ELSE | |
1907 | cmpwi r3,0xa00 | |
a9af97aa | 1908 | beq doorbell_super_common_msgclr |
0f0c6ca1 | 1909 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) |
3e23a12b | 1910 | replay_interrupt_return: |
0f0c6ca1 | 1911 | blr |
b48bbb82 | 1912 | |
15770a13 | 1913 | _ASM_NOKPROBE_SYMBOL(__replay_interrupt) |