traps_64.c 84 KB

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