exception-64s.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. #ifndef _ASM_POWERPC_EXCEPTION_H
  2. #define _ASM_POWERPC_EXCEPTION_H
  3. /*
  4. * Extracted from head_64.S
  5. *
  6. * PowerPC version
  7. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  8. *
  9. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  10. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  11. * Adapted for Power Macintosh by Paul Mackerras.
  12. * Low-level exception handlers and MMU support
  13. * rewritten by Paul Mackerras.
  14. * Copyright (C) 1996 Paul Mackerras.
  15. *
  16. * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
  17. * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
  18. *
  19. * This file contains the low-level support and setup for the
  20. * PowerPC-64 platform, including trap and interrupt dispatch.
  21. *
  22. * This program is free software; you can redistribute it and/or
  23. * modify it under the terms of the GNU General Public License
  24. * as published by the Free Software Foundation; either version
  25. * 2 of the License, or (at your option) any later version.
  26. */
  27. /*
  28. * The following macros define the code that appears as
  29. * the prologue to each of the exception handlers. They
  30. * are split into two parts to allow a single kernel binary
  31. * to be used for pSeries and iSeries.
  32. *
  33. * We make as much of the exception code common between native
  34. * exception handlers (including pSeries LPAR) and iSeries LPAR
  35. * implementations as possible.
  36. */
  37. #include <asm/head-64.h>
  38. #define EX_R9 0
  39. #define EX_R10 8
  40. #define EX_R11 16
  41. #define EX_R12 24
  42. #define EX_R13 32
  43. #define EX_SRR0 40
  44. #define EX_DAR 48
  45. #define EX_DSISR 56
  46. #define EX_CCR 60
  47. #define EX_R3 64
  48. #define EX_LR 72
  49. #define EX_CFAR 80
  50. #define EX_PPR 88 /* SMT thread status register (priority) */
  51. #define EX_CTR 96
  52. #define STF_ENTRY_BARRIER_SLOT \
  53. STF_ENTRY_BARRIER_FIXUP_SECTION; \
  54. nop; \
  55. nop; \
  56. nop
  57. #define STF_EXIT_BARRIER_SLOT \
  58. STF_EXIT_BARRIER_FIXUP_SECTION; \
  59. nop; \
  60. nop; \
  61. nop; \
  62. nop; \
  63. nop; \
  64. nop
  65. /*
  66. * r10 must be free to use, r13 must be paca
  67. */
  68. #define INTERRUPT_TO_KERNEL \
  69. STF_ENTRY_BARRIER_SLOT
  70. /*
  71. * Macros for annotating the expected destination of (h)rfid
  72. *
  73. * The nop instructions allow us to insert one or more instructions to flush the
  74. * L1-D cache when returning to userspace or a guest.
  75. */
  76. #define RFI_FLUSH_SLOT \
  77. RFI_FLUSH_FIXUP_SECTION; \
  78. nop; \
  79. nop; \
  80. nop
  81. #define RFI_TO_KERNEL \
  82. rfid
  83. #define RFI_TO_USER \
  84. STF_EXIT_BARRIER_SLOT; \
  85. RFI_FLUSH_SLOT; \
  86. rfid; \
  87. b rfi_flush_fallback
  88. #define RFI_TO_USER_OR_KERNEL \
  89. STF_EXIT_BARRIER_SLOT; \
  90. RFI_FLUSH_SLOT; \
  91. rfid; \
  92. b rfi_flush_fallback
  93. #define RFI_TO_GUEST \
  94. STF_EXIT_BARRIER_SLOT; \
  95. RFI_FLUSH_SLOT; \
  96. rfid; \
  97. b rfi_flush_fallback
  98. #define HRFI_TO_KERNEL \
  99. hrfid
  100. #define HRFI_TO_USER \
  101. STF_EXIT_BARRIER_SLOT; \
  102. RFI_FLUSH_SLOT; \
  103. hrfid; \
  104. b hrfi_flush_fallback
  105. #define HRFI_TO_USER_OR_KERNEL \
  106. STF_EXIT_BARRIER_SLOT; \
  107. RFI_FLUSH_SLOT; \
  108. hrfid; \
  109. b hrfi_flush_fallback
  110. #define HRFI_TO_GUEST \
  111. STF_EXIT_BARRIER_SLOT; \
  112. RFI_FLUSH_SLOT; \
  113. hrfid; \
  114. b hrfi_flush_fallback
  115. #define HRFI_TO_UNKNOWN \
  116. STF_EXIT_BARRIER_SLOT; \
  117. RFI_FLUSH_SLOT; \
  118. hrfid; \
  119. b hrfi_flush_fallback
  120. #ifdef CONFIG_RELOCATABLE
  121. #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
  122. mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
  123. LOAD_HANDLER(r12,label); \
  124. mtctr r12; \
  125. mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
  126. li r10,MSR_RI; \
  127. mtmsrd r10,1; /* Set RI (EE=0) */ \
  128. bctr;
  129. #else
  130. /* If not relocatable, we can jump directly -- and save messing with LR */
  131. #define __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
  132. mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
  133. mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
  134. li r10,MSR_RI; \
  135. mtmsrd r10,1; /* Set RI (EE=0) */ \
  136. b label;
  137. #endif
  138. #define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
  139. __EXCEPTION_RELON_PROLOG_PSERIES_1(label, h) \
  140. /*
  141. * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on
  142. * so no need to rfid. Save lr in case we're CONFIG_RELOCATABLE, in which
  143. * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr.
  144. */
  145. #define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec) \
  146. EXCEPTION_PROLOG_0(area); \
  147. EXCEPTION_PROLOG_1(area, extra, vec); \
  148. EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
  149. /*
  150. * We're short on space and time in the exception prolog, so we can't
  151. * use the normal LOAD_REG_IMMEDIATE macro to load the address of label.
  152. * Instead we get the base of the kernel from paca->kernelbase and or in the low
  153. * part of label. This requires that the label be within 64KB of kernelbase, and
  154. * that kernelbase be 64K aligned.
  155. */
  156. #define LOAD_HANDLER(reg, label) \
  157. ld reg,PACAKBASE(r13); /* get high part of &label */ \
  158. ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label);
  159. #define __LOAD_HANDLER(reg, label) \
  160. ld reg,PACAKBASE(r13); \
  161. ori reg,reg,(ABS_ADDR(label))@l;
  162. /* Exception register prefixes */
  163. #define EXC_HV H
  164. #define EXC_STD
  165. #if defined(CONFIG_RELOCATABLE)
  166. /*
  167. * If we support interrupts with relocation on AND we're a relocatable kernel,
  168. * we need to use CTR to get to the 2nd level handler. So, save/restore it
  169. * when required.
  170. */
  171. #define SAVE_CTR(reg, area) mfctr reg ; std reg,area+EX_CTR(r13)
  172. #define GET_CTR(reg, area) ld reg,area+EX_CTR(r13)
  173. #define RESTORE_CTR(reg, area) ld reg,area+EX_CTR(r13) ; mtctr reg
  174. #else
  175. /* ...else CTR is unused and in register. */
  176. #define SAVE_CTR(reg, area)
  177. #define GET_CTR(reg, area) mfctr reg
  178. #define RESTORE_CTR(reg, area)
  179. #endif
  180. /*
  181. * PPR save/restore macros used in exceptions_64s.S
  182. * Used for P7 or later processors
  183. */
  184. #define SAVE_PPR(area, ra, rb) \
  185. BEGIN_FTR_SECTION_NESTED(940) \
  186. ld ra,PACACURRENT(r13); \
  187. ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \
  188. std rb,TASKTHREADPPR(ra); \
  189. END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940)
  190. #define RESTORE_PPR_PACA(area, ra) \
  191. BEGIN_FTR_SECTION_NESTED(941) \
  192. ld ra,area+EX_PPR(r13); \
  193. mtspr SPRN_PPR,ra; \
  194. END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,941)
  195. /*
  196. * Get an SPR into a register if the CPU has the given feature
  197. */
  198. #define OPT_GET_SPR(ra, spr, ftr) \
  199. BEGIN_FTR_SECTION_NESTED(943) \
  200. mfspr ra,spr; \
  201. END_FTR_SECTION_NESTED(ftr,ftr,943)
  202. /*
  203. * Set an SPR from a register if the CPU has the given feature
  204. */
  205. #define OPT_SET_SPR(ra, spr, ftr) \
  206. BEGIN_FTR_SECTION_NESTED(943) \
  207. mtspr spr,ra; \
  208. END_FTR_SECTION_NESTED(ftr,ftr,943)
  209. /*
  210. * Save a register to the PACA if the CPU has the given feature
  211. */
  212. #define OPT_SAVE_REG_TO_PACA(offset, ra, ftr) \
  213. BEGIN_FTR_SECTION_NESTED(943) \
  214. std ra,offset(r13); \
  215. END_FTR_SECTION_NESTED(ftr,ftr,943)
  216. #define EXCEPTION_PROLOG_0_PACA(area) \
  217. std r9,area+EX_R9(r13); /* save r9 */ \
  218. OPT_GET_SPR(r9, SPRN_PPR, CPU_FTR_HAS_PPR); \
  219. HMT_MEDIUM; \
  220. std r10,area+EX_R10(r13); /* save r10 - r12 */ \
  221. OPT_GET_SPR(r10, SPRN_CFAR, CPU_FTR_CFAR)
  222. #define EXCEPTION_PROLOG_0(area) \
  223. GET_PACA(r13); \
  224. EXCEPTION_PROLOG_0_PACA(area)
  225. #define __EXCEPTION_PROLOG_1(area, extra, vec) \
  226. OPT_SAVE_REG_TO_PACA(area+EX_PPR, r9, CPU_FTR_HAS_PPR); \
  227. OPT_SAVE_REG_TO_PACA(area+EX_CFAR, r10, CPU_FTR_CFAR); \
  228. INTERRUPT_TO_KERNEL; \
  229. SAVE_CTR(r10, area); \
  230. mfcr r9; \
  231. extra(vec); \
  232. std r11,area+EX_R11(r13); \
  233. std r12,area+EX_R12(r13); \
  234. GET_SCRATCH0(r10); \
  235. std r10,area+EX_R13(r13)
  236. #define EXCEPTION_PROLOG_1(area, extra, vec) \
  237. __EXCEPTION_PROLOG_1(area, extra, vec)
  238. #define __EXCEPTION_PROLOG_PSERIES_1(label, h) \
  239. ld r10,PACAKMSR(r13); /* get MSR value for kernel */ \
  240. mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \
  241. LOAD_HANDLER(r12,label) \
  242. mtspr SPRN_##h##SRR0,r12; \
  243. mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \
  244. mtspr SPRN_##h##SRR1,r10; \
  245. h##RFI_TO_KERNEL; \
  246. b . /* prevent speculative execution */
  247. #define EXCEPTION_PROLOG_PSERIES_1(label, h) \
  248. __EXCEPTION_PROLOG_PSERIES_1(label, h)
  249. #define EXCEPTION_PROLOG_PSERIES(area, label, h, extra, vec) \
  250. EXCEPTION_PROLOG_0(area); \
  251. EXCEPTION_PROLOG_1(area, extra, vec); \
  252. EXCEPTION_PROLOG_PSERIES_1(label, h);
  253. /* Have the PACA in r13 already */
  254. #define EXCEPTION_PROLOG_PSERIES_PACA(area, label, h, extra, vec) \
  255. EXCEPTION_PROLOG_0_PACA(area); \
  256. EXCEPTION_PROLOG_1(area, extra, vec); \
  257. EXCEPTION_PROLOG_PSERIES_1(label, h);
  258. #define __KVMTEST(h, n) \
  259. lbz r10,HSTATE_IN_GUEST(r13); \
  260. cmpwi r10,0; \
  261. bne do_kvm_##h##n
  262. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  263. /*
  264. * If hv is possible, interrupts come into to the hv version
  265. * of the kvmppc_interrupt code, which then jumps to the PR handler,
  266. * kvmppc_interrupt_pr, if the guest is a PR guest.
  267. */
  268. #define kvmppc_interrupt kvmppc_interrupt_hv
  269. #else
  270. #define kvmppc_interrupt kvmppc_interrupt_pr
  271. #endif
  272. #ifdef CONFIG_RELOCATABLE
  273. #define BRANCH_TO_COMMON(reg, label) \
  274. __LOAD_HANDLER(reg, label); \
  275. mtctr reg; \
  276. bctr
  277. #else
  278. #define BRANCH_TO_COMMON(reg, label) \
  279. b label
  280. #endif
  281. #define __KVM_HANDLER_PROLOG(area, n) \
  282. BEGIN_FTR_SECTION_NESTED(947) \
  283. ld r10,area+EX_CFAR(r13); \
  284. std r10,HSTATE_CFAR(r13); \
  285. END_FTR_SECTION_NESTED(CPU_FTR_CFAR,CPU_FTR_CFAR,947); \
  286. BEGIN_FTR_SECTION_NESTED(948) \
  287. ld r10,area+EX_PPR(r13); \
  288. std r10,HSTATE_PPR(r13); \
  289. END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
  290. ld r10,area+EX_R10(r13); \
  291. stw r9,HSTATE_SCRATCH1(r13); \
  292. ld r9,area+EX_R9(r13); \
  293. std r12,HSTATE_SCRATCH0(r13); \
  294. #define __KVM_HANDLER(area, h, n) \
  295. __KVM_HANDLER_PROLOG(area, n) \
  296. li r12,n; \
  297. b kvmppc_interrupt
  298. #define __KVM_HANDLER_SKIP(area, h, n) \
  299. cmpwi r10,KVM_GUEST_MODE_SKIP; \
  300. ld r10,area+EX_R10(r13); \
  301. beq 89f; \
  302. stw r9,HSTATE_SCRATCH1(r13); \
  303. BEGIN_FTR_SECTION_NESTED(948) \
  304. ld r9,area+EX_PPR(r13); \
  305. std r9,HSTATE_PPR(r13); \
  306. END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,948); \
  307. ld r9,area+EX_R9(r13); \
  308. std r12,HSTATE_SCRATCH0(r13); \
  309. li r12,n; \
  310. b kvmppc_interrupt; \
  311. 89: mtocrf 0x80,r9; \
  312. ld r9,area+EX_R9(r13); \
  313. b kvmppc_skip_##h##interrupt
  314. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  315. #define KVMTEST(h, n) __KVMTEST(h, n)
  316. #define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n)
  317. #define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n)
  318. #else
  319. #define KVMTEST(h, n)
  320. #define KVM_HANDLER(area, h, n)
  321. #define KVM_HANDLER_SKIP(area, h, n)
  322. #endif
  323. #define NOTEST(n)
  324. /*
  325. * The common exception prolog is used for all except a few exceptions
  326. * such as a segment miss on a kernel address. We have to be prepared
  327. * to take another exception from the point where we first touch the
  328. * kernel stack onwards.
  329. *
  330. * On entry r13 points to the paca, r9-r13 are saved in the paca,
  331. * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
  332. * SRR1, and relocation is on.
  333. */
  334. #define EXCEPTION_PROLOG_COMMON(n, area) \
  335. andi. r10,r12,MSR_PR; /* See if coming from user */ \
  336. mr r10,r1; /* Save r1 */ \
  337. subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \
  338. beq- 1f; \
  339. ld r1,PACAKSAVE(r13); /* kernel stack to use */ \
  340. 1: cmpdi cr1,r1,-INT_FRAME_SIZE; /* check if r1 is in userspace */ \
  341. blt+ cr1,3f; /* abort if it is */ \
  342. li r1,(n); /* will be reloaded later */ \
  343. sth r1,PACA_TRAP_SAVE(r13); \
  344. std r3,area+EX_R3(r13); \
  345. addi r3,r13,area; /* r3 -> where regs are saved*/ \
  346. RESTORE_CTR(r1, area); \
  347. b bad_stack; \
  348. 3: std r9,_CCR(r1); /* save CR in stackframe */ \
  349. std r11,_NIP(r1); /* save SRR0 in stackframe */ \
  350. std r12,_MSR(r1); /* save SRR1 in stackframe */ \
  351. std r10,0(r1); /* make stack chain pointer */ \
  352. std r0,GPR0(r1); /* save r0 in stackframe */ \
  353. std r10,GPR1(r1); /* save r1 in stackframe */ \
  354. beq 4f; /* if from kernel mode */ \
  355. ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \
  356. SAVE_PPR(area, r9, r10); \
  357. 4: EXCEPTION_PROLOG_COMMON_2(area) \
  358. EXCEPTION_PROLOG_COMMON_3(n) \
  359. ACCOUNT_STOLEN_TIME
  360. /* Save original regs values from save area to stack frame. */
  361. #define EXCEPTION_PROLOG_COMMON_2(area) \
  362. ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \
  363. ld r10,area+EX_R10(r13); \
  364. std r9,GPR9(r1); \
  365. std r10,GPR10(r1); \
  366. ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \
  367. ld r10,area+EX_R12(r13); \
  368. ld r11,area+EX_R13(r13); \
  369. std r9,GPR11(r1); \
  370. std r10,GPR12(r1); \
  371. std r11,GPR13(r1); \
  372. BEGIN_FTR_SECTION_NESTED(66); \
  373. ld r10,area+EX_CFAR(r13); \
  374. std r10,ORIG_GPR3(r1); \
  375. END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \
  376. GET_CTR(r10, area); \
  377. std r10,_CTR(r1);
  378. #define EXCEPTION_PROLOG_COMMON_3(n) \
  379. std r2,GPR2(r1); /* save r2 in stackframe */ \
  380. SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \
  381. SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \
  382. mflr r9; /* Get LR, later save to stack */ \
  383. ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \
  384. std r9,_LINK(r1); \
  385. lbz r10,PACASOFTIRQEN(r13); \
  386. mfspr r11,SPRN_XER; /* save XER in stackframe */ \
  387. std r10,SOFTE(r1); \
  388. std r11,_XER(r1); \
  389. li r9,(n)+1; \
  390. std r9,_TRAP(r1); /* set trap number */ \
  391. li r10,0; \
  392. ld r11,exception_marker@toc(r2); \
  393. std r10,RESULT(r1); /* clear regs->result */ \
  394. std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */
  395. /*
  396. * Exception vectors.
  397. */
  398. #define STD_EXCEPTION_PSERIES(vec, label) \
  399. SET_SCRATCH0(r13); /* save r13 */ \
  400. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
  401. EXC_STD, KVMTEST_PR, vec); \
  402. /* Version of above for when we have to branch out-of-line */
  403. #define __OOL_EXCEPTION(vec, label, hdlr) \
  404. SET_SCRATCH0(r13) \
  405. EXCEPTION_PROLOG_0(PACA_EXGEN) \
  406. b hdlr;
  407. #define STD_EXCEPTION_PSERIES_OOL(vec, label) \
  408. EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_PR, vec); \
  409. EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
  410. #define STD_EXCEPTION_HV(loc, vec, label) \
  411. SET_SCRATCH0(r13); /* save r13 */ \
  412. EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label, \
  413. EXC_HV, KVMTEST_HV, vec);
  414. #define STD_EXCEPTION_HV_OOL(vec, label) \
  415. EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \
  416. EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
  417. #define STD_RELON_EXCEPTION_PSERIES(loc, vec, label) \
  418. /* No guest interrupts come through here */ \
  419. SET_SCRATCH0(r13); /* save r13 */ \
  420. EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_STD, NOTEST, vec);
  421. #define STD_RELON_EXCEPTION_PSERIES_OOL(vec, label) \
  422. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \
  423. EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_STD)
  424. #define STD_RELON_EXCEPTION_HV(loc, vec, label) \
  425. /* No guest interrupts come through here */ \
  426. SET_SCRATCH0(r13); /* save r13 */ \
  427. EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, EXC_HV, NOTEST, vec);
  428. #define STD_RELON_EXCEPTION_HV_OOL(vec, label) \
  429. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, vec); \
  430. EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV)
  431. /* This associate vector numbers with bits in paca->irq_happened */
  432. #define SOFTEN_VALUE_0x500 PACA_IRQ_EE
  433. #define SOFTEN_VALUE_0x900 PACA_IRQ_DEC
  434. #define SOFTEN_VALUE_0x980 PACA_IRQ_DEC
  435. #define SOFTEN_VALUE_0xa00 PACA_IRQ_DBELL
  436. #define SOFTEN_VALUE_0xe80 PACA_IRQ_DBELL
  437. #define SOFTEN_VALUE_0xe60 PACA_IRQ_HMI
  438. #define SOFTEN_VALUE_0xea0 PACA_IRQ_EE
  439. #define __SOFTEN_TEST(h, vec) \
  440. lbz r10,PACASOFTIRQEN(r13); \
  441. cmpwi r10,0; \
  442. li r10,SOFTEN_VALUE_##vec; \
  443. beq masked_##h##interrupt
  444. #define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec)
  445. #define SOFTEN_TEST_PR(vec) \
  446. KVMTEST(EXC_STD, vec); \
  447. _SOFTEN_TEST(EXC_STD, vec)
  448. #define SOFTEN_TEST_HV(vec) \
  449. KVMTEST(EXC_HV, vec); \
  450. _SOFTEN_TEST(EXC_HV, vec)
  451. #define KVMTEST_PR(vec) \
  452. KVMTEST(EXC_STD, vec)
  453. #define KVMTEST_HV(vec) \
  454. KVMTEST(EXC_HV, vec)
  455. #define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec)
  456. #define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec)
  457. #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
  458. SET_SCRATCH0(r13); /* save r13 */ \
  459. EXCEPTION_PROLOG_0(PACA_EXGEN); \
  460. __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
  461. EXCEPTION_PROLOG_PSERIES_1(label, h);
  462. #define _MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra) \
  463. __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)
  464. #define MASKABLE_EXCEPTION_PSERIES(loc, vec, label) \
  465. _MASKABLE_EXCEPTION_PSERIES(vec, label, \
  466. EXC_STD, SOFTEN_TEST_PR)
  467. #define MASKABLE_EXCEPTION_PSERIES_OOL(vec, label) \
  468. EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_PR, vec); \
  469. EXCEPTION_PROLOG_PSERIES_1(label, EXC_STD)
  470. #define MASKABLE_EXCEPTION_HV(loc, vec, label) \
  471. _MASKABLE_EXCEPTION_PSERIES(vec, label, \
  472. EXC_HV, SOFTEN_TEST_HV)
  473. #define MASKABLE_EXCEPTION_HV_OOL(vec, label) \
  474. EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \
  475. EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
  476. #define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
  477. SET_SCRATCH0(r13); /* save r13 */ \
  478. EXCEPTION_PROLOG_0(PACA_EXGEN); \
  479. __EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec); \
  480. EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
  481. #define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra) \
  482. __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)
  483. #define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label) \
  484. _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
  485. EXC_STD, SOFTEN_NOTEST_PR)
  486. #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \
  487. _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \
  488. EXC_HV, SOFTEN_NOTEST_HV)
  489. #define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label) \
  490. EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_NOTEST_HV, vec); \
  491. EXCEPTION_PROLOG_PSERIES_1(label, EXC_HV)
  492. /*
  493. * Our exception common code can be passed various "additions"
  494. * to specify the behaviour of interrupts, whether to kick the
  495. * runlatch, etc...
  496. */
  497. /*
  498. * This addition reconciles our actual IRQ state with the various software
  499. * flags that track it. This may call C code.
  500. */
  501. #define ADD_RECONCILE RECONCILE_IRQ_STATE(r10,r11)
  502. #define ADD_NVGPRS \
  503. bl save_nvgprs
  504. #define RUNLATCH_ON \
  505. BEGIN_FTR_SECTION \
  506. CURRENT_THREAD_INFO(r3, r1); \
  507. ld r4,TI_LOCAL_FLAGS(r3); \
  508. andi. r0,r4,_TLF_RUNLATCH; \
  509. beql ppc64_runlatch_on_trampoline; \
  510. END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
  511. #define EXCEPTION_COMMON(trap, label, hdlr, ret, additions) \
  512. EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \
  513. /* Volatile regs are potentially clobbered here */ \
  514. additions; \
  515. addi r3,r1,STACK_FRAME_OVERHEAD; \
  516. bl hdlr; \
  517. b ret
  518. #define STD_EXCEPTION_COMMON(trap, label, hdlr) \
  519. EXCEPTION_COMMON(trap, label, hdlr, ret_from_except, \
  520. ADD_NVGPRS;ADD_RECONCILE)
  521. /*
  522. * Like STD_EXCEPTION_COMMON, but for exceptions that can occur
  523. * in the idle task and therefore need the special idle handling
  524. * (finish nap and runlatch)
  525. */
  526. #define STD_EXCEPTION_COMMON_ASYNC(trap, label, hdlr) \
  527. EXCEPTION_COMMON(trap, label, hdlr, ret_from_except_lite, \
  528. FINISH_NAP;ADD_RECONCILE;RUNLATCH_ON)
  529. /*
  530. * When the idle code in power4_idle puts the CPU into NAP mode,
  531. * it has to do so in a loop, and relies on the external interrupt
  532. * and decrementer interrupt entry code to get it out of the loop.
  533. * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags
  534. * to signal that it is in the loop and needs help to get out.
  535. */
  536. #ifdef CONFIG_PPC_970_NAP
  537. #define FINISH_NAP \
  538. BEGIN_FTR_SECTION \
  539. CURRENT_THREAD_INFO(r11, r1); \
  540. ld r9,TI_LOCAL_FLAGS(r11); \
  541. andi. r10,r9,_TLF_NAPPING; \
  542. bnel power4_fixup_nap; \
  543. END_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP)
  544. #else
  545. #define FINISH_NAP
  546. #endif
  547. #endif /* _ASM_POWERPC_EXCEPTION_H */