[PATCH 06/11] io: move PIO_OFFSET to linux/io.h

Andrew Ballance posted 11 patches 9 months ago
[PATCH 06/11] io: move PIO_OFFSET to linux/io.h
Posted by Andrew Ballance 9 months ago
From: Fiona Behrens <me@kloenk.dev>

Move the non arch specific PIO size to linux/io.h.

This allows rust to access `PIO_OFFSET`, `PIO_MASK` and
`PIO_RESERVED`. This is required to implement `IO_COND` in rust.

Signed-off-by: Fiona Behrens <me@kloenk.dev>
Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
---
 include/linux/io.h | 13 +++++++++++++
 lib/iomap.c        | 13 -------------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/linux/io.h b/include/linux/io.h
index 6a6bc4d46d0a..df032061544a 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -12,6 +12,19 @@
 #include <asm/io.h>
 #include <asm/page.h>
 
+#ifndef HAVE_ARCH_PIO_SIZE
+/*
+ * We encode the physical PIO addresses (0-0xffff) into the
+ * pointer by offsetting them with a constant (0x10000) and
+ * assuming that all the low addresses are always PIO. That means
+ * we can do some sanity checks on the low bits, and don't
+ * need to just take things for granted.
+ */
+#define PIO_OFFSET	0x10000UL
+#define PIO_MASK	0x0ffffUL
+#define PIO_RESERVED	0x40000UL
+#endif
+
 struct device;
 
 #ifndef __iowrite32_copy
diff --git a/lib/iomap.c b/lib/iomap.c
index a65717cd86f7..e13cfe77c32f 100644
--- a/lib/iomap.c
+++ b/lib/iomap.c
@@ -24,19 +24,6 @@
  * implementation and should do their own copy.
  */
 
-#ifndef HAVE_ARCH_PIO_SIZE
-/*
- * We encode the physical PIO addresses (0-0xffff) into the
- * pointer by offsetting them with a constant (0x10000) and
- * assuming that all the low addresses are always PIO. That means
- * we can do some sanity checks on the low bits, and don't
- * need to just take things for granted.
- */
-#define PIO_OFFSET	0x10000UL
-#define PIO_MASK	0x0ffffUL
-#define PIO_RESERVED	0x40000UL
-#endif
-
 static void bad_io_access(unsigned long port, const char *access)
 {
 	static int count = 10;
-- 
2.49.0
Re: [PATCH 06/11] io: move PIO_OFFSET to linux/io.h
Posted by Andy Shevchenko 9 months ago
On Thu, May 08, 2025 at 10:15:19PM -0500, Andrew Ballance wrote:
> From: Fiona Behrens <me@kloenk.dev>
> 
> Move the non arch specific PIO size to linux/io.h.
> 
> This allows rust to access `PIO_OFFSET`, `PIO_MASK` and
> `PIO_RESERVED`. This is required to implement `IO_COND` in rust.

...

> +/*
> + * We encode the physical PIO addresses (0-0xffff) into the

I know this is the original text, but we have a chance to improve it a bit by
saying range more explicitly:

 * We encode the physical PIO addresses (0x0000-0xffff) into the

> + * pointer by offsetting them with a constant (0x10000) and
> + * assuming that all the low addresses are always PIO. That means
> + * we can do some sanity checks on the low bits, and don't
> + * need to just take things for granted.
> + */
> +#define PIO_OFFSET	0x10000UL
> +#define PIO_MASK	0x0ffffUL
> +#define PIO_RESERVED	0x40000UL
> +#endif


-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH 06/11] io: move PIO_OFFSET to linux/io.h
Posted by Arnd Bergmann 9 months ago
On Fri, May 9, 2025, at 05:15, Andrew Ballance wrote:
> From: Fiona Behrens <me@kloenk.dev>
>
> Move the non arch specific PIO size to linux/io.h.
>
> This allows rust to access `PIO_OFFSET`, `PIO_MASK` and
> `PIO_RESERVED`. This is required to implement `IO_COND` in rust.
>
> Signed-off-by: Fiona Behrens <me@kloenk.dev>
> Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>

This puts an implementation detail of the x86 specific
iomap() code (unfortunately named "GENERIC_IOMAP" for historic
reasons) into common code. Please don't do that.

We still have a couple of users of GENERIC_IOMAP outside of
x86, but they all work in subtly different ways, and I've
been thinking about better ways to handle those. Ideally
the nonstandard iomap variants (x86, uml, powerpc/powernv,
m68k/q40) should just implement their own ioread/iowrite
helpers out-of-line like we do on alpha and parisc, while
everyone else just aliases them to readl/writel.

      Arnd