Skip to contentSkip to conversation

iomap: Add specific address space __iomap for iomap pointers

RFC/PATCH Benjamin Herrenschmidt 1 participant 2 messages Feb 18, 2008

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

The current iomap stuff (pci_iomap, ioport_map, pcim_iomap, ...) is confusing as it returns pointers in the _miomem address space.

However, even if that would work on some architectures, the result of those functions is -not- to be used as an __iomem, with accessors such as readl/writel, but only with the new brand of specific accessors (ioread32/iowrite32/...).

This causes confusion, there have been bugs in the past due to that, and this is just wrong, so this is an attempt at fixing it by introducing a new address space __iomap for the iomap stuff.

This patch adds the annotation and changes the generic and arch code that returns these pointers. I have -not- yet started looking at drivers and fixing them (that will be the hard part) and I may well have missed or even borked things, as this stage, I'm looking for feedback on the approach and for the affected arch maintainers to have a quick look in case I missed something in their code.

_THIS_ _IS_ _UNTESTED_ (just so that you know !)

Note that incorrect address space annotations will not break build, though they will spew warnings in sparse. So it is doable to get a patch such as this one in, and -then- fix the drivers, though it would be best to have as much conversion as possible done at once still.

---

 arch/frv/mb93090-mb00/pci-iomap.c |    4 -
 arch/powerpc/kernel/iomap.c       |   69 ++++++++++++++++--------------
 arch/sparc/lib/iomap.c            |   14 +++---
 arch/sparc64/lib/iomap.c          |   12 ++---
 arch/v850/kernel/rte_mb_a_pci.c   |    4 -
 include/asm-arm/io.h              |    8 +--
 include/asm-frv/io.h              |   16 +++---
 include/asm-generic/iomap.h       |   44 +++++++++----------
 include/asm-mn10300/io.h          |   24 +++++-----
 include/asm-ppc/io.h              |   58 +++++++++++++------------
 include/asm-sparc/io.h            |   32 ++++++-------
 include/asm-sparc64/io.h          |   20 ++++----
 include/asm-v850/io.h             |   12 ++---
 include/asm-v850/pci.h            |    4 -
 include/linux/compiler.h          |    2 
 include/linux/pci.h               |    6 +-
 lib/devres.c                      |   26 +++++------
 lib/iomap.c                       |   87 +++++++++++++++++++-------------------
 18 files changed, 226 insertions(+), 216 deletions(-)
include/linux/compiler.h +2 -0
@@ -10,6 +10,7 @@
 # define __force	__attribute__((force))
 # define __nocast	__attribute__((nocast))
 # define __iomem	__attribute__((noderef, address_space(2)))
+# define __iomap	__attribute__((noderef, address_space(4)))
 # define __acquires(x)	__attribute__((context(x,0,1)))
 # define __releases(x)	__attribute__((context(x,1,0)))
 # define __acquire(x)	__context__(x,1)
@@ -24,6 +25,7 @@ extern void __chk_io_ptr(const volatile 
 # define __force
 # define __nocast
 # define __iomem
+# define __iomap
 # define __chk_user_ptr(x) (void)0
 # define __chk_io_ptr(x) (void)0
 # define __builtin_warning(x, y...) (1)
lib/iomap.c +44 -43

185 lines not on this page · raw message

arch/powerpc/kernel/iomap.c +37 -32

143 lines not on this page · raw message

arch/frv/mb93090-mb00/pci-iomap.c +2 -2
Index: linux-work/arch/frv/mb93090-mb00/pci-iomap.c
===================================================================
@@ -11,7 +11,7 @@
 #include <linux/pci.h>
 #include <linux/module.h>
 
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomap *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 {
 	unsigned long start = pci_resource_start(dev, bar);
 	unsigned long len = pci_resource_len(dev, bar);
@@ -21,7 +21,7 @@ void __iomem *pci_iomap(struct pci_dev *
 		return NULL;
 
 	if ((flags & IORESOURCE_IO) || (flags & IORESOURCE_MEM))
-		return (void __iomem *) start;
+		return (void __iomap *) start;
 
 	return NULL;
 }
arch/sparc/lib/iomap.c +7 -7
Index: linux-work/arch/sparc/lib/iomap.c
===================================================================
@@ -6,12 +6,12 @@
 #include <asm/io.h>
 
 /* Create a virtual mapping cookie for an IO port range */
-void __iomem *ioport_map(unsigned long port, unsigned int nr)
+void __iomap *ioport_map(unsigned long port, unsigned int nr)
 {
-	return (void __iomem *) (unsigned long) port;
+	return (void __iomap *) (unsigned long) port;
 }
 
-void ioport_unmap(void __iomem *addr)
+void ioport_unmap(void __iomap *addr)
 {
 	/* Nothing to do */
 }
@@ -19,7 +19,7 @@ EXPORT_SYMBOL(ioport_map);
 EXPORT_SYMBOL(ioport_unmap);
 
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomap *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 {
 	unsigned long start = pci_resource_start(dev, bar);
 	unsigned long len = pci_resource_len(dev, bar);
@@ -33,14 +33,14 @@ void __iomem *pci_iomap(struct pci_dev *
 		return ioport_map(start, len);
 	if (flags & IORESOURCE_MEM) {
 		if (flags & IORESOURCE_CACHEABLE)
-			return ioremap(start, len);
-		return ioremap_nocache(start, len);
+			return (void __iomap __force *)ioremap(start, len);
+		return (void __iomap __force *)ioremap_nocache(start, len);
 	}
 	/* What? */
 	return NULL;
 }
 
-void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
+void pci_iounmap(struct pci_dev *dev, void __iomap * addr)
 {
 	/* nothing to do */
 }
arch/sparc64/lib/iomap.c +6 -6
Index: linux-work/arch/sparc64/lib/iomap.c
===================================================================
@@ -6,12 +6,12 @@
 #include <asm/io.h>
 
 /* Create a virtual mapping cookie for an IO port range */
-void __iomem *ioport_map(unsigned long port, unsigned int nr)
+void __iomap *ioport_map(unsigned long port, unsigned int nr)
 {
 	return (void __iomem *) (unsigned long) port;
 }
 
-void ioport_unmap(void __iomem *addr)
+void ioport_unmap(void __iomap *addr)
 {
 	/* Nothing to do */
 }
@@ -19,7 +19,7 @@ EXPORT_SYMBOL(ioport_map);
 EXPORT_SYMBOL(ioport_unmap);
 
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
-void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+void __iomap *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
 {
 	unsigned long start = pci_resource_start(dev, bar);
 	unsigned long len = pci_resource_len(dev, bar);
@@ -33,14 +33,14 @@ void __iomem *pci_iomap(struct pci_dev *
 		return ioport_map(start, len);
 	if (flags & IORESOURCE_MEM) {
 		if (flags & IORESOURCE_CACHEABLE)
-			return ioremap(start, len);
-		return ioremap_nocache(start, len);
+			return (void __iomap __force *)ioremap(start, len);
+		return (void __iomap __force *)ioremap_nocache(start, len);
 	}
 	/* What? */
 	return NULL;
 }
 
-void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
+void pci_iounmap(struct pci_dev *dev, void __iomap * addr)
 {
 	/* nothing to do */
 }
arch/v850/kernel/rte_mb_a_pci.c +2 -2
Index: linux-work/arch/v850/kernel/rte_mb_a_pci.c
===================================================================
@@ -788,7 +788,7 @@ pci_free_consistent (struct pci_dev *pde
 
 /* iomap/iomap */
 
-void __iomem *pci_iomap (struct pci_dev *dev, int bar, unsigned long max)
+void __iomap *pci_iomap (struct pci_dev *dev, int bar, unsigned long max)
 {
 	unsigned long start = pci_resource_start (dev, bar);
 	unsigned long len = pci_resource_len (dev, bar);
@@ -801,7 +801,7 @@ void __iomem *pci_iomap (struct pci_dev 
 	return ioremap (start, len);
 }
 
-void pci_iounmap (struct pci_dev *dev, void __iomem *addr)
+void pci_iounmap (struct pci_dev *dev, void __iomap *addr)
 {
 	/* nothing */
 }
include/asm-arm/io.h +4 -4
Index: linux-work/include/asm-arm/io.h
===================================================================
@@ -243,14 +243,14 @@ extern void _memset_io(volatile void __i
 #define iowrite16_rep(p,s,c)	__raw_writesw(p,s,c)
 #define iowrite32_rep(p,s,c)	__raw_writesl(p,s,c)
 
-extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
-extern void ioport_unmap(void __iomem *addr);
+extern void __iomap *ioport_map(unsigned long port, unsigned int nr);
+extern void ioport_unmap(void __iomap *addr);
 #endif
 
 struct pci_dev;
 
-extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen);
-extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
+extern void __iomao *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen);
+extern void pci_iounmap(struct pci_dev *dev, void __iomap *addr);
 
 /*
  * can the hardware map this into one segment or not, given no other
include/asm-frv/io.h +8 -8
Index: linux-work/include/asm-frv/io.h
===================================================================
@@ -290,12 +290,12 @@ static inline void flush_write_buffers(v
 /*
  * do appropriate I/O accesses for token type
  */
-static inline unsigned int ioread8(void __iomem *p)
+static inline unsigned int ioread8(void __iomap *p)
 {
 	return __builtin_read8(p);
 }
 
-static inline unsigned int ioread16(void __iomem *p)
+static inline unsigned int ioread16(void __iomap *p)
 {
 	uint16_t ret = __builtin_read16(p);
 	if (__is_PCI_addr(p))
@@ -303,7 +303,7 @@ static inline unsigned int ioread16(void
 	return ret;
 }
 
-static inline unsigned int ioread32(void __iomem *p)
+static inline unsigned int ioread32(void __iomap *p)
 {
 	uint32_t ret = __builtin_read32(p);
 	if (__is_PCI_addr(p))
@@ -311,14 +311,14 @@ static inline unsigned int ioread32(void
 	return ret;
 }
 
-static inline void iowrite8(u8 val, void __iomem *p)
+static inline void iowrite8(u8 val, void __iomap *p)
 {
 	__builtin_write8(p, val);
 	if (__is_PCI_MEM(p))
 		__flush_PCI_writes();
 }
 
-static inline void iowrite16(u16 val, void __iomem *p)
+static inline void iowrite16(u16 val, void __iomap *p)
 {
 	if (__is_PCI_addr(p))
 		val = _swapw(val);
@@ -327,7 +327,7 @@ static inline void iowrite16(u16 val, vo
 		__flush_PCI_writes();
 }
 
-static inline void iowrite32(u32 val, void __iomem *p)
+static inline void iowrite32(u32 val, void __iomap *p)
 {
 	if (__is_PCI_addr(p))
 		val = _swapl(val);
@@ -368,8 +368,8 @@ static inline void iowrite32_rep(void __
 
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 struct pci_dev;
-extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
-static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
+extern void __iomap *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+static inline void pci_iounmap(struct pci_dev *dev, void __iomap *p)
 {
 }
 
include/asm-generic/iomap.h +22 -22

60 lines not on this page · raw message

include/asm-mn10300/io.h +12 -12
Index: linux-work/include/asm-mn10300/io.h
===================================================================
@@ -184,13 +184,13 @@ static inline void outsl(unsigned long a
 	}
 }
 
-#define ioread8(addr)		readb(addr)
-#define ioread16(addr)		readw(addr)
-#define ioread32(addr)		readl(addr)
-
-#define iowrite8(v, addr)	writeb((v), (addr))
-#define iowrite16(v, addr)	writew((v), (addr))
-#define iowrite32(v, addr)	writel((v), (addr))
+#define ioread8(addr)		readb((void __iomem __force *)(addr))
+#define ioread16(addr)		readw((void __iomem __force *)(addr))
+#define ioread32(addr)		readl((void __iomem __force *)(addr))
+
+#define iowrite8(v, addr)	writeb((v), (void __iomem __force *)(addr))
+#define iowrite16(v, addr)	writew((v), (void __iomem __force *)(addr))
+#define iowrite32(v, addr)	writel((v), (void __iomem __force *)(addr))
 
 #define ioread8_rep(p, dst, count) \
 	insb((unsigned long) (p), (dst), (count))
@@ -216,8 +216,8 @@ static inline void outsl(unsigned long a
 
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 struct pci_dev;
-extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
-static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
+extern void __iomap *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+static inline void pci_iounmap(struct pci_dev *dev, void __iomap *p)
 {
 }
 
@@ -263,12 +263,12 @@ static inline void iounmap(void *addr)
 {
 }
 
-static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
+static inline void __iomap *ioport_map(unsigned long port, unsigned int nr)
 {
-	return (void __iomem *) port;
+	return (void __iomap *) port;
 }
 
-static inline void ioport_unmap(void __iomem *p)
+static inline void ioport_unmap(void __iomap *p)
 {
 }
 
include/asm-ppc/io.h +30 -28

104 lines not on this page · raw message

include/asm-sparc/io.h +16 -16
Index: linux-work/include/asm-sparc/io.h
===================================================================
@@ -249,50 +249,50 @@ extern void __iomem *ioremap(unsigned lo
 #define ioremap_nocache(X,Y)	ioremap((X),(Y))
 extern void iounmap(volatile void __iomem *addr);
 
-#define ioread8(X)			readb(X)
-#define ioread16(X)			readw(X)
-#define ioread32(X)			readl(X)
-#define iowrite8(val,X)			writeb(val,X)
-#define iowrite16(val,X)		writew(val,X)
-#define iowrite32(val,X)		writel(val,X)
+#define ioread8(X)			readb((void __iomem __force *)(X))
+#define ioread16(X)			readw((void __iomem __force *)(X))
+#define ioread32(X)			readl((void __iomem __force *)(X))
+#define iowrite8(val,X)			writeb(val,(void __iomem __force *)(X))
+#define iowrite16(val,X)		writew(val,(void __iomem __force *)(X))
+#define iowrite32(val,X)		writel(val,(void __iomem __force *)(X))
 
-static inline void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
+static inline void ioread8_rep(void __iomap *port, void *buf, unsigned long count)
 {
 	insb((unsigned long __force)port, buf, count);
 }
-static inline void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
+static inline void ioread16_rep(void __iomap *port, void *buf, unsigned long count)
 {
 	insw((unsigned long __force)port, buf, count);
 }
 
-static inline void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
+static inline void ioread32_rep(void __iomap *port, void *buf, unsigned long count)
 {
 	insl((unsigned long __force)port, buf, count);
 }
 
-static inline void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
+static inline void iowrite8_rep(void __iomap *port, const void *buf, unsigned long count)
 {
 	outsb((unsigned long __force)port, buf, count);
 }
 
-static inline void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
+static inline void iowrite16_rep(void __iomap *port, const void *buf, unsigned long count)
 {
 	outsw((unsigned long __force)port, buf, count);
 }
 
-static inline void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
+static inline void iowrite32_rep(void __iomap *port, const void *buf, unsigned long count)
 {
 	outsl((unsigned long __force)port, buf, count);
 }
 
 /* Create a virtual mapping cookie for an IO port range */
-extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
-extern void ioport_unmap(void __iomem *);
+extern void __iomap *ioport_map(unsigned long port, unsigned int nr);
+extern void ioport_unmap(void __iomap *);
 
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 struct pci_dev;
-extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
-extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
+extern void __iomap *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void pci_iounmap(struct pci_dev *dev, void __iomap *);
 
 /*
  * Bus number may be in res->flags... somewhere.
include/asm-sparc64/io.h +10 -10
Index: linux-work/include/asm-sparc64/io.h
===================================================================
@@ -444,21 +444,21 @@ static inline void iounmap(volatile void
 {
 }
 
-#define ioread8(X)			readb(X)
-#define ioread16(X)			readw(X)
-#define ioread32(X)			readl(X)
-#define iowrite8(val,X)			writeb(val,X)
-#define iowrite16(val,X)		writew(val,X)
-#define iowrite32(val,X)		writel(val,X)
+#define ioread8(X)			readb((void __iomem __force *)(X))
+#define ioread16(X)			readw((void __iomem __force *)(X))
+#define ioread32(X)			readl((void __iomem __force *)(X))
+#define iowrite8(val,X)			writeb(val,(void __iomem __force *)(X))
+#define iowrite16(val,X)		writew(val,(void __iomem __force *)(X))
+#define iowrite32(val,X)		writel(val,(void __iomem __force *)(X))
 
 /* Create a virtual mapping cookie for an IO port range */
-extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
-extern void ioport_unmap(void __iomem *);
+extern void __iomap *ioport_map(unsigned long port, unsigned int nr);
+extern void ioport_unmap(void __iomap *);
 
 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
 struct pci_dev;
-extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
-extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
+extern void __iomap *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void pci_iounmap(struct pci_dev *dev, void __iomap *);
 
 /* Similarly for SBUS. */
 #define sbus_ioremap(__res, __offset, __size, __name) \
include/asm-v850/io.h +6 -6
Index: linux-work/include/asm-v850/io.h
===================================================================
@@ -106,12 +106,12 @@ outsl (unsigned long port, const void *s
 #define ioremap_writethrough(physaddr, size)	ioremap (physaddr, size)
 #define ioremap_fullcache(physaddr, size)	ioremap (physaddr, size)
 
-#define ioread8(addr)		readb (addr)
-#define ioread16(addr)		readw (addr)
-#define ioread32(addr)		readl (addr)
-#define iowrite8(val, addr)	writeb (val, addr)
-#define iowrite16(val, addr)	writew (val, addr)
-#define iowrite32(val, addr)	writel (val, addr)
+#define ioread8(addr)		readb ((void __iomem __force *)(addr))
+#define ioread16(addr)		readw ((void __iomem __force *)(addr))
+#define ioread32(addr)		readl ((void __iomem __force *)(addr))
+#define iowrite8(val, addr)	writeb (val, (void __iomem __force *)(addr))
+#define iowrite16(val, addr)	writew (val, (void __iomem __force *)(addr))
+#define iowrite32(val, addr)	writel (val, (void __iomem __force *)(addr))
 
 #define mmiowb()
 
include/asm-v850/pci.h +2 -2
Index: linux-work/include/asm-v850/pci.h
===================================================================
@@ -113,7 +113,7 @@ static inline void pci_dma_burst_advice(
 }
 #endif
 
-extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
-extern void pci_iounmap (struct pci_dev *dev, void __iomem *addr);
+extern void __iomap *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+extern void pci_iounmap (struct pci_dev *dev, void __iomap *addr);
 
 #endif /* __V850_PCI_H__ */
include/linux/pci.h +3 -3
Index: linux-work/include/linux/pci.h
===================================================================
@@ -1030,9 +1030,9 @@ enum pci_fixup_pass {
 
 void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
 
-void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
-void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
-void __iomem * const *pcim_iomap_table(struct pci_dev *pdev);
+void __iomap *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
+void pcim_iounmap(struct pci_dev *pdev, void __iomap *addr);
+void __iomap * const *pcim_iomap_table(struct pci_dev *pdev);
 int pcim_iomap_regions(struct pci_dev *pdev, u16 mask, const char *name);
 void pcim_iounmap_regions(struct pci_dev *pdev, u16 mask);
 
lib/devres.c +13 -13
Index: linux-work/lib/devres.c
===================================================================
@@ -90,7 +90,7 @@ EXPORT_SYMBOL(devm_iounmap);
  */
 static void devm_ioport_map_release(struct device *dev, void *res)
 {
-	ioport_unmap(*(void __iomem **)res);
+	ioport_unmap(*(void __iomap **)res);
 }
 
 static int devm_ioport_map_match(struct device *dev, void *res,
@@ -111,7 +111,7 @@ static int devm_ioport_map_match(struct 
 void __iomem * devm_ioport_map(struct device *dev, unsigned long port,
 			       unsigned int nr)
 {
-	void __iomem **ptr, *addr;
+	void __iomap **ptr, *addr;
 
 	ptr = devres_alloc(devm_ioport_map_release, sizeof(*ptr), GFP_KERNEL);
 	if (!ptr)
@@ -136,7 +136,7 @@ EXPORT_SYMBOL(devm_ioport_map);
  * Managed ioport_unmap().  @addr must have been mapped using
  * devm_ioport_map().
  */
-void devm_ioport_unmap(struct device *dev, void __iomem *addr)
+void devm_ioport_unmap(struct device *dev, void __iomap *addr)
 {
 	ioport_unmap(addr);
 	WARN_ON(devres_destroy(dev, devm_ioport_map_release,
@@ -151,7 +151,7 @@ EXPORT_SYMBOL(devm_ioport_unmap);
 #define PCIM_IOMAP_MAX	PCI_ROM_RESOURCE
 
 struct pcim_iomap_devres {
-	void __iomem *table[PCIM_IOMAP_MAX];
+	void __iomap *table[PCIM_IOMAP_MAX];
 };
 
 static void pcim_iomap_release(struct device *gendev, void *res)
@@ -178,7 +178,7 @@ static void pcim_iomap_release(struct de
  * be safely called without context and guaranteed to succed once
  * allocated.
  */
-void __iomem * const * pcim_iomap_table(struct pci_dev *pdev)
+void __iomap * const * pcim_iomap_table(struct pci_dev *pdev)
 {
 	struct pcim_iomap_devres *dr, *new_dr;
 
@@ -203,13 +203,13 @@ EXPORT_SYMBOL(pcim_iomap_table);
  * Managed pci_iomap().  Map is automatically unmapped on driver
  * detach.
  */
-void __iomem * pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
+void __iomap * pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
 {
-	void __iomem **tbl;
+	void __iomap **tbl;
 
 	BUG_ON(bar >= PCIM_IOMAP_MAX);
 
-	tbl = (void __iomem **)pcim_iomap_table(pdev);
+	tbl = (void __iomap **)pcim_iomap_table(pdev);
 	if (!tbl || tbl[bar])	/* duplicate mappings not allowed */
 		return NULL;
 
@@ -225,14 +225,14 @@ EXPORT_SYMBOL(pcim_iomap);
  *
  * Managed pci_iounmap().  @addr must have been mapped using pcim_iomap().
  */
-void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr)
+void pcim_iounmap(struct pci_dev *pdev, void __iomap *addr)
 {
-	void __iomem **tbl;
+	void __iomap **tbl;
 	int i;
 
 	pci_iounmap(pdev, addr);
 
-	tbl = (void __iomem **)pcim_iomap_table(pdev);
+	tbl = (void __iomap **)pcim_iomap_table(pdev);
 	BUG_ON(!tbl);
 
 	for (i = 0; i < PCIM_IOMAP_MAX; i++)
@@ -254,7 +254,7 @@ EXPORT_SYMBOL(pcim_iounmap);
  */
 int pcim_iomap_regions(struct pci_dev *pdev, u16 mask, const char *name)
 {
-	void __iomem * const *iomap;
+	void __iomap * const *iomap;
 	int i, rc;
 
 	iomap = pcim_iomap_table(pdev);
@@ -306,7 +306,7 @@ EXPORT_SYMBOL(pcim_iomap_regions);
  */
 void pcim_iounmap_regions(struct pci_dev *pdev, u16 mask)
 {
-	void __iomem * const *iomap;
+	void __iomap * const *iomap;
 	int i;
 
 	iomap = pcim_iomap_table(pdev);
#1 lore raw
Quoted 7 lines · Benjamin Herrenschmidt

The current iomap stuff (pci_iomap, ioport_map, pcim_iomap, ...) is confusing as it returns pointers in the _miomem address space.

However, even if that would work on some architectures, the result of those functions is -not- to be used as an __iomem, with accessors such as readl/writel, but only with the new brand of specific accessors (ioread32/iowrite32/...).

Willy and Al raised a good point off-list, is that in all effective implementations of this, the MMIO case -does- use compatible virtual addresses with ioremap, in fact even powerpc does.

Thus if we consider iomap as a kind of superset of the ioremap space with a "hole" in it for PIO, it's fine to use the same address space marker and it's fine to interchange the accessors when one -knows- for sure it's dealing with memory and not IO.

Thus drop my patch,

Ben.