ARM: tegra: Automatic UART selection for earlyprintk
Subsystems (3)
cover ARM: tegra: Automatic UART selection for earlyprintk
This series allows a Tegra zImage to automatically select the UART to use for the zImage decompressor and early printk, based on information from the bootloader. The code scans each UART, looking for one that is clocked, is out of reset, and that the bootloader has written 'D' (for 'D'ebug) to the scratch register.
At present, the ChromiumOS branch of U-Boot sets up UARTs in this way. If this patch is accepted into the kernel, I'll upstream the U-Boot change to mainline U-Boot.
This is important, since different boards use different UARTs, and it's nice not to have to configure the kernel differently when switching boards.
This patch series depends on patch "[PATCH V2] arm/tegra: Support Tegra30 in decompressor UART setup" for context.
Doug Anderson (2):
ARM: tegra: Introduce define DEBUG_UART_SHIFT
ARM: tegra: uncompress.h: Store UART address in a variable
Stephen Warren (2):
ARM: tegra: uncompress.h: Choose a UART at runtime
ARM: tegra: Pass uncompress.h UART selection to DEBUG_LL
arch/arm/mach-tegra/common.c | 17 ++++ arch/arm/mach-tegra/include/mach/debug-macro.S | 87 +++++++++++++++++--- arch/arm/mach-tegra/include/mach/uncompress.h | 108 +++++++++++++++++++++--- 3 files changed, 190 insertions(+), 22 deletions(-)
PATCH 1/4 ARM: tegra: Introduce define DEBUG_UART_SHIFT
From: Doug Anderson <[email protected]>
This removes the need for the variable "shift" in all functions in uncompress.h.
--- arch/arm/mach-tegra/include/mach/uncompress.h | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
arch/arm/mach-tegra/include/mach/uncompress.h +10 -8
@@ -2,10 +2,12 @@* arch/arm/mach-tegra/include/mach/uncompress.h * * Copyright (C) 2010 Google, Inc. +* Copyright (C) 2011 Google, Inc. * * Author: * Colin Cross <[email protected]> * Erik Gilling <[email protected]> +* Doug Anderson <[email protected]> * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and
@@ -26,17 +28,18 @@#include <mach/iomap.h> +#define DEBUG_UART_SHIFT 2 +static void putc (int c) {volatile u8 *uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; -int shift =2 ;if (uart ==NULL )return ; -while (!(uart[UART_LSR << shift] &UART_LSR_THRE )) +while (!(uart[UART_LSR <<DEBUG_UART_SHIFT ] &UART_LSR_THRE ))barrier (); - uart[UART_TX << shift] = c; + uart[UART_TX <<DEBUG_UART_SHIFT ] = c; }static inline void flush (void )
@@ -48,7 +51,6 @@ static inline void arch_decomp_setup(void)volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE ;u32 chip, div;volatile u8 *uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; -int shift =2 ;if (uart ==NULL )return ;
@@ -59,10 +61,10 @@ static inline void arch_decomp_setup(void)else div =0x00dd ; - uart[UART_LCR << shift] |=UART_LCR_DLAB ; - uart[UART_DLL << shift] = div &0xff ; - uart[UART_DLM << shift] = div >>8 ; - uart[UART_LCR << shift] =3 ; + uart[UART_LCR <<DEBUG_UART_SHIFT ] |=UART_LCR_DLAB ; + uart[UART_DLL <<DEBUG_UART_SHIFT ] = div &0xff ; + uart[UART_DLM <<DEBUG_UART_SHIFT ] = div >>8 ; + uart[UART_LCR <<DEBUG_UART_SHIFT ] =3 ; }static inline void arch_decomp_wdog (void )
Signature · 1 line
1.7.0.4
PATCH 2/4 ARM: tegra: uncompress.h: Store UART address in a variable
In reply to Stephen WarrenFrom: Doug Anderson <[email protected]>
This will allow a future change to auto-detect which UART to use.
--- arch/arm/mach-tegra/include/mach/uncompress.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/mach-tegra/include/mach/uncompress.h +3 -3
@@ -30,10 +30,10 @@#define DEBUG_UART_SHIFT 2 +volatile u8 *uart; +static void putc (int c) { -volatile u8 *uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; -if (uart ==NULL )return ;
@@ -50,8 +50,8 @@ static inline void arch_decomp_setup(void) {volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE ;u32 chip, div; -volatile u8 *uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; + uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ;if (uart ==NULL )return ;
Signature · 1 line
1.7.0.4
PATCH 3/4 ARM: tegra: uncompress.h: Choose a UART at runtime
In reply to Stephen WarrenWith this change we automatically detect which UART to use for for printing during decompression. The detection involves coordination with the bootloader: it's expected that the bootloader will leave a 'D' (for [D]ebug) in the UART scratchpad register for whichever UART we should use for debugging.
If we don't find any such UART, we fall back to the UART that was specified during config time: CONFIG_TEGRA_DEBUG_UART_XXX.
As a side effect of this change, uncompress debug messages will work if you've specified CONFIG_TEGRA_DEBUG_UART_NONE, provided the bootloader obeys the protocol.
This change is in line with what is documented inDocumentation/arm/Booting.
Other approaches considered:
* Hardcode based on machine ID (as many other ARM boards do). OK, but nice to not have yet another place to add per-board code. Better to have bootloader parse device tree and pass us this info.
* Check for TXE bit (like SA1110). Nice (and doesn't require a bootloader change), but a little less explicit. Also: if bootloader (for some reason) uses another UART, it needs to remember to turn it off before jumping to the kernel or we may print to it. NOTE: adapting this patch to check TXE too would be easy if desired.
--- arch/arm/mach-tegra/include/mach/uncompress.h | 74 ++++++++++++++++++++++++- 1 files changed, 73 insertions(+), 1 deletions(-)
arch/arm/mach-tegra/include/mach/uncompress.h +73 -1
@@ -3,11 +3,13 @@* * Copyright (C) 2010 Google, Inc. * Copyright (C) 2011 Google, Inc. +* Copyright (C) 2011 NVIDIA CORPORATION. All Rights Reserved. * * Author: * Colin Cross <[email protected]> * Erik Gilling <[email protected]> * Doug Anderson <[email protected]> +* Stephen Warren <[email protected]> * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and
@@ -46,12 +48,82 @@ static inline void flush(void) { } +/* +* Setup before decompression. This is where we do UART selection for +* earlyprintk and init the uart_base register. +*/ static inline void arch_decomp_setup (void ) { +static const struct { +u32 base; +u32 reset_reg; +u32 clock_reg; +u32 bit; + } uarts[] = { + { +TEGRA_UARTA_BASE , +TEGRA_CLK_RESET_BASE +0x04 , +TEGRA_CLK_RESET_BASE +0x10 , +6 , + }, + { +TEGRA_UARTB_BASE , +TEGRA_CLK_RESET_BASE +0x04 , +TEGRA_CLK_RESET_BASE +0x10 , +7 , + }, + { +TEGRA_UARTC_BASE , +TEGRA_CLK_RESET_BASE +0x08 , +TEGRA_CLK_RESET_BASE +0x14 , +23 , + }, + { +TEGRA_UARTD_BASE , +TEGRA_CLK_RESET_BASE +0x0c , +TEGRA_CLK_RESET_BASE +0x18 , +1 , + }, + { +TEGRA_UARTE_BASE , +TEGRA_CLK_RESET_BASE +0x0c , +TEGRA_CLK_RESET_BASE +0x18 , +2 , + }, + }; +int i;volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE ;u32 chip, div; - uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; +/* +* Look for the first UART that: +* a) Is not in reset. +* b) Is clocked. +* c) Has a 'D' in the scratchpad register. +* +* Note that on Tegra30, the first two conditions are required, since +* if not true, accesses to the UART scratch register will hang. +* Tegra20 doesn't have this issue. +* +* The intent is that the bootloader will tell the kernel which UART +* to use by setting up those conditions. If nothing found, we'll fall +* back to what's specified in TEGRA_DEBUG_UART_BASE. +*/ +for (i =0 ; i <ARRAY_SIZE (uarts); i++) { +if (*(u8 *)uarts[i].reset_reg &BIT (uarts[i].bit)) +continue ; + +if (!(*(u8 *)uarts[i].clock_reg &BIT (uarts[i].bit))) +continue ; + + uart = (volatile u8 *)uarts[i].base; +if (uart[UART_SCR <<DEBUG_UART_SHIFT ] !='D' ) +continue ; + +break ; + } +if (i ==ARRAY_SIZE (uarts)) + uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ;if (uart ==NULL )return ;
Signature · 1 line
1.7.0.4
PATCH 4/4 ARM: tegra: Pass uncompress.h UART selection to DEBUG_LL
In reply to Stephen Warrenuncompress.h now saves the selected UART's physical address in Tegra's IRAM, along with a cookie to indicate validity.
The first time it's run, macro addruart in debug-macro.S looks for this cookie, and if it's present, uses the UART address stored there. If not, the static value TEGRA_DEBUG_UART_BASE is used, as was previous behaviour. The static behaviour will thus be used when not booting using a zImage.
This work was inspired by work by Doug Anderson <[email protected]>; see http://lkml.org/lkml/2011/9/26/284. However, this patch relies on the data passing describe above, rather than duplicating the UART selection logic in debug-macro.S; the latest selection logic is more complex due to the need to check reset/clock bits too.
--- arch/arm/mach-tegra/common.c | 17 +++++ arch/arm/mach-tegra/include/mach/debug-macro.S | 87 +++++++++++++++++++++--- arch/arm/mach-tegra/include/mach/uncompress.h | 12 +++ 3 files changed, 105 insertions(+), 11 deletions(-)
arch/arm/mach-tegra/common.c +17 -0
@@ -33,6 +33,23 @@#include "clock.h" #include "fuse.h" +/* +* Storage for debug-macro.S's state. +* +* This must be in .data not .bss so that it gets initialized each time the +* kernel is loaded. The data is declared here rather than debug-macro.S so +* that multiple inclusions of debug-macro.S point at the same data. +*/ +#define TEGRA_DEBUG_UART_OFFSET (TEGRA_DEBUG_UART_BASE & 0xFFFF) +u32 tegra_uart_config[3 ] = { +/* Debug UART initialization required */ +1 , +/* Debug UART physical address */ + (u32)(IO_APB_PHYS +TEGRA_DEBUG_UART_OFFSET ), +/* Debug UART virtual address */ + (u32)(IO_APB_VIRT +TEGRA_DEBUG_UART_OFFSET ), +}; +#ifdef CONFIG_OF static const struct of_device_id tegra_dt_irq_match[]__initconst = { { .compatible = "arm,cortex-a9-gic", .data = gic_of_init },
arch/arm/mach-tegra/include/mach/debug-macro.S +76 -11
105 lines not on this page · raw message
arch/arm/mach-tegra/include/mach/uncompress.h +12 -0
@@ -48,6 +48,17 @@ static inline void flush(void) { } +static inline void save_uart_address (void ) +{ +u32 *iram = (u32 *)(TEGRA_IRAM_BASE +0x100 ); + +if (uart) { + iram[0 ] =0x55415254 ;/* "UART" */ + iram[1 ] = (u32 )uart; + }else + iram[0 ] =0 ; +} +/* * Setup before decompression. This is where we do UART selection for * earlyprintk and init the uart_base register.
@@ -124,6 +135,7 @@ static inline void arch_decomp_setup(void) }if (i ==ARRAY_SIZE (uarts)) uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; +save_uart_address ();if (uart ==NULL )return ;
Signature · 1 line
1.7.0.4
cover ARM: tegra: Automatic UART selection for earlyprintk
In reply to Stephen WarrenFor the series,
Thank you for picking this up.
A few overall comments on the patch set:1. This patch has the side effect of requiring the use of zImage to?? ?get the proper behavior. If we ever try to move decompression? ?of the kernel to the bootloader (as has been talked about, since? ?u-boot supports it) we'll lose earlyprintk behavior. ?...of course,?? ?this does match how some other ARM boards do things. ?I'm OK with? ?this.2. I'm slightly concerned about cramming stuff into IRAM, since? ?I don't have a good concept of what IRAM adresses are used when.? ?When I grep for IRAM users in our kernel, I see?? ?TEGRA_AVP_RESUME_ADDR is using the base of IRAM. We're not going? ?to be hosing suspend/resume or anything else with this CL, are we?? ?In the very least, I'd perfer to see a #define for the '0x100' and?? ?the '0x55415254' so that we can correlate the constants in?? ?uncompress.h and debug-macro.S Tested:Tested the series on a Tegra2-based board (Kaen) withCONFIG_TEGRA_DEBUG_UART_NONE defined on the current ToT chromium-os?tree with the following pre-changes:1. Reverted hack from our tree: 63b76a4638f3934e69c8724881060f121845184c2. Added "arm/tegra:
Support Tegra30 in decompressor UART setup" as? ?described in the patch header.3. Adjusted patch 4 to apply cleanly to our older "common.c"4. Added missing #include <linux/kernel.h> to uncompress.h, as?? ?indicated by swarren on tegra IRC.
Also tried stopping in the bootloader and clearing the 'D' with:? mw.b 0x7000605c 0...and validated that I missed the earlyprintks (as expected) butstill booted.
---
Quoted 30 lines · Stephen Warren
This series allows a Tegra zImage to automatically select the UART to use for the zImage decompressor and early printk, based on information from the bootloader. The code scans each UART, looking for one that is clocked, is out of reset, and that the bootloader has written 'D' (for 'D'ebug) to the scratch register.
At present, the ChromiumOS branch of U-Boot sets up UARTs in this way. If this patch is accepted into the kernel, I'll upstream the U-Boot change to mainline U-Boot.
This is important, since different boards use different UARTs, and it's nice not to have to configure the kernel differently when switching boards.
This patch series depends on patch "[PATCH V2] arm/tegra: Support Tegra30 in decompressor UART setup" for context.
Doug Anderson (2):
?ARM: tegra: Introduce defineDEBUG_UART_SHIFT?ARM: tegra:uncompress.h: Store UART address in a variableStephen Warren (2):
?ARM: tegra:uncompress.h: Choose a UART at runtime ?ARM: tegra: Passuncompress.hUART selection toDEBUG_LL?arch/arm/mach-tegra/common.c ? ? ? ? ? ? ? ? ? | ? 17 ++++ ?arch/arm/mach-tegra/include/mach/debug-macro.S | ? 87 +++++++++++++++++--- ?arch/arm/mach-tegra/include/mach/uncompress.h ?| ?108 +++++++++++++++++++++---?3 files changed, 190 insertions(+), 22 deletions(-)
cover ARM: tegra: Automatic UART selection for earlyprintk
(repost, since gmail seems to have mangled my message)
For the series,
Thank you for picking this up.
A few overall comments on the patch set:
1. This patch has the side effect of requiring the use of zImage to ? ?get the proper behavior. ?If we ever try to move decompression ? ?of the kernel to the bootloader (as has been talked about, since ? ?u-boot supports it) we'll lose earlyprintk behavior. ?...of course, ? ?this does match how some other ARM boards do things. ?I'm OK with ? ?this.
2. I'm slightly concerned about cramming stuff into IRAM, since ? ?I don't have a good concept of what IRAM adresses are used when. ? ?When I grep for IRAM users in our kernel, I see
? ?TEGRA_AVP_RESUME_ADDR is using the base of IRAM. ?We're not going ? ?to be hosing suspend/resume or anything else with this CL, are we? ? ?In the very least, I'd perfer to see a #define for the '0x100' and ? ?the '0x55415254' so that we can correlate the constants in ? ?uncompress.h and debug-macro.S
Tested:
Tested the series on a Tegra2-based board (Kaen) with CONFIG_TEGRA_DEBUG_UART_NONE defined on the current ToT chromium-os tree with the following pre-changes:
1. Reverted hack from our tree: 63b76a4638f3934e69c8724881060f121845184c
2. Added "arm/tegra: Support Tegra30 in decompressor UART setup" as ? ?described in the patch header.
3. Adjusted patch 4 to apply cleanly to our older "common.c"
4. Added missing #include <linux/kernel.h> to uncompress.h, as ? ?indicated by swarren on tegra IRC.
Also tried stopping in the bootloader and clearing the 'D' with:
? mw.b 0x7000605c 0
...and validated that I missed the earlyprintks (as expected) but still booted.
---
Quoted 59 lines · Doug Anderson
For the series,
Tested-by Doug Anderson <[email protected]>Thank you for picking this up.
A few overall comments on the patch set:1. This patch has the side effect of requiring the use of zImage to?? ?get the proper behavior. If we ever try to move decompression? ?of the kernel to the bootloader (as has been talked about, since? ?u-boot supports it) we'll lose earlyprintk behavior. ?...of course,?? ?this does match how some other ARM boards do things. ?I'm OK with? ?this.2. I'm slightly concerned about cramming stuff into IRAM, since? ?I don't have a good concept of what IRAM adresses are used when.? ?When I grep for IRAM users in our kernel, I see?? ?TEGRA_AVP_RESUME_ADDR is using the base of IRAM. We're not going? ?to be hosing suspend/resume or anything else with this CL, are we?? ?In the very least, I'd perfer to see a #define for the '0x100' and?? ?the '0x55415254' so that we can correlate the constants in?? ?uncompress.h anddebug-macro.STested:Tested the series on a Tegra2-based board (Kaen)withCONFIG_TEGRA_DEBUG_UART_NONEdefined on the current ToT chromium-os?tree with the following pre-changes:1. Reverted hack from our tree:63b76a4638f3934e69c8724881060f121845184c2. Added "arm/tegra:
Support Tegra30 in decompressor UART setup" as? ?described in the patch header.3. Adjusted patch 4 to apply cleanly to our older "common.c"4. Added missing #include <linux/kernel.h> touncompress.h, as?? ?indicated by swarren on tegra IRC.
Also tried stopping in the bootloader and clearing the 'D' with:? mw.b0x7000605c0...and validated that I missed the earlyprintks (as expected) butstill booted.
---Quoted 30 lines · Stephen Warren
This series allows a Tegra zImage to automatically select the UART to use for the zImage decompressor and early printk, based on information from the bootloader. The code scans each UART, looking for one that is clocked, is out of reset, and that the bootloader has written 'D' (for 'D'ebug) to the scratch register.
At present, the ChromiumOS branch of U-Boot sets up UARTs in this way. If this patch is accepted into the kernel, I'll upstream the U-Boot change to mainline U-Boot.
This is important, since different boards use different UARTs, and it's nice not to have to configure the kernel differently when switching boards.
This patch series depends on patch "[PATCH V2] arm/tegra: Support Tegra30 in decompressor UART setup" for context.
Doug Anderson (2):
?ARM: tegra: Introduce defineDEBUG_UART_SHIFT?ARM: tegra:uncompress.h: Store UART address in a variableStephen Warren (2):
?ARM: tegra:uncompress.h: Choose a UART at runtime ?ARM: tegra: Passuncompress.hUART selection toDEBUG_LL?arch/arm/mach-tegra/common.c ? ? ? ? ? ? ? ? ? | ? 17 ++++ ?arch/arm/mach-tegra/include/mach/debug-macro.S | ? 87 +++++++++++++++++--- ?arch/arm/mach-tegra/include/mach/uncompress.h ?| ?108 +++++++++++++++++++++---?3 files changed, 190 insertions(+), 22 deletions(-)
cover ARM: tegra: Automatic UART selection for earlyprintk
Doug Anderson wrote at Wednesday, January 04, 2012 4:48 PM:
...
Quoted 8 lines
2. I'm slightly concerned about cramming stuff into IRAM, since ? ?I don't have a good concept of what IRAM adresses are used when. ? ?When I grep for IRAM users in our kernel, I see
? ?TEGRA_AVP_RESUME_ADDR is using the base of IRAM. ?We're not going ? ?to be hosing suspend/resume or anything else with this CL, are we? ? ?In the very least, I'd perfer to see a #define for the '0x100' and ? ?the '0x55415254' so that we can correlate the constants in ? ?uncompress.h anddebug-macro.S
I discussed this with a few people, and it sounds like it's safe to use IRAM for this. However, I did discover a few other uses of IRAM too, in our downstream kernels anyway, so I'll certainly create arch/arm/mach- tegra/include/mach/irammap.h that provides defines for all the IRAM offsets, what they're used for, and when.
Signature · 1 line
nvpublic
Olof Johansson
Appliedcover ARM: tegra: Automatic UART selection for earlyprintk
In reply to Stephen WarrenQuoted 17 lines · Stephen Warren
This series allows a Tegra zImage to automatically select the UART to use for the zImage decompressor and early printk, based on information from the bootloader. The code scans each UART, looking for one that is clocked, is out of reset, and that the bootloader has written 'D' (for 'D'ebug) to the scratch register.
At present, the ChromiumOS branch of U-Boot sets up UARTs in this way. If this patch is accepted into the kernel, I'll upstream the U-Boot change to mainline U-Boot.
This is important, since different boards use different UARTs, and it's nice not to have to configure the kernel differently when switching boards.
This patch series depends on patch "[PATCH V2] arm/tegra: Support Tegra30 in decompressor UART setup" for context.
Quoted 7 lines
Doug Anderson (2):
ARM: tegra: Introduce defineDEBUG_UART_SHIFT
ARM: tegra:uncompress.h: Store UART address in a variableStephen Warren (2):
ARM: tegra:uncompress.h: Choose a UART at runtime
ARM: tegra: Passuncompress.hUART selection toDEBUG_LL
Thanks, applied.
-Olof