Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1 | /* |
Colin Cross | 66bbef2 | 2014-04-02 18:30:04 -0700 | [diff] [blame] | 2 | * drivers/staging/android/fiq_debugger.c |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 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 | |
| 18 | #include <stdarg.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/console.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/clk.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/kernel_stat.h> |
Arve Hjønnevåg | 9de62e0 | 2012-11-26 20:05:37 -0800 | [diff] [blame] | 26 | #include <linux/kmsg_dump.h> |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 27 | #include <linux/irq.h> |
| 28 | #include <linux/delay.h> |
Colin Cross | 69279c6 | 2012-03-14 16:28:45 -0700 | [diff] [blame] | 29 | #include <linux/reboot.h> |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 30 | #include <linux/sched.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/smp.h> |
| 33 | #include <linux/timer.h> |
| 34 | #include <linux/tty.h> |
| 35 | #include <linux/tty_flip.h> |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 36 | |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 37 | #ifdef CONFIG_FIQ_GLUE |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 38 | #include <asm/fiq_glue.h> |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 39 | #endif |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 40 | |
Dmitry Shmidt | caff55c | 2016-05-04 13:51:38 -0700 | [diff] [blame] | 41 | #ifdef CONFIG_FIQ_DEBUGGER_UART_OVERLAY |
| 42 | #include <linux/of.h> |
| 43 | #endif |
| 44 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 45 | #include <linux/uaccess.h> |
| 46 | |
Colin Cross | 66bbef2 | 2014-04-02 18:30:04 -0700 | [diff] [blame] | 47 | #include "fiq_debugger.h" |
Colin Cross | cffbe78 | 2014-04-02 18:42:13 -0700 | [diff] [blame] | 48 | #include "fiq_debugger_priv.h" |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 49 | #include "fiq_debugger_ringbuf.h" |
| 50 | |
| 51 | #define DEBUG_MAX 64 |
| 52 | #define MAX_UNHANDLED_FIQ_COUNT 1000000 |
| 53 | |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 54 | #define MAX_FIQ_DEBUGGER_PORTS 4 |
| 55 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 56 | struct fiq_debugger_state { |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 57 | #ifdef CONFIG_FIQ_GLUE |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 58 | struct fiq_glue_handler handler; |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 59 | #endif |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 60 | struct fiq_debugger_output output; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 61 | |
| 62 | int fiq; |
| 63 | int uart_irq; |
| 64 | int signal_irq; |
| 65 | int wakeup_irq; |
| 66 | bool wakeup_irq_no_set_wake; |
| 67 | struct clk *clk; |
| 68 | struct fiq_debugger_pdata *pdata; |
| 69 | struct platform_device *pdev; |
| 70 | |
| 71 | char debug_cmd[DEBUG_MAX]; |
| 72 | int debug_busy; |
| 73 | int debug_abort; |
| 74 | |
| 75 | char debug_buf[DEBUG_MAX]; |
| 76 | int debug_count; |
| 77 | |
| 78 | bool no_sleep; |
| 79 | bool debug_enable; |
| 80 | bool ignore_next_wakeup_irq; |
| 81 | struct timer_list sleep_timer; |
| 82 | spinlock_t sleep_timer_lock; |
| 83 | bool uart_enabled; |
Dmitry Shmidt | b4a2694 | 2017-01-12 12:28:08 -0800 | [diff] [blame] | 84 | struct wakeup_source debugger_wake_src; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 85 | bool console_enable; |
| 86 | int current_cpu; |
| 87 | atomic_t unhandled_fiq_count; |
| 88 | bool in_fiq; |
| 89 | |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 90 | struct work_struct work; |
| 91 | spinlock_t work_lock; |
| 92 | char work_cmd[DEBUG_MAX]; |
| 93 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 94 | #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 95 | spinlock_t console_lock; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 96 | struct console console; |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 97 | struct tty_port tty_port; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 98 | struct fiq_debugger_ringbuf *tty_rbuf; |
| 99 | bool syslog_dumping; |
| 100 | #endif |
| 101 | |
| 102 | unsigned int last_irqs[NR_IRQS]; |
| 103 | unsigned int last_local_timer_irqs[NR_CPUS]; |
| 104 | }; |
| 105 | |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 106 | #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE |
| 107 | struct tty_driver *fiq_tty_driver; |
| 108 | #endif |
| 109 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 110 | #ifdef CONFIG_FIQ_DEBUGGER_NO_SLEEP |
| 111 | static bool initial_no_sleep = true; |
| 112 | #else |
| 113 | static bool initial_no_sleep; |
| 114 | #endif |
| 115 | |
| 116 | #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE_DEFAULT_ENABLE |
| 117 | static bool initial_debug_enable = true; |
| 118 | static bool initial_console_enable = true; |
| 119 | #else |
| 120 | static bool initial_debug_enable; |
| 121 | static bool initial_console_enable; |
| 122 | #endif |
| 123 | |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 124 | static bool fiq_kgdb_enable; |
Dmitry Shmidt | 023f889 | 2016-05-11 11:01:02 -0700 | [diff] [blame] | 125 | static bool fiq_debugger_disable; |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 126 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 127 | module_param_named(no_sleep, initial_no_sleep, bool, 0644); |
| 128 | module_param_named(debug_enable, initial_debug_enable, bool, 0644); |
| 129 | module_param_named(console_enable, initial_console_enable, bool, 0644); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 130 | module_param_named(kgdb_enable, fiq_kgdb_enable, bool, 0644); |
Dmitry Shmidt | 023f889 | 2016-05-11 11:01:02 -0700 | [diff] [blame] | 131 | module_param_named(disable, fiq_debugger_disable, bool, 0644); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 132 | |
| 133 | #ifdef CONFIG_FIQ_DEBUGGER_WAKEUP_IRQ_ALWAYS_ON |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 134 | static inline |
| 135 | void fiq_debugger_enable_wakeup_irq(struct fiq_debugger_state *state) {} |
| 136 | static inline |
| 137 | void fiq_debugger_disable_wakeup_irq(struct fiq_debugger_state *state) {} |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 138 | #else |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 139 | static inline |
| 140 | void fiq_debugger_enable_wakeup_irq(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 141 | { |
| 142 | if (state->wakeup_irq < 0) |
| 143 | return; |
| 144 | enable_irq(state->wakeup_irq); |
| 145 | if (!state->wakeup_irq_no_set_wake) |
| 146 | enable_irq_wake(state->wakeup_irq); |
| 147 | } |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 148 | static inline |
| 149 | void fiq_debugger_disable_wakeup_irq(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 150 | { |
| 151 | if (state->wakeup_irq < 0) |
| 152 | return; |
| 153 | disable_irq_nosync(state->wakeup_irq); |
| 154 | if (!state->wakeup_irq_no_set_wake) |
| 155 | disable_irq_wake(state->wakeup_irq); |
| 156 | } |
| 157 | #endif |
| 158 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 159 | static inline bool fiq_debugger_have_fiq(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 160 | { |
| 161 | return (state->fiq >= 0); |
| 162 | } |
| 163 | |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 164 | #ifdef CONFIG_FIQ_GLUE |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 165 | static void fiq_debugger_force_irq(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 166 | { |
| 167 | unsigned int irq = state->signal_irq; |
| 168 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 169 | if (WARN_ON(!fiq_debugger_have_fiq(state))) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 170 | return; |
| 171 | if (state->pdata->force_irq) { |
| 172 | state->pdata->force_irq(state->pdev, irq); |
| 173 | } else { |
| 174 | struct irq_chip *chip = irq_get_chip(irq); |
| 175 | if (chip && chip->irq_retrigger) |
| 176 | chip->irq_retrigger(irq_get_irq_data(irq)); |
| 177 | } |
| 178 | } |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 179 | #endif |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 180 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 181 | static void fiq_debugger_uart_enable(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 182 | { |
| 183 | if (state->clk) |
| 184 | clk_enable(state->clk); |
| 185 | if (state->pdata->uart_enable) |
| 186 | state->pdata->uart_enable(state->pdev); |
| 187 | } |
| 188 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 189 | static void fiq_debugger_uart_disable(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 190 | { |
| 191 | if (state->pdata->uart_disable) |
| 192 | state->pdata->uart_disable(state->pdev); |
| 193 | if (state->clk) |
| 194 | clk_disable(state->clk); |
| 195 | } |
| 196 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 197 | static void fiq_debugger_uart_flush(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 198 | { |
| 199 | if (state->pdata->uart_flush) |
| 200 | state->pdata->uart_flush(state->pdev); |
| 201 | } |
| 202 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 203 | static void fiq_debugger_putc(struct fiq_debugger_state *state, char c) |
Colin Cross | 31c550f | 2012-03-15 12:57:20 -0700 | [diff] [blame] | 204 | { |
| 205 | state->pdata->uart_putc(state->pdev, c); |
| 206 | } |
| 207 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 208 | static void fiq_debugger_puts(struct fiq_debugger_state *state, char *s) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 209 | { |
| 210 | unsigned c; |
| 211 | while ((c = *s++)) { |
| 212 | if (c == '\n') |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 213 | fiq_debugger_putc(state, '\r'); |
| 214 | fiq_debugger_putc(state, c); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 218 | static void fiq_debugger_prompt(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 219 | { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 220 | fiq_debugger_puts(state, "debug> "); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 223 | static void fiq_debugger_dump_kernel_log(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 224 | { |
Arve Hjønnevåg | 9de62e0 | 2012-11-26 20:05:37 -0800 | [diff] [blame] | 225 | char buf[512]; |
| 226 | size_t len; |
| 227 | struct kmsg_dumper dumper = { .active = true }; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 228 | |
Arve Hjønnevåg | 9de62e0 | 2012-11-26 20:05:37 -0800 | [diff] [blame] | 229 | |
| 230 | kmsg_dump_rewind_nolock(&dumper); |
| 231 | while (kmsg_dump_get_line_nolock(&dumper, true, buf, |
| 232 | sizeof(buf) - 1, &len)) { |
| 233 | buf[len] = 0; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 234 | fiq_debugger_puts(state, buf); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 235 | } |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 238 | static void fiq_debugger_printf(struct fiq_debugger_output *output, |
| 239 | const char *fmt, ...) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 240 | { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 241 | struct fiq_debugger_state *state; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 242 | char buf[256]; |
| 243 | va_list ap; |
| 244 | |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 245 | state = container_of(output, struct fiq_debugger_state, output); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 246 | va_start(ap, fmt); |
| 247 | vsnprintf(buf, sizeof(buf), fmt, ap); |
| 248 | va_end(ap); |
| 249 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 250 | fiq_debugger_puts(state, buf); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /* Safe outside fiq context */ |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 254 | static int fiq_debugger_printf_nfiq(void *cookie, const char *fmt, ...) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 255 | { |
| 256 | struct fiq_debugger_state *state = cookie; |
| 257 | char buf[256]; |
| 258 | va_list ap; |
| 259 | unsigned long irq_flags; |
| 260 | |
| 261 | va_start(ap, fmt); |
| 262 | vsnprintf(buf, 128, fmt, ap); |
| 263 | va_end(ap); |
| 264 | |
| 265 | local_irq_save(irq_flags); |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 266 | fiq_debugger_puts(state, buf); |
| 267 | fiq_debugger_uart_flush(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 268 | local_irq_restore(irq_flags); |
| 269 | return state->debug_abort; |
| 270 | } |
| 271 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 272 | static void fiq_debugger_dump_irqs(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 273 | { |
| 274 | int n; |
Arve Hjønnevåg | d05890d | 2012-11-26 16:23:33 -0800 | [diff] [blame] | 275 | struct irq_desc *desc; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 276 | |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 277 | fiq_debugger_printf(&state->output, |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 278 | "irqnr total since-last status name\n"); |
Arve Hjønnevåg | d05890d | 2012-11-26 16:23:33 -0800 | [diff] [blame] | 279 | for_each_irq_desc(n, desc) { |
| 280 | struct irqaction *act = desc->action; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 281 | if (!act && !kstat_irqs(n)) |
| 282 | continue; |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 283 | fiq_debugger_printf(&state->output, "%5d: %10u %11u %8x %s\n", n, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 284 | kstat_irqs(n), |
| 285 | kstat_irqs(n) - state->last_irqs[n], |
Arve Hjønnevåg | d05890d | 2012-11-26 16:23:33 -0800 | [diff] [blame] | 286 | desc->status_use_accessors, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 287 | (act && act->name) ? act->name : "???"); |
| 288 | state->last_irqs[n] = kstat_irqs(n); |
| 289 | } |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 292 | static void fiq_debugger_do_ps(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 293 | { |
| 294 | struct task_struct *g; |
| 295 | struct task_struct *p; |
| 296 | unsigned task_state; |
| 297 | static const char stat_nam[] = "RSDTtZX"; |
| 298 | |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 299 | fiq_debugger_printf(&state->output, "pid ppid prio task pc\n"); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 300 | read_lock(&tasklist_lock); |
| 301 | do_each_thread(g, p) { |
| 302 | task_state = p->state ? __ffs(p->state) + 1 : 0; |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 303 | fiq_debugger_printf(&state->output, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 304 | "%5d %5d %4d ", p->pid, p->parent->pid, p->prio); |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 305 | fiq_debugger_printf(&state->output, "%-13.13s %c", p->comm, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 306 | task_state >= sizeof(stat_nam) ? '?' : stat_nam[task_state]); |
| 307 | if (task_state == TASK_RUNNING) |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 308 | fiq_debugger_printf(&state->output, " running\n"); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 309 | else |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 310 | fiq_debugger_printf(&state->output, " %08lx\n", |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 311 | thread_saved_pc(p)); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 312 | } while_each_thread(g, p); |
| 313 | read_unlock(&tasklist_lock); |
| 314 | } |
| 315 | |
| 316 | #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 317 | static void fiq_debugger_begin_syslog_dump(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 318 | { |
| 319 | state->syslog_dumping = true; |
| 320 | } |
| 321 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 322 | static void fiq_debugger_end_syslog_dump(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 323 | { |
| 324 | state->syslog_dumping = false; |
| 325 | } |
| 326 | #else |
| 327 | extern int do_syslog(int type, char __user *bug, int count); |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 328 | static void fiq_debugger_begin_syslog_dump(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 329 | { |
| 330 | do_syslog(5 /* clear */, NULL, 0); |
| 331 | } |
| 332 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 333 | static void fiq_debugger_end_syslog_dump(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 334 | { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 335 | fiq_debugger_dump_kernel_log(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 336 | } |
| 337 | #endif |
| 338 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 339 | static void fiq_debugger_do_sysrq(struct fiq_debugger_state *state, char rq) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 340 | { |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 341 | if ((rq == 'g' || rq == 'G') && !fiq_kgdb_enable) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 342 | fiq_debugger_printf(&state->output, "sysrq-g blocked\n"); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 343 | return; |
| 344 | } |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 345 | fiq_debugger_begin_syslog_dump(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 346 | handle_sysrq(rq); |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 347 | fiq_debugger_end_syslog_dump(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 350 | #ifdef CONFIG_KGDB |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 351 | static void fiq_debugger_do_kgdb(struct fiq_debugger_state *state) |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 352 | { |
| 353 | if (!fiq_kgdb_enable) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 354 | fiq_debugger_printf(&state->output, "kgdb through fiq debugger not enabled\n"); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 358 | fiq_debugger_printf(&state->output, "enabling console and triggering kgdb\n"); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 359 | state->console_enable = true; |
| 360 | handle_sysrq('g'); |
| 361 | } |
| 362 | #endif |
| 363 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 364 | static void fiq_debugger_schedule_work(struct fiq_debugger_state *state, |
| 365 | char *cmd) |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 366 | { |
| 367 | unsigned long flags; |
| 368 | |
| 369 | spin_lock_irqsave(&state->work_lock, flags); |
| 370 | if (state->work_cmd[0] != '\0') { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 371 | fiq_debugger_printf(&state->output, "work command processor busy\n"); |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 372 | spin_unlock_irqrestore(&state->work_lock, flags); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | strlcpy(state->work_cmd, cmd, sizeof(state->work_cmd)); |
| 377 | spin_unlock_irqrestore(&state->work_lock, flags); |
| 378 | |
| 379 | schedule_work(&state->work); |
| 380 | } |
| 381 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 382 | static void fiq_debugger_work(struct work_struct *work) |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 383 | { |
| 384 | struct fiq_debugger_state *state; |
| 385 | char work_cmd[DEBUG_MAX]; |
| 386 | char *cmd; |
| 387 | unsigned long flags; |
| 388 | |
| 389 | state = container_of(work, struct fiq_debugger_state, work); |
| 390 | |
| 391 | spin_lock_irqsave(&state->work_lock, flags); |
| 392 | |
| 393 | strlcpy(work_cmd, state->work_cmd, sizeof(work_cmd)); |
| 394 | state->work_cmd[0] = '\0'; |
| 395 | |
| 396 | spin_unlock_irqrestore(&state->work_lock, flags); |
| 397 | |
| 398 | cmd = work_cmd; |
| 399 | if (!strncmp(cmd, "reboot", 6)) { |
| 400 | cmd += 6; |
| 401 | while (*cmd == ' ') |
| 402 | cmd++; |
Greg Kaiser | 3b61956 | 2017-09-05 15:55:41 -0700 | [diff] [blame] | 403 | if (*cmd != '\0') |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 404 | kernel_restart(cmd); |
| 405 | else |
| 406 | kernel_restart(NULL); |
| 407 | } else { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 408 | fiq_debugger_printf(&state->output, "unknown work command '%s'\n", |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 409 | work_cmd); |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 413 | /* This function CANNOT be called in FIQ context */ |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 414 | static void fiq_debugger_irq_exec(struct fiq_debugger_state *state, char *cmd) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 415 | { |
| 416 | if (!strcmp(cmd, "ps")) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 417 | fiq_debugger_do_ps(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 418 | if (!strcmp(cmd, "sysrq")) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 419 | fiq_debugger_do_sysrq(state, 'h'); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 420 | if (!strncmp(cmd, "sysrq ", 6)) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 421 | fiq_debugger_do_sysrq(state, cmd[6]); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 422 | #ifdef CONFIG_KGDB |
| 423 | if (!strcmp(cmd, "kgdb")) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 424 | fiq_debugger_do_kgdb(state); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 425 | #endif |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 426 | if (!strncmp(cmd, "reboot", 6)) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 427 | fiq_debugger_schedule_work(state, cmd); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 430 | static void fiq_debugger_help(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 431 | { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 432 | fiq_debugger_printf(&state->output, |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 433 | "FIQ Debugger commands:\n" |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 434 | " pc PC status\n" |
| 435 | " regs Register dump\n" |
| 436 | " allregs Extended Register dump\n" |
| 437 | " bt Stack trace\n" |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 438 | " reboot [<c>] Reboot with command <c>\n" |
| 439 | " reset [<c>] Hard reset with command <c>\n" |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 440 | " irqs Interupt status\n" |
| 441 | " kmsg Kernel log\n" |
| 442 | " version Kernel version\n"); |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 443 | fiq_debugger_printf(&state->output, |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 444 | " sleep Allow sleep while in FIQ\n" |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 445 | " nosleep Disable sleep while in FIQ\n" |
| 446 | " console Switch terminal to console\n" |
| 447 | " cpu Current CPU\n" |
| 448 | " cpu <number> Switch to CPU<number>\n"); |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 449 | fiq_debugger_printf(&state->output, |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 450 | " ps Process list\n" |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 451 | " sysrq sysrq options\n" |
| 452 | " sysrq <param> Execute sysrq with <param>\n"); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 453 | #ifdef CONFIG_KGDB |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 454 | fiq_debugger_printf(&state->output, |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 455 | " kgdb Enter kernel debugger\n"); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 456 | #endif |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 459 | static void fiq_debugger_take_affinity(void *info) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 460 | { |
| 461 | struct fiq_debugger_state *state = info; |
| 462 | struct cpumask cpumask; |
| 463 | |
| 464 | cpumask_clear(&cpumask); |
| 465 | cpumask_set_cpu(get_cpu(), &cpumask); |
| 466 | |
| 467 | irq_set_affinity(state->uart_irq, &cpumask); |
| 468 | } |
| 469 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 470 | static void fiq_debugger_switch_cpu(struct fiq_debugger_state *state, int cpu) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 471 | { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 472 | if (!fiq_debugger_have_fiq(state)) |
| 473 | smp_call_function_single(cpu, fiq_debugger_take_affinity, state, |
| 474 | false); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 475 | state->current_cpu = cpu; |
| 476 | } |
| 477 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 478 | static bool fiq_debugger_fiq_exec(struct fiq_debugger_state *state, |
Colin Cross | 7efcbb8 | 2014-04-04 17:05:19 -0700 | [diff] [blame] | 479 | const char *cmd, const struct pt_regs *regs, |
| 480 | void *svc_sp) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 481 | { |
| 482 | bool signal_helper = false; |
| 483 | |
| 484 | if (!strcmp(cmd, "help") || !strcmp(cmd, "?")) { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 485 | fiq_debugger_help(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 486 | } else if (!strcmp(cmd, "pc")) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 487 | fiq_debugger_dump_pc(&state->output, regs); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 488 | } else if (!strcmp(cmd, "regs")) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 489 | fiq_debugger_dump_regs(&state->output, regs); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 490 | } else if (!strcmp(cmd, "allregs")) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 491 | fiq_debugger_dump_allregs(&state->output, regs); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 492 | } else if (!strcmp(cmd, "bt")) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 493 | fiq_debugger_dump_stacktrace(&state->output, regs, 100, svc_sp); |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 494 | } else if (!strncmp(cmd, "reset", 5)) { |
| 495 | cmd += 5; |
Colin Cross | ae9d69a | 2012-03-14 16:29:47 -0700 | [diff] [blame] | 496 | while (*cmd == ' ') |
| 497 | cmd++; |
| 498 | if (*cmd) { |
| 499 | char tmp_cmd[32]; |
| 500 | strlcpy(tmp_cmd, cmd, sizeof(tmp_cmd)); |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 501 | machine_restart(tmp_cmd); |
Colin Cross | ae9d69a | 2012-03-14 16:29:47 -0700 | [diff] [blame] | 502 | } else { |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 503 | machine_restart(NULL); |
Colin Cross | ae9d69a | 2012-03-14 16:29:47 -0700 | [diff] [blame] | 504 | } |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 505 | } else if (!strcmp(cmd, "irqs")) { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 506 | fiq_debugger_dump_irqs(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 507 | } else if (!strcmp(cmd, "kmsg")) { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 508 | fiq_debugger_dump_kernel_log(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 509 | } else if (!strcmp(cmd, "version")) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 510 | fiq_debugger_printf(&state->output, "%s\n", linux_banner); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 511 | } else if (!strcmp(cmd, "sleep")) { |
| 512 | state->no_sleep = false; |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 513 | fiq_debugger_printf(&state->output, "enabling sleep\n"); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 514 | } else if (!strcmp(cmd, "nosleep")) { |
| 515 | state->no_sleep = true; |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 516 | fiq_debugger_printf(&state->output, "disabling sleep\n"); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 517 | } else if (!strcmp(cmd, "console")) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 518 | fiq_debugger_printf(&state->output, "console mode\n"); |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 519 | fiq_debugger_uart_flush(state); |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 520 | state->console_enable = true; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 521 | } else if (!strcmp(cmd, "cpu")) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 522 | fiq_debugger_printf(&state->output, "cpu %d\n", state->current_cpu); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 523 | } else if (!strncmp(cmd, "cpu ", 4)) { |
| 524 | unsigned long cpu = 0; |
John Stultz | daeea72 | 2015-12-04 11:32:21 -0800 | [diff] [blame] | 525 | if (kstrtoul(cmd + 4, 10, &cpu) == 0) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 526 | fiq_debugger_switch_cpu(state, cpu); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 527 | else |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 528 | fiq_debugger_printf(&state->output, "invalid cpu\n"); |
| 529 | fiq_debugger_printf(&state->output, "cpu %d\n", state->current_cpu); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 530 | } else { |
| 531 | if (state->debug_busy) { |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 532 | fiq_debugger_printf(&state->output, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 533 | "command processor busy. trying to abort.\n"); |
| 534 | state->debug_abort = -1; |
| 535 | } else { |
| 536 | strcpy(state->debug_cmd, cmd); |
| 537 | state->debug_busy = 1; |
| 538 | } |
| 539 | |
| 540 | return true; |
| 541 | } |
| 542 | if (!state->console_enable) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 543 | fiq_debugger_prompt(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 544 | |
| 545 | return signal_helper; |
| 546 | } |
| 547 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 548 | static void fiq_debugger_sleep_timer_expired(unsigned long data) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 549 | { |
| 550 | struct fiq_debugger_state *state = (struct fiq_debugger_state *)data; |
| 551 | unsigned long flags; |
| 552 | |
| 553 | spin_lock_irqsave(&state->sleep_timer_lock, flags); |
| 554 | if (state->uart_enabled && !state->no_sleep) { |
| 555 | if (state->debug_enable && !state->console_enable) { |
| 556 | state->debug_enable = false; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 557 | fiq_debugger_printf_nfiq(state, |
| 558 | "suspending fiq debugger\n"); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 559 | } |
| 560 | state->ignore_next_wakeup_irq = true; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 561 | fiq_debugger_uart_disable(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 562 | state->uart_enabled = false; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 563 | fiq_debugger_enable_wakeup_irq(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 564 | } |
Dmitry Shmidt | b4a2694 | 2017-01-12 12:28:08 -0800 | [diff] [blame] | 565 | __pm_relax(&state->debugger_wake_src); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 566 | spin_unlock_irqrestore(&state->sleep_timer_lock, flags); |
| 567 | } |
| 568 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 569 | static void fiq_debugger_handle_wakeup(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 570 | { |
| 571 | unsigned long flags; |
| 572 | |
| 573 | spin_lock_irqsave(&state->sleep_timer_lock, flags); |
| 574 | if (state->wakeup_irq >= 0 && state->ignore_next_wakeup_irq) { |
| 575 | state->ignore_next_wakeup_irq = false; |
| 576 | } else if (!state->uart_enabled) { |
Dmitry Shmidt | b4a2694 | 2017-01-12 12:28:08 -0800 | [diff] [blame] | 577 | __pm_stay_awake(&state->debugger_wake_src); |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 578 | fiq_debugger_uart_enable(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 579 | state->uart_enabled = true; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 580 | fiq_debugger_disable_wakeup_irq(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 581 | mod_timer(&state->sleep_timer, jiffies + HZ / 2); |
| 582 | } |
| 583 | spin_unlock_irqrestore(&state->sleep_timer_lock, flags); |
| 584 | } |
| 585 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 586 | static irqreturn_t fiq_debugger_wakeup_irq_handler(int irq, void *dev) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 587 | { |
| 588 | struct fiq_debugger_state *state = dev; |
| 589 | |
| 590 | if (!state->no_sleep) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 591 | fiq_debugger_puts(state, "WAKEUP\n"); |
| 592 | fiq_debugger_handle_wakeup(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 593 | |
| 594 | return IRQ_HANDLED; |
| 595 | } |
| 596 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 597 | static |
| 598 | void fiq_debugger_handle_console_irq_context(struct fiq_debugger_state *state) |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 599 | { |
| 600 | #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE) |
| 601 | if (state->tty_port.ops) { |
| 602 | int i; |
| 603 | int count = fiq_debugger_ringbuf_level(state->tty_rbuf); |
| 604 | for (i = 0; i < count; i++) { |
| 605 | int c = fiq_debugger_ringbuf_peek(state->tty_rbuf, 0); |
| 606 | tty_insert_flip_char(&state->tty_port, c, TTY_NORMAL); |
| 607 | if (!fiq_debugger_ringbuf_consume(state->tty_rbuf, 1)) |
| 608 | pr_warn("fiq tty failed to consume byte\n"); |
| 609 | } |
| 610 | tty_flip_buffer_push(&state->tty_port); |
| 611 | } |
| 612 | #endif |
| 613 | } |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 614 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 615 | static void fiq_debugger_handle_irq_context(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 616 | { |
| 617 | if (!state->no_sleep) { |
| 618 | unsigned long flags; |
| 619 | |
| 620 | spin_lock_irqsave(&state->sleep_timer_lock, flags); |
Dmitry Shmidt | b4a2694 | 2017-01-12 12:28:08 -0800 | [diff] [blame] | 621 | __pm_stay_awake(&state->debugger_wake_src); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 622 | mod_timer(&state->sleep_timer, jiffies + HZ * 5); |
| 623 | spin_unlock_irqrestore(&state->sleep_timer_lock, flags); |
| 624 | } |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 625 | fiq_debugger_handle_console_irq_context(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 626 | if (state->debug_busy) { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 627 | fiq_debugger_irq_exec(state, state->debug_cmd); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 628 | if (!state->console_enable) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 629 | fiq_debugger_prompt(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 630 | state->debug_busy = 0; |
| 631 | } |
| 632 | } |
| 633 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 634 | static int fiq_debugger_getc(struct fiq_debugger_state *state) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 635 | { |
| 636 | return state->pdata->uart_getc(state->pdev); |
| 637 | } |
| 638 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 639 | static bool fiq_debugger_handle_uart_interrupt(struct fiq_debugger_state *state, |
Colin Cross | 7efcbb8 | 2014-04-04 17:05:19 -0700 | [diff] [blame] | 640 | int this_cpu, const struct pt_regs *regs, void *svc_sp) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 641 | { |
| 642 | int c; |
| 643 | static int last_c; |
| 644 | int count = 0; |
| 645 | bool signal_helper = false; |
| 646 | |
| 647 | if (this_cpu != state->current_cpu) { |
| 648 | if (state->in_fiq) |
| 649 | return false; |
| 650 | |
| 651 | if (atomic_inc_return(&state->unhandled_fiq_count) != |
| 652 | MAX_UNHANDLED_FIQ_COUNT) |
| 653 | return false; |
| 654 | |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 655 | fiq_debugger_printf(&state->output, |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 656 | "fiq_debugger: cpu %d not responding, " |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 657 | "reverting to cpu %d\n", state->current_cpu, |
| 658 | this_cpu); |
| 659 | |
| 660 | atomic_set(&state->unhandled_fiq_count, 0); |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 661 | fiq_debugger_switch_cpu(state, this_cpu); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 662 | return false; |
| 663 | } |
| 664 | |
| 665 | state->in_fiq = true; |
| 666 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 667 | while ((c = fiq_debugger_getc(state)) != FIQ_DEBUGGER_NO_CHAR) { |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 668 | count++; |
| 669 | if (!state->debug_enable) { |
| 670 | if ((c == 13) || (c == 10)) { |
| 671 | state->debug_enable = true; |
| 672 | state->debug_count = 0; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 673 | fiq_debugger_prompt(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 674 | } |
| 675 | } else if (c == FIQ_DEBUGGER_BREAK) { |
| 676 | state->console_enable = false; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 677 | fiq_debugger_puts(state, "fiq debugger mode\n"); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 678 | state->debug_count = 0; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 679 | fiq_debugger_prompt(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 680 | #ifdef CONFIG_FIQ_DEBUGGER_CONSOLE |
| 681 | } else if (state->console_enable && state->tty_rbuf) { |
| 682 | fiq_debugger_ringbuf_push(state->tty_rbuf, c); |
| 683 | signal_helper = true; |
| 684 | #endif |
| 685 | } else if ((c >= ' ') && (c < 127)) { |
| 686 | if (state->debug_count < (DEBUG_MAX - 1)) { |
| 687 | state->debug_buf[state->debug_count++] = c; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 688 | fiq_debugger_putc(state, c); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 689 | } |
| 690 | } else if ((c == 8) || (c == 127)) { |
| 691 | if (state->debug_count > 0) { |
| 692 | state->debug_count--; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 693 | fiq_debugger_putc(state, 8); |
| 694 | fiq_debugger_putc(state, ' '); |
| 695 | fiq_debugger_putc(state, 8); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 696 | } |
| 697 | } else if ((c == 13) || (c == 10)) { |
| 698 | if (c == '\r' || (c == '\n' && last_c != '\r')) { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 699 | fiq_debugger_putc(state, '\r'); |
| 700 | fiq_debugger_putc(state, '\n'); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 701 | } |
| 702 | if (state->debug_count) { |
| 703 | state->debug_buf[state->debug_count] = 0; |
| 704 | state->debug_count = 0; |
| 705 | signal_helper |= |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 706 | fiq_debugger_fiq_exec(state, |
| 707 | state->debug_buf, |
| 708 | regs, svc_sp); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 709 | } else { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 710 | fiq_debugger_prompt(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | last_c = c; |
| 714 | } |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 715 | if (!state->console_enable) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 716 | fiq_debugger_uart_flush(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 717 | if (state->pdata->fiq_ack) |
| 718 | state->pdata->fiq_ack(state->pdev, state->fiq); |
| 719 | |
| 720 | /* poke sleep timer if necessary */ |
| 721 | if (state->debug_enable && !state->no_sleep) |
| 722 | signal_helper = true; |
| 723 | |
| 724 | atomic_set(&state->unhandled_fiq_count, 0); |
| 725 | state->in_fiq = false; |
| 726 | |
| 727 | return signal_helper; |
| 728 | } |
| 729 | |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 730 | #ifdef CONFIG_FIQ_GLUE |
Colin Cross | 7efcbb8 | 2014-04-04 17:05:19 -0700 | [diff] [blame] | 731 | static void fiq_debugger_fiq(struct fiq_glue_handler *h, |
| 732 | const struct pt_regs *regs, void *svc_sp) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 733 | { |
| 734 | struct fiq_debugger_state *state = |
| 735 | container_of(h, struct fiq_debugger_state, handler); |
| 736 | unsigned int this_cpu = THREAD_INFO(svc_sp)->cpu; |
| 737 | bool need_irq; |
| 738 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 739 | need_irq = fiq_debugger_handle_uart_interrupt(state, this_cpu, regs, |
| 740 | svc_sp); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 741 | if (need_irq) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 742 | fiq_debugger_force_irq(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 743 | } |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 744 | #endif |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 745 | |
| 746 | /* |
| 747 | * When not using FIQs, we only use this single interrupt as an entry point. |
| 748 | * This just effectively takes over the UART interrupt and does all the work |
| 749 | * in this context. |
| 750 | */ |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 751 | static irqreturn_t fiq_debugger_uart_irq(int irq, void *dev) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 752 | { |
| 753 | struct fiq_debugger_state *state = dev; |
| 754 | bool not_done; |
| 755 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 756 | fiq_debugger_handle_wakeup(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 757 | |
| 758 | /* handle the debugger irq in regular context */ |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 759 | not_done = fiq_debugger_handle_uart_interrupt(state, smp_processor_id(), |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 760 | get_irq_regs(), |
| 761 | current_thread_info()); |
| 762 | if (not_done) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 763 | fiq_debugger_handle_irq_context(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 764 | |
| 765 | return IRQ_HANDLED; |
| 766 | } |
| 767 | |
| 768 | /* |
| 769 | * If FIQs are used, not everything can happen in fiq context. |
| 770 | * FIQ handler does what it can and then signals this interrupt to finish the |
| 771 | * job in irq context. |
| 772 | */ |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 773 | static irqreturn_t fiq_debugger_signal_irq(int irq, void *dev) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 774 | { |
| 775 | struct fiq_debugger_state *state = dev; |
| 776 | |
| 777 | if (state->pdata->force_irq_ack) |
| 778 | state->pdata->force_irq_ack(state->pdev, state->signal_irq); |
| 779 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 780 | fiq_debugger_handle_irq_context(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 781 | |
| 782 | return IRQ_HANDLED; |
| 783 | } |
| 784 | |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 785 | #ifdef CONFIG_FIQ_GLUE |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 786 | static void fiq_debugger_resume(struct fiq_glue_handler *h) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 787 | { |
| 788 | struct fiq_debugger_state *state = |
| 789 | container_of(h, struct fiq_debugger_state, handler); |
| 790 | if (state->pdata->uart_resume) |
| 791 | state->pdata->uart_resume(state->pdev); |
| 792 | } |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 793 | #endif |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 794 | |
| 795 | #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 796 | struct tty_driver *fiq_debugger_console_device(struct console *co, int *index) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 797 | { |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 798 | *index = co->index; |
| 799 | return fiq_tty_driver; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 802 | static void fiq_debugger_console_write(struct console *co, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 803 | const char *s, unsigned int count) |
| 804 | { |
| 805 | struct fiq_debugger_state *state; |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 806 | unsigned long flags; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 807 | |
| 808 | state = container_of(co, struct fiq_debugger_state, console); |
| 809 | |
| 810 | if (!state->console_enable && !state->syslog_dumping) |
| 811 | return; |
| 812 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 813 | fiq_debugger_uart_enable(state); |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 814 | spin_lock_irqsave(&state->console_lock, flags); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 815 | while (count--) { |
| 816 | if (*s == '\n') |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 817 | fiq_debugger_putc(state, '\r'); |
| 818 | fiq_debugger_putc(state, *s++); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 819 | } |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 820 | fiq_debugger_uart_flush(state); |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 821 | spin_unlock_irqrestore(&state->console_lock, flags); |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 822 | fiq_debugger_uart_disable(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | static struct console fiq_debugger_console = { |
| 826 | .name = "ttyFIQ", |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 827 | .device = fiq_debugger_console_device, |
| 828 | .write = fiq_debugger_console_write, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 829 | .flags = CON_PRINTBUFFER | CON_ANYTIME | CON_ENABLED, |
| 830 | }; |
| 831 | |
| 832 | int fiq_tty_open(struct tty_struct *tty, struct file *filp) |
| 833 | { |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 834 | int line = tty->index; |
| 835 | struct fiq_debugger_state **states = tty->driver->driver_state; |
| 836 | struct fiq_debugger_state *state = states[line]; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 837 | |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 838 | return tty_port_open(&state->tty_port, tty, filp); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | void fiq_tty_close(struct tty_struct *tty, struct file *filp) |
| 842 | { |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 843 | tty_port_close(tty->port, tty, filp); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | int fiq_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) |
| 847 | { |
| 848 | int i; |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 849 | int line = tty->index; |
| 850 | struct fiq_debugger_state **states = tty->driver->driver_state; |
| 851 | struct fiq_debugger_state *state = states[line]; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 852 | |
| 853 | if (!state->console_enable) |
| 854 | return count; |
| 855 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 856 | fiq_debugger_uart_enable(state); |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 857 | spin_lock_irq(&state->console_lock); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 858 | for (i = 0; i < count; i++) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 859 | fiq_debugger_putc(state, *buf++); |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 860 | spin_unlock_irq(&state->console_lock); |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 861 | fiq_debugger_uart_disable(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 862 | |
| 863 | return count; |
| 864 | } |
| 865 | |
| 866 | int fiq_tty_write_room(struct tty_struct *tty) |
| 867 | { |
Colin Cross | 9e789c9 | 2012-10-31 17:41:39 -0700 | [diff] [blame] | 868 | return 16; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 871 | #ifdef CONFIG_CONSOLE_POLL |
| 872 | static int fiq_tty_poll_init(struct tty_driver *driver, int line, char *options) |
| 873 | { |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | static int fiq_tty_poll_get_char(struct tty_driver *driver, int line) |
| 878 | { |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 879 | struct fiq_debugger_state **states = driver->driver_state; |
| 880 | struct fiq_debugger_state *state = states[line]; |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 881 | int c = NO_POLL_CHAR; |
| 882 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 883 | fiq_debugger_uart_enable(state); |
| 884 | if (fiq_debugger_have_fiq(state)) { |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 885 | int count = fiq_debugger_ringbuf_level(state->tty_rbuf); |
| 886 | if (count > 0) { |
| 887 | c = fiq_debugger_ringbuf_peek(state->tty_rbuf, 0); |
| 888 | fiq_debugger_ringbuf_consume(state->tty_rbuf, 1); |
| 889 | } |
| 890 | } else { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 891 | c = fiq_debugger_getc(state); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 892 | if (c == FIQ_DEBUGGER_NO_CHAR) |
| 893 | c = NO_POLL_CHAR; |
| 894 | } |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 895 | fiq_debugger_uart_disable(state); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 896 | |
| 897 | return c; |
| 898 | } |
| 899 | |
| 900 | static void fiq_tty_poll_put_char(struct tty_driver *driver, int line, char ch) |
| 901 | { |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 902 | struct fiq_debugger_state **states = driver->driver_state; |
| 903 | struct fiq_debugger_state *state = states[line]; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 904 | fiq_debugger_uart_enable(state); |
| 905 | fiq_debugger_putc(state, ch); |
| 906 | fiq_debugger_uart_disable(state); |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 907 | } |
| 908 | #endif |
| 909 | |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 910 | static const struct tty_port_operations fiq_tty_port_ops; |
| 911 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 912 | static const struct tty_operations fiq_tty_driver_ops = { |
| 913 | .write = fiq_tty_write, |
| 914 | .write_room = fiq_tty_write_room, |
| 915 | .open = fiq_tty_open, |
| 916 | .close = fiq_tty_close, |
Colin Cross | 3bfc29b | 2012-03-14 19:23:29 -0700 | [diff] [blame] | 917 | #ifdef CONFIG_CONSOLE_POLL |
| 918 | .poll_init = fiq_tty_poll_init, |
| 919 | .poll_get_char = fiq_tty_poll_get_char, |
| 920 | .poll_put_char = fiq_tty_poll_put_char, |
| 921 | #endif |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 922 | }; |
| 923 | |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 924 | static int fiq_debugger_tty_init(void) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 925 | { |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 926 | int ret; |
| 927 | struct fiq_debugger_state **states = NULL; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 928 | |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 929 | states = kzalloc(sizeof(*states) * MAX_FIQ_DEBUGGER_PORTS, GFP_KERNEL); |
| 930 | if (!states) { |
| 931 | pr_err("Failed to allocate fiq debugger state structres\n"); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 932 | return -ENOMEM; |
| 933 | } |
| 934 | |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 935 | fiq_tty_driver = alloc_tty_driver(MAX_FIQ_DEBUGGER_PORTS); |
| 936 | if (!fiq_tty_driver) { |
| 937 | pr_err("Failed to allocate fiq debugger tty\n"); |
| 938 | ret = -ENOMEM; |
| 939 | goto err_free_state; |
| 940 | } |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 941 | |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 942 | fiq_tty_driver->owner = THIS_MODULE; |
| 943 | fiq_tty_driver->driver_name = "fiq-debugger"; |
| 944 | fiq_tty_driver->name = "ttyFIQ"; |
| 945 | fiq_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
| 946 | fiq_tty_driver->subtype = SERIAL_TYPE_NORMAL; |
| 947 | fiq_tty_driver->init_termios = tty_std_termios; |
| 948 | fiq_tty_driver->flags = TTY_DRIVER_REAL_RAW | |
| 949 | TTY_DRIVER_DYNAMIC_DEV; |
| 950 | fiq_tty_driver->driver_state = states; |
| 951 | |
| 952 | fiq_tty_driver->init_termios.c_cflag = |
| 953 | B115200 | CS8 | CREAD | HUPCL | CLOCAL; |
| 954 | fiq_tty_driver->init_termios.c_ispeed = 115200; |
| 955 | fiq_tty_driver->init_termios.c_ospeed = 115200; |
| 956 | |
| 957 | tty_set_operations(fiq_tty_driver, &fiq_tty_driver_ops); |
| 958 | |
| 959 | ret = tty_register_driver(fiq_tty_driver); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 960 | if (ret) { |
| 961 | pr_err("Failed to register fiq tty: %d\n", ret); |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 962 | goto err_free_tty; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 965 | pr_info("Registered FIQ tty driver\n"); |
| 966 | return 0; |
| 967 | |
| 968 | err_free_tty: |
| 969 | put_tty_driver(fiq_tty_driver); |
| 970 | fiq_tty_driver = NULL; |
| 971 | err_free_state: |
| 972 | kfree(states); |
| 973 | return ret; |
| 974 | } |
| 975 | |
| 976 | static int fiq_debugger_tty_init_one(struct fiq_debugger_state *state) |
| 977 | { |
| 978 | int ret; |
| 979 | struct device *tty_dev; |
| 980 | struct fiq_debugger_state **states = fiq_tty_driver->driver_state; |
| 981 | |
| 982 | states[state->pdev->id] = state; |
| 983 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 984 | state->tty_rbuf = fiq_debugger_ringbuf_alloc(1024); |
| 985 | if (!state->tty_rbuf) { |
| 986 | pr_err("Failed to allocate fiq debugger ringbuf\n"); |
| 987 | ret = -ENOMEM; |
| 988 | goto err; |
| 989 | } |
| 990 | |
Arve Hjønnevåg | 053d547 | 2013-01-15 15:10:31 -0800 | [diff] [blame] | 991 | tty_port_init(&state->tty_port); |
| 992 | state->tty_port.ops = &fiq_tty_port_ops; |
| 993 | |
| 994 | tty_dev = tty_port_register_device(&state->tty_port, fiq_tty_driver, |
| 995 | state->pdev->id, &state->pdev->dev); |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 996 | if (IS_ERR(tty_dev)) { |
| 997 | pr_err("Failed to register fiq debugger tty device\n"); |
| 998 | ret = PTR_ERR(tty_dev); |
| 999 | goto err; |
| 1000 | } |
| 1001 | |
| 1002 | device_set_wakeup_capable(tty_dev, 1); |
| 1003 | |
| 1004 | pr_info("Registered fiq debugger ttyFIQ%d\n", state->pdev->id); |
| 1005 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1006 | return 0; |
| 1007 | |
| 1008 | err: |
| 1009 | fiq_debugger_ringbuf_free(state->tty_rbuf); |
| 1010 | state->tty_rbuf = NULL; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1011 | return ret; |
| 1012 | } |
| 1013 | #endif |
| 1014 | |
| 1015 | static int fiq_debugger_dev_suspend(struct device *dev) |
| 1016 | { |
| 1017 | struct platform_device *pdev = to_platform_device(dev); |
| 1018 | struct fiq_debugger_state *state = platform_get_drvdata(pdev); |
| 1019 | |
| 1020 | if (state->pdata->uart_dev_suspend) |
| 1021 | return state->pdata->uart_dev_suspend(pdev); |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | static int fiq_debugger_dev_resume(struct device *dev) |
| 1026 | { |
| 1027 | struct platform_device *pdev = to_platform_device(dev); |
| 1028 | struct fiq_debugger_state *state = platform_get_drvdata(pdev); |
| 1029 | |
| 1030 | if (state->pdata->uart_dev_resume) |
| 1031 | return state->pdata->uart_dev_resume(pdev); |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | static int fiq_debugger_probe(struct platform_device *pdev) |
| 1036 | { |
| 1037 | int ret; |
| 1038 | struct fiq_debugger_pdata *pdata = dev_get_platdata(&pdev->dev); |
| 1039 | struct fiq_debugger_state *state; |
| 1040 | int fiq; |
| 1041 | int uart_irq; |
| 1042 | |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 1043 | if (pdev->id >= MAX_FIQ_DEBUGGER_PORTS) |
| 1044 | return -EINVAL; |
| 1045 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1046 | if (!pdata->uart_getc || !pdata->uart_putc) |
| 1047 | return -EINVAL; |
| 1048 | if ((pdata->uart_enable && !pdata->uart_disable) || |
| 1049 | (!pdata->uart_enable && pdata->uart_disable)) |
| 1050 | return -EINVAL; |
| 1051 | |
| 1052 | fiq = platform_get_irq_byname(pdev, "fiq"); |
| 1053 | uart_irq = platform_get_irq_byname(pdev, "uart_irq"); |
| 1054 | |
| 1055 | /* uart_irq mode and fiq mode are mutually exclusive, but one of them |
| 1056 | * is required */ |
| 1057 | if ((uart_irq < 0 && fiq < 0) || (uart_irq >= 0 && fiq >= 0)) |
| 1058 | return -EINVAL; |
| 1059 | if (fiq >= 0 && !pdata->fiq_enable) |
| 1060 | return -EINVAL; |
| 1061 | |
| 1062 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
Arve Hjønnevåg | e073df6 | 2014-05-02 19:52:54 -0700 | [diff] [blame] | 1063 | state->output.printf = fiq_debugger_printf; |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1064 | setup_timer(&state->sleep_timer, fiq_debugger_sleep_timer_expired, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1065 | (unsigned long)state); |
| 1066 | state->pdata = pdata; |
| 1067 | state->pdev = pdev; |
| 1068 | state->no_sleep = initial_no_sleep; |
| 1069 | state->debug_enable = initial_debug_enable; |
| 1070 | state->console_enable = initial_console_enable; |
| 1071 | |
| 1072 | state->fiq = fiq; |
| 1073 | state->uart_irq = uart_irq; |
| 1074 | state->signal_irq = platform_get_irq_byname(pdev, "signal"); |
| 1075 | state->wakeup_irq = platform_get_irq_byname(pdev, "wakeup"); |
| 1076 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1077 | INIT_WORK(&state->work, fiq_debugger_work); |
Colin Cross | 2b672ca | 2012-07-19 18:40:04 -0700 | [diff] [blame] | 1078 | spin_lock_init(&state->work_lock); |
| 1079 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1080 | platform_set_drvdata(pdev, state); |
| 1081 | |
| 1082 | spin_lock_init(&state->sleep_timer_lock); |
| 1083 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1084 | if (state->wakeup_irq < 0 && fiq_debugger_have_fiq(state)) |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1085 | state->no_sleep = true; |
| 1086 | state->ignore_next_wakeup_irq = !state->no_sleep; |
| 1087 | |
Dmitry Shmidt | b4a2694 | 2017-01-12 12:28:08 -0800 | [diff] [blame] | 1088 | wakeup_source_init(&state->debugger_wake_src, "serial-debug"); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1089 | |
| 1090 | state->clk = clk_get(&pdev->dev, NULL); |
| 1091 | if (IS_ERR(state->clk)) |
| 1092 | state->clk = NULL; |
| 1093 | |
| 1094 | /* do not call pdata->uart_enable here since uart_init may still |
| 1095 | * need to do some initialization before uart_enable can work. |
| 1096 | * So, only try to manage the clock during init. |
| 1097 | */ |
| 1098 | if (state->clk) |
| 1099 | clk_enable(state->clk); |
| 1100 | |
| 1101 | if (pdata->uart_init) { |
| 1102 | ret = pdata->uart_init(pdev); |
| 1103 | if (ret) |
| 1104 | goto err_uart_init; |
| 1105 | } |
| 1106 | |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1107 | fiq_debugger_printf_nfiq(state, |
| 1108 | "<hit enter %sto activate fiq debugger>\n", |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1109 | state->no_sleep ? "" : "twice "); |
| 1110 | |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 1111 | #ifdef CONFIG_FIQ_GLUE |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1112 | if (fiq_debugger_have_fiq(state)) { |
| 1113 | state->handler.fiq = fiq_debugger_fiq; |
| 1114 | state->handler.resume = fiq_debugger_resume; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1115 | ret = fiq_glue_register_handler(&state->handler); |
| 1116 | if (ret) { |
| 1117 | pr_err("%s: could not install fiq handler\n", __func__); |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 1118 | goto err_register_irq; |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | pdata->fiq_enable(pdev, state->fiq, 1); |
Colin Cross | cbee915 | 2014-04-02 18:37:29 -0700 | [diff] [blame] | 1122 | } else |
| 1123 | #endif |
| 1124 | { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1125 | ret = request_irq(state->uart_irq, fiq_debugger_uart_irq, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1126 | IRQF_NO_SUSPEND, "debug", state); |
| 1127 | if (ret) { |
| 1128 | pr_err("%s: could not install irq handler\n", __func__); |
| 1129 | goto err_register_irq; |
| 1130 | } |
| 1131 | |
| 1132 | /* for irq-only mode, we want this irq to wake us up, if it |
| 1133 | * can. |
| 1134 | */ |
| 1135 | enable_irq_wake(state->uart_irq); |
| 1136 | } |
| 1137 | |
| 1138 | if (state->clk) |
| 1139 | clk_disable(state->clk); |
| 1140 | |
| 1141 | if (state->signal_irq >= 0) { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1142 | ret = request_irq(state->signal_irq, fiq_debugger_signal_irq, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1143 | IRQF_TRIGGER_RISING, "debug-signal", state); |
| 1144 | if (ret) |
| 1145 | pr_err("serial_debugger: could not install signal_irq"); |
| 1146 | } |
| 1147 | |
| 1148 | if (state->wakeup_irq >= 0) { |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1149 | ret = request_irq(state->wakeup_irq, |
| 1150 | fiq_debugger_wakeup_irq_handler, |
John Stultz | daeea72 | 2015-12-04 11:32:21 -0800 | [diff] [blame] | 1151 | IRQF_TRIGGER_FALLING, |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1152 | "debug-wakeup", state); |
| 1153 | if (ret) { |
| 1154 | pr_err("serial_debugger: " |
| 1155 | "could not install wakeup irq\n"); |
| 1156 | state->wakeup_irq = -1; |
| 1157 | } else { |
| 1158 | ret = enable_irq_wake(state->wakeup_irq); |
| 1159 | if (ret) { |
| 1160 | pr_err("serial_debugger: " |
| 1161 | "could not enable wakeup\n"); |
| 1162 | state->wakeup_irq_no_set_wake = true; |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | if (state->no_sleep) |
Colin Cross | a6bec1f | 2014-04-04 22:58:23 -0700 | [diff] [blame] | 1167 | fiq_debugger_handle_wakeup(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1168 | |
| 1169 | #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE) |
Mars | b4ffdde | 2012-11-03 12:15:38 +0800 | [diff] [blame] | 1170 | spin_lock_init(&state->console_lock); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1171 | state->console = fiq_debugger_console; |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 1172 | state->console.index = pdev->id; |
| 1173 | if (!console_set_on_cmdline) |
| 1174 | add_preferred_console(state->console.name, |
| 1175 | state->console.index, NULL); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1176 | register_console(&state->console); |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 1177 | fiq_debugger_tty_init_one(state); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1178 | #endif |
| 1179 | return 0; |
| 1180 | |
| 1181 | err_register_irq: |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1182 | if (pdata->uart_free) |
| 1183 | pdata->uart_free(pdev); |
| 1184 | err_uart_init: |
| 1185 | if (state->clk) |
| 1186 | clk_disable(state->clk); |
| 1187 | if (state->clk) |
| 1188 | clk_put(state->clk); |
Dmitry Shmidt | b4a2694 | 2017-01-12 12:28:08 -0800 | [diff] [blame] | 1189 | wakeup_source_trash(&state->debugger_wake_src); |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1190 | platform_set_drvdata(pdev, NULL); |
| 1191 | kfree(state); |
| 1192 | return ret; |
| 1193 | } |
| 1194 | |
| 1195 | static const struct dev_pm_ops fiq_debugger_dev_pm_ops = { |
| 1196 | .suspend = fiq_debugger_dev_suspend, |
| 1197 | .resume = fiq_debugger_dev_resume, |
| 1198 | }; |
| 1199 | |
| 1200 | static struct platform_driver fiq_debugger_driver = { |
| 1201 | .probe = fiq_debugger_probe, |
| 1202 | .driver = { |
| 1203 | .name = "fiq_debugger", |
| 1204 | .pm = &fiq_debugger_dev_pm_ops, |
| 1205 | }, |
| 1206 | }; |
| 1207 | |
Dmitry Shmidt | caff55c | 2016-05-04 13:51:38 -0700 | [diff] [blame] | 1208 | #if defined(CONFIG_FIQ_DEBUGGER_UART_OVERLAY) |
| 1209 | int fiq_debugger_uart_overlay(void) |
| 1210 | { |
| 1211 | struct device_node *onp = of_find_node_by_path("/uart_overlay@0"); |
| 1212 | int ret; |
| 1213 | |
| 1214 | if (!onp) { |
| 1215 | pr_err("serial_debugger: uart overlay not found\n"); |
| 1216 | return -ENODEV; |
| 1217 | } |
| 1218 | |
| 1219 | ret = of_overlay_create(onp); |
| 1220 | if (ret < 0) { |
| 1221 | pr_err("serial_debugger: fail to create overlay: %d\n", ret); |
| 1222 | of_node_put(onp); |
| 1223 | return ret; |
| 1224 | } |
| 1225 | |
| 1226 | pr_info("serial_debugger: uart overlay applied\n"); |
| 1227 | return 0; |
| 1228 | } |
| 1229 | #endif |
| 1230 | |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1231 | static int __init fiq_debugger_init(void) |
| 1232 | { |
Dmitry Shmidt | 023f889 | 2016-05-11 11:01:02 -0700 | [diff] [blame] | 1233 | if (fiq_debugger_disable) { |
| 1234 | pr_err("serial_debugger: disabled\n"); |
| 1235 | return -ENODEV; |
| 1236 | } |
Colin Cross | 77fcefe | 2012-03-18 15:25:55 -0700 | [diff] [blame] | 1237 | #if defined(CONFIG_FIQ_DEBUGGER_CONSOLE) |
| 1238 | fiq_debugger_tty_init(); |
| 1239 | #endif |
Dmitry Shmidt | caff55c | 2016-05-04 13:51:38 -0700 | [diff] [blame] | 1240 | #if defined(CONFIG_FIQ_DEBUGGER_UART_OVERLAY) |
| 1241 | fiq_debugger_uart_overlay(); |
| 1242 | #endif |
Iliyan Malchev | 8c0dbf6 | 2010-06-05 17:36:24 -0700 | [diff] [blame] | 1243 | return platform_driver_register(&fiq_debugger_driver); |
| 1244 | } |
| 1245 | |
| 1246 | postcore_initcall(fiq_debugger_init); |