traps_64.c 84 KB

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