#include <common.h>
#include <efi_loader.h>
#include <log.h>
+#include <malloc.h>
#include <mapmem.h>
#include <smbios.h>
+#include <linux/sizes.h>
+
+enum {
+ TABLE_SIZE = SZ_4K,
+};
/*
* Install the SMBIOS table as a configuration table.
*/
efi_status_t efi_smbios_register(void)
{
- /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
- u64 dmi_addr = U32_MAX;
+ ulong addr;
efi_status_t ret;
- void *dmi;
- /* Reserve 4kiB page for SMBIOS */
- ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
- EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr);
+ addr = gd->arch.smbios_start;
+ if (!addr) {
+ log_err("No SMBIOS tables to install\n");
+ return EFI_NOT_FOUND;
+ }
+
+ /* Mark space used for tables */
+ ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA);
+ if (ret)
+ return ret;
+
+ log_debug("EFI using SMBIOS tables at %lx\n", addr);
+
+ /* Install SMBIOS information as configuration table */
+ return efi_install_configuration_table(&smbios_guid,
+ map_sysmem(addr, 0));
+}
+
+static int install_smbios_table(void)
+{
+ ulong addr;
+ void *buf;
- if (ret != EFI_SUCCESS) {
- /* Could not find space in lowmem, use highmem instead */
- ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
- EFI_RUNTIME_SERVICES_DATA, 1,
- &dmi_addr);
+ if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86))
+ return 0;
- if (ret != EFI_SUCCESS)
- return ret;
+ /* Align the table to a 4KB boundary to keep EFI happy */
+ buf = memalign(SZ_4K, TABLE_SIZE);
+ if (!buf)
+ return log_msg_ret("mem", -ENOMEM);
+
+ addr = map_to_sysmem(buf);
+ if (!write_smbios_table(addr)) {
+ log_err("Failed to write SMBIOS table\n");
+ return log_msg_ret("smbios", -EINVAL);
}
- /*
- * Generate SMBIOS tables - we know that efi_allocate_pages() returns
- * a 4k-aligned address, so it is safe to assume that
- * write_smbios_table() will write the table at that address.
- */
- assert(!(dmi_addr & 0xf));
- dmi = (void *)(uintptr_t)dmi_addr;
- if (write_smbios_table(map_to_sysmem(dmi)))
- /* Install SMBIOS information as configuration table */
- return efi_install_configuration_table(&smbios_guid, dmi);
- efi_free_pages(dmi_addr, 1);
- log_err("Cannot create SMBIOS table\n");
- return EFI_SUCCESS;
+ /* Make a note of where we put it */
+ log_debug("SMBIOS tables written to %lx\n", addr);
+ gd->arch.smbios_start = addr;
+
+ return 0;
}
+EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, install_smbios_table);