1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
8 * Intel Simple Firmware Interface (SFI)
10 * Yet another way to pass information to the Linux kernel.
12 * See https://simplefirmware.org/ for details
18 #include <asm/ioapic.h>
20 #include <asm/tables.h>
21 #include <dm/uclass-internal.h>
27 u64 table[SFI_TABLE_MAX_ENTRIES];
31 static void *get_entry_start(struct table_info *tab)
33 if (tab->count == SFI_TABLE_MAX_ENTRIES)
35 tab->entry_start = tab->base + tab->ptr;
36 tab->table[tab->count] = tab->entry_start;
37 tab->entry_start += sizeof(struct sfi_table_header);
39 return (void *)(uintptr_t)tab->entry_start;
42 static void finish_table(struct table_info *tab, const char *sig, void *entry)
44 struct sfi_table_header *hdr;
46 hdr = (struct sfi_table_header *)(uintptr_t)(tab->base + tab->ptr);
47 strcpy(hdr->sig, sig);
48 hdr->len = sizeof(*hdr) + ((ulong)entry - tab->entry_start);
50 strncpy(hdr->oem_id, "U-Boot", SFI_OEM_ID_SIZE);
51 strncpy(hdr->oem_table_id, "Table v1", SFI_OEM_TABLE_ID_SIZE);
53 hdr->csum = table_compute_checksum(hdr, hdr->len);
55 tab->ptr = ALIGN(tab->ptr, 16);
59 static int sfi_write_system_header(struct table_info *tab)
61 u64 *entry = get_entry_start(tab);
67 for (i = 0; i < tab->count; i++)
68 *entry++ = tab->table[i];
69 finish_table(tab, SFI_SIG_SYST, entry);
74 static int sfi_write_cpus(struct table_info *tab)
76 struct sfi_cpu_table_entry *entry = get_entry_start(tab);
83 for (uclass_find_first_device(UCLASS_CPU, &dev);
85 uclass_find_next_device(&dev)) {
86 struct cpu_plat *plat = dev_get_parent_plat(dev);
88 if (!device_active(dev))
90 entry->apic_id = plat->cpu_id;
95 /* Omit the table if there is only one CPU */
97 finish_table(tab, SFI_SIG_CPUS, entry);
102 static int sfi_write_apic(struct table_info *tab)
104 struct sfi_apic_table_entry *entry = get_entry_start(tab);
109 entry->phys_addr = IO_APIC_ADDR;
111 finish_table(tab, SFI_SIG_APIC, entry);
116 static int sfi_write_xsdt(struct table_info *tab)
118 struct sfi_xsdt_header *entry = get_entry_start(tab);
123 entry->oem_revision = 1;
124 entry->creator_id = 1;
125 entry->creator_revision = 1;
127 finish_table(tab, SFI_SIG_XSDT, entry);
132 ulong write_sfi_table(ulong base)
134 struct table_info table;
139 sfi_write_cpus(&table);
140 sfi_write_apic(&table);
143 * The SFI specification marks the XSDT table as option, but Linux 4.0
144 * crashes on start-up when it is not provided.
146 sfi_write_xsdt(&table);
148 /* Finally, write out the system header which points to the others */
149 sfi_write_system_header(&table);
151 return base + table.ptr;