Commit d2392df7 authored by Leif Lindholm's avatar Leif Lindholm Committed by Colin Watson

efi: refactor grub_efi_allocate_pages

Expose a new function, grub_efi_allocate_pages_real(), making it possible
to specify allocation type and memory type as supported by the UEFI
AllocatePages boot service.

Make grub_efi_allocate_pages() a consumer of the new function,
maintaining its old functionality.

Also delete some left-around #if 1/#else blocks in the affected
functions.
Signed-off-by: 's avatarLeif Lindholm <leif.lindholm@linaro.org>

Origin: upstream, https://git.savannah.gnu.org/cgit/grub.git/commit/?id=dd5fde2df83c5c03b7ba04d2cc5b7be96de8da7b
Bug-Debian: https://bugs.debian.org/907596
Bug-Debian: https://bugs.debian.org/909420
Last-Update: 2018-12-06

Patch-Name: efi-refactor-grub_efi_allocate_pages.patch
parent 68d1db98
......@@ -83,36 +83,20 @@ grub_efi_allocate_pages_max (grub_efi_physical_address_t max,
/* Allocate pages. Return the pointer to the first of allocated pages. */
void *
grub_efi_allocate_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
grub_efi_uintn_t pages,
grub_efi_allocate_type_t alloctype,
grub_efi_memory_type_t memtype)
{
grub_efi_allocate_type_t type;
grub_efi_status_t status;
grub_efi_boot_services_t *b;
#if 1
/* Limit the memory access to less than 4GB for 32-bit platforms. */
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
return 0;
#endif
#if 1
if (address == 0)
{
type = GRUB_EFI_ALLOCATE_MAX_ADDRESS;
address = GRUB_EFI_MAX_USABLE_ADDRESS;
}
else
type = GRUB_EFI_ALLOCATE_ADDRESS;
#else
if (address == 0)
type = GRUB_EFI_ALLOCATE_ANY_PAGES;
else
type = GRUB_EFI_ALLOCATE_ADDRESS;
#endif
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address);
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
if (status != GRUB_EFI_SUCCESS)
return 0;
......@@ -121,7 +105,7 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,
/* Uggh, the address 0 was allocated... This is too annoying,
so reallocate another one. */
address = GRUB_EFI_MAX_USABLE_ADDRESS;
status = efi_call_4 (b->allocate_pages, type, GRUB_EFI_LOADER_DATA, pages, &address);
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
grub_efi_free_pages (0, pages);
if (status != GRUB_EFI_SUCCESS)
return 0;
......@@ -130,6 +114,24 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,
return (void *) ((grub_addr_t) address);
}
void *
grub_efi_allocate_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
grub_efi_allocate_type_t alloctype;
if (address == 0)
{
alloctype = GRUB_EFI_ALLOCATE_MAX_ADDRESS;
address = GRUB_EFI_MAX_USABLE_ADDRESS;
}
else
alloctype = GRUB_EFI_ALLOCATE_ADDRESS;
return grub_efi_allocate_pages_real (address, pages, alloctype,
GRUB_EFI_LOADER_DATA);
}
/* Free pages starting from ADDRESS. */
void
grub_efi_free_pages (grub_efi_physical_address_t address,
......
......@@ -38,6 +38,11 @@ void *EXPORT_FUNC(grub_efi_open_protocol) (grub_efi_handle_t handle,
int EXPORT_FUNC(grub_efi_set_text_mode) (int on);
void EXPORT_FUNC(grub_efi_stall) (grub_efi_uintn_t microseconds);
void *
EXPORT_FUNC(grub_efi_allocate_pages_real) (grub_efi_physical_address_t address,
grub_efi_uintn_t pages,
grub_efi_allocate_type_t alloctype,
grub_efi_memory_type_t memtype);
void *
EXPORT_FUNC(grub_efi_allocate_pages) (grub_efi_physical_address_t address,
grub_efi_uintn_t pages);
void *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment