aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2014-11-17 07:46:44 -0500
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2015-01-12 03:17:00 -0500
commitcf2b0f102cdf912eedb87b10271fa0ad582cf2c1 (patch)
tree0ca4f7122012289593bb8cb12eed4d3bbd8ce98e /drivers/firmware
parent7bb68410ef22067b08fd52887875b8f337f89dcc (diff)
efi: efistub: allow allocation alignment larger than EFI_PAGE_SIZE
On systems with 64 KB pages, it is preferable for UEFI memory map entries to be 64 KB aligned multiples of 64 KB, because it relieves us of having to deal with the residues. So, if EFI_ALLOC_ALIGN is #define'd by the platform, use it to round up all memory allocations made. Acked-by: Matt Fleming <matt.fleming@intel.com> Acked-by: Borislav Petkov <bp@suse.de> Tested-by: Leif Lindholm <leif.lindholm@linaro.org> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Diffstat (limited to 'drivers/firmware')
-rw-r--r--drivers/firmware/efi/libstub/efi-stub-helper.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index a920fec8fe88..e766df60fbfb 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -32,6 +32,15 @@
32 32
33static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE; 33static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE;
34 34
35/*
36 * Allow the platform to override the allocation granularity: this allows
37 * systems that have the capability to run with a larger page size to deal
38 * with the allocations for initrd and fdt more efficiently.
39 */
40#ifndef EFI_ALLOC_ALIGN
41#define EFI_ALLOC_ALIGN EFI_PAGE_SIZE
42#endif
43
35struct file_info { 44struct file_info {
36 efi_file_handle_t *handle; 45 efi_file_handle_t *handle;
37 u64 size; 46 u64 size;
@@ -150,10 +159,10 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
150 * a specific address. We are doing page-based allocations, 159 * a specific address. We are doing page-based allocations,
151 * so we must be aligned to a page. 160 * so we must be aligned to a page.
152 */ 161 */
153 if (align < EFI_PAGE_SIZE) 162 if (align < EFI_ALLOC_ALIGN)
154 align = EFI_PAGE_SIZE; 163 align = EFI_ALLOC_ALIGN;
155 164
156 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 165 nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE;
157again: 166again:
158 for (i = 0; i < map_size / desc_size; i++) { 167 for (i = 0; i < map_size / desc_size; i++) {
159 efi_memory_desc_t *desc; 168 efi_memory_desc_t *desc;
@@ -235,10 +244,10 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
235 * a specific address. We are doing page-based allocations, 244 * a specific address. We are doing page-based allocations,
236 * so we must be aligned to a page. 245 * so we must be aligned to a page.
237 */ 246 */
238 if (align < EFI_PAGE_SIZE) 247 if (align < EFI_ALLOC_ALIGN)
239 align = EFI_PAGE_SIZE; 248 align = EFI_ALLOC_ALIGN;
240 249
241 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 250 nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE;
242 for (i = 0; i < map_size / desc_size; i++) { 251 for (i = 0; i < map_size / desc_size; i++) {
243 efi_memory_desc_t *desc; 252 efi_memory_desc_t *desc;
244 unsigned long m = (unsigned long)map; 253 unsigned long m = (unsigned long)map;
@@ -292,7 +301,7 @@ void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
292 if (!size) 301 if (!size)
293 return; 302 return;
294 303
295 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 304 nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE;
296 efi_call_early(free_pages, addr, nr_pages); 305 efi_call_early(free_pages, addr, nr_pages);
297} 306}
298 307
@@ -561,7 +570,7 @@ efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
561 * to the preferred address. If that fails, allocate as low 570 * to the preferred address. If that fails, allocate as low
562 * as possible while respecting the required alignment. 571 * as possible while respecting the required alignment.
563 */ 572 */
564 nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 573 nr_pages = round_up(alloc_size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE;
565 status = efi_call_early(allocate_pages, 574 status = efi_call_early(allocate_pages,
566 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 575 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
567 nr_pages, &efi_addr); 576 nr_pages, &efi_addr);