15d00995cSAlexander Graf /* 25d00995cSAlexander Graf * EFI application memory management 35d00995cSAlexander Graf * 45d00995cSAlexander Graf * Copyright (c) 2016 Alexander Graf 55d00995cSAlexander Graf * 65d00995cSAlexander Graf * SPDX-License-Identifier: GPL-2.0+ 75d00995cSAlexander Graf */ 85d00995cSAlexander Graf 95d00995cSAlexander Graf #include <common.h> 105d00995cSAlexander Graf #include <efi_loader.h> 115d00995cSAlexander Graf #include <malloc.h> 125d00995cSAlexander Graf #include <asm/global_data.h> 135d00995cSAlexander Graf #include <libfdt_env.h> 1438ce65e1SAlexander Graf #include <linux/list_sort.h> 155d00995cSAlexander Graf #include <inttypes.h> 165d00995cSAlexander Graf #include <watchdog.h> 175d00995cSAlexander Graf 185d00995cSAlexander Graf DECLARE_GLOBAL_DATA_PTR; 195d00995cSAlexander Graf 205d00995cSAlexander Graf struct efi_mem_list { 215d00995cSAlexander Graf struct list_head link; 225d00995cSAlexander Graf struct efi_mem_desc desc; 235d00995cSAlexander Graf }; 245d00995cSAlexander Graf 25*74c16accSAlexander Graf #define EFI_CARVE_NO_OVERLAP -1 26*74c16accSAlexander Graf #define EFI_CARVE_LOOP_AGAIN -2 27*74c16accSAlexander Graf #define EFI_CARVE_OVERLAPS_NONRAM -3 28*74c16accSAlexander Graf 295d00995cSAlexander Graf /* This list contains all memory map items */ 305d00995cSAlexander Graf LIST_HEAD(efi_mem); 315d00995cSAlexander Graf 3251735ae0SAlexander Graf #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER 3351735ae0SAlexander Graf void *efi_bounce_buffer; 3451735ae0SAlexander Graf #endif 3551735ae0SAlexander Graf 365d00995cSAlexander Graf /* 3738ce65e1SAlexander Graf * Sorts the memory list from highest address to lowest address 3838ce65e1SAlexander Graf * 3938ce65e1SAlexander Graf * When allocating memory we should always start from the highest 4038ce65e1SAlexander Graf * address chunk, so sort the memory list such that the first list 4138ce65e1SAlexander Graf * iterator gets the highest address and goes lower from there. 4238ce65e1SAlexander Graf */ 4338ce65e1SAlexander Graf static int efi_mem_cmp(void *priv, struct list_head *a, struct list_head *b) 4438ce65e1SAlexander Graf { 4538ce65e1SAlexander Graf struct efi_mem_list *mema = list_entry(a, struct efi_mem_list, link); 4638ce65e1SAlexander Graf struct efi_mem_list *memb = list_entry(b, struct efi_mem_list, link); 4738ce65e1SAlexander Graf 4838ce65e1SAlexander Graf if (mema->desc.physical_start == memb->desc.physical_start) 4938ce65e1SAlexander Graf return 0; 5038ce65e1SAlexander Graf else if (mema->desc.physical_start < memb->desc.physical_start) 5138ce65e1SAlexander Graf return 1; 5238ce65e1SAlexander Graf else 5338ce65e1SAlexander Graf return -1; 5438ce65e1SAlexander Graf } 5538ce65e1SAlexander Graf 5638ce65e1SAlexander Graf static void efi_mem_sort(void) 5738ce65e1SAlexander Graf { 5838ce65e1SAlexander Graf list_sort(NULL, &efi_mem, efi_mem_cmp); 5938ce65e1SAlexander Graf } 6038ce65e1SAlexander Graf 6138ce65e1SAlexander Graf /* 625d00995cSAlexander Graf * Unmaps all memory occupied by the carve_desc region from the 635d00995cSAlexander Graf * list entry pointed to by map. 645d00995cSAlexander Graf * 655d00995cSAlexander Graf * Returns 1 if carving was performed or 0 if the regions don't overlap. 665d00995cSAlexander Graf * Returns -1 if it would affect non-RAM regions but overlap_only_ram is set. 675d00995cSAlexander Graf * Carving is only guaranteed to complete when all regions return 0. 685d00995cSAlexander Graf */ 695d00995cSAlexander Graf static int efi_mem_carve_out(struct efi_mem_list *map, 705d00995cSAlexander Graf struct efi_mem_desc *carve_desc, 715d00995cSAlexander Graf bool overlap_only_ram) 725d00995cSAlexander Graf { 735d00995cSAlexander Graf struct efi_mem_list *newmap; 745d00995cSAlexander Graf struct efi_mem_desc *map_desc = &map->desc; 755d00995cSAlexander Graf uint64_t map_start = map_desc->physical_start; 765d00995cSAlexander Graf uint64_t map_end = map_start + (map_desc->num_pages << EFI_PAGE_SHIFT); 775d00995cSAlexander Graf uint64_t carve_start = carve_desc->physical_start; 785d00995cSAlexander Graf uint64_t carve_end = carve_start + 795d00995cSAlexander Graf (carve_desc->num_pages << EFI_PAGE_SHIFT); 805d00995cSAlexander Graf 815d00995cSAlexander Graf /* check whether we're overlapping */ 825d00995cSAlexander Graf if ((carve_end <= map_start) || (carve_start >= map_end)) 83*74c16accSAlexander Graf return EFI_CARVE_NO_OVERLAP; 845d00995cSAlexander Graf 855d00995cSAlexander Graf /* We're overlapping with non-RAM, warn the caller if desired */ 865d00995cSAlexander Graf if (overlap_only_ram && (map_desc->type != EFI_CONVENTIONAL_MEMORY)) 87*74c16accSAlexander Graf return EFI_CARVE_OVERLAPS_NONRAM; 885d00995cSAlexander Graf 895d00995cSAlexander Graf /* Sanitize carve_start and carve_end to lie within our bounds */ 905d00995cSAlexander Graf carve_start = max(carve_start, map_start); 915d00995cSAlexander Graf carve_end = min(carve_end, map_end); 925d00995cSAlexander Graf 935d00995cSAlexander Graf /* Carving at the beginning of our map? Just move it! */ 945d00995cSAlexander Graf if (carve_start == map_start) { 955d00995cSAlexander Graf if (map_end == carve_end) { 965d00995cSAlexander Graf /* Full overlap, just remove map */ 975d00995cSAlexander Graf list_del(&map->link); 985d00995cSAlexander Graf } 995d00995cSAlexander Graf 1005d00995cSAlexander Graf map_desc->physical_start = carve_end; 1015d00995cSAlexander Graf map_desc->num_pages = (map_end - carve_end) >> EFI_PAGE_SHIFT; 102*74c16accSAlexander Graf return (carve_end - carve_start) >> EFI_PAGE_SHIFT; 1035d00995cSAlexander Graf } 1045d00995cSAlexander Graf 1055d00995cSAlexander Graf /* 1065d00995cSAlexander Graf * Overlapping maps, just split the list map at carve_start, 1075d00995cSAlexander Graf * it will get moved or removed in the next iteration. 1085d00995cSAlexander Graf * 1095d00995cSAlexander Graf * [ map_desc |__carve_start__| newmap ] 1105d00995cSAlexander Graf */ 1115d00995cSAlexander Graf 1125d00995cSAlexander Graf /* Create a new map from [ carve_start ... map_end ] */ 1135d00995cSAlexander Graf newmap = calloc(1, sizeof(*newmap)); 1145d00995cSAlexander Graf newmap->desc = map->desc; 1155d00995cSAlexander Graf newmap->desc.physical_start = carve_start; 1165d00995cSAlexander Graf newmap->desc.num_pages = (map_end - carve_start) >> EFI_PAGE_SHIFT; 1175d00995cSAlexander Graf list_add_tail(&newmap->link, &efi_mem); 1185d00995cSAlexander Graf 1195d00995cSAlexander Graf /* Shrink the map to [ map_start ... carve_start ] */ 1205d00995cSAlexander Graf map_desc->num_pages = (carve_start - map_start) >> EFI_PAGE_SHIFT; 1215d00995cSAlexander Graf 122*74c16accSAlexander Graf return EFI_CARVE_LOOP_AGAIN; 1235d00995cSAlexander Graf } 1245d00995cSAlexander Graf 1255d00995cSAlexander Graf uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type, 1265d00995cSAlexander Graf bool overlap_only_ram) 1275d00995cSAlexander Graf { 1285d00995cSAlexander Graf struct list_head *lhandle; 1295d00995cSAlexander Graf struct efi_mem_list *newlist; 130*74c16accSAlexander Graf bool carve_again; 131*74c16accSAlexander Graf uint64_t carved_pages = 0; 1325d00995cSAlexander Graf 1335d00995cSAlexander Graf if (!pages) 1345d00995cSAlexander Graf return start; 1355d00995cSAlexander Graf 1365d00995cSAlexander Graf newlist = calloc(1, sizeof(*newlist)); 1375d00995cSAlexander Graf newlist->desc.type = memory_type; 1385d00995cSAlexander Graf newlist->desc.physical_start = start; 1395d00995cSAlexander Graf newlist->desc.virtual_start = start; 1405d00995cSAlexander Graf newlist->desc.num_pages = pages; 1415d00995cSAlexander Graf 1425d00995cSAlexander Graf switch (memory_type) { 1435d00995cSAlexander Graf case EFI_RUNTIME_SERVICES_CODE: 1445d00995cSAlexander Graf case EFI_RUNTIME_SERVICES_DATA: 1455d00995cSAlexander Graf newlist->desc.attribute = (1 << EFI_MEMORY_WB_SHIFT) | 1465d00995cSAlexander Graf (1ULL << EFI_MEMORY_RUNTIME_SHIFT); 1475d00995cSAlexander Graf break; 1485d00995cSAlexander Graf case EFI_MMAP_IO: 1495d00995cSAlexander Graf newlist->desc.attribute = 1ULL << EFI_MEMORY_RUNTIME_SHIFT; 1505d00995cSAlexander Graf break; 1515d00995cSAlexander Graf default: 1525d00995cSAlexander Graf newlist->desc.attribute = 1 << EFI_MEMORY_WB_SHIFT; 1535d00995cSAlexander Graf break; 1545d00995cSAlexander Graf } 1555d00995cSAlexander Graf 1565d00995cSAlexander Graf /* Add our new map */ 1575d00995cSAlexander Graf do { 158*74c16accSAlexander Graf carve_again = false; 1595d00995cSAlexander Graf list_for_each(lhandle, &efi_mem) { 1605d00995cSAlexander Graf struct efi_mem_list *lmem; 1615d00995cSAlexander Graf int r; 1625d00995cSAlexander Graf 1635d00995cSAlexander Graf lmem = list_entry(lhandle, struct efi_mem_list, link); 1645d00995cSAlexander Graf r = efi_mem_carve_out(lmem, &newlist->desc, 1655d00995cSAlexander Graf overlap_only_ram); 166*74c16accSAlexander Graf switch (r) { 167*74c16accSAlexander Graf case EFI_CARVE_OVERLAPS_NONRAM: 168*74c16accSAlexander Graf /* 169*74c16accSAlexander Graf * The user requested to only have RAM overlaps, 170*74c16accSAlexander Graf * but we hit a non-RAM region. Error out. 171*74c16accSAlexander Graf */ 1725d00995cSAlexander Graf return 0; 173*74c16accSAlexander Graf case EFI_CARVE_NO_OVERLAP: 174*74c16accSAlexander Graf /* Just ignore this list entry */ 175*74c16accSAlexander Graf break; 176*74c16accSAlexander Graf case EFI_CARVE_LOOP_AGAIN: 177*74c16accSAlexander Graf /* 178*74c16accSAlexander Graf * We split an entry, but need to loop through 179*74c16accSAlexander Graf * the list again to actually carve it. 180*74c16accSAlexander Graf */ 181*74c16accSAlexander Graf carve_again = true; 182*74c16accSAlexander Graf break; 183*74c16accSAlexander Graf default: 184*74c16accSAlexander Graf /* We carved a number of pages */ 185*74c16accSAlexander Graf carved_pages += r; 186*74c16accSAlexander Graf carve_again = true; 187*74c16accSAlexander Graf break; 188*74c16accSAlexander Graf } 189*74c16accSAlexander Graf 190*74c16accSAlexander Graf if (carve_again) { 191*74c16accSAlexander Graf /* The list changed, we need to start over */ 1925d00995cSAlexander Graf break; 1935d00995cSAlexander Graf } 1945d00995cSAlexander Graf } 195*74c16accSAlexander Graf } while (carve_again); 196*74c16accSAlexander Graf 197*74c16accSAlexander Graf if (overlap_only_ram && (carved_pages != pages)) { 198*74c16accSAlexander Graf /* 199*74c16accSAlexander Graf * The payload wanted to have RAM overlaps, but we overlapped 200*74c16accSAlexander Graf * with an unallocated region. Error out. 201*74c16accSAlexander Graf */ 202*74c16accSAlexander Graf return 0; 203*74c16accSAlexander Graf } 2045d00995cSAlexander Graf 2055d00995cSAlexander Graf /* Add our new map */ 2065d00995cSAlexander Graf list_add_tail(&newlist->link, &efi_mem); 2075d00995cSAlexander Graf 20838ce65e1SAlexander Graf /* And make sure memory is listed in descending order */ 20938ce65e1SAlexander Graf efi_mem_sort(); 21038ce65e1SAlexander Graf 2115d00995cSAlexander Graf return start; 2125d00995cSAlexander Graf } 2135d00995cSAlexander Graf 2145d00995cSAlexander Graf static uint64_t efi_find_free_memory(uint64_t len, uint64_t max_addr) 2155d00995cSAlexander Graf { 2165d00995cSAlexander Graf struct list_head *lhandle; 2175d00995cSAlexander Graf 2185d00995cSAlexander Graf list_for_each(lhandle, &efi_mem) { 2195d00995cSAlexander Graf struct efi_mem_list *lmem = list_entry(lhandle, 2205d00995cSAlexander Graf struct efi_mem_list, link); 2215d00995cSAlexander Graf struct efi_mem_desc *desc = &lmem->desc; 2225d00995cSAlexander Graf uint64_t desc_len = desc->num_pages << EFI_PAGE_SHIFT; 2235d00995cSAlexander Graf uint64_t desc_end = desc->physical_start + desc_len; 2245d00995cSAlexander Graf uint64_t curmax = min(max_addr, desc_end); 2255d00995cSAlexander Graf uint64_t ret = curmax - len; 2265d00995cSAlexander Graf 2275d00995cSAlexander Graf /* We only take memory from free RAM */ 2285d00995cSAlexander Graf if (desc->type != EFI_CONVENTIONAL_MEMORY) 2295d00995cSAlexander Graf continue; 2305d00995cSAlexander Graf 2315d00995cSAlexander Graf /* Out of bounds for max_addr */ 2325d00995cSAlexander Graf if ((ret + len) > max_addr) 2335d00995cSAlexander Graf continue; 2345d00995cSAlexander Graf 2355d00995cSAlexander Graf /* Out of bounds for upper map limit */ 2365d00995cSAlexander Graf if ((ret + len) > desc_end) 2375d00995cSAlexander Graf continue; 2385d00995cSAlexander Graf 2395d00995cSAlexander Graf /* Out of bounds for lower map limit */ 2405d00995cSAlexander Graf if (ret < desc->physical_start) 2415d00995cSAlexander Graf continue; 2425d00995cSAlexander Graf 2435d00995cSAlexander Graf /* Return the highest address in this map within bounds */ 2445d00995cSAlexander Graf return ret; 2455d00995cSAlexander Graf } 2465d00995cSAlexander Graf 2475d00995cSAlexander Graf return 0; 2485d00995cSAlexander Graf } 2495d00995cSAlexander Graf 2505d00995cSAlexander Graf efi_status_t efi_allocate_pages(int type, int memory_type, 2515d00995cSAlexander Graf unsigned long pages, uint64_t *memory) 2525d00995cSAlexander Graf { 2535d00995cSAlexander Graf u64 len = pages << EFI_PAGE_SHIFT; 2545d00995cSAlexander Graf efi_status_t r = EFI_SUCCESS; 2555d00995cSAlexander Graf uint64_t addr; 2565d00995cSAlexander Graf 2575d00995cSAlexander Graf switch (type) { 2585d00995cSAlexander Graf case 0: 2595d00995cSAlexander Graf /* Any page */ 260dede284dSAndreas Färber addr = efi_find_free_memory(len, gd->start_addr_sp); 2615d00995cSAlexander Graf if (!addr) { 2625d00995cSAlexander Graf r = EFI_NOT_FOUND; 2635d00995cSAlexander Graf break; 2645d00995cSAlexander Graf } 2655d00995cSAlexander Graf break; 2665d00995cSAlexander Graf case 1: 2675d00995cSAlexander Graf /* Max address */ 2685d00995cSAlexander Graf addr = efi_find_free_memory(len, *memory); 2695d00995cSAlexander Graf if (!addr) { 2705d00995cSAlexander Graf r = EFI_NOT_FOUND; 2715d00995cSAlexander Graf break; 2725d00995cSAlexander Graf } 2735d00995cSAlexander Graf break; 2745d00995cSAlexander Graf case 2: 2755d00995cSAlexander Graf /* Exact address, reserve it. The addr is already in *memory. */ 2765d00995cSAlexander Graf addr = *memory; 2775d00995cSAlexander Graf break; 2785d00995cSAlexander Graf default: 2795d00995cSAlexander Graf /* UEFI doesn't specify other allocation types */ 2805d00995cSAlexander Graf r = EFI_INVALID_PARAMETER; 2815d00995cSAlexander Graf break; 2825d00995cSAlexander Graf } 2835d00995cSAlexander Graf 2845d00995cSAlexander Graf if (r == EFI_SUCCESS) { 2855d00995cSAlexander Graf uint64_t ret; 2865d00995cSAlexander Graf 2875d00995cSAlexander Graf /* Reserve that map in our memory maps */ 2885d00995cSAlexander Graf ret = efi_add_memory_map(addr, pages, memory_type, true); 2895d00995cSAlexander Graf if (ret == addr) { 2905d00995cSAlexander Graf *memory = addr; 2915d00995cSAlexander Graf } else { 2925d00995cSAlexander Graf /* Map would overlap, bail out */ 2935d00995cSAlexander Graf r = EFI_OUT_OF_RESOURCES; 2945d00995cSAlexander Graf } 2955d00995cSAlexander Graf } 2965d00995cSAlexander Graf 2975d00995cSAlexander Graf return r; 2985d00995cSAlexander Graf } 2995d00995cSAlexander Graf 3005d00995cSAlexander Graf void *efi_alloc(uint64_t len, int memory_type) 3015d00995cSAlexander Graf { 3025d00995cSAlexander Graf uint64_t ret = 0; 3035d00995cSAlexander Graf uint64_t pages = (len + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; 3045d00995cSAlexander Graf efi_status_t r; 3055d00995cSAlexander Graf 3065d00995cSAlexander Graf r = efi_allocate_pages(0, memory_type, pages, &ret); 3075d00995cSAlexander Graf if (r == EFI_SUCCESS) 3085d00995cSAlexander Graf return (void*)(uintptr_t)ret; 3095d00995cSAlexander Graf 3105d00995cSAlexander Graf return NULL; 3115d00995cSAlexander Graf } 3125d00995cSAlexander Graf 3135d00995cSAlexander Graf efi_status_t efi_free_pages(uint64_t memory, unsigned long pages) 3145d00995cSAlexander Graf { 3155d00995cSAlexander Graf /* We don't free, let's cross our fingers we have plenty RAM */ 3165d00995cSAlexander Graf return EFI_SUCCESS; 3175d00995cSAlexander Graf } 3185d00995cSAlexander Graf 3195d00995cSAlexander Graf efi_status_t efi_get_memory_map(unsigned long *memory_map_size, 3205d00995cSAlexander Graf struct efi_mem_desc *memory_map, 3215d00995cSAlexander Graf unsigned long *map_key, 3225d00995cSAlexander Graf unsigned long *descriptor_size, 3235d00995cSAlexander Graf uint32_t *descriptor_version) 3245d00995cSAlexander Graf { 3255d00995cSAlexander Graf ulong map_size = 0; 326cee752faSAlexander Graf int map_entries = 0; 3275d00995cSAlexander Graf struct list_head *lhandle; 3285d00995cSAlexander Graf 3295d00995cSAlexander Graf list_for_each(lhandle, &efi_mem) 330cee752faSAlexander Graf map_entries++; 331cee752faSAlexander Graf 332cee752faSAlexander Graf map_size = map_entries * sizeof(struct efi_mem_desc); 3335d00995cSAlexander Graf 3345d00995cSAlexander Graf *memory_map_size = map_size; 3355d00995cSAlexander Graf 3365d00995cSAlexander Graf if (descriptor_size) 3375d00995cSAlexander Graf *descriptor_size = sizeof(struct efi_mem_desc); 3385d00995cSAlexander Graf 3395d00995cSAlexander Graf if (*memory_map_size < map_size) 3405d00995cSAlexander Graf return EFI_BUFFER_TOO_SMALL; 3415d00995cSAlexander Graf 3425d00995cSAlexander Graf /* Copy list into array */ 3435d00995cSAlexander Graf if (memory_map) { 344cee752faSAlexander Graf /* Return the list in ascending order */ 345cee752faSAlexander Graf memory_map = &memory_map[map_entries - 1]; 3465d00995cSAlexander Graf list_for_each(lhandle, &efi_mem) { 3475d00995cSAlexander Graf struct efi_mem_list *lmem; 3485d00995cSAlexander Graf 3495d00995cSAlexander Graf lmem = list_entry(lhandle, struct efi_mem_list, link); 3505d00995cSAlexander Graf *memory_map = lmem->desc; 351cee752faSAlexander Graf memory_map--; 3525d00995cSAlexander Graf } 3535d00995cSAlexander Graf } 3545d00995cSAlexander Graf 3555d00995cSAlexander Graf return EFI_SUCCESS; 3565d00995cSAlexander Graf } 3575d00995cSAlexander Graf 3585d00995cSAlexander Graf int efi_memory_init(void) 3595d00995cSAlexander Graf { 360dede284dSAndreas Färber unsigned long runtime_start, runtime_end, runtime_pages; 361dede284dSAndreas Färber unsigned long uboot_start, uboot_pages; 362dede284dSAndreas Färber unsigned long uboot_stack_size = 16 * 1024 * 1024; 3635d00995cSAlexander Graf int i; 3645d00995cSAlexander Graf 3655d00995cSAlexander Graf /* Add RAM */ 3665d00995cSAlexander Graf for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { 3675d00995cSAlexander Graf u64 ram_start = gd->bd->bi_dram[i].start; 3685d00995cSAlexander Graf u64 ram_size = gd->bd->bi_dram[i].size; 3695d00995cSAlexander Graf u64 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK; 3705d00995cSAlexander Graf u64 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; 3715d00995cSAlexander Graf 3725d00995cSAlexander Graf efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY, 3735d00995cSAlexander Graf false); 3745d00995cSAlexander Graf } 3755d00995cSAlexander Graf 3765d00995cSAlexander Graf /* Add U-Boot */ 3775d00995cSAlexander Graf uboot_start = (gd->start_addr_sp - uboot_stack_size) & ~EFI_PAGE_MASK; 3785d00995cSAlexander Graf uboot_pages = (gd->ram_top - uboot_start) >> EFI_PAGE_SHIFT; 3795d00995cSAlexander Graf efi_add_memory_map(uboot_start, uboot_pages, EFI_LOADER_DATA, false); 3805d00995cSAlexander Graf 3815d00995cSAlexander Graf /* Add Runtime Services */ 3825d00995cSAlexander Graf runtime_start = (ulong)&__efi_runtime_start & ~EFI_PAGE_MASK; 3835d00995cSAlexander Graf runtime_end = (ulong)&__efi_runtime_stop; 3845d00995cSAlexander Graf runtime_end = (runtime_end + EFI_PAGE_MASK) & ~EFI_PAGE_MASK; 3855d00995cSAlexander Graf runtime_pages = (runtime_end - runtime_start) >> EFI_PAGE_SHIFT; 3865d00995cSAlexander Graf efi_add_memory_map(runtime_start, runtime_pages, 3875d00995cSAlexander Graf EFI_RUNTIME_SERVICES_CODE, false); 3885d00995cSAlexander Graf 38951735ae0SAlexander Graf #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER 39051735ae0SAlexander Graf /* Request a 32bit 64MB bounce buffer region */ 39151735ae0SAlexander Graf uint64_t efi_bounce_buffer_addr = 0xffffffff; 39251735ae0SAlexander Graf 39351735ae0SAlexander Graf if (efi_allocate_pages(1, EFI_LOADER_DATA, 39451735ae0SAlexander Graf (64 * 1024 * 1024) >> EFI_PAGE_SHIFT, 39551735ae0SAlexander Graf &efi_bounce_buffer_addr) != EFI_SUCCESS) 39651735ae0SAlexander Graf return -1; 39751735ae0SAlexander Graf 39851735ae0SAlexander Graf efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr; 39951735ae0SAlexander Graf #endif 40051735ae0SAlexander Graf 4015d00995cSAlexander Graf return 0; 4025d00995cSAlexander Graf } 403