Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Procedures for maintaining information about logical memory blocks. |
| 4 | * |
| 5 | * Peter Bergner, IBM Corp. June 2001. |
| 6 | * Copyright (C) 2001 Peter Bergner. |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 9 | #include <alist.h> |
Heinrich Schuchardt | 06d514d | 2023-01-04 01:36:14 +0100 | [diff] [blame] | 10 | #include <efi_loader.h> |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 11 | #include <event.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 12 | #include <image.h> |
Heinrich Schuchardt | 06d514d | 2023-01-04 01:36:14 +0100 | [diff] [blame] | 13 | #include <mapmem.h> |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 14 | #include <lmb.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 16 | #include <malloc.h> |
Sughosh Ganu | f4fb154 | 2024-08-26 17:29:24 +0530 | [diff] [blame] | 17 | #include <spl.h> |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 18 | |
Marek Vasut | 1274698 | 2021-09-10 22:47:09 +0200 | [diff] [blame] | 19 | #include <asm/global_data.h> |
Marek Vasut | bd994c0 | 2021-11-13 18:34:37 +0100 | [diff] [blame] | 20 | #include <asm/sections.h> |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Sughosh Ganu | 6534d26 | 2024-08-26 17:29:30 +0530 | [diff] [blame] | 22 | #include <linux/sizes.h> |
Marek Vasut | 1274698 | 2021-09-10 22:47:09 +0200 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 26 | #define MAP_OP_RESERVE (u8)0x1 |
| 27 | #define MAP_OP_FREE (u8)0x2 |
| 28 | #define MAP_OP_ADD (u8)0x3 |
| 29 | |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 30 | #define LMB_ALLOC_ANYWHERE 0 |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 31 | #define LMB_ALIST_INITIAL_SIZE 4 |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 32 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 33 | static struct lmb lmb; |
| 34 | |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 35 | static bool lmb_should_notify(enum lmb_flags flags) |
| 36 | { |
| 37 | return !lmb.test && !(flags & LMB_NONOTIFY) && |
| 38 | CONFIG_IS_ENABLED(EFI_LOADER); |
| 39 | } |
| 40 | |
| 41 | static int __maybe_unused lmb_map_update_notify(phys_addr_t addr, |
| 42 | phys_size_t size, |
Ilias Apalodimas | f6fb6a8 | 2024-10-23 18:22:01 +0300 | [diff] [blame^] | 43 | u8 op, enum lmb_flags flags) |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 44 | { |
| 45 | u64 efi_addr; |
| 46 | u64 pages; |
| 47 | efi_status_t status; |
| 48 | |
| 49 | if (op != MAP_OP_RESERVE && op != MAP_OP_FREE && op != MAP_OP_ADD) { |
| 50 | log_err("Invalid map update op received (%d)\n", op); |
| 51 | return -1; |
| 52 | } |
| 53 | |
Ilias Apalodimas | f6fb6a8 | 2024-10-23 18:22:01 +0300 | [diff] [blame^] | 54 | if (!lmb_should_notify(flags)) |
| 55 | return 0; |
| 56 | |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 57 | efi_addr = (uintptr_t)map_sysmem(addr, 0); |
| 58 | pages = efi_size_in_pages(size + (efi_addr & EFI_PAGE_MASK)); |
| 59 | efi_addr &= ~EFI_PAGE_MASK; |
| 60 | |
| 61 | status = efi_add_memory_map_pg(efi_addr, pages, |
| 62 | op == MAP_OP_RESERVE ? |
| 63 | EFI_BOOT_SERVICES_DATA : |
| 64 | EFI_CONVENTIONAL_MEMORY, |
| 65 | false); |
| 66 | if (status != EFI_SUCCESS) { |
| 67 | log_err("%s: LMB Map notify failure %lu\n", __func__, |
| 68 | status & ~EFI_ERROR_MASK); |
| 69 | return -1; |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 70 | } |
Ilias Apalodimas | f6fb6a8 | 2024-10-23 18:22:01 +0300 | [diff] [blame^] | 71 | |
| 72 | return 0; |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 73 | } |
| 74 | |
Sughosh Ganu | f8ffc6f | 2024-08-26 17:29:40 +0530 | [diff] [blame] | 75 | static void lmb_print_region_flags(enum lmb_flags flags) |
| 76 | { |
| 77 | u64 bitpos; |
Sughosh Ganu | 3c6896a | 2024-10-15 21:07:04 +0530 | [diff] [blame] | 78 | const char *flag_str[] = { "none", "no-map", "no-overwrite", "no-notify" }; |
Sughosh Ganu | f8ffc6f | 2024-08-26 17:29:40 +0530 | [diff] [blame] | 79 | |
| 80 | do { |
| 81 | bitpos = flags ? fls(flags) - 1 : 0; |
Sughosh Ganu | c3cf0dc | 2024-10-21 22:48:20 +0530 | [diff] [blame] | 82 | assert_noisy(bitpos < ARRAY_SIZE(flag_str)); |
Sughosh Ganu | f8ffc6f | 2024-08-26 17:29:40 +0530 | [diff] [blame] | 83 | printf("%s", flag_str[bitpos]); |
| 84 | flags &= ~(1ull << bitpos); |
| 85 | puts(flags ? ", " : "\n"); |
| 86 | } while (flags); |
| 87 | } |
| 88 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 89 | static void lmb_dump_region(struct alist *lmb_rgn_lst, char *name) |
Patrick Delaunay | 358c778 | 2021-05-07 14:50:31 +0200 | [diff] [blame] | 90 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 91 | struct lmb_region *rgn = lmb_rgn_lst->data; |
Patrick Delaunay | 358c778 | 2021-05-07 14:50:31 +0200 | [diff] [blame] | 92 | unsigned long long base, size, end; |
| 93 | enum lmb_flags flags; |
| 94 | int i; |
| 95 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 96 | printf(" %s.count = 0x%x\n", name, lmb_rgn_lst->count); |
Patrick Delaunay | 358c778 | 2021-05-07 14:50:31 +0200 | [diff] [blame] | 97 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 98 | for (i = 0; i < lmb_rgn_lst->count; i++) { |
| 99 | base = rgn[i].base; |
| 100 | size = rgn[i].size; |
Patrick Delaunay | 358c778 | 2021-05-07 14:50:31 +0200 | [diff] [blame] | 101 | end = base + size - 1; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 102 | flags = rgn[i].flags; |
Patrick Delaunay | 358c778 | 2021-05-07 14:50:31 +0200 | [diff] [blame] | 103 | |
Sughosh Ganu | f8ffc6f | 2024-08-26 17:29:40 +0530 | [diff] [blame] | 104 | printf(" %s[%d]\t[0x%llx-0x%llx], 0x%08llx bytes flags: ", |
| 105 | name, i, base, end, size); |
| 106 | lmb_print_region_flags(flags); |
Patrick Delaunay | 358c778 | 2021-05-07 14:50:31 +0200 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 110 | void lmb_dump_all_force(void) |
Tero Kristo | 9996cea | 2020-07-20 11:10:45 +0300 | [diff] [blame] | 111 | { |
Tero Kristo | 9996cea | 2020-07-20 11:10:45 +0300 | [diff] [blame] | 112 | printf("lmb_dump_all:\n"); |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 113 | lmb_dump_region(&lmb.free_mem, "memory"); |
| 114 | lmb_dump_region(&lmb.used_mem, "reserved"); |
Tero Kristo | 9996cea | 2020-07-20 11:10:45 +0300 | [diff] [blame] | 115 | } |
| 116 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 117 | void lmb_dump_all(void) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 118 | { |
| 119 | #ifdef DEBUG |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 120 | lmb_dump_all_force(); |
Tero Kristo | 9996cea | 2020-07-20 11:10:45 +0300 | [diff] [blame] | 121 | #endif |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 122 | } |
| 123 | |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 124 | static long lmb_addrs_overlap(phys_addr_t base1, phys_size_t size1, |
| 125 | phys_addr_t base2, phys_size_t size2) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 126 | { |
Simon Goldschmidt | d67f33c | 2019-01-14 22:38:15 +0100 | [diff] [blame] | 127 | const phys_addr_t base1_end = base1 + size1 - 1; |
| 128 | const phys_addr_t base2_end = base2 + size2 - 1; |
| 129 | |
| 130 | return ((base1 <= base2_end) && (base2 <= base1_end)); |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 131 | } |
| 132 | |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 133 | static long lmb_addrs_adjacent(phys_addr_t base1, phys_size_t size1, |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 134 | phys_addr_t base2, phys_size_t size2) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 135 | { |
| 136 | if (base2 == base1 + size1) |
| 137 | return 1; |
| 138 | else if (base1 == base2 + size2) |
| 139 | return -1; |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 144 | static long lmb_regions_overlap(struct alist *lmb_rgn_lst, unsigned long r1, |
Udit Kumar | edb5824 | 2023-09-26 16:54:42 +0530 | [diff] [blame] | 145 | unsigned long r2) |
| 146 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 147 | struct lmb_region *rgn = lmb_rgn_lst->data; |
| 148 | |
| 149 | phys_addr_t base1 = rgn[r1].base; |
| 150 | phys_size_t size1 = rgn[r1].size; |
| 151 | phys_addr_t base2 = rgn[r2].base; |
| 152 | phys_size_t size2 = rgn[r2].size; |
Udit Kumar | edb5824 | 2023-09-26 16:54:42 +0530 | [diff] [blame] | 153 | |
| 154 | return lmb_addrs_overlap(base1, size1, base2, size2); |
| 155 | } |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 156 | |
| 157 | static long lmb_regions_adjacent(struct alist *lmb_rgn_lst, unsigned long r1, |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 158 | unsigned long r2) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 159 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 160 | struct lmb_region *rgn = lmb_rgn_lst->data; |
| 161 | |
| 162 | phys_addr_t base1 = rgn[r1].base; |
| 163 | phys_size_t size1 = rgn[r1].size; |
| 164 | phys_addr_t base2 = rgn[r2].base; |
| 165 | phys_size_t size2 = rgn[r2].size; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 166 | return lmb_addrs_adjacent(base1, size1, base2, size2); |
| 167 | } |
| 168 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 169 | static void lmb_remove_region(struct alist *lmb_rgn_lst, unsigned long r) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 170 | { |
| 171 | unsigned long i; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 172 | struct lmb_region *rgn = lmb_rgn_lst->data; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 173 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 174 | for (i = r; i < lmb_rgn_lst->count - 1; i++) { |
| 175 | rgn[i].base = rgn[i + 1].base; |
| 176 | rgn[i].size = rgn[i + 1].size; |
| 177 | rgn[i].flags = rgn[i + 1].flags; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 178 | } |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 179 | lmb_rgn_lst->count--; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* Assumption: base addr of region 1 < base addr of region 2 */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 183 | static void lmb_coalesce_regions(struct alist *lmb_rgn_lst, unsigned long r1, |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 184 | unsigned long r2) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 185 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 186 | struct lmb_region *rgn = lmb_rgn_lst->data; |
| 187 | |
| 188 | rgn[r1].size += rgn[r2].size; |
| 189 | lmb_remove_region(lmb_rgn_lst, r2); |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 190 | } |
| 191 | |
Udit Kumar | edb5824 | 2023-09-26 16:54:42 +0530 | [diff] [blame] | 192 | /*Assumption : base addr of region 1 < base addr of region 2*/ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 193 | static void lmb_fix_over_lap_regions(struct alist *lmb_rgn_lst, |
| 194 | unsigned long r1, unsigned long r2) |
Udit Kumar | edb5824 | 2023-09-26 16:54:42 +0530 | [diff] [blame] | 195 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 196 | struct lmb_region *rgn = lmb_rgn_lst->data; |
| 197 | |
| 198 | phys_addr_t base1 = rgn[r1].base; |
| 199 | phys_size_t size1 = rgn[r1].size; |
| 200 | phys_addr_t base2 = rgn[r2].base; |
| 201 | phys_size_t size2 = rgn[r2].size; |
Udit Kumar | edb5824 | 2023-09-26 16:54:42 +0530 | [diff] [blame] | 202 | |
| 203 | if (base1 + size1 > base2 + size2) { |
| 204 | printf("This will not be a case any time\n"); |
| 205 | return; |
| 206 | } |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 207 | rgn[r1].size = base2 + size2 - base1; |
| 208 | lmb_remove_region(lmb_rgn_lst, r2); |
Udit Kumar | edb5824 | 2023-09-26 16:54:42 +0530 | [diff] [blame] | 209 | } |
| 210 | |
Sughosh Ganu | 6534d26 | 2024-08-26 17:29:30 +0530 | [diff] [blame] | 211 | static void lmb_reserve_uboot_region(void) |
| 212 | { |
| 213 | int bank; |
| 214 | ulong end, bank_end; |
| 215 | phys_addr_t rsv_start; |
| 216 | |
| 217 | rsv_start = gd->start_addr_sp - CONFIG_STACK_SIZE; |
| 218 | end = gd->ram_top; |
| 219 | |
| 220 | /* |
| 221 | * Reserve memory from aligned address below the bottom of U-Boot stack |
| 222 | * until end of RAM area to prevent LMB from overwriting that memory. |
| 223 | */ |
| 224 | debug("## Current stack ends at 0x%08lx ", (ulong)rsv_start); |
| 225 | |
| 226 | /* adjust sp by 16K to be safe */ |
| 227 | rsv_start -= SZ_16K; |
| 228 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
| 229 | if (!gd->bd->bi_dram[bank].size || |
| 230 | rsv_start < gd->bd->bi_dram[bank].start) |
| 231 | continue; |
| 232 | /* Watch out for RAM at end of address space! */ |
| 233 | bank_end = gd->bd->bi_dram[bank].start + |
| 234 | gd->bd->bi_dram[bank].size - 1; |
| 235 | if (rsv_start > bank_end) |
| 236 | continue; |
| 237 | if (bank_end > end) |
| 238 | bank_end = end - 1; |
| 239 | |
| 240 | lmb_reserve_flags(rsv_start, bank_end - rsv_start + 1, |
| 241 | LMB_NOOVERWRITE); |
| 242 | |
| 243 | if (gd->flags & GD_FLG_SKIP_RELOC) |
| 244 | lmb_reserve_flags((phys_addr_t)(uintptr_t)_start, |
| 245 | gd->mon_len, LMB_NOOVERWRITE); |
| 246 | |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 251 | static void lmb_reserve_common(void *fdt_blob) |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 252 | { |
Sughosh Ganu | 6534d26 | 2024-08-26 17:29:30 +0530 | [diff] [blame] | 253 | lmb_reserve_uboot_region(); |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 254 | |
Simon Glass | 0c303f9 | 2021-09-25 19:43:21 -0600 | [diff] [blame] | 255 | if (CONFIG_IS_ENABLED(OF_LIBFDT) && fdt_blob) |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 256 | boot_fdt_add_mem_rsv_regions(fdt_blob); |
Simon Goldschmidt | aa3c609 | 2019-01-14 22:38:19 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Sughosh Ganu | f4fb154 | 2024-08-26 17:29:24 +0530 | [diff] [blame] | 259 | static __maybe_unused void lmb_reserve_common_spl(void) |
| 260 | { |
| 261 | phys_addr_t rsv_start; |
| 262 | phys_size_t rsv_size; |
| 263 | |
| 264 | /* |
| 265 | * Assume a SPL stack of 16KB. This must be |
| 266 | * more than enough for the SPL stage. |
| 267 | */ |
| 268 | if (IS_ENABLED(CONFIG_SPL_STACK_R_ADDR)) { |
| 269 | rsv_start = gd->start_addr_sp - 16384; |
| 270 | rsv_size = 16384; |
| 271 | lmb_reserve_flags(rsv_start, rsv_size, LMB_NOOVERWRITE); |
| 272 | } |
| 273 | |
| 274 | if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS)) { |
| 275 | /* Reserve the bss region */ |
| 276 | rsv_start = (phys_addr_t)(uintptr_t)__bss_start; |
| 277 | rsv_size = (phys_addr_t)(uintptr_t)__bss_end - |
| 278 | (phys_addr_t)(uintptr_t)__bss_start; |
| 279 | lmb_reserve_flags(rsv_start, rsv_size, LMB_NOOVERWRITE); |
| 280 | } |
| 281 | } |
| 282 | |
Sughosh Ganu | 8a9fc30 | 2024-08-26 17:29:23 +0530 | [diff] [blame] | 283 | /** |
| 284 | * lmb_add_memory() - Add memory range for LMB allocations |
| 285 | * |
| 286 | * Add the entire available memory range to the pool of memory that |
| 287 | * can be used by the LMB module for allocations. |
| 288 | * |
| 289 | * Return: None |
| 290 | */ |
| 291 | void lmb_add_memory(void) |
| 292 | { |
| 293 | int i; |
| 294 | phys_size_t size; |
Sughosh Ganu | 8a9fc30 | 2024-08-26 17:29:23 +0530 | [diff] [blame] | 295 | u64 ram_top = gd->ram_top; |
| 296 | struct bd_info *bd = gd->bd; |
| 297 | |
Sughosh Ganu | 497da0c | 2024-10-15 21:07:11 +0530 | [diff] [blame] | 298 | if (CONFIG_IS_ENABLED(LMB_ARCH_MEM_MAP)) |
| 299 | return lmb_arch_add_memory(); |
| 300 | |
Sughosh Ganu | 8a9fc30 | 2024-08-26 17:29:23 +0530 | [diff] [blame] | 301 | /* Assume a 4GB ram_top if not defined */ |
| 302 | if (!ram_top) |
| 303 | ram_top = 0x100000000ULL; |
| 304 | |
| 305 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 306 | size = bd->bi_dram[i].size; |
| 307 | if (size) { |
Sughosh Ganu | 8a9fc30 | 2024-08-26 17:29:23 +0530 | [diff] [blame] | 308 | lmb_add(bd->bi_dram[i].start, size); |
Sughosh Ganu | eb052cb | 2024-10-15 21:07:05 +0530 | [diff] [blame] | 309 | |
| 310 | /* |
| 311 | * Reserve memory above ram_top as |
| 312 | * no-overwrite so that it cannot be |
| 313 | * allocated |
| 314 | */ |
| 315 | if (bd->bi_dram[i].start >= ram_top) |
| 316 | lmb_reserve_flags(bd->bi_dram[i].start, size, |
| 317 | LMB_NOOVERWRITE); |
Sughosh Ganu | 8a9fc30 | 2024-08-26 17:29:23 +0530 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 322 | static long lmb_resize_regions(struct alist *lmb_rgn_lst, |
| 323 | unsigned long idx_start, |
| 324 | phys_addr_t base, phys_size_t size) |
| 325 | { |
| 326 | phys_size_t rgnsize; |
| 327 | unsigned long rgn_cnt, idx, idx_end; |
| 328 | phys_addr_t rgnbase, rgnend; |
| 329 | phys_addr_t mergebase, mergeend; |
| 330 | struct lmb_region *rgn = lmb_rgn_lst->data; |
| 331 | |
| 332 | rgn_cnt = 0; |
| 333 | idx = idx_start; |
| 334 | idx_end = idx_start; |
| 335 | |
| 336 | /* |
| 337 | * First thing to do is to identify how many regions |
| 338 | * the requested region overlaps. |
| 339 | * If the flags match, combine all these overlapping |
| 340 | * regions into a single region, and remove the merged |
| 341 | * regions. |
| 342 | */ |
| 343 | while (idx <= lmb_rgn_lst->count - 1) { |
| 344 | rgnbase = rgn[idx].base; |
| 345 | rgnsize = rgn[idx].size; |
| 346 | |
| 347 | if (lmb_addrs_overlap(base, size, rgnbase, |
| 348 | rgnsize)) { |
| 349 | if (rgn[idx].flags != LMB_NONE) |
| 350 | return -1; |
| 351 | rgn_cnt++; |
| 352 | idx_end = idx; |
| 353 | } |
| 354 | idx++; |
| 355 | } |
| 356 | |
| 357 | /* The merged region's base and size */ |
| 358 | rgnbase = rgn[idx_start].base; |
| 359 | mergebase = min(base, rgnbase); |
| 360 | rgnend = rgn[idx_end].base + rgn[idx_end].size; |
| 361 | mergeend = max(rgnend, (base + size)); |
| 362 | |
| 363 | rgn[idx_start].base = mergebase; |
| 364 | rgn[idx_start].size = mergeend - mergebase; |
| 365 | |
| 366 | /* Now remove the merged regions */ |
| 367 | while (--rgn_cnt) |
| 368 | lmb_remove_region(lmb_rgn_lst, idx_start + 1); |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 373 | /** |
| 374 | * lmb_add_region_flags() - Add an lmb region to the given list |
| 375 | * @lmb_rgn_lst: LMB list to which region is to be added(free/used) |
| 376 | * @base: Start address of the region |
| 377 | * @size: Size of the region to be added |
| 378 | * @flags: Attributes of the LMB region |
| 379 | * |
| 380 | * Add a region of memory to the list. If the region does not exist, add |
| 381 | * it to the list. Depending on the attributes of the region to be added, |
| 382 | * the function might resize an already existing region or coalesce two |
| 383 | * adjacent regions. |
| 384 | * |
| 385 | * |
| 386 | * Returns: 0 if the region addition successful, -1 on failure |
| 387 | */ |
| 388 | static long lmb_add_region_flags(struct alist *lmb_rgn_lst, phys_addr_t base, |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 389 | phys_size_t size, enum lmb_flags flags) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 390 | { |
| 391 | unsigned long coalesced = 0; |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 392 | long ret, i; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 393 | struct lmb_region *rgn = lmb_rgn_lst->data; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 394 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 395 | if (alist_err(lmb_rgn_lst)) |
| 396 | return -1; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 397 | |
| 398 | /* First try and coalesce this LMB with another. */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 399 | for (i = 0; i < lmb_rgn_lst->count; i++) { |
| 400 | phys_addr_t rgnbase = rgn[i].base; |
| 401 | phys_size_t rgnsize = rgn[i].size; |
| 402 | phys_size_t rgnflags = rgn[i].flags; |
Sjoerd Simons | 0d91c88 | 2023-02-12 16:07:05 +0100 | [diff] [blame] | 403 | phys_addr_t end = base + size - 1; |
| 404 | phys_addr_t rgnend = rgnbase + rgnsize - 1; |
Sjoerd Simons | 0d91c88 | 2023-02-12 16:07:05 +0100 | [diff] [blame] | 405 | if (rgnbase <= base && end <= rgnend) { |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 406 | if (flags == rgnflags) |
| 407 | /* Already have this region, so we're done */ |
| 408 | return 0; |
| 409 | else |
| 410 | return -1; /* regions with new flags */ |
| 411 | } |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 412 | |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 413 | ret = lmb_addrs_adjacent(base, size, rgnbase, rgnsize); |
| 414 | if (ret > 0) { |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 415 | if (flags != rgnflags) |
| 416 | break; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 417 | rgn[i].base -= size; |
| 418 | rgn[i].size += size; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 419 | coalesced++; |
| 420 | break; |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 421 | } else if (ret < 0) { |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 422 | if (flags != rgnflags) |
| 423 | break; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 424 | rgn[i].size += size; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 425 | coalesced++; |
| 426 | break; |
Simon Goldschmidt | 0f7c51a | 2019-01-14 22:38:16 +0100 | [diff] [blame] | 427 | } else if (lmb_addrs_overlap(base, size, rgnbase, rgnsize)) { |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 428 | if (flags == LMB_NONE) { |
| 429 | ret = lmb_resize_regions(lmb_rgn_lst, i, base, |
| 430 | size); |
| 431 | if (ret < 0) |
| 432 | return -1; |
| 433 | |
| 434 | coalesced++; |
| 435 | break; |
| 436 | } else { |
| 437 | return -1; |
| 438 | } |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 442 | if (lmb_rgn_lst->count && i < lmb_rgn_lst->count - 1) { |
| 443 | rgn = lmb_rgn_lst->data; |
| 444 | if (rgn[i].flags == rgn[i + 1].flags) { |
| 445 | if (lmb_regions_adjacent(lmb_rgn_lst, i, i + 1)) { |
| 446 | lmb_coalesce_regions(lmb_rgn_lst, i, i + 1); |
| 447 | coalesced++; |
| 448 | } else if (lmb_regions_overlap(lmb_rgn_lst, i, i + 1)) { |
| 449 | /* fix overlapping area */ |
| 450 | lmb_fix_over_lap_regions(lmb_rgn_lst, i, i + 1); |
| 451 | coalesced++; |
| 452 | } |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 453 | } |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | if (coalesced) |
Ilias Apalodimas | 0f57b00 | 2024-10-23 18:22:00 +0300 | [diff] [blame] | 457 | return 0; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 458 | |
| 459 | if (alist_full(lmb_rgn_lst) && |
| 460 | !alist_expand_by(lmb_rgn_lst, lmb_rgn_lst->alloc)) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 461 | return -1; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 462 | rgn = lmb_rgn_lst->data; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 463 | |
| 464 | /* Couldn't coalesce the LMB, so add it to the sorted table. */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 465 | for (i = lmb_rgn_lst->count; i >= 0; i--) { |
| 466 | if (i && base < rgn[i - 1].base) { |
| 467 | rgn[i] = rgn[i - 1]; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 468 | } else { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 469 | rgn[i].base = base; |
| 470 | rgn[i].size = size; |
| 471 | rgn[i].flags = flags; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 472 | break; |
| 473 | } |
| 474 | } |
| 475 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 476 | lmb_rgn_lst->count++; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 481 | static long lmb_add_region(struct alist *lmb_rgn_lst, phys_addr_t base, |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 482 | phys_size_t size) |
| 483 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 484 | return lmb_add_region_flags(lmb_rgn_lst, base, size, LMB_NONE); |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 485 | } |
| 486 | |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 487 | /* This routine may be called with relocation disabled. */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 488 | long lmb_add(phys_addr_t base, phys_size_t size) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 489 | { |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 490 | long ret; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 491 | struct alist *lmb_rgn_lst = &lmb.free_mem; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 492 | |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 493 | ret = lmb_add_region(lmb_rgn_lst, base, size); |
Ilias Apalodimas | 0f57b00 | 2024-10-23 18:22:00 +0300 | [diff] [blame] | 494 | if (ret) |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 495 | return ret; |
| 496 | |
Ilias Apalodimas | f6fb6a8 | 2024-10-23 18:22:01 +0300 | [diff] [blame^] | 497 | return lmb_map_update_notify(base, size, MAP_OP_ADD, LMB_NONE); |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 498 | } |
| 499 | |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 500 | static long _lmb_free(phys_addr_t base, phys_size_t size) |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 501 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 502 | struct lmb_region *rgn; |
| 503 | struct alist *lmb_rgn_lst = &lmb.used_mem; |
Andy Fleming | 98874ff | 2008-07-07 14:24:39 -0500 | [diff] [blame] | 504 | phys_addr_t rgnbegin, rgnend; |
Simon Goldschmidt | d67f33c | 2019-01-14 22:38:15 +0100 | [diff] [blame] | 505 | phys_addr_t end = base + size - 1; |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 506 | int i; |
| 507 | |
| 508 | rgnbegin = rgnend = 0; /* supress gcc warnings */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 509 | rgn = lmb_rgn_lst->data; |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 510 | /* Find the region where (base, size) belongs to */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 511 | for (i = 0; i < lmb_rgn_lst->count; i++) { |
| 512 | rgnbegin = rgn[i].base; |
| 513 | rgnend = rgnbegin + rgn[i].size - 1; |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 514 | |
| 515 | if ((rgnbegin <= base) && (end <= rgnend)) |
| 516 | break; |
| 517 | } |
| 518 | |
| 519 | /* Didn't find the region */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 520 | if (i == lmb_rgn_lst->count) |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 521 | return -1; |
| 522 | |
| 523 | /* Check to see if we are removing entire region */ |
| 524 | if ((rgnbegin == base) && (rgnend == end)) { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 525 | lmb_remove_region(lmb_rgn_lst, i); |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | /* Check to see if region is matching at the front */ |
| 530 | if (rgnbegin == base) { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 531 | rgn[i].base = end + 1; |
| 532 | rgn[i].size -= size; |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | /* Check to see if the region is matching at the end */ |
| 537 | if (rgnend == end) { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 538 | rgn[i].size -= size; |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | /* |
| 543 | * We need to split the entry - adjust the current one to the |
| 544 | * beginging of the hole and add the region after hole. |
| 545 | */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 546 | rgn[i].size = base - rgn[i].base; |
| 547 | return lmb_add_region_flags(lmb_rgn_lst, end + 1, rgnend - end, |
| 548 | rgn[i].flags); |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 549 | } |
| 550 | |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 551 | /** |
| 552 | * lmb_free_flags() - Free up a region of memory |
| 553 | * @base: Base Address of region to be freed |
| 554 | * @size: Size of the region to be freed |
| 555 | * @flags: Memory region attributes |
| 556 | * |
| 557 | * Free up a region of memory. |
| 558 | * |
| 559 | * Return: 0 if successful, -1 on failure |
| 560 | */ |
| 561 | long lmb_free_flags(phys_addr_t base, phys_size_t size, |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 562 | uint flags) |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 563 | { |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 564 | long ret; |
| 565 | |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 566 | ret = _lmb_free(base, size); |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 567 | if (ret < 0) |
| 568 | return ret; |
| 569 | |
Ilias Apalodimas | f6fb6a8 | 2024-10-23 18:22:01 +0300 | [diff] [blame^] | 570 | return lmb_map_update_notify(base, size, MAP_OP_FREE, flags); |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | long lmb_free(phys_addr_t base, phys_size_t size) |
| 574 | { |
| 575 | return lmb_free_flags(base, size, LMB_NONE); |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 576 | } |
| 577 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 578 | long lmb_reserve_flags(phys_addr_t base, phys_size_t size, enum lmb_flags flags) |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 579 | { |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 580 | long ret = 0; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 581 | struct alist *lmb_rgn_lst = &lmb.used_mem; |
Patrick Delaunay | 59c0ea5 | 2021-05-07 14:50:29 +0200 | [diff] [blame] | 582 | |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 583 | ret = lmb_add_region_flags(lmb_rgn_lst, base, size, flags); |
Ilias Apalodimas | 0f57b00 | 2024-10-23 18:22:00 +0300 | [diff] [blame] | 584 | if (ret) |
| 585 | return ret; |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 586 | |
Ilias Apalodimas | f6fb6a8 | 2024-10-23 18:22:01 +0300 | [diff] [blame^] | 587 | return lmb_map_update_notify(base, size, MAP_OP_RESERVE, flags); |
Andy Fleming | 63796c4 | 2008-06-16 13:58:54 -0500 | [diff] [blame] | 588 | } |
| 589 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 590 | long lmb_reserve(phys_addr_t base, phys_size_t size) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 591 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 592 | return lmb_reserve_flags(base, size, LMB_NONE); |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 593 | } |
| 594 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 595 | static long lmb_overlaps_region(struct alist *lmb_rgn_lst, phys_addr_t base, |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 596 | phys_size_t size) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 597 | { |
| 598 | unsigned long i; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 599 | struct lmb_region *rgn = lmb_rgn_lst->data; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 600 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 601 | for (i = 0; i < lmb_rgn_lst->count; i++) { |
| 602 | phys_addr_t rgnbase = rgn[i].base; |
| 603 | phys_size_t rgnsize = rgn[i].size; |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 604 | if (lmb_addrs_overlap(base, size, rgnbase, rgnsize)) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 605 | break; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 606 | } |
| 607 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 608 | return (i < lmb_rgn_lst->count) ? i : -1; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 609 | } |
| 610 | |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 611 | static phys_addr_t lmb_align_down(phys_addr_t addr, phys_size_t size) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 612 | { |
| 613 | return addr & ~(size - 1); |
| 614 | } |
| 615 | |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 616 | static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align, |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 617 | phys_addr_t max_addr, enum lmb_flags flags) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 618 | { |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 619 | int ret; |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 620 | long i, rgn; |
Becky Bruce | 391fd93 | 2008-06-09 20:37:18 -0500 | [diff] [blame] | 621 | phys_addr_t base = 0; |
Andy Fleming | 7570a99 | 2008-06-16 13:58:55 -0500 | [diff] [blame] | 622 | phys_addr_t res_base; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 623 | struct lmb_region *lmb_used = lmb.used_mem.data; |
| 624 | struct lmb_region *lmb_memory = lmb.free_mem.data; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 625 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 626 | for (i = lmb.free_mem.count - 1; i >= 0; i--) { |
| 627 | phys_addr_t lmbbase = lmb_memory[i].base; |
| 628 | phys_size_t lmbsize = lmb_memory[i].size; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 629 | |
Andy Fleming | 7570a99 | 2008-06-16 13:58:55 -0500 | [diff] [blame] | 630 | if (lmbsize < size) |
| 631 | continue; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 632 | if (max_addr == LMB_ALLOC_ANYWHERE) |
| 633 | base = lmb_align_down(lmbbase + lmbsize - size, align); |
| 634 | else if (lmbbase < max_addr) { |
Stephen Warren | ad3fda5 | 2014-07-31 13:40:07 -0600 | [diff] [blame] | 635 | base = lmbbase + lmbsize; |
| 636 | if (base < lmbbase) |
| 637 | base = -1; |
| 638 | base = min(base, max_addr); |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 639 | base = lmb_align_down(base - size, align); |
| 640 | } else |
| 641 | continue; |
| 642 | |
Andy Fleming | 7570a99 | 2008-06-16 13:58:55 -0500 | [diff] [blame] | 643 | while (base && lmbbase <= base) { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 644 | rgn = lmb_overlaps_region(&lmb.used_mem, base, size); |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 645 | if (rgn < 0) { |
Andy Fleming | 7570a99 | 2008-06-16 13:58:55 -0500 | [diff] [blame] | 646 | /* This area isn't reserved, take it */ |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 647 | if (lmb_add_region_flags(&lmb.used_mem, base, |
Ilias Apalodimas | 0f57b00 | 2024-10-23 18:22:00 +0300 | [diff] [blame] | 648 | size, flags)) |
Andy Fleming | 7570a99 | 2008-06-16 13:58:55 -0500 | [diff] [blame] | 649 | return 0; |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 650 | |
Ilias Apalodimas | f6fb6a8 | 2024-10-23 18:22:01 +0300 | [diff] [blame^] | 651 | ret = lmb_map_update_notify(base, size, |
| 652 | MAP_OP_RESERVE, |
| 653 | flags); |
| 654 | if (ret) |
| 655 | return ret; |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 656 | |
Andy Fleming | 7570a99 | 2008-06-16 13:58:55 -0500 | [diff] [blame] | 657 | return base; |
| 658 | } |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 659 | |
| 660 | res_base = lmb_used[rgn].base; |
Andy Fleming | 7570a99 | 2008-06-16 13:58:55 -0500 | [diff] [blame] | 661 | if (res_base < size) |
| 662 | break; |
| 663 | base = lmb_align_down(res_base - size, align); |
| 664 | } |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 665 | } |
Andy Fleming | 7570a99 | 2008-06-16 13:58:55 -0500 | [diff] [blame] | 666 | return 0; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 667 | } |
| 668 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 669 | phys_addr_t lmb_alloc(phys_size_t size, ulong align) |
Sughosh Ganu | 3d679ae | 2024-08-26 17:29:16 +0530 | [diff] [blame] | 670 | { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 671 | return lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE); |
Sughosh Ganu | 3d679ae | 2024-08-26 17:29:16 +0530 | [diff] [blame] | 672 | } |
| 673 | |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 674 | /** |
| 675 | * lmb_alloc_flags() - Allocate memory region with specified attributes |
| 676 | * @size: Size of the region requested |
| 677 | * @align: Alignment of the memory region requested |
| 678 | * @flags: Memory region attributes to be set |
| 679 | * |
| 680 | * Allocate a region of memory with the attributes specified through the |
| 681 | * parameter. |
| 682 | * |
| 683 | * Return: base address on success, 0 on error |
| 684 | */ |
| 685 | phys_addr_t lmb_alloc_flags(phys_size_t size, ulong align, uint flags) |
| 686 | { |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 687 | return _lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE, |
| 688 | flags); |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 689 | } |
| 690 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 691 | phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr) |
Sughosh Ganu | 3d679ae | 2024-08-26 17:29:16 +0530 | [diff] [blame] | 692 | { |
| 693 | phys_addr_t alloc; |
| 694 | |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 695 | alloc = _lmb_alloc_base(size, align, max_addr, LMB_NONE); |
Sughosh Ganu | 3d679ae | 2024-08-26 17:29:16 +0530 | [diff] [blame] | 696 | |
| 697 | if (alloc == 0) |
| 698 | printf("ERROR: Failed to allocate 0x%lx bytes below 0x%lx.\n", |
| 699 | (ulong)size, (ulong)max_addr); |
| 700 | |
| 701 | return alloc; |
| 702 | } |
| 703 | |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 704 | /** |
| 705 | * lmb_alloc_base_flags() - Allocate specified memory region with specified attributes |
| 706 | * @size: Size of the region requested |
| 707 | * @align: Alignment of the memory region requested |
| 708 | * @max_addr: Maximum address of the requested region |
| 709 | * @flags: Memory region attributes to be set |
| 710 | * |
| 711 | * Allocate a region of memory with the attributes specified through the |
| 712 | * parameter. The max_addr parameter is used to specify the maximum address |
| 713 | * below which the requested region should be allocated. |
| 714 | * |
| 715 | * Return: base address on success, 0 on error |
| 716 | */ |
| 717 | phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align, |
| 718 | phys_addr_t max_addr, uint flags) |
| 719 | { |
| 720 | phys_addr_t alloc; |
| 721 | |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 722 | alloc = _lmb_alloc_base(size, align, max_addr, flags); |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 723 | |
| 724 | if (alloc == 0) |
| 725 | printf("ERROR: Failed to allocate 0x%lx bytes below 0x%lx.\n", |
| 726 | (ulong)size, (ulong)max_addr); |
| 727 | |
| 728 | return alloc; |
| 729 | } |
| 730 | |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 731 | static phys_addr_t _lmb_alloc_addr(phys_addr_t base, phys_size_t size, |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 732 | enum lmb_flags flags) |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 733 | { |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 734 | long rgn; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 735 | struct lmb_region *lmb_memory = lmb.free_mem.data; |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 736 | |
| 737 | /* Check if the requested address is in one of the memory regions */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 738 | rgn = lmb_overlaps_region(&lmb.free_mem, base, size); |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 739 | if (rgn >= 0) { |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 740 | /* |
| 741 | * Check if the requested end address is in the same memory |
| 742 | * region we found. |
| 743 | */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 744 | if (lmb_addrs_overlap(lmb_memory[rgn].base, |
| 745 | lmb_memory[rgn].size, |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 746 | base + size - 1, 1)) { |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 747 | /* ok, reserve the memory */ |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 748 | if (lmb_reserve_flags(base, size, flags) >= 0) |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 749 | return base; |
| 750 | } |
| 751 | } |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 752 | |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 753 | return 0; |
| 754 | } |
| 755 | |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 756 | /* |
| 757 | * Try to allocate a specific address range: must be in defined memory but not |
| 758 | * reserved |
| 759 | */ |
| 760 | phys_addr_t lmb_alloc_addr(phys_addr_t base, phys_size_t size) |
| 761 | { |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 762 | return _lmb_alloc_addr(base, size, LMB_NONE); |
Sughosh Ganu | 5e9553c | 2024-08-26 17:29:19 +0530 | [diff] [blame] | 763 | } |
| 764 | |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 765 | /** |
| 766 | * lmb_alloc_addr_flags() - Allocate specified memory address with specified attributes |
| 767 | * @base: Base Address requested |
| 768 | * @size: Size of the region requested |
| 769 | * @flags: Memory region attributes to be set |
| 770 | * |
| 771 | * Allocate a region of memory with the attributes specified through the |
| 772 | * parameter. The base parameter is used to specify the base address |
| 773 | * of the requested region. |
| 774 | * |
| 775 | * Return: base address on success, 0 on error |
| 776 | */ |
| 777 | phys_addr_t lmb_alloc_addr_flags(phys_addr_t base, phys_size_t size, |
| 778 | uint flags) |
| 779 | { |
Sughosh Ganu | 8d0df5f | 2024-10-15 21:07:17 +0530 | [diff] [blame] | 780 | return _lmb_alloc_addr(base, size, flags); |
Sughosh Ganu | c8a8f01 | 2024-10-15 21:07:03 +0530 | [diff] [blame] | 781 | } |
| 782 | |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 783 | /* Return number of bytes from a given address that are free */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 784 | phys_size_t lmb_get_free_size(phys_addr_t addr) |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 785 | { |
| 786 | int i; |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 787 | long rgn; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 788 | struct lmb_region *lmb_used = lmb.used_mem.data; |
| 789 | struct lmb_region *lmb_memory = lmb.free_mem.data; |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 790 | |
| 791 | /* check if the requested address is in the memory regions */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 792 | rgn = lmb_overlaps_region(&lmb.free_mem, addr, 1); |
Simon Goldschmidt | e35d2a7 | 2019-01-21 20:29:56 +0100 | [diff] [blame] | 793 | if (rgn >= 0) { |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 794 | for (i = 0; i < lmb.used_mem.count; i++) { |
| 795 | if (addr < lmb_used[i].base) { |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 796 | /* first reserved range > requested address */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 797 | return lmb_used[i].base - addr; |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 798 | } |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 799 | if (lmb_used[i].base + |
| 800 | lmb_used[i].size > addr) { |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 801 | /* requested addr is in this reserved range */ |
| 802 | return 0; |
| 803 | } |
| 804 | } |
| 805 | /* if we come here: no reserved ranges above requested addr */ |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 806 | return lmb_memory[lmb.free_mem.count - 1].base + |
| 807 | lmb_memory[lmb.free_mem.count - 1].size - addr; |
Simon Goldschmidt | 4cc8af8 | 2019-01-14 22:38:18 +0100 | [diff] [blame] | 808 | } |
| 809 | return 0; |
| 810 | } |
| 811 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 812 | int lmb_is_reserved_flags(phys_addr_t addr, int flags) |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 813 | { |
| 814 | int i; |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 815 | struct lmb_region *lmb_used = lmb.used_mem.data; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 816 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 817 | for (i = 0; i < lmb.used_mem.count; i++) { |
| 818 | phys_addr_t upper = lmb_used[i].base + |
| 819 | lmb_used[i].size - 1; |
| 820 | if (addr >= lmb_used[i].base && addr <= upper) |
| 821 | return (lmb_used[i].flags & flags) == flags; |
Kumar Gala | 4ed6552 | 2008-02-27 21:51:47 -0600 | [diff] [blame] | 822 | } |
| 823 | return 0; |
| 824 | } |
Mike Frysinger | a16028d | 2009-11-03 11:35:59 -0500 | [diff] [blame] | 825 | |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 826 | static int lmb_setup(bool test) |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 827 | { |
| 828 | bool ret; |
| 829 | |
| 830 | ret = alist_init(&lmb.free_mem, sizeof(struct lmb_region), |
| 831 | (uint)LMB_ALIST_INITIAL_SIZE); |
| 832 | if (!ret) { |
| 833 | log_debug("Unable to initialise the list for LMB free memory\n"); |
| 834 | return -ENOMEM; |
| 835 | } |
| 836 | |
| 837 | ret = alist_init(&lmb.used_mem, sizeof(struct lmb_region), |
| 838 | (uint)LMB_ALIST_INITIAL_SIZE); |
| 839 | if (!ret) { |
| 840 | log_debug("Unable to initialise the list for LMB used memory\n"); |
| 841 | return -ENOMEM; |
| 842 | } |
| 843 | |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 844 | lmb.test = test; |
| 845 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | /** |
| 850 | * lmb_init() - Initialise the LMB module |
| 851 | * |
| 852 | * Initialise the LMB lists needed for keeping the memory map. There |
| 853 | * are two lists, in form of alloced list data structure. One for the |
| 854 | * available memory, and one for the used memory. Initialise the two |
| 855 | * lists as part of board init. Add memory to the available memory |
| 856 | * list and reserve common areas by adding them to the used memory |
| 857 | * list. |
| 858 | * |
| 859 | * Return: 0 on success, -ve on error |
| 860 | */ |
| 861 | int lmb_init(void) |
| 862 | { |
| 863 | int ret; |
| 864 | |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 865 | ret = lmb_setup(false); |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 866 | if (ret) { |
| 867 | log_info("Unable to init LMB\n"); |
| 868 | return ret; |
| 869 | } |
| 870 | |
Sughosh Ganu | 8a9fc30 | 2024-08-26 17:29:23 +0530 | [diff] [blame] | 871 | lmb_add_memory(); |
| 872 | |
Sughosh Ganu | f4fb154 | 2024-08-26 17:29:24 +0530 | [diff] [blame] | 873 | /* Reserve the U-Boot image region once U-Boot has relocated */ |
Simon Glass | 456bdb7 | 2024-09-29 19:49:36 -0600 | [diff] [blame] | 874 | if (xpl_phase() == PHASE_SPL) |
Sughosh Ganu | f4fb154 | 2024-08-26 17:29:24 +0530 | [diff] [blame] | 875 | lmb_reserve_common_spl(); |
Simon Glass | 456bdb7 | 2024-09-29 19:49:36 -0600 | [diff] [blame] | 876 | else if (xpl_phase() == PHASE_BOARD_R) |
Sughosh Ganu | f4fb154 | 2024-08-26 17:29:24 +0530 | [diff] [blame] | 877 | lmb_reserve_common((void *)gd->fdt_blob); |
| 878 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 879 | return 0; |
| 880 | } |
| 881 | |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 882 | struct lmb *lmb_get(void) |
| 883 | { |
| 884 | return &lmb; |
| 885 | } |
| 886 | |
Simon Glass | 1c30f7a | 2024-10-21 10:19:31 +0200 | [diff] [blame] | 887 | #if CONFIG_IS_ENABLED(UNIT_TEST) |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 888 | int lmb_push(struct lmb *store) |
| 889 | { |
| 890 | int ret; |
| 891 | |
| 892 | *store = lmb; |
Sughosh Ganu | 2f61915 | 2024-10-15 21:07:07 +0530 | [diff] [blame] | 893 | ret = lmb_setup(true); |
Sughosh Ganu | ed17a33 | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 894 | if (ret) |
| 895 | return ret; |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | void lmb_pop(struct lmb *store) |
| 901 | { |
| 902 | alist_uninit(&lmb.free_mem); |
| 903 | alist_uninit(&lmb.used_mem); |
| 904 | lmb = *store; |
| 905 | } |
| 906 | #endif /* UNIT_TEST */ |