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 <common.h> |
| 11 | #include <efi_loader.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame^] | 13 | #include <malloc.h> |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 14 | #include <mapmem.h> |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 15 | #include <smbios.h> |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame^] | 16 | #include <linux/sizes.h> |
| 17 | |
| 18 | enum { |
| 19 | TABLE_SIZE = SZ_4K, |
| 20 | }; |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 21 | |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 22 | /* |
| 23 | * Install the SMBIOS table as a configuration table. |
| 24 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 25 | * Return: status code |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 26 | */ |
| 27 | efi_status_t efi_smbios_register(void) |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 28 | { |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame^] | 29 | ulong addr; |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 30 | efi_status_t ret; |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 31 | |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame^] | 32 | addr = gd->arch.smbios_start; |
| 33 | if (!addr) { |
| 34 | log_err("No SMBIOS tables to install\n"); |
| 35 | return EFI_NOT_FOUND; |
Alexander Graf | 62f3757 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 36 | } |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 37 | |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame^] | 38 | /* Mark space used for tables */ |
| 39 | ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA); |
| 40 | if (ret) |
| 41 | return ret; |
| 42 | |
| 43 | log_debug("EFI using SMBIOS tables at %lx\n", addr); |
| 44 | |
| 45 | /* Install SMBIOS information as configuration table */ |
| 46 | return efi_install_configuration_table(&smbios_guid, |
| 47 | map_sysmem(addr, 0)); |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 48 | } |
Simon Glass | 53fab13 | 2023-09-20 07:29:51 -0600 | [diff] [blame^] | 49 | |
| 50 | static int install_smbios_table(void) |
| 51 | { |
| 52 | ulong addr; |
| 53 | void *buf; |
| 54 | |
| 55 | if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86)) |
| 56 | return 0; |
| 57 | |
| 58 | /* Align the table to a 4KB boundary to keep EFI happy */ |
| 59 | buf = memalign(SZ_4K, TABLE_SIZE); |
| 60 | if (!buf) |
| 61 | return log_msg_ret("mem", -ENOMEM); |
| 62 | |
| 63 | addr = map_to_sysmem(buf); |
| 64 | if (!write_smbios_table(addr)) { |
| 65 | log_err("Failed to write SMBIOS table\n"); |
| 66 | return log_msg_ret("smbios", -EINVAL); |
| 67 | } |
| 68 | |
| 69 | /* Make a note of where we put it */ |
| 70 | log_debug("SMBIOS tables written to %lx\n", addr); |
| 71 | gd->arch.smbios_start = addr; |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table); |