summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntony Pavlov <antonynpavlov@gmail.com>2022-07-26 13:24:12 +0300
committerSascha Hauer <s.hauer@pengutronix.de>2022-08-08 15:22:53 +0200
commitf6eccbf5924514087074129dca102f8b632c3f17 (patch)
tree44c2e6f814f4f931cc0c65c95721ebbbe01ddbdf
parent2a3008a347021bc2d3b91e1b252b328f64db7ffe (diff)
downloadbarebox-f6eccbf5924514087074129dca102f8b632c3f17.tar.gz
barebox-f6eccbf5924514087074129dca102f8b632c3f17.tar.xz
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. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Link: https://lore.barebox.org/20220726102412.1104232-1-antonynpavlov@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/include/asm/io.h10
-rw-r--r--arch/mips/include/asm/io.h2
-rw-r--r--arch/riscv/include/asm/io.h10
-rw-r--r--arch/sandbox/include/asm/io.h10
-rw-r--r--arch/x86/include/asm/io.h10
-rw-r--r--include/asm-generic/io.h20
6 files changed, 22 insertions, 40 deletions
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 1c0f522d1d..486b142950 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 0d228aa0f5..a3acbd7017 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 978f644340..76d66c0a3b 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 71cf50cd9a..eec279b888 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 41c5cb3c14..d4b5c26919 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 47f8c3ec1b..e41b4df403 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