exceptions-64s.S 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140
  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 <linux/linkage.h>
  16. #include <asm/hw_irq.h>
  17. #include <asm/exception-64s.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/cpuidle.h>
  20. #include <asm/head-64.h>
  21. #include <asm/feature-fixups.h>
  22. #include <asm/kup.h>
  23. /*
  24. * Following are fixed section helper macros.
  25. *
  26. * EXC_REAL_BEGIN/END - real, unrelocated exception vectors
  27. * EXC_VIRT_BEGIN/END - virt (AIL), unrelocated exception vectors
  28. * TRAMP_REAL_BEGIN - real, unrelocated helpers (virt may call these)
  29. * TRAMP_VIRT_BEGIN - virt, unreloc helpers (in practice, real can use)
  30. * EXC_COMMON - After switching to virtual, relocated mode.
  31. */
  32. #define EXC_REAL_BEGIN(name, start, size) \
  33. FIXED_SECTION_ENTRY_BEGIN_LOCATION(real_vectors, exc_real_##start##_##name, start, size)
  34. #define EXC_REAL_END(name, start, size) \
  35. FIXED_SECTION_ENTRY_END_LOCATION(real_vectors, exc_real_##start##_##name, start, size)
  36. #define EXC_VIRT_BEGIN(name, start, size) \
  37. FIXED_SECTION_ENTRY_BEGIN_LOCATION(virt_vectors, exc_virt_##start##_##name, start, size)
  38. #define EXC_VIRT_END(name, start, size) \
  39. FIXED_SECTION_ENTRY_END_LOCATION(virt_vectors, exc_virt_##start##_##name, start, size)
  40. #define EXC_COMMON_BEGIN(name) \
  41. USE_TEXT_SECTION(); \
  42. .balign IFETCH_ALIGN_BYTES; \
  43. .global name; \
  44. _ASM_NOKPROBE_SYMBOL(name); \
  45. DEFINE_FIXED_SYMBOL(name, text); \
  46. name:
  47. #define TRAMP_REAL_BEGIN(name) \
  48. FIXED_SECTION_ENTRY_BEGIN(real_trampolines, name)
  49. #define TRAMP_VIRT_BEGIN(name) \
  50. FIXED_SECTION_ENTRY_BEGIN(virt_trampolines, name)
  51. #define EXC_REAL_NONE(start, size) \
  52. FIXED_SECTION_ENTRY_BEGIN_LOCATION(real_vectors, exc_real_##start##_##unused, start, size); \
  53. FIXED_SECTION_ENTRY_END_LOCATION(real_vectors, exc_real_##start##_##unused, start, size)
  54. #define EXC_VIRT_NONE(start, size) \
  55. FIXED_SECTION_ENTRY_BEGIN_LOCATION(virt_vectors, exc_virt_##start##_##unused, start, size); \
  56. FIXED_SECTION_ENTRY_END_LOCATION(virt_vectors, exc_virt_##start##_##unused, start, size)
  57. /*
  58. * We're short on space and time in the exception prolog, so we can't
  59. * use the normal LOAD_REG_IMMEDIATE macro to load the address of label.
  60. * Instead we get the base of the kernel from paca->kernelbase and or in the low
  61. * part of label. This requires that the label be within 64KB of kernelbase, and
  62. * that kernelbase be 64K aligned.
  63. */
  64. #define LOAD_HANDLER(reg, label) \
  65. ld reg,PACAKBASE(r13); /* get high part of &label */ \
  66. ori reg,reg,FIXED_SYMBOL_ABS_ADDR(label)
  67. #define __LOAD_HANDLER(reg, label, section) \
  68. ld reg,PACAKBASE(r13); \
  69. ori reg,reg,(ABS_ADDR(label, section))@l
  70. /*
  71. * Branches from unrelocated code (e.g., interrupts) to labels outside
  72. * head-y require >64K offsets.
  73. */
  74. #define __LOAD_FAR_HANDLER(reg, label, section) \
  75. ld reg,PACAKBASE(r13); \
  76. ori reg,reg,(ABS_ADDR(label, section))@l; \
  77. addis reg,reg,(ABS_ADDR(label, section))@h
  78. /*
  79. * Interrupt code generation macros
  80. */
  81. #define IVEC .L_IVEC_\name\() /* Interrupt vector address */
  82. #define IHSRR .L_IHSRR_\name\() /* Sets SRR or HSRR registers */
  83. #define IHSRR_IF_HVMODE .L_IHSRR_IF_HVMODE_\name\() /* HSRR if HV else SRR */
  84. #define IAREA .L_IAREA_\name\() /* PACA save area */
  85. #define IVIRT .L_IVIRT_\name\() /* Has virt mode entry point */
  86. #define IISIDE .L_IISIDE_\name\() /* Uses SRR0/1 not DAR/DSISR */
  87. #define ICFAR .L_ICFAR_\name\() /* Uses CFAR */
  88. #define ICFAR_IF_HVMODE .L_ICFAR_IF_HVMODE_\name\() /* Uses CFAR if HV */
  89. #define IDAR .L_IDAR_\name\() /* Uses DAR (or SRR0) */
  90. #define IDSISR .L_IDSISR_\name\() /* Uses DSISR (or SRR1) */
  91. #define IBRANCH_TO_COMMON .L_IBRANCH_TO_COMMON_\name\() /* ENTRY branch to common */
  92. #define IREALMODE_COMMON .L_IREALMODE_COMMON_\name\() /* Common runs in realmode */
  93. #define IMASK .L_IMASK_\name\() /* IRQ soft-mask bit */
  94. #define IKVM_REAL .L_IKVM_REAL_\name\() /* Real entry tests KVM */
  95. #define __IKVM_REAL(name) .L_IKVM_REAL_ ## name
  96. #define IKVM_VIRT .L_IKVM_VIRT_\name\() /* Virt entry tests KVM */
  97. #define ISTACK .L_ISTACK_\name\() /* Set regular kernel stack */
  98. #define __ISTACK(name) .L_ISTACK_ ## name
  99. #define IKUAP .L_IKUAP_\name\() /* Do KUAP lock */
  100. #define IMSR_R12 .L_IMSR_R12_\name\() /* Assumes MSR saved to r12 */
  101. #define INT_DEFINE_BEGIN(n) \
  102. .macro int_define_ ## n name
  103. #define INT_DEFINE_END(n) \
  104. .endm ; \
  105. int_define_ ## n n ; \
  106. do_define_int n
  107. .macro do_define_int name
  108. .ifndef IVEC
  109. .error "IVEC not defined"
  110. .endif
  111. .ifndef IHSRR
  112. IHSRR=0
  113. .endif
  114. .ifndef IHSRR_IF_HVMODE
  115. IHSRR_IF_HVMODE=0
  116. .endif
  117. .ifndef IAREA
  118. IAREA=PACA_EXGEN
  119. .endif
  120. .ifndef IVIRT
  121. IVIRT=1
  122. .endif
  123. .ifndef IISIDE
  124. IISIDE=0
  125. .endif
  126. .ifndef ICFAR
  127. ICFAR=1
  128. .endif
  129. .ifndef ICFAR_IF_HVMODE
  130. ICFAR_IF_HVMODE=0
  131. .endif
  132. .ifndef IDAR
  133. IDAR=0
  134. .endif
  135. .ifndef IDSISR
  136. IDSISR=0
  137. .endif
  138. .ifndef IBRANCH_TO_COMMON
  139. IBRANCH_TO_COMMON=1
  140. .endif
  141. .ifndef IREALMODE_COMMON
  142. IREALMODE_COMMON=0
  143. .else
  144. .if ! IBRANCH_TO_COMMON
  145. .error "IREALMODE_COMMON=1 but IBRANCH_TO_COMMON=0"
  146. .endif
  147. .endif
  148. .ifndef IMASK
  149. IMASK=0
  150. .endif
  151. .ifndef IKVM_REAL
  152. IKVM_REAL=0
  153. .endif
  154. .ifndef IKVM_VIRT
  155. IKVM_VIRT=0
  156. .endif
  157. .ifndef ISTACK
  158. ISTACK=1
  159. .endif
  160. .ifndef IKUAP
  161. IKUAP=1
  162. .endif
  163. .ifndef IMSR_R12
  164. IMSR_R12=0
  165. .endif
  166. .endm
  167. /*
  168. * All interrupts which set HSRR registers, as well as SRESET and MCE and
  169. * syscall when invoked with "sc 1" switch to MSR[HV]=1 (HVMODE) to be taken,
  170. * so they all generally need to test whether they were taken in guest context.
  171. *
  172. * Note: SRESET and MCE may also be sent to the guest by the hypervisor, and be
  173. * taken with MSR[HV]=0.
  174. *
  175. * Interrupts which set SRR registers (with the above exceptions) do not
  176. * elevate to MSR[HV]=1 mode, though most can be taken when running with
  177. * MSR[HV]=1 (e.g., bare metal kernel and userspace). So these interrupts do
  178. * not need to test whether a guest is running because they get delivered to
  179. * the guest directly, including nested HV KVM guests.
  180. *
  181. * The exception is PR KVM, where the guest runs with MSR[PR]=1 and the host
  182. * runs with MSR[HV]=0, so the host takes all interrupts on behalf of the
  183. * guest. PR KVM runs with LPCR[AIL]=0 which causes interrupts to always be
  184. * delivered to the real-mode entry point, therefore such interrupts only test
  185. * KVM in their real mode handlers, and only when PR KVM is possible.
  186. *
  187. * Interrupts that are taken in MSR[HV]=0 and escalate to MSR[HV]=1 are always
  188. * delivered in real-mode when the MMU is in hash mode because the MMU
  189. * registers are not set appropriately to translate host addresses. In nested
  190. * radix mode these can be delivered in virt-mode as the host translations are
  191. * used implicitly (see: effective LPID, effective PID).
  192. */
  193. /*
  194. * If an interrupt is taken while a guest is running, it is immediately routed
  195. * to KVM to handle.
  196. */
  197. .macro KVMTEST name handler
  198. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  199. lbz r10,HSTATE_IN_GUEST(r13)
  200. cmpwi r10,0
  201. /* HSRR variants have the 0x2 bit added to their trap number */
  202. .if IHSRR_IF_HVMODE
  203. BEGIN_FTR_SECTION
  204. li r10,(IVEC + 0x2)
  205. FTR_SECTION_ELSE
  206. li r10,(IVEC)
  207. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  208. .elseif IHSRR
  209. li r10,(IVEC + 0x2)
  210. .else
  211. li r10,(IVEC)
  212. .endif
  213. bne \handler
  214. #endif
  215. .endm
  216. /*
  217. * This is the BOOK3S interrupt entry code macro.
  218. *
  219. * This can result in one of several things happening:
  220. * - Branch to the _common handler, relocated, in virtual mode.
  221. * These are normal interrupts (synchronous and asynchronous) handled by
  222. * the kernel.
  223. * - Branch to KVM, relocated but real mode interrupts remain in real mode.
  224. * These occur when HSTATE_IN_GUEST is set. The interrupt may be caused by
  225. * / intended for host or guest kernel, but KVM must always be involved
  226. * because the machine state is set for guest execution.
  227. * - Branch to the masked handler, unrelocated.
  228. * These occur when maskable asynchronous interrupts are taken with the
  229. * irq_soft_mask set.
  230. * - Branch to an "early" handler in real mode but relocated.
  231. * This is done if early=1. MCE and HMI use these to handle errors in real
  232. * mode.
  233. * - Fall through and continue executing in real, unrelocated mode.
  234. * This is done if early=2.
  235. */
  236. .macro GEN_BRANCH_TO_COMMON name, virt
  237. .if IREALMODE_COMMON
  238. LOAD_HANDLER(r10, \name\()_common)
  239. mtctr r10
  240. bctr
  241. .else
  242. .if \virt
  243. #ifndef CONFIG_RELOCATABLE
  244. b \name\()_common_virt
  245. #else
  246. LOAD_HANDLER(r10, \name\()_common_virt)
  247. mtctr r10
  248. bctr
  249. #endif
  250. .else
  251. LOAD_HANDLER(r10, \name\()_common_real)
  252. mtctr r10
  253. bctr
  254. .endif
  255. .endif
  256. .endm
  257. .macro GEN_INT_ENTRY name, virt, ool=0
  258. SET_SCRATCH0(r13) /* save r13 */
  259. GET_PACA(r13)
  260. std r9,IAREA+EX_R9(r13) /* save r9 */
  261. BEGIN_FTR_SECTION
  262. mfspr r9,SPRN_PPR
  263. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  264. HMT_MEDIUM
  265. std r10,IAREA+EX_R10(r13) /* save r10 */
  266. .if ICFAR
  267. BEGIN_FTR_SECTION
  268. mfspr r10,SPRN_CFAR
  269. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  270. .elseif ICFAR_IF_HVMODE
  271. BEGIN_FTR_SECTION
  272. BEGIN_FTR_SECTION_NESTED(69)
  273. mfspr r10,SPRN_CFAR
  274. END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 69)
  275. FTR_SECTION_ELSE
  276. BEGIN_FTR_SECTION_NESTED(69)
  277. li r10,0
  278. END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 69)
  279. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  280. .endif
  281. .if \ool
  282. .if !\virt
  283. b tramp_real_\name
  284. .pushsection .text
  285. TRAMP_REAL_BEGIN(tramp_real_\name)
  286. .else
  287. b tramp_virt_\name
  288. .pushsection .text
  289. TRAMP_VIRT_BEGIN(tramp_virt_\name)
  290. .endif
  291. .endif
  292. BEGIN_FTR_SECTION
  293. std r9,IAREA+EX_PPR(r13)
  294. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  295. .if ICFAR || ICFAR_IF_HVMODE
  296. BEGIN_FTR_SECTION
  297. std r10,IAREA+EX_CFAR(r13)
  298. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  299. .endif
  300. INTERRUPT_TO_KERNEL
  301. mfctr r10
  302. std r10,IAREA+EX_CTR(r13)
  303. mfcr r9
  304. std r11,IAREA+EX_R11(r13) /* save r11 - r12 */
  305. std r12,IAREA+EX_R12(r13)
  306. /*
  307. * DAR/DSISR, SCRATCH0 must be read before setting MSR[RI],
  308. * because a d-side MCE will clobber those registers so is
  309. * not recoverable if they are live.
  310. */
  311. GET_SCRATCH0(r10)
  312. std r10,IAREA+EX_R13(r13)
  313. .if IDAR && !IISIDE
  314. .if IHSRR
  315. mfspr r10,SPRN_HDAR
  316. .else
  317. mfspr r10,SPRN_DAR
  318. .endif
  319. std r10,IAREA+EX_DAR(r13)
  320. .endif
  321. .if IDSISR && !IISIDE
  322. .if IHSRR
  323. mfspr r10,SPRN_HDSISR
  324. .else
  325. mfspr r10,SPRN_DSISR
  326. .endif
  327. stw r10,IAREA+EX_DSISR(r13)
  328. .endif
  329. .if IHSRR_IF_HVMODE
  330. BEGIN_FTR_SECTION
  331. mfspr r11,SPRN_HSRR0 /* save HSRR0 */
  332. mfspr r12,SPRN_HSRR1 /* and HSRR1 */
  333. FTR_SECTION_ELSE
  334. mfspr r11,SPRN_SRR0 /* save SRR0 */
  335. mfspr r12,SPRN_SRR1 /* and SRR1 */
  336. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  337. .elseif IHSRR
  338. mfspr r11,SPRN_HSRR0 /* save HSRR0 */
  339. mfspr r12,SPRN_HSRR1 /* and HSRR1 */
  340. .else
  341. mfspr r11,SPRN_SRR0 /* save SRR0 */
  342. mfspr r12,SPRN_SRR1 /* and SRR1 */
  343. .endif
  344. .if IBRANCH_TO_COMMON
  345. GEN_BRANCH_TO_COMMON \name \virt
  346. .endif
  347. .if \ool
  348. .popsection
  349. .endif
  350. .endm
  351. /*
  352. * __GEN_COMMON_ENTRY is required to receive the branch from interrupt
  353. * entry, except in the case of the real-mode handlers which require
  354. * __GEN_REALMODE_COMMON_ENTRY.
  355. *
  356. * This switches to virtual mode and sets MSR[RI].
  357. */
  358. .macro __GEN_COMMON_ENTRY name
  359. DEFINE_FIXED_SYMBOL(\name\()_common_real, text)
  360. \name\()_common_real:
  361. .if IKVM_REAL
  362. KVMTEST \name kvm_interrupt
  363. .endif
  364. ld r10,PACAKMSR(r13) /* get MSR value for kernel */
  365. /* MSR[RI] is clear iff using SRR regs */
  366. .if IHSRR_IF_HVMODE
  367. BEGIN_FTR_SECTION
  368. xori r10,r10,MSR_RI
  369. END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
  370. .elseif ! IHSRR
  371. xori r10,r10,MSR_RI
  372. .endif
  373. mtmsrd r10
  374. .if IVIRT
  375. .if IKVM_VIRT
  376. b 1f /* skip the virt test coming from real */
  377. .endif
  378. .balign IFETCH_ALIGN_BYTES
  379. DEFINE_FIXED_SYMBOL(\name\()_common_virt, text)
  380. \name\()_common_virt:
  381. .if IKVM_VIRT
  382. KVMTEST \name kvm_interrupt
  383. 1:
  384. .endif
  385. .endif /* IVIRT */
  386. .endm
  387. /*
  388. * Don't switch to virt mode. Used for early MCE and HMI handlers that
  389. * want to run in real mode.
  390. */
  391. .macro __GEN_REALMODE_COMMON_ENTRY name
  392. DEFINE_FIXED_SYMBOL(\name\()_common_real, text)
  393. \name\()_common_real:
  394. .if IKVM_REAL
  395. KVMTEST \name kvm_interrupt
  396. .endif
  397. .endm
  398. .macro __GEN_COMMON_BODY name
  399. .if IMASK
  400. .if ! ISTACK
  401. .error "No support for masked interrupt to use custom stack"
  402. .endif
  403. /* If coming from user, skip soft-mask tests. */
  404. andi. r10,r12,MSR_PR
  405. bne 3f
  406. /*
  407. * Kernel code running below __end_soft_masked may be
  408. * implicitly soft-masked if it is within the regions
  409. * in the soft mask table.
  410. */
  411. LOAD_HANDLER(r10, __end_soft_masked)
  412. cmpld r11,r10
  413. bge+ 1f
  414. /* SEARCH_SOFT_MASK_TABLE clobbers r9,r10,r12 */
  415. mtctr r12
  416. stw r9,PACA_EXGEN+EX_CCR(r13)
  417. SEARCH_SOFT_MASK_TABLE
  418. cmpdi r12,0
  419. mfctr r12 /* Restore r12 to SRR1 */
  420. lwz r9,PACA_EXGEN+EX_CCR(r13)
  421. beq 1f /* Not in soft-mask table */
  422. li r10,IMASK
  423. b 2f /* In soft-mask table, always mask */
  424. /* Test the soft mask state against our interrupt's bit */
  425. 1: lbz r10,PACAIRQSOFTMASK(r13)
  426. 2: andi. r10,r10,IMASK
  427. /* Associate vector numbers with bits in paca->irq_happened */
  428. .if IVEC == 0x500 || IVEC == 0xea0
  429. li r10,PACA_IRQ_EE
  430. .elseif IVEC == 0x900
  431. li r10,PACA_IRQ_DEC
  432. .elseif IVEC == 0xa00 || IVEC == 0xe80
  433. li r10,PACA_IRQ_DBELL
  434. .elseif IVEC == 0xe60
  435. li r10,PACA_IRQ_HMI
  436. .elseif IVEC == 0xf00
  437. li r10,PACA_IRQ_PMI
  438. .else
  439. .abort "Bad maskable vector"
  440. .endif
  441. .if IHSRR_IF_HVMODE
  442. BEGIN_FTR_SECTION
  443. bne masked_Hinterrupt
  444. FTR_SECTION_ELSE
  445. bne masked_interrupt
  446. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  447. .elseif IHSRR
  448. bne masked_Hinterrupt
  449. .else
  450. bne masked_interrupt
  451. .endif
  452. .endif
  453. .if ISTACK
  454. andi. r10,r12,MSR_PR /* See if coming from user */
  455. 3: mr r10,r1 /* Save r1 */
  456. subi r1,r1,INT_FRAME_SIZE /* alloc frame on kernel stack */
  457. beq- 100f
  458. ld r1,PACAKSAVE(r13) /* kernel stack to use */
  459. 100: tdgei r1,-INT_FRAME_SIZE /* trap if r1 is in userspace */
  460. EMIT_BUG_ENTRY 100b,__FILE__,__LINE__,0
  461. .endif
  462. std r9,_CCR(r1) /* save CR in stackframe */
  463. std r11,_NIP(r1) /* save SRR0 in stackframe */
  464. std r12,_MSR(r1) /* save SRR1 in stackframe */
  465. std r10,0(r1) /* make stack chain pointer */
  466. std r0,GPR0(r1) /* save r0 in stackframe */
  467. std r10,GPR1(r1) /* save r1 in stackframe */
  468. SANITIZE_GPR(0)
  469. /* Mark our [H]SRRs valid for return */
  470. li r10,1
  471. .if IHSRR_IF_HVMODE
  472. BEGIN_FTR_SECTION
  473. stb r10,PACAHSRR_VALID(r13)
  474. FTR_SECTION_ELSE
  475. stb r10,PACASRR_VALID(r13)
  476. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  477. .elseif IHSRR
  478. stb r10,PACAHSRR_VALID(r13)
  479. .else
  480. stb r10,PACASRR_VALID(r13)
  481. .endif
  482. .if ISTACK
  483. .if IKUAP
  484. kuap_save_amr_and_lock r9, r10, cr1, cr0
  485. .endif
  486. beq 101f /* if from kernel mode */
  487. BEGIN_FTR_SECTION
  488. ld r9,IAREA+EX_PPR(r13) /* Read PPR from paca */
  489. std r9,_PPR(r1)
  490. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  491. 101:
  492. .else
  493. .if IKUAP
  494. kuap_save_amr_and_lock r9, r10, cr1
  495. .endif
  496. .endif
  497. /* Save original regs values from save area to stack frame. */
  498. ld r9,IAREA+EX_R9(r13) /* move r9, r10 to stackframe */
  499. ld r10,IAREA+EX_R10(r13)
  500. std r9,GPR9(r1)
  501. std r10,GPR10(r1)
  502. ld r9,IAREA+EX_R11(r13) /* move r11 - r13 to stackframe */
  503. ld r10,IAREA+EX_R12(r13)
  504. ld r11,IAREA+EX_R13(r13)
  505. std r9,GPR11(r1)
  506. std r10,GPR12(r1)
  507. std r11,GPR13(r1)
  508. .if !IMSR_R12
  509. SANITIZE_GPRS(9, 12)
  510. .else
  511. SANITIZE_GPRS(9, 11)
  512. .endif
  513. SAVE_NVGPRS(r1)
  514. SANITIZE_NVGPRS()
  515. .if IDAR
  516. .if IISIDE
  517. ld r10,_NIP(r1)
  518. .else
  519. ld r10,IAREA+EX_DAR(r13)
  520. .endif
  521. std r10,_DAR(r1)
  522. .endif
  523. .if IDSISR
  524. .if IISIDE
  525. ld r10,_MSR(r1)
  526. lis r11,DSISR_SRR1_MATCH_64S@h
  527. and r10,r10,r11
  528. .else
  529. lwz r10,IAREA+EX_DSISR(r13)
  530. .endif
  531. std r10,_DSISR(r1)
  532. .endif
  533. BEGIN_FTR_SECTION
  534. .if ICFAR || ICFAR_IF_HVMODE
  535. ld r10,IAREA+EX_CFAR(r13)
  536. .else
  537. li r10,0
  538. .endif
  539. std r10,ORIG_GPR3(r1)
  540. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  541. ld r10,IAREA+EX_CTR(r13)
  542. std r10,_CTR(r1)
  543. SAVE_GPRS(2, 8, r1) /* save r2 - r8 in stackframe */
  544. SANITIZE_GPRS(2, 8)
  545. mflr r9 /* Get LR, later save to stack */
  546. LOAD_PACA_TOC() /* get kernel TOC into r2 */
  547. std r9,_LINK(r1)
  548. lbz r10,PACAIRQSOFTMASK(r13)
  549. mfspr r11,SPRN_XER /* save XER in stackframe */
  550. std r10,SOFTE(r1)
  551. std r11,_XER(r1)
  552. li r9,IVEC
  553. std r9,_TRAP(r1) /* set trap number */
  554. li r10,0
  555. LOAD_REG_IMMEDIATE(r11, STACK_FRAME_REGS_MARKER)
  556. std r10,RESULT(r1) /* clear regs->result */
  557. std r11,STACK_INT_FRAME_MARKER(r1) /* mark the frame */
  558. .endm
  559. /*
  560. * On entry r13 points to the paca, r9-r13 are saved in the paca,
  561. * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
  562. * SRR1, and relocation is on.
  563. *
  564. * If stack=0, then the stack is already set in r1, and r1 is saved in r10.
  565. * PPR save and CPU accounting is not done for the !stack case (XXX why not?)
  566. */
  567. .macro GEN_COMMON name
  568. __GEN_COMMON_ENTRY \name
  569. __GEN_COMMON_BODY \name
  570. .endm
  571. .macro SEARCH_RESTART_TABLE
  572. #ifdef CONFIG_RELOCATABLE
  573. mr r12,r2
  574. LOAD_PACA_TOC()
  575. LOAD_REG_ADDR(r9, __start___restart_table)
  576. LOAD_REG_ADDR(r10, __stop___restart_table)
  577. mr r2,r12
  578. #else
  579. LOAD_REG_IMMEDIATE_SYM(r9, r12, __start___restart_table)
  580. LOAD_REG_IMMEDIATE_SYM(r10, r12, __stop___restart_table)
  581. #endif
  582. 300:
  583. cmpd r9,r10
  584. beq 302f
  585. ld r12,0(r9)
  586. cmpld r11,r12
  587. blt 301f
  588. ld r12,8(r9)
  589. cmpld r11,r12
  590. bge 301f
  591. ld r12,16(r9)
  592. b 303f
  593. 301:
  594. addi r9,r9,24
  595. b 300b
  596. 302:
  597. li r12,0
  598. 303:
  599. .endm
  600. .macro SEARCH_SOFT_MASK_TABLE
  601. #ifdef CONFIG_RELOCATABLE
  602. mr r12,r2
  603. LOAD_PACA_TOC()
  604. LOAD_REG_ADDR(r9, __start___soft_mask_table)
  605. LOAD_REG_ADDR(r10, __stop___soft_mask_table)
  606. mr r2,r12
  607. #else
  608. LOAD_REG_IMMEDIATE_SYM(r9, r12, __start___soft_mask_table)
  609. LOAD_REG_IMMEDIATE_SYM(r10, r12, __stop___soft_mask_table)
  610. #endif
  611. 300:
  612. cmpd r9,r10
  613. beq 302f
  614. ld r12,0(r9)
  615. cmpld r11,r12
  616. blt 301f
  617. ld r12,8(r9)
  618. cmpld r11,r12
  619. bge 301f
  620. li r12,1
  621. b 303f
  622. 301:
  623. addi r9,r9,16
  624. b 300b
  625. 302:
  626. li r12,0
  627. 303:
  628. .endm
  629. /*
  630. * Restore all registers including H/SRR0/1 saved in a stack frame of a
  631. * standard exception.
  632. */
  633. .macro EXCEPTION_RESTORE_REGS hsrr=0
  634. /* Move original SRR0 and SRR1 into the respective regs */
  635. ld r9,_MSR(r1)
  636. li r10,0
  637. .if \hsrr
  638. mtspr SPRN_HSRR1,r9
  639. stb r10,PACAHSRR_VALID(r13)
  640. .else
  641. mtspr SPRN_SRR1,r9
  642. stb r10,PACASRR_VALID(r13)
  643. .endif
  644. ld r9,_NIP(r1)
  645. .if \hsrr
  646. mtspr SPRN_HSRR0,r9
  647. .else
  648. mtspr SPRN_SRR0,r9
  649. .endif
  650. ld r9,_CTR(r1)
  651. mtctr r9
  652. ld r9,_XER(r1)
  653. mtxer r9
  654. ld r9,_LINK(r1)
  655. mtlr r9
  656. ld r9,_CCR(r1)
  657. mtcr r9
  658. SANITIZE_RESTORE_NVGPRS()
  659. REST_GPRS(2, 13, r1)
  660. REST_GPR(0, r1)
  661. /* restore original r1. */
  662. ld r1,GPR1(r1)
  663. .endm
  664. /*
  665. * EARLY_BOOT_FIXUP - Fix real-mode interrupt with wrong endian in early boot.
  666. *
  667. * There's a short window during boot where although the kernel is running
  668. * little endian, any exceptions will cause the CPU to switch back to big
  669. * endian. For example a WARN() boils down to a trap instruction, which will
  670. * cause a program check, and we end up here but with the CPU in big endian
  671. * mode. The first instruction of the program check handler (in GEN_INT_ENTRY
  672. * below) is an mtsprg, which when executed in the wrong endian is an lhzu with
  673. * a ~3GB displacement from r3. The content of r3 is random, so that is a load
  674. * from some random location, and depending on the system can easily lead to a
  675. * checkstop, or an infinitely recursive page fault.
  676. *
  677. * So to handle that case we have a trampoline here that can detect we are in
  678. * the wrong endian and flip us back to the correct endian. We can't flip
  679. * MSR[LE] using mtmsr, so we have to use rfid. That requires backing up SRR0/1
  680. * as well as a GPR. To do that we use SPRG0/2/3, as SPRG1 is already used for
  681. * the paca. SPRG3 is user readable, but this trampoline is only active very
  682. * early in boot, and SPRG3 will be reinitialised in vdso_getcpu_init() before
  683. * userspace starts.
  684. */
  685. .macro EARLY_BOOT_FIXUP
  686. BEGIN_FTR_SECTION
  687. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  688. tdi 0,0,0x48 // Trap never, or in reverse endian: b . + 8
  689. b 2f // Skip trampoline if endian is correct
  690. .long 0xa643707d // mtsprg 0, r11 Backup r11
  691. .long 0xa6027a7d // mfsrr0 r11
  692. .long 0xa643727d // mtsprg 2, r11 Backup SRR0 in SPRG2
  693. .long 0xa6027b7d // mfsrr1 r11
  694. .long 0xa643737d // mtsprg 3, r11 Backup SRR1 in SPRG3
  695. .long 0xa600607d // mfmsr r11
  696. .long 0x01006b69 // xori r11, r11, 1 Invert MSR[LE]
  697. .long 0xa6037b7d // mtsrr1 r11
  698. /*
  699. * This is 'li r11,1f' where 1f is the absolute address of that
  700. * label, byteswapped into the SI field of the instruction.
  701. */
  702. .long 0x00006039 | \
  703. ((ABS_ADDR(1f, real_vectors) & 0x00ff) << 24) | \
  704. ((ABS_ADDR(1f, real_vectors) & 0xff00) << 8)
  705. .long 0xa6037a7d // mtsrr0 r11
  706. .long 0x2400004c // rfid
  707. 1:
  708. mfsprg r11, 3
  709. mtsrr1 r11 // Restore SRR1
  710. mfsprg r11, 2
  711. mtsrr0 r11 // Restore SRR0
  712. mfsprg r11, 0 // Restore r11
  713. 2:
  714. #endif
  715. /*
  716. * program check could hit at any time, and pseries can not block
  717. * MSR[ME] in early boot. So check if there is anything useful in r13
  718. * yet, and spin forever if not.
  719. */
  720. mtsprg 0, r11
  721. mfcr r11
  722. cmpdi r13, 0
  723. beq .
  724. mtcr r11
  725. mfsprg r11, 0
  726. END_FTR_SECTION(0, 1) // nop out after boot
  727. .endm
  728. /*
  729. * There are a few constraints to be concerned with.
  730. * - Real mode exceptions code/data must be located at their physical location.
  731. * - Virtual mode exceptions must be mapped at their 0xc000... location.
  732. * - Fixed location code must not call directly beyond the __end_interrupts
  733. * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
  734. * must be used.
  735. * - LOAD_HANDLER targets must be within first 64K of physical 0 /
  736. * virtual 0xc00...
  737. * - Conditional branch targets must be within +/-32K of caller.
  738. *
  739. * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
  740. * therefore don't have to run in physically located code or rfid to
  741. * virtual mode kernel code. However on relocatable kernels they do have
  742. * to branch to KERNELBASE offset because the rest of the kernel (outside
  743. * the exception vectors) may be located elsewhere.
  744. *
  745. * Virtual exceptions correspond with physical, except their entry points
  746. * are offset by 0xc000000000000000 and also tend to get an added 0x4000
  747. * offset applied. Virtual exceptions are enabled with the Alternate
  748. * Interrupt Location (AIL) bit set in the LPCR. However this does not
  749. * guarantee they will be delivered virtually. Some conditions (see the ISA)
  750. * cause exceptions to be delivered in real mode.
  751. *
  752. * The scv instructions are a special case. They get a 0x3000 offset applied.
  753. * scv exceptions have unique reentrancy properties, see below.
  754. *
  755. * It's impossible to receive interrupts below 0x300 via AIL.
  756. *
  757. * KVM: None of the virtual exceptions are from the guest. Anything that
  758. * escalated to HV=1 from HV=0 is delivered via real mode handlers.
  759. *
  760. *
  761. * We layout physical memory as follows:
  762. * 0x0000 - 0x00ff : Secondary processor spin code
  763. * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
  764. * 0x1900 - 0x2fff : Real mode trampolines
  765. * 0x3000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
  766. * 0x5900 - 0x6fff : Relon mode trampolines
  767. * 0x7000 - 0x7fff : FWNMI data area
  768. * 0x8000 - .... : Common interrupt handlers, remaining early
  769. * setup code, rest of kernel.
  770. *
  771. * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
  772. * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
  773. * vectors there.
  774. */
  775. OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900)
  776. OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x3000)
  777. OPEN_FIXED_SECTION(virt_vectors, 0x3000, 0x5900)
  778. OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000)
  779. #ifdef CONFIG_PPC_POWERNV
  780. .globl start_real_trampolines
  781. .globl end_real_trampolines
  782. .globl start_virt_trampolines
  783. .globl end_virt_trampolines
  784. #endif
  785. #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
  786. /*
  787. * Data area reserved for FWNMI option.
  788. * This address (0x7000) is fixed by the RPA.
  789. * pseries and powernv need to keep the whole page from
  790. * 0x7000 to 0x8000 free for use by the firmware
  791. */
  792. ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000)
  793. OPEN_TEXT_SECTION(0x8000)
  794. #else
  795. OPEN_TEXT_SECTION(0x7000)
  796. #endif
  797. USE_FIXED_SECTION(real_vectors)
  798. /*
  799. * This is the start of the interrupt handlers for pSeries
  800. * This code runs with relocation off.
  801. * Code from here to __end_interrupts gets copied down to real
  802. * address 0x100 when we are running a relocatable kernel.
  803. * Therefore any relative branches in this section must only
  804. * branch to labels in this section.
  805. */
  806. .globl __start_interrupts
  807. __start_interrupts:
  808. /**
  809. * Interrupt 0x3000 - System Call Vectored Interrupt (syscall).
  810. * This is a synchronous interrupt invoked with the "scv" instruction. The
  811. * system call does not alter the HV bit, so it is directed to the OS.
  812. *
  813. * Handling:
  814. * scv instructions enter the kernel without changing EE, RI, ME, or HV.
  815. * In particular, this means we can take a maskable interrupt at any point
  816. * in the scv handler, which is unlike any other interrupt. This is solved
  817. * by treating the instruction addresses in the handler as being soft-masked,
  818. * by adding a SOFT_MASK_TABLE entry for them.
  819. *
  820. * AIL-0 mode scv exceptions go to 0x17000-0x17fff, but we set AIL-3 and
  821. * ensure scv is never executed with relocation off, which means AIL-0
  822. * should never happen.
  823. *
  824. * Before leaving the following inside-__end_soft_masked text, at least of the
  825. * following must be true:
  826. * - MSR[PR]=1 (i.e., return to userspace)
  827. * - MSR_EE|MSR_RI is clear (no reentrant exceptions)
  828. * - Standard kernel environment is set up (stack, paca, etc)
  829. *
  830. * KVM:
  831. * These interrupts do not elevate HV 0->1, so HV is not involved. PR KVM
  832. * ensures that FSCR[SCV] is disabled whenever it has to force AIL off.
  833. *
  834. * Call convention:
  835. *
  836. * syscall register convention is in Documentation/arch/powerpc/syscall64-abi.rst
  837. */
  838. EXC_VIRT_BEGIN(system_call_vectored, 0x3000, 0x1000)
  839. /* SCV 0 */
  840. mr r9,r13
  841. GET_PACA(r13)
  842. mflr r11
  843. mfctr r12
  844. li r10,IRQS_ALL_DISABLED
  845. stb r10,PACAIRQSOFTMASK(r13)
  846. #ifdef CONFIG_RELOCATABLE
  847. b system_call_vectored_tramp
  848. #else
  849. b system_call_vectored_common
  850. #endif
  851. nop
  852. /* SCV 1 - 127 */
  853. .rept 127
  854. mr r9,r13
  855. GET_PACA(r13)
  856. mflr r11
  857. mfctr r12
  858. li r10,IRQS_ALL_DISABLED
  859. stb r10,PACAIRQSOFTMASK(r13)
  860. li r0,-1 /* cause failure */
  861. #ifdef CONFIG_RELOCATABLE
  862. b system_call_vectored_sigill_tramp
  863. #else
  864. b system_call_vectored_sigill
  865. #endif
  866. .endr
  867. EXC_VIRT_END(system_call_vectored, 0x3000, 0x1000)
  868. // Treat scv vectors as soft-masked, see comment above.
  869. // Use absolute values rather than labels here, so they don't get relocated,
  870. // because this code runs unrelocated.
  871. SOFT_MASK_TABLE(0xc000000000003000, 0xc000000000004000)
  872. #ifdef CONFIG_RELOCATABLE
  873. TRAMP_VIRT_BEGIN(system_call_vectored_tramp)
  874. __LOAD_HANDLER(r10, system_call_vectored_common, virt_trampolines)
  875. mtctr r10
  876. bctr
  877. TRAMP_VIRT_BEGIN(system_call_vectored_sigill_tramp)
  878. __LOAD_HANDLER(r10, system_call_vectored_sigill, virt_trampolines)
  879. mtctr r10
  880. bctr
  881. #endif
  882. /* No virt vectors corresponding with 0x0..0x100 */
  883. EXC_VIRT_NONE(0x4000, 0x100)
  884. /**
  885. * Interrupt 0x100 - System Reset Interrupt (SRESET aka NMI).
  886. * This is a non-maskable, asynchronous interrupt always taken in real-mode.
  887. * It is caused by:
  888. * - Wake from power-saving state, on powernv.
  889. * - An NMI from another CPU, triggered by firmware or hypercall.
  890. * - As crash/debug signal injected from BMC, firmware or hypervisor.
  891. *
  892. * Handling:
  893. * Power-save wakeup is the only performance critical path, so this is
  894. * determined quickly as possible first. In this case volatile registers
  895. * can be discarded and SPRs like CFAR don't need to be read.
  896. *
  897. * If not a powersave wakeup, then it's run as a regular interrupt, however
  898. * it uses its own stack and PACA save area to preserve the regular kernel
  899. * environment for debugging.
  900. *
  901. * This interrupt is not maskable, so triggering it when MSR[RI] is clear,
  902. * or SCRATCH0 is in use, etc. may cause a crash. It's also not entirely
  903. * correct to switch to virtual mode to run the regular interrupt handler
  904. * because it might be interrupted when the MMU is in a bad state (e.g., SLB
  905. * is clear).
  906. *
  907. * FWNMI:
  908. * PAPR specifies a "fwnmi" facility which sends the sreset to a different
  909. * entry point with a different register set up. Some hypervisors will
  910. * send the sreset to 0x100 in the guest if it is not fwnmi capable.
  911. *
  912. * KVM:
  913. * Unlike most SRR interrupts, this may be taken by the host while executing
  914. * in a guest, so a KVM test is required. KVM will pull the CPU out of guest
  915. * mode and then raise the sreset.
  916. */
  917. INT_DEFINE_BEGIN(system_reset)
  918. IVEC=0x100
  919. IAREA=PACA_EXNMI
  920. IVIRT=0 /* no virt entry point */
  921. ISTACK=0
  922. IKVM_REAL=1
  923. INT_DEFINE_END(system_reset)
  924. EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
  925. #ifdef CONFIG_PPC_P7_NAP
  926. /*
  927. * If running native on arch 2.06 or later, check if we are waking up
  928. * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
  929. * bits 46:47. A non-0 value indicates that we are coming from a power
  930. * saving state. The idle wakeup handler initially runs in real mode,
  931. * but we branch to the 0xc000... address so we can turn on relocation
  932. * with mtmsrd later, after SPRs are restored.
  933. *
  934. * Careful to minimise cost for the fast path (idle wakeup) while
  935. * also avoiding clobbering CFAR for the debug path (non-idle).
  936. *
  937. * For the idle wake case volatile registers can be clobbered, which
  938. * is why we use those initially. If it turns out to not be an idle
  939. * wake, carefully put everything back the way it was, so we can use
  940. * common exception macros to handle it.
  941. */
  942. BEGIN_FTR_SECTION
  943. SET_SCRATCH0(r13)
  944. GET_PACA(r13)
  945. std r3,PACA_EXNMI+0*8(r13)
  946. std r4,PACA_EXNMI+1*8(r13)
  947. std r5,PACA_EXNMI+2*8(r13)
  948. mfspr r3,SPRN_SRR1
  949. mfocrf r4,0x80
  950. rlwinm. r5,r3,47-31,30,31
  951. bne+ system_reset_idle_wake
  952. /* Not powersave wakeup. Restore regs for regular interrupt handler. */
  953. mtocrf 0x80,r4
  954. ld r3,PACA_EXNMI+0*8(r13)
  955. ld r4,PACA_EXNMI+1*8(r13)
  956. ld r5,PACA_EXNMI+2*8(r13)
  957. GET_SCRATCH0(r13)
  958. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  959. #endif
  960. GEN_INT_ENTRY system_reset, virt=0
  961. /*
  962. * In theory, we should not enable relocation here if it was disabled
  963. * in SRR1, because the MMU may not be configured to support it (e.g.,
  964. * SLB may have been cleared). In practice, there should only be a few
  965. * small windows where that's the case, and sreset is considered to
  966. * be dangerous anyway.
  967. */
  968. EXC_REAL_END(system_reset, 0x100, 0x100)
  969. EXC_VIRT_NONE(0x4100, 0x100)
  970. #ifdef CONFIG_PPC_P7_NAP
  971. TRAMP_REAL_BEGIN(system_reset_idle_wake)
  972. /* We are waking up from idle, so may clobber any volatile register */
  973. cmpwi cr1,r5,2
  974. bltlr cr1 /* no state loss, return to idle caller with r3=SRR1 */
  975. __LOAD_FAR_HANDLER(r12, DOTSYM(idle_return_gpr_loss), real_trampolines)
  976. mtctr r12
  977. bctr
  978. #endif
  979. #ifdef CONFIG_PPC_PSERIES
  980. /*
  981. * Vectors for the FWNMI option. Share common code.
  982. */
  983. TRAMP_REAL_BEGIN(system_reset_fwnmi)
  984. GEN_INT_ENTRY system_reset, virt=0
  985. #endif /* CONFIG_PPC_PSERIES */
  986. EXC_COMMON_BEGIN(system_reset_common)
  987. __GEN_COMMON_ENTRY system_reset
  988. /*
  989. * Increment paca->in_nmi. When the interrupt entry wrapper later
  990. * enable MSR_RI, then SLB or MCE will be able to recover, but a nested
  991. * NMI will notice in_nmi and not recover because of the use of the NMI
  992. * stack. in_nmi reentrancy is tested in system_reset_exception.
  993. */
  994. lhz r10,PACA_IN_NMI(r13)
  995. addi r10,r10,1
  996. sth r10,PACA_IN_NMI(r13)
  997. mr r10,r1
  998. ld r1,PACA_NMI_EMERG_SP(r13)
  999. subi r1,r1,INT_FRAME_SIZE
  1000. __GEN_COMMON_BODY system_reset
  1001. addi r3,r1,STACK_INT_FRAME_REGS
  1002. bl CFUNC(system_reset_exception)
  1003. /* Clear MSR_RI before setting SRR0 and SRR1. */
  1004. li r9,0
  1005. mtmsrd r9,1
  1006. /*
  1007. * MSR_RI is clear, now we can decrement paca->in_nmi.
  1008. */
  1009. lhz r10,PACA_IN_NMI(r13)
  1010. subi r10,r10,1
  1011. sth r10,PACA_IN_NMI(r13)
  1012. kuap_kernel_restore r9, r10
  1013. EXCEPTION_RESTORE_REGS
  1014. RFI_TO_USER_OR_KERNEL
  1015. /**
  1016. * Interrupt 0x200 - Machine Check Interrupt (MCE).
  1017. * This is a non-maskable interrupt always taken in real-mode. It can be
  1018. * synchronous or asynchronous, caused by hardware or software, and it may be
  1019. * taken in a power-saving state.
  1020. *
  1021. * Handling:
  1022. * Similarly to system reset, this uses its own stack and PACA save area,
  1023. * the difference is re-entrancy is allowed on the machine check stack.
  1024. *
  1025. * machine_check_early is run in real mode, and carefully decodes the
  1026. * machine check and tries to handle it (e.g., flush the SLB if there was an
  1027. * error detected there), determines if it was recoverable and logs the
  1028. * event.
  1029. *
  1030. * This early code does not "reconcile" irq soft-mask state like SRESET or
  1031. * regular interrupts do, so irqs_disabled() among other things may not work
  1032. * properly (irq disable/enable already doesn't work because irq tracing can
  1033. * not work in real mode).
  1034. *
  1035. * Then, depending on the execution context when the interrupt is taken, there
  1036. * are 3 main actions:
  1037. * - Executing in kernel mode. The event is queued with irq_work, which means
  1038. * it is handled when it is next safe to do so (i.e., the kernel has enabled
  1039. * interrupts), which could be immediately when the interrupt returns. This
  1040. * avoids nasty issues like switching to virtual mode when the MMU is in a
  1041. * bad state, or when executing OPAL code. (SRESET is exposed to such issues,
  1042. * but it has different priorities). Check to see if the CPU was in power
  1043. * save, and return via the wake up code if it was.
  1044. *
  1045. * - Executing in user mode. machine_check_exception is run like a normal
  1046. * interrupt handler, which processes the data generated by the early handler.
  1047. *
  1048. * - Executing in guest mode. The interrupt is run with its KVM test, and
  1049. * branches to KVM to deal with. KVM may queue the event for the host
  1050. * to report later.
  1051. *
  1052. * This interrupt is not maskable, so if it triggers when MSR[RI] is clear,
  1053. * or SCRATCH0 is in use, it may cause a crash.
  1054. *
  1055. * KVM:
  1056. * See SRESET.
  1057. */
  1058. INT_DEFINE_BEGIN(machine_check_early)
  1059. IVEC=0x200
  1060. IAREA=PACA_EXMC
  1061. IVIRT=0 /* no virt entry point */
  1062. IREALMODE_COMMON=1
  1063. ISTACK=0
  1064. IDAR=1
  1065. IDSISR=1
  1066. IKUAP=0 /* We don't touch AMR here, we never go to virtual mode */
  1067. INT_DEFINE_END(machine_check_early)
  1068. INT_DEFINE_BEGIN(machine_check)
  1069. IVEC=0x200
  1070. IAREA=PACA_EXMC
  1071. IVIRT=0 /* no virt entry point */
  1072. IDAR=1
  1073. IDSISR=1
  1074. IKVM_REAL=1
  1075. INT_DEFINE_END(machine_check)
  1076. EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
  1077. EARLY_BOOT_FIXUP
  1078. GEN_INT_ENTRY machine_check_early, virt=0
  1079. EXC_REAL_END(machine_check, 0x200, 0x100)
  1080. EXC_VIRT_NONE(0x4200, 0x100)
  1081. #ifdef CONFIG_PPC_PSERIES
  1082. TRAMP_REAL_BEGIN(machine_check_fwnmi)
  1083. /* See comment at machine_check exception, don't turn on RI */
  1084. GEN_INT_ENTRY machine_check_early, virt=0
  1085. #endif
  1086. #define MACHINE_CHECK_HANDLER_WINDUP \
  1087. /* Clear MSR_RI before setting SRR0 and SRR1. */\
  1088. li r9,0; \
  1089. mtmsrd r9,1; /* Clear MSR_RI */ \
  1090. /* Decrement paca->in_mce now RI is clear. */ \
  1091. lhz r12,PACA_IN_MCE(r13); \
  1092. subi r12,r12,1; \
  1093. sth r12,PACA_IN_MCE(r13); \
  1094. EXCEPTION_RESTORE_REGS
  1095. EXC_COMMON_BEGIN(machine_check_early_common)
  1096. __GEN_REALMODE_COMMON_ENTRY machine_check_early
  1097. /*
  1098. * Switch to mc_emergency stack and handle re-entrancy (we limit
  1099. * the nested MCE upto level 4 to avoid stack overflow).
  1100. * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
  1101. *
  1102. * We use paca->in_mce to check whether this is the first entry or
  1103. * nested machine check. We increment paca->in_mce to track nested
  1104. * machine checks.
  1105. *
  1106. * If this is the first entry then set stack pointer to
  1107. * paca->mc_emergency_sp, otherwise r1 is already pointing to
  1108. * stack frame on mc_emergency stack.
  1109. *
  1110. * NOTE: We are here with MSR_ME=0 (off), which means we risk a
  1111. * checkstop if we get another machine check exception before we do
  1112. * rfid with MSR_ME=1.
  1113. *
  1114. * This interrupt can wake directly from idle. If that is the case,
  1115. * the machine check is handled then the idle wakeup code is called
  1116. * to restore state.
  1117. */
  1118. lhz r10,PACA_IN_MCE(r13)
  1119. cmpwi r10,0 /* Are we in nested machine check */
  1120. cmpwi cr1,r10,MAX_MCE_DEPTH /* Are we at maximum nesting */
  1121. addi r10,r10,1 /* increment paca->in_mce */
  1122. sth r10,PACA_IN_MCE(r13)
  1123. mr r10,r1 /* Save r1 */
  1124. bne 1f
  1125. /* First machine check entry */
  1126. ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
  1127. 1: /* Limit nested MCE to level 4 to avoid stack overflow */
  1128. bgt cr1,unrecoverable_mce /* Check if we hit limit of 4 */
  1129. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  1130. __GEN_COMMON_BODY machine_check_early
  1131. BEGIN_FTR_SECTION
  1132. bl enable_machine_check
  1133. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  1134. addi r3,r1,STACK_INT_FRAME_REGS
  1135. BEGIN_FTR_SECTION
  1136. bl CFUNC(machine_check_early_boot)
  1137. END_FTR_SECTION(0, 1) // nop out after boot
  1138. bl CFUNC(machine_check_early)
  1139. std r3,RESULT(r1) /* Save result */
  1140. ld r12,_MSR(r1)
  1141. #ifdef CONFIG_PPC_P7_NAP
  1142. /*
  1143. * Check if thread was in power saving mode. We come here when any
  1144. * of the following is true:
  1145. * a. thread wasn't in power saving mode
  1146. * b. thread was in power saving mode with no state loss,
  1147. * supervisor state loss or hypervisor state loss.
  1148. *
  1149. * Go back to nap/sleep/winkle mode again if (b) is true.
  1150. */
  1151. BEGIN_FTR_SECTION
  1152. rlwinm. r11,r12,47-31,30,31
  1153. bne machine_check_idle_common
  1154. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  1155. #endif
  1156. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  1157. /*
  1158. * Check if we are coming from guest. If yes, then run the normal
  1159. * exception handler which will take the
  1160. * machine_check_kvm->kvm_interrupt branch to deliver the MC event
  1161. * to guest.
  1162. */
  1163. lbz r11,HSTATE_IN_GUEST(r13)
  1164. cmpwi r11,0 /* Check if coming from guest */
  1165. bne mce_deliver /* continue if we are. */
  1166. #endif
  1167. /*
  1168. * Check if we are coming from userspace. If yes, then run the normal
  1169. * exception handler which will deliver the MC event to this kernel.
  1170. */
  1171. andi. r11,r12,MSR_PR /* See if coming from user. */
  1172. bne mce_deliver /* continue in V mode if we are. */
  1173. /*
  1174. * At this point we are coming from kernel context.
  1175. * Queue up the MCE event and return from the interrupt.
  1176. * But before that, check if this is an un-recoverable exception.
  1177. * If yes, then stay on emergency stack and panic.
  1178. */
  1179. andi. r11,r12,MSR_RI
  1180. beq unrecoverable_mce
  1181. /*
  1182. * Check if we have successfully handled/recovered from error, if not
  1183. * then stay on emergency stack and panic.
  1184. */
  1185. ld r3,RESULT(r1) /* Load result */
  1186. cmpdi r3,0 /* see if we handled MCE successfully */
  1187. beq unrecoverable_mce /* if !handled then panic */
  1188. /*
  1189. * Return from MC interrupt.
  1190. * Queue up the MCE event so that we can log it later, while
  1191. * returning from kernel or opal call.
  1192. */
  1193. bl CFUNC(machine_check_queue_event)
  1194. MACHINE_CHECK_HANDLER_WINDUP
  1195. RFI_TO_KERNEL
  1196. mce_deliver:
  1197. /*
  1198. * This is a host user or guest MCE. Restore all registers, then
  1199. * run the "late" handler. For host user, this will run the
  1200. * machine_check_exception handler in virtual mode like a normal
  1201. * interrupt handler. For guest, this will trigger the KVM test
  1202. * and branch to the KVM interrupt similarly to other interrupts.
  1203. */
  1204. BEGIN_FTR_SECTION
  1205. ld r10,ORIG_GPR3(r1)
  1206. mtspr SPRN_CFAR,r10
  1207. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1208. MACHINE_CHECK_HANDLER_WINDUP
  1209. GEN_INT_ENTRY machine_check, virt=0
  1210. EXC_COMMON_BEGIN(machine_check_common)
  1211. /*
  1212. * Machine check is different because we use a different
  1213. * save area: PACA_EXMC instead of PACA_EXGEN.
  1214. */
  1215. GEN_COMMON machine_check
  1216. addi r3,r1,STACK_INT_FRAME_REGS
  1217. bl CFUNC(machine_check_exception_async)
  1218. b interrupt_return_srr
  1219. #ifdef CONFIG_PPC_P7_NAP
  1220. /*
  1221. * This is an idle wakeup. Low level machine check has already been
  1222. * done. Queue the event then call the idle code to do the wake up.
  1223. */
  1224. EXC_COMMON_BEGIN(machine_check_idle_common)
  1225. bl CFUNC(machine_check_queue_event)
  1226. /*
  1227. * GPR-loss wakeups are relatively straightforward, because the
  1228. * idle sleep code has saved all non-volatile registers on its
  1229. * own stack, and r1 in PACAR1.
  1230. *
  1231. * For no-loss wakeups the r1 and lr registers used by the
  1232. * early machine check handler have to be restored first. r2 is
  1233. * the kernel TOC, so no need to restore it.
  1234. *
  1235. * Then decrement MCE nesting after finishing with the stack.
  1236. */
  1237. ld r3,_MSR(r1)
  1238. ld r4,_LINK(r1)
  1239. ld r1,GPR1(r1)
  1240. lhz r11,PACA_IN_MCE(r13)
  1241. subi r11,r11,1
  1242. sth r11,PACA_IN_MCE(r13)
  1243. mtlr r4
  1244. rlwinm r10,r3,47-31,30,31
  1245. cmpwi cr1,r10,2
  1246. bltlr cr1 /* no state loss, return to idle caller with r3=SRR1 */
  1247. b idle_return_gpr_loss
  1248. #endif
  1249. EXC_COMMON_BEGIN(unrecoverable_mce)
  1250. /*
  1251. * We are going down. But there are chances that we might get hit by
  1252. * another MCE during panic path and we may run into unstable state
  1253. * with no way out. Hence, turn ME bit off while going down, so that
  1254. * when another MCE is hit during panic path, system will checkstop
  1255. * and hypervisor will get restarted cleanly by SP.
  1256. */
  1257. BEGIN_FTR_SECTION
  1258. li r10,0 /* clear MSR_RI */
  1259. mtmsrd r10,1
  1260. bl CFUNC(disable_machine_check)
  1261. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  1262. ld r10,PACAKMSR(r13)
  1263. li r3,MSR_ME
  1264. andc r10,r10,r3
  1265. mtmsrd r10
  1266. lhz r12,PACA_IN_MCE(r13)
  1267. subi r12,r12,1
  1268. sth r12,PACA_IN_MCE(r13)
  1269. /*
  1270. * Invoke machine_check_exception to print MCE event and panic.
  1271. * This is the NMI version of the handler because we are called from
  1272. * the early handler which is a true NMI.
  1273. */
  1274. addi r3,r1,STACK_INT_FRAME_REGS
  1275. bl CFUNC(machine_check_exception)
  1276. /*
  1277. * We will not reach here. Even if we did, there is no way out.
  1278. * Call unrecoverable_exception and die.
  1279. */
  1280. addi r3,r1,STACK_INT_FRAME_REGS
  1281. bl CFUNC(unrecoverable_exception)
  1282. b .
  1283. /**
  1284. * Interrupt 0x300 - Data Storage Interrupt (DSI).
  1285. * This is a synchronous interrupt generated due to a data access exception,
  1286. * e.g., a load orstore which does not have a valid page table entry with
  1287. * permissions. DAWR matches also fault here, as do RC updates, and minor misc
  1288. * errors e.g., copy/paste, AMO, certain invalid CI accesses, etc.
  1289. *
  1290. * Handling:
  1291. * - Hash MMU
  1292. * Go to do_hash_fault, which attempts to fill the HPT from an entry in the
  1293. * Linux page table. Hash faults can hit in kernel mode in a fairly
  1294. * arbitrary state (e.g., interrupts disabled, locks held) when accessing
  1295. * "non-bolted" regions, e.g., vmalloc space. However these should always be
  1296. * backed by Linux page table entries.
  1297. *
  1298. * If no entry is found the Linux page fault handler is invoked (by
  1299. * do_hash_fault). Linux page faults can happen in kernel mode due to user
  1300. * copy operations of course.
  1301. *
  1302. * KVM: The KVM HDSI handler may perform a load with MSR[DR]=1 in guest
  1303. * MMU context, which may cause a DSI in the host, which must go to the
  1304. * KVM handler. MSR[IR] is not enabled, so the real-mode handler will
  1305. * always be used regardless of AIL setting.
  1306. *
  1307. * - Radix MMU
  1308. * The hardware loads from the Linux page table directly, so a fault goes
  1309. * immediately to Linux page fault.
  1310. *
  1311. * Conditions like DAWR match are handled on the way in to Linux page fault.
  1312. */
  1313. INT_DEFINE_BEGIN(data_access)
  1314. IVEC=0x300
  1315. IDAR=1
  1316. IDSISR=1
  1317. IKVM_REAL=1
  1318. INT_DEFINE_END(data_access)
  1319. EXC_REAL_BEGIN(data_access, 0x300, 0x80)
  1320. GEN_INT_ENTRY data_access, virt=0
  1321. EXC_REAL_END(data_access, 0x300, 0x80)
  1322. EXC_VIRT_BEGIN(data_access, 0x4300, 0x80)
  1323. GEN_INT_ENTRY data_access, virt=1
  1324. EXC_VIRT_END(data_access, 0x4300, 0x80)
  1325. EXC_COMMON_BEGIN(data_access_common)
  1326. GEN_COMMON data_access
  1327. ld r4,_DSISR(r1)
  1328. addi r3,r1,STACK_INT_FRAME_REGS
  1329. andis. r0,r4,DSISR_DABRMATCH@h
  1330. bne- 1f
  1331. #ifdef CONFIG_PPC_64S_HASH_MMU
  1332. BEGIN_MMU_FTR_SECTION
  1333. bl CFUNC(do_hash_fault)
  1334. MMU_FTR_SECTION_ELSE
  1335. bl CFUNC(do_page_fault)
  1336. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  1337. #else
  1338. bl CFUNC(do_page_fault)
  1339. #endif
  1340. b interrupt_return_srr
  1341. 1: bl CFUNC(do_break)
  1342. /*
  1343. * do_break() may have changed the NV GPRS while handling a breakpoint.
  1344. * If so, we need to restore them with their updated values.
  1345. */
  1346. HANDLER_RESTORE_NVGPRS()
  1347. b interrupt_return_srr
  1348. /**
  1349. * Interrupt 0x380 - Data Segment Interrupt (DSLB).
  1350. * This is a synchronous interrupt in response to an MMU fault missing SLB
  1351. * entry for HPT, or an address outside RPT translation range.
  1352. *
  1353. * Handling:
  1354. * - HPT:
  1355. * This refills the SLB, or reports an access fault similarly to a bad page
  1356. * fault. When coming from user-mode, the SLB handler may access any kernel
  1357. * data, though it may itself take a DSLB. When coming from kernel mode,
  1358. * recursive faults must be avoided so access is restricted to the kernel
  1359. * image text/data, kernel stack, and any data allocated below
  1360. * ppc64_bolted_size (first segment). The kernel handler must avoid stomping
  1361. * on user-handler data structures.
  1362. *
  1363. * KVM: Same as 0x300, DSLB must test for KVM guest.
  1364. */
  1365. INT_DEFINE_BEGIN(data_access_slb)
  1366. IVEC=0x380
  1367. IDAR=1
  1368. IKVM_REAL=1
  1369. INT_DEFINE_END(data_access_slb)
  1370. EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
  1371. GEN_INT_ENTRY data_access_slb, virt=0
  1372. EXC_REAL_END(data_access_slb, 0x380, 0x80)
  1373. EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
  1374. GEN_INT_ENTRY data_access_slb, virt=1
  1375. EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
  1376. EXC_COMMON_BEGIN(data_access_slb_common)
  1377. GEN_COMMON data_access_slb
  1378. #ifdef CONFIG_PPC_64S_HASH_MMU
  1379. BEGIN_MMU_FTR_SECTION
  1380. /* HPT case, do SLB fault */
  1381. addi r3,r1,STACK_INT_FRAME_REGS
  1382. bl CFUNC(do_slb_fault)
  1383. cmpdi r3,0
  1384. bne- 1f
  1385. b fast_interrupt_return_srr
  1386. 1: /* Error case */
  1387. MMU_FTR_SECTION_ELSE
  1388. /* Radix case, access is outside page table range */
  1389. li r3,-EFAULT
  1390. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  1391. #else
  1392. li r3,-EFAULT
  1393. #endif
  1394. std r3,RESULT(r1)
  1395. addi r3,r1,STACK_INT_FRAME_REGS
  1396. bl CFUNC(do_bad_segment_interrupt)
  1397. b interrupt_return_srr
  1398. /**
  1399. * Interrupt 0x400 - Instruction Storage Interrupt (ISI).
  1400. * This is a synchronous interrupt in response to an MMU fault due to an
  1401. * instruction fetch.
  1402. *
  1403. * Handling:
  1404. * Similar to DSI, though in response to fetch. The faulting address is found
  1405. * in SRR0 (rather than DAR), and status in SRR1 (rather than DSISR).
  1406. */
  1407. INT_DEFINE_BEGIN(instruction_access)
  1408. IVEC=0x400
  1409. IISIDE=1
  1410. IDAR=1
  1411. IDSISR=1
  1412. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  1413. IKVM_REAL=1
  1414. #endif
  1415. INT_DEFINE_END(instruction_access)
  1416. EXC_REAL_BEGIN(instruction_access, 0x400, 0x80)
  1417. GEN_INT_ENTRY instruction_access, virt=0
  1418. EXC_REAL_END(instruction_access, 0x400, 0x80)
  1419. EXC_VIRT_BEGIN(instruction_access, 0x4400, 0x80)
  1420. GEN_INT_ENTRY instruction_access, virt=1
  1421. EXC_VIRT_END(instruction_access, 0x4400, 0x80)
  1422. EXC_COMMON_BEGIN(instruction_access_common)
  1423. GEN_COMMON instruction_access
  1424. addi r3,r1,STACK_INT_FRAME_REGS
  1425. #ifdef CONFIG_PPC_64S_HASH_MMU
  1426. BEGIN_MMU_FTR_SECTION
  1427. bl CFUNC(do_hash_fault)
  1428. MMU_FTR_SECTION_ELSE
  1429. bl CFUNC(do_page_fault)
  1430. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  1431. #else
  1432. bl CFUNC(do_page_fault)
  1433. #endif
  1434. b interrupt_return_srr
  1435. /**
  1436. * Interrupt 0x480 - Instruction Segment Interrupt (ISLB).
  1437. * This is a synchronous interrupt in response to an MMU fault due to an
  1438. * instruction fetch.
  1439. *
  1440. * Handling:
  1441. * Similar to DSLB, though in response to fetch. The faulting address is found
  1442. * in SRR0 (rather than DAR).
  1443. */
  1444. INT_DEFINE_BEGIN(instruction_access_slb)
  1445. IVEC=0x480
  1446. IISIDE=1
  1447. IDAR=1
  1448. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  1449. IKVM_REAL=1
  1450. #endif
  1451. INT_DEFINE_END(instruction_access_slb)
  1452. EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)
  1453. GEN_INT_ENTRY instruction_access_slb, virt=0
  1454. EXC_REAL_END(instruction_access_slb, 0x480, 0x80)
  1455. EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
  1456. GEN_INT_ENTRY instruction_access_slb, virt=1
  1457. EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
  1458. EXC_COMMON_BEGIN(instruction_access_slb_common)
  1459. GEN_COMMON instruction_access_slb
  1460. #ifdef CONFIG_PPC_64S_HASH_MMU
  1461. BEGIN_MMU_FTR_SECTION
  1462. /* HPT case, do SLB fault */
  1463. addi r3,r1,STACK_INT_FRAME_REGS
  1464. bl CFUNC(do_slb_fault)
  1465. cmpdi r3,0
  1466. bne- 1f
  1467. b fast_interrupt_return_srr
  1468. 1: /* Error case */
  1469. MMU_FTR_SECTION_ELSE
  1470. /* Radix case, access is outside page table range */
  1471. li r3,-EFAULT
  1472. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  1473. #else
  1474. li r3,-EFAULT
  1475. #endif
  1476. std r3,RESULT(r1)
  1477. addi r3,r1,STACK_INT_FRAME_REGS
  1478. bl CFUNC(do_bad_segment_interrupt)
  1479. b interrupt_return_srr
  1480. /**
  1481. * Interrupt 0x500 - External Interrupt.
  1482. * This is an asynchronous maskable interrupt in response to an "external
  1483. * exception" from the interrupt controller or hypervisor (e.g., device
  1484. * interrupt). It is maskable in hardware by clearing MSR[EE], and
  1485. * soft-maskable with IRQS_DISABLED mask (i.e., local_irq_disable()).
  1486. *
  1487. * When running in HV mode, Linux sets up the LPCR[LPES] bit such that
  1488. * interrupts are delivered with HSRR registers, guests use SRRs, which
  1489. * reqiures IHSRR_IF_HVMODE.
  1490. *
  1491. * On bare metal POWER9 and later, Linux sets the LPCR[HVICE] bit such that
  1492. * external interrupts are delivered as Hypervisor Virtualization Interrupts
  1493. * rather than External Interrupts.
  1494. *
  1495. * Handling:
  1496. * This calls into Linux IRQ handler. NVGPRs are not saved to reduce overhead,
  1497. * because registers at the time of the interrupt are not so important as it is
  1498. * asynchronous.
  1499. *
  1500. * If soft masked, the masked handler will note the pending interrupt for
  1501. * replay, and clear MSR[EE] in the interrupted context.
  1502. *
  1503. * CFAR is not required because this is an asynchronous interrupt that in
  1504. * general won't have much bearing on the state of the CPU, with the possible
  1505. * exception of crash/debug IPIs, but those are generally moving to use SRESET
  1506. * IPIs. Unless this is an HV interrupt and KVM HV is possible, in which case
  1507. * it may be exiting the guest and need CFAR to be saved.
  1508. */
  1509. INT_DEFINE_BEGIN(hardware_interrupt)
  1510. IVEC=0x500
  1511. IHSRR_IF_HVMODE=1
  1512. IMASK=IRQS_DISABLED
  1513. IKVM_REAL=1
  1514. IKVM_VIRT=1
  1515. ICFAR=0
  1516. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  1517. ICFAR_IF_HVMODE=1
  1518. #endif
  1519. INT_DEFINE_END(hardware_interrupt)
  1520. EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
  1521. GEN_INT_ENTRY hardware_interrupt, virt=0
  1522. EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
  1523. EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
  1524. GEN_INT_ENTRY hardware_interrupt, virt=1
  1525. EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
  1526. EXC_COMMON_BEGIN(hardware_interrupt_common)
  1527. GEN_COMMON hardware_interrupt
  1528. addi r3,r1,STACK_INT_FRAME_REGS
  1529. bl CFUNC(do_IRQ)
  1530. BEGIN_FTR_SECTION
  1531. b interrupt_return_hsrr
  1532. FTR_SECTION_ELSE
  1533. b interrupt_return_srr
  1534. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  1535. /**
  1536. * Interrupt 0x600 - Alignment Interrupt
  1537. * This is a synchronous interrupt in response to data alignment fault.
  1538. */
  1539. INT_DEFINE_BEGIN(alignment)
  1540. IVEC=0x600
  1541. IDAR=1
  1542. IDSISR=1
  1543. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  1544. IKVM_REAL=1
  1545. #endif
  1546. INT_DEFINE_END(alignment)
  1547. EXC_REAL_BEGIN(alignment, 0x600, 0x100)
  1548. GEN_INT_ENTRY alignment, virt=0
  1549. EXC_REAL_END(alignment, 0x600, 0x100)
  1550. EXC_VIRT_BEGIN(alignment, 0x4600, 0x100)
  1551. GEN_INT_ENTRY alignment, virt=1
  1552. EXC_VIRT_END(alignment, 0x4600, 0x100)
  1553. EXC_COMMON_BEGIN(alignment_common)
  1554. GEN_COMMON alignment
  1555. addi r3,r1,STACK_INT_FRAME_REGS
  1556. bl CFUNC(alignment_exception)
  1557. HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */
  1558. b interrupt_return_srr
  1559. /**
  1560. * Interrupt 0x700 - Program Interrupt (program check).
  1561. * This is a synchronous interrupt in response to various instruction faults:
  1562. * traps, privilege errors, TM errors, floating point exceptions.
  1563. *
  1564. * Handling:
  1565. * This interrupt may use the "emergency stack" in some cases when being taken
  1566. * from kernel context, which complicates handling.
  1567. */
  1568. INT_DEFINE_BEGIN(program_check)
  1569. IVEC=0x700
  1570. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  1571. IKVM_REAL=1
  1572. #endif
  1573. INT_DEFINE_END(program_check)
  1574. EXC_REAL_BEGIN(program_check, 0x700, 0x100)
  1575. EARLY_BOOT_FIXUP
  1576. GEN_INT_ENTRY program_check, virt=0
  1577. EXC_REAL_END(program_check, 0x700, 0x100)
  1578. EXC_VIRT_BEGIN(program_check, 0x4700, 0x100)
  1579. GEN_INT_ENTRY program_check, virt=1
  1580. EXC_VIRT_END(program_check, 0x4700, 0x100)
  1581. EXC_COMMON_BEGIN(program_check_common)
  1582. __GEN_COMMON_ENTRY program_check
  1583. /*
  1584. * It's possible to receive a TM Bad Thing type program check with
  1585. * userspace register values (in particular r1), but with SRR1 reporting
  1586. * that we came from the kernel. Normally that would confuse the bad
  1587. * stack logic, and we would report a bad kernel stack pointer. Instead
  1588. * we switch to the emergency stack if we're taking a TM Bad Thing from
  1589. * the kernel.
  1590. */
  1591. andi. r10,r12,MSR_PR
  1592. bne .Lnormal_stack /* If userspace, go normal path */
  1593. andis. r10,r12,(SRR1_PROGTM)@h
  1594. bne .Lemergency_stack /* If TM, emergency */
  1595. cmpdi r1,-INT_FRAME_SIZE /* check if r1 is in userspace */
  1596. blt .Lnormal_stack /* normal path if not */
  1597. /* Use the emergency stack */
  1598. .Lemergency_stack:
  1599. andi. r10,r12,MSR_PR /* Set CR0 correctly for label */
  1600. /* 3 in EXCEPTION_PROLOG_COMMON */
  1601. mr r10,r1 /* Save r1 */
  1602. ld r1,PACAEMERGSP(r13) /* Use emergency stack */
  1603. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  1604. __ISTACK(program_check)=0
  1605. __GEN_COMMON_BODY program_check
  1606. b .Ldo_program_check
  1607. .Lnormal_stack:
  1608. __ISTACK(program_check)=1
  1609. __GEN_COMMON_BODY program_check
  1610. .Ldo_program_check:
  1611. addi r3,r1,STACK_INT_FRAME_REGS
  1612. bl CFUNC(program_check_exception)
  1613. HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */
  1614. b interrupt_return_srr
  1615. /*
  1616. * Interrupt 0x800 - Floating-Point Unavailable Interrupt.
  1617. * This is a synchronous interrupt in response to executing an fp instruction
  1618. * with MSR[FP]=0.
  1619. *
  1620. * Handling:
  1621. * This will load FP registers and enable the FP bit if coming from userspace,
  1622. * otherwise report a bad kernel use of FP.
  1623. */
  1624. INT_DEFINE_BEGIN(fp_unavailable)
  1625. IVEC=0x800
  1626. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  1627. IKVM_REAL=1
  1628. #endif
  1629. IMSR_R12=1
  1630. INT_DEFINE_END(fp_unavailable)
  1631. EXC_REAL_BEGIN(fp_unavailable, 0x800, 0x100)
  1632. GEN_INT_ENTRY fp_unavailable, virt=0
  1633. EXC_REAL_END(fp_unavailable, 0x800, 0x100)
  1634. EXC_VIRT_BEGIN(fp_unavailable, 0x4800, 0x100)
  1635. GEN_INT_ENTRY fp_unavailable, virt=1
  1636. EXC_VIRT_END(fp_unavailable, 0x4800, 0x100)
  1637. EXC_COMMON_BEGIN(fp_unavailable_common)
  1638. GEN_COMMON fp_unavailable
  1639. bne 1f /* if from user, just load it up */
  1640. addi r3,r1,STACK_INT_FRAME_REGS
  1641. bl CFUNC(kernel_fp_unavailable_exception)
  1642. 0: trap
  1643. EMIT_BUG_ENTRY 0b, __FILE__, __LINE__, 0
  1644. 1:
  1645. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1646. BEGIN_FTR_SECTION
  1647. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1648. * transaction), go do TM stuff
  1649. */
  1650. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1651. bne- 2f
  1652. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  1653. #endif
  1654. bl CFUNC(load_up_fpu)
  1655. b fast_interrupt_return_srr
  1656. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1657. 2: /* User process was in a transaction */
  1658. addi r3,r1,STACK_INT_FRAME_REGS
  1659. bl CFUNC(fp_unavailable_tm)
  1660. b interrupt_return_srr
  1661. #endif
  1662. /**
  1663. * Interrupt 0x900 - Decrementer Interrupt.
  1664. * This is an asynchronous interrupt in response to a decrementer exception
  1665. * (e.g., DEC has wrapped below zero). It is maskable in hardware by clearing
  1666. * MSR[EE], and soft-maskable with IRQS_DISABLED mask (i.e.,
  1667. * local_irq_disable()).
  1668. *
  1669. * Handling:
  1670. * This calls into Linux timer handler. NVGPRs are not saved (see 0x500).
  1671. *
  1672. * If soft masked, the masked handler will note the pending interrupt for
  1673. * replay, and bump the decrementer to a high value, leaving MSR[EE] enabled
  1674. * in the interrupted context.
  1675. * If PPC_WATCHDOG is configured, the soft masked handler will actually set
  1676. * things back up to run soft_nmi_interrupt as a regular interrupt handler
  1677. * on the emergency stack.
  1678. *
  1679. * CFAR is not required because this is asynchronous (see hardware_interrupt).
  1680. * A watchdog interrupt may like to have CFAR, but usually the interesting
  1681. * branch is long gone by that point (e.g., infinite loop).
  1682. */
  1683. INT_DEFINE_BEGIN(decrementer)
  1684. IVEC=0x900
  1685. IMASK=IRQS_DISABLED
  1686. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  1687. IKVM_REAL=1
  1688. #endif
  1689. ICFAR=0
  1690. INT_DEFINE_END(decrementer)
  1691. EXC_REAL_BEGIN(decrementer, 0x900, 0x80)
  1692. GEN_INT_ENTRY decrementer, virt=0
  1693. EXC_REAL_END(decrementer, 0x900, 0x80)
  1694. EXC_VIRT_BEGIN(decrementer, 0x4900, 0x80)
  1695. GEN_INT_ENTRY decrementer, virt=1
  1696. EXC_VIRT_END(decrementer, 0x4900, 0x80)
  1697. EXC_COMMON_BEGIN(decrementer_common)
  1698. GEN_COMMON decrementer
  1699. addi r3,r1,STACK_INT_FRAME_REGS
  1700. bl CFUNC(timer_interrupt)
  1701. b interrupt_return_srr
  1702. /**
  1703. * Interrupt 0x980 - Hypervisor Decrementer Interrupt.
  1704. * This is an asynchronous interrupt, similar to 0x900 but for the HDEC
  1705. * register.
  1706. *
  1707. * Handling:
  1708. * Linux does not use this outside KVM where it's used to keep a host timer
  1709. * while the guest is given control of DEC. It should normally be caught by
  1710. * the KVM test and routed there.
  1711. */
  1712. INT_DEFINE_BEGIN(hdecrementer)
  1713. IVEC=0x980
  1714. IHSRR=1
  1715. ISTACK=0
  1716. IKVM_REAL=1
  1717. IKVM_VIRT=1
  1718. INT_DEFINE_END(hdecrementer)
  1719. EXC_REAL_BEGIN(hdecrementer, 0x980, 0x80)
  1720. GEN_INT_ENTRY hdecrementer, virt=0
  1721. EXC_REAL_END(hdecrementer, 0x980, 0x80)
  1722. EXC_VIRT_BEGIN(hdecrementer, 0x4980, 0x80)
  1723. GEN_INT_ENTRY hdecrementer, virt=1
  1724. EXC_VIRT_END(hdecrementer, 0x4980, 0x80)
  1725. EXC_COMMON_BEGIN(hdecrementer_common)
  1726. __GEN_COMMON_ENTRY hdecrementer
  1727. /*
  1728. * Hypervisor decrementer interrupts not caught by the KVM test
  1729. * shouldn't occur but are sometimes left pending on exit from a KVM
  1730. * guest. We don't need to do anything to clear them, as they are
  1731. * edge-triggered.
  1732. *
  1733. * Be careful to avoid touching the kernel stack.
  1734. */
  1735. li r10,0
  1736. stb r10,PACAHSRR_VALID(r13)
  1737. ld r10,PACA_EXGEN+EX_CTR(r13)
  1738. mtctr r10
  1739. mtcrf 0x80,r9
  1740. ld r9,PACA_EXGEN+EX_R9(r13)
  1741. ld r10,PACA_EXGEN+EX_R10(r13)
  1742. ld r11,PACA_EXGEN+EX_R11(r13)
  1743. ld r12,PACA_EXGEN+EX_R12(r13)
  1744. ld r13,PACA_EXGEN+EX_R13(r13)
  1745. HRFI_TO_KERNEL
  1746. /**
  1747. * Interrupt 0xa00 - Directed Privileged Doorbell Interrupt.
  1748. * This is an asynchronous interrupt in response to a msgsndp doorbell.
  1749. * It is maskable in hardware by clearing MSR[EE], and soft-maskable with
  1750. * IRQS_DISABLED mask (i.e., local_irq_disable()).
  1751. *
  1752. * Handling:
  1753. * Guests may use this for IPIs between threads in a core if the
  1754. * hypervisor supports it. NVGPRS are not saved (see 0x500).
  1755. *
  1756. * If soft masked, the masked handler will note the pending interrupt for
  1757. * replay, leaving MSR[EE] enabled in the interrupted context because the
  1758. * doorbells are edge triggered.
  1759. *
  1760. * CFAR is not required, similarly to hardware_interrupt.
  1761. */
  1762. INT_DEFINE_BEGIN(doorbell_super)
  1763. IVEC=0xa00
  1764. IMASK=IRQS_DISABLED
  1765. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  1766. IKVM_REAL=1
  1767. #endif
  1768. ICFAR=0
  1769. INT_DEFINE_END(doorbell_super)
  1770. EXC_REAL_BEGIN(doorbell_super, 0xa00, 0x100)
  1771. GEN_INT_ENTRY doorbell_super, virt=0
  1772. EXC_REAL_END(doorbell_super, 0xa00, 0x100)
  1773. EXC_VIRT_BEGIN(doorbell_super, 0x4a00, 0x100)
  1774. GEN_INT_ENTRY doorbell_super, virt=1
  1775. EXC_VIRT_END(doorbell_super, 0x4a00, 0x100)
  1776. EXC_COMMON_BEGIN(doorbell_super_common)
  1777. GEN_COMMON doorbell_super
  1778. addi r3,r1,STACK_INT_FRAME_REGS
  1779. #ifdef CONFIG_PPC_DOORBELL
  1780. bl CFUNC(doorbell_exception)
  1781. #else
  1782. bl CFUNC(unknown_async_exception)
  1783. #endif
  1784. b interrupt_return_srr
  1785. EXC_REAL_NONE(0xb00, 0x100)
  1786. EXC_VIRT_NONE(0x4b00, 0x100)
  1787. /**
  1788. * Interrupt 0xc00 - System Call Interrupt (syscall, hcall).
  1789. * This is a synchronous interrupt invoked with the "sc" instruction. The
  1790. * system call is invoked with "sc 0" and does not alter the HV bit, so it
  1791. * is directed to the currently running OS. The hypercall is invoked with
  1792. * "sc 1" and it sets HV=1, so it elevates to hypervisor.
  1793. *
  1794. * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
  1795. * 0x4c00 virtual mode.
  1796. *
  1797. * Handling:
  1798. * If the KVM test fires then it was due to a hypercall and is accordingly
  1799. * routed to KVM. Otherwise this executes a normal Linux system call.
  1800. *
  1801. * Call convention:
  1802. *
  1803. * syscall and hypercalls register conventions are documented in
  1804. * Documentation/arch/powerpc/syscall64-abi.rst and
  1805. * Documentation/arch/powerpc/papr_hcalls.rst respectively.
  1806. *
  1807. * The intersection of volatile registers that don't contain possible
  1808. * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
  1809. * without saving, though xer is not a good idea to use, as hardware may
  1810. * interpret some bits so it may be costly to change them.
  1811. */
  1812. INT_DEFINE_BEGIN(system_call)
  1813. IVEC=0xc00
  1814. IKVM_REAL=1
  1815. IKVM_VIRT=1
  1816. ICFAR=0
  1817. INT_DEFINE_END(system_call)
  1818. .macro SYSTEM_CALL virt
  1819. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  1820. /*
  1821. * There is a little bit of juggling to get syscall and hcall
  1822. * working well. Save r13 in ctr to avoid using SPRG scratch
  1823. * register.
  1824. *
  1825. * Userspace syscalls have already saved the PPR, hcalls must save
  1826. * it before setting HMT_MEDIUM.
  1827. */
  1828. mtctr r13
  1829. GET_PACA(r13)
  1830. std r10,PACA_EXGEN+EX_R10(r13)
  1831. INTERRUPT_TO_KERNEL
  1832. KVMTEST system_call kvm_hcall /* uses r10, branch to kvm_hcall */
  1833. mfctr r9
  1834. #else
  1835. mr r9,r13
  1836. GET_PACA(r13)
  1837. INTERRUPT_TO_KERNEL
  1838. #endif
  1839. /* We reach here with PACA in r13, r13 in r9. */
  1840. mfspr r11,SPRN_SRR0
  1841. mfspr r12,SPRN_SRR1
  1842. HMT_MEDIUM
  1843. .if ! \virt
  1844. __LOAD_HANDLER(r10, system_call_common_real, real_vectors)
  1845. mtctr r10
  1846. bctr
  1847. .else
  1848. #ifdef CONFIG_RELOCATABLE
  1849. __LOAD_HANDLER(r10, system_call_common, virt_vectors)
  1850. mtctr r10
  1851. bctr
  1852. #else
  1853. b system_call_common
  1854. #endif
  1855. .endif
  1856. .endm
  1857. EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
  1858. SYSTEM_CALL 0
  1859. EXC_REAL_END(system_call, 0xc00, 0x100)
  1860. EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
  1861. SYSTEM_CALL 1
  1862. EXC_VIRT_END(system_call, 0x4c00, 0x100)
  1863. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  1864. TRAMP_REAL_BEGIN(kvm_hcall)
  1865. std r9,PACA_EXGEN+EX_R9(r13)
  1866. std r11,PACA_EXGEN+EX_R11(r13)
  1867. std r12,PACA_EXGEN+EX_R12(r13)
  1868. mfcr r9
  1869. mfctr r10
  1870. std r10,PACA_EXGEN+EX_R13(r13)
  1871. li r10,0
  1872. std r10,PACA_EXGEN+EX_CFAR(r13)
  1873. std r10,PACA_EXGEN+EX_CTR(r13)
  1874. /*
  1875. * Save the PPR (on systems that support it) before changing to
  1876. * HMT_MEDIUM. That allows the KVM code to save that value into the
  1877. * guest state (it is the guest's PPR value).
  1878. */
  1879. BEGIN_FTR_SECTION
  1880. mfspr r10,SPRN_PPR
  1881. std r10,PACA_EXGEN+EX_PPR(r13)
  1882. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  1883. HMT_MEDIUM
  1884. #ifdef CONFIG_RELOCATABLE
  1885. /*
  1886. * Requires __LOAD_FAR_HANDLER beause kvmppc_hcall lives
  1887. * outside the head section.
  1888. */
  1889. __LOAD_FAR_HANDLER(r10, kvmppc_hcall, real_trampolines)
  1890. mtctr r10
  1891. bctr
  1892. #else
  1893. b kvmppc_hcall
  1894. #endif
  1895. #endif
  1896. /**
  1897. * Interrupt 0xd00 - Trace Interrupt.
  1898. * This is a synchronous interrupt in response to instruction step or
  1899. * breakpoint faults.
  1900. */
  1901. INT_DEFINE_BEGIN(single_step)
  1902. IVEC=0xd00
  1903. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  1904. IKVM_REAL=1
  1905. #endif
  1906. INT_DEFINE_END(single_step)
  1907. EXC_REAL_BEGIN(single_step, 0xd00, 0x100)
  1908. GEN_INT_ENTRY single_step, virt=0
  1909. EXC_REAL_END(single_step, 0xd00, 0x100)
  1910. EXC_VIRT_BEGIN(single_step, 0x4d00, 0x100)
  1911. GEN_INT_ENTRY single_step, virt=1
  1912. EXC_VIRT_END(single_step, 0x4d00, 0x100)
  1913. EXC_COMMON_BEGIN(single_step_common)
  1914. GEN_COMMON single_step
  1915. addi r3,r1,STACK_INT_FRAME_REGS
  1916. bl CFUNC(single_step_exception)
  1917. b interrupt_return_srr
  1918. /**
  1919. * Interrupt 0xe00 - Hypervisor Data Storage Interrupt (HDSI).
  1920. * This is a synchronous interrupt in response to an MMU fault caused by a
  1921. * guest data access.
  1922. *
  1923. * Handling:
  1924. * This should always get routed to KVM. In radix MMU mode, this is caused
  1925. * by a guest nested radix access that can't be performed due to the
  1926. * partition scope page table. In hash mode, this can be caused by guests
  1927. * running with translation disabled (virtual real mode) or with VPM enabled.
  1928. * KVM will update the page table structures or disallow the access.
  1929. */
  1930. INT_DEFINE_BEGIN(h_data_storage)
  1931. IVEC=0xe00
  1932. IHSRR=1
  1933. IDAR=1
  1934. IDSISR=1
  1935. IKVM_REAL=1
  1936. IKVM_VIRT=1
  1937. INT_DEFINE_END(h_data_storage)
  1938. EXC_REAL_BEGIN(h_data_storage, 0xe00, 0x20)
  1939. GEN_INT_ENTRY h_data_storage, virt=0, ool=1
  1940. EXC_REAL_END(h_data_storage, 0xe00, 0x20)
  1941. EXC_VIRT_BEGIN(h_data_storage, 0x4e00, 0x20)
  1942. GEN_INT_ENTRY h_data_storage, virt=1, ool=1
  1943. EXC_VIRT_END(h_data_storage, 0x4e00, 0x20)
  1944. EXC_COMMON_BEGIN(h_data_storage_common)
  1945. GEN_COMMON h_data_storage
  1946. addi r3,r1,STACK_INT_FRAME_REGS
  1947. BEGIN_MMU_FTR_SECTION
  1948. bl CFUNC(do_bad_page_fault_segv)
  1949. MMU_FTR_SECTION_ELSE
  1950. bl CFUNC(unknown_exception)
  1951. ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_TYPE_RADIX)
  1952. b interrupt_return_hsrr
  1953. /**
  1954. * Interrupt 0xe20 - Hypervisor Instruction Storage Interrupt (HISI).
  1955. * This is a synchronous interrupt in response to an MMU fault caused by a
  1956. * guest instruction fetch, similar to HDSI.
  1957. */
  1958. INT_DEFINE_BEGIN(h_instr_storage)
  1959. IVEC=0xe20
  1960. IHSRR=1
  1961. IKVM_REAL=1
  1962. IKVM_VIRT=1
  1963. INT_DEFINE_END(h_instr_storage)
  1964. EXC_REAL_BEGIN(h_instr_storage, 0xe20, 0x20)
  1965. GEN_INT_ENTRY h_instr_storage, virt=0, ool=1
  1966. EXC_REAL_END(h_instr_storage, 0xe20, 0x20)
  1967. EXC_VIRT_BEGIN(h_instr_storage, 0x4e20, 0x20)
  1968. GEN_INT_ENTRY h_instr_storage, virt=1, ool=1
  1969. EXC_VIRT_END(h_instr_storage, 0x4e20, 0x20)
  1970. EXC_COMMON_BEGIN(h_instr_storage_common)
  1971. GEN_COMMON h_instr_storage
  1972. addi r3,r1,STACK_INT_FRAME_REGS
  1973. bl CFUNC(unknown_exception)
  1974. b interrupt_return_hsrr
  1975. /**
  1976. * Interrupt 0xe40 - Hypervisor Emulation Assistance Interrupt.
  1977. */
  1978. INT_DEFINE_BEGIN(emulation_assist)
  1979. IVEC=0xe40
  1980. IHSRR=1
  1981. IKVM_REAL=1
  1982. IKVM_VIRT=1
  1983. INT_DEFINE_END(emulation_assist)
  1984. EXC_REAL_BEGIN(emulation_assist, 0xe40, 0x20)
  1985. GEN_INT_ENTRY emulation_assist, virt=0, ool=1
  1986. EXC_REAL_END(emulation_assist, 0xe40, 0x20)
  1987. EXC_VIRT_BEGIN(emulation_assist, 0x4e40, 0x20)
  1988. GEN_INT_ENTRY emulation_assist, virt=1, ool=1
  1989. EXC_VIRT_END(emulation_assist, 0x4e40, 0x20)
  1990. EXC_COMMON_BEGIN(emulation_assist_common)
  1991. GEN_COMMON emulation_assist
  1992. addi r3,r1,STACK_INT_FRAME_REGS
  1993. bl CFUNC(emulation_assist_interrupt)
  1994. HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */
  1995. b interrupt_return_hsrr
  1996. /**
  1997. * Interrupt 0xe60 - Hypervisor Maintenance Interrupt (HMI).
  1998. * This is an asynchronous interrupt caused by a Hypervisor Maintenance
  1999. * Exception. It is always taken in real mode but uses HSRR registers
  2000. * unlike SRESET and MCE.
  2001. *
  2002. * It is maskable in hardware by clearing MSR[EE], and partially soft-maskable
  2003. * with IRQS_DISABLED mask (i.e., local_irq_disable()).
  2004. *
  2005. * Handling:
  2006. * This is a special case, this is handled similarly to machine checks, with an
  2007. * initial real mode handler that is not soft-masked, which attempts to fix the
  2008. * problem. Then a regular handler which is soft-maskable and reports the
  2009. * problem.
  2010. *
  2011. * The emergency stack is used for the early real mode handler.
  2012. *
  2013. * XXX: unclear why MCE and HMI schemes could not be made common, e.g.,
  2014. * either use soft-masking for the MCE, or use irq_work for the HMI.
  2015. *
  2016. * KVM:
  2017. * Unlike MCE, this calls into KVM without calling the real mode handler
  2018. * first.
  2019. */
  2020. INT_DEFINE_BEGIN(hmi_exception_early)
  2021. IVEC=0xe60
  2022. IHSRR=1
  2023. IREALMODE_COMMON=1
  2024. ISTACK=0
  2025. IKUAP=0 /* We don't touch AMR here, we never go to virtual mode */
  2026. IKVM_REAL=1
  2027. INT_DEFINE_END(hmi_exception_early)
  2028. INT_DEFINE_BEGIN(hmi_exception)
  2029. IVEC=0xe60
  2030. IHSRR=1
  2031. IMASK=IRQS_DISABLED
  2032. IKVM_REAL=1
  2033. INT_DEFINE_END(hmi_exception)
  2034. EXC_REAL_BEGIN(hmi_exception, 0xe60, 0x20)
  2035. GEN_INT_ENTRY hmi_exception_early, virt=0, ool=1
  2036. EXC_REAL_END(hmi_exception, 0xe60, 0x20)
  2037. EXC_VIRT_NONE(0x4e60, 0x20)
  2038. EXC_COMMON_BEGIN(hmi_exception_early_common)
  2039. __GEN_REALMODE_COMMON_ENTRY hmi_exception_early
  2040. mr r10,r1 /* Save r1 */
  2041. ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
  2042. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  2043. __GEN_COMMON_BODY hmi_exception_early
  2044. addi r3,r1,STACK_INT_FRAME_REGS
  2045. bl CFUNC(hmi_exception_realmode)
  2046. cmpdi cr0,r3,0
  2047. bne 1f
  2048. EXCEPTION_RESTORE_REGS hsrr=1
  2049. HRFI_TO_USER_OR_KERNEL
  2050. 1:
  2051. /*
  2052. * Go to virtual mode and pull the HMI event information from
  2053. * firmware.
  2054. */
  2055. EXCEPTION_RESTORE_REGS hsrr=1
  2056. GEN_INT_ENTRY hmi_exception, virt=0
  2057. EXC_COMMON_BEGIN(hmi_exception_common)
  2058. GEN_COMMON hmi_exception
  2059. addi r3,r1,STACK_INT_FRAME_REGS
  2060. bl CFUNC(handle_hmi_exception)
  2061. b interrupt_return_hsrr
  2062. /**
  2063. * Interrupt 0xe80 - Directed Hypervisor Doorbell Interrupt.
  2064. * This is an asynchronous interrupt in response to a msgsnd doorbell.
  2065. * Similar to the 0xa00 doorbell but for host rather than guest.
  2066. *
  2067. * CFAR is not required (similar to doorbell_interrupt), unless KVM HV
  2068. * is enabled, in which case it may be a guest exit. Most PowerNV kernels
  2069. * include KVM support so it would be nice if this could be dynamically
  2070. * patched out if KVM was not currently running any guests.
  2071. */
  2072. INT_DEFINE_BEGIN(h_doorbell)
  2073. IVEC=0xe80
  2074. IHSRR=1
  2075. IMASK=IRQS_DISABLED
  2076. IKVM_REAL=1
  2077. IKVM_VIRT=1
  2078. #ifndef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  2079. ICFAR=0
  2080. #endif
  2081. INT_DEFINE_END(h_doorbell)
  2082. EXC_REAL_BEGIN(h_doorbell, 0xe80, 0x20)
  2083. GEN_INT_ENTRY h_doorbell, virt=0, ool=1
  2084. EXC_REAL_END(h_doorbell, 0xe80, 0x20)
  2085. EXC_VIRT_BEGIN(h_doorbell, 0x4e80, 0x20)
  2086. GEN_INT_ENTRY h_doorbell, virt=1, ool=1
  2087. EXC_VIRT_END(h_doorbell, 0x4e80, 0x20)
  2088. EXC_COMMON_BEGIN(h_doorbell_common)
  2089. GEN_COMMON h_doorbell
  2090. addi r3,r1,STACK_INT_FRAME_REGS
  2091. #ifdef CONFIG_PPC_DOORBELL
  2092. bl CFUNC(doorbell_exception)
  2093. #else
  2094. bl CFUNC(unknown_async_exception)
  2095. #endif
  2096. b interrupt_return_hsrr
  2097. /**
  2098. * Interrupt 0xea0 - Hypervisor Virtualization Interrupt.
  2099. * This is an asynchronous interrupt in response to an "external exception".
  2100. * Similar to 0x500 but for host only.
  2101. *
  2102. * Like h_doorbell, CFAR is only required for KVM HV because this can be
  2103. * a guest exit.
  2104. */
  2105. INT_DEFINE_BEGIN(h_virt_irq)
  2106. IVEC=0xea0
  2107. IHSRR=1
  2108. IMASK=IRQS_DISABLED
  2109. IKVM_REAL=1
  2110. IKVM_VIRT=1
  2111. #ifndef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  2112. ICFAR=0
  2113. #endif
  2114. INT_DEFINE_END(h_virt_irq)
  2115. EXC_REAL_BEGIN(h_virt_irq, 0xea0, 0x20)
  2116. GEN_INT_ENTRY h_virt_irq, virt=0, ool=1
  2117. EXC_REAL_END(h_virt_irq, 0xea0, 0x20)
  2118. EXC_VIRT_BEGIN(h_virt_irq, 0x4ea0, 0x20)
  2119. GEN_INT_ENTRY h_virt_irq, virt=1, ool=1
  2120. EXC_VIRT_END(h_virt_irq, 0x4ea0, 0x20)
  2121. EXC_COMMON_BEGIN(h_virt_irq_common)
  2122. GEN_COMMON h_virt_irq
  2123. addi r3,r1,STACK_INT_FRAME_REGS
  2124. bl CFUNC(do_IRQ)
  2125. b interrupt_return_hsrr
  2126. EXC_REAL_NONE(0xec0, 0x20)
  2127. EXC_VIRT_NONE(0x4ec0, 0x20)
  2128. EXC_REAL_NONE(0xee0, 0x20)
  2129. EXC_VIRT_NONE(0x4ee0, 0x20)
  2130. /*
  2131. * Interrupt 0xf00 - Performance Monitor Interrupt (PMI, PMU).
  2132. * This is an asynchronous interrupt in response to a PMU exception.
  2133. * It is maskable in hardware by clearing MSR[EE], and soft-maskable with
  2134. * IRQS_PMI_DISABLED mask (NOTE: NOT local_irq_disable()).
  2135. *
  2136. * Handling:
  2137. * This calls into the perf subsystem.
  2138. *
  2139. * Like the watchdog soft-nmi, it appears an NMI interrupt to Linux, in that it
  2140. * runs under local_irq_disable. However it may be soft-masked in
  2141. * powerpc-specific code.
  2142. *
  2143. * If soft masked, the masked handler will note the pending interrupt for
  2144. * replay, and clear MSR[EE] in the interrupted context.
  2145. *
  2146. * CFAR is not used by perf interrupts so not required.
  2147. */
  2148. INT_DEFINE_BEGIN(performance_monitor)
  2149. IVEC=0xf00
  2150. IMASK=IRQS_PMI_DISABLED
  2151. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  2152. IKVM_REAL=1
  2153. #endif
  2154. ICFAR=0
  2155. INT_DEFINE_END(performance_monitor)
  2156. EXC_REAL_BEGIN(performance_monitor, 0xf00, 0x20)
  2157. GEN_INT_ENTRY performance_monitor, virt=0, ool=1
  2158. EXC_REAL_END(performance_monitor, 0xf00, 0x20)
  2159. EXC_VIRT_BEGIN(performance_monitor, 0x4f00, 0x20)
  2160. GEN_INT_ENTRY performance_monitor, virt=1, ool=1
  2161. EXC_VIRT_END(performance_monitor, 0x4f00, 0x20)
  2162. EXC_COMMON_BEGIN(performance_monitor_common)
  2163. GEN_COMMON performance_monitor
  2164. addi r3,r1,STACK_INT_FRAME_REGS
  2165. lbz r4,PACAIRQSOFTMASK(r13)
  2166. cmpdi r4,IRQS_ENABLED
  2167. bne 1f
  2168. bl CFUNC(performance_monitor_exception_async)
  2169. b interrupt_return_srr
  2170. 1:
  2171. bl CFUNC(performance_monitor_exception_nmi)
  2172. /* Clear MSR_RI before setting SRR0 and SRR1. */
  2173. li r9,0
  2174. mtmsrd r9,1
  2175. kuap_kernel_restore r9, r10
  2176. EXCEPTION_RESTORE_REGS hsrr=0
  2177. RFI_TO_KERNEL
  2178. /**
  2179. * Interrupt 0xf20 - Vector Unavailable Interrupt.
  2180. * This is a synchronous interrupt in response to
  2181. * executing a vector (or altivec) instruction with MSR[VEC]=0.
  2182. * Similar to FP unavailable.
  2183. */
  2184. INT_DEFINE_BEGIN(altivec_unavailable)
  2185. IVEC=0xf20
  2186. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  2187. IKVM_REAL=1
  2188. #endif
  2189. IMSR_R12=1
  2190. INT_DEFINE_END(altivec_unavailable)
  2191. EXC_REAL_BEGIN(altivec_unavailable, 0xf20, 0x20)
  2192. GEN_INT_ENTRY altivec_unavailable, virt=0, ool=1
  2193. EXC_REAL_END(altivec_unavailable, 0xf20, 0x20)
  2194. EXC_VIRT_BEGIN(altivec_unavailable, 0x4f20, 0x20)
  2195. GEN_INT_ENTRY altivec_unavailable, virt=1, ool=1
  2196. EXC_VIRT_END(altivec_unavailable, 0x4f20, 0x20)
  2197. EXC_COMMON_BEGIN(altivec_unavailable_common)
  2198. GEN_COMMON altivec_unavailable
  2199. #ifdef CONFIG_ALTIVEC
  2200. BEGIN_FTR_SECTION
  2201. beq 1f
  2202. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  2203. BEGIN_FTR_SECTION_NESTED(69)
  2204. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  2205. * transaction), go do TM stuff
  2206. */
  2207. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  2208. bne- 2f
  2209. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  2210. #endif
  2211. bl CFUNC(load_up_altivec)
  2212. b fast_interrupt_return_srr
  2213. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  2214. 2: /* User process was in a transaction */
  2215. addi r3,r1,STACK_INT_FRAME_REGS
  2216. bl CFUNC(altivec_unavailable_tm)
  2217. b interrupt_return_srr
  2218. #endif
  2219. 1:
  2220. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  2221. #endif
  2222. addi r3,r1,STACK_INT_FRAME_REGS
  2223. bl CFUNC(altivec_unavailable_exception)
  2224. b interrupt_return_srr
  2225. /**
  2226. * Interrupt 0xf40 - VSX Unavailable Interrupt.
  2227. * This is a synchronous interrupt in response to
  2228. * executing a VSX instruction with MSR[VSX]=0.
  2229. * Similar to FP unavailable.
  2230. */
  2231. INT_DEFINE_BEGIN(vsx_unavailable)
  2232. IVEC=0xf40
  2233. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  2234. IKVM_REAL=1
  2235. #endif
  2236. IMSR_R12=1
  2237. INT_DEFINE_END(vsx_unavailable)
  2238. EXC_REAL_BEGIN(vsx_unavailable, 0xf40, 0x20)
  2239. GEN_INT_ENTRY vsx_unavailable, virt=0, ool=1
  2240. EXC_REAL_END(vsx_unavailable, 0xf40, 0x20)
  2241. EXC_VIRT_BEGIN(vsx_unavailable, 0x4f40, 0x20)
  2242. GEN_INT_ENTRY vsx_unavailable, virt=1, ool=1
  2243. EXC_VIRT_END(vsx_unavailable, 0x4f40, 0x20)
  2244. EXC_COMMON_BEGIN(vsx_unavailable_common)
  2245. GEN_COMMON vsx_unavailable
  2246. #ifdef CONFIG_VSX
  2247. BEGIN_FTR_SECTION
  2248. beq 1f
  2249. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  2250. BEGIN_FTR_SECTION_NESTED(69)
  2251. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  2252. * transaction), go do TM stuff
  2253. */
  2254. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  2255. bne- 2f
  2256. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  2257. #endif
  2258. b load_up_vsx
  2259. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  2260. 2: /* User process was in a transaction */
  2261. addi r3,r1,STACK_INT_FRAME_REGS
  2262. bl CFUNC(vsx_unavailable_tm)
  2263. b interrupt_return_srr
  2264. #endif
  2265. 1:
  2266. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  2267. #endif
  2268. addi r3,r1,STACK_INT_FRAME_REGS
  2269. bl CFUNC(vsx_unavailable_exception)
  2270. b interrupt_return_srr
  2271. /**
  2272. * Interrupt 0xf60 - Facility Unavailable Interrupt.
  2273. * This is a synchronous interrupt in response to
  2274. * executing an instruction without access to the facility that can be
  2275. * resolved by the OS (e.g., FSCR, MSR).
  2276. * Similar to FP unavailable.
  2277. */
  2278. INT_DEFINE_BEGIN(facility_unavailable)
  2279. IVEC=0xf60
  2280. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  2281. IKVM_REAL=1
  2282. #endif
  2283. INT_DEFINE_END(facility_unavailable)
  2284. EXC_REAL_BEGIN(facility_unavailable, 0xf60, 0x20)
  2285. GEN_INT_ENTRY facility_unavailable, virt=0, ool=1
  2286. EXC_REAL_END(facility_unavailable, 0xf60, 0x20)
  2287. EXC_VIRT_BEGIN(facility_unavailable, 0x4f60, 0x20)
  2288. GEN_INT_ENTRY facility_unavailable, virt=1, ool=1
  2289. EXC_VIRT_END(facility_unavailable, 0x4f60, 0x20)
  2290. EXC_COMMON_BEGIN(facility_unavailable_common)
  2291. GEN_COMMON facility_unavailable
  2292. addi r3,r1,STACK_INT_FRAME_REGS
  2293. bl CFUNC(facility_unavailable_exception)
  2294. HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */
  2295. b interrupt_return_srr
  2296. /**
  2297. * Interrupt 0xf60 - Hypervisor Facility Unavailable Interrupt.
  2298. * This is a synchronous interrupt in response to
  2299. * executing an instruction without access to the facility that can only
  2300. * be resolved in HV mode (e.g., HFSCR).
  2301. * Similar to FP unavailable.
  2302. */
  2303. INT_DEFINE_BEGIN(h_facility_unavailable)
  2304. IVEC=0xf80
  2305. IHSRR=1
  2306. IKVM_REAL=1
  2307. IKVM_VIRT=1
  2308. INT_DEFINE_END(h_facility_unavailable)
  2309. EXC_REAL_BEGIN(h_facility_unavailable, 0xf80, 0x20)
  2310. GEN_INT_ENTRY h_facility_unavailable, virt=0, ool=1
  2311. EXC_REAL_END(h_facility_unavailable, 0xf80, 0x20)
  2312. EXC_VIRT_BEGIN(h_facility_unavailable, 0x4f80, 0x20)
  2313. GEN_INT_ENTRY h_facility_unavailable, virt=1, ool=1
  2314. EXC_VIRT_END(h_facility_unavailable, 0x4f80, 0x20)
  2315. EXC_COMMON_BEGIN(h_facility_unavailable_common)
  2316. GEN_COMMON h_facility_unavailable
  2317. addi r3,r1,STACK_INT_FRAME_REGS
  2318. bl CFUNC(facility_unavailable_exception)
  2319. /* XXX Shouldn't be necessary in practice */
  2320. HANDLER_RESTORE_NVGPRS()
  2321. b interrupt_return_hsrr
  2322. EXC_REAL_NONE(0xfa0, 0x20)
  2323. EXC_VIRT_NONE(0x4fa0, 0x20)
  2324. EXC_REAL_NONE(0xfc0, 0x20)
  2325. EXC_VIRT_NONE(0x4fc0, 0x20)
  2326. EXC_REAL_NONE(0xfe0, 0x20)
  2327. EXC_VIRT_NONE(0x4fe0, 0x20)
  2328. EXC_REAL_NONE(0x1000, 0x100)
  2329. EXC_VIRT_NONE(0x5000, 0x100)
  2330. EXC_REAL_NONE(0x1100, 0x100)
  2331. EXC_VIRT_NONE(0x5100, 0x100)
  2332. #ifdef CONFIG_CBE_RAS
  2333. INT_DEFINE_BEGIN(cbe_system_error)
  2334. IVEC=0x1200
  2335. IHSRR=1
  2336. INT_DEFINE_END(cbe_system_error)
  2337. EXC_REAL_BEGIN(cbe_system_error, 0x1200, 0x100)
  2338. GEN_INT_ENTRY cbe_system_error, virt=0
  2339. EXC_REAL_END(cbe_system_error, 0x1200, 0x100)
  2340. EXC_VIRT_NONE(0x5200, 0x100)
  2341. EXC_COMMON_BEGIN(cbe_system_error_common)
  2342. GEN_COMMON cbe_system_error
  2343. addi r3,r1,STACK_INT_FRAME_REGS
  2344. bl CFUNC(cbe_system_error_exception)
  2345. b interrupt_return_hsrr
  2346. #else /* CONFIG_CBE_RAS */
  2347. EXC_REAL_NONE(0x1200, 0x100)
  2348. EXC_VIRT_NONE(0x5200, 0x100)
  2349. #endif
  2350. /**
  2351. * Interrupt 0x1300 - Instruction Address Breakpoint Interrupt.
  2352. * This has been removed from the ISA before 2.01, which is the earliest
  2353. * 64-bit BookS ISA supported, however the G5 / 970 implements this
  2354. * interrupt with a non-architected feature available through the support
  2355. * processor interface.
  2356. */
  2357. INT_DEFINE_BEGIN(instruction_breakpoint)
  2358. IVEC=0x1300
  2359. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  2360. IKVM_REAL=1
  2361. #endif
  2362. INT_DEFINE_END(instruction_breakpoint)
  2363. EXC_REAL_BEGIN(instruction_breakpoint, 0x1300, 0x100)
  2364. GEN_INT_ENTRY instruction_breakpoint, virt=0
  2365. EXC_REAL_END(instruction_breakpoint, 0x1300, 0x100)
  2366. EXC_VIRT_BEGIN(instruction_breakpoint, 0x5300, 0x100)
  2367. GEN_INT_ENTRY instruction_breakpoint, virt=1
  2368. EXC_VIRT_END(instruction_breakpoint, 0x5300, 0x100)
  2369. EXC_COMMON_BEGIN(instruction_breakpoint_common)
  2370. GEN_COMMON instruction_breakpoint
  2371. addi r3,r1,STACK_INT_FRAME_REGS
  2372. bl CFUNC(instruction_breakpoint_exception)
  2373. b interrupt_return_srr
  2374. EXC_REAL_NONE(0x1400, 0x100)
  2375. EXC_VIRT_NONE(0x5400, 0x100)
  2376. /**
  2377. * Interrupt 0x1500 - Soft Patch Interrupt
  2378. *
  2379. * Handling:
  2380. * This is an implementation specific interrupt which can be used for a
  2381. * range of exceptions.
  2382. *
  2383. * This interrupt handler is unique in that it runs the denormal assist
  2384. * code even for guests (and even in guest context) without going to KVM,
  2385. * for speed. POWER9 does not raise denorm exceptions, so this special case
  2386. * could be phased out in future to reduce special cases.
  2387. */
  2388. INT_DEFINE_BEGIN(denorm_exception)
  2389. IVEC=0x1500
  2390. IHSRR=1
  2391. IBRANCH_TO_COMMON=0
  2392. IKVM_REAL=1
  2393. INT_DEFINE_END(denorm_exception)
  2394. EXC_REAL_BEGIN(denorm_exception, 0x1500, 0x100)
  2395. GEN_INT_ENTRY denorm_exception, virt=0
  2396. #ifdef CONFIG_PPC_DENORMALISATION
  2397. andis. r10,r12,(HSRR1_DENORM)@h /* denorm? */
  2398. bne+ denorm_assist
  2399. #endif
  2400. GEN_BRANCH_TO_COMMON denorm_exception, virt=0
  2401. EXC_REAL_END(denorm_exception, 0x1500, 0x100)
  2402. #ifdef CONFIG_PPC_DENORMALISATION
  2403. EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
  2404. GEN_INT_ENTRY denorm_exception, virt=1
  2405. andis. r10,r12,(HSRR1_DENORM)@h /* denorm? */
  2406. bne+ denorm_assist
  2407. GEN_BRANCH_TO_COMMON denorm_exception, virt=1
  2408. EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
  2409. #else
  2410. EXC_VIRT_NONE(0x5500, 0x100)
  2411. #endif
  2412. #ifdef CONFIG_PPC_DENORMALISATION
  2413. TRAMP_REAL_BEGIN(denorm_assist)
  2414. BEGIN_FTR_SECTION
  2415. /*
  2416. * To denormalise we need to move a copy of the register to itself.
  2417. * For POWER6 do that here for all FP regs.
  2418. */
  2419. mfmsr r10
  2420. ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
  2421. xori r10,r10,(MSR_FE0|MSR_FE1)
  2422. mtmsrd r10
  2423. sync
  2424. .Lreg=0
  2425. .rept 32
  2426. fmr .Lreg,.Lreg
  2427. .Lreg=.Lreg+1
  2428. .endr
  2429. FTR_SECTION_ELSE
  2430. /*
  2431. * To denormalise we need to move a copy of the register to itself.
  2432. * For POWER7 do that here for the first 32 VSX registers only.
  2433. */
  2434. mfmsr r10
  2435. oris r10,r10,MSR_VSX@h
  2436. mtmsrd r10
  2437. sync
  2438. .Lreg=0
  2439. .rept 32
  2440. XVCPSGNDP(.Lreg,.Lreg,.Lreg)
  2441. .Lreg=.Lreg+1
  2442. .endr
  2443. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
  2444. BEGIN_FTR_SECTION
  2445. b denorm_done
  2446. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  2447. /*
  2448. * To denormalise we need to move a copy of the register to itself.
  2449. * For POWER8 we need to do that for all 64 VSX registers
  2450. */
  2451. .Lreg=32
  2452. .rept 32
  2453. XVCPSGNDP(.Lreg,.Lreg,.Lreg)
  2454. .Lreg=.Lreg+1
  2455. .endr
  2456. denorm_done:
  2457. mfspr r11,SPRN_HSRR0
  2458. subi r11,r11,4
  2459. mtspr SPRN_HSRR0,r11
  2460. mtcrf 0x80,r9
  2461. ld r9,PACA_EXGEN+EX_R9(r13)
  2462. BEGIN_FTR_SECTION
  2463. ld r10,PACA_EXGEN+EX_PPR(r13)
  2464. mtspr SPRN_PPR,r10
  2465. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  2466. BEGIN_FTR_SECTION
  2467. ld r10,PACA_EXGEN+EX_CFAR(r13)
  2468. mtspr SPRN_CFAR,r10
  2469. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  2470. li r10,0
  2471. stb r10,PACAHSRR_VALID(r13)
  2472. ld r10,PACA_EXGEN+EX_R10(r13)
  2473. ld r11,PACA_EXGEN+EX_R11(r13)
  2474. ld r12,PACA_EXGEN+EX_R12(r13)
  2475. ld r13,PACA_EXGEN+EX_R13(r13)
  2476. HRFI_TO_UNKNOWN
  2477. b .
  2478. #endif
  2479. EXC_COMMON_BEGIN(denorm_exception_common)
  2480. GEN_COMMON denorm_exception
  2481. addi r3,r1,STACK_INT_FRAME_REGS
  2482. bl CFUNC(unknown_exception)
  2483. b interrupt_return_hsrr
  2484. #ifdef CONFIG_CBE_RAS
  2485. INT_DEFINE_BEGIN(cbe_maintenance)
  2486. IVEC=0x1600
  2487. IHSRR=1
  2488. INT_DEFINE_END(cbe_maintenance)
  2489. EXC_REAL_BEGIN(cbe_maintenance, 0x1600, 0x100)
  2490. GEN_INT_ENTRY cbe_maintenance, virt=0
  2491. EXC_REAL_END(cbe_maintenance, 0x1600, 0x100)
  2492. EXC_VIRT_NONE(0x5600, 0x100)
  2493. EXC_COMMON_BEGIN(cbe_maintenance_common)
  2494. GEN_COMMON cbe_maintenance
  2495. addi r3,r1,STACK_INT_FRAME_REGS
  2496. bl CFUNC(cbe_maintenance_exception)
  2497. b interrupt_return_hsrr
  2498. #else /* CONFIG_CBE_RAS */
  2499. EXC_REAL_NONE(0x1600, 0x100)
  2500. EXC_VIRT_NONE(0x5600, 0x100)
  2501. #endif
  2502. INT_DEFINE_BEGIN(altivec_assist)
  2503. IVEC=0x1700
  2504. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  2505. IKVM_REAL=1
  2506. #endif
  2507. INT_DEFINE_END(altivec_assist)
  2508. EXC_REAL_BEGIN(altivec_assist, 0x1700, 0x100)
  2509. GEN_INT_ENTRY altivec_assist, virt=0
  2510. EXC_REAL_END(altivec_assist, 0x1700, 0x100)
  2511. EXC_VIRT_BEGIN(altivec_assist, 0x5700, 0x100)
  2512. GEN_INT_ENTRY altivec_assist, virt=1
  2513. EXC_VIRT_END(altivec_assist, 0x5700, 0x100)
  2514. EXC_COMMON_BEGIN(altivec_assist_common)
  2515. GEN_COMMON altivec_assist
  2516. addi r3,r1,STACK_INT_FRAME_REGS
  2517. #ifdef CONFIG_ALTIVEC
  2518. bl CFUNC(altivec_assist_exception)
  2519. HANDLER_RESTORE_NVGPRS() /* instruction emulation may change GPRs */
  2520. #else
  2521. bl CFUNC(unknown_exception)
  2522. #endif
  2523. b interrupt_return_srr
  2524. #ifdef CONFIG_CBE_RAS
  2525. INT_DEFINE_BEGIN(cbe_thermal)
  2526. IVEC=0x1800
  2527. IHSRR=1
  2528. INT_DEFINE_END(cbe_thermal)
  2529. EXC_REAL_BEGIN(cbe_thermal, 0x1800, 0x100)
  2530. GEN_INT_ENTRY cbe_thermal, virt=0
  2531. EXC_REAL_END(cbe_thermal, 0x1800, 0x100)
  2532. EXC_VIRT_NONE(0x5800, 0x100)
  2533. EXC_COMMON_BEGIN(cbe_thermal_common)
  2534. GEN_COMMON cbe_thermal
  2535. addi r3,r1,STACK_INT_FRAME_REGS
  2536. bl CFUNC(cbe_thermal_exception)
  2537. b interrupt_return_hsrr
  2538. #else /* CONFIG_CBE_RAS */
  2539. EXC_REAL_NONE(0x1800, 0x100)
  2540. EXC_VIRT_NONE(0x5800, 0x100)
  2541. #endif
  2542. #ifdef CONFIG_PPC_WATCHDOG
  2543. INT_DEFINE_BEGIN(soft_nmi)
  2544. IVEC=0x900
  2545. ISTACK=0
  2546. ICFAR=0
  2547. INT_DEFINE_END(soft_nmi)
  2548. /*
  2549. * Branch to soft_nmi_interrupt using the emergency stack. The emergency
  2550. * stack is one that is usable by maskable interrupts so long as MSR_EE
  2551. * remains off. It is used for recovery when something has corrupted the
  2552. * normal kernel stack, for example. The "soft NMI" must not use the process
  2553. * stack because we want irq disabled sections to avoid touching the stack
  2554. * at all (other than PMU interrupts), so use the emergency stack for this,
  2555. * and run it entirely with interrupts hard disabled.
  2556. */
  2557. EXC_COMMON_BEGIN(soft_nmi_common)
  2558. mr r10,r1
  2559. ld r1,PACAEMERGSP(r13)
  2560. subi r1,r1,INT_FRAME_SIZE
  2561. __GEN_COMMON_BODY soft_nmi
  2562. addi r3,r1,STACK_INT_FRAME_REGS
  2563. bl CFUNC(soft_nmi_interrupt)
  2564. /* Clear MSR_RI before setting SRR0 and SRR1. */
  2565. li r9,0
  2566. mtmsrd r9,1
  2567. kuap_kernel_restore r9, r10
  2568. EXCEPTION_RESTORE_REGS hsrr=0
  2569. RFI_TO_KERNEL
  2570. #endif /* CONFIG_PPC_WATCHDOG */
  2571. /*
  2572. * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
  2573. * - If it was a decrementer interrupt, we bump the dec to max and return.
  2574. * - If it was a doorbell we return immediately since doorbells are edge
  2575. * triggered and won't automatically refire.
  2576. * - If it was a HMI we return immediately since we handled it in realmode
  2577. * and it won't refire.
  2578. * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.
  2579. * This is called with r10 containing the value to OR to the paca field.
  2580. */
  2581. .macro MASKED_INTERRUPT hsrr=0
  2582. .if \hsrr
  2583. masked_Hinterrupt:
  2584. .else
  2585. masked_interrupt:
  2586. .endif
  2587. stw r9,PACA_EXGEN+EX_CCR(r13)
  2588. #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
  2589. /*
  2590. * Ensure there was no previous MUST_HARD_MASK interrupt or
  2591. * HARD_DIS setting. If this does fire, the interrupt is still
  2592. * masked and MSR[EE] will be cleared on return, so no need to
  2593. * panic, but somebody probably enabled MSR[EE] under
  2594. * PACA_IRQ_HARD_DIS, mtmsr(mfmsr() | MSR_x) being a common
  2595. * cause.
  2596. */
  2597. lbz r9,PACAIRQHAPPENED(r13)
  2598. andi. r9,r9,(PACA_IRQ_MUST_HARD_MASK|PACA_IRQ_HARD_DIS)
  2599. 0: tdnei r9,0
  2600. EMIT_WARN_ENTRY 0b,__FILE__,__LINE__,(BUGFLAG_WARNING | BUGFLAG_ONCE)
  2601. #endif
  2602. lbz r9,PACAIRQHAPPENED(r13)
  2603. or r9,r9,r10
  2604. stb r9,PACAIRQHAPPENED(r13)
  2605. .if ! \hsrr
  2606. cmpwi r10,PACA_IRQ_DEC
  2607. bne 1f
  2608. LOAD_REG_IMMEDIATE(r9, 0x7fffffff)
  2609. mtspr SPRN_DEC,r9
  2610. #ifdef CONFIG_PPC_WATCHDOG
  2611. lwz r9,PACA_EXGEN+EX_CCR(r13)
  2612. b soft_nmi_common
  2613. #else
  2614. b 2f
  2615. #endif
  2616. .endif
  2617. 1: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK
  2618. beq 2f
  2619. xori r12,r12,MSR_EE /* clear MSR_EE */
  2620. .if \hsrr
  2621. mtspr SPRN_HSRR1,r12
  2622. .else
  2623. mtspr SPRN_SRR1,r12
  2624. .endif
  2625. ori r9,r9,PACA_IRQ_HARD_DIS
  2626. stb r9,PACAIRQHAPPENED(r13)
  2627. 2: /* done */
  2628. li r9,0
  2629. .if \hsrr
  2630. stb r9,PACAHSRR_VALID(r13)
  2631. .else
  2632. stb r9,PACASRR_VALID(r13)
  2633. .endif
  2634. SEARCH_RESTART_TABLE
  2635. cmpdi r12,0
  2636. beq 3f
  2637. .if \hsrr
  2638. mtspr SPRN_HSRR0,r12
  2639. .else
  2640. mtspr SPRN_SRR0,r12
  2641. .endif
  2642. 3:
  2643. ld r9,PACA_EXGEN+EX_CTR(r13)
  2644. mtctr r9
  2645. lwz r9,PACA_EXGEN+EX_CCR(r13)
  2646. mtcrf 0x80,r9
  2647. std r1,PACAR1(r13)
  2648. ld r9,PACA_EXGEN+EX_R9(r13)
  2649. ld r10,PACA_EXGEN+EX_R10(r13)
  2650. ld r11,PACA_EXGEN+EX_R11(r13)
  2651. ld r12,PACA_EXGEN+EX_R12(r13)
  2652. ld r13,PACA_EXGEN+EX_R13(r13)
  2653. /* May return to masked low address where r13 is not set up */
  2654. .if \hsrr
  2655. HRFI_TO_KERNEL
  2656. .else
  2657. RFI_TO_KERNEL
  2658. .endif
  2659. b .
  2660. .endm
  2661. TRAMP_REAL_BEGIN(stf_barrier_fallback)
  2662. std r9,PACA_EXRFI+EX_R9(r13)
  2663. std r10,PACA_EXRFI+EX_R10(r13)
  2664. sync
  2665. ld r9,PACA_EXRFI+EX_R9(r13)
  2666. ld r10,PACA_EXRFI+EX_R10(r13)
  2667. ori 31,31,0
  2668. .rept 14
  2669. b 1f
  2670. 1:
  2671. .endr
  2672. blr
  2673. /* Clobbers r10, r11, ctr */
  2674. .macro L1D_DISPLACEMENT_FLUSH
  2675. ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
  2676. ld r11,PACA_L1D_FLUSH_SIZE(r13)
  2677. srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
  2678. mtctr r11
  2679. DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
  2680. /* order ld/st prior to dcbt stop all streams with flushing */
  2681. sync
  2682. /*
  2683. * The load addresses are at staggered offsets within cachelines,
  2684. * which suits some pipelines better (on others it should not
  2685. * hurt).
  2686. */
  2687. 1:
  2688. ld r11,(0x80 + 8)*0(r10)
  2689. ld r11,(0x80 + 8)*1(r10)
  2690. ld r11,(0x80 + 8)*2(r10)
  2691. ld r11,(0x80 + 8)*3(r10)
  2692. ld r11,(0x80 + 8)*4(r10)
  2693. ld r11,(0x80 + 8)*5(r10)
  2694. ld r11,(0x80 + 8)*6(r10)
  2695. ld r11,(0x80 + 8)*7(r10)
  2696. addi r10,r10,0x80*8
  2697. bdnz 1b
  2698. .endm
  2699. TRAMP_REAL_BEGIN(entry_flush_fallback)
  2700. std r9,PACA_EXRFI+EX_R9(r13)
  2701. std r10,PACA_EXRFI+EX_R10(r13)
  2702. std r11,PACA_EXRFI+EX_R11(r13)
  2703. mfctr r9
  2704. L1D_DISPLACEMENT_FLUSH
  2705. mtctr r9
  2706. ld r9,PACA_EXRFI+EX_R9(r13)
  2707. ld r10,PACA_EXRFI+EX_R10(r13)
  2708. ld r11,PACA_EXRFI+EX_R11(r13)
  2709. blr
  2710. /*
  2711. * The SCV entry flush happens with interrupts enabled, so it must disable
  2712. * to prevent EXRFI being clobbered by NMIs (e.g., soft_nmi_common). r10
  2713. * (containing LR) does not need to be preserved here because scv entry
  2714. * puts 0 in the pt_regs, CTR can be clobbered for the same reason.
  2715. */
  2716. TRAMP_REAL_BEGIN(scv_entry_flush_fallback)
  2717. li r10,0
  2718. mtmsrd r10,1
  2719. lbz r10,PACAIRQHAPPENED(r13)
  2720. ori r10,r10,PACA_IRQ_HARD_DIS
  2721. stb r10,PACAIRQHAPPENED(r13)
  2722. std r11,PACA_EXRFI+EX_R11(r13)
  2723. L1D_DISPLACEMENT_FLUSH
  2724. ld r11,PACA_EXRFI+EX_R11(r13)
  2725. li r10,MSR_RI
  2726. mtmsrd r10,1
  2727. blr
  2728. TRAMP_REAL_BEGIN(rfi_flush_fallback)
  2729. SET_SCRATCH0(r13);
  2730. GET_PACA(r13);
  2731. std r1,PACA_EXRFI+EX_R12(r13)
  2732. ld r1,PACAKSAVE(r13)
  2733. std r9,PACA_EXRFI+EX_R9(r13)
  2734. std r10,PACA_EXRFI+EX_R10(r13)
  2735. std r11,PACA_EXRFI+EX_R11(r13)
  2736. mfctr r9
  2737. L1D_DISPLACEMENT_FLUSH
  2738. mtctr r9
  2739. ld r9,PACA_EXRFI+EX_R9(r13)
  2740. ld r10,PACA_EXRFI+EX_R10(r13)
  2741. ld r11,PACA_EXRFI+EX_R11(r13)
  2742. ld r1,PACA_EXRFI+EX_R12(r13)
  2743. GET_SCRATCH0(r13);
  2744. rfid
  2745. TRAMP_REAL_BEGIN(hrfi_flush_fallback)
  2746. SET_SCRATCH0(r13);
  2747. GET_PACA(r13);
  2748. std r1,PACA_EXRFI+EX_R12(r13)
  2749. ld r1,PACAKSAVE(r13)
  2750. std r9,PACA_EXRFI+EX_R9(r13)
  2751. std r10,PACA_EXRFI+EX_R10(r13)
  2752. std r11,PACA_EXRFI+EX_R11(r13)
  2753. mfctr r9
  2754. L1D_DISPLACEMENT_FLUSH
  2755. mtctr r9
  2756. ld r9,PACA_EXRFI+EX_R9(r13)
  2757. ld r10,PACA_EXRFI+EX_R10(r13)
  2758. ld r11,PACA_EXRFI+EX_R11(r13)
  2759. ld r1,PACA_EXRFI+EX_R12(r13)
  2760. GET_SCRATCH0(r13);
  2761. hrfid
  2762. TRAMP_REAL_BEGIN(rfscv_flush_fallback)
  2763. /* system call volatile */
  2764. mr r7,r13
  2765. GET_PACA(r13);
  2766. mr r8,r1
  2767. ld r1,PACAKSAVE(r13)
  2768. mfctr r9
  2769. ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
  2770. ld r11,PACA_L1D_FLUSH_SIZE(r13)
  2771. srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
  2772. mtctr r11
  2773. DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
  2774. /* order ld/st prior to dcbt stop all streams with flushing */
  2775. sync
  2776. /*
  2777. * The load adresses are at staggered offsets within cachelines,
  2778. * which suits some pipelines better (on others it should not
  2779. * hurt).
  2780. */
  2781. 1:
  2782. ld r11,(0x80 + 8)*0(r10)
  2783. ld r11,(0x80 + 8)*1(r10)
  2784. ld r11,(0x80 + 8)*2(r10)
  2785. ld r11,(0x80 + 8)*3(r10)
  2786. ld r11,(0x80 + 8)*4(r10)
  2787. ld r11,(0x80 + 8)*5(r10)
  2788. ld r11,(0x80 + 8)*6(r10)
  2789. ld r11,(0x80 + 8)*7(r10)
  2790. addi r10,r10,0x80*8
  2791. bdnz 1b
  2792. mtctr r9
  2793. li r9,0
  2794. li r10,0
  2795. li r11,0
  2796. mr r1,r8
  2797. mr r13,r7
  2798. RFSCV
  2799. USE_TEXT_SECTION()
  2800. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  2801. kvm_interrupt:
  2802. /*
  2803. * The conditional branch in KVMTEST can't reach all the way,
  2804. * make a stub.
  2805. */
  2806. b kvmppc_interrupt
  2807. #endif
  2808. _GLOBAL(do_uaccess_flush)
  2809. UACCESS_FLUSH_FIXUP_SECTION
  2810. nop
  2811. nop
  2812. nop
  2813. blr
  2814. L1D_DISPLACEMENT_FLUSH
  2815. blr
  2816. _ASM_NOKPROBE_SYMBOL(do_uaccess_flush)
  2817. EXPORT_SYMBOL(do_uaccess_flush)
  2818. MASKED_INTERRUPT
  2819. MASKED_INTERRUPT hsrr=1
  2820. USE_FIXED_SECTION(virt_trampolines)
  2821. /*
  2822. * All code below __end_soft_masked is treated as soft-masked. If
  2823. * any code runs here with MSR[EE]=1, it must then cope with pending
  2824. * soft interrupt being raised (i.e., by ensuring it is replayed).
  2825. *
  2826. * The __end_interrupts marker must be past the out-of-line (OOL)
  2827. * handlers, so that they are copied to real address 0x100 when running
  2828. * a relocatable kernel. This ensures they can be reached from the short
  2829. * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
  2830. * directly, without using LOAD_HANDLER().
  2831. */
  2832. .align 7
  2833. .globl __end_interrupts
  2834. __end_interrupts:
  2835. DEFINE_FIXED_SYMBOL(__end_interrupts, virt_trampolines)
  2836. CLOSE_FIXED_SECTION(real_vectors);
  2837. CLOSE_FIXED_SECTION(real_trampolines);
  2838. CLOSE_FIXED_SECTION(virt_vectors);
  2839. CLOSE_FIXED_SECTION(virt_trampolines);
  2840. USE_TEXT_SECTION()
  2841. /* MSR[RI] should be clear because this uses SRR[01] */
  2842. _GLOBAL(enable_machine_check)
  2843. mflr r0
  2844. bcl 20,31,$+4
  2845. 0: mflr r3
  2846. addi r3,r3,(1f - 0b)
  2847. mtspr SPRN_SRR0,r3
  2848. mfmsr r3
  2849. ori r3,r3,MSR_ME
  2850. mtspr SPRN_SRR1,r3
  2851. RFI_TO_KERNEL
  2852. 1: mtlr r0
  2853. blr
  2854. /* MSR[RI] should be clear because this uses SRR[01] */
  2855. SYM_FUNC_START_LOCAL(disable_machine_check)
  2856. mflr r0
  2857. bcl 20,31,$+4
  2858. 0: mflr r3
  2859. addi r3,r3,(1f - 0b)
  2860. mtspr SPRN_SRR0,r3
  2861. mfmsr r3
  2862. li r4,MSR_ME
  2863. andc r3,r3,r4
  2864. mtspr SPRN_SRR1,r3
  2865. RFI_TO_KERNEL
  2866. 1: mtlr r0
  2867. blr
  2868. SYM_FUNC_END(disable_machine_check)