xref: /openbmc/u-boot/lib/efi_loader/efi_acpi.c (revision afaea1f5)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  EFI application ACPI tables support
4  *
5  *  Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
6  */
7 
8 #include <common.h>
9 #include <efi_loader.h>
10 #include <asm/acpi_table.h>
11 
12 static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
13 
14 /*
15  * Install the ACPI table as a configuration table.
16  *
17  * @return	status code
18  */
19 efi_status_t efi_acpi_register(void)
20 {
21 	/* Map within the low 32 bits, to allow for 32bit ACPI tables */
22 	u64 acpi = U32_MAX;
23 	efi_status_t ret;
24 
25 	/* Reserve 64kiB page for ACPI */
26 	ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
27 				 EFI_RUNTIME_SERVICES_DATA, 16, &acpi);
28 	if (ret != EFI_SUCCESS)
29 		return ret;
30 
31 	/*
32 	 * Generate ACPI tables - we know that efi_allocate_pages() returns
33 	 * a 4k-aligned address, so it is safe to assume that
34 	 * write_acpi_tables() will write the table at that address.
35 	 */
36 	assert(!(acpi & 0xf));
37 	write_acpi_tables(acpi);
38 
39 	/* And expose them to our EFI payload */
40 	return efi_install_configuration_table(&acpi_guid,
41 					       (void *)(uintptr_t)acpi);
42 }
43