diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-01 22:09:49 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-04 22:26:07 +0100 |
commit | ec8dd2542847c4e161d8fc521dfc6af0ed25c896 (patch) | |
tree | c10bfda6666f0231585f02a92fa3e790ad2c2170 /common | |
parent | 32f163f67c10ff7415baee2d022459cc859d84b1 (diff) | |
download | barebox-ec8dd2542847c4e161d8fc521dfc6af0ed25c896.tar.gz barebox-ec8dd2542847c4e161d8fc521dfc6af0ed25c896.tar.xz |
register sdram as resources
Also, request the sdram regions used by the barebox binary,
bss, malloc space and stack.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/memory.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/common/memory.c b/common/memory.c index 0ba9a18e88..7d0f4cab2a 100644 --- a/common/memory.c +++ b/common/memory.c @@ -25,6 +25,9 @@ #include <of.h> #include <init.h> #include <libfdt.h> +#include <linux/ioport.h> +#include <asm-generic/memory_layout.h> +#include <asm/sections.h> /* * Begin and End of memory area for malloc(), and current "brk" @@ -50,6 +53,33 @@ void mem_malloc_init(void *start, void *end) malloc_brk = malloc_start; } +static int mem_malloc_resource(void) +{ + /* + * Normally it's a bug when one of these fails, + * but we have some setups where some of these + * regions are outside of sdram in which case + * the following fails. + */ + request_sdram_region("malloc space", + malloc_start, + malloc_end - malloc_start + 1); + request_sdram_region("barebox", + (unsigned long)&_stext, + (unsigned long)&_etext - + (unsigned long)&_stext + 1); + request_sdram_region("bss", + (unsigned long)&__bss_start, + (unsigned long)&__bss_stop - + (unsigned long)&__bss_start + 1); +#ifdef STACK_BASE + request_sdram_region("stack", STACK_BASE, STACK_SIZE); +#endif + + return 0; +} +coredevice_initcall(mem_malloc_resource); + static void *sbrk_no_zero(ptrdiff_t increment) { unsigned long old = malloc_brk; @@ -82,6 +112,10 @@ void barebox_add_memory_bank(const char *name, resource_size_t start, struct memory_bank *bank = xzalloc(sizeof(*bank)); struct device_d *dev; + bank->res = request_iomem_region(name, start, size); + + BUG_ON(!bank->res); + dev = add_mem_device(name, start, size, IORESOURCE_MEM_WRITEABLE); bank->dev = dev; @@ -91,6 +125,30 @@ void barebox_add_memory_bank(const char *name, resource_size_t start, list_add_tail(&bank->list, &memory_banks); } +/* + * Request a region from the registered sdram + */ +struct resource *request_sdram_region(const char *name, resource_size_t start, + resource_size_t size) +{ + struct memory_bank *bank; + + for_each_memory_bank(bank) { + struct resource *res; + + res = request_region(bank->res, name, start, size); + if (res) + return res; + } + + return NULL; +} + +int release_sdram_region(struct resource *res) +{ + return release_region(res); +} + #ifdef CONFIG_OFTREE /* |