mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] sandbox: io: alias first page of I/O memory to I/O port space
Date: Mon,  1 Jul 2024 09:27:32 +0200	[thread overview]
Message-ID: <20240701072733.163431-1-a.fatoum@pengutronix.de> (raw)

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@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




             reply	other threads:[~2024-07-01  7:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-01  7:27 Ahmad Fatoum [this message]
2024-07-01  7:27 ` [PATCH 2/2] sandbox: add dummy pinctrl nodes Ahmad Fatoum

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=20240701072733.163431-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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