traps_64.c 79 KB

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