traps.c 74 KB

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