Skip to contentSkip to conversation

Fix some bugs on RV32 build fail and issue.

PATCH Superseded Zong Li 3 participants 16 messages Sep 18, 2018 – Sep 26, 2018

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zong Li

author
#0 lore raw

cover Fix some bugs on RV32 build fail and issue.

This patches fix up the building fail, less function and other issue on RV32.

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          | 291 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/umoddi3.c             |  16 +++
 8 files changed, 318 insertions(+), 2 deletions(-)
 create mode 100644 lib/udivmoddi4.c
 create mode 100644 lib/umoddi3.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 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
index 445ec84..5739bd0 100644
@@ -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
author
#4 lore raw

PATCH 2/5 RISC-V: Use swiotlb on RV64 only

In reply to Zong Li

Only RV64 supports swiotlb.

---
 arch/riscv/kernel/setup.c | 3 +++
 1 file changed, 3 insertions(+)
arch/riscv/kernel/setup.c +3 -0
index aee6031..872a280 100644
@@ -227,7 +227,10 @@ void __init setup_arch(char **cmdline_p)
 	setup_bootmem();
 	paging_init();
 	unflatten_device_tree();
+
+#ifdef CONFIG_64bit
 	swiotlb_init(1);
+#endif
 
 #ifdef CONFIG_SMP
 	setup_smp();
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH 3/5 lib: Add umoddi3 and udivmoddi4 of GCC library routines

In reply to Zong Li

Add umoddi3 and udivmoddi4 support for 32-bit.

---
 lib/Kconfig      |   3 +
 lib/Makefile     |   1 +
 lib/udivmoddi4.c | 291 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/umoddi3.c    |  16 +++
 4 files changed, 311 insertions(+)
 create mode 100644 lib/udivmoddi4.c
 create mode 100644 lib/umoddi3.c
lib/Kconfig +3 -0
index a3928d4..d82f206 100644
@@ -621,3 +621,6 @@ config GENERIC_LIB_CMPDI2
 
 config GENERIC_LIB_UCMPDI2
 	bool
+
+config GENERIC_LIB_UMODDI3
+	bool
lib/Makefile +1 -0
index ca3f7eb..51bf24d 100644
@@ -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 +291 -0

291 lines not on this page · raw message

lib/umoddi3.c new file +16 -0
new file mode 100644
index 0000000..85b2b86
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#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
author
#13 lore raw

PATCH 4/5 RISC-V: Select GENERIC_LIB_UMODDI3 on RV32

In reply to Zong Li

On 32-bit, it need to use __umoddi3 by some drivers.

---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
index a344980..dc262fa 100644
@@ -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
author
#14 lore raw

PATCH 5/5 RISC-V: Avoid corrupting the upper 32-bit of phys_addr_t in ioremap

In reply to Zong Li

From: 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
index 70ef272..bd2f2db 100644
@@ -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
#7 lore raw

Re: [PATCH 3/5] lib: Add umoddi3 and udivmoddi4 of GCC library routines

In reply to Zong Li
Quoted 1 line · Zong Li

Add umoddi3 and udivmoddi4 support for 32-bit.

This probably wants a better explanation of why you need them.

lib/udivmoddi4.c line 1

Quoted 5 lines

index 0000000..69f2d36

lib/udivmoddi4.c new file +1 -0
@@ -0,0 +1,291 @@
+// SPDX-License-Identifier: GPL-2.0

Who wrote this code, where does it come from?

Reviewed-by on v1 5/5
#15 lore raw

Re: [PATCH 5/5] RISC-V: Avoid corrupting the upper 32-bit of phys_addr_t in ioremap

In reply to Zong Li
Quoted 8 lines · Zong Li

From: 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.

Looks fine,

author
#8 lore raw

Re: [PATCH 3/5] lib: Add umoddi3 and udivmoddi4 of GCC library routines

In reply to Christoph Hellwig

Christoph Hellwig <[email protected]> ? 2018?9?21? ?? ??3:00???

Quoted 6 lines · Zong Li
Quoted 1 line

Add umoddi3 and udivmoddi4 support for 32-bit.

This probably wants a better explanation of why you need them.

Quoted 7 lines

lib/udivmoddi4.c line 1

Quoted 5 lines

index 0000000..69f2d36

lib/udivmoddi4.c new file +1 -0
@@ -0,0 +1,291 @@
+// SPDX-License-Identifier: GPL-2.0

Who wrote this code, where does it come from?

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.

author
#3 lore raw

Re: [PATCH 1/5] RISC-V: Build tishift only on 64-bit

In reply to Christoph Hellwig

Christoph Hellwig <[email protected]> ? 2018?9?21? ?? ??2:58???

Quoted 8 lines · Zong Li
Quoted 3 lines

Only RV64 supports 128 integer size.

This looks fine. Just curious, what do we even need 128-bit integers for on riscv64? Did you see any issues if you drop it entirely?

You can refer to this issue, but I didn't try it.
https://github.com/riscv/riscv-linux/issues/136

#9 lore raw

Re: [PATCH 3/5] lib: Add umoddi3 and udivmoddi4 of GCC library routines

In reply to Zong Li
Quoted 5 lines · Zong Li

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.

You probably should use the macros from <asm/div64.h> instead.

Andreas.

Signature · 3 lines
Andreas Schwab, SUSE Labs, schwab at suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
#11 lore raw

Re: [PATCH 3/5] lib: Add umoddi3 and udivmoddi4 of GCC library routines

In reply to Zong Li
Quoted 8 lines · Zong Li

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.

I don't think libgcc is GPLv2 licensed, is it? Also please retain the copyright notices from libgcc.

author
#12 lore raw

Re: [PATCH 3/5] lib: Add umoddi3 and udivmoddi4 of GCC library routines

Christoph Hellwig <[email protected]> ? 2018?9?25? ?? ??11:25???

Quoted 11 lines · Zong Li
Quoted 8 lines

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.

Quoted 2 lines

I don't think libgcc is GPLv2 licensed, is it? Also please retain the copyright notices from libgcc.

I will give next version patch. Thanks.

author
#10 lore raw

Re: [PATCH 3/5] lib: Add umoddi3 and udivmoddi4 of GCC library routines

In reply to Andreas Schwab

Andreas Schwab <[email protected]> ? 2018?9?25? ?? ??3:20???

Quoted 10 lines · Zong Li
Quoted 6 lines

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.

You probably should use the macros from <asm/div64.h> instead.

Hi Andreas,

This doesn't work for me, the divisor of my case is also long long type.