blob: 046986a75188532495db127d930225784ac8dc7d [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
Simon Glassa0b45f42025-03-06 07:31:24 -070010#include <bloblist.h>
Bin Meng2cfbdae2018-06-27 20:38:03 -070011#include <efi_loader.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass367f00d2021-12-01 09:02:42 -070013#include <mapmem.h>
Simon Glass858fed12020-04-08 16:57:36 -060014#include <acpi/acpi_table.h>
Simon Glass8965f292023-07-15 21:39:17 -060015#include <asm/global_data.h>
16
17DECLARE_GLOBAL_DATA_PTR;
Bin Meng2cfbdae2018-06-27 20:38:03 -070018
19static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
20
21/*
22 * Install the ACPI table as a configuration table.
23 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010024 * Return: status code
Bin Meng2cfbdae2018-06-27 20:38:03 -070025 */
26efi_status_t efi_acpi_register(void)
27{
Simon Glass8965f292023-07-15 21:39:17 -060028 ulong addr, start, end;
Bin Meng2cfbdae2018-06-27 20:38:03 -070029 efi_status_t ret;
30
Simon Glassd7d7a032025-01-10 17:00:25 -070031 /*
32 * The bloblist is already marked reserved. For now, we don't bother
33 * marking it with EFI_ACPI_RECLAIM_MEMORY since we would need to cut a
34 * hole in the EFI_BOOT_SERVICES_CODE region added by
35 * add_u_boot_and_runtime(). At some point that function could create a
36 * more detailed map.
37 */
Simon Glassa0b45f42025-03-06 07:31:24 -070038 if (IS_ENABLED(CONFIG_BLOBLIST_TABLES)) {
39 int size;
40 void *tab = bloblist_get_blob(BLOBLISTT_ACPI_TABLES, &size);
Simon Glassd7d7a032025-01-10 17:00:25 -070041
Simon Glassa0b45f42025-03-06 07:31:24 -070042 if (!tab)
43 return EFI_NOT_FOUND;
44 addr = map_to_sysmem(tab);
45
46 ret = efi_add_memory_map(addr, size,
47 EFI_ACPI_RECLAIM_MEMORY);
48 if (ret != EFI_SUCCESS)
49 return ret;
50 } else {
51 /* Mark space used for tables */
52 start = ALIGN_DOWN(gd->arch.table_start, EFI_PAGE_MASK);
53 end = ALIGN(gd->arch.table_end, EFI_PAGE_MASK);
Simon Glass8965f292023-07-15 21:39:17 -060054 ret = efi_add_memory_map(start, end - start,
55 EFI_ACPI_RECLAIM_MEMORY);
56 if (ret != EFI_SUCCESS)
57 return ret;
Simon Glassa0b45f42025-03-06 07:31:24 -070058 if (gd->arch.table_start_high) {
59 start = ALIGN_DOWN(gd->arch.table_start_high,
60 EFI_PAGE_MASK);
61 end = ALIGN(gd->arch.table_end_high, EFI_PAGE_MASK);
62 ret = efi_add_memory_map(start, end - start,
63 EFI_ACPI_RECLAIM_MEMORY);
64 if (ret != EFI_SUCCESS)
65 return ret;
66 }
Bin Meng2cfbdae2018-06-27 20:38:03 -070067
Simon Glassa0b45f42025-03-06 07:31:24 -070068 addr = gd_acpi_start();
69 }
Heinrich Schuchardt3b56ffd2024-04-09 22:48:24 +020070 log_debug("EFI using ACPI tables at %lx\n", addr);
Bin Meng2cfbdae2018-06-27 20:38:03 -070071
72 /* And expose them to our EFI payload */
73 return efi_install_configuration_table(&acpi_guid,
Simon Glass8965f292023-07-15 21:39:17 -060074 (void *)(ulong)addr);
Bin Meng2cfbdae2018-06-27 20:38:03 -070075}