traps.c 74 KB

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