traps_64.c 80 KB

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