aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efi/libstub/mem.c
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2020-03-27 16:09:40 +0100
committerArd Biesheuvel <ardb@kernel.org>2020-04-24 14:52:16 +0200
commit43b1df0e013c25abb536699f46d0e9f291b586a0 (patch)
treecc2415ae3b79cb9494824ba9a5ce1e7a25e39d5c /drivers/firmware/efi/libstub/mem.c
parentefi/libstub/arm64: Simplify randomized loading of kernel image (diff)
downloadlinux-dev-43b1df0e013c25abb536699f46d0e9f291b586a0.tar.xz
linux-dev-43b1df0e013c25abb536699f46d0e9f291b586a0.zip
efi/libstub: Add API function to allocate aligned memory
Break out the code to create an aligned page allocation from mem.c and move it into a function efi_allocate_pages_aligned() in alignedmem.c. Update efi_allocate_pages() to invoke it unless the minimum alignment equals the EFI page size (4 KB), in which case the ordinary page allocator is sufficient. This way, efi_allocate_pages_aligned() will only be pulled into the build if it is actually being used (which will be on arm64 only in the immediate future) Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Diffstat (limited to 'drivers/firmware/efi/libstub/mem.c')
-rw-r--r--drivers/firmware/efi/libstub/mem.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c
index 869a79c8946f..0020b0fa9587 100644
--- a/drivers/firmware/efi/libstub/mem.c
+++ b/drivers/firmware/efi/libstub/mem.c
@@ -93,31 +93,24 @@ fail:
efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
unsigned long max)
{
- efi_physical_addr_t alloc_addr = ALIGN_DOWN(max + 1, EFI_ALLOC_ALIGN) - 1;
- int slack = EFI_ALLOC_ALIGN / EFI_PAGE_SIZE - 1;
+ efi_physical_addr_t alloc_addr;
efi_status_t status;
- size = round_up(size, EFI_ALLOC_ALIGN);
+ if (EFI_ALLOC_ALIGN > EFI_PAGE_SIZE)
+ return efi_allocate_pages_aligned(size, addr, max,
+ EFI_ALLOC_ALIGN);
+
+ alloc_addr = ALIGN_DOWN(max + 1, EFI_ALLOC_ALIGN) - 1;
status = efi_bs_call(allocate_pages, EFI_ALLOCATE_MAX_ADDRESS,
- EFI_LOADER_DATA, size / EFI_PAGE_SIZE + slack,
+ EFI_LOADER_DATA, DIV_ROUND_UP(size, EFI_PAGE_SIZE),
&alloc_addr);
if (status != EFI_SUCCESS)
return status;
- *addr = ALIGN((unsigned long)alloc_addr, EFI_ALLOC_ALIGN);
-
- if (slack > 0) {
- int l = (alloc_addr % EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE;
-
- if (l) {
- efi_bs_call(free_pages, alloc_addr, slack - l + 1);
- slack = l - 1;
- }
- if (slack)
- efi_bs_call(free_pages, *addr + size, slack);
- }
+ *addr = alloc_addr;
return EFI_SUCCESS;
}
+
/**
* efi_low_alloc_above() - allocate pages at or above given address
* @size: size of the memory area to allocate