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 | |
| 8 | #include <common.h> |
| 9 | #include <efi_loader.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 11 | #include <mapmem.h> |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 12 | #include <smbios.h> |
| 13 | |
| 14 | static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; |
| 15 | |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 16 | /* |
| 17 | * Install the SMBIOS table as a configuration table. |
| 18 | * |
| 19 | * @return status code |
| 20 | */ |
| 21 | efi_status_t efi_smbios_register(void) |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 22 | { |
| 23 | /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */ |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 24 | u64 dmi_addr = U32_MAX; |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 25 | efi_status_t ret; |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 26 | void *dmi; |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 27 | |
Heinrich Schuchardt | 7657152 | 2018-03-03 15:28:54 +0100 | [diff] [blame] | 28 | /* Reserve 4kiB page for SMBIOS */ |
| 29 | ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 30 | EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr); |
Alexander Graf | 62f3757 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 31 | |
| 32 | if (ret != EFI_SUCCESS) { |
| 33 | /* Could not find space in lowmem, use highmem instead */ |
| 34 | ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 35 | EFI_RUNTIME_SERVICES_DATA, 1, |
| 36 | &dmi_addr); |
Alexander Graf | 62f3757 | 2018-06-18 17:23:00 +0200 | [diff] [blame] | 37 | |
| 38 | if (ret != EFI_SUCCESS) |
| 39 | return ret; |
| 40 | } |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 41 | |
Simon Glass | 0864c56 | 2018-05-16 09:42:19 -0600 | [diff] [blame] | 42 | /* |
| 43 | * Generate SMBIOS tables - we know that efi_allocate_pages() returns |
| 44 | * a 4k-aligned address, so it is safe to assume that |
| 45 | * write_smbios_table() will write the table at that address. |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 46 | * |
| 47 | * Note that on sandbox, efi_allocate_pages() unfortunately returns a |
| 48 | * pointer even though it uses a uint64_t type. Convert it. |
Simon Glass | 0864c56 | 2018-05-16 09:42:19 -0600 | [diff] [blame] | 49 | */ |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 50 | assert(!(dmi_addr & 0xf)); |
| 51 | dmi = (void *)(uintptr_t)dmi_addr; |
| 52 | write_smbios_table(map_to_sysmem(dmi)); |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 53 | |
| 54 | /* And expose them to our EFI payload */ |
Simon Glass | a2505fc | 2018-11-22 13:46:37 -0700 | [diff] [blame] | 55 | return efi_install_configuration_table(&smbios_guid, dmi); |
Alexander Graf | e663b35 | 2016-08-19 01:23:29 +0200 | [diff] [blame] | 56 | } |