"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Sughosh Ganu and committed by
Tom Rini
6e4675b8 9d37a3d6

+141 -102
+18 -9
arch/arm/mach-apple/board.c
··· 773 773 774 774 #define KERNEL_COMP_SIZE SZ_128M 775 775 776 + #define lmb_alloc(size, addr) lmb_alloc_mem(LMB_MEM_ALLOC_ANY, SZ_2M, addr, size, LMB_NONE) 777 + 776 778 int board_late_init(void) 777 779 { 778 780 u32 status = 0; 781 + phys_addr_t addr; 779 782 780 783 /* somewhat based on the Linux Kernel boot requirements: 781 784 * align by 2M and maximal FDT size 2M 782 785 */ 783 - status |= env_set_hex("loadaddr", lmb_alloc(SZ_1G, SZ_2M)); 784 - status |= env_set_hex("fdt_addr_r", lmb_alloc(SZ_2M, SZ_2M)); 785 - status |= env_set_hex("kernel_addr_r", lmb_alloc(SZ_128M, SZ_2M)); 786 - status |= env_set_hex("ramdisk_addr_r", lmb_alloc(SZ_1G, SZ_2M)); 787 - status |= env_set_hex("kernel_comp_addr_r", 788 - lmb_alloc(KERNEL_COMP_SIZE, SZ_2M)); 789 - status |= env_set_hex("kernel_comp_size", KERNEL_COMP_SIZE); 790 - status |= env_set_hex("scriptaddr", lmb_alloc(SZ_4M, SZ_2M)); 791 - status |= env_set_hex("pxefile_addr_r", lmb_alloc(SZ_4M, SZ_2M)); 786 + status |= !lmb_alloc(SZ_1G, &addr) ? env_set_hex("loadaddr", addr) : 1; 787 + status |= !lmb_alloc(SZ_2M, &addr) ? 788 + env_set_hex("fdt_addr_r", addr) : 1; 789 + status |= !lmb_alloc(SZ_128M, &addr) ? 790 + env_set_hex("kernel_addr_r", addr) : 1; 791 + status |= !lmb_alloc(SZ_1G, &addr) ? 792 + env_set_hex("ramdisk_addr_r", addr) : 1; 793 + status |= !lmb_alloc(KERNEL_COMP_SIZE, &addr) ? 794 + env_set_hex("kernel_comp_addr_r", addr) : 1; 795 + status |= !lmb_alloc(KERNEL_COMP_SIZE, &addr) ? 796 + env_set_hex("kernel_comp_size", addr) : 1; 797 + status |= !lmb_alloc(SZ_4M, &addr) ? 798 + env_set_hex("scriptaddr", addr) : 1; 799 + status |= !lmb_alloc(SZ_4M, &addr) ? 800 + env_set_hex("pxefile_addr_r", addr) : 1; 792 801 793 802 if (status) 794 803 log_warning("late_init: Failed to set run time variables\n");
+19 -11
arch/arm/mach-snapdragon/board.c
··· 492 492 #define FASTBOOT_BUF_SIZE 0 493 493 #endif 494 494 495 - #define addr_alloc(size) lmb_alloc(size, SZ_2M) 495 + #define lmb_alloc(size, addr) lmb_alloc_mem(LMB_MEM_ALLOC_ANY, SZ_2M, addr, size, LMB_NONE) 496 496 497 497 /* Stolen from arch/arm/mach-apple/board.c */ 498 498 int board_late_init(void) ··· 502 502 struct fdt_header *fdt_blob = (struct fdt_header *)gd->fdt_blob; 503 503 504 504 /* We need to be fairly conservative here as we support boards with just 1G of TOTAL RAM */ 505 - addr = addr_alloc(SZ_128M); 505 + status |= !lmb_alloc(SZ_128M, &addr) ? 506 + env_set_hex("loadaddr", addr) : 1; 506 507 status |= env_set_hex("kernel_addr_r", addr); 507 - status |= env_set_hex("loadaddr", addr); 508 - status |= env_set_hex("ramdisk_addr_r", addr_alloc(SZ_128M)); 509 - status |= env_set_hex("kernel_comp_addr_r", addr_alloc(KERNEL_COMP_SIZE)); 510 - status |= env_set_hex("kernel_comp_size", KERNEL_COMP_SIZE); 508 + status |= !lmb_alloc(SZ_128M, &addr) ? 509 + env_set_hex("ramdisk_addr_r", addr) : 1; 510 + status |= !lmb_alloc(KERNEL_COMP_SIZE, &addr) ? 511 + env_set_hex("kernel_comp_addr_r", addr) : 1; 512 + status |= !lmb_alloc(KERNEL_COMP_SIZE, &addr) ? 513 + env_set_hex("kernel_comp_size", addr) : 1; 514 + status |= !lmb_alloc(SZ_4M, &addr) ? 515 + env_set_hex("scriptaddr", addr) : 1; 516 + status |= !lmb_alloc(SZ_4M, &addr) ? 517 + env_set_hex("pxefile_addr_r", addr) : 1; 518 + 511 519 if (IS_ENABLED(CONFIG_FASTBOOT)) 512 - status |= env_set_hex("fastboot_addr_r", addr_alloc(FASTBOOT_BUF_SIZE)); 513 - status |= env_set_hex("scriptaddr", addr_alloc(SZ_4M)); 514 - status |= env_set_hex("pxefile_addr_r", addr_alloc(SZ_4M)); 515 - addr = addr_alloc(SZ_2M); 516 - status |= env_set_hex("fdt_addr_r", addr); 520 + status |= !lmb_alloc(FASTBOOT_BUF_SIZE, &addr) ? 521 + env_set_hex("fastboot_addr_r", addr) : 1; 522 + 523 + status |= !lmb_alloc(SZ_2M, &addr) ? 524 + env_set_hex("fdt_addr_r", addr) : 1; 517 525 518 526 if (status) 519 527 log_warning("%s: Failed to set run time variables\n", __func__);
+8 -4
boot/bootm.c
··· 623 623 */ 624 624 if (os.type == IH_TYPE_KERNEL_NOLOAD && os.comp != IH_COMP_NONE) { 625 625 ulong req_size = ALIGN(image_len * 4, SZ_1M); 626 + phys_addr_t addr; 626 627 627 - load = lmb_alloc(req_size, SZ_2M); 628 - if (!load) 628 + err = lmb_alloc_mem(LMB_MEM_ALLOC_ANY, SZ_2M, &addr, 629 + req_size, LMB_NONE); 630 + if (err) 629 631 return 1; 630 - os.load = load; 631 - images->ep = load; 632 + 633 + load = (ulong)addr; 634 + os.load = (ulong)addr; 635 + images->ep = (ulong)addr; 632 636 debug("Allocated %lx bytes at %lx for kernel (size %lx) decompression\n", 633 637 req_size, load, image_len); 634 638 }
+26 -23
boot/image-board.c
··· 16 16 #include <fpga.h> 17 17 #include <image.h> 18 18 #include <init.h> 19 + #include <lmb.h> 19 20 #include <log.h> 20 21 #include <mapmem.h> 21 22 #include <rtc.h> ··· 566 567 *initrd_start = rd_data; 567 568 *initrd_end = rd_data + rd_len; 568 569 initrd_addr = (phys_addr_t)rd_data; 569 - err = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, 570 - &initrd_addr, rd_len, LMB_NONE); 570 + err = lmb_alloc_mem(LMB_MEM_ALLOC_ADDR, 0, &initrd_addr, 571 + rd_len, LMB_NONE); 571 572 if (err) { 572 573 puts("in-place initrd alloc failed\n"); 573 574 goto error; 574 575 } 575 576 } else { 576 - if (initrd_high) 577 - *initrd_start = 578 - (ulong)lmb_alloc_base(rd_len, 579 - 0x1000, 580 - initrd_high, 581 - LMB_NONE); 582 - else 583 - *initrd_start = (ulong)lmb_alloc(rd_len, 584 - 0x1000); 577 + enum lmb_mem_type type = initrd_high ? 578 + LMB_MEM_ALLOC_MAX : LMB_MEM_ALLOC_ANY; 585 579 586 - if (*initrd_start == 0) { 580 + err = lmb_alloc_mem(type, 0x1000, &initrd_high, rd_len, 581 + LMB_NONE); 582 + if (err) { 587 583 puts("ramdisk - allocation error\n"); 588 584 goto error; 589 585 } 586 + 587 + *initrd_start = (ulong)initrd_high; 590 588 bootstage_mark(BOOTSTAGE_ID_COPY_RAMDISK); 591 589 592 590 *initrd_end = *initrd_start + rd_len; ··· 837 835 */ 838 836 int boot_get_cmdline(ulong *cmd_start, ulong *cmd_end) 839 837 { 840 - int barg; 838 + int barg, err; 841 839 char *cmdline; 842 840 char *s; 841 + phys_addr_t addr; 843 842 844 843 /* 845 844 * Help the compiler detect that this function is only called when ··· 849 848 return 0; 850 849 851 850 barg = IF_ENABLED_INT(CONFIG_SYS_BOOT_GET_CMDLINE, CONFIG_SYS_BARGSIZE); 852 - cmdline = (char *)(ulong)lmb_alloc_base(barg, 0xf, 853 - env_get_bootm_mapsize() + env_get_bootm_low(), 854 - LMB_NONE); 855 - if (!cmdline) 851 + addr = env_get_bootm_mapsize() + env_get_bootm_low(); 852 + 853 + err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, 0xf, &addr, barg, LMB_NONE); 854 + if (err) 856 855 return -1; 856 + 857 + cmdline = (char *)(uintptr_t)addr; 857 858 858 859 s = env_get("bootargs"); 859 860 if (!s) ··· 883 884 */ 884 885 int boot_get_kbd(struct bd_info **kbd) 885 886 { 886 - *kbd = (struct bd_info *)(ulong)lmb_alloc_base(sizeof(struct bd_info), 887 - 0xf, 888 - env_get_bootm_mapsize() + 889 - env_get_bootm_low(), 890 - LMB_NONE); 891 - if (!*kbd) 887 + int err; 888 + phys_addr_t addr; 889 + 890 + addr = env_get_bootm_mapsize() + env_get_bootm_low(); 891 + err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, 0xf, &addr, 892 + sizeof(struct bd_info), LMB_NONE); 893 + if (err) 892 894 return -1; 893 895 896 + *kbd = (struct bd_info *)(uintptr_t)addr; 894 897 **kbd = *gd->bd; 895 898 896 899 debug("## kernel board info at 0x%08lx\n", (ulong)*kbd);
+20 -15
boot/image-fdt.c
··· 183 183 /* If fdt_high is set use it to select the relocation address */ 184 184 fdt_high = env_get("fdt_high"); 185 185 if (fdt_high) { 186 - ulong desired_addr = hextoul(fdt_high, NULL); 186 + ulong high_addr = hextoul(fdt_high, NULL); 187 187 188 - if (desired_addr == ~0UL) { 188 + if (high_addr == ~0UL) { 189 189 /* All ones means use fdt in place */ 190 190 of_start = fdt_blob; 191 191 addr = map_to_sysmem(fdt_blob); ··· 198 198 } 199 199 200 200 disable_relocation = 1; 201 - } else if (desired_addr) { 202 - addr = lmb_alloc_base(of_len, 0x1000, desired_addr, 203 - LMB_NONE); 204 - of_start = map_sysmem(addr, of_len); 205 - if (of_start == NULL) { 206 - puts("Failed using fdt_high value for Device Tree"); 201 + } else { 202 + enum lmb_mem_type type = high_addr ? 203 + LMB_MEM_ALLOC_MAX : LMB_MEM_ALLOC_ANY; 204 + 205 + addr = high_addr; 206 + err = lmb_alloc_mem(type, 0x1000, &addr, of_len, 207 + LMB_NONE); 208 + if (err) { 209 + puts("Failed to allocate memory for Device Tree relocation\n"); 207 210 goto error; 208 211 } 209 - } else { 210 - addr = lmb_alloc(of_len, 0x1000); 211 212 of_start = map_sysmem(addr, of_len); 212 213 } 213 214 } else { ··· 229 230 * for LMB allocation. 230 231 */ 231 232 usable = min(start + size, low + mapsize); 232 - addr = lmb_alloc_base(of_len, 0x1000, usable, LMB_NONE); 233 - of_start = map_sysmem(addr, of_len); 234 - /* Allocation succeeded, use this block. */ 235 - if (of_start != NULL) 236 - break; 233 + addr = usable; 234 + err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, 0x1000, 235 + &addr, of_len, LMB_NONE); 236 + if (!err) { 237 + of_start = map_sysmem(addr, of_len); 238 + /* Allocation succeeded, use this block. */ 239 + if (of_start) 240 + break; 241 + } 237 242 238 243 /* 239 244 * Reduce the mapping size in the next bank
+4 -18
include/lmb.h
··· 34 34 /** 35 35 * enum lmb_mem_type - type of memory allocation request 36 36 * @LMB_MEM_ALLOC_ADDR: request for a particular region of memory 37 + * @LMB_MEM_ALLOC_ANY: allocate any available memory region 38 + * @LMB_MEM_ALLOC_MAX: allocate memory below a particular address 37 39 */ 38 40 enum lmb_mem_type { 39 41 LMB_MEM_ALLOC_ADDR = 1, 42 + LMB_MEM_ALLOC_ANY, 43 + LMB_MEM_ALLOC_MAX, 40 44 }; 41 45 42 46 /** ··· 130 134 131 135 long lmb_add(phys_addr_t base, phys_size_t size); 132 136 133 - phys_addr_t lmb_alloc(phys_size_t size, ulong align); 134 137 phys_size_t lmb_get_free_size(phys_addr_t addr); 135 - 136 - /** 137 - * lmb_alloc_base() - Allocate specified memory region with specified 138 - * attributes 139 - * @size: Size of the region requested 140 - * @align: Alignment of the memory region requested 141 - * @max_addr: Maximum address of the requested region 142 - * @flags: Memory region attributes to be set 143 - * 144 - * Allocate a region of memory with the attributes specified through the 145 - * parameter. The max_addr parameter is used to specify the maximum address 146 - * below which the requested region should be allocated. 147 - * 148 - * Return: Base address on success, 0 on error. 149 - */ 150 - phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr, 151 - uint flags); 152 138 153 139 /** 154 140 * lmb_is_reserved_flags() - Test if address is in reserved region with flag
+8 -6
lib/efi_loader/efi_memory.c
··· 454 454 enum efi_memory_type memory_type, 455 455 efi_uintn_t pages, uint64_t *memory) 456 456 { 457 + int err; 457 458 u64 efi_addr, len; 458 459 uint flags; 459 460 efi_status_t ret; ··· 475 476 switch (type) { 476 477 case EFI_ALLOCATE_ANY_PAGES: 477 478 /* Any page */ 478 - addr = (u64)lmb_alloc_base(len, EFI_PAGE_SIZE, 479 - LMB_ALLOC_ANYWHERE, flags); 480 - if (!addr) 479 + err = lmb_alloc_mem(LMB_MEM_ALLOC_ANY, EFI_PAGE_SIZE, &addr, 480 + len, flags); 481 + if (err) 481 482 return EFI_OUT_OF_RESOURCES; 482 483 break; 483 484 case EFI_ALLOCATE_MAX_ADDRESS: 484 485 /* Max address */ 485 486 addr = map_to_sysmem((void *)(uintptr_t)*memory); 486 - addr = (u64)lmb_alloc_base(len, EFI_PAGE_SIZE, addr, 487 - flags); 488 - if (!addr) 487 + 488 + err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, EFI_PAGE_SIZE, &addr, 489 + len, flags); 490 + if (err) 489 491 return EFI_OUT_OF_RESOURCES; 490 492 break; 491 493 case EFI_ALLOCATE_ADDRESS:
+12 -16
lib/lmb.c
··· 672 672 return lmb_free_flags(base, size, LMB_NONE); 673 673 } 674 674 675 - static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align, 676 - phys_addr_t max_addr, u32 flags) 675 + static int _lmb_alloc_base(phys_size_t size, ulong align, 676 + phys_addr_t *addr, u32 flags) 677 677 { 678 678 int ret; 679 679 long i, rgn; 680 + phys_addr_t max_addr; 680 681 phys_addr_t base = 0; 681 682 phys_addr_t res_base; 682 683 struct lmb_region *lmb_used = lmb.used_mem.data; 683 684 struct lmb_region *lmb_memory = lmb.available_mem.data; 684 685 686 + max_addr = *addr; 685 687 for (i = lmb.available_mem.count - 1; i >= 0; i--) { 686 688 phys_addr_t lmbbase = lmb_memory[i].base; 687 689 phys_size_t lmbsize = lmb_memory[i].size; ··· 714 716 flags); 715 717 if (ret) 716 718 return ret; 717 - 718 - return base; 719 + *addr = base; 720 + return 0; 719 721 } 720 722 721 723 res_base = lmb_used[rgn].base; ··· 728 730 log_debug("%s: Failed to allocate 0x%lx bytes below 0x%lx\n", 729 731 __func__, (ulong)size, (ulong)max_addr); 730 732 731 - return 0; 732 - } 733 - 734 - phys_addr_t lmb_alloc(phys_size_t size, ulong align) 735 - { 736 - return _lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE, LMB_NONE); 737 - } 738 - 739 - phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr, 740 - uint flags) 741 - { 742 - return _lmb_alloc_base(size, align, max_addr, flags); 733 + return -1; 743 734 } 744 735 745 736 static int _lmb_alloc_addr(phys_addr_t base, phys_size_t size, u32 flags) ··· 776 767 return -EINVAL; 777 768 778 769 switch (type) { 770 + case LMB_MEM_ALLOC_ANY: 771 + *addr = LMB_ALLOC_ANYWHERE; 772 + case LMB_MEM_ALLOC_MAX: 773 + ret = _lmb_alloc_base(size, align, addr, flags); 774 + break; 779 775 case LMB_MEM_ALLOC_ADDR: 780 776 ret = _lmb_alloc_addr(*addr, size, flags); 781 777 break;
+26
test/lib/lmb.c
··· 82 82 return 0; 83 83 } 84 84 85 + static phys_addr_t lmb_alloc(phys_size_t size, ulong align) 86 + { 87 + int err; 88 + phys_addr_t addr; 89 + 90 + err = lmb_alloc_mem(LMB_MEM_ALLOC_ANY, align, &addr, size, LMB_NONE); 91 + if (err) 92 + return 0; 93 + 94 + return addr; 95 + } 96 + 97 + static phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, 98 + phys_addr_t max_addr, u32 flags) 99 + { 100 + int err; 101 + phys_addr_t addr; 102 + 103 + addr = max_addr; 104 + err = lmb_alloc_mem(LMB_MEM_ALLOC_MAX, align, &addr, size, flags); 105 + if (err) 106 + return 0; 107 + 108 + return addr; 109 + } 110 + 85 111 #define lmb_alloc_addr(addr, size, flags) lmb_reserve(addr, size, flags) 86 112 87 113 static int test_multi_alloc(struct unit_test_state *uts, const phys_addr_t ram,