traps.c 75 KB

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