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