traps.c 63 KB

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