Generic Linux architectural discussions
 help / color / mirror / Atom feed
* [PATCH v9 0/4] Consolidate IO memcpy functions
@ 2024-10-10 12:36 Julian Vetter
  2024-10-10 12:36 ` [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c Julian Vetter
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-10 12:36 UTC (permalink / raw)
  To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
	WANG Xuerui, Andrew Morton, Geert Uytterhoeven, Richard Henderson,
	Niklas Schnelle, Takashi Iwai, Miquel Raynal, David Laight,
	Johannes Berg, Christoph Hellwig
  Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch, linux-arch,
	Yann Sionneau, Julian Vetter

Thank you for your remarks Arnd and Christoph. You're right the patches
got a bit out of hand. I have now guarded the prototypes as well with
'#ifndef' and I have dropped the other unnecessary patches for now.

Thank you Niklas for testing the changes on s390! I have dropped the
according patch for now. But I will send it to the s390 mailinglist as a
separate patch.

Thank you Takashi for ack'ing the patch 14. I will send this one as well
as a separate patch to the UM mailinglist.

Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v9:
- Moved functions into a new file iomem_copy.c which is built
  unconditionally
- Guard prototypes with '#ifndef memcpy_fromio', etc.
- Dropped patches 5 to 14 for now. I will send some of the changes in
  separate patches or patchsets to the appropriate mailinglists
- Added proper reviewed-by and acked-by to arm64 and csky patches

Changes for v8:
- Dropped the arch/um patch that adds dummy implementations for IO
  memcpy functions
- Added 3 new patches that fix the dependency problem for UM (added
  dependencies on HAS_IOMEM || INDIRECT_IOMEM)
- Added new patch for s390 to internally call the zpci_memcpy functions
  and not the generic ones from libs/iomap_copy.c
- Addressed reviewer comments and replaced 2 or 3 shifts by
  'qc *= ~0UL / 0xff;'
- Addressed reviewer comments on pasrisc (masking the int value)
- Addressed reviewer comments on alpha (masking the int value)

Changes for v7:
- Added dummy implementations for memcpy_{to,from}io and memset_io on um
  architecture so drivers that use these functions build for um
- Replaced all accesses and checks by long type
- Added function prototypes as extern to asm-generic/io.h
- Removed '__' from the 3 new function names
- Some archs implement their own version of these IO functions with
  slightly different prototypes. So, I added 3 new patches to align
  prototypes with new ones in iomap_copy.c + io.h

Changes for v6:
- Added include of linux/align.h to fix build on arm arch
- Replaced compile-time check by ifdef for the CONFIG_64BIT otherwise we
  get a warning for the 'qc << 32' for archs with 32bit int types
- Suffixed arch commits by arch name

Changes for v5:
- Added functions to iomap_copy.c as proposed by Arndt
- Removed again the new io_copy.c and related objects
- Removed GENERIC_IO_COPY symbol and instead rely on the existing
  HAS_IOMEM symbol
- Added prototypes of __memcpy_{to,from}io and __memset_io functions to
  asm-generic/io.h

Changes for v4:
- Replaced memcpy/memset in asm-generic/io.h by the new
  __memcpy_{to,from}io and __memset_io, so individual architectures can
  use it instead of using their own implementation.

Changes for v3:
- Replaced again 'if(IS_ENABLED(CONFIG_64BIT))' by '#ifdef CONFIG_64BIT'
  because on 32bit architectures (e.g., csky), __raw_{read,write}q are
  not defined. So, it leads to compilation errors

Changes for v2:
- Renamed io.c -> io_copy.c
- Updated flag to 'GENERIC_IO_COPY'
- Replaced pointer dereferences by 'put_unaligned()'/'get_unaligned()'
- Replaced '#ifdef CONFIG_64BIT' by 'if(IS_ENABLED(CONFIG_64BIT))'
- Removed '__raw_{read,write}_native' and replaced by
  'if(IS_ENABLED(CONFIG_64BIT))' -> '__raw_write{l,q}'
---
Julian Vetter (4):
  Consolidate IO memcpy/memset into iomem_copy.c
  arm64: Use generic IO memcpy/memset
  csky: Use generic IO memcpy/memset
  loongarch: Use generic IO memcpy/memset

 arch/arm64/include/asm/io.h     |  11 ---
 arch/arm64/kernel/io.c          |  87 ---------------------
 arch/csky/include/asm/io.h      |  11 ---
 arch/csky/kernel/Makefile       |   2 +-
 arch/csky/kernel/io.c           |  91 ----------------------
 arch/loongarch/include/asm/io.h |  10 ---
 arch/loongarch/kernel/Makefile  |   2 +-
 arch/loongarch/kernel/io.c      |  94 ----------------------
 include/asm-generic/io.h        |  62 +++------------
 lib/Makefile                    |   2 +-
 lib/iomem_copy.c                | 134 ++++++++++++++++++++++++++++++++
 11 files changed, 147 insertions(+), 359 deletions(-)
 delete mode 100644 arch/csky/kernel/io.c
 delete mode 100644 arch/loongarch/kernel/io.c
 create mode 100644 lib/iomem_copy.c

-- 
2.34.1






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

* [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c
  2024-10-10 12:36 [PATCH v9 0/4] Consolidate IO memcpy functions Julian Vetter
@ 2024-10-10 12:36 ` Julian Vetter
  2024-10-11  7:49   ` Christoph Hellwig
  2024-10-11  8:23   ` Arnd Bergmann
  2024-10-10 12:36 ` [PATCH v9 2/4] arm64: Use generic IO memcpy/memset Julian Vetter
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-10 12:36 UTC (permalink / raw)
  To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
	WANG Xuerui, Andrew Morton, Geert Uytterhoeven, Richard Henderson,
	Niklas Schnelle, Takashi Iwai, Miquel Raynal, David Laight,
	Johannes Berg, Christoph Hellwig
  Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch, linux-arch,
	Yann Sionneau, Julian Vetter

Various architectures have almost the same implementations for
memcpy_{to,from}io and memset_io functions. So, consolidate them
into a common lib/iomem_copy.c.

Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v9:
- Moved all functions to iomem_copy.c
- Build the new iomem_copy.c unconditionally
- Guard prototypes in asm-generic/io.h with ifdefs
---
 include/asm-generic/io.h |  62 +++---------------
 lib/Makefile             |   2 +-
 lib/iomem_copy.c         | 134 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 145 insertions(+), 53 deletions(-)
 create mode 100644 lib/iomem_copy.c

diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index 80de699bf6af..4ab47ef7095f 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -102,6 +102,16 @@ static inline void log_post_read_mmio(u64 val, u8 width, const volatile void __i
 
 #endif /* CONFIG_TRACE_MMIO_ACCESS */
 
+#ifndef memcpy_fromio
+void memcpy_fromio(void *to, const volatile void __iomem *from, size_t count);
+#endif
+#ifndef memcpy_toio
+void memcpy_toio(volatile void __iomem *to, const void *from, size_t count);
+#endif
+#ifndef memset_io
+void memset_io(volatile void __iomem *dst, int c, size_t count);
+#endif
+
 /*
  * __raw_{read,write}{b,w,l,q}() access memory in native endianness.
  *
@@ -1150,58 +1160,6 @@ static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
 }
 #endif
 
-#ifndef memset_io
-#define memset_io memset_io
-/**
- * memset_io	Set a range of I/O memory to a constant value
- * @addr:	The beginning of the I/O-memory range to set
- * @val:	The value to set the memory to
- * @count:	The number of bytes to set
- *
- * Set a range of I/O memory to a given value.
- */
-static inline void memset_io(volatile void __iomem *addr, int value,
-			     size_t size)
-{
-	memset(__io_virt(addr), value, size);
-}
-#endif
-
-#ifndef memcpy_fromio
-#define memcpy_fromio memcpy_fromio
-/**
- * memcpy_fromio	Copy a block of data from I/O memory
- * @dst:		The (RAM) destination for the copy
- * @src:		The (I/O memory) source for the data
- * @count:		The number of bytes to copy
- *
- * Copy a block of data from I/O memory.
- */
-static inline void memcpy_fromio(void *buffer,
-				 const volatile void __iomem *addr,
-				 size_t size)
-{
-	memcpy(buffer, __io_virt(addr), size);
-}
-#endif
-
-#ifndef memcpy_toio
-#define memcpy_toio memcpy_toio
-/**
- * memcpy_toio		Copy a block of data into I/O memory
- * @dst:		The (I/O memory) destination for the copy
- * @src:		The (RAM) source for the data
- * @count:		The number of bytes to copy
- *
- * Copy a block of data to I/O memory.
- */
-static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer,
-			       size_t size)
-{
-	memcpy(__io_virt(addr), buffer, size);
-}
-#endif
-
 extern int devmem_is_allowed(unsigned long pfn);
 
 #endif /* __KERNEL__ */
diff --git a/lib/Makefile b/lib/Makefile
index 773adf88af41..db4717538fad 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -35,7 +35,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
 	 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
 	 nmi_backtrace.o win_minmax.o memcat_p.o \
-	 buildid.o objpool.o union_find.o
+	 buildid.o objpool.o union_find.o iomem_copy.o
 
 lib-$(CONFIG_PRINTK) += dump_stack.o
 lib-$(CONFIG_SMP) += cpumask.o
diff --git a/lib/iomem_copy.c b/lib/iomem_copy.c
new file mode 100644
index 000000000000..4de710c2a9f0
--- /dev/null
+++ b/lib/iomem_copy.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2024 Kalray, Inc.  All Rights Reserved.
+ */
+
+#include <linux/align.h>
+#include <linux/export.h>
+#include <linux/io.h>
+#include <linux/types.h>
+#include <linux/unaligned.h>
+
+#ifndef memcpy_fromio
+/**
+ * memcpy_fromio	Copy a block of data from I/O memory
+ * @to:			The (RAM) destination for the copy
+ * @from:		The (I/O memory) source for the data
+ * @count:		The number of bytes to copy
+ *
+ * Copy a block of data from I/O memory.
+ */
+void memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
+{
+	while (count && !IS_ALIGNED((long)from, sizeof(long))) {
+		*(u8 *)to = __raw_readb(from);
+		from++;
+		to++;
+		count--;
+	}
+
+	while (count >= sizeof(long)) {
+#ifdef CONFIG_64BIT
+		long val = __raw_readq(from);
+#else
+		long val = __raw_readl(from);
+#endif
+		put_unaligned(val, (long *)to);
+
+
+		from += sizeof(long);
+		to += sizeof(long);
+		count -= sizeof(long);
+	}
+
+	while (count) {
+		*(u8 *)to = __raw_readb(from);
+		from++;
+		to++;
+		count--;
+	}
+}
+EXPORT_SYMBOL(memcpy_fromio);
+#endif
+
+#ifndef memcpy_toio
+/**
+ * memcpy_toio		Copy a block of data into I/O memory
+ * @to:			The (I/O memory) destination for the copy
+ * @from:		The (RAM) source for the data
+ * @count:		The number of bytes to copy
+ *
+ * Copy a block of data to I/O memory.
+ */
+void memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
+{
+	while (count && !IS_ALIGNED((long)to, sizeof(long))) {
+		__raw_writeb(*(u8 *)from, to);
+		from++;
+		to++;
+		count--;
+	}
+
+	while (count >= sizeof(long)) {
+		long val = get_unaligned((long *)from);
+#ifdef CONFIG_64BIT
+		__raw_writeq(val, to);
+#else
+		__raw_writel(val, to);
+#endif
+
+		from += sizeof(long);
+		to += sizeof(long);
+		count -= sizeof(long);
+	}
+
+	while (count) {
+		__raw_writeb(*(u8 *)from, to);
+		from++;
+		to++;
+		count--;
+	}
+}
+EXPORT_SYMBOL(memcpy_toio);
+#endif
+
+#ifndef memset_io
+/**
+ * memset_io		Set a range of I/O memory to a constant value
+ * @dst:		The beginning of the I/O-memory range to set
+ * @c:			The value to set the memory to
+ * @count:		The number of bytes to set
+ *
+ * Set a range of I/O memory to a given value.
+ */
+void memset_io(volatile void __iomem *dst, int c, size_t count)
+{
+	long qc = (u8)c;
+
+	qc *= ~0UL / 0xff;
+
+	while (count && !IS_ALIGNED((long)dst, sizeof(long))) {
+		__raw_writeb(c, dst);
+		dst++;
+		count--;
+	}
+
+	while (count >= sizeof(long)) {
+#ifdef CONFIG_64BIT
+		__raw_writeq(qc, dst);
+#else
+		__raw_writel(qc, dst);
+#endif
+
+		dst += sizeof(long);
+		count -= sizeof(long);
+	}
+
+	while (count) {
+		__raw_writeb(c, dst);
+		dst++;
+		count--;
+	}
+}
+EXPORT_SYMBOL(memset_io);
+#endif
-- 
2.34.1






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

* [PATCH v9 2/4] arm64: Use generic IO memcpy/memset
  2024-10-10 12:36 [PATCH v9 0/4] Consolidate IO memcpy functions Julian Vetter
  2024-10-10 12:36 ` [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c Julian Vetter
@ 2024-10-10 12:36 ` Julian Vetter
  2024-10-10 12:36 ` [PATCH v9 3/4] csky: " Julian Vetter
  2024-10-10 12:36 ` [PATCH v9 4/4] loongarch: " Julian Vetter
  3 siblings, 0 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-10 12:36 UTC (permalink / raw)
  To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
	WANG Xuerui, Andrew Morton, Geert Uytterhoeven, Richard Henderson,
	Niklas Schnelle, Takashi Iwai, Miquel Raynal, David Laight,
	Johannes Berg, Christoph Hellwig
  Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch, linux-arch,
	Yann Sionneau, Julian Vetter

Use the generic memcpy_{from,to}io and memset_io functions on the
arm64 processor architecture.

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v9:
- No changes
---
 arch/arm64/include/asm/io.h | 11 -----
 arch/arm64/kernel/io.c      | 87 -------------------------------------
 2 files changed, 98 deletions(-)

diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
index 1ada23a6ec19..463067bffdfd 100644
--- a/arch/arm64/include/asm/io.h
+++ b/arch/arm64/include/asm/io.h
@@ -128,17 +128,6 @@ static __always_inline u64 __raw_readq(const volatile void __iomem *addr)
 #define IO_SPACE_LIMIT		(PCI_IO_SIZE - 1)
 #define PCI_IOBASE		((void __iomem *)PCI_IO_START)
 
-/*
- * String version of I/O memory access operations.
- */
-extern void __memcpy_fromio(void *, const volatile void __iomem *, size_t);
-extern void __memcpy_toio(volatile void __iomem *, const void *, size_t);
-extern void __memset_io(volatile void __iomem *, int, size_t);
-
-#define memset_io(c,v,l)	__memset_io((c),(v),(l))
-#define memcpy_fromio(a,c,l)	__memcpy_fromio((a),(c),(l))
-#define memcpy_toio(c,a,l)	__memcpy_toio((c),(a),(l))
-
 /*
  * The ARM64 iowrite implementation is intended to support drivers that want to
  * use write combining. For instance PCI drivers using write combining with a 64
diff --git a/arch/arm64/kernel/io.c b/arch/arm64/kernel/io.c
index ef48089fbfe1..fe86ada23c7d 100644
--- a/arch/arm64/kernel/io.c
+++ b/arch/arm64/kernel/io.c
@@ -9,34 +9,6 @@
 #include <linux/types.h>
 #include <linux/io.h>
 
-/*
- * Copy data from IO memory space to "real" memory space.
- */
-void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
-{
-	while (count && !IS_ALIGNED((unsigned long)from, 8)) {
-		*(u8 *)to = __raw_readb(from);
-		from++;
-		to++;
-		count--;
-	}
-
-	while (count >= 8) {
-		*(u64 *)to = __raw_readq(from);
-		from += 8;
-		to += 8;
-		count -= 8;
-	}
-
-	while (count) {
-		*(u8 *)to = __raw_readb(from);
-		from++;
-		to++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memcpy_fromio);
-
 /*
  * This generates a memcpy that works on a from/to address which is aligned to
  * bits. Count is in terms of the number of bits sized quantities to copy. It
@@ -78,62 +50,3 @@ void __iowrite32_copy_full(void __iomem *to, const void *from, size_t count)
 	dgh();
 }
 EXPORT_SYMBOL(__iowrite32_copy_full);
-
-/*
- * Copy data from "real" memory space to IO memory space.
- */
-void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
-{
-	while (count && !IS_ALIGNED((unsigned long)to, 8)) {
-		__raw_writeb(*(u8 *)from, to);
-		from++;
-		to++;
-		count--;
-	}
-
-	while (count >= 8) {
-		__raw_writeq(*(u64 *)from, to);
-		from += 8;
-		to += 8;
-		count -= 8;
-	}
-
-	while (count) {
-		__raw_writeb(*(u8 *)from, to);
-		from++;
-		to++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memcpy_toio);
-
-/*
- * "memset" on IO memory space.
- */
-void __memset_io(volatile void __iomem *dst, int c, size_t count)
-{
-	u64 qc = (u8)c;
-
-	qc |= qc << 8;
-	qc |= qc << 16;
-	qc |= qc << 32;
-
-	while (count && !IS_ALIGNED((unsigned long)dst, 8)) {
-		__raw_writeb(c, dst);
-		dst++;
-		count--;
-	}
-
-	while (count >= 8) {
-		__raw_writeq(qc, dst);
-		dst += 8;
-		count -= 8;
-	}
-
-	while (count) {
-		__raw_writeb(c, dst);
-		dst++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memset_io);
-- 
2.34.1






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

* [PATCH v9 3/4] csky: Use generic IO memcpy/memset
  2024-10-10 12:36 [PATCH v9 0/4] Consolidate IO memcpy functions Julian Vetter
  2024-10-10 12:36 ` [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c Julian Vetter
  2024-10-10 12:36 ` [PATCH v9 2/4] arm64: Use generic IO memcpy/memset Julian Vetter
@ 2024-10-10 12:36 ` Julian Vetter
  2024-10-10 12:36 ` [PATCH v9 4/4] loongarch: " Julian Vetter
  3 siblings, 0 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-10 12:36 UTC (permalink / raw)
  To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
	WANG Xuerui, Andrew Morton, Geert Uytterhoeven, Richard Henderson,
	Niklas Schnelle, Takashi Iwai, Miquel Raynal, David Laight,
	Johannes Berg, Christoph Hellwig
  Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch, linux-arch,
	Yann Sionneau, Julian Vetter

Use the generic memcpy_{from,to}io and memset_io functions on the csky
processor architecture.

Acked-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v9:
- No changes
---
 arch/csky/include/asm/io.h | 11 -----
 arch/csky/kernel/Makefile  |  2 +-
 arch/csky/kernel/io.c      | 91 --------------------------------------
 3 files changed, 1 insertion(+), 103 deletions(-)
 delete mode 100644 arch/csky/kernel/io.c

diff --git a/arch/csky/include/asm/io.h b/arch/csky/include/asm/io.h
index 4725bb977b0f..ed53f0b47388 100644
--- a/arch/csky/include/asm/io.h
+++ b/arch/csky/include/asm/io.h
@@ -31,17 +31,6 @@
 #define writel(v,c)		({ wmb(); writel_relaxed((v),(c)); mb(); })
 #endif
 
-/*
- * String version of I/O memory access operations.
- */
-extern void __memcpy_fromio(void *, const volatile void __iomem *, size_t);
-extern void __memcpy_toio(volatile void __iomem *, const void *, size_t);
-extern void __memset_io(volatile void __iomem *, int, size_t);
-
-#define memset_io(c,v,l)        __memset_io((c),(v),(l))
-#define memcpy_fromio(a,c,l)    __memcpy_fromio((a),(c),(l))
-#define memcpy_toio(c,a,l)      __memcpy_toio((c),(a),(l))
-
 /*
  * I/O memory mapping functions.
  */
diff --git a/arch/csky/kernel/Makefile b/arch/csky/kernel/Makefile
index 8a868316b912..de1c3472e8f0 100644
--- a/arch/csky/kernel/Makefile
+++ b/arch/csky/kernel/Makefile
@@ -2,7 +2,7 @@
 extra-y := vmlinux.lds
 
 obj-y += head.o entry.o atomic.o signal.o traps.o irq.o time.o vdso.o vdso/
-obj-y += power.o syscall.o syscall_table.o setup.o io.o
+obj-y += power.o syscall.o syscall_table.o setup.o
 obj-y += process.o cpu-probe.o ptrace.o stacktrace.o
 obj-y += probes/
 
diff --git a/arch/csky/kernel/io.c b/arch/csky/kernel/io.c
deleted file mode 100644
index 5883f13fa2b1..000000000000
--- a/arch/csky/kernel/io.c
+++ /dev/null
@@ -1,91 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/export.h>
-#include <linux/types.h>
-#include <linux/io.h>
-
-/*
- * Copy data from IO memory space to "real" memory space.
- */
-void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
-{
-	while (count && !IS_ALIGNED((unsigned long)from, 4)) {
-		*(u8 *)to = __raw_readb(from);
-		from++;
-		to++;
-		count--;
-	}
-
-	while (count >= 4) {
-		*(u32 *)to = __raw_readl(from);
-		from += 4;
-		to += 4;
-		count -= 4;
-	}
-
-	while (count) {
-		*(u8 *)to = __raw_readb(from);
-		from++;
-		to++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memcpy_fromio);
-
-/*
- * Copy data from "real" memory space to IO memory space.
- */
-void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
-{
-	while (count && !IS_ALIGNED((unsigned long)to, 4)) {
-		__raw_writeb(*(u8 *)from, to);
-		from++;
-		to++;
-		count--;
-	}
-
-	while (count >= 4) {
-		__raw_writel(*(u32 *)from, to);
-		from += 4;
-		to += 4;
-		count -= 4;
-	}
-
-	while (count) {
-		__raw_writeb(*(u8 *)from, to);
-		from++;
-		to++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memcpy_toio);
-
-/*
- * "memset" on IO memory space.
- */
-void __memset_io(volatile void __iomem *dst, int c, size_t count)
-{
-	u32 qc = (u8)c;
-
-	qc |= qc << 8;
-	qc |= qc << 16;
-
-	while (count && !IS_ALIGNED((unsigned long)dst, 4)) {
-		__raw_writeb(c, dst);
-		dst++;
-		count--;
-	}
-
-	while (count >= 4) {
-		__raw_writel(qc, dst);
-		dst += 4;
-		count -= 4;
-	}
-
-	while (count) {
-		__raw_writeb(c, dst);
-		dst++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memset_io);
-- 
2.34.1






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

* [PATCH v9 4/4] loongarch: Use generic IO memcpy/memset
  2024-10-10 12:36 [PATCH v9 0/4] Consolidate IO memcpy functions Julian Vetter
                   ` (2 preceding siblings ...)
  2024-10-10 12:36 ` [PATCH v9 3/4] csky: " Julian Vetter
@ 2024-10-10 12:36 ` Julian Vetter
  3 siblings, 0 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-10 12:36 UTC (permalink / raw)
  To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
	WANG Xuerui, Andrew Morton, Geert Uytterhoeven, Richard Henderson,
	Niklas Schnelle, Takashi Iwai, Miquel Raynal, David Laight,
	Johannes Berg, Christoph Hellwig
  Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch, linux-arch,
	Yann Sionneau, Julian Vetter

Use the generic memcpy_{from,to}io and memset_io functions on the
loongarch processor architecture.

Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v9:
- No changes
---
 arch/loongarch/include/asm/io.h | 10 ----
 arch/loongarch/kernel/Makefile  |  2 +-
 arch/loongarch/kernel/io.c      | 94 ---------------------------------
 3 files changed, 1 insertion(+), 105 deletions(-)
 delete mode 100644 arch/loongarch/kernel/io.c

diff --git a/arch/loongarch/include/asm/io.h b/arch/loongarch/include/asm/io.h
index 5e95a60df180..e77a56eaf906 100644
--- a/arch/loongarch/include/asm/io.h
+++ b/arch/loongarch/include/asm/io.h
@@ -62,16 +62,6 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
 
 #define mmiowb() wmb()
 
-/*
- * String version of I/O memory access operations.
- */
-extern void __memset_io(volatile void __iomem *dst, int c, size_t count);
-extern void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count);
-extern void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count);
-#define memset_io(c, v, l)     __memset_io((c), (v), (l))
-#define memcpy_fromio(a, c, l) __memcpy_fromio((a), (c), (l))
-#define memcpy_toio(c, a, l)   __memcpy_toio((c), (a), (l))
-
 #define __io_aw() mmiowb()
 
 #ifdef CONFIG_KFENCE
diff --git a/arch/loongarch/kernel/Makefile b/arch/loongarch/kernel/Makefile
index c9bfeda89e40..9497968ee158 100644
--- a/arch/loongarch/kernel/Makefile
+++ b/arch/loongarch/kernel/Makefile
@@ -8,7 +8,7 @@ OBJECT_FILES_NON_STANDARD_head.o := y
 extra-y		:= vmlinux.lds
 
 obj-y		+= head.o cpu-probe.o cacheinfo.o env.o setup.o entry.o genex.o \
-		   traps.o irq.o idle.o process.o dma.o mem.o io.o reset.o switch.o \
+		   traps.o irq.o idle.o process.o dma.o mem.o reset.o switch.o \
 		   elf.o syscall.o signal.o time.o topology.o inst.o ptrace.o vdso.o \
 		   alternative.o unwind.o
 
diff --git a/arch/loongarch/kernel/io.c b/arch/loongarch/kernel/io.c
deleted file mode 100644
index cb85bda5a6ad..000000000000
--- a/arch/loongarch/kernel/io.c
+++ /dev/null
@@ -1,94 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
- */
-#include <linux/export.h>
-#include <linux/types.h>
-#include <linux/io.h>
-
-/*
- * Copy data from IO memory space to "real" memory space.
- */
-void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
-{
-	while (count && !IS_ALIGNED((unsigned long)from, 8)) {
-		*(u8 *)to = __raw_readb(from);
-		from++;
-		to++;
-		count--;
-	}
-
-	while (count >= 8) {
-		*(u64 *)to = __raw_readq(from);
-		from += 8;
-		to += 8;
-		count -= 8;
-	}
-
-	while (count) {
-		*(u8 *)to = __raw_readb(from);
-		from++;
-		to++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memcpy_fromio);
-
-/*
- * Copy data from "real" memory space to IO memory space.
- */
-void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
-{
-	while (count && !IS_ALIGNED((unsigned long)to, 8)) {
-		__raw_writeb(*(u8 *)from, to);
-		from++;
-		to++;
-		count--;
-	}
-
-	while (count >= 8) {
-		__raw_writeq(*(u64 *)from, to);
-		from += 8;
-		to += 8;
-		count -= 8;
-	}
-
-	while (count) {
-		__raw_writeb(*(u8 *)from, to);
-		from++;
-		to++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memcpy_toio);
-
-/*
- * "memset" on IO memory space.
- */
-void __memset_io(volatile void __iomem *dst, int c, size_t count)
-{
-	u64 qc = (u8)c;
-
-	qc |= qc << 8;
-	qc |= qc << 16;
-	qc |= qc << 32;
-
-	while (count && !IS_ALIGNED((unsigned long)dst, 8)) {
-		__raw_writeb(c, dst);
-		dst++;
-		count--;
-	}
-
-	while (count >= 8) {
-		__raw_writeq(qc, dst);
-		dst += 8;
-		count -= 8;
-	}
-
-	while (count) {
-		__raw_writeb(c, dst);
-		dst++;
-		count--;
-	}
-}
-EXPORT_SYMBOL(__memset_io);
-- 
2.34.1






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

* Re: [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c
  2024-10-10 12:36 ` [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c Julian Vetter
@ 2024-10-11  7:49   ` Christoph Hellwig
  2024-10-11  8:23   ` Arnd Bergmann
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2024-10-11  7:49 UTC (permalink / raw)
  To: Julian Vetter
  Cc: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
	WANG Xuerui, Andrew Morton, Geert Uytterhoeven, Richard Henderson,
	Niklas Schnelle, Takashi Iwai, Miquel Raynal, David Laight,
	Johannes Berg, Christoph Hellwig, linux-arm-kernel, linux-kernel,
	linux-csky, loongarch, linux-arch, Yann Sionneau

On Thu, Oct 10, 2024 at 02:36:24PM +0200, Julian Vetter wrote:
> Various architectures have almost the same implementations for
> memcpy_{to,from}io and memset_io functions. So, consolidate them
> into a common lib/iomem_copy.c.

That might be the final intent of this seris, but what this patch does is
to replace the trivial memset/memcpy inline implementations with a more 
complex one that actually use the accessors.

So this actually changes behavior for those architectures that did not
provide them before quite a lot.  You'll need to explain in more
detail why that is safe and desireable.


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

* Re: [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c
  2024-10-10 12:36 ` [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c Julian Vetter
  2024-10-11  7:49   ` Christoph Hellwig
@ 2024-10-11  8:23   ` Arnd Bergmann
  1 sibling, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2024-10-11  8:23 UTC (permalink / raw)
  To: Julian Vetter, Catalin Marinas, Will Deacon, guoren, Huacai Chen,
	WANG Xuerui, Andrew Morton, Geert Uytterhoeven, Richard Henderson,
	Niklas Schnelle, Takashi Iwai, Miquel Raynal, David Laight,
	Johannes Berg, Christoph Hellwig
  Cc: linux-arm-kernel, linux-kernel, linux-csky@vger.kernel.org,
	loongarch, Linux-Arch, Yann Sionneau

On Thu, Oct 10, 2024, at 12:36, Julian Vetter wrote:
> Various architectures have almost the same implementations for
> memcpy_{to,from}io and memset_io functions. So, consolidate them
> into a common lib/iomem_copy.c.
>
> Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
> Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
> ---
> Changes for v9:
> - Moved all functions to iomem_copy.c
> - Build the new iomem_copy.c unconditionally
> - Guard prototypes in asm-generic/io.h with ifdefs

I'm happy with the patch contents, but it looks like you forgot
to update the description as this is not what this version of the
patch does: Instead of consolidating the identical versions (which
you do in patches 2-4), this changes the ones that use the
memcpy/memset fallback: arc, microblaze, mips, nios2, openrisc,
riscv, and xtensa.

> --- a/include/asm-generic/io.h
> +++ b/include/asm-generic/io.h
> @@ -102,6 +102,16 @@ static inline void log_post_read_mmio(u64 val, u8 
> width, const volatile void __i
> 
>  #endif /* CONFIG_TRACE_MMIO_ACCESS */
> 
> +#ifndef memcpy_fromio
> +void memcpy_fromio(void *to, const volatile void __iomem *from, size_t 
> count);
> +#endif
> +#ifndef memcpy_toio
> +void memcpy_toio(volatile void __iomem *to, const void *from, size_t 
> count);
> +#endif
> +#ifndef memset_io
> +void memset_io(volatile void __iomem *dst, int c, size_t count);
> +#endif
> +
>  /*
>   * __raw_{read,write}{b,w,l,q}() access memory in native endianness.
>   *
> @@ -1150,58 +1160,6 @@ static inline void 
> unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
>  }
>  #endif
> 
> -#ifndef memset_io
> -#define memset_io memset_io
> -/**
> - * memset_io	Set a range of I/O memory to a constant value
> - * @addr:	The beginning of the I/O-memory range to set
> - * @val:	The value to set the memory to
> - * @count:	The number of bytes to set
> - *
> - * Set a range of I/O memory to a given value.
> - */
> -static inline void memset_io(volatile void __iomem *addr, int value,
> -			     size_t size)
> -{
> -	memset(__io_virt(addr), value, size);
> -}
> -#endif

Unless there is a technical reason to move the location of
these I think it would be clearer to change it in place
and keep the three #ifdef but replace the contents.

You can also choose to add the definition in one patch
and then change the header in the next patch, which would
let you have more descriptive changelog texts for the
new common implementation and the second patch that changes
the fallback.

     Arnd

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

end of thread, other threads:[~2024-10-11  8:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-10 12:36 [PATCH v9 0/4] Consolidate IO memcpy functions Julian Vetter
2024-10-10 12:36 ` [PATCH v9 1/4] Consolidate IO memcpy/memset into iomem_copy.c Julian Vetter
2024-10-11  7:49   ` Christoph Hellwig
2024-10-11  8:23   ` Arnd Bergmann
2024-10-10 12:36 ` [PATCH v9 2/4] arm64: Use generic IO memcpy/memset Julian Vetter
2024-10-10 12:36 ` [PATCH v9 3/4] csky: " Julian Vetter
2024-10-10 12:36 ` [PATCH v9 4/4] loongarch: " Julian Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox