diff options
Diffstat (limited to 'common/memory.c')
-rw-r--r-- | common/memory.c | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/common/memory.c b/common/memory.c index fd782c7f24..583843cc34 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" @@ -56,17 +57,6 @@ void mem_malloc_init(void *start, void *end) mem_malloc_initialized = 1; } -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__ @@ -96,7 +86,7 @@ static int mem_malloc_resource(void) request_sdram_region("stack", STACK_BASE, STACK_SIZE); #endif - return of_reserved_mem_walk(request_reservation); + return 0; } coredevice_initcall(mem_malloc_resource); @@ -160,6 +150,7 @@ int barebox_add_memory_bank(const char *name, resource_size_t start, struct resource newres = { .start = start, .end = start + size - 1, + .flags = IORESOURCE_MEM, }; for_each_memory_bank(bank) { @@ -173,6 +164,8 @@ int barebox_add_memory_bank(const char *name, resource_size_t start, if (IS_ERR(res)) return PTR_ERR(res); + res->flags = IORESOURCE_MEM; + bank = xzalloc(sizeof(*bank)); bank->res = res; @@ -195,21 +188,23 @@ static int add_mem_devices(void) return 0; } -mmu_initcall(add_mem_devices); +postmem_initcall(add_mem_devices); /* * Request a region from the registered sdram */ -struct resource *request_sdram_region(const char *name, resource_size_t start, - resource_size_t size) +struct resource *__request_sdram_region(const char *name, unsigned flags, + resource_size_t start, resource_size_t size) { struct memory_bank *bank; + flags |= IORESOURCE_MEM; + for_each_memory_bank(bank) { struct resource *res; - res = __request_region(bank->res, name, start, - start + size - 1); + res = __request_region(bank->res, start, start + size - 1, + name, flags); if (!IS_ERR(res)) return res; } @@ -217,6 +212,31 @@ struct resource *request_sdram_region(const char *name, resource_size_t start, 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; + + 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); + } + + res = __request_sdram_region(name, IORESOURCE_BUSY, start, size); + if (!res) + return NULL; + + remap_range((void *)start, size, MAP_UNCACHED); + + return res; +} + int release_sdram_region(struct resource *res) { return release_region(res); |