traps_64.c 75 KB

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