blob: 4422b31ac6a7af1fdd317c57e53ff79344149d4e [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
Heinrich Schuchardt955a3212025-01-16 20:26:59 +01008#define LOG_CATEGORY LOGC_EFI
9
Bin Meng2cfbdae2018-06-27 20:38:03 -070010#include <efi_loader.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass367f00d2021-12-01 09:02:42 -070012#include <mapmem.h>
Simon Glass858fed12020-04-08 16:57:36 -060013#include <acpi/acpi_table.h>
Simon Glass8965f292023-07-15 21:39:17 -060014#include <asm/global_data.h>
15
16DECLARE_GLOBAL_DATA_PTR;
Bin Meng2cfbdae2018-06-27 20:38:03 -070017
18static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
19
20/*
21 * Install the ACPI table as a configuration table.
22 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010023 * Return: status code
Bin Meng2cfbdae2018-06-27 20:38:03 -070024 */
25efi_status_t efi_acpi_register(void)
26{
Simon Glass8965f292023-07-15 21:39:17 -060027 ulong addr, start, end;
Bin Meng2cfbdae2018-06-27 20:38:03 -070028 efi_status_t ret;
29
Simon Glassd7d7a032025-01-10 17:00:25 -070030 /*
31 * The bloblist is already marked reserved. For now, we don't bother
32 * marking it with EFI_ACPI_RECLAIM_MEMORY since we would need to cut a
33 * hole in the EFI_BOOT_SERVICES_CODE region added by
34 * add_u_boot_and_runtime(). At some point that function could create a
35 * more detailed map.
36 */
37 if (IS_ENABLED(CONFIG_BLOBLIST_TABLES))
38 return EFI_SUCCESS;
39
Simon Glass8965f292023-07-15 21:39:17 -060040 /* Mark space used for tables */
41 start = ALIGN_DOWN(gd->arch.table_start, EFI_PAGE_MASK);
42 end = ALIGN(gd->arch.table_end, EFI_PAGE_MASK);
43 ret = efi_add_memory_map(start, end - start, EFI_ACPI_RECLAIM_MEMORY);
Bin Meng2cfbdae2018-06-27 20:38:03 -070044 if (ret != EFI_SUCCESS)
45 return ret;
Simon Glass8965f292023-07-15 21:39:17 -060046 if (gd->arch.table_start_high) {
47 start = ALIGN_DOWN(gd->arch.table_start_high, EFI_PAGE_MASK);
48 end = ALIGN(gd->arch.table_end_high, EFI_PAGE_MASK);
49 ret = efi_add_memory_map(start, end - start,
50 EFI_ACPI_RECLAIM_MEMORY);
51 if (ret != EFI_SUCCESS)
52 return ret;
53 }
Bin Meng2cfbdae2018-06-27 20:38:03 -070054
Simon Glass8965f292023-07-15 21:39:17 -060055 addr = gd_acpi_start();
Heinrich Schuchardt3b56ffd2024-04-09 22:48:24 +020056 log_debug("EFI using ACPI tables at %lx\n", addr);
Bin Meng2cfbdae2018-06-27 20:38:03 -070057
58 /* And expose them to our EFI payload */
59 return efi_install_configuration_table(&acpi_guid,
Simon Glass8965f292023-07-15 21:39:17 -060060 (void *)(ulong)addr);
Bin Meng2cfbdae2018-06-27 20:38:03 -070061}