traps_64.c 75 KB

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