traps.c 73 KB

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