traps.c 71 KB

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