mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julian Vetter <julian@outer-limits.org>
To: Arnd Bergmann <arnd@arndb.de>, Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Julian Vetter <julian@outer-limits.org>
Subject: [PATCH] Add io_sync stubs to generic IO memcpy/memset
Date: Mon, 27 Jan 2025 11:04:07 +0100	[thread overview]
Message-ID: <20250127100407.866238-1-julian@outer-limits.org> (raw)

The recently added IO memcpy and memset functions lack support for
barriers or other sync functions before and/or after the transaction. To
convert more architectures to use the generic IO memcpy and memset
functions, add empty __pre_io_sync and __post_io_sync defines that can
be overwritten by individual architectures if needed.

Signed-off-by: Julian Vetter <julian@outer-limits.org>
---
 lib/iomem_copy.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lib/iomem_copy.c b/lib/iomem_copy.c
index dec7eaea60e0..2e81182dd4d3 100644
--- a/lib/iomem_copy.c
+++ b/lib/iomem_copy.c
@@ -9,6 +9,14 @@
 #include <linux/types.h>
 #include <linux/unaligned.h>
 
+#ifndef __pre_io_sync
+#define __pre_io_sync
+#endif
+
+#ifndef __post_io_sync
+#define __post_io_sync
+#endif
+
 #ifndef memset_io
 /**
  * memset_io() - Set a range of I/O memory to a constant value
@@ -24,6 +32,8 @@ void memset_io(volatile void __iomem *addr, int val, size_t count)
 
 	qc *= ~0UL / 0xff;
 
+	__pre_io_sync;
+
 	while (count && !IS_ALIGNED((long)addr, sizeof(long))) {
 		__raw_writeb(val, addr);
 		addr++;
@@ -46,6 +56,8 @@ void memset_io(volatile void __iomem *addr, int val, size_t count)
 		addr++;
 		count--;
 	}
+
+	__post_io_sync;
 }
 EXPORT_SYMBOL(memset_io);
 #endif
@@ -61,6 +73,8 @@ EXPORT_SYMBOL(memset_io);
  */
 void memcpy_fromio(void *dst, const volatile void __iomem *src, size_t count)
 {
+	__pre_io_sync;
+
 	while (count && !IS_ALIGNED((long)src, sizeof(long))) {
 		*(u8 *)dst = __raw_readb(src);
 		src++;
@@ -88,6 +102,8 @@ void memcpy_fromio(void *dst, const volatile void __iomem *src, size_t count)
 		dst++;
 		count--;
 	}
+
+	__post_io_sync
 }
 EXPORT_SYMBOL(memcpy_fromio);
 #endif
@@ -103,6 +119,8 @@ EXPORT_SYMBOL(memcpy_fromio);
  */
 void memcpy_toio(volatile void __iomem *dst, const void *src, size_t count)
 {
+	__pre_io_sync;
+
 	while (count && !IS_ALIGNED((long)dst, sizeof(long))) {
 		__raw_writeb(*(u8 *)src, dst);
 		src++;
@@ -129,6 +147,8 @@ void memcpy_toio(volatile void __iomem *dst, const void *src, size_t count)
 		dst++;
 		count--;
 	}
+
+	__post_io_sync;
 }
 EXPORT_SYMBOL(memcpy_toio);
 #endif
-- 
2.34.1


             reply	other threads:[~2025-01-27 10:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-27 10:04 Julian Vetter [this message]
2025-01-27 10:27 ` Arnd Bergmann
2025-01-27 14:11   ` Julian Vetter
2025-01-27 15:48     ` Arnd Bergmann
2025-01-28  8:32       ` Julian Vetter
2025-01-28  9:14         ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250127100407.866238-1-julian@outer-limits.org \
    --to=julian@outer-limits.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®