Skip to contentSkip to conversation

drivers/pl011: Don't configure baudrate

PATCH In review Shanker Donthineni 3 participants 6 messages Jun 9, 2016 – Jun 14, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v9 1/3 drivers/pl011: Don't configure baudrate

The default baud and clock_hz configuration parameters are hardcoded (commit 60ff9444480995008caf) for Versatile Express. Other platforms, these default values may not be valid and might cause problems by programming registers IBRD and FBRD incorrectly.

So, removing driver logic that sets the baudrate to fix the problem. The behavior is unchanged because the driver was already relying on the boot firmware for setting the correct baudrate.

---
Changes since v1:
Edited commit text.

 xen/drivers/char/pl011.c | 21 +--------------------
 1 file changed, 1 insertion(+), 20 deletions(-)
xen/drivers/char/pl011.c +1 -20
index 1212d5c..6a3c21b 100644
@@ -31,7 +31,7 @@
 #include <asm/io.h>
 
 static struct pl011 {
-    unsigned int baud, clock_hz, data_bits, parity, stop_bits;
+    unsigned int data_bits, parity, stop_bits;
     unsigned int irq;
     void __iomem *regs;
     /* UART with IRQ line: interrupt-driven I/O. */
@@ -84,7 +84,6 @@ static void pl011_interrupt(int irq, void *data, struct cpu_user_regs *regs)
 static void __init pl011_init_preirq(struct serial_port *port)
 {
     struct pl011 *uart = port->uart;
-    unsigned int divisor;
     unsigned int cr;
 
     /* No interrupts, please. */
@@ -93,22 +92,6 @@ static void __init pl011_init_preirq(struct serial_port *port)
     /* Definitely no DMA */
     pl011_write(uart, DMACR, 0x0);
 
-    /* Line control and baud-rate generator. */
-    if ( uart->baud != BAUD_AUTO )
-    {
-        /* Baud rate specified: program it into the divisor latch. */
-        divisor = (uart->clock_hz << 2) / uart->baud; /* clk << 6 / bd << 4 */
-        pl011_write(uart, FBRD, divisor & 0x3f);
-        pl011_write(uart, IBRD, divisor >> 6);
-    }
-    else
-    {
-        /* Baud rate already set: read it out from the divisor latch. */
-        divisor = (pl011_read(uart, IBRD) << 6) | (pl011_read(uart, FBRD));
-        if (!divisor)
-            panic("pl011: No Baud rate configured\n");
-        uart->baud = (uart->clock_hz << 2) / divisor;
-    }
     /* This write must follow FBRD and IBRD writes. */
     pl011_write(uart, LCR_H, (uart->data_bits - 5) << 5
                             | FEN
@@ -232,8 +215,6 @@ static int __init pl011_uart_init(int irq, u64 addr, u64 size)
 
     uart = &pl011_com;
     uart->irq       = irq;
-    uart->clock_hz  = 0x16e3600;
-    uart->baud      = BAUD_AUTO;
     uart->data_bits = 8;
     uart->parity    = PARITY_NONE;
     uart->stop_bits = 1;
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

PATCH v9 2/3 drivers/pl011: Use combination of UARTRIS and UARTMSC instead of UARTMIS

The Masked interrupt status register (UARTMIS) is not described in ARM SBSA 2.x document. Anding of two registers UARTMSC and UARTRIS values gives the same information as register UARTMIS.

UARTRIS, UARTMSC and UARTMIS definitions are found in PrimeCell UART PL011 (Revision: r1p4).
- 3.3.10 Interrupt mask set/clear register, UARTIMSC
- 3.3.11 Raw interrupt status register, UARTRIS
- 3.3.12 Masked interrupt status register, UARTMIS

This change is necessary for driver to be SBSA compliant v2.x without affecting the current driver functionality.

---
Changes since v8:
Fixed white spaces.

Changes since v7:
Moved comment 'To compatible with SBSA v2.x document, all accesses should be 32-bit' to #3

Changes since v1:
Added a new function to return an interrupt status.

 xen/drivers/char/pl011.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
xen/drivers/char/pl011.c +8 -2
index 6a3c21b..7e19c4a 100644
@@ -53,11 +53,17 @@ static struct pl011 {
 #define pl011_read(uart, off)           readl((uart)->regs + (off))
 #define pl011_write(uart, off,val)      writel((val), (uart)->regs + (off))
 
+static unsigned int pl011_intr_status(struct pl011 *uart)
+{
+    /* UARTMIS is not documented in SBSA v2.x, so use UARTRIS/UARTIMSC. */
+    return (pl011_read(uart, RIS) & pl011_read(uart, IMSC));
+}
+
 static void pl011_interrupt(int irq, void *data, struct cpu_user_regs *regs)
 {
     struct serial_port *port = data;
     struct pl011 *uart = port->uart;
-    unsigned int status = pl011_read(uart, MIS);
+    unsigned int status = pl011_intr_status(uart);
 
     if ( status )
     {
@@ -76,7 +82,7 @@ static void pl011_interrupt(int irq, void *data, struct cpu_user_regs *regs)
             if ( status & (TXI) )
                 serial_tx_interrupt(port, regs);
 
-            status = pl011_read(uart, MIS);
+            status = pl011_intr_status(uart);
         } while (status != 0);
     }
 }
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH V9 2/3] drivers/pl011: Use combination of UARTRIS and UARTMSC instead of UARTMIS

Quoted 33 lines · Shanker Donthineni

The Masked interrupt status register (UARTMIS) is not described in ARM SBSA 2.x document. Anding of two registers UARTMSC and UARTRIS values gives the same information as register UARTMIS.

UARTRIS, UARTMSC and UARTMIS definitions are found in PrimeCell UART PL011 (Revision: r1p4).
- 3.3.10 Interrupt mask set/clear register, UARTIMSC
- 3.3.11 Raw interrupt status register, UARTRIS
- 3.3.12 Masked interrupt status register, UARTMIS

This change is necessary for driver to be SBSA compliant v2.x without affecting the current driver functionality.

Changes since v8:
Fixed white spaces.

Changes since v7:
Moved comment 'To compatible with SBSA v2.x document, all accesses should be 32-bit' to #3

Changes since v1:
Added a new function to return an interrupt status.

 xen/drivers/char/pl011.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
xen/drivers/char/pl011.c +0 -0
index 6a3c21b..7e19c4a 100644

xen/drivers/char/pl011.c static struct pl011 { · line 56

Quoted 4 lines
xen/drivers/char/pl011.c +1 -0
@@ -53,11 +53,17 @@ static struct pl011 {
 #define pl011_read(uart, off)           readl((uart)->regs + (off))
 #define pl011_write(uart, off,val)      writel((val), (uart)->regs + (off))
 
+static unsigned int pl011_intr_status(struct pl011 *uart)

Maybe this should be static inline?

In any case the series is good, I am happy to queue it up for 4.8.

Quoted 28 lines
xen/drivers/char/pl011.c +7 -2
+{
+    /* UARTMIS is not documented in SBSA v2.x, so use UARTRIS/UARTIMSC. */
+    return (pl011_read(uart, RIS) & pl011_read(uart, IMSC));
+}
+
 static void pl011_interrupt(int irq, void *data, struct cpu_user_regs *regs)
 {
     struct serial_port *port = data;
     struct pl011 *uart = port->uart;
-    unsigned int status = pl011_read(uart, MIS);
+    unsigned int status = pl011_intr_status(uart);
 
     if ( status )
     {
@@ -76,7 +82,7 @@ static void pl011_interrupt(int irq, void *data, struct cpu_user_regs *regs)
             if ( status & (TXI) )
                 serial_tx_interrupt(port, regs);
 
-            status = pl011_read(uart, MIS);
+            status = pl011_intr_status(uart);
         } while (status != 0);
     }
 }
Signature · 3 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH V9 2/3] drivers/pl011: Use combination of UARTRIS and UARTMSC instead of UARTMIS

Quoted 38 lines · Stefano Stabellini
Quoted 13 lines · Shanker Donthineni

The Masked interrupt status register (UARTMIS) is not described in ARM SBSA 2.x document. Anding of two registers UARTMSC and UARTRIS values gives the same information as register UARTMIS.

UARTRIS, UARTMSC and UARTMIS definitions are found in PrimeCell UART PL011 (Revision: r1p4).
- 3.3.10 Interrupt mask set/clear register, UARTIMSC
- 3.3.11 Raw interrupt status register, UARTRIS
- 3.3.12 Masked interrupt status register, UARTMIS

This change is necessary for driver to be SBSA compliant v2.x without affecting the current driver functionality.

Quoted 8 lines

Changes since v8:
Fixed white spaces.

Changes since v7:
Moved comment 'To compatible with SBSA v2.x document, all accesses

should be 32-bit' to #3

xen/drivers/char/pl011.c static struct pl011 { · line 54

Quoted 13 lines

Changes since v1:
Added a new function to return an interrupt status.

  xen/drivers/char/pl011.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
xen/drivers/char/pl011.c +0 -0
index 6a3c21b..7e19c4a 100644
@@ -53,11 +53,17 @@ static struct pl011 {
  #define pl011_read(uart, off)           readl((uart)->regs + (off))
  #define pl011_write(uart, off,val)      writel((val), (uart)->regs +

(off))

Quoted 1 line
Quoted 4 lines
Quoted 1 line

+static unsigned int pl011_intr_status(struct pl011 *uart)

Maybe this should be static inline?

In any case the series is good, I am happy to queue it up for 4.8.

Nice discussion on usage of keyword 'inline', https://www.kernel.org/doc/local/inline.html.

Signature · 9 lines
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw

Re: [PATCH V9 2/3] drivers/pl011: Use combination of UARTRIS and UARTMSC instead of UARTMIS

Hello Shanker,

Quoted 40 lines · Shanker Donthineni
Quoted 37 lines · Stefano Stabellini
Quoted 13 lines · Shanker Donthineni

The Masked interrupt status register (UARTMIS) is not described in ARM SBSA 2.x document. Anding of two registers UARTMSC and UARTRIS values gives the same information as register UARTMIS.

UARTRIS, UARTMSC and UARTMIS definitions are found in PrimeCell UART PL011 (Revision: r1p4).
- 3.3.10 Interrupt mask set/clear register, UARTIMSC
- 3.3.11 Raw interrupt status register, UARTRIS
- 3.3.12 Masked interrupt status register, UARTMIS

This change is necessary for driver to be SBSA compliant v2.x without affecting the current driver functionality.

Quoted 8 lines

Changes since v8:
Fixed white spaces.

Changes since v7:
Moved comment 'To compatible with SBSA v2.x document, all accesses

should be 32-bit' to #3

xen/drivers/char/pl011.c static struct pl011 { · line 54

Quoted 13 lines

Changes since v1:
Added a new function to return an interrupt status.

  xen/drivers/char/pl011.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
xen/drivers/char/pl011.c +0 -0
index 6a3c21b..7e19c4a 100644
@@ -53,11 +53,17 @@ static struct pl011 {
  #define pl011_read(uart, off)           readl((uart)->regs + (off))
  #define pl011_write(uart, off,val)      writel((val), (uart)->regs +

(off))

Quoted 6 lines
Quoted 4 lines

xen/drivers/char/pl011.c static struct pl011 { · line 56

Quoted 1 line
xen/drivers/char/pl011.c +1 -0
+static unsigned int pl011_intr_status(struct pl011 *uart)

Maybe this should be static inline?

In any case the series is good, I am happy to queue it up for 4.8.

Nice discussion on usage of keyword 'inline',
https://www.kernel.org/doc/local/inline.html.

Well, this page has been created in 2007. GCC may have been fixed since then.

Looking at the GCC manual [1]: "GCC does not inline any functions when not optimizing unless you specify the ‘always_inline’ attribute for the function". Although, non-debug build will always have use optimization flags. For debug build, we don't really care about performance so this is fine.

Note that without the keyword "inline" GCC may or not may inline the function. In the case of this patch, this would result to 2 function calls in the interrupt handler. Also, Xen may be built by other compilers than GCC (such as Clang) which may require the keyword "inline" to effectively inline the function.

Anyway, as mentioned by Stefano this is not that important.

Regards,

[1] https://gcc.gnu.org/onlinedocs/gcc/Inline.html#Inline

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#5 lore raw

PATCH v9 3/3 arm/acpi: Add Server Base System Architecture UART support

In reply to Shanker Donthineni

The ARM Server Base System Architecture describes a generic UART interface. It doesn't support clock control registers, modem control, DMA and hardware flow control features. So, extend the driver probe() to handle SBSA interface and skip the accessing PL011 registers that are not described in SBSA document (ARM-DEN-0029 Version 3.0, 6 APPENDIX B: GENERIC UART).

---
Changes sicne v8:
Simplified condition 'if (spcr->interface_type == ACPI_DBG2_SBSA) || ....'.

Changes sicne v7:
Moved comment 'To compatible with SBSA v2.x document, all accesses should be 32-bit' from #2.

Changes since v3:
Moved non-SBSA related changes to patches 1/3 and 2/3.

changes since v2:
Edited commit text to include SBSA document version.
Remove setting baudrate code completely as per Julien's suggestion. Support both the SBSA interface types ACPI_DBG2_SBSA & ACPI_DBG2_SBSA_32. Replace MIS references with combination of RIS & IMSC.

Changes since v1:
Don't access UART registers that are not part of SBSA document. Move setting baudrate function to a separate function.

 xen/drivers/char/pl011.c | 54 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 15 deletions(-)
xen/drivers/char/pl011.c +39 -15
index 7e19c4a..ab22f7f 100644
@@ -41,6 +41,7 @@ static struct pl011 {
     /* struct timer timer; */
     /* unsigned int timeout_ms; */
     /* bool_t probing, intr_works; */
+    bool sbsa;  /* ARM SBSA generic interface */
 } pl011_com = {0};
 
 /* These parity settings can be ORed directly into the LCR. */
@@ -50,6 +51,7 @@ static struct pl011 {
 #define PARITY_MARK  (PEN|SPS)
 #define PARITY_SPACE (PEN|EPS|SPS)
 
+/* SBSA v2.x document requires, all reads/writes must be 32-bit accesses */
 #define pl011_read(uart, off)           readl((uart)->regs + (off))
 #define pl011_write(uart, off,val)      writel((val), (uart)->regs + (off))
 
@@ -95,14 +97,17 @@ static void __init pl011_init_preirq(struct serial_port *port)
     /* No interrupts, please. */
     pl011_write(uart, IMSC, 0);
 
-    /* Definitely no DMA */
-    pl011_write(uart, DMACR, 0x0);
-
-    /* This write must follow FBRD and IBRD writes. */
-    pl011_write(uart, LCR_H, (uart->data_bits - 5) << 5
-                            | FEN
-                            | ((uart->stop_bits - 1) << 3)
-                            | uart->parity);
+    if ( !uart->sbsa )
+    {
+        /* Definitely no DMA */
+        pl011_write(uart, DMACR, 0x0);
+
+        /* This write must follow FBRD and IBRD writes. */
+        pl011_write(uart, LCR_H, (uart->data_bits - 5) << 5
+                                | FEN
+                                | ((uart->stop_bits - 1) << 3)
+                                | uart->parity);
+    }
     /* Clear errors */
     pl011_write(uart, RSR, 0);
 
@@ -110,10 +115,13 @@ static void __init pl011_init_preirq(struct serial_port *port)
     pl011_write(uart, IMSC, 0);
     pl011_write(uart, ICR, ALLI);
 
-    /* Enable the UART for RX and TX; keep RTS and DTR */
-    cr = pl011_read(uart, CR);
-    cr &= RTS | DTR;
-    pl011_write(uart, CR, cr | RXE | TXE | UARTEN);
+    if ( !uart->sbsa )
+    {
+        /* Enable the UART for RX and TX; keep RTS and DTR */
+        cr = pl011_read(uart, CR);
+        cr &= RTS | DTR;
+        pl011_write(uart, CR, cr | RXE | TXE | UARTEN);
+    }
 }
 
 static void __init pl011_init_postirq(struct serial_port *port)
@@ -215,7 +223,7 @@ static struct uart_driver __read_mostly pl011_driver = {
     .vuart_info   = pl011_vuart,
 };
 
-static int __init pl011_uart_init(int irq, u64 addr, u64 size)
+static int __init pl011_uart_init(int irq, u64 addr, u64 size, bool sbsa)
 {
     struct pl011 *uart;
 
@@ -224,6 +232,7 @@ static int __init pl011_uart_init(int irq, u64 addr, u64 size)
     uart->data_bits = 8;
     uart->parity    = PARITY_NONE;
     uart->stop_bits = 1;
+    uart->sbsa      = sbsa;
 
     uart->regs = ioremap_nocache(addr, size);
     if ( !uart->regs )
@@ -272,7 +281,7 @@ static int __init pl011_dt_uart_init(struct dt_device_node *dev,
         return -EINVAL;
     }
 
-    res = pl011_uart_init(res, addr, size);
+    res = pl011_uart_init(res, addr, size, false);
     if ( res < 0 )
     {
         printk("pl011: Unable to initialize\n");
@@ -303,6 +312,7 @@ static int __init pl011_acpi_uart_init(const void *data)
     acpi_status status;
     struct acpi_table_spcr *spcr = NULL;
     int res;
+    bool sbsa;
 
     status = acpi_get_table(ACPI_SIG_SPCR, 0,
                             (struct acpi_table_header **)&spcr);
@@ -313,11 +323,14 @@ static int __init pl011_acpi_uart_init(const void *data)
         return -EINVAL;
     }
 
+    sbsa = (spcr->interface_type == ACPI_DBG2_SBSA ||
+            spcr->interface_type == ACPI_DBG2_SBSA_32);
+
     /* trigger/polarity information is not available in spcr */
     irq_set_type(spcr->interrupt, IRQ_TYPE_LEVEL_HIGH);
 
     res = pl011_uart_init(spcr->interrupt, spcr->serial_port.address,
-                          PAGE_SIZE);
+                          PAGE_SIZE, sbsa);
     if ( res < 0 )
     {
         printk("pl011: Unable to initialize\n");
@@ -331,6 +344,17 @@ ACPI_DEVICE_START(apl011, "PL011 UART", DEVICE_SERIAL)
         .class_type = ACPI_DBG2_PL011,
         .init = pl011_acpi_uart_init,
 ACPI_DEVICE_END
+
+ACPI_DEVICE_START(asbsa_uart, "SBSA UART", DEVICE_SERIAL)
+    .class_type = ACPI_DBG2_SBSA,
+    .init = pl011_acpi_uart_init,
+ACPI_DEVICE_END
+
+ACPI_DEVICE_START(asbsa32_uart, "SBSA32 UART", DEVICE_SERIAL)
+    .class_type = ACPI_DBG2_SBSA_32,
+    .init = pl011_acpi_uart_init,
+ACPI_DEVICE_END
+
 #endif
 
 /*
Signature · 9 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
a Linux Foundation Collaborative Project


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel