1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
11 #include <acpi/acpi_table.h>
12 #include <asm/global_data.h>
14 #include <asm/mpspec.h>
15 #include <asm/tables.h>
16 #include <asm/coreboot_tables.h>
18 DECLARE_GLOBAL_DATA_PTR;
21 * Function prototype to write a specific configuration table
23 * @addr: start address to write the table
24 * @return: end address of the table
26 typedef ulong (*table_write)(ulong addr);
29 * struct table_info - Information about each table to write
31 * @name: Name of table (for debugging)
32 * @write: Function to call to write this table
33 * @tag: Bloblist tag if using CONFIG_BLOBLIST_TABLES
34 * @size: Maximum table size
35 * @align: Table alignment in bytes
40 enum bloblist_tag_t tag;
45 static struct table_info table_list[] = {
46 #ifdef CONFIG_GENERATE_PIRQ_TABLE
47 { "pirq", write_pirq_routing_table },
49 #ifdef CONFIG_GENERATE_SFI_TABLE
50 { "sfi", write_sfi_table, },
52 #ifdef CONFIG_GENERATE_MP_TABLE
53 { "mp", write_mp_table, },
55 #ifdef CONFIG_GENERATE_ACPI_TABLE
56 { "acpi", write_acpi_tables, BLOBLISTT_ACPI_TABLES, 0x10000, 0x1000},
58 #ifdef CONFIG_GENERATE_SMBIOS_TABLE
59 { "smbios", write_smbios_table, BLOBLISTT_SMBIOS_TABLES, 0x1000, 0x100},
63 void table_fill_string(char *dest, const char *src, size_t n, char pad)
68 strncpy(dest, src, n);
70 /* Fill the remaining bytes with pad */
72 start = len < n ? len : n;
73 for (i = start; i < n; i++)
77 int write_tables(void)
81 u32 high_table, table_size;
82 struct memory_area cfg_tables[ARRAY_SIZE(table_list) + 1];
85 rom_table_start = ROM_TABLE_ADDR;
87 debug("Writing tables to %x:\n", rom_table_start);
88 for (i = 0; i < ARRAY_SIZE(table_list); i++) {
89 const struct table_info *table = &table_list[i];
90 int size = table->size ? : CONFIG_ROM_TABLE_SIZE;
92 if (IS_ENABLED(CONFIG_BLOBLIST_TABLES) && table->tag) {
93 rom_table_start = (ulong)bloblist_add(table->tag, size,
96 return log_msg_ret("bloblist", -ENOBUFS);
98 rom_table_end = table->write(rom_table_start);
99 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
101 if (IS_ENABLED(CONFIG_SEABIOS)) {
102 table_size = rom_table_end - rom_table_start;
103 high_table = (u32)(ulong)high_table_malloc(table_size);
105 table->write(high_table);
107 cfg_tables[i].start = high_table;
108 cfg_tables[i].size = table_size;
110 printf("%d: no memory for configuration tables\n",
116 debug("- wrote '%s' to %x, end %x\n", table->name,
117 rom_table_start, rom_table_end);
118 if (rom_table_end - rom_table_start > size) {
119 log_err("Out of space for configuration tables: need %x, have %x\n",
120 rom_table_end - rom_table_start, size);
121 return log_msg_ret("bloblist", -ENOSPC);
123 rom_table_start = rom_table_end;
126 if (IS_ENABLED(CONFIG_SEABIOS)) {
127 /* make sure the last item is zero */
128 cfg_tables[i].size = 0;
129 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
132 if (IS_ENABLED(CONFIG_BLOBLIST_TABLES)) {
133 void *ptr = (void *)CONFIG_ROM_TABLE_ADDR;
135 /* Write an RSDP pointing to the tables */
136 if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
137 struct acpi_ctx *ctx = gd_acpi_ctx();
139 acpi_write_rsdp(ptr, ctx->rsdt, ctx->xsdt);
140 ptr += ALIGN(sizeof(struct acpi_rsdp), 16);
142 if (IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE)) {
145 smbios = bloblist_find(BLOBLISTT_SMBIOS_TABLES, 0);
147 return log_msg_ret("smbios", -ENOENT);
148 memcpy(ptr, smbios, sizeof(struct smbios_entry));
152 debug("- done writing tables\n");