traps_64.c 82 KB

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