traps.c 61 KB

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