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