From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
To: Baoquan He <bhe@redhat.com>, linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, arnd@arndb.de,
hch@lst.de, christophe.leroy@csgroup.eu, rppt@kernel.org,
willy@infradead.org, agordeev@linux.ibm.com,
wangkefeng.wang@huawei.com, schnelle@linux.ibm.com,
David.Laight@ACULAB.COM, shorne@gmail.com, deller@gmx.de,
nathan@kernel.org, Yoshinori Sato <ysato@users.sourceforge.jp>,
Rich Felker <dalias@libc.org>,
linux-sh@vger.kernel.org
Subject: Re: [PATCH v7 12/19] sh: mm: Convert to GENERIC_IOREMAP
Date: Sun, 25 Jun 2023 23:12:50 +0200 [thread overview]
Message-ID: <20fdf89dde5eee365ab15d9f4753e3c9fc43d46e.camel@physik.fu-berlin.de> (raw)
In-Reply-To: <20230620131356.25440-13-bhe@redhat.com>
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
next prev parent reply other threads:[~2023-06-25 21:13 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-20 13:13 [PATCH v7 00/19] mm: ioremap: Convert architectures to take GENERIC_IOREMAP way Baoquan He
2023-06-20 13:13 ` [PATCH v7 01/19] asm-generic/iomap.h: remove ARCH_HAS_IOREMAP_xx macros Baoquan He
2023-06-20 13:13 ` [PATCH v7 02/19] hexagon: mm: Convert to GENERIC_IOREMAP Baoquan He
2023-06-21 2:15 ` kernel test robot
2023-06-21 8:50 ` Baoquan He
2023-06-21 19:08 ` Nathan Chancellor
2023-06-25 1:15 ` Baoquan He
2023-06-20 13:13 ` [PATCH v7 03/19] openrisc: mm: remove unneeded early ioremap code Baoquan He
2023-06-20 13:13 ` [PATCH v7 04/19] mm/ioremap: Define generic_ioremap_prot() and generic_iounmap() Baoquan He
2023-06-20 13:13 ` [PATCH v7 05/19] mm: ioremap: allow ARCH to have its own ioremap method definition Baoquan He
2023-06-20 13:13 ` [PATCH v7 06/19] mm/ioremap: add slab availability checking in ioremap_prot Baoquan He
2023-06-20 13:13 ` [PATCH v7 07/19] arc: mm: Convert to GENERIC_IOREMAP Baoquan He
2023-06-20 13:13 ` [PATCH v7 08/19] ia64: " Baoquan He
2023-06-20 13:13 ` [PATCH v7 09/19] openrisc: " Baoquan He
2023-07-08 0:33 ` Stafford Horne
2023-07-09 10:11 ` Baoquan He
2023-06-20 13:13 ` [PATCH v7 10/19] s390: " Baoquan He
2023-06-21 5:43 ` kernel test robot
2023-06-21 10:41 ` Baoquan He
2023-06-21 10:46 ` Alexander Gordeev
2023-06-21 13:55 ` Baoquan He
2023-06-21 19:21 ` Nathan Chancellor
2023-06-24 12:45 ` Baoquan He
2023-07-06 15:55 ` Baoquan He
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 [this message]
2023-06-26 2:45 ` Baoquan He
2023-06-20 13:13 ` [PATCH v7 13/19] xtensa: " Baoquan He
2023-06-20 13:13 ` [PATCH v7 14/19] parisc: " Baoquan He
2023-06-20 13:13 ` [PATCH v7 15/19] mm/ioremap: Consider IOREMAP space in generic ioremap Baoquan He
2023-06-20 13:13 ` [PATCH v7 16/19] mm: move is_ioremap_addr() into new header file Baoquan He
2023-06-20 13:13 ` [PATCH v7 17/19] powerpc: mm: Convert to GENERIC_IOREMAP Baoquan He
2023-06-20 13:13 ` [PATCH v7 18/19] arm64 : mm: add wrapper function ioremap_prot() Baoquan He
2023-06-20 13:13 ` [PATCH v7 19/19] mm: ioremap: remove unneeded ioremap_allowed and iounmap_allowed Baoquan He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20fdf89dde5eee365ab15d9f4753e3c9fc43d46e.camel@physik.fu-berlin.de \
--to=glaubitz@physik.fu-berlin.de \
--cc=David.Laight@ACULAB.COM \
--cc=agordeev@linux.ibm.com \
--cc=arnd@arndb.de \
--cc=bhe@redhat.com \
--cc=christophe.leroy@csgroup.eu \
--cc=dalias@libc.org \
--cc=deller@gmx.de \
--cc=hch@lst.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-sh@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=rppt@kernel.org \
--cc=schnelle@linux.ibm.com \
--cc=shorne@gmail.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=ysato@users.sourceforge.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox