]> git.ipfire.org Git - thirdparty/u-boot.git/blame - lib/efi_loader/efi_memory.c
efi_loader: macro efi_size_in_pages()
[thirdparty/u-boot.git] / lib / efi_loader / efi_memory.c
CommitLineData
f739fcd8 1// SPDX-License-Identifier: GPL-2.0+
5d00995c
AG
2/*
3 * EFI application memory management
4 *
5 * Copyright (c) 2016 Alexander Graf
5d00995c
AG
6 */
7
5d00995c
AG
8#include <common.h>
9#include <efi_loader.h>
10#include <malloc.h>
282a06cb 11#include <mapmem.h>
bdecaebd 12#include <watchdog.h>
38ce65e1 13#include <linux/list_sort.h>
5d00995c
AG
14
15DECLARE_GLOBAL_DATA_PTR;
16
1fcb7ea2
HS
17efi_uintn_t efi_memory_map_key;
18
5d00995c
AG
19struct efi_mem_list {
20 struct list_head link;
21 struct efi_mem_desc desc;
22};
23
74c16acc
AG
24#define EFI_CARVE_NO_OVERLAP -1
25#define EFI_CARVE_LOOP_AGAIN -2
26#define EFI_CARVE_OVERLAPS_NONRAM -3
27
5d00995c
AG
28/* This list contains all memory map items */
29LIST_HEAD(efi_mem);
30
51735ae0
AG
31#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
32void *efi_bounce_buffer;
33#endif
34
42417bc8
SB
35/*
36 * U-Boot services each EFI AllocatePool request as a separate
37 * (multiple) page allocation. We have to track the number of pages
38 * to be able to free the correct amount later.
39 * EFI requires 8 byte alignment for pool allocations, so we can
40 * prepend each allocation with an 64 bit header tracking the
41 * allocation size, and hand out the remainder to the caller.
42 */
43struct efi_pool_allocation {
44 u64 num_pages;
946160f3 45 char data[] __aligned(ARCH_DMA_MINALIGN);
42417bc8
SB
46};
47
38ce65e1
AG
48/*
49 * Sorts the memory list from highest address to lowest address
50 *
51 * When allocating memory we should always start from the highest
52 * address chunk, so sort the memory list such that the first list
53 * iterator gets the highest address and goes lower from there.
54 */
55static int efi_mem_cmp(void *priv, struct list_head *a, struct list_head *b)
56{
57 struct efi_mem_list *mema = list_entry(a, struct efi_mem_list, link);
58 struct efi_mem_list *memb = list_entry(b, struct efi_mem_list, link);
59
60 if (mema->desc.physical_start == memb->desc.physical_start)
61 return 0;
62 else if (mema->desc.physical_start < memb->desc.physical_start)
63 return 1;
64 else
65 return -1;
66}
67
7b05667c
AG
68static uint64_t desc_get_end(struct efi_mem_desc *desc)
69{
70 return desc->physical_start + (desc->num_pages << EFI_PAGE_SHIFT);
71}
72
38ce65e1
AG
73static void efi_mem_sort(void)
74{
7b05667c
AG
75 struct list_head *lhandle;
76 struct efi_mem_list *prevmem = NULL;
77 bool merge_again = true;
78
38ce65e1 79 list_sort(NULL, &efi_mem, efi_mem_cmp);
7b05667c
AG
80
81 /* Now merge entries that can be merged */
82 while (merge_again) {
83 merge_again = false;
84 list_for_each(lhandle, &efi_mem) {
85 struct efi_mem_list *lmem;
86 struct efi_mem_desc *prev = &prevmem->desc;
87 struct efi_mem_desc *cur;
88 uint64_t pages;
89
90 lmem = list_entry(lhandle, struct efi_mem_list, link);
91 if (!prevmem) {
92 prevmem = lmem;
93 continue;
94 }
95
96 cur = &lmem->desc;
97
98 if ((desc_get_end(cur) == prev->physical_start) &&
99 (prev->type == cur->type) &&
100 (prev->attribute == cur->attribute)) {
101 /* There is an existing map before, reuse it */
102 pages = cur->num_pages;
103 prev->num_pages += pages;
104 prev->physical_start -= pages << EFI_PAGE_SHIFT;
105 prev->virtual_start -= pages << EFI_PAGE_SHIFT;
106 list_del(&lmem->link);
107 free(lmem);
108
109 merge_again = true;
110 break;
111 }
112
113 prevmem = lmem;
114 }
115 }
38ce65e1
AG
116}
117
32826140
HS
118/** efi_mem_carve_out - unmap memory region
119 *
120 * @map: memory map
121 * @carve_desc: memory region to unmap
122 * @overlap_only_ram: the carved out region may only overlap RAM
123 * Return Value: the number of overlapping pages which have been
124 * removed from the map,
125 * EFI_CARVE_NO_OVERLAP, if the regions don't overlap,
126 * EFI_CARVE_OVERLAPS_NONRAM, if the carve and map overlap,
127 * and the map contains anything but free ram
128 * (only when overlap_only_ram is true),
129 * EFI_CARVE_LOOP_AGAIN, if the mapping list should be
130 * traversed again, as it has been altered.
5d00995c 131 *
32826140
HS
132 * Unmaps all memory occupied by the carve_desc region from the list entry
133 * pointed to by map.
852efbf5
SB
134 *
135 * In case of EFI_CARVE_OVERLAPS_NONRAM it is the callers responsibility
32826140 136 * to re-add the already carved out pages to the mapping.
5d00995c 137 */
32826140 138static s64 efi_mem_carve_out(struct efi_mem_list *map,
5d00995c
AG
139 struct efi_mem_desc *carve_desc,
140 bool overlap_only_ram)
141{
142 struct efi_mem_list *newmap;
143 struct efi_mem_desc *map_desc = &map->desc;
144 uint64_t map_start = map_desc->physical_start;
145 uint64_t map_end = map_start + (map_desc->num_pages << EFI_PAGE_SHIFT);
146 uint64_t carve_start = carve_desc->physical_start;
147 uint64_t carve_end = carve_start +
148 (carve_desc->num_pages << EFI_PAGE_SHIFT);
149
150 /* check whether we're overlapping */
151 if ((carve_end <= map_start) || (carve_start >= map_end))
74c16acc 152 return EFI_CARVE_NO_OVERLAP;
5d00995c
AG
153
154 /* We're overlapping with non-RAM, warn the caller if desired */
155 if (overlap_only_ram && (map_desc->type != EFI_CONVENTIONAL_MEMORY))
74c16acc 156 return EFI_CARVE_OVERLAPS_NONRAM;
5d00995c
AG
157
158 /* Sanitize carve_start and carve_end to lie within our bounds */
159 carve_start = max(carve_start, map_start);
160 carve_end = min(carve_end, map_end);
161
162 /* Carving at the beginning of our map? Just move it! */
163 if (carve_start == map_start) {
164 if (map_end == carve_end) {
165 /* Full overlap, just remove map */
166 list_del(&map->link);
511d0b97
SB
167 free(map);
168 } else {
169 map->desc.physical_start = carve_end;
170 map->desc.num_pages = (map_end - carve_end)
171 >> EFI_PAGE_SHIFT;
5d00995c
AG
172 }
173
74c16acc 174 return (carve_end - carve_start) >> EFI_PAGE_SHIFT;
5d00995c
AG
175 }
176
177 /*
178 * Overlapping maps, just split the list map at carve_start,
179 * it will get moved or removed in the next iteration.
180 *
181 * [ map_desc |__carve_start__| newmap ]
182 */
183
184 /* Create a new map from [ carve_start ... map_end ] */
185 newmap = calloc(1, sizeof(*newmap));
186 newmap->desc = map->desc;
187 newmap->desc.physical_start = carve_start;
188 newmap->desc.num_pages = (map_end - carve_start) >> EFI_PAGE_SHIFT;
b6a95172
SB
189 /* Insert before current entry (descending address order) */
190 list_add_tail(&newmap->link, &map->link);
5d00995c
AG
191
192 /* Shrink the map to [ map_start ... carve_start ] */
193 map_desc->num_pages = (carve_start - map_start) >> EFI_PAGE_SHIFT;
194
74c16acc 195 return EFI_CARVE_LOOP_AGAIN;
5d00995c
AG
196}
197
198uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type,
199 bool overlap_only_ram)
200{
201 struct list_head *lhandle;
202 struct efi_mem_list *newlist;
74c16acc
AG
203 bool carve_again;
204 uint64_t carved_pages = 0;
5d00995c 205
dee37fc9 206 debug("%s: 0x%llx 0x%llx %d %s\n", __func__,
c933ed94
AF
207 start, pages, memory_type, overlap_only_ram ? "yes" : "no");
208
1fcb7ea2
HS
209 if (memory_type >= EFI_MAX_MEMORY_TYPE)
210 return EFI_INVALID_PARAMETER;
211
5d00995c
AG
212 if (!pages)
213 return start;
214
1fcb7ea2 215 ++efi_memory_map_key;
5d00995c
AG
216 newlist = calloc(1, sizeof(*newlist));
217 newlist->desc.type = memory_type;
218 newlist->desc.physical_start = start;
219 newlist->desc.virtual_start = start;
220 newlist->desc.num_pages = pages;
221
222 switch (memory_type) {
223 case EFI_RUNTIME_SERVICES_CODE:
224 case EFI_RUNTIME_SERVICES_DATA:
9b89183b 225 newlist->desc.attribute = EFI_MEMORY_WB | EFI_MEMORY_RUNTIME;
5d00995c
AG
226 break;
227 case EFI_MMAP_IO:
9b89183b 228 newlist->desc.attribute = EFI_MEMORY_RUNTIME;
5d00995c
AG
229 break;
230 default:
9b89183b 231 newlist->desc.attribute = EFI_MEMORY_WB;
5d00995c
AG
232 break;
233 }
234
235 /* Add our new map */
236 do {
74c16acc 237 carve_again = false;
5d00995c
AG
238 list_for_each(lhandle, &efi_mem) {
239 struct efi_mem_list *lmem;
32826140 240 s64 r;
5d00995c
AG
241
242 lmem = list_entry(lhandle, struct efi_mem_list, link);
243 r = efi_mem_carve_out(lmem, &newlist->desc,
244 overlap_only_ram);
74c16acc
AG
245 switch (r) {
246 case EFI_CARVE_OVERLAPS_NONRAM:
247 /*
248 * The user requested to only have RAM overlaps,
249 * but we hit a non-RAM region. Error out.
250 */
5d00995c 251 return 0;
74c16acc
AG
252 case EFI_CARVE_NO_OVERLAP:
253 /* Just ignore this list entry */
254 break;
255 case EFI_CARVE_LOOP_AGAIN:
256 /*
257 * We split an entry, but need to loop through
258 * the list again to actually carve it.
259 */
260 carve_again = true;
261 break;
262 default:
263 /* We carved a number of pages */
264 carved_pages += r;
265 carve_again = true;
266 break;
267 }
268
269 if (carve_again) {
270 /* The list changed, we need to start over */
5d00995c
AG
271 break;
272 }
273 }
74c16acc
AG
274 } while (carve_again);
275
276 if (overlap_only_ram && (carved_pages != pages)) {
277 /*
278 * The payload wanted to have RAM overlaps, but we overlapped
279 * with an unallocated region. Error out.
280 */
281 return 0;
282 }
5d00995c
AG
283
284 /* Add our new map */
285 list_add_tail(&newlist->link, &efi_mem);
286
38ce65e1
AG
287 /* And make sure memory is listed in descending order */
288 efi_mem_sort();
289
5d00995c
AG
290 return start;
291}
292
293static uint64_t efi_find_free_memory(uint64_t len, uint64_t max_addr)
294{
295 struct list_head *lhandle;
296
c2e1ad70
AG
297 /*
298 * Prealign input max address, so we simplify our matching
299 * logic below and can just reuse it as return pointer.
300 */
301 max_addr &= ~EFI_PAGE_MASK;
302
5d00995c
AG
303 list_for_each(lhandle, &efi_mem) {
304 struct efi_mem_list *lmem = list_entry(lhandle,
305 struct efi_mem_list, link);
306 struct efi_mem_desc *desc = &lmem->desc;
307 uint64_t desc_len = desc->num_pages << EFI_PAGE_SHIFT;
308 uint64_t desc_end = desc->physical_start + desc_len;
309 uint64_t curmax = min(max_addr, desc_end);
310 uint64_t ret = curmax - len;
311
312 /* We only take memory from free RAM */
313 if (desc->type != EFI_CONVENTIONAL_MEMORY)
314 continue;
315
316 /* Out of bounds for max_addr */
317 if ((ret + len) > max_addr)
318 continue;
319
320 /* Out of bounds for upper map limit */
321 if ((ret + len) > desc_end)
322 continue;
323
324 /* Out of bounds for lower map limit */
325 if (ret < desc->physical_start)
326 continue;
327
328 /* Return the highest address in this map within bounds */
329 return ret;
330 }
331
332 return 0;
333}
334
474a6f5a
HS
335/*
336 * Allocate memory pages.
337 *
338 * @type type of allocation to be performed
339 * @memory_type usage type of the allocated memory
340 * @pages number of pages to be allocated
341 * @memory allocated memory
342 * @return status code
343 */
5d00995c 344efi_status_t efi_allocate_pages(int type, int memory_type,
f5a2a938 345 efi_uintn_t pages, uint64_t *memory)
5d00995c
AG
346{
347 u64 len = pages << EFI_PAGE_SHIFT;
348 efi_status_t r = EFI_SUCCESS;
349 uint64_t addr;
350
4d5e071e
HS
351 if (!memory)
352 return EFI_INVALID_PARAMETER;
353
5d00995c 354 switch (type) {
7c92fd69 355 case EFI_ALLOCATE_ANY_PAGES:
5d00995c 356 /* Any page */
14deb5e6 357 addr = efi_find_free_memory(len, -1ULL);
5d00995c
AG
358 if (!addr) {
359 r = EFI_NOT_FOUND;
360 break;
361 }
362 break;
7c92fd69 363 case EFI_ALLOCATE_MAX_ADDRESS:
5d00995c
AG
364 /* Max address */
365 addr = efi_find_free_memory(len, *memory);
366 if (!addr) {
367 r = EFI_NOT_FOUND;
368 break;
369 }
370 break;
7c92fd69 371 case EFI_ALLOCATE_ADDRESS:
5d00995c
AG
372 /* Exact address, reserve it. The addr is already in *memory. */
373 addr = *memory;
374 break;
375 default:
376 /* UEFI doesn't specify other allocation types */
377 r = EFI_INVALID_PARAMETER;
378 break;
379 }
380
381 if (r == EFI_SUCCESS) {
382 uint64_t ret;
383
384 /* Reserve that map in our memory maps */
385 ret = efi_add_memory_map(addr, pages, memory_type, true);
386 if (ret == addr) {
49759743 387 *memory = addr;
5d00995c
AG
388 } else {
389 /* Map would overlap, bail out */
390 r = EFI_OUT_OF_RESOURCES;
391 }
392 }
393
394 return r;
395}
396
397void *efi_alloc(uint64_t len, int memory_type)
398{
399 uint64_t ret = 0;
c3772ca1 400 uint64_t pages = efi_size_in_pages(len);
5d00995c
AG
401 efi_status_t r;
402
e09159c8
HS
403 r = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, memory_type, pages,
404 &ret);
5d00995c
AG
405 if (r == EFI_SUCCESS)
406 return (void*)(uintptr_t)ret;
407
408 return NULL;
409}
410
474a6f5a
HS
411/*
412 * Free memory pages.
413 *
414 * @memory start of the memory area to be freed
415 * @pages number of pages to be freed
416 * @return status code
417 */
f5a2a938 418efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages)
5d00995c 419{
b61d857b
SB
420 uint64_t r = 0;
421
49759743 422 r = efi_add_memory_map(memory, pages, EFI_CONVENTIONAL_MEMORY, false);
b61d857b
SB
423 /* Merging of adjacent free regions is missing */
424
49759743 425 if (r == memory)
b61d857b
SB
426 return EFI_SUCCESS;
427
428 return EFI_NOT_FOUND;
5d00995c
AG
429}
430
474a6f5a
HS
431/*
432 * Allocate memory from pool.
433 *
434 * @pool_type type of the pool from which memory is to be allocated
435 * @size number of bytes to be allocated
436 * @buffer allocated memory
437 * @return status code
438 */
439efi_status_t efi_allocate_pool(int pool_type, efi_uintn_t size, void **buffer)
ead1274b
SB
440{
441 efi_status_t r;
282a06cb 442 struct efi_pool_allocation *alloc;
c3772ca1
HS
443 u64 num_pages = efi_size_in_pages(size +
444 sizeof(struct efi_pool_allocation));
42417bc8 445
4d5e071e
HS
446 if (!buffer)
447 return EFI_INVALID_PARAMETER;
448
42417bc8
SB
449 if (size == 0) {
450 *buffer = NULL;
451 return EFI_SUCCESS;
452 }
ead1274b 453
e09159c8 454 r = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, pool_type, num_pages,
282a06cb 455 (uint64_t *)&alloc);
42417bc8
SB
456
457 if (r == EFI_SUCCESS) {
42417bc8
SB
458 alloc->num_pages = num_pages;
459 *buffer = alloc->data;
460 }
461
462 return r;
463}
464
474a6f5a
HS
465/*
466 * Free memory from pool.
467 *
468 * @buffer start of memory to be freed
469 * @return status code
470 */
42417bc8
SB
471efi_status_t efi_free_pool(void *buffer)
472{
473 efi_status_t r;
474 struct efi_pool_allocation *alloc;
475
71275a3e
HS
476 if (buffer == NULL)
477 return EFI_INVALID_PARAMETER;
478
42417bc8
SB
479 alloc = container_of(buffer, struct efi_pool_allocation, data);
480 /* Sanity check, was the supplied address returned by allocate_pool */
481 assert(((uintptr_t)alloc & EFI_PAGE_MASK) == 0);
482
483 r = efi_free_pages((uintptr_t)alloc, alloc->num_pages);
ead1274b
SB
484
485 return r;
486}
487
474a6f5a
HS
488/*
489 * Get map describing memory usage.
490 *
491 * @memory_map_size on entry the size, in bytes, of the memory map buffer,
492 * on exit the size of the copied memory map
493 * @memory_map buffer to which the memory map is written
494 * @map_key key for the memory map
495 * @descriptor_size size of an individual memory descriptor
496 * @descriptor_version version number of the memory descriptor structure
497 * @return status code
498 */
f5a2a938
HS
499efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
500 struct efi_mem_desc *memory_map,
501 efi_uintn_t *map_key,
502 efi_uintn_t *descriptor_size,
503 uint32_t *descriptor_version)
5d00995c 504{
f5a2a938 505 efi_uintn_t map_size = 0;
cee752fa 506 int map_entries = 0;
5d00995c 507 struct list_head *lhandle;
fa995d0d 508 efi_uintn_t provided_map_size;
5d00995c 509
8e835554
HS
510 if (!memory_map_size)
511 return EFI_INVALID_PARAMETER;
512
fa995d0d
HS
513 provided_map_size = *memory_map_size;
514
5d00995c 515 list_for_each(lhandle, &efi_mem)
cee752fa
AG
516 map_entries++;
517
518 map_size = map_entries * sizeof(struct efi_mem_desc);
5d00995c 519
a1b24823
RC
520 *memory_map_size = map_size;
521
0ecba5db
HS
522 if (provided_map_size < map_size)
523 return EFI_BUFFER_TOO_SMALL;
524
8e835554
HS
525 if (!memory_map)
526 return EFI_INVALID_PARAMETER;
527
5d00995c
AG
528 if (descriptor_size)
529 *descriptor_size = sizeof(struct efi_mem_desc);
530
4c02c11d
MYK
531 if (descriptor_version)
532 *descriptor_version = EFI_MEMORY_DESCRIPTOR_VERSION;
533
5d00995c 534 /* Copy list into array */
8e835554
HS
535 /* Return the list in ascending order */
536 memory_map = &memory_map[map_entries - 1];
537 list_for_each(lhandle, &efi_mem) {
538 struct efi_mem_list *lmem;
5d00995c 539
8e835554
HS
540 lmem = list_entry(lhandle, struct efi_mem_list, link);
541 *memory_map = lmem->desc;
542 memory_map--;
5d00995c
AG
543 }
544
8e835554 545 if (map_key)
1fcb7ea2 546 *map_key = efi_memory_map_key;
c6e3c3e6 547
5d00995c
AG
548 return EFI_SUCCESS;
549}
550
42633745 551__weak void efi_add_known_memory(void)
5d00995c 552{
7b78d643 553 u64 ram_top = board_get_usable_ram_top(0) & ~EFI_PAGE_MASK;
5d00995c
AG
554 int i;
555
7b78d643
AG
556 /* Fix for 32bit targets with ram_top at 4G */
557 if (!ram_top)
558 ram_top = 0x100000000ULL;
559
5d00995c
AG
560 /* Add RAM */
561 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
108bdff8 562 u64 ram_end, ram_start, pages;
5d00995c 563
49759743 564 ram_start = (uintptr_t)map_sysmem(gd->bd->bi_dram[i].start, 0);
108bdff8
HS
565 ram_end = ram_start + gd->bd->bi_dram[i].size;
566
567 /* Remove partial pages */
568 ram_end &= ~EFI_PAGE_MASK;
569 ram_start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
570
7b78d643
AG
571 if (ram_end <= ram_start) {
572 /* Invalid mapping, keep going. */
573 continue;
574 }
575
576 pages = (ram_end - ram_start) >> EFI_PAGE_SHIFT;
108bdff8 577
7b78d643
AG
578 efi_add_memory_map(ram_start, pages,
579 EFI_CONVENTIONAL_MEMORY, false);
580
581 /*
582 * Boards may indicate to the U-Boot memory core that they
583 * can not support memory above ram_top. Let's honor this
584 * in the efi_loader subsystem too by declaring any memory
585 * above ram_top as "already occupied by firmware".
586 */
587 if (ram_top < ram_start) {
588 /* ram_top is before this region, reserve all */
108bdff8 589 efi_add_memory_map(ram_start, pages,
7b78d643
AG
590 EFI_BOOT_SERVICES_DATA, true);
591 } else if ((ram_top >= ram_start) && (ram_top < ram_end)) {
592 /* ram_top is inside this region, reserve parts */
593 pages = (ram_end - ram_top) >> EFI_PAGE_SHIFT;
594
595 efi_add_memory_map(ram_top, pages,
596 EFI_BOOT_SERVICES_DATA, true);
108bdff8 597 }
5d00995c 598 }
42633745
YS
599}
600
69259b83
SG
601/* Add memory regions for U-Boot's memory and for the runtime services code */
602static void add_u_boot_and_runtime(void)
42633745
YS
603{
604 unsigned long runtime_start, runtime_end, runtime_pages;
605 unsigned long uboot_start, uboot_pages;
606 unsigned long uboot_stack_size = 16 * 1024 * 1024;
607
5d00995c
AG
608 /* Add U-Boot */
609 uboot_start = (gd->start_addr_sp - uboot_stack_size) & ~EFI_PAGE_MASK;
610 uboot_pages = (gd->ram_top - uboot_start) >> EFI_PAGE_SHIFT;
611 efi_add_memory_map(uboot_start, uboot_pages, EFI_LOADER_DATA, false);
612
613 /* Add Runtime Services */
614 runtime_start = (ulong)&__efi_runtime_start & ~EFI_PAGE_MASK;
615 runtime_end = (ulong)&__efi_runtime_stop;
616 runtime_end = (runtime_end + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
617 runtime_pages = (runtime_end - runtime_start) >> EFI_PAGE_SHIFT;
618 efi_add_memory_map(runtime_start, runtime_pages,
619 EFI_RUNTIME_SERVICES_CODE, false);
69259b83
SG
620}
621
622int efi_memory_init(void)
623{
624 efi_add_known_memory();
625
626 if (!IS_ENABLED(CONFIG_SANDBOX))
627 add_u_boot_and_runtime();
5d00995c 628
51735ae0
AG
629#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
630 /* Request a 32bit 64MB bounce buffer region */
631 uint64_t efi_bounce_buffer_addr = 0xffffffff;
632
e09159c8 633 if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, EFI_LOADER_DATA,
51735ae0
AG
634 (64 * 1024 * 1024) >> EFI_PAGE_SHIFT,
635 &efi_bounce_buffer_addr) != EFI_SUCCESS)
636 return -1;
637
638 efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr;
639#endif
640
5d00995c
AG
641 return 0;
642}