summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-08-15 13:42:45 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-08-16 10:18:00 +0200
commitad05e170f6d1d40137c87c48d5f1a04cbf56ce50 (patch)
treed38a672f26feb10644d0bfb1e521e0a19630d476 /common
parentdb5522fe3e5d193895565a720e00d42e09ae8155 (diff)
downloadbarebox-ad05e170f6d1d40137c87c48d5f1a04cbf56ce50.tar.gz
barebox-ad05e170f6d1d40137c87c48d5f1a04cbf56ce50.tar.xz
of: add new of_fixup_reserved_memory() helper
We are opencoding the reserved memory fixup in fs/pstore/ram.c and the sequence is generic enough that we could use it for other fixups as well, e.g. rmem, barebox as secure monitor or OP-TEE which is not configured to generate an overlay or fix up the device tree itself. Add a helper that can be directly registered and reads all the necessary information out of a struct resource. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220815114246.2275465-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/oftree.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/common/oftree.c b/common/oftree.c
index 91b3fcc9fa..e459f84601 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -271,6 +271,47 @@ static int of_register_bootargs_fixup(void)
}
late_initcall(of_register_bootargs_fixup);
+int of_fixup_reserved_memory(struct device_node *root, void *_res)
+{
+ struct resource *res = _res;
+ struct device_node *node, *child;
+ struct property *pp;
+ unsigned addr_n_cells = sizeof(void *) / sizeof(__be32),
+ size_n_cells = sizeof(void *) / sizeof(__be32);
+ unsigned rangelen = 0;
+ __be32 reg[4];
+ int ret;
+
+ node = of_get_child_by_name(root, "reserved-memory") ?: of_new_node(root, "reserved-memory");
+
+ ret = of_property_read_u32(node, "#address-cells", &addr_n_cells);
+ if (ret)
+ of_property_write_u32(node, "#address-cells", addr_n_cells);
+
+ ret = of_property_read_u32(node, "#size-cells", &size_n_cells);
+ if (ret)
+ of_property_write_u32(node, "#size-cells", size_n_cells);
+
+ pp = of_find_property(node, "ranges", &rangelen) ?: of_new_property(node, "ranges", NULL, 0);
+ if (rangelen) {
+ pr_warn("reserved-memory ranges not 1:1 mapped. Aborting fixup\n");
+ return -EINVAL;
+ }
+
+ child = of_get_child_by_name(node, res->name) ?: of_new_node(node, res->name);
+
+ if (res->flags & IORESOURCE_BUSY)
+ of_property_write_bool(child, "no-map", true);
+
+ of_write_number(reg, res->start, addr_n_cells);
+ of_write_number(reg + addr_n_cells, resource_size(res), size_n_cells);
+
+ of_new_property(child, "reg", reg,
+ (addr_n_cells + size_n_cells) * sizeof(*reg));
+
+ return 0;
+}
+
struct of_fixup_status_data {
const char *path;
bool status;