From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Rouven Czerwinski <r.czerwinski@pengutronix.de>,
barebox@lists.infradead.org
Subject: Re: [PATCH 6/8] pbl: fdt: add support to parse reserved mem
Date: Tue, 20 Apr 2021 12:29:06 +0200 [thread overview]
Message-ID: <5a8054fc-0ef9-0ef9-35e0-0027527b9566@pengutronix.de> (raw)
In-Reply-To: <20210420075700.246124-6-r.czerwinski@pengutronix.de>
On 20.04.21 09:56, 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 | 15 ++++++++++
> pbl/fdt.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 95 insertions(+)
>
> diff --git a/include/pbl.h b/include/pbl.h
> index 194d5e7508..df0f41ac5b 100644
> --- a/include/pbl.h
> +++ b/include/pbl.h
> @@ -34,4 +34,19 @@ ssize_t pbl_fat_load(struct pbl_bio *, const char *filename, void *dest, size_t
>
> void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize);
>
> +struct pbl_reserved_memory {
> + phys_addr_t base;
> + phys_addr_t size;
> + unsigned int flag;
flags
> +};
> +
> +#define MAX_RESERVED_REGIONS 8
> +
> +#define FDT_RES_MEM_FLAG_NOMAP BIT(0)
> +
> +void fdt_fill_reserve_mem(const void *fdt);
> +
> +struct pbl_reserved_memory* get_pbl_reserved_memory(void);
> +int get_pbl_reserved_memory_num(void);
> +
> #endif /* __PBL_H__ */
> diff --git a/pbl/fdt.c b/pbl/fdt.c
> index b4a40a514b..f8e301843f 100644
> --- a/pbl/fdt.c
> +++ b/pbl/fdt.c
> @@ -68,3 +68,83 @@ err:
> pr_err("No memory, cannot continue\n");
> while (1);
> }
> +
> +struct pbl_reserved_memory reserved_mem[MAX_RESERVED_REGIONS];
> +int reserved_mem_count;
Both can be made static.
> +
> +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);
fdt_address_cells?
> +
> + 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);
fdt_size_cells?
> +
> + 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++);
I wondered whether there's a helper for that, but couldn't find anything.
> +
> + /* 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++);
> +
> + prop = fdt_getprop(fdt, node, "nomap", NULL);
> + if (!prop)
> + nomap = false;
> +
> + reserved_mem[reserved_mem_count].base = membase64;
> + reserved_mem[reserved_mem_count].size = memsize64;
> + if (nomap)
> + reserved_mem[reserved_mem_count].flag |= 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;
> + }
> +}
> +
> +struct pbl_reserved_memory* get_pbl_reserved_memory(void) {
{ on separate line, make it const.
> + return (struct pbl_reserved_memory*)&reserved_mem;
just return reserved_mem; should work
> +}
> +
> +int get_pbl_reserved_memory_num(void) {
Ditto
> + 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-04-20 10:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-20 7:56 [PATCH 1/8] of: reserve: add xn flag mem entries Rouven Czerwinski
2021-04-20 7:56 ` [PATCH 2/8] of: export of_get_reserve_map Rouven Czerwinski
2021-04-20 8:47 ` Ahmad Fatoum
2021-04-20 7:56 ` [PATCH 3/8] ARM: mmu: use reserve mem entries to modify maps Rouven Czerwinski
2021-04-20 9:09 ` Ahmad Fatoum
2021-04-20 7:56 ` [PATCH 4/8] of: add flag to not create resmem DT entries Rouven Czerwinski
2021-04-20 9:22 ` Ahmad Fatoum
2021-04-20 7:56 ` [PATCH 5/8] of: add reserved_mem_read initcall Rouven Czerwinski
2021-04-20 9:23 ` Ahmad Fatoum
2021-04-20 10:36 ` Ahmad Fatoum
2021-04-20 7:56 ` [PATCH 6/8] pbl: fdt: add support to parse reserved mem Rouven Czerwinski
2021-04-20 10:29 ` Ahmad Fatoum [this message]
2021-04-20 7:57 ` [PATCH 7/8] ARM: mmu-early: map no-map entries XN & uncached Rouven Czerwinski
2021-04-20 9:00 ` Lucas Stach
2021-04-20 7:57 ` [PATCH 8/8] PBL: enable LIBFDT for OP-TEE early loading Rouven Czerwinski
2021-04-20 10:33 ` Ahmad Fatoum
2021-04-20 8:45 ` [PATCH 1/8] of: reserve: add xn flag mem entries Ahmad Fatoum
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=5a8054fc-0ef9-0ef9-35e0-0027527b9566@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