[PATCH v2 1/2] sandbox: alias I/O ports region in MMIO space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux