[PATCH v2 3/3] of: request reserved memory regions so other code can't
Sascha Hauer
sha at pengutronix.de
Tue Jun 14 23:28:36 PDT 2022
On Wed, Jun 15, 2022 at 08:06:29AM +0200, Ahmad Fatoum wrote:
> On 15.06.22 07:08, Sascha Hauer wrote:
> > On Thu, Jun 09, 2022 at 01:18:10PM +0200, Ahmad Fatoum wrote:
> >> Add a new of_reserved_mem_walk that can be used to request
> >> reserved memory regions. This avoids e.g. bootm trying to
> >> place the kernel into a reserved region.
> >>
> >> Signed-off-by: Rouven Czerwinski <r.czerwinski at pengutronix.de>
> >> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> >> ---
> >> v1 -> v2:
> >> - don't use of_reserve_entry accounting and instead
> >> directly request memory (Sascha)
> >> ---
> >> common/memory.c | 21 ++++++++++--
> >> drivers/of/Makefile | 1 +
> >> drivers/of/reserved-mem.c | 71 +++++++++++++++++++++++++++++++++++++++
> >> include/of.h | 9 +++++
> >> 4 files changed, 99 insertions(+), 3 deletions(-)
> >> create mode 100644 drivers/of/reserved-mem.c
> >>
> >> diff --git a/common/memory.c b/common/memory.c
> >> index 95995bb6e310..fd782c7f24f6 100644
> >> --- a/common/memory.c
> >> +++ b/common/memory.c
> >> @@ -3,6 +3,8 @@
> >> * Copyright (c) 2011 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
> >> */
> >>
> >> +#define pr_fmt(fmt) "memory: " fmt
> >> +
> >> #include <common.h>
> >> #include <memory.h>
> >> #include <of.h>
> >> @@ -12,6 +14,7 @@
> >> #include <asm-generic/memory_layout.h>
> >> #include <asm/sections.h>
> >> #include <malloc.h>
> >> +#include <of.h>
> >>
> >> /*
> >> * Begin and End of memory area for malloc(), and current "brk"
> >> @@ -53,9 +56,20 @@ void mem_malloc_init(void *start, void *end)
> >> mem_malloc_initialized = 1;
> >> }
> >>
> >> -#if !defined __SANDBOX__
> >> +static int request_reservation(const struct resource *res)
> >> +{
> >> + if (!(res->flags & IORESOURCE_EXCLUSIVE))
> >> + return 0;
> >> +
> >> + pr_debug("region %s %pa-%pa\n", res->name, &res->start, &res->end);
> >> +
> >> + request_sdram_region(res->name, res->start, resource_size(res));
> >> + return 0;
> >> +}
> >> +
> >> static int mem_malloc_resource(void)
> >> {
> >> +#if !defined __SANDBOX__
> >> /*
> >> * Normally it's a bug when one of these fails,
> >> * but we have some setups where some of these
> >> @@ -77,13 +91,14 @@ static int mem_malloc_resource(void)
> >> (unsigned long)&__bss_start,
> >> (unsigned long)&__bss_stop -
> >> (unsigned long)&__bss_start);
> >> +#endif
> >> #ifdef STACK_BASE
> >> request_sdram_region("stack", STACK_BASE, STACK_SIZE);
> >> #endif
> >> - return 0;
> >> +
> >> + return of_reserved_mem_walk(request_reservation);
> >> }
> >> coredevice_initcall(mem_malloc_resource);
> >> -#endif
> >>
> >> static void *sbrk_no_zero(ptrdiff_t increment)
> >> {
> >> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> >> index ca8da71cb4f0..99b610cba85e 100644
> >> --- a/drivers/of/Makefile
> >> +++ b/drivers/of/Makefile
> >> @@ -5,6 +5,7 @@ obj-$(CONFIG_OF_GPIO) += of_gpio.o
> >> obj-$(CONFIG_OF_PCI) += of_pci.o
> >> obj-y += partition.o
> >> obj-y += of_net.o
> >> +obj-$(CONFIG_OFDEVICE) += reserved-mem.o
> >
> > Compilation of this file depends on CONFIG_OFDEVICE, but the static
> > inline wrapper or not decision depends on CONFIG_OFTREE. This breaks a
> > number of defconfigs.
> > I took the easiest way out for now and changed to obj-y above to fix
> > this.
>
> I am surprised that works. With !CONFIG_OFTREE, <of.h> included in
> reserved-mem.c would provide a static inline helper that should
> clash with of_reserved_mem_walk defined with external linkage
> in that file. Can you change this into obj-$(CONFIG_OFTREE)?
I should have mentioned it's obj-$(CONFIG_OFTREE) implicitly because the
directory is obj-$(CONFIG_OFTREE).
Sascha
--
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 |
More information about the barebox
mailing list