Skip to contentSkip to conversation

arch/*/io.h: remove ioremap_uc in some architectures

PATCH Applied Baoquan He 6 participants 14 messages Sep 21, 2023 – Oct 26, 2023

Subsystems (12)
lore
Share & tools
lore

Baoquan He

author
#0 lore raw

v5 cover arch/*/io.h: remove ioremap_uc in some architectures

This patchset tries to remove ioremap_uc() in the current architectures except of x86 and ia64. They will use the default ioremap_uc version in <asm-generic/io.h> which returns NULL. Anyone who wants to add new invocation of ioremap_uc(), please consider using ioremap() instead or adding a new ARCH specific ioremap_uc(), or refer to the callsite in drivers/video/fbdev/aty/atyfb_base.c.

This change won't cuase breakage to the current kernel because in the only ioremap_uc callsite, an adjustment is made to eliminate impact in patch 1 of this series.

To get rid of all of them other than x86 and ia64, add asm-generic/io.h to asm/io.h of mips ARCH. With this adding, we can get rid of the ioremap_uc() in mips too. This is done in patch 2. And a followup patch 4 is added to remove duplicated code according to Arnd's suggestion.

Test:
=====
Except of Jiaxun's efficient testing on patch 2/4, I also did cross compiling of this series on mips64, building passed.

History:
=======
v4->v5:
- In v4, Thomas reported that adding <asm-generic/io.h> including into mips always cause crash on his malta qemu. Finally, Jiaxun stood up to take over the patch 2/4 and make it work. This patchset collects Jiaxun's patch v5 and add Arnd's tag. Thanks to Jiaxun.
- Meanwhile, the old patch 4/4 need be adjusted because Jiaxun has done some removal of duplicated codes in <asm/io.h>.
- Add reviewers' tags from v4.
v3->v4:
- Add patch 1 to adjust code in the only ioremap_uc() callsite so that later removing ioremap_uc() won't cause breakage.
- Update log and document writing in patch 3.
- Add followup patch 4 to clean up duplicated code in asm/io.h of MIPS.
v2->v3:
- In patch 1, move those macro definition of functio near its function declaration according to Arnd's suggestion. And remove the unneeded change in asm/mmiowb.h introduced in old version.
- In patch 2, clean up and rewrite the messy document related to ioremap_uc() in Documentation/driver-api/device-io.rst.
v1->v2:
- Update log of patch 2, and document related to ioremap_uc() according to Geert's comment.
- Add Geert's Acked-by.

Arnd Bergmann (1):
video: fbdev: atyfb: only use ioremap_uc() on i386 and ia64

Baoquan He (2):
arch/*/io.h: remove ioremap_uc in some architectures
mips: io: remove duplicated codes

Jiaxun Yang (1):
mips: add <asm-generic/io.h> including

 Documentation/driver-api/device-io.rst |   9 +-
 arch/alpha/include/asm/io.h            |   1 -
 arch/hexagon/include/asm/io.h          |   3 -
 arch/m68k/include/asm/kmap.h           |   1 -
 arch/mips/include/asm/io.h             | 123 +++++++++++++++----------
 arch/mips/include/asm/mmiowb.h         |   4 +-
 arch/mips/include/asm/smp-ops.h        |   2 -
 arch/mips/include/asm/smp.h            |   4 +-
 arch/mips/kernel/setup.c               |   1 +
 arch/mips/pci/pci-ip27.c               |   3 +
 arch/parisc/include/asm/io.h           |   2 -
 arch/powerpc/include/asm/io.h          |   1 -
 arch/sh/include/asm/io.h               |   2 -
 arch/sparc/include/asm/io_64.h         |   1 -
 drivers/video/fbdev/aty/atyfb_base.c   |   4 +
 15 files changed, 88 insertions(+), 73 deletions(-)
Signature · 1 line
2.41.0
author
#1 lore raw

PATCH v5 1/4 video: fbdev: atyfb: only use ioremap_uc() on i386 and ia64

From: Arnd Bergmann <[email protected]>

ioremap_uc() is only meaningful on old x86-32 systems with the PAT extension, and on ia64 with its slightly unconventional ioremap() behavior, everywhere else this is the same as ioremap() anyway.

Change the only driver that still references ioremap_uc() to only do so on x86-32/ia64 in order to allow removing that interface at some point in the future for the other architectures.

On some architectures, ioremap_uc() just returns NULL, changing the driver to call ioremap() means that they now have a chance of working correctly.

---
 drivers/video/fbdev/aty/atyfb_base.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/video/fbdev/aty/atyfb_base.c +4 -0
index 5c87817a4f4c..3dcf83f5e7b4 100644
@@ -3440,11 +3440,15 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info,
 	}
 
 	info->fix.mmio_start = raddr;
+#if defined(__i386__) || defined(__ia64__)
 	/*
 	 * By using strong UC we force the MTRR to never have an
 	 * effect on the MMIO region on both non-PAT and PAT systems.
 	 */
 	par->ati_regbase = ioremap_uc(info->fix.mmio_start, 0x1000);
+#else
+	par->ati_regbase = ioremap(info->fix.mmio_start, 0x1000);
+#endif
 	if (par->ati_regbase == NULL)
 		return -ENOMEM;
 
Signature · 1 line
2.41.0
maintainer Applied
#2 lore raw

Re: [PATCH v5 1/4] video: fbdev: atyfb: only use ioremap_uc() on i386 and ia64

Quoted 14 lines · Baoquan He

From: Arnd Bergmann <[email protected]>

ioremap_uc() is only meaningful on old x86-32 systems with the PAT extension, and on ia64 with its slightly unconventional ioremap() behavior, everywhere else this is the same as ioremap() anyway.

Change the only driver that still references ioremap_uc() to only do so on x86-32/ia64 in order to allow removing that interface at some point in the future for the other architectures.

On some architectures, ioremap_uc() just returns NULL, changing the driver to call ioremap() means that they now have a chance of working correctly.

Quoted 8 lines

applied to fbdev git tree.

Thanks!
Helge

Quoted 24 lines
---
  drivers/video/fbdev/aty/atyfb_base.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/video/fbdev/aty/atyfb_base.c +4 -0
index 5c87817a4f4c..3dcf83f5e7b4 100644
@@ -3440,11 +3440,15 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info,
  	}
 
  	info->fix.mmio_start = raddr;
+#if defined(__i386__) || defined(__ia64__)
  	/*
  	 * By using strong UC we force the MTRR to never have an
  	 * effect on the MMIO region on both non-PAT and PAT systems.
  	 */
  	par->ati_regbase = ioremap_uc(info->fix.mmio_start, 0x1000);
+#else
+	par->ati_regbase = ioremap(info->fix.mmio_start, 0x1000);
+#endif
  	if (par->ati_regbase == NULL)
  		return -ENOMEM;
 
author
#3 lore raw

PATCH v5 2/4 mips: add <asm-generic/io.h> including

In reply to Baoquan He

From: Jiaxun Yang <[email protected]>

With the adding, some default ioremap_xx methods defined in asm-generic/io.h can be used. E.g the default ioremap_uc() returning NULL.

We also massaged various headers to avoid nested includes.

[[email protected]: Massage more headers, fix ioport defines]
Cc Thomas Bogendoerfer <[email protected]>
Cc Huacai Chen <[email protected]>
---
 arch/mips/include/asm/io.h      | 96 +++++++++++++++++++++++----------
 arch/mips/include/asm/mmiowb.h  |  4 +-
 arch/mips/include/asm/smp-ops.h |  2 -
 arch/mips/include/asm/smp.h     |  4 +-
 arch/mips/kernel/setup.c        |  1 +
 arch/mips/pci/pci-ip27.c        |  3 ++
 6 files changed, 75 insertions(+), 35 deletions(-)
arch/mips/include/asm/io.h +68 -28
index 062dd4e6b954..41d8bd5adef8 100644
@@ -13,7 +13,6 @@
 #define _ASM_IO_H
 
 #include <linux/compiler.h>
-#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/irqflags.h>
 
@@ -25,7 +24,6 @@
 #include <asm/cpu-features.h>
 #include <asm/page.h>
 #include <asm/pgtable-bits.h>
-#include <asm/processor.h>
 #include <asm/string.h>
 #include <mangle-port.h>
 
@@ -41,6 +39,11 @@
 # define __raw_ioswabq(a, x)	(x)
 # define ____raw_ioswabq(a, x)	(x)
 
+# define _ioswabb ioswabb
+# define _ioswabw ioswabw
+# define _ioswabl ioswabl
+# define _ioswabq ioswabq
+
 # define __relaxed_ioswabb ioswabb
 # define __relaxed_ioswabw ioswabw
 # define __relaxed_ioswabl ioswabl
@@ -126,6 +129,7 @@ static inline phys_addr_t virt_to_phys(const volatile void *x)
  *     almost all conceivable cases a device driver should not be using
  *     this function
  */
+#define phys_to_virt phys_to_virt
 static inline void * phys_to_virt(unsigned long address)
 {
 	return __va(address);
@@ -296,9 +300,9 @@ static inline type pfx##read##bwlq(const volatile void __iomem *mem)	\
 	return pfx##ioswab##bwlq(__mem, __val);				\
 }
 
-#define __BUILD_IOPORT_SINGLE(pfx, bwlq, type, barrier, relax, p)	\
+#define __BUILD_IOPORT_SINGLE(pfx, bwlq, type, barrier, relax)		\
 									\
-static inline void pfx##out##bwlq##p(type val, unsigned long port)	\
+static inline void pfx##out##bwlq(type val, unsigned long port)		\
 {									\
 	volatile type *__addr;						\
 	type __val;							\
@@ -318,7 +322,7 @@ static inline void pfx##out##bwlq##p(type val, unsigned long port)	\
 	*__addr = __val;						\
 }									\
 									\
-static inline type pfx##in##bwlq##p(unsigned long port)			\
+static inline type pfx##in##bwlq(unsigned long port)			\
 {									\
 	volatile type *__addr;						\
 	type __val;							\
@@ -360,11 +364,10 @@ __BUILD_MEMORY_PFX(__mem_, q, u64, 0)
 #endif
 
 #define __BUILD_IOPORT_PFX(bus, bwlq, type)				\
-	__BUILD_IOPORT_SINGLE(bus, bwlq, type, 1, 0,)			\
-	__BUILD_IOPORT_SINGLE(bus, bwlq, type, 1, 0, _p)
+	__BUILD_IOPORT_SINGLE(bus, bwlq, type, 1, 0)
 
 #define BUILDIO_IOPORT(bwlq, type)					\
-	__BUILD_IOPORT_PFX(, bwlq, type)				\
+	__BUILD_IOPORT_PFX(_, bwlq, type)				\
 	__BUILD_IOPORT_PFX(__mem_, bwlq, type)
 
 BUILDIO_IOPORT(b, u8)
@@ -412,14 +415,6 @@ __BUILDIO(q, u64)
 #define writeq_be(val, addr)						\
 	__raw_writeq(cpu_to_be64((val)), (__force unsigned *)(addr))
 
-/*
- * Some code tests for these symbols
- */
-#ifdef CONFIG_64BIT
-#define readq				readq
-#define writeq				writeq
-#endif
-
 #define __BUILD_MEMORY_STRING(bwlq, type)				\
 									\
 static inline void writes##bwlq(volatile void __iomem *mem,		\
@@ -480,18 +475,6 @@ BUILDSTRING(l, u32)
 BUILDSTRING(q, u64)
 #endif
 
-static inline void memset_io(volatile void __iomem *addr, unsigned char val, int count)
-{
-	memset((void __force *) addr, val, count);
-}
-static inline void memcpy_fromio(void *dst, const volatile void __iomem *src, int count)
-{
-	memcpy(dst, (void __force *) src, count);
-}
-static inline void memcpy_toio(volatile void __iomem *dst, const void *src, int count)
-{
-	memcpy((void __force *) dst, src, count);
-}
 
 /*
  * The caches on some architectures aren't dma-coherent and have need to
@@ -548,6 +531,61 @@ extern void (*_dma_cache_inv)(unsigned long start, unsigned long size);
 #define csr_out32(v, a) (*(volatile u32 *)((unsigned long)(a) + __CSR_32_ADJUST) = (v))
 #define csr_in32(a)    (*(volatile u32 *)((unsigned long)(a) + __CSR_32_ADJUST))
 
+
+#define __raw_readb __raw_readb
+#define __raw_readw __raw_readw
+#define __raw_readl __raw_readl
+#ifdef CONFIG_64BIT
+#define __raw_readq __raw_readq
+#endif
+#define __raw_writeb __raw_writeb
+#define __raw_writew __raw_writew
+#define __raw_writel __raw_writel
+#ifdef CONFIG_64BIT
+#define __raw_writeq __raw_writeq
+#endif
+
+#define readb readb
+#define readw readw
+#define readl readl
+#ifdef CONFIG_64BIT
+#define readq readq
+#endif
+#define writeb writeb
+#define writew writew
+#define writel writel
+#ifdef CONFIG_64BIT
+#define writeq writeq
+#endif
+
+#define readsb readsb
+#define readsw readsw
+#define readsl readsl
+#ifdef CONFIG_64BIT
+#define readsq readsq
+#endif
+#define writesb writesb
+#define writesw writesw
+#define writesl writesl
+#ifdef CONFIG_64BIT
+#define writesq writesq
+#endif
+
+#define _inb _inb
+#define _inw _inw
+#define _inl _inl
+#define insb insb
+#define insw insw
+#define insl insl
+
+#define _outb _outb
+#define _outw _outw
+#define _outl _outl
+#define outsb outsb
+#define outsw outsw
+#define outsl outsl
+
+
 /*
  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  * access
@@ -557,4 +595,6 @@ extern void (*_dma_cache_inv)(unsigned long start, unsigned long size);
 
 void __ioread64_copy(void *to, const void __iomem *from, size_t count);
 
+#include <asm-generic/io.h>
+
 #endif /* _ASM_IO_H */
arch/mips/include/asm/mmiowb.h +2 -2
index a40824e3ef8e..cf27752fd220 100644
@@ -2,9 +2,9 @@
 #ifndef _ASM_MMIOWB_H
 #define _ASM_MMIOWB_H
 
-#include <asm/io.h>
+#include <asm/barrier.h>
 
-#define mmiowb()	iobarrier_w()
+#define mmiowb()	wmb()
 
 #include <asm-generic/mmiowb.h>
 
arch/mips/include/asm/smp-ops.h +0 -2
index 5719ff49eff1..a6941b7f0cc0 100644
@@ -13,8 +13,6 @@
 
 #include <linux/errno.h>
 
-#include <asm/mips-cps.h>
-
 #ifdef CONFIG_SMP
 
 #include <linux/cpumask.h>
arch/mips/include/asm/smp.h +1 -3
index a40d8c0e4b87..f3b18b4a5e44 100644
@@ -11,13 +11,11 @@
 #ifndef __ASM_SMP_H
 #define __ASM_SMP_H
 
-#include <linux/bitops.h>
+#include <linux/compiler.h>
 #include <linux/linkage.h>
-#include <linux/smp.h>
 #include <linux/threads.h>
 #include <linux/cpumask.h>
 
-#include <linux/atomic.h>
 #include <asm/smp-ops.h>
 
 extern int smp_num_siblings;
arch/mips/kernel/setup.c +1 -0
index cb871eb784a7..6939b27b1106 100644
@@ -43,6 +43,7 @@
 #include <asm/sections.h>
 #include <asm/setup.h>
 #include <asm/smp-ops.h>
+#include <asm/mips-cps.h>
 #include <asm/prom.h>
 #include <asm/fw/fw.h>
 
arch/mips/pci/pci-ip27.c +3 -0
index d85cbf84e41c..973faea61cad 100644
@@ -7,6 +7,9 @@
  * Copyright (C) 1999, 2000, 04 Ralf Baechle ([email protected])
  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  */
+
+#include <linux/io.h>
+
 #include <asm/sn/addrs.h>
 #include <asm/sn/types.h>
 #include <asm/sn/klconfig.h>
Signature · 1 line
2.41.0
maintainer Acked-by on v5 2/4
#4 lore raw

Re: [PATCH v5 2/4] mips: add <asm-generic/io.h> including

Quoted 16 lines · Baoquan He

From: Jiaxun Yang <[email protected]>

With the adding, some default ioremap_xx methods defined in asm-generic/io.h can be used. E.g the default ioremap_uc() returning NULL.

We also massaged various headers to avoid nested includes.

[[email protected]: Massage more headers, fix ioport defines]
Cc Thomas Bogendoerfer <[email protected]>
Cc Huacai Chen <[email protected]>
Quoted 8 lines
---
 arch/mips/include/asm/io.h      | 96 +++++++++++++++++++++++----------
 arch/mips/include/asm/mmiowb.h  |  4 +-
 arch/mips/include/asm/smp-ops.h |  2 -
 arch/mips/include/asm/smp.h     |  4 +-
 arch/mips/kernel/setup.c        |  1 +
 arch/mips/pci/pci-ip27.c        |  3 ++
 6 files changed, 75 insertions(+), 35 deletions(-)
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
author
#5 lore raw

PATCH v5 3/4 arch/*/io.h: remove ioremap_uc in some architectures

In reply to Baoquan He

ioremap_uc() is only meaningful on old x86-32 systems with the PAT extension, and on ia64 with its slightly unconventional ioremap() behavior. So remove the ioremap_uc() definition in architecutures other than x86 and ia64. These architectures all have asm-generic/io.h included and will have the default ioremap_uc() definition which returns NULL.

This changes the existing behaviour, while no need to worry about any breakage because in the only callsite of ioremap_uc(), code has been adjusted to eliminate the impact. Please see atyfb_setup_generic() of drivers/video/fbdev/aty/atyfb_base.c.

If any new invocation of ioremap_uc() need be added, please consider using ioremap() intead or adding a ARCH specific version if necessary.

---
 Documentation/driver-api/device-io.rst | 9 +++++----
 arch/alpha/include/asm/io.h            | 1 -
 arch/hexagon/include/asm/io.h          | 3 ---
 arch/m68k/include/asm/kmap.h           | 1 -
 arch/mips/include/asm/io.h             | 1 -
 arch/parisc/include/asm/io.h           | 2 --
 arch/powerpc/include/asm/io.h          | 1 -
 arch/sh/include/asm/io.h               | 2 --
 arch/sparc/include/asm/io_64.h         | 1 -
 9 files changed, 5 insertions(+), 16 deletions(-)
Documentation/driver-api/device-io.rst +5 -4
index 2c7abd234f4e..d55384b106bd 100644
@@ -408,11 +408,12 @@ functions for details on the CPU side of things.
 ioremap_uc()
 ------------
 
-ioremap_uc() behaves like ioremap() except that on the x86 architecture without
-'PAT' mode, it marks memory as uncached even when the MTRR has designated
-it as cacheable, see Documentation/arch/x86/pat.rst.
+ioremap_uc() is only meaningful on old x86-32 systems with the PAT extension,
+and on ia64 with its slightly unconventional ioremap() behavior, everywhere
+elss ioremap_uc() defaults to return NULL.
 
-Portable drivers should avoid the use of ioremap_uc().
+
+Portable drivers should avoid the use of ioremap_uc(), use ioremap() instead.
 
 ioremap_cache()
 ---------------
arch/alpha/include/asm/io.h +0 -1
index 7aeaf7c30a6f..076f0e4e7f1e 100644
@@ -308,7 +308,6 @@ static inline void __iomem *ioremap(unsigned long port, unsigned long size)
 }
 
 #define ioremap_wc ioremap
-#define ioremap_uc ioremap
 
 static inline void iounmap(volatile void __iomem *addr)
 {
arch/hexagon/include/asm/io.h +0 -3
index e2b308e32a37..b7bc246dbcb1 100644
@@ -174,9 +174,6 @@ static inline void writel(u32 data, volatile void __iomem *addr)
 #define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
 		       (__HEXAGON_C_DEV << 6))
 
-#define ioremap_uc(addr, size) ioremap((addr), (size))
-
-
 #define __raw_writel writel
 
 static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
arch/m68k/include/asm/kmap.h +0 -1
index 4efb3efa593a..b778f015c917 100644
@@ -25,7 +25,6 @@ static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
 }
 
-#define ioremap_uc ioremap
 #define ioremap_wt ioremap_wt
 static inline void __iomem *ioremap_wt(unsigned long physaddr,
 				       unsigned long size)
arch/mips/include/asm/io.h +0 -1
index 41d8bd5adef8..1ecf255efb40 100644
@@ -170,7 +170,6 @@ void iounmap(const volatile void __iomem *addr);
  */
 #define ioremap(offset, size)						\
 	ioremap_prot((offset), (size), _CACHE_UNCACHED)
-#define ioremap_uc		ioremap
 
 /*
  * ioremap_cache -	map bus memory into CPU space
arch/parisc/include/asm/io.h +0 -2
index 366537042465..48630c78714a 100644
@@ -132,8 +132,6 @@ static inline void gsc_writeq(unsigned long long val, unsigned long addr)
 
 #define ioremap_wc(addr, size)  \
 	ioremap_prot((addr), (size), _PAGE_IOREMAP)
-#define ioremap_uc(addr, size)  \
-	ioremap_prot((addr), (size), _PAGE_IOREMAP)
 
 #define pci_iounmap			pci_iounmap
 
arch/powerpc/include/asm/io.h +0 -1
index 0732b743e099..21bd3e8bffce 100644
@@ -900,7 +900,6 @@ void __iomem *ioremap_wt(phys_addr_t address, unsigned long size);
 #endif
 
 void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size);
-#define ioremap_uc(addr, size)		ioremap((addr), (size))
 #define ioremap_cache(addr, size) \
 	ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL))
 
arch/sh/include/asm/io.h +0 -2
index f2f38e9d489a..790bea22c9b5 100644
@@ -302,8 +302,6 @@ unsigned long long poke_real_address_q(unsigned long long addr,
 	ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL))
 #endif /* CONFIG_MMU */
 
-#define ioremap_uc	ioremap
-
 /*
  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  * access
arch/sparc/include/asm/io_64.h +0 -1
index 9303270b22f3..d8ee1442f303 100644
@@ -423,7 +423,6 @@ static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
 	return (void __iomem *)offset;
 }
 
-#define ioremap_uc(X,Y)			ioremap((X),(Y))
 #define ioremap_wc(X,Y)			ioremap((X),(Y))
 #define ioremap_wt(X,Y)			ioremap((X),(Y))
 static inline void __iomem *ioremap_np(unsigned long offset, unsigned long size)
Signature · 1 line
2.41.0
maintainer Acked-by on v5 3/4
#6 lore raw
Quoted 15 lines · Baoquan He

ioremap_uc() is only meaningful on old x86-32 systems with the PAT extension, and on ia64 with its slightly unconventional ioremap() behavior. So remove the ioremap_uc() definition in architecutures other than x86 and ia64. These architectures all have asm-generic/io.h included and will have the default ioremap_uc() definition which returns NULL.

This changes the existing behaviour, while no need to worry about any breakage because in the only callsite of ioremap_uc(), code has been adjusted to eliminate the impact. Please see atyfb_setup_generic() of drivers/video/fbdev/aty/atyfb_base.c.

If any new invocation of ioremap_uc() need be added, please consider using ioremap() intead or adding a ARCH specific version if necessary.

Quoted 12 lines
maintainer Acked-by on v5 3/4
#7 lore raw
In reply to Baoquan He
Quoted 27 lines · Baoquan He

ioremap_uc() is only meaningful on old x86-32 systems with the PAT extension, and on ia64 with its slightly unconventional ioremap() behavior. So remove the ioremap_uc() definition in architecutures other than x86 and ia64. These architectures all have asm-generic/io.h included and will have the default ioremap_uc() definition which returns NULL.

This changes the existing behaviour, while no need to worry about any breakage because in the only callsite of ioremap_uc(), code has been adjusted to eliminate the impact. Please see atyfb_setup_generic() of drivers/video/fbdev/aty/atyfb_base.c.

If any new invocation of ioremap_uc() need be added, please consider using ioremap() intead or adding a ARCH specific version if necessary.

Quoted 6 lines
---
 Documentation/driver-api/device-io.rst | 9 +++++----
 arch/alpha/include/asm/io.h            | 1 -
 arch/hexagon/include/asm/io.h          | 3 ---
 arch/m68k/include/asm/kmap.h           | 1 -
 arch/mips/include/asm/io.h             | 1 -
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
maintainer Acked-by on v5 3/4
#8 lore raw
In reply to Baoquan He
Quoted 153 lines · Baoquan He

ioremap_uc() is only meaningful on old x86-32 systems with the PAT extension, and on ia64 with its slightly unconventional ioremap() behavior. So remove the ioremap_uc() definition in architecutures other than x86 and ia64. These architectures all have asm-generic/io.h included and will have the default ioremap_uc() definition which returns NULL.

This changes the existing behaviour, while no need to worry about any breakage because in the only callsite of ioremap_uc(), code has been adjusted to eliminate the impact. Please see atyfb_setup_generic() of drivers/video/fbdev/aty/atyfb_base.c.

If any new invocation of ioremap_uc() need be added, please consider using ioremap() intead or adding a ARCH specific version if necessary.

---
 Documentation/driver-api/device-io.rst | 9 +++++----
 arch/alpha/include/asm/io.h            | 1 -
 arch/hexagon/include/asm/io.h          | 3 ---
 arch/m68k/include/asm/kmap.h           | 1 -
 arch/mips/include/asm/io.h             | 1 -
 arch/parisc/include/asm/io.h           | 2 --
 arch/powerpc/include/asm/io.h          | 1 -
 arch/sh/include/asm/io.h               | 2 --
 arch/sparc/include/asm/io_64.h         | 1 -
 9 files changed, 5 insertions(+), 16 deletions(-)
Documentation/driver-api/device-io.rst +5 -4
index 2c7abd234f4e..d55384b106bd 100644
@@ -408,11 +408,12 @@ functions for details on the CPU side of things.
 ioremap_uc()
 ------------
 
-ioremap_uc() behaves like ioremap() except that on the x86 architecture without
-'PAT' mode, it marks memory as uncached even when the MTRR has designated
-it as cacheable, see Documentation/arch/x86/pat.rst.
+ioremap_uc() is only meaningful on old x86-32 systems with the PAT extension,
+and on ia64 with its slightly unconventional ioremap() behavior, everywhere
+elss ioremap_uc() defaults to return NULL.
 
-Portable drivers should avoid the use of ioremap_uc().
+
+Portable drivers should avoid the use of ioremap_uc(), use ioremap() instead.
 
 ioremap_cache()
 ---------------
arch/alpha/include/asm/io.h +0 -1
index 7aeaf7c30a6f..076f0e4e7f1e 100644
@@ -308,7 +308,6 @@ static inline void __iomem *ioremap(unsigned long port, unsigned long size)
 }
 
 #define ioremap_wc ioremap
-#define ioremap_uc ioremap
 
 static inline void iounmap(volatile void __iomem *addr)
 {
arch/hexagon/include/asm/io.h +0 -3
index e2b308e32a37..b7bc246dbcb1 100644
@@ -174,9 +174,6 @@ static inline void writel(u32 data, volatile void __iomem *addr)
 #define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
 		       (__HEXAGON_C_DEV << 6))
 
-#define ioremap_uc(addr, size) ioremap((addr), (size))
-
-
 #define __raw_writel writel
 
 static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
arch/m68k/include/asm/kmap.h +0 -1
index 4efb3efa593a..b778f015c917 100644
@@ -25,7 +25,6 @@ static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
 	return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
 }
 
-#define ioremap_uc ioremap
 #define ioremap_wt ioremap_wt
 static inline void __iomem *ioremap_wt(unsigned long physaddr,
 				       unsigned long size)
arch/mips/include/asm/io.h +0 -1
index 41d8bd5adef8..1ecf255efb40 100644
@@ -170,7 +170,6 @@ void iounmap(const volatile void __iomem *addr);
  */
 #define ioremap(offset, size)						\
 	ioremap_prot((offset), (size), _CACHE_UNCACHED)
-#define ioremap_uc		ioremap
 
 /*
  * ioremap_cache -	map bus memory into CPU space
arch/parisc/include/asm/io.h +0 -2
index 366537042465..48630c78714a 100644
@@ -132,8 +132,6 @@ static inline void gsc_writeq(unsigned long long val, unsigned long addr)
 
 #define ioremap_wc(addr, size)  \
 	ioremap_prot((addr), (size), _PAGE_IOREMAP)
-#define ioremap_uc(addr, size)  \
-	ioremap_prot((addr), (size), _PAGE_IOREMAP)
 
 #define pci_iounmap			pci_iounmap
 
arch/powerpc/include/asm/io.h +0 -1
index 0732b743e099..21bd3e8bffce 100644
@@ -900,7 +900,6 @@ void __iomem *ioremap_wt(phys_addr_t address, unsigned long size);
 #endif
 
 void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size);
-#define ioremap_uc(addr, size)		ioremap((addr), (size))
 #define ioremap_cache(addr, size) \
 	ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL))
 
arch/sh/include/asm/io.h +0 -2
index f2f38e9d489a..790bea22c9b5 100644
@@ -302,8 +302,6 @@ unsigned long long poke_real_address_q(unsigned long long addr,
 	ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL))
 #endif /* CONFIG_MMU */
 
-#define ioremap_uc	ioremap
-
 /*
  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  * access
arch/sparc/include/asm/io_64.h +0 -0
index 9303270b22f3..d8ee1442f303 100644

arch/sparc/include/asm/io_64.h static inline void __iomem *ioremap(unsigned long offset, unsigned long size) · line 428

Quoted 7 lines
arch/sparc/include/asm/io_64.h +0 -1
@@ -423,7 +423,6 @@ static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
 	return (void __iomem *)offset;
 }
 
-#define ioremap_uc(X,Y)			ioremap((X),(Y))
 #define ioremap_wc(X,Y)			ioremap((X),(Y))
 #define ioremap_wt(X,Y)			ioremap((X),(Y))
 static inline void __iomem *ioremap_np(unsigned long offset, unsigned long size)
Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
author
#9 lore raw

PATCH v5 4/4 mips: io: remove duplicated codes

In reply to Baoquan He

By adding <asm-generic/io.h> support, the duplicated phys_to_virt can be removed to use the default version in <asm-gneneric/io.h>.

Meanwhile move isa_bus_to_virt() down below <asm-generic/io.h> including to fix the compiling error of missing phys_to_virt definition.

Cc Thomas Bogendoerfer <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Helge Deller <[email protected]>
Cc Serge Semin <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Huacai Chen <[email protected]>
Cc Jiaxun Yang <[email protected]>
---
 arch/mips/include/asm/io.h | 28 +++++-----------------------
 1 file changed, 5 insertions(+), 23 deletions(-)
arch/mips/include/asm/io.h +5 -23
index 1ecf255efb40..fe5476c1c689 100644
@@ -117,24 +117,6 @@ static inline phys_addr_t virt_to_phys(const volatile void *x)
 	return __virt_to_phys(x);
 }
 
-/*
- *     phys_to_virt    -       map physical address to virtual
- *     @address: address to remap
- *
- *     The returned virtual address is a current CPU mapping for
- *     the memory address given. It is only valid to use this function on
- *     addresses that have a kernel mapping
- *
- *     This function does not handle bus mappings for DMA transfers. In
- *     almost all conceivable cases a device driver should not be using
- *     this function
- */
-#define phys_to_virt phys_to_virt
-static inline void * phys_to_virt(unsigned long address)
-{
-	return __va(address);
-}
-
 /*
  * ISA I/O bus memory addresses are 1:1 with the physical address.
  */
@@ -143,11 +125,6 @@ static inline unsigned long isa_virt_to_bus(volatile void *address)
 	return virt_to_phys(address);
 }
 
-static inline void *isa_bus_to_virt(unsigned long address)
-{
-	return phys_to_virt(address);
-}
-
 /*
  * Change "struct page" to physical address.
  */
@@ -596,4 +573,9 @@ void __ioread64_copy(void *to, const void __iomem *from, size_t count);
 
 #include <asm-generic/io.h>
 
+static inline void *isa_bus_to_virt(unsigned long address)
+{
+	return phys_to_virt(address);
+}
+
 #endif /* _ASM_IO_H */
Signature · 1 line
2.41.0
maintainer Acked-by on v5 4/4
#10 lore raw

Re: [PATCH v5 4/4] mips: io: remove duplicated codes

Quoted 6 lines · Baoquan He

By adding <asm-generic/io.h> support, the duplicated phys_to_virt can be removed to use the default version in <asm-gneneric/io.h>.

Meanwhile move isa_bus_to_virt() down below <asm-generic/io.h> including to fix the compiling error of missing phys_to_virt definition.

maintainer Acked-by on v5 4/4
#11 lore raw

Re: [PATCH v5 4/4] mips: io: remove duplicated codes

In reply to Baoquan He
Quoted 15 lines · Baoquan He

By adding <asm-generic/io.h> support, the duplicated phys_to_virt can be removed to use the default version in <asm-gneneric/io.h>.

Meanwhile move isa_bus_to_virt() down below <asm-generic/io.h> including to fix the compiling error of missing phys_to_virt definition.

Cc Thomas Bogendoerfer <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Helge Deller <[email protected]>
Cc Serge Semin <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Huacai Chen <[email protected]>
Cc Jiaxun Yang <[email protected]>
Quoted 3 lines
---
 arch/mips/include/asm/io.h | 28 +++++-----------------------
 1 file changed, 5 insertions(+), 23 deletions(-)
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
Tested-by on the v5 series
#12 lore raw
In reply to Baoquan He
Quoted 16 lines · 在2023年9月21日九月 下午12:04,Baoquan He写道:

This patchset tries to remove ioremap_uc() in the current architectures except of x86 and ia64. They will use the default ioremap_uc version in <asm-generic/io.h> which returns NULL. Anyone who wants to add new invocation of ioremap_uc(), please consider using ioremap() instead or adding a new ARCH specific ioremap_uc(), or refer to the callsite in drivers/video/fbdev/aty/atyfb_base.c.

This change won't cuase breakage to the current kernel because in the only ioremap_uc callsite, an adjustment is made to eliminate impact in patch 1 of this series.

To get rid of all of them other than x86 and ia64, add asm-generic/io.h to asm/io.h of mips ARCH. With this adding, we can get rid of the ioremap_uc() in mips too. This is done in patch 2. And a followup patch 4 is added to remove duplicated code according to Arnd's suggestion.

Quoted 5 lines

Test:
=====
Except of Jiaxun's efficient testing on patch 2/4, I also did cross compiling of this series on mips64, building passed.

For whole series:

Hi Arnd and Thomas,

I've got some work pending based on this series, however I'm unclear about which tree this series will go since both of you give acked-by.

Given that there are some tree-wide modifications, I guess it should go into Arnd's asm-generic tree?

Thanks

Signature · 1 line
- Jiaxun
author
#13 lore raw
Quoted 25 lines · Jiaxun Yang
Quoted 16 lines · 在2023年9月21日九月 下午12:04,Baoquan He写道:

This patchset tries to remove ioremap_uc() in the current architectures except of x86 and ia64. They will use the default ioremap_uc version in <asm-generic/io.h> which returns NULL. Anyone who wants to add new invocation of ioremap_uc(), please consider using ioremap() instead or adding a new ARCH specific ioremap_uc(), or refer to the callsite in drivers/video/fbdev/aty/atyfb_base.c.

This change won't cuase breakage to the current kernel because in the only ioremap_uc callsite, an adjustment is made to eliminate impact in patch 1 of this series.

To get rid of all of them other than x86 and ia64, add asm-generic/io.h to asm/io.h of mips ARCH. With this adding, we can get rid of the ioremap_uc() in mips too. This is done in patch 2. And a followup patch 4 is added to remove duplicated code according to Arnd's suggestion.

Quoted 5 lines

Test:
=====
Except of Jiaxun's efficient testing on patch 2/4, I also did cross compiling of this series on mips64, building passed.

Quoted 3 lines

For whole series:

Thanks for testing, Jiaxun.

Quoted 8 lines

Hi Arnd and Thomas,

I've got some work pending based on this series, however I'm unclear about which tree this series will go since both of you give acked-by.

Given that there are some tree-wide modifications, I guess it should go into Arnd's asm-generic tree?

Previously Andrew merged my below patchset. This patchset is solving the left issue during reviewing below patchset and discussing. Maybe Andrew can help pick this patches?

[PATCH v8 00/19] mm: ioremap: Convert architectures to take GENERIC_IOREMAP way
https://lore.kernel.org/all/[email protected]/T/#u

Thanks
Baoquan