Fix some bugs on RV32 build fail and issue
Subsystems (2)
v2 cover Fix some bugs on RV32 build fail and issue
This patches contain the modificaion as follows:
1. Fix up the building fail on RV32.
2. Add umoddi3 and udivmoddi4 functions for RV32.
3. Fix ioremap problem on RV32.
Changes in v2:
- Retain the copyright notices from libgcc in umoddi3.c and udivmoddi4.c.
Vincent Chen (1):
RISC-V: Avoid corrupting the upper 32-bit of phys_addr_t in ioremap
Zong Li (4):
RISC-V: Build tishift only on 64-bit
RISC-V: Use swiotlb on RV64 only
lib: Add umoddi3 and udivmoddi4 of GCC library routines
RISC-V: Select GENERIC_LIB_UMODDI3 on RV32
arch/riscv/Kconfig | 1 + arch/riscv/kernel/setup.c | 3 + arch/riscv/lib/Makefile | 3 +- arch/riscv/mm/ioremap.c | 2 +- lib/Kconfig | 3 + lib/Makefile | 1 + lib/udivmoddi4.c | 309 ++++++++++++++++++++++++++++++++++++++++++++++ lib/umoddi3.c | 34 +++++ 8 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 lib/udivmoddi4.c create mode 100644 lib/umoddi3.c
Signature · 1 line
2.7.4
PATCH v2 1/5 RISC-V: Build tishift only on 64-bit
Only RV64 supports 128 integer size.
--- arch/riscv/lib/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/lib/Makefile +2 -1
@@ -2,6 +2,7 @@ lib-y += delay.o lib-y += memcpy.o lib-y += memset.o lib-y += uaccess.o -lib-y += tishift.o + +lib-(CONFIG_64BIT) += tishift.o lib-$(CONFIG_32BIT) += udivdi3.o
Signature · 1 line
2.7.4
PATCH v2 2/5 RISC-V: Use swiotlb on RV64 only
In reply to Zong LiOnly RV64 supports swiotlb.
--- arch/riscv/kernel/setup.c | 3 +++ 1 file changed, 3 insertions(+)
arch/riscv/kernel/setup.c +3 -0
@@ -227,7 +227,10 @@ void __init setup_arch(char **cmdline_p)setup_bootmem ();paging_init ();unflatten_device_tree (); + +#ifdef CONFIG_64bitswiotlb_init (1 ); +#endif #ifdef CONFIG_SMP setup_smp ();
Signature · 1 line
2.7.4
PATCH v2 3/5 lib: Add umoddi3 and udivmoddi4 of GCC library routines
In reply to Zong LiAdd umoddi3 and udivmoddi4 support for 32-bit.
The RV32 need the umoddi3 to do modulo when the operands are long long type, like other libraries implementation such as ucmpdi2, lshrdi3 and so on.
I encounter the undefined reference 'umoddi3' when I use the in house dma driver, although it is in house driver, but I think that umoddi3 is a common function for RV32.
The udivmoddi4 and umoddi3 are copies from libgcc in gcc. There are other functions use the udivmoddi4 in libgcc, so I separate the umoddi3 and udivmoddi4 for flexible extension in the future.
--- lib/Kconfig | 3 + lib/Makefile | 1 + lib/udivmoddi4.c | 309 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/umoddi3.c | 34 ++++++ 4 files changed, 347 insertions(+) create mode 100644 lib/udivmoddi4.c create mode 100644 lib/umoddi3.c
lib/Kconfig +3 -0
@@ -621,3 +621,6 @@ config GENERIC_LIB_CMPDI2 config GENERIC_LIB_UCMPDI2 bool + +config GENERIC_LIB_UMODDI3 + bool
lib/Makefile +1 -0
@@ -271,3 +271,4 @@ obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o +obj-$(CONFIG_GENERIC_LIB_UMODDI3) += umoddi3.o udivmoddi4.o
lib/udivmoddi4.c new file +309 -0
309 lines not on this page · raw message
lib/umoddi3.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 3, or (at your option) any later +* version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* Under Section 7 of GPL version 3, you are granted additional +* permissions described in the GCC Runtime Library Exception, version +* 3.1, as published by the Free Software Foundation. +* +* You should have received a copy of the GNU General Public License and +* a copy of the GCC Runtime Library Exception along with this program; +* see the files COPYING3 and COPYING.RUNTIME respectively. +*/ + +#include <linux/module.h> +#include <linux/libgcc.h> + +extern unsigned long long __udivmoddi4 (unsigned long long u, +unsigned long long v, +unsigned long long *rp); + +unsigned long long __umoddi3 (unsigned long long u,unsigned long long v) +{ +unsigned long long w; + (void )__udivmoddi4 (u, v, &w); +return w; +} +EXPORT_SYMBOL (__umoddi3);
Signature · 1 line
2.7.4
PATCH v2 4/5 RISC-V: Select GENERIC_LIB_UMODDI3 on RV32
In reply to Zong LiOn 32-bit, it need to use __umoddi3 by some drivers.
--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
@@ -108,6 +108,7 @@ config ARCH_RV32I select GENERIC_LIB_ASHRDI3 select GENERIC_LIB_LSHRDI3 select GENERIC_LIB_UCMPDI2 + select GENERIC_LIB_UMODDI3 config ARCH_RV64I bool "RV64I"
Signature · 1 line
2.7.4
PATCH v2 5/5 RISC-V: Avoid corrupting the upper 32-bit of phys_addr_t in ioremap
In reply to Zong LiFrom: Vincent Chen <[email protected]>
For 32bit, the upper 32-bit of phys_addr_t will be flushed to zero after AND with PAGE_MASK because the data type of PAGE_MASK is unsigned long. To fix this problem, the page alignment is done by subtracting the page offset instead of AND with PAGE_MASK.
--- arch/riscv/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/ioremap.c +1 -1
@@ -42,7 +42,7 @@ static void __iomem *__ioremap_caller(phys_addr_t addr, size_t size,/* Page-align mappings */ offset = addr & (~PAGE_MASK ); - addr &=PAGE_MASK ; + addr -= offset; size =PAGE_ALIGN (size + offset); area =get_vm_area_caller (size,VM_IOREMAP , caller);
Signature · 1 line
2.7.4
Re: [PATCH v2 3/5] lib: Add umoddi3 and udivmoddi4 of GCC library routines
In reply to Zong Lilib/udivmoddi4.c
Quoted 6 lines · Zong Li
lib/udivmoddi4.c new file +0
-0@@ -0,0 +1,309 @@
needs and SPDX tag.
lib/udivmoddi4.c line 5
Quoted 5 lines
lib/udivmoddi4.c new file +5
-0+/* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 3, or (at your option) any later +* version.
We can't take GPLv3 code for the kernel.
lib/udivmoddi4.c line 18
Quoted 7 lines
lib/udivmoddi4.c new file +7
-0+* Under Section 7 of GPL version 3, you are granted additional +* permissions described in the GCC Runtime Library Exception, version +* 3.1, as published by the Free Software Foundation. +* +* You should have received a copy of the GNU General Public License and +* a copy of the GCC Runtime Library Exception along with this program; +* see the files COPYING3 and COPYING.RUNTIME respectively.
unless this exception somehow counts (which I doubt), but for that we'd actually need it in the tree.
Quoted 17 lines · zongbox at gmail.com
This patches contain the modificaion as follows:
1. Fix up the building fail on RV32.
2. Add umoddi3 and udivmoddi4 functions for RV32.
3. Fix ioremap problem on RV32.Changes in v2:
- Retain the copyright notices from libgcc inumoddi3.candudivmoddi4.c.Vincent Chen (1):
RISC-V: Avoid corrupting the upper 32-bit ofphys_addr_tin ioremapZong Li (4):
RISC-V: Build tishift only on 64-bit
RISC-V: Use swiotlb on RV64 only
lib: Add umoddi3 and udivmoddi4 of GCC library routines
RISC-V: SelectGENERIC_LIB_UMODDI3on RV32
Quoted 11 lines
arch/riscv/Kconfig | 1 + arch/riscv/kernel/setup.c | 3 + arch/riscv/lib/Makefile | 3 +- arch/riscv/mm/ioremap.c | 2 +- lib/Kconfig | 3 + lib/Makefile | 1 + lib/udivmoddi4.c | 309 ++++++++++++++++++++++++++++++++++++++++++++++ lib/umoddi3.c | 34 +++++ 8 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 lib/udivmoddi4.c create mode 100644 lib/umoddi3.c
I like what this does, but there's a license issue here that Christoph pointed out. It'd be great to have RV32I systems booting 4.19, do you think there's a chance you can sort this out next week so we can get it into the last RC? That would help with the rv32i glibc process, as we'll actually be able to boot an upstream kernel.
It looks like the functions we have an issue with come from libgcc2.c, which doesn't change very much. As far as I can tell we might be able to get away with these functions from 4.2.1, which was licensed under the GPLv2. Here's the relevant functions on GCC's github mirror
https://github.com/gcc-mirror/gcc/blob/gcc-4_2_1-release/gcc/libgcc2.c#L559 https://github.com/gcc-mirror/gcc/blob/gcc-4_2_1-release/gcc/libgcc2.c#L844
These look very similar to what you send out. As far as I can tell, if you base your code on the GPLv2 version then this should be fine to include.
Thanks!
Palmer Dabbelt <[email protected]> ? 2018?9?29? ?? ??7:52???
Quoted 42 lines · zongbox at gmail.com
Quoted 17 lines
This patches contain the modificaion as follows:
1. Fix up the building fail on RV32.
2. Add umoddi3 and udivmoddi4 functions for RV32.
3. Fix ioremap problem on RV32.Changes in v2:
- Retain the copyright notices from libgcc inumoddi3.candudivmoddi4.c.Vincent Chen (1):
RISC-V: Avoid corrupting the upper 32-bit ofphys_addr_tin ioremapZong Li (4):
RISC-V: Build tishift only on 64-bit
RISC-V: Use swiotlb on RV64 only
lib: Add umoddi3 and udivmoddi4 of GCC library routines
RISC-V: SelectGENERIC_LIB_UMODDI3on RV32Quoted 11 lines
arch/riscv/Kconfig | 1 + arch/riscv/kernel/setup.c | 3 + arch/riscv/lib/Makefile | 3 +- arch/riscv/mm/ioremap.c | 2 +- lib/Kconfig | 3 + lib/Makefile | 1 + lib/udivmoddi4.c | 309 ++++++++++++++++++++++++++++++++++++++++++++++ lib/umoddi3.c | 34 +++++ 8 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 lib/udivmoddi4.c create mode 100644 lib/umoddi3.cI like what this does, but there's a license issue here that Christoph pointed out. It'd be great to have RV32I systems booting 4.19, do you think there's a chance you can sort this out next week so we can get it into the last RC? That would help with the rv32i glibc process, as we'll actually be able to boot an upstream kernel.
It looks like the functions we have an issue with come from
libgcc2.c, which doesn't change very much. As far as I can tell we might be able to get away with these functions from 4.2.1, which was licensed under the GPLv2. Here's the relevant functions on GCC's github mirror
Quoted 7 lines
https://github.com/gcc-mirror/gcc/blob/gcc-4_2_1-release/gcc/libgcc2.c#L559 https://github.com/gcc-mirror/gcc/blob/gcc-4_2_1-release/gcc/libgcc2.c#L844These look very similar to what you send out. As far as I can tell, if you base your code on the GPLv2 version then this should be fine to include.
Thanks!
Thanks for the help and useful information. I will modify the implementation and submit the next version.