exceptions-64s.S 52 KB

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