traps.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179
  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 long i;
  774. /* Clear the valid bits in all the tags. */
  775. for (i = 0; i < (1 << 15); i += (1 << 5)) {
  776. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  777. "membar #Sync"
  778. : /* no outputs */
  779. : "r" (i | (2 << 3)), "i" (ASI_IC_TAG));
  780. }
  781. }
  782. static void cheetah_flush_icache(void)
  783. {
  784. unsigned long dcu_save;
  785. /* Save current DCU, disable I-cache. */
  786. __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
  787. "or %0, %2, %%g1\n\t"
  788. "stxa %%g1, [%%g0] %1\n\t"
  789. "membar #Sync"
  790. : "=r" (dcu_save)
  791. : "i" (ASI_DCU_CONTROL_REG), "i" (DCU_IC)
  792. : "g1");
  793. __cheetah_flush_icache();
  794. /* Restore DCU register */
  795. __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
  796. "membar #Sync"
  797. : /* no outputs */
  798. : "r" (dcu_save), "i" (ASI_DCU_CONTROL_REG));
  799. }
  800. static void cheetah_flush_dcache(void)
  801. {
  802. unsigned long i;
  803. for (i = 0; i < (1 << 16); i += (1 << 5)) {
  804. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  805. "membar #Sync"
  806. : /* no outputs */
  807. : "r" (i), "i" (ASI_DCACHE_TAG));
  808. }
  809. }
  810. /* In order to make the even parity correct we must do two things.
  811. * First, we clear DC_data_parity and set DC_utag to an appropriate value.
  812. * Next, we clear out all 32-bytes of data for that line. Data of
  813. * all-zero + tag parity value of zero == correct parity.
  814. */
  815. static void cheetah_plus_zap_dcache_parity(void)
  816. {
  817. unsigned long i;
  818. for (i = 0; i < (1 << 16); i += (1 << 5)) {
  819. unsigned long tag = (i >> 14);
  820. unsigned long j;
  821. __asm__ __volatile__("membar #Sync\n\t"
  822. "stxa %0, [%1] %2\n\t"
  823. "membar #Sync"
  824. : /* no outputs */
  825. : "r" (tag), "r" (i),
  826. "i" (ASI_DCACHE_UTAG));
  827. for (j = i; j < i + (1 << 5); j += (1 << 3))
  828. __asm__ __volatile__("membar #Sync\n\t"
  829. "stxa %%g0, [%0] %1\n\t"
  830. "membar #Sync"
  831. : /* no outputs */
  832. : "r" (j), "i" (ASI_DCACHE_DATA));
  833. }
  834. }
  835. /* Conversion tables used to frob Cheetah AFSR syndrome values into
  836. * something palatable to the memory controller driver get_unumber
  837. * routine.
  838. */
  839. #define MT0 137
  840. #define MT1 138
  841. #define MT2 139
  842. #define NONE 254
  843. #define MTC0 140
  844. #define MTC1 141
  845. #define MTC2 142
  846. #define MTC3 143
  847. #define C0 128
  848. #define C1 129
  849. #define C2 130
  850. #define C3 131
  851. #define C4 132
  852. #define C5 133
  853. #define C6 134
  854. #define C7 135
  855. #define C8 136
  856. #define M2 144
  857. #define M3 145
  858. #define M4 146
  859. #define M 147
  860. static unsigned char cheetah_ecc_syntab[] = {
  861. /*00*/NONE, C0, C1, M2, C2, M2, M3, 47, C3, M2, M2, 53, M2, 41, 29, M,
  862. /*01*/C4, M, M, 50, M2, 38, 25, M2, M2, 33, 24, M2, 11, M, M2, 16,
  863. /*02*/C5, M, M, 46, M2, 37, 19, M2, M, 31, 32, M, 7, M2, M2, 10,
  864. /*03*/M2, 40, 13, M2, 59, M, M2, 66, M, M2, M2, 0, M2, 67, 71, M,
  865. /*04*/C6, M, M, 43, M, 36, 18, M, M2, 49, 15, M, 63, M2, M2, 6,
  866. /*05*/M2, 44, 28, M2, M, M2, M2, 52, 68, M2, M2, 62, M2, M3, M3, M4,
  867. /*06*/M2, 26, 106, M2, 64, M, M2, 2, 120, M, M2, M3, M, M3, M3, M4,
  868. /*07*/116, M2, M2, M3, M2, M3, M, M4, M2, 58, 54, M2, M, M4, M4, M3,
  869. /*08*/C7, M2, M, 42, M, 35, 17, M2, M, 45, 14, M2, 21, M2, M2, 5,
  870. /*09*/M, 27, M, M, 99, M, M, 3, 114, M2, M2, 20, M2, M3, M3, M,
  871. /*0a*/M2, 23, 113, M2, 112, M2, M, 51, 95, M, M2, M3, M2, M3, M3, M2,
  872. /*0b*/103, M, M2, M3, M2, M3, M3, M4, M2, 48, M, M, 73, M2, M, M3,
  873. /*0c*/M2, 22, 110, M2, 109, M2, M, 9, 108, M2, M, M3, M2, M3, M3, M,
  874. /*0d*/102, M2, M, M, M2, M3, M3, M, M2, M3, M3, M2, M, M4, M, M3,
  875. /*0e*/98, M, M2, M3, M2, M, M3, M4, M2, M3, M3, M4, M3, M, M, M,
  876. /*0f*/M2, M3, M3, M, M3, M, M, M, 56, M4, M, M3, M4, M, M, M,
  877. /*10*/C8, M, M2, 39, M, 34, 105, M2, M, 30, 104, M, 101, M, M, 4,
  878. /*11*/M, M, 100, M, 83, M, M2, 12, 87, M, M, 57, M2, M, M3, M,
  879. /*12*/M2, 97, 82, M2, 78, M2, M2, 1, 96, M, M, M, M, M, M3, M2,
  880. /*13*/94, M, M2, M3, M2, M, M3, M, M2, M, 79, M, 69, M, M4, M,
  881. /*14*/M2, 93, 92, M, 91, M, M2, 8, 90, M2, M2, M, M, M, M, M4,
  882. /*15*/89, M, M, M3, M2, M3, M3, M, M, M, M3, M2, M3, M2, M, M3,
  883. /*16*/86, M, M2, M3, M2, M, M3, M, M2, M, M3, M, M3, M, M, M3,
  884. /*17*/M, M, M3, M2, M3, M2, M4, M, 60, M, M2, M3, M4, M, M, M2,
  885. /*18*/M2, 88, 85, M2, 84, M, M2, 55, 81, M2, M2, M3, M2, M3, M3, M4,
  886. /*19*/77, M, M, M, M2, M3, M, M, M2, M3, M3, M4, M3, M2, M, M,
  887. /*1a*/74, M, M2, M3, M, M, M3, M, M, M, M3, M, M3, M, M4, M3,
  888. /*1b*/M2, 70, 107, M4, 65, M2, M2, M, 127, M, M, M, M2, M3, M3, M,
  889. /*1c*/80, M2, M2, 72, M, 119, 118, M, M2, 126, 76, M, 125, M, M4, M3,
  890. /*1d*/M2, 115, 124, M, 75, M, M, M3, 61, M, M4, M, M4, M, M, M,
  891. /*1e*/M, 123, 122, M4, 121, M4, M, M3, 117, M2, M2, M3, M4, M3, M, M,
  892. /*1f*/111, M, M, M, M4, M3, M3, M, M, M, M3, M, M3, M2, M, M
  893. };
  894. static unsigned char cheetah_mtag_syntab[] = {
  895. NONE, MTC0,
  896. MTC1, NONE,
  897. MTC2, NONE,
  898. NONE, MT0,
  899. MTC3, NONE,
  900. NONE, MT1,
  901. NONE, MT2,
  902. NONE, NONE
  903. };
  904. /* Return the highest priority error conditon mentioned. */
  905. static __inline__ unsigned long cheetah_get_hipri(unsigned long afsr)
  906. {
  907. unsigned long tmp = 0;
  908. int i;
  909. for (i = 0; cheetah_error_table[i].mask; i++) {
  910. if ((tmp = (afsr & cheetah_error_table[i].mask)) != 0UL)
  911. return tmp;
  912. }
  913. return tmp;
  914. }
  915. static const char *cheetah_get_string(unsigned long bit)
  916. {
  917. int i;
  918. for (i = 0; cheetah_error_table[i].mask; i++) {
  919. if ((bit & cheetah_error_table[i].mask) != 0UL)
  920. return cheetah_error_table[i].name;
  921. }
  922. return "???";
  923. }
  924. extern int chmc_getunumber(int, unsigned long, char *, int);
  925. static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *info,
  926. unsigned long afsr, unsigned long afar, int recoverable)
  927. {
  928. unsigned long hipri;
  929. char unum[256];
  930. printk("%s" "ERROR(%d): Cheetah error trap taken afsr[%016lx] afar[%016lx] TL1(%d)\n",
  931. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  932. afsr, afar,
  933. (afsr & CHAFSR_TL1) ? 1 : 0);
  934. printk("%s" "ERROR(%d): TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
  935. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  936. regs->tpc, regs->tnpc, regs->tstate);
  937. printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
  938. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  939. (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
  940. (afsr & CHAFSR_E_SYNDROME) >> CHAFSR_E_SYNDROME_SHIFT,
  941. (afsr & CHAFSR_ME) ? ", Multiple Errors" : "",
  942. (afsr & CHAFSR_PRIV) ? ", Privileged" : "");
  943. hipri = cheetah_get_hipri(afsr);
  944. printk("%s" "ERROR(%d): Highest priority error (%016lx) \"%s\"\n",
  945. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  946. hipri, cheetah_get_string(hipri));
  947. /* Try to get unumber if relevant. */
  948. #define ESYND_ERRORS (CHAFSR_IVC | CHAFSR_IVU | \
  949. CHAFSR_CPC | CHAFSR_CPU | \
  950. CHAFSR_UE | CHAFSR_CE | \
  951. CHAFSR_EDC | CHAFSR_EDU | \
  952. CHAFSR_UCC | CHAFSR_UCU | \
  953. CHAFSR_WDU | CHAFSR_WDC)
  954. #define MSYND_ERRORS (CHAFSR_EMC | CHAFSR_EMU)
  955. if (afsr & ESYND_ERRORS) {
  956. int syndrome;
  957. int ret;
  958. syndrome = (afsr & CHAFSR_E_SYNDROME) >> CHAFSR_E_SYNDROME_SHIFT;
  959. syndrome = cheetah_ecc_syntab[syndrome];
  960. ret = chmc_getunumber(syndrome, afar, unum, sizeof(unum));
  961. if (ret != -1)
  962. printk("%s" "ERROR(%d): AFAR E-syndrome [%s]\n",
  963. (recoverable ? KERN_WARNING : KERN_CRIT),
  964. smp_processor_id(), unum);
  965. } else if (afsr & MSYND_ERRORS) {
  966. int syndrome;
  967. int ret;
  968. syndrome = (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT;
  969. syndrome = cheetah_mtag_syntab[syndrome];
  970. ret = chmc_getunumber(syndrome, afar, unum, sizeof(unum));
  971. if (ret != -1)
  972. printk("%s" "ERROR(%d): AFAR M-syndrome [%s]\n",
  973. (recoverable ? KERN_WARNING : KERN_CRIT),
  974. smp_processor_id(), unum);
  975. }
  976. /* Now dump the cache snapshots. */
  977. printk("%s" "ERROR(%d): D-cache idx[%x] tag[%016lx] utag[%016lx] stag[%016lx]\n",
  978. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  979. (int) info->dcache_index,
  980. info->dcache_tag,
  981. info->dcache_utag,
  982. info->dcache_stag);
  983. printk("%s" "ERROR(%d): D-cache data0[%016lx] data1[%016lx] data2[%016lx] data3[%016lx]\n",
  984. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  985. info->dcache_data[0],
  986. info->dcache_data[1],
  987. info->dcache_data[2],
  988. info->dcache_data[3]);
  989. printk("%s" "ERROR(%d): I-cache idx[%x] tag[%016lx] utag[%016lx] stag[%016lx] "
  990. "u[%016lx] l[%016lx]\n",
  991. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  992. (int) info->icache_index,
  993. info->icache_tag,
  994. info->icache_utag,
  995. info->icache_stag,
  996. info->icache_upper,
  997. info->icache_lower);
  998. printk("%s" "ERROR(%d): I-cache INSN0[%016lx] INSN1[%016lx] INSN2[%016lx] INSN3[%016lx]\n",
  999. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1000. info->icache_data[0],
  1001. info->icache_data[1],
  1002. info->icache_data[2],
  1003. info->icache_data[3]);
  1004. printk("%s" "ERROR(%d): I-cache INSN4[%016lx] INSN5[%016lx] INSN6[%016lx] INSN7[%016lx]\n",
  1005. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1006. info->icache_data[4],
  1007. info->icache_data[5],
  1008. info->icache_data[6],
  1009. info->icache_data[7]);
  1010. printk("%s" "ERROR(%d): E-cache idx[%x] tag[%016lx]\n",
  1011. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1012. (int) info->ecache_index, info->ecache_tag);
  1013. printk("%s" "ERROR(%d): E-cache data0[%016lx] data1[%016lx] data2[%016lx] data3[%016lx]\n",
  1014. (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
  1015. info->ecache_data[0],
  1016. info->ecache_data[1],
  1017. info->ecache_data[2],
  1018. info->ecache_data[3]);
  1019. afsr = (afsr & ~hipri) & cheetah_afsr_errors;
  1020. while (afsr != 0UL) {
  1021. unsigned long bit = cheetah_get_hipri(afsr);
  1022. printk("%s" "ERROR: Multiple-error (%016lx) \"%s\"\n",
  1023. (recoverable ? KERN_WARNING : KERN_CRIT),
  1024. bit, cheetah_get_string(bit));
  1025. afsr &= ~bit;
  1026. }
  1027. if (!recoverable)
  1028. printk(KERN_CRIT "ERROR: This condition is not recoverable.\n");
  1029. }
  1030. static int cheetah_recheck_errors(struct cheetah_err_info *logp)
  1031. {
  1032. unsigned long afsr, afar;
  1033. int ret = 0;
  1034. __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
  1035. : "=r" (afsr)
  1036. : "i" (ASI_AFSR));
  1037. if ((afsr & cheetah_afsr_errors) != 0) {
  1038. if (logp != NULL) {
  1039. __asm__ __volatile__("ldxa [%%g0] %1, %0\n\t"
  1040. : "=r" (afar)
  1041. : "i" (ASI_AFAR));
  1042. logp->afsr = afsr;
  1043. logp->afar = afar;
  1044. }
  1045. ret = 1;
  1046. }
  1047. __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
  1048. "membar #Sync\n\t"
  1049. : : "r" (afsr), "i" (ASI_AFSR));
  1050. return ret;
  1051. }
  1052. void cheetah_fecc_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
  1053. {
  1054. struct cheetah_err_info local_snapshot, *p;
  1055. int recoverable;
  1056. /* Flush E-cache */
  1057. cheetah_flush_ecache();
  1058. p = cheetah_get_error_log(afsr);
  1059. if (!p) {
  1060. prom_printf("ERROR: Early Fast-ECC error afsr[%016lx] afar[%016lx]\n",
  1061. afsr, afar);
  1062. prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
  1063. smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
  1064. prom_halt();
  1065. }
  1066. /* Grab snapshot of logged error. */
  1067. memcpy(&local_snapshot, p, sizeof(local_snapshot));
  1068. /* If the current trap snapshot does not match what the
  1069. * trap handler passed along into our args, big trouble.
  1070. * In such a case, mark the local copy as invalid.
  1071. *
  1072. * Else, it matches and we mark the afsr in the non-local
  1073. * copy as invalid so we may log new error traps there.
  1074. */
  1075. if (p->afsr != afsr || p->afar != afar)
  1076. local_snapshot.afsr = CHAFSR_INVALID;
  1077. else
  1078. p->afsr = CHAFSR_INVALID;
  1079. cheetah_flush_icache();
  1080. cheetah_flush_dcache();
  1081. /* Re-enable I-cache/D-cache */
  1082. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1083. "or %%g1, %1, %%g1\n\t"
  1084. "stxa %%g1, [%%g0] %0\n\t"
  1085. "membar #Sync"
  1086. : /* no outputs */
  1087. : "i" (ASI_DCU_CONTROL_REG),
  1088. "i" (DCU_DC | DCU_IC)
  1089. : "g1");
  1090. /* Re-enable error reporting */
  1091. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1092. "or %%g1, %1, %%g1\n\t"
  1093. "stxa %%g1, [%%g0] %0\n\t"
  1094. "membar #Sync"
  1095. : /* no outputs */
  1096. : "i" (ASI_ESTATE_ERROR_EN),
  1097. "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
  1098. : "g1");
  1099. /* Decide if we can continue after handling this trap and
  1100. * logging the error.
  1101. */
  1102. recoverable = 1;
  1103. if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
  1104. recoverable = 0;
  1105. /* Re-check AFSR/AFAR. What we are looking for here is whether a new
  1106. * error was logged while we had error reporting traps disabled.
  1107. */
  1108. if (cheetah_recheck_errors(&local_snapshot)) {
  1109. unsigned long new_afsr = local_snapshot.afsr;
  1110. /* If we got a new asynchronous error, die... */
  1111. if (new_afsr & (CHAFSR_EMU | CHAFSR_EDU |
  1112. CHAFSR_WDU | CHAFSR_CPU |
  1113. CHAFSR_IVU | CHAFSR_UE |
  1114. CHAFSR_BERR | CHAFSR_TO))
  1115. recoverable = 0;
  1116. }
  1117. /* Log errors. */
  1118. cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
  1119. if (!recoverable)
  1120. panic("Irrecoverable Fast-ECC error trap.\n");
  1121. /* Flush E-cache to kick the error trap handlers out. */
  1122. cheetah_flush_ecache();
  1123. }
  1124. /* Try to fix a correctable error by pushing the line out from
  1125. * the E-cache. Recheck error reporting registers to see if the
  1126. * problem is intermittent.
  1127. */
  1128. static int cheetah_fix_ce(unsigned long physaddr)
  1129. {
  1130. unsigned long orig_estate;
  1131. unsigned long alias1, alias2;
  1132. int ret;
  1133. /* Make sure correctable error traps are disabled. */
  1134. __asm__ __volatile__("ldxa [%%g0] %2, %0\n\t"
  1135. "andn %0, %1, %%g1\n\t"
  1136. "stxa %%g1, [%%g0] %2\n\t"
  1137. "membar #Sync"
  1138. : "=&r" (orig_estate)
  1139. : "i" (ESTATE_ERROR_CEEN),
  1140. "i" (ASI_ESTATE_ERROR_EN)
  1141. : "g1");
  1142. /* We calculate alias addresses that will force the
  1143. * cache line in question out of the E-cache. Then
  1144. * we bring it back in with an atomic instruction so
  1145. * that we get it in some modified/exclusive state,
  1146. * then we displace it again to try and get proper ECC
  1147. * pushed back into the system.
  1148. */
  1149. physaddr &= ~(8UL - 1UL);
  1150. alias1 = (ecache_flush_physbase +
  1151. (physaddr & ((ecache_flush_size >> 1) - 1)));
  1152. alias2 = alias1 + (ecache_flush_size >> 1);
  1153. __asm__ __volatile__("ldxa [%0] %3, %%g0\n\t"
  1154. "ldxa [%1] %3, %%g0\n\t"
  1155. "casxa [%2] %3, %%g0, %%g0\n\t"
  1156. "membar #StoreLoad | #StoreStore\n\t"
  1157. "ldxa [%0] %3, %%g0\n\t"
  1158. "ldxa [%1] %3, %%g0\n\t"
  1159. "membar #Sync"
  1160. : /* no outputs */
  1161. : "r" (alias1), "r" (alias2),
  1162. "r" (physaddr), "i" (ASI_PHYS_USE_EC));
  1163. /* Did that trigger another error? */
  1164. if (cheetah_recheck_errors(NULL)) {
  1165. /* Try one more time. */
  1166. __asm__ __volatile__("ldxa [%0] %1, %%g0\n\t"
  1167. "membar #Sync"
  1168. : : "r" (physaddr), "i" (ASI_PHYS_USE_EC));
  1169. if (cheetah_recheck_errors(NULL))
  1170. ret = 2;
  1171. else
  1172. ret = 1;
  1173. } else {
  1174. /* No new error, intermittent problem. */
  1175. ret = 0;
  1176. }
  1177. /* Restore error enables. */
  1178. __asm__ __volatile__("stxa %0, [%%g0] %1\n\t"
  1179. "membar #Sync"
  1180. : : "r" (orig_estate), "i" (ASI_ESTATE_ERROR_EN));
  1181. return ret;
  1182. }
  1183. /* Return non-zero if PADDR is a valid physical memory address. */
  1184. static int cheetah_check_main_memory(unsigned long paddr)
  1185. {
  1186. int i;
  1187. for (i = 0; ; i++) {
  1188. if (sp_banks[i].num_bytes == 0)
  1189. break;
  1190. if (paddr >= sp_banks[i].base_addr &&
  1191. paddr < (sp_banks[i].base_addr + sp_banks[i].num_bytes))
  1192. return 1;
  1193. }
  1194. return 0;
  1195. }
  1196. void cheetah_cee_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
  1197. {
  1198. struct cheetah_err_info local_snapshot, *p;
  1199. int recoverable, is_memory;
  1200. p = cheetah_get_error_log(afsr);
  1201. if (!p) {
  1202. prom_printf("ERROR: Early CEE error afsr[%016lx] afar[%016lx]\n",
  1203. afsr, afar);
  1204. prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
  1205. smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
  1206. prom_halt();
  1207. }
  1208. /* Grab snapshot of logged error. */
  1209. memcpy(&local_snapshot, p, sizeof(local_snapshot));
  1210. /* If the current trap snapshot does not match what the
  1211. * trap handler passed along into our args, big trouble.
  1212. * In such a case, mark the local copy as invalid.
  1213. *
  1214. * Else, it matches and we mark the afsr in the non-local
  1215. * copy as invalid so we may log new error traps there.
  1216. */
  1217. if (p->afsr != afsr || p->afar != afar)
  1218. local_snapshot.afsr = CHAFSR_INVALID;
  1219. else
  1220. p->afsr = CHAFSR_INVALID;
  1221. is_memory = cheetah_check_main_memory(afar);
  1222. if (is_memory && (afsr & CHAFSR_CE) != 0UL) {
  1223. /* XXX Might want to log the results of this operation
  1224. * XXX somewhere... -DaveM
  1225. */
  1226. cheetah_fix_ce(afar);
  1227. }
  1228. {
  1229. int flush_all, flush_line;
  1230. flush_all = flush_line = 0;
  1231. if ((afsr & CHAFSR_EDC) != 0UL) {
  1232. if ((afsr & cheetah_afsr_errors) == CHAFSR_EDC)
  1233. flush_line = 1;
  1234. else
  1235. flush_all = 1;
  1236. } else if ((afsr & CHAFSR_CPC) != 0UL) {
  1237. if ((afsr & cheetah_afsr_errors) == CHAFSR_CPC)
  1238. flush_line = 1;
  1239. else
  1240. flush_all = 1;
  1241. }
  1242. /* Trap handler only disabled I-cache, flush it. */
  1243. cheetah_flush_icache();
  1244. /* Re-enable I-cache */
  1245. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1246. "or %%g1, %1, %%g1\n\t"
  1247. "stxa %%g1, [%%g0] %0\n\t"
  1248. "membar #Sync"
  1249. : /* no outputs */
  1250. : "i" (ASI_DCU_CONTROL_REG),
  1251. "i" (DCU_IC)
  1252. : "g1");
  1253. if (flush_all)
  1254. cheetah_flush_ecache();
  1255. else if (flush_line)
  1256. cheetah_flush_ecache_line(afar);
  1257. }
  1258. /* Re-enable error reporting */
  1259. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1260. "or %%g1, %1, %%g1\n\t"
  1261. "stxa %%g1, [%%g0] %0\n\t"
  1262. "membar #Sync"
  1263. : /* no outputs */
  1264. : "i" (ASI_ESTATE_ERROR_EN),
  1265. "i" (ESTATE_ERROR_CEEN)
  1266. : "g1");
  1267. /* Decide if we can continue after handling this trap and
  1268. * logging the error.
  1269. */
  1270. recoverable = 1;
  1271. if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
  1272. recoverable = 0;
  1273. /* Re-check AFSR/AFAR */
  1274. (void) cheetah_recheck_errors(&local_snapshot);
  1275. /* Log errors. */
  1276. cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
  1277. if (!recoverable)
  1278. panic("Irrecoverable Correctable-ECC error trap.\n");
  1279. }
  1280. void cheetah_deferred_handler(struct pt_regs *regs, unsigned long afsr, unsigned long afar)
  1281. {
  1282. struct cheetah_err_info local_snapshot, *p;
  1283. int recoverable, is_memory;
  1284. #ifdef CONFIG_PCI
  1285. /* Check for the special PCI poke sequence. */
  1286. if (pci_poke_in_progress && pci_poke_cpu == smp_processor_id()) {
  1287. cheetah_flush_icache();
  1288. cheetah_flush_dcache();
  1289. /* Re-enable I-cache/D-cache */
  1290. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1291. "or %%g1, %1, %%g1\n\t"
  1292. "stxa %%g1, [%%g0] %0\n\t"
  1293. "membar #Sync"
  1294. : /* no outputs */
  1295. : "i" (ASI_DCU_CONTROL_REG),
  1296. "i" (DCU_DC | DCU_IC)
  1297. : "g1");
  1298. /* Re-enable error reporting */
  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_ESTATE_ERROR_EN),
  1305. "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
  1306. : "g1");
  1307. (void) cheetah_recheck_errors(NULL);
  1308. pci_poke_faulted = 1;
  1309. regs->tpc += 4;
  1310. regs->tnpc = regs->tpc + 4;
  1311. return;
  1312. }
  1313. #endif
  1314. p = cheetah_get_error_log(afsr);
  1315. if (!p) {
  1316. prom_printf("ERROR: Early deferred error afsr[%016lx] afar[%016lx]\n",
  1317. afsr, afar);
  1318. prom_printf("ERROR: CPU(%d) TPC[%016lx] TNPC[%016lx] TSTATE[%016lx]\n",
  1319. smp_processor_id(), regs->tpc, regs->tnpc, regs->tstate);
  1320. prom_halt();
  1321. }
  1322. /* Grab snapshot of logged error. */
  1323. memcpy(&local_snapshot, p, sizeof(local_snapshot));
  1324. /* If the current trap snapshot does not match what the
  1325. * trap handler passed along into our args, big trouble.
  1326. * In such a case, mark the local copy as invalid.
  1327. *
  1328. * Else, it matches and we mark the afsr in the non-local
  1329. * copy as invalid so we may log new error traps there.
  1330. */
  1331. if (p->afsr != afsr || p->afar != afar)
  1332. local_snapshot.afsr = CHAFSR_INVALID;
  1333. else
  1334. p->afsr = CHAFSR_INVALID;
  1335. is_memory = cheetah_check_main_memory(afar);
  1336. {
  1337. int flush_all, flush_line;
  1338. flush_all = flush_line = 0;
  1339. if ((afsr & CHAFSR_EDU) != 0UL) {
  1340. if ((afsr & cheetah_afsr_errors) == CHAFSR_EDU)
  1341. flush_line = 1;
  1342. else
  1343. flush_all = 1;
  1344. } else if ((afsr & CHAFSR_BERR) != 0UL) {
  1345. if ((afsr & cheetah_afsr_errors) == CHAFSR_BERR)
  1346. flush_line = 1;
  1347. else
  1348. flush_all = 1;
  1349. }
  1350. cheetah_flush_icache();
  1351. cheetah_flush_dcache();
  1352. /* Re-enable I/D caches */
  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_DCU_CONTROL_REG),
  1359. "i" (DCU_IC | DCU_DC)
  1360. : "g1");
  1361. if (flush_all)
  1362. cheetah_flush_ecache();
  1363. else if (flush_line)
  1364. cheetah_flush_ecache_line(afar);
  1365. }
  1366. /* Re-enable error reporting */
  1367. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1368. "or %%g1, %1, %%g1\n\t"
  1369. "stxa %%g1, [%%g0] %0\n\t"
  1370. "membar #Sync"
  1371. : /* no outputs */
  1372. : "i" (ASI_ESTATE_ERROR_EN),
  1373. "i" (ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN)
  1374. : "g1");
  1375. /* Decide if we can continue after handling this trap and
  1376. * logging the error.
  1377. */
  1378. recoverable = 1;
  1379. if (afsr & (CHAFSR_PERR | CHAFSR_IERR | CHAFSR_ISAP))
  1380. recoverable = 0;
  1381. /* Re-check AFSR/AFAR. What we are looking for here is whether a new
  1382. * error was logged while we had error reporting traps disabled.
  1383. */
  1384. if (cheetah_recheck_errors(&local_snapshot)) {
  1385. unsigned long new_afsr = local_snapshot.afsr;
  1386. /* If we got a new asynchronous error, die... */
  1387. if (new_afsr & (CHAFSR_EMU | CHAFSR_EDU |
  1388. CHAFSR_WDU | CHAFSR_CPU |
  1389. CHAFSR_IVU | CHAFSR_UE |
  1390. CHAFSR_BERR | CHAFSR_TO))
  1391. recoverable = 0;
  1392. }
  1393. /* Log errors. */
  1394. cheetah_log_errors(regs, &local_snapshot, afsr, afar, recoverable);
  1395. /* "Recoverable" here means we try to yank the page from ever
  1396. * being newly used again. This depends upon a few things:
  1397. * 1) Must be main memory, and AFAR must be valid.
  1398. * 2) If we trapped from user, OK.
  1399. * 3) Else, if we trapped from kernel we must find exception
  1400. * table entry (ie. we have to have been accessing user
  1401. * space).
  1402. *
  1403. * If AFAR is not in main memory, or we trapped from kernel
  1404. * and cannot find an exception table entry, it is unacceptable
  1405. * to try and continue.
  1406. */
  1407. if (recoverable && is_memory) {
  1408. if ((regs->tstate & TSTATE_PRIV) == 0UL) {
  1409. /* OK, usermode access. */
  1410. recoverable = 1;
  1411. } else {
  1412. unsigned long g2 = regs->u_regs[UREG_G2];
  1413. unsigned long fixup = search_extables_range(regs->tpc, &g2);
  1414. if (fixup != 0UL) {
  1415. /* OK, kernel access to userspace. */
  1416. recoverable = 1;
  1417. } else {
  1418. /* BAD, privileged state is corrupted. */
  1419. recoverable = 0;
  1420. }
  1421. if (recoverable) {
  1422. if (pfn_valid(afar >> PAGE_SHIFT))
  1423. get_page(pfn_to_page(afar >> PAGE_SHIFT));
  1424. else
  1425. recoverable = 0;
  1426. /* Only perform fixup if we still have a
  1427. * recoverable condition.
  1428. */
  1429. if (recoverable) {
  1430. regs->tpc = fixup;
  1431. regs->tnpc = regs->tpc + 4;
  1432. regs->u_regs[UREG_G2] = g2;
  1433. }
  1434. }
  1435. }
  1436. } else {
  1437. recoverable = 0;
  1438. }
  1439. if (!recoverable)
  1440. panic("Irrecoverable deferred error trap.\n");
  1441. }
  1442. /* Handle a D/I cache parity error trap. TYPE is encoded as:
  1443. *
  1444. * Bit0: 0=dcache,1=icache
  1445. * Bit1: 0=recoverable,1=unrecoverable
  1446. *
  1447. * The hardware has disabled both the I-cache and D-cache in
  1448. * the %dcr register.
  1449. */
  1450. void cheetah_plus_parity_error(int type, struct pt_regs *regs)
  1451. {
  1452. if (type & 0x1)
  1453. __cheetah_flush_icache();
  1454. else
  1455. cheetah_plus_zap_dcache_parity();
  1456. cheetah_flush_dcache();
  1457. /* Re-enable I-cache/D-cache */
  1458. __asm__ __volatile__("ldxa [%%g0] %0, %%g1\n\t"
  1459. "or %%g1, %1, %%g1\n\t"
  1460. "stxa %%g1, [%%g0] %0\n\t"
  1461. "membar #Sync"
  1462. : /* no outputs */
  1463. : "i" (ASI_DCU_CONTROL_REG),
  1464. "i" (DCU_DC | DCU_IC)
  1465. : "g1");
  1466. if (type & 0x2) {
  1467. printk(KERN_EMERG "CPU[%d]: Cheetah+ %c-cache parity error at TPC[%016lx]\n",
  1468. smp_processor_id(),
  1469. (type & 0x1) ? 'I' : 'D',
  1470. regs->tpc);
  1471. panic("Irrecoverable Cheetah+ parity error.");
  1472. }
  1473. printk(KERN_WARNING "CPU[%d]: Cheetah+ %c-cache parity error at TPC[%016lx]\n",
  1474. smp_processor_id(),
  1475. (type & 0x1) ? 'I' : 'D',
  1476. regs->tpc);
  1477. }
  1478. void do_fpe_common(struct pt_regs *regs)
  1479. {
  1480. if (regs->tstate & TSTATE_PRIV) {
  1481. regs->tpc = regs->tnpc;
  1482. regs->tnpc += 4;
  1483. } else {
  1484. unsigned long fsr = current_thread_info()->xfsr[0];
  1485. siginfo_t info;
  1486. if (test_thread_flag(TIF_32BIT)) {
  1487. regs->tpc &= 0xffffffff;
  1488. regs->tnpc &= 0xffffffff;
  1489. }
  1490. info.si_signo = SIGFPE;
  1491. info.si_errno = 0;
  1492. info.si_addr = (void __user *)regs->tpc;
  1493. info.si_trapno = 0;
  1494. info.si_code = __SI_FAULT;
  1495. if ((fsr & 0x1c000) == (1 << 14)) {
  1496. if (fsr & 0x10)
  1497. info.si_code = FPE_FLTINV;
  1498. else if (fsr & 0x08)
  1499. info.si_code = FPE_FLTOVF;
  1500. else if (fsr & 0x04)
  1501. info.si_code = FPE_FLTUND;
  1502. else if (fsr & 0x02)
  1503. info.si_code = FPE_FLTDIV;
  1504. else if (fsr & 0x01)
  1505. info.si_code = FPE_FLTRES;
  1506. }
  1507. force_sig_info(SIGFPE, &info, current);
  1508. }
  1509. }
  1510. void do_fpieee(struct pt_regs *regs)
  1511. {
  1512. if (notify_die(DIE_TRAP, "fpu exception ieee", regs,
  1513. 0, 0x24, SIGFPE) == NOTIFY_STOP)
  1514. return;
  1515. do_fpe_common(regs);
  1516. }
  1517. extern int do_mathemu(struct pt_regs *, struct fpustate *);
  1518. void do_fpother(struct pt_regs *regs)
  1519. {
  1520. struct fpustate *f = FPUSTATE;
  1521. int ret = 0;
  1522. if (notify_die(DIE_TRAP, "fpu exception other", regs,
  1523. 0, 0x25, SIGFPE) == NOTIFY_STOP)
  1524. return;
  1525. switch ((current_thread_info()->xfsr[0] & 0x1c000)) {
  1526. case (2 << 14): /* unfinished_FPop */
  1527. case (3 << 14): /* unimplemented_FPop */
  1528. ret = do_mathemu(regs, f);
  1529. break;
  1530. }
  1531. if (ret)
  1532. return;
  1533. do_fpe_common(regs);
  1534. }
  1535. void do_tof(struct pt_regs *regs)
  1536. {
  1537. siginfo_t info;
  1538. if (notify_die(DIE_TRAP, "tagged arithmetic overflow", regs,
  1539. 0, 0x26, SIGEMT) == NOTIFY_STOP)
  1540. return;
  1541. if (regs->tstate & TSTATE_PRIV)
  1542. die_if_kernel("Penguin overflow trap from kernel mode", regs);
  1543. if (test_thread_flag(TIF_32BIT)) {
  1544. regs->tpc &= 0xffffffff;
  1545. regs->tnpc &= 0xffffffff;
  1546. }
  1547. info.si_signo = SIGEMT;
  1548. info.si_errno = 0;
  1549. info.si_code = EMT_TAGOVF;
  1550. info.si_addr = (void __user *)regs->tpc;
  1551. info.si_trapno = 0;
  1552. force_sig_info(SIGEMT, &info, current);
  1553. }
  1554. void do_div0(struct pt_regs *regs)
  1555. {
  1556. siginfo_t info;
  1557. if (notify_die(DIE_TRAP, "integer division by zero", regs,
  1558. 0, 0x28, SIGFPE) == NOTIFY_STOP)
  1559. return;
  1560. if (regs->tstate & TSTATE_PRIV)
  1561. die_if_kernel("TL0: Kernel divide by zero.", regs);
  1562. if (test_thread_flag(TIF_32BIT)) {
  1563. regs->tpc &= 0xffffffff;
  1564. regs->tnpc &= 0xffffffff;
  1565. }
  1566. info.si_signo = SIGFPE;
  1567. info.si_errno = 0;
  1568. info.si_code = FPE_INTDIV;
  1569. info.si_addr = (void __user *)regs->tpc;
  1570. info.si_trapno = 0;
  1571. force_sig_info(SIGFPE, &info, current);
  1572. }
  1573. void instruction_dump (unsigned int *pc)
  1574. {
  1575. int i;
  1576. if ((((unsigned long) pc) & 3))
  1577. return;
  1578. printk("Instruction DUMP:");
  1579. for (i = -3; i < 6; i++)
  1580. printk("%c%08x%c",i?' ':'<',pc[i],i?' ':'>');
  1581. printk("\n");
  1582. }
  1583. static void user_instruction_dump (unsigned int __user *pc)
  1584. {
  1585. int i;
  1586. unsigned int buf[9];
  1587. if ((((unsigned long) pc) & 3))
  1588. return;
  1589. if (copy_from_user(buf, pc - 3, sizeof(buf)))
  1590. return;
  1591. printk("Instruction DUMP:");
  1592. for (i = 0; i < 9; i++)
  1593. printk("%c%08x%c",i==3?' ':'<',buf[i],i==3?' ':'>');
  1594. printk("\n");
  1595. }
  1596. void show_stack(struct task_struct *tsk, unsigned long *_ksp)
  1597. {
  1598. unsigned long pc, fp, thread_base, ksp;
  1599. struct thread_info *tp = tsk->thread_info;
  1600. struct reg_window *rw;
  1601. int count = 0;
  1602. ksp = (unsigned long) _ksp;
  1603. if (tp == current_thread_info())
  1604. flushw_all();
  1605. fp = ksp + STACK_BIAS;
  1606. thread_base = (unsigned long) tp;
  1607. printk("Call Trace:");
  1608. #ifdef CONFIG_KALLSYMS
  1609. printk("\n");
  1610. #endif
  1611. do {
  1612. /* Bogus frame pointer? */
  1613. if (fp < (thread_base + sizeof(struct thread_info)) ||
  1614. fp >= (thread_base + THREAD_SIZE))
  1615. break;
  1616. rw = (struct reg_window *)fp;
  1617. pc = rw->ins[7];
  1618. printk(" [%016lx] ", pc);
  1619. print_symbol("%s\n", pc);
  1620. fp = rw->ins[6] + STACK_BIAS;
  1621. } while (++count < 16);
  1622. #ifndef CONFIG_KALLSYMS
  1623. printk("\n");
  1624. #endif
  1625. }
  1626. void dump_stack(void)
  1627. {
  1628. unsigned long *ksp;
  1629. __asm__ __volatile__("mov %%fp, %0"
  1630. : "=r" (ksp));
  1631. show_stack(current, ksp);
  1632. }
  1633. EXPORT_SYMBOL(dump_stack);
  1634. static inline int is_kernel_stack(struct task_struct *task,
  1635. struct reg_window *rw)
  1636. {
  1637. unsigned long rw_addr = (unsigned long) rw;
  1638. unsigned long thread_base, thread_end;
  1639. if (rw_addr < PAGE_OFFSET) {
  1640. if (task != &init_task)
  1641. return 0;
  1642. }
  1643. thread_base = (unsigned long) task->thread_info;
  1644. thread_end = thread_base + sizeof(union thread_union);
  1645. if (rw_addr >= thread_base &&
  1646. rw_addr < thread_end &&
  1647. !(rw_addr & 0x7UL))
  1648. return 1;
  1649. return 0;
  1650. }
  1651. static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
  1652. {
  1653. unsigned long fp = rw->ins[6];
  1654. if (!fp)
  1655. return NULL;
  1656. return (struct reg_window *) (fp + STACK_BIAS);
  1657. }
  1658. void die_if_kernel(char *str, struct pt_regs *regs)
  1659. {
  1660. static int die_counter;
  1661. extern void __show_regs(struct pt_regs * regs);
  1662. extern void smp_report_regs(void);
  1663. int count = 0;
  1664. /* Amuse the user. */
  1665. printk(
  1666. " \\|/ ____ \\|/\n"
  1667. " \"@'/ .. \\`@\"\n"
  1668. " /_| \\__/ |_\\\n"
  1669. " \\__U_/\n");
  1670. printk("%s(%d): %s [#%d]\n", current->comm, current->pid, str, ++die_counter);
  1671. notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
  1672. __asm__ __volatile__("flushw");
  1673. __show_regs(regs);
  1674. if (regs->tstate & TSTATE_PRIV) {
  1675. struct reg_window *rw = (struct reg_window *)
  1676. (regs->u_regs[UREG_FP] + STACK_BIAS);
  1677. /* Stop the back trace when we hit userland or we
  1678. * find some badly aligned kernel stack.
  1679. */
  1680. while (rw &&
  1681. count++ < 30&&
  1682. is_kernel_stack(current, rw)) {
  1683. printk("Caller[%016lx]", rw->ins[7]);
  1684. print_symbol(": %s", rw->ins[7]);
  1685. printk("\n");
  1686. rw = kernel_stack_up(rw);
  1687. }
  1688. instruction_dump ((unsigned int *) regs->tpc);
  1689. } else {
  1690. if (test_thread_flag(TIF_32BIT)) {
  1691. regs->tpc &= 0xffffffff;
  1692. regs->tnpc &= 0xffffffff;
  1693. }
  1694. user_instruction_dump ((unsigned int __user *) regs->tpc);
  1695. }
  1696. #ifdef CONFIG_SMP
  1697. smp_report_regs();
  1698. #endif
  1699. if (regs->tstate & TSTATE_PRIV)
  1700. do_exit(SIGKILL);
  1701. do_exit(SIGSEGV);
  1702. }
  1703. extern int handle_popc(u32 insn, struct pt_regs *regs);
  1704. extern int handle_ldf_stq(u32 insn, struct pt_regs *regs);
  1705. void do_illegal_instruction(struct pt_regs *regs)
  1706. {
  1707. unsigned long pc = regs->tpc;
  1708. unsigned long tstate = regs->tstate;
  1709. u32 insn;
  1710. siginfo_t info;
  1711. if (notify_die(DIE_TRAP, "illegal instruction", regs,
  1712. 0, 0x10, SIGILL) == NOTIFY_STOP)
  1713. return;
  1714. if (tstate & TSTATE_PRIV)
  1715. die_if_kernel("Kernel illegal instruction", regs);
  1716. if (test_thread_flag(TIF_32BIT))
  1717. pc = (u32)pc;
  1718. if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
  1719. if ((insn & 0xc1ffc000) == 0x81700000) /* POPC */ {
  1720. if (handle_popc(insn, regs))
  1721. return;
  1722. } else if ((insn & 0xc1580000) == 0xc1100000) /* LDQ/STQ */ {
  1723. if (handle_ldf_stq(insn, regs))
  1724. return;
  1725. }
  1726. }
  1727. info.si_signo = SIGILL;
  1728. info.si_errno = 0;
  1729. info.si_code = ILL_ILLOPC;
  1730. info.si_addr = (void __user *)pc;
  1731. info.si_trapno = 0;
  1732. force_sig_info(SIGILL, &info, current);
  1733. }
  1734. void mem_address_unaligned(struct pt_regs *regs, unsigned long sfar, unsigned long sfsr)
  1735. {
  1736. siginfo_t info;
  1737. if (notify_die(DIE_TRAP, "memory address unaligned", regs,
  1738. 0, 0x34, SIGSEGV) == NOTIFY_STOP)
  1739. return;
  1740. if (regs->tstate & TSTATE_PRIV) {
  1741. extern void kernel_unaligned_trap(struct pt_regs *regs,
  1742. unsigned int insn,
  1743. unsigned long sfar,
  1744. unsigned long sfsr);
  1745. kernel_unaligned_trap(regs, *((unsigned int *)regs->tpc),
  1746. sfar, sfsr);
  1747. return;
  1748. }
  1749. info.si_signo = SIGBUS;
  1750. info.si_errno = 0;
  1751. info.si_code = BUS_ADRALN;
  1752. info.si_addr = (void __user *)sfar;
  1753. info.si_trapno = 0;
  1754. force_sig_info(SIGBUS, &info, current);
  1755. }
  1756. void do_privop(struct pt_regs *regs)
  1757. {
  1758. siginfo_t info;
  1759. if (notify_die(DIE_TRAP, "privileged operation", regs,
  1760. 0, 0x11, SIGILL) == NOTIFY_STOP)
  1761. return;
  1762. if (test_thread_flag(TIF_32BIT)) {
  1763. regs->tpc &= 0xffffffff;
  1764. regs->tnpc &= 0xffffffff;
  1765. }
  1766. info.si_signo = SIGILL;
  1767. info.si_errno = 0;
  1768. info.si_code = ILL_PRVOPC;
  1769. info.si_addr = (void __user *)regs->tpc;
  1770. info.si_trapno = 0;
  1771. force_sig_info(SIGILL, &info, current);
  1772. }
  1773. void do_privact(struct pt_regs *regs)
  1774. {
  1775. do_privop(regs);
  1776. }
  1777. /* Trap level 1 stuff or other traps we should never see... */
  1778. void do_cee(struct pt_regs *regs)
  1779. {
  1780. die_if_kernel("TL0: Cache Error Exception", regs);
  1781. }
  1782. void do_cee_tl1(struct pt_regs *regs)
  1783. {
  1784. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1785. die_if_kernel("TL1: Cache Error Exception", regs);
  1786. }
  1787. void do_dae_tl1(struct pt_regs *regs)
  1788. {
  1789. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1790. die_if_kernel("TL1: Data Access Exception", regs);
  1791. }
  1792. void do_iae_tl1(struct pt_regs *regs)
  1793. {
  1794. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1795. die_if_kernel("TL1: Instruction Access Exception", regs);
  1796. }
  1797. void do_div0_tl1(struct pt_regs *regs)
  1798. {
  1799. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1800. die_if_kernel("TL1: DIV0 Exception", regs);
  1801. }
  1802. void do_fpdis_tl1(struct pt_regs *regs)
  1803. {
  1804. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1805. die_if_kernel("TL1: FPU Disabled", regs);
  1806. }
  1807. void do_fpieee_tl1(struct pt_regs *regs)
  1808. {
  1809. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1810. die_if_kernel("TL1: FPU IEEE Exception", regs);
  1811. }
  1812. void do_fpother_tl1(struct pt_regs *regs)
  1813. {
  1814. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1815. die_if_kernel("TL1: FPU Other Exception", regs);
  1816. }
  1817. void do_ill_tl1(struct pt_regs *regs)
  1818. {
  1819. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1820. die_if_kernel("TL1: Illegal Instruction Exception", regs);
  1821. }
  1822. void do_irq_tl1(struct pt_regs *regs)
  1823. {
  1824. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1825. die_if_kernel("TL1: IRQ Exception", regs);
  1826. }
  1827. void do_lddfmna_tl1(struct pt_regs *regs)
  1828. {
  1829. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1830. die_if_kernel("TL1: LDDF Exception", regs);
  1831. }
  1832. void do_stdfmna_tl1(struct pt_regs *regs)
  1833. {
  1834. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1835. die_if_kernel("TL1: STDF Exception", regs);
  1836. }
  1837. void do_paw(struct pt_regs *regs)
  1838. {
  1839. die_if_kernel("TL0: Phys Watchpoint Exception", regs);
  1840. }
  1841. void do_paw_tl1(struct pt_regs *regs)
  1842. {
  1843. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1844. die_if_kernel("TL1: Phys Watchpoint Exception", regs);
  1845. }
  1846. void do_vaw(struct pt_regs *regs)
  1847. {
  1848. die_if_kernel("TL0: Virt Watchpoint Exception", regs);
  1849. }
  1850. void do_vaw_tl1(struct pt_regs *regs)
  1851. {
  1852. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1853. die_if_kernel("TL1: Virt Watchpoint Exception", regs);
  1854. }
  1855. void do_tof_tl1(struct pt_regs *regs)
  1856. {
  1857. dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
  1858. die_if_kernel("TL1: Tag Overflow Exception", regs);
  1859. }
  1860. void do_getpsr(struct pt_regs *regs)
  1861. {
  1862. regs->u_regs[UREG_I0] = tstate_to_psr(regs->tstate);
  1863. regs->tpc = regs->tnpc;
  1864. regs->tnpc += 4;
  1865. if (test_thread_flag(TIF_32BIT)) {
  1866. regs->tpc &= 0xffffffff;
  1867. regs->tnpc &= 0xffffffff;
  1868. }
  1869. }
  1870. extern void thread_info_offsets_are_bolixed_dave(void);
  1871. /* Only invoked on boot processor. */
  1872. void __init trap_init(void)
  1873. {
  1874. /* Compile time sanity check. */
  1875. if (TI_TASK != offsetof(struct thread_info, task) ||
  1876. TI_FLAGS != offsetof(struct thread_info, flags) ||
  1877. TI_CPU != offsetof(struct thread_info, cpu) ||
  1878. TI_FPSAVED != offsetof(struct thread_info, fpsaved) ||
  1879. TI_KSP != offsetof(struct thread_info, ksp) ||
  1880. TI_FAULT_ADDR != offsetof(struct thread_info, fault_address) ||
  1881. TI_KREGS != offsetof(struct thread_info, kregs) ||
  1882. TI_UTRAPS != offsetof(struct thread_info, utraps) ||
  1883. TI_EXEC_DOMAIN != offsetof(struct thread_info, exec_domain) ||
  1884. TI_REG_WINDOW != offsetof(struct thread_info, reg_window) ||
  1885. TI_RWIN_SPTRS != offsetof(struct thread_info, rwbuf_stkptrs) ||
  1886. TI_GSR != offsetof(struct thread_info, gsr) ||
  1887. TI_XFSR != offsetof(struct thread_info, xfsr) ||
  1888. TI_USER_CNTD0 != offsetof(struct thread_info, user_cntd0) ||
  1889. TI_USER_CNTD1 != offsetof(struct thread_info, user_cntd1) ||
  1890. TI_KERN_CNTD0 != offsetof(struct thread_info, kernel_cntd0) ||
  1891. TI_KERN_CNTD1 != offsetof(struct thread_info, kernel_cntd1) ||
  1892. TI_PCR != offsetof(struct thread_info, pcr_reg) ||
  1893. TI_CEE_STUFF != offsetof(struct thread_info, cee_stuff) ||
  1894. TI_PRE_COUNT != offsetof(struct thread_info, preempt_count) ||
  1895. TI_NEW_CHILD != offsetof(struct thread_info, new_child) ||
  1896. TI_SYS_NOERROR != offsetof(struct thread_info, syscall_noerror) ||
  1897. TI_RESTART_BLOCK != offsetof(struct thread_info, restart_block) ||
  1898. TI_KUNA_REGS != offsetof(struct thread_info, kern_una_regs) ||
  1899. TI_KUNA_INSN != offsetof(struct thread_info, kern_una_insn) ||
  1900. TI_FPREGS != offsetof(struct thread_info, fpregs) ||
  1901. (TI_FPREGS & (64 - 1)))
  1902. thread_info_offsets_are_bolixed_dave();
  1903. /* Attach to the address space of init_task. On SMP we
  1904. * do this in smp.c:smp_callin for other cpus.
  1905. */
  1906. atomic_inc(&init_mm.mm_count);
  1907. current->active_mm = &init_mm;
  1908. }