blob: ce29bcc6a3030d9260bb514c712908a62cd2ef34 [file] [log] [blame]
Tom Rini70df9d62018-05-07 17:02:21 -04001// SPDX-License-Identifier: GPL-2.0+
Alexander Graf8623f922016-03-04 01:10:04 +01002/*
3 * EFI application memory management
4 *
5 * Copyright (c) 2016 Alexander Graf
Alexander Graf8623f922016-03-04 01:10:04 +01006 */
7
Alexander Graf8623f922016-03-04 01:10:04 +01008#include <common.h>
9#include <efi_loader.h>
Simon Glass3e852172018-03-08 21:53:27 +010010#include <inttypes.h>
Alexander Graf8623f922016-03-04 01:10:04 +010011#include <malloc.h>
Simon Glass3e852172018-03-08 21:53:27 +010012#include <watchdog.h>
Alexander Grafde2a13b2016-03-30 16:38:29 +020013#include <linux/list_sort.h>
Alexander Graf8623f922016-03-04 01:10:04 +010014
15DECLARE_GLOBAL_DATA_PTR;
16
17struct efi_mem_list {
18 struct list_head link;
19 struct efi_mem_desc desc;
20};
21
Alexander Graf66d86232016-05-27 12:25:03 +020022#define EFI_CARVE_NO_OVERLAP -1
23#define EFI_CARVE_LOOP_AGAIN -2
24#define EFI_CARVE_OVERLAPS_NONRAM -3
25
Alexander Graf8623f922016-03-04 01:10:04 +010026/* This list contains all memory map items */
27LIST_HEAD(efi_mem);
28
Alexander Graf7c00a3c2016-05-11 18:25:48 +020029#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
30void *efi_bounce_buffer;
31#endif
32
Alexander Graf8623f922016-03-04 01:10:04 +010033/*
Stefan Brüns67b67d92016-10-09 22:17:26 +020034 * U-Boot services each EFI AllocatePool request as a separate
35 * (multiple) page allocation. We have to track the number of pages
36 * to be able to free the correct amount later.
37 * EFI requires 8 byte alignment for pool allocations, so we can
38 * prepend each allocation with an 64 bit header tracking the
39 * allocation size, and hand out the remainder to the caller.
40 */
41struct efi_pool_allocation {
42 u64 num_pages;
Rob Clarke597fd42017-09-13 18:05:36 -040043 char data[] __aligned(ARCH_DMA_MINALIGN);
Stefan Brüns67b67d92016-10-09 22:17:26 +020044};
45
46/*
Alexander Grafde2a13b2016-03-30 16:38:29 +020047 * Sorts the memory list from highest address to lowest address
48 *
49 * When allocating memory we should always start from the highest
50 * address chunk, so sort the memory list such that the first list
51 * iterator gets the highest address and goes lower from there.
52 */
53static int efi_mem_cmp(void *priv, struct list_head *a, struct list_head *b)
54{
55 struct efi_mem_list *mema = list_entry(a, struct efi_mem_list, link);
56 struct efi_mem_list *memb = list_entry(b, struct efi_mem_list, link);
57
58 if (mema->desc.physical_start == memb->desc.physical_start)
59 return 0;
60 else if (mema->desc.physical_start < memb->desc.physical_start)
61 return 1;
62 else
63 return -1;
64}
65
66static void efi_mem_sort(void)
67{
68 list_sort(NULL, &efi_mem, efi_mem_cmp);
69}
70
Heinrich Schuchardtf00caa52018-05-27 16:45:09 +020071/** efi_mem_carve_out - unmap memory region
Alexander Graf8623f922016-03-04 01:10:04 +010072 *
Heinrich Schuchardtf00caa52018-05-27 16:45:09 +020073 * @map: memory map
74 * @carve_desc: memory region to unmap
75 * @overlap_only_ram: the carved out region may only overlap RAM
76 * Return Value: the number of overlapping pages which have been
77 * removed from the map,
78 * EFI_CARVE_NO_OVERLAP, if the regions don't overlap,
79 * EFI_CARVE_OVERLAPS_NONRAM, if the carve and map overlap,
80 * and the map contains anything but free ram
81 * (only when overlap_only_ram is true),
82 * EFI_CARVE_LOOP_AGAIN, if the mapping list should be
83 * traversed again, as it has been altered.
84 *
85 * Unmaps all memory occupied by the carve_desc region from the list entry
86 * pointed to by map.
Stefan Brüns1b00dc12016-10-01 23:32:23 +020087 *
88 * In case of EFI_CARVE_OVERLAPS_NONRAM it is the callers responsibility
Heinrich Schuchardtf00caa52018-05-27 16:45:09 +020089 * to re-add the already carved out pages to the mapping.
Alexander Graf8623f922016-03-04 01:10:04 +010090 */
Heinrich Schuchardtf00caa52018-05-27 16:45:09 +020091static s64 efi_mem_carve_out(struct efi_mem_list *map,
Alexander Graf8623f922016-03-04 01:10:04 +010092 struct efi_mem_desc *carve_desc,
93 bool overlap_only_ram)
94{
95 struct efi_mem_list *newmap;
96 struct efi_mem_desc *map_desc = &map->desc;
97 uint64_t map_start = map_desc->physical_start;
98 uint64_t map_end = map_start + (map_desc->num_pages << EFI_PAGE_SHIFT);
99 uint64_t carve_start = carve_desc->physical_start;
100 uint64_t carve_end = carve_start +
101 (carve_desc->num_pages << EFI_PAGE_SHIFT);
102
103 /* check whether we're overlapping */
104 if ((carve_end <= map_start) || (carve_start >= map_end))
Alexander Graf66d86232016-05-27 12:25:03 +0200105 return EFI_CARVE_NO_OVERLAP;
Alexander Graf8623f922016-03-04 01:10:04 +0100106
107 /* We're overlapping with non-RAM, warn the caller if desired */
108 if (overlap_only_ram && (map_desc->type != EFI_CONVENTIONAL_MEMORY))
Alexander Graf66d86232016-05-27 12:25:03 +0200109 return EFI_CARVE_OVERLAPS_NONRAM;
Alexander Graf8623f922016-03-04 01:10:04 +0100110
111 /* Sanitize carve_start and carve_end to lie within our bounds */
112 carve_start = max(carve_start, map_start);
113 carve_end = min(carve_end, map_end);
114
115 /* Carving at the beginning of our map? Just move it! */
116 if (carve_start == map_start) {
117 if (map_end == carve_end) {
118 /* Full overlap, just remove map */
119 list_del(&map->link);
Stefan Brüns4e9ad8d2016-10-01 23:32:29 +0200120 free(map);
121 } else {
122 map->desc.physical_start = carve_end;
123 map->desc.num_pages = (map_end - carve_end)
124 >> EFI_PAGE_SHIFT;
Alexander Graf8623f922016-03-04 01:10:04 +0100125 }
126
Alexander Graf66d86232016-05-27 12:25:03 +0200127 return (carve_end - carve_start) >> EFI_PAGE_SHIFT;
Alexander Graf8623f922016-03-04 01:10:04 +0100128 }
129
130 /*
131 * Overlapping maps, just split the list map at carve_start,
132 * it will get moved or removed in the next iteration.
133 *
134 * [ map_desc |__carve_start__| newmap ]
135 */
136
137 /* Create a new map from [ carve_start ... map_end ] */
138 newmap = calloc(1, sizeof(*newmap));
139 newmap->desc = map->desc;
140 newmap->desc.physical_start = carve_start;
141 newmap->desc.num_pages = (map_end - carve_start) >> EFI_PAGE_SHIFT;
Stefan Brüns9d656512016-10-01 23:32:28 +0200142 /* Insert before current entry (descending address order) */
143 list_add_tail(&newmap->link, &map->link);
Alexander Graf8623f922016-03-04 01:10:04 +0100144
145 /* Shrink the map to [ map_start ... carve_start ] */
146 map_desc->num_pages = (carve_start - map_start) >> EFI_PAGE_SHIFT;
147
Alexander Graf66d86232016-05-27 12:25:03 +0200148 return EFI_CARVE_LOOP_AGAIN;
Alexander Graf8623f922016-03-04 01:10:04 +0100149}
150
151uint64_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type,
152 bool overlap_only_ram)
153{
154 struct list_head *lhandle;
155 struct efi_mem_list *newlist;
Alexander Graf66d86232016-05-27 12:25:03 +0200156 bool carve_again;
157 uint64_t carved_pages = 0;
Alexander Graf8623f922016-03-04 01:10:04 +0100158
Andreas Färber102f8bd2016-07-17 06:57:11 +0200159 debug("%s: 0x%" PRIx64 " 0x%" PRIx64 " %d %s\n", __func__,
160 start, pages, memory_type, overlap_only_ram ? "yes" : "no");
161
Alexander Graf8623f922016-03-04 01:10:04 +0100162 if (!pages)
163 return start;
164
165 newlist = calloc(1, sizeof(*newlist));
166 newlist->desc.type = memory_type;
167 newlist->desc.physical_start = start;
168 newlist->desc.virtual_start = start;
169 newlist->desc.num_pages = pages;
170
171 switch (memory_type) {
172 case EFI_RUNTIME_SERVICES_CODE:
173 case EFI_RUNTIME_SERVICES_DATA:
174 newlist->desc.attribute = (1 << EFI_MEMORY_WB_SHIFT) |
175 (1ULL << EFI_MEMORY_RUNTIME_SHIFT);
176 break;
177 case EFI_MMAP_IO:
178 newlist->desc.attribute = 1ULL << EFI_MEMORY_RUNTIME_SHIFT;
179 break;
180 default:
181 newlist->desc.attribute = 1 << EFI_MEMORY_WB_SHIFT;
182 break;
183 }
184
185 /* Add our new map */
186 do {
Alexander Graf66d86232016-05-27 12:25:03 +0200187 carve_again = false;
Alexander Graf8623f922016-03-04 01:10:04 +0100188 list_for_each(lhandle, &efi_mem) {
189 struct efi_mem_list *lmem;
Heinrich Schuchardtf00caa52018-05-27 16:45:09 +0200190 s64 r;
Alexander Graf8623f922016-03-04 01:10:04 +0100191
192 lmem = list_entry(lhandle, struct efi_mem_list, link);
193 r = efi_mem_carve_out(lmem, &newlist->desc,
194 overlap_only_ram);
Alexander Graf66d86232016-05-27 12:25:03 +0200195 switch (r) {
196 case EFI_CARVE_OVERLAPS_NONRAM:
197 /*
198 * The user requested to only have RAM overlaps,
199 * but we hit a non-RAM region. Error out.
200 */
Alexander Graf8623f922016-03-04 01:10:04 +0100201 return 0;
Alexander Graf66d86232016-05-27 12:25:03 +0200202 case EFI_CARVE_NO_OVERLAP:
203 /* Just ignore this list entry */
204 break;
205 case EFI_CARVE_LOOP_AGAIN:
206 /*
207 * We split an entry, but need to loop through
208 * the list again to actually carve it.
209 */
210 carve_again = true;
211 break;
212 default:
213 /* We carved a number of pages */
214 carved_pages += r;
215 carve_again = true;
Alexander Graf8623f922016-03-04 01:10:04 +0100216 break;
217 }
Alexander Graf66d86232016-05-27 12:25:03 +0200218
219 if (carve_again) {
220 /* The list changed, we need to start over */
221 break;
222 }
Alexander Graf8623f922016-03-04 01:10:04 +0100223 }
Alexander Graf66d86232016-05-27 12:25:03 +0200224 } while (carve_again);
225
226 if (overlap_only_ram && (carved_pages != pages)) {
227 /*
228 * The payload wanted to have RAM overlaps, but we overlapped
229 * with an unallocated region. Error out.
230 */
231 return 0;
232 }
Alexander Graf8623f922016-03-04 01:10:04 +0100233
234 /* Add our new map */
235 list_add_tail(&newlist->link, &efi_mem);
236
Alexander Grafde2a13b2016-03-30 16:38:29 +0200237 /* And make sure memory is listed in descending order */
238 efi_mem_sort();
239
Alexander Graf8623f922016-03-04 01:10:04 +0100240 return start;
241}
242
243static uint64_t efi_find_free_memory(uint64_t len, uint64_t max_addr)
244{
245 struct list_head *lhandle;
246
247 list_for_each(lhandle, &efi_mem) {
248 struct efi_mem_list *lmem = list_entry(lhandle,
249 struct efi_mem_list, link);
250 struct efi_mem_desc *desc = &lmem->desc;
251 uint64_t desc_len = desc->num_pages << EFI_PAGE_SHIFT;
252 uint64_t desc_end = desc->physical_start + desc_len;
253 uint64_t curmax = min(max_addr, desc_end);
254 uint64_t ret = curmax - len;
255
256 /* We only take memory from free RAM */
257 if (desc->type != EFI_CONVENTIONAL_MEMORY)
258 continue;
259
260 /* Out of bounds for max_addr */
261 if ((ret + len) > max_addr)
262 continue;
263
264 /* Out of bounds for upper map limit */
265 if ((ret + len) > desc_end)
266 continue;
267
268 /* Out of bounds for lower map limit */
269 if (ret < desc->physical_start)
270 continue;
271
272 /* Return the highest address in this map within bounds */
273 return ret;
274 }
275
276 return 0;
277}
278
Heinrich Schuchardt1b32cae2017-12-04 20:52:41 +0100279/*
280 * Allocate memory pages.
281 *
282 * @type type of allocation to be performed
283 * @memory_type usage type of the allocated memory
284 * @pages number of pages to be allocated
285 * @memory allocated memory
286 * @return status code
287 */
Alexander Graf8623f922016-03-04 01:10:04 +0100288efi_status_t efi_allocate_pages(int type, int memory_type,
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100289 efi_uintn_t pages, uint64_t *memory)
Alexander Graf8623f922016-03-04 01:10:04 +0100290{
291 u64 len = pages << EFI_PAGE_SHIFT;
292 efi_status_t r = EFI_SUCCESS;
293 uint64_t addr;
294
295 switch (type) {
Heinrich Schuchardt3b7b3b62018-01-30 21:08:00 +0100296 case EFI_ALLOCATE_ANY_PAGES:
Alexander Graf8623f922016-03-04 01:10:04 +0100297 /* Any page */
Heinrich Schuchardt55076982018-06-18 17:23:02 +0200298 addr = efi_find_free_memory(len, -1ULL);
Alexander Graf8623f922016-03-04 01:10:04 +0100299 if (!addr) {
300 r = EFI_NOT_FOUND;
301 break;
302 }
303 break;
Heinrich Schuchardt3b7b3b62018-01-30 21:08:00 +0100304 case EFI_ALLOCATE_MAX_ADDRESS:
Alexander Graf8623f922016-03-04 01:10:04 +0100305 /* Max address */
306 addr = efi_find_free_memory(len, *memory);
307 if (!addr) {
308 r = EFI_NOT_FOUND;
309 break;
310 }
311 break;
Heinrich Schuchardt3b7b3b62018-01-30 21:08:00 +0100312 case EFI_ALLOCATE_ADDRESS:
Alexander Graf8623f922016-03-04 01:10:04 +0100313 /* Exact address, reserve it. The addr is already in *memory. */
314 addr = *memory;
315 break;
316 default:
317 /* UEFI doesn't specify other allocation types */
318 r = EFI_INVALID_PARAMETER;
319 break;
320 }
321
322 if (r == EFI_SUCCESS) {
323 uint64_t ret;
324
325 /* Reserve that map in our memory maps */
326 ret = efi_add_memory_map(addr, pages, memory_type, true);
327 if (ret == addr) {
328 *memory = addr;
329 } else {
330 /* Map would overlap, bail out */
331 r = EFI_OUT_OF_RESOURCES;
332 }
333 }
334
335 return r;
336}
337
338void *efi_alloc(uint64_t len, int memory_type)
339{
340 uint64_t ret = 0;
341 uint64_t pages = (len + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
342 efi_status_t r;
343
Heinrich Schuchardt0f7186b2018-05-26 10:32:27 +0200344 r = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, memory_type, pages,
345 &ret);
Alexander Graf8623f922016-03-04 01:10:04 +0100346 if (r == EFI_SUCCESS)
347 return (void*)(uintptr_t)ret;
348
349 return NULL;
350}
351
Heinrich Schuchardt1b32cae2017-12-04 20:52:41 +0100352/*
353 * Free memory pages.
354 *
355 * @memory start of the memory area to be freed
356 * @pages number of pages to be freed
357 * @return status code
358 */
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100359efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages)
Alexander Graf8623f922016-03-04 01:10:04 +0100360{
Stefan Brünsa4f43022016-10-01 23:32:27 +0200361 uint64_t r = 0;
362
363 r = efi_add_memory_map(memory, pages, EFI_CONVENTIONAL_MEMORY, false);
364 /* Merging of adjacent free regions is missing */
365
366 if (r == memory)
367 return EFI_SUCCESS;
368
369 return EFI_NOT_FOUND;
Alexander Graf8623f922016-03-04 01:10:04 +0100370}
371
Heinrich Schuchardt1b32cae2017-12-04 20:52:41 +0100372/*
373 * Allocate memory from pool.
374 *
375 * @pool_type type of the pool from which memory is to be allocated
376 * @size number of bytes to be allocated
377 * @buffer allocated memory
378 * @return status code
379 */
380efi_status_t efi_allocate_pool(int pool_type, efi_uintn_t size, void **buffer)
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200381{
382 efi_status_t r;
383 efi_physical_addr_t t;
Rob Clarke597fd42017-09-13 18:05:36 -0400384 u64 num_pages = (size + sizeof(struct efi_pool_allocation) +
385 EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
Stefan Brüns67b67d92016-10-09 22:17:26 +0200386
387 if (size == 0) {
388 *buffer = NULL;
389 return EFI_SUCCESS;
390 }
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200391
Heinrich Schuchardt0f7186b2018-05-26 10:32:27 +0200392 r = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, pool_type, num_pages,
393 &t);
Stefan Brüns67b67d92016-10-09 22:17:26 +0200394
395 if (r == EFI_SUCCESS) {
396 struct efi_pool_allocation *alloc = (void *)(uintptr_t)t;
397 alloc->num_pages = num_pages;
398 *buffer = alloc->data;
399 }
400
401 return r;
402}
403
Heinrich Schuchardt1b32cae2017-12-04 20:52:41 +0100404/*
405 * Free memory from pool.
406 *
407 * @buffer start of memory to be freed
408 * @return status code
409 */
Stefan Brüns67b67d92016-10-09 22:17:26 +0200410efi_status_t efi_free_pool(void *buffer)
411{
412 efi_status_t r;
413 struct efi_pool_allocation *alloc;
414
xypron.glpk@gmx.de34ddae72017-07-14 19:12:39 +0200415 if (buffer == NULL)
416 return EFI_INVALID_PARAMETER;
417
Stefan Brüns67b67d92016-10-09 22:17:26 +0200418 alloc = container_of(buffer, struct efi_pool_allocation, data);
419 /* Sanity check, was the supplied address returned by allocate_pool */
420 assert(((uintptr_t)alloc & EFI_PAGE_MASK) == 0);
421
422 r = efi_free_pages((uintptr_t)alloc, alloc->num_pages);
Stefan Brüns5a09aef2016-10-09 22:17:18 +0200423
424 return r;
425}
426
Heinrich Schuchardt1b32cae2017-12-04 20:52:41 +0100427/*
428 * Get map describing memory usage.
429 *
430 * @memory_map_size on entry the size, in bytes, of the memory map buffer,
431 * on exit the size of the copied memory map
432 * @memory_map buffer to which the memory map is written
433 * @map_key key for the memory map
434 * @descriptor_size size of an individual memory descriptor
435 * @descriptor_version version number of the memory descriptor structure
436 * @return status code
437 */
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100438efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
439 struct efi_mem_desc *memory_map,
440 efi_uintn_t *map_key,
441 efi_uintn_t *descriptor_size,
442 uint32_t *descriptor_version)
Alexander Graf8623f922016-03-04 01:10:04 +0100443{
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100444 efi_uintn_t map_size = 0;
Alexander Graf9b591022016-04-11 23:51:02 +0200445 int map_entries = 0;
Alexander Graf8623f922016-03-04 01:10:04 +0100446 struct list_head *lhandle;
Heinrich Schuchardt798a4412017-11-06 21:17:48 +0100447 efi_uintn_t provided_map_size = *memory_map_size;
Alexander Graf8623f922016-03-04 01:10:04 +0100448
449 list_for_each(lhandle, &efi_mem)
Alexander Graf9b591022016-04-11 23:51:02 +0200450 map_entries++;
451
452 map_size = map_entries * sizeof(struct efi_mem_desc);
Alexander Graf8623f922016-03-04 01:10:04 +0100453
Rob Clarka84c9742017-07-26 14:34:05 -0400454 *memory_map_size = map_size;
455
xypron.glpk@gmx.de5487ab52017-07-21 19:04:33 +0200456 if (provided_map_size < map_size)
457 return EFI_BUFFER_TOO_SMALL;
458
Alexander Graf8623f922016-03-04 01:10:04 +0100459 if (descriptor_size)
460 *descriptor_size = sizeof(struct efi_mem_desc);
461
Mian Yousaf Kaukab338cf562016-09-05 23:59:22 +0200462 if (descriptor_version)
463 *descriptor_version = EFI_MEMORY_DESCRIPTOR_VERSION;
464
Alexander Graf8623f922016-03-04 01:10:04 +0100465 /* Copy list into array */
466 if (memory_map) {
Alexander Graf9b591022016-04-11 23:51:02 +0200467 /* Return the list in ascending order */
468 memory_map = &memory_map[map_entries - 1];
Alexander Graf8623f922016-03-04 01:10:04 +0100469 list_for_each(lhandle, &efi_mem) {
470 struct efi_mem_list *lmem;
471
472 lmem = list_entry(lhandle, struct efi_mem_list, link);
473 *memory_map = lmem->desc;
Alexander Graf9b591022016-04-11 23:51:02 +0200474 memory_map--;
Alexander Graf8623f922016-03-04 01:10:04 +0100475 }
476 }
477
xypron.glpk@gmx.dee436e632017-07-21 19:05:44 +0200478 *map_key = 0;
479
Alexander Graf8623f922016-03-04 01:10:04 +0100480 return EFI_SUCCESS;
481}
482
York Suna8e9f0a2017-03-06 09:02:27 -0800483__weak void efi_add_known_memory(void)
Alexander Graf8623f922016-03-04 01:10:04 +0100484{
Alexander Graf8623f922016-03-04 01:10:04 +0100485 int i;
486
487 /* Add RAM */
488 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
489 u64 ram_start = gd->bd->bi_dram[i].start;
490 u64 ram_size = gd->bd->bi_dram[i].size;
491 u64 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
492 u64 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
493
494 efi_add_memory_map(start, pages, EFI_CONVENTIONAL_MEMORY,
495 false);
496 }
York Suna8e9f0a2017-03-06 09:02:27 -0800497}
498
499int efi_memory_init(void)
500{
501 unsigned long runtime_start, runtime_end, runtime_pages;
502 unsigned long uboot_start, uboot_pages;
503 unsigned long uboot_stack_size = 16 * 1024 * 1024;
504
505 efi_add_known_memory();
Alexander Graf8623f922016-03-04 01:10:04 +0100506
507 /* Add U-Boot */
508 uboot_start = (gd->start_addr_sp - uboot_stack_size) & ~EFI_PAGE_MASK;
509 uboot_pages = (gd->ram_top - uboot_start) >> EFI_PAGE_SHIFT;
510 efi_add_memory_map(uboot_start, uboot_pages, EFI_LOADER_DATA, false);
511
512 /* Add Runtime Services */
513 runtime_start = (ulong)&__efi_runtime_start & ~EFI_PAGE_MASK;
514 runtime_end = (ulong)&__efi_runtime_stop;
515 runtime_end = (runtime_end + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
516 runtime_pages = (runtime_end - runtime_start) >> EFI_PAGE_SHIFT;
517 efi_add_memory_map(runtime_start, runtime_pages,
518 EFI_RUNTIME_SERVICES_CODE, false);
519
Alexander Graf7c00a3c2016-05-11 18:25:48 +0200520#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
521 /* Request a 32bit 64MB bounce buffer region */
522 uint64_t efi_bounce_buffer_addr = 0xffffffff;
523
Heinrich Schuchardt0f7186b2018-05-26 10:32:27 +0200524 if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, EFI_LOADER_DATA,
Alexander Graf7c00a3c2016-05-11 18:25:48 +0200525 (64 * 1024 * 1024) >> EFI_PAGE_SHIFT,
526 &efi_bounce_buffer_addr) != EFI_SUCCESS)
527 return -1;
528
529 efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr;
530#endif
531
Alexander Graf8623f922016-03-04 01:10:04 +0100532 return 0;
533}