powerpc: mm: convert to GENERIC_IOREMAP
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Thu, 6 Jul 2023 15:45:18 +0000 (23:45 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 18 Aug 2023 17:12:35 +0000 (10:12 -0700)
By taking GENERIC_IOREMAP method, the generic generic_ioremap_prot(),
generic_iounmap(), and their generic wrapper ioremap_prot(), ioremap()
and iounmap() are all visible and available to arch. Arch needs to
provide wrapper functions to override the generic versions if there's
arch specific handling in its ioremap_prot(), ioremap() or iounmap().
This change will simplify implementation by removing duplicated code
with generic_ioremap_prot() and generic_iounmap(), and has the equivalent
functioality as before.

Here, add wrapper functions ioremap_prot() and iounmap() for powerpc's
special operation when ioremap() and iounmap().

Link: https://lkml.kernel.org/r/20230706154520.11257-18-bhe@redhat.com
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Baoquan He <bhe@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Brian Cain <bcain@quicinc.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: David Laight <David.Laight@ACULAB.COM>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Niklas Schnelle <schnelle@linux.ibm.com>
Cc: Rich Felker <dalias@libc.org>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vineet Gupta <vgupta@kernel.org>
Cc: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/powerpc/Kconfig
arch/powerpc/include/asm/io.h
arch/powerpc/mm/ioremap.c
arch/powerpc/mm/ioremap_32.c
arch/powerpc/mm/ioremap_64.c

index 0b1172cbeccb302191362b9f288c6f5ed01d36a2..9222c138c45702ff0f1257851edc68951ecdacb3 100644 (file)
@@ -193,6 +193,7 @@ config PPC
        select GENERIC_CPU_VULNERABILITIES      if PPC_BARRIER_NOSPEC
        select GENERIC_EARLY_IOREMAP
        select GENERIC_GETTIMEOFDAY
+       select GENERIC_IOREMAP
        select GENERIC_IRQ_SHOW
        select GENERIC_IRQ_SHOW_LEVEL
        select GENERIC_PCI_IOMAP                if PCI
index 67a3fb6de498efe752d1c474a7ee8890ea39c4ff..0732b743e099624d63eb062ef777a662fae5d6e8 100644 (file)
@@ -889,8 +889,8 @@ static inline void iosync(void)
  *
  */
 extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
-extern void __iomem *ioremap_prot(phys_addr_t address, unsigned long size,
-                                 unsigned long flags);
+#define ioremap ioremap
+#define ioremap_prot ioremap_prot
 extern void __iomem *ioremap_wc(phys_addr_t address, unsigned long size);
 #define ioremap_wc ioremap_wc
 
@@ -904,14 +904,12 @@ void __iomem *ioremap_coherent(phys_addr_t address, unsigned long size);
 #define ioremap_cache(addr, size) \
        ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL))
 
-extern void iounmap(volatile void __iomem *addr);
+#define iounmap iounmap
 
 void __iomem *ioremap_phb(phys_addr_t paddr, unsigned long size);
 
 int early_ioremap_range(unsigned long ea, phys_addr_t pa,
                        unsigned long size, pgprot_t prot);
-void __iomem *do_ioremap(phys_addr_t pa, phys_addr_t offset, unsigned long size,
-                        pgprot_t prot, void *caller);
 
 extern void __iomem *__ioremap_caller(phys_addr_t, unsigned long size,
                                      pgprot_t prot, void *caller);
index 4f12504fb405b170d58d46f4636d7f99e6e6d368..705e8e8ffde4d7e653edc42c18aaf2c2788fb363 100644 (file)
@@ -41,7 +41,7 @@ void __iomem *ioremap_coherent(phys_addr_t addr, unsigned long size)
        return __ioremap_caller(addr, size, prot, caller);
 }
 
-void __iomem *ioremap_prot(phys_addr_t addr, unsigned long size, unsigned long flags)
+void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long flags)
 {
        pte_t pte = __pte(flags);
        void *caller = __builtin_return_address(0);
@@ -74,27 +74,3 @@ int early_ioremap_range(unsigned long ea, phys_addr_t pa,
 
        return 0;
 }
-
-void __iomem *do_ioremap(phys_addr_t pa, phys_addr_t offset, unsigned long size,
-                        pgprot_t prot, void *caller)
-{
-       struct vm_struct *area;
-       int ret;
-       unsigned long va;
-
-       area = __get_vm_area_caller(size, VM_IOREMAP, IOREMAP_START, IOREMAP_END, caller);
-       if (area == NULL)
-               return NULL;
-
-       area->phys_addr = pa;
-       va = (unsigned long)area->addr;
-
-       ret = ioremap_page_range(va, va + size, pa, prot);
-       if (!ret)
-               return (void __iomem *)area->addr + offset;
-
-       vunmap_range(va, va + size);
-       free_vm_area(area);
-
-       return NULL;
-}
index 9d13143b8be496a8625f5b3ba7a76e86d2d15d71..ca5bc6be3e6f997e7a6bdc7530eb11ba09530f10 100644 (file)
@@ -21,6 +21,13 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call
        phys_addr_t p, offset;
        int err;
 
+       /*
+        * If the address lies within the first 16 MB, assume it's in ISA
+        * memory space
+        */
+       if (addr < SZ_16M)
+               addr += _ISA_MEM_BASE;
+
        /*
         * Choose an address to map it to.
         * Once the vmalloc system is running, we use it.
@@ -31,13 +38,6 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call
        offset = addr & ~PAGE_MASK;
        size = PAGE_ALIGN(addr + size) - p;
 
-       /*
-        * If the address lies within the first 16 MB, assume it's in ISA
-        * memory space
-        */
-       if (p < 16 * 1024 * 1024)
-               p += _ISA_MEM_BASE;
-
 #ifndef CONFIG_CRASH_DUMP
        /*
         * Don't allow anybody to remap normal RAM that we're using.
@@ -63,7 +63,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call
                return (void __iomem *)v + offset;
 
        if (slab_is_available())
-               return do_ioremap(p, offset, size, prot, caller);
+               return generic_ioremap_prot(addr, size, prot);
 
        /*
         * Should check if it is a candidate for a BAT mapping
@@ -87,7 +87,6 @@ void iounmap(volatile void __iomem *addr)
        if (v_block_mapped((unsigned long)addr))
                return;
 
-       if (addr > high_memory && (unsigned long)addr < ioremap_bot)
-               vunmap((void *)(PAGE_MASK & (unsigned long)addr));
+       generic_iounmap(addr);
 }
 EXPORT_SYMBOL(iounmap);
index 3acece00b33e87680d83b37f9c16f69a5940e621..d24e5f1667237dc20d479868af5aadf49f5bf499 100644 (file)
@@ -29,7 +29,7 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size,
                return NULL;
 
        if (slab_is_available())
-               return do_ioremap(paligned, offset, size, prot, caller);
+               return generic_ioremap_prot(addr, size, prot);
 
        pr_warn("ioremap() called early from %pS. Use early_ioremap() instead\n", caller);
 
@@ -49,17 +49,9 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size,
  */
 void iounmap(volatile void __iomem *token)
 {
-       void *addr;
-
        if (!slab_is_available())
                return;
 
-       addr = (void *)((unsigned long __force)PCI_FIX_ADDR(token) & PAGE_MASK);
-
-       if ((unsigned long)addr < ioremap_bot) {
-               pr_warn("Attempt to iounmap early bolted mapping at 0x%p\n", addr);
-               return;
-       }
-       vunmap(addr);
+       generic_iounmap(PCI_FIX_ADDR(token));
 }
 EXPORT_SYMBOL(iounmap);