Skip to contentSkip to conversation

RISC-V: Build tishift only on 64-bit

PATCH Superseded Zong Li 3 participants 13 messages Oct 2, 2018 – Oct 3, 2018 1 message not in the archive

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Zong Li

author
#1 lore raw

PATCH v3 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
#3 lore raw

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

In reply to a message not in the archive

Only RV64 supports swiotlb. On RV32, it don't select the SWIOTLB.

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

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

In reply to a message not in the archive

Add 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 | 310 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/umoddi3.c    |  32 ++++++
 4 files changed, 346 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 +310 -0

310 lines not on this page · raw message

lib/umoddi3.c new file +32 -0
new file mode 100644
index 0000000..d7bbf0f
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.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 2 of the License, 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */
+
+#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
#6 lore raw

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

Quoted 3 lines

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.

Can you please mention which exact version of an external projected you imported things from? That will generally help if/when someone has to dig into diverging versions.

Quoted 9 lines

+++ b/lib/udivmoddi4.c

lib/udivmoddi4.c new file +7 -0
@@ -0,0 +1,310 @@
+// SPDX-License-Identifier: GPL-2.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 2 of the License, or
+ * (at your option) any later version.

lib/udivmoddi4.c line 17

Quoted 10 lines
lib/udivmoddi4.c new file +10 -0
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */

The SPDX tag was supposed to replace this boiler plate. On the other hand I'm surpriced there is no Copyright statement here - the FSF is usually very good about having them uptodate in every GNU project.

#7 lore raw

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

Quoted 23 lines · Christoph Hellwig
Quoted 3 lines

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.

Can you please mention which exact version of an external projected you imported things from? That will generally help if/when someone has to dig into diverging versions.

Quoted 15 lines

+++ b/lib/udivmoddi4.c

lib/udivmoddi4.c new file +13 -0
@@ -0,0 +1,310 @@
+// SPDX-License-Identifier: GPL-2.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 2 of the License, 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.
+ *
Quoted 8 lines

lib/udivmoddi4.c line 17

Quoted 4 lines
lib/udivmoddi4.c new file +4 -0
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */

The SPDX tag was supposed to replace this boiler plate. On the other hand I'm surpriced there is no Copyright statement here - the FSF is usually very good about having them uptodate in every GNU project.

I suggested he import the gcc-4.2.1 version, which has a big copyright notice

/* More subroutines needed by GCC output code on some machines. */ /* Compile this one with gcc. */
/* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.

This file is part of GCC.

GCC 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 2, or (at your option) any later version.

In addition to the permissions in the GNU General Public License, the Free Software Foundation gives you unlimited permission to link the compiled version of this file into combinations with other programs, and to distribute those combinations without any restriction coming from the use of this file. (The General Public License restrictions do apply in other respects; for example, they cover modification of the file, and distribution when not linked into a combine executable.)

GCC 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.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */

so it looks like something went wrong here. Zong: did you go back and re-construct this function from the GPLv2 source?

author
#8 lore raw

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

Palmer Dabbelt <[email protected]> ? 2018?10?2? ?? ??11:02???

Quoted 62 lines · Christoph Hellwig
Quoted 23 lines
Quoted 3 lines

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.

Can you please mention which exact version of an external projected you imported things from? That will generally help if/when someone has to dig into diverging versions.

Quoted 15 lines

+++ b/lib/udivmoddi4.c

lib/udivmoddi4.c new file +13 -0
@@ -0,0 +1,310 @@
+// SPDX-License-Identifier: GPL-2.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 2 of the License, 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.
+ *
Quoted 8 lines

lib/udivmoddi4.c line 17

Quoted 4 lines
lib/udivmoddi4.c new file +4 -0
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see the file COPYING, or write
+ * to the Free Software Foundation, Inc.
+ */

The SPDX tag was supposed to replace this boiler plate. On the other hand I'm surpriced there is no Copyright statement here - the FSF is usually very good about having them uptodate in every GNU project.

I suggested he import the gcc-4.2.1 version, which has a big copyright notice

/* More subroutines needed by GCC output code on some machines. */ /* Compile this one with gcc. */
/* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.

This file is part of GCC.

GCC 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 2, or (at your option) any later version.

In addition to the permissions in the GNU General Public License, the Free Software Foundation gives you unlimited permission to link the compiled version of this file into combinations with other programs, and to distribute those combinations without any restriction coming from the use of this file. (The General Public License restrictions do apply in other respects; for example, they cover modification of the file, and distribution when not linked into a combine executable.)

GCC 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.

Quoted 7 lines

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */

so it looks like something went wrong here. Zong: did you go back and re-construct this function from the GPLv2 source?

Yes, I re-construct this function from GCC 4.2.1. The copyright part, I referred to the other GCC routine copies in kernel such as ucmpdi2, muldi3, ashldi3 and so on, I found they removed the 'GCC' string, so I use the same copyright from these files.
I will re-write the copyright part and submit the next version. Thanks to all for help.

author
#9 lore raw

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

In reply to a message not in the archive

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
#11 lore raw

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

In reply to a message not in the archive

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
Reviewed-by on v3 5/5
#12 lore raw

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

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 good,

(and I'm pretty sure I reviewed this before..)

author
#13 lore raw

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

Christoph Hellwig <[email protected]> ? 2018?10?2? ?? ??10:51???

Quoted 9 lines · Zong Li
Quoted 7 lines

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.

Quoted 7 lines
Quoted 1 line

Looks good,

(and I'm pretty sure I reviewed this before..)

Hi Christoph,

Very sorry about that. I didn't notice I lose these review tags. Could you please help to review again in version 4 patches? Thank you.

Regards,
Zong