traps.c 62 KB

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