lmb: replace the lmb_alloc() and lmb_alloc_base() API's
There currently are two API's for requesting memory from the LMB
module, lmb_alloc() and lmb_alloc_base(). The function which does the
actual allocation is the same. Use the earlier introduced API
lmb_alloc_mem() for both types of allocation requests.
Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff --git a/boot/bootm.c b/boot/bootm.c
index 3282bfc..4bdca22 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -623,12 +623,16 @@
*/
if (os.type == IH_TYPE_KERNEL_NOLOAD && os.comp != IH_COMP_NONE) {
ulong req_size = ALIGN(image_len * 4, SZ_1M);
+ phys_addr_t addr;
- load = lmb_alloc(req_size, SZ_2M);
- if (!load)
+ err = lmb_alloc_mem(LMB_MEM_ALLOC_ANY, SZ_2M, &addr,
+ req_size, LMB_NONE);
+ if (err)
return 1;
- os.load = load;
- images->ep = load;
+
+ load = (ulong)addr;
+ os.load = (ulong)addr;
+ images->ep = (ulong)addr;
debug("Allocated %lx bytes at %lx for kernel (size %lx) decompression\n",
req_size, load, image_len);
}
diff --git a/boot/image-board.c b/boot/image-board.c
index b0fa028..005d60c 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -16,6 +16,7 @@
#include <fpga.h>
#include <image.h>
#include <init.h>
+#include <lmb.h>
#include <log.h>
#include <mapmem.h>
#include <rtc.h>
@@ -566,27 +567,24 @@
*initrd_start = rd_data;
*initrd_end = rd_data + rd_len;
initrd_addr = (phys_addr_t)rd_data;
- err = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0,
- &initrd_addr, rd_len, LMB_NONE);
+ err = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &initrd_addr,
+ rd_len, LMB_NONE);
if (err) {
puts("in-place initrd alloc failed\n");
goto error;
}
} else {
- if (initrd_high)
- *initrd_start =
- (ulong)lmb_alloc_base(rd_len,
- 0x1000,
- initrd_high,
- LMB_NONE);
- else
- *initrd_start = (ulong)lmb_alloc(rd_len,
- 0x1000);
+ enum lmb_mem_type type = initrd_high ?
+ LMB_MEM_ALLOC_MAX : LMB_MEM_ALLOC_ANY;
- if (*initrd_start == 0) {
+ err = lmb_alloc_mem(type, 0x1000, &initrd_high, rd_len,
+ LMB_NONE);
+ if (err) {
puts("ramdisk - allocation error\n");
goto error;
}
+
+ *initrd_start = (ulong)initrd_high;
bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK);
*initrd_end = *initrd_start + rd_len;
@@ -837,9 +835,10 @@
*/
int boot_get_cmdline(ulong *cmd_start, ulong *cmd_end)
{
- int barg;
+ int barg, err;
char *cmdline;
char *s;
+ phys_addr_t addr;
/*
* Help the compiler detect that this function is only called when
@@ -849,12 +848,14 @@
return 0;
barg = IF_ENABLED_INT(CONFIG_SYS_BOOT_GET_CMDLINE, CONFIG_SYS_BARGSIZE);
- cmdline = (char *)(ulong)lmb_alloc_base(barg, 0xf,
- env_get_bootm_mapsize() + env_get_bootm_low(),
- LMB_NONE);
- if (!cmdline)
+ addr = env_get_bootm_mapsize() + env_get_bootm_low();
+
+ err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, 0xf, &addr, barg, LMB_NONE);
+ if (err)
return -1;
+ cmdline = (char *)(uintptr_t)addr;
+
s = env_get("bootargs");
if (!s)
s = "";
@@ -883,14 +884,16 @@
*/
int boot_get_kbd(struct bd_info **kbd)
{
- *kbd = (struct bd_info *)(ulong)lmb_alloc_base(sizeof(struct bd_info),
- 0xf,
- env_get_bootm_mapsize() +
- env_get_bootm_low(),
- LMB_NONE);
- if (!*kbd)
+ int err;
+ phys_addr_t addr;
+
+ addr = env_get_bootm_mapsize() + env_get_bootm_low();
+ err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, 0xf, &addr,
+ sizeof(struct bd_info), LMB_NONE);
+ if (err)
return -1;
+ *kbd = (struct bd_info *)(uintptr_t)addr;
**kbd = *gd->bd;
debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index bd5a623..2720ce6 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -183,9 +183,9 @@
/* If fdt_high is set use it to select the relocation address */
fdt_high = env_get("fdt_high");
if (fdt_high) {
- ulong desired_addr = hextoul(fdt_high, NULL);
+ ulong high_addr = hextoul(fdt_high, NULL);
- if (desired_addr == ~0UL) {
+ if (high_addr == ~0UL) {
/* All ones means use fdt in place */
of_start = fdt_blob;
addr = map_to_sysmem(fdt_blob);
@@ -198,16 +198,17 @@
}
disable_relocation = 1;
- } else if (desired_addr) {
- addr = lmb_alloc_base(of_len, 0x1000, desired_addr,
- LMB_NONE);
- of_start = map_sysmem(addr, of_len);
- if (of_start == NULL) {
- puts("Failed using fdt_high value for Device Tree");
+ } else {
+ enum lmb_mem_type type = high_addr ?
+ LMB_MEM_ALLOC_MAX : LMB_MEM_ALLOC_ANY;
+
+ addr = high_addr;
+ err = lmb_alloc_mem(type, 0x1000, &addr, of_len,
+ LMB_NONE);
+ if (err) {
+ puts("Failed to allocate memory for Device Tree relocation\n");
goto error;
}
- } else {
- addr = lmb_alloc(of_len, 0x1000);
of_start = map_sysmem(addr, of_len);
}
} else {
@@ -229,11 +230,15 @@
* for LMB allocation.
*/
usable = min(start + size, low + mapsize);
- addr = lmb_alloc_base(of_len, 0x1000, usable, LMB_NONE);
- of_start = map_sysmem(addr, of_len);
- /* Allocation succeeded, use this block. */
- if (of_start != NULL)
- break;
+ addr = usable;
+ err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, 0x1000,
+ &addr, of_len, LMB_NONE);
+ if (!err) {
+ of_start = map_sysmem(addr, of_len);
+ /* Allocation succeeded, use this block. */
+ if (of_start)
+ break;
+ }
/*
* Reduce the mapping size in the next bank