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