Skip to contentSkip to conversation

Blackfin Serial Drivers bug fixing (v2)

PATCH In review Bryan Wu 3 participants 5 messages Aug 15, 2008

lore
Share & tools
lore

Bryan Wu

author
#0 lore raw

cover Blackfin Serial Drivers bug fixing (v2)

Hi Alan,

Sorry for sending out a patch (Blackfin Serial Driver: Fix bug - request UART2/3 peripheral mapped interrupts in PIO mode) you acked before. This time is the 2 bug fixing patches in my queue.

Thanks
-Bryan

author
#1 lore raw

PATCH 1/2 Blackfin Serial Driver: fix bug - Avoid null point exception in kgdb over UART

From: Sonic Zhang <[email protected]>

---
 drivers/serial/bfin_5xx.c |   43 ++++++++++++++++++++++++++-----------------
 1 files changed, 26 insertions(+), 17 deletions(-)
drivers/serial/bfin_5xx.c +26 -17
index 487a562..a5ff54e 100644
@@ -124,8 +124,6 @@ static void bfin_serial_enable_ms(struct uart_port *port)
 }
 
 #ifdef CONFIG_KGDB_UART
-static int kgdb_entry_state;
-
 void kgdb_put_debug_char(int chr)
 {
 	struct bfin_serial_port *uart;
@@ -178,7 +176,7 @@ int kgdb_get_debug_char(void)
 #ifdef CONFIG_SERIAL_BFIN_PIO
 static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
 {
-	struct tty_struct *tty = uart->port.info->port.tty;
+	struct tty_struct *tty = NULL;
 	unsigned int status, ch, flg;
 	static struct timeval anomaly_start = { .tv_sec = 0 };
 
@@ -191,24 +189,33 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
 #ifdef CONFIG_KGDB_UART
 	if (uart->port.line == CONFIG_KGDB_UART_PORT) {
 		struct pt_regs *regs = get_irq_regs();
-		if (uart->port.cons->index == CONFIG_KGDB_UART_PORT && ch == 0x1) { /* Ctrl + A */
-			kgdb_breakkey_pressed(regs);
-			return;
-		} else if (kgdb_entry_state == 0 && ch == '$') {/* connection from KGDB */
-			kgdb_entry_state = 1;
-		} else if (kgdb_entry_state == 1 && ch == 'q') {
-			kgdb_entry_state = 0;
+		int kgdb_timeout;
+		if (uart->port.cons->index == CONFIG_KGDB_UART_PORT
+			&& ch == 0x1) { /* Ctrl + A */
 			kgdb_breakkey_pressed(regs);
 			return;
+		}
+		if (ch == '$') {
+			/* connection from KGDB */
+			kgdb_timeout = get_cclk()/10000;
+			while (!(UART_GET_LSR(uart) & DR)
+				&& kgdb_timeout > 0) {
+				kgdb_timeout--;
+				cpu_relax();
+			}
+			if (kgdb_timeout && UART_GET_CHAR(uart) == 'q') {
+				kgdb_breakkey_pressed(regs);
+				return;
+			}
 		} else if (ch == 0x3) {/* Ctrl + C */
-			kgdb_entry_state = 0;
 			kgdb_breakkey_pressed(regs);
 			return;
-		} else {
-			kgdb_entry_state = 0;
 		}
+		if (!uart->port.info)
+			return;
 	}
 #endif
+	tty = uart->port.info->tty;
 
 	if (ANOMALY_05000363) {
 		/* The BF533 (and BF561) family of processors have a nice anomaly
@@ -1076,10 +1083,7 @@ static int __init bfin_serial_rs_console_init(void)
 {
 	bfin_serial_init_ports();
 	register_console(&bfin_serial_console);
-#ifdef CONFIG_KGDB_UART
-	kgdb_entry_state = 0;
-	init_kgdb_uart();
-#endif
+
 	return 0;
 }
 console_initcall(bfin_serial_rs_console_init);
@@ -1266,6 +1270,7 @@ static int __init bfin_serial_init(void)
 		t.c_line = CONFIG_KGDB_UART_PORT;
 		bfin_serial_set_termios(&uart->port, &t, &t);
 	}
+	init_kgdb_uart();
 #endif
 	return ret;
 }
@@ -1276,7 +1281,11 @@ static void __exit bfin_serial_exit(void)
 	uart_unregister_driver(&bfin_serial_reg);
 }
 
+#ifdef CONFIG_KGDB_UART
+subsys_initcall(bfin_serial_init);
+#else
 module_init(bfin_serial_init);
+#endif
 module_exit(bfin_serial_exit);
 
 MODULE_AUTHOR("Aubrey.Li <[email protected]>");
Signature · 1 line
1.5.6
author
#2 lore raw

PATCH 2/2 Blackfin Serial Driver: Add a debug function to serial driver.

In reply to Bryan Wu

From: Graf Yang <[email protected]>

---
 drivers/serial/bfin_5xx.c |   53 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)
drivers/serial/bfin_5xx.c +52 -1
index a5ff54e..1917904 100644
@@ -21,6 +21,7 @@
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
 #include <linux/serial_core.h>
+#include <stdarg.h>
 
 #ifdef CONFIG_KGDB_UART
 #include <linux/kgdb.h>
@@ -1101,7 +1102,8 @@ static __init void early_serial_putc(struct uart_port *port, int ch)
 	struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
 
 	while ((!(UART_GET_LSR(uart) & THRE)) && --timeout)
-		cpu_relax();
+		barrier();
+
 	UART_PUT_CHAR(uart, ch);
 }
 
@@ -1150,6 +1152,55 @@ struct console __init *bfin_earlyserial_init(unsigned int port,
 
 #endif /* CONFIG_SERIAL_BFIN_CONSOLE */
 
+#ifdef CONFIG_DEBUG_KERNEL
+void bfin_serial_debug(const char *fmt, ...)
+{
+	struct bfin_serial_port *uart = &bfin_serial_ports[0];
+	unsigned short status, tmp;
+	int flags, i, count;
+	char buf[128];
+	va_list ap;
+
+	if (bfin_serial_console.index < 0)
+		return;		/* Too early. */
+
+	va_start(ap, fmt);
+	vsprintf(buf, fmt, ap);
+	va_end(ap);
+	count = strlen(buf);
+
+	spin_lock_irqsave(&uart->port.lock, flags);
+
+	for (i = 0; i < count; i++) {
+		do {
+			status = UART_GET_LSR(uart);
+		} while (!(status & THRE));
+
+#ifndef CONFIG_BF54x
+		tmp = UART_GET_LCR(uart);
+		tmp &= ~DLAB;
+		UART_PUT_LCR(uart, tmp);
+#endif
+		UART_PUT_CHAR(uart, buf[i]);
+		if (buf[i] == '\n') {
+			do {
+				status = UART_GET_LSR(uart);
+			} while (!(status & THRE));
+			UART_PUT_CHAR(uart, '\r');
+		}
+	}
+
+	spin_unlock_irqrestore(&uart->port.lock, flags);
+}
+EXPORT_SYMBOL(bfin_serial_debug);
+#else
+void bfin_serial_debug(const char *fmt, ...)
+{
+	return;
+}
+EXPORT_SYMBOL(bfin_serial_debug);
+#endif
+
 static struct uart_driver bfin_serial_reg = {
 	.owner			= THIS_MODULE,
 	.driver_name		= "bfin-uart",
Signature · 1 line
1.5.6
#3 lore raw

Re: [PATCH 2/2] Blackfin Serial Driver: Add a debug function to serial driver.

drivers/serial/bfin_5xx.c struct console __init *bfin_earlyserial_init(unsigned int port, · line 1202

Quoted 9 lines · Bryan Wu
drivers/serial/bfin_5xx.c +9 -0
+#ifdef CONFIG_DEBUG_KERNEL
+ ...
+#else
+void bfin_serial_debug(const char *fmt, ...)
+{
+       return;
+}
+EXPORT_SYMBOL(bfin_serial_debug);
+#endif

it doesnt really make sense to export the symbol or make it available when debugging is not enabled.
-mike

Acked-by on the v1 series
#4 lore raw
In reply to Bryan Wu
Quoted 6 lines · On Fri, 15 Aug 2008 16:23:35 +0800 Bryan Wu <[email protected]> wrote:

Hi Alan,

Sorry for sending out a patch (Blackfin Serial Driver: Fix bug - request UART2/3 peripheral mapped interrupts in PIO mode) you acked before. This time is the 2 bug fixing patches in my queue.

Look fine to me