Message ID | 20241211105504.453234-8-ilias.apalodimas@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | Cleanup the LMB subsystem | expand |
On Wed, Dec 11, 2024 at 4:55 AM Ilias Apalodimas <ilias.apalodimas@linaro.org> wrote: > > lmb_alloc_base() is just calling lmb_alloc_base_flags() with LMB_NONE. > There's not much we gain from this abstraction, so let's remove the > former add the flags argument to lmb_alloc_base() and make the code > a bit easier to follow. > > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> > --- Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org> > boot/image-board.c | 18 +++++++++++------- > boot/image-fdt.c | 5 +++-- > include/lmb.h | 7 +++---- > lib/efi_loader/efi_memory.c | 4 ++-- > lib/lmb.c | 19 +++---------------- > test/lib/lmb.c | 8 ++++---- > 6 files changed, 26 insertions(+), 35 deletions(-) > > diff --git a/boot/image-board.c b/boot/image-board.c > index 070ada007185..4e86a9a22719 100644 > --- a/boot/image-board.c > +++ b/boot/image-board.c > @@ -565,9 +565,11 @@ int boot_ramdisk_high(ulong rd_data, ulong rd_len, ulong *initrd_start, > lmb_reserve(rd_data, rd_len, LMB_NONE); > } else { > if (initrd_high) > - *initrd_start = (ulong)lmb_alloc_base(rd_len, > - 0x1000, > - initrd_high); > + *initrd_start = > + (ulong)lmb_alloc_base(rd_len, > + 0x1000, > + initrd_high, > + LMB_NONE); > else > *initrd_start = (ulong)lmb_alloc(rd_len, > 0x1000); > @@ -839,7 +841,8 @@ int boot_get_cmdline(ulong *cmd_start, ulong *cmd_end) > > 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()); > + env_get_bootm_mapsize() + env_get_bootm_low(), > + LMB_NONE); > if (!cmdline) > return -1; > > @@ -872,9 +875,10 @@ int boot_get_cmdline(ulong *cmd_start, ulong *cmd_end) > 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()); > + 0xf, > + env_get_bootm_mapsize() + > + env_get_bootm_low(), > + LMB_NONE); > if (!*kbd) > return -1; > > diff --git a/boot/image-fdt.c b/boot/image-fdt.c > index d717f6690729..9d1598b1a93c 100644 > --- a/boot/image-fdt.c > +++ b/boot/image-fdt.c > @@ -187,7 +187,8 @@ int boot_relocate_fdt(char **of_flat_tree, ulong *of_size) > lmb_reserve(map_to_sysmem(of_start), of_len, LMB_NONE); > disable_relocation = 1; > } else if (desired_addr) { > - addr = lmb_alloc_base(of_len, 0x1000, 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"); > @@ -216,7 +217,7 @@ int boot_relocate_fdt(char **of_flat_tree, ulong *of_size) > * for LMB allocation. > */ > usable = min(start + size, low + mapsize); > - addr = lmb_alloc_base(of_len, 0x1000, usable); > + 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) > diff --git a/include/lmb.h b/include/lmb.h > index 5e59915340b7..d481972a6686 100644 > --- a/include/lmb.h > +++ b/include/lmb.h > @@ -91,11 +91,10 @@ long lmb_add(phys_addr_t base, phys_size_t size); > long lmb_reserve(phys_addr_t base, phys_size_t size, u32 flags); > > phys_addr_t lmb_alloc(phys_size_t size, ulong align); > -phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr); > phys_size_t lmb_get_free_size(phys_addr_t addr); > > /** > - * lmb_alloc_base_flags() - Allocate specified memory region with specified > + * lmb_alloc_base() - Allocate specified memory region with specified > * attributes > * @size: Size of the region requested > * @align: Alignment of the memory region requested > @@ -108,8 +107,8 @@ phys_size_t lmb_get_free_size(phys_addr_t addr); > * > * Return: Base address on success, 0 on error. > */ > -phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align, > - phys_addr_t max_addr, uint flags); > +phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr, > + uint flags); > > /** > * lmb_alloc_addr() - Allocate specified memory address with specified attributes > diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c > index 34e2b9e18ef0..1212772471e3 100644 > --- a/lib/efi_loader/efi_memory.c > +++ b/lib/efi_loader/efi_memory.c > @@ -472,7 +472,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, > switch (type) { > case EFI_ALLOCATE_ANY_PAGES: > /* Any page */ > - addr = (u64)lmb_alloc_base_flags(len, EFI_PAGE_SIZE, > + addr = (u64)lmb_alloc_base(len, EFI_PAGE_SIZE, > LMB_ALLOC_ANYWHERE, flags); > if (!addr) > return EFI_OUT_OF_RESOURCES; > @@ -480,7 +480,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, > case EFI_ALLOCATE_MAX_ADDRESS: > /* Max address */ > addr = map_to_sysmem((void *)(uintptr_t)*memory); > - addr = (u64)lmb_alloc_base_flags(len, EFI_PAGE_SIZE, addr, > + addr = (u64)lmb_alloc_base(len, EFI_PAGE_SIZE, addr, > flags); > if (!addr) > return EFI_OUT_OF_RESOURCES; > diff --git a/lib/lmb.c b/lib/lmb.c > index ffad7ec12eb5..bdaaa634abd1 100644 > --- a/lib/lmb.c > +++ b/lib/lmb.c > @@ -731,24 +731,11 @@ static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align, > > phys_addr_t lmb_alloc(phys_size_t size, ulong align) > { > - return lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE); > + return lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE, LMB_NONE); > } > > -phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr) > -{ > - phys_addr_t alloc; > - > - alloc = _lmb_alloc_base(size, align, max_addr, LMB_NONE); > - > - if (alloc == 0) > - printf("ERROR: Failed to allocate 0x%lx bytes below 0x%lx.\n", > - (ulong)size, (ulong)max_addr); > - > - return alloc; > -} > - > -phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align, > - phys_addr_t max_addr, uint flags) > +phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr, > + uint flags) > { > phys_addr_t alloc; > > diff --git a/test/lib/lmb.c b/test/lib/lmb.c > index 971614fd8314..fcb5f1af532a 100644 > --- a/test/lib/lmb.c > +++ b/test/lib/lmb.c > @@ -128,7 +128,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, > ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr, 0x10000, > ram_end - 4, 4, 0, 0); > /* alloc below end of reserved region -> below reserved region */ > - b = lmb_alloc_base(4, 1, alloc_64k_end); > + b = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE); > ut_asserteq(b, alloc_64k_addr - 4); > ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, > alloc_64k_addr - 4, 0x10000 + 4, ram_end - 4, 4, 0, 0); > @@ -138,7 +138,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, > ut_asserteq(c, ram_end - 8); > ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, > alloc_64k_addr - 4, 0x10000 + 4, ram_end - 8, 8, 0, 0); > - d = lmb_alloc_base(4, 1, alloc_64k_end); > + d = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE); > ut_asserteq(d, alloc_64k_addr - 8); > ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, > alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 8, 0, 0); > @@ -163,7 +163,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, > alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000, > ram_end - 8, 4); > /* allocate again to ensure we get the same address */ > - b2 = lmb_alloc_base(4, 1, alloc_64k_end); > + b2 = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE); > ut_asserteq(b, b2); > ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, > alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0); > @@ -363,7 +363,7 @@ static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram, > ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); > > /* allocate a block with base*/ > - b = lmb_alloc_base(alloc_size, align, ram_end); > + b = lmb_alloc_base(alloc_size, align, ram_end, LMB_NONE); > ut_assert(a == b); > ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, > ram + ram_size - alloc_size_aligned, > -- > 2.45.2 >
diff --git a/boot/image-board.c b/boot/image-board.c index 070ada007185..4e86a9a22719 100644 --- a/boot/image-board.c +++ b/boot/image-board.c @@ -565,9 +565,11 @@ int boot_ramdisk_high(ulong rd_data, ulong rd_len, ulong *initrd_start, lmb_reserve(rd_data, rd_len, LMB_NONE); } else { if (initrd_high) - *initrd_start = (ulong)lmb_alloc_base(rd_len, - 0x1000, - initrd_high); + *initrd_start = + (ulong)lmb_alloc_base(rd_len, + 0x1000, + initrd_high, + LMB_NONE); else *initrd_start = (ulong)lmb_alloc(rd_len, 0x1000); @@ -839,7 +841,8 @@ int boot_get_cmdline(ulong *cmd_start, ulong *cmd_end) 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()); + env_get_bootm_mapsize() + env_get_bootm_low(), + LMB_NONE); if (!cmdline) return -1; @@ -872,9 +875,10 @@ int boot_get_cmdline(ulong *cmd_start, ulong *cmd_end) 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()); + 0xf, + env_get_bootm_mapsize() + + env_get_bootm_low(), + LMB_NONE); if (!*kbd) return -1; diff --git a/boot/image-fdt.c b/boot/image-fdt.c index d717f6690729..9d1598b1a93c 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -187,7 +187,8 @@ int boot_relocate_fdt(char **of_flat_tree, ulong *of_size) lmb_reserve(map_to_sysmem(of_start), of_len, LMB_NONE); disable_relocation = 1; } else if (desired_addr) { - addr = lmb_alloc_base(of_len, 0x1000, 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"); @@ -216,7 +217,7 @@ int boot_relocate_fdt(char **of_flat_tree, ulong *of_size) * for LMB allocation. */ usable = min(start + size, low + mapsize); - addr = lmb_alloc_base(of_len, 0x1000, usable); + 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) diff --git a/include/lmb.h b/include/lmb.h index 5e59915340b7..d481972a6686 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -91,11 +91,10 @@ long lmb_add(phys_addr_t base, phys_size_t size); long lmb_reserve(phys_addr_t base, phys_size_t size, u32 flags); phys_addr_t lmb_alloc(phys_size_t size, ulong align); -phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr); phys_size_t lmb_get_free_size(phys_addr_t addr); /** - * lmb_alloc_base_flags() - Allocate specified memory region with specified + * lmb_alloc_base() - Allocate specified memory region with specified * attributes * @size: Size of the region requested * @align: Alignment of the memory region requested @@ -108,8 +107,8 @@ phys_size_t lmb_get_free_size(phys_addr_t addr); * * Return: Base address on success, 0 on error. */ -phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align, - phys_addr_t max_addr, uint flags); +phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr, + uint flags); /** * lmb_alloc_addr() - Allocate specified memory address with specified attributes diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 34e2b9e18ef0..1212772471e3 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -472,7 +472,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, switch (type) { case EFI_ALLOCATE_ANY_PAGES: /* Any page */ - addr = (u64)lmb_alloc_base_flags(len, EFI_PAGE_SIZE, + addr = (u64)lmb_alloc_base(len, EFI_PAGE_SIZE, LMB_ALLOC_ANYWHERE, flags); if (!addr) return EFI_OUT_OF_RESOURCES; @@ -480,7 +480,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, case EFI_ALLOCATE_MAX_ADDRESS: /* Max address */ addr = map_to_sysmem((void *)(uintptr_t)*memory); - addr = (u64)lmb_alloc_base_flags(len, EFI_PAGE_SIZE, addr, + addr = (u64)lmb_alloc_base(len, EFI_PAGE_SIZE, addr, flags); if (!addr) return EFI_OUT_OF_RESOURCES; diff --git a/lib/lmb.c b/lib/lmb.c index ffad7ec12eb5..bdaaa634abd1 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -731,24 +731,11 @@ static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t lmb_alloc(phys_size_t size, ulong align) { - return lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE); + return lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE, LMB_NONE); } -phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr) -{ - phys_addr_t alloc; - - alloc = _lmb_alloc_base(size, align, max_addr, LMB_NONE); - - if (alloc == 0) - printf("ERROR: Failed to allocate 0x%lx bytes below 0x%lx.\n", - (ulong)size, (ulong)max_addr); - - return alloc; -} - -phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align, - phys_addr_t max_addr, uint flags) +phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr, + uint flags) { phys_addr_t alloc; diff --git a/test/lib/lmb.c b/test/lib/lmb.c index 971614fd8314..fcb5f1af532a 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -128,7 +128,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr, 0x10000, ram_end - 4, 4, 0, 0); /* alloc below end of reserved region -> below reserved region */ - b = lmb_alloc_base(4, 1, alloc_64k_end); + b = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE); ut_asserteq(b, alloc_64k_addr - 4); ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 4, 0x10000 + 4, ram_end - 4, 4, 0, 0); @@ -138,7 +138,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, ut_asserteq(c, ram_end - 8); ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 4, 0x10000 + 4, ram_end - 8, 8, 0, 0); - d = lmb_alloc_base(4, 1, alloc_64k_end); + d = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE); ut_asserteq(d, alloc_64k_addr - 8); ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 8, 0, 0); @@ -163,7 +163,7 @@ static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram, alloc_64k_addr - 8, 4, alloc_64k_addr, 0x10000, ram_end - 8, 4); /* allocate again to ensure we get the same address */ - b2 = lmb_alloc_base(4, 1, alloc_64k_end); + b2 = lmb_alloc_base(4, 1, alloc_64k_end, LMB_NONE); ut_asserteq(b, b2); ASSERT_LMB(mem_lst, used_lst, 0, 0, 2, alloc_64k_addr - 8, 0x10000 + 8, ram_end - 8, 4, 0, 0); @@ -363,7 +363,7 @@ static int test_noreserved(struct unit_test_state *uts, const phys_addr_t ram, ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 0, 0, 0, 0, 0, 0, 0); /* allocate a block with base*/ - b = lmb_alloc_base(alloc_size, align, ram_end); + b = lmb_alloc_base(alloc_size, align, ram_end, LMB_NONE); ut_assert(a == b); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, ram + ram_size - alloc_size_aligned,
lmb_alloc_base() is just calling lmb_alloc_base_flags() with LMB_NONE. There's not much we gain from this abstraction, so let's remove the former add the flags argument to lmb_alloc_base() and make the code a bit easier to follow. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> --- boot/image-board.c | 18 +++++++++++------- boot/image-fdt.c | 5 +++-- include/lmb.h | 7 +++---- lib/efi_loader/efi_memory.c | 4 ++-- lib/lmb.c | 19 +++---------------- test/lib/lmb.c | 8 ++++---- 6 files changed, 26 insertions(+), 35 deletions(-)