Tom Rini | f739fcd | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 2 | /* |
| 3 | * EFI application tables support |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Heinrich Schuchardt | c193d9b | 2021-05-15 18:07:47 +0200 | [diff] [blame] | 8 | #define LOG_CATEGORY LOGC_EFI |
| 9 | |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 10 | #include <efi_loader.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 13 | #include <mapmem.h> |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 14 | #include <smbios.h> |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 15 | #include <linux/sizes.h> |
| 16 | |
Simon Glass | 138e691 | 2023-12-31 08:25:49 -0700 | [diff] [blame^] | 17 | const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID; |
| 18 | |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 19 | enum { |
| 20 | TABLE_SIZE = SZ_4K, |
| 21 | }; |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 22 | |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 23 | /* |
| 24 | * Install the SMBIOS table as a configuration table. |
| 25 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 26 | * Return: status code |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 27 | */ |
| 28 | efi_status_t efi_smbios_register(void) |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 29 | { |
Simon Glass | 138e691 | 2023-12-31 08:25:49 -0700 | [diff] [blame^] | 30 | const efi_guid_t *guid; |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 31 | ulong addr; |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 32 | efi_status_t ret; |
Simon Glass | 138e691 | 2023-12-31 08:25:49 -0700 | [diff] [blame^] | 33 | void *buf; |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 34 | |
Simon Glass | b2b58e1 | 2023-12-31 08:25:48 -0700 | [diff] [blame] | 35 | addr = gd_smbios_start(); |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 36 | if (!addr) { |
| 37 | log_err("No SMBIOS tables to install\n"); |
| 38 | return EFI_NOT_FOUND; |
Alexander Graf | 62f3757 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 39 | } |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 40 | |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 41 | /* Mark space used for tables */ |
| 42 | ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA); |
| 43 | if (ret) |
| 44 | return ret; |
| 45 | |
| 46 | log_debug("EFI using SMBIOS tables at %lx\n", addr); |
| 47 | |
| 48 | /* Install SMBIOS information as configuration table */ |
Simon Glass | 138e691 | 2023-12-31 08:25:49 -0700 | [diff] [blame^] | 49 | buf = map_sysmem(addr, 0); |
| 50 | guid = !memcmp(buf, "_SM_", 4) ? &smbios_guid : &smbios3_guid; |
| 51 | ret = efi_install_configuration_table(guid, buf); |
| 52 | unmap_sysmem(buf); |
| 53 | |
| 54 | return ret; |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 55 | } |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 56 | |
| 57 | static int install_smbios_table(void) |
| 58 | { |
Heinrich Schuchardt | 89cb3a9 | 2023-11-20 23:25:58 +0100 | [diff] [blame] | 59 | u64 addr; |
| 60 | efi_status_t ret; |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 61 | |
| 62 | if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86)) |
| 63 | return 0; |
| 64 | |
Heinrich Schuchardt | 89cb3a9 | 2023-11-20 23:25:58 +0100 | [diff] [blame] | 65 | addr = SZ_4G; |
| 66 | ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, |
| 67 | EFI_RUNTIME_SERVICES_DATA, |
| 68 | efi_size_in_pages(TABLE_SIZE), &addr); |
| 69 | if (ret != EFI_SUCCESS) |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 70 | return log_msg_ret("mem", -ENOMEM); |
| 71 | |
Heinrich Schuchardt | 89cb3a9 | 2023-11-20 23:25:58 +0100 | [diff] [blame] | 72 | addr = map_to_sysmem((void *)(uintptr_t)addr); |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 73 | if (!write_smbios_table(addr)) { |
| 74 | log_err("Failed to write SMBIOS table\n"); |
| 75 | return log_msg_ret("smbios", -EINVAL); |
| 76 | } |
| 77 | |
| 78 | /* Make a note of where we put it */ |
Heinrich Schuchardt | 89cb3a9 | 2023-11-20 23:25:58 +0100 | [diff] [blame] | 79 | log_debug("SMBIOS tables written to %llx\n", addr); |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 80 | gd->arch.smbios_start = addr; |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table); |