traps_64.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* arch/sparc64/kernel/traps.c
  3. *
  4. * Copyright (C) 1995,1997,2008,2009,2012 David S. Miller ([email protected])
  5. * Copyright (C) 1997,1999,2000 Jakub Jelinek ([email protected])
  6. */
  7. /*
  8. * I like traps on v9, :))))
  9. */
  10. #include <linux/extable.h>
  11. #include <linux/sched/mm.h>
  12. #include <linux/sched/debug.h>
  13. #include <linux/linkage.h>
  14. #include <linux/kernel.h>
  15. #include <linux/signal.h>
  16. #include <linux/smp.h>
  17. #include <linux/mm.h>
  18. #include <linux/init.h>
  19. #include <linux/kallsyms.h>
  20. #include <linux/kdebug.h>
  21. #include <linux/ftrace.h>
  22. #include <linux/reboot.h>
  23. #include <linux/gfp.h>
  24. #include <linux/context_tracking.h>
  25. #include <asm/smp.h>
  26. #include <asm/delay.h>
  27. #include <asm/ptrace.h>
  28. #include <asm/oplib.h>
  29. #include <asm/page.h>
  30. #include <asm/unistd.h>
  31. #include <linux/uaccess.h>
  32. #include <asm/fpumacro.h>
  33. #include <asm/lsu.h>
  34. #include <asm/dcu.h>
  35. #include <asm/estate.h>
  36. #include <asm/chafsr.h>
  37. #include <asm/sfafsr.h>
  38. #include <asm/psrcompat.h>
  39. #include <asm/processor.h>
  40. #include <asm/timer.h>
  41. #include <asm/head.h>
  42. #include <asm/prom.h>
  43. #include <asm/memctrl.h>
  44. #include <asm/cacheflush.h>
  45. #include <asm/setup.h>
  46. #include "entry.h"
  47. #include "kernel.h"
  48. #include "kstack.h"
  49. /* When an irrecoverable trap occurs at tl > 0, the trap entry
  50. * code logs the trap state registers at every level in the trap
  51. * stack. It is found at (pt_regs + sizeof(pt_regs)) and the layout
  52. * is as follows:
  53. */
  54. struct tl1_traplog {
  55. struct {
  56. unsigned long tstate;
  57. unsigned long tpc;
  58. unsigned long tnpc;
  59. unsigned long tt;
  60. } trapstack[4];
  61. unsigned long tl;
  62. };
  63. static void dump_tl1_traplog(struct tl1_traplog *p)
  64. {
  65. int i, limit;
  66. printk(KERN_EMERG "TRAPLOG: Error at trap level 0x%lx, "
  67. "dumping track stack.\n", p->tl);
  68. limit = (tlb_type == hypervisor) ? 2 : 4;
  69. for (i = 0; i < limit; i++) {
  70. printk(KERN_EMERG
  71. "TRAPLOG: Trap level %d TSTATE[%016lx] TPC[%016lx] "
  72. "TNPC[%016lx] TT[%lx]\n",
  73. i + 1,
  74. p->trapstack[i].tstate, p->trapstack[i].tpc,
  75. p->trapstack[i].tnpc, p->trapstack[i].tt);
  76. printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
  77. }
  78. }
  79. void bad_trap(struct pt_regs *regs, long lvl)
  80. {
  81. char buffer[36];
  82. if (notify_die(DIE_TRAP, "bad trap", regs,
  83. 0, lvl, SIGTRAP) == NOTIFY_STOP)
  84. return;
  85. if (lvl < 0x100) {
  86. sprintf(buffer, "Bad hw trap %lx at tl0\n", lvl);
  87. die_if_kernel(buffer, regs);
  88. }
  89. lvl -= 0x100;
  90. if (regs->tstate & TSTATE_PRIV) {
  91. sprintf(buffer, "Kernel bad sw trap %lx", lvl);
  92. die_if_kernel(buffer, regs);
  93. }
  94. if (test_thread_flag(TIF_32BIT)) {
  95. regs->tpc &= 0xffffffff;
  96. regs->tnpc &= 0xffffffff;
  97. }
  98. force_sig_fault_trapno(SIGILL, ILL_ILLTRP,
  99. (void __user *)regs->tpc, lvl);
  100. }
  101. void bad_trap_tl1(struct pt_regs *regs, long lvl)
  102. {
  103. char buffer[36];
  104. if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
  105. 0, lvl, SIGTRAP) == NOTIFY_STOP)
  106. return;
  107. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  108. sprintf (buffer, "Bad trap %lx at tl>0", lvl);
  109. die_if_kernel (buffer, regs);
  110. }
  111. #ifdef CONFIG_DEBUG_BUGVERBOSE
  112. void do_BUG(const char *file, int line)
  113. {
  114. bust_spinlocks(1);
  115. printk("kernel BUG at %s:%d!\n", file, line);
  116. }
  117. EXPORT_SYMBOL(do_BUG);
  118. #endif
  119. static DEFINE_SPINLOCK(dimm_handler_lock);
  120. static dimm_printer_t dimm_handler;
  121. static int sprintf_dimm(int synd_code, unsigned long paddr, char *buf, int buflen)
  122. {
  123. unsigned long flags;
  124. int ret = -ENODEV;
  125. spin_lock_irqsave(&dimm_handler_lock, flags);
  126. if (dimm_handler) {
  127. ret = dimm_handler(synd_code, paddr, buf, buflen);
  128. } else if (tlb_type == spitfire) {
  129. if (prom_getunumber(synd_code, paddr, buf, buflen) == -1)
  130. ret = -EINVAL;
  131. else
  132. ret = 0;
  133. } else
  134. ret = -ENODEV;
  135. spin_unlock_irqrestore(&dimm_handler_lock, flags);
  136. return ret;
  137. }
  138. int register_dimm_printer(dimm_printer_t func)
  139. {
  140. unsigned long flags;
  141. int ret = 0;
  142. spin_lock_irqsave(&dimm_handler_lock, flags);
  143. if (!dimm_handler)
  144. dimm_handler = func;
  145. else
  146. ret = -EEXIST;
  147. spin_unlock_irqrestore(&dimm_handler_lock, flags);
  148. return ret;
  149. }
  150. EXPORT_SYMBOL_GPL(register_dimm_printer);
  151. void unregister_dimm_printer(dimm_printer_t func)
  152. {
  153. unsigned long flags;
  154. spin_lock_irqsave(&dimm_handler_lock, flags);
  155. if (dimm_handler == func)
  156. dimm_handler = NULL;
  157. spin_unlock_irqrestore(&dimm_handler_lock, flags);
  158. }
  159. EXPORT_SYMBOL_GPL(unregister_dimm_printer);
  160. void spitfire_insn_access_exception(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
  161. {
  162. enum ctx_state prev_state = exception_enter();
  163. if (notify_die(DIE_TRAP, "instruction access exception", regs,
  164. 0, 0x8, SIGTRAP) == NOTIFY_STOP)
  165. goto out;
  166. if (regs->tstate & TSTATE_PRIV) {
  167. printk("spitfire_insn_access_exception: SFSR[%016lx] "
  168. "SFAR[%016lx], going.\n", sfsr, sfar);
  169. die_if_kernel("Iax", regs);
  170. }
  171. if (test_thread_flag(TIF_32BIT)) {
  172. regs->tpc &= 0xffffffff;
  173. regs->tnpc &= 0xffffffff;
  174. }
  175. force_sig_fault(SIGSEGV, SEGV_MAPERR, (void __user *)regs->tpc);
  176. out:
  177. exception_exit(prev_state);
  178. }
  179. void spitfire_insn_access_exception_tl1(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
  180. {
  181. if (notify_die(DIE_TRAP_TL1, "instruction access exception tl1", regs,
  182. 0, 0x8, SIGTRAP) == NOTIFY_STOP)
  183. return;
  184. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  185. spitfire_insn_access_exception(regs, sfsr, sfar);
  186. }
  187. void sun4v_insn_access_exception(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
  188. {
  189. unsigned short type = (type_ctx >> 16);
  190. unsigned short ctx = (type_ctx & 0xffff);
  191. if (notify_die(DIE_TRAP, "instruction access exception", regs,
  192. 0, 0x8, SIGTRAP) == NOTIFY_STOP)
  193. return;
  194. if (regs->tstate & TSTATE_PRIV) {
  195. printk("sun4v_insn_access_exception: ADDR[%016lx] "
  196. "CTX[%04x] TYPE[%04x], going.\n",
  197. addr, ctx, type);
  198. die_if_kernel("Iax", regs);
  199. }
  200. if (test_thread_flag(TIF_32BIT)) {
  201. regs->tpc &= 0xffffffff;
  202. regs->tnpc &= 0xffffffff;
  203. }
  204. force_sig_fault(SIGSEGV, SEGV_MAPERR, (void __user *) addr);
  205. }
  206. void sun4v_insn_access_exception_tl1(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
  207. {
  208. if (notify_die(DIE_TRAP_TL1, "instruction access exception tl1", regs,
  209. 0, 0x8, SIGTRAP) == NOTIFY_STOP)
  210. return;
  211. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  212. sun4v_insn_access_exception(regs, addr, type_ctx);
  213. }
  214. bool is_no_fault_exception(struct pt_regs *regs)
  215. {
  216. unsigned char asi;
  217. u32 insn;
  218. if (get_user(insn, (u32 __user *)regs->tpc) == -EFAULT)
  219. return false;
  220. /*
  221. * Must do a little instruction decoding here in order to
  222. * decide on a course of action. The bits of interest are:
  223. * insn[31:30] = op, where 3 indicates the load/store group
  224. * insn[24:19] = op3, which identifies individual opcodes
  225. * insn[13] indicates an immediate offset
  226. * op3[4]=1 identifies alternate space instructions
  227. * op3[5:4]=3 identifies floating point instructions
  228. * op3[2]=1 identifies stores
  229. * See "Opcode Maps" in the appendix of any Sparc V9
  230. * architecture spec for full details.
  231. */
  232. if ((insn & 0xc0800000) == 0xc0800000) { /* op=3, op3[4]=1 */
  233. if (insn & 0x2000) /* immediate offset */
  234. asi = (regs->tstate >> 24); /* saved %asi */
  235. else
  236. asi = (insn >> 5); /* immediate asi */
  237. if ((asi & 0xf6) == ASI_PNF) {
  238. if (insn & 0x200000) /* op3[2], stores */
  239. return false;
  240. if (insn & 0x1000000) /* op3[5:4]=3 (fp) */
  241. handle_ldf_stq(insn, regs);
  242. else
  243. handle_ld_nf(insn, regs);
  244. return true;
  245. }
  246. }
  247. return false;
  248. }
  249. void spitfire_data_access_exception(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
  250. {
  251. enum ctx_state prev_state = exception_enter();
  252. if (notify_die(DIE_TRAP, "data access exception", regs,
  253. 0, 0x30, SIGTRAP) == NOTIFY_STOP)
  254. goto out;
  255. if (regs->tstate & TSTATE_PRIV) {
  256. /* Test if this comes from uaccess places. */
  257. const struct exception_table_entry *entry;
  258. entry = search_exception_tables(regs->tpc);
  259. if (entry) {
  260. /* Ouch, somebody is trying VM hole tricks on us... */
  261. #ifdef DEBUG_EXCEPTIONS
  262. printk("Exception: PC<%016lx> faddr<UNKNOWN>\n", regs->tpc);
  263. printk("EX_TABLE: insn<%016lx> fixup<%016lx>\n",
  264. regs->tpc, entry->fixup);
  265. #endif
  266. regs->tpc = entry->fixup;
  267. regs->tnpc = regs->tpc + 4;
  268. goto out;
  269. }
  270. /* Shit... */
  271. printk("spitfire_data_access_exception: SFSR[%016lx] "
  272. "SFAR[%016lx], going.\n", sfsr, sfar);
  273. die_if_kernel("Dax", regs);
  274. }
  275. if (is_no_fault_exception(regs))
  276. return;
  277. force_sig_fault(SIGSEGV, SEGV_MAPERR, (void __user *)sfar);
  278. out:
  279. exception_exit(prev_state);
  280. }
  281. void spitfire_data_access_exception_tl1(struct pt_regs *regs, unsigned long sfsr, unsigned long sfar)
  282. {
  283. if (notify_die(DIE_TRAP_TL1, "data access exception tl1", regs,
  284. 0, 0x30, SIGTRAP) == NOTIFY_STOP)
  285. return;
  286. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  287. spitfire_data_access_exception(regs, sfsr, sfar);
  288. }
  289. void sun4v_data_access_exception(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
  290. {
  291. unsigned short type = (type_ctx >> 16);
  292. unsigned short ctx = (type_ctx & 0xffff);
  293. if (notify_die(DIE_TRAP, "data access exception", regs,
  294. 0, 0x8, SIGTRAP) == NOTIFY_STOP)
  295. return;
  296. if (regs->tstate & TSTATE_PRIV) {
  297. /* Test if this comes from uaccess places. */
  298. const struct exception_table_entry *entry;
  299. entry = search_exception_tables(regs->tpc);
  300. if (entry) {
  301. /* Ouch, somebody is trying VM hole tricks on us... */
  302. #ifdef DEBUG_EXCEPTIONS
  303. printk("Exception: PC<%016lx> faddr<UNKNOWN>\n", regs->tpc);
  304. printk("EX_TABLE: insn<%016lx> fixup<%016lx>\n",
  305. regs->tpc, entry->fixup);
  306. #endif
  307. regs->tpc = entry->fixup;
  308. regs->tnpc = regs->tpc + 4;
  309. return;
  310. }
  311. printk("sun4v_data_access_exception: ADDR[%016lx] "
  312. "CTX[%04x] TYPE[%04x], going.\n",
  313. addr, ctx, type);
  314. die_if_kernel("Dax", regs);
  315. }
  316. if (test_thread_flag(TIF_32BIT)) {
  317. regs->tpc &= 0xffffffff;
  318. regs->tnpc &= 0xffffffff;
  319. }
  320. if (is_no_fault_exception(regs))
  321. return;
  322. /* MCD (Memory Corruption Detection) disabled trap (TT=0x19) in HV
  323. * is vectored thorugh data access exception trap with fault type
  324. * set to HV_FAULT_TYPE_MCD_DIS. Check for MCD disabled trap.
  325. * Accessing an address with invalid ASI for the address, for
  326. * example setting an ADI tag on an address with ASI_MCD_PRIMARY
  327. * when TTE.mcd is not set for the VA, is also vectored into
  328. * kerbel by HV as data access exception with fault type set to
  329. * HV_FAULT_TYPE_INV_ASI.
  330. */
  331. switch (type) {
  332. case HV_FAULT_TYPE_INV_ASI:
  333. force_sig_fault(SIGILL, ILL_ILLADR, (void __user *)addr);
  334. break;
  335. case HV_FAULT_TYPE_MCD_DIS:
  336. force_sig_fault(SIGSEGV, SEGV_ACCADI, (void __user *)addr);
  337. break;
  338. default:
  339. force_sig_fault(SIGSEGV, SEGV_MAPERR, (void __user *)addr);
  340. break;
  341. }
  342. }
  343. void sun4v_data_access_exception_tl1(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
  344. {
  345. if (notify_die(DIE_TRAP_TL1, "data access exception tl1", regs,
  346. 0, 0x8, SIGTRAP) == NOTIFY_STOP)
  347. return;
  348. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  349. sun4v_data_access_exception(regs, addr, type_ctx);
  350. }
  351. #ifdef CONFIG_PCI
  352. #include "pci_impl.h"
  353. #endif
  354. /* When access exceptions happen, we must do this. */
  355. static void spitfire_clean_and_reenable_l1_caches(void)
  356. {
  357. unsigned long va;
  358. if (tlb_type != spitfire)
  359. BUG();
  360. /* Clean 'em. */
  361. for (va = 0; va < (PAGE_SIZE << 1); va += 32) {
  362. spitfire_put_icache_tag(va, 0x0);
  363. spitfire_put_dcache_tag(va, 0x0);
  364. }
  365. /* Re-enable in LSU. */
  366. __asm__ __volatile__("flush %%g6\n\t"
  367. "membar #Sync\n\t"
  368. "stxa %0, [%%g0] %1\n\t"
  369. "membar #Sync"
  370. : /* no outputs */
  371. : "r" (LSU_CONTROL_IC | LSU_CONTROL_DC |
  372. LSU_CONTROL_IM | LSU_CONTROL_DM),
  373. "i" (ASI_LSU_CONTROL)
  374. : "memory");
  375. }
  376. static void spitfire_enable_estate_errors(void)
  377. {
  378. __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
  379. "membar #Sync"
  380. : /* no outputs */
  381. : "r" (ESTATE_ERR_ALL),
  382. "i" (ASI_ESTATE_ERROR_EN));
  383. }
  384. static char ecc_syndrome_table[] = {
  385. 0x4c, 0x40, 0x41, 0x48, 0x42, 0x48, 0x48, 0x49,
  386. 0x43, 0x48, 0x48, 0x49, 0x48, 0x49, 0x49, 0x4a,
  387. 0x44, 0x48, 0x48, 0x20, 0x48, 0x39, 0x4b, 0x48,
  388. 0x48, 0x25, 0x31, 0x48, 0x28, 0x48, 0x48, 0x2c,
  389. 0x45, 0x48, 0x48, 0x21, 0x48, 0x3d, 0x04, 0x48,
  390. 0x48, 0x4b, 0x35, 0x48, 0x2d, 0x48, 0x48, 0x29,
  391. 0x48, 0x00, 0x01, 0x48, 0x0a, 0x48, 0x48, 0x4b,
  392. 0x0f, 0x48, 0x48, 0x4b, 0x48, 0x49, 0x49, 0x48,
  393. 0x46, 0x48, 0x48, 0x2a, 0x48, 0x3b, 0x27, 0x48,
  394. 0x48, 0x4b, 0x33, 0x48, 0x22, 0x48, 0x48, 0x2e,
  395. 0x48, 0x19, 0x1d, 0x48, 0x1b, 0x4a, 0x48, 0x4b,
  396. 0x1f, 0x48, 0x4a, 0x4b, 0x48, 0x4b, 0x4b, 0x48,
  397. 0x48, 0x4b, 0x24, 0x48, 0x07, 0x48, 0x48, 0x36,
  398. 0x4b, 0x48, 0x48, 0x3e, 0x48, 0x30, 0x38, 0x48,
  399. 0x49, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x16, 0x48,
  400. 0x48, 0x12, 0x4b, 0x48, 0x49, 0x48, 0x48, 0x4b,
  401. 0x47, 0x48, 0x48, 0x2f, 0x48, 0x3f, 0x4b, 0x48,
  402. 0x48, 0x06, 0x37, 0x48, 0x23, 0x48, 0x48, 0x2b,
  403. 0x48, 0x05, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x32,
  404. 0x26, 0x48, 0x48, 0x3a, 0x48, 0x34, 0x3c, 0x48,
  405. 0x48, 0x11, 0x15, 0x48, 0x13, 0x4a, 0x48, 0x4b,
  406. 0x17, 0x48, 0x4a, 0x4b, 0x48, 0x4b, 0x4b, 0x48,
  407. 0x49, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x1e, 0x48,
  408. 0x48, 0x1a, 0x4b, 0x48, 0x49, 0x48, 0x48, 0x4b,
  409. 0x48, 0x08, 0x0d, 0x48, 0x02, 0x48, 0x48, 0x49,
  410. 0x03, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x4b, 0x48,
  411. 0x49, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x10, 0x48,
  412. 0x48, 0x14, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x4b,
  413. 0x49, 0x48, 0x48, 0x49, 0x48, 0x4b, 0x18, 0x48,
  414. 0x48, 0x1c, 0x4b, 0x48, 0x4b, 0x48, 0x48, 0x4b,
  415. 0x4a, 0x0c, 0x09, 0x48, 0x0e, 0x48, 0x48, 0x4b,
  416. 0x0b, 0x48, 0x48, 0x4b, 0x48, 0x4b, 0x4b, 0x4a
  417. };
  418. static char *syndrome_unknown = "<Unknown>";
  419. static void spitfire_log_udb_syndrome(unsigned long afar, unsigned long udbh, unsigned long udbl, unsigned long bit)
  420. {
  421. unsigned short scode;
  422. char memmod_str[64], *p;
  423. if (udbl & bit) {
  424. scode = ecc_syndrome_table[udbl & 0xff];
  425. if (sprintf_dimm(scode, afar, memmod_str, sizeof(memmod_str)) < 0)
  426. p = syndrome_unknown;
  427. else
  428. p = memmod_str;
  429. printk(KERN_WARNING "CPU[%d]: UDBL Syndrome[%x] "
  430. "Memory Module \"%s\"\n",
  431. smp_processor_id(), scode, p);
  432. }
  433. if (udbh & bit) {
  434. scode = ecc_syndrome_table[udbh & 0xff];
  435. if (sprintf_dimm(scode, afar, memmod_str, sizeof(memmod_str)) < 0)
  436. p = syndrome_unknown;
  437. else
  438. p = memmod_str;
  439. printk(KERN_WARNING "CPU[%d]: UDBH Syndrome[%x] "
  440. "Memory Module \"%s\"\n",
  441. smp_processor_id(), scode, p);
  442. }
  443. }
  444. static void spitfire_cee_log(unsigned long afsr, unsigned long afar, unsigned long udbh, unsigned long udbl, int tl1, struct pt_regs *regs)
  445. {
  446. printk(KERN_WARNING "CPU[%d]: Correctable ECC Error "
  447. "AFSR[%lx] AFAR[%016lx] UDBL[%lx] UDBH[%lx] TL>1[%d]\n",
  448. smp_processor_id(), afsr, afar, udbl, udbh, tl1);
  449. spitfire_log_udb_syndrome(afar, udbh, udbl, UDBE_CE);
  450. /* We always log it, even if someone is listening for this
  451. * trap.
  452. */
  453. notify_die(DIE_TRAP, "Correctable ECC Error", regs,
  454. 0, TRAP_TYPE_CEE, SIGTRAP);
  455. /* The Correctable ECC Error trap does not disable I/D caches. So
  456. * we only have to restore the ESTATE Error Enable register.
  457. */
  458. spitfire_enable_estate_errors();
  459. }
  460. static void spitfire_ue_log(unsigned long afsr, unsigned long afar, unsigned long udbh, unsigned long udbl, unsigned long tt, int tl1, struct pt_regs *regs)
  461. {
  462. printk(KERN_WARNING "CPU[%d]: Uncorrectable Error AFSR[%lx] "
  463. "AFAR[%lx] UDBL[%lx] UDBH[%ld] TT[%lx] TL>1[%d]\n",
  464. smp_processor_id(), afsr, afar, udbl, udbh, tt, tl1);
  465. /* XXX add more human friendly logging of the error status
  466. * XXX as is implemented for cheetah
  467. */
  468. spitfire_log_udb_syndrome(afar, udbh, udbl, UDBE_UE);
  469. /* We always log it, even if someone is listening for this
  470. * trap.
  471. */
  472. notify_die(DIE_TRAP, "Uncorrectable Error", regs,
  473. 0, tt, SIGTRAP);
  474. if (regs->tstate & TSTATE_PRIV) {
  475. if (tl1)
  476. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  477. die_if_kernel("UE", regs);
  478. }
  479. /* XXX need more intelligent processing here, such as is implemented
  480. * XXX for cheetah errors, in fact if the E-cache still holds the
  481. * XXX line with bad parity this will loop
  482. */
  483. spitfire_clean_and_reenable_l1_caches();
  484. spitfire_enable_estate_errors();
  485. if (test_thread_flag(TIF_32BIT)) {
  486. regs->tpc &= 0xffffffff;
  487. regs->tnpc &= 0xffffffff;
  488. }
  489. force_sig_fault(SIGBUS, BUS_OBJERR, (void *)0);
  490. }
  491. void spitfire_access_error(struct pt_regs *regs, unsigned long status_encoded, unsigned long afar)
  492. {
  493. unsigned long afsr, tt, udbh, udbl;
  494. int tl1;
  495. afsr = (status_encoded & SFSTAT_AFSR_MASK) >> SFSTAT_AFSR_SHIFT;
  496. tt = (status_encoded & SFSTAT_TRAP_TYPE) >> SFSTAT_TRAP_TYPE_SHIFT;
  497. tl1 = (status_encoded & SFSTAT_TL_GT_ONE) ? 1 : 0;
  498. udbl = (status_encoded & SFSTAT_UDBL_MASK) >> SFSTAT_UDBL_SHIFT;
  499. udbh = (status_encoded & SFSTAT_UDBH_MASK) >> SFSTAT_UDBH_SHIFT;
  500. #ifdef CONFIG_PCI
  501. if (tt == TRAP_TYPE_DAE &&
  502. pci_poke_in_progress && pci_poke_cpu == smp_processor_id()) {
  503. spitfire_clean_and_reenable_l1_caches();
  504. spitfire_enable_estate_errors();
  505. pci_poke_faulted = 1;
  506. regs->tnpc = regs->tpc + 4;
  507. return;
  508. }
  509. #endif
  510. if (afsr & SFAFSR_UE)
  511. spitfire_ue_log(afsr, afar, udbh, udbl, tt, tl1, regs);
  512. if (tt == TRAP_TYPE_CEE) {
  513. /* Handle the case where we took a CEE trap, but ACK'd
  514. * only the UE state in the UDB error registers.
  515. */
  516. if (afsr & SFAFSR_UE) {
  517. if (udbh & UDBE_CE) {
  518. __asm__ __volatile__(
  519. "stxa %0, [%1] %2\n\t"
  520. "membar #Sync"
  521. : /* no outputs */
  522. : "r" (udbh & UDBE_CE),
  523. "r" (0x0), "i" (ASI_UDB_ERROR_W));
  524. }
  525. if (udbl & UDBE_CE) {
  526. __asm__ __volatile__(
  527. "stxa %0, [%1] %2\n\t"
  528. "membar #Sync"
  529. : /* no outputs */
  530. : "r" (udbl & UDBE_CE),
  531. "r" (0x18), "i" (ASI_UDB_ERROR_W));
  532. }
  533. }
  534. spitfire_cee_log(afsr, afar, udbh, udbl, tl1, regs);
  535. }
  536. }
  537. int cheetah_pcache_forced_on;
  538. void cheetah_enable_pcache(void)
  539. {
  540. unsigned long dcr;
  541. printk("CHEETAH: Enabling P-Cache on cpu %d.\n",
  542. smp_processor_id());
  543. __asm__ __volatile__("ldxa [%%g0] %1, %0"
  544. : "=r" (dcr)
  545. : "i" (ASI_DCU_CONTROL_REG));
  546. dcr |= (DCU_PE | DCU_HPE | DCU_SPE | DCU_SL);
  547. __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
  548. "membar #Sync"
  549. : /* no outputs */
  550. : "r" (dcr), "i" (ASI_DCU_CONTROL_REG));
  551. }
  552. /* Cheetah error trap handling. */
  553. static unsigned long ecache_flush_physbase;
  554. static unsigned long ecache_flush_linesize;
  555. static unsigned long ecache_flush_size;
  556. /* This table is ordered in priority of errors and matches the
  557. * AFAR overwrite policy as well.
  558. */
  559. struct afsr_error_table {
  560. unsigned long mask;
  561. const char *name;
  562. };
  563. static const char CHAFSR_PERR_msg[] =
  564. "System interface protocol error";
  565. static const char CHAFSR_IERR_msg[] =
  566. "Internal processor error";
  567. static const char CHAFSR_ISAP_msg[] =
  568. "System request parity error on incoming address";
  569. static const char CHAFSR_UCU_msg[] =
  570. "Uncorrectable E-cache ECC error for ifetch/data";
  571. static const char CHAFSR_UCC_msg[] =
  572. "SW Correctable E-cache ECC error for ifetch/data";
  573. static const char CHAFSR_UE_msg[] =
  574. "Uncorrectable system bus data ECC error for read";
  575. static const char CHAFSR_EDU_msg[] =
  576. "Uncorrectable E-cache ECC error for stmerge/blkld";
  577. static const char CHAFSR_EMU_msg[] =
  578. "Uncorrectable system bus MTAG error";
  579. static const char CHAFSR_WDU_msg[] =
  580. "Uncorrectable E-cache ECC error for writeback";
  581. static const char CHAFSR_CPU_msg[] =
  582. "Uncorrectable ECC error for copyout";
  583. static const char CHAFSR_CE_msg[] =
  584. "HW corrected system bus data ECC error for read";
  585. static const char CHAFSR_EDC_msg[] =
  586. "HW corrected E-cache ECC error for stmerge/blkld";
  587. static const char CHAFSR_EMC_msg[] =
  588. "HW corrected system bus MTAG ECC error";
  589. static const char CHAFSR_WDC_msg[] =
  590. "HW corrected E-cache ECC error for writeback";
  591. static const char CHAFSR_CPC_msg[] =
  592. "HW corrected ECC error for copyout";
  593. static const char CHAFSR_TO_msg[] =
  594. "Unmapped error from system bus";
  595. static const char CHAFSR_BERR_msg[] =
  596. "Bus error response from system bus";
  597. static const char CHAFSR_IVC_msg[] =
  598. "HW corrected system bus data ECC error for ivec read";
  599. static const char CHAFSR_IVU_msg[] =
  600. "Uncorrectable system bus data ECC error for ivec read";
  601. static struct afsr_error_table __cheetah_error_table[] = {
  602. { CHAFSR_PERR, CHAFSR_PERR_msg },
  603. { CHAFSR_IERR, CHAFSR_IERR_msg },
  604. { CHAFSR_ISAP, CHAFSR_ISAP_msg },
  605. { CHAFSR_UCU, CHAFSR_UCU_msg },
  606. { CHAFSR_UCC, CHAFSR_UCC_msg },
  607. { CHAFSR_UE, CHAFSR_UE_msg },
  608. { CHAFSR_EDU, CHAFSR_EDU_msg },
  609. { CHAFSR_EMU, CHAFSR_EMU_msg },
  610. { CHAFSR_WDU, CHAFSR_WDU_msg },
  611. { CHAFSR_CPU, CHAFSR_CPU_msg },
  612. { CHAFSR_CE, CHAFSR_CE_msg },
  613. { CHAFSR_EDC, CHAFSR_EDC_msg },
  614. { CHAFSR_EMC, CHAFSR_EMC_msg },
  615. { CHAFSR_WDC, CHAFSR_WDC_msg },
  616. { CHAFSR_CPC, CHAFSR_CPC_msg },
  617. { CHAFSR_TO, CHAFSR_TO_msg },
  618. { CHAFSR_BERR, CHAFSR_BERR_msg },
  619. /* These two do not update the AFAR. */
  620. { CHAFSR_IVC, CHAFSR_IVC_msg },
  621. { CHAFSR_IVU, CHAFSR_IVU_msg },
  622. { 0, NULL },
  623. };
  624. static const char CHPAFSR_DTO_msg[] =
  625. "System bus unmapped error for prefetch/storequeue-read";
  626. static const char CHPAFSR_DBERR_msg[] =
  627. "System bus error for prefetch/storequeue-read";
  628. static const char CHPAFSR_THCE_msg[] =
  629. "Hardware corrected E-cache Tag ECC error";
  630. static const char CHPAFSR_TSCE_msg[] =
  631. "SW handled correctable E-cache Tag ECC error";
  632. static const char CHPAFSR_TUE_msg[] =
  633. "Uncorrectable E-cache Tag ECC error";
  634. static const char CHPAFSR_DUE_msg[] =
  635. "System bus uncorrectable data ECC error due to prefetch/store-fill";
  636. static struct afsr_error_table __cheetah_plus_error_table[] = {
  637. { CHAFSR_PERR, CHAFSR_PERR_msg },
  638. { CHAFSR_IERR, CHAFSR_IERR_msg },
  639. { CHAFSR_ISAP, CHAFSR_ISAP_msg },
  640. { CHAFSR_UCU, CHAFSR_UCU_msg },
  641. { CHAFSR_UCC, CHAFSR_UCC_msg },
  642. { CHAFSR_UE, CHAFSR_UE_msg },
  643. { CHAFSR_EDU, CHAFSR_EDU_msg },
  644. { CHAFSR_EMU, CHAFSR_EMU_msg },
  645. { CHAFSR_WDU, CHAFSR_WDU_msg },
  646. { CHAFSR_CPU, CHAFSR_CPU_msg },
  647. { CHAFSR_CE, CHAFSR_CE_msg },
  648. { CHAFSR_EDC, CHAFSR_EDC_msg },
  649. { CHAFSR_EMC, CHAFSR_EMC_msg },
  650. { CHAFSR_WDC, CHAFSR_WDC_msg },
  651. { CHAFSR_CPC, CHAFSR_CPC_msg },
  652. { CHAFSR_TO, CHAFSR_TO_msg },
  653. { CHAFSR_BERR, CHAFSR_BERR_msg },
  654. { CHPAFSR_DTO, CHPAFSR_DTO_msg },
  655. { CHPAFSR_DBERR, CHPAFSR_DBERR_msg },
  656. { CHPAFSR_THCE, CHPAFSR_THCE_msg },
  657. { CHPAFSR_TSCE, CHPAFSR_TSCE_msg },
  658. { CHPAFSR_TUE, CHPAFSR_TUE_msg },
  659. { CHPAFSR_DUE, CHPAFSR_DUE_msg },
  660. /* These two do not update the AFAR. */
  661. { CHAFSR_IVC, CHAFSR_IVC_msg },
  662. { CHAFSR_IVU, CHAFSR_IVU_msg },
  663. { 0, NULL },
  664. };
  665. static const char JPAFSR_JETO_msg[] =
  666. "System interface protocol error, hw timeout caused";
  667. static const char JPAFSR_SCE_msg[] =
  668. "Parity error on system snoop results";
  669. static const char JPAFSR_JEIC_msg[] =
  670. "System interface protocol error, illegal command detected";
  671. static const char JPAFSR_JEIT_msg[] =
  672. "System interface protocol error, illegal ADTYPE detected";
  673. static const char JPAFSR_OM_msg[] =
  674. "Out of range memory error has occurred";
  675. static const char JPAFSR_ETP_msg[] =
  676. "Parity error on L2 cache tag SRAM";
  677. static const char JPAFSR_UMS_msg[] =
  678. "Error due to unsupported store";
  679. static const char JPAFSR_RUE_msg[] =
  680. "Uncorrectable ECC error from remote cache/memory";
  681. static const char JPAFSR_RCE_msg[] =
  682. "Correctable ECC error from remote cache/memory";
  683. static const char JPAFSR_BP_msg[] =
  684. "JBUS parity error on returned read data";
  685. static const char JPAFSR_WBP_msg[] =
  686. "JBUS parity error on data for writeback or block store";
  687. static const char JPAFSR_FRC_msg[] =
  688. "Foreign read to DRAM incurring correctable ECC error";
  689. static const char JPAFSR_FRU_msg[] =
  690. "Foreign read to DRAM incurring uncorrectable ECC error";
  691. static struct afsr_error_table __jalapeno_error_table[] = {
  692. { JPAFSR_JETO, JPAFSR_JETO_msg },
  693. { JPAFSR_SCE, JPAFSR_SCE_msg },
  694. { JPAFSR_JEIC, JPAFSR_JEIC_msg },
  695. { JPAFSR_JEIT, JPAFSR_JEIT_msg },
  696. { CHAFSR_PERR, CHAFSR_PERR_msg },
  697. { CHAFSR_IERR, CHAFSR_IERR_msg },
  698. { CHAFSR_ISAP, CHAFSR_ISAP_msg },
  699. { CHAFSR_UCU, CHAFSR_UCU_msg },
  700. { CHAFSR_UCC, CHAFSR_UCC_msg },
  701. { CHAFSR_UE, CHAFSR_UE_msg },
  702. { CHAFSR_EDU, CHAFSR_EDU_msg },
  703. { JPAFSR_OM, JPAFSR_OM_msg },
  704. { CHAFSR_WDU, CHAFSR_WDU_msg },
  705. { CHAFSR_CPU, CHAFSR_CPU_msg },
  706. { CHAFSR_CE, CHAFSR_CE_msg },
  707. { CHAFSR_EDC, CHAFSR_EDC_msg },
  708. { JPAFSR_ETP, JPAFSR_ETP_msg },
  709. { CHAFSR_WDC, CHAFSR_WDC_msg },
  710. { CHAFSR_CPC, CHAFSR_CPC_msg },
  711. { CHAFSR_TO, CHAFSR_TO_msg },
  712. { CHAFSR_BERR, CHAFSR_BERR_msg },
  713. { JPAFSR_UMS, JPAFSR_UMS_msg },
  714. { JPAFSR_RUE, JPAFSR_RUE_msg },
  715. { JPAFSR_RCE, JPAFSR_RCE_msg },
  716. { JPAFSR_BP, JPAFSR_BP_msg },
  717. { JPAFSR_WBP, JPAFSR_WBP_msg },
  718. { JPAFSR_FRC, JPAFSR_FRC_msg },
  719. { JPAFSR_FRU, JPAFSR_FRU_msg },
  720. /* These two do not update the AFAR. */
  721. { CHAFSR_IVU, CHAFSR_IVU_msg },
  722. { 0, NULL },
  723. };
  724. static struct afsr_error_table *cheetah_error_table;
  725. static unsigned long cheetah_afsr_errors;
  726. struct cheetah_err_info *cheetah_error_log;
  727. static inline struct cheetah_err_info *cheetah_get_error_log(unsigned long afsr)
  728. {
  729. struct cheetah_err_info *p;
  730. int cpu = smp_processor_id();
  731. if (!cheetah_error_log)
  732. return NULL;
  733. p = cheetah_error_log + (cpu * 2);
  734. if ((afsr & CHAFSR_TL1) != 0UL)
  735. p++;
  736. return p;
  737. }
  738. extern unsigned int tl0_icpe[], tl1_icpe[];
  739. extern unsigned int tl0_dcpe[], tl1_dcpe[];
  740. extern unsigned int tl0_fecc[], tl1_fecc[];
  741. extern unsigned int tl0_cee[], tl1_cee[];
  742. extern unsigned int tl0_iae[], tl1_iae[];
  743. extern unsigned int tl0_dae[], tl1_dae[];
  744. extern unsigned int cheetah_plus_icpe_trap_vector[], cheetah_plus_icpe_trap_vector_tl1[];
  745. extern unsigned int cheetah_plus_dcpe_trap_vector[], cheetah_plus_dcpe_trap_vector_tl1[];
  746. extern unsigned int cheetah_fecc_trap_vector[], cheetah_fecc_trap_vector_tl1[];
  747. extern unsigned int cheetah_cee_trap_vector[], cheetah_cee_trap_vector_tl1[];
  748. extern unsigned int cheetah_deferred_trap_vector[], cheetah_deferred_trap_vector_tl1[];
  749. void __init cheetah_ecache_flush_init(void)
  750. {
  751. unsigned long largest_size, smallest_linesize, order, ver;
  752. int i, sz;
  753. /* Scan all cpu device tree nodes, note two values:
  754. * 1) largest E-cache size
  755. * 2) smallest E-cache line size
  756. */
  757. largest_size = 0UL;
  758. smallest_linesize = ~0UL;
  759. for (i = 0; i < NR_CPUS; i++) {
  760. unsigned long val;
  761. val = cpu_data(i).ecache_size;
  762. if (!val)
  763. continue;
  764. if (val > largest_size)
  765. largest_size = val;
  766. val = cpu_data(i).ecache_line_size;
  767. if (val < smallest_linesize)
  768. smallest_linesize = val;
  769. }
  770. if (largest_size == 0UL || smallest_linesize == ~0UL) {
  771. prom_printf("cheetah_ecache_flush_init: Cannot probe cpu E-cache "
  772. "parameters.\n");
  773. prom_halt();
  774. }
  775. ecache_flush_size = (2 * largest_size);
  776. ecache_flush_linesize = smallest_linesize;
  777. ecache_flush_physbase = find_ecache_flush_span(ecache_flush_size);
  778. if (ecache_flush_physbase == ~0UL) {
  779. prom_printf("cheetah_ecache_flush_init: Cannot find %ld byte "
  780. "contiguous physical memory.\n",
  781. ecache_flush_size);
  782. prom_halt();
  783. }
  784. /* Now allocate error trap reporting scoreboard. */
  785. sz = NR_CPUS * (2 * sizeof(struct cheetah_err_info));
  786. for (order = 0; order < MAX_ORDER; order++) {
  787. if ((PAGE_SIZE << order) >= sz)
  788. break;
  789. }
  790. cheetah_error_log = (struct cheetah_err_info *)
  791. __get_free_pages(GFP_KERNEL, order);
  792. if (!cheetah_error_log) {
  793. prom_printf("cheetah_ecache_flush_init: Failed to allocate "
  794. "error logging scoreboard (%d bytes).\n", sz);
  795. prom_halt();
  796. }
  797. memset(cheetah_error_log, 0, PAGE_SIZE << order);
  798. /* Mark all AFSRs as invalid so that the trap handler will
  799. * log new new information there.
  800. */
  801. for (i = 0; i < 2 * NR_CPUS; i++)
  802. cheetah_error_log[i].afsr = CHAFSR_INVALID;
  803. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  804. if ((ver >> 32) == __JALAPENO_ID ||
  805. (ver >> 32) == __SERRANO_ID) {
  806. cheetah_error_table = &__jalapeno_error_table[0];
  807. cheetah_afsr_errors = JPAFSR_ERRORS;
  808. } else if ((ver >> 32) == 0x003e0015) {
  809. cheetah_error_table = &__cheetah_plus_error_table[0];
  810. cheetah_afsr_errors = CHPAFSR_ERRORS;
  811. } else {
  812. cheetah_error_table = &__cheetah_error_table[0];
  813. cheetah_afsr_errors = CHAFSR_ERRORS;
  814. }
  815. /* Now patch trap tables. */
  816. memcpy(tl0_fecc, cheetah_fecc_trap_vector, (8 * 4));
  817. memcpy(tl1_fecc, cheetah_fecc_trap_vector_tl1, (8 * 4));
  818. memcpy(tl0_cee, cheetah_cee_trap_vector, (8 * 4));
  819. memcpy(tl1_cee, cheetah_cee_trap_vector_tl1, (8 * 4));
  820. memcpy(tl0_iae, cheetah_deferred_trap_vector, (8 * 4));
  821. memcpy(tl1_iae, cheetah_deferred_trap_vector_tl1, (8 * 4));
  822. memcpy(tl0_dae, cheetah_deferred_trap_vector, (8 * 4));
  823. memcpy(tl1_dae, cheetah_deferred_trap_vector_tl1, (8 * 4));
  824. if (tlb_type == cheetah_plus) {
  825. memcpy(tl0_dcpe, cheetah_plus_dcpe_trap_vector, (8 * 4));
  826. memcpy(tl1_dcpe, cheetah_plus_dcpe_trap_vector_tl1, (8 * 4));
  827. memcpy(tl0_icpe, cheetah_plus_icpe_trap_vector, (8 * 4));
  828. memcpy(tl1_icpe, cheetah_plus_icpe_trap_vector_tl1, (8 * 4));
  829. }
  830. flushi(PAGE_OFFSET);
  831. }
  832. static void cheetah_flush_ecache(void)
  833. {
  834. unsigned long flush_base = ecache_flush_physbase;
  835. unsigned long flush_linesize = ecache_flush_linesize;
  836. unsigned long flush_size = ecache_flush_size;
  837. __asm__ __volatile__("1: subcc %0, %4, %0\n\t"
  838. " bne,pt %%xcc, 1b\n\t"
  839. " ldxa [%2 + %0] %3, %%g0\n\t"
  840. : "=&r" (flush_size)
  841. : "0" (flush_size), "r" (flush_base),
  842. "i" (ASI_PHYS_USE_EC), "r" (flush_linesize));
  843. }
  844. static void cheetah_flush_ecache_line(unsigned long physaddr)
  845. {
  846. unsigned long alias;
  847. physaddr &= ~(8UL - 1UL);
  848. physaddr = (ecache_flush_physbase +
  849. (physaddr & ((ecache_flush_size>>1UL) - 1UL)));
  850. alias = physaddr + (ecache_flush_size >> 1UL);
  851. __asm__ __volatile__("ldxa [%0] %2, %%g0\n\t"
  852. "ldxa [%1] %2, %%g0\n\t"
  853. "membar #Sync"
  854. : /* no outputs */
  855. : "r" (physaddr), "r" (alias),
  856. "i" (ASI_PHYS_USE_EC));
  857. }
  858. /* Unfortunately, the diagnostic access to the I-cache tags we need to
  859. * use to clear the thing interferes with I-cache coherency transactions.
  860. *
  861. * So we must only flush the I-cache when it is disabled.
  862. */
  863. static void __cheetah_flush_icache(void)
  864. {
  865. unsigned int icache_size, icache_line_size;
  866. unsigned long addr;
  867. icache_size = local_cpu_data().icache_size;
  868. icache_line_size = local_cpu_data().icache_line_size;
  869. /* Clear the valid bits in all the tags. */
  870. for (addr = 0; addr < icache_size; addr += icache_line_size) {
  871. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  872. "membar #Sync"
  873. : /* no outputs */
  874. : "r" (addr | (2 << 3)),
  875. "i" (ASI_IC_TAG));
  876. }
  877. }
  878. static void cheetah_flush_icache(void)
  879. {
  880. unsigned long dcu_save;
  881. /* Save current DCU, disable I-cache. */
  882. __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
  883. "or %0, %2, %%g1\n\t"
  884. "stxa %%g1, [%%g0] %1\n\t"
  885. "membar #Sync"
  886. : "=r" (dcu_save)
  887. : "i" (ASI_DCU_CONTROL_REG), "i" (DCU_IC)
  888. : "g1");
  889. __cheetah_flush_icache();
  890. /* Restore DCU register */
  891. __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
  892. "membar #Sync"
  893. : /* no outputs */
  894. : "r" (dcu_save), "i" (ASI_DCU_CONTROL_REG));
  895. }
  896. static void cheetah_flush_dcache(void)
  897. {
  898. unsigned int dcache_size, dcache_line_size;
  899. unsigned long addr;
  900. dcache_size = local_cpu_data().dcache_size;
  901. dcache_line_size = local_cpu_data().dcache_line_size;
  902. for (addr = 0; addr < dcache_size; addr += dcache_line_size) {
  903. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  904. "membar #Sync"
  905. : /* no outputs */
  906. : "r" (addr), "i" (ASI_DCACHE_TAG));
  907. }
  908. }
  909. /* In order to make the even parity correct we must do two things.
  910. * First, we clear DC_data_parity and set DC_utag to an appropriate value.
  911. * Next, we clear out all 32-bytes of data for that line. Data of
  912. * all-zero + tag parity value of zero == correct parity.
  913. */
  914. static void cheetah_plus_zap_dcache_parity(void)
  915. {
  916. unsigned int dcache_size, dcache_line_size;
  917. unsigned long addr;
  918. dcache_size = local_cpu_data().dcache_size;
  919. dcache_line_size = local_cpu_data().dcache_line_size;
  920. for (addr = 0; addr < dcache_size; addr += dcache_line_size) {
  921. unsigned long tag = (addr >> 14);
  922. unsigned long line;
  923. __asm__ __volatile__("membar #Sync\n\t"
  924. "stxa %0, [%1] %2\n\t"
  925. "membar #Sync"
  926. : /* no outputs */
  927. : "r" (tag), "r" (addr),
  928. "i" (ASI_DCACHE_UTAG));
  929. for (line = addr; line < addr + dcache_line_size; line += 8)
  930. __asm__ __volatile__("membar #Sync\n\t"
  931. "stxa %%g0, [%0] %1\n\t"
  932. "membar #Sync"
  933. : /* no outputs */
  934. : "r" (line),
  935. "i" (ASI_DCACHE_DATA));
  936. }
  937. }
  938. /* Conversion tables used to frob Cheetah AFSR syndrome values into
  939. * something palatable to the memory controller driver get_unumber
  940. * routine.
  941. */
  942. #define MT0 137
  943. #define MT1 138
  944. #define MT2 139
  945. #define NONE 254
  946. #define MTC0 140
  947. #define MTC1 141
  948. #define MTC2 142
  949. #define MTC3 143
  950. #define C0 128
  951. #define C1 129
  952. #define C2 130
  953. #define C3 131
  954. #define C4 132
  955. #define C5 133
  956. #define C6 134
  957. #define C7 135
  958. #define C8 136
  959. #define M2 144
  960. #define M3 145
  961. #define M4 146
  962. #define M 147
  963. static unsigned char cheetah_ecc_syntab[] = {
  964. /*00*/NONE, C0, C1, M2, C2, M2, M3, 47, C3, M2, M2, 53, M2, 41, 29, M,
  965. /*01*/C4, M, M, 50, M2, 38, 25, M2, M2, 33, 24, M2, 11, M, M2, 16,
  966. /*02*/C5, M, M, 46, M2, 37, 19, M2, M, 31, 32, M, 7, M2, M2, 10,
  967. /*03*/M2, 40, 13, M2, 59, M, M2, 66, M, M2, M2, 0, M2, 67, 71, M,
  968. /*04*/C6, M, M, 43, M, 36, 18, M, M2, 49, 15, M, 63, M2, M2, 6,
  969. /*05*/M2, 44, 28, M2, M, M2, M2, 52, 68, M2, M2, 62, M2, M3, M3, M4,
  970. /*06*/M2, 26, 106, M2, 64, M, M2, 2, 120, M, M2, M3, M, M3, M3, M4,
  971. /*07*/116, M2, M2, M3, M2, M3, M, M4, M2, 58, 54, M2, M, M4, M4, M3,
  972. /*08*/C7, M2, M, 42, M, 35, 17, M2, M, 45, 14, M2, 21, M2, M2, 5,
  973. /*09*/M, 27, M, M, 99, M, M, 3, 114, M2, M2, 20, M2, M3, M3, M,
  974. /*0a*/M2, 23, 113, M2, 112, M2, M, 51, 95, M, M2, M3, M2, M3, M3, M2,
  975. /*0b*/103, M, M2, M3, M2, M3, M3, M4, M2, 48, M, M, 73, M2, M, M3,
  976. /*0c*/M2, 22, 110, M2, 109, M2, M, 9, 108, M2, M, M3, M2, M3, M3, M,
  977. /*0d*/102, M2, M, M, M2, M3, M3, M, M2, M3, M3, M2, M, M4, M, M3,
  978. /*0e*/98, M, M2, M3, M2, M, M3, M4, M2, M3, M3, M4, M3, M, M, M,
  979. /*0f*/M2, M3, M3, M, M3, M, M, M, 56, M4, M, M3, M4, M, M, M,
  980. /*10*/C8, M, M2, 39, M, 34, 105, M2, M, 30, 104, M, 101, M, M, 4,
  981. /*11*/M, M, 100, M, 83, M, M2, 12, 87, M, M, 57, M2, M, M3, M,
  982. /*12*/M2, 97, 82, M2, 78, M2, M2, 1, 96, M, M, M, M, M, M3, M2,
  983. /*13*/94, M, M2, M3, M2, M, M3, M, M2, M, 79, M, 69, M, M4, M,
  984. /*14*/M2, 93, 92, M, 91, M, M2, 8, 90, M2, M2, M, M, M, M, M4,
  985. /*15*/89, M, M, M3, M2, M3, M3, M, M, M, M3, M2, M3, M2, M, M3,
  986. /*16*/86, M, M2, M3, M2, M, M3, M, M2, M, M3, M, M3, M, M, M3,
  987. /*17*/M, M, M3, M2, M3, M2, M4, M, 60, M, M2, M3, M4, M, M, M2,
  988. /*18*/M2, 88, 85, M2, 84, M, M2, 55, 81, M2, M2, M3, M2, M3, M3, M4,
  989. /*19*/77, M, M, M, M2, M3, M, M, M2, M3, M3, M4, M3, M2, M, M,
  990. /*1a*/74, M, M2, M3, M, M, M3, M, M, M, M3, M, M3, M, M4, M3,
  991. /*1b*/M2, 70, 107, M4, 65, M2, M2, M, 127, M, M, M, M2, M3, M3, M,
  992. /*1c*/80, M2, M2, 72, M, 119, 118, M, M2, 126, 76, M, 125, M, M4, M3,
  993. /*1d*/M2, 115, 124, M, 75, M, M, M3, 61, M, M4, M, M4, M, M, M,
  994. /*1e*/M, 123, 122, M4, 121, M4, M, M3, 117, M2, M2, M3, M4, M3, M, M,
  995. /*1f*/111, M, M, M, M4, M3, M3, M, M, M, M3, M, M3, M2, M, M
  996. };
  997. static unsigned char cheetah_mtag_syntab[] = {
  998. NONE, MTC0,
  999. MTC1, NONE,
  1000. MTC2, NONE,
  1001. NONE, MT0,
  1002. MTC3, NONE,
  1003. NONE, MT1,
  1004. NONE, MT2,
  1005. NONE, NONE
  1006. };
  1007. /* Return the highest priority error conditon mentioned. */
  1008. static inline unsigned long cheetah_get_hipri(unsigned long afsr)
  1009. {
  1010. unsigned long tmp = 0;
  1011. int i;
  1012. for (i = 0; cheetah_error_table[i].mask; i++) {
  1013. if ((tmp = (afsr & cheetah_error_table[i].mask)) != 0UL)
  1014. return tmp;
  1015. }
  1016. return tmp;
  1017. }
  1018. static const char *cheetah_get_string(unsigned long bit)
  1019. {
  1020. int i;
  1021. for (i = 0; cheetah_error_table[i].mask; i++) {
  1022. if ((bit & cheetah_error_table[i].mask) != 0UL)
  1023. return cheetah_error_table[i].name;
  1024. }
  1025. return "???";
  1026. }
  1027. static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *info,
  1028. unsigned long afsr, unsigned long afar, int recoverable)
  1029. {
  1030. unsigned long hipri;
  1031. char unum[256];
  1032. printk("%s" "ERROR(%d): Cheetah error trap taken afsr[%016lx] afar[%016lx] TL1(%d)\n",
  1033. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1034. afsr, afar,
  1035. (afsr & CHAFSR_TL1) ? 1 : 0);
  1036. printk("%s" "ERROR(%d): TPC[%lx] TNPC[%lx] O7[%lx] TSTATE[%lx]\n",
  1037. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1038. regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
  1039. printk("%s" "ERROR(%d): ",
  1040. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
  1041. printk("TPC<%pS>\n", (void *) regs->tpc);
  1042. printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
  1043. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1044. (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
  1045. (afsr & CHAFSR_E_SYNDROME) >> CHAFSR_E_SYNDROME_SHIFT,
  1046. (afsr & CHAFSR_ME) ? ", Multiple Errors" : "",
  1047. (afsr & CHAFSR_PRIV) ? ", Privileged" : "");
  1048. hipri = cheetah_get_hipri(afsr);
  1049. printk("%s" "ERROR(%d): Highest priority error (%016lx) \"%s\"\n",
  1050. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1051. hipri, cheetah_get_string(hipri));
  1052. /* Try to get unumber if relevant. */
  1053. #define ESYND_ERRORS (CHAFSR_IVC | CHAFSR_IVU | \
  1054. CHAFSR_CPC | CHAFSR_CPU | \
  1055. CHAFSR_UE | CHAFSR_CE | \
  1056. CHAFSR_EDC | CHAFSR_EDU | \
  1057. CHAFSR_UCC | CHAFSR_UCU | \
  1058. CHAFSR_WDU | CHAFSR_WDC)
  1059. #define MSYND_ERRORS (CHAFSR_EMC | CHAFSR_EMU)
  1060. if (afsr & ESYND_ERRORS) {
  1061. int syndrome;
  1062. int ret;
  1063. syndrome = (afsr & CHAFSR_E_SYNDROME) >> CHAFSR_E_SYNDROME_SHIFT;
  1064. syndrome = cheetah_ecc_syntab[syndrome];
  1065. ret = sprintf_dimm(syndrome, afar, unum, sizeof(unum));
  1066. if (ret != -1)
  1067. printk("%s" "ERROR(%d): AFAR E-syndrome [%s]\n",
  1068. (recoverable ? KERN_WARNING : KERN_CRIT),
  1069. smp_processor_id(), unum);
  1070. } else if (afsr & MSYND_ERRORS) {
  1071. int syndrome;
  1072. int ret;
  1073. syndrome = (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT;
  1074. syndrome = cheetah_mtag_syntab[syndrome];
  1075. ret = sprintf_dimm(syndrome, afar, unum, sizeof(unum));
  1076. if (ret != -1)
  1077. printk("%s" "ERROR(%d): AFAR M-syndrome [%s]\n",
  1078. (recoverable ? KERN_WARNING : KERN_CRIT),
  1079. smp_processor_id(), unum);
  1080. }
  1081. /* Now dump the cache snapshots. */
  1082. printk("%s" "ERROR(%d): D-cache idx[%x] tag[%016llx] utag[%016llx] stag[%016llx]\n",
  1083. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1084. (int) info->dcache_index,
  1085. info->dcache_tag,
  1086. info->dcache_utag,
  1087. info->dcache_stag);
  1088. printk("%s" "ERROR(%d): D-cache data0[%016llx] data1[%016llx] data2[%016llx] data3[%016llx]\n",
  1089. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1090. info->dcache_data[0],
  1091. info->dcache_data[1],
  1092. info->dcache_data[2],
  1093. info->dcache_data[3]);
  1094. printk("%s" "ERROR(%d): I-cache idx[%x] tag[%016llx] utag[%016llx] stag[%016llx] "
  1095. "u[%016llx] l[%016llx]\n",
  1096. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1097. (int) info->icache_index,
  1098. info->icache_tag,
  1099. info->icache_utag,
  1100. info->icache_stag,
  1101. info->icache_upper,
  1102. info->icache_lower);
  1103. printk("%s" "ERROR(%d): I-cache INSN0[%016llx] INSN1[%016llx] INSN2[%016llx] INSN3[%016llx]\n",
  1104. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1105. info->icache_data[0],
  1106. info->icache_data[1],
  1107. info->icache_data[2],
  1108. info->icache_data[3]);
  1109. printk("%s" "ERROR(%d): I-cache INSN4[%016llx] INSN5[%016llx] INSN6[%016llx] INSN7[%016llx]\n",
  1110. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1111. info->icache_data[4],
  1112. info->icache_data[5],
  1113. info->icache_data[6],
  1114. info->icache_data[7]);
  1115. printk("%s" "ERROR(%d): E-cache idx[%x] tag[%016llx]\n",
  1116. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1117. (int) info->ecache_index, info->ecache_tag);
  1118. printk("%s" "ERROR(%d): E-cache data0[%016llx] data1[%016llx] data2[%016llx] data3[%016llx]\n",
  1119. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1120. info->ecache_data[0],
  1121. info->ecache_data[1],
  1122. info->ecache_data[2],
  1123. info->ecache_data[3]);
  1124. afsr = (afsr & ~hipri) & cheetah_afsr_errors;
  1125. while (afsr != 0UL) {
  1126. unsigned long bit = cheetah_get_hipri(afsr);
  1127. printk("%s" "ERROR: Multiple-error (%016lx) \"%s\"\n",
  1128. (recoverable ? KERN_WARNING : KERN_CRIT),
  1129. bit, cheetah_get_string(bit));
  1130. afsr &= ~bit;
  1131. }
  1132. if (!recoverable)
  1133. printk(KERN_CRIT "ERROR: This condition is not recoverable.\n");
  1134. }
  1135. static int cheetah_recheck_errors(struct cheetah_err_info *logp)
  1136. {
  1137. unsigned long afsr, afar;
  1138. int ret = 0;
  1139. __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
  1140. : "=r" (afsr)
  1141. : "i" (ASI_AFSR));
  1142. if ((afsr & cheetah_afsr_errors) != 0) {
  1143. if (logp != NULL) {
  1144. __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
  1145. : "=r" (afar)
  1146. : "i" (ASI_AFAR));
  1147. logp->afsr = afsr;
  1148. logp->afar = afar;
  1149. }
  1150. ret = 1;
  1151. }
  1152. __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
  1153. "membar #Sync\n\t"
  1154. : : "r" (afsr), "i" (ASI_AFSR));
  1155. return ret;
  1156. }
  1157. void cheetah_fecc_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
  1158. {
  1159. struct cheetah_err_info local_snapshot, *p;
  1160. int recoverable;
  1161. /* Flush E-cache */
  1162. cheetah_flush_ecache();
  1163. p = cheetah_get_error_log(afsr);
  1164. if (!p) {
  1165. prom_printf("ERROR: Early Fast-ECC error afsr[%016lx] afar[%016lx]\n",
  1166. afsr, afar);
  1167. prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
  1168. smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
  1169. prom_halt();
  1170. }
  1171. /* Grab snapshot of logged error. */
  1172. memcpy(&local_snapshot, p, sizeof(local_snapshot));
  1173. /* If the current trap snapshot does not match what the
  1174. * trap handler passed along into our args, big trouble.
  1175. * In such a case, mark the local copy as invalid.
  1176. *
  1177. * Else, it matches and we mark the afsr in the non-local
  1178. * copy as invalid so we may log new error traps there.
  1179. */
  1180. if (p->afsr != afsr || p->afar != afar)
  1181. local_snapshot.afsr = CHAFSR_INVALID;
  1182. else
  1183. p->afsr = CHAFSR_INVALID;
  1184. cheetah_flush_icache();
  1185. cheetah_flush_dcache();
  1186. /* Re-enable I-cache/D-cache */
  1187. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1188. "or %%g1, %1, %%g1\n\t"
  1189. "stxa %%g1, [%%g0] %0\n\t"
  1190. "membar #Sync"
  1191. : /* no outputs */
  1192. : "i" (ASI_DCU_CONTROL_REG),
  1193. "i" (DCU_DC | DCU_IC)
  1194. : "g1");
  1195. /* Re-enable error reporting */
  1196. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1197. "or %%g1, %1, %%g1\n\t"
  1198. "stxa %%g1, [%%g0] %0\n\t"
  1199. "membar #Sync"
  1200. : /* no outputs */
  1201. : "i" (ASI_ESTATE_ERROR_EN),
  1202. "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
  1203. : "g1");
  1204. /* Decide if we can continue after handling this trap and
  1205. * logging the error.
  1206. */
  1207. recoverable = 1;
  1208. if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
  1209. recoverable = 0;
  1210. /* Re-check AFSR/AFAR. What we are looking for here is whether a new
  1211. * error was logged while we had error reporting traps disabled.
  1212. */
  1213. if (cheetah_recheck_errors(&local_snapshot)) {
  1214. unsigned long new_afsr = local_snapshot.afsr;
  1215. /* If we got a new asynchronous error, die... */
  1216. if (new_afsr & (CHAFSR_EMU | CHAFSR_EDU |
  1217. CHAFSR_WDU | CHAFSR_CPU |
  1218. CHAFSR_IVU | CHAFSR_UE |
  1219. CHAFSR_BERR | CHAFSR_TO))
  1220. recoverable = 0;
  1221. }
  1222. /* Log errors. */
  1223. cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
  1224. if (!recoverable)
  1225. panic("Irrecoverable Fast-ECC error trap.\n");
  1226. /* Flush E-cache to kick the error trap handlers out. */
  1227. cheetah_flush_ecache();
  1228. }
  1229. /* Try to fix a correctable error by pushing the line out from
  1230. * the E-cache. Recheck error reporting registers to see if the
  1231. * problem is intermittent.
  1232. */
  1233. static int cheetah_fix_ce(unsigned long physaddr)
  1234. {
  1235. unsigned long orig_estate;
  1236. unsigned long alias1, alias2;
  1237. int ret;
  1238. /* Make sure correctable error traps are disabled. */
  1239. __asm__ __volatile__("ldxa [%%g0] %2, %0\n\t"
  1240. "andn %0, %1, %%g1\n\t"
  1241. "stxa %%g1, [%%g0] %2\n\t"
  1242. "membar #Sync"
  1243. : "=&r" (orig_estate)
  1244. : "i" (ESTATE_ERROR_CEEN),
  1245. "i" (ASI_ESTATE_ERROR_EN)
  1246. : "g1");
  1247. /* We calculate alias addresses that will force the
  1248. * cache line in question out of the E-cache. Then
  1249. * we bring it back in with an atomic instruction so
  1250. * that we get it in some modified/exclusive state,
  1251. * then we displace it again to try and get proper ECC
  1252. * pushed back into the system.
  1253. */
  1254. physaddr &= ~(8UL - 1UL);
  1255. alias1 = (ecache_flush_physbase +
  1256. (physaddr & ((ecache_flush_size >> 1) - 1)));
  1257. alias2 = alias1 + (ecache_flush_size >> 1);
  1258. __asm__ __volatile__("ldxa [%0] %3, %%g0\n\t"
  1259. "ldxa [%1] %3, %%g0\n\t"
  1260. "casxa [%2] %3, %%g0, %%g0\n\t"
  1261. "ldxa [%0] %3, %%g0\n\t"
  1262. "ldxa [%1] %3, %%g0\n\t"
  1263. "membar #Sync"
  1264. : /* no outputs */
  1265. : "r" (alias1), "r" (alias2),
  1266. "r" (physaddr), "i" (ASI_PHYS_USE_EC));
  1267. /* Did that trigger another error? */
  1268. if (cheetah_recheck_errors(NULL)) {
  1269. /* Try one more time. */
  1270. __asm__ __volatile__("ldxa [%0] %1, %%g0\n\t"
  1271. "membar #Sync"
  1272. : : "r" (physaddr), "i" (ASI_PHYS_USE_EC));
  1273. if (cheetah_recheck_errors(NULL))
  1274. ret = 2;
  1275. else
  1276. ret = 1;
  1277. } else {
  1278. /* No new error, intermittent problem. */
  1279. ret = 0;
  1280. }
  1281. /* Restore error enables. */
  1282. __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
  1283. "membar #Sync"
  1284. : : "r" (orig_estate), "i" (ASI_ESTATE_ERROR_EN));
  1285. return ret;
  1286. }
  1287. /* Return non-zero if PADDR is a valid physical memory address. */
  1288. static int cheetah_check_main_memory(unsigned long paddr)
  1289. {
  1290. unsigned long vaddr = PAGE_OFFSET + paddr;
  1291. if (vaddr > (unsigned long) high_memory)
  1292. return 0;
  1293. return kern_addr_valid(vaddr);
  1294. }
  1295. void cheetah_cee_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
  1296. {
  1297. struct cheetah_err_info local_snapshot, *p;
  1298. int recoverable, is_memory;
  1299. p = cheetah_get_error_log(afsr);
  1300. if (!p) {
  1301. prom_printf("ERROR: Early CEE error afsr[%016lx] afar[%016lx]\n",
  1302. afsr, afar);
  1303. prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
  1304. smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
  1305. prom_halt();
  1306. }
  1307. /* Grab snapshot of logged error. */
  1308. memcpy(&local_snapshot, p, sizeof(local_snapshot));
  1309. /* If the current trap snapshot does not match what the
  1310. * trap handler passed along into our args, big trouble.
  1311. * In such a case, mark the local copy as invalid.
  1312. *
  1313. * Else, it matches and we mark the afsr in the non-local
  1314. * copy as invalid so we may log new error traps there.
  1315. */
  1316. if (p->afsr != afsr || p->afar != afar)
  1317. local_snapshot.afsr = CHAFSR_INVALID;
  1318. else
  1319. p->afsr = CHAFSR_INVALID;
  1320. is_memory = cheetah_check_main_memory(afar);
  1321. if (is_memory && (afsr & CHAFSR_CE) != 0UL) {
  1322. /* XXX Might want to log the results of this operation
  1323. * XXX somewhere... -DaveM
  1324. */
  1325. cheetah_fix_ce(afar);
  1326. }
  1327. {
  1328. int flush_all, flush_line;
  1329. flush_all = flush_line = 0;
  1330. if ((afsr & CHAFSR_EDC) != 0UL) {
  1331. if ((afsr & cheetah_afsr_errors) == CHAFSR_EDC)
  1332. flush_line = 1;
  1333. else
  1334. flush_all = 1;
  1335. } else if ((afsr & CHAFSR_CPC) != 0UL) {
  1336. if ((afsr & cheetah_afsr_errors) == CHAFSR_CPC)
  1337. flush_line = 1;
  1338. else
  1339. flush_all = 1;
  1340. }
  1341. /* Trap handler only disabled I-cache, flush it. */
  1342. cheetah_flush_icache();
  1343. /* Re-enable I-cache */
  1344. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1345. "or %%g1, %1, %%g1\n\t"
  1346. "stxa %%g1, [%%g0] %0\n\t"
  1347. "membar #Sync"
  1348. : /* no outputs */
  1349. : "i" (ASI_DCU_CONTROL_REG),
  1350. "i" (DCU_IC)
  1351. : "g1");
  1352. if (flush_all)
  1353. cheetah_flush_ecache();
  1354. else if (flush_line)
  1355. cheetah_flush_ecache_line(afar);
  1356. }
  1357. /* Re-enable error reporting */
  1358. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1359. "or %%g1, %1, %%g1\n\t"
  1360. "stxa %%g1, [%%g0] %0\n\t"
  1361. "membar #Sync"
  1362. : /* no outputs */
  1363. : "i" (ASI_ESTATE_ERROR_EN),
  1364. "i" (ESTATE_ERROR_CEEN)
  1365. : "g1");
  1366. /* Decide if we can continue after handling this trap and
  1367. * logging the error.
  1368. */
  1369. recoverable = 1;
  1370. if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
  1371. recoverable = 0;
  1372. /* Re-check AFSR/AFAR */
  1373. (void) cheetah_recheck_errors(&local_snapshot);
  1374. /* Log errors. */
  1375. cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
  1376. if (!recoverable)
  1377. panic("Irrecoverable Correctable-ECC error trap.\n");
  1378. }
  1379. void cheetah_deferred_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
  1380. {
  1381. struct cheetah_err_info local_snapshot, *p;
  1382. int recoverable, is_memory;
  1383. #ifdef CONFIG_PCI
  1384. /* Check for the special PCI poke sequence. */
  1385. if (pci_poke_in_progress && pci_poke_cpu == smp_processor_id()) {
  1386. cheetah_flush_icache();
  1387. cheetah_flush_dcache();
  1388. /* Re-enable I-cache/D-cache */
  1389. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1390. "or %%g1, %1, %%g1\n\t"
  1391. "stxa %%g1, [%%g0] %0\n\t"
  1392. "membar #Sync"
  1393. : /* no outputs */
  1394. : "i" (ASI_DCU_CONTROL_REG),
  1395. "i" (DCU_DC | DCU_IC)
  1396. : "g1");
  1397. /* Re-enable error reporting */
  1398. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1399. "or %%g1, %1, %%g1\n\t"
  1400. "stxa %%g1, [%%g0] %0\n\t"
  1401. "membar #Sync"
  1402. : /* no outputs */
  1403. : "i" (ASI_ESTATE_ERROR_EN),
  1404. "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
  1405. : "g1");
  1406. (void) cheetah_recheck_errors(NULL);
  1407. pci_poke_faulted = 1;
  1408. regs->tpc += 4;
  1409. regs->tnpc = regs->tpc + 4;
  1410. return;
  1411. }
  1412. #endif
  1413. p = cheetah_get_error_log(afsr);
  1414. if (!p) {
  1415. prom_printf("ERROR: Early deferred error afsr[%016lx] afar[%016lx]\n",
  1416. afsr, afar);
  1417. prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
  1418. smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
  1419. prom_halt();
  1420. }
  1421. /* Grab snapshot of logged error. */
  1422. memcpy(&local_snapshot, p, sizeof(local_snapshot));
  1423. /* If the current trap snapshot does not match what the
  1424. * trap handler passed along into our args, big trouble.
  1425. * In such a case, mark the local copy as invalid.
  1426. *
  1427. * Else, it matches and we mark the afsr in the non-local
  1428. * copy as invalid so we may log new error traps there.
  1429. */
  1430. if (p->afsr != afsr || p->afar != afar)
  1431. local_snapshot.afsr = CHAFSR_INVALID;
  1432. else
  1433. p->afsr = CHAFSR_INVALID;
  1434. is_memory = cheetah_check_main_memory(afar);
  1435. {
  1436. int flush_all, flush_line;
  1437. flush_all = flush_line = 0;
  1438. if ((afsr & CHAFSR_EDU) != 0UL) {
  1439. if ((afsr & cheetah_afsr_errors) == CHAFSR_EDU)
  1440. flush_line = 1;
  1441. else
  1442. flush_all = 1;
  1443. } else if ((afsr & CHAFSR_BERR) != 0UL) {
  1444. if ((afsr & cheetah_afsr_errors) == CHAFSR_BERR)
  1445. flush_line = 1;
  1446. else
  1447. flush_all = 1;
  1448. }
  1449. cheetah_flush_icache();
  1450. cheetah_flush_dcache();
  1451. /* Re-enable I/D caches */
  1452. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1453. "or %%g1, %1, %%g1\n\t"
  1454. "stxa %%g1, [%%g0] %0\n\t"
  1455. "membar #Sync"
  1456. : /* no outputs */
  1457. : "i" (ASI_DCU_CONTROL_REG),
  1458. "i" (DCU_IC | DCU_DC)
  1459. : "g1");
  1460. if (flush_all)
  1461. cheetah_flush_ecache();
  1462. else if (flush_line)
  1463. cheetah_flush_ecache_line(afar);
  1464. }
  1465. /* Re-enable error reporting */
  1466. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1467. "or %%g1, %1, %%g1\n\t"
  1468. "stxa %%g1, [%%g0] %0\n\t"
  1469. "membar #Sync"
  1470. : /* no outputs */
  1471. : "i" (ASI_ESTATE_ERROR_EN),
  1472. "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
  1473. : "g1");
  1474. /* Decide if we can continue after handling this trap and
  1475. * logging the error.
  1476. */
  1477. recoverable = 1;
  1478. if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
  1479. recoverable = 0;
  1480. /* Re-check AFSR/AFAR. What we are looking for here is whether a new
  1481. * error was logged while we had error reporting traps disabled.
  1482. */
  1483. if (cheetah_recheck_errors(&local_snapshot)) {
  1484. unsigned long new_afsr = local_snapshot.afsr;
  1485. /* If we got a new asynchronous error, die... */
  1486. if (new_afsr & (CHAFSR_EMU | CHAFSR_EDU |
  1487. CHAFSR_WDU | CHAFSR_CPU |
  1488. CHAFSR_IVU | CHAFSR_UE |
  1489. CHAFSR_BERR | CHAFSR_TO))
  1490. recoverable = 0;
  1491. }
  1492. /* Log errors. */
  1493. cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
  1494. /* "Recoverable" here means we try to yank the page from ever
  1495. * being newly used again. This depends upon a few things:
  1496. * 1) Must be main memory, and AFAR must be valid.
  1497. * 2) If we trapped from user, OK.
  1498. * 3) Else, if we trapped from kernel we must find exception
  1499. * table entry (ie. we have to have been accessing user
  1500. * space).
  1501. *
  1502. * If AFAR is not in main memory, or we trapped from kernel
  1503. * and cannot find an exception table entry, it is unacceptable
  1504. * to try and continue.
  1505. */
  1506. if (recoverable && is_memory) {
  1507. if ((regs->tstate & TSTATE_PRIV) == 0UL) {
  1508. /* OK, usermode access. */
  1509. recoverable = 1;
  1510. } else {
  1511. const struct exception_table_entry *entry;
  1512. entry = search_exception_tables(regs->tpc);
  1513. if (entry) {
  1514. /* OK, kernel access to userspace. */
  1515. recoverable = 1;
  1516. } else {
  1517. /* BAD, privileged state is corrupted. */
  1518. recoverable = 0;
  1519. }
  1520. if (recoverable) {
  1521. if (pfn_valid(afar >> PAGE_SHIFT))
  1522. get_page(pfn_to_page(afar >> PAGE_SHIFT));
  1523. else
  1524. recoverable = 0;
  1525. /* Only perform fixup if we still have a
  1526. * recoverable condition.
  1527. */
  1528. if (recoverable) {
  1529. regs->tpc = entry->fixup;
  1530. regs->tnpc = regs->tpc + 4;
  1531. }
  1532. }
  1533. }
  1534. } else {
  1535. recoverable = 0;
  1536. }
  1537. if (!recoverable)
  1538. panic("Irrecoverable deferred error trap.\n");
  1539. }
  1540. /* Handle a D/I cache parity error trap. TYPE is encoded as:
  1541. *
  1542. * Bit0: 0=dcache,1=icache
  1543. * Bit1: 0=recoverable,1=unrecoverable
  1544. *
  1545. * The hardware has disabled both the I-cache and D-cache in
  1546. * the %dcr register.
  1547. */
  1548. void cheetah_plus_parity_error(int type, struct pt_regs *regs)
  1549. {
  1550. if (type & 0x1)
  1551. __cheetah_flush_icache();
  1552. else
  1553. cheetah_plus_zap_dcache_parity();
  1554. cheetah_flush_dcache();
  1555. /* Re-enable I-cache/D-cache */
  1556. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1557. "or %%g1, %1, %%g1\n\t"
  1558. "stxa %%g1, [%%g0] %0\n\t"
  1559. "membar #Sync"
  1560. : /* no outputs */
  1561. : "i" (ASI_DCU_CONTROL_REG),
  1562. "i" (DCU_DC | DCU_IC)
  1563. : "g1");
  1564. if (type & 0x2) {
  1565. printk(KERN_EMERG "CPU[%d]: Cheetah+ %c-cache parity error at TPC[%016lx]\n",
  1566. smp_processor_id(),
  1567. (type & 0x1) ? 'I' : 'D',
  1568. regs->tpc);
  1569. printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
  1570. panic("Irrecoverable Cheetah+ parity error.");
  1571. }
  1572. printk(KERN_WARNING "CPU[%d]: Cheetah+ %c-cache parity error at TPC[%016lx]\n",
  1573. smp_processor_id(),
  1574. (type & 0x1) ? 'I' : 'D',
  1575. regs->tpc);
  1576. printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
  1577. }
  1578. struct sun4v_error_entry {
  1579. /* Unique error handle */
  1580. /*0x00*/u64 err_handle;
  1581. /* %stick value at the time of the error */
  1582. /*0x08*/u64 err_stick;
  1583. /*0x10*/u8 reserved_1[3];
  1584. /* Error type */
  1585. /*0x13*/u8 err_type;
  1586. #define SUN4V_ERR_TYPE_UNDEFINED 0
  1587. #define SUN4V_ERR_TYPE_UNCORRECTED_RES 1
  1588. #define SUN4V_ERR_TYPE_PRECISE_NONRES 2
  1589. #define SUN4V_ERR_TYPE_DEFERRED_NONRES 3
  1590. #define SUN4V_ERR_TYPE_SHUTDOWN_RQST 4
  1591. #define SUN4V_ERR_TYPE_DUMP_CORE 5
  1592. #define SUN4V_ERR_TYPE_SP_STATE_CHANGE 6
  1593. #define SUN4V_ERR_TYPE_NUM 7
  1594. /* Error attributes */
  1595. /*0x14*/u32 err_attrs;
  1596. #define SUN4V_ERR_ATTRS_PROCESSOR 0x00000001
  1597. #define SUN4V_ERR_ATTRS_MEMORY 0x00000002
  1598. #define SUN4V_ERR_ATTRS_PIO 0x00000004
  1599. #define SUN4V_ERR_ATTRS_INT_REGISTERS 0x00000008
  1600. #define SUN4V_ERR_ATTRS_FPU_REGISTERS 0x00000010
  1601. #define SUN4V_ERR_ATTRS_SHUTDOWN_RQST 0x00000020
  1602. #define SUN4V_ERR_ATTRS_ASR 0x00000040
  1603. #define SUN4V_ERR_ATTRS_ASI 0x00000080
  1604. #define SUN4V_ERR_ATTRS_PRIV_REG 0x00000100
  1605. #define SUN4V_ERR_ATTRS_SPSTATE_MSK 0x00000600
  1606. #define SUN4V_ERR_ATTRS_MCD 0x00000800
  1607. #define SUN4V_ERR_ATTRS_SPSTATE_SHFT 9
  1608. #define SUN4V_ERR_ATTRS_MODE_MSK 0x03000000
  1609. #define SUN4V_ERR_ATTRS_MODE_SHFT 24
  1610. #define SUN4V_ERR_ATTRS_RES_QUEUE_FULL 0x80000000
  1611. #define SUN4V_ERR_SPSTATE_FAULTED 0
  1612. #define SUN4V_ERR_SPSTATE_AVAILABLE 1
  1613. #define SUN4V_ERR_SPSTATE_NOT_PRESENT 2
  1614. #define SUN4V_ERR_MODE_USER 1
  1615. #define SUN4V_ERR_MODE_PRIV 2
  1616. /* Real address of the memory region or PIO transaction */
  1617. /*0x18*/u64 err_raddr;
  1618. /* Size of the operation triggering the error, in bytes */
  1619. /*0x20*/u32 err_size;
  1620. /* ID of the CPU */
  1621. /*0x24*/u16 err_cpu;
  1622. /* Grace periof for shutdown, in seconds */
  1623. /*0x26*/u16 err_secs;
  1624. /* Value of the %asi register */
  1625. /*0x28*/u8 err_asi;
  1626. /*0x29*/u8 reserved_2;
  1627. /* Value of the ASR register number */
  1628. /*0x2a*/u16 err_asr;
  1629. #define SUN4V_ERR_ASR_VALID 0x8000
  1630. /*0x2c*/u32 reserved_3;
  1631. /*0x30*/u64 reserved_4;
  1632. /*0x38*/u64 reserved_5;
  1633. };
  1634. static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
  1635. static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
  1636. static const char *sun4v_err_type_to_str(u8 type)
  1637. {
  1638. static const char *types[SUN4V_ERR_TYPE_NUM] = {
  1639. "undefined",
  1640. "uncorrected resumable",
  1641. "precise nonresumable",
  1642. "deferred nonresumable",
  1643. "shutdown request",
  1644. "dump core",
  1645. "SP state change",
  1646. };
  1647. if (type < SUN4V_ERR_TYPE_NUM)
  1648. return types[type];
  1649. return "unknown";
  1650. }
  1651. static void sun4v_emit_err_attr_strings(u32 attrs)
  1652. {
  1653. static const char *attr_names[] = {
  1654. "processor",
  1655. "memory",
  1656. "PIO",
  1657. "int-registers",
  1658. "fpu-registers",
  1659. "shutdown-request",
  1660. "ASR",
  1661. "ASI",
  1662. "priv-reg",
  1663. };
  1664. static const char *sp_states[] = {
  1665. "sp-faulted",
  1666. "sp-available",
  1667. "sp-not-present",
  1668. "sp-state-reserved",
  1669. };
  1670. static const char *modes[] = {
  1671. "mode-reserved0",
  1672. "user",
  1673. "priv",
  1674. "mode-reserved1",
  1675. };
  1676. u32 sp_state, mode;
  1677. int i;
  1678. for (i = 0; i < ARRAY_SIZE(attr_names); i++) {
  1679. if (attrs & (1U << i)) {
  1680. const char *s = attr_names[i];
  1681. pr_cont("%s ", s);
  1682. }
  1683. }
  1684. sp_state = ((attrs & SUN4V_ERR_ATTRS_SPSTATE_MSK) >>
  1685. SUN4V_ERR_ATTRS_SPSTATE_SHFT);
  1686. pr_cont("%s ", sp_states[sp_state]);
  1687. mode = ((attrs & SUN4V_ERR_ATTRS_MODE_MSK) >>
  1688. SUN4V_ERR_ATTRS_MODE_SHFT);
  1689. pr_cont("%s ", modes[mode]);
  1690. if (attrs & SUN4V_ERR_ATTRS_RES_QUEUE_FULL)
  1691. pr_cont("res-queue-full ");
  1692. }
  1693. /* When the report contains a real-address of "-1" it means that the
  1694. * hardware did not provide the address. So we compute the effective
  1695. * address of the load or store instruction at regs->tpc and report
  1696. * that. Usually when this happens it's a PIO and in such a case we
  1697. * are using physical addresses with bypass ASIs anyways, so what we
  1698. * report here is exactly what we want.
  1699. */
  1700. static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
  1701. {
  1702. unsigned int insn;
  1703. u64 addr;
  1704. if (!(regs->tstate & TSTATE_PRIV))
  1705. return;
  1706. insn = *(unsigned int *) regs->tpc;
  1707. addr = compute_effective_address(regs, insn, 0);
  1708. printk("%s: insn effective address [0x%016llx]\n",
  1709. pfx, addr);
  1710. }
  1711. static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
  1712. int cpu, const char *pfx, atomic_t *ocnt)
  1713. {
  1714. u64 *raw_ptr = (u64 *) ent;
  1715. u32 attrs;
  1716. int cnt;
  1717. printk("%s: Reporting on cpu %d\n", pfx, cpu);
  1718. printk("%s: TPC [0x%016lx] <%pS>\n",
  1719. pfx, regs->tpc, (void *) regs->tpc);
  1720. printk("%s: RAW [%016llx:%016llx:%016llx:%016llx\n",
  1721. pfx, raw_ptr[0], raw_ptr[1], raw_ptr[2], raw_ptr[3]);
  1722. printk("%s: %016llx:%016llx:%016llx:%016llx]\n",
  1723. pfx, raw_ptr[4], raw_ptr[5], raw_ptr[6], raw_ptr[7]);
  1724. printk("%s: handle [0x%016llx] stick [0x%016llx]\n",
  1725. pfx, ent->err_handle, ent->err_stick);
  1726. printk("%s: type [%s]\n", pfx, sun4v_err_type_to_str(ent->err_type));
  1727. attrs = ent->err_attrs;
  1728. printk("%s: attrs [0x%08x] < ", pfx, attrs);
  1729. sun4v_emit_err_attr_strings(attrs);
  1730. pr_cont(">\n");
  1731. /* Various fields in the error report are only valid if
  1732. * certain attribute bits are set.
  1733. */
  1734. if (attrs & (SUN4V_ERR_ATTRS_MEMORY |
  1735. SUN4V_ERR_ATTRS_PIO |
  1736. SUN4V_ERR_ATTRS_ASI)) {
  1737. printk("%s: raddr [0x%016llx]\n", pfx, ent->err_raddr);
  1738. if (ent->err_raddr == ~(u64)0)
  1739. sun4v_report_real_raddr(pfx, regs);
  1740. }
  1741. if (attrs & (SUN4V_ERR_ATTRS_MEMORY | SUN4V_ERR_ATTRS_ASI))
  1742. printk("%s: size [0x%x]\n", pfx, ent->err_size);
  1743. if (attrs & (SUN4V_ERR_ATTRS_PROCESSOR |
  1744. SUN4V_ERR_ATTRS_INT_REGISTERS |
  1745. SUN4V_ERR_ATTRS_FPU_REGISTERS |
  1746. SUN4V_ERR_ATTRS_PRIV_REG))
  1747. printk("%s: cpu[%u]\n", pfx, ent->err_cpu);
  1748. if (attrs & SUN4V_ERR_ATTRS_ASI)
  1749. printk("%s: asi [0x%02x]\n", pfx, ent->err_asi);
  1750. if ((attrs & (SUN4V_ERR_ATTRS_INT_REGISTERS |
  1751. SUN4V_ERR_ATTRS_FPU_REGISTERS |
  1752. SUN4V_ERR_ATTRS_PRIV_REG)) &&
  1753. (ent->err_asr & SUN4V_ERR_ASR_VALID) != 0)
  1754. printk("%s: reg [0x%04x]\n",
  1755. pfx, ent->err_asr & ~SUN4V_ERR_ASR_VALID);
  1756. show_regs(regs);
  1757. if ((cnt = atomic_read(ocnt)) != 0) {
  1758. atomic_set(ocnt, 0);
  1759. wmb();
  1760. printk("%s: Queue overflowed %d times.\n",
  1761. pfx, cnt);
  1762. }
  1763. }
  1764. /* Handle memory corruption detected error which is vectored in
  1765. * through resumable error trap.
  1766. */
  1767. void do_mcd_err(struct pt_regs *regs, struct sun4v_error_entry ent)
  1768. {
  1769. if (notify_die(DIE_TRAP, "MCD error", regs, 0, 0x34,
  1770. SIGSEGV) == NOTIFY_STOP)
  1771. return;
  1772. if (regs->tstate & TSTATE_PRIV) {
  1773. /* MCD exception could happen because the task was
  1774. * running a system call with MCD enabled and passed a
  1775. * non-versioned pointer or pointer with bad version
  1776. * tag to the system call. In such cases, hypervisor
  1777. * places the address of offending instruction in the
  1778. * resumable error report. This is a deferred error,
  1779. * so the read/write that caused the trap was potentially
  1780. * retired long time back and we may have no choice
  1781. * but to send SIGSEGV to the process.
  1782. */
  1783. const struct exception_table_entry *entry;
  1784. entry = search_exception_tables(regs->tpc);
  1785. if (entry) {
  1786. /* Looks like a bad syscall parameter */
  1787. #ifdef DEBUG_EXCEPTIONS
  1788. pr_emerg("Exception: PC<%016lx> faddr<UNKNOWN>\n",
  1789. regs->tpc);
  1790. pr_emerg("EX_TABLE: insn<%016lx> fixup<%016lx>\n",
  1791. ent.err_raddr, entry->fixup);
  1792. #endif
  1793. regs->tpc = entry->fixup;
  1794. regs->tnpc = regs->tpc + 4;
  1795. return;
  1796. }
  1797. }
  1798. /* Send SIGSEGV to the userspace process with the right signal
  1799. * code
  1800. */
  1801. force_sig_fault(SIGSEGV, SEGV_ADIDERR, (void __user *)ent.err_raddr);
  1802. }
  1803. /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
  1804. * Log the event and clear the first word of the entry.
  1805. */
  1806. void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
  1807. {
  1808. enum ctx_state prev_state = exception_enter();
  1809. struct sun4v_error_entry *ent, local_copy;
  1810. struct trap_per_cpu *tb;
  1811. unsigned long paddr;
  1812. int cpu;
  1813. cpu = get_cpu();
  1814. tb = &trap_block[cpu];
  1815. paddr = tb->resum_kernel_buf_pa + offset;
  1816. ent = __va(paddr);
  1817. memcpy(&local_copy, ent, sizeof(struct sun4v_error_entry));
  1818. /* We have a local copy now, so release the entry. */
  1819. ent->err_handle = 0;
  1820. wmb();
  1821. put_cpu();
  1822. if (local_copy.err_type == SUN4V_ERR_TYPE_SHUTDOWN_RQST) {
  1823. /* We should really take the seconds field of
  1824. * the error report and use it for the shutdown
  1825. * invocation, but for now do the same thing we
  1826. * do for a DS shutdown request.
  1827. */
  1828. pr_info("Shutdown request, %u seconds...\n",
  1829. local_copy.err_secs);
  1830. orderly_poweroff(true);
  1831. goto out;
  1832. }
  1833. /* If this is a memory corruption detected error vectored in
  1834. * by HV through resumable error trap, call the handler
  1835. */
  1836. if (local_copy.err_attrs & SUN4V_ERR_ATTRS_MCD) {
  1837. do_mcd_err(regs, local_copy);
  1838. return;
  1839. }
  1840. sun4v_log_error(regs, &local_copy, cpu,
  1841. KERN_ERR "RESUMABLE ERROR",
  1842. &sun4v_resum_oflow_cnt);
  1843. out:
  1844. exception_exit(prev_state);
  1845. }
  1846. /* If we try to printk() we'll probably make matters worse, by trying
  1847. * to retake locks this cpu already holds or causing more errors. So
  1848. * just bump a counter, and we'll report these counter bumps above.
  1849. */
  1850. void sun4v_resum_overflow(struct pt_regs *regs)
  1851. {
  1852. atomic_inc(&sun4v_resum_oflow_cnt);
  1853. }
  1854. /* Given a set of registers, get the virtual addressi that was being accessed
  1855. * by the faulting instructions at tpc.
  1856. */
  1857. static unsigned long sun4v_get_vaddr(struct pt_regs *regs)
  1858. {
  1859. unsigned int insn;
  1860. if (!copy_from_user(&insn, (void __user *)regs->tpc, 4)) {
  1861. return compute_effective_address(regs, insn,
  1862. (insn >> 25) & 0x1f);
  1863. }
  1864. return 0;
  1865. }
  1866. /* Attempt to handle non-resumable errors generated from userspace.
  1867. * Returns true if the signal was handled, false otherwise.
  1868. */
  1869. bool sun4v_nonresum_error_user_handled(struct pt_regs *regs,
  1870. struct sun4v_error_entry *ent) {
  1871. unsigned int attrs = ent->err_attrs;
  1872. if (attrs & SUN4V_ERR_ATTRS_MEMORY) {
  1873. unsigned long addr = ent->err_raddr;
  1874. if (addr == ~(u64)0) {
  1875. /* This seems highly unlikely to ever occur */
  1876. pr_emerg("SUN4V NON-RECOVERABLE ERROR: Memory error detected in unknown location!\n");
  1877. } else {
  1878. unsigned long page_cnt = DIV_ROUND_UP(ent->err_size,
  1879. PAGE_SIZE);
  1880. /* Break the unfortunate news. */
  1881. pr_emerg("SUN4V NON-RECOVERABLE ERROR: Memory failed at %016lX\n",
  1882. addr);
  1883. pr_emerg("SUN4V NON-RECOVERABLE ERROR: Claiming %lu ages.\n",
  1884. page_cnt);
  1885. while (page_cnt-- > 0) {
  1886. if (pfn_valid(addr >> PAGE_SHIFT))
  1887. get_page(pfn_to_page(addr >> PAGE_SHIFT));
  1888. addr += PAGE_SIZE;
  1889. }
  1890. }
  1891. force_sig(SIGKILL);
  1892. return true;
  1893. }
  1894. if (attrs & SUN4V_ERR_ATTRS_PIO) {
  1895. force_sig_fault(SIGBUS, BUS_ADRERR,
  1896. (void __user *)sun4v_get_vaddr(regs));
  1897. return true;
  1898. }
  1899. /* Default to doing nothing */
  1900. return false;
  1901. }
  1902. /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
  1903. * Log the event, clear the first word of the entry, and die.
  1904. */
  1905. void sun4v_nonresum_error(struct pt_regs *regs, unsigned long offset)
  1906. {
  1907. struct sun4v_error_entry *ent, local_copy;
  1908. struct trap_per_cpu *tb;
  1909. unsigned long paddr;
  1910. int cpu;
  1911. cpu = get_cpu();
  1912. tb = &trap_block[cpu];
  1913. paddr = tb->nonresum_kernel_buf_pa + offset;
  1914. ent = __va(paddr);
  1915. memcpy(&local_copy, ent, sizeof(struct sun4v_error_entry));
  1916. /* We have a local copy now, so release the entry. */
  1917. ent->err_handle = 0;
  1918. wmb();
  1919. put_cpu();
  1920. if (!(regs->tstate & TSTATE_PRIV) &&
  1921. sun4v_nonresum_error_user_handled(regs, &local_copy)) {
  1922. /* DON'T PANIC: This userspace error was handled. */
  1923. return;
  1924. }
  1925. #ifdef CONFIG_PCI
  1926. /* Check for the special PCI poke sequence. */
  1927. if (pci_poke_in_progress && pci_poke_cpu == cpu) {
  1928. pci_poke_faulted = 1;
  1929. regs->tpc += 4;
  1930. regs->tnpc = regs->tpc + 4;
  1931. return;
  1932. }
  1933. #endif
  1934. sun4v_log_error(regs, &local_copy, cpu,
  1935. KERN_EMERG "NON-RESUMABLE ERROR",
  1936. &sun4v_nonresum_oflow_cnt);
  1937. panic("Non-resumable error.");
  1938. }
  1939. /* If we try to printk() we'll probably make matters worse, by trying
  1940. * to retake locks this cpu already holds or causing more errors. So
  1941. * just bump a counter, and we'll report these counter bumps above.
  1942. */
  1943. void sun4v_nonresum_overflow(struct pt_regs *regs)
  1944. {
  1945. /* XXX Actually even this can make not that much sense. Perhaps
  1946. * XXX we should just pull the plug and panic directly from here?
  1947. */
  1948. atomic_inc(&sun4v_nonresum_oflow_cnt);
  1949. }
  1950. static void sun4v_tlb_error(struct pt_regs *regs)
  1951. {
  1952. die_if_kernel("TLB/TSB error", regs);
  1953. }
  1954. unsigned long sun4v_err_itlb_vaddr;
  1955. unsigned long sun4v_err_itlb_ctx;
  1956. unsigned long sun4v_err_itlb_pte;
  1957. unsigned long sun4v_err_itlb_error;
  1958. void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
  1959. {
  1960. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1961. printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
  1962. regs->tpc, tl);
  1963. printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
  1964. printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
  1965. printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
  1966. (void *) regs->u_regs[UREG_I7]);
  1967. printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
  1968. "pte[%lx] error[%lx]\n",
  1969. sun4v_err_itlb_vaddr, sun4v_err_itlb_ctx,
  1970. sun4v_err_itlb_pte, sun4v_err_itlb_error);
  1971. sun4v_tlb_error(regs);
  1972. }
  1973. unsigned long sun4v_err_dtlb_vaddr;
  1974. unsigned long sun4v_err_dtlb_ctx;
  1975. unsigned long sun4v_err_dtlb_pte;
  1976. unsigned long sun4v_err_dtlb_error;
  1977. void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
  1978. {
  1979. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1980. printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
  1981. regs->tpc, tl);
  1982. printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
  1983. printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
  1984. printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
  1985. (void *) regs->u_regs[UREG_I7]);
  1986. printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
  1987. "pte[%lx] error[%lx]\n",
  1988. sun4v_err_dtlb_vaddr, sun4v_err_dtlb_ctx,
  1989. sun4v_err_dtlb_pte, sun4v_err_dtlb_error);
  1990. sun4v_tlb_error(regs);
  1991. }
  1992. void hypervisor_tlbop_error(unsigned long err, unsigned long op)
  1993. {
  1994. printk(KERN_CRIT "SUN4V: TLB hv call error %lu for op %lu\n",
  1995. err, op);
  1996. }
  1997. void hypervisor_tlbop_error_xcall(unsigned long err, unsigned long op)
  1998. {
  1999. printk(KERN_CRIT "SUN4V: XCALL TLB hv call error %lu for op %lu\n",
  2000. err, op);
  2001. }
  2002. static void do_fpe_common(struct pt_regs *regs)
  2003. {
  2004. if (regs->tstate & TSTATE_PRIV) {
  2005. regs->tpc = regs->tnpc;
  2006. regs->tnpc += 4;
  2007. } else {
  2008. unsigned long fsr = current_thread_info()->xfsr[0];
  2009. int code;
  2010. if (test_thread_flag(TIF_32BIT)) {
  2011. regs->tpc &= 0xffffffff;
  2012. regs->tnpc &= 0xffffffff;
  2013. }
  2014. code = FPE_FLTUNK;
  2015. if ((fsr & 0x1c000) == (1 << 14)) {
  2016. if (fsr & 0x10)
  2017. code = FPE_FLTINV;
  2018. else if (fsr & 0x08)
  2019. code = FPE_FLTOVF;
  2020. else if (fsr & 0x04)
  2021. code = FPE_FLTUND;
  2022. else if (fsr & 0x02)
  2023. code = FPE_FLTDIV;
  2024. else if (fsr & 0x01)
  2025. code = FPE_FLTRES;
  2026. }
  2027. force_sig_fault(SIGFPE, code, (void __user *)regs->tpc);
  2028. }
  2029. }
  2030. void do_fpieee(struct pt_regs *regs)
  2031. {
  2032. enum ctx_state prev_state = exception_enter();
  2033. if (notify_die(DIE_TRAP, "fpu exception ieee", regs,
  2034. 0, 0x24, SIGFPE) == NOTIFY_STOP)
  2035. goto out;
  2036. do_fpe_common(regs);
  2037. out:
  2038. exception_exit(prev_state);
  2039. }
  2040. void do_fpother(struct pt_regs *regs)
  2041. {
  2042. enum ctx_state prev_state = exception_enter();
  2043. struct fpustate *f = FPUSTATE;
  2044. int ret = 0;
  2045. if (notify_die(DIE_TRAP, "fpu exception other", regs,
  2046. 0, 0x25, SIGFPE) == NOTIFY_STOP)
  2047. goto out;
  2048. switch ((current_thread_info()->xfsr[0] & 0x1c000)) {
  2049. case (2 << 14): /* unfinished_FPop */
  2050. case (3 << 14): /* unimplemented_FPop */
  2051. ret = do_mathemu(regs, f, false);
  2052. break;
  2053. }
  2054. if (ret)
  2055. goto out;
  2056. do_fpe_common(regs);
  2057. out:
  2058. exception_exit(prev_state);
  2059. }
  2060. void do_tof(struct pt_regs *regs)
  2061. {
  2062. enum ctx_state prev_state = exception_enter();
  2063. if (notify_die(DIE_TRAP, "tagged arithmetic overflow", regs,
  2064. 0, 0x26, SIGEMT) == NOTIFY_STOP)
  2065. goto out;
  2066. if (regs->tstate & TSTATE_PRIV)
  2067. die_if_kernel("Penguin overflow trap from kernel mode", regs);
  2068. if (test_thread_flag(TIF_32BIT)) {
  2069. regs->tpc &= 0xffffffff;
  2070. regs->tnpc &= 0xffffffff;
  2071. }
  2072. force_sig_fault(SIGEMT, EMT_TAGOVF, (void __user *)regs->tpc);
  2073. out:
  2074. exception_exit(prev_state);
  2075. }
  2076. void do_div0(struct pt_regs *regs)
  2077. {
  2078. enum ctx_state prev_state = exception_enter();
  2079. if (notify_die(DIE_TRAP, "integer division by zero", regs,
  2080. 0, 0x28, SIGFPE) == NOTIFY_STOP)
  2081. goto out;
  2082. if (regs->tstate & TSTATE_PRIV)
  2083. die_if_kernel("TL0: Kernel divide by zero.", regs);
  2084. if (test_thread_flag(TIF_32BIT)) {
  2085. regs->tpc &= 0xffffffff;
  2086. regs->tnpc &= 0xffffffff;
  2087. }
  2088. force_sig_fault(SIGFPE, FPE_INTDIV, (void __user *)regs->tpc);
  2089. out:
  2090. exception_exit(prev_state);
  2091. }
  2092. static void instruction_dump(unsigned int *pc)
  2093. {
  2094. int i;
  2095. if ((((unsigned long) pc) & 3))
  2096. return;
  2097. printk("Instruction DUMP:");
  2098. for (i = -3; i < 6; i++)
  2099. printk("%c%08x%c",i?' ':'<',pc[i],i?' ':'>');
  2100. printk("\n");
  2101. }
  2102. static void user_instruction_dump(unsigned int __user *pc)
  2103. {
  2104. int i;
  2105. unsigned int buf[9];
  2106. if ((((unsigned long) pc) & 3))
  2107. return;
  2108. if (copy_from_user(buf, pc - 3, sizeof(buf)))
  2109. return;
  2110. printk("Instruction DUMP:");
  2111. for (i = 0; i < 9; i++)
  2112. printk("%c%08x%c",i==3?' ':'<',buf[i],i==3?' ':'>');
  2113. printk("\n");
  2114. }
  2115. void show_stack(struct task_struct *tsk, unsigned long *_ksp, const char *loglvl)
  2116. {
  2117. unsigned long fp, ksp;
  2118. struct thread_info *tp;
  2119. int count = 0;
  2120. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  2121. int graph = 0;
  2122. #endif
  2123. ksp = (unsigned long) _ksp;
  2124. if (!tsk)
  2125. tsk = current;
  2126. tp = task_thread_info(tsk);
  2127. if (ksp == 0UL) {
  2128. if (tsk == current)
  2129. asm("mov %%fp, %0" : "=r" (ksp));
  2130. else
  2131. ksp = tp->ksp;
  2132. }
  2133. if (tp == current_thread_info())
  2134. flushw_all();
  2135. fp = ksp + STACK_BIAS;
  2136. printk("%sCall Trace:\n", loglvl);
  2137. do {
  2138. struct sparc_stackf *sf;
  2139. struct pt_regs *regs;
  2140. unsigned long pc;
  2141. if (!kstack_valid(tp, fp))
  2142. break;
  2143. sf = (struct sparc_stackf *) fp;
  2144. regs = (struct pt_regs *) (sf + 1);
  2145. if (kstack_is_trap_frame(tp, regs)) {
  2146. if (!(regs->tstate & TSTATE_PRIV))
  2147. break;
  2148. pc = regs->tpc;
  2149. fp = regs->u_regs[UREG_I6] + STACK_BIAS;
  2150. } else {
  2151. pc = sf->callers_pc;
  2152. fp = (unsigned long)sf->fp + STACK_BIAS;
  2153. }
  2154. print_ip_sym(loglvl, pc);
  2155. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  2156. if ((pc + 8UL) == (unsigned long) &return_to_handler) {
  2157. struct ftrace_ret_stack *ret_stack;
  2158. ret_stack = ftrace_graph_get_ret_stack(tsk, graph);
  2159. if (ret_stack) {
  2160. pc = ret_stack->ret;
  2161. print_ip_sym(loglvl, pc);
  2162. graph++;
  2163. }
  2164. }
  2165. #endif
  2166. } while (++count < 16);
  2167. }
  2168. static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
  2169. {
  2170. unsigned long fp = rw->ins[6];
  2171. if (!fp)
  2172. return NULL;
  2173. return (struct reg_window *) (fp + STACK_BIAS);
  2174. }
  2175. void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
  2176. {
  2177. static int die_counter;
  2178. int count = 0;
  2179. /* Amuse the user. */
  2180. printk(
  2181. " \\|/ ____ \\|/\n"
  2182. " \"@'/ .. \\`@\"\n"
  2183. " /_| \\__/ |_\\\n"
  2184. " \\__U_/\n");
  2185. printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
  2186. notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
  2187. __asm__ __volatile__("flushw");
  2188. show_regs(regs);
  2189. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  2190. if (regs->tstate & TSTATE_PRIV) {
  2191. struct thread_info *tp = current_thread_info();
  2192. struct reg_window *rw = (struct reg_window *)
  2193. (regs->u_regs[UREG_FP] + STACK_BIAS);
  2194. /* Stop the back trace when we hit userland or we
  2195. * find some badly aligned kernel stack.
  2196. */
  2197. while (rw &&
  2198. count++ < 30 &&
  2199. kstack_valid(tp, (unsigned long) rw)) {
  2200. printk("Caller[%016lx]: %pS\n", rw->ins[7],
  2201. (void *) rw->ins[7]);
  2202. rw = kernel_stack_up(rw);
  2203. }
  2204. instruction_dump ((unsigned int *) regs->tpc);
  2205. } else {
  2206. if (test_thread_flag(TIF_32BIT)) {
  2207. regs->tpc &= 0xffffffff;
  2208. regs->tnpc &= 0xffffffff;
  2209. }
  2210. user_instruction_dump ((unsigned int __user *) regs->tpc);
  2211. }
  2212. if (panic_on_oops)
  2213. panic("Fatal exception");
  2214. make_task_dead((regs->tstate & TSTATE_PRIV)? SIGKILL : SIGSEGV);
  2215. }
  2216. EXPORT_SYMBOL(die_if_kernel);
  2217. #define VIS_OPCODE_MASK ((0x3 << 30) | (0x3f << 19))
  2218. #define VIS_OPCODE_VAL ((0x2 << 30) | (0x36 << 19))
  2219. void do_illegal_instruction(struct pt_regs *regs)
  2220. {
  2221. enum ctx_state prev_state = exception_enter();
  2222. unsigned long pc = regs->tpc;
  2223. unsigned long tstate = regs->tstate;
  2224. u32 insn;
  2225. if (notify_die(DIE_TRAP, "illegal instruction", regs,
  2226. 0, 0x10, SIGILL) == NOTIFY_STOP)
  2227. goto out;
  2228. if (tstate & TSTATE_PRIV)
  2229. die_if_kernel("Kernel illegal instruction", regs);
  2230. if (test_thread_flag(TIF_32BIT))
  2231. pc = (u32)pc;
  2232. if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
  2233. if ((insn & 0xc1ffc000) == 0x81700000) /* POPC */ {
  2234. if (handle_popc(insn, regs))
  2235. goto out;
  2236. } else if ((insn & 0xc1580000) == 0xc1100000) /* LDQ/STQ */ {
  2237. if (handle_ldf_stq(insn, regs))
  2238. goto out;
  2239. } else if (tlb_type == hypervisor) {
  2240. if ((insn & VIS_OPCODE_MASK) == VIS_OPCODE_VAL) {
  2241. if (!vis_emul(regs, insn))
  2242. goto out;
  2243. } else {
  2244. struct fpustate *f = FPUSTATE;
  2245. /* On UltraSPARC T2 and later, FPU insns which
  2246. * are not implemented in HW signal an illegal
  2247. * instruction trap and do not set the FP Trap
  2248. * Trap in the %fsr to unimplemented_FPop.
  2249. */
  2250. if (do_mathemu(regs, f, true))
  2251. goto out;
  2252. }
  2253. }
  2254. }
  2255. force_sig_fault(SIGILL, ILL_ILLOPC, (void __user *)pc);
  2256. out:
  2257. exception_exit(prev_state);
  2258. }
  2259. void mem_address_unaligned(struct pt_regs *regs, unsigned long sfar, unsigned long sfsr)
  2260. {
  2261. enum ctx_state prev_state = exception_enter();
  2262. if (notify_die(DIE_TRAP, "memory address unaligned", regs,
  2263. 0, 0x34, SIGSEGV) == NOTIFY_STOP)
  2264. goto out;
  2265. if (regs->tstate & TSTATE_PRIV) {
  2266. kernel_unaligned_trap(regs, *((unsigned int *)regs->tpc));
  2267. goto out;
  2268. }
  2269. if (is_no_fault_exception(regs))
  2270. return;
  2271. force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *)sfar);
  2272. out:
  2273. exception_exit(prev_state);
  2274. }
  2275. void sun4v_do_mna(struct pt_regs *regs, unsigned long addr, unsigned long type_ctx)
  2276. {
  2277. if (notify_die(DIE_TRAP, "memory address unaligned", regs,
  2278. 0, 0x34, SIGSEGV) == NOTIFY_STOP)
  2279. return;
  2280. if (regs->tstate & TSTATE_PRIV) {
  2281. kernel_unaligned_trap(regs, *((unsigned int *)regs->tpc));
  2282. return;
  2283. }
  2284. if (is_no_fault_exception(regs))
  2285. return;
  2286. force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *) addr);
  2287. }
  2288. /* sun4v_mem_corrupt_detect_precise() - Handle precise exception on an ADI
  2289. * tag mismatch.
  2290. *
  2291. * ADI version tag mismatch on a load from memory always results in a
  2292. * precise exception. Tag mismatch on a store to memory will result in
  2293. * precise exception if MCDPER or PMCDPER is set to 1.
  2294. */
  2295. void sun4v_mem_corrupt_detect_precise(struct pt_regs *regs, unsigned long addr,
  2296. unsigned long context)
  2297. {
  2298. if (notify_die(DIE_TRAP, "memory corruption precise exception", regs,
  2299. 0, 0x8, SIGSEGV) == NOTIFY_STOP)
  2300. return;
  2301. if (regs->tstate & TSTATE_PRIV) {
  2302. /* MCD exception could happen because the task was running
  2303. * a system call with MCD enabled and passed a non-versioned
  2304. * pointer or pointer with bad version tag to the system
  2305. * call.
  2306. */
  2307. const struct exception_table_entry *entry;
  2308. entry = search_exception_tables(regs->tpc);
  2309. if (entry) {
  2310. /* Looks like a bad syscall parameter */
  2311. #ifdef DEBUG_EXCEPTIONS
  2312. pr_emerg("Exception: PC<%016lx> faddr<UNKNOWN>\n",
  2313. regs->tpc);
  2314. pr_emerg("EX_TABLE: insn<%016lx> fixup<%016lx>\n",
  2315. regs->tpc, entry->fixup);
  2316. #endif
  2317. regs->tpc = entry->fixup;
  2318. regs->tnpc = regs->tpc + 4;
  2319. return;
  2320. }
  2321. pr_emerg("%s: ADDR[%016lx] CTX[%lx], going.\n",
  2322. __func__, addr, context);
  2323. die_if_kernel("MCD precise", regs);
  2324. }
  2325. if (test_thread_flag(TIF_32BIT)) {
  2326. regs->tpc &= 0xffffffff;
  2327. regs->tnpc &= 0xffffffff;
  2328. }
  2329. force_sig_fault(SIGSEGV, SEGV_ADIPERR, (void __user *)addr);
  2330. }
  2331. void do_privop(struct pt_regs *regs)
  2332. {
  2333. enum ctx_state prev_state = exception_enter();
  2334. if (notify_die(DIE_TRAP, "privileged operation", regs,
  2335. 0, 0x11, SIGILL) == NOTIFY_STOP)
  2336. goto out;
  2337. if (test_thread_flag(TIF_32BIT)) {
  2338. regs->tpc &= 0xffffffff;
  2339. regs->tnpc &= 0xffffffff;
  2340. }
  2341. force_sig_fault(SIGILL, ILL_PRVOPC, (void __user *)regs->tpc);
  2342. out:
  2343. exception_exit(prev_state);
  2344. }
  2345. void do_privact(struct pt_regs *regs)
  2346. {
  2347. do_privop(regs);
  2348. }
  2349. /* Trap level 1 stuff or other traps we should never see... */
  2350. void do_cee(struct pt_regs *regs)
  2351. {
  2352. exception_enter();
  2353. die_if_kernel("TL0: Cache Error Exception", regs);
  2354. }
  2355. void do_div0_tl1(struct pt_regs *regs)
  2356. {
  2357. exception_enter();
  2358. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2359. die_if_kernel("TL1: DIV0 Exception", regs);
  2360. }
  2361. void do_fpieee_tl1(struct pt_regs *regs)
  2362. {
  2363. exception_enter();
  2364. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2365. die_if_kernel("TL1: FPU IEEE Exception", regs);
  2366. }
  2367. void do_fpother_tl1(struct pt_regs *regs)
  2368. {
  2369. exception_enter();
  2370. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2371. die_if_kernel("TL1: FPU Other Exception", regs);
  2372. }
  2373. void do_ill_tl1(struct pt_regs *regs)
  2374. {
  2375. exception_enter();
  2376. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2377. die_if_kernel("TL1: Illegal Instruction Exception", regs);
  2378. }
  2379. void do_irq_tl1(struct pt_regs *regs)
  2380. {
  2381. exception_enter();
  2382. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2383. die_if_kernel("TL1: IRQ Exception", regs);
  2384. }
  2385. void do_lddfmna_tl1(struct pt_regs *regs)
  2386. {
  2387. exception_enter();
  2388. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2389. die_if_kernel("TL1: LDDF Exception", regs);
  2390. }
  2391. void do_stdfmna_tl1(struct pt_regs *regs)
  2392. {
  2393. exception_enter();
  2394. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2395. die_if_kernel("TL1: STDF Exception", regs);
  2396. }
  2397. void do_paw(struct pt_regs *regs)
  2398. {
  2399. exception_enter();
  2400. die_if_kernel("TL0: Phys Watchpoint Exception", regs);
  2401. }
  2402. void do_paw_tl1(struct pt_regs *regs)
  2403. {
  2404. exception_enter();
  2405. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2406. die_if_kernel("TL1: Phys Watchpoint Exception", regs);
  2407. }
  2408. void do_vaw(struct pt_regs *regs)
  2409. {
  2410. exception_enter();
  2411. die_if_kernel("TL0: Virt Watchpoint Exception", regs);
  2412. }
  2413. void do_vaw_tl1(struct pt_regs *regs)
  2414. {
  2415. exception_enter();
  2416. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2417. die_if_kernel("TL1: Virt Watchpoint Exception", regs);
  2418. }
  2419. void do_tof_tl1(struct pt_regs *regs)
  2420. {
  2421. exception_enter();
  2422. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  2423. die_if_kernel("TL1: Tag Overflow Exception", regs);
  2424. }
  2425. void do_getpsr(struct pt_regs *regs)
  2426. {
  2427. regs->u_regs[UREG_I0] = tstate_to_psr(regs->tstate);
  2428. regs->tpc = regs->tnpc;
  2429. regs->tnpc += 4;
  2430. if (test_thread_flag(TIF_32BIT)) {
  2431. regs->tpc &= 0xffffffff;
  2432. regs->tnpc &= 0xffffffff;
  2433. }
  2434. }
  2435. u64 cpu_mondo_counter[NR_CPUS] = {0};
  2436. struct trap_per_cpu trap_block[NR_CPUS];
  2437. EXPORT_SYMBOL(trap_block);
  2438. /* This can get invoked before sched_init() so play it super safe
  2439. * and use hard_smp_processor_id().
  2440. */
  2441. void notrace init_cur_cpu_trap(struct thread_info *t)
  2442. {
  2443. int cpu = hard_smp_processor_id();
  2444. struct trap_per_cpu *p = &trap_block[cpu];
  2445. p->thread = t;
  2446. p->pgd_paddr = 0;
  2447. }
  2448. extern void thread_info_offsets_are_bolixed_dave(void);
  2449. extern void trap_per_cpu_offsets_are_bolixed_dave(void);
  2450. extern void tsb_config_offsets_are_bolixed_dave(void);
  2451. /* Only invoked on boot processor. */
  2452. void __init trap_init(void)
  2453. {
  2454. /* Compile time sanity check. */
  2455. BUILD_BUG_ON(TI_TASK != offsetof(struct thread_info, task) ||
  2456. TI_FLAGS != offsetof(struct thread_info, flags) ||
  2457. TI_CPU != offsetof(struct thread_info, cpu) ||
  2458. TI_FPSAVED != offsetof(struct thread_info, fpsaved) ||
  2459. TI_KSP != offsetof(struct thread_info, ksp) ||
  2460. TI_FAULT_ADDR != offsetof(struct thread_info,
  2461. fault_address) ||
  2462. TI_KREGS != offsetof(struct thread_info, kregs) ||
  2463. TI_UTRAPS != offsetof(struct thread_info, utraps) ||
  2464. TI_REG_WINDOW != offsetof(struct thread_info,
  2465. reg_window) ||
  2466. TI_RWIN_SPTRS != offsetof(struct thread_info,
  2467. rwbuf_stkptrs) ||
  2468. TI_GSR != offsetof(struct thread_info, gsr) ||
  2469. TI_XFSR != offsetof(struct thread_info, xfsr) ||
  2470. TI_PRE_COUNT != offsetof(struct thread_info,
  2471. preempt_count) ||
  2472. TI_NEW_CHILD != offsetof(struct thread_info, new_child) ||
  2473. TI_KUNA_REGS != offsetof(struct thread_info,
  2474. kern_una_regs) ||
  2475. TI_KUNA_INSN != offsetof(struct thread_info,
  2476. kern_una_insn) ||
  2477. TI_FPREGS != offsetof(struct thread_info, fpregs) ||
  2478. (TI_FPREGS & (64 - 1)));
  2479. BUILD_BUG_ON(TRAP_PER_CPU_THREAD != offsetof(struct trap_per_cpu,
  2480. thread) ||
  2481. (TRAP_PER_CPU_PGD_PADDR !=
  2482. offsetof(struct trap_per_cpu, pgd_paddr)) ||
  2483. (TRAP_PER_CPU_CPU_MONDO_PA !=
  2484. offsetof(struct trap_per_cpu, cpu_mondo_pa)) ||
  2485. (TRAP_PER_CPU_DEV_MONDO_PA !=
  2486. offsetof(struct trap_per_cpu, dev_mondo_pa)) ||
  2487. (TRAP_PER_CPU_RESUM_MONDO_PA !=
  2488. offsetof(struct trap_per_cpu, resum_mondo_pa)) ||
  2489. (TRAP_PER_CPU_RESUM_KBUF_PA !=
  2490. offsetof(struct trap_per_cpu, resum_kernel_buf_pa)) ||
  2491. (TRAP_PER_CPU_NONRESUM_MONDO_PA !=
  2492. offsetof(struct trap_per_cpu, nonresum_mondo_pa)) ||
  2493. (TRAP_PER_CPU_NONRESUM_KBUF_PA !=
  2494. offsetof(struct trap_per_cpu, nonresum_kernel_buf_pa)) ||
  2495. (TRAP_PER_CPU_FAULT_INFO !=
  2496. offsetof(struct trap_per_cpu, fault_info)) ||
  2497. (TRAP_PER_CPU_CPU_MONDO_BLOCK_PA !=
  2498. offsetof(struct trap_per_cpu, cpu_mondo_block_pa)) ||
  2499. (TRAP_PER_CPU_CPU_LIST_PA !=
  2500. offsetof(struct trap_per_cpu, cpu_list_pa)) ||
  2501. (TRAP_PER_CPU_TSB_HUGE !=
  2502. offsetof(struct trap_per_cpu, tsb_huge)) ||
  2503. (TRAP_PER_CPU_TSB_HUGE_TEMP !=
  2504. offsetof(struct trap_per_cpu, tsb_huge_temp)) ||
  2505. (TRAP_PER_CPU_IRQ_WORKLIST_PA !=
  2506. offsetof(struct trap_per_cpu, irq_worklist_pa)) ||
  2507. (TRAP_PER_CPU_CPU_MONDO_QMASK !=
  2508. offsetof(struct trap_per_cpu, cpu_mondo_qmask)) ||
  2509. (TRAP_PER_CPU_DEV_MONDO_QMASK !=
  2510. offsetof(struct trap_per_cpu, dev_mondo_qmask)) ||
  2511. (TRAP_PER_CPU_RESUM_QMASK !=
  2512. offsetof(struct trap_per_cpu, resum_qmask)) ||
  2513. (TRAP_PER_CPU_NONRESUM_QMASK !=
  2514. offsetof(struct trap_per_cpu, nonresum_qmask)) ||
  2515. (TRAP_PER_CPU_PER_CPU_BASE !=
  2516. offsetof(struct trap_per_cpu, __per_cpu_base)));
  2517. BUILD_BUG_ON((TSB_CONFIG_TSB !=
  2518. offsetof(struct tsb_config, tsb)) ||
  2519. (TSB_CONFIG_RSS_LIMIT !=
  2520. offsetof(struct tsb_config, tsb_rss_limit)) ||
  2521. (TSB_CONFIG_NENTRIES !=
  2522. offsetof(struct tsb_config, tsb_nentries)) ||
  2523. (TSB_CONFIG_REG_VAL !=
  2524. offsetof(struct tsb_config, tsb_reg_val)) ||
  2525. (TSB_CONFIG_MAP_VADDR !=
  2526. offsetof(struct tsb_config, tsb_map_vaddr)) ||
  2527. (TSB_CONFIG_MAP_PTE !=
  2528. offsetof(struct tsb_config, tsb_map_pte)));
  2529. /* Attach to the address space of init_task. On SMP we
  2530. * do this in smp.c:smp_callin for other cpus.
  2531. */
  2532. mmgrab(&init_mm);
  2533. current->active_mm = &init_mm;
  2534. }