[PATCH] introduce-resume-exception-capture.patch

Andy Green andy at openmoko.com
Sat Jun 21 15:20:48 CEST 2008


This patch introduces a new resume debugging concept: if we
get an OOPS inbetween starting suspend and finishing resume, it
uses a new "emergency spew" device similar to BUT NOT REQUIRING
CONFIG_DEBUG_LL to dump the syslog buffer and then the OOPS
on the debug device defined by the existing CONFIG_DEBUG_S3C_UART
index.  But neither CONFIG_DEBUG_LL nor the S3C low level configs
are needed to use this feature.

Another difference between this feature and CONFIG_DEBUG_LL is that
it does not affect resume timing, ordering or UART traffic UNLESS
there is an OOPS during resume.

The patch adds three global exports, one to say if we are inside
suspend / resume, and two callbacks for printk() to use to init
and dump the emergency data.  The callbacks are set in s3c serial
device init, but the whole structure is arch independent.

Signed-off-by: Andy Green <andy at openmoko.com>
---

 drivers/serial/s3c2410.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++
 kernel/power/main.c      |   10 ++++++
 kernel/printk.c          |   39 +++++++++++++++++++++++++
 3 files changed, 119 insertions(+), 1 deletions(-)

diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index e3e82f7..c17c84a 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -81,6 +81,7 @@
 
 #include <asm/plat-s3c/regs-serial.h>
 #include <asm/arch/regs-gpio.h>
+#include <asm/arch/regs-clock.h>
 
 #include <linux/neospy.h>
 extern struct neospy_logdata neospy;
@@ -1043,6 +1044,69 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = {
 #endif
 };
 
+static void s3c24xx_serial_force_debug_port_up(void)
+{
+	struct s3c24xx_uart_port *ourport = &s3c24xx_serial_ports[
+							 CONFIG_DEBUG_S3C_UART];
+	struct s3c24xx_uart_clksrc *clksrc = NULL;
+	struct clk *clk = NULL;
+	unsigned long tmp;
+
+	s3c24xx_serial_getclk(&ourport->port, &clksrc, &clk, 115200);
+
+	tmp = __raw_readl(S3C2410_CLKCON);
+
+	/* re-start uart clocks */
+	tmp |= S3C2410_CLKCON_UART0;
+	tmp |= S3C2410_CLKCON_UART1;
+	tmp |= S3C2410_CLKCON_UART2;
+
+	__raw_writel(tmp, S3C2410_CLKCON);
+	udelay(10);
+
+	s3c24xx_serial_setsource(&ourport->port, clksrc);
+
+	if (ourport->baudclk != NULL && !IS_ERR(ourport->baudclk)) {
+		clk_disable(ourport->baudclk);
+		ourport->baudclk  = NULL;
+	}
+
+	clk_enable(clk);
+
+	ourport->clksrc = clksrc;
+	ourport->baudclk = clk;
+}
+
+static void s3c2410_printascii(const char *sz)
+{
+	struct s3c24xx_uart_port *ourport = &s3c24xx_serial_ports[
+							 CONFIG_DEBUG_S3C_UART];
+	struct uart_port *port = &ourport->port;
+
+	/* 8 N 1 */
+	wr_regl(port, S3C2410_ULCON, (rd_regl(port, S3C2410_ULCON)) | 3);
+	/* polling mode */
+	wr_regl(port, S3C2410_UCON, (rd_regl(port, S3C2410_UCON) & ~0xc0f) | 5);
+	/* disable FIFO */
+	wr_regl(port, S3C2410_UFCON, (rd_regl(port, S3C2410_UFCON) & ~0x01));
+	/* fix baud rate */
+	wr_regl(port, S3C2410_UBRDIV, 26);
+
+	while (*sz) {
+		int timeout = 10000000;
+
+		/* spin on it being busy */
+		while ((!(rd_regl(port, S3C2410_UTRSTAT) & 2)) && timeout--)
+			;
+
+		/* transmit register */
+		wr_regl(port, S3C2410_UTXH, *sz);
+
+		sz++;
+	}
+}
+
+
 /* s3c24xx_serial_resetport
  *
  * wrapper to call the specific reset for this port (reset the fifos
@@ -1263,6 +1327,13 @@ static int s3c24xx_serial_resume(struct platform_device *dev)
 static int s3c24xx_serial_init(struct platform_driver *drv,
 			       struct s3c24xx_uart_info *info)
 {
+	/* set up the emergency debug UART functions */
+	extern void (*emergency_debug_spew_init)(void);
+	extern void (*emergency_debug_spew_send_string)(const char *);
+
+	emergency_debug_spew_init = s3c24xx_serial_force_debug_port_up;
+	emergency_debug_spew_send_string= s3c2410_printascii;
+
 	dbg("s3c24xx_serial_init(%p,%p)\n", drv, info);
 	return platform_driver_register(drv);
 }
diff --git a/kernel/power/main.c b/kernel/power/main.c
index f71c950..d87bf0d 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -31,6 +31,10 @@ DEFINE_MUTEX(pm_mutex);
 unsigned int pm_flags;
 EXPORT_SYMBOL(pm_flags);
 
+int global_inside_suspend;
+EXPORT_SYMBOL(global_inside_suspend);
+
+
 #ifdef CONFIG_SUSPEND
 
 /* This is just an arbitrary number */
@@ -156,10 +160,12 @@ int suspend_devices_and_enter(suspend_state_t state)
 	if (!suspend_ops)
 		return -ENOSYS;
 
+	global_inside_suspend = 1;
+
 	if (suspend_ops->set_target) {
 		error = suspend_ops->set_target(state);
 		if (error)
-			return error;
+			goto bail;
 	}
 	suspend_console();
 	error = device_suspend(PMSG_SUSPEND);
@@ -183,6 +189,8 @@ int suspend_devices_and_enter(suspend_state_t state)
 	device_resume();
  Resume_console:
 	resume_console();
+bail:
+	global_inside_suspend = 0;
 	return error;
 }
 
diff --git a/kernel/printk.c b/kernel/printk.c
index 89011bf..5470af8 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -35,6 +35,8 @@
 #include <linux/jiffies.h>
 
 #include <asm/uaccess.h>
+#include <asm/plat-s3c24xx/neo1973.h>
+#include <asm/arch/gta02.h>
 
 #define __LOG_BUF_LEN	(1 << CONFIG_LOG_BUF_SHIFT)
 
@@ -61,6 +63,11 @@ int console_printk[4] = {
 int oops_in_progress;
 EXPORT_SYMBOL(oops_in_progress);
 
+void (*emergency_debug_spew_init)(void) = NULL;
+EXPORT_SYMBOL(emergency_debug_spew_init);
+void (*emergency_debug_spew_send_string)(const char *) = NULL;
+EXPORT_SYMBOL(emergency_debug_spew_send_string);
+
 /*
  * console_sem protects the console_drivers list, and also
  * provides serialisation for access to the entire console
@@ -635,6 +642,7 @@ asmlinkage int vprintk(const char *fmt, va_list args)
 	char *p;
 	static char printk_buf[1024];
 	static int log_level_unknown = 1;
+	extern int global_inside_suspend;
 
 	boot_delay_msec();
 
@@ -653,6 +661,37 @@ asmlinkage int vprintk(const char *fmt, va_list args)
 	/* Emit the output into the temporary buffer */
 	printed_len = vscnprintf(printk_buf, sizeof(printk_buf), fmt, args);
 
+	/* if you're debugging resume, the normal methods can change resume
+	 * ordering behaviours because their debugging output is synchronous
+	 * (ie, CONFIG_DEBUG_LL).  If your problem is an OOPS, this code
+	 * will not affect the speed and duration and ordering of resume
+	 * actions, but will give you a chance to read the full undumped
+	 * syslog AND the OOPS data when it happens
+	 *
+	 * if you support it, your debug device init can override the exported
+	 * emergency_debug_spew_init and emergency_debug_spew_send_string to
+	 * usually force polling or bitbanging on your debug console device
+	 */
+	if (oops_in_progress && global_inside_suspend &&
+	    emergency_debug_spew_init && emergency_debug_spew_send_string) {
+		unsigned long cur_index;
+		char ch[2];
+
+		if (global_inside_suspend == 1) {
+			(emergency_debug_spew_init)();
+
+			ch[1] = '\0';
+			cur_index = con_start;
+			while (cur_index != log_end) {
+				ch[0] = LOG_BUF(cur_index);
+				(emergency_debug_spew_send_string)(ch);
+				cur_index++;
+			}
+			global_inside_suspend++; /* only once */
+		}
+		(emergency_debug_spew_send_string)(printk_buf);
+	}
+
 	/*
 	 * Copy the output into log_buf.  If the caller didn't provide
 	 * appropriate log level tags, we insert them here





More information about the openmoko-kernel mailing list