traps.c 61 KB

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