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