From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Rouven Czerwinski <r.czerwinski@pengutronix.de>,
barebox@lists.infradead.org
Subject: Re: [PATCH v2 6/8] pbl: fdt: add support to parse reserved mem
Date: Thu, 5 Aug 2021 16:20:57 +0200 [thread overview]
Message-ID: <9452a831-7497-962f-dca4-74638b3d3553@pengutronix.de> (raw)
In-Reply-To: <20210803094418.475609-7-r.czerwinski@pengutronix.de>
Hello,
On 03.08.21 11:44, Rouven Czerwinski wrote:
> This allows the PBL to fill a reserved memory map which a subsequent
> commit will use modify the early MMU mapping.
>
> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
> ---
> include/pbl.h | 25 ++++++++++++
> pbl/fdt.c | 103 ++++++++++++++++++++++++++++++++++++++++++--------
> 2 files changed, 113 insertions(+), 15 deletions(-)
>
> diff --git a/include/pbl.h b/include/pbl.h
> index f58daec735..03272879d7 100644
> --- a/include/pbl.h
> +++ b/include/pbl.h
> @@ -42,5 +42,30 @@ struct fdt_device_id {
> const void *
> fdt_device_get_match_data(const void *fdt, const char *nodepath,
> const struct fdt_device_id ids[]);
> +struct pbl_reserved_memory {
> + phys_addr_t base;
> + phys_addr_t size;
> + unsigned int flags;
> +};
> +
> +#define MAX_RESERVED_REGIONS 8
> +
> +#define FDT_RES_MEM_FLAG_NOMAP BIT(0)
> +
> +void fdt_fill_reserve_mem(const void *fdt);
> +
> +#ifdef CONFIG_LIBFDT
> +const struct pbl_reserved_memory *get_pbl_reserved_memory(void);
> +int get_pbl_reserved_memory_num(void);
> +#else
> +static inline const struct pbl_reserved_memory *get_pbl_reserved_memory(void)
> +{
> + return NULL;
> +}
> +static inline int get_pbl_reserved_memory_num(void)
> +{
> + return 0;
> +}
> +#endif
>
> #endif /* __PBL_H__ */
> diff --git a/pbl/fdt.c b/pbl/fdt.c
> index 18ddb9f48a..383d0fec74 100644
> --- a/pbl/fdt.c
> +++ b/pbl/fdt.c
> @@ -5,8 +5,8 @@
>
> void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize)
> {
> - const __be32 *nap, *nsp, *reg;
> - uint32_t na, ns;
> + const __be32 *reg;
> + int na, ns;
> uint64_t memsize64, membase64;
> int node, size, i;
>
> @@ -16,26 +16,17 @@ void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsiz
> goto err;
> }
>
> - /* Find the #address-cells and #size-cells properties */
> - node = fdt_path_offset(fdt, "/");
> - if (node < 0) {
> - pr_err("Cannot find root node\n");
> - goto err;
> - }
> -
> - nap = fdt_getprop(fdt, node, "#address-cells", &size);
> - if (!nap || (size != 4)) {
> + na = fdt_address_cells(fdt, 0);
> + if (na < 0) {
> pr_err("Cannot find #address-cells property");
> goto err;
> }
> - na = fdt32_to_cpu(*nap);
>
> - nsp = fdt_getprop(fdt, node, "#size-cells", &size);
> - if (!nsp || (size != 4)) {
> + ns = fdt_size_cells(fdt, 0);
> + if (ns < 0) {
> pr_err("Cannot find #size-cells property");
> goto err;
> }
> - ns = fdt32_to_cpu(*nap);
I like the simplification, but it looks unrelated to the early reserved mem support..?
Perhaps split it up?
>
> /* Find the memory range */
> node = fdt_node_offset_by_prop_value(fdt, -1, "device_type",
> @@ -103,3 +94,85 @@ const void *fdt_device_get_match_data(const void *fdt, const char *nodepath,
>
> return NULL;
> }
> +
> +static struct pbl_reserved_memory reserved_mem[MAX_RESERVED_REGIONS];
> +static int reserved_mem_count;
> +
> +void fdt_fill_reserve_mem(const void *fdt)
> +{
> + const __be32 *nap, *nsp, *reg;
> + uint32_t na, ns;
> + int node, size, i, parent;
> + const void *prop;
> + uint64_t memsize64, membase64;
> + bool nomap;
> +
> + /* Make sure FDT blob is sane */
> + if (fdt_check_header(fdt) != 0) {
> + pr_err("Invalid device tree blob\n");
> + return;
> + }
> +
> + parent = fdt_path_offset(fdt, "/reserved-memory");
> + if (parent < 0) {
> + pr_info("Cannot find reserved-memory node\n");
> + return;
> + }
> +
> + nap = fdt_getprop(fdt, parent, "#address-cells", &size);
> + if (!nap || (size != 4)) {
> + pr_err("Cannot find #address-cells property");
> + return;
> + }
> + na = fdt32_to_cpu(*nap);
> +
> + nsp = fdt_getprop(fdt, parent, "#size-cells", &size);
> + if (!nsp || (size != 4)) {
> + pr_err("Cannot find #size-cells property");
> + return;
> + }
> + ns = fdt32_to_cpu(*nap);
Oh, did you mean to use the cool fdt_address_cells and fdt_size_cells helper you found here
but fuzzily wrote your code? ^^'
> +
> + fdt_for_each_subnode(node, fdt, parent) {
> + nomap = true;
> + reg = fdt_getprop(fdt, node, "reg", &size);
> + if (size < (na + ns) * sizeof(u32)) {
> + pr_err("cannot get memory range\n");
> + return;
> + }
> +
> + membase64 = 0;
> + for (i = 0; i < na; i++)
> + membase64 = (membase64 << 32) | fdt32_to_cpu(*reg++);
> +
> + /* get the memsize and truncate it to under 4G on 32 bit machines */
> + memsize64 = 0;
> + for (i = 0; i < ns; i++)
> + memsize64 = (memsize64 << 32) | fdt32_to_cpu(*reg++);
Can you turn this into a helper and use that for both fdt_find_mem and fdt_fill_reserve_mem?
> +
> + prop = fdt_getprop(fdt, node, "nomap", NULL);
> + if (!prop)
> + nomap = false;
Nitpick:
if (fdt_getprop(fdt, node, "nomap", NULL))
reserved_mem[reserved_mem_count].flags |= FDT_RES_MEM_FLAG_NOMAP;
would've worked too. Neither prop or nomap is strictly needed.
> +
> + reserved_mem[reserved_mem_count].base = membase64;
> + reserved_mem[reserved_mem_count].size = memsize64;
> + if (nomap)
> + reserved_mem[reserved_mem_count].flags |= FDT_RES_MEM_FLAG_NOMAP;
> + reserved_mem_count++;
> + }
> +
> + if ((node < 0) && (node != -FDT_ERR_NOTFOUND)) {
> + pr_err("Error while parsing reserved-memory nodes: %d\n", node);
> + return;
> + }
> +}
> +
> +const struct pbl_reserved_memory *get_pbl_reserved_memory(void)
> +{
> + return reserved_mem;
> +}
> +
> +int get_pbl_reserved_memory_num(void)
> +{
> + return reserved_mem_count;
> +}
>
--
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 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-08-05 14:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-03 9:44 [PATCH v2 0/8] XN Support for reserved-memory areas Rouven Czerwinski
2021-08-03 9:44 ` [PATCH v2 1/8] of: reserve: add xn flag mem entries Rouven Czerwinski
2021-08-05 13:54 ` Ahmad Fatoum
2021-08-09 18:26 ` Sascha Hauer
2021-08-03 9:44 ` [PATCH v2 2/8] of: add of_get_reserve_map stub for !CONFIG_OFTREE Rouven Czerwinski
2021-08-05 13:55 ` Ahmad Fatoum
2021-08-03 9:44 ` [PATCH v2 3/8] ARM: mmu: use reserve mem entries to modify maps Rouven Czerwinski
2021-08-05 14:06 ` Ahmad Fatoum
2021-08-09 18:30 ` Sascha Hauer
2021-08-24 7:09 ` Ahmad Fatoum
2021-08-03 9:44 ` [PATCH v2 4/8] of: add flag to not create resmem DT entries Rouven Czerwinski
2021-08-05 14:09 ` Ahmad Fatoum
2021-08-03 9:44 ` [PATCH v2 5/8] of: add reserved_mem_read initcall Rouven Czerwinski
2021-08-05 14:14 ` Ahmad Fatoum
2021-08-03 9:44 ` [PATCH v2 6/8] pbl: fdt: add support to parse reserved mem Rouven Czerwinski
2021-08-05 14:20 ` Ahmad Fatoum [this message]
2021-08-03 9:44 ` [PATCH v2 7/8] ARM: mmu-early: map no-map entries XN & uncached Rouven Czerwinski
2021-08-05 14:24 ` Ahmad Fatoum
2021-08-03 9:44 ` [PATCH v2 8/8] PBL: enable LIBFDT for OP-TEE early loading Rouven Czerwinski
2021-08-05 13:53 ` Ahmad Fatoum
2021-08-24 6:47 ` Rouven Czerwinski
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=9452a831-7497-962f-dca4-74638b3d3553@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=r.czerwinski@pengutronix.de \
/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