1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
8 * Intel Simple Firmware Interface (SFI)
10 * Yet another way to pass information to the Linux kernel.
12 * See https://simplefirmware.org/ for details
19 #include <asm/ioapic.h>
21 #include <asm/tables.h>
22 #include <dm/uclass-internal.h>
28 u64 table[SFI_TABLE_MAX_ENTRIES];
32 static void *get_entry_start(struct table_info *tab)
34 if (tab->count == SFI_TABLE_MAX_ENTRIES)
36 tab->entry_start = tab->base + tab->ptr;
37 tab->table[tab->count] = tab->entry_start;
38 tab->entry_start += sizeof(struct sfi_table_header);
40 return (void *)(uintptr_t)tab->entry_start;
43 static void finish_table(struct table_info *tab, const char *sig, void *entry)
45 struct sfi_table_header *hdr;
47 hdr = (struct sfi_table_header *)(uintptr_t)(tab->base + tab->ptr);
48 strcpy(hdr->sig, sig);
49 hdr->len = sizeof(*hdr) + ((ulong)entry - tab->entry_start);
51 strncpy(hdr->oem_id, "U-Boot", SFI_OEM_ID_SIZE);
52 strncpy(hdr->oem_table_id, "Table v1", SFI_OEM_TABLE_ID_SIZE);
54 hdr->csum = table_compute_checksum(hdr, hdr->len);
56 tab->ptr = ALIGN(tab->ptr, 16);
60 static int sfi_write_system_header(struct table_info *tab)
62 u64 *entry = get_entry_start(tab);
68 for (i = 0; i < tab->count; i++)
69 *entry++ = tab->table[i];
70 finish_table(tab, SFI_SIG_SYST, entry);
75 static int sfi_write_cpus(struct table_info *tab)
77 struct sfi_cpu_table_entry *entry = get_entry_start(tab);
84 for (uclass_find_first_device(UCLASS_CPU, &dev);
86 uclass_find_next_device(&dev)) {
87 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
89 if (!device_active(dev))
91 entry->apic_id = plat->cpu_id;
96 /* Omit the table if there is only one CPU */
98 finish_table(tab, SFI_SIG_CPUS, entry);
103 static int sfi_write_apic(struct table_info *tab)
105 struct sfi_apic_table_entry *entry = get_entry_start(tab);
110 entry->phys_addr = IO_APIC_ADDR;
112 finish_table(tab, SFI_SIG_APIC, entry);
117 static int sfi_write_xsdt(struct table_info *tab)
119 struct sfi_xsdt_header *entry = get_entry_start(tab);
124 entry->oem_revision = 1;
125 entry->creator_id = 1;
126 entry->creator_revision = 1;
128 finish_table(tab, SFI_SIG_XSDT, entry);
133 ulong write_sfi_table(ulong base)
135 struct table_info table;
140 sfi_write_cpus(&table);
141 sfi_write_apic(&table);
144 * The SFI specification marks the XSDT table as option, but Linux 4.0
145 * crashes on start-up when it is not provided.
147 sfi_write_xsdt(&table);
149 /* Finally, write out the system header which points to the others */
150 sfi_write_system_header(&table);
152 return base + table.ptr;