Bin Meng | 2cfbdae | 2018-06-27 20:38:03 -0700 | [diff] [blame] | 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> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 367f00d | 2021-12-01 09:02:42 -0700 | [diff] [blame] | 11 | #include <mapmem.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 12 | #include <acpi/acpi_table.h> |
Bin Meng | 2cfbdae | 2018-06-27 20:38:03 -0700 | [diff] [blame] | 13 | |
| 14 | static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID; |
| 15 | |
| 16 | /* |
| 17 | * Install the ACPI table as a configuration table. |
| 18 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 19 | * Return: status code |
Bin Meng | 2cfbdae | 2018-06-27 20:38:03 -0700 | [diff] [blame] | 20 | */ |
| 21 | efi_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 Glass | 367f00d | 2021-12-01 09:02:42 -0700 | [diff] [blame] | 26 | ulong addr; |
Bin Meng | 2cfbdae | 2018-06-27 20:38:03 -0700 | [diff] [blame] | 27 | |
| 28 | /* Reserve 64kiB page for ACPI */ |
| 29 | ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, |
Heinrich Schuchardt | c462ae4 | 2021-02-21 10:16:58 +0100 | [diff] [blame] | 30 | EFI_ACPI_RECLAIM_MEMORY, 16, &acpi); |
Bin Meng | 2cfbdae | 2018-06-27 20:38:03 -0700 | [diff] [blame] | 31 | 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 Glass | 367f00d | 2021-12-01 09:02:42 -0700 | [diff] [blame] | 39 | addr = map_to_sysmem((void *)(ulong)acpi); |
| 40 | write_acpi_tables(addr); |
Bin Meng | 2cfbdae | 2018-06-27 20:38:03 -0700 | [diff] [blame] | 41 | |
| 42 | /* And expose them to our EFI payload */ |
| 43 | return efi_install_configuration_table(&acpi_guid, |
| 44 | (void *)(uintptr_t)acpi); |
| 45 | } |