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> |
Heinrich Schuchardt | 34e97aa | 2024-01-03 09:07:20 +0100 | [diff] [blame] | 16 | #include <asm/global_data.h> |
| 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 19 | |
Simon Glass | 9723670 | 2023-12-31 08:25:49 -0700 | [diff] [blame] | 20 | const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID; |
| 21 | |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 22 | enum { |
| 23 | TABLE_SIZE = SZ_4K, |
| 24 | }; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 25 | |
Heinrich Schuchardt | 7a369c4 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 26 | /* |
| 27 | * Install the SMBIOS table as a configuration table. |
| 28 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 29 | * Return: status code |
Heinrich Schuchardt | 7a369c4 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 30 | */ |
| 31 | efi_status_t efi_smbios_register(void) |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 32 | { |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 33 | ulong addr; |
Heinrich Schuchardt | 7a369c4 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 34 | efi_status_t ret; |
Simon Glass | 9723670 | 2023-12-31 08:25:49 -0700 | [diff] [blame] | 35 | void *buf; |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 36 | |
Simon Glass | 42b7da5 | 2023-12-31 08:25:48 -0700 | [diff] [blame] | 37 | addr = gd_smbios_start(); |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 38 | if (!addr) { |
| 39 | log_err("No SMBIOS tables to install\n"); |
| 40 | return EFI_NOT_FOUND; |
| 41 | } |
| 42 | |
| 43 | /* Mark space used for tables */ |
| 44 | ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA); |
| 45 | if (ret) |
| 46 | return ret; |
| 47 | |
| 48 | log_debug("EFI using SMBIOS tables at %lx\n", addr); |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 49 | |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 50 | /* Install SMBIOS information as configuration table */ |
Simon Glass | 9723670 | 2023-12-31 08:25:49 -0700 | [diff] [blame] | 51 | buf = map_sysmem(addr, 0); |
Simon Glass | 70f9959 | 2023-12-31 08:25:52 -0700 | [diff] [blame] | 52 | ret = efi_install_configuration_table(&smbios3_guid, buf); |
Simon Glass | 9723670 | 2023-12-31 08:25:49 -0700 | [diff] [blame] | 53 | unmap_sysmem(buf); |
| 54 | |
| 55 | return ret; |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static int install_smbios_table(void) |
| 59 | { |
Simon Glass | 2802f09 | 2023-12-31 08:25:55 -0700 | [diff] [blame] | 60 | ulong addr; |
| 61 | void *buf; |
Alexander Graf | 1799007 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 62 | |
Heinrich Schuchardt | 08d931a | 2023-12-23 02:03:34 +0100 | [diff] [blame] | 63 | if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || |
| 64 | IS_ENABLED(CONFIG_X86) || |
| 65 | IS_ENABLED(CONFIG_QFW_SMBIOS)) |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 66 | return 0; |
Alexander Graf | 1799007 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 67 | |
Simon Glass | 2802f09 | 2023-12-31 08:25:55 -0700 | [diff] [blame] | 68 | /* Align the table to a 4KB boundary to keep EFI happy */ |
| 69 | buf = memalign(SZ_4K, TABLE_SIZE); |
| 70 | if (!buf) |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 71 | return log_msg_ret("mem", -ENOMEM); |
| 72 | |
Simon Glass | 2802f09 | 2023-12-31 08:25:55 -0700 | [diff] [blame] | 73 | addr = map_to_sysmem(buf); |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 74 | if (!write_smbios_table(addr)) { |
| 75 | log_err("Failed to write SMBIOS table\n"); |
| 76 | return log_msg_ret("smbios", -EINVAL); |
Alexander Graf | 1799007 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 77 | } |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 78 | |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 79 | /* Make a note of where we put it */ |
Simon Glass | 2802f09 | 2023-12-31 08:25:55 -0700 | [diff] [blame] | 80 | log_debug("SMBIOS tables written to %lx\n", addr); |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 81 | gd->arch.smbios_start = addr; |
| 82 | |
| 83 | return 0; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 84 | } |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame] | 85 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table); |