traps_64.c 79 KB

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