asm-generic: provide phys_to_virt() and virt_to_phys()
Subsystems (5)
PATCH 1/1 asm-generic: provide phys_to_virt() and virt_to_phys()
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.
--- 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(-)
arch/arm/include/asm/io.h +0 -10
@@ -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 */
arch/mips/include/asm/io.h +2 -0
@@ -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_physstatic 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_virtstatic inline void *phys_to_virt (unsigned long address) {if (IS_ENABLED (CONFIG_MMU )) {
arch/riscv/include/asm/io.h +0 -10
@@ -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 */
arch/sandbox/include/asm/io.h +0 -10
@@ -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 */
arch/x86/include/asm/io.h +0 -10
@@ -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 */
include/asm-generic/io.h +20 -0
@@ -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
Signature · 1 line
2.36.1
Sascha Hauer
AppliedQuoted 12 lines · Antony Pavlov
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()andvirt_to_phys()generic implementation toinclude/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 <[email protected]>
Quoted 8 lines
--- 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
Quoted 134 lines
arch/arm/include/asm/io.h +0
-10@@ -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 */ arch/mips/include/asm/io.h +2
-0@@ -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_physstatic 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_virtstatic inline void *phys_to_virt (unsigned long address) {if (IS_ENABLED (CONFIG_MMU )) {arch/riscv/include/asm/io.h +0
-10@@ -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 */ arch/sandbox/include/asm/io.h +0
-10@@ -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 */ arch/x86/include/asm/io.h +0
-10@@ -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 */ include/asm-generic/io.h +20
-0@@ -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 Signature · 1 line
2.36.1
Signature · 4 lines
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 |