traps.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 - 1999, 2000, 01, 06 Ralf Baechle
  7. * Copyright (C) 1995, 1996 Paul M. Antoine
  8. * Copyright (C) 1998 Ulf Carlsson
  9. * Copyright (C) 1999 Silicon Graphics, Inc.
  10. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  11. * Copyright (C) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
  12. * Copyright (C) 2000, 2001, 2012 MIPS Technologies, Inc. All rights reserved.
  13. * Copyright (C) 2014, Imagination Technologies Ltd.
  14. */
  15. #include <linux/bitops.h>
  16. #include <linux/bug.h>
  17. #include <linux/compiler.h>
  18. #include <linux/context_tracking.h>
  19. #include <linux/cpu_pm.h>
  20. #include <linux/kexec.h>
  21. #include <linux/init.h>
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/extable.h>
  25. #include <linux/mm.h>
  26. #include <linux/sched/mm.h>
  27. #include <linux/sched/debug.h>
  28. #include <linux/smp.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/kallsyms.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/ptrace.h>
  34. #include <linux/kgdb.h>
  35. #include <linux/kdebug.h>
  36. #include <linux/kprobes.h>
  37. #include <linux/notifier.h>
  38. #include <linux/kdb.h>
  39. #include <linux/irq.h>
  40. #include <linux/perf_event.h>
  41. #include <asm/addrspace.h>
  42. #include <asm/bootinfo.h>
  43. #include <asm/branch.h>
  44. #include <asm/break.h>
  45. #include <asm/cop2.h>
  46. #include <asm/cpu.h>
  47. #include <asm/cpu-type.h>
  48. #include <asm/dsp.h>
  49. #include <asm/fpu.h>
  50. #include <asm/fpu_emulator.h>
  51. #include <asm/idle.h>
  52. #include <asm/mips-cm.h>
  53. #include <asm/mips-r2-to-r6-emul.h>
  54. #include <asm/mips-cm.h>
  55. #include <asm/mipsregs.h>
  56. #include <asm/mipsmtregs.h>
  57. #include <asm/module.h>
  58. #include <asm/msa.h>
  59. #include <asm/pgtable.h>
  60. #include <asm/ptrace.h>
  61. #include <asm/sections.h>
  62. #include <asm/siginfo.h>
  63. #include <asm/tlbdebug.h>
  64. #include <asm/traps.h>
  65. #include <linux/uaccess.h>
  66. #include <asm/watch.h>
  67. #include <asm/mmu_context.h>
  68. #include <asm/types.h>
  69. #include <asm/stacktrace.h>
  70. #include <asm/uasm.h>
  71. extern void check_wait(void);
  72. extern asmlinkage void rollback_handle_int(void);
  73. extern asmlinkage void handle_int(void);
  74. extern u32 handle_tlbl[];
  75. extern u32 handle_tlbs[];
  76. extern u32 handle_tlbm[];
  77. extern asmlinkage void handle_adel(void);
  78. extern asmlinkage void handle_ades(void);
  79. extern asmlinkage void handle_ibe(void);
  80. extern asmlinkage void handle_dbe(void);
  81. extern asmlinkage void handle_sys(void);
  82. extern asmlinkage void handle_bp(void);
  83. extern asmlinkage void handle_ri(void);
  84. extern asmlinkage void handle_ri_rdhwr_tlbp(void);
  85. extern asmlinkage void handle_ri_rdhwr(void);
  86. extern asmlinkage void handle_cpu(void);
  87. extern asmlinkage void handle_ov(void);
  88. extern asmlinkage void handle_tr(void);
  89. extern asmlinkage void handle_msa_fpe(void);
  90. extern asmlinkage void handle_fpe(void);
  91. extern asmlinkage void handle_ftlb(void);
  92. extern asmlinkage void handle_msa(void);
  93. extern asmlinkage void handle_mdmx(void);
  94. extern asmlinkage void handle_watch(void);
  95. extern asmlinkage void handle_mt(void);
  96. extern asmlinkage void handle_dsp(void);
  97. extern asmlinkage void handle_mcheck(void);
  98. extern asmlinkage void handle_reserved(void);
  99. extern void tlb_do_page_fault_0(void);
  100. void (*board_be_init)(void);
  101. int (*board_be_handler)(struct pt_regs *regs, int is_fixup);
  102. void (*board_nmi_handler_setup)(void);
  103. void (*board_ejtag_handler_setup)(void);
  104. void (*board_bind_eic_interrupt)(int irq, int regset);
  105. void (*board_ebase_setup)(void);
  106. void(*board_cache_error_setup)(void);
  107. static void show_raw_backtrace(unsigned long reg29)
  108. {
  109. unsigned long *sp = (unsigned long *)(reg29 & ~3);
  110. unsigned long addr;
  111. printk("Call Trace:");
  112. #ifdef CONFIG_KALLSYMS
  113. printk("\n");
  114. #endif
  115. while (!kstack_end(sp)) {
  116. unsigned long __user *p =
  117. (unsigned long __user *)(unsigned long)sp++;
  118. if (__get_user(addr, p)) {
  119. printk(" (Bad stack address)");
  120. break;
  121. }
  122. if (__kernel_text_address(addr))
  123. print_ip_sym(addr);
  124. }
  125. printk("\n");
  126. }
  127. #ifdef CONFIG_KALLSYMS
  128. int raw_show_trace;
  129. static int __init set_raw_show_trace(char *str)
  130. {
  131. raw_show_trace = 1;
  132. return 1;
  133. }
  134. __setup("raw_show_trace", set_raw_show_trace);
  135. #endif
  136. static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
  137. {
  138. unsigned long sp = regs->regs[29];
  139. unsigned long ra = regs->regs[31];
  140. unsigned long pc = regs->cp0_epc;
  141. if (!task)
  142. task = current;
  143. if (raw_show_trace || user_mode(regs) || !__kernel_text_address(pc)) {
  144. show_raw_backtrace(sp);
  145. return;
  146. }
  147. printk("Call Trace:\n");
  148. do {
  149. print_ip_sym(pc);
  150. pc = unwind_stack(task, &sp, pc, &ra);
  151. } while (pc);
  152. pr_cont("\n");
  153. }
  154. /*
  155. * This routine abuses get_user()/put_user() to reference pointers
  156. * with at least a bit of error checking ...
  157. */
  158. static void show_stacktrace(struct task_struct *task,
  159. const struct pt_regs *regs)
  160. {
  161. const int field = 2 * sizeof(unsigned long);
  162. long stackdata;
  163. int i;
  164. unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
  165. printk("Stack :");
  166. i = 0;
  167. while ((unsigned long) sp & (PAGE_SIZE - 1)) {
  168. if (i && ((i % (64 / field)) == 0)) {
  169. pr_cont("\n");
  170. printk(" ");
  171. }
  172. if (i > 39) {
  173. pr_cont(" ...");
  174. break;
  175. }
  176. if (__get_user(stackdata, sp++)) {
  177. pr_cont(" (Bad stack address)");
  178. break;
  179. }
  180. pr_cont(" %0*lx", field, stackdata);
  181. i++;
  182. }
  183. pr_cont("\n");
  184. show_backtrace(task, regs);
  185. }
  186. void show_stack(struct task_struct *task, unsigned long *sp)
  187. {
  188. struct pt_regs regs;
  189. mm_segment_t old_fs = get_fs();
  190. regs.cp0_status = KSU_KERNEL;
  191. if (sp) {
  192. regs.regs[29] = (unsigned long)sp;
  193. regs.regs[31] = 0;
  194. regs.cp0_epc = 0;
  195. } else {
  196. if (task && task != current) {
  197. regs.regs[29] = task->thread.reg29;
  198. regs.regs[31] = 0;
  199. regs.cp0_epc = task->thread.reg31;
  200. #ifdef CONFIG_KGDB_KDB
  201. } else if (atomic_read(&kgdb_active) != -1 &&
  202. kdb_current_regs) {
  203. memcpy(&regs, kdb_current_regs, sizeof(regs));
  204. #endif /* CONFIG_KGDB_KDB */
  205. } else {
  206. prepare_frametrace(&regs);
  207. }
  208. }
  209. /*
  210. * show_stack() deals exclusively with kernel mode, so be sure to access
  211. * the stack in the kernel (not user) address space.
  212. */
  213. set_fs(KERNEL_DS);
  214. show_stacktrace(task, &regs);
  215. set_fs(old_fs);
  216. }
  217. static void show_code(unsigned int __user *pc)
  218. {
  219. long i;
  220. unsigned short __user *pc16 = NULL;
  221. printk("Code:");
  222. if ((unsigned long)pc & 1)
  223. pc16 = (unsigned short __user *)((unsigned long)pc & ~1);
  224. for(i = -3 ; i < 6 ; i++) {
  225. unsigned int insn;
  226. if (pc16 ? __get_user(insn, pc16 + i) : __get_user(insn, pc + i)) {
  227. pr_cont(" (Bad address in epc)\n");
  228. break;
  229. }
  230. pr_cont("%c%0*x%c", (i?' ':'<'), pc16 ? 4 : 8, insn, (i?' ':'>'));
  231. }
  232. pr_cont("\n");
  233. }
  234. static void __show_regs(const struct pt_regs *regs)
  235. {
  236. const int field = 2 * sizeof(unsigned long);
  237. unsigned int cause = regs->cp0_cause;
  238. unsigned int exccode;
  239. int i;
  240. show_regs_print_info(KERN_DEFAULT);
  241. /*
  242. * Saved main processor registers
  243. */
  244. for (i = 0; i < 32; ) {
  245. if ((i % 4) == 0)
  246. printk("$%2d :", i);
  247. if (i == 0)
  248. pr_cont(" %0*lx", field, 0UL);
  249. else if (i == 26 || i == 27)
  250. pr_cont(" %*s", field, "");
  251. else
  252. pr_cont(" %0*lx", field, regs->regs[i]);
  253. i++;
  254. if ((i % 4) == 0)
  255. pr_cont("\n");
  256. }
  257. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  258. printk("Acx : %0*lx\n", field, regs->acx);
  259. #endif
  260. printk("Hi : %0*lx\n", field, regs->hi);
  261. printk("Lo : %0*lx\n", field, regs->lo);
  262. /*
  263. * Saved cp0 registers
  264. */
  265. printk("epc : %0*lx %pS\n", field, regs->cp0_epc,
  266. (void *) regs->cp0_epc);
  267. printk("ra : %0*lx %pS\n", field, regs->regs[31],
  268. (void *) regs->regs[31]);
  269. printk("Status: %08x ", (uint32_t) regs->cp0_status);
  270. if (cpu_has_3kex) {
  271. if (regs->cp0_status & ST0_KUO)
  272. pr_cont("KUo ");
  273. if (regs->cp0_status & ST0_IEO)
  274. pr_cont("IEo ");
  275. if (regs->cp0_status & ST0_KUP)
  276. pr_cont("KUp ");
  277. if (regs->cp0_status & ST0_IEP)
  278. pr_cont("IEp ");
  279. if (regs->cp0_status & ST0_KUC)
  280. pr_cont("KUc ");
  281. if (regs->cp0_status & ST0_IEC)
  282. pr_cont("IEc ");
  283. } else if (cpu_has_4kex) {
  284. if (regs->cp0_status & ST0_KX)
  285. pr_cont("KX ");
  286. if (regs->cp0_status & ST0_SX)
  287. pr_cont("SX ");
  288. if (regs->cp0_status & ST0_UX)
  289. pr_cont("UX ");
  290. switch (regs->cp0_status & ST0_KSU) {
  291. case KSU_USER:
  292. pr_cont("USER ");
  293. break;
  294. case KSU_SUPERVISOR:
  295. pr_cont("SUPERVISOR ");
  296. break;
  297. case KSU_KERNEL:
  298. pr_cont("KERNEL ");
  299. break;
  300. default:
  301. pr_cont("BAD_MODE ");
  302. break;
  303. }
  304. if (regs->cp0_status & ST0_ERL)
  305. pr_cont("ERL ");
  306. if (regs->cp0_status & ST0_EXL)
  307. pr_cont("EXL ");
  308. if (regs->cp0_status & ST0_IE)
  309. pr_cont("IE ");
  310. }
  311. pr_cont("\n");
  312. exccode = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
  313. printk("Cause : %08x (ExcCode %02x)\n", cause, exccode);
  314. if (1 <= exccode && exccode <= 5)
  315. printk("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
  316. printk("PrId : %08x (%s)\n", read_c0_prid(),
  317. cpu_name_string());
  318. }
  319. /*
  320. * FIXME: really the generic show_regs should take a const pointer argument.
  321. */
  322. void show_regs(struct pt_regs *regs)
  323. {
  324. __show_regs((struct pt_regs *)regs);
  325. }
  326. void show_registers(struct pt_regs *regs)
  327. {
  328. const int field = 2 * sizeof(unsigned long);
  329. mm_segment_t old_fs = get_fs();
  330. __show_regs(regs);
  331. print_modules();
  332. printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
  333. current->comm, current->pid, current_thread_info(), current,
  334. field, current_thread_info()->tp_value);
  335. if (cpu_has_userlocal) {
  336. unsigned long tls;
  337. tls = read_c0_userlocal();
  338. if (tls != current_thread_info()->tp_value)
  339. printk("*HwTLS: %0*lx\n", field, tls);
  340. }
  341. if (!user_mode(regs))
  342. /* Necessary for getting the correct stack content */
  343. set_fs(KERNEL_DS);
  344. show_stacktrace(current, regs);
  345. show_code((unsigned int __user *) regs->cp0_epc);
  346. printk("\n");
  347. set_fs(old_fs);
  348. }
  349. static DEFINE_RAW_SPINLOCK(die_lock);
  350. void __noreturn die(const char *str, struct pt_regs *regs)
  351. {
  352. static int die_counter;
  353. int sig = SIGSEGV;
  354. oops_enter();
  355. if (notify_die(DIE_OOPS, str, regs, 0, current->thread.trap_nr,
  356. SIGSEGV) == NOTIFY_STOP)
  357. sig = 0;
  358. console_verbose();
  359. raw_spin_lock_irq(&die_lock);
  360. bust_spinlocks(1);
  361. printk("%s[#%d]:\n", str, ++die_counter);
  362. show_registers(regs);
  363. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  364. raw_spin_unlock_irq(&die_lock);
  365. oops_exit();
  366. if (in_interrupt())
  367. panic("Fatal exception in interrupt");
  368. if (panic_on_oops)
  369. panic("Fatal exception");
  370. if (regs && kexec_should_crash(current))
  371. crash_kexec(regs);
  372. do_exit(sig);
  373. }
  374. extern struct exception_table_entry __start___dbe_table[];
  375. extern struct exception_table_entry __stop___dbe_table[];
  376. __asm__(
  377. " .section __dbe_table, \"a\"\n"
  378. " .previous \n");
  379. /* Given an address, look for it in the exception tables. */
  380. static const struct exception_table_entry *search_dbe_tables(unsigned long addr)
  381. {
  382. const struct exception_table_entry *e;
  383. e = search_extable(__start___dbe_table,
  384. __stop___dbe_table - __start___dbe_table, addr);
  385. if (!e)
  386. e = search_module_dbetables(addr);
  387. return e;
  388. }
  389. asmlinkage void do_be(struct pt_regs *regs)
  390. {
  391. const int field = 2 * sizeof(unsigned long);
  392. const struct exception_table_entry *fixup = NULL;
  393. int data = regs->cp0_cause & 4;
  394. int action = MIPS_BE_FATAL;
  395. enum ctx_state prev_state;
  396. prev_state = exception_enter();
  397. /* XXX For now. Fixme, this searches the wrong table ... */
  398. if (data && !user_mode(regs))
  399. fixup = search_dbe_tables(exception_epc(regs));
  400. if (fixup)
  401. action = MIPS_BE_FIXUP;
  402. if (board_be_handler)
  403. action = board_be_handler(regs, fixup != NULL);
  404. else
  405. mips_cm_error_report();
  406. switch (action) {
  407. case MIPS_BE_DISCARD:
  408. goto out;
  409. case MIPS_BE_FIXUP:
  410. if (fixup) {
  411. regs->cp0_epc = fixup->nextinsn;
  412. goto out;
  413. }
  414. break;
  415. default:
  416. break;
  417. }
  418. /*
  419. * Assume it would be too dangerous to continue ...
  420. */
  421. printk(KERN_ALERT "%s bus error, epc == %0*lx, ra == %0*lx\n",
  422. data ? "Data" : "Instruction",
  423. field, regs->cp0_epc, field, regs->regs[31]);
  424. if (notify_die(DIE_OOPS, "bus error", regs, 0, current->thread.trap_nr,
  425. SIGBUS) == NOTIFY_STOP)
  426. goto out;
  427. die_if_kernel("Oops", regs);
  428. force_sig(SIGBUS, current);
  429. out:
  430. exception_exit(prev_state);
  431. }
  432. /*
  433. * ll/sc, rdhwr, sync emulation
  434. */
  435. #define OPCODE 0xfc000000
  436. #define BASE 0x03e00000
  437. #define RT 0x001f0000
  438. #define OFFSET 0x0000ffff
  439. #define LL 0xc0000000
  440. #define SC 0xe0000000
  441. #define SPEC0 0x00000000
  442. #define SPEC3 0x7c000000
  443. #define RD 0x0000f800
  444. #define FUNC 0x0000003f
  445. #define SYNC 0x0000000f
  446. #define RDHWR 0x0000003b
  447. /* microMIPS definitions */
  448. #define MM_POOL32A_FUNC 0xfc00ffff
  449. #define MM_RDHWR 0x00006b3c
  450. #define MM_RS 0x001f0000
  451. #define MM_RT 0x03e00000
  452. /*
  453. * The ll_bit is cleared by r*_switch.S
  454. */
  455. unsigned int ll_bit;
  456. struct task_struct *ll_task;
  457. static inline int simulate_ll(struct pt_regs *regs, unsigned int opcode)
  458. {
  459. unsigned long value, __user *vaddr;
  460. long offset;
  461. /*
  462. * analyse the ll instruction that just caused a ri exception
  463. * and put the referenced address to addr.
  464. */
  465. /* sign extend offset */
  466. offset = opcode & OFFSET;
  467. offset <<= 16;
  468. offset >>= 16;
  469. vaddr = (unsigned long __user *)
  470. ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
  471. if ((unsigned long)vaddr & 3)
  472. return SIGBUS;
  473. if (get_user(value, vaddr))
  474. return SIGSEGV;
  475. preempt_disable();
  476. if (ll_task == NULL || ll_task == current) {
  477. ll_bit = 1;
  478. } else {
  479. ll_bit = 0;
  480. }
  481. ll_task = current;
  482. preempt_enable();
  483. regs->regs[(opcode & RT) >> 16] = value;
  484. return 0;
  485. }
  486. static inline int simulate_sc(struct pt_regs *regs, unsigned int opcode)
  487. {
  488. unsigned long __user *vaddr;
  489. unsigned long reg;
  490. long offset;
  491. /*
  492. * analyse the sc instruction that just caused a ri exception
  493. * and put the referenced address to addr.
  494. */
  495. /* sign extend offset */
  496. offset = opcode & OFFSET;
  497. offset <<= 16;
  498. offset >>= 16;
  499. vaddr = (unsigned long __user *)
  500. ((unsigned long)(regs->regs[(opcode & BASE) >> 21]) + offset);
  501. reg = (opcode & RT) >> 16;
  502. if ((unsigned long)vaddr & 3)
  503. return SIGBUS;
  504. preempt_disable();
  505. if (ll_bit == 0 || ll_task != current) {
  506. regs->regs[reg] = 0;
  507. preempt_enable();
  508. return 0;
  509. }
  510. preempt_enable();
  511. if (put_user(regs->regs[reg], vaddr))
  512. return SIGSEGV;
  513. regs->regs[reg] = 1;
  514. return 0;
  515. }
  516. /*
  517. * ll uses the opcode of lwc0 and sc uses the opcode of swc0. That is both
  518. * opcodes are supposed to result in coprocessor unusable exceptions if
  519. * executed on ll/sc-less processors. That's the theory. In practice a
  520. * few processors such as NEC's VR4100 throw reserved instruction exceptions
  521. * instead, so we're doing the emulation thing in both exception handlers.
  522. */
  523. static int simulate_llsc(struct pt_regs *regs, unsigned int opcode)
  524. {
  525. if ((opcode & OPCODE) == LL) {
  526. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  527. 1, regs, 0);
  528. return simulate_ll(regs, opcode);
  529. }
  530. if ((opcode & OPCODE) == SC) {
  531. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  532. 1, regs, 0);
  533. return simulate_sc(regs, opcode);
  534. }
  535. return -1; /* Must be something else ... */
  536. }
  537. /*
  538. * Simulate trapping 'rdhwr' instructions to provide user accessible
  539. * registers not implemented in hardware.
  540. */
  541. static int simulate_rdhwr(struct pt_regs *regs, int rd, int rt)
  542. {
  543. struct thread_info *ti = task_thread_info(current);
  544. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  545. 1, regs, 0);
  546. switch (rd) {
  547. case MIPS_HWR_CPUNUM: /* CPU number */
  548. regs->regs[rt] = smp_processor_id();
  549. return 0;
  550. case MIPS_HWR_SYNCISTEP: /* SYNCI length */
  551. regs->regs[rt] = min(current_cpu_data.dcache.linesz,
  552. current_cpu_data.icache.linesz);
  553. return 0;
  554. case MIPS_HWR_CC: /* Read count register */
  555. regs->regs[rt] = read_c0_count();
  556. return 0;
  557. case MIPS_HWR_CCRES: /* Count register resolution */
  558. switch (current_cpu_type()) {
  559. case CPU_20KC:
  560. case CPU_25KF:
  561. regs->regs[rt] = 1;
  562. break;
  563. default:
  564. regs->regs[rt] = 2;
  565. }
  566. return 0;
  567. case MIPS_HWR_ULR: /* Read UserLocal register */
  568. regs->regs[rt] = ti->tp_value;
  569. return 0;
  570. default:
  571. return -1;
  572. }
  573. }
  574. static int simulate_rdhwr_normal(struct pt_regs *regs, unsigned int opcode)
  575. {
  576. if ((opcode & OPCODE) == SPEC3 && (opcode & FUNC) == RDHWR) {
  577. int rd = (opcode & RD) >> 11;
  578. int rt = (opcode & RT) >> 16;
  579. simulate_rdhwr(regs, rd, rt);
  580. return 0;
  581. }
  582. /* Not ours. */
  583. return -1;
  584. }
  585. static int simulate_rdhwr_mm(struct pt_regs *regs, unsigned int opcode)
  586. {
  587. if ((opcode & MM_POOL32A_FUNC) == MM_RDHWR) {
  588. int rd = (opcode & MM_RS) >> 16;
  589. int rt = (opcode & MM_RT) >> 21;
  590. simulate_rdhwr(regs, rd, rt);
  591. return 0;
  592. }
  593. /* Not ours. */
  594. return -1;
  595. }
  596. static int simulate_sync(struct pt_regs *regs, unsigned int opcode)
  597. {
  598. if ((opcode & OPCODE) == SPEC0 && (opcode & FUNC) == SYNC) {
  599. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS,
  600. 1, regs, 0);
  601. return 0;
  602. }
  603. return -1; /* Must be something else ... */
  604. }
  605. asmlinkage void do_ov(struct pt_regs *regs)
  606. {
  607. enum ctx_state prev_state;
  608. siginfo_t info = {
  609. .si_signo = SIGFPE,
  610. .si_code = FPE_INTOVF,
  611. .si_addr = (void __user *)regs->cp0_epc,
  612. };
  613. prev_state = exception_enter();
  614. die_if_kernel("Integer overflow", regs);
  615. force_sig_info(SIGFPE, &info, current);
  616. exception_exit(prev_state);
  617. }
  618. /*
  619. * Send SIGFPE according to FCSR Cause bits, which must have already
  620. * been masked against Enable bits. This is impotant as Inexact can
  621. * happen together with Overflow or Underflow, and `ptrace' can set
  622. * any bits.
  623. */
  624. void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
  625. struct task_struct *tsk)
  626. {
  627. struct siginfo si = { .si_addr = fault_addr, .si_signo = SIGFPE };
  628. if (fcr31 & FPU_CSR_INV_X)
  629. si.si_code = FPE_FLTINV;
  630. else if (fcr31 & FPU_CSR_DIV_X)
  631. si.si_code = FPE_FLTDIV;
  632. else if (fcr31 & FPU_CSR_OVF_X)
  633. si.si_code = FPE_FLTOVF;
  634. else if (fcr31 & FPU_CSR_UDF_X)
  635. si.si_code = FPE_FLTUND;
  636. else if (fcr31 & FPU_CSR_INE_X)
  637. si.si_code = FPE_FLTRES;
  638. else
  639. si.si_code = __SI_FAULT;
  640. force_sig_info(SIGFPE, &si, tsk);
  641. }
  642. int process_fpemu_return(int sig, void __user *fault_addr, unsigned long fcr31)
  643. {
  644. struct siginfo si = { 0 };
  645. struct vm_area_struct *vma;
  646. switch (sig) {
  647. case 0:
  648. return 0;
  649. case SIGFPE:
  650. force_fcr31_sig(fcr31, fault_addr, current);
  651. return 1;
  652. case SIGBUS:
  653. si.si_addr = fault_addr;
  654. si.si_signo = sig;
  655. si.si_code = BUS_ADRERR;
  656. force_sig_info(sig, &si, current);
  657. return 1;
  658. case SIGSEGV:
  659. si.si_addr = fault_addr;
  660. si.si_signo = sig;
  661. down_read(&current->mm->mmap_sem);
  662. vma = find_vma(current->mm, (unsigned long)fault_addr);
  663. if (vma && (vma->vm_start <= (unsigned long)fault_addr))
  664. si.si_code = SEGV_ACCERR;
  665. else
  666. si.si_code = SEGV_MAPERR;
  667. up_read(&current->mm->mmap_sem);
  668. force_sig_info(sig, &si, current);
  669. return 1;
  670. default:
  671. force_sig(sig, current);
  672. return 1;
  673. }
  674. }
  675. static int simulate_fp(struct pt_regs *regs, unsigned int opcode,
  676. unsigned long old_epc, unsigned long old_ra)
  677. {
  678. union mips_instruction inst = { .word = opcode };
  679. void __user *fault_addr;
  680. unsigned long fcr31;
  681. int sig;
  682. /* If it's obviously not an FP instruction, skip it */
  683. switch (inst.i_format.opcode) {
  684. case cop1_op:
  685. case cop1x_op:
  686. case lwc1_op:
  687. case ldc1_op:
  688. case swc1_op:
  689. case sdc1_op:
  690. break;
  691. default:
  692. return -1;
  693. }
  694. /*
  695. * do_ri skipped over the instruction via compute_return_epc, undo
  696. * that for the FPU emulator.
  697. */
  698. regs->cp0_epc = old_epc;
  699. regs->regs[31] = old_ra;
  700. /* Save the FP context to struct thread_struct */
  701. lose_fpu(1);
  702. /* Run the emulator */
  703. sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
  704. &fault_addr);
  705. /*
  706. * We can't allow the emulated instruction to leave any
  707. * enabled Cause bits set in $fcr31.
  708. */
  709. fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
  710. current->thread.fpu.fcr31 &= ~fcr31;
  711. /* Restore the hardware register state */
  712. own_fpu(1);
  713. /* Send a signal if required. */
  714. process_fpemu_return(sig, fault_addr, fcr31);
  715. return 0;
  716. }
  717. /*
  718. * XXX Delayed fp exceptions when doing a lazy ctx switch XXX
  719. */
  720. asmlinkage void do_fpe(struct pt_regs *regs, unsigned long fcr31)
  721. {
  722. enum ctx_state prev_state;
  723. void __user *fault_addr;
  724. int sig;
  725. prev_state = exception_enter();
  726. if (notify_die(DIE_FP, "FP exception", regs, 0, current->thread.trap_nr,
  727. SIGFPE) == NOTIFY_STOP)
  728. goto out;
  729. /* Clear FCSR.Cause before enabling interrupts */
  730. write_32bit_cp1_register(CP1_STATUS, fcr31 & ~mask_fcr31_x(fcr31));
  731. local_irq_enable();
  732. die_if_kernel("FP exception in kernel code", regs);
  733. if (fcr31 & FPU_CSR_UNI_X) {
  734. /*
  735. * Unimplemented operation exception. If we've got the full
  736. * software emulator on-board, let's use it...
  737. *
  738. * Force FPU to dump state into task/thread context. We're
  739. * moving a lot of data here for what is probably a single
  740. * instruction, but the alternative is to pre-decode the FP
  741. * register operands before invoking the emulator, which seems
  742. * a bit extreme for what should be an infrequent event.
  743. */
  744. /* Ensure 'resume' not overwrite saved fp context again. */
  745. lose_fpu(1);
  746. /* Run the emulator */
  747. sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
  748. &fault_addr);
  749. /*
  750. * We can't allow the emulated instruction to leave any
  751. * enabled Cause bits set in $fcr31.
  752. */
  753. fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
  754. current->thread.fpu.fcr31 &= ~fcr31;
  755. /* Restore the hardware register state */
  756. own_fpu(1); /* Using the FPU again. */
  757. } else {
  758. sig = SIGFPE;
  759. fault_addr = (void __user *) regs->cp0_epc;
  760. }
  761. /* Send a signal if required. */
  762. process_fpemu_return(sig, fault_addr, fcr31);
  763. out:
  764. exception_exit(prev_state);
  765. }
  766. void do_trap_or_bp(struct pt_regs *regs, unsigned int code, int si_code,
  767. const char *str)
  768. {
  769. siginfo_t info = { 0 };
  770. char b[40];
  771. #ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
  772. if (kgdb_ll_trap(DIE_TRAP, str, regs, code, current->thread.trap_nr,
  773. SIGTRAP) == NOTIFY_STOP)
  774. return;
  775. #endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
  776. if (notify_die(DIE_TRAP, str, regs, code, current->thread.trap_nr,
  777. SIGTRAP) == NOTIFY_STOP)
  778. return;
  779. /*
  780. * A short test says that IRIX 5.3 sends SIGTRAP for all trap
  781. * insns, even for trap and break codes that indicate arithmetic
  782. * failures. Weird ...
  783. * But should we continue the brokenness??? --macro
  784. */
  785. switch (code) {
  786. case BRK_OVERFLOW:
  787. case BRK_DIVZERO:
  788. scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
  789. die_if_kernel(b, regs);
  790. if (code == BRK_DIVZERO)
  791. info.si_code = FPE_INTDIV;
  792. else
  793. info.si_code = FPE_INTOVF;
  794. info.si_signo = SIGFPE;
  795. info.si_addr = (void __user *) regs->cp0_epc;
  796. force_sig_info(SIGFPE, &info, current);
  797. break;
  798. case BRK_BUG:
  799. die_if_kernel("Kernel bug detected", regs);
  800. force_sig(SIGTRAP, current);
  801. break;
  802. case BRK_MEMU:
  803. /*
  804. * This breakpoint code is used by the FPU emulator to retake
  805. * control of the CPU after executing the instruction from the
  806. * delay slot of an emulated branch.
  807. *
  808. * Terminate if exception was recognized as a delay slot return
  809. * otherwise handle as normal.
  810. */
  811. if (do_dsemulret(regs))
  812. return;
  813. die_if_kernel("Math emu break/trap", regs);
  814. force_sig(SIGTRAP, current);
  815. break;
  816. default:
  817. scnprintf(b, sizeof(b), "%s instruction in kernel code", str);
  818. die_if_kernel(b, regs);
  819. if (si_code) {
  820. info.si_signo = SIGTRAP;
  821. info.si_code = si_code;
  822. force_sig_info(SIGTRAP, &info, current);
  823. } else {
  824. force_sig(SIGTRAP, current);
  825. }
  826. }
  827. }
  828. asmlinkage void do_bp(struct pt_regs *regs)
  829. {
  830. unsigned long epc = msk_isa16_mode(exception_epc(regs));
  831. unsigned int opcode, bcode;
  832. enum ctx_state prev_state;
  833. mm_segment_t seg;
  834. seg = get_fs();
  835. if (!user_mode(regs))
  836. set_fs(KERNEL_DS);
  837. prev_state = exception_enter();
  838. current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
  839. if (get_isa16_mode(regs->cp0_epc)) {
  840. u16 instr[2];
  841. if (__get_user(instr[0], (u16 __user *)epc))
  842. goto out_sigsegv;
  843. if (!cpu_has_mmips) {
  844. /* MIPS16e mode */
  845. bcode = (instr[0] >> 5) & 0x3f;
  846. } else if (mm_insn_16bit(instr[0])) {
  847. /* 16-bit microMIPS BREAK */
  848. bcode = instr[0] & 0xf;
  849. } else {
  850. /* 32-bit microMIPS BREAK */
  851. if (__get_user(instr[1], (u16 __user *)(epc + 2)))
  852. goto out_sigsegv;
  853. opcode = (instr[0] << 16) | instr[1];
  854. bcode = (opcode >> 6) & ((1 << 20) - 1);
  855. }
  856. } else {
  857. if (__get_user(opcode, (unsigned int __user *)epc))
  858. goto out_sigsegv;
  859. bcode = (opcode >> 6) & ((1 << 20) - 1);
  860. }
  861. /*
  862. * There is the ancient bug in the MIPS assemblers that the break
  863. * code starts left to bit 16 instead to bit 6 in the opcode.
  864. * Gas is bug-compatible, but not always, grrr...
  865. * We handle both cases with a simple heuristics. --macro
  866. */
  867. if (bcode >= (1 << 10))
  868. bcode = ((bcode & ((1 << 10) - 1)) << 10) | (bcode >> 10);
  869. /*
  870. * notify the kprobe handlers, if instruction is likely to
  871. * pertain to them.
  872. */
  873. switch (bcode) {
  874. case BRK_UPROBE:
  875. if (notify_die(DIE_UPROBE, "uprobe", regs, bcode,
  876. current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
  877. goto out;
  878. else
  879. break;
  880. case BRK_UPROBE_XOL:
  881. if (notify_die(DIE_UPROBE_XOL, "uprobe_xol", regs, bcode,
  882. current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
  883. goto out;
  884. else
  885. break;
  886. case BRK_KPROBE_BP:
  887. if (notify_die(DIE_BREAK, "debug", regs, bcode,
  888. current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
  889. goto out;
  890. else
  891. break;
  892. case BRK_KPROBE_SSTEPBP:
  893. if (notify_die(DIE_SSTEPBP, "single_step", regs, bcode,
  894. current->thread.trap_nr, SIGTRAP) == NOTIFY_STOP)
  895. goto out;
  896. else
  897. break;
  898. default:
  899. break;
  900. }
  901. do_trap_or_bp(regs, bcode, TRAP_BRKPT, "Break");
  902. out:
  903. set_fs(seg);
  904. exception_exit(prev_state);
  905. return;
  906. out_sigsegv:
  907. force_sig(SIGSEGV, current);
  908. goto out;
  909. }
  910. asmlinkage void do_tr(struct pt_regs *regs)
  911. {
  912. u32 opcode, tcode = 0;
  913. enum ctx_state prev_state;
  914. u16 instr[2];
  915. mm_segment_t seg;
  916. unsigned long epc = msk_isa16_mode(exception_epc(regs));
  917. seg = get_fs();
  918. if (!user_mode(regs))
  919. set_fs(get_ds());
  920. prev_state = exception_enter();
  921. current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
  922. if (get_isa16_mode(regs->cp0_epc)) {
  923. if (__get_user(instr[0], (u16 __user *)(epc + 0)) ||
  924. __get_user(instr[1], (u16 __user *)(epc + 2)))
  925. goto out_sigsegv;
  926. opcode = (instr[0] << 16) | instr[1];
  927. /* Immediate versions don't provide a code. */
  928. if (!(opcode & OPCODE))
  929. tcode = (opcode >> 12) & ((1 << 4) - 1);
  930. } else {
  931. if (__get_user(opcode, (u32 __user *)epc))
  932. goto out_sigsegv;
  933. /* Immediate versions don't provide a code. */
  934. if (!(opcode & OPCODE))
  935. tcode = (opcode >> 6) & ((1 << 10) - 1);
  936. }
  937. do_trap_or_bp(regs, tcode, 0, "Trap");
  938. out:
  939. set_fs(seg);
  940. exception_exit(prev_state);
  941. return;
  942. out_sigsegv:
  943. force_sig(SIGSEGV, current);
  944. goto out;
  945. }
  946. asmlinkage void do_ri(struct pt_regs *regs)
  947. {
  948. unsigned int __user *epc = (unsigned int __user *)exception_epc(regs);
  949. unsigned long old_epc = regs->cp0_epc;
  950. unsigned long old31 = regs->regs[31];
  951. enum ctx_state prev_state;
  952. unsigned int opcode = 0;
  953. int status = -1;
  954. /*
  955. * Avoid any kernel code. Just emulate the R2 instruction
  956. * as quickly as possible.
  957. */
  958. if (mipsr2_emulation && cpu_has_mips_r6 &&
  959. likely(user_mode(regs)) &&
  960. likely(get_user(opcode, epc) >= 0)) {
  961. unsigned long fcr31 = 0;
  962. status = mipsr2_decoder(regs, opcode, &fcr31);
  963. switch (status) {
  964. case 0:
  965. case SIGEMT:
  966. return;
  967. case SIGILL:
  968. goto no_r2_instr;
  969. default:
  970. process_fpemu_return(status,
  971. &current->thread.cp0_baduaddr,
  972. fcr31);
  973. return;
  974. }
  975. }
  976. no_r2_instr:
  977. prev_state = exception_enter();
  978. current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
  979. if (notify_die(DIE_RI, "RI Fault", regs, 0, current->thread.trap_nr,
  980. SIGILL) == NOTIFY_STOP)
  981. goto out;
  982. die_if_kernel("Reserved instruction in kernel code", regs);
  983. if (unlikely(compute_return_epc(regs) < 0))
  984. goto out;
  985. if (!get_isa16_mode(regs->cp0_epc)) {
  986. if (unlikely(get_user(opcode, epc) < 0))
  987. status = SIGSEGV;
  988. if (!cpu_has_llsc && status < 0)
  989. status = simulate_llsc(regs, opcode);
  990. if (status < 0)
  991. status = simulate_rdhwr_normal(regs, opcode);
  992. if (status < 0)
  993. status = simulate_sync(regs, opcode);
  994. if (status < 0)
  995. status = simulate_fp(regs, opcode, old_epc, old31);
  996. } else if (cpu_has_mmips) {
  997. unsigned short mmop[2] = { 0 };
  998. if (unlikely(get_user(mmop[0], (u16 __user *)epc + 0) < 0))
  999. status = SIGSEGV;
  1000. if (unlikely(get_user(mmop[1], (u16 __user *)epc + 1) < 0))
  1001. status = SIGSEGV;
  1002. opcode = mmop[0];
  1003. opcode = (opcode << 16) | mmop[1];
  1004. if (status < 0)
  1005. status = simulate_rdhwr_mm(regs, opcode);
  1006. }
  1007. if (status < 0)
  1008. status = SIGILL;
  1009. if (unlikely(status > 0)) {
  1010. regs->cp0_epc = old_epc; /* Undo skip-over. */
  1011. regs->regs[31] = old31;
  1012. force_sig(status, current);
  1013. }
  1014. out:
  1015. exception_exit(prev_state);
  1016. }
  1017. /*
  1018. * MIPS MT processors may have fewer FPU contexts than CPU threads. If we've
  1019. * emulated more than some threshold number of instructions, force migration to
  1020. * a "CPU" that has FP support.
  1021. */
  1022. static void mt_ase_fp_affinity(void)
  1023. {
  1024. #ifdef CONFIG_MIPS_MT_FPAFF
  1025. if (mt_fpemul_threshold > 0 &&
  1026. ((current->thread.emulated_fp++ > mt_fpemul_threshold))) {
  1027. /*
  1028. * If there's no FPU present, or if the application has already
  1029. * restricted the allowed set to exclude any CPUs with FPUs,
  1030. * we'll skip the procedure.
  1031. */
  1032. if (cpumask_intersects(&current->cpus_allowed, &mt_fpu_cpumask)) {
  1033. cpumask_t tmask;
  1034. current->thread.user_cpus_allowed
  1035. = current->cpus_allowed;
  1036. cpumask_and(&tmask, &current->cpus_allowed,
  1037. &mt_fpu_cpumask);
  1038. set_cpus_allowed_ptr(current, &tmask);
  1039. set_thread_flag(TIF_FPUBOUND);
  1040. }
  1041. }
  1042. #endif /* CONFIG_MIPS_MT_FPAFF */
  1043. }
  1044. /*
  1045. * No lock; only written during early bootup by CPU 0.
  1046. */
  1047. static RAW_NOTIFIER_HEAD(cu2_chain);
  1048. int __ref register_cu2_notifier(struct notifier_block *nb)
  1049. {
  1050. return raw_notifier_chain_register(&cu2_chain, nb);
  1051. }
  1052. int cu2_notifier_call_chain(unsigned long val, void *v)
  1053. {
  1054. return raw_notifier_call_chain(&cu2_chain, val, v);
  1055. }
  1056. static int default_cu2_call(struct notifier_block *nfb, unsigned long action,
  1057. void *data)
  1058. {
  1059. struct pt_regs *regs = data;
  1060. die_if_kernel("COP2: Unhandled kernel unaligned access or invalid "
  1061. "instruction", regs);
  1062. force_sig(SIGILL, current);
  1063. return NOTIFY_OK;
  1064. }
  1065. static int wait_on_fp_mode_switch(atomic_t *p)
  1066. {
  1067. /*
  1068. * The FP mode for this task is currently being switched. That may
  1069. * involve modifications to the format of this tasks FP context which
  1070. * make it unsafe to proceed with execution for the moment. Instead,
  1071. * schedule some other task.
  1072. */
  1073. schedule();
  1074. return 0;
  1075. }
  1076. static int enable_restore_fp_context(int msa)
  1077. {
  1078. int err, was_fpu_owner, prior_msa;
  1079. /*
  1080. * If an FP mode switch is currently underway, wait for it to
  1081. * complete before proceeding.
  1082. */
  1083. wait_on_atomic_t(&current->mm->context.fp_mode_switching,
  1084. wait_on_fp_mode_switch, TASK_KILLABLE);
  1085. if (!used_math()) {
  1086. /* First time FP context user. */
  1087. preempt_disable();
  1088. err = init_fpu();
  1089. if (msa && !err) {
  1090. enable_msa();
  1091. init_msa_upper();
  1092. set_thread_flag(TIF_USEDMSA);
  1093. set_thread_flag(TIF_MSA_CTX_LIVE);
  1094. }
  1095. preempt_enable();
  1096. if (!err)
  1097. set_used_math();
  1098. return err;
  1099. }
  1100. /*
  1101. * This task has formerly used the FP context.
  1102. *
  1103. * If this thread has no live MSA vector context then we can simply
  1104. * restore the scalar FP context. If it has live MSA vector context
  1105. * (that is, it has or may have used MSA since last performing a
  1106. * function call) then we'll need to restore the vector context. This
  1107. * applies even if we're currently only executing a scalar FP
  1108. * instruction. This is because if we were to later execute an MSA
  1109. * instruction then we'd either have to:
  1110. *
  1111. * - Restore the vector context & clobber any registers modified by
  1112. * scalar FP instructions between now & then.
  1113. *
  1114. * or
  1115. *
  1116. * - Not restore the vector context & lose the most significant bits
  1117. * of all vector registers.
  1118. *
  1119. * Neither of those options is acceptable. We cannot restore the least
  1120. * significant bits of the registers now & only restore the most
  1121. * significant bits later because the most significant bits of any
  1122. * vector registers whose aliased FP register is modified now will have
  1123. * been zeroed. We'd have no way to know that when restoring the vector
  1124. * context & thus may load an outdated value for the most significant
  1125. * bits of a vector register.
  1126. */
  1127. if (!msa && !thread_msa_context_live())
  1128. return own_fpu(1);
  1129. /*
  1130. * This task is using or has previously used MSA. Thus we require
  1131. * that Status.FR == 1.
  1132. */
  1133. preempt_disable();
  1134. was_fpu_owner = is_fpu_owner();
  1135. err = own_fpu_inatomic(0);
  1136. if (err)
  1137. goto out;
  1138. enable_msa();
  1139. write_msa_csr(current->thread.fpu.msacsr);
  1140. set_thread_flag(TIF_USEDMSA);
  1141. /*
  1142. * If this is the first time that the task is using MSA and it has
  1143. * previously used scalar FP in this time slice then we already nave
  1144. * FP context which we shouldn't clobber. We do however need to clear
  1145. * the upper 64b of each vector register so that this task has no
  1146. * opportunity to see data left behind by another.
  1147. */
  1148. prior_msa = test_and_set_thread_flag(TIF_MSA_CTX_LIVE);
  1149. if (!prior_msa && was_fpu_owner) {
  1150. init_msa_upper();
  1151. goto out;
  1152. }
  1153. if (!prior_msa) {
  1154. /*
  1155. * Restore the least significant 64b of each vector register
  1156. * from the existing scalar FP context.
  1157. */
  1158. _restore_fp(current);
  1159. /*
  1160. * The task has not formerly used MSA, so clear the upper 64b
  1161. * of each vector register such that it cannot see data left
  1162. * behind by another task.
  1163. */
  1164. init_msa_upper();
  1165. } else {
  1166. /* We need to restore the vector context. */
  1167. restore_msa(current);
  1168. /* Restore the scalar FP control & status register */
  1169. if (!was_fpu_owner)
  1170. write_32bit_cp1_register(CP1_STATUS,
  1171. current->thread.fpu.fcr31);
  1172. }
  1173. out:
  1174. preempt_enable();
  1175. return 0;
  1176. }
  1177. asmlinkage void do_cpu(struct pt_regs *regs)
  1178. {
  1179. enum ctx_state prev_state;
  1180. unsigned int __user *epc;
  1181. unsigned long old_epc, old31;
  1182. void __user *fault_addr;
  1183. unsigned int opcode;
  1184. unsigned long fcr31;
  1185. unsigned int cpid;
  1186. int status, err;
  1187. int sig;
  1188. prev_state = exception_enter();
  1189. cpid = (regs->cp0_cause >> CAUSEB_CE) & 3;
  1190. if (cpid != 2)
  1191. die_if_kernel("do_cpu invoked from kernel context!", regs);
  1192. switch (cpid) {
  1193. case 0:
  1194. epc = (unsigned int __user *)exception_epc(regs);
  1195. old_epc = regs->cp0_epc;
  1196. old31 = regs->regs[31];
  1197. opcode = 0;
  1198. status = -1;
  1199. if (unlikely(compute_return_epc(regs) < 0))
  1200. break;
  1201. if (!get_isa16_mode(regs->cp0_epc)) {
  1202. if (unlikely(get_user(opcode, epc) < 0))
  1203. status = SIGSEGV;
  1204. if (!cpu_has_llsc && status < 0)
  1205. status = simulate_llsc(regs, opcode);
  1206. }
  1207. if (status < 0)
  1208. status = SIGILL;
  1209. if (unlikely(status > 0)) {
  1210. regs->cp0_epc = old_epc; /* Undo skip-over. */
  1211. regs->regs[31] = old31;
  1212. force_sig(status, current);
  1213. }
  1214. break;
  1215. case 3:
  1216. /*
  1217. * The COP3 opcode space and consequently the CP0.Status.CU3
  1218. * bit and the CP0.Cause.CE=3 encoding have been removed as
  1219. * of the MIPS III ISA. From the MIPS IV and MIPS32r2 ISAs
  1220. * up the space has been reused for COP1X instructions, that
  1221. * are enabled by the CP0.Status.CU1 bit and consequently
  1222. * use the CP0.Cause.CE=1 encoding for Coprocessor Unusable
  1223. * exceptions. Some FPU-less processors that implement one
  1224. * of these ISAs however use this code erroneously for COP1X
  1225. * instructions. Therefore we redirect this trap to the FP
  1226. * emulator too.
  1227. */
  1228. if (raw_cpu_has_fpu || !cpu_has_mips_4_5_64_r2_r6) {
  1229. force_sig(SIGILL, current);
  1230. break;
  1231. }
  1232. /* Fall through. */
  1233. case 1:
  1234. err = enable_restore_fp_context(0);
  1235. if (raw_cpu_has_fpu && !err)
  1236. break;
  1237. sig = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 0,
  1238. &fault_addr);
  1239. /*
  1240. * We can't allow the emulated instruction to leave
  1241. * any enabled Cause bits set in $fcr31.
  1242. */
  1243. fcr31 = mask_fcr31_x(current->thread.fpu.fcr31);
  1244. current->thread.fpu.fcr31 &= ~fcr31;
  1245. /* Send a signal if required. */
  1246. if (!process_fpemu_return(sig, fault_addr, fcr31) && !err)
  1247. mt_ase_fp_affinity();
  1248. break;
  1249. case 2:
  1250. raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
  1251. break;
  1252. }
  1253. exception_exit(prev_state);
  1254. }
  1255. asmlinkage void do_msa_fpe(struct pt_regs *regs, unsigned int msacsr)
  1256. {
  1257. enum ctx_state prev_state;
  1258. prev_state = exception_enter();
  1259. current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
  1260. if (notify_die(DIE_MSAFP, "MSA FP exception", regs, 0,
  1261. current->thread.trap_nr, SIGFPE) == NOTIFY_STOP)
  1262. goto out;
  1263. /* Clear MSACSR.Cause before enabling interrupts */
  1264. write_msa_csr(msacsr & ~MSA_CSR_CAUSEF);
  1265. local_irq_enable();
  1266. die_if_kernel("do_msa_fpe invoked from kernel context!", regs);
  1267. force_sig(SIGFPE, current);
  1268. out:
  1269. exception_exit(prev_state);
  1270. }
  1271. asmlinkage void do_msa(struct pt_regs *regs)
  1272. {
  1273. enum ctx_state prev_state;
  1274. int err;
  1275. prev_state = exception_enter();
  1276. if (!cpu_has_msa || test_thread_flag(TIF_32BIT_FPREGS)) {
  1277. force_sig(SIGILL, current);
  1278. goto out;
  1279. }
  1280. die_if_kernel("do_msa invoked from kernel context!", regs);
  1281. err = enable_restore_fp_context(1);
  1282. if (err)
  1283. force_sig(SIGILL, current);
  1284. out:
  1285. exception_exit(prev_state);
  1286. }
  1287. asmlinkage void do_mdmx(struct pt_regs *regs)
  1288. {
  1289. enum ctx_state prev_state;
  1290. prev_state = exception_enter();
  1291. force_sig(SIGILL, current);
  1292. exception_exit(prev_state);
  1293. }
  1294. /*
  1295. * Called with interrupts disabled.
  1296. */
  1297. asmlinkage void do_watch(struct pt_regs *regs)
  1298. {
  1299. siginfo_t info = { .si_signo = SIGTRAP, .si_code = TRAP_HWBKPT };
  1300. enum ctx_state prev_state;
  1301. prev_state = exception_enter();
  1302. /*
  1303. * Clear WP (bit 22) bit of cause register so we don't loop
  1304. * forever.
  1305. */
  1306. clear_c0_cause(CAUSEF_WP);
  1307. /*
  1308. * If the current thread has the watch registers loaded, save
  1309. * their values and send SIGTRAP. Otherwise another thread
  1310. * left the registers set, clear them and continue.
  1311. */
  1312. if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) {
  1313. mips_read_watch_registers();
  1314. local_irq_enable();
  1315. force_sig_info(SIGTRAP, &info, current);
  1316. } else {
  1317. mips_clear_watch_registers();
  1318. local_irq_enable();
  1319. }
  1320. exception_exit(prev_state);
  1321. }
  1322. asmlinkage void do_mcheck(struct pt_regs *regs)
  1323. {
  1324. int multi_match = regs->cp0_status & ST0_TS;
  1325. enum ctx_state prev_state;
  1326. mm_segment_t old_fs = get_fs();
  1327. prev_state = exception_enter();
  1328. show_regs(regs);
  1329. if (multi_match) {
  1330. dump_tlb_regs();
  1331. pr_info("\n");
  1332. dump_tlb_all();
  1333. }
  1334. if (!user_mode(regs))
  1335. set_fs(KERNEL_DS);
  1336. show_code((unsigned int __user *) regs->cp0_epc);
  1337. set_fs(old_fs);
  1338. /*
  1339. * Some chips may have other causes of machine check (e.g. SB1
  1340. * graduation timer)
  1341. */
  1342. panic("Caught Machine Check exception - %scaused by multiple "
  1343. "matching entries in the TLB.",
  1344. (multi_match) ? "" : "not ");
  1345. }
  1346. asmlinkage void do_mt(struct pt_regs *regs)
  1347. {
  1348. int subcode;
  1349. subcode = (read_vpe_c0_vpecontrol() & VPECONTROL_EXCPT)
  1350. >> VPECONTROL_EXCPT_SHIFT;
  1351. switch (subcode) {
  1352. case 0:
  1353. printk(KERN_DEBUG "Thread Underflow\n");
  1354. break;
  1355. case 1:
  1356. printk(KERN_DEBUG "Thread Overflow\n");
  1357. break;
  1358. case 2:
  1359. printk(KERN_DEBUG "Invalid YIELD Qualifier\n");
  1360. break;
  1361. case 3:
  1362. printk(KERN_DEBUG "Gating Storage Exception\n");
  1363. break;
  1364. case 4:
  1365. printk(KERN_DEBUG "YIELD Scheduler Exception\n");
  1366. break;
  1367. case 5:
  1368. printk(KERN_DEBUG "Gating Storage Scheduler Exception\n");
  1369. break;
  1370. default:
  1371. printk(KERN_DEBUG "*** UNKNOWN THREAD EXCEPTION %d ***\n",
  1372. subcode);
  1373. break;
  1374. }
  1375. die_if_kernel("MIPS MT Thread exception in kernel", regs);
  1376. force_sig(SIGILL, current);
  1377. }
  1378. asmlinkage void do_dsp(struct pt_regs *regs)
  1379. {
  1380. if (cpu_has_dsp)
  1381. panic("Unexpected DSP exception");
  1382. force_sig(SIGILL, current);
  1383. }
  1384. asmlinkage void do_reserved(struct pt_regs *regs)
  1385. {
  1386. /*
  1387. * Game over - no way to handle this if it ever occurs. Most probably
  1388. * caused by a new unknown cpu type or after another deadly
  1389. * hard/software error.
  1390. */
  1391. show_regs(regs);
  1392. panic("Caught reserved exception %ld - should not happen.",
  1393. (regs->cp0_cause & 0x7f) >> 2);
  1394. }
  1395. static int __initdata l1parity = 1;
  1396. static int __init nol1parity(char *s)
  1397. {
  1398. l1parity = 0;
  1399. return 1;
  1400. }
  1401. __setup("nol1par", nol1parity);
  1402. static int __initdata l2parity = 1;
  1403. static int __init nol2parity(char *s)
  1404. {
  1405. l2parity = 0;
  1406. return 1;
  1407. }
  1408. __setup("nol2par", nol2parity);
  1409. /*
  1410. * Some MIPS CPUs can enable/disable for cache parity detection, but do
  1411. * it different ways.
  1412. */
  1413. static inline void parity_protection_init(void)
  1414. {
  1415. #define ERRCTL_PE 0x80000000
  1416. #define ERRCTL_L2P 0x00800000
  1417. if (mips_cm_revision() >= CM_REV_CM3) {
  1418. ulong gcr_ectl, cp0_ectl;
  1419. /*
  1420. * With CM3 systems we need to ensure that the L1 & L2
  1421. * parity enables are set to the same value, since this
  1422. * is presumed by the hardware engineers.
  1423. *
  1424. * If the user disabled either of L1 or L2 ECC checking,
  1425. * disable both.
  1426. */
  1427. l1parity &= l2parity;
  1428. l2parity &= l1parity;
  1429. /* Probe L1 ECC support */
  1430. cp0_ectl = read_c0_ecc();
  1431. write_c0_ecc(cp0_ectl | ERRCTL_PE);
  1432. back_to_back_c0_hazard();
  1433. cp0_ectl = read_c0_ecc();
  1434. /* Probe L2 ECC support */
  1435. gcr_ectl = read_gcr_err_control();
  1436. if (!(gcr_ectl & CM_GCR_ERR_CONTROL_L2_ECC_SUPPORT_MSK) ||
  1437. !(cp0_ectl & ERRCTL_PE)) {
  1438. /*
  1439. * One of L1 or L2 ECC checking isn't supported,
  1440. * so we cannot enable either.
  1441. */
  1442. l1parity = l2parity = 0;
  1443. }
  1444. /* Configure L1 ECC checking */
  1445. if (l1parity)
  1446. cp0_ectl |= ERRCTL_PE;
  1447. else
  1448. cp0_ectl &= ~ERRCTL_PE;
  1449. write_c0_ecc(cp0_ectl);
  1450. back_to_back_c0_hazard();
  1451. WARN_ON(!!(read_c0_ecc() & ERRCTL_PE) != l1parity);
  1452. /* Configure L2 ECC checking */
  1453. if (l2parity)
  1454. gcr_ectl |= CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
  1455. else
  1456. gcr_ectl &= ~CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
  1457. write_gcr_err_control(gcr_ectl);
  1458. gcr_ectl = read_gcr_err_control();
  1459. gcr_ectl &= CM_GCR_ERR_CONTROL_L2_ECC_EN_MSK;
  1460. WARN_ON(!!gcr_ectl != l2parity);
  1461. pr_info("Cache parity protection %sabled\n",
  1462. l1parity ? "en" : "dis");
  1463. return;
  1464. }
  1465. switch (current_cpu_type()) {
  1466. case CPU_24K:
  1467. case CPU_34K:
  1468. case CPU_74K:
  1469. case CPU_1004K:
  1470. case CPU_1074K:
  1471. case CPU_INTERAPTIV:
  1472. case CPU_PROAPTIV:
  1473. case CPU_P5600:
  1474. case CPU_QEMU_GENERIC:
  1475. case CPU_P6600:
  1476. {
  1477. unsigned long errctl;
  1478. unsigned int l1parity_present, l2parity_present;
  1479. errctl = read_c0_ecc();
  1480. errctl &= ~(ERRCTL_PE|ERRCTL_L2P);
  1481. /* probe L1 parity support */
  1482. write_c0_ecc(errctl | ERRCTL_PE);
  1483. back_to_back_c0_hazard();
  1484. l1parity_present = (read_c0_ecc() & ERRCTL_PE);
  1485. /* probe L2 parity support */
  1486. write_c0_ecc(errctl|ERRCTL_L2P);
  1487. back_to_back_c0_hazard();
  1488. l2parity_present = (read_c0_ecc() & ERRCTL_L2P);
  1489. if (l1parity_present && l2parity_present) {
  1490. if (l1parity)
  1491. errctl |= ERRCTL_PE;
  1492. if (l1parity ^ l2parity)
  1493. errctl |= ERRCTL_L2P;
  1494. } else if (l1parity_present) {
  1495. if (l1parity)
  1496. errctl |= ERRCTL_PE;
  1497. } else if (l2parity_present) {
  1498. if (l2parity)
  1499. errctl |= ERRCTL_L2P;
  1500. } else {
  1501. /* No parity available */
  1502. }
  1503. printk(KERN_INFO "Writing ErrCtl register=%08lx\n", errctl);
  1504. write_c0_ecc(errctl);
  1505. back_to_back_c0_hazard();
  1506. errctl = read_c0_ecc();
  1507. printk(KERN_INFO "Readback ErrCtl register=%08lx\n", errctl);
  1508. if (l1parity_present)
  1509. printk(KERN_INFO "Cache parity protection %sabled\n",
  1510. (errctl & ERRCTL_PE) ? "en" : "dis");
  1511. if (l2parity_present) {
  1512. if (l1parity_present && l1parity)
  1513. errctl ^= ERRCTL_L2P;
  1514. printk(KERN_INFO "L2 cache parity protection %sabled\n",
  1515. (errctl & ERRCTL_L2P) ? "en" : "dis");
  1516. }
  1517. }
  1518. break;
  1519. case CPU_5KC:
  1520. case CPU_5KE:
  1521. case CPU_LOONGSON1:
  1522. write_c0_ecc(0x80000000);
  1523. back_to_back_c0_hazard();
  1524. /* Set the PE bit (bit 31) in the c0_errctl register. */
  1525. printk(KERN_INFO "Cache parity protection %sabled\n",
  1526. (read_c0_ecc() & 0x80000000) ? "en" : "dis");
  1527. break;
  1528. case CPU_20KC:
  1529. case CPU_25KF:
  1530. /* Clear the DE bit (bit 16) in the c0_status register. */
  1531. printk(KERN_INFO "Enable cache parity protection for "
  1532. "MIPS 20KC/25KF CPUs.\n");
  1533. clear_c0_status(ST0_DE);
  1534. break;
  1535. default:
  1536. break;
  1537. }
  1538. }
  1539. asmlinkage void cache_parity_error(void)
  1540. {
  1541. const int field = 2 * sizeof(unsigned long);
  1542. unsigned int reg_val;
  1543. /* For the moment, report the problem and hang. */
  1544. printk("Cache error exception:\n");
  1545. printk("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
  1546. reg_val = read_c0_cacheerr();
  1547. printk("c0_cacheerr == %08x\n", reg_val);
  1548. printk("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
  1549. reg_val & (1<<30) ? "secondary" : "primary",
  1550. reg_val & (1<<31) ? "data" : "insn");
  1551. if ((cpu_has_mips_r2_r6) &&
  1552. ((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_MIPS)) {
  1553. pr_err("Error bits: %s%s%s%s%s%s%s%s\n",
  1554. reg_val & (1<<29) ? "ED " : "",
  1555. reg_val & (1<<28) ? "ET " : "",
  1556. reg_val & (1<<27) ? "ES " : "",
  1557. reg_val & (1<<26) ? "EE " : "",
  1558. reg_val & (1<<25) ? "EB " : "",
  1559. reg_val & (1<<24) ? "EI " : "",
  1560. reg_val & (1<<23) ? "E1 " : "",
  1561. reg_val & (1<<22) ? "E0 " : "");
  1562. } else {
  1563. pr_err("Error bits: %s%s%s%s%s%s%s\n",
  1564. reg_val & (1<<29) ? "ED " : "",
  1565. reg_val & (1<<28) ? "ET " : "",
  1566. reg_val & (1<<26) ? "EE " : "",
  1567. reg_val & (1<<25) ? "EB " : "",
  1568. reg_val & (1<<24) ? "EI " : "",
  1569. reg_val & (1<<23) ? "E1 " : "",
  1570. reg_val & (1<<22) ? "E0 " : "");
  1571. }
  1572. printk("IDX: 0x%08x\n", reg_val & ((1<<22)-1));
  1573. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  1574. if (reg_val & (1<<22))
  1575. printk("DErrAddr0: 0x%0*lx\n", field, read_c0_derraddr0());
  1576. if (reg_val & (1<<23))
  1577. printk("DErrAddr1: 0x%0*lx\n", field, read_c0_derraddr1());
  1578. #endif
  1579. panic("Can't handle the cache error!");
  1580. }
  1581. asmlinkage void do_ftlb(void)
  1582. {
  1583. const int field = 2 * sizeof(unsigned long);
  1584. unsigned int reg_val;
  1585. /* For the moment, report the problem and hang. */
  1586. if ((cpu_has_mips_r2_r6) &&
  1587. (((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_MIPS) ||
  1588. ((current_cpu_data.processor_id & 0xff0000) == PRID_COMP_LOONGSON))) {
  1589. pr_err("FTLB error exception, cp0_ecc=0x%08x:\n",
  1590. read_c0_ecc());
  1591. pr_err("cp0_errorepc == %0*lx\n", field, read_c0_errorepc());
  1592. reg_val = read_c0_cacheerr();
  1593. pr_err("c0_cacheerr == %08x\n", reg_val);
  1594. if ((reg_val & 0xc0000000) == 0xc0000000) {
  1595. pr_err("Decoded c0_cacheerr: FTLB parity error\n");
  1596. } else {
  1597. pr_err("Decoded c0_cacheerr: %s cache fault in %s reference.\n",
  1598. reg_val & (1<<30) ? "secondary" : "primary",
  1599. reg_val & (1<<31) ? "data" : "insn");
  1600. }
  1601. } else {
  1602. pr_err("FTLB error exception\n");
  1603. }
  1604. /* Just print the cacheerr bits for now */
  1605. cache_parity_error();
  1606. }
  1607. /*
  1608. * SDBBP EJTAG debug exception handler.
  1609. * We skip the instruction and return to the next instruction.
  1610. */
  1611. void ejtag_exception_handler(struct pt_regs *regs)
  1612. {
  1613. const int field = 2 * sizeof(unsigned long);
  1614. unsigned long depc, old_epc, old_ra;
  1615. unsigned int debug;
  1616. printk(KERN_DEBUG "SDBBP EJTAG debug exception - not handled yet, just ignored!\n");
  1617. depc = read_c0_depc();
  1618. debug = read_c0_debug();
  1619. printk(KERN_DEBUG "c0_depc = %0*lx, DEBUG = %08x\n", field, depc, debug);
  1620. if (debug & 0x80000000) {
  1621. /*
  1622. * In branch delay slot.
  1623. * We cheat a little bit here and use EPC to calculate the
  1624. * debug return address (DEPC). EPC is restored after the
  1625. * calculation.
  1626. */
  1627. old_epc = regs->cp0_epc;
  1628. old_ra = regs->regs[31];
  1629. regs->cp0_epc = depc;
  1630. compute_return_epc(regs);
  1631. depc = regs->cp0_epc;
  1632. regs->cp0_epc = old_epc;
  1633. regs->regs[31] = old_ra;
  1634. } else
  1635. depc += 4;
  1636. write_c0_depc(depc);
  1637. #if 0
  1638. printk(KERN_DEBUG "\n\n----- Enable EJTAG single stepping ----\n\n");
  1639. write_c0_debug(debug | 0x100);
  1640. #endif
  1641. }
  1642. /*
  1643. * NMI exception handler.
  1644. * No lock; only written during early bootup by CPU 0.
  1645. */
  1646. static RAW_NOTIFIER_HEAD(nmi_chain);
  1647. int register_nmi_notifier(struct notifier_block *nb)
  1648. {
  1649. return raw_notifier_chain_register(&nmi_chain, nb);
  1650. }
  1651. void __noreturn nmi_exception_handler(struct pt_regs *regs)
  1652. {
  1653. char str[100];
  1654. nmi_enter();
  1655. raw_notifier_call_chain(&nmi_chain, 0, regs);
  1656. bust_spinlocks(1);
  1657. snprintf(str, 100, "CPU%d NMI taken, CP0_EPC=%lx\n",
  1658. smp_processor_id(), regs->cp0_epc);
  1659. regs->cp0_epc = read_c0_errorepc();
  1660. die(str, regs);
  1661. nmi_exit();
  1662. }
  1663. #define VECTORSPACING 0x100 /* for EI/VI mode */
  1664. unsigned long ebase;
  1665. EXPORT_SYMBOL_GPL(ebase);
  1666. unsigned long exception_handlers[32];
  1667. unsigned long vi_handlers[64];
  1668. void __init *set_except_vector(int n, void *addr)
  1669. {
  1670. unsigned long handler = (unsigned long) addr;
  1671. unsigned long old_handler;
  1672. #ifdef CONFIG_CPU_MICROMIPS
  1673. /*
  1674. * Only the TLB handlers are cache aligned with an even
  1675. * address. All other handlers are on an odd address and
  1676. * require no modification. Otherwise, MIPS32 mode will
  1677. * be entered when handling any TLB exceptions. That
  1678. * would be bad...since we must stay in microMIPS mode.
  1679. */
  1680. if (!(handler & 0x1))
  1681. handler |= 1;
  1682. #endif
  1683. old_handler = xchg(&exception_handlers[n], handler);
  1684. if (n == 0 && cpu_has_divec) {
  1685. #ifdef CONFIG_CPU_MICROMIPS
  1686. unsigned long jump_mask = ~((1 << 27) - 1);
  1687. #else
  1688. unsigned long jump_mask = ~((1 << 28) - 1);
  1689. #endif
  1690. u32 *buf = (u32 *)(ebase + 0x200);
  1691. unsigned int k0 = 26;
  1692. if ((handler & jump_mask) == ((ebase + 0x200) & jump_mask)) {
  1693. uasm_i_j(&buf, handler & ~jump_mask);
  1694. uasm_i_nop(&buf);
  1695. } else {
  1696. UASM_i_LA(&buf, k0, handler);
  1697. uasm_i_jr(&buf, k0);
  1698. uasm_i_nop(&buf);
  1699. }
  1700. local_flush_icache_range(ebase + 0x200, (unsigned long)buf);
  1701. }
  1702. return (void *)old_handler;
  1703. }
  1704. static void do_default_vi(void)
  1705. {
  1706. show_regs(get_irq_regs());
  1707. panic("Caught unexpected vectored interrupt.");
  1708. }
  1709. static void *set_vi_srs_handler(int n, vi_handler_t addr, int srs)
  1710. {
  1711. unsigned long handler;
  1712. unsigned long old_handler = vi_handlers[n];
  1713. int srssets = current_cpu_data.srsets;
  1714. u16 *h;
  1715. unsigned char *b;
  1716. BUG_ON(!cpu_has_veic && !cpu_has_vint);
  1717. if (addr == NULL) {
  1718. handler = (unsigned long) do_default_vi;
  1719. srs = 0;
  1720. } else
  1721. handler = (unsigned long) addr;
  1722. vi_handlers[n] = handler;
  1723. b = (unsigned char *)(ebase + 0x200 + n*VECTORSPACING);
  1724. if (srs >= srssets)
  1725. panic("Shadow register set %d not supported", srs);
  1726. if (cpu_has_veic) {
  1727. if (board_bind_eic_interrupt)
  1728. board_bind_eic_interrupt(n, srs);
  1729. } else if (cpu_has_vint) {
  1730. /* SRSMap is only defined if shadow sets are implemented */
  1731. if (srssets > 1)
  1732. change_c0_srsmap(0xf << n*4, srs << n*4);
  1733. }
  1734. if (srs == 0) {
  1735. /*
  1736. * If no shadow set is selected then use the default handler
  1737. * that does normal register saving and standard interrupt exit
  1738. */
  1739. extern char except_vec_vi, except_vec_vi_lui;
  1740. extern char except_vec_vi_ori, except_vec_vi_end;
  1741. extern char rollback_except_vec_vi;
  1742. char *vec_start = using_rollback_handler() ?
  1743. &rollback_except_vec_vi : &except_vec_vi;
  1744. #if defined(CONFIG_CPU_MICROMIPS) || defined(CONFIG_CPU_BIG_ENDIAN)
  1745. const int lui_offset = &except_vec_vi_lui - vec_start + 2;
  1746. const int ori_offset = &except_vec_vi_ori - vec_start + 2;
  1747. #else
  1748. const int lui_offset = &except_vec_vi_lui - vec_start;
  1749. const int ori_offset = &except_vec_vi_ori - vec_start;
  1750. #endif
  1751. const int handler_len = &except_vec_vi_end - vec_start;
  1752. if (handler_len > VECTORSPACING) {
  1753. /*
  1754. * Sigh... panicing won't help as the console
  1755. * is probably not configured :(
  1756. */
  1757. panic("VECTORSPACING too small");
  1758. }
  1759. set_handler(((unsigned long)b - ebase), vec_start,
  1760. #ifdef CONFIG_CPU_MICROMIPS
  1761. (handler_len - 1));
  1762. #else
  1763. handler_len);
  1764. #endif
  1765. h = (u16 *)(b + lui_offset);
  1766. *h = (handler >> 16) & 0xffff;
  1767. h = (u16 *)(b + ori_offset);
  1768. *h = (handler & 0xffff);
  1769. local_flush_icache_range((unsigned long)b,
  1770. (unsigned long)(b+handler_len));
  1771. }
  1772. else {
  1773. /*
  1774. * In other cases jump directly to the interrupt handler. It
  1775. * is the handler's responsibility to save registers if required
  1776. * (eg hi/lo) and return from the exception using "eret".
  1777. */
  1778. u32 insn;
  1779. h = (u16 *)b;
  1780. /* j handler */
  1781. #ifdef CONFIG_CPU_MICROMIPS
  1782. insn = 0xd4000000 | (((u32)handler & 0x07ffffff) >> 1);
  1783. #else
  1784. insn = 0x08000000 | (((u32)handler & 0x0fffffff) >> 2);
  1785. #endif
  1786. h[0] = (insn >> 16) & 0xffff;
  1787. h[1] = insn & 0xffff;
  1788. h[2] = 0;
  1789. h[3] = 0;
  1790. local_flush_icache_range((unsigned long)b,
  1791. (unsigned long)(b+8));
  1792. }
  1793. return (void *)old_handler;
  1794. }
  1795. void *set_vi_handler(int n, vi_handler_t addr)
  1796. {
  1797. return set_vi_srs_handler(n, addr, 0);
  1798. }
  1799. extern void tlb_init(void);
  1800. /*
  1801. * Timer interrupt
  1802. */
  1803. int cp0_compare_irq;
  1804. EXPORT_SYMBOL_GPL(cp0_compare_irq);
  1805. int cp0_compare_irq_shift;
  1806. /*
  1807. * Performance counter IRQ or -1 if shared with timer
  1808. */
  1809. int cp0_perfcount_irq;
  1810. EXPORT_SYMBOL_GPL(cp0_perfcount_irq);
  1811. /*
  1812. * Fast debug channel IRQ or -1 if not present
  1813. */
  1814. int cp0_fdc_irq;
  1815. EXPORT_SYMBOL_GPL(cp0_fdc_irq);
  1816. static int noulri;
  1817. static int __init ulri_disable(char *s)
  1818. {
  1819. pr_info("Disabling ulri\n");
  1820. noulri = 1;
  1821. return 1;
  1822. }
  1823. __setup("noulri", ulri_disable);
  1824. /* configure STATUS register */
  1825. static void configure_status(void)
  1826. {
  1827. /*
  1828. * Disable coprocessors and select 32-bit or 64-bit addressing
  1829. * and the 16/32 or 32/32 FPR register model. Reset the BEV
  1830. * flag that some firmware may have left set and the TS bit (for
  1831. * IP27). Set XX for ISA IV code to work.
  1832. */
  1833. unsigned int status_set = ST0_CU0;
  1834. #ifdef CONFIG_64BIT
  1835. status_set |= ST0_FR|ST0_KX|ST0_SX|ST0_UX;
  1836. #endif
  1837. if (current_cpu_data.isa_level & MIPS_CPU_ISA_IV)
  1838. status_set |= ST0_XX;
  1839. if (cpu_has_dsp)
  1840. status_set |= ST0_MX;
  1841. change_c0_status(ST0_CU|ST0_MX|ST0_RE|ST0_FR|ST0_BEV|ST0_TS|ST0_KX|ST0_SX|ST0_UX,
  1842. status_set);
  1843. }
  1844. unsigned int hwrena;
  1845. EXPORT_SYMBOL_GPL(hwrena);
  1846. /* configure HWRENA register */
  1847. static void configure_hwrena(void)
  1848. {
  1849. hwrena = cpu_hwrena_impl_bits;
  1850. if (cpu_has_mips_r2_r6)
  1851. hwrena |= MIPS_HWRENA_CPUNUM |
  1852. MIPS_HWRENA_SYNCISTEP |
  1853. MIPS_HWRENA_CC |
  1854. MIPS_HWRENA_CCRES;
  1855. if (!noulri && cpu_has_userlocal)
  1856. hwrena |= MIPS_HWRENA_ULR;
  1857. if (hwrena)
  1858. write_c0_hwrena(hwrena);
  1859. }
  1860. static void configure_exception_vector(void)
  1861. {
  1862. if (cpu_has_veic || cpu_has_vint) {
  1863. unsigned long sr = set_c0_status(ST0_BEV);
  1864. /* If available, use WG to set top bits of EBASE */
  1865. if (cpu_has_ebase_wg) {
  1866. #ifdef CONFIG_64BIT
  1867. write_c0_ebase_64(ebase | MIPS_EBASE_WG);
  1868. #else
  1869. write_c0_ebase(ebase | MIPS_EBASE_WG);
  1870. #endif
  1871. }
  1872. write_c0_ebase(ebase);
  1873. write_c0_status(sr);
  1874. /* Setting vector spacing enables EI/VI mode */
  1875. change_c0_intctl(0x3e0, VECTORSPACING);
  1876. }
  1877. if (cpu_has_divec) {
  1878. if (cpu_has_mipsmt) {
  1879. unsigned int vpflags = dvpe();
  1880. set_c0_cause(CAUSEF_IV);
  1881. evpe(vpflags);
  1882. } else
  1883. set_c0_cause(CAUSEF_IV);
  1884. }
  1885. }
  1886. void per_cpu_trap_init(bool is_boot_cpu)
  1887. {
  1888. unsigned int cpu = smp_processor_id();
  1889. configure_status();
  1890. configure_hwrena();
  1891. configure_exception_vector();
  1892. /*
  1893. * Before R2 both interrupt numbers were fixed to 7, so on R2 only:
  1894. *
  1895. * o read IntCtl.IPTI to determine the timer interrupt
  1896. * o read IntCtl.IPPCI to determine the performance counter interrupt
  1897. * o read IntCtl.IPFDC to determine the fast debug channel interrupt
  1898. */
  1899. if (cpu_has_mips_r2_r6) {
  1900. /*
  1901. * We shouldn't trust a secondary core has a sane EBASE register
  1902. * so use the one calculated by the boot CPU.
  1903. */
  1904. if (!is_boot_cpu) {
  1905. /* If available, use WG to set top bits of EBASE */
  1906. if (cpu_has_ebase_wg) {
  1907. #ifdef CONFIG_64BIT
  1908. write_c0_ebase_64(ebase | MIPS_EBASE_WG);
  1909. #else
  1910. write_c0_ebase(ebase | MIPS_EBASE_WG);
  1911. #endif
  1912. }
  1913. write_c0_ebase(ebase);
  1914. }
  1915. cp0_compare_irq_shift = CAUSEB_TI - CAUSEB_IP;
  1916. cp0_compare_irq = (read_c0_intctl() >> INTCTLB_IPTI) & 7;
  1917. cp0_perfcount_irq = (read_c0_intctl() >> INTCTLB_IPPCI) & 7;
  1918. cp0_fdc_irq = (read_c0_intctl() >> INTCTLB_IPFDC) & 7;
  1919. if (!cp0_fdc_irq)
  1920. cp0_fdc_irq = -1;
  1921. } else {
  1922. cp0_compare_irq = CP0_LEGACY_COMPARE_IRQ;
  1923. cp0_compare_irq_shift = CP0_LEGACY_PERFCNT_IRQ;
  1924. cp0_perfcount_irq = -1;
  1925. cp0_fdc_irq = -1;
  1926. }
  1927. if (!cpu_data[cpu].asid_cache)
  1928. cpu_data[cpu].asid_cache = asid_first_version(cpu);
  1929. mmgrab(&init_mm);
  1930. current->active_mm = &init_mm;
  1931. BUG_ON(current->mm);
  1932. enter_lazy_tlb(&init_mm, current);
  1933. /* Boot CPU's cache setup in setup_arch(). */
  1934. if (!is_boot_cpu)
  1935. cpu_cache_init();
  1936. tlb_init();
  1937. TLBMISS_HANDLER_SETUP();
  1938. }
  1939. /* Install CPU exception handler */
  1940. void set_handler(unsigned long offset, void *addr, unsigned long size)
  1941. {
  1942. #ifdef CONFIG_CPU_MICROMIPS
  1943. memcpy((void *)(ebase + offset), ((unsigned char *)addr - 1), size);
  1944. #else
  1945. memcpy((void *)(ebase + offset), addr, size);
  1946. #endif
  1947. local_flush_icache_range(ebase + offset, ebase + offset + size);
  1948. }
  1949. static const char panic_null_cerr[] =
  1950. "Trying to set NULL cache error exception handler\n";
  1951. /*
  1952. * Install uncached CPU exception handler.
  1953. * This is suitable only for the cache error exception which is the only
  1954. * exception handler that is being run uncached.
  1955. */
  1956. void set_uncached_handler(unsigned long offset, void *addr,
  1957. unsigned long size)
  1958. {
  1959. unsigned long uncached_ebase = CKSEG1ADDR(ebase);
  1960. if (!addr)
  1961. panic(panic_null_cerr);
  1962. memcpy((void *)(uncached_ebase + offset), addr, size);
  1963. }
  1964. static int __initdata rdhwr_noopt;
  1965. static int __init set_rdhwr_noopt(char *str)
  1966. {
  1967. rdhwr_noopt = 1;
  1968. return 1;
  1969. }
  1970. __setup("rdhwr_noopt", set_rdhwr_noopt);
  1971. void __init trap_init(void)
  1972. {
  1973. extern char except_vec3_generic;
  1974. extern char except_vec4;
  1975. extern char except_vec3_r4000;
  1976. unsigned long i;
  1977. check_wait();
  1978. if (cpu_has_veic || cpu_has_vint) {
  1979. unsigned long size = 0x200 + VECTORSPACING*64;
  1980. phys_addr_t ebase_pa;
  1981. ebase = (unsigned long)
  1982. __alloc_bootmem(size, 1 << fls(size), 0);
  1983. /*
  1984. * Try to ensure ebase resides in KSeg0 if possible.
  1985. *
  1986. * It shouldn't generally be in XKPhys on MIPS64 to avoid
  1987. * hitting a poorly defined exception base for Cache Errors.
  1988. * The allocation is likely to be in the low 512MB of physical,
  1989. * in which case we should be able to convert to KSeg0.
  1990. *
  1991. * EVA is special though as it allows segments to be rearranged
  1992. * and to become uncached during cache error handling.
  1993. */
  1994. ebase_pa = __pa(ebase);
  1995. if (!IS_ENABLED(CONFIG_EVA) && !WARN_ON(ebase_pa >= 0x20000000))
  1996. ebase = CKSEG0ADDR(ebase_pa);
  1997. } else {
  1998. ebase = CAC_BASE;
  1999. if (cpu_has_mips_r2_r6) {
  2000. if (cpu_has_ebase_wg) {
  2001. #ifdef CONFIG_64BIT
  2002. ebase = (read_c0_ebase_64() & ~0xfff);
  2003. #else
  2004. ebase = (read_c0_ebase() & ~0xfff);
  2005. #endif
  2006. } else {
  2007. ebase += (read_c0_ebase() & 0x3ffff000);
  2008. }
  2009. }
  2010. }
  2011. if (cpu_has_mmips) {
  2012. unsigned int config3 = read_c0_config3();
  2013. if (IS_ENABLED(CONFIG_CPU_MICROMIPS))
  2014. write_c0_config3(config3 | MIPS_CONF3_ISA_OE);
  2015. else
  2016. write_c0_config3(config3 & ~MIPS_CONF3_ISA_OE);
  2017. }
  2018. if (board_ebase_setup)
  2019. board_ebase_setup();
  2020. per_cpu_trap_init(true);
  2021. /*
  2022. * Copy the generic exception handlers to their final destination.
  2023. * This will be overridden later as suitable for a particular
  2024. * configuration.
  2025. */
  2026. set_handler(0x180, &except_vec3_generic, 0x80);
  2027. /*
  2028. * Setup default vectors
  2029. */
  2030. for (i = 0; i <= 31; i++)
  2031. set_except_vector(i, handle_reserved);
  2032. /*
  2033. * Copy the EJTAG debug exception vector handler code to it's final
  2034. * destination.
  2035. */
  2036. if (cpu_has_ejtag && board_ejtag_handler_setup)
  2037. board_ejtag_handler_setup();
  2038. /*
  2039. * Only some CPUs have the watch exceptions.
  2040. */
  2041. if (cpu_has_watch)
  2042. set_except_vector(EXCCODE_WATCH, handle_watch);
  2043. /*
  2044. * Initialise interrupt handlers
  2045. */
  2046. if (cpu_has_veic || cpu_has_vint) {
  2047. int nvec = cpu_has_veic ? 64 : 8;
  2048. for (i = 0; i < nvec; i++)
  2049. set_vi_handler(i, NULL);
  2050. }
  2051. else if (cpu_has_divec)
  2052. set_handler(0x200, &except_vec4, 0x8);
  2053. /*
  2054. * Some CPUs can enable/disable for cache parity detection, but does
  2055. * it different ways.
  2056. */
  2057. parity_protection_init();
  2058. /*
  2059. * The Data Bus Errors / Instruction Bus Errors are signaled
  2060. * by external hardware. Therefore these two exceptions
  2061. * may have board specific handlers.
  2062. */
  2063. if (board_be_init)
  2064. board_be_init();
  2065. set_except_vector(EXCCODE_INT, using_rollback_handler() ?
  2066. rollback_handle_int : handle_int);
  2067. set_except_vector(EXCCODE_MOD, handle_tlbm);
  2068. set_except_vector(EXCCODE_TLBL, handle_tlbl);
  2069. set_except_vector(EXCCODE_TLBS, handle_tlbs);
  2070. set_except_vector(EXCCODE_ADEL, handle_adel);
  2071. set_except_vector(EXCCODE_ADES, handle_ades);
  2072. set_except_vector(EXCCODE_IBE, handle_ibe);
  2073. set_except_vector(EXCCODE_DBE, handle_dbe);
  2074. set_except_vector(EXCCODE_SYS, handle_sys);
  2075. set_except_vector(EXCCODE_BP, handle_bp);
  2076. if (rdhwr_noopt)
  2077. set_except_vector(EXCCODE_RI, handle_ri);
  2078. else {
  2079. if (cpu_has_vtag_icache)
  2080. set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp);
  2081. else if (current_cpu_type() == CPU_LOONGSON3)
  2082. set_except_vector(EXCCODE_RI, handle_ri_rdhwr_tlbp);
  2083. else
  2084. set_except_vector(EXCCODE_RI, handle_ri_rdhwr);
  2085. }
  2086. set_except_vector(EXCCODE_CPU, handle_cpu);
  2087. set_except_vector(EXCCODE_OV, handle_ov);
  2088. set_except_vector(EXCCODE_TR, handle_tr);
  2089. set_except_vector(EXCCODE_MSAFPE, handle_msa_fpe);
  2090. if (current_cpu_type() == CPU_R6000 ||
  2091. current_cpu_type() == CPU_R6000A) {
  2092. /*
  2093. * The R6000 is the only R-series CPU that features a machine
  2094. * check exception (similar to the R4000 cache error) and
  2095. * unaligned ldc1/sdc1 exception. The handlers have not been
  2096. * written yet. Well, anyway there is no R6000 machine on the
  2097. * current list of targets for Linux/MIPS.
  2098. * (Duh, crap, there is someone with a triple R6k machine)
  2099. */
  2100. //set_except_vector(14, handle_mc);
  2101. //set_except_vector(15, handle_ndc);
  2102. }
  2103. if (board_nmi_handler_setup)
  2104. board_nmi_handler_setup();
  2105. if (cpu_has_fpu && !cpu_has_nofpuex)
  2106. set_except_vector(EXCCODE_FPE, handle_fpe);
  2107. set_except_vector(MIPS_EXCCODE_TLBPAR, handle_ftlb);
  2108. if (cpu_has_rixiex) {
  2109. set_except_vector(EXCCODE_TLBRI, tlb_do_page_fault_0);
  2110. set_except_vector(EXCCODE_TLBXI, tlb_do_page_fault_0);
  2111. }
  2112. set_except_vector(EXCCODE_MSADIS, handle_msa);
  2113. set_except_vector(EXCCODE_MDMX, handle_mdmx);
  2114. if (cpu_has_mcheck)
  2115. set_except_vector(EXCCODE_MCHECK, handle_mcheck);
  2116. if (cpu_has_mipsmt)
  2117. set_except_vector(EXCCODE_THREAD, handle_mt);
  2118. set_except_vector(EXCCODE_DSPDIS, handle_dsp);
  2119. if (board_cache_error_setup)
  2120. board_cache_error_setup();
  2121. if (cpu_has_vce)
  2122. /* Special exception: R4[04]00 uses also the divec space. */
  2123. set_handler(0x180, &except_vec3_r4000, 0x100);
  2124. else if (cpu_has_4kex)
  2125. set_handler(0x180, &except_vec3_generic, 0x80);
  2126. else
  2127. set_handler(0x080, &except_vec3_generic, 0x80);
  2128. local_flush_icache_range(ebase, ebase + 0x400);
  2129. sort_extable(__start___dbe_table, __stop___dbe_table);
  2130. cu2_notifier(default_cu2_call, 0x80000000); /* Run last */
  2131. }
  2132. static int trap_pm_notifier(struct notifier_block *self, unsigned long cmd,
  2133. void *v)
  2134. {
  2135. switch (cmd) {
  2136. case CPU_PM_ENTER_FAILED:
  2137. case CPU_PM_EXIT:
  2138. configure_status();
  2139. configure_hwrena();
  2140. configure_exception_vector();
  2141. /* Restore register with CPU number for TLB handlers */
  2142. TLBMISS_HANDLER_RESTORE();
  2143. break;
  2144. }
  2145. return NOTIFY_OK;
  2146. }
  2147. static struct notifier_block trap_pm_notifier_block = {
  2148. .notifier_call = trap_pm_notifier,
  2149. };
  2150. static int __init trap_pm_init(void)
  2151. {
  2152. return cpu_pm_register_notifier(&trap_pm_notifier_block);
  2153. }
  2154. arch_initcall(trap_pm_init);