[PATCH 1/2] sandbox: io: alias first page of I/O memory to I/O port space

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jul 1 00:27:32 PDT 2024


We already emulate 64KiB of port space by directing (in|out)[bwl] accesses
to the __pci_iobase static array.

By have (read|write)[bwlq] access the first 4K of that port space when
trying to access the NULL page.

That way generic drivers like e.g. pinctrl-single can be trivially
described in the device tree without having to worry about runtime fixup
of the base address in the DT.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/sandbox/include/asm/io.h | 70 +++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index eec279b88834..81e9a78151c1 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -3,12 +3,82 @@
 #ifndef __ASM_SANDBOX_IO_H
 #define __ASM_SANDBOX_IO_H
 
+#include <linux/types.h>
+#include <linux/compiler.h>
+
 #define	IO_SPACE_LIMIT 0xffff
 /* pacify static analyzers */
 #define PCI_IOBASE     ((void __iomem *)__pci_iobase)
 
 extern unsigned char __pci_iobase[IO_SPACE_LIMIT];
 
+/*
+ * Alias first page of I/O memory to I/O port space
+ */
+static inline volatile void __iomem *
+__xlate_addr(const volatile void __iomem *addr)
+{
+	if ((uintptr_t)addr  < 0x1000)
+		addr += (uintptr_t)__pci_iobase;
+	return (volatile void __iomem *)addr;
+}
+
+#define __raw_readb __raw_readb
+static inline u8 __raw_readb(const volatile void __iomem *addr)
+{
+	return *(const volatile u8 __force *)__xlate_addr(addr);
+}
+
+#define __raw_readw __raw_readw
+static inline u16 __raw_readw(const volatile void __iomem *addr)
+{
+	return *(const volatile u16 __force *)__xlate_addr(addr);
+}
+
+#define __raw_readl __raw_readl
+static inline u32 __raw_readl(const volatile void __iomem *addr)
+{
+	return *(const volatile u32 __force *)__xlate_addr(addr);
+}
+
+#ifdef CONFIG_64BIT
+#define __raw_readq __raw_readq
+static inline u64 __raw_readq(const volatile void __iomem *addr)
+{
+	return *(const volatile u64 __force *)__xlate_addr(addr);
+}
+#endif /* CONFIG_64BIT */
+
+#define __raw_writeb __raw_writeb
+static inline void __raw_writeb(u8 value, volatile void __iomem *addr)
+{
+	*(volatile u8 __force *)__xlate_addr(addr) = value;
+}
+
+#define __raw_writew __raw_writew
+static inline void __raw_writew(u16 value, volatile void __iomem *addr)
+{
+	*(volatile u16 __force *)__xlate_addr(addr) = value;
+}
+
+#ifndef __raw_writel
+#define __raw_writel __raw_writel
+static inline void __raw_writel(u32 value, volatile void __iomem *addr)
+{
+	*(volatile u32 __force *)__xlate_addr(addr) = value;
+}
+#endif
+
+#ifdef CONFIG_64BIT
+#define __raw_writeq __raw_writeq
+static inline void __raw_writeq(u64 value, volatile void __iomem *addr)
+{
+	*(volatile u64 __force *)__xlate_addr(addr) = value;
+}
+#endif /* CONFIG_64BIT */
+
+#undef __xlate_addr
+
 #include <asm-generic/io.h>
 
 #endif /* __ASM_SANDBOX_IO_H */
-- 
2.39.2




More information about the barebox mailing list