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 v2 1/2] sandbox: alias I/O ports region in MMIO space
Date: Tue, 16 Jul 2024 14:03:09 +0200	[thread overview]
Message-ID: <20240716120310.1968471-1-a.fatoum@pengutronix.de> (raw)

We currently define __pci_iobase to please static analyzers that would
otherwise complain about inb/outb and friends accessing the NULL page.

Let's make better use of it and add a node representing it to the device
tree. This way we can add simple memory mapped peripherals on top that
just need writable registers that can be read back in tests.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - new commit: instead of messing with readb/writeb and friends'
    definition, we just do a device tree fixup
---
 arch/sandbox/board/Makefile   |  1 +
 arch/sandbox/board/devices.c  |  2 --
 arch/sandbox/board/io-ports.c | 35 +++++++++++++++++++++++++++++++++++
 arch/sandbox/dts/sandbox.dts  |  6 ++++++
 4 files changed, 42 insertions(+), 2 deletions(-)
 create mode 100644 arch/sandbox/board/io-ports.c

diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile
index b4bab02163fb..8e6e1d2d8843 100644
--- a/arch/sandbox/board/Makefile
+++ b/arch/sandbox/board/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
+obj-y += io-ports.o
 obj-y += board.o
 obj-y += clock.o
 obj-y += hostfile.o
diff --git a/arch/sandbox/board/devices.c b/arch/sandbox/board/devices.c
index ecd24e920721..0f344017b213 100644
--- a/arch/sandbox/board/devices.c
+++ b/arch/sandbox/board/devices.c
@@ -10,8 +10,6 @@
 #include <mach/linux.h>
 #include <asm/io.h>
 
-unsigned char __pci_iobase[IO_SPACE_LIMIT];
-
 static LIST_HEAD(sandbox_device_list);
 
 int sandbox_add_device(struct device *dev)
diff --git a/arch/sandbox/board/io-ports.c b/arch/sandbox/board/io-ports.c
new file mode 100644
index 000000000000..c5a26cdd0155
--- /dev/null
+++ b/arch/sandbox/board/io-ports.c
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <asm/io.h>
+#include <driver.h>
+#include <of.h>
+
+unsigned char __pci_iobase[IO_SPACE_LIMIT];
+
+static int ioport_bus_probe(struct device *dev)
+{
+	struct device_node *bus = dev->of_node;
+	u64 arr[3] = {
+		0,				/* child bus address */
+		virt_to_phys(__pci_iobase),	/* parent bus address */
+		sizeof(__pci_iobase),		/* resource size */
+	};
+
+	of_property_write_u64_array(bus, "reg", &arr[1], 2);
+	of_property_write_u64_array(bus, "ranges", &arr[0], 3);
+
+	return of_platform_populate(bus, of_default_bus_match_table, dev);
+}
+
+static __maybe_unused struct of_device_id sandbox_ioport_dt_ids[] = {
+	{ .compatible = "barebox,sandbox-ioport-bus", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, sandbox_ioport_dt_ids);
+
+static struct driver sandbox_ioport_driver = {
+	.name  = "sandbox-ioport-bus",
+	.of_compatible = sandbox_ioport_dt_ids,
+	.probe = ioport_bus_probe,
+};
+postcore_platform_driver(sandbox_ioport_driver);
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 3ed2c115a67e..ea75f3a6a9b0 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -55,6 +55,12 @@ y {
 		};
 	};
 
+	io-ports {
+		compatible = "barebox,sandbox-ioport-bus";
+		#address-cells = <2>;
+		#size-cells = <2>;
+	};
+
 	stickypage: stickypage {
 		compatible = "barebox,stickypage", "syscon";
 		reg = <0 0 0 4096>;
-- 
2.39.2




             reply	other threads:[~2024-07-16 12:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 12:03 Ahmad Fatoum [this message]
2024-07-16 12:03 ` [PATCH v2 2/2] sandbox: add dummy pinctrl nodes Ahmad Fatoum
2024-07-19 12:31 ` [PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space Sascha Hauer

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=20240716120310.1968471-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