]>
Commit | Line | Data |
---|---|---|
f739fcd8 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
e663b350 AG |
2 | /* |
3 | * EFI application tables support | |
4 | * | |
5 | * Copyright (c) 2016 Alexander Graf | |
e663b350 AG |
6 | */ |
7 | ||
c193d9bd HS |
8 | #define LOG_CATEGORY LOGC_EFI |
9 | ||
e663b350 | 10 | #include <efi_loader.h> |
f7ae49fc | 11 | #include <log.h> |
53fab13a | 12 | #include <malloc.h> |
a2505fc8 | 13 | #include <mapmem.h> |
e663b350 | 14 | #include <smbios.h> |
53fab13a | 15 | #include <linux/sizes.h> |
efe441a0 HS |
16 | #include <asm/global_data.h> |
17 | ||
18 | DECLARE_GLOBAL_DATA_PTR; | |
53fab13a | 19 | |
138e6914 SG |
20 | const efi_guid_t smbios3_guid = SMBIOS3_TABLE_GUID; |
21 | ||
53fab13a SG |
22 | enum { |
23 | TABLE_SIZE = SZ_4K, | |
24 | }; | |
e663b350 | 25 | |
7657152b HS |
26 | /* |
27 | * Install the SMBIOS table as a configuration table. | |
28 | * | |
185f812c | 29 | * Return: status code |
7657152b HS |
30 | */ |
31 | efi_status_t efi_smbios_register(void) | |
e663b350 | 32 | { |
53fab13a | 33 | ulong addr; |
7657152b | 34 | efi_status_t ret; |
138e6914 | 35 | void *buf; |
e663b350 | 36 | |
b2b58e1e | 37 | addr = gd_smbios_start(); |
53fab13a SG |
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); | |
49 | ||
50 | /* Install SMBIOS information as configuration table */ | |
138e6914 | 51 | buf = map_sysmem(addr, 0); |
aa849968 | 52 | ret = efi_install_configuration_table(&smbios3_guid, buf); |
138e6914 SG |
53 | unmap_sysmem(buf); |
54 | ||
55 | return ret; | |
53fab13a SG |
56 | } |
57 | ||
58 | static int install_smbios_table(void) | |
59 | { | |
06ef8089 SG |
60 | ulong addr; |
61 | void *buf; | |
62f37578 | 62 | |
1c5aab80 HS |
63 | if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || |
64 | IS_ENABLED(CONFIG_X86) || | |
65 | IS_ENABLED(CONFIG_QFW_SMBIOS)) | |
53fab13a | 66 | return 0; |
62f37578 | 67 | |
06ef8089 SG |
68 | /* Align the table to a 4KB boundary to keep EFI happy */ |
69 | buf = memalign(SZ_4K, TABLE_SIZE); | |
70 | if (!buf) | |
53fab13a SG |
71 | return log_msg_ret("mem", -ENOMEM); |
72 | ||
06ef8089 | 73 | addr = map_to_sysmem(buf); |
53fab13a SG |
74 | if (!write_smbios_table(addr)) { |
75 | log_err("Failed to write SMBIOS table\n"); | |
76 | return log_msg_ret("smbios", -EINVAL); | |
62f37578 | 77 | } |
e663b350 | 78 | |
53fab13a | 79 | /* Make a note of where we put it */ |
06ef8089 | 80 | log_debug("SMBIOS tables written to %lx\n", addr); |
53fab13a SG |
81 | gd->arch.smbios_start = addr; |
82 | ||
83 | return 0; | |
e663b350 | 84 | } |
53fab13a | 85 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table); |