2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
9 * Intel Simple Firmware Interface (SFI)
11 * Yet another way to pass information to the Linux kernel.
13 * See https://simplefirmware.org/ for details
20 #include <asm/ioapic.h>
22 #include <asm/tables.h>
23 #include <dm/uclass-internal.h>
29 u64 table[SFI_TABLE_MAX_ENTRIES];
33 static void *get_entry_start(struct table_info *tab)
35 if (tab->count == SFI_TABLE_MAX_ENTRIES)
37 tab->entry_start = tab->base + tab->ptr;
38 tab->table[tab->count] = tab->entry_start;
39 tab->entry_start += sizeof(struct sfi_table_header);
41 return (void *)tab->entry_start;
44 static void finish_table(struct table_info *tab, const char *sig, void *entry)
46 struct sfi_table_header *hdr;
48 hdr = (struct sfi_table_header *)(tab->base + tab->ptr);
49 strcpy(hdr->sig, sig);
50 hdr->len = sizeof(*hdr) + ((ulong)entry - tab->entry_start);
52 strncpy(hdr->oem_id, "U-Boot", SFI_OEM_ID_SIZE);
53 strncpy(hdr->oem_table_id, "Table v1", SFI_OEM_TABLE_ID_SIZE);
55 hdr->csum = table_compute_checksum(hdr, hdr->len);
57 tab->ptr = ALIGN(tab->ptr, 16);
61 static int sfi_write_system_header(struct table_info *tab)
63 u64 *entry = get_entry_start(tab);
69 for (i = 0; i < tab->count; i++)
70 *entry++ = tab->table[i];
71 finish_table(tab, SFI_SIG_SYST, entry);
76 static int sfi_write_cpus(struct table_info *tab)
78 struct sfi_cpu_table_entry *entry = get_entry_start(tab);
85 for (uclass_find_first_device(UCLASS_CPU, &dev);
87 uclass_find_next_device(&dev)) {
88 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
90 if (!device_active(dev))
92 entry->apic_id = plat->cpu_id;
97 /* Omit the table if there is only one CPU */
99 finish_table(tab, SFI_SIG_CPUS, entry);
104 static int sfi_write_apic(struct table_info *tab)
106 struct sfi_apic_table_entry *entry = get_entry_start(tab);
111 entry->phys_addr = IO_APIC_ADDR;
113 finish_table(tab, SFI_SIG_APIC, entry);
118 static int sfi_write_xsdt(struct table_info *tab)
120 struct sfi_xsdt_header *entry = get_entry_start(tab);
125 entry->oem_revision = 1;
126 entry->creator_id = 1;
127 entry->creator_revision = 1;
129 finish_table(tab, SFI_SIG_XSDT, entry);
134 u32 write_sfi_table(u32 base)
136 struct table_info table;
141 sfi_write_cpus(&table);
142 sfi_write_apic(&table);
145 * The SFI specification marks the XSDT table as option, but Linux 4.0
146 * crashes on start-up when it is not provided.
148 sfi_write_xsdt(&table);
150 /* Finally, write out the system header which points to the others */
151 sfi_write_system_header(&table);
153 return base + table.ptr;