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

openrisc: 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.

For openrisc, the current ioremap() and iounmap() are the same as generic
version. After taking GENERIC_IOREMAP way, the old ioremap() and
iounmap() can be completely removed.

Link: https://lkml.kernel.org/r/20230706154520.11257-10-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: Stafford Horne <shorne@gmail.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
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: 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: 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>

authored by

Baoquan He and committed by
Andrew Morton
9b994429 38d110ab

+7 -54
+1
arch/openrisc/Kconfig
··· 21 21 select GENERIC_IRQ_PROBE 22 22 select GENERIC_IRQ_SHOW 23 23 select GENERIC_PCI_IOMAP 24 + select GENERIC_IOREMAP 24 25 select GENERIC_CPU_DEVICES 25 26 select HAVE_PCI 26 27 select HAVE_UID16
+6 -5
arch/openrisc/include/asm/io.h
··· 15 15 #define __ASM_OPENRISC_IO_H 16 16 17 17 #include <linux/types.h> 18 + #include <asm/pgalloc.h> 19 + #include <asm/pgtable.h> 18 20 19 21 /* 20 22 * PCI: We do not use IO ports in OpenRISC ··· 29 27 #define PIO_OFFSET 0 30 28 #define PIO_MASK 0 31 29 32 - #define ioremap ioremap 33 - void __iomem *ioremap(phys_addr_t offset, unsigned long size); 34 - 35 - #define iounmap iounmap 36 - extern void iounmap(volatile void __iomem *addr); 30 + /* 31 + * I/O memory mapping functions. 32 + */ 33 + #define _PAGE_IOREMAP (pgprot_val(PAGE_KERNEL) | _PAGE_CI) 37 34 38 35 #include <asm-generic/io.h> 39 36
-49
arch/openrisc/mm/ioremap.c
··· 22 22 23 23 extern int mem_init_done; 24 24 25 - /* 26 - * Remap an arbitrary physical address space into the kernel virtual 27 - * address space. Needed when the kernel wants to access high addresses 28 - * directly. 29 - * 30 - * NOTE! We need to allow non-page-aligned mappings too: we will obviously 31 - * have to convert them into an offset in a page-aligned mapping, but the 32 - * caller shouldn't need to know that small detail. 33 - */ 34 - void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size) 35 - { 36 - phys_addr_t p; 37 - unsigned long v; 38 - unsigned long offset, last_addr; 39 - struct vm_struct *area = NULL; 40 - 41 - /* Don't allow wraparound or zero size */ 42 - last_addr = addr + size - 1; 43 - if (!size || last_addr < addr) 44 - return NULL; 45 - 46 - /* 47 - * Mappings have to be page-aligned 48 - */ 49 - offset = addr & ~PAGE_MASK; 50 - p = addr & PAGE_MASK; 51 - size = PAGE_ALIGN(last_addr + 1) - p; 52 - 53 - area = get_vm_area(size, VM_IOREMAP); 54 - if (!area) 55 - return NULL; 56 - v = (unsigned long)area->addr; 57 - 58 - if (ioremap_page_range(v, v + size, p, 59 - __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CI))) { 60 - vfree(area->addr); 61 - return NULL; 62 - } 63 - 64 - return (void __iomem *)(offset + (char *)v); 65 - } 66 - EXPORT_SYMBOL(ioremap); 67 - 68 - void iounmap(volatile void __iomem *addr) 69 - { 70 - return vfree((void *)(PAGE_MASK & (unsigned long)addr)); 71 - } 72 - EXPORT_SYMBOL(iounmap); 73 - 74 25 /** 75 26 * OK, this one's a bit tricky... ioremap can get called before memory is 76 27 * initialized (early serial console does this) and will want to alloc a page