traps_64.c 84 KB

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