* [PATCH v2 1/2] powerpc/64: Fix the definition of the fixmap area
@ 2021-04-20 13:32 ` Christophe Leroy
0 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2021-04-20 13:32 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, chris.packham
Cc: linux-kernel, linuxppc-dev
At the time being, the fixmap area is defined at the top of
the address space or just below KASAN.
This definition is not valid for PPC64.
For PPC64, use the top of the I/O space.
Because of circular dependencies, it is not possible to include
asm/fixmap.h in asm/book3s/64/pgtable.h , so define a fixed size
AREA at the top of the I/O space for fixmap and ensure during
build that the size is big enough.
Fixes: 265c3491c4bc ("powerpc: Add support for GENERIC_EARLY_IOREMAP")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/include/asm/book3s/64/pgtable.h | 4 +++-
arch/powerpc/include/asm/fixmap.h | 9 +++++++++
arch/powerpc/include/asm/nohash/64/pgtable.h | 5 ++++-
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 0c89977ec10b..a666d561b44d 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -7,6 +7,7 @@
#ifndef __ASSEMBLY__
#include <linux/mmdebug.h>
#include <linux/bug.h>
+#include <linux/sizes.h>
#endif
/*
@@ -324,7 +325,8 @@ extern unsigned long pci_io_base;
#define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE)
#define IOREMAP_BASE (PHB_IO_END)
#define IOREMAP_START (ioremap_bot)
-#define IOREMAP_END (KERN_IO_END)
+#define IOREMAP_END (KERN_IO_END - FIXADDR_SIZE)
+#define FIXADDR_SIZE SZ_32M
/* Advertise special mapping type for AGP */
#define HAVE_PAGE_AGP
diff --git a/arch/powerpc/include/asm/fixmap.h b/arch/powerpc/include/asm/fixmap.h
index 8d03c16a3663..947b5b9c4424 100644
--- a/arch/powerpc/include/asm/fixmap.h
+++ b/arch/powerpc/include/asm/fixmap.h
@@ -23,12 +23,17 @@
#include <asm/kmap_size.h>
#endif
+#ifdef CONFIG_PPC64
+#define FIXADDR_TOP (IOREMAP_END + FIXADDR_SIZE)
+#else
+#define FIXADDR_SIZE 0
#ifdef CONFIG_KASAN
#include <asm/kasan.h>
#define FIXADDR_TOP (KASAN_SHADOW_START - PAGE_SIZE)
#else
#define FIXADDR_TOP ((unsigned long)(-PAGE_SIZE))
#endif
+#endif
/*
* Here we define all the compile-time 'special' virtual
@@ -50,6 +55,7 @@
*/
enum fixed_addresses {
FIX_HOLE,
+#ifdef CONFIG_PPC32
/* reserve the top 128K for early debugging purposes */
FIX_EARLY_DEBUG_TOP = FIX_HOLE,
FIX_EARLY_DEBUG_BASE = FIX_EARLY_DEBUG_TOP+(ALIGN(SZ_128K, PAGE_SIZE)/PAGE_SIZE)-1,
@@ -72,6 +78,7 @@ enum fixed_addresses {
FIX_IMMR_SIZE,
#endif
/* FIX_PCIE_MCFG, */
+#endif /* CONFIG_PPC32 */
__end_of_permanent_fixed_addresses,
#define NR_FIX_BTMAPS (SZ_256K / PAGE_SIZE)
@@ -98,6 +105,8 @@ enum fixed_addresses {
static inline void __set_fixmap(enum fixed_addresses idx,
phys_addr_t phys, pgprot_t flags)
{
+ BUILD_BUG_ON(IS_ENABLED(CONFIG_PPC64) && __FIXADDR_SIZE > FIXADDR_SIZE);
+
if (__builtin_constant_p(idx))
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
else if (WARN_ON(idx >= __end_of_fixed_addresses))
diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h b/arch/powerpc/include/asm/nohash/64/pgtable.h
index 6cb8aa357191..57cd3892bfe0 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -6,6 +6,8 @@
* the ppc64 non-hashed page table.
*/
+#include <linux/sizes.h>
+
#include <asm/nohash/64/pgtable-4k.h>
#include <asm/barrier.h>
#include <asm/asm-const.h>
@@ -54,7 +56,8 @@
#define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE)
#define IOREMAP_BASE (PHB_IO_END)
#define IOREMAP_START (ioremap_bot)
-#define IOREMAP_END (KERN_VIRT_START + KERN_VIRT_SIZE)
+#define IOREMAP_END (KERN_VIRT_START + KERN_VIRT_SIZE - FIXADDR_SIZE)
+#define FIXADDR_SIZE SZ_32M
/*
--
2.25.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 1/2] powerpc/64: Fix the definition of the fixmap area
@ 2021-04-20 13:32 ` Christophe Leroy
0 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2021-04-20 13:32 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, chris.packham
Cc: linuxppc-dev, linux-kernel
At the time being, the fixmap area is defined at the top of
the address space or just below KASAN.
This definition is not valid for PPC64.
For PPC64, use the top of the I/O space.
Because of circular dependencies, it is not possible to include
asm/fixmap.h in asm/book3s/64/pgtable.h , so define a fixed size
AREA at the top of the I/O space for fixmap and ensure during
build that the size is big enough.
Fixes: 265c3491c4bc ("powerpc: Add support for GENERIC_EARLY_IOREMAP")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/include/asm/book3s/64/pgtable.h | 4 +++-
arch/powerpc/include/asm/fixmap.h | 9 +++++++++
arch/powerpc/include/asm/nohash/64/pgtable.h | 5 ++++-
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index 0c89977ec10b..a666d561b44d 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -7,6 +7,7 @@
#ifndef __ASSEMBLY__
#include <linux/mmdebug.h>
#include <linux/bug.h>
+#include <linux/sizes.h>
#endif
/*
@@ -324,7 +325,8 @@ extern unsigned long pci_io_base;
#define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE)
#define IOREMAP_BASE (PHB_IO_END)
#define IOREMAP_START (ioremap_bot)
-#define IOREMAP_END (KERN_IO_END)
+#define IOREMAP_END (KERN_IO_END - FIXADDR_SIZE)
+#define FIXADDR_SIZE SZ_32M
/* Advertise special mapping type for AGP */
#define HAVE_PAGE_AGP
diff --git a/arch/powerpc/include/asm/fixmap.h b/arch/powerpc/include/asm/fixmap.h
index 8d03c16a3663..947b5b9c4424 100644
--- a/arch/powerpc/include/asm/fixmap.h
+++ b/arch/powerpc/include/asm/fixmap.h
@@ -23,12 +23,17 @@
#include <asm/kmap_size.h>
#endif
+#ifdef CONFIG_PPC64
+#define FIXADDR_TOP (IOREMAP_END + FIXADDR_SIZE)
+#else
+#define FIXADDR_SIZE 0
#ifdef CONFIG_KASAN
#include <asm/kasan.h>
#define FIXADDR_TOP (KASAN_SHADOW_START - PAGE_SIZE)
#else
#define FIXADDR_TOP ((unsigned long)(-PAGE_SIZE))
#endif
+#endif
/*
* Here we define all the compile-time 'special' virtual
@@ -50,6 +55,7 @@
*/
enum fixed_addresses {
FIX_HOLE,
+#ifdef CONFIG_PPC32
/* reserve the top 128K for early debugging purposes */
FIX_EARLY_DEBUG_TOP = FIX_HOLE,
FIX_EARLY_DEBUG_BASE = FIX_EARLY_DEBUG_TOP+(ALIGN(SZ_128K, PAGE_SIZE)/PAGE_SIZE)-1,
@@ -72,6 +78,7 @@ enum fixed_addresses {
FIX_IMMR_SIZE,
#endif
/* FIX_PCIE_MCFG, */
+#endif /* CONFIG_PPC32 */
__end_of_permanent_fixed_addresses,
#define NR_FIX_BTMAPS (SZ_256K / PAGE_SIZE)
@@ -98,6 +105,8 @@ enum fixed_addresses {
static inline void __set_fixmap(enum fixed_addresses idx,
phys_addr_t phys, pgprot_t flags)
{
+ BUILD_BUG_ON(IS_ENABLED(CONFIG_PPC64) && __FIXADDR_SIZE > FIXADDR_SIZE);
+
if (__builtin_constant_p(idx))
BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
else if (WARN_ON(idx >= __end_of_fixed_addresses))
diff --git a/arch/powerpc/include/asm/nohash/64/pgtable.h b/arch/powerpc/include/asm/nohash/64/pgtable.h
index 6cb8aa357191..57cd3892bfe0 100644
--- a/arch/powerpc/include/asm/nohash/64/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/64/pgtable.h
@@ -6,6 +6,8 @@
* the ppc64 non-hashed page table.
*/
+#include <linux/sizes.h>
+
#include <asm/nohash/64/pgtable-4k.h>
#include <asm/barrier.h>
#include <asm/asm-const.h>
@@ -54,7 +56,8 @@
#define PHB_IO_END (KERN_IO_START + FULL_IO_SIZE)
#define IOREMAP_BASE (PHB_IO_END)
#define IOREMAP_START (ioremap_bot)
-#define IOREMAP_END (KERN_VIRT_START + KERN_VIRT_SIZE)
+#define IOREMAP_END (KERN_VIRT_START + KERN_VIRT_SIZE - FIXADDR_SIZE)
+#define FIXADDR_SIZE SZ_32M
/*
--
2.25.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 2/2] powerpc/legacy_serial: Use early_ioremap()
2021-04-20 13:32 ` Christophe Leroy
@ 2021-04-20 13:32 ` Christophe Leroy
-1 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2021-04-20 13:32 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, chris.packham
Cc: linux-kernel, linuxppc-dev
From: Christophe Leroy <christophe.leroy@c-s.fr>
[ 0.000000] ioremap() called early from find_legacy_serial_ports+0x3cc/0x474. Use early_ioremap() instead
find_legacy_serial_ports() is called early from setup_arch(), before
paging_init(). vmalloc is not available yet, ioremap shouldn't be
used that early.
Use early_ioremap() and switch to a regular ioremap() later.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/kernel/legacy_serial.c | 33 +++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index f061e06e9f51..8b2c1a8553a0 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -15,6 +15,7 @@
#include <asm/udbg.h>
#include <asm/pci-bridge.h>
#include <asm/ppc-pci.h>
+#include <asm/early_ioremap.h>
#undef DEBUG
@@ -34,6 +35,7 @@ static struct legacy_serial_info {
unsigned int clock;
int irq_check_parent;
phys_addr_t taddr;
+ void __iomem *early_addr;
} legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
static const struct of_device_id legacy_serial_parents[] __initconst = {
@@ -325,17 +327,16 @@ static void __init setup_legacy_serial_console(int console)
{
struct legacy_serial_info *info = &legacy_serial_infos[console];
struct plat_serial8250_port *port = &legacy_serial_ports[console];
- void __iomem *addr;
unsigned int stride;
stride = 1 << port->regshift;
/* Check if a translated MMIO address has been found */
if (info->taddr) {
- addr = ioremap(info->taddr, 0x1000);
- if (addr == NULL)
+ info->early_addr = early_ioremap(info->taddr, 0x1000);
+ if (info->early_addr == NULL)
return;
- udbg_uart_init_mmio(addr, stride);
+ udbg_uart_init_mmio(info->early_addr, stride);
} else {
/* Check if it's PIO and we support untranslated PIO */
if (port->iotype == UPIO_PORT && isa_io_special)
@@ -353,6 +354,30 @@ static void __init setup_legacy_serial_console(int console)
udbg_uart_setup(info->speed, info->clock);
}
+static int __init ioremap_legacy_serial_console(void)
+{
+ struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
+ struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];
+ void __iomem *vaddr;
+
+ if (legacy_serial_console < 0)
+ return 0;
+
+ if (!info->early_addr)
+ return 0;
+
+ vaddr = ioremap(info->taddr, 0x1000);
+ if (WARN_ON(!vaddr))
+ return -ENOMEM;
+
+ udbg_uart_init_mmio(vaddr, 1 << port->regshift);
+ early_iounmap(info->early_addr, 0x1000);
+ info->early_addr = NULL;
+
+ return 0;
+}
+early_initcall(ioremap_legacy_serial_console);
+
/*
* This is called very early, as part of setup_system() or eventually
* setup_arch(), basically before anything else in this file. This function
--
2.25.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 2/2] powerpc/legacy_serial: Use early_ioremap()
@ 2021-04-20 13:32 ` Christophe Leroy
0 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2021-04-20 13:32 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, chris.packham
Cc: linuxppc-dev, linux-kernel
From: Christophe Leroy <christophe.leroy@c-s.fr>
[ 0.000000] ioremap() called early from find_legacy_serial_ports+0x3cc/0x474. Use early_ioremap() instead
find_legacy_serial_ports() is called early from setup_arch(), before
paging_init(). vmalloc is not available yet, ioremap shouldn't be
used that early.
Use early_ioremap() and switch to a regular ioremap() later.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/kernel/legacy_serial.c | 33 +++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index f061e06e9f51..8b2c1a8553a0 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -15,6 +15,7 @@
#include <asm/udbg.h>
#include <asm/pci-bridge.h>
#include <asm/ppc-pci.h>
+#include <asm/early_ioremap.h>
#undef DEBUG
@@ -34,6 +35,7 @@ static struct legacy_serial_info {
unsigned int clock;
int irq_check_parent;
phys_addr_t taddr;
+ void __iomem *early_addr;
} legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
static const struct of_device_id legacy_serial_parents[] __initconst = {
@@ -325,17 +327,16 @@ static void __init setup_legacy_serial_console(int console)
{
struct legacy_serial_info *info = &legacy_serial_infos[console];
struct plat_serial8250_port *port = &legacy_serial_ports[console];
- void __iomem *addr;
unsigned int stride;
stride = 1 << port->regshift;
/* Check if a translated MMIO address has been found */
if (info->taddr) {
- addr = ioremap(info->taddr, 0x1000);
- if (addr == NULL)
+ info->early_addr = early_ioremap(info->taddr, 0x1000);
+ if (info->early_addr == NULL)
return;
- udbg_uart_init_mmio(addr, stride);
+ udbg_uart_init_mmio(info->early_addr, stride);
} else {
/* Check if it's PIO and we support untranslated PIO */
if (port->iotype == UPIO_PORT && isa_io_special)
@@ -353,6 +354,30 @@ static void __init setup_legacy_serial_console(int console)
udbg_uart_setup(info->speed, info->clock);
}
+static int __init ioremap_legacy_serial_console(void)
+{
+ struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
+ struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];
+ void __iomem *vaddr;
+
+ if (legacy_serial_console < 0)
+ return 0;
+
+ if (!info->early_addr)
+ return 0;
+
+ vaddr = ioremap(info->taddr, 0x1000);
+ if (WARN_ON(!vaddr))
+ return -ENOMEM;
+
+ udbg_uart_init_mmio(vaddr, 1 << port->regshift);
+ early_iounmap(info->early_addr, 0x1000);
+ info->early_addr = NULL;
+
+ return 0;
+}
+early_initcall(ioremap_legacy_serial_console);
+
/*
* This is called very early, as part of setup_system() or eventually
* setup_arch(), basically before anything else in this file. This function
--
2.25.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/2] powerpc/legacy_serial: Use early_ioremap()
2021-04-20 13:32 ` Christophe Leroy
(?)
@ 2021-04-20 13:39 ` Christophe Leroy
-1 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2021-04-20 13:39 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, chris.packham
Cc: linuxppc-dev, linux-kernel
Le 20/04/2021 à 15:32, Christophe Leroy a écrit :
> From: Christophe Leroy <christophe.leroy@c-s.fr>
Oops, I forgot to reset the Author. Michael if you apply this patch please update the author and
remove the old Signed-off-by
Thanks
>
> [ 0.000000] ioremap() called early from find_legacy_serial_ports+0x3cc/0x474. Use early_ioremap() instead
>
> find_legacy_serial_ports() is called early from setup_arch(), before
> paging_init(). vmalloc is not available yet, ioremap shouldn't be
> used that early.
>
> Use early_ioremap() and switch to a regular ioremap() later.
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> arch/powerpc/kernel/legacy_serial.c | 33 +++++++++++++++++++++++++----
> 1 file changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
> index f061e06e9f51..8b2c1a8553a0 100644
> --- a/arch/powerpc/kernel/legacy_serial.c
> +++ b/arch/powerpc/kernel/legacy_serial.c
> @@ -15,6 +15,7 @@
> #include <asm/udbg.h>
> #include <asm/pci-bridge.h>
> #include <asm/ppc-pci.h>
> +#include <asm/early_ioremap.h>
>
> #undef DEBUG
>
> @@ -34,6 +35,7 @@ static struct legacy_serial_info {
> unsigned int clock;
> int irq_check_parent;
> phys_addr_t taddr;
> + void __iomem *early_addr;
> } legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
>
> static const struct of_device_id legacy_serial_parents[] __initconst = {
> @@ -325,17 +327,16 @@ static void __init setup_legacy_serial_console(int console)
> {
> struct legacy_serial_info *info = &legacy_serial_infos[console];
> struct plat_serial8250_port *port = &legacy_serial_ports[console];
> - void __iomem *addr;
> unsigned int stride;
>
> stride = 1 << port->regshift;
>
> /* Check if a translated MMIO address has been found */
> if (info->taddr) {
> - addr = ioremap(info->taddr, 0x1000);
> - if (addr == NULL)
> + info->early_addr = early_ioremap(info->taddr, 0x1000);
> + if (info->early_addr == NULL)
> return;
> - udbg_uart_init_mmio(addr, stride);
> + udbg_uart_init_mmio(info->early_addr, stride);
> } else {
> /* Check if it's PIO and we support untranslated PIO */
> if (port->iotype == UPIO_PORT && isa_io_special)
> @@ -353,6 +354,30 @@ static void __init setup_legacy_serial_console(int console)
> udbg_uart_setup(info->speed, info->clock);
> }
>
> +static int __init ioremap_legacy_serial_console(void)
> +{
> + struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
> + struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];
> + void __iomem *vaddr;
> +
> + if (legacy_serial_console < 0)
> + return 0;
> +
> + if (!info->early_addr)
> + return 0;
> +
> + vaddr = ioremap(info->taddr, 0x1000);
> + if (WARN_ON(!vaddr))
> + return -ENOMEM;
> +
> + udbg_uart_init_mmio(vaddr, 1 << port->regshift);
> + early_iounmap(info->early_addr, 0x1000);
> + info->early_addr = NULL;
> +
> + return 0;
> +}
> +early_initcall(ioremap_legacy_serial_console);
> +
> /*
> * This is called very early, as part of setup_system() or eventually
> * setup_arch(), basically before anything else in this file. This function
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/2] powerpc/legacy_serial: Use early_ioremap()
2021-04-20 13:32 ` Christophe Leroy
@ 2021-04-20 21:15 ` Chris Packham
-1 siblings, 0 replies; 11+ messages in thread
From: Chris Packham @ 2021-04-20 21:15 UTC (permalink / raw)
To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman
Cc: linux-kernel, linuxppc-dev
Hi Christophe,
On 21/04/21 1:32 am, Christophe Leroy wrote:
> From: Christophe Leroy <christophe.leroy@c-s.fr>
>
> [ 0.000000] ioremap() called early from find_legacy_serial_ports+0x3cc/0x474. Use early_ioremap() instead
>
> find_legacy_serial_ports() is called early from setup_arch(), before
> paging_init(). vmalloc is not available yet, ioremap shouldn't be
> used that early.
>
> Use early_ioremap() and switch to a regular ioremap() later.
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
I gave it a spin on my T2080RDB. The error message is gone and I still
get console output.
Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> arch/powerpc/kernel/legacy_serial.c | 33 +++++++++++++++++++++++++----
> 1 file changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
> index f061e06e9f51..8b2c1a8553a0 100644
> --- a/arch/powerpc/kernel/legacy_serial.c
> +++ b/arch/powerpc/kernel/legacy_serial.c
> @@ -15,6 +15,7 @@
> #include <asm/udbg.h>
> #include <asm/pci-bridge.h>
> #include <asm/ppc-pci.h>
> +#include <asm/early_ioremap.h>
>
> #undef DEBUG
>
> @@ -34,6 +35,7 @@ static struct legacy_serial_info {
> unsigned int clock;
> int irq_check_parent;
> phys_addr_t taddr;
> + void __iomem *early_addr;
> } legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
>
> static const struct of_device_id legacy_serial_parents[] __initconst = {
> @@ -325,17 +327,16 @@ static void __init setup_legacy_serial_console(int console)
> {
> struct legacy_serial_info *info = &legacy_serial_infos[console];
> struct plat_serial8250_port *port = &legacy_serial_ports[console];
> - void __iomem *addr;
> unsigned int stride;
>
> stride = 1 << port->regshift;
>
> /* Check if a translated MMIO address has been found */
> if (info->taddr) {
> - addr = ioremap(info->taddr, 0x1000);
> - if (addr == NULL)
> + info->early_addr = early_ioremap(info->taddr, 0x1000);
> + if (info->early_addr == NULL)
> return;
> - udbg_uart_init_mmio(addr, stride);
> + udbg_uart_init_mmio(info->early_addr, stride);
> } else {
> /* Check if it's PIO and we support untranslated PIO */
> if (port->iotype == UPIO_PORT && isa_io_special)
> @@ -353,6 +354,30 @@ static void __init setup_legacy_serial_console(int console)
> udbg_uart_setup(info->speed, info->clock);
> }
>
> +static int __init ioremap_legacy_serial_console(void)
> +{
> + struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
> + struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];
> + void __iomem *vaddr;
> +
> + if (legacy_serial_console < 0)
> + return 0;
> +
> + if (!info->early_addr)
> + return 0;
> +
> + vaddr = ioremap(info->taddr, 0x1000);
> + if (WARN_ON(!vaddr))
> + return -ENOMEM;
> +
> + udbg_uart_init_mmio(vaddr, 1 << port->regshift);
> + early_iounmap(info->early_addr, 0x1000);
> + info->early_addr = NULL;
> +
> + return 0;
> +}
> +early_initcall(ioremap_legacy_serial_console);
> +
> /*
> * This is called very early, as part of setup_system() or eventually
> * setup_arch(), basically before anything else in this file. This function
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/2] powerpc/legacy_serial: Use early_ioremap()
@ 2021-04-20 21:15 ` Chris Packham
0 siblings, 0 replies; 11+ messages in thread
From: Chris Packham @ 2021-04-20 21:15 UTC (permalink / raw)
To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman
Cc: linuxppc-dev, linux-kernel
Hi Christophe,
On 21/04/21 1:32 am, Christophe Leroy wrote:
> From: Christophe Leroy <christophe.leroy@c-s.fr>
>
> [ 0.000000] ioremap() called early from find_legacy_serial_ports+0x3cc/0x474. Use early_ioremap() instead
>
> find_legacy_serial_ports() is called early from setup_arch(), before
> paging_init(). vmalloc is not available yet, ioremap shouldn't be
> used that early.
>
> Use early_ioremap() and switch to a regular ioremap() later.
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
I gave it a spin on my T2080RDB. The error message is gone and I still
get console output.
Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> arch/powerpc/kernel/legacy_serial.c | 33 +++++++++++++++++++++++++----
> 1 file changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
> index f061e06e9f51..8b2c1a8553a0 100644
> --- a/arch/powerpc/kernel/legacy_serial.c
> +++ b/arch/powerpc/kernel/legacy_serial.c
> @@ -15,6 +15,7 @@
> #include <asm/udbg.h>
> #include <asm/pci-bridge.h>
> #include <asm/ppc-pci.h>
> +#include <asm/early_ioremap.h>
>
> #undef DEBUG
>
> @@ -34,6 +35,7 @@ static struct legacy_serial_info {
> unsigned int clock;
> int irq_check_parent;
> phys_addr_t taddr;
> + void __iomem *early_addr;
> } legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
>
> static const struct of_device_id legacy_serial_parents[] __initconst = {
> @@ -325,17 +327,16 @@ static void __init setup_legacy_serial_console(int console)
> {
> struct legacy_serial_info *info = &legacy_serial_infos[console];
> struct plat_serial8250_port *port = &legacy_serial_ports[console];
> - void __iomem *addr;
> unsigned int stride;
>
> stride = 1 << port->regshift;
>
> /* Check if a translated MMIO address has been found */
> if (info->taddr) {
> - addr = ioremap(info->taddr, 0x1000);
> - if (addr == NULL)
> + info->early_addr = early_ioremap(info->taddr, 0x1000);
> + if (info->early_addr == NULL)
> return;
> - udbg_uart_init_mmio(addr, stride);
> + udbg_uart_init_mmio(info->early_addr, stride);
> } else {
> /* Check if it's PIO and we support untranslated PIO */
> if (port->iotype == UPIO_PORT && isa_io_special)
> @@ -353,6 +354,30 @@ static void __init setup_legacy_serial_console(int console)
> udbg_uart_setup(info->speed, info->clock);
> }
>
> +static int __init ioremap_legacy_serial_console(void)
> +{
> + struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
> + struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];
> + void __iomem *vaddr;
> +
> + if (legacy_serial_console < 0)
> + return 0;
> +
> + if (!info->early_addr)
> + return 0;
> +
> + vaddr = ioremap(info->taddr, 0x1000);
> + if (WARN_ON(!vaddr))
> + return -ENOMEM;
> +
> + udbg_uart_init_mmio(vaddr, 1 << port->regshift);
> + early_iounmap(info->early_addr, 0x1000);
> + info->early_addr = NULL;
> +
> + return 0;
> +}
> +early_initcall(ioremap_legacy_serial_console);
> +
> /*
> * This is called very early, as part of setup_system() or eventually
> * setup_arch(), basically before anything else in this file. This function
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/2] powerpc/64: Fix the definition of the fixmap area
2021-04-20 13:32 ` Christophe Leroy
@ 2021-04-29 14:01 ` Michael Ellerman
-1 siblings, 0 replies; 11+ messages in thread
From: Michael Ellerman @ 2021-04-29 14:01 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Christophe Leroy, Michael Ellerman,
chris.packham, Paul Mackerras
Cc: linux-kernel, linuxppc-dev
On Tue, 20 Apr 2021 13:32:48 +0000 (UTC), Christophe Leroy wrote:
> At the time being, the fixmap area is defined at the top of
> the address space or just below KASAN.
>
> This definition is not valid for PPC64.
>
> For PPC64, use the top of the I/O space.
>
> [...]
Applied to powerpc/next.
[1/2] powerpc/64: Fix the definition of the fixmap area
https://git.kernel.org/powerpc/c/9ccba66d4d2aff9a3909aa77d57ea8b7cc166f3c
[2/2] powerpc/legacy_serial: Use early_ioremap()
https://git.kernel.org/powerpc/c/0bd3f9e953bd3636e73d296e9bed11a25c09c118
cheers
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/2] powerpc/64: Fix the definition of the fixmap area
@ 2021-04-29 14:01 ` Michael Ellerman
0 siblings, 0 replies; 11+ messages in thread
From: Michael Ellerman @ 2021-04-29 14:01 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Christophe Leroy, Michael Ellerman,
chris.packham, Paul Mackerras
Cc: linuxppc-dev, linux-kernel
On Tue, 20 Apr 2021 13:32:48 +0000 (UTC), Christophe Leroy wrote:
> At the time being, the fixmap area is defined at the top of
> the address space or just below KASAN.
>
> This definition is not valid for PPC64.
>
> For PPC64, use the top of the I/O space.
>
> [...]
Applied to powerpc/next.
[1/2] powerpc/64: Fix the definition of the fixmap area
https://git.kernel.org/powerpc/c/9ccba66d4d2aff9a3909aa77d57ea8b7cc166f3c
[2/2] powerpc/legacy_serial: Use early_ioremap()
https://git.kernel.org/powerpc/c/0bd3f9e953bd3636e73d296e9bed11a25c09c118
cheers
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/2] powerpc/legacy_serial: Use early_ioremap()
2021-04-20 13:32 ` Christophe Leroy
@ 2021-05-19 14:57 ` Alexey Kardashevskiy
-1 siblings, 0 replies; 11+ messages in thread
From: Alexey Kardashevskiy @ 2021-05-19 14:57 UTC (permalink / raw)
To: Christophe Leroy
Cc: linuxppc-dev, linux-kernel, Paul Mackerras,
Benjamin Herrenschmidt, Michael Ellerman, chris.packham
On 20/04/2021 23:32, Christophe Leroy wrote:
> From: Christophe Leroy <christophe.leroy@c-s.fr>
>
> [ 0.000000] ioremap() called early from find_legacy_serial_ports+0x3cc/0x474. Use early_ioremap() instead
>
> find_legacy_serial_ports() is called early from setup_arch(), before
> paging_init(). vmalloc is not available yet, ioremap shouldn't be
> used that early.
>
> Use early_ioremap() and switch to a regular ioremap() later.
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
My POWER9 box silently reboots with the upstream kernel which has this.
This hunk:
diff --git a/arch/powerpc/kernel/legacy_serial.c
b/arch/powerpc/kernel/legacy_serial.c
index f061e06e9f51..6bdb3f5f64e3 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -336,6 +336,16 @@ static void __init setup_legacy_serial_console(int
console)
if (addr == NULL)
return;
udbg_uart_init_mmio(addr, stride);
+
+
+ {
+ void *ea = early_ioremap(info->taddr, 0x1000);
+ pr_err("___K___ (%u) %s %u: ior=%lx early=%lx\n",
+ smp_processor_id(), __func__, __LINE__,
+ (unsigned long) addr, (unsigned
long) ea);
+ early_iounmap(ea, 0x1000);
+ }
+
produced:
[ 0.000000] ___K___ (0) setup_legacy_serial_console 345:
ior=c00a0000800003f8 early=ffffffffffc003f8
The early address just does not look right - ffffffffffc003f8. Do you
have a quick idea what is exactly wrong before I wake up and dig more?
:) It is powernv_defconfig. Thanks,
> ---
> arch/powerpc/kernel/legacy_serial.c | 33 +++++++++++++++++++++++++----
> 1 file changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
> index f061e06e9f51..8b2c1a8553a0 100644
> --- a/arch/powerpc/kernel/legacy_serial.c
> +++ b/arch/powerpc/kernel/legacy_serial.c
> @@ -15,6 +15,7 @@
> #include <asm/udbg.h>
> #include <asm/pci-bridge.h>
> #include <asm/ppc-pci.h>
> +#include <asm/early_ioremap.h>
>
> #undef DEBUG
>
> @@ -34,6 +35,7 @@ static struct legacy_serial_info {
> unsigned int clock;
> int irq_check_parent;
> phys_addr_t taddr;
> + void __iomem *early_addr;
> } legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
>
> static const struct of_device_id legacy_serial_parents[] __initconst = {
> @@ -325,17 +327,16 @@ static void __init setup_legacy_serial_console(int console)
> {
> struct legacy_serial_info *info = &legacy_serial_infos[console];
> struct plat_serial8250_port *port = &legacy_serial_ports[console];
> - void __iomem *addr;
> unsigned int stride;
>
> stride = 1 << port->regshift;
>
> /* Check if a translated MMIO address has been found */
> if (info->taddr) {
> - addr = ioremap(info->taddr, 0x1000);
> - if (addr == NULL)
> + info->early_addr = early_ioremap(info->taddr, 0x1000);
> + if (info->early_addr == NULL)
> return;
> - udbg_uart_init_mmio(addr, stride);
> + udbg_uart_init_mmio(info->early_addr, stride);
> } else {
> /* Check if it's PIO and we support untranslated PIO */
> if (port->iotype == UPIO_PORT && isa_io_special)
> @@ -353,6 +354,30 @@ static void __init setup_legacy_serial_console(int console)
> udbg_uart_setup(info->speed, info->clock);
> }
>
> +static int __init ioremap_legacy_serial_console(void)
> +{
> + struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
> + struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];
> + void __iomem *vaddr;
> +
> + if (legacy_serial_console < 0)
> + return 0;
> +
> + if (!info->early_addr)
> + return 0;
> +
> + vaddr = ioremap(info->taddr, 0x1000);
> + if (WARN_ON(!vaddr))
> + return -ENOMEM;
> +
> + udbg_uart_init_mmio(vaddr, 1 << port->regshift);
> + early_iounmap(info->early_addr, 0x1000);
> + info->early_addr = NULL;
> +
> + return 0;
> +}
> +early_initcall(ioremap_legacy_serial_console);
> +
> /*
> * This is called very early, as part of setup_system() or eventually
> * setup_arch(), basically before anything else in this file. This function
>
--
Alexey
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 2/2] powerpc/legacy_serial: Use early_ioremap()
@ 2021-05-19 14:57 ` Alexey Kardashevskiy
0 siblings, 0 replies; 11+ messages in thread
From: Alexey Kardashevskiy @ 2021-05-19 14:57 UTC (permalink / raw)
To: Christophe Leroy
Cc: linux-kernel, chris.packham, Paul Mackerras, linuxppc-dev
On 20/04/2021 23:32, Christophe Leroy wrote:
> From: Christophe Leroy <christophe.leroy@c-s.fr>
>
> [ 0.000000] ioremap() called early from find_legacy_serial_ports+0x3cc/0x474. Use early_ioremap() instead
>
> find_legacy_serial_ports() is called early from setup_arch(), before
> paging_init(). vmalloc is not available yet, ioremap shouldn't be
> used that early.
>
> Use early_ioremap() and switch to a regular ioremap() later.
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
My POWER9 box silently reboots with the upstream kernel which has this.
This hunk:
diff --git a/arch/powerpc/kernel/legacy_serial.c
b/arch/powerpc/kernel/legacy_serial.c
index f061e06e9f51..6bdb3f5f64e3 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -336,6 +336,16 @@ static void __init setup_legacy_serial_console(int
console)
if (addr == NULL)
return;
udbg_uart_init_mmio(addr, stride);
+
+
+ {
+ void *ea = early_ioremap(info->taddr, 0x1000);
+ pr_err("___K___ (%u) %s %u: ior=%lx early=%lx\n",
+ smp_processor_id(), __func__, __LINE__,
+ (unsigned long) addr, (unsigned
long) ea);
+ early_iounmap(ea, 0x1000);
+ }
+
produced:
[ 0.000000] ___K___ (0) setup_legacy_serial_console 345:
ior=c00a0000800003f8 early=ffffffffffc003f8
The early address just does not look right - ffffffffffc003f8. Do you
have a quick idea what is exactly wrong before I wake up and dig more?
:) It is powernv_defconfig. Thanks,
> ---
> arch/powerpc/kernel/legacy_serial.c | 33 +++++++++++++++++++++++++----
> 1 file changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
> index f061e06e9f51..8b2c1a8553a0 100644
> --- a/arch/powerpc/kernel/legacy_serial.c
> +++ b/arch/powerpc/kernel/legacy_serial.c
> @@ -15,6 +15,7 @@
> #include <asm/udbg.h>
> #include <asm/pci-bridge.h>
> #include <asm/ppc-pci.h>
> +#include <asm/early_ioremap.h>
>
> #undef DEBUG
>
> @@ -34,6 +35,7 @@ static struct legacy_serial_info {
> unsigned int clock;
> int irq_check_parent;
> phys_addr_t taddr;
> + void __iomem *early_addr;
> } legacy_serial_infos[MAX_LEGACY_SERIAL_PORTS];
>
> static const struct of_device_id legacy_serial_parents[] __initconst = {
> @@ -325,17 +327,16 @@ static void __init setup_legacy_serial_console(int console)
> {
> struct legacy_serial_info *info = &legacy_serial_infos[console];
> struct plat_serial8250_port *port = &legacy_serial_ports[console];
> - void __iomem *addr;
> unsigned int stride;
>
> stride = 1 << port->regshift;
>
> /* Check if a translated MMIO address has been found */
> if (info->taddr) {
> - addr = ioremap(info->taddr, 0x1000);
> - if (addr == NULL)
> + info->early_addr = early_ioremap(info->taddr, 0x1000);
> + if (info->early_addr == NULL)
> return;
> - udbg_uart_init_mmio(addr, stride);
> + udbg_uart_init_mmio(info->early_addr, stride);
> } else {
> /* Check if it's PIO and we support untranslated PIO */
> if (port->iotype == UPIO_PORT && isa_io_special)
> @@ -353,6 +354,30 @@ static void __init setup_legacy_serial_console(int console)
> udbg_uart_setup(info->speed, info->clock);
> }
>
> +static int __init ioremap_legacy_serial_console(void)
> +{
> + struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console];
> + struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console];
> + void __iomem *vaddr;
> +
> + if (legacy_serial_console < 0)
> + return 0;
> +
> + if (!info->early_addr)
> + return 0;
> +
> + vaddr = ioremap(info->taddr, 0x1000);
> + if (WARN_ON(!vaddr))
> + return -ENOMEM;
> +
> + udbg_uart_init_mmio(vaddr, 1 << port->regshift);
> + early_iounmap(info->early_addr, 0x1000);
> + info->early_addr = NULL;
> +
> + return 0;
> +}
> +early_initcall(ioremap_legacy_serial_console);
> +
> /*
> * This is called very early, as part of setup_system() or eventually
> * setup_arch(), basically before anything else in this file. This function
>
--
Alexey
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-05-19 14:58 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 13:32 [PATCH v2 1/2] powerpc/64: Fix the definition of the fixmap area Christophe Leroy
2021-04-20 13:32 ` Christophe Leroy
2021-04-20 13:32 ` [PATCH v2 2/2] powerpc/legacy_serial: Use early_ioremap() Christophe Leroy
2021-04-20 13:32 ` Christophe Leroy
2021-04-20 13:39 ` Christophe Leroy
2021-04-20 21:15 ` Chris Packham
2021-04-20 21:15 ` Chris Packham
2021-05-19 14:57 ` Alexey Kardashevskiy
2021-05-19 14:57 ` Alexey Kardashevskiy
2021-04-29 14:01 ` [PATCH v2 1/2] powerpc/64: Fix the definition of the fixmap area Michael Ellerman
2021-04-29 14:01 ` Michael Ellerman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.