From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] of: add new of_fixup_reserved_memory() helper
Date: Mon, 15 Aug 2022 13:42:45 +0200 [thread overview]
Message-ID: <20220815114246.2275465-1-a.fatoum@pengutronix.de> (raw)
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>
---
common/oftree.c | 41 +++++++++++++++++++++++++++++++++++++++++
include/of.h | 2 ++
2 files changed, 43 insertions(+)
diff --git a/common/oftree.c b/common/oftree.c
index 91b3fcc9fad6..e459f84601a3 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;
diff --git a/include/of.h b/include/of.h
index 9130a36d372d..223c634bc88a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -113,6 +113,8 @@ int of_parse_dtb(struct fdt_header *fdt);
struct device_node *of_unflatten_dtb(const void *fdt, int size);
struct device_node *of_unflatten_dtb_const(const void *infdt, int size);
+int of_fixup_reserved_memory(struct device_node *node, void *data);
+
struct cdev;
#ifdef CONFIG_OFTREE
--
2.30.2
next reply other threads:[~2022-08-15 11:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-15 11:42 Ahmad Fatoum [this message]
2022-08-15 11:42 ` [PATCH 2/2] pstore: ram: use " Ahmad Fatoum
2022-08-15 14:17 ` [PATCH] fixup! " Ahmad Fatoum
2022-08-16 8:18 ` [PATCH 1/2] of: add " 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=20220815114246.2275465-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