Skip to contentSkip to conversation

PC Chipset: Improve serial divisor calculation

PATCH Guenter Roeck 2 participants 3 messages Aug 31, 2018 – Sep 11, 2018

lore
Share & tools
lore
#0 lore raw

Hi,

Quoted 5 lines · Calvin Lee

This fixes several problems I found in the UART serial implementation. Now all divisor values are allowed, while before divisor values of zero and below the base baud rate were rejected. All changes are in reference to http://www.sci.muni.cz/docs/pc/serport.txt

This patch is causing tracebacks in all Linux kernels running the PXA serial driver. Here is an example:

[    1.907584] ------------[ cut here ]------------
[    1.907805] WARNING: CPU: 0 PID: 1 at drivers/tty/serial/pxa.c:544 serial_pxa_set_termios+0x254/0x268
[    1.907865] Modules linked in:
[    1.908130] CPU: 0 PID: 1 Comm: swapper Not tainted 4.9.125-rc1-00067-g7236e21 #1
[    1.908155] Hardware name: Zipit Z2
[    1.908783] [<c0011f54>] (unwind_backtrace) from [<c000e9ac>] (show_stack+0x20/0x24)
[    1.908846] [<c000e9ac>] (show_stack) from [<c029aa80>] (dump_stack+0x20/0x28)
[    1.908877] [<c029aa80>] (dump_stack) from [<c002befc>] (__warn+0xec/0x114)
[    1.908905] [<c002befc>] (__warn) from [<c002bff4>] (warn_slowpath_null+0x30/0x38)
[    1.908931] [<c002bff4>] (warn_slowpath_null) from [<c033eeb4>] (serial_pxa_set_termios+0x254/0x268)
[    1.908958] [<c033eeb4>] (serial_pxa_set_termios) from [<c0339b00>] (uart_set_options+0xc8/0xf0)
[    1.908987] [<c0339b00>] (uart_set_options) from [<c0712200>] (serial_pxa_console_setup+0xb4/0xc4)

...

The patch results in an unexpected DLL register value. Here is the surrounding code from drivers/tty/serial/pxa.c:

	serial_out(up, UART_DLL, quot & 0xff);		/* LS of divisor */

	/*
	 * work around Errata #75 according to Intel(R) PXA27x
	 * Processor Family Specification Update (Nov 2005)
	 */
	dll = serial_in(up, UART_DLL);
	WARN_ON(dll != (quot & 0xff));	// <-- warning

Reverting the patch fixes the problem.

Guenter

#1 lore raw
Quoted 12 lines · Guenter Roeck

The patch results in an unexpected DLL register value. Here is the surrounding code from drivers/tty/serial/pxa.c:

	serial_out(up, UART_DLL, quot & 0xff);		/* LS of divisor */

	/*
	 * work around Errata #75 according to Intel(R) PXA27x
	 * Processor Family Specification Update (Nov 2005)
	 */
	dll = serial_in(up, UART_DLL);
	WARN_ON(dll != (quot & 0xff));	// <-- warning
Quoted 1 line

Reverting the patch fixes the problem.

I think it's a typo. Can you try this:

hw/char/serial.c +2 -2
index 251f40fdac..02463e3388 100644
@@ -345,9 +345,9 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     default:
     case 0:
         if (s->lcr & UART_LCR_DLAB) {
-            if (size == 2) {
+            if (size == 1) {
                 s->divider = (s->divider & 0xff00) | val;
-            } else if (size == 4) {
+            } else {
                 s->divider = val;
             }
             serial_update_parameters(s);

Thanks,

Paolo

author Tested-by
#2 lore raw
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Guenter Roeck

The patch results in an unexpected DLL register value. Here is the surrounding code from drivers/tty/serial/pxa.c:

	serial_out(up, UART_DLL, quot & 0xff);		/* LS of divisor */

	/*
	 * work around Errata #75 according to Intel(R) PXA27x
	 * Processor Family Specification Update (Nov 2005)
	 */
	dll = serial_in(up, UART_DLL);
	WARN_ON(dll != (quot & 0xff));	// <-- warning
Quoted 4 lines
Quoted 1 line

Reverting the patch fixes the problem.

I think it's a typo. Can you try this:

You are correct, the patch below fixes the problem.

Thanks!
Guenter

Quoted 20 lines
hw/char/serial.c +2 -2
index 251f40fdac..02463e3388 100644
@@ -345,9 +345,9 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,
     default:
     case 0:
         if (s->lcr & UART_LCR_DLAB) {
-            if (size == 2) {
+            if (size == 1) {
                 s->divider = (s->divider & 0xff00) | val;
-            } else if (size == 4) {
+            } else {
                 s->divider = val;
             }
             serial_update_parameters(s);

Thanks,

Paolo