xref: /OK3568_Linux_fs/kernel/drivers/soc/rockchip/fiq_debugger/fiq_watchdog.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2014 Google, Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  */
14 
15 #include <linux/kernel.h>
16 #include <linux/spinlock.h>
17 #include <linux/pstore_ram.h>
18 
19 #include "fiq_watchdog.h"
20 #include "fiq_debugger_priv.h"
21 
22 static DEFINE_RAW_SPINLOCK(fiq_watchdog_lock);
23 
fiq_watchdog_printf(struct fiq_debugger_output * output,const char * fmt,...)24 static void fiq_watchdog_printf(struct fiq_debugger_output *output,
25 				const char *fmt, ...)
26 {
27 	char buf[256];
28 	va_list ap;
29 	int len;
30 
31 	va_start(ap, fmt);
32 	len = vscnprintf(buf, sizeof(buf), fmt, ap);
33 	va_end(ap);
34 
35 	ramoops_console_write_buf(buf, len);
36 }
37 
38 struct fiq_debugger_output fiq_watchdog_output = {
39 	.printf = fiq_watchdog_printf,
40 };
41 
fiq_watchdog_triggered(const struct pt_regs * regs,void * svc_sp)42 void fiq_watchdog_triggered(const struct pt_regs *regs, void *svc_sp)
43 {
44 	char msg[24];
45 	int len;
46 
47 	raw_spin_lock(&fiq_watchdog_lock);
48 
49 	len = scnprintf(msg, sizeof(msg), "watchdog fiq cpu %d\n",
50 			THREAD_INFO(svc_sp)->cpu);
51 	ramoops_console_write_buf(msg, len);
52 
53 	fiq_debugger_dump_stacktrace(&fiq_watchdog_output, regs, 100, svc_sp);
54 
55 	raw_spin_unlock(&fiq_watchdog_lock);
56 }
57