exceptions-64s.S 54 KB

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