Skip to contentSkip to conversation

xen/arm: debug-pl011.inc: Use macros instead of hardcoded values

PATCH In review Michal Orzel 4 participants 19 messages Oct 24, 2022 – Nov 18, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: debug-pl011.inc: Use macros instead of hardcoded values

Make use of the macros defined in asm/pl011-uart.h instead of hardcoding the values. Also, take the opportunity to fix the file extension in a top-level comment.

No functional change intended.

---
 xen/arch/arm/arm64/debug-pl011.inc | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
xen/arch/arm/arm64/debug-pl011.inc +11 -9
index 1928a2e3ffbb..d82f2f1de197 100644
@@ -1,5 +1,5 @@
 /*
- * xen/arch/arm/arm64/debug-pl011.S
+ * xen/arch/arm/arm64/debug-pl011.inc
  *
  * PL011 specific debug code
  *
@@ -16,6 +16,8 @@
  * GNU General Public License for more details.
  */
 
+ #include <asm/pl011-uart.h>
+
 /*
  * PL011 UART initialization
  * xb: register which containts the UART base address
@@ -23,13 +25,13 @@
  */
 .macro early_uart_init xb, c
         mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE % 16)
-        strh  w\c, [\xb, #0x28]      /* -> UARTFBRD (Baud divisor fraction) */
+        strh  w\c, [\xb, #FBRD]      /* -> UARTFBRD (Baud divisor fraction) */
         mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE / 16)
-        strh  w\c, [\xb, #0x24]      /* -> UARTIBRD (Baud divisor integer) */
+        strh  w\c, [\xb, #IBRD]      /* -> UARTIBRD (Baud divisor integer) */
         mov   x\c, #0x60             /* 8n1 */
-        str   w\c, [\xb, #0x2C]      /* -> UARTLCR_H (Line control) */
-        ldr   x\c, =0x00000301       /* RXE | TXE | UARTEN */
-        str   w\c, [\xb, #0x30]      /* -> UARTCR (Control Register) */
+        str   w\c, [\xb, #LCR_H]     /* -> UARTLCR_H (Line control) */
+        ldr   x\c, =(RXE | TXE | UARTEN)
+        str   w\c, [\xb, #CR]        /* -> UARTCR (Control Register) */
 .endm
 
 /*
@@ -39,8 +41,8 @@
  */
 .macro early_uart_ready xb, c
 1:
-        ldrh  w\c, [\xb, #0x18]      /* <- UARTFR (Flag register) */
-        tst   w\c, #0x8              /* Check BUSY bit */
+        ldrh  w\c, [\xb, #FR]        /* <- UARTFR (Flag register) */
+        tst   w\c, #BUSY             /* Check BUSY bit */
         b.ne  1b                     /* Wait for the UART to be ready */
 .endm
 
@@ -50,7 +52,7 @@
  * wt: register which contains the character to transmit
  */
 .macro early_uart_transmit xb, wt
-        strb  \wt, [\xb]             /* -> UARTDR (Data Register) */
+        strb  \wt, [\xb, #DR]        /* -> UARTDR (Data Register) */
 .endm
 
 /*
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#2 lore raw
In reply to Michal Orzel

Hi Michal,

Quoted 7 lines · Michal Orzel

Make use of the macros defined in asm/pl011-uart.h instead of hardcoding the values. Also, take the opportunity to fix the file extension in a top-level comment.

No functional change intended.

With one comment below:

Quoted 25 lines
---
  xen/arch/arm/arm64/debug-pl011.inc | 20 +++++++++++---------
  1 file changed, 11 insertions(+), 9 deletions(-)
xen/arch/arm/arm64/debug-pl011.inc +3 -1
index 1928a2e3ffbb..d82f2f1de197 100644
@@ -1,5 +1,5 @@
  /*
- * xen/arch/arm/arm64/debug-pl011.S
+ * xen/arch/arm/arm64/debug-pl011.inc
   *
   * PL011 specific debug code
   *
@@ -16,6 +16,8 @@
   * GNU General Public License for more details.
   */
 
+ #include <asm/pl011-uart.h>
+
  /*
   * PL011 UART initialization
   * xb: register which containts the UART base address

xen/arch/arm/arm64/debug-pl011.inc line 31

Quoted 9 lines
xen/arch/arm/arm64/debug-pl011.inc +2 -2
@@ -23,13 +25,13 @@
   */
  .macro early_uart_init xb, c
          mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE % 16)
-        strh  w\c, [\xb, #0x28]      /* -> UARTFBRD (Baud divisor fraction) */
+        strh  w\c, [\xb, #FBRD]      /* -> UARTFBRD (Baud divisor fraction) */
          mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE / 16)
-        strh  w\c, [\xb, #0x24]      /* -> UARTIBRD (Baud divisor integer) */
+        strh  w\c, [\xb, #IBRD]      /* -> UARTIBRD (Baud divisor integer) */
          mov   x\c, #0x60             /* 8n1 */

Can we introduce macro/define for 0x60?

xen/arch/arm/arm64/debug-pl011.inc line 35

Quoted 7 lines
xen/arch/arm/arm64/debug-pl011.inc +3 -3
-        str   w\c, [\xb, #0x2C]      /* -> UARTLCR_H (Line control) */
-        ldr   x\c, =0x00000301       /* RXE | TXE | UARTEN */
-        str   w\c, [\xb, #0x30]      /* -> UARTCR (Control Register) */
+        str   w\c, [\xb, #LCR_H]     /* -> UARTLCR_H (Line control) */
+        ldr   x\c, =(RXE | TXE | UARTEN)
+        str   w\c, [\xb, #CR]        /* -> UARTCR (Control Register) */
  .endm

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

Hi Julien,

Quoted 45 lines · Julien Grall

Hi Michal,

Quoted 7 lines · Michal Orzel

Make use of the macros defined in asm/pl011-uart.h instead of hardcoding the values. Also, take the opportunity to fix the file extension in a top-level comment.

No functional change intended.

With one comment below:

Quoted 28 lines
---
  xen/arch/arm/arm64/debug-pl011.inc | 20 +++++++++++---------
  1 file changed, 11 insertions(+), 9 deletions(-)
xen/arch/arm/arm64/debug-pl011.inc +3 -1
index 1928a2e3ffbb..d82f2f1de197 100644
@@ -1,5 +1,5 @@
  /*
- * xen/arch/arm/arm64/debug-pl011.S
+ * xen/arch/arm/arm64/debug-pl011.inc
   *
   * PL011 specific debug code
   *
@@ -16,6 +16,8 @@
   * GNU General Public License for more details.
   */
 
+ #include <asm/pl011-uart.h>
+
  /*
   * PL011 UART initialization
   * xb: register which containts the UART base address
@@ -23,13 +25,13 @@
   */
  .macro early_uart_init xb, c
          mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE % 16)
Quoted 8 lines

xen/arch/arm/arm64/debug-pl011.inc line 31

Quoted 6 lines
xen/arch/arm/arm64/debug-pl011.inc +2 -2
-        strh  w\c, [\xb, #0x28]      /* -> UARTFBRD (Baud divisor fraction) */
+        strh  w\c, [\xb, #FBRD]      /* -> UARTFBRD (Baud divisor fraction) */
          mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE / 16)
-        strh  w\c, [\xb, #0x24]      /* -> UARTIBRD (Baud divisor integer) */
+        strh  w\c, [\xb, #IBRD]      /* -> UARTIBRD (Baud divisor integer) */
          mov   x\c, #0x60             /* 8n1 */

Can we introduce macro/define for 0x60?

We could but I think this should not be part of this patch.
The reason being, the arm32 code also uses hardcoded 0x60 so it should be changed as well.
I can create a prerequisite patch introducing the macro and changing the arm32 code first unless you prefer to have everything in a single patch.

As for the macro itself, because 8n1 only requires setting bits for WLEN (1 stop bit and no parity are 0 by default), we can do the following in pl011-uart.h:
#define WLEN_8 0x60
and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

Quoted 9 lines

xen/arch/arm/arm64/debug-pl011.inc line 35

Quoted 8 lines
xen/arch/arm/arm64/debug-pl011.inc +3 -3
-        str   w\c, [\xb, #0x2C]      /* -> UARTLCR_H (Line control) */
-        ldr   x\c, =0x00000301       /* RXE | TXE | UARTEN */
-        str   w\c, [\xb, #0x30]      /* -> UARTCR (Control Register) */
+        str   w\c, [\xb, #LCR_H]     /* -> UARTLCR_H (Line control) */
+        ldr   x\c, =(RXE | TXE | UARTEN)
+        str   w\c, [\xb, #CR]        /* -> UARTCR (Control Register) */
  .endm
Quoted 4 lines

Cheers,

--
Julien Grall

~Michal

#4 lore raw
Quoted 54 lines · Michal Orzel
Quoted 45 lines · Julien Grall

Hi Michal,

Quoted 7 lines · Michal Orzel

Make use of the macros defined in asm/pl011-uart.h instead of hardcoding the values. Also, take the opportunity to fix the file extension in a top-level comment.

No functional change intended.

With one comment below:

Quoted 28 lines
---
   xen/arch/arm/arm64/debug-pl011.inc | 20 +++++++++++---------
   1 file changed, 11 insertions(+), 9 deletions(-)
xen/arch/arm/arm64/debug-pl011.inc +3 -1
index 1928a2e3ffbb..d82f2f1de197 100644
@@ -1,5 +1,5 @@
   /*
- * xen/arch/arm/arm64/debug-pl011.S
+ * xen/arch/arm/arm64/debug-pl011.inc
    *
    * PL011 specific debug code
    *
@@ -16,6 +16,8 @@
    * GNU General Public License for more details.
    */
 
+ #include <asm/pl011-uart.h>
+
   /*
    * PL011 UART initialization
    * xb: register which containts the UART base address
@@ -23,13 +25,13 @@
    */
   .macro early_uart_init xb, c
           mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE % 16)
Quoted 8 lines

xen/arch/arm/arm64/debug-pl011.inc line 31

Quoted 6 lines
xen/arch/arm/arm64/debug-pl011.inc +2 -2
-        strh  w\c, [\xb, #0x28]      /* -> UARTFBRD (Baud divisor fraction) */
+        strh  w\c, [\xb, #FBRD]      /* -> UARTFBRD (Baud divisor fraction) */
           mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE / 16)
-        strh  w\c, [\xb, #0x24]      /* -> UARTIBRD (Baud divisor integer) */
+        strh  w\c, [\xb, #IBRD]      /* -> UARTIBRD (Baud divisor integer) */
           mov   x\c, #0x60             /* 8n1 */

Can we introduce macro/define for 0x60?

Quoted 3 lines

We could but I think this should not be part of this patch.
The reason being, the arm32 code also uses hardcoded 0x60 so it should be changed as well.
I can create a prerequisite patch introducing the macro and changing the arm32 code first unless you prefer to have everything in a single patch.

I am fine with either prerequisite or a follow-up to define a macro and use it in both arm32/arm64.

Quoted 4 lines

As for the macro itself, because 8n1 only requires setting bits for WLEN (1 stop bit and no parity are 0 by default), we can do the following in pl011-uart.h:
#define WLEN_8 0x60

I think it would be clearer and easier to check the spec if the value is (_AC(0x3, U) << 5).

Quoted 1 line

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw

Hi Julien,

Quoted 57 lines · Julien Grall
Quoted 54 lines · Michal Orzel
Quoted 53 lines · Julien Grall

Hi Michal,

Quoted 7 lines · Michal Orzel

Make use of the macros defined in asm/pl011-uart.h instead of hardcoding the values. Also, take the opportunity to fix the file extension in a top-level comment.

No functional change intended.

With one comment below:

Quoted 25 lines
---
   xen/arch/arm/arm64/debug-pl011.inc | 20 +++++++++++---------
   1 file changed, 11 insertions(+), 9 deletions(-)
xen/arch/arm/arm64/debug-pl011.inc +3 -1
index 1928a2e3ffbb..d82f2f1de197 100644
@@ -1,5 +1,5 @@
   /*
- * xen/arch/arm/arm64/debug-pl011.S
+ * xen/arch/arm/arm64/debug-pl011.inc
    *
    * PL011 specific debug code
    *
@@ -16,6 +16,8 @@
    * GNU General Public License for more details.
    */
 
+ #include <asm/pl011-uart.h>
+
   /*
    * PL011 UART initialization
    * xb: register which containts the UART base address

xen/arch/arm/arm64/debug-pl011.inc line 31

Quoted 9 lines
xen/arch/arm/arm64/debug-pl011.inc +2 -2
@@ -23,13 +25,13 @@
    */
   .macro early_uart_init xb, c
           mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE % 16)
-        strh  w\c, [\xb, #0x28]      /* -> UARTFBRD (Baud divisor fraction) */
+        strh  w\c, [\xb, #FBRD]      /* -> UARTFBRD (Baud divisor fraction) */
           mov   x\c, #(7372800 / CONFIG_EARLY_UART_PL011_BAUD_RATE / 16)
-        strh  w\c, [\xb, #0x24]      /* -> UARTIBRD (Baud divisor integer) */
+        strh  w\c, [\xb, #IBRD]      /* -> UARTIBRD (Baud divisor integer) */
           mov   x\c, #0x60             /* 8n1 */

Can we introduce macro/define for 0x60?

Quoted 6 lines
Quoted 3 lines

We could but I think this should not be part of this patch.
The reason being, the arm32 code also uses hardcoded 0x60 so it should be changed as well.
I can create a prerequisite patch introducing the macro and changing the arm32 code first unless you prefer to have everything in a single patch.

I am fine with either prerequisite or a follow-up to define a macro and use it in both arm32/arm64.

I would then prefer to add a follow-up patch as this one is already acked and created for a different reason.

Quoted 8 lines
Quoted 5 lines

As for the macro itself, because 8n1 only requires setting bits for WLEN (1 stop bit and no parity are 0 by default), we can do the following in pl011-uart.h:
#define WLEN_8 0x60

I think it would be clearer and easier to check the spec if the value is (_AC(0x3, U) << 5).

sounds good.

Quoted 9 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.
At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

Quoted 5 lines

Cheers,

--
Julien Grall

~Michal

#6 lore raw
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

Quoted 4 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

So we have two choices:
1) Remove the baud rate setting in the early uart code
2) Support the baud rate in the runtime driver

I strongly prefer 1 so far because there are not any practical use to have a different baud rate for Xen and the firmware.

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw

Hi Julien,

Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 10 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Quoted 7 lines

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Quoted 5 lines

So we have two choices:
1) Remove the baud rate setting in the early uart code
2) Support the baud rate in the runtime driver

Quoted 7 lines

I strongly prefer 1 so far because there are not any practical use to have a different baud rate for Xen and the firmware.

Cheers,

--
Julien Grall

~Michal

#8 lore raw

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

Cheers,

Signature · 1 line
Julien Grall
#9 lore raw

Hi Julien,

Quoted 52 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Quoted 7 lines

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

[1] It is not stated anywhere in our docs.

[2] BTW: our docs/misc/arm/booting contains invalid links to the kernel docs. I guess this wants to be fixed.

Quoted 5 lines

Cheers,

--
Julien Grall

~Michal

#10 lore raw
Quoted 59 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 4 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

Quoted 2 lines

[1] It is not stated anywhere in our docs.

Our docs are not perfect. Patches are welcomed for improvement. Although, I think the statement should only be for driver where we don't set the baud rate. For the others, we should leave it as is unless you can prove this is not necessary (we don't want to break existing setup).

Quoted 3 lines

[2] BTW: our docs/misc/arm/booting contains invalid links to the kernel docs. I guess this wants to be fixed.

Patches are welcomed.

[3] I do have a large list of more critical bugs that I will be happy to share if you are looking for improving Xen.

Signature · 1 line
Julien Grall
#11 lore raw

Hi,

Quoted 77 lines · Julien Grall
Quoted 58 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 3 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

Quoted 7 lines

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

Just one remark here: In some cases the firmware might use a different console than the serial one (for example a graphical one) and Xen could be the first to use the serial console. So there might be cases where if we do not set a default value, the console will not be configured at all.

I think the best solution here would be to have a CONFIG setting so that someone compiling Xen could choose between “keeping firmware config” or “force a config”.

Cheers
Bertrand

Quoted 14 lines
Quoted 2 lines

[1] It is not stated anywhere in our docs.

Our docs are not perfect. Patches are welcomed for improvement. Although, I think the statement should only be for driver where we don't set the baud rate. For the others, we should leave it as is unless you can prove this is not necessary (we don't want to break existing setup).

Quoted 2 lines

[2] BTW: our docs/misc/arm/booting contains invalid links to the kernel docs. I guess this wants to be fixed.

Patches are welcomed.

[3] I do have a large list of more critical bugs that I will be happy to share if you are looking for improving Xen.

Signature · 1 line
Julien Grall
#12 lore raw
Quoted 81 lines · Bertrand Marquis

Hi,

Quoted 79 lines · Julien Grall
Quoted 58 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 3 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

Quoted 8 lines
Quoted 5 lines

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

Just one remark here: In some cases the firmware might use a different console than the serial one (for example a graphical one) and Xen could be the first to use the serial console. So there might be cases where if we do not set a default value, the console will not be configured at all.

Fair point.

Quoted 2 lines

I think the best solution here would be to have a CONFIG setting so that someone compiling Xen could choose between “keeping firmware config” or “force a config”.

I don't like the idea of the CONFIG to force the baud rate at runtime. If you want to give the choice to the user, then this should be read from the firmware tables.

In fact, the information should already be there.

Cheers,

Signature · 1 line
Julien Grall
#13 lore raw
In reply to Julien Grall

Hi Julien,

Quoted 86 lines · Julien Grall
Quoted 59 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 4 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Quoted 5 lines

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

I'm not in favor of this approach either. That said, I will prepare patches to remove CONFIG_EARLY_UART_PL011_BAUD_RATE and its usage in early printk code as we agreed earlier. As for the LCR setting, I will keep it in early printk code to maintain the same behavior as runtime driver who sets them.

Quoted 10 lines
Quoted 3 lines

[1] It is not stated anywhere in our docs.

Our docs are not perfect. Patches are welcomed for improvement. Although, I think the statement should only be for driver where we don't set the baud rate. For the others, we should leave it as is unless you can prove this is not necessary (we don't want to break existing setup).

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

[2] BTW: our docs/misc/arm/booting contains invalid links to the kernel docs. I guess this wants to be fixed.

Patches are welcomed.

[3] I do have a large list of more critical bugs that I will be happy to share if you are looking for improving Xen.

That is cool and such list would be great for everyone having some spare time (+ newcomers). Taking the opportunity of having a GitLab CI epics, I think it is worth adding such work items here:
https://gitlab.com/groups/xen-project/-/epics?state=opened&page=1&sort=start_date_desc

Quoted 3 lines

--
Julien Grall

~Michal

#14 lore raw

Hi,

Quoted 110 lines · Michal Orzel
Quoted 86 lines · Julien Grall
Quoted 59 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 4 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Quoted 5 lines

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

I'm not in favor of this approach either. That said, I will prepare patches to remove CONFIG_EARLY_UART_PL011_BAUD_RATE and its usage in early printk code as we agreed earlier. As for the LCR setting, I will keep it in early printk code to maintain the same behavior as runtime driver who sets them.

Quoted 13 lines
Quoted 3 lines

[1] It is not stated anywhere in our docs.

Our docs are not perfect. Patches are welcomed for improvement. Although, I think the statement should only be for driver where we don't set the baud rate. For the others, we should leave it as is unless you can prove this is not necessary (we don't want to break existing setup).

Quoted 3 lines

[2] BTW: our docs/misc/arm/booting contains invalid links to the kernel docs. I guess this wants to be fixed.

Quoted 7 lines
Quoted 4 lines

Patches are welcomed.

[3] I do have a large list of more critical bugs that I will be happy to share if you are looking for improving Xen.

That is cool and such list would be great for everyone having some spare time (+ newcomers). Taking the opportunity of having a GitLab CI epics, I think it is worth adding such work items here:
https://gitlab.com/groups/xen-project/-/epics?state=opened&page=1&sort=start_date_desc

I already have a Trello board I created a few years ago when I left Arm [1] with 30+ issues. I have another 30+ in my private board.

I can try to clean-up the one I have in my private board. But I will need some help for transfer everything to gitlab.

Cheers,

[1] https://trello.com/invite/b/L54vXoqM/ATTI99c86a2718dec17b3b08f0de35fb3b5bC8729E45/xen

Signature · 1 line
Julien Grall
#15 lore raw

Hi Julien,

Quoted 118 lines · Julien Grall

Hi,

Quoted 113 lines · Michal Orzel
Quoted 86 lines · Julien Grall
Quoted 59 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 4 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Quoted 5 lines

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

I'm not in favor of this approach either. That said, I will prepare patches to remove CONFIG_EARLY_UART_PL011_BAUD_RATE and its usage in early printk code as we agreed earlier. As for the LCR setting, I will keep it in early printk code to maintain the same behavior as runtime driver who sets them.

Quoted 17 lines
Quoted 3 lines

[1] It is not stated anywhere in our docs.

Our docs are not perfect. Patches are welcomed for improvement. Although, I think the statement should only be for driver where we don't set the baud rate. For the others, we should leave it as is unless you can prove this is not necessary (we don't want to break existing setup).

Quoted 3 lines

[2] BTW: our docs/misc/arm/booting contains invalid links to the kernel docs. I guess this wants to be fixed.

Patches are welcomed.

[3] I do have a large list of more critical bugs that I will be happy to share if you are looking for improving Xen.

Quoted 7 lines
Quoted 3 lines

That is cool and such list would be great for everyone having some spare time (+ newcomers). Taking the opportunity of having a GitLab CI epics, I think it is worth adding such work items here:
https://gitlab.com/groups/xen-project/-/epics?state=opened&page=1&sort=start_date_desc

I already have a Trello board I created a few years ago when I left Arm [1] with 30+ issues. I have another 30+ in my private board.

I can try to clean-up the one I have in my private board. But I will need some help for transfer everything to gitlab.

Do not hesitate to ping me if you want some help on that :-)

Cheers
Bertrand

Quoted 7 lines

Cheers,

[1] https://trello.com/invite/b/L54vXoqM/ATTI99c86a2718dec17b3b08f0de35fb3b5bC8729E45/xen

Signature · 1 line
Julien Grall
#16 lore raw
In reply to Michal Orzel
Quoted 94 lines · Michal Orzel

Hi Julien,

Quoted 89 lines · Julien Grall
Quoted 59 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 4 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

Quoted 6 lines
Quoted 2 lines

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

I'm not in favor of this approach either. That said, I will prepare patches to remove CONFIG_EARLY_UART_PL011_BAUD_RATE and its usage in early printk code as we agreed earlier. As for the LCR setting, I will keep it in early printk code to maintain the same behavior as runtime driver who sets them.

Actually, there is one more thing to consider.
early_uart_init, even though it also sets LCR apart from the baud rate, is called when CONFIG_EARLY_UART_INIT is set. The latter depends on EARLY_UART_PL011 && EARLY_UART_PL011_BAUD_RATE != 0.
If we remove EARLY_UART_PL011_BAUD_RATE, we need to decide when do we want early_uart_init to be called. It is defined only for pl011 (it is also defined for meson but this is an unreachable code, as EARLY_UART_PL011 is 0 for meson), so we have the following options:
1. Redefine CONFIG_EARLY_UART_INIT to be CONFIG_EARLY_UART_PL011_INIT and mark it as n by default
2. Keep CONFIG_EARLY_UART_INIT so that future drivers can use it (?) and mark it as n by default
2. Completely remove early_uart_init

Quoted 23 lines
Quoted 11 lines
Quoted 4 lines

[1] It is not stated anywhere in our docs.

Our docs are not perfect. Patches are welcomed for improvement. Although, I think the statement should only be for driver where we don't set the baud rate. For the others, we should leave it as is unless you can prove this is not necessary (we don't want to break existing setup).

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

[2] BTW: our docs/misc/arm/booting contains invalid links to the kernel docs. I guess this wants to be fixed.

Patches are welcomed.

[3] I do have a large list of more critical bugs that I will be happy to share if you are looking for improving Xen.

That is cool and such list would be great for everyone having some spare time (+ newcomers). Taking the opportunity of having a GitLab CI epics, I think it is worth adding such work items here:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.com%2Fgroups%2Fxen-project%2F-%2Fepics%3Fstate%3Dopened%26page%3D1%26sort%3Dstart_date_desc&amp;data=05%7C01%7Cmichal.orzel%40amd.com%7Ce2f65ddb895243bdb9cc08dac881acba%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C638042756535884326%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=5Hf%2BXW3nogjzasoTQ821OPAjJLJVVofyGpb0LNxRAto%3D&amp;reserved=0

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

--
Julien Grall

~Michal

~Michal

#17 lore raw
Quoted 103 lines · Michal Orzel
Quoted 94 lines · Michal Orzel

Hi Julien,

Quoted 89 lines · Julien Grall
Quoted 59 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 4 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

Quoted 6 lines
Quoted 2 lines

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

I'm not in favor of this approach either. That said, I will prepare patches to remove CONFIG_EARLY_UART_PL011_BAUD_RATE and its usage in early printk code as we agreed earlier. As for the LCR setting, I will keep it in early printk code to maintain the same behavior as runtime driver who sets them.

Quoted 5 lines

Actually, there is one more thing to consider.
early_uart_init, even though it also sets LCR apart from the baud rate, is called when CONFIG_EARLY_UART_INIT is set. The latter depends on EARLY_UART_PL011 && EARLY_UART_PL011_BAUD_RATE != 0.
If we remove EARLY_UART_PL011_BAUD_RATE, we need to decide when do we want early_uart_init to be called. It is defined only for pl011 (it is also defined for meson but this is an unreachable code, as EARLY_UART_PL011 is 0 for meson), so we have the following options:

Good spot. I am not sure why the function was defined for Meson if it does nothing. I would drop it but keep the comment explaining why we don't have the helper.

Quoted 1 line

2. Keep CONFIG_EARLY_UART_INIT so that future drivers can use it (?) and mark it as n by default

Based on the discussion with Bertrand, I would keep CONFIG_EARLY_UART_INIT in case someone wants to use a different UART for Xen and the firmware output.

Also, I would like to revise my opinion from earlier. I now think we should keep the baud rate part in early PL011 code even this means inconsistency between the early and runtime driver.

Cheers,

Signature · 1 line
Julien Grall
#18 lore raw

Hi Julien,

Quoted 112 lines · Julien Grall
Quoted 103 lines · Michal Orzel
Quoted 94 lines · Michal Orzel

Hi Julien,

Quoted 89 lines · Julien Grall
Quoted 59 lines · Michal Orzel

Hi Julien,

Quoted 56 lines · Julien Grall

Hi Michal,

Quoted 39 lines · Michal Orzel
Quoted 13 lines · Julien Grall
Quoted 1 line · Michal Orzel

Hi Julien,

Hi Michal,

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

and use it in the pl011-debug files (+ there is a question whether we should define WLEN_7-5 for completeness).

I would not define WLEN_7-5. That said, I wonder if we really need to set the baud rate & co here?

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

AFAICT the runtime driver never touch them. The reasoning is the firmware is responsible to configure the serial. Therefore, I would consider to drop the code (setting UARTCR might still be necessary).

I do not really agree because the current behavior was done on purpose.

EARLY_UART_PL011_BAUD_RATE is only used for very early debugging (this is protected by CONFIG_DEBUG and CONFIG_EXPERT). This is not a production ready code.

I am fully aware of it. I just found it useful but I understand the global reasoning.

Quoted 15 lines
Quoted 5 lines

At the moment early_uart_init is called only if EARLY_UART_PL011_BAUD_RATE is set to a value != 0. This is done in order to have flexibility to either stick to what firmware/bootloader configured or to change this configuration by specifying the EARLY_UART_PL011_BAUD_RATE (useful when you do not know what the firmware configured).

The chances are that you want to use the baud rate that was configured by the firmware. Otherwise, you would need to change the configuration of minicom (or whatever you used) to get proper output for the firmware and then Xen.

Furthermore, as I wrote before, the runtime driver doesn't configure the baud rate. This was removed in Xen 4.7 (see commit 2048e17ca9df "drivers/pl011: Don't configure baudrate") because it was buggy and this code is not simple.

Quoted 7 lines
Quoted 2 lines

So it makes no sense to configure the baud rate when using early printk but not the runtime driver.

Ok, so we will get rid of EARLY_UART_PL011_BAUD_RATE config and setting the bd in the early uart code. Now, what about setting "8n1"? The runtime driver sets them as well as the early code. It can also be set to a different value from the firmware (unlikely but it can happen I think). In any case, if we decide to do what the runtime driver does, I reckon setting LCR_H should be kept in early code.

Good question. I think, you would end up with the same issue I mentioned above if the firmware and Xen have different line control registers (tools like minicom/screen would ask for it).

Quoted 8 lines
Quoted 3 lines

So I am on the fence here. In one way, it seems pointless keep it. But on the other hand, Xen has always set it. So I have no data to prove this will be fine everywhere.

If we are relying on the firmware[1] to configure the baud rate, it is not very wise not to rely on it to configure the LCR. Looking at the other serial drivers in Xen, we have a real mismatch in what is being configured. Some of the drivers (omap, imx), apart from setting 8n1 also set the baud rate explicitly to 115200 and almost all of them do set 8n1. In that case we will not benefit too much from fixing just pl011.

It is not great that Xen hardcode the baud rate (I can't remember whether there was a reason), but I don't think the consistency is necessary here (see more below).

Quoted 4 lines

On the other hand, Xen follows the zImage/Image protocols for ARM [2] which do not state that serial port initializing is something mandatory. This could indicate that the firmware does not really need to configure the serial.

The firmware doesn't need to configure the serial and yes in theory Xen should configure the baud rate and parity based on the firmware table.

However, this is a trade off between complexity and benefits. The patch I mentioned earlier has been removed nearly 6 years ago and I haven't seen anyone reporting any issues.

Hence why I think for the PL011 it is not worth looking [3] at the baud rate and instead removing it completely in the early PL011 code as well.

Quoted 6 lines
Quoted 2 lines

That said, if you feel strongly adding support for baud rate then I will be happy to review the patch.

I'm not in favor of this approach either. That said, I will prepare patches to remove CONFIG_EARLY_UART_PL011_BAUD_RATE and its usage in early printk code as we agreed earlier. As for the LCR setting, I will keep it in early printk code to maintain the same behavior as runtime driver who sets them.

Quoted 5 lines

Actually, there is one more thing to consider.
early_uart_init, even though it also sets LCR apart from the baud rate, is called when CONFIG_EARLY_UART_INIT is set. The latter depends on EARLY_UART_PL011 && EARLY_UART_PL011_BAUD_RATE != 0.
If we remove EARLY_UART_PL011_BAUD_RATE, we need to decide when do we want early_uart_init to be called. It is defined only for pl011 (it is also defined for meson but this is an unreachable code, as EARLY_UART_PL011 is 0 for meson), so we have the following options:

Quoted 3 lines

Good spot. I am not sure why the function was defined for Meson if it does nothing. I would drop it but keep the comment explaining why we don't have the helper.

Hmm, other drivers do not have such a comment but I can leave it there if you want. Although, it should then be slightly modified to avoid ambiguity after removing macro:
/*
* No need for early_uart_init, as UART has already been initialized
* by Firmware, for instance by TF-A.
*/

Quoted 10 lines
Quoted 2 lines

2. Keep CONFIG_EARLY_UART_INIT so that future drivers can use it (?) and mark it as n by default

Based on the discussion with Bertrand, I would keep CONFIG_EARLY_UART_INIT in case someone wants to use a different UART for Xen and the firmware output.

Also, I would like to revise my opinion from earlier. I now think we should keep the baud rate part in early PL011 code even this means inconsistency between the early and runtime driver.

Ok, in this case I will just create a series containing this patch without any modifications, the meson fix + macro for 8n1 to be used in early code as agreed earlier.

Quoted 5 lines

Cheers,

--
Julien Grall

~Michal