mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Antony Pavlov <antonynpavlov@gmail.com>
Cc: barebox@lists.infradead.org, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: Re: [PATCH] asm-generic: provide phys_to_virt() and virt_to_phys()
Date: Mon, 8 Aug 2022 15:23:04 +0200	[thread overview]
Message-ID: <20220808132304.GQ31528@pengutronix.de> (raw)
In-Reply-To: <20220726102412.1104232-1-antonynpavlov@gmail.com>

On Tue, Jul 26, 2022 at 01:24:12PM +0300, Antony Pavlov wrote:
> The arm, riscv, sandbox and x86 architectures use
> just the same phys_to_virt()/virt_to_phys() implementation.
> Only the mips architecture has its own special implementation.
> 
> So we can move phys_to_virt() and virt_to_phys()
> generic implementation to include/asm-generic/io.h.
> 
> Use override functions way introduced in the 9216efafc52ff99e
> ("asm-generic/io.h: Reconcile I/O accessor overrides")
> linux kernel commit.
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
>  arch/arm/include/asm/io.h     | 10 ----------
>  arch/mips/include/asm/io.h    |  2 ++
>  arch/riscv/include/asm/io.h   | 10 ----------
>  arch/sandbox/include/asm/io.h | 10 ----------
>  arch/x86/include/asm/io.h     | 10 ----------
>  include/asm-generic/io.h      | 20 ++++++++++++++++++++
>  6 files changed, 22 insertions(+), 40 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
> index 1c0f522d1d4..486b1429502 100644
> --- a/arch/arm/include/asm/io.h
> +++ b/arch/arm/include/asm/io.h
> @@ -18,14 +18,4 @@ extern void memcpy_fromio(void *, const volatile void __iomem *, size_t);
>  extern void memcpy_toio(volatile void __iomem *, const void *, size_t);
>  extern void memset_io(volatile void __iomem *, int, size_t);
>  
> -static inline void *phys_to_virt(unsigned long phys)
> -{
> -	return (void *)phys;
> -}
> -
> -static inline unsigned long virt_to_phys(volatile void *mem)
> -{
> -	return (unsigned long)mem;
> -}
> -
>  #endif	/* __ASM_ARM_IO_H */
> diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h
> index 0d228aa0f51..a3acbd7017c 100644
> --- a/arch/mips/include/asm/io.h
> +++ b/arch/mips/include/asm/io.h
> @@ -27,6 +27,7 @@ void dma_inv_range(unsigned long, unsigned long);
>   *     The returned physical address is the physical (CPU) mapping for
>   *     the memory address given.
>   */
> +#define virt_to_phys virt_to_phys
>  static inline unsigned long virt_to_phys(const void *address)
>  {
>  	return (unsigned long)CPHYSADDR(address);
> @@ -39,6 +40,7 @@ static inline unsigned long virt_to_phys(const void *address)
>   *     The returned virtual address is a current CPU mapping for
>   *     the memory address given.
>   */
> +#define phys_to_virt phys_to_virt
>  static inline void *phys_to_virt(unsigned long address)
>  {
>  	if (IS_ENABLED(CONFIG_MMU)) {
> diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h
> index 978f6443407..76d66c0a3b8 100644
> --- a/arch/riscv/include/asm/io.h
> +++ b/arch/riscv/include/asm/io.h
> @@ -7,14 +7,4 @@
>  
>  #include <asm-generic/io.h>
>  
> -static inline void *phys_to_virt(unsigned long phys)
> -{
> -	return (void *)phys;
> -}
> -
> -static inline unsigned long virt_to_phys(volatile void *mem)
> -{
> -	return (unsigned long)mem;
> -}
> -
>  #endif /* __ASM_RISCV_IO_H */
> diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
> index 71cf50cd9a0..eec279b8883 100644
> --- a/arch/sandbox/include/asm/io.h
> +++ b/arch/sandbox/include/asm/io.h
> @@ -11,14 +11,4 @@ extern unsigned char __pci_iobase[IO_SPACE_LIMIT];
>  
>  #include <asm-generic/io.h>
>  
> -static inline void *phys_to_virt(unsigned long phys)
> -{
> -       return (void *)phys;
> -}
> -
> -static inline unsigned long virt_to_phys(volatile void *mem)
> -{
> -       return (unsigned long)mem;
> -}
> -
>  #endif /* __ASM_SANDBOX_IO_H */
> diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
> index 41c5cb3c14f..d4b5c269190 100644
> --- a/arch/x86/include/asm/io.h
> +++ b/arch/x86/include/asm/io.h
> @@ -84,16 +84,6 @@ static inline void io_delay(void)
>  	inb(0x80);
>  }
>  
> -static inline void *phys_to_virt(unsigned long phys)
> -{
> -	return (void *)phys;
> -}
> -
> -static inline unsigned long virt_to_phys(volatile void *mem)
> -{
> -	return (unsigned long)mem;
> -}
> -
>  #include <asm-generic/io.h>
>  
>  #endif	/* __ASM_X86_IO_H */
> diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
> index 47f8c3ec1be..e41b4df4036 100644
> --- a/include/asm-generic/io.h
> +++ b/include/asm-generic/io.h
> @@ -421,6 +421,26 @@ static inline void iowrite64be(u64 value, volatile void __iomem *addr)
>  #endif
>  #endif /* CONFIG_64BIT */
>  
> +/*
> + * Change virtual addresses to physical addresses and vv.
> + * These are pretty trivial
> + */
> +#ifndef virt_to_phys
> +#define virt_to_phys virt_to_phys
> +static inline unsigned long virt_to_phys(volatile void *mem)
> +{
> +	return (unsigned long)mem;
> +}
> +#endif
> +
> +#ifndef phys_to_virt
> +#define phys_to_virt phys_to_virt
> +static inline void *phys_to_virt(unsigned long phys)
> +{
> +	return (void *)phys;
> +}
> +#endif
> +
>  #ifndef IOMEM
>  #define IOMEM(addr)	((void __force __iomem *)(addr))
>  #endif
> -- 
> 2.36.1
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      reply	other threads:[~2022-08-08 13:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 10:24 Antony Pavlov
2022-08-08 13:23 ` Sascha Hauer [this message]

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=20220808132304.GQ31528@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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