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