diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2023-10-23 09:49:34 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-10-23 10:43:56 +0200 |
commit | 58e9c930de5babda02097458a2ab0f42424eca50 (patch) | |
tree | f37cc3e026f6029948a651d11bf07dba5a463507 /common | |
parent | 95249ca7a94dd92d61098935d0de25bc92b82ba3 (diff) | |
download | barebox-58e9c930de5babda02097458a2ab0f42424eca50.tar.gz barebox-58e9c930de5babda02097458a2ab0f42424eca50.tar.xz |
memory: remap immediately in reserve_sdram_region()
reserve_sdram_region() has the purpose of reserving SDRAM regions from
being accessed by the CPU. Right now this remaps the reserved region
during MMU setup. Instead of doing this, remap the region immediately.
The MMU may be enabled already by early code. This means that when
reserve_sdram_region() is called with MMU enabled, we can't rely on
the region being mapped non-executable right after the call, but only
when __mmu_init() is executed. This patch relaxes this constraint.
Also, reserve_sdram_region() may now be called after __mmu_init() is
executed.
So far we silently aligned the remapped region to page boundaries, but
really calling reserve_sdram_region() with non page aligned boundaries
has undesired effects on the regions between the reserved region and
the page boundaries. Stay with this behaviour, but warn the user when
the to be reserved region is not page aligned as this really shouldn't
happen.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/memory.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/common/memory.c b/common/memory.c index 0ae9e7383c..d560d444b0 100644 --- a/common/memory.c +++ b/common/memory.c @@ -15,6 +15,7 @@ #include <asm/sections.h> #include <malloc.h> #include <of.h> +#include <mmu.h> /* * Begin and End of memory area for malloc(), and current "brk" @@ -211,6 +212,31 @@ struct resource *__request_sdram_region(const char *name, unsigned flags, return NULL; } +/* use for secure firmware to inhibit speculation */ +struct resource *reserve_sdram_region(const char *name, resource_size_t start, + resource_size_t size) +{ + struct resource *res; + + res = __request_sdram_region(name, IORESOURCE_BUSY, start, size); + if (IS_ERR(res)) + return ERR_CAST(res); + + if (!IS_ALIGNED(start, PAGE_SIZE)) { + pr_err("%s: %s start is not page aligned\n", __func__, name); + start = ALIGN_DOWN(start, PAGE_SIZE); + } + + if (!IS_ALIGNED(size, PAGE_SIZE)) { + pr_err("%s: %s size is not page aligned\n", __func__, name); + size = ALIGN(size, PAGE_SIZE); + } + + remap_range((void *)start, size, MAP_UNCACHED); + + return res; +} + int release_sdram_region(struct resource *res) { return release_region(res); |