traps_64.c 78 KB

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