Skip to contentSkip to conversation

powerpc: make iowrite32be etc. inline

RFC PATCH In review Rasmus Villemoes 3 participants 9 messages Oct 31, 2019 – Nov 2, 2019

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

cover powerpc: make iowrite32be etc. inline

When trying to make the QUICC Engine drivers compile on arm, I mechanically (with coccinelle) changed out_be32() to iowrite32be() etc. Christophe pointed out [1][2] that that would pessimize the powerpc SOCs since the IO accesses now incur a function call overhead. He asked that I try to make those io accessors inline on ppc, and this is the best I could come up with.

At first I tried something that wouldn't need to touch anything outside arch/powerpc/, but I ended up with conditional inclusion of asm-generic headers and/or duplicating a lot of their contents.

The diffstat may become a little better if kernel/iomap.c can indeed be removed (due to !CONFIG_PPC_INDIRECT_PIO && CONFIG_PPC_INDIRECT_MMIO never happening).

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

Rasmus Villemoes (5):
asm-generic: move pcu_iounmap from iomap.h to pci_iomap.h
asm-generic: employ "ifndef foo; define foo foo" idiom in iomap.h
powerpc: move pci_iounmap() from iomap.c to pci-common.c
powerpc: make pcibios_vaddr_is_ioport() static
powerpc: make iowrite32 and friends static inline when no indirection

 arch/powerpc/include/asm/io.h         | 172 ++++++++++++++++++++++++++
 arch/powerpc/include/asm/pci-bridge.h |   9 --
 arch/powerpc/kernel/Makefile          |   2 +-
 arch/powerpc/kernel/iomap.c           |  13 --
 arch/powerpc/kernel/pci-common.c      |  15 ++-
 include/asm-generic/iomap.h           | 104 +++++++++++++---
 include/asm-generic/pci_iomap.h       |   7 ++
 7 files changed, 282 insertions(+), 40 deletions(-)
Signature · 1 line
2.23.0
#1 lore raw

RFC PATCH 1/5 asm-generic: move pcu_iounmap from iomap.h to pci_iomap.h

pci_iounmap seems misplaced in iomap.h. Move it to where its cousins live. Since iomap.h includes pci_iomap.h, anybody relying on getting the declaration through iomap.h will still get it.

It would be natural to put the static inline version inside the

#elif defined(CONFIG_GENERIC_PCI_IOMAP)

Since GENERIC_IOMAP selects GENERIC_PCI_IOMAP, that would be ok for those who select GENERIC_IOMAP. However, I fear there are some that select GENERIC_PCI_IOMAP without GENERIC_IOMAP, and which perhaps have their own pci_iounmap stub definition somewhere. So for now at least, define the static inline version under the same conditions as it were in iomap.h.

---
 include/asm-generic/iomap.h     | 10 ----------
 include/asm-generic/pci_iomap.h |  7 +++++++
 2 files changed, 7 insertions(+), 10 deletions(-)
include/asm-generic/iomap.h +0 -10
index a008f504a2d0..5f8321e8fea9 100644
@@ -101,16 +101,6 @@ extern void ioport_unmap(void __iomem *);
 #define ioremap_wt ioremap_nocache
 #endif
 
-#ifdef CONFIG_PCI
-/* Destroy a virtual mapping cookie for a PCI BAR (memory or IO) */
-struct pci_dev;
-extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
-#elif defined(CONFIG_GENERIC_IOMAP)
-struct pci_dev;
-static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
-{ }
-#endif
-
 #include <asm-generic/pci_iomap.h>
 
 #endif
include/asm-generic/pci_iomap.h +7 -0
index d4f16dcc2ed7..c2f78db2420e 100644
@@ -18,6 +18,8 @@ extern void __iomem *pci_iomap_range(struct pci_dev *dev, int bar,
 extern void __iomem *pci_iomap_wc_range(struct pci_dev *dev, int bar,
 					unsigned long offset,
 					unsigned long maxlen);
+/* Destroy a virtual mapping cookie for a PCI BAR (memory or IO) */
+extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
 /* Create a virtual mapping cookie for a port on a given PCI device.
  * Do not call this directly, it exists to make it easier for architectures
  * to override */
@@ -52,4 +54,9 @@ static inline void __iomem *pci_iomap_wc_range(struct pci_dev *dev, int bar,
 }
 #endif
 
+#if !defined(CONFIG_PCI) && defined(CONFIG_GENERIC_IOMAP)
+static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
+{ }
+#endif
+
 #endif /* __ASM_GENERIC_IO_H */
Signature · 1 line
2.23.0
#2 lore raw

Re: [RFC PATCH 1/5] asm-generic: move pcu_iounmap from iomap.h to pci_iomap.h

[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Rasmus,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on powerpc/next]
[cannot apply to v5.4-rc5 next-20191031]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Rasmus-Villemoes/powerpc-make-iowrite32be-etc-inline/20191102-074232
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: riscv-defconfig (attached as .config)
compiler: riscv64-linux-gcc (GCC) 7.4.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=riscv

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

In file included from arch/riscv/include/asm/io.h:280:0,

                    from include/linux/io.h:13,
                    from include/linux/irq.h:20,
                    from include/asm-generic/hardirq.h:13,
                    from ./arch/riscv/include/generated/asm/hardirq.h:1,
                    from include/linux/hardirq.h:9,
                    from include/linux/highmem.h:10,
                    from include/linux/pagemap.h:11,
                    from include/linux/blkdev.h:16,
                    from include/linux/backing-dev.h:15,
                    from fs/open.c:16:
>> include/asm-generic/io.h:895:21: error: static declaration of 'pci_iounmap' follows non-static declaration
    #define pci_iounmap pci_iounmap
                        ^
   include/asm-generic/io.h:896:20: note: in expansion of macro 'pci_iounmap'
    static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
                       ^~~~~~~~~~~
   In file included from include/asm-generic/io.h:19:0,
                    from arch/riscv/include/asm/io.h:280,
                    from include/linux/io.h:13,
                    from include/linux/irq.h:20,
                    from include/asm-generic/hardirq.h:13,
                    from ./arch/riscv/include/generated/asm/hardirq.h:1,
                    from include/linux/hardirq.h:9,
                    from include/linux/highmem.h:10,
                    from include/linux/pagemap.h:11,
                    from include/linux/blkdev.h:16,
                    from include/linux/backing-dev.h:15,
                    from fs/open.c:16:
   include/asm-generic/pci_iomap.h:22:13: note: previous declaration of 'pci_iounmap' was here
    extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
                ^~~~~~~~~~~
--
   In file included from arch/riscv/include/asm/io.h:280:0,
                    from include/linux/io.h:13,
                    from include/linux/irq.h:20,
                    from include/asm-generic/hardirq.h:13,
                    from ./arch/riscv/include/generated/asm/hardirq.h:1,
                    from include/linux/hardirq.h:9,
                    from include/linux/highmem.h:10,
                    from include/linux/pagemap.h:11,
                    from include/linux/nfs_fs.h:24,
                    from fs//nfs/nfstrace.c:5:
>> include/asm-generic/io.h:895:21: error: static declaration of 'pci_iounmap' follows non-static declaration
    #define pci_iounmap pci_iounmap
                        ^
   include/asm-generic/io.h:896:20: note: in expansion of macro 'pci_iounmap'
    static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
                       ^~~~~~~~~~~
   In file included from include/asm-generic/io.h:19:0,
                    from arch/riscv/include/asm/io.h:280,
                    from include/linux/io.h:13,
                    from include/linux/irq.h:20,
                    from include/asm-generic/hardirq.h:13,
                    from ./arch/riscv/include/generated/asm/hardirq.h:1,
                    from include/linux/hardirq.h:9,
                    from include/linux/highmem.h:10,
                    from include/linux/pagemap.h:11,
                    from include/linux/nfs_fs.h:24,
                    from fs//nfs/nfstrace.c:5:
   include/asm-generic/pci_iomap.h:22:13: note: previous declaration of 'pci_iounmap' was here
    extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
                ^~~~~~~~~~~
   In file included from fs//nfs/nfstrace.h:1176:0,
                    from fs//nfs/nfstrace.c:10:
   include/trace/define_trace.h:95:42: fatal error: ./nfstrace.h: No such file or directory
    #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
                                             ^
   compilation terminated.
--
   In file included from arch/riscv/include/asm/io.h:280:0,
                    from include/linux/io.h:13,
                    from include/linux/irq.h:20,
                    from include/asm-generic/hardirq.h:13,
                    from ./arch/riscv/include/generated/asm/hardirq.h:1,
                    from include/linux/hardirq.h:9,
                    from include/linux/highmem.h:10,
                    from include/linux/pagemap.h:11,
                    from include/linux/nfs_fs.h:24,
                    from fs//nfs/nfs4trace.c:5:
>> include/asm-generic/io.h:895:21: error: static declaration of 'pci_iounmap' follows non-static declaration
    #define pci_iounmap pci_iounmap
                        ^
   include/asm-generic/io.h:896:20: note: in expansion of macro 'pci_iounmap'
    static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
                       ^~~~~~~~~~~
   In file included from include/asm-generic/io.h:19:0,
                    from arch/riscv/include/asm/io.h:280,
                    from include/linux/io.h:13,
                    from include/linux/irq.h:20,
                    from include/asm-generic/hardirq.h:13,
                    from ./arch/riscv/include/generated/asm/hardirq.h:1,
                    from include/linux/hardirq.h:9,
                    from include/linux/highmem.h:10,
                    from include/linux/pagemap.h:11,
                    from include/linux/nfs_fs.h:24,
                    from fs//nfs/nfs4trace.c:5:
   include/asm-generic/pci_iomap.h:22:13: note: previous declaration of 'pci_iounmap' was here
    extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
                ^~~~~~~~~~~
   In file included from fs//nfs/nfs4trace.h:1930:0,
                    from fs//nfs/nfs4trace.c:13:
   include/trace/define_trace.h:95:42: fatal error: ./nfs4trace.h: No such file or directory
    #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
                                             ^

compilation terminated.

vim +/pci_iounmap +895 include/asm-generic/io.h

cd24834130ac65 Jan Glauber    2012-11-29  893  
cd24834130ac65 Jan Glauber    2012-11-29  894  #ifndef pci_iounmap
9216efafc52ff9 Thierry Reding 2014-10-01 @895  #define pci_iounmap pci_iounmap
3f7e212df82ca0 Arnd Bergmann  2009-05-13  896  static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
3f7e212df82ca0 Arnd Bergmann  2009-05-13  897  {
3f7e212df82ca0 Arnd Bergmann  2009-05-13  898  }
cd24834130ac65 Jan Glauber    2012-11-29  899  #endif
3f7e212df82ca0 Arnd Bergmann  2009-05-13  900  #endif /* CONFIG_GENERIC_IOMAP */

3f7e212df82ca0 Arnd Bergmann 2009-05-13 901

:::::: The code at line 895 was first introduced by commit
:::::: 9216efafc52ff99e9351ef60de5fcafc2bc8adb6 asm-generic/io.h: Reconcile I/O accessor overrides

:::::: TO: Thierry Reding <[email protected]>
:::::: CC: Thierry Reding <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw

RFC PATCH 2/5 asm-generic: employ "ifndef foo; define foo foo" idiom in iomap.h

In reply to Rasmus Villemoes

Make it possible for an architecture to include asm-generic/iomap.h without necessarily getting all the external declarations for iowrite32 and friends. For example, the architecture could (maybe just in some configurations) provide static inline versions of some or all of these, but still use asm-generic/iomap.h for the ARCH_HAS_IOREMAP_WT/WC logic.

This will be used on powerpc.

---
 include/asm-generic/iomap.h | 94 ++++++++++++++++++++++++++++++++++---
 1 file changed, 88 insertions(+), 6 deletions(-)
include/asm-generic/iomap.h +88 -6
index 5f8321e8fea9..1b247d3b9fbb 100644
@@ -26,47 +26,105 @@
  * in the low address range. Architectures for which this is not
  * true can't use this generic implementation.
  */
+#ifndef ioread8
+#define ioread8 ioread8
 extern unsigned int ioread8(void __iomem *);
+#endif
+#ifndef ioread16
+#define ioread16 ioread16
 extern unsigned int ioread16(void __iomem *);
+#endif
+#ifndef ioread16be
+#define ioread16be ioread16be
 extern unsigned int ioread16be(void __iomem *);
+#endif
+#ifndef ioread32
+#define ioread32 ioread32
 extern unsigned int ioread32(void __iomem *);
+#endif
+#ifndef ioread32be
+#define ioread32be ioread32be
 extern unsigned int ioread32be(void __iomem *);
+#endif
 #ifdef CONFIG_64BIT
+#ifndef ioread64
+#define ioread64 ioread64
 extern u64 ioread64(void __iomem *);
+#endif
+#ifndef ioread64be
+#define ioread64be ioread64be
 extern u64 ioread64be(void __iomem *);
 #endif
+#endif /* CONFIG_64BIT */
 
 #ifdef readq
+#ifndef ioread64_lo_hi
 #define ioread64_lo_hi ioread64_lo_hi
-#define ioread64_hi_lo ioread64_hi_lo
-#define ioread64be_lo_hi ioread64be_lo_hi
-#define ioread64be_hi_lo ioread64be_hi_lo
 extern u64 ioread64_lo_hi(void __iomem *addr);
+#endif
+#ifndef ioread64_hi_lo
+#define ioread64_hi_lo ioread64_hi_lo
 extern u64 ioread64_hi_lo(void __iomem *addr);
+#endif
+#ifndef ioread64be_lo_hi
+#define ioread64be_lo_hi ioread64be_lo_hi
 extern u64 ioread64be_lo_hi(void __iomem *addr);
+#endif
+#ifndef ioread64be_hi_lo
+#define ioread64be_hi_lo ioread64be_hi_lo
 extern u64 ioread64be_hi_lo(void __iomem *addr);
 #endif
+#endif /* readq */
 
+#ifndef iowrite8
+#define iowrite8 iowrite8
 extern void iowrite8(u8, void __iomem *);
+#endif
+#ifndef iowrite16
+#define iowrite16 iowrite16
 extern void iowrite16(u16, void __iomem *);
+#endif
+#ifndef iowrite16be
+#define iowrite16be iowrite16be
 extern void iowrite16be(u16, void __iomem *);
+#endif
+#ifndef iowrite32
+#define iowrite32 iowrite32
 extern void iowrite32(u32, void __iomem *);
+#endif
+#ifndef iowrite32be
+#define iowrite32be iowrite32be
 extern void iowrite32be(u32, void __iomem *);
+#endif
 #ifdef CONFIG_64BIT
+#ifndef iowrite64
+#define iowrite64 iowrite64
 extern void iowrite64(u64, void __iomem *);
+#endif
+#ifndef iowrite64be
+#define iowrite64be iowrite64be
 extern void iowrite64be(u64, void __iomem *);
 #endif
+#endif /* CONFIG_64BIT */
 
 #ifdef writeq
+#ifndef iowrite64_lo_hi
 #define iowrite64_lo_hi iowrite64_lo_hi
-#define iowrite64_hi_lo iowrite64_hi_lo
-#define iowrite64be_lo_hi iowrite64be_lo_hi
-#define iowrite64be_hi_lo iowrite64be_hi_lo
 extern void iowrite64_lo_hi(u64 val, void __iomem *addr);
+#endif
+#ifndef iowrite64_hi_lo
+#define iowrite64_hi_lo iowrite64_hi_lo
 extern void iowrite64_hi_lo(u64 val, void __iomem *addr);
+#endif
+#ifndef iowrite64be_lo_hi
+#define iowrite64be_lo_hi iowrite64be_lo_hi
 extern void iowrite64be_lo_hi(u64 val, void __iomem *addr);
+#endif
+#ifndef iowrite64be_hi_lo
+#define iowrite64be_hi_lo iowrite64be_hi_lo
 extern void iowrite64be_hi_lo(u64 val, void __iomem *addr);
 #endif
+#endif /* writeq */
 
 /*
  * "string" versions of the above. Note that they
@@ -79,19 +137,43 @@ extern void iowrite64be_hi_lo(u64 val, void __iomem *addr);
  * memory across multiple ports, use "memcpy_toio()"
  * and friends.
  */
+#ifndef ioread8_rep
+#define ioread8_rep ioread8_rep
 extern void ioread8_rep(void __iomem *port, void *buf, unsigned long count);
+#endif
+#ifndef ioread16_rep
+#define ioread16_rep ioread16_rep
 extern void ioread16_rep(void __iomem *port, void *buf, unsigned long count);
+#endif
+#ifndef ioread32_rep
+#define ioread32_rep ioread32_rep
 extern void ioread32_rep(void __iomem *port, void *buf, unsigned long count);
+#endif
 
+#ifndef iowrite8_rep
+#define iowrite8_rep iowrite8_rep
 extern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
+#endif
+#ifndef iowrite16_rep
+#define iowrite16_rep iowrite16_rep
 extern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
+#endif
+#ifndef iowrite32_rep
+#define iowrite32_rep iowrite32_rep
 extern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
+#endif
 
 #ifdef CONFIG_HAS_IOPORT_MAP
 /* Create a virtual mapping cookie for an IO port range */
+#ifndef ioport_map
+#define ioport_map ioport_map
 extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
+#endif
+#ifndef ioport_unmap
+#define ioport_unmap ioport_unmap
 extern void ioport_unmap(void __iomem *);
 #endif
+#endif /* CONFIG_HAS_IOPORT_MAP */
 
 #ifndef ARCH_HAS_IOREMAP_WC
 #define ioremap_wc ioremap_nocache
Signature · 1 line
2.23.0
#4 lore raw

RFC PATCH 3/5 powerpc: move pci_iounmap() from iomap.c to pci-common.c

In reply to Rasmus Villemoes

As preparation for making iowrite32 and friends static inlines, move the definition of pci_iounmap() from iomap.c to pci-common.c. This definition of pci_iounmap() is compiled in when !CONFIG_PPC_INDIRECT_PIO && CONFIG_PCI - we're just interchanging which condition is in the Kbuild logic and which is in the .c file.

---
 arch/powerpc/kernel/iomap.c      | 13 -------------
 arch/powerpc/kernel/pci-common.c | 13 +++++++++++++
 2 files changed, 13 insertions(+), 13 deletions(-)
arch/powerpc/kernel/iomap.c +0 -13
index 5ac84efc6ede..b22fa8db5068 100644
@@ -182,16 +182,3 @@ void ioport_unmap(void __iomem *addr)
 }
 EXPORT_SYMBOL(ioport_map);
 EXPORT_SYMBOL(ioport_unmap);
-
-#ifdef CONFIG_PCI
-void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
-{
-	if (isa_vaddr_is_ioport(addr))
-		return;
-	if (pcibios_vaddr_is_ioport(addr))
-		return;
-	iounmap(addr);
-}
-
-EXPORT_SYMBOL(pci_iounmap);
-#endif /* CONFIG_PCI */
arch/powerpc/kernel/pci-common.c +13 -0
index 1c448cf25506..d89a2426b405 100644
@@ -34,6 +34,7 @@
 #include <asm/io.h>
 #include <asm/prom.h>
 #include <asm/pci-bridge.h>
+#include <asm/isa-bridge.h>
 #include <asm/byteorder.h>
 #include <asm/machdep.h>
 #include <asm/ppc-pci.h>
@@ -295,6 +296,18 @@ int pcibios_vaddr_is_ioport(void __iomem *address)
 	return ret;
 }
 
+#ifndef CONFIG_PPC_INDIRECT_PIO
+void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
+{
+	if (isa_vaddr_is_ioport(addr))
+		return;
+	if (pcibios_vaddr_is_ioport(addr))
+		return;
+	iounmap(addr);
+}
+EXPORT_SYMBOL(pci_iounmap);
+#endif /* CONFIG_PPC_INDIRECT_PIO */
+
 unsigned long pci_address_to_pio(phys_addr_t address)
 {
 	struct pci_controller *hose;
Signature · 1 line
2.23.0
#5 lore raw

RFC PATCH 4/5 powerpc: make pcibios_vaddr_is_ioport() static

In reply to Rasmus Villemoes

The only caller of pcibios_vaddr_is_ioport() is in pci-common.c, so we can make it static and move it into the same #ifndef block as its caller.

---
 arch/powerpc/include/asm/pci-bridge.h | 9 ---------
 arch/powerpc/kernel/pci-common.c      | 4 ++--
 2 files changed, 2 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/pci-bridge.h +0 -9
index ea6ec65970ef..deb29a1c9708 100644
@@ -283,14 +283,5 @@ extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev);
 extern void pcibios_free_controller(struct pci_controller *phb);
 extern void pcibios_free_controller_deferred(struct pci_host_bridge *bridge);
 
-#ifdef CONFIG_PCI
-extern int pcibios_vaddr_is_ioport(void __iomem *address);
-#else
-static inline int pcibios_vaddr_is_ioport(void __iomem *address)
-{
-	return 0;
-}
-#endif	/* CONFIG_PCI */
-
 #endif	/* __KERNEL__ */
 #endif	/* _ASM_POWERPC_PCI_BRIDGE_H */
arch/powerpc/kernel/pci-common.c +2 -2
index d89a2426b405..928d7576c6c2 100644
@@ -277,7 +277,8 @@ static resource_size_t pcibios_io_size(const struct pci_controller *hose)
 #endif
 }
 
-int pcibios_vaddr_is_ioport(void __iomem *address)
+#ifndef CONFIG_PPC_INDIRECT_PIO
+static int pcibios_vaddr_is_ioport(void __iomem *address)
 {
 	int ret = 0;
 	struct pci_controller *hose;
@@ -296,7 +297,6 @@ int pcibios_vaddr_is_ioport(void __iomem *address)
 	return ret;
 }
 
-#ifndef CONFIG_PPC_INDIRECT_PIO
 void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
 {
 	if (isa_vaddr_is_ioport(addr))
Signature · 1 line
2.23.0
#6 lore raw

RFC PATCH 5/5 powerpc: make iowrite32 and friends static inline when no indirection

In reply to Rasmus Villemoes

When porting a powerpc-only driver to work on another architecture, one has to change e.g. out_be32 to iowrite32be. Unfortunately, while the other target architecture (in my case arm) may have static inline definitions of iowrite32 and friends, this change pessimizes the existing powerpc users of that driver since out_be32() is inline while iowrite32be() is out-of-line.

When neither CONFIG_PPC_INDIRECT_PIO or CONFIG_PPC_INDIRECT_MMIO are set (e.g. all of PPC32), there's no reason for those to be out-of-line as they compile to just two or three instructions. So copy the definitions from iomap.c into io.h, make them static inline, and add the self-define macro boilerplate to prevent asm-generic/iomap.h from providing extern declarations.

This means that kernel/iomap.c is now only compiled when !CONFIG_PPC_INDIRECT_PIO && CONFIG_PPC_INDIRECT_MMIO - a combination I don't think currently exists. So it's possible that file could simply be deleted.

---
 arch/powerpc/include/asm/io.h | 172 ++++++++++++++++++++++++++++++++++
 arch/powerpc/kernel/Makefile  |   2 +-
 2 files changed, 173 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/io.h +172 -0
index a63ec938636d..a59310620067 100644
@@ -638,6 +638,178 @@ static inline void name at					\
 #define writel_relaxed(v, addr)	writel(v, addr)
 #define writeq_relaxed(v, addr)	writeq(v, addr)
 
+#if !defined(CONFIG_PPC_INDIRECT_PIO) && !defined(CONFIG_PPC_INDIRECT_MMIO)
+
+#define ioread8 ioread8
+static inline unsigned int ioread8(void __iomem *addr)
+{
+	return readb(addr);
+}
+#define ioread16 ioread16
+static inline unsigned int ioread16(void __iomem *addr)
+{
+	return readw(addr);
+}
+#define ioread16be ioread16be
+static inline unsigned int ioread16be(void __iomem *addr)
+{
+	return readw_be(addr);
+}
+#define ioread32 ioread32
+static inline unsigned int ioread32(void __iomem *addr)
+{
+	return readl(addr);
+}
+#define ioread32be ioread32be
+static inline unsigned int ioread32be(void __iomem *addr)
+{
+	return readl_be(addr);
+}
+#ifdef __powerpc64__
+#define ioread64 ioread64
+static inline u64 ioread64(void __iomem *addr)
+{
+	return readq(addr);
+}
+#define ioread64_lo_hi ioread64_lo_hi
+static inline u64 ioread64_lo_hi(void __iomem *addr)
+{
+	return readq(addr);
+}
+#define ioread64_hi_lo ioread64_hi_lo
+static inline u64 ioread64_hi_lo(void __iomem *addr)
+{
+	return readq(addr);
+}
+#define ioread64be ioread64be
+static inline u64 ioread64be(void __iomem *addr)
+{
+	return readq_be(addr);
+}
+#define ioread64be_lo_hi ioread64be_lo_hi
+static inline u64 ioread64be_lo_hi(void __iomem *addr)
+{
+	return readq_be(addr);
+}
+#define ioread64be_hi_lo ioread64be_hi_lo
+static inline u64 ioread64be_hi_lo(void __iomem *addr)
+{
+	return readq_be(addr);
+}
+#endif /* __powerpc64__ */
+
+#define iowrite8 iowrite8
+static inline void iowrite8(u8 val, void __iomem *addr)
+{
+	writeb(val, addr);
+}
+#define iowrite16 iowrite16
+static inline void iowrite16(u16 val, void __iomem *addr)
+{
+	writew(val, addr);
+}
+#define iowrite16be iowrite16be
+static inline void iowrite16be(u16 val, void __iomem *addr)
+{
+	writew_be(val, addr);
+}
+#define iowrite32 iowrite32
+static inline void iowrite32(u32 val, void __iomem *addr)
+{
+	writel(val, addr);
+}
+#define iowrite32be iowrite32be
+static inline void iowrite32be(u32 val, void __iomem *addr)
+{
+	writel_be(val, addr);
+}
+#ifdef __powerpc64__
+#define iowrite64 iowrite64
+static inline void iowrite64(u64 val, void __iomem *addr)
+{
+	writeq(val, addr);
+}
+#define iowrite64_lo_hi iowrite64_lo_hi
+static inline void iowrite64_lo_hi(u64 val, void __iomem *addr)
+{
+	writeq(val, addr);
+}
+#define iowrite64_hi_lo iowrite64_hi_lo
+static inline void iowrite64_hi_lo(u64 val, void __iomem *addr)
+{
+	writeq(val, addr);
+}
+#define iowrite64be iowrite64be
+static inline void iowrite64be(u64 val, void __iomem *addr)
+{
+	writeq_be(val, addr);
+}
+#define iowrite64be_lo_hi iowrite64be_lo_hi
+static inline void iowrite64be_lo_hi(u64 val, void __iomem *addr)
+{
+	writeq_be(val, addr);
+}
+#define iowrite64be_hi_lo iowrite64be_hi_lo
+static inline void iowrite64be_hi_lo(u64 val, void __iomem *addr)
+{
+	writeq_be(val, addr);
+}
+#endif /* __powerpc64__ */
+
+/*
+ * These are the "repeat read/write" functions. Note the
+ * non-CPU byte order. We do things in "IO byteorder"
+ * here.
+ *
+ * FIXME! We could make these do EEH handling if we really
+ * wanted. Not clear if we do.
+ */
+#define ioread8_rep ioread8_rep
+static inline void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
+{
+	readsb(addr, dst, count);
+}
+#define ioread16_rep ioread16_rep
+static inline void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
+{
+	readsw(addr, dst, count);
+}
+#define ioread32_rep ioread32_rep
+static inline void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
+{
+	readsl(addr, dst, count);
+}
+
+#define iowrite8_rep iowrite8_rep
+static inline void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
+{
+	writesb(addr, src, count);
+}
+#define iowrite16_rep iowrite16_rep
+static inline void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
+{
+	writesw(addr, src, count);
+}
+#define iowrite32_rep iowrite32_rep
+static inline void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
+{
+	writesl(addr, src, count);
+}
+
+#define ioport_map ioport_map
+static inline void __iomem *ioport_map(unsigned long port, unsigned int len)
+{
+	return (void __iomem *) (port + _IO_BASE);
+}
+
+#define ioport_unmap ioport_unmap
+static inline void ioport_unmap(void __iomem *addr)
+{
+	/* Nothing to do */
+}
+
+#endif /* !defined(CONFIG_PPC_INDIRECT_PIO) && !defined(CONFIG_PPC_INDIRECT_MMIO) */
+
 #include <asm-generic/iomap.h>
 
 static inline void iosync(void)
arch/powerpc/kernel/Makefile +1 -1
index a7ca8fe62368..0991b3cd007b 100644
@@ -143,7 +143,7 @@ obj-$(CONFIG_PPC_IO_WORKAROUNDS)	+= io-workarounds.o
 obj-y				+= trace/
 
 ifneq ($(CONFIG_PPC_INDIRECT_PIO),y)
-obj-y				+= iomap.o
+obj-$(CONFIG_PPC_INDIRECT_MMIO)	+= iomap.o
 endif
 
 obj64-$(CONFIG_PPC_TRANSACTIONAL_MEM)	+= tm.o
Signature · 1 line
2.23.0
#7 lore raw
In reply to Rasmus Villemoes
Quoted 3 lines · Rasmus Villemoes

At first I tried something that wouldn't need to touch anything outside arch/powerpc/, but I ended up with conditional inclusion of asm-generic headers and/or duplicating a lot of their contents.

Urrgh, this is much worse than I feared. Already 1/5 is broken because asm-generic.h includes asm-generic/iomap.h conditionally, but asm-generic/pci_iomap.h unconditionally, so now users of io.h with CONFIG_PCI and !CONFIG_GENERIC_IOMAP get an external declaration of pci_iounmap they didn't use to, in addition to the static inline defined in io.h.

And I didn't think 2/5 could break anything - on the premise that if somebody already have a non-trivial define of ioread16, they couldn't possibly also include asm-generic/iomap.h. alpha proves me wrong; as long as one doesn't define ioread16 until after iomap.h has been parsed, there's no problem (well, except of course if some static inline that uses ioread16 got parsed between the compiler seeing the extern declaration and alpha then defining the ioread16 macro, but apparently that doesn't happen).

So sorry for the noise. Maybe I'll just have to bite the bullet and introduce private qe_iowrite32be etc. and define them based on $ARCH. Any better ideas would be much appreciated.

Thanks,
Rasmus

maintainer
#8 lore raw
Quoted 5 lines · Rasmus Villemoes

On 31/10/2019 01.31, Rasmus Villemoes wrote:

So sorry for the noise. Maybe I'll just have to bite the bullet and introduce private qe_iowrite32be etc. and define them based on $ARCH. Any better ideas would be much appreciated.

We use that approach in a number of drivers already, I think it's ok to add it to another driver. Just make the powerpc case use out_be32 and everything else use iowrite32_be. You may also be able to enable the driver for CONFIG_COMPILE_TEST after that.

Arnd