GoogleGit

blob: d06863881f0214082451c0f71a9c20736bb3f97b [file] [log] [blame]
  1. /*
  2. * arch/arm/common/fiq_debugger.c
  3. *
  4. * Serial Debugger Interface accessed through an FIQ interrupt.
  5. *
  6. * Copyright (C) 2008 Google, Inc.
  7. *
  8. * This software is licensed under the terms of the GNU General Public
  9. * License version 2, as published by the Free Software Foundation, and
  10. * may be copied, distributed, and modified under those terms.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <stdarg.h>
  18. #include <linux/module.h>
  19. #include <linux/io.h>
  20. #include <linux/console.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/clk.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/kernel_stat.h>
  25. #include <linux/irq.h>
  26. #include <linux/delay.h>
  27. #include <linux/reboot.h>
  28. #include <linux/sched.h>
  29. #include <linux/slab.h>
  30. #include <linux/smp.h>
  31. #include <linux/timer.h>
  32. #include <linux/tty.h>
  33. #include <linux/tty_flip.h>
  34. #include <linux/wakelock.h>
  35. #include <asm/fiq_debugger.h>
  36. #include <asm/fiq_glue.h>
  37. #include <asm/stacktrace.h>
  38. #include <linux/uaccess.h>
  39. #include "fiq_debugger_ringbuf.h"
  40. #define DEBUG_MAX 64
  41. #define MAX_UNHANDLED_FIQ_COUNT 1000000
  42. #define MAX_FIQ_DEBUGGER_PORTS 4
  43. #define THREAD_INFO(sp) ((struct thread_info *) \
  44. ((unsigned long)(sp) & ~(THREAD_SIZE - 1)))
  45. struct fiq_debugger_state {
  46. struct fiq_glue_handler handler;
  47. int fiq;
  48. int uart_irq;
  49. int signal_irq;
  50. int wakeup_irq;
  51. bool wakeup_irq_no_set_wake;
  52. struct clk *clk;
  53. struct fiq_debugger_pdata *pdata;
  54. struct platform_device *pdev;
  55. char debug_cmd[DEBUG_MAX];
  56. int debug_busy;
  57. int debug_abort;
  58. char debug_buf[DEBUG_MAX];
  59. int debug_count;
  60. bool no_sleep;
  61. bool debug_enable;
  62. bool ignore_next_wakeup_irq;
  63. struct timer_list sleep_timer;
  64. spinlock_t sleep_timer_lock;
  65. bool uart_enabled;
  66. struct wake_lock debugger_wake_lock;
  67. bool console_enable;
  68. int current_cpu;
  69. atomic_t unhandled_fiq_count;
  70. bool in_fiq;
  71. struct work_struct work;
  72. spinlock_t work_lock;
  73. char work_cmd[DEBUG_MAX];
  74. #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
  75. spinlock_t console_lock;
  76. struct console console;
  77. struct tty_struct *tty;
  78. int tty_open_count;
  79. struct fiq_debugger_ringbuf *tty_rbuf;
  80. bool syslog_dumping;
  81. #endif
  82. unsigned int last_irqs[NR_IRQS];
  83. unsigned int last_local_timer_irqs[NR_CPUS];
  84. };
  85. #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
  86. struct tty_driver *fiq_tty_driver;
  87. #endif
  88. #ifdef CONFIG_FIQ_DEBUGGER_NO_SLEEP
  89. static bool initial_no_sleep = true;
  90. #else
  91. static bool initial_no_sleep;
  92. #endif
  93. #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE_DEFAULT_ENABLE
  94. static bool initial_debug_enable = true;
  95. static bool initial_console_enable = true;
  96. #else
  97. static bool initial_debug_enable;
  98. static bool initial_console_enable;
  99. #endif
  100. static bool fiq_kgdb_enable;
  101. module_param_named(no_sleep, initial_no_sleep, bool, 0644);
  102. module_param_named(debug_enable, initial_debug_enable, bool, 0644);
  103. module_param_named(console_enable, initial_console_enable, bool, 0644);
  104. module_param_named(kgdb_enable, fiq_kgdb_enable, bool, 0644);
  105. #ifdef CONFIG_FIQ_DEBUGGER_WAKEUP_IRQ_ALWAYS_ON
  106. static inline void enable_wakeup_irq(struct fiq_debugger_state *state) {}
  107. static inline void disable_wakeup_irq(struct fiq_debugger_state *state) {}
  108. #else
  109. static inline void enable_wakeup_irq(struct fiq_debugger_state *state)
  110. {
  111. if (state->wakeup_irq < 0)
  112. return;
  113. enable_irq(state->wakeup_irq);
  114. if (!state->wakeup_irq_no_set_wake)
  115. enable_irq_wake(state->wakeup_irq);
  116. }
  117. static inline void disable_wakeup_irq(struct fiq_debugger_state *state)
  118. {
  119. if (state->wakeup_irq < 0)
  120. return;
  121. disable_irq_nosync(state->wakeup_irq);
  122. if (!state->wakeup_irq_no_set_wake)
  123. disable_irq_wake(state->wakeup_irq);
  124. }
  125. #endif
  126. static bool inline debug_have_fiq(struct fiq_debugger_state *state)
  127. {
  128. return (state->fiq >= 0);
  129. }
  130. static void debug_force_irq(struct fiq_debugger_state *state)
  131. {
  132. unsigned int irq = state->signal_irq;
  133. if (WARN_ON(!debug_have_fiq(state)))
  134. return;
  135. if (state->pdata->force_irq) {
  136. state->pdata->force_irq(state->pdev, irq);
  137. } else {
  138. struct irq_chip *chip = irq_get_chip(irq);
  139. if (chip && chip->irq_retrigger)
  140. chip->irq_retrigger(irq_get_irq_data(irq));
  141. }
  142. }
  143. static void debug_uart_enable(struct fiq_debugger_state *state)
  144. {
  145. if (state->clk)
  146. clk_enable(state->clk);
  147. if (state->pdata->uart_enable)
  148. state->pdata->uart_enable(state->pdev);
  149. }
  150. static void debug_uart_disable(struct fiq_debugger_state *state)
  151. {
  152. if (state->pdata->uart_disable)
  153. state->pdata->uart_disable(state->pdev);
  154. if (state->clk)
  155. clk_disable(state->clk);
  156. }
  157. static void debug_uart_flush(struct fiq_debugger_state *state)
  158. {
  159. if (state->pdata->uart_flush)
  160. state->pdata->uart_flush(state->pdev);
  161. }
  162. static void debug_putc(struct fiq_debugger_state *state, char c)
  163. {
  164. state->pdata->uart_putc(state->pdev, c);
  165. }
  166. static void debug_puts(struct fiq_debugger_state *state, char *s)
  167. {
  168. unsigned c;
  169. while ((c = *s++)) {
  170. if (c == '\n')
  171. debug_putc(state, '\r');
  172. debug_putc(state, c);
  173. }
  174. }
  175. static void debug_prompt(struct fiq_debugger_state *state)
  176. {
  177. debug_puts(state, "debug> ");
  178. }
  179. int log_buf_copy(char *dest, int idx, int len);
  180. static void dump_kernel_log(struct fiq_debugger_state *state)
  181. {
  182. char buf[1024];
  183. int idx = 0;
  184. int ret;
  185. int saved_oip;
  186. /* setting oops_in_progress prevents log_buf_copy()
  187. * from trying to take a spinlock which will make it
  188. * very unhappy in some cases...
  189. */
  190. saved_oip = oops_in_progress;
  191. oops_in_progress = 1;
  192. for (;;) {
  193. ret = log_buf_copy(buf, idx, 1023);
  194. if (ret <= 0)
  195. break;
  196. buf[ret] = 0;
  197. debug_puts(state, buf);
  198. idx += ret;
  199. }
  200. oops_in_progress = saved_oip;
  201. }
  202. static char *mode_name(unsigned cpsr)
  203. {
  204. switch (cpsr & MODE_MASK) {
  205. case USR_MODE: return "USR";
  206. case FIQ_MODE: return "FIQ";
  207. case IRQ_MODE: return "IRQ";
  208. case SVC_MODE: return "SVC";
  209. case ABT_MODE: return "ABT";
  210. case UND_MODE: return "UND";
  211. case SYSTEM_MODE: return "SYS";
  212. default: return "???";
  213. }
  214. }
  215. static int debug_printf(void *cookie, const char *fmt, ...)
  216. {
  217. struct fiq_debugger_state *state = cookie;
  218. char buf[256];
  219. va_list ap;
  220. va_start(ap, fmt);
  221. vsnprintf(buf, sizeof(buf), fmt, ap);
  222. va_end(ap);
  223. debug_puts(state, buf);
  224. return state->debug_abort;
  225. }
  226. /* Safe outside fiq context */
  227. static int debug_printf_nfiq(void *cookie, const char *fmt, ...)
  228. {
  229. struct fiq_debugger_state *state = cookie;
  230. char buf[256];
  231. va_list ap;
  232. unsigned long irq_flags;
  233. va_start(ap, fmt);
  234. vsnprintf(buf, 128, fmt, ap);
  235. va_end(ap);
  236. local_irq_save(irq_flags);
  237. debug_puts(state, buf);
  238. debug_uart_flush(state);
  239. local_irq_restore(irq_flags);
  240. return state->debug_abort;
  241. }
  242. static void dump_regs(struct fiq_debugger_state *state, unsigned *regs)
  243. {
  244. debug_printf(state, " r0 %08x r1 %08x r2 %08x r3 %08x\n",
  245. regs[0], regs[1], regs[2], regs[3]);
  246. debug_printf(state, " r4 %08x r5 %08x r6 %08x r7 %08x\n",
  247. regs[4], regs[5], regs[6], regs[7]);
  248. debug_printf(state, " r8 %08x r9 %08x r10 %08x r11 %08x mode %s\n",
  249. regs[8], regs[9], regs[10], regs[11],
  250. mode_name(regs[16]));
  251. if ((regs[16] & MODE_MASK) == USR_MODE)
  252. debug_printf(state, " ip %08x sp %08x lr %08x pc %08x "
  253. "cpsr %08x\n", regs[12], regs[13], regs[14],
  254. regs[15], regs[16]);
  255. else
  256. debug_printf(state, " ip %08x sp %08x lr %08x pc %08x "
  257. "cpsr %08x spsr %08x\n", regs[12], regs[13],
  258. regs[14], regs[15], regs[16], regs[17]);
  259. }
  260. struct mode_regs {
  261. unsigned long sp_svc;
  262. unsigned long lr_svc;
  263. unsigned long spsr_svc;
  264. unsigned long sp_abt;
  265. unsigned long lr_abt;
  266. unsigned long spsr_abt;
  267. unsigned long sp_und;
  268. unsigned long lr_und;
  269. unsigned long spsr_und;
  270. unsigned long sp_irq;
  271. unsigned long lr_irq;
  272. unsigned long spsr_irq;
  273. unsigned long r8_fiq;
  274. unsigned long r9_fiq;
  275. unsigned long r10_fiq;
  276. unsigned long r11_fiq;
  277. unsigned long r12_fiq;
  278. unsigned long sp_fiq;
  279. unsigned long lr_fiq;
  280. unsigned long spsr_fiq;
  281. };
  282. void __naked get_mode_regs(struct mode_regs *regs)
  283. {
  284. asm volatile (
  285. "mrs r1, cpsr\n"
  286. "msr cpsr_c, #0xd3 @(SVC_MODE | PSR_I_BIT | PSR_F_BIT)\n"
  287. "stmia r0!, {r13 - r14}\n"
  288. "mrs r2, spsr\n"
  289. "msr cpsr_c, #0xd7 @(ABT_MODE | PSR_I_BIT | PSR_F_BIT)\n"
  290. "stmia r0!, {r2, r13 - r14}\n"
  291. "mrs r2, spsr\n"
  292. "msr cpsr_c, #0xdb @(UND_MODE | PSR_I_BIT | PSR_F_BIT)\n"
  293. "stmia r0!, {r2, r13 - r14}\n"
  294. "mrs r2, spsr\n"
  295. "msr cpsr_c, #0xd2 @(IRQ_MODE | PSR_I_BIT | PSR_F_BIT)\n"
  296. "stmia r0!, {r2, r13 - r14}\n"
  297. "mrs r2, spsr\n"
  298. "msr cpsr_c, #0xd1 @(FIQ_MODE | PSR_I_BIT | PSR_F_BIT)\n"
  299. "stmia r0!, {r2, r8 - r14}\n"
  300. "mrs r2, spsr\n"
  301. "stmia r0!, {r2}\n"
  302. "msr cpsr_c, r1\n"
  303. "bx lr\n");
  304. }
  305. static void dump_allregs(struct fiq_debugger_state *state, unsigned *regs)
  306. {
  307. struct mode_regs mode_regs;
  308. dump_regs(state, regs);
  309. get_mode_regs(&mode_regs);
  310. debug_printf(state, " svc: sp %08x lr %08x spsr %08x\n",
  311. mode_regs.sp_svc, mode_regs.lr_svc, mode_regs.spsr_svc);
  312. debug_printf(state, " abt: sp %08x lr %08x spsr %08x\n",
  313. mode_regs.sp_abt, mode_regs.lr_abt, mode_regs.spsr_abt);
  314. debug_printf(state, " und: sp %08x lr %08x spsr %08x\n",
  315. mode_regs.sp_und, mode_regs.lr_und, mode_regs.spsr_und);
  316. debug_printf(state, " irq: sp %08x lr %08x spsr %08x\n",
  317. mode_regs.sp_irq, mode_regs.lr_irq, mode_regs.spsr_irq);
  318. debug_printf(state, " fiq: r8 %08x r9 %08x r10 %08x r11 %08x "
  319. "r12 %08x\n",
  320. mode_regs.r8_fiq, mode_regs.r9_fiq, mode_regs.r10_fiq,
  321. mode_regs.r11_fiq, mode_regs.r12_fiq);
  322. debug_printf(state, " fiq: sp %08x lr %08x spsr %08x\n",
  323. mode_regs.sp_fiq, mode_regs.lr_fiq, mode_regs.spsr_fiq);
  324. }
  325. static void dump_irqs(struct fiq_debugger_state *state)
  326. {
  327. int n;
  328. debug_printf(state, "irqnr total since-last status name\n");
  329. for (n = 0; n < NR_IRQS; n++) {
  330. struct irqaction *act = irq_desc[n].action;
  331. if (!act && !kstat_irqs(n))
  332. continue;
  333. debug_printf(state, "%5d: %10u %11u %8x %s\n", n,
  334. kstat_irqs(n),
  335. kstat_irqs(n) - state->last_irqs[n],
  336. irq_desc[n].status_use_accessors,
  337. (act && act->name) ? act->name : "???");
  338. state->last_irqs[n] = kstat_irqs(n);
  339. }
  340. }
  341. struct stacktrace_state {
  342. struct fiq_debugger_state *state;
  343. unsigned int depth;
  344. };
  345. static int report_trace(struct stackframe *frame, void *d)
  346. {
  347. struct stacktrace_state *sts = d;
  348. if (sts->depth) {
  349. debug_printf(sts->state,
  350. " pc: %p (%pF), lr %p (%pF), sp %p, fp %p\n",
  351. frame->pc, frame->pc, frame->lr, frame->lr,
  352. frame->sp, frame->fp);
  353. sts->depth--;
  354. return 0;
  355. }
  356. debug_printf(sts->state, " ...\n");
  357. return sts->depth == 0;
  358. }
  359. struct frame_tail {
  360. struct frame_tail *fp;
  361. unsigned long sp;
  362. unsigned long lr;
  363. } __attribute__((packed));
  364. static struct frame_tail *user_backtrace(struct fiq_debugger_state *state,
  365. struct frame_tail *tail)
  366. {
  367. struct frame_tail buftail[2];
  368. /* Also check accessibility of one struct frame_tail beyond */
  369. if (!access_ok(VERIFY_READ, tail, sizeof(buftail))) {
  370. debug_printf(state, " invalid frame pointer %p\n", tail);
  371. return NULL;
  372. }
  373. if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail))) {
  374. debug_printf(state,
  375. " failed to copy frame pointer %p\n", tail);
  376. return NULL;
  377. }
  378. debug_printf(state, " %p\n", buftail[0].lr);
  379. /* frame pointers should strictly progress back up the stack
  380. * (towards higher addresses) */
  381. if (tail >= buftail[0].fp)
  382. return NULL;
  383. return buftail[0].fp-1;
  384. }
  385. void dump_stacktrace(struct fiq_debugger_state *state,
  386. struct pt_regs * const regs, unsigned int depth, void *ssp)
  387. {
  388. struct frame_tail *tail;
  389. struct thread_info *real_thread_info = THREAD_INFO(ssp);
  390. struct stacktrace_state sts;
  391. sts.depth = depth;
  392. sts.state = state;
  393. *current_thread_info() = *real_thread_info;
  394. if (!current)
  395. debug_printf(state, "current NULL\n");
  396. else
  397. debug_printf(state, "pid: %d comm: %s\n",
  398. current->pid, current->comm);
  399. dump_regs(state, (unsigned *)regs);
  400. if (!user_mode(regs)) {
  401. struct stackframe frame;
  402. frame.fp = regs->ARM_fp;
  403. frame.sp = regs->ARM_sp;
  404. frame.lr = regs->ARM_lr;
  405. frame.pc = regs->ARM_pc;
  406. debug_printf(state,
  407. " pc: %p (%pF), lr %p (%pF), sp %p, fp %p\n",
  408. regs->ARM_pc, regs->ARM_pc, regs->ARM_lr, regs->ARM_lr,
  409. regs->ARM_sp, regs->ARM_fp);
  410. walk_stackframe(&frame, report_trace, &sts);
  411. return;
  412. }
  413. tail = ((struct frame_tail *) regs->ARM_fp) - 1;
  414. while (depth-- && tail && !((unsigned long) tail & 3))
  415. tail = user_backtrace(state, tail);
  416. }
  417. static void do_ps(struct fiq_debugger_state *state)
  418. {
  419. struct task_struct *g;
  420. struct task_struct *p;
  421. unsigned task_state;
  422. static const char stat_nam[] = "RSDTtZX";
  423. debug_printf(state, "pid ppid prio task pc\n");
  424. read_lock(&tasklist_lock);
  425. do_each_thread(g, p) {
  426. task_state = p->state ? __ffs(p->state) + 1 : 0;
  427. debug_printf(state,
  428. "%5d %5d %4d ", p->pid, p->parent->pid, p->prio);
  429. debug_printf(state, "%-13.13s %c", p->comm,
  430. task_state >= sizeof(stat_nam) ? '?' : stat_nam[task_state]);
  431. if (task_state == TASK_RUNNING)
  432. debug_printf(state, " running\n");
  433. else
  434. debug_printf(state, " %08lx\n", thread_saved_pc(p));
  435. } while_each_thread(g, p);
  436. read_unlock(&tasklist_lock);
  437. }
  438. #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
  439. static void begin_syslog_dump(struct fiq_debugger_state *state)
  440. {
  441. state->syslog_dumping = true;
  442. }
  443. static void end_syslog_dump(struct fiq_debugger_state *state)
  444. {
  445. state->syslog_dumping = false;
  446. }
  447. #else
  448. extern int do_syslog(int type, char __user *bug, int count);
  449. static void begin_syslog_dump(struct fiq_debugger_state *state)
  450. {
  451. do_syslog(5 /* clear */, NULL, 0);
  452. }
  453. static void end_syslog_dump(struct fiq_debugger_state *state)
  454. {
  455. char buf[128];
  456. int ret;
  457. int idx = 0;
  458. while (1) {
  459. ret = log_buf_copy(buf, idx, sizeof(buf) - 1);
  460. if (ret <= 0)
  461. break;
  462. buf[ret] = 0;
  463. debug_printf(state, "%s", buf);
  464. idx += ret;
  465. }
  466. }
  467. #endif
  468. static void do_sysrq(struct fiq_debugger_state *state, char rq)
  469. {
  470. if ((rq == 'g' || rq == 'G') && !fiq_kgdb_enable) {
  471. debug_printf(state, "sysrq-g blocked\n");
  472. return;
  473. }
  474. begin_syslog_dump(state);
  475. handle_sysrq(rq);
  476. end_syslog_dump(state);
  477. }
  478. #ifdef CONFIG_KGDB
  479. static void do_kgdb(struct fiq_debugger_state *state)
  480. {
  481. if (!fiq_kgdb_enable) {
  482. debug_printf(state, "kgdb through fiq debugger not enabled\n");
  483. return;
  484. }
  485. debug_printf(state, "enabling console and triggering kgdb\n");
  486. state->console_enable = true;
  487. handle_sysrq('g');
  488. }
  489. #endif
  490. static void debug_schedule_work(struct fiq_debugger_state *state, char *cmd)
  491. {
  492. unsigned long flags;
  493. spin_lock_irqsave(&state->work_lock, flags);
  494. if (state->work_cmd[0] != '\0') {
  495. debug_printf(state, "work command processor busy\n");
  496. spin_unlock_irqrestore(&state->work_lock, flags);
  497. return;
  498. }
  499. strlcpy(state->work_cmd, cmd, sizeof(state->work_cmd));
  500. spin_unlock_irqrestore(&state->work_lock, flags);
  501. schedule_work(&state->work);
  502. }
  503. static void debug_work(struct work_struct *work)
  504. {
  505. struct fiq_debugger_state *state;
  506. char work_cmd[DEBUG_MAX];
  507. char *cmd;
  508. unsigned long flags;
  509. state = container_of(work, struct fiq_debugger_state, work);
  510. spin_lock_irqsave(&state->work_lock, flags);
  511. strlcpy(work_cmd, state->work_cmd, sizeof(work_cmd));
  512. state->work_cmd[0] = '\0';
  513. spin_unlock_irqrestore(&state->work_lock, flags);
  514. cmd = work_cmd;
  515. if (!strncmp(cmd, "reboot", 6)) {
  516. cmd += 6;
  517. while (*cmd == ' ')
  518. cmd++;
  519. if (cmd != '\0')
  520. kernel_restart(cmd);
  521. else
  522. kernel_restart(NULL);
  523. } else {
  524. debug_printf(state, "unknown work command '%s'\n", work_cmd);
  525. }
  526. }
  527. /* This function CANNOT be called in FIQ context */
  528. static void debug_irq_exec(struct fiq_debugger_state *state, char *cmd)
  529. {
  530. if (!strcmp(cmd, "ps"))
  531. do_ps(state);
  532. if (!strcmp(cmd, "sysrq"))
  533. do_sysrq(state, 'h');
  534. if (!strncmp(cmd, "sysrq ", 6))
  535. do_sysrq(state, cmd[6]);
  536. #ifdef CONFIG_KGDB
  537. if (!strcmp(cmd, "kgdb"))
  538. do_kgdb(state);
  539. #endif
  540. if (!strncmp(cmd, "reboot", 6))
  541. debug_schedule_work(state, cmd);
  542. }
  543. static void debug_help(struct fiq_debugger_state *state)
  544. {
  545. debug_printf(state, "FIQ Debugger commands:\n"
  546. " pc PC status\n"
  547. " regs Register dump\n"
  548. " allregs Extended Register dump\n"
  549. " bt Stack trace\n"
  550. " reboot [<c>] Reboot with command <c>\n"
  551. " reset [<c>] Hard reset with command <c>\n"
  552. " irqs Interupt status\n"
  553. " kmsg Kernel log\n"
  554. " version Kernel version\n");
  555. debug_printf(state, " sleep Allow sleep while in FIQ\n"
  556. " nosleep Disable sleep while in FIQ\n"
  557. " console Switch terminal to console\n"
  558. " cpu Current CPU\n"
  559. " cpu <number> Switch to CPU<number>\n");
  560. debug_printf(state, " ps Process list\n"
  561. " sysrq sysrq options\n"
  562. " sysrq <param> Execute sysrq with <param>\n");
  563. #ifdef CONFIG_KGDB
  564. debug_printf(state, " kgdb Enter kernel debugger\n");
  565. #endif
  566. }
  567. static void take_affinity(void *info)
  568. {
  569. struct fiq_debugger_state *state = info;
  570. struct cpumask cpumask;
  571. cpumask_clear(&cpumask);
  572. cpumask_set_cpu(get_cpu(), &cpumask);
  573. irq_set_affinity(state->uart_irq, &cpumask);
  574. }
  575. static void switch_cpu(struct fiq_debugger_state *state, int cpu)
  576. {
  577. if (!debug_have_fiq(state))
  578. smp_call_function_single(cpu, take_affinity, state, false);
  579. state->current_cpu = cpu;
  580. }
  581. static bool debug_fiq_exec(struct fiq_debugger_state *state,
  582. const char *cmd, unsigned *regs, void *svc_sp)
  583. {
  584. bool signal_helper = false;
  585. if (!strcmp(cmd, "help") || !strcmp(cmd, "?")) {
  586. debug_help(state);
  587. } else if (!strcmp(cmd, "pc")) {
  588. debug_printf(state, " pc %08x cpsr %08x mode %s\n",
  589. regs[15], regs[16], mode_name(regs[16]));
  590. } else if (!strcmp(cmd, "regs")) {
  591. dump_regs(state, regs);
  592. } else if (!strcmp(cmd, "allregs")) {
  593. dump_allregs(state, regs);
  594. } else if (!strcmp(cmd, "bt")) {
  595. dump_stacktrace(state, (struct pt_regs *)regs, 100, svc_sp);
  596. } else if (!strncmp(cmd, "reset", 5)) {
  597. cmd += 5;
  598. while (*cmd == ' ')
  599. cmd++;
  600. if (*cmd) {
  601. char tmp_cmd[32];
  602. strlcpy(tmp_cmd, cmd, sizeof(tmp_cmd));
  603. machine_restart(tmp_cmd);
  604. } else {
  605. machine_restart(NULL);
  606. }
  607. } else if (!strcmp(cmd, "irqs")) {
  608. dump_irqs(state);
  609. } else if (!strcmp(cmd, "kmsg")) {
  610. dump_kernel_log(state);
  611. } else if (!strcmp(cmd, "version")) {
  612. debug_printf(state, "%s\n", linux_banner);
  613. } else if (!strcmp(cmd, "sleep")) {
  614. state->no_sleep = false;
  615. debug_printf(state, "enabling sleep\n");
  616. } else if (!strcmp(cmd, "nosleep")) {
  617. state->no_sleep = true;
  618. debug_printf(state, "disabling sleep\n");
  619. } else if (!strcmp(cmd, "console")) {
  620. debug_printf(state, "console mode\n");
  621. debug_uart_flush(state);
  622. state->console_enable = true;
  623. } else if (!strcmp(cmd, "cpu")) {
  624. debug_printf(state, "cpu %d\n", state->current_cpu);
  625. } else if (!strncmp(cmd, "cpu ", 4)) {
  626. unsigned long cpu = 0;
  627. if (strict_strtoul(cmd + 4, 10, &cpu) == 0)
  628. switch_cpu(state, cpu);
  629. else
  630. debug_printf(state, "invalid cpu\n");
  631. debug_printf(state, "cpu %d\n", state->current_cpu);
  632. } else {
  633. if (state->debug_busy) {
  634. debug_printf(state,
  635. "command processor busy. trying to abort.\n");
  636. state->debug_abort = -1;
  637. } else {
  638. strcpy(state->debug_cmd, cmd);
  639. state->debug_busy = 1;
  640. }
  641. return true;
  642. }
  643. if (!state->console_enable)
  644. debug_prompt(state);
  645. return signal_helper;
  646. }
  647. static void sleep_timer_expired(unsigned long data)
  648. {
  649. struct fiq_debugger_state *state = (struct fiq_debugger_state *)data;
  650. unsigned long flags;
  651. spin_lock_irqsave(&state->sleep_timer_lock, flags);
  652. if (state->uart_enabled && !state->no_sleep) {
  653. if (state->debug_enable && !state->console_enable) {
  654. state->debug_enable = false;
  655. debug_printf_nfiq(state, "suspending fiq debugger\n");
  656. }
  657. state->ignore_next_wakeup_irq = true;
  658. debug_uart_disable(state);
  659. state->uart_enabled = false;
  660. enable_wakeup_irq(state);
  661. }
  662. wake_unlock(&state->debugger_wake_lock);
  663. spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
  664. }
  665. static void handle_wakeup(struct fiq_debugger_state *state)
  666. {
  667. unsigned long flags;
  668. spin_lock_irqsave(&state->sleep_timer_lock, flags);
  669. if (state->wakeup_irq >= 0 && state->ignore_next_wakeup_irq) {
  670. state->ignore_next_wakeup_irq = false;
  671. } else if (!state->uart_enabled) {
  672. wake_lock(&state->debugger_wake_lock);
  673. debug_uart_enable(state);
  674. state->uart_enabled = true;
  675. disable_wakeup_irq(state);
  676. mod_timer(&state->sleep_timer, jiffies + HZ / 2);
  677. }
  678. spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
  679. }
  680. static irqreturn_t wakeup_irq_handler(int irq, void *dev)
  681. {
  682. struct fiq_debugger_state *state = dev;
  683. if (!state->no_sleep)
  684. debug_puts(state, "WAKEUP\n");
  685. handle_wakeup(state);
  686. return IRQ_HANDLED;
  687. }
  688. static void debug_handle_irq_context(struct fiq_debugger_state *state)
  689. {
  690. if (!state->no_sleep) {
  691. unsigned long flags;
  692. spin_lock_irqsave(&state->sleep_timer_lock, flags);
  693. wake_lock(&state->debugger_wake_lock);
  694. mod_timer(&state->sleep_timer, jiffies + HZ * 5);
  695. spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
  696. }
  697. #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
  698. if (state->tty) {
  699. int i;
  700. int count = fiq_debugger_ringbuf_level(state->tty_rbuf);
  701. for (i = 0; i < count; i++) {
  702. int c = fiq_debugger_ringbuf_peek(state->tty_rbuf, 0);
  703. tty_insert_flip_char(state->tty, c, TTY_NORMAL);
  704. if (!fiq_debugger_ringbuf_consume(state->tty_rbuf, 1))
  705. pr_warn("fiq tty failed to consume byte\n");
  706. }
  707. tty_flip_buffer_push(state->tty);
  708. }
  709. #endif
  710. if (state->debug_busy) {
  711. debug_irq_exec(state, state->debug_cmd);
  712. if (!state->console_enable)
  713. debug_prompt(state);
  714. state->debug_busy = 0;
  715. }
  716. }
  717. static int debug_getc(struct fiq_debugger_state *state)
  718. {
  719. return state->pdata->uart_getc(state->pdev);
  720. }
  721. static bool debug_handle_uart_interrupt(struct fiq_debugger_state *state,
  722. int this_cpu, void *regs, void *svc_sp)
  723. {
  724. int c;
  725. static int last_c;
  726. int count = 0;
  727. bool signal_helper = false;
  728. if (this_cpu != state->current_cpu) {
  729. if (state->in_fiq)
  730. return false;
  731. if (atomic_inc_return(&state->unhandled_fiq_count) !=
  732. MAX_UNHANDLED_FIQ_COUNT)
  733. return false;
  734. debug_printf(state, "fiq_debugger: cpu %d not responding, "
  735. "reverting to cpu %d\n", state->current_cpu,
  736. this_cpu);
  737. atomic_set(&state->unhandled_fiq_count, 0);
  738. switch_cpu(state, this_cpu);
  739. return false;
  740. }
  741. state->in_fiq = true;
  742. while ((c = debug_getc(state)) != FIQ_DEBUGGER_NO_CHAR) {
  743. count++;
  744. if (!state->debug_enable) {
  745. if ((c == 13) || (c == 10)) {
  746. state->debug_enable = true;
  747. state->debug_count = 0;
  748. debug_prompt(state);
  749. }
  750. } else if (c == FIQ_DEBUGGER_BREAK) {
  751. state->console_enable = false;
  752. debug_puts(state, "fiq debugger mode\n");
  753. state->debug_count = 0;
  754. debug_prompt(state);
  755. #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
  756. } else if (state->console_enable && state->tty_rbuf) {
  757. fiq_debugger_ringbuf_push(state->tty_rbuf, c);
  758. signal_helper = true;
  759. #endif
  760. } else if ((c >= ' ') && (c < 127)) {
  761. if (state->debug_count < (DEBUG_MAX - 1)) {
  762. state->debug_buf[state->debug_count++] = c;
  763. debug_putc(state, c);
  764. }
  765. } else if ((c == 8) || (c == 127)) {
  766. if (state->debug_count > 0) {
  767. state->debug_count--;
  768. debug_putc(state, 8);
  769. debug_putc(state, ' ');
  770. debug_putc(state, 8);
  771. }
  772. } else if ((c == 13) || (c == 10)) {
  773. if (c == '\r' || (c == '\n' && last_c != '\r')) {
  774. debug_putc(state, '\r');
  775. debug_putc(state, '\n');
  776. }
  777. if (state->debug_count) {
  778. state->debug_buf[state->debug_count] = 0;
  779. state->debug_count = 0;
  780. signal_helper |=
  781. debug_fiq_exec(state, state->debug_buf,
  782. regs, svc_sp);
  783. } else {
  784. debug_prompt(state);
  785. }
  786. }
  787. last_c = c;
  788. }
  789. if (!state->console_enable)
  790. debug_uart_flush(state);
  791. if (state->pdata->fiq_ack)
  792. state->pdata->fiq_ack(state->pdev, state->fiq);
  793. /* poke sleep timer if necessary */
  794. if (state->debug_enable && !state->no_sleep)
  795. signal_helper = true;
  796. atomic_set(&state->unhandled_fiq_count, 0);
  797. state->in_fiq = false;
  798. return signal_helper;
  799. }
  800. static void debug_fiq(struct fiq_glue_handler *h, void *regs, void *svc_sp)
  801. {
  802. struct fiq_debugger_state *state =
  803. container_of(h, struct fiq_debugger_state, handler);
  804. unsigned int this_cpu = THREAD_INFO(svc_sp)->cpu;
  805. bool need_irq;
  806. need_irq = debug_handle_uart_interrupt(state, this_cpu, regs, svc_sp);
  807. if (need_irq)
  808. debug_force_irq(state);
  809. }
  810. /*
  811. * When not using FIQs, we only use this single interrupt as an entry point.
  812. * This just effectively takes over the UART interrupt and does all the work
  813. * in this context.
  814. */
  815. static irqreturn_t debug_uart_irq(int irq, void *dev)
  816. {
  817. struct fiq_debugger_state *state = dev;
  818. bool not_done;
  819. handle_wakeup(state);
  820. /* handle the debugger irq in regular context */
  821. not_done = debug_handle_uart_interrupt(state, smp_processor_id(),
  822. get_irq_regs(),
  823. current_thread_info());
  824. if (not_done)
  825. debug_handle_irq_context(state);
  826. return IRQ_HANDLED;
  827. }
  828. /*
  829. * If FIQs are used, not everything can happen in fiq context.
  830. * FIQ handler does what it can and then signals this interrupt to finish the
  831. * job in irq context.
  832. */
  833. static irqreturn_t debug_signal_irq(int irq, void *dev)
  834. {
  835. struct fiq_debugger_state *state = dev;
  836. if (state->pdata->force_irq_ack)
  837. state->pdata->force_irq_ack(state->pdev, state->signal_irq);
  838. debug_handle_irq_context(state);
  839. return IRQ_HANDLED;
  840. }
  841. static void debug_resume(struct fiq_glue_handler *h)
  842. {
  843. struct fiq_debugger_state *state =
  844. container_of(h, struct fiq_debugger_state, handler);
  845. if (state->pdata->uart_resume)
  846. state->pdata->uart_resume(state->pdev);
  847. }
  848. #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
  849. struct tty_driver *debug_console_device(struct console *co, int *index)
  850. {
  851. *index = co->index;
  852. return fiq_tty_driver;
  853. }
  854. static void debug_console_write(struct console *co,
  855. const char *s, unsigned int count)
  856. {
  857. struct fiq_debugger_state *state;
  858. unsigned long flags;
  859. state = container_of(co, struct fiq_debugger_state, console);
  860. if (!state->console_enable && !state->syslog_dumping)
  861. return;
  862. debug_uart_enable(state);
  863. spin_lock_irqsave(&state->console_lock, flags);
  864. while (count--) {
  865. if (*s == '\n')
  866. debug_putc(state, '\r');
  867. debug_putc(state, *s++);
  868. }
  869. debug_uart_flush(state);
  870. spin_unlock_irqrestore(&state->console_lock, flags);
  871. debug_uart_disable(state);
  872. }
  873. static struct console fiq_debugger_console = {
  874. .name = "ttyFIQ",
  875. .device = debug_console_device,
  876. .write = debug_console_write,
  877. .flags = CON_PRINTBUFFER | CON_ANYTIME | CON_ENABLED,
  878. };
  879. int fiq_tty_open(struct tty_struct *tty, struct file *filp)
  880. {
  881. int line = tty->index;
  882. struct fiq_debugger_state **states = tty->driver->driver_state;
  883. struct fiq_debugger_state *state = states[line];
  884. if (state->tty_open_count++)
  885. return 0;
  886. tty->driver_data = state;
  887. state->tty = tty;
  888. return 0;
  889. }
  890. void fiq_tty_close(struct tty_struct *tty, struct file *filp)
  891. {
  892. struct fiq_debugger_state *state = tty->driver_data;
  893. if (--state->tty_open_count)
  894. return;
  895. state->tty = NULL;
  896. }
  897. int fiq_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
  898. {
  899. int i;
  900. struct fiq_debugger_state *state = tty->driver_data;
  901. if (!state->console_enable)
  902. return count;
  903. debug_uart_enable(state);
  904. spin_lock_irq(&state->console_lock);
  905. for (i = 0; i < count; i++)
  906. debug_putc(state, *buf++);
  907. spin_unlock_irq(&state->console_lock);
  908. debug_uart_disable(state);
  909. return count;
  910. }
  911. int fiq_tty_write_room(struct tty_struct *tty)
  912. {
  913. return 16;
  914. }
  915. #ifdef CONFIG_CONSOLE_POLL
  916. static int fiq_tty_poll_init(struct tty_driver *driver, int line, char *options)
  917. {
  918. return 0;
  919. }
  920. static int fiq_tty_poll_get_char(struct tty_driver *driver, int line)
  921. {
  922. struct fiq_debugger_state *state = driver->ttys[line]->driver_data;
  923. int c = NO_POLL_CHAR;
  924. debug_uart_enable(state);
  925. if (debug_have_fiq(state)) {
  926. int count = fiq_debugger_ringbuf_level(state->tty_rbuf);
  927. if (count > 0) {
  928. c = fiq_debugger_ringbuf_peek(state->tty_rbuf, 0);
  929. fiq_debugger_ringbuf_consume(state->tty_rbuf, 1);
  930. }
  931. } else {
  932. c = debug_getc(state);
  933. if (c == FIQ_DEBUGGER_NO_CHAR)
  934. c = NO_POLL_CHAR;
  935. }
  936. debug_uart_disable(state);
  937. return c;
  938. }
  939. static void fiq_tty_poll_put_char(struct tty_driver *driver, int line, char ch)
  940. {
  941. struct fiq_debugger_state *state = driver->ttys[line]->driver_data;
  942. debug_uart_enable(state);
  943. debug_putc(state, ch);
  944. debug_uart_disable(state);
  945. }
  946. #endif
  947. static const struct tty_operations fiq_tty_driver_ops = {
  948. .write = fiq_tty_write,
  949. .write_room = fiq_tty_write_room,
  950. .open = fiq_tty_open,
  951. .close = fiq_tty_close,
  952. #ifdef CONFIG_CONSOLE_POLL
  953. .poll_init = fiq_tty_poll_init,
  954. .poll_get_char = fiq_tty_poll_get_char,
  955. .poll_put_char = fiq_tty_poll_put_char,
  956. #endif
  957. };
  958. static int fiq_debugger_tty_init(void)
  959. {
  960. int ret;
  961. struct fiq_debugger_state **states = NULL;
  962. states = kzalloc(sizeof(*states) * MAX_FIQ_DEBUGGER_PORTS, GFP_KERNEL);
  963. if (!states) {
  964. pr_err("Failed to allocate fiq debugger state structres\n");
  965. return -ENOMEM;
  966. }
  967. fiq_tty_driver = alloc_tty_driver(MAX_FIQ_DEBUGGER_PORTS);
  968. if (!fiq_tty_driver) {
  969. pr_err("Failed to allocate fiq debugger tty\n");
  970. ret = -ENOMEM;
  971. goto err_free_state;
  972. }
  973. fiq_tty_driver->owner = THIS_MODULE;
  974. fiq_tty_driver->driver_name = "fiq-debugger";
  975. fiq_tty_driver->name = "ttyFIQ";
  976. fiq_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
  977. fiq_tty_driver->subtype = SERIAL_TYPE_NORMAL;
  978. fiq_tty_driver->init_termios = tty_std_termios;
  979. fiq_tty_driver->flags = TTY_DRIVER_REAL_RAW |
  980. TTY_DRIVER_DYNAMIC_DEV;
  981. fiq_tty_driver->driver_state = states;
  982. fiq_tty_driver->init_termios.c_cflag =
  983. B115200 | CS8 | CREAD | HUPCL | CLOCAL;
  984. fiq_tty_driver->init_termios.c_ispeed = 115200;
  985. fiq_tty_driver->init_termios.c_ospeed = 115200;
  986. tty_set_operations(fiq_tty_driver, &fiq_tty_driver_ops);
  987. ret = tty_register_driver(fiq_tty_driver);
  988. if (ret) {
  989. pr_err("Failed to register fiq tty: %d\n", ret);
  990. goto err_free_tty;
  991. }
  992. pr_info("Registered FIQ tty driver\n");
  993. return 0;
  994. err_free_tty:
  995. put_tty_driver(fiq_tty_driver);
  996. fiq_tty_driver = NULL;
  997. err_free_state:
  998. kfree(states);
  999. return ret;
  1000. }
  1001. static int fiq_debugger_tty_init_one(struct fiq_debugger_state *state)
  1002. {
  1003. int ret;
  1004. struct device *tty_dev;
  1005. struct fiq_debugger_state **states = fiq_tty_driver->driver_state;
  1006. states[state->pdev->id] = state;
  1007. state->tty_rbuf = fiq_debugger_ringbuf_alloc(1024);
  1008. if (!state->tty_rbuf) {
  1009. pr_err("Failed to allocate fiq debugger ringbuf\n");
  1010. ret = -ENOMEM;
  1011. goto err;
  1012. }
  1013. tty_dev = tty_register_device(fiq_tty_driver, state->pdev->id,
  1014. &state->pdev->dev);
  1015. if (IS_ERR(tty_dev)) {
  1016. pr_err("Failed to register fiq debugger tty device\n");
  1017. ret = PTR_ERR(tty_dev);
  1018. goto err;
  1019. }
  1020. device_set_wakeup_capable(tty_dev, 1);
  1021. pr_info("Registered fiq debugger ttyFIQ%d\n", state->pdev->id);
  1022. return 0;
  1023. err:
  1024. fiq_debugger_ringbuf_free(state->tty_rbuf);
  1025. state->tty_rbuf = NULL;
  1026. return ret;
  1027. }
  1028. #endif
  1029. static int fiq_debugger_dev_suspend(struct device *dev)
  1030. {
  1031. struct platform_device *pdev = to_platform_device(dev);
  1032. struct fiq_debugger_state *state = platform_get_drvdata(pdev);
  1033. if (state->pdata->uart_dev_suspend)
  1034. return state->pdata->uart_dev_suspend(pdev);
  1035. return 0;
  1036. }
  1037. static int fiq_debugger_dev_resume(struct device *dev)
  1038. {
  1039. struct platform_device *pdev = to_platform_device(dev);
  1040. struct fiq_debugger_state *state = platform_get_drvdata(pdev);
  1041. if (state->pdata->uart_dev_resume)
  1042. return state->pdata->uart_dev_resume(pdev);
  1043. return 0;
  1044. }
  1045. static int fiq_debugger_probe(struct platform_device *pdev)
  1046. {
  1047. int ret;
  1048. struct fiq_debugger_pdata *pdata = dev_get_platdata(&pdev->dev);
  1049. struct fiq_debugger_state *state;
  1050. int fiq;
  1051. int uart_irq;
  1052. if (pdev->id >= MAX_FIQ_DEBUGGER_PORTS)
  1053. return -EINVAL;
  1054. if (!pdata->uart_getc || !pdata->uart_putc)
  1055. return -EINVAL;
  1056. if ((pdata->uart_enable && !pdata->uart_disable) ||
  1057. (!pdata->uart_enable && pdata->uart_disable))
  1058. return -EINVAL;
  1059. fiq = platform_get_irq_byname(pdev, "fiq");
  1060. uart_irq = platform_get_irq_byname(pdev, "uart_irq");
  1061. /* uart_irq mode and fiq mode are mutually exclusive, but one of them
  1062. * is required */
  1063. if ((uart_irq < 0 && fiq < 0) || (uart_irq >= 0 && fiq >= 0))
  1064. return -EINVAL;
  1065. if (fiq >= 0 && !pdata->fiq_enable)
  1066. return -EINVAL;
  1067. state = kzalloc(sizeof(*state), GFP_KERNEL);
  1068. setup_timer(&state->sleep_timer, sleep_timer_expired,
  1069. (unsigned long)state);
  1070. state->pdata = pdata;
  1071. state->pdev = pdev;
  1072. state->no_sleep = initial_no_sleep;
  1073. state->debug_enable = initial_debug_enable;
  1074. state->console_enable = initial_console_enable;
  1075. state->fiq = fiq;
  1076. state->uart_irq = uart_irq;
  1077. state->signal_irq = platform_get_irq_byname(pdev, "signal");
  1078. state->wakeup_irq = platform_get_irq_byname(pdev, "wakeup");
  1079. INIT_WORK(&state->work, debug_work);
  1080. spin_lock_init(&state->work_lock);
  1081. platform_set_drvdata(pdev, state);
  1082. spin_lock_init(&state->sleep_timer_lock);
  1083. if (state->wakeup_irq < 0 && debug_have_fiq(state))
  1084. state->no_sleep = true;
  1085. state->ignore_next_wakeup_irq = !state->no_sleep;
  1086. wake_lock_init(&state->debugger_wake_lock,
  1087. WAKE_LOCK_SUSPEND, "serial-debug");
  1088. state->clk = clk_get(&pdev->dev, NULL);
  1089. if (IS_ERR(state->clk))
  1090. state->clk = NULL;
  1091. /* do not call pdata->uart_enable here since uart_init may still
  1092. * need to do some initialization before uart_enable can work.
  1093. * So, only try to manage the clock during init.
  1094. */
  1095. if (state->clk)
  1096. clk_enable(state->clk);
  1097. if (pdata->uart_init) {
  1098. ret = pdata->uart_init(pdev);
  1099. if (ret)
  1100. goto err_uart_init;
  1101. }
  1102. debug_printf_nfiq(state, "<hit enter %sto activate fiq debugger>\n",
  1103. state->no_sleep ? "" : "twice ");
  1104. if (debug_have_fiq(state)) {
  1105. state->handler.fiq = debug_fiq;
  1106. state->handler.resume = debug_resume;
  1107. ret = fiq_glue_register_handler(&state->handler);
  1108. if (ret) {
  1109. pr_err("%s: could not install fiq handler\n", __func__);
  1110. goto err_register_fiq;
  1111. }
  1112. pdata->fiq_enable(pdev, state->fiq, 1);
  1113. } else {
  1114. ret = request_irq(state->uart_irq, debug_uart_irq,
  1115. IRQF_NO_SUSPEND, "debug", state);
  1116. if (ret) {
  1117. pr_err("%s: could not install irq handler\n", __func__);
  1118. goto err_register_irq;
  1119. }
  1120. /* for irq-only mode, we want this irq to wake us up, if it
  1121. * can.
  1122. */
  1123. enable_irq_wake(state->uart_irq);
  1124. }
  1125. if (state->clk)
  1126. clk_disable(state->clk);
  1127. if (state->signal_irq >= 0) {
  1128. ret = request_irq(state->signal_irq, debug_signal_irq,
  1129. IRQF_TRIGGER_RISING, "debug-signal", state);
  1130. if (ret)
  1131. pr_err("serial_debugger: could not install signal_irq");
  1132. }
  1133. if (state->wakeup_irq >= 0) {
  1134. ret = request_irq(state->wakeup_irq, wakeup_irq_handler,
  1135. IRQF_TRIGGER_FALLING | IRQF_DISABLED,
  1136. "debug-wakeup", state);
  1137. if (ret) {
  1138. pr_err("serial_debugger: "
  1139. "could not install wakeup irq\n");
  1140. state->wakeup_irq = -1;
  1141. } else {
  1142. ret = enable_irq_wake(state->wakeup_irq);
  1143. if (ret) {
  1144. pr_err("serial_debugger: "
  1145. "could not enable wakeup\n");
  1146. state->wakeup_irq_no_set_wake = true;
  1147. }
  1148. }
  1149. }
  1150. if (state->no_sleep)
  1151. handle_wakeup(state);
  1152. #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
  1153. spin_lock_init(&state->console_lock);
  1154. state->console = fiq_debugger_console;
  1155. state->console.index = pdev->id;
  1156. if (!console_set_on_cmdline)
  1157. add_preferred_console(state->console.name,
  1158. state->console.index, NULL);
  1159. register_console(&state->console);
  1160. fiq_debugger_tty_init_one(state);
  1161. #endif
  1162. return 0;
  1163. err_register_irq:
  1164. err_register_fiq:
  1165. if (pdata->uart_free)
  1166. pdata->uart_free(pdev);
  1167. err_uart_init:
  1168. if (state->clk)
  1169. clk_disable(state->clk);
  1170. if (state->clk)
  1171. clk_put(state->clk);
  1172. wake_lock_destroy(&state->debugger_wake_lock);
  1173. platform_set_drvdata(pdev, NULL);
  1174. kfree(state);
  1175. return ret;
  1176. }
  1177. static const struct dev_pm_ops fiq_debugger_dev_pm_ops = {
  1178. .suspend = fiq_debugger_dev_suspend,
  1179. .resume = fiq_debugger_dev_resume,
  1180. };
  1181. static struct platform_driver fiq_debugger_driver = {
  1182. .probe = fiq_debugger_probe,
  1183. .driver = {
  1184. .name = "fiq_debugger",
  1185. .pm = &fiq_debugger_dev_pm_ops,
  1186. },
  1187. };
  1188. static int __init fiq_debugger_init(void)
  1189. {
  1190. fiq_debugger_tty_init();
  1191. return platform_driver_register(&fiq_debugger_driver);
  1192. }
  1193. postcore_initcall(fiq_debugger_init);