linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 11/19] sh: add <asm-generic/io.h> including
       [not found] <20230620131356.25440-1-bhe@redhat.com>
@ 2023-06-20 13:13 ` Baoquan He
  2023-06-20 13:13 ` [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP Baoquan He
  1 sibling, 0 replies; 4+ messages in thread
From: Baoquan He @ 2023-06-20 13:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arch, linux-mm, arnd, hch, christophe.leroy, rppt, willy,
	agordeev, wangkefeng.wang, schnelle, David.Laight, shorne, deller,
	nathan, glaubitz, Baoquan He, Yoshinori Sato, Rich Felker,
	linux-sh

In <asm-generic/io.h>, it provides a generic implementation of all
I/O accessors.

For some port|mm io functions, SuperH has its own implementation
in arch/sh/kernel/iomap.c and arch/sh/include/asm/io_noioport.h.
These will conflict with those in <asm-generic/io.h> and cause compiling
error. Hence add macro definitions to ensure that the SuperH version
of them will override the generic version.

Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: linux-sh@vger.kernel.org
---
 arch/sh/include/asm/io.h          | 25 +++++++++++++++++++++++++
 arch/sh/include/asm/io_noioport.h |  7 +++++++
 2 files changed, 32 insertions(+)

diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h
index fba90e670ed4..270e7952950c 100644
--- a/arch/sh/include/asm/io.h
+++ b/arch/sh/include/asm/io.h
@@ -119,6 +119,26 @@ void __raw_readsl(const void __iomem *addr, void *data, int longlen);
 
 __BUILD_MEMORY_STRING(__raw_, q, u64)
 
+#define ioread8 ioread8
+#define ioread16 ioread16
+#define ioread16be ioread16be
+#define ioread32 ioread32
+#define ioread32be ioread32be
+
+#define iowrite8 iowrite8
+#define iowrite16 iowrite16
+#define iowrite16be iowrite16be
+#define iowrite32 iowrite32
+#define iowrite32be iowrite32be
+
+#define ioread8_rep ioread8_rep
+#define ioread16_rep ioread16_rep
+#define ioread32_rep ioread32_rep
+
+#define iowrite8_rep iowrite8_rep
+#define iowrite16_rep iowrite16_rep
+#define iowrite32_rep iowrite32_rep
+
 #ifdef CONFIG_HAS_IOPORT_MAP
 
 /*
@@ -225,6 +245,9 @@ __BUILD_IOPORT_STRING(q, u64)
 #define IO_SPACE_LIMIT 0xffffffff
 
 /* We really want to try and get these to memcpy etc */
+#define memset_io memset_io
+#define memcpy_fromio memcpy_fromio
+#define memcpy_toio memcpy_toio
 void memcpy_fromio(void *, const volatile void __iomem *, unsigned long);
 void memcpy_toio(volatile void __iomem *, const void *, unsigned long);
 void memset_io(volatile void __iomem *, int, unsigned long);
@@ -287,6 +310,8 @@ static inline void iounmap(volatile void __iomem *addr) { }
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
+#include <asm-generic/io.h>
+
 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
 int valid_phys_addr_range(phys_addr_t addr, size_t size);
 int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
diff --git a/arch/sh/include/asm/io_noioport.h b/arch/sh/include/asm/io_noioport.h
index f7938fe0f911..5ba4116b4265 100644
--- a/arch/sh/include/asm/io_noioport.h
+++ b/arch/sh/include/asm/io_noioport.h
@@ -53,6 +53,13 @@ static inline void ioport_unmap(void __iomem *addr)
 #define outw_p(x, addr)	outw((x), (addr))
 #define outl_p(x, addr)	outl((x), (addr))
 
+#define insb insb
+#define insw insw
+#define insl insl
+#define outsb outsb
+#define outsw outsw
+#define outsl outsl
+
 static inline void insb(unsigned long port, void *dst, unsigned long count)
 {
 	BUG();
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP
       [not found] <20230620131356.25440-1-bhe@redhat.com>
  2023-06-20 13:13 ` [PATCH v7 11/19] sh: add <asm-generic/io.h> including Baoquan He
@ 2023-06-20 13:13 ` Baoquan He
  2023-06-25 21:12   ` John Paul Adrian Glaubitz
  1 sibling, 1 reply; 4+ messages in thread
From: Baoquan He @ 2023-06-20 13:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-arch, linux-mm, arnd, hch, christophe.leroy, rppt, willy,
	agordeev, wangkefeng.wang, schnelle, David.Laight, shorne, deller,
	nathan, glaubitz, Baoquan He, Yoshinori Sato, Rich Felker,
	linux-sh

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 codes
with generic_ioremap_prot() and generic_iounmap(), and has the equivalent
functioality as before.

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

Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: linux-sh@vger.kernel.org
---
 arch/sh/Kconfig          |  1 +
 arch/sh/include/asm/io.h | 40 +++++--------------------
 arch/sh/mm/ioremap.c     | 65 +++++++---------------------------------
 3 files changed, 20 insertions(+), 86 deletions(-)

diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index 9652d367fc37..f326985e46e0 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -28,6 +28,7 @@ config SUPERH
 	select GENERIC_SMP_IDLE_THREAD
 	select GUP_GET_PXX_LOW_HIGH if X2TLB
 	select HAS_IOPORT if HAS_IOPORT_MAP
+	select GENERIC_IOREMAP if MMU
 	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_SECCOMP_FILTER
diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h
index 270e7952950c..b3a26b405c8d 100644
--- a/arch/sh/include/asm/io.h
+++ b/arch/sh/include/asm/io.h
@@ -266,40 +266,16 @@ unsigned long long poke_real_address_q(unsigned long long addr,
 #endif
 
 #ifdef CONFIG_MMU
-void iounmap(void __iomem *addr);
-void __iomem *__ioremap_caller(phys_addr_t offset, unsigned long size,
-			       pgprot_t prot, void *caller);
-
-static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size)
-{
-	return __ioremap_caller(offset, size, PAGE_KERNEL_NOCACHE,
-			__builtin_return_address(0));
-}
-
-static inline void __iomem *
-ioremap_cache(phys_addr_t offset, unsigned long size)
-{
-	return __ioremap_caller(offset, size, PAGE_KERNEL,
-			__builtin_return_address(0));
-}
-#define ioremap_cache ioremap_cache
-
-#ifdef CONFIG_HAVE_IOREMAP_PROT
-static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
-		unsigned long flags)
-{
-	return __ioremap_caller(offset, size, __pgprot(flags),
-			__builtin_return_address(0));
-}
-#endif /* CONFIG_HAVE_IOREMAP_PROT */
+/*
+ * I/O memory mapping functions.
+ */
+#define ioremap_prot ioremap_prot
+#define iounmap iounmap
 
-#else /* CONFIG_MMU */
-static inline void __iomem *ioremap(phys_addr_t offset, size_t size)
-{
-	return (void __iomem *)(unsigned long)offset;
-}
+#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL_NOCACHE)
 
-static inline void iounmap(volatile void __iomem *addr) { }
+#define ioremap_cache(addr, size)  \
+	ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL))
 #endif /* CONFIG_MMU */
 
 #define ioremap_uc	ioremap
diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c
index 21342581144d..c33b3daa4ad1 100644
--- a/arch/sh/mm/ioremap.c
+++ b/arch/sh/mm/ioremap.c
@@ -72,22 +72,11 @@ __ioremap_29bit(phys_addr_t offset, unsigned long size, pgprot_t prot)
 #define __ioremap_29bit(offset, size, prot)		NULL
 #endif /* CONFIG_29BIT */
 
-/*
- * Remap an arbitrary physical address space into the kernel virtual
- * address space. Needed when the kernel wants to access high addresses
- * directly.
- *
- * NOTE! We need to allow non-page-aligned mappings too: we will obviously
- * have to convert them into an offset in a page-aligned mapping, but the
- * caller shouldn't need to know that small detail.
- */
-void __iomem * __ref
-__ioremap_caller(phys_addr_t phys_addr, unsigned long size,
-		 pgprot_t pgprot, void *caller)
+void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
+			   unsigned long prot)
 {
-	struct vm_struct *area;
-	unsigned long offset, last_addr, addr, orig_addr;
 	void __iomem *mapped;
+	pgprot_t pgprot = __pgprot(prot);
 
 	mapped = __ioremap_trapped(phys_addr, size);
 	if (mapped)
@@ -97,11 +86,6 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size,
 	if (mapped)
 		return mapped;
 
-	/* Don't allow wraparound or zero size */
-	last_addr = phys_addr + size - 1;
-	if (!size || last_addr < phys_addr)
-		return NULL;
-
 	/*
 	 * If we can't yet use the regular approach, go the fixmap route.
 	 */
@@ -112,34 +96,14 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size,
 	 * First try to remap through the PMB.
 	 * PMB entries are all pre-faulted.
 	 */
-	mapped = pmb_remap_caller(phys_addr, size, pgprot, caller);
+	mapped = pmb_remap_caller(phys_addr, size, pgprot,
+			__builtin_return_address(0));
 	if (mapped && !IS_ERR(mapped))
 		return mapped;
 
-	/*
-	 * Mappings have to be page-aligned
-	 */
-	offset = phys_addr & ~PAGE_MASK;
-	phys_addr &= PAGE_MASK;
-	size = PAGE_ALIGN(last_addr+1) - phys_addr;
-
-	/*
-	 * Ok, go for it..
-	 */
-	area = get_vm_area_caller(size, VM_IOREMAP, caller);
-	if (!area)
-		return NULL;
-	area->phys_addr = phys_addr;
-	orig_addr = addr = (unsigned long)area->addr;
-
-	if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) {
-		vunmap((void *)orig_addr);
-		return NULL;
-	}
-
-	return (void __iomem *)(offset + (char *)orig_addr);
+	return generic_ioremap_prot(phys_addr, size, pgprot);
 }
-EXPORT_SYMBOL(__ioremap_caller);
+EXPORT_SYMBOL(ioremap_prot);
 
 /*
  * Simple checks for non-translatable mappings.
@@ -158,10 +122,9 @@ static inline int iomapping_nontranslatable(unsigned long offset)
 	return 0;
 }
 
-void iounmap(void __iomem *addr)
+void iounmap(volatile void __iomem *addr)
 {
 	unsigned long vaddr = (unsigned long __force)addr;
-	struct vm_struct *p;
 
 	/*
 	 * Nothing to do if there is no translatable mapping.
@@ -172,21 +135,15 @@ void iounmap(void __iomem *addr)
 	/*
 	 * There's no VMA if it's from an early fixed mapping.
 	 */
-	if (iounmap_fixed(addr) == 0)
+	if (iounmap_fixed((void __iomem *)addr) == 0)
 		return;
 
 	/*
 	 * If the PMB handled it, there's nothing else to do.
 	 */
-	if (pmb_unmap(addr) == 0)
+	if (pmb_unmap((void __iomem *)addr) == 0)
 		return;
 
-	p = remove_vm_area((void *)(vaddr & PAGE_MASK));
-	if (!p) {
-		printk(KERN_ERR "%s: bad address %p\n", __func__, addr);
-		return;
-	}
-
-	kfree(p);
+	generic_iounmap(addr);
 }
 EXPORT_SYMBOL(iounmap);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP
  2023-06-20 13:13 ` [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP Baoquan He
@ 2023-06-25 21:12   ` John Paul Adrian Glaubitz
  2023-06-26  2:45     ` Baoquan He
  0 siblings, 1 reply; 4+ messages in thread
From: John Paul Adrian Glaubitz @ 2023-06-25 21:12 UTC (permalink / raw)
  To: Baoquan He, linux-kernel
  Cc: linux-arch, linux-mm, arnd, hch, christophe.leroy, rppt, willy,
	agordeev, wangkefeng.wang, schnelle, David.Laight, shorne, deller,
	nathan, Yoshinori Sato, Rich Felker, linux-sh

Hi Baoquan!

On Tue, 2023-06-20 at 21:13 +0800, Baoquan He wrote:
> 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 codes
                                                                  ^^^^^
Nit-pick: It should be "code", not "codes".

I'll review and test the rest tomorrow. There are quite some changes.

Adrian

> with generic_ioremap_prot() and generic_iounmap(), and has the equivalent
> functioality as before.
> 
> Here, add wrapper functions ioremap_prot() and iounmap() for SuperH's
> special operation when ioremap() and iounmap().
> 
> Signed-off-by: Baoquan He <bhe@redhat.com>
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Cc: Rich Felker <dalias@libc.org>
> Cc: linux-sh@vger.kernel.org
> ---
>  arch/sh/Kconfig          |  1 +
>  arch/sh/include/asm/io.h | 40 +++++--------------------
>  arch/sh/mm/ioremap.c     | 65 +++++++---------------------------------
>  3 files changed, 20 insertions(+), 86 deletions(-)
> 
> diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
> index 9652d367fc37..f326985e46e0 100644
> --- a/arch/sh/Kconfig
> +++ b/arch/sh/Kconfig
> @@ -28,6 +28,7 @@ config SUPERH
>  	select GENERIC_SMP_IDLE_THREAD
>  	select GUP_GET_PXX_LOW_HIGH if X2TLB
>  	select HAS_IOPORT if HAS_IOPORT_MAP
> +	select GENERIC_IOREMAP if MMU
>  	select HAVE_ARCH_AUDITSYSCALL
>  	select HAVE_ARCH_KGDB
>  	select HAVE_ARCH_SECCOMP_FILTER
> diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h
> index 270e7952950c..b3a26b405c8d 100644
> --- a/arch/sh/include/asm/io.h
> +++ b/arch/sh/include/asm/io.h
> @@ -266,40 +266,16 @@ unsigned long long poke_real_address_q(unsigned long long addr,
>  #endif
>  
>  #ifdef CONFIG_MMU
> -void iounmap(void __iomem *addr);
> -void __iomem *__ioremap_caller(phys_addr_t offset, unsigned long size,
> -			       pgprot_t prot, void *caller);
> -
> -static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size)
> -{
> -	return __ioremap_caller(offset, size, PAGE_KERNEL_NOCACHE,
> -			__builtin_return_address(0));
> -}
> -
> -static inline void __iomem *
> -ioremap_cache(phys_addr_t offset, unsigned long size)
> -{
> -	return __ioremap_caller(offset, size, PAGE_KERNEL,
> -			__builtin_return_address(0));
> -}
> -#define ioremap_cache ioremap_cache
> -
> -#ifdef CONFIG_HAVE_IOREMAP_PROT
> -static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
> -		unsigned long flags)
> -{
> -	return __ioremap_caller(offset, size, __pgprot(flags),
> -			__builtin_return_address(0));
> -}
> -#endif /* CONFIG_HAVE_IOREMAP_PROT */
> +/*
> + * I/O memory mapping functions.
> + */
> +#define ioremap_prot ioremap_prot
> +#define iounmap iounmap
>  
> -#else /* CONFIG_MMU */
> -static inline void __iomem *ioremap(phys_addr_t offset, size_t size)
> -{
> -	return (void __iomem *)(unsigned long)offset;
> -}
> +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL_NOCACHE)
>  
> -static inline void iounmap(volatile void __iomem *addr) { }
> +#define ioremap_cache(addr, size)  \
> +	ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL))
>  #endif /* CONFIG_MMU */
>  
>  #define ioremap_uc	ioremap
> diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c
> index 21342581144d..c33b3daa4ad1 100644
> --- a/arch/sh/mm/ioremap.c
> +++ b/arch/sh/mm/ioremap.c
> @@ -72,22 +72,11 @@ __ioremap_29bit(phys_addr_t offset, unsigned long size, pgprot_t prot)
>  #define __ioremap_29bit(offset, size, prot)		NULL
>  #endif /* CONFIG_29BIT */
>  
> -/*
> - * Remap an arbitrary physical address space into the kernel virtual
> - * address space. Needed when the kernel wants to access high addresses
> - * directly.
> - *
> - * NOTE! We need to allow non-page-aligned mappings too: we will obviously
> - * have to convert them into an offset in a page-aligned mapping, but the
> - * caller shouldn't need to know that small detail.
> - */
> -void __iomem * __ref
> -__ioremap_caller(phys_addr_t phys_addr, unsigned long size,
> -		 pgprot_t pgprot, void *caller)
> +void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
> +			   unsigned long prot)
>  {
> -	struct vm_struct *area;
> -	unsigned long offset, last_addr, addr, orig_addr;
>  	void __iomem *mapped;
> +	pgprot_t pgprot = __pgprot(prot);
>  
>  	mapped = __ioremap_trapped(phys_addr, size);
>  	if (mapped)
> @@ -97,11 +86,6 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size,
>  	if (mapped)
>  		return mapped;
>  
> -	/* Don't allow wraparound or zero size */
> -	last_addr = phys_addr + size - 1;
> -	if (!size || last_addr < phys_addr)
> -		return NULL;
> -
>  	/*
>  	 * If we can't yet use the regular approach, go the fixmap route.
>  	 */
> @@ -112,34 +96,14 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size,
>  	 * First try to remap through the PMB.
>  	 * PMB entries are all pre-faulted.
>  	 */
> -	mapped = pmb_remap_caller(phys_addr, size, pgprot, caller);
> +	mapped = pmb_remap_caller(phys_addr, size, pgprot,
> +			__builtin_return_address(0));
>  	if (mapped && !IS_ERR(mapped))
>  		return mapped;
>  
> -	/*
> -	 * Mappings have to be page-aligned
> -	 */
> -	offset = phys_addr & ~PAGE_MASK;
> -	phys_addr &= PAGE_MASK;
> -	size = PAGE_ALIGN(last_addr+1) - phys_addr;
> -
> -	/*
> -	 * Ok, go for it..
> -	 */
> -	area = get_vm_area_caller(size, VM_IOREMAP, caller);
> -	if (!area)
> -		return NULL;
> -	area->phys_addr = phys_addr;
> -	orig_addr = addr = (unsigned long)area->addr;
> -
> -	if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) {
> -		vunmap((void *)orig_addr);
> -		return NULL;
> -	}
> -
> -	return (void __iomem *)(offset + (char *)orig_addr);
> +	return generic_ioremap_prot(phys_addr, size, pgprot);
>  }
> -EXPORT_SYMBOL(__ioremap_caller);
> +EXPORT_SYMBOL(ioremap_prot);
>  
>  /*
>   * Simple checks for non-translatable mappings.
> @@ -158,10 +122,9 @@ static inline int iomapping_nontranslatable(unsigned long offset)
>  	return 0;
>  }
>  
> -void iounmap(void __iomem *addr)
> +void iounmap(volatile void __iomem *addr)
>  {
>  	unsigned long vaddr = (unsigned long __force)addr;
> -	struct vm_struct *p;
>  
>  	/*
>  	 * Nothing to do if there is no translatable mapping.
> @@ -172,21 +135,15 @@ void iounmap(void __iomem *addr)
>  	/*
>  	 * There's no VMA if it's from an early fixed mapping.
>  	 */
> -	if (iounmap_fixed(addr) == 0)
> +	if (iounmap_fixed((void __iomem *)addr) == 0)
>  		return;
>  
>  	/*
>  	 * If the PMB handled it, there's nothing else to do.
>  	 */
> -	if (pmb_unmap(addr) == 0)
> +	if (pmb_unmap((void __iomem *)addr) == 0)
>  		return;
>  
> -	p = remove_vm_area((void *)(vaddr & PAGE_MASK));
> -	if (!p) {
> -		printk(KERN_ERR "%s: bad address %p\n", __func__, addr);
> -		return;
> -	}
> -
> -	kfree(p);
> +	generic_iounmap(addr);
>  }
>  EXPORT_SYMBOL(iounmap);

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP
  2023-06-25 21:12   ` John Paul Adrian Glaubitz
@ 2023-06-26  2:45     ` Baoquan He
  0 siblings, 0 replies; 4+ messages in thread
From: Baoquan He @ 2023-06-26  2:45 UTC (permalink / raw)
  To: John Paul Adrian Glaubitz
  Cc: linux-kernel, linux-arch, linux-mm, arnd, hch, christophe.leroy,
	rppt, willy, agordeev, wangkefeng.wang, schnelle, David.Laight,
	shorne, deller, nathan, Yoshinori Sato, Rich Felker, linux-sh

On 06/25/23 at 11:12pm, John Paul Adrian Glaubitz wrote:
> Hi Baoquan!
> 
> On Tue, 2023-06-20 at 21:13 +0800, Baoquan He wrote:
> > 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 codes
>                                                                   ^^^^^
> Nit-pick: It should be "code", not "codes".

Will change.

> 
> I'll review and test the rest tomorrow. There are quite some changes.

That would be great, thanks a lot for your help.

> 
> > with generic_ioremap_prot() and generic_iounmap(), and has the equivalent
> > functioality as before.
> > 
> > Here, add wrapper functions ioremap_prot() and iounmap() for SuperH's
> > special operation when ioremap() and iounmap().
> > 
> > Signed-off-by: Baoquan He <bhe@redhat.com>
> > Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> > Cc: Rich Felker <dalias@libc.org>
> > Cc: linux-sh@vger.kernel.org
> > ---
> >  arch/sh/Kconfig          |  1 +
> >  arch/sh/include/asm/io.h | 40 +++++--------------------
> >  arch/sh/mm/ioremap.c     | 65 +++++++---------------------------------
> >  3 files changed, 20 insertions(+), 86 deletions(-)
> > 
> > diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
> > index 9652d367fc37..f326985e46e0 100644
> > --- a/arch/sh/Kconfig
> > +++ b/arch/sh/Kconfig
> > @@ -28,6 +28,7 @@ config SUPERH
> >  	select GENERIC_SMP_IDLE_THREAD
> >  	select GUP_GET_PXX_LOW_HIGH if X2TLB
> >  	select HAS_IOPORT if HAS_IOPORT_MAP
> > +	select GENERIC_IOREMAP if MMU
> >  	select HAVE_ARCH_AUDITSYSCALL
> >  	select HAVE_ARCH_KGDB
> >  	select HAVE_ARCH_SECCOMP_FILTER
> > diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h
> > index 270e7952950c..b3a26b405c8d 100644
> > --- a/arch/sh/include/asm/io.h
> > +++ b/arch/sh/include/asm/io.h
> > @@ -266,40 +266,16 @@ unsigned long long poke_real_address_q(unsigned long long addr,
> >  #endif
> >  
> >  #ifdef CONFIG_MMU
> > -void iounmap(void __iomem *addr);
> > -void __iomem *__ioremap_caller(phys_addr_t offset, unsigned long size,
> > -			       pgprot_t prot, void *caller);
> > -
> > -static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size)
> > -{
> > -	return __ioremap_caller(offset, size, PAGE_KERNEL_NOCACHE,
> > -			__builtin_return_address(0));
> > -}
> > -
> > -static inline void __iomem *
> > -ioremap_cache(phys_addr_t offset, unsigned long size)
> > -{
> > -	return __ioremap_caller(offset, size, PAGE_KERNEL,
> > -			__builtin_return_address(0));
> > -}
> > -#define ioremap_cache ioremap_cache
> > -
> > -#ifdef CONFIG_HAVE_IOREMAP_PROT
> > -static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
> > -		unsigned long flags)
> > -{
> > -	return __ioremap_caller(offset, size, __pgprot(flags),
> > -			__builtin_return_address(0));
> > -}
> > -#endif /* CONFIG_HAVE_IOREMAP_PROT */
> > +/*
> > + * I/O memory mapping functions.
> > + */
> > +#define ioremap_prot ioremap_prot
> > +#define iounmap iounmap
> >  
> > -#else /* CONFIG_MMU */
> > -static inline void __iomem *ioremap(phys_addr_t offset, size_t size)
> > -{
> > -	return (void __iomem *)(unsigned long)offset;
> > -}
> > +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL_NOCACHE)
> >  
> > -static inline void iounmap(volatile void __iomem *addr) { }
> > +#define ioremap_cache(addr, size)  \
> > +	ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL))
> >  #endif /* CONFIG_MMU */
> >  
> >  #define ioremap_uc	ioremap
> > diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c
> > index 21342581144d..c33b3daa4ad1 100644
> > --- a/arch/sh/mm/ioremap.c
> > +++ b/arch/sh/mm/ioremap.c
> > @@ -72,22 +72,11 @@ __ioremap_29bit(phys_addr_t offset, unsigned long size, pgprot_t prot)
> >  #define __ioremap_29bit(offset, size, prot)		NULL
> >  #endif /* CONFIG_29BIT */
> >  
> > -/*
> > - * Remap an arbitrary physical address space into the kernel virtual
> > - * address space. Needed when the kernel wants to access high addresses
> > - * directly.
> > - *
> > - * NOTE! We need to allow non-page-aligned mappings too: we will obviously
> > - * have to convert them into an offset in a page-aligned mapping, but the
> > - * caller shouldn't need to know that small detail.
> > - */
> > -void __iomem * __ref
> > -__ioremap_caller(phys_addr_t phys_addr, unsigned long size,
> > -		 pgprot_t pgprot, void *caller)
> > +void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size,
> > +			   unsigned long prot)
> >  {
> > -	struct vm_struct *area;
> > -	unsigned long offset, last_addr, addr, orig_addr;
> >  	void __iomem *mapped;
> > +	pgprot_t pgprot = __pgprot(prot);
> >  
> >  	mapped = __ioremap_trapped(phys_addr, size);
> >  	if (mapped)
> > @@ -97,11 +86,6 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size,
> >  	if (mapped)
> >  		return mapped;
> >  
> > -	/* Don't allow wraparound or zero size */
> > -	last_addr = phys_addr + size - 1;
> > -	if (!size || last_addr < phys_addr)
> > -		return NULL;
> > -
> >  	/*
> >  	 * If we can't yet use the regular approach, go the fixmap route.
> >  	 */
> > @@ -112,34 +96,14 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size,
> >  	 * First try to remap through the PMB.
> >  	 * PMB entries are all pre-faulted.
> >  	 */
> > -	mapped = pmb_remap_caller(phys_addr, size, pgprot, caller);
> > +	mapped = pmb_remap_caller(phys_addr, size, pgprot,
> > +			__builtin_return_address(0));
> >  	if (mapped && !IS_ERR(mapped))
> >  		return mapped;
> >  
> > -	/*
> > -	 * Mappings have to be page-aligned
> > -	 */
> > -	offset = phys_addr & ~PAGE_MASK;
> > -	phys_addr &= PAGE_MASK;
> > -	size = PAGE_ALIGN(last_addr+1) - phys_addr;
> > -
> > -	/*
> > -	 * Ok, go for it..
> > -	 */
> > -	area = get_vm_area_caller(size, VM_IOREMAP, caller);
> > -	if (!area)
> > -		return NULL;
> > -	area->phys_addr = phys_addr;
> > -	orig_addr = addr = (unsigned long)area->addr;
> > -
> > -	if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) {
> > -		vunmap((void *)orig_addr);
> > -		return NULL;
> > -	}
> > -
> > -	return (void __iomem *)(offset + (char *)orig_addr);
> > +	return generic_ioremap_prot(phys_addr, size, pgprot);
> >  }
> > -EXPORT_SYMBOL(__ioremap_caller);
> > +EXPORT_SYMBOL(ioremap_prot);
> >  
> >  /*
> >   * Simple checks for non-translatable mappings.
> > @@ -158,10 +122,9 @@ static inline int iomapping_nontranslatable(unsigned long offset)
> >  	return 0;
> >  }
> >  
> > -void iounmap(void __iomem *addr)
> > +void iounmap(volatile void __iomem *addr)
> >  {
> >  	unsigned long vaddr = (unsigned long __force)addr;
> > -	struct vm_struct *p;
> >  
> >  	/*
> >  	 * Nothing to do if there is no translatable mapping.
> > @@ -172,21 +135,15 @@ void iounmap(void __iomem *addr)
> >  	/*
> >  	 * There's no VMA if it's from an early fixed mapping.
> >  	 */
> > -	if (iounmap_fixed(addr) == 0)
> > +	if (iounmap_fixed((void __iomem *)addr) == 0)
> >  		return;
> >  
> >  	/*
> >  	 * If the PMB handled it, there's nothing else to do.
> >  	 */
> > -	if (pmb_unmap(addr) == 0)
> > +	if (pmb_unmap((void __iomem *)addr) == 0)
> >  		return;
> >  
> > -	p = remove_vm_area((void *)(vaddr & PAGE_MASK));
> > -	if (!p) {
> > -		printk(KERN_ERR "%s: bad address %p\n", __func__, addr);
> > -		return;
> > -	}
> > -
> > -	kfree(p);
> > +	generic_iounmap(addr);
> >  }
> >  EXPORT_SYMBOL(iounmap);
> 
> -- 
>  .''`.  John Paul Adrian Glaubitz
> : :' :  Debian Developer
> `. `'   Physicist
>   `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-26  2:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20230620131356.25440-1-bhe@redhat.com>
2023-06-20 13:13 ` [PATCH v7 11/19] sh: add <asm-generic/io.h> including Baoquan He
2023-06-20 13:13 ` [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP Baoquan He
2023-06-25 21:12   ` John Paul Adrian Glaubitz
2023-06-26  2:45     ` Baoquan He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).