traps_64.c 78 KB

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