blob: 2ddc3502b5df2a9adc22fbead14f64938f751e16 [file] [log] [blame]
Bin Meng2cfbdae2018-06-27 20:38:03 -07001// 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>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass367f00d2021-12-01 09:02:42 -070011#include <mapmem.h>
Simon Glass858fed12020-04-08 16:57:36 -060012#include <acpi/acpi_table.h>
Bin Meng2cfbdae2018-06-27 20:38:03 -070013
14static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
15
16/*
17 * Install the ACPI table as a configuration table.
18 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010019 * Return: status code
Bin Meng2cfbdae2018-06-27 20:38:03 -070020 */
21efi_status_t efi_acpi_register(void)
22{
23 /* Map within the low 32 bits, to allow for 32bit ACPI tables */
24 u64 acpi = U32_MAX;
25 efi_status_t ret;
Simon Glass367f00d2021-12-01 09:02:42 -070026 ulong addr;
Bin Meng2cfbdae2018-06-27 20:38:03 -070027
28 /* Reserve 64kiB page for ACPI */
29 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
Heinrich Schuchardtc462ae42021-02-21 10:16:58 +010030 EFI_ACPI_RECLAIM_MEMORY, 16, &acpi);
Bin Meng2cfbdae2018-06-27 20:38:03 -070031 if (ret != EFI_SUCCESS)
32 return ret;
33
34 /*
35 * Generate ACPI tables - we know that efi_allocate_pages() returns
36 * a 4k-aligned address, so it is safe to assume that
37 * write_acpi_tables() will write the table at that address.
38 */
Simon Glass367f00d2021-12-01 09:02:42 -070039 addr = map_to_sysmem((void *)(ulong)acpi);
40 write_acpi_tables(addr);
Bin Meng2cfbdae2018-06-27 20:38:03 -070041
42 /* And expose them to our EFI payload */
43 return efi_install_configuration_table(&acpi_guid,
44 (void *)(uintptr_t)acpi);
45}