blob: 24bc1d34cc51ab87953beeda40e2942522bcd9ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/kernel.h>
#include <linux/sizes.h>
#include <efi.h>
#include <efi/efi-payload.h>
#include <linux/pagemap.h>
efi_physical_addr_t efi_earlymem_alloc(const struct efi_system_table *sys_table,
size_t *memsize)
{
struct efi_boot_services *bs = sys_table->boottime;
efi_physical_addr_t mem;
efi_status_t efiret;
mem = IS_ENABLED(CONFIG_X86) ? 0x3fffffff : ~0ULL;
for (*memsize = SZ_256M; *memsize >= SZ_8M; *memsize /= 2) {
efiret = bs->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
EFI_LOADER_DATA,
*memsize/PAGE_SIZE, &mem);
if (!EFI_ERROR(efiret))
break;
if (efiret != EFI_OUT_OF_RESOURCES)
panic("failed to allocate malloc pool: %s\n",
efi_strerror(efiret));
}
if (EFI_ERROR(efiret))
panic("failed to allocate malloc pool: %s\n",
efi_strerror(efiret));
return mem;
}
|