traps.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815
  1. /*
  2. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  3. * Copyright 2007-2010 Freescale Semiconductor, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. *
  10. * Modified by Cort Dougan (cort@cs.nmt.edu)
  11. * and Paul Mackerras (paulus@samba.org)
  12. */
  13. /*
  14. * This file handles the architecture-dependent parts of hardware exceptions
  15. */
  16. #include <linux/errno.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/stddef.h>
  21. #include <linux/unistd.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/user.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/prctl.h>
  28. #include <linux/delay.h>
  29. #include <linux/kprobes.h>
  30. #include <linux/kexec.h>
  31. #include <linux/backlight.h>
  32. #include <linux/bug.h>
  33. #include <linux/kdebug.h>
  34. #include <linux/debugfs.h>
  35. #include <linux/ratelimit.h>
  36. #include <linux/context_tracking.h>
  37. #include <asm/emulated_ops.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/io.h>
  41. #include <asm/machdep.h>
  42. #include <asm/rtas.h>
  43. #include <asm/pmc.h>
  44. #ifdef CONFIG_PPC32
  45. #include <asm/reg.h>
  46. #endif
  47. #ifdef CONFIG_PMAC_BACKLIGHT
  48. #include <asm/backlight.h>
  49. #endif
  50. #ifdef CONFIG_PPC64
  51. #include <asm/firmware.h>
  52. #include <asm/processor.h>
  53. #endif
  54. #include <asm/kexec.h>
  55. #include <asm/ppc-opcode.h>
  56. #include <asm/rio.h>
  57. #include <asm/fadump.h>
  58. #include <asm/switch_to.h>
  59. #include <asm/tm.h>
  60. #include <asm/debug.h>
  61. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  62. int (*__debugger)(struct pt_regs *regs) __read_mostly;
  63. int (*__debugger_ipi)(struct pt_regs *regs) __read_mostly;
  64. int (*__debugger_bpt)(struct pt_regs *regs) __read_mostly;
  65. int (*__debugger_sstep)(struct pt_regs *regs) __read_mostly;
  66. int (*__debugger_iabr_match)(struct pt_regs *regs) __read_mostly;
  67. int (*__debugger_break_match)(struct pt_regs *regs) __read_mostly;
  68. int (*__debugger_fault_handler)(struct pt_regs *regs) __read_mostly;
  69. EXPORT_SYMBOL(__debugger);
  70. EXPORT_SYMBOL(__debugger_ipi);
  71. EXPORT_SYMBOL(__debugger_bpt);
  72. EXPORT_SYMBOL(__debugger_sstep);
  73. EXPORT_SYMBOL(__debugger_iabr_match);
  74. EXPORT_SYMBOL(__debugger_break_match);
  75. EXPORT_SYMBOL(__debugger_fault_handler);
  76. #endif
  77. /* Transactional Memory trap debug */
  78. #ifdef TM_DEBUG_SW
  79. #define TM_DEBUG(x...) printk(KERN_INFO x)
  80. #else
  81. #define TM_DEBUG(x...) do { } while(0)
  82. #endif
  83. /*
  84. * Trap & Exception support
  85. */
  86. #ifdef CONFIG_PMAC_BACKLIGHT
  87. static void pmac_backlight_unblank(void)
  88. {
  89. mutex_lock(&pmac_backlight_mutex);
  90. if (pmac_backlight) {
  91. struct backlight_properties *props;
  92. props = &pmac_backlight->props;
  93. props->brightness = props->max_brightness;
  94. props->power = FB_BLANK_UNBLANK;
  95. backlight_update_status(pmac_backlight);
  96. }
  97. mutex_unlock(&pmac_backlight_mutex);
  98. }
  99. #else
  100. static inline void pmac_backlight_unblank(void) { }
  101. #endif
  102. static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
  103. static int die_owner = -1;
  104. static unsigned int die_nest_count;
  105. static int die_counter;
  106. static unsigned __kprobes long oops_begin(struct pt_regs *regs)
  107. {
  108. int cpu;
  109. unsigned long flags;
  110. if (debugger(regs))
  111. return 1;
  112. oops_enter();
  113. /* racy, but better than risking deadlock. */
  114. raw_local_irq_save(flags);
  115. cpu = smp_processor_id();
  116. if (!arch_spin_trylock(&die_lock)) {
  117. if (cpu == die_owner)
  118. /* nested oops. should stop eventually */;
  119. else
  120. arch_spin_lock(&die_lock);
  121. }
  122. die_nest_count++;
  123. die_owner = cpu;
  124. console_verbose();
  125. bust_spinlocks(1);
  126. if (machine_is(powermac))
  127. pmac_backlight_unblank();
  128. return flags;
  129. }
  130. static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
  131. int signr)
  132. {
  133. bust_spinlocks(0);
  134. die_owner = -1;
  135. add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  136. die_nest_count--;
  137. oops_exit();
  138. printk("\n");
  139. if (!die_nest_count)
  140. /* Nest count reaches zero, release the lock. */
  141. arch_spin_unlock(&die_lock);
  142. raw_local_irq_restore(flags);
  143. crash_fadump(regs, "die oops");
  144. /*
  145. * A system reset (0x100) is a request to dump, so we always send
  146. * it through the crashdump code.
  147. */
  148. if (kexec_should_crash(current) || (TRAP(regs) == 0x100)) {
  149. crash_kexec(regs);
  150. /*
  151. * We aren't the primary crash CPU. We need to send it
  152. * to a holding pattern to avoid it ending up in the panic
  153. * code.
  154. */
  155. crash_kexec_secondary(regs);
  156. }
  157. if (!signr)
  158. return;
  159. /*
  160. * While our oops output is serialised by a spinlock, output
  161. * from panic() called below can race and corrupt it. If we
  162. * know we are going to panic, delay for 1 second so we have a
  163. * chance to get clean backtraces from all CPUs that are oopsing.
  164. */
  165. if (in_interrupt() || panic_on_oops || !current->pid ||
  166. is_global_init(current)) {
  167. mdelay(MSEC_PER_SEC);
  168. }
  169. if (in_interrupt())
  170. panic("Fatal exception in interrupt");
  171. if (panic_on_oops)
  172. panic("Fatal exception");
  173. do_exit(signr);
  174. }
  175. static int __kprobes __die(const char *str, struct pt_regs *regs, long err)
  176. {
  177. printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
  178. #ifdef CONFIG_PREEMPT
  179. printk("PREEMPT ");
  180. #endif
  181. #ifdef CONFIG_SMP
  182. printk("SMP NR_CPUS=%d ", NR_CPUS);
  183. #endif
  184. #ifdef CONFIG_DEBUG_PAGEALLOC
  185. printk("DEBUG_PAGEALLOC ");
  186. #endif
  187. #ifdef CONFIG_NUMA
  188. printk("NUMA ");
  189. #endif
  190. printk("%s\n", ppc_md.name ? ppc_md.name : "");
  191. if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP)
  192. return 1;
  193. print_modules();
  194. show_regs(regs);
  195. return 0;
  196. }
  197. void die(const char *str, struct pt_regs *regs, long err)
  198. {
  199. unsigned long flags = oops_begin(regs);
  200. if (__die(str, regs, err))
  201. err = 0;
  202. oops_end(flags, regs, err);
  203. }
  204. void user_single_step_siginfo(struct task_struct *tsk,
  205. struct pt_regs *regs, siginfo_t *info)
  206. {
  207. memset(info, 0, sizeof(*info));
  208. info->si_signo = SIGTRAP;
  209. info->si_code = TRAP_TRACE;
  210. info->si_addr = (void __user *)regs->nip;
  211. }
  212. void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
  213. {
  214. siginfo_t info;
  215. const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \
  216. "at %08lx nip %08lx lr %08lx code %x\n";
  217. const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \
  218. "at %016lx nip %016lx lr %016lx code %x\n";
  219. if (!user_mode(regs)) {
  220. die("Exception in kernel mode", regs, signr);
  221. return;
  222. }
  223. if (show_unhandled_signals && unhandled_signal(current, signr)) {
  224. printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32,
  225. current->comm, current->pid, signr,
  226. addr, regs->nip, regs->link, code);
  227. }
  228. if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs))
  229. local_irq_enable();
  230. current->thread.trap_nr = code;
  231. memset(&info, 0, sizeof(info));
  232. info.si_signo = signr;
  233. info.si_code = code;
  234. info.si_addr = (void __user *) addr;
  235. force_sig_info(signr, &info, current);
  236. }
  237. #ifdef CONFIG_PPC64
  238. void system_reset_exception(struct pt_regs *regs)
  239. {
  240. /* See if any machine dependent calls */
  241. if (ppc_md.system_reset_exception) {
  242. if (ppc_md.system_reset_exception(regs))
  243. return;
  244. }
  245. die("System Reset", regs, SIGABRT);
  246. /* Must die if the interrupt is not recoverable */
  247. if (!(regs->msr & MSR_RI))
  248. panic("Unrecoverable System Reset");
  249. /* What should we do here? We could issue a shutdown or hard reset. */
  250. }
  251. #endif
  252. /*
  253. * I/O accesses can cause machine checks on powermacs.
  254. * Check if the NIP corresponds to the address of a sync
  255. * instruction for which there is an entry in the exception
  256. * table.
  257. * Note that the 601 only takes a machine check on TEA
  258. * (transfer error ack) signal assertion, and does not
  259. * set any of the top 16 bits of SRR1.
  260. * -- paulus.
  261. */
  262. static inline int check_io_access(struct pt_regs *regs)
  263. {
  264. #ifdef CONFIG_PPC32
  265. unsigned long msr = regs->msr;
  266. const struct exception_table_entry *entry;
  267. unsigned int *nip = (unsigned int *)regs->nip;
  268. if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000)))
  269. && (entry = search_exception_tables(regs->nip)) != NULL) {
  270. /*
  271. * Check that it's a sync instruction, or somewhere
  272. * in the twi; isync; nop sequence that inb/inw/inl uses.
  273. * As the address is in the exception table
  274. * we should be able to read the instr there.
  275. * For the debug message, we look at the preceding
  276. * load or store.
  277. */
  278. if (*nip == 0x60000000) /* nop */
  279. nip -= 2;
  280. else if (*nip == 0x4c00012c) /* isync */
  281. --nip;
  282. if (*nip == 0x7c0004ac || (*nip >> 26) == 3) {
  283. /* sync or twi */
  284. unsigned int rb;
  285. --nip;
  286. rb = (*nip >> 11) & 0x1f;
  287. printk(KERN_DEBUG "%s bad port %lx at %p\n",
  288. (*nip & 0x100)? "OUT to": "IN from",
  289. regs->gpr[rb] - _IO_BASE, nip);
  290. regs->msr |= MSR_RI;
  291. regs->nip = entry->fixup;
  292. return 1;
  293. }
  294. }
  295. #endif /* CONFIG_PPC32 */
  296. return 0;
  297. }
  298. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  299. /* On 4xx, the reason for the machine check or program exception
  300. is in the ESR. */
  301. #define get_reason(regs) ((regs)->dsisr)
  302. #ifndef CONFIG_FSL_BOOKE
  303. #define get_mc_reason(regs) ((regs)->dsisr)
  304. #else
  305. #define get_mc_reason(regs) (mfspr(SPRN_MCSR))
  306. #endif
  307. #define REASON_FP ESR_FP
  308. #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
  309. #define REASON_PRIVILEGED ESR_PPR
  310. #define REASON_TRAP ESR_PTR
  311. /* single-step stuff */
  312. #define single_stepping(regs) (current->thread.dbcr0 & DBCR0_IC)
  313. #define clear_single_step(regs) (current->thread.dbcr0 &= ~DBCR0_IC)
  314. #else
  315. /* On non-4xx, the reason for the machine check or program
  316. exception is in the MSR. */
  317. #define get_reason(regs) ((regs)->msr)
  318. #define get_mc_reason(regs) ((regs)->msr)
  319. #define REASON_TM 0x200000
  320. #define REASON_FP 0x100000
  321. #define REASON_ILLEGAL 0x80000
  322. #define REASON_PRIVILEGED 0x40000
  323. #define REASON_TRAP 0x20000
  324. #define single_stepping(regs) ((regs)->msr & MSR_SE)
  325. #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
  326. #endif
  327. #if defined(CONFIG_4xx)
  328. int machine_check_4xx(struct pt_regs *regs)
  329. {
  330. unsigned long reason = get_mc_reason(regs);
  331. if (reason & ESR_IMCP) {
  332. printk("Instruction");
  333. mtspr(SPRN_ESR, reason & ~ESR_IMCP);
  334. } else
  335. printk("Data");
  336. printk(" machine check in kernel mode.\n");
  337. return 0;
  338. }
  339. int machine_check_440A(struct pt_regs *regs)
  340. {
  341. unsigned long reason = get_mc_reason(regs);
  342. printk("Machine check in kernel mode.\n");
  343. if (reason & ESR_IMCP){
  344. printk("Instruction Synchronous Machine Check exception\n");
  345. mtspr(SPRN_ESR, reason & ~ESR_IMCP);
  346. }
  347. else {
  348. u32 mcsr = mfspr(SPRN_MCSR);
  349. if (mcsr & MCSR_IB)
  350. printk("Instruction Read PLB Error\n");
  351. if (mcsr & MCSR_DRB)
  352. printk("Data Read PLB Error\n");
  353. if (mcsr & MCSR_DWB)
  354. printk("Data Write PLB Error\n");
  355. if (mcsr & MCSR_TLBP)
  356. printk("TLB Parity Error\n");
  357. if (mcsr & MCSR_ICP){
  358. flush_instruction_cache();
  359. printk("I-Cache Parity Error\n");
  360. }
  361. if (mcsr & MCSR_DCSP)
  362. printk("D-Cache Search Parity Error\n");
  363. if (mcsr & MCSR_DCFP)
  364. printk("D-Cache Flush Parity Error\n");
  365. if (mcsr & MCSR_IMPE)
  366. printk("Machine Check exception is imprecise\n");
  367. /* Clear MCSR */
  368. mtspr(SPRN_MCSR, mcsr);
  369. }
  370. return 0;
  371. }
  372. int machine_check_47x(struct pt_regs *regs)
  373. {
  374. unsigned long reason = get_mc_reason(regs);
  375. u32 mcsr;
  376. printk(KERN_ERR "Machine check in kernel mode.\n");
  377. if (reason & ESR_IMCP) {
  378. printk(KERN_ERR
  379. "Instruction Synchronous Machine Check exception\n");
  380. mtspr(SPRN_ESR, reason & ~ESR_IMCP);
  381. return 0;
  382. }
  383. mcsr = mfspr(SPRN_MCSR);
  384. if (mcsr & MCSR_IB)
  385. printk(KERN_ERR "Instruction Read PLB Error\n");
  386. if (mcsr & MCSR_DRB)
  387. printk(KERN_ERR "Data Read PLB Error\n");
  388. if (mcsr & MCSR_DWB)
  389. printk(KERN_ERR "Data Write PLB Error\n");
  390. if (mcsr & MCSR_TLBP)
  391. printk(KERN_ERR "TLB Parity Error\n");
  392. if (mcsr & MCSR_ICP) {
  393. flush_instruction_cache();
  394. printk(KERN_ERR "I-Cache Parity Error\n");
  395. }
  396. if (mcsr & MCSR_DCSP)
  397. printk(KERN_ERR "D-Cache Search Parity Error\n");
  398. if (mcsr & PPC47x_MCSR_GPR)
  399. printk(KERN_ERR "GPR Parity Error\n");
  400. if (mcsr & PPC47x_MCSR_FPR)
  401. printk(KERN_ERR "FPR Parity Error\n");
  402. if (mcsr & PPC47x_MCSR_IPR)
  403. printk(KERN_ERR "Machine Check exception is imprecise\n");
  404. /* Clear MCSR */
  405. mtspr(SPRN_MCSR, mcsr);
  406. return 0;
  407. }
  408. #elif defined(CONFIG_E500)
  409. int machine_check_e500mc(struct pt_regs *regs)
  410. {
  411. unsigned long mcsr = mfspr(SPRN_MCSR);
  412. unsigned long reason = mcsr;
  413. int recoverable = 1;
  414. if (reason & MCSR_LD) {
  415. recoverable = fsl_rio_mcheck_exception(regs);
  416. if (recoverable == 1)
  417. goto silent_out;
  418. }
  419. printk("Machine check in kernel mode.\n");
  420. printk("Caused by (from MCSR=%lx): ", reason);
  421. if (reason & MCSR_MCP)
  422. printk("Machine Check Signal\n");
  423. if (reason & MCSR_ICPERR) {
  424. printk("Instruction Cache Parity Error\n");
  425. /*
  426. * This is recoverable by invalidating the i-cache.
  427. */
  428. mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI);
  429. while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI)
  430. ;
  431. /*
  432. * This will generally be accompanied by an instruction
  433. * fetch error report -- only treat MCSR_IF as fatal
  434. * if it wasn't due to an L1 parity error.
  435. */
  436. reason &= ~MCSR_IF;
  437. }
  438. if (reason & MCSR_DCPERR_MC) {
  439. printk("Data Cache Parity Error\n");
  440. /*
  441. * In write shadow mode we auto-recover from the error, but it
  442. * may still get logged and cause a machine check. We should
  443. * only treat the non-write shadow case as non-recoverable.
  444. */
  445. if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS))
  446. recoverable = 0;
  447. }
  448. if (reason & MCSR_L2MMU_MHIT) {
  449. printk("Hit on multiple TLB entries\n");
  450. recoverable = 0;
  451. }
  452. if (reason & MCSR_NMI)
  453. printk("Non-maskable interrupt\n");
  454. if (reason & MCSR_IF) {
  455. printk("Instruction Fetch Error Report\n");
  456. recoverable = 0;
  457. }
  458. if (reason & MCSR_LD) {
  459. printk("Load Error Report\n");
  460. recoverable = 0;
  461. }
  462. if (reason & MCSR_ST) {
  463. printk("Store Error Report\n");
  464. recoverable = 0;
  465. }
  466. if (reason & MCSR_LDG) {
  467. printk("Guarded Load Error Report\n");
  468. recoverable = 0;
  469. }
  470. if (reason & MCSR_TLBSYNC)
  471. printk("Simultaneous tlbsync operations\n");
  472. if (reason & MCSR_BSL2_ERR) {
  473. printk("Level 2 Cache Error\n");
  474. recoverable = 0;
  475. }
  476. if (reason & MCSR_MAV) {
  477. u64 addr;
  478. addr = mfspr(SPRN_MCAR);
  479. addr |= (u64)mfspr(SPRN_MCARU) << 32;
  480. printk("Machine Check %s Address: %#llx\n",
  481. reason & MCSR_MEA ? "Effective" : "Physical", addr);
  482. }
  483. silent_out:
  484. mtspr(SPRN_MCSR, mcsr);
  485. return mfspr(SPRN_MCSR) == 0 && recoverable;
  486. }
  487. int machine_check_e500(struct pt_regs *regs)
  488. {
  489. unsigned long reason = get_mc_reason(regs);
  490. if (reason & MCSR_BUS_RBERR) {
  491. if (fsl_rio_mcheck_exception(regs))
  492. return 1;
  493. }
  494. printk("Machine check in kernel mode.\n");
  495. printk("Caused by (from MCSR=%lx): ", reason);
  496. if (reason & MCSR_MCP)
  497. printk("Machine Check Signal\n");
  498. if (reason & MCSR_ICPERR)
  499. printk("Instruction Cache Parity Error\n");
  500. if (reason & MCSR_DCP_PERR)
  501. printk("Data Cache Push Parity Error\n");
  502. if (reason & MCSR_DCPERR)
  503. printk("Data Cache Parity Error\n");
  504. if (reason & MCSR_BUS_IAERR)
  505. printk("Bus - Instruction Address Error\n");
  506. if (reason & MCSR_BUS_RAERR)
  507. printk("Bus - Read Address Error\n");
  508. if (reason & MCSR_BUS_WAERR)
  509. printk("Bus - Write Address Error\n");
  510. if (reason & MCSR_BUS_IBERR)
  511. printk("Bus - Instruction Data Error\n");
  512. if (reason & MCSR_BUS_RBERR)
  513. printk("Bus - Read Data Bus Error\n");
  514. if (reason & MCSR_BUS_WBERR)
  515. printk("Bus - Read Data Bus Error\n");
  516. if (reason & MCSR_BUS_IPERR)
  517. printk("Bus - Instruction Parity Error\n");
  518. if (reason & MCSR_BUS_RPERR)
  519. printk("Bus - Read Parity Error\n");
  520. return 0;
  521. }
  522. int machine_check_generic(struct pt_regs *regs)
  523. {
  524. return 0;
  525. }
  526. #elif defined(CONFIG_E200)
  527. int machine_check_e200(struct pt_regs *regs)
  528. {
  529. unsigned long reason = get_mc_reason(regs);
  530. printk("Machine check in kernel mode.\n");
  531. printk("Caused by (from MCSR=%lx): ", reason);
  532. if (reason & MCSR_MCP)
  533. printk("Machine Check Signal\n");
  534. if (reason & MCSR_CP_PERR)
  535. printk("Cache Push Parity Error\n");
  536. if (reason & MCSR_CPERR)
  537. printk("Cache Parity Error\n");
  538. if (reason & MCSR_EXCP_ERR)
  539. printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
  540. if (reason & MCSR_BUS_IRERR)
  541. printk("Bus - Read Bus Error on instruction fetch\n");
  542. if (reason & MCSR_BUS_DRERR)
  543. printk("Bus - Read Bus Error on data load\n");
  544. if (reason & MCSR_BUS_WRERR)
  545. printk("Bus - Write Bus Error on buffered store or cache line push\n");
  546. return 0;
  547. }
  548. #else
  549. int machine_check_generic(struct pt_regs *regs)
  550. {
  551. unsigned long reason = get_mc_reason(regs);
  552. printk("Machine check in kernel mode.\n");
  553. printk("Caused by (from SRR1=%lx): ", reason);
  554. switch (reason & 0x601F0000) {
  555. case 0x80000:
  556. printk("Machine check signal\n");
  557. break;
  558. case 0: /* for 601 */
  559. case 0x40000:
  560. case 0x140000: /* 7450 MSS error and TEA */
  561. printk("Transfer error ack signal\n");
  562. break;
  563. case 0x20000:
  564. printk("Data parity error signal\n");
  565. break;
  566. case 0x10000:
  567. printk("Address parity error signal\n");
  568. break;
  569. case 0x20000000:
  570. printk("L1 Data Cache error\n");
  571. break;
  572. case 0x40000000:
  573. printk("L1 Instruction Cache error\n");
  574. break;
  575. case 0x00100000:
  576. printk("L2 data cache parity error\n");
  577. break;
  578. default:
  579. printk("Unknown values in msr\n");
  580. }
  581. return 0;
  582. }
  583. #endif /* everything else */
  584. void machine_check_exception(struct pt_regs *regs)
  585. {
  586. enum ctx_state prev_state = exception_enter();
  587. int recover = 0;
  588. __get_cpu_var(irq_stat).mce_exceptions++;
  589. /* See if any machine dependent calls. In theory, we would want
  590. * to call the CPU first, and call the ppc_md. one if the CPU
  591. * one returns a positive number. However there is existing code
  592. * that assumes the board gets a first chance, so let's keep it
  593. * that way for now and fix things later. --BenH.
  594. */
  595. if (ppc_md.machine_check_exception)
  596. recover = ppc_md.machine_check_exception(regs);
  597. else if (cur_cpu_spec->machine_check)
  598. recover = cur_cpu_spec->machine_check(regs);
  599. if (recover > 0)
  600. goto bail;
  601. #if defined(CONFIG_8xx) && defined(CONFIG_PCI)
  602. /* the qspan pci read routines can cause machine checks -- Cort
  603. *
  604. * yuck !!! that totally needs to go away ! There are better ways
  605. * to deal with that than having a wart in the mcheck handler.
  606. * -- BenH
  607. */
  608. bad_page_fault(regs, regs->dar, SIGBUS);
  609. goto bail;
  610. #endif
  611. if (debugger_fault_handler(regs))
  612. goto bail;
  613. if (check_io_access(regs))
  614. goto bail;
  615. die("Machine check", regs, SIGBUS);
  616. /* Must die if the interrupt is not recoverable */
  617. if (!(regs->msr & MSR_RI))
  618. panic("Unrecoverable Machine check");
  619. bail:
  620. exception_exit(prev_state);
  621. }
  622. void SMIException(struct pt_regs *regs)
  623. {
  624. die("System Management Interrupt", regs, SIGABRT);
  625. }
  626. void unknown_exception(struct pt_regs *regs)
  627. {
  628. enum ctx_state prev_state = exception_enter();
  629. printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n",
  630. regs->nip, regs->msr, regs->trap);
  631. _exception(SIGTRAP, regs, 0, 0);
  632. exception_exit(prev_state);
  633. }
  634. void instruction_breakpoint_exception(struct pt_regs *regs)
  635. {
  636. enum ctx_state prev_state = exception_enter();
  637. if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5,
  638. 5, SIGTRAP) == NOTIFY_STOP)
  639. goto bail;
  640. if (debugger_iabr_match(regs))
  641. goto bail;
  642. _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
  643. bail:
  644. exception_exit(prev_state);
  645. }
  646. void RunModeException(struct pt_regs *regs)
  647. {
  648. _exception(SIGTRAP, regs, 0, 0);
  649. }
  650. void __kprobes single_step_exception(struct pt_regs *regs)
  651. {
  652. enum ctx_state prev_state = exception_enter();
  653. clear_single_step(regs);
  654. if (notify_die(DIE_SSTEP, "single_step", regs, 5,
  655. 5, SIGTRAP) == NOTIFY_STOP)
  656. goto bail;
  657. if (debugger_sstep(regs))
  658. goto bail;
  659. _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
  660. bail:
  661. exception_exit(prev_state);
  662. }
  663. /*
  664. * After we have successfully emulated an instruction, we have to
  665. * check if the instruction was being single-stepped, and if so,
  666. * pretend we got a single-step exception. This was pointed out
  667. * by Kumar Gala. -- paulus
  668. */
  669. static void emulate_single_step(struct pt_regs *regs)
  670. {
  671. if (single_stepping(regs))
  672. single_step_exception(regs);
  673. }
  674. static inline int __parse_fpscr(unsigned long fpscr)
  675. {
  676. int ret = 0;
  677. /* Invalid operation */
  678. if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX))
  679. ret = FPE_FLTINV;
  680. /* Overflow */
  681. else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX))
  682. ret = FPE_FLTOVF;
  683. /* Underflow */
  684. else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX))
  685. ret = FPE_FLTUND;
  686. /* Divide by zero */
  687. else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX))
  688. ret = FPE_FLTDIV;
  689. /* Inexact result */
  690. else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX))
  691. ret = FPE_FLTRES;
  692. return ret;
  693. }
  694. static void parse_fpe(struct pt_regs *regs)
  695. {
  696. int code = 0;
  697. flush_fp_to_thread(current);
  698. code = __parse_fpscr(current->thread.fpscr.val);
  699. _exception(SIGFPE, regs, code, regs->nip);
  700. }
  701. /*
  702. * Illegal instruction emulation support. Originally written to
  703. * provide the PVR to user applications using the mfspr rd, PVR.
  704. * Return non-zero if we can't emulate, or -EFAULT if the associated
  705. * memory access caused an access fault. Return zero on success.
  706. *
  707. * There are a couple of ways to do this, either "decode" the instruction
  708. * or directly match lots of bits. In this case, matching lots of
  709. * bits is faster and easier.
  710. *
  711. */
  712. static int emulate_string_inst(struct pt_regs *regs, u32 instword)
  713. {
  714. u8 rT = (instword >> 21) & 0x1f;
  715. u8 rA = (instword >> 16) & 0x1f;
  716. u8 NB_RB = (instword >> 11) & 0x1f;
  717. u32 num_bytes;
  718. unsigned long EA;
  719. int pos = 0;
  720. /* Early out if we are an invalid form of lswx */
  721. if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX)
  722. if ((rT == rA) || (rT == NB_RB))
  723. return -EINVAL;
  724. EA = (rA == 0) ? 0 : regs->gpr[rA];
  725. switch (instword & PPC_INST_STRING_MASK) {
  726. case PPC_INST_LSWX:
  727. case PPC_INST_STSWX:
  728. EA += NB_RB;
  729. num_bytes = regs->xer & 0x7f;
  730. break;
  731. case PPC_INST_LSWI:
  732. case PPC_INST_STSWI:
  733. num_bytes = (NB_RB == 0) ? 32 : NB_RB;
  734. break;
  735. default:
  736. return -EINVAL;
  737. }
  738. while (num_bytes != 0)
  739. {
  740. u8 val;
  741. u32 shift = 8 * (3 - (pos & 0x3));
  742. switch ((instword & PPC_INST_STRING_MASK)) {
  743. case PPC_INST_LSWX:
  744. case PPC_INST_LSWI:
  745. if (get_user(val, (u8 __user *)EA))
  746. return -EFAULT;
  747. /* first time updating this reg,
  748. * zero it out */
  749. if (pos == 0)
  750. regs->gpr[rT] = 0;
  751. regs->gpr[rT] |= val << shift;
  752. break;
  753. case PPC_INST_STSWI:
  754. case PPC_INST_STSWX:
  755. val = regs->gpr[rT] >> shift;
  756. if (put_user(val, (u8 __user *)EA))
  757. return -EFAULT;
  758. break;
  759. }
  760. /* move EA to next address */
  761. EA += 1;
  762. num_bytes--;
  763. /* manage our position within the register */
  764. if (++pos == 4) {
  765. pos = 0;
  766. if (++rT == 32)
  767. rT = 0;
  768. }
  769. }
  770. return 0;
  771. }
  772. static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword)
  773. {
  774. u32 ra,rs;
  775. unsigned long tmp;
  776. ra = (instword >> 16) & 0x1f;
  777. rs = (instword >> 21) & 0x1f;
  778. tmp = regs->gpr[rs];
  779. tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL);
  780. tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL);
  781. tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL;
  782. regs->gpr[ra] = tmp;
  783. return 0;
  784. }
  785. static int emulate_isel(struct pt_regs *regs, u32 instword)
  786. {
  787. u8 rT = (instword >> 21) & 0x1f;
  788. u8 rA = (instword >> 16) & 0x1f;
  789. u8 rB = (instword >> 11) & 0x1f;
  790. u8 BC = (instword >> 6) & 0x1f;
  791. u8 bit;
  792. unsigned long tmp;
  793. tmp = (rA == 0) ? 0 : regs->gpr[rA];
  794. bit = (regs->ccr >> (31 - BC)) & 0x1;
  795. regs->gpr[rT] = bit ? tmp : regs->gpr[rB];
  796. return 0;
  797. }
  798. static int emulate_instruction(struct pt_regs *regs)
  799. {
  800. u32 instword;
  801. u32 rd;
  802. if (!user_mode(regs) || (regs->msr & MSR_LE))
  803. return -EINVAL;
  804. CHECK_FULL_REGS(regs);
  805. if (get_user(instword, (u32 __user *)(regs->nip)))
  806. return -EFAULT;
  807. /* Emulate the mfspr rD, PVR. */
  808. if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) {
  809. PPC_WARN_EMULATED(mfpvr, regs);
  810. rd = (instword >> 21) & 0x1f;
  811. regs->gpr[rd] = mfspr(SPRN_PVR);
  812. return 0;
  813. }
  814. /* Emulating the dcba insn is just a no-op. */
  815. if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) {
  816. PPC_WARN_EMULATED(dcba, regs);
  817. return 0;
  818. }
  819. /* Emulate the mcrxr insn. */
  820. if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) {
  821. int shift = (instword >> 21) & 0x1c;
  822. unsigned long msk = 0xf0000000UL >> shift;
  823. PPC_WARN_EMULATED(mcrxr, regs);
  824. regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk);
  825. regs->xer &= ~0xf0000000UL;
  826. return 0;
  827. }
  828. /* Emulate load/store string insn. */
  829. if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) {
  830. PPC_WARN_EMULATED(string, regs);
  831. return emulate_string_inst(regs, instword);
  832. }
  833. /* Emulate the popcntb (Population Count Bytes) instruction. */
  834. if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) {
  835. PPC_WARN_EMULATED(popcntb, regs);
  836. return emulate_popcntb_inst(regs, instword);
  837. }
  838. /* Emulate isel (Integer Select) instruction */
  839. if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) {
  840. PPC_WARN_EMULATED(isel, regs);
  841. return emulate_isel(regs, instword);
  842. }
  843. #ifdef CONFIG_PPC64
  844. /* Emulate the mfspr rD, DSCR. */
  845. if ((((instword & PPC_INST_MFSPR_DSCR_USER_MASK) ==
  846. PPC_INST_MFSPR_DSCR_USER) ||
  847. ((instword & PPC_INST_MFSPR_DSCR_MASK) ==
  848. PPC_INST_MFSPR_DSCR)) &&
  849. cpu_has_feature(CPU_FTR_DSCR)) {
  850. PPC_WARN_EMULATED(mfdscr, regs);
  851. rd = (instword >> 21) & 0x1f;
  852. regs->gpr[rd] = mfspr(SPRN_DSCR);
  853. return 0;
  854. }
  855. /* Emulate the mtspr DSCR, rD. */
  856. if ((((instword & PPC_INST_MTSPR_DSCR_USER_MASK) ==
  857. PPC_INST_MTSPR_DSCR_USER) ||
  858. ((instword & PPC_INST_MTSPR_DSCR_MASK) ==
  859. PPC_INST_MTSPR_DSCR)) &&
  860. cpu_has_feature(CPU_FTR_DSCR)) {
  861. PPC_WARN_EMULATED(mtdscr, regs);
  862. rd = (instword >> 21) & 0x1f;
  863. current->thread.dscr = regs->gpr[rd];
  864. current->thread.dscr_inherit = 1;
  865. mtspr(SPRN_DSCR, current->thread.dscr);
  866. return 0;
  867. }
  868. #endif
  869. return -EINVAL;
  870. }
  871. int is_valid_bugaddr(unsigned long addr)
  872. {
  873. return is_kernel_addr(addr);
  874. }
  875. void __kprobes program_check_exception(struct pt_regs *regs)
  876. {
  877. enum ctx_state prev_state = exception_enter();
  878. unsigned int reason = get_reason(regs);
  879. extern int do_mathemu(struct pt_regs *regs);
  880. /* We can now get here via a FP Unavailable exception if the core
  881. * has no FPU, in that case the reason flags will be 0 */
  882. if (reason & REASON_FP) {
  883. /* IEEE FP exception */
  884. parse_fpe(regs);
  885. goto bail;
  886. }
  887. if (reason & REASON_TRAP) {
  888. /* Debugger is first in line to stop recursive faults in
  889. * rcu_lock, notify_die, or atomic_notifier_call_chain */
  890. if (debugger_bpt(regs))
  891. goto bail;
  892. /* trap exception */
  893. if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
  894. == NOTIFY_STOP)
  895. goto bail;
  896. if (!(regs->msr & MSR_PR) && /* not user-mode */
  897. report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
  898. regs->nip += 4;
  899. goto bail;
  900. }
  901. _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip);
  902. goto bail;
  903. }
  904. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  905. if (reason & REASON_TM) {
  906. /* This is a TM "Bad Thing Exception" program check.
  907. * This occurs when:
  908. * - An rfid/hrfid/mtmsrd attempts to cause an illegal
  909. * transition in TM states.
  910. * - A trechkpt is attempted when transactional.
  911. * - A treclaim is attempted when non transactional.
  912. * - A tend is illegally attempted.
  913. * - writing a TM SPR when transactional.
  914. */
  915. if (!user_mode(regs) &&
  916. report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {
  917. regs->nip += 4;
  918. goto bail;
  919. }
  920. /* If usermode caused this, it's done something illegal and
  921. * gets a SIGILL slap on the wrist. We call it an illegal
  922. * operand to distinguish from the instruction just being bad
  923. * (e.g. executing a 'tend' on a CPU without TM!); it's an
  924. * illegal /placement/ of a valid instruction.
  925. */
  926. if (user_mode(regs)) {
  927. _exception(SIGILL, regs, ILL_ILLOPN, regs->nip);
  928. goto bail;
  929. } else {
  930. printk(KERN_EMERG "Unexpected TM Bad Thing exception "
  931. "at %lx (msr 0x%x)\n", regs->nip, reason);
  932. die("Unrecoverable exception", regs, SIGABRT);
  933. }
  934. }
  935. #endif
  936. /* We restore the interrupt state now */
  937. if (!arch_irq_disabled_regs(regs))
  938. local_irq_enable();
  939. #ifdef CONFIG_MATH_EMULATION
  940. /* (reason & REASON_ILLEGAL) would be the obvious thing here,
  941. * but there seems to be a hardware bug on the 405GP (RevD)
  942. * that means ESR is sometimes set incorrectly - either to
  943. * ESR_DST (!?) or 0. In the process of chasing this with the
  944. * hardware people - not sure if it can happen on any illegal
  945. * instruction or only on FP instructions, whether there is a
  946. * pattern to occurrences etc. -dgibson 31/Mar/2003 */
  947. switch (do_mathemu(regs)) {
  948. case 0:
  949. emulate_single_step(regs);
  950. goto bail;
  951. case 1: {
  952. int code = 0;
  953. code = __parse_fpscr(current->thread.fpscr.val);
  954. _exception(SIGFPE, regs, code, regs->nip);
  955. goto bail;
  956. }
  957. case -EFAULT:
  958. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  959. goto bail;
  960. }
  961. /* fall through on any other errors */
  962. #endif /* CONFIG_MATH_EMULATION */
  963. /* Try to emulate it if we should. */
  964. if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) {
  965. switch (emulate_instruction(regs)) {
  966. case 0:
  967. regs->nip += 4;
  968. emulate_single_step(regs);
  969. goto bail;
  970. case -EFAULT:
  971. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  972. goto bail;
  973. }
  974. }
  975. if (reason & REASON_PRIVILEGED)
  976. _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
  977. else
  978. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  979. bail:
  980. exception_exit(prev_state);
  981. }
  982. void alignment_exception(struct pt_regs *regs)
  983. {
  984. enum ctx_state prev_state = exception_enter();
  985. int sig, code, fixed = 0;
  986. /* We restore the interrupt state now */
  987. if (!arch_irq_disabled_regs(regs))
  988. local_irq_enable();
  989. /* we don't implement logging of alignment exceptions */
  990. if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS))
  991. fixed = fix_alignment(regs);
  992. if (fixed == 1) {
  993. regs->nip += 4; /* skip over emulated instruction */
  994. emulate_single_step(regs);
  995. goto bail;
  996. }
  997. /* Operand address was bad */
  998. if (fixed == -EFAULT) {
  999. sig = SIGSEGV;
  1000. code = SEGV_ACCERR;
  1001. } else {
  1002. sig = SIGBUS;
  1003. code = BUS_ADRALN;
  1004. }
  1005. if (user_mode(regs))
  1006. _exception(sig, regs, code, regs->dar);
  1007. else
  1008. bad_page_fault(regs, regs->dar, sig);
  1009. bail:
  1010. exception_exit(prev_state);
  1011. }
  1012. void StackOverflow(struct pt_regs *regs)
  1013. {
  1014. printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n",
  1015. current, regs->gpr[1]);
  1016. debugger(regs);
  1017. show_regs(regs);
  1018. panic("kernel stack overflow");
  1019. }
  1020. void nonrecoverable_exception(struct pt_regs *regs)
  1021. {
  1022. printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
  1023. regs->nip, regs->msr);
  1024. debugger(regs);
  1025. die("nonrecoverable exception", regs, SIGKILL);
  1026. }
  1027. void trace_syscall(struct pt_regs *regs)
  1028. {
  1029. printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
  1030. current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
  1031. regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
  1032. }
  1033. void kernel_fp_unavailable_exception(struct pt_regs *regs)
  1034. {
  1035. enum ctx_state prev_state = exception_enter();
  1036. printk(KERN_EMERG "Unrecoverable FP Unavailable Exception "
  1037. "%lx at %lx\n", regs->trap, regs->nip);
  1038. die("Unrecoverable FP Unavailable Exception", regs, SIGABRT);
  1039. exception_exit(prev_state);
  1040. }
  1041. void altivec_unavailable_exception(struct pt_regs *regs)
  1042. {
  1043. enum ctx_state prev_state = exception_enter();
  1044. if (user_mode(regs)) {
  1045. /* A user program has executed an altivec instruction,
  1046. but this kernel doesn't support altivec. */
  1047. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1048. goto bail;
  1049. }
  1050. printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception "
  1051. "%lx at %lx\n", regs->trap, regs->nip);
  1052. die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT);
  1053. bail:
  1054. exception_exit(prev_state);
  1055. }
  1056. void vsx_unavailable_exception(struct pt_regs *regs)
  1057. {
  1058. if (user_mode(regs)) {
  1059. /* A user program has executed an vsx instruction,
  1060. but this kernel doesn't support vsx. */
  1061. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1062. return;
  1063. }
  1064. printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception "
  1065. "%lx at %lx\n", regs->trap, regs->nip);
  1066. die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT);
  1067. }
  1068. void tm_unavailable_exception(struct pt_regs *regs)
  1069. {
  1070. /* We restore the interrupt state now */
  1071. if (!arch_irq_disabled_regs(regs))
  1072. local_irq_enable();
  1073. /* Currently we never expect a TMU exception. Catch
  1074. * this and kill the process!
  1075. */
  1076. printk(KERN_EMERG "Unexpected TM unavailable exception at %lx "
  1077. "(msr %lx)\n",
  1078. regs->nip, regs->msr);
  1079. if (user_mode(regs)) {
  1080. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1081. return;
  1082. }
  1083. die("Unexpected TM unavailable exception", regs, SIGABRT);
  1084. }
  1085. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1086. extern void do_load_up_fpu(struct pt_regs *regs);
  1087. void fp_unavailable_tm(struct pt_regs *regs)
  1088. {
  1089. /* Note: This does not handle any kind of FP laziness. */
  1090. TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n",
  1091. regs->nip, regs->msr);
  1092. tm_enable();
  1093. /* We can only have got here if the task started using FP after
  1094. * beginning the transaction. So, the transactional regs are just a
  1095. * copy of the checkpointed ones. But, we still need to recheckpoint
  1096. * as we're enabling FP for the process; it will return, abort the
  1097. * transaction, and probably retry but now with FP enabled. So the
  1098. * checkpointed FP registers need to be loaded.
  1099. */
  1100. tm_reclaim(&current->thread, current->thread.regs->msr,
  1101. TM_CAUSE_FAC_UNAV);
  1102. /* Reclaim didn't save out any FPRs to transact_fprs. */
  1103. /* Enable FP for the task: */
  1104. regs->msr |= (MSR_FP | current->thread.fpexc_mode);
  1105. /* This loads and recheckpoints the FP registers from
  1106. * thread.fpr[]. They will remain in registers after the
  1107. * checkpoint so we don't need to reload them after.
  1108. */
  1109. tm_recheckpoint(&current->thread, regs->msr);
  1110. }
  1111. #ifdef CONFIG_ALTIVEC
  1112. extern void do_load_up_altivec(struct pt_regs *regs);
  1113. void altivec_unavailable_tm(struct pt_regs *regs)
  1114. {
  1115. /* See the comments in fp_unavailable_tm(). This function operates
  1116. * the same way.
  1117. */
  1118. TM_DEBUG("Vector Unavailable trap whilst transactional at 0x%lx,"
  1119. "MSR=%lx\n",
  1120. regs->nip, regs->msr);
  1121. tm_enable();
  1122. tm_reclaim(&current->thread, current->thread.regs->msr,
  1123. TM_CAUSE_FAC_UNAV);
  1124. regs->msr |= MSR_VEC;
  1125. tm_recheckpoint(&current->thread, regs->msr);
  1126. current->thread.used_vr = 1;
  1127. }
  1128. #endif
  1129. #ifdef CONFIG_VSX
  1130. void vsx_unavailable_tm(struct pt_regs *regs)
  1131. {
  1132. /* See the comments in fp_unavailable_tm(). This works similarly,
  1133. * though we're loading both FP and VEC registers in here.
  1134. *
  1135. * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC
  1136. * regs. Either way, set MSR_VSX.
  1137. */
  1138. TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx,"
  1139. "MSR=%lx\n",
  1140. regs->nip, regs->msr);
  1141. tm_enable();
  1142. /* This reclaims FP and/or VR regs if they're already enabled */
  1143. tm_reclaim(&current->thread, current->thread.regs->msr,
  1144. TM_CAUSE_FAC_UNAV);
  1145. regs->msr |= MSR_VEC | MSR_FP | current->thread.fpexc_mode |
  1146. MSR_VSX;
  1147. /* This loads & recheckpoints FP and VRs. */
  1148. tm_recheckpoint(&current->thread, regs->msr);
  1149. current->thread.used_vsr = 1;
  1150. }
  1151. #endif
  1152. #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
  1153. void performance_monitor_exception(struct pt_regs *regs)
  1154. {
  1155. __get_cpu_var(irq_stat).pmu_irqs++;
  1156. perf_irq(regs);
  1157. }
  1158. #ifdef CONFIG_8xx
  1159. void SoftwareEmulation(struct pt_regs *regs)
  1160. {
  1161. extern int do_mathemu(struct pt_regs *);
  1162. extern int Soft_emulate_8xx(struct pt_regs *);
  1163. #if defined(CONFIG_MATH_EMULATION) || defined(CONFIG_8XX_MINIMAL_FPEMU)
  1164. int errcode;
  1165. #endif
  1166. CHECK_FULL_REGS(regs);
  1167. if (!user_mode(regs)) {
  1168. debugger(regs);
  1169. die("Kernel Mode Software FPU Emulation", regs, SIGFPE);
  1170. }
  1171. #ifdef CONFIG_MATH_EMULATION
  1172. errcode = do_mathemu(regs);
  1173. if (errcode >= 0)
  1174. PPC_WARN_EMULATED(math, regs);
  1175. switch (errcode) {
  1176. case 0:
  1177. emulate_single_step(regs);
  1178. return;
  1179. case 1: {
  1180. int code = 0;
  1181. code = __parse_fpscr(current->thread.fpscr.val);
  1182. _exception(SIGFPE, regs, code, regs->nip);
  1183. return;
  1184. }
  1185. case -EFAULT:
  1186. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  1187. return;
  1188. default:
  1189. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1190. return;
  1191. }
  1192. #elif defined(CONFIG_8XX_MINIMAL_FPEMU)
  1193. errcode = Soft_emulate_8xx(regs);
  1194. if (errcode >= 0)
  1195. PPC_WARN_EMULATED(8xx, regs);
  1196. switch (errcode) {
  1197. case 0:
  1198. emulate_single_step(regs);
  1199. return;
  1200. case 1:
  1201. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1202. return;
  1203. case -EFAULT:
  1204. _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip);
  1205. return;
  1206. }
  1207. #else
  1208. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1209. #endif
  1210. }
  1211. #endif /* CONFIG_8xx */
  1212. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1213. static void handle_debug(struct pt_regs *regs, unsigned long debug_status)
  1214. {
  1215. int changed = 0;
  1216. /*
  1217. * Determine the cause of the debug event, clear the
  1218. * event flags and send a trap to the handler. Torez
  1219. */
  1220. if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) {
  1221. dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  1222. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1223. current->thread.dbcr2 &= ~DBCR2_DAC12MODE;
  1224. #endif
  1225. do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT,
  1226. 5);
  1227. changed |= 0x01;
  1228. } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) {
  1229. dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W);
  1230. do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT,
  1231. 6);
  1232. changed |= 0x01;
  1233. } else if (debug_status & DBSR_IAC1) {
  1234. current->thread.dbcr0 &= ~DBCR0_IAC1;
  1235. dbcr_iac_range(current) &= ~DBCR_IAC12MODE;
  1236. do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT,
  1237. 1);
  1238. changed |= 0x01;
  1239. } else if (debug_status & DBSR_IAC2) {
  1240. current->thread.dbcr0 &= ~DBCR0_IAC2;
  1241. do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT,
  1242. 2);
  1243. changed |= 0x01;
  1244. } else if (debug_status & DBSR_IAC3) {
  1245. current->thread.dbcr0 &= ~DBCR0_IAC3;
  1246. dbcr_iac_range(current) &= ~DBCR_IAC34MODE;
  1247. do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT,
  1248. 3);
  1249. changed |= 0x01;
  1250. } else if (debug_status & DBSR_IAC4) {
  1251. current->thread.dbcr0 &= ~DBCR0_IAC4;
  1252. do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT,
  1253. 4);
  1254. changed |= 0x01;
  1255. }
  1256. /*
  1257. * At the point this routine was called, the MSR(DE) was turned off.
  1258. * Check all other debug flags and see if that bit needs to be turned
  1259. * back on or not.
  1260. */
  1261. if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0, current->thread.dbcr1))
  1262. regs->msr |= MSR_DE;
  1263. else
  1264. /* Make sure the IDM flag is off */
  1265. current->thread.dbcr0 &= ~DBCR0_IDM;
  1266. if (changed & 0x01)
  1267. mtspr(SPRN_DBCR0, current->thread.dbcr0);
  1268. }
  1269. void __kprobes DebugException(struct pt_regs *regs, unsigned long debug_status)
  1270. {
  1271. current->thread.dbsr = debug_status;
  1272. /* Hack alert: On BookE, Branch Taken stops on the branch itself, while
  1273. * on server, it stops on the target of the branch. In order to simulate
  1274. * the server behaviour, we thus restart right away with a single step
  1275. * instead of stopping here when hitting a BT
  1276. */
  1277. if (debug_status & DBSR_BT) {
  1278. regs->msr &= ~MSR_DE;
  1279. /* Disable BT */
  1280. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT);
  1281. /* Clear the BT event */
  1282. mtspr(SPRN_DBSR, DBSR_BT);
  1283. /* Do the single step trick only when coming from userspace */
  1284. if (user_mode(regs)) {
  1285. current->thread.dbcr0 &= ~DBCR0_BT;
  1286. current->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC;
  1287. regs->msr |= MSR_DE;
  1288. return;
  1289. }
  1290. if (notify_die(DIE_SSTEP, "block_step", regs, 5,
  1291. 5, SIGTRAP) == NOTIFY_STOP) {
  1292. return;
  1293. }
  1294. if (debugger_sstep(regs))
  1295. return;
  1296. } else if (debug_status & DBSR_IC) { /* Instruction complete */
  1297. regs->msr &= ~MSR_DE;
  1298. /* Disable instruction completion */
  1299. mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC);
  1300. /* Clear the instruction completion event */
  1301. mtspr(SPRN_DBSR, DBSR_IC);
  1302. if (notify_die(DIE_SSTEP, "single_step", regs, 5,
  1303. 5, SIGTRAP) == NOTIFY_STOP) {
  1304. return;
  1305. }
  1306. if (debugger_sstep(regs))
  1307. return;
  1308. if (user_mode(regs)) {
  1309. current->thread.dbcr0 &= ~DBCR0_IC;
  1310. if (DBCR_ACTIVE_EVENTS(current->thread.dbcr0,
  1311. current->thread.dbcr1))
  1312. regs->msr |= MSR_DE;
  1313. else
  1314. /* Make sure the IDM bit is off */
  1315. current->thread.dbcr0 &= ~DBCR0_IDM;
  1316. }
  1317. _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip);
  1318. } else
  1319. handle_debug(regs, debug_status);
  1320. }
  1321. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  1322. #if !defined(CONFIG_TAU_INT)
  1323. void TAUException(struct pt_regs *regs)
  1324. {
  1325. printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
  1326. regs->nip, regs->msr, regs->trap, print_tainted());
  1327. }
  1328. #endif /* CONFIG_INT_TAU */
  1329. #ifdef CONFIG_ALTIVEC
  1330. void altivec_assist_exception(struct pt_regs *regs)
  1331. {
  1332. int err;
  1333. if (!user_mode(regs)) {
  1334. printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode"
  1335. " at %lx\n", regs->nip);
  1336. die("Kernel VMX/Altivec assist exception", regs, SIGILL);
  1337. }
  1338. flush_altivec_to_thread(current);
  1339. PPC_WARN_EMULATED(altivec, regs);
  1340. err = emulate_altivec(regs);
  1341. if (err == 0) {
  1342. regs->nip += 4; /* skip emulated instruction */
  1343. emulate_single_step(regs);
  1344. return;
  1345. }
  1346. if (err == -EFAULT) {
  1347. /* got an error reading the instruction */
  1348. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1349. } else {
  1350. /* didn't recognize the instruction */
  1351. /* XXX quick hack for now: set the non-Java bit in the VSCR */
  1352. printk_ratelimited(KERN_ERR "Unrecognized altivec instruction "
  1353. "in %s at %lx\n", current->comm, regs->nip);
  1354. current->thread.vscr.u[3] |= 0x10000;
  1355. }
  1356. }
  1357. #endif /* CONFIG_ALTIVEC */
  1358. #ifdef CONFIG_VSX
  1359. void vsx_assist_exception(struct pt_regs *regs)
  1360. {
  1361. if (!user_mode(regs)) {
  1362. printk(KERN_EMERG "VSX assist exception in kernel mode"
  1363. " at %lx\n", regs->nip);
  1364. die("Kernel VSX assist exception", regs, SIGILL);
  1365. }
  1366. flush_vsx_to_thread(current);
  1367. printk(KERN_INFO "VSX assist not supported at %lx\n", regs->nip);
  1368. _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
  1369. }
  1370. #endif /* CONFIG_VSX */
  1371. #ifdef CONFIG_FSL_BOOKE
  1372. void CacheLockingException(struct pt_regs *regs, unsigned long address,
  1373. unsigned long error_code)
  1374. {
  1375. /* We treat cache locking instructions from the user
  1376. * as priv ops, in the future we could try to do
  1377. * something smarter
  1378. */
  1379. if (error_code & (ESR_DLK|ESR_ILK))
  1380. _exception(SIGILL, regs, ILL_PRVOPC, regs->nip);
  1381. return;
  1382. }
  1383. #endif /* CONFIG_FSL_BOOKE */
  1384. #ifdef CONFIG_SPE
  1385. void SPEFloatingPointException(struct pt_regs *regs)
  1386. {
  1387. extern int do_spe_mathemu(struct pt_regs *regs);
  1388. unsigned long spefscr;
  1389. int fpexc_mode;
  1390. int code = 0;
  1391. int err;
  1392. flush_spe_to_thread(current);
  1393. spefscr = current->thread.spefscr;
  1394. fpexc_mode = current->thread.fpexc_mode;
  1395. if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) {
  1396. code = FPE_FLTOVF;
  1397. }
  1398. else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) {
  1399. code = FPE_FLTUND;
  1400. }
  1401. else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV))
  1402. code = FPE_FLTDIV;
  1403. else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) {
  1404. code = FPE_FLTINV;
  1405. }
  1406. else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES))
  1407. code = FPE_FLTRES;
  1408. err = do_spe_mathemu(regs);
  1409. if (err == 0) {
  1410. regs->nip += 4; /* skip emulated instruction */
  1411. emulate_single_step(regs);
  1412. return;
  1413. }
  1414. if (err == -EFAULT) {
  1415. /* got an error reading the instruction */
  1416. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1417. } else if (err == -EINVAL) {
  1418. /* didn't recognize the instruction */
  1419. printk(KERN_ERR "unrecognized spe instruction "
  1420. "in %s at %lx\n", current->comm, regs->nip);
  1421. } else {
  1422. _exception(SIGFPE, regs, code, regs->nip);
  1423. }
  1424. return;
  1425. }
  1426. void SPEFloatingPointRoundException(struct pt_regs *regs)
  1427. {
  1428. extern int speround_handler(struct pt_regs *regs);
  1429. int err;
  1430. preempt_disable();
  1431. if (regs->msr & MSR_SPE)
  1432. giveup_spe(current);
  1433. preempt_enable();
  1434. regs->nip -= 4;
  1435. err = speround_handler(regs);
  1436. if (err == 0) {
  1437. regs->nip += 4; /* skip emulated instruction */
  1438. emulate_single_step(regs);
  1439. return;
  1440. }
  1441. if (err == -EFAULT) {
  1442. /* got an error reading the instruction */
  1443. _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip);
  1444. } else if (err == -EINVAL) {
  1445. /* didn't recognize the instruction */
  1446. printk(KERN_ERR "unrecognized spe instruction "
  1447. "in %s at %lx\n", current->comm, regs->nip);
  1448. } else {
  1449. _exception(SIGFPE, regs, 0, regs->nip);
  1450. return;
  1451. }
  1452. }
  1453. #endif
  1454. /*
  1455. * We enter here if we get an unrecoverable exception, that is, one
  1456. * that happened at a point where the RI (recoverable interrupt) bit
  1457. * in the MSR is 0. This indicates that SRR0/1 are live, and that
  1458. * we therefore lost state by taking this exception.
  1459. */
  1460. void unrecoverable_exception(struct pt_regs *regs)
  1461. {
  1462. printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
  1463. regs->trap, regs->nip);
  1464. die("Unrecoverable exception", regs, SIGABRT);
  1465. }
  1466. #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x)
  1467. /*
  1468. * Default handler for a Watchdog exception,
  1469. * spins until a reboot occurs
  1470. */
  1471. void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs)
  1472. {
  1473. /* Generic WatchdogHandler, implement your own */
  1474. mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE));
  1475. return;
  1476. }
  1477. void WatchdogException(struct pt_regs *regs)
  1478. {
  1479. printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n");
  1480. WatchdogHandler(regs);
  1481. }
  1482. #endif
  1483. /*
  1484. * We enter here if we discover during exception entry that we are
  1485. * running in supervisor mode with a userspace value in the stack pointer.
  1486. */
  1487. void kernel_bad_stack(struct pt_regs *regs)
  1488. {
  1489. printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n",
  1490. regs->gpr[1], regs->nip);
  1491. die("Bad kernel stack pointer", regs, SIGABRT);
  1492. }
  1493. void __init trap_init(void)
  1494. {
  1495. }
  1496. #ifdef CONFIG_PPC_EMULATED_STATS
  1497. #define WARN_EMULATED_SETUP(type) .type = { .name = #type }
  1498. struct ppc_emulated ppc_emulated = {
  1499. #ifdef CONFIG_ALTIVEC
  1500. WARN_EMULATED_SETUP(altivec),
  1501. #endif
  1502. WARN_EMULATED_SETUP(dcba),
  1503. WARN_EMULATED_SETUP(dcbz),
  1504. WARN_EMULATED_SETUP(fp_pair),
  1505. WARN_EMULATED_SETUP(isel),
  1506. WARN_EMULATED_SETUP(mcrxr),
  1507. WARN_EMULATED_SETUP(mfpvr),
  1508. WARN_EMULATED_SETUP(multiple),
  1509. WARN_EMULATED_SETUP(popcntb),
  1510. WARN_EMULATED_SETUP(spe),
  1511. WARN_EMULATED_SETUP(string),
  1512. WARN_EMULATED_SETUP(unaligned),
  1513. #ifdef CONFIG_MATH_EMULATION
  1514. WARN_EMULATED_SETUP(math),
  1515. #elif defined(CONFIG_8XX_MINIMAL_FPEMU)
  1516. WARN_EMULATED_SETUP(8xx),
  1517. #endif
  1518. #ifdef CONFIG_VSX
  1519. WARN_EMULATED_SETUP(vsx),
  1520. #endif
  1521. #ifdef CONFIG_PPC64
  1522. WARN_EMULATED_SETUP(mfdscr),
  1523. WARN_EMULATED_SETUP(mtdscr),
  1524. #endif
  1525. };
  1526. u32 ppc_warn_emulated;
  1527. void ppc_warn_emulated_print(const char *type)
  1528. {
  1529. pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm,
  1530. type);
  1531. }
  1532. static int __init ppc_warn_emulated_init(void)
  1533. {
  1534. struct dentry *dir, *d;
  1535. unsigned int i;
  1536. struct ppc_emulated_entry *entries = (void *)&ppc_emulated;
  1537. if (!powerpc_debugfs_root)
  1538. return -ENODEV;
  1539. dir = debugfs_create_dir("emulated_instructions",
  1540. powerpc_debugfs_root);
  1541. if (!dir)
  1542. return -ENOMEM;
  1543. d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir,
  1544. &ppc_warn_emulated);
  1545. if (!d)
  1546. goto fail;
  1547. for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) {
  1548. d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir,
  1549. (u32 *)&entries[i].val.counter);
  1550. if (!d)
  1551. goto fail;
  1552. }
  1553. return 0;
  1554. fail:
  1555. debugfs_remove_recursive(dir);
  1556. return -ENOMEM;
  1557. }
  1558. device_initcall(ppc_warn_emulated_init);
  1559. #endif /* CONFIG_PPC_EMULATED_STATS */