* [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset
@ 2024-10-21 13:31 Julian Vetter
2024-10-21 13:31 ` [PATCH v10 1/4] " Julian Vetter
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-21 13:31 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 again for your remarks Arnd and Christoph! I have updated the
patchset, and placed the functions directly in asm-generic/io.h. I have
dropped the libs/iomem_copy.c and have updated/clarified the commit
message in the first patch.
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v10:
- Removed libs/iomem_copy.c again
- Replaced the three functions in asm-generic/io.h directly
- Updated description for the first patch to clarify the matter
- Slightly updated description in patches 2 to 4
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):
Replace fallback for IO memcpy and IO memset
arm64: Use new fallback IO memcpy/memset
csky: Use new fallback IO memcpy/memset
loongarch: Use new fallback 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 | 116 ++++++++++++++++++++++++++------
9 files changed, 98 insertions(+), 326 deletions(-)
delete mode 100644 arch/csky/kernel/io.c
delete mode 100644 arch/loongarch/kernel/io.c
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v10 1/4] Replace fallback for IO memcpy and IO memset
2024-10-21 13:31 [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset Julian Vetter
@ 2024-10-21 13:31 ` Julian Vetter
2024-10-21 13:31 ` [PATCH v10 2/4] arm64: Use new fallback IO memcpy/memset Julian Vetter
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-21 13:31 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
The fallback for IO memcpy and IO memset in asm-generic/io.h simply call
memcpy and memset. This might lead to alignment problems or faults on
architectures that do not define their own version and fall back to
these defaults.
This patch replaces the memcpy and memset. The new versions use
read{l,q} accessor functions, align accesses to machine word size, and
resort to byte accesses when the target memory is not machine word
aligned. So, architectures that were using the old fallback functions
(e.g., arc, mips, riscv, etc.) now have more resilient versions that
take IO memory constrains into account. Moreover, architectures with
similar implementations can use this new fallback versions as well, not
needing to implement their own.
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v10:
- Removed iomem_copy.c again
- Updated implementations directly in asm-generic/io.h
- Updated commit message to reflect the changes made in the patch
---
include/asm-generic/io.h | 116 ++++++++++++++++++++++++++++++++-------
1 file changed, 96 insertions(+), 20 deletions(-)
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index 80de699bf6af..00cbf8587586 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -7,10 +7,12 @@
#ifndef __ASM_GENERIC_IO_H
#define __ASM_GENERIC_IO_H
+#include <linux/align.h>
#include <asm/page.h> /* I/O is all done through memory accesses */
#include <linux/string.h> /* for memset() and memcpy() */
#include <linux/sizes.h>
#include <linux/types.h>
+#include <linux/unaligned.h>
#include <linux/instruction_pointer.h>
#ifdef CONFIG_GENERIC_IOMAP
@@ -1154,16 +1156,40 @@ static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
#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
+ * @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.
*/
-static inline void memset_io(volatile void __iomem *addr, int value,
- size_t size)
+static inline void memset_io(volatile void __iomem *dst, int c, size_t count)
{
- memset(__io_virt(addr), value, size);
+ 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--;
+ }
}
#endif
@@ -1171,34 +1197,84 @@ static inline void memset_io(volatile void __iomem *addr, int value,
#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
+ * @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.
*/
-static inline void memcpy_fromio(void *buffer,
- const volatile void __iomem *addr,
- size_t size)
-{
- memcpy(buffer, __io_virt(addr), size);
+static inline 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--;
+ }
}
#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
+ * 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.
*/
-static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer,
- size_t size)
-{
- memcpy(__io_virt(addr), buffer, size);
+static inline 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--;
+ }
}
#endif
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v10 2/4] arm64: Use new fallback IO memcpy/memset
2024-10-21 13:31 [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset Julian Vetter
2024-10-21 13:31 ` [PATCH v10 1/4] " Julian Vetter
@ 2024-10-21 13:31 ` Julian Vetter
2024-10-21 13:31 ` [PATCH v10 3/4] csky: " Julian Vetter
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-21 13:31 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 new fallback memcpy_{from,to}io and memset_io functions from
asm-generic/io.h 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 v10:
- Slightly updated commit message to clarify that on arm64 we now use
the fallback from asm-generic/io.h
---
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 [flat|nested] 7+ messages in thread
* [PATCH v10 3/4] csky: Use new fallback IO memcpy/memset
2024-10-21 13:31 [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset Julian Vetter
2024-10-21 13:31 ` [PATCH v10 1/4] " Julian Vetter
2024-10-21 13:31 ` [PATCH v10 2/4] arm64: Use new fallback IO memcpy/memset Julian Vetter
@ 2024-10-21 13:31 ` Julian Vetter
2024-10-21 13:31 ` [PATCH v10 4/4] loongarch: " Julian Vetter
2024-10-21 14:16 ` [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset David Laight
4 siblings, 0 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-21 13:31 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 new fallback memcpy_{from,to}io and memset_io functions from
asm-generic/io.h 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 v10:
- Slightly updated commit message to clarify that on csky we now use
the fallback from asm-generic/io.h
---
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 [flat|nested] 7+ messages in thread
* [PATCH v10 4/4] loongarch: Use new fallback IO memcpy/memset
2024-10-21 13:31 [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset Julian Vetter
` (2 preceding siblings ...)
2024-10-21 13:31 ` [PATCH v10 3/4] csky: " Julian Vetter
@ 2024-10-21 13:31 ` Julian Vetter
2024-10-21 14:16 ` [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset David Laight
4 siblings, 0 replies; 7+ messages in thread
From: Julian Vetter @ 2024-10-21 13:31 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 new fallback memcpy_{from,to}io and memset_io functions from
asm-generic/io.h on the loongarch processor architecture.
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v10:
- Slightly updated commit message to clarify that on loongarch we now
use the fallback from asm-generic/io.h
---
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 [flat|nested] 7+ messages in thread
* RE: [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset
2024-10-21 13:31 [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset Julian Vetter
` (3 preceding siblings ...)
2024-10-21 13:31 ` [PATCH v10 4/4] loongarch: " Julian Vetter
@ 2024-10-21 14:16 ` David Laight
2024-10-25 14:20 ` Arnd Bergmann
4 siblings, 1 reply; 7+ messages in thread
From: David Laight @ 2024-10-21 14:16 UTC (permalink / raw)
To: 'Julian Vetter',
Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren,
Huacai Chen, WANG Xuerui, Andrew Morton, Geert Uytterhoeven,
Richard Henderson, Niklas Schnelle, Takashi Iwai, Miquel Raynal,
Johannes Berg, Christoph Hellwig
Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch,
linux-arch, Yann Sionneau
From: Julian Vetter
> Sent: 21 October 2024 14:32
>
> Thank you again for your remarks Arnd and Christoph! I have updated the
> patchset, and placed the functions directly in asm-generic/io.h. I have
> dropped the libs/iomem_copy.c and have updated/clarified the commit
> message in the first patch.
Apart from build 'issues' what is the justification for inlining
these functions?
They are quite large for inlining and some drivers could easily
call them many times.
The I/O cycles themselves are likely to be slow enough that
the cost of a function call is pretty much likely to be noise.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset
2024-10-21 14:16 ` [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset David Laight
@ 2024-10-25 14:20 ` Arnd Bergmann
0 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2024-10-25 14:20 UTC (permalink / raw)
To: David Laight, Julian Vetter, Catalin Marinas, Will Deacon,
guoren, Huacai Chen, WANG Xuerui, Andrew Morton,
Geert Uytterhoeven, Richard Henderson, Niklas Schnelle,
Takashi Iwai, Miquel Raynal, Johannes Berg, Christoph Hellwig
Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch,
Linux-Arch, Yann Sionneau
On Mon, Oct 21, 2024, at 14:16, David Laight wrote:
> From: Julian Vetter
>> Sent: 21 October 2024 14:32
>>
>> Thank you again for your remarks Arnd and Christoph! I have updated the
>> patchset, and placed the functions directly in asm-generic/io.h. I have
>> dropped the libs/iomem_copy.c and have updated/clarified the commit
>> message in the first patch.
>
> Apart from build 'issues' what is the justification for inlining
> these functions?
I think I wasn't clear enough with my previous comment, and Julian
just misunderstood what I was asking him to do. Sorry about causing
extra work here.
> They are quite large for inlining and some drivers could easily
> call them many times.
>
> The I/O cycles themselves are likely to be slow enough that
> the cost of a function call is pretty much likely to be noise.
I'm not overly worried about the this, as the functions are
not that big and there are not that many callers. If a file
contains multiple calls to this function, we can expect the
compiler to be smart enough to keep it out of line, though it
still gets duplicated in each driver calling it.
The bit that I am worried about however is the extra #include
for linux/unaligned.h that pulls in fairly large headers
and may lead to circular header dependencies.
To be clear: what I had expected here was to not have any
changes to the v9 version of lib/iomem_copy.c and to simplify
the asm-generic/io.h change to the version below.
Arnd
---
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -1211,7 +1211,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
@@ -1220,15 +1219,10 @@ static inline void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
*
* 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);
-}
+void memset_io(volatile void __iomem *addr, int value, size_t 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
@@ -1237,16 +1231,11 @@ static inline void memset_io(volatile void __iomem *addr, int value,
*
* 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);
-}
+void memcpy_fromio(void *buffer, const volatile void __iomem *addr,
+ size_t 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
@@ -1255,11 +1244,8 @@ static inline void memcpy_fromio(void *buffer,
*
* 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);
-}
+void memcpy_toio(volatile void __iomem *addr, const void *buffer,
+ size_t size);
#endif
extern int devmem_is_allowed(unsigned long pfn);
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-25 14:20 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-21 13:31 [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset Julian Vetter
2024-10-21 13:31 ` [PATCH v10 1/4] " Julian Vetter
2024-10-21 13:31 ` [PATCH v10 2/4] arm64: Use new fallback IO memcpy/memset Julian Vetter
2024-10-21 13:31 ` [PATCH v10 3/4] csky: " Julian Vetter
2024-10-21 13:31 ` [PATCH v10 4/4] loongarch: " Julian Vetter
2024-10-21 14:16 ` [PATCH v10 0/4] Replace fallback for IO memcpy and IO memset David Laight
2024-10-25 14:20 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®