All of lore.kernel.org
 help / color / mirror / Atom feed
* More K210 Support
@ 2020-04-08 16:57 Palmer Dabbelt
  2020-04-08 16:57 ` [PATCH 1/3] RISC-V: Allow device trees to be built into the kernel Palmer Dabbelt
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Palmer Dabbelt @ 2020-04-08 16:57 UTC (permalink / raw)
  To: linux-riscv; +Cc: Damien Le Moal, kernel-team

* Builds a table of device trees, keyed by mvendorid/marchid/mimpid.  This
  allows multiple device trees to be built into the kernel.  I don't really
  like maintaining the two lists (one in C and one in assembly) or having that
  function in the table, but it's the best I could come up with.
* "handles" PMP traps by just skipping the PMP setup phase.

I don't actually have a K210 so I can't test any of this.  I also couldn't find
the K210 identifiers listed anywhere online, so someone will have to dig them
out of the board.

I also didn't spend any time thinking through how we free these device trees,
but given that .dtb.init.rodata already exists as a section I'm just guessing
that's were we're supposed to put them.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/3] RISC-V: Allow device trees to be built into the kernel
  2020-04-08 16:57 More K210 Support Palmer Dabbelt
@ 2020-04-08 16:57 ` Palmer Dabbelt
  2020-04-08 16:57 ` [PATCH 2/3] RISC-V: K210: Add a built-in device tree Palmer Dabbelt
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Palmer Dabbelt @ 2020-04-08 16:57 UTC (permalink / raw)
  To: linux-riscv; +Cc: Damien Le Moal, Palmer Dabbelt

From: Palmer Dabbelt <palmerdabbelt@google.com>

Some systems don't provide a useful device tree to the kernel on boot.
Chasing around bootloaders for these systems is a headache, so instead
le't's just keep device tree table in the kernel, keyed by the SOC's
unique identifier, that contains the relevant DTB.

This is only implemented for M mode right now.  While we could implement
this via the SBI calls that allow access to these identifiers, we don't
have any systems that need this right now.

Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
 arch/riscv/Kconfig                    |  5 +++++
 arch/riscv/include/asm/soc.h          | 27 +++++++++++++++++++++++++++
 arch/riscv/kernel/Makefile            |  3 +++
 arch/riscv/kernel/builtin-dtb-table.c |  6 ++++++
 arch/riscv/kernel/builtin-dtb.S       |  3 +++
 arch/riscv/kernel/soc.c               | 25 +++++++++++++++++++++++++
 arch/riscv/kernel/vmlinux.lds.S       |  5 +++++
 arch/riscv/mm/init.c                  | 14 ++++++++++++++
 8 files changed, 88 insertions(+)
 create mode 100644 arch/riscv/kernel/builtin-dtb-table.c
 create mode 100644 arch/riscv/kernel/builtin-dtb.S

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index bc713666f00a..7572afc43bd8 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -380,6 +380,11 @@ endchoice
 
 endmenu
 
+config BUILTIN_DTB
+	def_bool y
+	depends on RISCV_M_MODE
+	depends on OF
+
 menu "Power management options"
 
 source "kernel/power/Kconfig"
diff --git a/arch/riscv/include/asm/soc.h b/arch/riscv/include/asm/soc.h
index 18bd1253ea18..c232e57bb356 100644
--- a/arch/riscv/include/asm/soc.h
+++ b/arch/riscv/include/asm/soc.h
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 /*
  * Copyright (C) 2020 Western Digital Corporation or its affiliates.
+ * Copyright (C) 2020 Google, Inc
  */
 
 #ifndef _ASM_RISCV_SOC_H
@@ -22,5 +23,31 @@
 
 void soc_early_init(void);
 
+/*
+ * Allows Linux to provide a device tree, which is necessary for SOCs that
+ * don't provide a useful one on their own.
+ */
+struct soc_builtin_dtb_table_entry {
+	long vendor_id;
+	long arch_id;
+	long imp_id;
+	void *(*dtb_func)(void);
+};
+
+#define SOC_BUILTIN_DTB_DECLARE(name, vendor, impl, arch, dtb)		\
+	static __init __used						\
+	void *__soc_builtin_dtb_f__##name(void) { return dtb; }		\
+									\
+	static const struct soc_builtin_dtb_table_entry			\
+	__soc_builtin_dtb__##name __used				\
+	__section(__soc_builtin_dtb_table)				\
+	= {								\
+		.vendor_id = vendor,					\
+		.arch_id   = arch,					\
+		.imp_id    = impl,					\
+		.dtb_func  = __soc_builtin_dtb_f__##name,		\
+	}
+
+void *soc_lookup_builtin_dtb(long vendor_id, long arch_id, long imp_id);
 
 #endif
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index 86c83081044f..f40516b6e6c1 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -52,4 +52,7 @@ obj-$(CONFIG_SMP) += cpu_ops_sbi.o
 endif
 obj-$(CONFIG_HOTPLUG_CPU)	+= cpu-hotplug.o
 
+obj-$(CONFIG_BUILTIN_DTB) += builtin-dtb.o
+obj-$(CONFIG_BUILTIN_DTB) += builtin-dtb-table.o
+
 clean:
diff --git a/arch/riscv/kernel/builtin-dtb-table.c b/arch/riscv/kernel/builtin-dtb-table.c
new file mode 100644
index 000000000000..7ad6fe93b8a6
--- /dev/null
+++ b/arch/riscv/kernel/builtin-dtb-table.c
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Table of built-in device trees
+ */
+
+#include <asm/soc.h>
diff --git a/arch/riscv/kernel/builtin-dtb.S b/arch/riscv/kernel/builtin-dtb.S
new file mode 100644
index 000000000000..3d459ad86948
--- /dev/null
+++ b/arch/riscv/kernel/builtin-dtb.S
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+.section .dtb.init.rodata,"a"
diff --git a/arch/riscv/kernel/soc.c b/arch/riscv/kernel/soc.c
index c32e7c8e7870..3a05110a2447 100644
--- a/arch/riscv/kernel/soc.c
+++ b/arch/riscv/kernel/soc.c
@@ -32,3 +32,28 @@ void __init soc_early_init(void)
 		}
 	}
 }
+
+static int builtin_dtb_match(long vendor_id, long arch_id, long imp_id,
+			     const struct soc_builtin_dtb_table_entry *entry)
+{
+	return (entry->vendor_id == vendor_id)
+	       && (entry->arch_id == arch_id)
+	       && (entry->imp_id == imp_id);
+}
+
+extern unsigned long __soc_builtin_dtb_table_start;
+extern unsigned long __soc_builtin_dtb_table_end;
+
+void * __init soc_lookup_builtin_dtb(long vendor_id, long arch_id, long imp_id)
+{
+	const struct soc_builtin_dtb_table_entry *s;
+
+	for (s = (void *)&__soc_early_init_table_start;
+	     (void *)s < (void *)&__soc_early_init_table_end; s++) {
+		if (builtin_dtb_match(vendor_id, arch_id, imp_id, s)) {
+			return s->dtb_func();
+		}
+	}
+
+	return NULL;
+}
diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
index 0339b6bbe11a..e6f8016b366a 100644
--- a/arch/riscv/kernel/vmlinux.lds.S
+++ b/arch/riscv/kernel/vmlinux.lds.S
@@ -34,6 +34,11 @@ SECTIONS
 		KEEP(*(__soc_early_init_table))
 		__soc_early_init_table_end = .;
 	}
+	__soc_builtin_dtb_table : {
+		__soc_builtin_dtb_table_start = .;
+		KEEP(*(__soc_builtin_dtb_table))
+		__soc_builtin_dtb_table_end = .;
+	}
 	/* we have to discard exit text and such at runtime, not link time */
 	.exit.text :
 	{
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 0c625a5e98db..ad07d931bca8 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -17,6 +17,7 @@
 #include <asm/fixmap.h>
 #include <asm/tlbflush.h>
 #include <asm/sections.h>
+#include <asm/soc.h>
 #include <asm/pgtable.h>
 #include <asm/io.h>
 
@@ -492,7 +493,20 @@ void free_initmem(void)
 #else
 asmlinkage void __init setup_vm(uintptr_t dtb_pa)
 {
+#ifdef CONFIG_RISCV_M_MODE
+	void *builtin_dtb;
+	long mvendorid, marchid, mimpid;
+
+	__asm__ ("csrr %0, mvendorid" : "=r"(mvendorid));
+	__asm__ ("csrr %0, marchid" : "=r"(marchid));
+	__asm__ ("csrr %0, mimpid" : "=r"(mimpid));
+
+	builtin_dtb = soc_lookup_builtin_dtb(mvendorid, marchid, mimpid);
+	if (builtin_dtb != NULL)
+		dtb_early_va = builtin_dtb;
+#else
 	dtb_early_va = (void *)dtb_pa;
+#endif
 }
 
 static inline void setup_vm_final(void)
-- 
2.26.0.292.g33ef6b2f38-goog



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/3] RISC-V: K210: Add a built-in device tree
  2020-04-08 16:57 More K210 Support Palmer Dabbelt
  2020-04-08 16:57 ` [PATCH 1/3] RISC-V: Allow device trees to be built into the kernel Palmer Dabbelt
@ 2020-04-08 16:57 ` Palmer Dabbelt
  2020-04-09  2:19   ` Damien Le Moal
  2020-04-08 16:57 ` [PATCH 3/3] RISC-V: Skip setting up PMPs on traps Palmer Dabbelt
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Palmer Dabbelt @ 2020-04-08 16:57 UTC (permalink / raw)
  To: linux-riscv; +Cc: Damien Le Moal, Palmer Dabbelt

From: Palmer Dabbelt <palmerdabbelt@google.com>

The K210's bootloader doesn't provide a device tree, so we must provide
our own.

FIXME: I don't actually know the unique IDs on the K210.

Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
 arch/riscv/Kconfig.socs               | 13 ++++++++++++-
 arch/riscv/boot/dts/kendryte/Makefile |  2 +-
 arch/riscv/kernel/builtin-dtb-table.c |  5 +++++
 arch/riscv/kernel/builtin-dtb.S       |  6 ++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index a843100124ae..49e953f45e1f 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -37,11 +37,22 @@ config SOC_VIRT
 config SOC_KENDRYTE
 	bool "Kendryte K210 SoC"
 	depends on !MMU
-	select BUILTIN_DTB
 	select SERIAL_SIFIVE if TTY
 	select SERIAL_SIFIVE_CONSOLE if TTY
 	select SIFIVE_PLIC
+	select SOC_KENDRYTE_K210_DTB_BUILTIN
 	help
 	  This enables support for Kendryte K210 SoC platform hardware.
 
+config SOC_KENDRYTE_K210_DTB
+	def_bool y
+	depends on OF
+
+config SOC_KENDRYTE_K210_DTB_BUILTIN
+	bool "Builtin device tree for the Kendryte K210"
+	depends on BUILTIN_DTB
+	select SOC_KENDRYTE_K210_DTB
+	help
+	  Builds a device tree for the Kendryte K210 into the Linux image.
+
 endmenu
diff --git a/arch/riscv/boot/dts/kendryte/Makefile b/arch/riscv/boot/dts/kendryte/Makefile
index 815444e69e89..01d7eb15673f 100644
--- a/arch/riscv/boot/dts/kendryte/Makefile
+++ b/arch/riscv/boot/dts/kendryte/Makefile
@@ -1,2 +1,2 @@
 # SPDX-License-Identifier: GPL-2.0
-dtb-$(CONFIG_SOC_KENDRYTE) += k210.dtb
+dtb-$(CONFIG_SOC_KENDRYTE_K210_DTB) += k210.dtb
diff --git a/arch/riscv/kernel/builtin-dtb-table.c b/arch/riscv/kernel/builtin-dtb-table.c
index 7ad6fe93b8a6..203174ba6f22 100644
--- a/arch/riscv/kernel/builtin-dtb-table.c
+++ b/arch/riscv/kernel/builtin-dtb-table.c
@@ -4,3 +4,8 @@
  */
 
 #include <asm/soc.h>
+
+#ifdef CONFIG_SOC_KENDRYTE_K210_DTB_BUILTIN
+extern void *kendryte_k210_dtb;
+SOC_BUILTIN_DTB_DECLARE(kendryte_k210, 0x0, 0x0, 0x0, kendryte_k210_dtb);
+#endif
diff --git a/arch/riscv/kernel/builtin-dtb.S b/arch/riscv/kernel/builtin-dtb.S
index 3d459ad86948..b0fd5ca231d7 100644
--- a/arch/riscv/kernel/builtin-dtb.S
+++ b/arch/riscv/kernel/builtin-dtb.S
@@ -1,3 +1,9 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
 .section .dtb.init.rodata,"a"
+
+#ifdef CONFIG_SOC_KENDRYTE_K210_DTB_BUILTIN
+.global kendryte_k210_dtb
+kendryte_k210_dtb:
+	.incbin "arch/riscv/boot/dts/kendryte/k210.dtb"
+#endif
-- 
2.26.0.292.g33ef6b2f38-goog



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/3] RISC-V: Skip setting up PMPs on traps
  2020-04-08 16:57 More K210 Support Palmer Dabbelt
  2020-04-08 16:57 ` [PATCH 1/3] RISC-V: Allow device trees to be built into the kernel Palmer Dabbelt
  2020-04-08 16:57 ` [PATCH 2/3] RISC-V: K210: Add a built-in device tree Palmer Dabbelt
@ 2020-04-08 16:57 ` Palmer Dabbelt
  2020-04-13  9:06   ` Damien Le Moal
  2020-04-13  1:45 ` More K210 Support Damien Le Moal
  2020-04-17  4:55 ` Damien Le Moal
  4 siblings, 1 reply; 11+ messages in thread
From: Palmer Dabbelt @ 2020-04-08 16:57 UTC (permalink / raw)
  To: linux-riscv; +Cc: Damien Le Moal, Palmer Dabbelt

From: Palmer Dabbelt <palmerdabbelt@google.com>

The RISC-V ISA manual says that PMPs are WARL, but it appears the K210
doesn't implement them and instead traps on the unsupported accesses.
This patch handles those traps by just skipping the PMP
initialization entirely, under the theory that machines that trap on PMP
accesses must allow memory accesses as otherwise they're pretty useless.

Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
 arch/riscv/kernel/head.S | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index 98a406474e7d..7ed1b22950fd 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -161,11 +161,20 @@ ENTRY(_start_kernel)
 	/* Reset all registers except ra, a0, a1 */
 	call reset_regs
 
-	/* Setup a PMP to permit access to all of memory. */
+	/*
+	 * Setup a PMP to permit access to all of memory.  Some machines may
+	 * not implement PMPs, so we set up a quick trap handler to just skip
+	 * touching the PMPs on any trap.
+	 */
+	la a0, pmp_done
+	csrw CSR_TVEC, a0
+
 	li a0, -1
 	csrw CSR_PMPADDR0, a0
 	li a0, (PMP_A_NAPOT | PMP_R | PMP_W | PMP_X)
 	csrw CSR_PMPCFG0, a0
+.align 2
+pmp_done:
 
 	/*
 	 * The hartid in a0 is expected later on, and we have no firmware
-- 
2.26.0.292.g33ef6b2f38-goog



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/3] RISC-V: K210: Add a built-in device tree
  2020-04-08 16:57 ` [PATCH 2/3] RISC-V: K210: Add a built-in device tree Palmer Dabbelt
@ 2020-04-09  2:19   ` Damien Le Moal
  0 siblings, 0 replies; 11+ messages in thread
From: Damien Le Moal @ 2020-04-09  2:19 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv; +Cc: Palmer Dabbelt

On 2020/04/09 1:58, Palmer Dabbelt wrote:
> From: Palmer Dabbelt <palmerdabbelt@google.com>
> 
> The K210's bootloader doesn't provide a device tree, so we must provide
> our own.
> 
> FIXME: I don't actually know the unique IDs on the K210.

OK. I will test.

> 
> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
> ---
>  arch/riscv/Kconfig.socs               | 13 ++++++++++++-
>  arch/riscv/boot/dts/kendryte/Makefile |  2 +-
>  arch/riscv/kernel/builtin-dtb-table.c |  5 +++++
>  arch/riscv/kernel/builtin-dtb.S       |  6 ++++++
>  4 files changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
> index a843100124ae..49e953f45e1f 100644
> --- a/arch/riscv/Kconfig.socs
> +++ b/arch/riscv/Kconfig.socs
> @@ -37,11 +37,22 @@ config SOC_VIRT
>  config SOC_KENDRYTE
>  	bool "Kendryte K210 SoC"
>  	depends on !MMU
> -	select BUILTIN_DTB

Since SOC_KENDRYTE_K210_DTB_BUILTIN depends on BUILTIN_DTB, you need to keep
this select, no ?

>  	select SERIAL_SIFIVE if TTY
>  	select SERIAL_SIFIVE_CONSOLE if TTY
>  	select SIFIVE_PLIC
> +	select SOC_KENDRYTE_K210_DTB_BUILTIN
>  	help
>  	  This enables support for Kendryte K210 SoC platform hardware.
>  
> +config SOC_KENDRYTE_K210_DTB
> +	def_bool y
> +	depends on OF

This one is used only in the makefile. Why not use SOC_KENDRYTE_K210_DTB_BUILTIN
directly and drop this SOC_KENDRYTE_K210_DTB ?

> +
> +config SOC_KENDRYTE_K210_DTB_BUILTIN
> +	bool "Builtin device tree for the Kendryte K210"
> +	depends on BUILTIN_DTB
> +	select SOC_KENDRYTE_K210_DTB
> +	help
> +	  Builds a device tree for the Kendryte K210 into the Linux image.
> +
>  endmenu
> diff --git a/arch/riscv/boot/dts/kendryte/Makefile b/arch/riscv/boot/dts/kendryte/Makefile
> index 815444e69e89..01d7eb15673f 100644
> --- a/arch/riscv/boot/dts/kendryte/Makefile
> +++ b/arch/riscv/boot/dts/kendryte/Makefile
> @@ -1,2 +1,2 @@
>  # SPDX-License-Identifier: GPL-2.0
> -dtb-$(CONFIG_SOC_KENDRYTE) += k210.dtb
> +dtb-$(CONFIG_SOC_KENDRYTE_K210_DTB) += k210.dtb
> diff --git a/arch/riscv/kernel/builtin-dtb-table.c b/arch/riscv/kernel/builtin-dtb-table.c
> index 7ad6fe93b8a6..203174ba6f22 100644
> --- a/arch/riscv/kernel/builtin-dtb-table.c
> +++ b/arch/riscv/kernel/builtin-dtb-table.c
> @@ -4,3 +4,8 @@
>   */
>  
>  #include <asm/soc.h>
> +
> +#ifdef CONFIG_SOC_KENDRYTE_K210_DTB_BUILTIN
> +extern void *kendryte_k210_dtb;
> +SOC_BUILTIN_DTB_DECLARE(kendryte_k210, 0x0, 0x0, 0x0, kendryte_k210_dtb);
> +#endif
> diff --git a/arch/riscv/kernel/builtin-dtb.S b/arch/riscv/kernel/builtin-dtb.S
> index 3d459ad86948..b0fd5ca231d7 100644
> --- a/arch/riscv/kernel/builtin-dtb.S
> +++ b/arch/riscv/kernel/builtin-dtb.S
> @@ -1,3 +1,9 @@
>  /* SPDX-License-Identifier: GPL-2.0 */
>  
>  .section .dtb.init.rodata,"a"
> +
> +#ifdef CONFIG_SOC_KENDRYTE_K210_DTB_BUILTIN
> +.global kendryte_k210_dtb
> +kendryte_k210_dtb:
> +	.incbin "arch/riscv/boot/dts/kendryte/k210.dtb"
> +#endif
> 


-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: More K210 Support
  2020-04-08 16:57 More K210 Support Palmer Dabbelt
                   ` (2 preceding siblings ...)
  2020-04-08 16:57 ` [PATCH 3/3] RISC-V: Skip setting up PMPs on traps Palmer Dabbelt
@ 2020-04-13  1:45 ` Damien Le Moal
  2020-04-20 20:28   ` Palmer Dabbelt
  2020-04-17  4:55 ` Damien Le Moal
  4 siblings, 1 reply; 11+ messages in thread
From: Damien Le Moal @ 2020-04-13  1:45 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv; +Cc: kernel-team

On 2020/04/09 1:58, Palmer Dabbelt wrote:
> * Builds a table of device trees, keyed by mvendorid/marchid/mimpid.  This
>   allows multiple device trees to be built into the kernel.  I don't really
>   like maintaining the two lists (one in C and one in assembly) or having that
>   function in the table, but it's the best I could come up with.
> * "handles" PMP traps by just skipping the PMP setup phase.
> 
> I don't actually have a K210 so I can't test any of this.  I also couldn't find
> the K210 identifiers listed anywhere online, so someone will have to dig them
> out of the board.
> 
> I also didn't spend any time thinking through how we free these device trees,
> but given that .dtb.init.rodata already exists as a section I'm just guessing
> that's were we're supposed to put them.

I cannot test anything yet. Something funky is going on with boot objcopy/Image
size: I end up with an Image file (and loader/loader.bin) that are 8.5MB instead
of the 1.4MB I had before pulling in Linus tree. rc1 as of this morning still
shows the same problem. vmlinux is 1.8MB vs 1.9 MB before.

To check if my toolchain is broken, I recompiled the 5.6 tree I used for
developing the series and I end up with a loader.bin file of 1.4 MB. All looking
good. But there are changes to the vmlinux elf section headers which likely
cause the huge final size I am seeing. Will try to dig into this.


-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/3] RISC-V: Skip setting up PMPs on traps
  2020-04-08 16:57 ` [PATCH 3/3] RISC-V: Skip setting up PMPs on traps Palmer Dabbelt
@ 2020-04-13  9:06   ` Damien Le Moal
  0 siblings, 0 replies; 11+ messages in thread
From: Damien Le Moal @ 2020-04-13  9:06 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv; +Cc: Palmer Dabbelt

On 2020/04/09 1:58, Palmer Dabbelt wrote:
> From: Palmer Dabbelt <palmerdabbelt@google.com>
> 
> The RISC-V ISA manual says that PMPs are WARL, but it appears the K210
> doesn't implement them and instead traps on the unsupported accesses.
> This patch handles those traps by just skipping the PMP
> initialization entirely, under the theory that machines that trap on PMP
> accesses must allow memory accesses as otherwise they're pretty useless.
> 
> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>

This one works:

Tested-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>

Testing/hacking the other 2 patches of the series now.


> ---
>  arch/riscv/kernel/head.S | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
> index 98a406474e7d..7ed1b22950fd 100644
> --- a/arch/riscv/kernel/head.S
> +++ b/arch/riscv/kernel/head.S
> @@ -161,11 +161,20 @@ ENTRY(_start_kernel)
>  	/* Reset all registers except ra, a0, a1 */
>  	call reset_regs
>  
> -	/* Setup a PMP to permit access to all of memory. */
> +	/*
> +	 * Setup a PMP to permit access to all of memory.  Some machines may
> +	 * not implement PMPs, so we set up a quick trap handler to just skip
> +	 * touching the PMPs on any trap.
> +	 */
> +	la a0, pmp_done
> +	csrw CSR_TVEC, a0
> +
>  	li a0, -1
>  	csrw CSR_PMPADDR0, a0
>  	li a0, (PMP_A_NAPOT | PMP_R | PMP_W | PMP_X)
>  	csrw CSR_PMPCFG0, a0
> +.align 2
> +pmp_done:
>  
>  	/*
>  	 * The hartid in a0 is expected later on, and we have no firmware
> 


-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: More K210 Support
  2020-04-08 16:57 More K210 Support Palmer Dabbelt
                   ` (3 preceding siblings ...)
  2020-04-13  1:45 ` More K210 Support Damien Le Moal
@ 2020-04-17  4:55 ` Damien Le Moal
  4 siblings, 0 replies; 11+ messages in thread
From: Damien Le Moal @ 2020-04-17  4:55 UTC (permalink / raw)
  To: Palmer Dabbelt, linux-riscv; +Cc: kernel-team

On 2020/04/09 1:58, Palmer Dabbelt wrote:
> * Builds a table of device trees, keyed by mvendorid/marchid/mimpid.  This
>   allows multiple device trees to be built into the kernel.  I don't really
>   like maintaining the two lists (one in C and one in assembly) or having that
>   function in the table, but it's the best I could come up with.
> * "handles" PMP traps by just skipping the PMP setup phase.
> 
> I don't actually have a K210 so I can't test any of this.  I also couldn't find
> the K210 identifiers listed anywhere online, so someone will have to dig them
> out of the board.
> 
> I also didn't spend any time thinking through how we free these device trees,
> but given that .dtb.init.rodata already exists as a section I'm just guessing
> that's were we're supposed to put them.
> 
> 
> 

(replying to your original post instead of my update since infradead does not
send me back my posts).

Palmer, have you had a chance to review the updated patches I sent for the
builtin dtb ?


-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: More K210 Support
  2020-04-13  1:45 ` More K210 Support Damien Le Moal
@ 2020-04-20 20:28   ` Palmer Dabbelt
  2020-04-20 22:25     ` Damien Le Moal
  0 siblings, 1 reply; 11+ messages in thread
From: Palmer Dabbelt @ 2020-04-20 20:28 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: linux-riscv, kernel-team

On Sun, 12 Apr 2020 18:45:33 PDT (-0700), Damien Le Moal wrote:
>> On 2020/04/09 1:58, Palmer Dabbelt wrote:
>> * Builds a table of device trees, keyed by mvendorid/marchid/mimpid.  This
>>   allows multiple device trees to be built into the kernel.  I don't really
>>   like maintaining the two lists (one in C and one in assembly) or having that
>>   function in the table, but it's the best I could come up with.
>> * "handles" PMP traps by just skipping the PMP setup phase.
>> 
>> I don't actually have a K210 so I can't test any of this.  I also couldn't find
>> the K210 identifiers listed anywhere online, so someone will have to dig them
>> out of the board.
>> 
>> I also didn't spend any time thinking through how we free these device trees,
>> but given that .dtb.init.rodata already exists as a section I'm just guessing
>> that's were we're supposed to put them.
>
> I cannot test anything yet. Something funky is going on with boot objcopy/Image
> size: I end up with an Image file (and loader/loader.bin) that are 8.5MB instead
> of the 1.4MB I had before pulling in Linus tree. rc1 as of this morning still
> shows the same problem. vmlinux is 1.8MB vs 1.9 MB before.
>
> To check if my toolchain is broken, I recompiled the 5.6 tree I used for
> developing the series and I end up with a loader.bin file of 1.4 MB. All looking
> good. But there are changes to the vmlinux elf section headers which likely
> cause the huge final size I am seeing. Will try to dig into this.

Thanks!


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: More K210 Support
  2020-04-20 20:28   ` Palmer Dabbelt
@ 2020-04-20 22:25     ` Damien Le Moal
  2020-04-24 18:31       ` Palmer Dabbelt
  0 siblings, 1 reply; 11+ messages in thread
From: Damien Le Moal @ 2020-04-20 22:25 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: linux-riscv, kernel-team

On 2020/04/21 5:29, Palmer Dabbelt wrote:
> On Sun, 12 Apr 2020 18:45:33 PDT (-0700), Damien Le Moal wrote:
>>> On 2020/04/09 1:58, Palmer Dabbelt wrote:
>>> * Builds a table of device trees, keyed by mvendorid/marchid/mimpid.  This
>>>   allows multiple device trees to be built into the kernel.  I don't really
>>>   like maintaining the two lists (one in C and one in assembly) or having that
>>>   function in the table, but it's the best I could come up with.
>>> * "handles" PMP traps by just skipping the PMP setup phase.
>>>
>>> I don't actually have a K210 so I can't test any of this.  I also couldn't find
>>> the K210 identifiers listed anywhere online, so someone will have to dig them
>>> out of the board.
>>>
>>> I also didn't spend any time thinking through how we free these device trees,
>>> but given that .dtb.init.rodata already exists as a section I'm just guessing
>>> that's were we're supposed to put them.
>>
>> I cannot test anything yet. Something funky is going on with boot objcopy/Image
>> size: I end up with an Image file (and loader/loader.bin) that are 8.5MB instead
>> of the 1.4MB I had before pulling in Linus tree. rc1 as of this morning still
>> shows the same problem. vmlinux is 1.8MB vs 1.9 MB before.
>>
>> To check if my toolchain is broken, I recompiled the 5.6 tree I used for
>> developing the series and I end up with a loader.bin file of 1.4 MB. All looking
>> good. But there are changes to the vmlinux elf section headers which likely
>> cause the huge final size I am seeing. Will try to dig into this.
> 
> Thanks!

I sent you fixed patches already. Please review them.
The large image size was due to the strict RWX alignment of elf sections, which
can be disabled for no mmu case since there is no RW protection anyway.


-- 
Damien Le Moal
Western Digital Research


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: More K210 Support
  2020-04-20 22:25     ` Damien Le Moal
@ 2020-04-24 18:31       ` Palmer Dabbelt
  0 siblings, 0 replies; 11+ messages in thread
From: Palmer Dabbelt @ 2020-04-24 18:31 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: linux-riscv, kernel-team

On Mon, 20 Apr 2020 15:25:33 PDT (-0700), Damien Le Moal wrote:
> On 2020/04/21 5:29, Palmer Dabbelt wrote:
>> On Sun, 12 Apr 2020 18:45:33 PDT (-0700), Damien Le Moal wrote:
>>>> On 2020/04/09 1:58, Palmer Dabbelt wrote:
>>>> * Builds a table of device trees, keyed by mvendorid/marchid/mimpid.  This
>>>>   allows multiple device trees to be built into the kernel.  I don't really
>>>>   like maintaining the two lists (one in C and one in assembly) or having that
>>>>   function in the table, but it's the best I could come up with.
>>>> * "handles" PMP traps by just skipping the PMP setup phase.
>>>>
>>>> I don't actually have a K210 so I can't test any of this.  I also couldn't find
>>>> the K210 identifiers listed anywhere online, so someone will have to dig them
>>>> out of the board.
>>>>
>>>> I also didn't spend any time thinking through how we free these device trees,
>>>> but given that .dtb.init.rodata already exists as a section I'm just guessing
>>>> that's were we're supposed to put them.
>>>
>>> I cannot test anything yet. Something funky is going on with boot objcopy/Image
>>> size: I end up with an Image file (and loader/loader.bin) that are 8.5MB instead
>>> of the 1.4MB I had before pulling in Linus tree. rc1 as of this morning still
>>> shows the same problem. vmlinux is 1.8MB vs 1.9 MB before.
>>>
>>> To check if my toolchain is broken, I recompiled the 5.6 tree I used for
>>> developing the series and I end up with a loader.bin file of 1.4 MB. All looking
>>> good. But there are changes to the vmlinux elf section headers which likely
>>> cause the huge final size I am seeing. Will try to dig into this.
>>
>> Thanks!
>
> I sent you fixed patches already. Please review them.
> The large image size was due to the strict RWX alignment of elf sections, which
> can be disabled for no mmu case since there is no RW protection anyway.

That RWX thing didn't make it to my inbox for some reason, but Atish pointed it
out in another thread.  It's on for-next now.  Thanks!


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-04-24 18:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-08 16:57 More K210 Support Palmer Dabbelt
2020-04-08 16:57 ` [PATCH 1/3] RISC-V: Allow device trees to be built into the kernel Palmer Dabbelt
2020-04-08 16:57 ` [PATCH 2/3] RISC-V: K210: Add a built-in device tree Palmer Dabbelt
2020-04-09  2:19   ` Damien Le Moal
2020-04-08 16:57 ` [PATCH 3/3] RISC-V: Skip setting up PMPs on traps Palmer Dabbelt
2020-04-13  9:06   ` Damien Le Moal
2020-04-13  1:45 ` More K210 Support Damien Le Moal
2020-04-20 20:28   ` Palmer Dabbelt
2020-04-20 22:25     ` Damien Le Moal
2020-04-24 18:31       ` Palmer Dabbelt
2020-04-17  4:55 ` Damien Le Moal

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.