From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] of: add new of_fixup_reserved_memory() helper
Date: Tue, 16 Aug 2022 10:18:47 +0200 [thread overview]
Message-ID: <20220816081847.GI17485@pengutronix.de> (raw)
In-Reply-To: <20220815114246.2275465-1-a.fatoum@pengutronix.de>
On Mon, Aug 15, 2022 at 01:42:45PM +0200, Ahmad Fatoum wrote:
> 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(+)
Applied, thanks
Sascha
>
> 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
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
prev parent reply other threads:[~2022-08-16 8:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-15 11:42 Ahmad Fatoum
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 ` Sascha Hauer [this message]
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=20220816081847.GI17485@pengutronix.de \
--to=sha@pengutronix.de \
--cc=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