Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arc: mm: convert to GENERIC_IOREMAP

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 arc's special
operation when ioremap_prot() and iounmap().

Link: https://lkml.kernel.org/r/20230706154520.11257-8-bhe@redhat.com
Signed-off-by: Baoquan He <bhe@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Vineet Gupta <vgupta@kernel.org>
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: Christophe Leroy <christophe.leroy@csgroup.eu>
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: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
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: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Baoquan He and committed by
Andrew Morton
06dfae39 a5f61648

+8 -49
+1
arch/arc/Kconfig
··· 26 26 select GENERIC_PENDING_IRQ if SMP 27 27 select GENERIC_SCHED_CLOCK 28 28 select GENERIC_SMP_IDLE_THREAD 29 + select GENERIC_IOREMAP 29 30 select HAVE_ARCH_KGDB 30 31 select HAVE_ARCH_TRACEHOOK 31 32 select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARC_MMU_V4
+3 -4
arch/arc/include/asm/io.h
··· 21 21 #endif 22 22 23 23 extern void __iomem *ioremap(phys_addr_t paddr, unsigned long size); 24 - extern void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size, 25 - unsigned long flags); 24 + #define ioremap ioremap 25 + #define ioremap_prot ioremap_prot 26 + #define iounmap iounmap 26 27 static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) 27 28 { 28 29 return (void __iomem *)port; ··· 32 31 static inline void ioport_unmap(void __iomem *addr) 33 32 { 34 33 } 35 - 36 - extern void iounmap(const volatile void __iomem *addr); 37 34 38 35 /* 39 36 * io{read,write}{16,32}be() macros
+4 -45
arch/arc/mm/ioremap.c
··· 8 8 #include <linux/module.h> 9 9 #include <linux/io.h> 10 10 #include <linux/mm.h> 11 - #include <linux/slab.h> 12 11 #include <linux/cache.h> 13 12 14 13 static inline bool arc_uncached_addr_space(phys_addr_t paddr) ··· 24 25 25 26 void __iomem *ioremap(phys_addr_t paddr, unsigned long size) 26 27 { 27 - phys_addr_t end; 28 - 29 - /* Don't allow wraparound or zero size */ 30 - end = paddr + size - 1; 31 - if (!size || (end < paddr)) 32 - return NULL; 33 - 34 28 /* 35 29 * If the region is h/w uncached, MMU mapping can be elided as optim 36 30 * The cast to u32 is fine as this region can only be inside 4GB ··· 43 51 * ARC hardware uncached region, this one still goes thru the MMU as caller 44 52 * might need finer access control (R/W/X) 45 53 */ 46 - void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size, 54 + void __iomem *ioremap_prot(phys_addr_t paddr, size_t size, 47 55 unsigned long flags) 48 56 { 49 - unsigned int off; 50 - unsigned long vaddr; 51 - struct vm_struct *area; 52 - phys_addr_t end; 53 57 pgprot_t prot = __pgprot(flags); 54 58 55 - /* Don't allow wraparound, zero size */ 56 - end = paddr + size - 1; 57 - if ((!size) || (end < paddr)) 58 - return NULL; 59 - 60 - /* An early platform driver might end up here */ 61 - if (!slab_is_available()) 62 - return NULL; 63 - 64 59 /* force uncached */ 65 - prot = pgprot_noncached(prot); 66 - 67 - /* Mappings have to be page-aligned */ 68 - off = paddr & ~PAGE_MASK; 69 - paddr &= PAGE_MASK_PHYS; 70 - size = PAGE_ALIGN(end + 1) - paddr; 71 - 72 - /* 73 - * Ok, go for it.. 74 - */ 75 - area = get_vm_area(size, VM_IOREMAP); 76 - if (!area) 77 - return NULL; 78 - area->phys_addr = paddr; 79 - vaddr = (unsigned long)area->addr; 80 - if (ioremap_page_range(vaddr, vaddr + size, paddr, prot)) { 81 - vunmap((void __force *)vaddr); 82 - return NULL; 83 - } 84 - return (void __iomem *)(off + (char __iomem *)vaddr); 60 + return generic_ioremap_prot(paddr, size, pgprot_noncached(prot)); 85 61 } 86 62 EXPORT_SYMBOL(ioremap_prot); 87 63 88 - 89 - void iounmap(const volatile void __iomem *addr) 64 + void iounmap(volatile void __iomem *addr) 90 65 { 91 66 /* weird double cast to handle phys_addr_t > 32 bits */ 92 67 if (arc_uncached_addr_space((phys_addr_t)(u32)addr)) 93 68 return; 94 69 95 - vfree((void *)(PAGE_MASK & (unsigned long __force)addr)); 70 + generic_iounmap(addr); 96 71 } 97 72 EXPORT_SYMBOL(iounmap);