blob: d9bc125308bdbd312aff2d84aa7ab3d65402ca27 [file] [log] [blame]
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001/*
Colin Cross66bbef22014-04-02 18:30:04 -07002 * drivers/staging/android/fiq_debugger.c
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07003 *
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åg9de62e02012-11-26 20:05:37 -080026#include <linux/kmsg_dump.h>
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070027#include <linux/irq.h>
28#include <linux/delay.h>
Colin Cross69279c62012-03-14 16:28:45 -070029#include <linux/reboot.h>
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070030#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 Malchev8c0dbf62010-06-05 17:36:24 -070036
Colin Crosscbee9152014-04-02 18:37:29 -070037#ifdef CONFIG_FIQ_GLUE
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070038#include <asm/fiq_glue.h>
Colin Crosscbee9152014-04-02 18:37:29 -070039#endif
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070040
Dmitry Shmidtcaff55c2016-05-04 13:51:38 -070041#ifdef CONFIG_FIQ_DEBUGGER_UART_OVERLAY
42#include <linux/of.h>
43#endif
44
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070045#include <linux/uaccess.h>
46
Colin Cross66bbef22014-04-02 18:30:04 -070047#include "fiq_debugger.h"
Colin Crosscffbe782014-04-02 18:42:13 -070048#include "fiq_debugger_priv.h"
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070049#include "fiq_debugger_ringbuf.h"
50
51#define DEBUG_MAX 64
52#define MAX_UNHANDLED_FIQ_COUNT 1000000
53
Colin Cross77fcefe2012-03-18 15:25:55 -070054#define MAX_FIQ_DEBUGGER_PORTS 4
55
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070056struct fiq_debugger_state {
Colin Crosscbee9152014-04-02 18:37:29 -070057#ifdef CONFIG_FIQ_GLUE
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070058 struct fiq_glue_handler handler;
Colin Crosscbee9152014-04-02 18:37:29 -070059#endif
Arve Hjønnevåge073df62014-05-02 19:52:54 -070060 struct fiq_debugger_output output;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070061
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 Shmidtb4a26942017-01-12 12:28:08 -080084 struct wakeup_source debugger_wake_src;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070085 bool console_enable;
86 int current_cpu;
87 atomic_t unhandled_fiq_count;
88 bool in_fiq;
89
Colin Cross2b672ca2012-07-19 18:40:04 -070090 struct work_struct work;
91 spinlock_t work_lock;
92 char work_cmd[DEBUG_MAX];
93
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070094#ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
Colin Cross9e789c92012-10-31 17:41:39 -070095 spinlock_t console_lock;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070096 struct console console;
Arve Hjønnevåg053d5472013-01-15 15:10:31 -080097 struct tty_port tty_port;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -070098 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 Cross77fcefe2012-03-18 15:25:55 -0700106#ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
107struct tty_driver *fiq_tty_driver;
108#endif
109
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700110#ifdef CONFIG_FIQ_DEBUGGER_NO_SLEEP
111static bool initial_no_sleep = true;
112#else
113static bool initial_no_sleep;
114#endif
115
116#ifdef CONFIG_FIQ_DEBUGGER_CONSOLE_DEFAULT_ENABLE
117static bool initial_debug_enable = true;
118static bool initial_console_enable = true;
119#else
120static bool initial_debug_enable;
121static bool initial_console_enable;
122#endif
123
Colin Cross3bfc29b2012-03-14 19:23:29 -0700124static bool fiq_kgdb_enable;
Dmitry Shmidt023f8892016-05-11 11:01:02 -0700125static bool fiq_debugger_disable;
Colin Cross3bfc29b2012-03-14 19:23:29 -0700126
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700127module_param_named(no_sleep, initial_no_sleep, bool, 0644);
128module_param_named(debug_enable, initial_debug_enable, bool, 0644);
129module_param_named(console_enable, initial_console_enable, bool, 0644);
Colin Cross3bfc29b2012-03-14 19:23:29 -0700130module_param_named(kgdb_enable, fiq_kgdb_enable, bool, 0644);
Dmitry Shmidt023f8892016-05-11 11:01:02 -0700131module_param_named(disable, fiq_debugger_disable, bool, 0644);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700132
133#ifdef CONFIG_FIQ_DEBUGGER_WAKEUP_IRQ_ALWAYS_ON
Colin Crossa6bec1f2014-04-04 22:58:23 -0700134static inline
135void fiq_debugger_enable_wakeup_irq(struct fiq_debugger_state *state) {}
136static inline
137void fiq_debugger_disable_wakeup_irq(struct fiq_debugger_state *state) {}
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700138#else
Colin Crossa6bec1f2014-04-04 22:58:23 -0700139static inline
140void fiq_debugger_enable_wakeup_irq(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700141{
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 Crossa6bec1f2014-04-04 22:58:23 -0700148static inline
149void fiq_debugger_disable_wakeup_irq(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700150{
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 Crossa6bec1f2014-04-04 22:58:23 -0700159static inline bool fiq_debugger_have_fiq(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700160{
161 return (state->fiq >= 0);
162}
163
Colin Crosscbee9152014-04-02 18:37:29 -0700164#ifdef CONFIG_FIQ_GLUE
Colin Crossa6bec1f2014-04-04 22:58:23 -0700165static void fiq_debugger_force_irq(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700166{
167 unsigned int irq = state->signal_irq;
168
Colin Crossa6bec1f2014-04-04 22:58:23 -0700169 if (WARN_ON(!fiq_debugger_have_fiq(state)))
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700170 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 Crosscbee9152014-04-02 18:37:29 -0700179#endif
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700180
Colin Crossa6bec1f2014-04-04 22:58:23 -0700181static void fiq_debugger_uart_enable(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700182{
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 Crossa6bec1f2014-04-04 22:58:23 -0700189static void fiq_debugger_uart_disable(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700190{
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 Crossa6bec1f2014-04-04 22:58:23 -0700197static void fiq_debugger_uart_flush(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700198{
199 if (state->pdata->uart_flush)
200 state->pdata->uart_flush(state->pdev);
201}
202
Colin Crossa6bec1f2014-04-04 22:58:23 -0700203static void fiq_debugger_putc(struct fiq_debugger_state *state, char c)
Colin Cross31c550f2012-03-15 12:57:20 -0700204{
205 state->pdata->uart_putc(state->pdev, c);
206}
207
Colin Crossa6bec1f2014-04-04 22:58:23 -0700208static void fiq_debugger_puts(struct fiq_debugger_state *state, char *s)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700209{
210 unsigned c;
211 while ((c = *s++)) {
212 if (c == '\n')
Colin Crossa6bec1f2014-04-04 22:58:23 -0700213 fiq_debugger_putc(state, '\r');
214 fiq_debugger_putc(state, c);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700215 }
216}
217
Colin Crossa6bec1f2014-04-04 22:58:23 -0700218static void fiq_debugger_prompt(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700219{
Colin Crossa6bec1f2014-04-04 22:58:23 -0700220 fiq_debugger_puts(state, "debug> ");
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700221}
222
Colin Crossa6bec1f2014-04-04 22:58:23 -0700223static void fiq_debugger_dump_kernel_log(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700224{
Arve Hjønnevåg9de62e02012-11-26 20:05:37 -0800225 char buf[512];
226 size_t len;
227 struct kmsg_dumper dumper = { .active = true };
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700228
Arve Hjønnevåg9de62e02012-11-26 20:05:37 -0800229
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 Crossa6bec1f2014-04-04 22:58:23 -0700234 fiq_debugger_puts(state, buf);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700235 }
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700236}
237
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700238static void fiq_debugger_printf(struct fiq_debugger_output *output,
239 const char *fmt, ...)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700240{
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700241 struct fiq_debugger_state *state;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700242 char buf[256];
243 va_list ap;
244
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700245 state = container_of(output, struct fiq_debugger_state, output);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700246 va_start(ap, fmt);
247 vsnprintf(buf, sizeof(buf), fmt, ap);
248 va_end(ap);
249
Colin Crossa6bec1f2014-04-04 22:58:23 -0700250 fiq_debugger_puts(state, buf);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700251}
252
253/* Safe outside fiq context */
Colin Crossa6bec1f2014-04-04 22:58:23 -0700254static int fiq_debugger_printf_nfiq(void *cookie, const char *fmt, ...)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700255{
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 Crossa6bec1f2014-04-04 22:58:23 -0700266 fiq_debugger_puts(state, buf);
267 fiq_debugger_uart_flush(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700268 local_irq_restore(irq_flags);
269 return state->debug_abort;
270}
271
Colin Crossa6bec1f2014-04-04 22:58:23 -0700272static void fiq_debugger_dump_irqs(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700273{
274 int n;
Arve Hjønnevågd05890d2012-11-26 16:23:33 -0800275 struct irq_desc *desc;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700276
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700277 fiq_debugger_printf(&state->output,
Colin Crossa6bec1f2014-04-04 22:58:23 -0700278 "irqnr total since-last status name\n");
Arve Hjønnevågd05890d2012-11-26 16:23:33 -0800279 for_each_irq_desc(n, desc) {
280 struct irqaction *act = desc->action;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700281 if (!act && !kstat_irqs(n))
282 continue;
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700283 fiq_debugger_printf(&state->output, "%5d: %10u %11u %8x %s\n", n,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700284 kstat_irqs(n),
285 kstat_irqs(n) - state->last_irqs[n],
Arve Hjønnevågd05890d2012-11-26 16:23:33 -0800286 desc->status_use_accessors,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700287 (act && act->name) ? act->name : "???");
288 state->last_irqs[n] = kstat_irqs(n);
289 }
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700290}
291
Colin Crossa6bec1f2014-04-04 22:58:23 -0700292static void fiq_debugger_do_ps(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700293{
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åge073df62014-05-02 19:52:54 -0700299 fiq_debugger_printf(&state->output, "pid ppid prio task pc\n");
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700300 read_lock(&tasklist_lock);
301 do_each_thread(g, p) {
302 task_state = p->state ? __ffs(p->state) + 1 : 0;
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700303 fiq_debugger_printf(&state->output,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700304 "%5d %5d %4d ", p->pid, p->parent->pid, p->prio);
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700305 fiq_debugger_printf(&state->output, "%-13.13s %c", p->comm,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700306 task_state >= sizeof(stat_nam) ? '?' : stat_nam[task_state]);
307 if (task_state == TASK_RUNNING)
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700308 fiq_debugger_printf(&state->output, " running\n");
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700309 else
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700310 fiq_debugger_printf(&state->output, " %08lx\n",
Colin Crossa6bec1f2014-04-04 22:58:23 -0700311 thread_saved_pc(p));
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700312 } while_each_thread(g, p);
313 read_unlock(&tasklist_lock);
314}
315
316#ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
Colin Crossa6bec1f2014-04-04 22:58:23 -0700317static void fiq_debugger_begin_syslog_dump(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700318{
319 state->syslog_dumping = true;
320}
321
Colin Crossa6bec1f2014-04-04 22:58:23 -0700322static void fiq_debugger_end_syslog_dump(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700323{
324 state->syslog_dumping = false;
325}
326#else
327extern int do_syslog(int type, char __user *bug, int count);
Colin Crossa6bec1f2014-04-04 22:58:23 -0700328static void fiq_debugger_begin_syslog_dump(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700329{
330 do_syslog(5 /* clear */, NULL, 0);
331}
332
Colin Crossa6bec1f2014-04-04 22:58:23 -0700333static void fiq_debugger_end_syslog_dump(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700334{
Colin Crossa6bec1f2014-04-04 22:58:23 -0700335 fiq_debugger_dump_kernel_log(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700336}
337#endif
338
Colin Crossa6bec1f2014-04-04 22:58:23 -0700339static void fiq_debugger_do_sysrq(struct fiq_debugger_state *state, char rq)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700340{
Colin Cross3bfc29b2012-03-14 19:23:29 -0700341 if ((rq == 'g' || rq == 'G') && !fiq_kgdb_enable) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700342 fiq_debugger_printf(&state->output, "sysrq-g blocked\n");
Colin Cross3bfc29b2012-03-14 19:23:29 -0700343 return;
344 }
Colin Crossa6bec1f2014-04-04 22:58:23 -0700345 fiq_debugger_begin_syslog_dump(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700346 handle_sysrq(rq);
Colin Crossa6bec1f2014-04-04 22:58:23 -0700347 fiq_debugger_end_syslog_dump(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700348}
349
Colin Cross3bfc29b2012-03-14 19:23:29 -0700350#ifdef CONFIG_KGDB
Colin Crossa6bec1f2014-04-04 22:58:23 -0700351static void fiq_debugger_do_kgdb(struct fiq_debugger_state *state)
Colin Cross3bfc29b2012-03-14 19:23:29 -0700352{
353 if (!fiq_kgdb_enable) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700354 fiq_debugger_printf(&state->output, "kgdb through fiq debugger not enabled\n");
Colin Cross3bfc29b2012-03-14 19:23:29 -0700355 return;
356 }
357
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700358 fiq_debugger_printf(&state->output, "enabling console and triggering kgdb\n");
Colin Cross3bfc29b2012-03-14 19:23:29 -0700359 state->console_enable = true;
360 handle_sysrq('g');
361}
362#endif
363
Colin Crossa6bec1f2014-04-04 22:58:23 -0700364static void fiq_debugger_schedule_work(struct fiq_debugger_state *state,
365 char *cmd)
Colin Cross2b672ca2012-07-19 18:40:04 -0700366{
367 unsigned long flags;
368
369 spin_lock_irqsave(&state->work_lock, flags);
370 if (state->work_cmd[0] != '\0') {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700371 fiq_debugger_printf(&state->output, "work command processor busy\n");
Colin Cross2b672ca2012-07-19 18:40:04 -0700372 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 Crossa6bec1f2014-04-04 22:58:23 -0700382static void fiq_debugger_work(struct work_struct *work)
Colin Cross2b672ca2012-07-19 18:40:04 -0700383{
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 Kaiser3b619562017-09-05 15:55:41 -0700403 if (*cmd != '\0')
Colin Cross2b672ca2012-07-19 18:40:04 -0700404 kernel_restart(cmd);
405 else
406 kernel_restart(NULL);
407 } else {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700408 fiq_debugger_printf(&state->output, "unknown work command '%s'\n",
Colin Crossa6bec1f2014-04-04 22:58:23 -0700409 work_cmd);
Colin Cross2b672ca2012-07-19 18:40:04 -0700410 }
411}
412
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700413/* This function CANNOT be called in FIQ context */
Colin Crossa6bec1f2014-04-04 22:58:23 -0700414static void fiq_debugger_irq_exec(struct fiq_debugger_state *state, char *cmd)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700415{
416 if (!strcmp(cmd, "ps"))
Colin Crossa6bec1f2014-04-04 22:58:23 -0700417 fiq_debugger_do_ps(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700418 if (!strcmp(cmd, "sysrq"))
Colin Crossa6bec1f2014-04-04 22:58:23 -0700419 fiq_debugger_do_sysrq(state, 'h');
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700420 if (!strncmp(cmd, "sysrq ", 6))
Colin Crossa6bec1f2014-04-04 22:58:23 -0700421 fiq_debugger_do_sysrq(state, cmd[6]);
Colin Cross3bfc29b2012-03-14 19:23:29 -0700422#ifdef CONFIG_KGDB
423 if (!strcmp(cmd, "kgdb"))
Colin Crossa6bec1f2014-04-04 22:58:23 -0700424 fiq_debugger_do_kgdb(state);
Colin Cross3bfc29b2012-03-14 19:23:29 -0700425#endif
Colin Cross2b672ca2012-07-19 18:40:04 -0700426 if (!strncmp(cmd, "reboot", 6))
Colin Crossa6bec1f2014-04-04 22:58:23 -0700427 fiq_debugger_schedule_work(state, cmd);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700428}
429
Colin Crossa6bec1f2014-04-04 22:58:23 -0700430static void fiq_debugger_help(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700431{
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700432 fiq_debugger_printf(&state->output,
Colin Crossa6bec1f2014-04-04 22:58:23 -0700433 "FIQ Debugger commands:\n"
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700434 " pc PC status\n"
435 " regs Register dump\n"
436 " allregs Extended Register dump\n"
437 " bt Stack trace\n"
Colin Cross2b672ca2012-07-19 18:40:04 -0700438 " reboot [<c>] Reboot with command <c>\n"
439 " reset [<c>] Hard reset with command <c>\n"
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700440 " irqs Interupt status\n"
441 " kmsg Kernel log\n"
442 " version Kernel version\n");
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700443 fiq_debugger_printf(&state->output,
Colin Crossa6bec1f2014-04-04 22:58:23 -0700444 " sleep Allow sleep while in FIQ\n"
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700445 " 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åge073df62014-05-02 19:52:54 -0700449 fiq_debugger_printf(&state->output,
Colin Crossa6bec1f2014-04-04 22:58:23 -0700450 " ps Process list\n"
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700451 " sysrq sysrq options\n"
452 " sysrq <param> Execute sysrq with <param>\n");
Colin Cross3bfc29b2012-03-14 19:23:29 -0700453#ifdef CONFIG_KGDB
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700454 fiq_debugger_printf(&state->output,
Colin Crossa6bec1f2014-04-04 22:58:23 -0700455 " kgdb Enter kernel debugger\n");
Colin Cross3bfc29b2012-03-14 19:23:29 -0700456#endif
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700457}
458
Colin Crossa6bec1f2014-04-04 22:58:23 -0700459static void fiq_debugger_take_affinity(void *info)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700460{
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 Crossa6bec1f2014-04-04 22:58:23 -0700470static void fiq_debugger_switch_cpu(struct fiq_debugger_state *state, int cpu)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700471{
Colin Crossa6bec1f2014-04-04 22:58:23 -0700472 if (!fiq_debugger_have_fiq(state))
473 smp_call_function_single(cpu, fiq_debugger_take_affinity, state,
474 false);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700475 state->current_cpu = cpu;
476}
477
Colin Crossa6bec1f2014-04-04 22:58:23 -0700478static bool fiq_debugger_fiq_exec(struct fiq_debugger_state *state,
Colin Cross7efcbb82014-04-04 17:05:19 -0700479 const char *cmd, const struct pt_regs *regs,
480 void *svc_sp)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700481{
482 bool signal_helper = false;
483
484 if (!strcmp(cmd, "help") || !strcmp(cmd, "?")) {
Colin Crossa6bec1f2014-04-04 22:58:23 -0700485 fiq_debugger_help(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700486 } else if (!strcmp(cmd, "pc")) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700487 fiq_debugger_dump_pc(&state->output, regs);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700488 } else if (!strcmp(cmd, "regs")) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700489 fiq_debugger_dump_regs(&state->output, regs);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700490 } else if (!strcmp(cmd, "allregs")) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700491 fiq_debugger_dump_allregs(&state->output, regs);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700492 } else if (!strcmp(cmd, "bt")) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700493 fiq_debugger_dump_stacktrace(&state->output, regs, 100, svc_sp);
Colin Cross2b672ca2012-07-19 18:40:04 -0700494 } else if (!strncmp(cmd, "reset", 5)) {
495 cmd += 5;
Colin Crossae9d69a2012-03-14 16:29:47 -0700496 while (*cmd == ' ')
497 cmd++;
498 if (*cmd) {
499 char tmp_cmd[32];
500 strlcpy(tmp_cmd, cmd, sizeof(tmp_cmd));
Colin Cross2b672ca2012-07-19 18:40:04 -0700501 machine_restart(tmp_cmd);
Colin Crossae9d69a2012-03-14 16:29:47 -0700502 } else {
Colin Cross2b672ca2012-07-19 18:40:04 -0700503 machine_restart(NULL);
Colin Crossae9d69a2012-03-14 16:29:47 -0700504 }
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700505 } else if (!strcmp(cmd, "irqs")) {
Colin Crossa6bec1f2014-04-04 22:58:23 -0700506 fiq_debugger_dump_irqs(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700507 } else if (!strcmp(cmd, "kmsg")) {
Colin Crossa6bec1f2014-04-04 22:58:23 -0700508 fiq_debugger_dump_kernel_log(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700509 } else if (!strcmp(cmd, "version")) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700510 fiq_debugger_printf(&state->output, "%s\n", linux_banner);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700511 } else if (!strcmp(cmd, "sleep")) {
512 state->no_sleep = false;
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700513 fiq_debugger_printf(&state->output, "enabling sleep\n");
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700514 } else if (!strcmp(cmd, "nosleep")) {
515 state->no_sleep = true;
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700516 fiq_debugger_printf(&state->output, "disabling sleep\n");
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700517 } else if (!strcmp(cmd, "console")) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700518 fiq_debugger_printf(&state->output, "console mode\n");
Colin Crossa6bec1f2014-04-04 22:58:23 -0700519 fiq_debugger_uart_flush(state);
Colin Cross9e789c92012-10-31 17:41:39 -0700520 state->console_enable = true;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700521 } else if (!strcmp(cmd, "cpu")) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700522 fiq_debugger_printf(&state->output, "cpu %d\n", state->current_cpu);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700523 } else if (!strncmp(cmd, "cpu ", 4)) {
524 unsigned long cpu = 0;
John Stultzdaeea722015-12-04 11:32:21 -0800525 if (kstrtoul(cmd + 4, 10, &cpu) == 0)
Colin Crossa6bec1f2014-04-04 22:58:23 -0700526 fiq_debugger_switch_cpu(state, cpu);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700527 else
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700528 fiq_debugger_printf(&state->output, "invalid cpu\n");
529 fiq_debugger_printf(&state->output, "cpu %d\n", state->current_cpu);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700530 } else {
531 if (state->debug_busy) {
Arve Hjønnevåge073df62014-05-02 19:52:54 -0700532 fiq_debugger_printf(&state->output,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700533 "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 Crossa6bec1f2014-04-04 22:58:23 -0700543 fiq_debugger_prompt(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700544
545 return signal_helper;
546}
547
Colin Crossa6bec1f2014-04-04 22:58:23 -0700548static void fiq_debugger_sleep_timer_expired(unsigned long data)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700549{
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 Crossa6bec1f2014-04-04 22:58:23 -0700557 fiq_debugger_printf_nfiq(state,
558 "suspending fiq debugger\n");
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700559 }
560 state->ignore_next_wakeup_irq = true;
Colin Crossa6bec1f2014-04-04 22:58:23 -0700561 fiq_debugger_uart_disable(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700562 state->uart_enabled = false;
Colin Crossa6bec1f2014-04-04 22:58:23 -0700563 fiq_debugger_enable_wakeup_irq(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700564 }
Dmitry Shmidtb4a26942017-01-12 12:28:08 -0800565 __pm_relax(&state->debugger_wake_src);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700566 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
567}
568
Colin Crossa6bec1f2014-04-04 22:58:23 -0700569static void fiq_debugger_handle_wakeup(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700570{
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 Shmidtb4a26942017-01-12 12:28:08 -0800577 __pm_stay_awake(&state->debugger_wake_src);
Colin Crossa6bec1f2014-04-04 22:58:23 -0700578 fiq_debugger_uart_enable(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700579 state->uart_enabled = true;
Colin Crossa6bec1f2014-04-04 22:58:23 -0700580 fiq_debugger_disable_wakeup_irq(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700581 mod_timer(&state->sleep_timer, jiffies + HZ / 2);
582 }
583 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
584}
585
Colin Crossa6bec1f2014-04-04 22:58:23 -0700586static irqreturn_t fiq_debugger_wakeup_irq_handler(int irq, void *dev)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700587{
588 struct fiq_debugger_state *state = dev;
589
590 if (!state->no_sleep)
Colin Crossa6bec1f2014-04-04 22:58:23 -0700591 fiq_debugger_puts(state, "WAKEUP\n");
592 fiq_debugger_handle_wakeup(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700593
594 return IRQ_HANDLED;
595}
596
Colin Crossa6bec1f2014-04-04 22:58:23 -0700597static
598void fiq_debugger_handle_console_irq_context(struct fiq_debugger_state *state)
Arve Hjønnevåg053d5472013-01-15 15:10:31 -0800599{
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 Malchev8c0dbf62010-06-05 17:36:24 -0700614
Colin Crossa6bec1f2014-04-04 22:58:23 -0700615static void fiq_debugger_handle_irq_context(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700616{
617 if (!state->no_sleep) {
618 unsigned long flags;
619
620 spin_lock_irqsave(&state->sleep_timer_lock, flags);
Dmitry Shmidtb4a26942017-01-12 12:28:08 -0800621 __pm_stay_awake(&state->debugger_wake_src);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700622 mod_timer(&state->sleep_timer, jiffies + HZ * 5);
623 spin_unlock_irqrestore(&state->sleep_timer_lock, flags);
624 }
Colin Crossa6bec1f2014-04-04 22:58:23 -0700625 fiq_debugger_handle_console_irq_context(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700626 if (state->debug_busy) {
Colin Crossa6bec1f2014-04-04 22:58:23 -0700627 fiq_debugger_irq_exec(state, state->debug_cmd);
Colin Cross3bfc29b2012-03-14 19:23:29 -0700628 if (!state->console_enable)
Colin Crossa6bec1f2014-04-04 22:58:23 -0700629 fiq_debugger_prompt(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700630 state->debug_busy = 0;
631 }
632}
633
Colin Crossa6bec1f2014-04-04 22:58:23 -0700634static int fiq_debugger_getc(struct fiq_debugger_state *state)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700635{
636 return state->pdata->uart_getc(state->pdev);
637}
638
Colin Crossa6bec1f2014-04-04 22:58:23 -0700639static bool fiq_debugger_handle_uart_interrupt(struct fiq_debugger_state *state,
Colin Cross7efcbb82014-04-04 17:05:19 -0700640 int this_cpu, const struct pt_regs *regs, void *svc_sp)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700641{
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åge073df62014-05-02 19:52:54 -0700655 fiq_debugger_printf(&state->output,
Colin Crossa6bec1f2014-04-04 22:58:23 -0700656 "fiq_debugger: cpu %d not responding, "
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700657 "reverting to cpu %d\n", state->current_cpu,
658 this_cpu);
659
660 atomic_set(&state->unhandled_fiq_count, 0);
Colin Crossa6bec1f2014-04-04 22:58:23 -0700661 fiq_debugger_switch_cpu(state, this_cpu);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700662 return false;
663 }
664
665 state->in_fiq = true;
666
Colin Crossa6bec1f2014-04-04 22:58:23 -0700667 while ((c = fiq_debugger_getc(state)) != FIQ_DEBUGGER_NO_CHAR) {
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700668 count++;
669 if (!state->debug_enable) {
670 if ((c == 13) || (c == 10)) {
671 state->debug_enable = true;
672 state->debug_count = 0;
Colin Crossa6bec1f2014-04-04 22:58:23 -0700673 fiq_debugger_prompt(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700674 }
675 } else if (c == FIQ_DEBUGGER_BREAK) {
676 state->console_enable = false;
Colin Crossa6bec1f2014-04-04 22:58:23 -0700677 fiq_debugger_puts(state, "fiq debugger mode\n");
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700678 state->debug_count = 0;
Colin Crossa6bec1f2014-04-04 22:58:23 -0700679 fiq_debugger_prompt(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700680#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 Crossa6bec1f2014-04-04 22:58:23 -0700688 fiq_debugger_putc(state, c);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700689 }
690 } else if ((c == 8) || (c == 127)) {
691 if (state->debug_count > 0) {
692 state->debug_count--;
Colin Crossa6bec1f2014-04-04 22:58:23 -0700693 fiq_debugger_putc(state, 8);
694 fiq_debugger_putc(state, ' ');
695 fiq_debugger_putc(state, 8);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700696 }
697 } else if ((c == 13) || (c == 10)) {
698 if (c == '\r' || (c == '\n' && last_c != '\r')) {
Colin Crossa6bec1f2014-04-04 22:58:23 -0700699 fiq_debugger_putc(state, '\r');
700 fiq_debugger_putc(state, '\n');
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700701 }
702 if (state->debug_count) {
703 state->debug_buf[state->debug_count] = 0;
704 state->debug_count = 0;
705 signal_helper |=
Colin Crossa6bec1f2014-04-04 22:58:23 -0700706 fiq_debugger_fiq_exec(state,
707 state->debug_buf,
708 regs, svc_sp);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700709 } else {
Colin Crossa6bec1f2014-04-04 22:58:23 -0700710 fiq_debugger_prompt(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700711 }
712 }
713 last_c = c;
714 }
Colin Cross9e789c92012-10-31 17:41:39 -0700715 if (!state->console_enable)
Colin Crossa6bec1f2014-04-04 22:58:23 -0700716 fiq_debugger_uart_flush(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700717 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 Crosscbee9152014-04-02 18:37:29 -0700730#ifdef CONFIG_FIQ_GLUE
Colin Cross7efcbb82014-04-04 17:05:19 -0700731static void fiq_debugger_fiq(struct fiq_glue_handler *h,
732 const struct pt_regs *regs, void *svc_sp)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700733{
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 Crossa6bec1f2014-04-04 22:58:23 -0700739 need_irq = fiq_debugger_handle_uart_interrupt(state, this_cpu, regs,
740 svc_sp);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700741 if (need_irq)
Colin Crossa6bec1f2014-04-04 22:58:23 -0700742 fiq_debugger_force_irq(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700743}
Colin Crosscbee9152014-04-02 18:37:29 -0700744#endif
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700745
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 Crossa6bec1f2014-04-04 22:58:23 -0700751static irqreturn_t fiq_debugger_uart_irq(int irq, void *dev)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700752{
753 struct fiq_debugger_state *state = dev;
754 bool not_done;
755
Colin Crossa6bec1f2014-04-04 22:58:23 -0700756 fiq_debugger_handle_wakeup(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700757
758 /* handle the debugger irq in regular context */
Colin Crossa6bec1f2014-04-04 22:58:23 -0700759 not_done = fiq_debugger_handle_uart_interrupt(state, smp_processor_id(),
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700760 get_irq_regs(),
761 current_thread_info());
762 if (not_done)
Colin Crossa6bec1f2014-04-04 22:58:23 -0700763 fiq_debugger_handle_irq_context(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700764
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 Crossa6bec1f2014-04-04 22:58:23 -0700773static irqreturn_t fiq_debugger_signal_irq(int irq, void *dev)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700774{
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 Crossa6bec1f2014-04-04 22:58:23 -0700780 fiq_debugger_handle_irq_context(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700781
782 return IRQ_HANDLED;
783}
784
Colin Crosscbee9152014-04-02 18:37:29 -0700785#ifdef CONFIG_FIQ_GLUE
Colin Crossa6bec1f2014-04-04 22:58:23 -0700786static void fiq_debugger_resume(struct fiq_glue_handler *h)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700787{
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 Crosscbee9152014-04-02 18:37:29 -0700793#endif
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700794
795#if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
Colin Crossa6bec1f2014-04-04 22:58:23 -0700796struct tty_driver *fiq_debugger_console_device(struct console *co, int *index)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700797{
Colin Cross77fcefe2012-03-18 15:25:55 -0700798 *index = co->index;
799 return fiq_tty_driver;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700800}
801
Colin Crossa6bec1f2014-04-04 22:58:23 -0700802static void fiq_debugger_console_write(struct console *co,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700803 const char *s, unsigned int count)
804{
805 struct fiq_debugger_state *state;
Colin Cross9e789c92012-10-31 17:41:39 -0700806 unsigned long flags;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700807
808 state = container_of(co, struct fiq_debugger_state, console);
809
810 if (!state->console_enable && !state->syslog_dumping)
811 return;
812
Colin Crossa6bec1f2014-04-04 22:58:23 -0700813 fiq_debugger_uart_enable(state);
Colin Cross9e789c92012-10-31 17:41:39 -0700814 spin_lock_irqsave(&state->console_lock, flags);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700815 while (count--) {
816 if (*s == '\n')
Colin Crossa6bec1f2014-04-04 22:58:23 -0700817 fiq_debugger_putc(state, '\r');
818 fiq_debugger_putc(state, *s++);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700819 }
Colin Crossa6bec1f2014-04-04 22:58:23 -0700820 fiq_debugger_uart_flush(state);
Colin Cross9e789c92012-10-31 17:41:39 -0700821 spin_unlock_irqrestore(&state->console_lock, flags);
Colin Crossa6bec1f2014-04-04 22:58:23 -0700822 fiq_debugger_uart_disable(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700823}
824
825static struct console fiq_debugger_console = {
826 .name = "ttyFIQ",
Colin Crossa6bec1f2014-04-04 22:58:23 -0700827 .device = fiq_debugger_console_device,
828 .write = fiq_debugger_console_write,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700829 .flags = CON_PRINTBUFFER | CON_ANYTIME | CON_ENABLED,
830};
831
832int fiq_tty_open(struct tty_struct *tty, struct file *filp)
833{
Colin Cross77fcefe2012-03-18 15:25:55 -0700834 int line = tty->index;
835 struct fiq_debugger_state **states = tty->driver->driver_state;
836 struct fiq_debugger_state *state = states[line];
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700837
Arve Hjønnevåg053d5472013-01-15 15:10:31 -0800838 return tty_port_open(&state->tty_port, tty, filp);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700839}
840
841void fiq_tty_close(struct tty_struct *tty, struct file *filp)
842{
Arve Hjønnevåg053d5472013-01-15 15:10:31 -0800843 tty_port_close(tty->port, tty, filp);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700844}
845
846int fiq_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
847{
848 int i;
Arve Hjønnevåg053d5472013-01-15 15:10:31 -0800849 int line = tty->index;
850 struct fiq_debugger_state **states = tty->driver->driver_state;
851 struct fiq_debugger_state *state = states[line];
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700852
853 if (!state->console_enable)
854 return count;
855
Colin Crossa6bec1f2014-04-04 22:58:23 -0700856 fiq_debugger_uart_enable(state);
Colin Cross9e789c92012-10-31 17:41:39 -0700857 spin_lock_irq(&state->console_lock);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700858 for (i = 0; i < count; i++)
Colin Crossa6bec1f2014-04-04 22:58:23 -0700859 fiq_debugger_putc(state, *buf++);
Colin Cross9e789c92012-10-31 17:41:39 -0700860 spin_unlock_irq(&state->console_lock);
Colin Crossa6bec1f2014-04-04 22:58:23 -0700861 fiq_debugger_uart_disable(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700862
863 return count;
864}
865
866int fiq_tty_write_room(struct tty_struct *tty)
867{
Colin Cross9e789c92012-10-31 17:41:39 -0700868 return 16;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700869}
870
Colin Cross3bfc29b2012-03-14 19:23:29 -0700871#ifdef CONFIG_CONSOLE_POLL
872static int fiq_tty_poll_init(struct tty_driver *driver, int line, char *options)
873{
874 return 0;
875}
876
877static int fiq_tty_poll_get_char(struct tty_driver *driver, int line)
878{
Arve Hjønnevåg053d5472013-01-15 15:10:31 -0800879 struct fiq_debugger_state **states = driver->driver_state;
880 struct fiq_debugger_state *state = states[line];
Colin Cross3bfc29b2012-03-14 19:23:29 -0700881 int c = NO_POLL_CHAR;
882
Colin Crossa6bec1f2014-04-04 22:58:23 -0700883 fiq_debugger_uart_enable(state);
884 if (fiq_debugger_have_fiq(state)) {
Colin Cross3bfc29b2012-03-14 19:23:29 -0700885 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 Crossa6bec1f2014-04-04 22:58:23 -0700891 c = fiq_debugger_getc(state);
Colin Cross3bfc29b2012-03-14 19:23:29 -0700892 if (c == FIQ_DEBUGGER_NO_CHAR)
893 c = NO_POLL_CHAR;
894 }
Colin Crossa6bec1f2014-04-04 22:58:23 -0700895 fiq_debugger_uart_disable(state);
Colin Cross3bfc29b2012-03-14 19:23:29 -0700896
897 return c;
898}
899
900static void fiq_tty_poll_put_char(struct tty_driver *driver, int line, char ch)
901{
Arve Hjønnevåg053d5472013-01-15 15:10:31 -0800902 struct fiq_debugger_state **states = driver->driver_state;
903 struct fiq_debugger_state *state = states[line];
Colin Crossa6bec1f2014-04-04 22:58:23 -0700904 fiq_debugger_uart_enable(state);
905 fiq_debugger_putc(state, ch);
906 fiq_debugger_uart_disable(state);
Colin Cross3bfc29b2012-03-14 19:23:29 -0700907}
908#endif
909
Arve Hjønnevåg053d5472013-01-15 15:10:31 -0800910static const struct tty_port_operations fiq_tty_port_ops;
911
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700912static 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 Cross3bfc29b2012-03-14 19:23:29 -0700917#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 Malchev8c0dbf62010-06-05 17:36:24 -0700922};
923
Colin Cross77fcefe2012-03-18 15:25:55 -0700924static int fiq_debugger_tty_init(void)
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700925{
Colin Cross77fcefe2012-03-18 15:25:55 -0700926 int ret;
927 struct fiq_debugger_state **states = NULL;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700928
Colin Cross77fcefe2012-03-18 15:25:55 -0700929 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 Malchev8c0dbf62010-06-05 17:36:24 -0700932 return -ENOMEM;
933 }
934
Colin Cross77fcefe2012-03-18 15:25:55 -0700935 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 Malchev8c0dbf62010-06-05 17:36:24 -0700941
Colin Cross77fcefe2012-03-18 15:25:55 -0700942 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 Malchev8c0dbf62010-06-05 17:36:24 -0700960 if (ret) {
961 pr_err("Failed to register fiq tty: %d\n", ret);
Colin Cross77fcefe2012-03-18 15:25:55 -0700962 goto err_free_tty;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -0700963 }
964
Colin Cross77fcefe2012-03-18 15:25:55 -0700965 pr_info("Registered FIQ tty driver\n");
966 return 0;
967
968err_free_tty:
969 put_tty_driver(fiq_tty_driver);
970 fiq_tty_driver = NULL;
971err_free_state:
972 kfree(states);
973 return ret;
974}
975
976static 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 Malchev8c0dbf62010-06-05 17:36:24 -0700984 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åg053d5472013-01-15 15:10:31 -0800991 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 Cross77fcefe2012-03-18 15:25:55 -0700996 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 Malchev8c0dbf62010-06-05 17:36:24 -07001006 return 0;
1007
1008err:
1009 fiq_debugger_ringbuf_free(state->tty_rbuf);
1010 state->tty_rbuf = NULL;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001011 return ret;
1012}
1013#endif
1014
1015static 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
1025static 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
1035static 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 Cross77fcefe2012-03-18 15:25:55 -07001043 if (pdev->id >= MAX_FIQ_DEBUGGER_PORTS)
1044 return -EINVAL;
1045
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001046 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åge073df62014-05-02 19:52:54 -07001063 state->output.printf = fiq_debugger_printf;
Colin Crossa6bec1f2014-04-04 22:58:23 -07001064 setup_timer(&state->sleep_timer, fiq_debugger_sleep_timer_expired,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001065 (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 Crossa6bec1f2014-04-04 22:58:23 -07001077 INIT_WORK(&state->work, fiq_debugger_work);
Colin Cross2b672ca2012-07-19 18:40:04 -07001078 spin_lock_init(&state->work_lock);
1079
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001080 platform_set_drvdata(pdev, state);
1081
1082 spin_lock_init(&state->sleep_timer_lock);
1083
Colin Crossa6bec1f2014-04-04 22:58:23 -07001084 if (state->wakeup_irq < 0 && fiq_debugger_have_fiq(state))
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001085 state->no_sleep = true;
1086 state->ignore_next_wakeup_irq = !state->no_sleep;
1087
Dmitry Shmidtb4a26942017-01-12 12:28:08 -08001088 wakeup_source_init(&state->debugger_wake_src, "serial-debug");
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001089
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 Crossa6bec1f2014-04-04 22:58:23 -07001107 fiq_debugger_printf_nfiq(state,
1108 "<hit enter %sto activate fiq debugger>\n",
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001109 state->no_sleep ? "" : "twice ");
1110
Colin Crosscbee9152014-04-02 18:37:29 -07001111#ifdef CONFIG_FIQ_GLUE
Colin Crossa6bec1f2014-04-04 22:58:23 -07001112 if (fiq_debugger_have_fiq(state)) {
1113 state->handler.fiq = fiq_debugger_fiq;
1114 state->handler.resume = fiq_debugger_resume;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001115 ret = fiq_glue_register_handler(&state->handler);
1116 if (ret) {
1117 pr_err("%s: could not install fiq handler\n", __func__);
Colin Crosscbee9152014-04-02 18:37:29 -07001118 goto err_register_irq;
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001119 }
1120
1121 pdata->fiq_enable(pdev, state->fiq, 1);
Colin Crosscbee9152014-04-02 18:37:29 -07001122 } else
1123#endif
1124 {
Colin Crossa6bec1f2014-04-04 22:58:23 -07001125 ret = request_irq(state->uart_irq, fiq_debugger_uart_irq,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001126 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 Crossa6bec1f2014-04-04 22:58:23 -07001142 ret = request_irq(state->signal_irq, fiq_debugger_signal_irq,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001143 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 Crossa6bec1f2014-04-04 22:58:23 -07001149 ret = request_irq(state->wakeup_irq,
1150 fiq_debugger_wakeup_irq_handler,
John Stultzdaeea722015-12-04 11:32:21 -08001151 IRQF_TRIGGER_FALLING,
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001152 "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 Crossa6bec1f2014-04-04 22:58:23 -07001167 fiq_debugger_handle_wakeup(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001168
1169#if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
Marsb4ffdde2012-11-03 12:15:38 +08001170 spin_lock_init(&state->console_lock);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001171 state->console = fiq_debugger_console;
Colin Cross77fcefe2012-03-18 15:25:55 -07001172 state->console.index = pdev->id;
1173 if (!console_set_on_cmdline)
1174 add_preferred_console(state->console.name,
1175 state->console.index, NULL);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001176 register_console(&state->console);
Colin Cross77fcefe2012-03-18 15:25:55 -07001177 fiq_debugger_tty_init_one(state);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001178#endif
1179 return 0;
1180
1181err_register_irq:
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001182 if (pdata->uart_free)
1183 pdata->uart_free(pdev);
1184err_uart_init:
1185 if (state->clk)
1186 clk_disable(state->clk);
1187 if (state->clk)
1188 clk_put(state->clk);
Dmitry Shmidtb4a26942017-01-12 12:28:08 -08001189 wakeup_source_trash(&state->debugger_wake_src);
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001190 platform_set_drvdata(pdev, NULL);
1191 kfree(state);
1192 return ret;
1193}
1194
1195static const struct dev_pm_ops fiq_debugger_dev_pm_ops = {
1196 .suspend = fiq_debugger_dev_suspend,
1197 .resume = fiq_debugger_dev_resume,
1198};
1199
1200static 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 Shmidtcaff55c2016-05-04 13:51:38 -07001208#if defined(CONFIG_FIQ_DEBUGGER_UART_OVERLAY)
1209int 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 Malchev8c0dbf62010-06-05 17:36:24 -07001231static int __init fiq_debugger_init(void)
1232{
Dmitry Shmidt023f8892016-05-11 11:01:02 -07001233 if (fiq_debugger_disable) {
1234 pr_err("serial_debugger: disabled\n");
1235 return -ENODEV;
1236 }
Colin Cross77fcefe2012-03-18 15:25:55 -07001237#if defined(CONFIG_FIQ_DEBUGGER_CONSOLE)
1238 fiq_debugger_tty_init();
1239#endif
Dmitry Shmidtcaff55c2016-05-04 13:51:38 -07001240#if defined(CONFIG_FIQ_DEBUGGER_UART_OVERLAY)
1241 fiq_debugger_uart_overlay();
1242#endif
Iliyan Malchev8c0dbf62010-06-05 17:36:24 -07001243 return platform_driver_register(&fiq_debugger_driver);
1244}
1245
1246postcore_initcall(fiq_debugger_init);