mm: ioremap: Convert architectures to take GENERIC_IOREMAP way
Subsystems (12)
PATCH 5/11 hexagon: mm: Convert to GENERIC_IOREMAP
In reply to Baoquan HeWith it, the old ioremap() and iounmap() can be perfectly removed since they are duplicated with the standard functions.
--- arch/hexagon/Kconfig | 1 + arch/hexagon/include/asm/io.h | 9 +++++-- arch/hexagon/mm/ioremap.c | 44 ----------------------------------- 3 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 arch/hexagon/mm/ioremap.c
arch/hexagon/Kconfig +1 -0
@@ -25,6 +25,7 @@ config HEXAGON select NEED_SG_DMA_LENGTH select NO_IOPORT_MAP select GENERIC_IOMAP + select GENERIC_IOREMAP select GENERIC_SMP_IDLE_THREAD select STACKTRACE_SUPPORT select GENERIC_CLOCKEVENTS_BROADCAST
arch/hexagon/include/asm/io.h +7 -2
@@ -170,8 +170,13 @@ static inline void writel(u32 data, volatile void __iomem *addr)#define writew_relaxed __raw_writew#define writel_relaxed __raw_writel -void __iomem *ioremap (unsigned long phys_addr,unsigned long size); -#define ioremap_uc (X ,Y ) ioremap((X), (Y)) +/* +* I/O memory mapping functions. +*/ +#define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \ + (__HEXAGON_C_DEV << 6)) + +#define ioremap_uc (addr, size) ioremap((addr), (size))#define __raw_writel writel
arch/hexagon/mm/ioremap.c deleted +0 -44
44 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 6/11 ia64: mm: Convert to GENERIC_IOREMAP
In reply to Baoquan HeAdd hooks ioremap_allowed() and iounmap_allowed() for ia64's special operation when ioremap() and iounmap(), then ioremap_cache() is converted to use ioremap_prot() from GENERIC_IOREMAP.
The old ioremap_uc() is kept and add its macro definittion.
--- arch/ia64/Kconfig | 1 + arch/ia64/include/asm/io.h | 26 ++++++++++++-------- arch/ia64/mm/ioremap.c | 50 +++++++++----------------------------- 3 files changed, 28 insertions(+), 49 deletions(-)
arch/ia64/Kconfig +1 -0
@@ -46,6 +46,7 @@ config IA64 select GENERIC_IRQ_LEGACY select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_IOMAP + select GENERIC_IOREMAP select GENERIC_SMP_IDLE_THREAD select ARCH_TASK_STRUCT_ON_STACK select ARCH_TASK_STRUCT_ALLOCATOR
arch/ia64/include/asm/io.h +16 -10
@@ -255,17 +255,23 @@ static inline void outsl(unsigned long port, const void *src,# ifdef __KERNEL__ -extern void __iomem *ioremap (unsigned long offset,unsigned long size); -extern void __iomem *ioremap_uc (unsigned long offset,unsigned long size); -extern void iounmap (volatile void __iomem *addr); -static inline void __iomem *ioremap_cache (unsigned long phys_addr,unsigned long size) -{ -return ioremap (phys_addr, size); -} -#define ioremap ioremap -#define ioremap_cache ioremap_cache +/* +* I/O memory mapping functions. +*/ +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed (void *addr); +#define iounmap_allowed iounmap_allowed + +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL) + +#define ioremap_cache (addr, size) \ + ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) + +void __iomem *ioremap_uc (unsigned long offset,unsigned long size);#define ioremap_uc ioremap_uc -#define iounmap iounmap/* * String version of IO memory access ops:
arch/ia64/mm/ioremap.c +11 -39
72 lines not on this page · raw message
Signature · 1 line
2.34.1
cover mm: ioremap: Convert architectures to take GENERIC_IOREMAP way
Currently, many architecutres have't taken the standard GENERIC_IOREMAP way to implement ioremap_prot(), iounmap(), and ioremap_xx(), but make these functions specifically under each arch's folder. Those cause many duplicated codes of ioremap() and iounmap().
In this patchset, firstly adapt the hooks io[re|un]map_allowed, then make use of them to convert those ARCH-es to take GENERIC_IOREMAP method. With these change, duplicated ioremap/iounmap() code uder ARCH-es are removed.
This is suggested by Christoph in below discussion:
https://lore.kernel.org/all/[email protected]/T/#u
And it's basically further action after arm64 has converted to GENERIC_IOREMAP way in below patchset.
[PATCH v5 0/6] arm64: Cleanup ioremap() and support ioremap_prot()
https://lore.kernel.org/all/[email protected]/T/#u
And some change of io[re|un]map_allowed() is borrowed from the v3 of arm64 converting patch.
[PATCH v3 4/6] mm: ioremap: Add arch_ioremap/iounmap()
https://lore.kernel.org/all/[email protected]/T/#u
For patch 1~3, I don't merge them because I made them in different rounds of changing. And splitting them makes me easily describe the intention and make review easier. I can merge them after v1 reviewing if anyone thinks they should be merged.
Testing:
It passes the testing on arm64 and s390. For other ARCHes, I only tried to pass build with existing RPMs of cross compiling tools. ARCHes like openrisc, parisc, don't build because of lack of cross compiling RPMS.
Baoquan He (11):
mm/ioremap: change the return value of io[re|un]map_allowed
mm: ioremap: fixup the physical address
mm: ioremap: allow ARCH to have its own ioremap definition
arc: mm: Convert to GENERIC_IOREMAP
hexagon: mm: Convert to GENERIC_IOREMAP
ia64: mm: Convert to GENERIC_IOREMAP
openrisc: mm: Convert to GENERIC_IOREMAP
parisc: mm: Convert to GENERIC_IOREMAP
s390: mm: Convert to GENERIC_IOREMAP
sh: mm: Convert to GENERIC_IOREMAP
xtensa: mm: Convert to GENERIC_IOREMAP
arch/arc/Kconfig | 1 + arch/arc/include/asm/io.h | 19 +++++++--- arch/arc/mm/ioremap.c | 60 +++++-------------------------- arch/arm64/include/asm/io.h | 3 +- arch/arm64/mm/ioremap.c | 17 ++++++--- arch/hexagon/Kconfig | 1 + arch/hexagon/include/asm/io.h | 9 +++-- arch/hexagon/mm/ioremap.c | 44 ----------------------- arch/ia64/Kconfig | 1 + arch/ia64/include/asm/io.h | 26 ++++++++------ arch/ia64/mm/ioremap.c | 50 ++++++-------------------- arch/openrisc/Kconfig | 1 + arch/openrisc/include/asm/io.h | 16 ++++++--- arch/openrisc/mm/ioremap.c | 49 ++++++++----------------- arch/parisc/include/asm/io.h | 16 ++++++--- arch/parisc/mm/ioremap.c | 66 ++++------------------------------ arch/s390/Kconfig | 1 + arch/s390/include/asm/io.h | 26 +++++++++----- arch/s390/pci/pci.c | 60 +++++-------------------------- arch/sh/Kconfig | 1 + arch/sh/include/asm/io.h | 47 ++++++++---------------- arch/sh/mm/ioremap.c | 62 +++++++------------------------- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/io.h | 39 ++++++++++---------- arch/xtensa/mm/ioremap.c | 56 +++++++---------------------- include/asm-generic/io.h | 24 +++++++------ mm/ioremap.c | 21 ++++++----- 27 files changed, 232 insertions(+), 485 deletions(-) delete mode 100644 arch/hexagon/mm/ioremap.c
Signature · 1 line
2.34.1
PATCH 1/11 mm/ioremap: change the return value of io[re|un]map_allowed
In some architectures, there are arch specifici io address mapping handling when calling ioremap() or ioremap_prot(), e.g, arc, ia64, openrisc, s390, sh.
In oder to convert them to take GENERIC_IOREMAP method, we need change the return value of ioremap_allowed() and iounmap_allowed() as below.
===
ioremap_allowed() return a bool,
- IS_ERR means return an error
- NULL means continue to remap
- a non-NULL, non-IS_ERR pointer is returned directly
iounmap_allowed() return a bool,
- 0 means continue to vunmap
- error code means skip vunmap and return directly
This is taken from Kefeng's below old patch. Christoph suggested the return value because he foresaw the doablity of converting to take GENERIC_IOREMAP on more architectures.
- [PATCH v3 4/6] mm: ioremap: Add arch_ioremap/iounmap()
- https://lore.kernel.org/all/[email protected]/T/#u
This is preparation for later patch, no functionality change.
--- arch/arm64/include/asm/io.h | 2 +- arch/arm64/mm/ioremap.c | 9 +++++---- include/asm-generic/io.h | 17 +++++++++-------- mm/ioremap.c | 10 +++++++--- 4 files changed, 22 insertions(+), 16 deletions(-)
arch/arm64/include/asm/io.h +1 -1
@@ -164,7 +164,7 @@ extern void __memset_io(volatile void __iomem *, int, size_t);* I/O memory mapping functions. */ -bool ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot); +void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot);#define ioremap_allowed ioremap_allowed#define _PAGE_IOREMAP PROT_DEVICE_nGnRE
arch/arm64/mm/ioremap.c +5 -4
@@ -3,19 +3,20 @@#include <linux/mm.h> #include <linux/io.h> -bool ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) {unsigned long last_addr = phys_addr + size -1 ; +int ret = -EINVAL ;/* Don't allow outside PHYS_MASK */ if (last_addr & ~PHYS_MASK ) -return false; +return IOMEM_ERR_PTR (ret);/* Don't allow RAM to be mapped. */ if (WARN_ON (pfn_is_map_memory (__phys_to_pfn (phys_addr)))) -return false; +return IOMEM_ERR_PTR (ret); -return true; +return NULL ; }/*
include/asm-generic/io.h +9 -8
@@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr)/* * Arch code can implement the following two hooks when using GENERIC_IOREMAP * ioremap_allowed() return a bool, -* - true means continue to remap -* - false means skip remap and return directly +* - IS_ERR means return an error +* - NULL means continue to remap +* - a non-NULL, non-IS_ERR pointer is returned directly * iounmap_allowed() return a bool, -* - true means continue to vunmap -* - false means skip vunmap and return directly +* - 0 means continue to vunmap +* - error code means skip vunmap and return directly */ #ifndef ioremap_allowed#define ioremap_allowed ioremap_allowed -static inline bool ioremap_allowed (phys_addr_t phys_addr,size_t size, +static inline void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) { -return true; +return NULL ; }#endif #ifndef iounmap_allowed#define iounmap_allowed iounmap_allowed -static inline bool iounmap_allowed (void *addr) +static inline int iounmap_allowed (void *addr) { -return true; +return 0 ; }#endif
mm/ioremap.c +7 -3
@@ -17,6 +17,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,unsigned long offset, vaddr;phys_addr_t last_addr;struct vm_struct *area; +void __iomem *base;/* Disallow wrap-around or zero size */ last_addr = phys_addr + size -1 ;
@@ -28,8 +29,11 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size =PAGE_ALIGN (size + offset); -if (!ioremap_allowed (phys_addr, size, prot)) + base =ioremap_allowed (phys_addr, size, prot); +if (IS_ERR (base))return NULL ; +else if (base) +return base; area =get_vm_area_caller (size,VM_IOREMAP ,__builtin_return_address (0 ));
@@ -50,9 +54,9 @@ EXPORT_SYMBOL(ioremap_prot);void iounmap (volatile void __iomem *addr) { -void *vaddr = (void *)((unsigned long )addr &PAGE_MASK ); +void __iomem *vaddr = (void __iomem *)((unsigned long )addr &PAGE_MASK ); -if (!iounmap_allowed (vaddr)) +if (iounmap_allowed (vaddr))return ;if (is_vmalloc_addr (vaddr))
Signature · 1 line
2.34.1
PATCH 2/11 mm: ioremap: fixup the physical address
In reply to Baoquan HeIn some architectures, the io address will be fixed up before doing mapping, e.g, parisc, mips.
In oder to convert them to take GENERIC_IOREMAP method, we need wrap the address fixing up code into ioremap_allowed() and pass the new address out for ioremap_prot() handling.
This is a preparation patch, no functionality change.
--- arch/arm64/include/asm/io.h | 3 ++- arch/arm64/mm/ioremap.c | 10 ++++++++-- include/asm-generic/io.h | 6 +++--- mm/ioremap.c | 19 ++++++++++--------- 4 files changed, 23 insertions(+), 15 deletions(-)
arch/arm64/include/asm/io.h +2 -1
@@ -164,7 +164,8 @@ extern void __memset_io(volatile void __iomem *, int, size_t);* I/O memory mapping functions. */ -void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot); +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val);#define ioremap_allowed ioremap_allowed#define _PAGE_IOREMAP PROT_DEVICE_nGnRE
arch/arm64/mm/ioremap.c +8 -2
@@ -3,11 +3,17 @@#include <linux/mm.h> #include <linux/io.h> -void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val) { -unsigned long last_addr = phys_addr + size -1 ; +unsigned long last_addr, offset, phys_addr = *paddr;int ret = -EINVAL ; + offset = phys_addr & (~PAGE_MASK ); + phys_addr -= offset; + size =PAGE_ALIGN (size + offset); + last_addr = phys_addr + size -1 ; +/* Don't allow outside PHYS_MASK */ if (last_addr & ~PHYS_MASK )return IOMEM_ERR_PTR (ret);
include/asm-generic/io.h +3 -3
@@ -976,8 +976,8 @@ static inline void iounmap(volatile void __iomem *addr)*/ #ifndef ioremap_allowed#define ioremap_allowed ioremap_allowed -static inline void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size, -unsigned long prot) +static inline void __iomem *ioremap_allowed (phys_addr_t *paddr,size_t size, +unsigned long *prot_val) {return NULL ; }
@@ -991,7 +991,7 @@ static inline int iounmap_allowed(void *addr) }#endif -void __iomem *ioremap_prot (phys_addr_t phys_addr,size_t size, +void __iomem *ioremap_prot (phys_addr_t paddr,size_t size,unsigned long prot);void iounmap (volatile void __iomem *addr);
mm/ioremap.c +10 -9
@@ -11,13 +11,20 @@#include <linux/io.h> #include <linux/export.h> -void __iomem *ioremap_prot (phys_addr_t phys_addr,size_t size, +void __iomem *ioremap_prot (phys_addr_t paddr,size_t size,unsigned long prot) {unsigned long offset, vaddr; -phys_addr_t last_addr; +phys_addr_t last_addr, phys_addr = paddr;struct vm_struct *area;void __iomem *base; +unsigned long prot_val = prot; + + base =ioremap_allowed (&phys_addr, size, &prot_val); +if (IS_ERR (base)) +return NULL ; +else if (base) +return base;/* Disallow wrap-around or zero size */ last_addr = phys_addr + size -1 ;
@@ -29,12 +36,6 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size =PAGE_ALIGN (size + offset); - base =ioremap_allowed (phys_addr, size, prot); -if (IS_ERR (base)) -return NULL ; -else if (base) -return base; - area =get_vm_area_caller (size,VM_IOREMAP ,__builtin_return_address (0 ));if (!area)
@@ -43,7 +44,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, area->phys_addr = phys_addr;if (ioremap_page_range (vaddr, vaddr + size, phys_addr, -__pgprot (prot))) { +__pgprot (prot_val))) {free_vm_area (area);return NULL ; }
Signature · 1 line
2.34.1
PATCH 4/11 arc: mm: Convert to GENERIC_IOREMAP
In reply to Baoquan HeAdd hooks ioremap_allowed() and iounmap_allowed() for arc's special operation when ioremap_prot() and iounmap(). Meanwhile define and implement arc's own ioremap() because arc has some special handling in ioremap() than standard ioremap().
--- arch/arc/Kconfig | 1 + arch/arc/include/asm/io.h | 19 +++++++++---- arch/arc/mm/ioremap.c | 60 ++++++--------------------------------- 3 files changed, 24 insertions(+), 56 deletions(-)
arch/arc/Kconfig +1 -0
@@ -26,6 +26,7 @@ config ARC select GENERIC_PENDING_IRQ if SMP select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD + select GENERIC_IOREMAP select HAVE_ARCH_KGDB select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARC_MMU_V4
arch/arc/include/asm/io.h +14 -5
@@ -20,9 +20,20 @@#define __iowmb () do { } while (0)#endif -extern void __iomem *ioremap (phys_addr_t paddr,unsigned long size); -extern void __iomem *ioremap_prot (phys_addr_t paddr,unsigned long size, -unsigned long flags); +/* +* I/O memory mapping functions. +*/ + +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed (void __iomem *addr); +#define iounmap_allowed iounmap_allowed + +void __iomem *ioremap (phys_addr_t paddr,unsigned long size); +#define ioremap ioremap +static inline void __iomem *ioport_map (unsigned long port,unsigned int nr) {return (void __iomem *)port;
@@ -32,8 +43,6 @@ static inline void ioport_unmap(void __iomem *addr) { } -extern void iounmap (const void __iomem *addr); -/* * io{read,write}{16,32}be() macros */
arch/arc/mm/ioremap.c +9 -51
84 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 3/11 mm: ioremap: allow ARCH to have its own ioremap definition
In reply to Baoquan HeArchitectures like xtensa, arc, can be converted to GENERIC_IOREMAP, to take standard ioremap_prot() and ioremap_xxx() way. But they have ARCH specific handling for ioremap() method, then standard ioremap() method.
In oder to convert them to take GENERIC_IOREMAP method, allow ARCH to have its own ioremap definition.
This is a preparation patch, no functionality change.
--- include/asm-generic/io.h | 3 +++ 1 file changed, 3 insertions(+)
include/asm-generic/io.h +3 -0
@@ -995,11 +995,14 @@ void __iomem *ioremap_prot(phys_addr_t paddr, size_t size, unsigned long prot);void iounmap (volatile void __iomem *addr); +#ifndef ioremap +#define ioremap ioremapstatic inline void __iomem *ioremap (phys_addr_t addr,size_t size) {/* _PAGE_IOREMAP needs to be supplied by the architecture */ return ioremap_prot (addr, size, _PAGE_IOREMAP); } +#endif #endif /* !CONFIG_MMU || CONFIG_GENERIC_IOREMAP */ #ifndef ioremap_wc
Signature · 1 line
2.34.1
PATCH 7/11 openrisc: mm: Convert to GENERIC_IOREMAP
In reply to Baoquan HeAdd hooks ioremap_allowed() and iounmap_allowed() for operisc's special operation when ioremap() and iounmap.
--- arch/openrisc/Kconfig | 1 + arch/openrisc/include/asm/io.h | 16 ++++++++--- arch/openrisc/mm/ioremap.c | 49 +++++++++++----------------------- 3 files changed, 28 insertions(+), 38 deletions(-)
arch/openrisc/Kconfig +1 -0
@@ -21,6 +21,7 @@ config OPENRISC select GENERIC_IRQ_PROBE select GENERIC_IRQ_SHOW select GENERIC_IOMAP + select GENERIC_IOREMAP select GENERIC_CPU_DEVICES select HAVE_UID16 select GENERIC_ATOMIC64
arch/openrisc/include/asm/io.h +12 -4
@@ -15,6 +15,8 @@#define __ASM_OPENRISC_IO_H#include <linux/types.h> +#include <asm/pgtable.h> +#include <asm/pgalloc.h> /* * PCI: can we really do 0 here if we have no port IO?
@@ -27,11 +29,17 @@#define PIO_OFFSET 0#define PIO_MASK 0 -#define ioremap ioremap -void __iomem *ioremap (phys_addr_t offset,unsigned long size); +/* +* I/O memory mapping functions. +*/ +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed (void *addr); +#define iounmap_allowed iounmap_allowed -#define iounmap iounmap -extern void iounmap (void __iomem *addr); +#define _PAGE_IOREMAP (pgprot_val(PAGE_KERNEL) | _PAGE_CI)#include <asm-generic/io.h>
arch/openrisc/mm/ioremap.c +15 -34
86 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 8/11 parisc: mm: Convert to GENERIC_IOREMAP
In reply to Baoquan HeAdd hook ioremap_allowed() for parisc's special operation when ioremap(), then ioremap_[wc|uc]() are converted to use ioremap_prot() from GENERIC_IOREMAP.
--- arch/parisc/include/asm/io.h | 16 ++++++--- arch/parisc/mm/ioremap.c | 66 ++++-------------------------------- 2 files changed, 18 insertions(+), 64 deletions(-)
arch/parisc/include/asm/io.h +11 -5
@@ -125,13 +125,19 @@ static inline void gsc_writeq(unsigned long long val, unsigned long addr) }/* -* The standard PCI ioremap interfaces +* I/O memory mapping functions. */ -void __iomem *ioremap (unsigned long offset,unsigned long size); -#define ioremap_wc ioremap -#define ioremap_uc ioremap +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long prot); +#define ioremap_allowed ioremap_allowed -extern void iounmap (const volatile void __iomem *addr); +#define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | \ + _PAGE_ACCESSED | _PAGE_NO_CACHE) + +#define ioremap_wc (addr, size) \ + ioremap_prot((addr), (size), _PAGE_IOREMAP) +#define ioremap_uc (addr, size) \ + ioremap_prot((addr), (size), _PAGE_IOREMAP)static inline unsigned char __raw_readb (const volatile void __iomem *addr) {
arch/parisc/mm/ioremap.c +7 -59
88 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 9/11 s390: mm: Convert to GENERIC_IOREMAP
In reply to Baoquan HeAdd hooks ioremap_allowed() and iounmap_allowed() for s390's special operation when ioremap() and iounmap(), then ioremap_[wc|wt]() are converted to use ioremap_prot() from GENERIC_IOREMAP.
--- arch/s390/Kconfig | 1 + arch/s390/include/asm/io.h | 26 +++++++++++------ arch/s390/pci/pci.c | 60 +++++--------------------------------- 3 files changed, 26 insertions(+), 61 deletions(-)
arch/s390/Kconfig +1 -0
@@ -135,6 +135,7 @@ config S390 select GENERIC_SMP_IDLE_THREAD select GENERIC_TIME_VSYSCALL select GENERIC_VDSO_TIME_NS + select GENERIC_IOREMAP select HAVE_ALIGNED_STRUCT_PAGE if SLUB select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL
arch/s390/include/asm/io.h +17 -9
@@ -22,11 +22,23 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);#define IO_SPACE_LIMIT 0 -void __iomem *ioremap_prot (phys_addr_t addr,size_t size,unsigned long prot); -void __iomem *ioremap (phys_addr_t addr,size_t size); -void __iomem *ioremap_wc (phys_addr_t addr,size_t size); -void __iomem *ioremap_wt (phys_addr_t addr,size_t size); -void iounmap (volatile void __iomem *addr); + +/* +* I/O memory mapping functions. +*/ +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed (void *addr); +#define iounmap_allowed iounmap_allowed + +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL) + +#define ioremap_wc (addr, size) \ + ioremap_prot((addr), (size), pgprot_val(pgprot_writecombine(PAGE_KERNEL))) +#define ioremap_wt (addr, size) \ + ioremap_prot((addr), (size), pgprot_val(pgprot_writethrough(PAGE_KERNEL)))static inline void __iomem *ioport_map (unsigned long port,unsigned int nr) {
@@ -51,10 +63,6 @@ static inline void ioport_unmap(void __iomem *p)#define pci_iomap_wc pci_iomap_wc#define pci_iomap_wc_range pci_iomap_wc_range -#define ioremap ioremap -#define ioremap_wt ioremap_wt -#define ioremap_wc ioremap_wc -#define memcpy_fromio (dst, src, count) zpci_memcpy_fromio(dst, src, count)#define memcpy_toio (dst, src, count) zpci_memcpy_toio(dst, src, count)#define memset_io (dst, val, count) zpci_memset_io(dst, val, count)
arch/s390/pci/pci.c +8 -52
72 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 10/11 sh: mm: Convert to GENERIC_IOREMAP
In reply to Baoquan HeAdd hook ioremap_allowed() for sh's special operation when ioremap(), then ioremap_cache() is converted to use ioremap_prot() from GENERIC_IOREMAP.
--- arch/sh/Kconfig | 1 + arch/sh/include/asm/io.h | 47 +++++++++--------------------- arch/sh/mm/ioremap.c | 62 ++++++++-------------------------------- 3 files changed, 27 insertions(+), 83 deletions(-)
arch/sh/Kconfig +1 -0
@@ -25,6 +25,7 @@ config SUPERH select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD select GUP_GET_PTE_LOW_HIGH if X2TLB + select GENERIC_IOREMAP if MMU select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_KGDB select HAVE_ARCH_SECCOMP_FILTER
arch/sh/include/asm/io.h +14 -33
59 lines not on this page · raw message
arch/sh/mm/ioremap.c +12 -50
104 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 11/11 xtensa: mm: Convert to GENERIC_IOREMAP
In reply to Baoquan HeAdd hooks ioremap_allowed() and iounmap_allowed() for xtensa's special operation when ioremap() and iounmap(). Then define and implement its own ioremap() and ioremap_cache().
--- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/io.h | 39 ++++++++++++------------- arch/xtensa/mm/ioremap.c | 56 +++++++++--------------------------- 3 files changed, 32 insertions(+), 64 deletions(-)
arch/xtensa/Kconfig +1 -0
@@ -27,6 +27,7 @@ config XTENSA select GENERIC_LIB_UCMPDI2 select GENERIC_PCI_IOMAP select GENERIC_SCHED_CLOCK + select GENERIC_IOREMAP if MMU select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL
arch/xtensa/include/asm/io.h +18 -21
@@ -16,6 +16,7 @@#include <asm/vectors.h> #include <linux/bug.h> #include <linux/kernel.h> +#include <linux/pgtable.h> #include <linux/types.h>
@@ -23,23 +24,29 @@#define IO_SPACE_LIMIT ~0#define PCI_IOBASE ((void __iomem *)XCHAL_KIO_BYPASS_VADDR) -#ifdef CONFIG_MMU - -void __iomem *xtensa_ioremap_nocache (unsigned long addr,unsigned long size); -void __iomem *xtensa_ioremap_cache (unsigned long addr,unsigned long size); -void xtensa_iounmap (volatile void __iomem *addr); -/* -* Return the virtual address for the specified bus memory. +* I/O memory mapping functions. */ +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed (void *addr); +#define iounmap_allowed iounmap_allowed + +void __iomem *ioremap_prot (phys_addr_t paddr,size_t size, +unsigned long prot); +static inline void __iomem *ioremap (unsigned long offset,unsigned long size) {if (offset >=XCHAL_KIO_PADDR && offset -XCHAL_KIO_PADDR <XCHAL_KIO_SIZE )return (void *)(offset-XCHAL_KIO_PADDR +XCHAL_KIO_BYPASS_VADDR );else -return xtensa_ioremap_nocache (offset, size); +return ioremap_prot (offset, size, +pgprot_val (pgprot_noncached (PAGE_KERNEL ))); } +#define ioremap ioremapstatic inline void __iomem *ioremap_cache (unsigned long offset,unsigned long size)
@@ -48,24 +55,14 @@ static inline void __iomem *ioremap_cache(unsigned long offset, && offset - XCHAL_KIO_PADDR < XCHAL_KIO_SIZE)return (void *)(offset-XCHAL_KIO_PADDR +XCHAL_KIO_CACHED_VADDR ); else - return xtensa_ioremap_cache(offset, size); -} -#define ioremap_cache ioremap_cache - -static inline void iounmap (volatile void __iomem *addr) -{ -unsigned long va = (unsigned long ) addr; + return ioremap_prot(offset, size, pgprot_val(PAGE_KERNEL)); -if (!(va >=XCHAL_KIO_CACHED_VADDR && - va -XCHAL_KIO_CACHED_VADDR <XCHAL_KIO_SIZE ) && - !(va >=XCHAL_KIO_BYPASS_VADDR && - va -XCHAL_KIO_BYPASS_VADDR <XCHAL_KIO_SIZE )) -xtensa_iounmap (addr); } +#define ioremap_cache ioremap_cache +#ifdef CONFIG_MMU #define virt_to_bus virt_to_phys#define bus_to_virt phys_to_virt -#endif /* CONFIG_MMU */ #include <asm-generic/io.h>
arch/xtensa/mm/ioremap.c +13 -43
73 lines not on this page · raw message
Signature · 1 line
2.34.1
Alexander Gordeev
maintainerRe: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed
In reply to Baoquan HeOn Mon, Aug 01, 2022 at 10:40:19PM +0800, Baoquan He wrote:
Hi Baoquan,
arch/arm64/mm/ioremap.c line 9
Quoted 11 lines
arch/arm64/mm/ioremap.c +2
-1@@ -3,19 +3,20 @@#include <linux/mm.h> #include <linux/io.h> -bool ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) {unsigned long last_addr = phys_addr + size -1 ; +int ret = -EINVAL ;
If ret variable is really needed?
include/asm-generic/io.h static inline void iounmap(volatile void __iomem *addr) · line 972
Quoted 13 lines
include/asm-generic/io.h +3
-2@@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr)/* * Arch code can implement the following two hooks when using GENERIC_IOREMAP * ioremap_allowed() return a bool, -* - true means continue to remap -* - false means skip remap and return directly +* - IS_ERR means return an error +* - NULL means continue to remap +* - a non-NULL, non-IS_ERR pointer is returned directly
If ioremap_allowed() returns a valid pointer, then the function name is not as precise anymore.
include/asm-generic/io.h void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, · line 36
Quoted 10 lines
include/asm-generic/io.h +4
-1@@ -28,8 +29,11 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size =PAGE_ALIGN (size + offset); -if (!ioremap_allowed (phys_addr, size, prot)) + base =ioremap_allowed (phys_addr, size, prot); +if (IS_ERR (base))return NULL ; +else if (base) +return base;
It is probably just me, but the base name bit misleading here.
include/asm-generic/io.h EXPORT_SYMBOL(ioremap_prot); · line 59
Quoted 9 lines
include/asm-generic/io.h +2
-2@@ -50,9 +54,9 @@ EXPORT_SYMBOL(ioremap_prot);void iounmap (volatile void __iomem *addr) { -void *vaddr = (void *)((unsigned long )addr &PAGE_MASK ); +void __iomem *vaddr = (void __iomem *)((unsigned long )addr &PAGE_MASK ); -if (!iounmap_allowed (vaddr)) +if (iounmap_allowed (vaddr))
I guess, iounmap_allowed() should accept void __iomem *, not void *. Then addr needs to be passed to iounmap_allowed() not vaddr.
Quoted 1 line
include/asm-generic/io.h +0
-0return ;
Alexander Gordeev
maintainerRe: [PATCH 02/11] mm: ioremap: fixup the physical address
In reply to Baoquan HeQuoted 1 line · Baoquan He
This is a preparation patch, no functionality change.
There is, please see below.
Quoted 4 lines
arch/arm64/mm/ioremap.c +0
-0@@ -3,11 +3,17 @@#include <linux/mm.h> #include <linux/io.h>
arch/arm64/mm/ioremap.c line 13
Quoted 10 lines
arch/arm64/mm/ioremap.c +5
-2-void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val) { -unsigned long last_addr = phys_addr + size -1 ; +unsigned long last_addr, offset, phys_addr = *paddr;int ret = -EINVAL ; + offset = phys_addr & (~PAGE_MASK ); + phys_addr -= offset;
FWIW, phys_addr &= PAGE_MASK looks much more usual.
Quoted 4 lines
mm/ioremap.c +0
-0@@ -11,13 +11,20 @@#include <linux/io.h> #include <linux/export.h>
mm/ioremap.c line 21
Quoted 10 lines
mm/ioremap.c +3
-2-void __iomem *ioremap_prot (phys_addr_t phys_addr,size_t size, +void __iomem *ioremap_prot (phys_addr_t paddr,size_t size,unsigned long prot) {unsigned long offset, vaddr; -phys_addr_t last_addr; +phys_addr_t last_addr, phys_addr = paddr;struct vm_struct *area;void __iomem *base; +unsigned long prot_val = prot;
Why prot_val is needed?
mm/ioremap.c line 27
Quoted 5 lines
mm/ioremap.c +5
-0+ base =ioremap_allowed (&phys_addr, size, &prot_val); +if (IS_ERR (base)) +return NULL ; +else if (base) +return base;
By moving ioremap_allowed() here you allow it to be called before the wrap-around check, including architectures that do not do fixups.
And now ioremap_allowed() semantics, prototype and name turn less than obvious. Why not introduce a separate fixup callback?
Quoted 15 lines
mm/ioremap.c +0
-6/* Disallow wrap-around or zero size */ last_addr = phys_addr + size -1 ;@@ -29,12 +36,6 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size =PAGE_ALIGN (size + offset); - base =ioremap_allowed (phys_addr, size, prot); -if (IS_ERR (base)) -return NULL ; -else if (base) -return base; - area =get_vm_area_caller (size,VM_IOREMAP ,__builtin_return_address (0 ));if (!area)
Re: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed
In reply to Alexander GordeevQuoted 17 lines · Alexander Gordeev
On Mon, Aug 01, 2022 at 10:40:19PM +0800, Baoquan He wrote:
Hi Baoquan,
arch/arm64/mm/ioremap.c line 9
Quoted 11 lines
arch/arm64/mm/ioremap.c +2
-1@@ -3,19 +3,20 @@#include <linux/mm.h> #include <linux/io.h> -bool ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) {unsigned long last_addr = phys_addr + size -1 ; +int ret = -EINVAL ;If ret variable is really needed?
Quoted 15 lines
include/asm-generic/io.h static inline void iounmap(volatile void __iomem *addr) · line 972
Quoted 13 lines
include/asm-generic/io.h +3
-2@@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr)/* * Arch code can implement the following two hooks when using GENERIC_IOREMAP * ioremap_allowed() return a bool, -* - true means continue to remap -* - false means skip remap and return directly +* - IS_ERR means return an error +* - NULL means continue to remap +* - a non-NULL, non-IS_ERR pointer is returned directly If
ioremap_allowed()returns a valid pointer, then the function name is not as precise anymore.
Maybe use arch_ioremap/unmap as before, or some better name.
Quoted 5 lines
Quoted 5 lines
include/asm-generic/io.h +0
-0@@ -28,8 +29,11 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size =PAGE_ALIGN (size + offset);
Quoted 7 lines
include/asm-generic/io.h void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, · line 36
Quoted 6 lines
include/asm-generic/io.h +4
-1-if (!ioremap_allowed (phys_addr, size, prot)) + base =ioremap_allowed (phys_addr, size, prot); +if (IS_ERR (base))return NULL ; +else if (base) +return base;It is probably just me, but the base name bit misleading here.
We could reuse vaddr, not add new base.
Quoted 8 lines
Quoted 8 lines
include/asm-generic/io.h +1
-1@@ -50,9 +54,9 @@ EXPORT_SYMBOL(ioremap_prot);void iounmap (volatile void __iomem *addr) { -void *vaddr = (void *)((unsigned long )addr &PAGE_MASK ); +void __iomem *vaddr = (void __iomem *)((unsigned long )addr &PAGE_MASK );
Quoted 4 lines
include/asm-generic/io.h EXPORT_SYMBOL(ioremap_prot); · line 59
Quoted 2 lines
include/asm-generic/io.h +1
-1-if (!iounmap_allowed (vaddr)) +if (iounmap_allowed (vaddr))I guess,
iounmap_allowed()should accept void__iomem*, not void *. Then addr needs to be passed toiounmap_allowed()not vaddr.
The following is_vmalloc_addr() and vunmap() in iounmap() use void *,
so we could simply use void* for iounmap_allowed().
Quoted 3 lines
include/asm-generic/io.h EXPORT_SYMBOL(ioremap_prot); · line 60
Quoted 2 lines
include/asm-generic/io.h +0
-0return ;.
Alexander Gordeev
maintainerRe: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed
Quoted 47 lines · Kefeng Wang
Quoted 16 lines · Alexander Gordeev
On Mon, Aug 01, 2022 at 10:40:19PM +0800, Baoquan He wrote:
Hi Baoquan,
arch/arm64/mm/ioremap.c line 8
Quoted 10 lines
arch/arm64/mm/ioremap.c +2
-1@@ -3,19 +3,20 @@#include <linux/mm.h> #include <linux/io.h> -bool ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) {unsigned long last_addr = phys_addr + size -1 ; +int ret = -EINVAL ;If ret variable is really needed?
Quoted 15 lines
include/asm-generic/io.h static inline void iounmap(volatile void __iomem *addr) · line 972
Quoted 13 lines
include/asm-generic/io.h +3
-2@@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr)/* * Arch code can implement the following two hooks when using GENERIC_IOREMAP * ioremap_allowed() return a bool, -* - true means continue to remap -* - false means skip remap and return directly +* - IS_ERR means return an error +* - NULL means continue to remap +* - a non-NULL, non-IS_ERR pointer is returned directly If
ioremap_allowed()returns a valid pointer, then the function name is not as precise anymore.Maybe use arch_ioremap/unmap as before, or some better name.
Quoted 11 lines
include/asm-generic/io.h void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, · line 35
Quoted 10 lines
include/asm-generic/io.h +4
-1@@ -28,8 +29,11 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size =PAGE_ALIGN (size + offset); -if (!ioremap_allowed (phys_addr, size, prot)) + base =ioremap_allowed (phys_addr, size, prot); +if (IS_ERR (base))return NULL ; +else if (base) +return base;It is probably just me, but the base name bit misleading here.
Quoted 1 line
We could reuse vaddr, not add new base.
vaddr name is wrong AFAICT. ioremap_allowed() returns __iomem address, not the virtual one.
Quoted 6 lines
Quoted 6 lines
include/asm-generic/io.h EXPORT_SYMBOL(ioremap_prot); · line 56
Quoted 6 lines
include/asm-generic/io.h +1
-1@@ -50,9 +54,9 @@ EXPORT_SYMBOL(ioremap_prot);void iounmap (volatile void __iomem *addr) { -void *vaddr = (void *)((unsigned long )addr &PAGE_MASK ); +void __iomem *vaddr = (void __iomem *)((unsigned long )addr &PAGE_MASK );
Same here.
Quoted 8 lines
Quoted 4 lines
include/asm-generic/io.h EXPORT_SYMBOL(ioremap_prot); · line 57
Quoted 2 lines
include/asm-generic/io.h +1
-1-if (!iounmap_allowed (vaddr)) +if (iounmap_allowed (vaddr))I guess,
iounmap_allowed()should accept void__iomem*, not void *. Then addr needs to be passed toiounmap_allowed()not vaddr.The following is_vmalloc_addr() and
vunmap()iniounmap()use void *,so we could simply use void* for
iounmap_allowed().
iounmap_allowed() accepts void __iomem * and I that looks correct to me.
Passing void * on the other hand means you pass a pointer that in theory differs from what architecture previously returned with ioremap_allowed() and "knows" nothing about.
I think you need to pass addr to iounmap_allowed() as is.
Re: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed
Quoted 48 lines · Alexander Gordeev
Quoted 47 lines · Kefeng Wang
Quoted 16 lines · Alexander Gordeev
On Mon, Aug 01, 2022 at 10:40:19PM +0800, Baoquan He wrote:
Hi Baoquan,
arch/arm64/mm/ioremap.c line 8
Quoted 10 lines
arch/arm64/mm/ioremap.c +2
-1@@ -3,19 +3,20 @@#include <linux/mm.h> #include <linux/io.h> -bool ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) {unsigned long last_addr = phys_addr + size -1 ; +int ret = -EINVAL ;If ret variable is really needed?
Quoted 15 lines
include/asm-generic/io.h static inline void iounmap(volatile void __iomem *addr) · line 972
Quoted 13 lines
include/asm-generic/io.h +3
-2@@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr)/* * Arch code can implement the following two hooks when using GENERIC_IOREMAP * ioremap_allowed() return a bool, -* - true means continue to remap -* - false means skip remap and return directly +* - IS_ERR means return an error +* - NULL means continue to remap +* - a non-NULL, non-IS_ERR pointer is returned directly If
ioremap_allowed()returns a valid pointer, then the function name is not as precise anymore.Maybe use arch_ioremap/unmap as before, or some better name.
Quoted 11 lines
include/asm-generic/io.h void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, · line 35
Quoted 10 lines
include/asm-generic/io.h +4
-1@@ -28,8 +29,11 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size =PAGE_ALIGN (size + offset); -if (!ioremap_allowed (phys_addr, size, prot)) + base =ioremap_allowed (phys_addr, size, prot); +if (IS_ERR (base))return NULL ; +else if (base) +return base;It is probably just me, but the base name bit misleading here.
Quoted 4 lines
Quoted 1 line
We could reuse vaddr, not add new base.
vaddr name is wrong AFAICT.
ioremap_allowed()returns__iomemaddress, not the virtual one.
Thanks a lot for reviewing, both.
Here, I tend to agree with Alexander. ioremap_allowed() returns __iomem*. How about naming it io_addr here. While I don't have strong opinion about it, reusing vaddr and casting it to (__iomem*) when return is also OK to me.
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
include/asm-generic/io.h EXPORT_SYMBOL(ioremap_prot); · line 56
Quoted 7 lines
include/asm-generic/io.h +1
-1@@ -50,9 +54,9 @@ EXPORT_SYMBOL(ioremap_prot);void iounmap (volatile void __iomem *addr) { -void *vaddr = (void *)((unsigned long )addr &PAGE_MASK ); +void __iomem *vaddr = (void __iomem *)((unsigned long )addr &PAGE_MASK );Same here.
Quoted 8 lines
Quoted 4 lines
include/asm-generic/io.h EXPORT_SYMBOL(ioremap_prot); · line 57
Quoted 2 lines
include/asm-generic/io.h +1
-1-if (!iounmap_allowed (vaddr)) +if (iounmap_allowed (vaddr))I guess,
iounmap_allowed()should accept void__iomem*, not void *. Then addr needs to be passed toiounmap_allowed()not vaddr.The following is_vmalloc_addr() and
vunmap()iniounmap()use void *,so we could simply use void* for
iounmap_allowed().
Quoted 7 lines
iounmap_allowed()accepts void__iomem* and I that looks correct to me.Passing void * on the other hand means you pass a pointer that in theory differs from what architecture previously returned with
ioremap_allowed()and "knows" nothing about.I think you need to pass addr to
iounmap_allowed()as is.
OK, I will change to pass (__iomem*) to iounmap_allowed() directly. Thanks.
Re: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed
In reply to Kefeng WangOn 08/06/22 at 10:29am, Kefeng Wang wrote:
...snip...
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
include/asm-generic/io.h +0
-0@@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr)/* * Arch code can implement the following two hooks when using GENERIC_IOREMAP Quoted 8 lines
include/asm-generic/io.h static inline void iounmap(volatile void __iomem *addr) · line 972
Quoted 6 lines
include/asm-generic/io.h +3
-2* ioremap_allowed() return a bool, -* - true means continue to remap -* - false means skip remap and return directly +* - IS_ERR means return an error +* - NULL means continue to remap +* - a non-NULL, non-IS_ERR pointer is returned directly If
ioremap_allowed()returns a valid pointer, then the function name is not as precise anymore.
Quoted 1 line
Maybe use arch_ioremap/unmap as before, or some better name.
Looks good to me. Or ioremap_check() which is a generic name, and usually xxx_check() can hanlde many things.
Re: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed
In reply to Alexander GordeevQuoted 10 lines · Alexander Gordeev
On Mon, Aug 01, 2022 at 10:40:19PM +0800, Baoquan He wrote:
Hi Baoquan,
Quoted 6 lines
arch/arm64/mm/ioremap.c +0
-0@@ -3,19 +3,20 @@#include <linux/mm.h> #include <linux/io.h>
Quoted 7 lines
arch/arm64/mm/ioremap.c line 9
Quoted 5 lines
arch/arm64/mm/ioremap.c +2
-1-bool ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) {unsigned long last_addr = phys_addr + size -1 ; +int ret = -EINVAL ;If ret variable is really needed?
There are two places where -EINVAL need be returned. I can remove variable ret, and return -EINVAL directly if there's concern.
Thanks again for looking into this series.
Re: [PATCH 02/11] mm: ioremap: fixup the physical address
In reply to Alexander GordeevQuoted 17 lines · Alexander Gordeev
Quoted 1 line · Baoquan He
This is a preparation patch, no functionality change.
There is, please see below.
Quoted 12 lines
arch/arm64/mm/ioremap.c +3
-2@@ -3,11 +3,17 @@#include <linux/mm.h> #include <linux/io.h> -void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val) { -unsigned long last_addr = phys_addr + size -1 ; +unsigned long last_addr, offset, phys_addr = *paddr;int ret = -EINVAL ;
Quoted 4 lines
arch/arm64/mm/ioremap.c line 13
Quoted 2 lines
arch/arm64/mm/ioremap.c +2
-0+ offset = phys_addr & (~PAGE_MASK ); + phys_addr -= offset;FWIW,
phys_addr&=PAGE_MASKlooks much more usual.
Sure, will change.
Quoted 5 lines
Quoted 5 lines
mm/ioremap.c +0
-0@@ -11,13 +11,20 @@#include <linux/io.h> #include <linux/export.h>
Quoted 12 lines
mm/ioremap.c line 21
Quoted 10 lines
mm/ioremap.c +3
-2-void __iomem *ioremap_prot (phys_addr_t phys_addr,size_t size, +void __iomem *ioremap_prot (phys_addr_t paddr,size_t size,unsigned long prot) {unsigned long offset, vaddr; -phys_addr_t last_addr; +phys_addr_t last_addr, phys_addr = paddr;struct vm_struct *area;void __iomem *base; +unsigned long prot_val = prot;Why
prot_valis needed?
I will remove it and pass &prot to ioremap_allowed(). I could think too much when I made change here. Thanks.
Quoted 10 lines
mm/ioremap.c line 27
Quoted 6 lines
mm/ioremap.c +5
-0+ base =ioremap_allowed (&phys_addr, size, &prot_val); +if (IS_ERR (base)) +return NULL ; +else if (base) +return base;By moving
ioremap_allowed()here you allow it to be called before the wrap-around check, including architectures that do not do fixups.
Yes, just as you say.
Quoted 3 lines
And now
ioremap_allowed()semantics, prototype and name turn less than obvious. Why not introduce a separate fixup callback?
I can do that, while a little worried if too many hooks introduced. I will introduce another fixup hook in v2 if no other suggestion or concern. Thanks.
Quoted 17 lines
Quoted 16 lines
mm/ioremap.c +0
-6/* Disallow wrap-around or zero size */ last_addr = phys_addr + size -1 ;@@ -29,12 +36,6 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size =PAGE_ALIGN (size + offset); - base =ioremap_allowed (phys_addr, size, prot); -if (IS_ERR (base)) -return NULL ; -else if (base) -return base; - area =get_vm_area_caller (size,VM_IOREMAP ,__builtin_return_address (0 ));if (!area)
Re: [PATCH 02/11] mm: ioremap: fixup the physical address
In reply to Alexander GordeevQuoted 49 lines · Alexander Gordeev
Quoted 1 line · Baoquan He
This is a preparation patch, no functionality change.
There is, please see below.
Quoted 4 lines
arch/arm64/mm/ioremap.c +0
-0@@ -3,11 +3,17 @@#include <linux/mm.h> #include <linux/io.h> arch/arm64/mm/ioremap.c line 13
Quoted 10 lines
arch/arm64/mm/ioremap.c +5
-2-void __iomem *ioremap_allowed (phys_addr_t phys_addr,size_t size,unsigned long prot) +void __iomem * +ioremap_allowed (phys_addr_t *paddr,size_t size,unsigned long *prot_val) { -unsigned long last_addr = phys_addr + size -1 ; +unsigned long last_addr, offset, phys_addr = *paddr;int ret = -EINVAL ; + offset = phys_addr & (~PAGE_MASK ); + phys_addr -= offset;FWIW,
phys_addr&=PAGE_MASKlooks much more usual.Quoted 4 lines
mm/ioremap.c +0
-0@@ -11,13 +11,20 @@#include <linux/io.h> #include <linux/export.h> mm/ioremap.c line 21
Quoted 10 lines
mm/ioremap.c +3
-2-void __iomem *ioremap_prot (phys_addr_t phys_addr,size_t size, +void __iomem *ioremap_prot (phys_addr_t paddr,size_t size,unsigned long prot) {unsigned long offset, vaddr; -phys_addr_t last_addr; +phys_addr_t last_addr, phys_addr = paddr;struct vm_struct *area;void __iomem *base; +unsigned long prot_val = prot;Why
prot_valis needed?mm/ioremap.c line 27
Quoted 5 lines
mm/ioremap.c +5
-0+ base =ioremap_allowed (&phys_addr, size, &prot_val); +if (IS_ERR (base)) +return NULL ; +else if (base) +return base;By moving
ioremap_allowed()here you allow it to be called before the wrap-around check, including architectures that do not do fixups.
Quoted 2 lines
And now
ioremap_allowed()semantics, prototype and name turn less than obvious. Why not introduce a separate fixup callback?
I finally renamed ioremap_allowed()/iounmap_allowed() to arch_ioremap() and arch_iounmap(). I didn't introduce a separate fixup callback, and have added more explanation to log of patch 1~2, please check that.