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 <common.h> |
| 11 | #include <efi_loader.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.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> |
| 15 | |
| 16 | static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; |
| 17 | |
Heinrich Schuchardt | 7a369c4 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 18 | /* |
| 19 | * Install the SMBIOS table as a configuration table. |
| 20 | * |
| 21 | * @return status code |
| 22 | */ |
| 23 | efi_status_t efi_smbios_register(void) |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 24 | { |
| 25 | /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */ |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 26 | u64 dmi_addr = U32_MAX; |
Heinrich Schuchardt | 7a369c4 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 27 | efi_status_t ret; |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 28 | void *dmi; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 29 | |
Heinrich Schuchardt | 7a369c4 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 30 | /* Reserve 4kiB page for SMBIOS */ |
| 31 | ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 32 | EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr); |
Alexander Graf | 1799007 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 33 | |
| 34 | if (ret != EFI_SUCCESS) { |
| 35 | /* Could not find space in lowmem, use highmem instead */ |
| 36 | ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 37 | EFI_RUNTIME_SERVICES_DATA, 1, |
| 38 | &dmi_addr); |
Alexander Graf | 1799007 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 39 | |
| 40 | if (ret != EFI_SUCCESS) |
| 41 | return ret; |
| 42 | } |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 43 | |
Simon Glass | 2e2858f | 2018-05-16 09:42:19 -0600 | [diff] [blame] | 44 | /* |
| 45 | * Generate SMBIOS tables - we know that efi_allocate_pages() returns |
| 46 | * a 4k-aligned address, so it is safe to assume that |
| 47 | * write_smbios_table() will write the table at that address. |
| 48 | */ |
Simon Glass | 2d93add | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 49 | assert(!(dmi_addr & 0xf)); |
| 50 | dmi = (void *)(uintptr_t)dmi_addr; |
Heinrich Schuchardt | 21da91f | 2021-05-15 18:07:47 +0200 | [diff] [blame] | 51 | if (write_smbios_table(map_to_sysmem(dmi))) |
| 52 | /* Install SMBIOS information as configuration table */ |
| 53 | return efi_install_configuration_table(&smbios_guid, dmi); |
| 54 | efi_free_pages(dmi_addr, 1); |
| 55 | log_err("Cannot create SMBIOS table\n"); |
| 56 | return EFI_SUCCESS; |
Alexander Graf | 66f96e1 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 57 | } |