blob: 7bad5dd30327a526f174d755a91906e59235e4b4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Mengf17cea62015-04-24 18:10:04 +08002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
Bin Mengf17cea62015-04-24 18:10:04 +08004 */
5
6#include <common.h>
Simon Glassf66fb302020-07-16 21:22:31 -06007#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -07008#include <malloc.h>
Alexander Graffb228082016-08-19 01:23:23 +02009#include <smbios.h>
Simon Glass858fed12020-04-08 16:57:36 -060010#include <acpi/acpi_table.h>
Simon Glass07e922a2015-04-28 20:25:10 -060011#include <asm/sfi.h>
Bin Mengc4f407e2015-06-23 12:18:52 +080012#include <asm/mpspec.h>
Bin Mengf17cea62015-04-24 18:10:04 +080013#include <asm/tables.h>
Bin Meng96030fa2016-02-28 23:54:50 -080014#include <asm/coreboot_tables.h>
Bin Mengf17cea62015-04-24 18:10:04 +080015
Bin Mengef47ed12016-02-27 22:58:01 -080016/**
17 * Function prototype to write a specific configuration table
18 *
19 * @addr: start address to write the table
20 * @return: end address of the table
21 */
Simon Glassca37a392017-01-16 07:03:35 -070022typedef ulong (*table_write)(ulong addr);
Bin Mengef47ed12016-02-27 22:58:01 -080023
Simon Glassf66fb302020-07-16 21:22:31 -060024/**
25 * struct table_info - Information about each table to write
26 *
27 * @name: Name of table (for debugging)
28 * @write: Function to call to write this table
29 */
30struct table_info {
31 const char *name;
32 table_write write;
33};
34
35static struct table_info table_list[] = {
Bin Mengef47ed12016-02-27 22:58:01 -080036#ifdef CONFIG_GENERATE_PIRQ_TABLE
Simon Glassf66fb302020-07-16 21:22:31 -060037 { "pirq", write_pirq_routing_table },
Bin Mengef47ed12016-02-27 22:58:01 -080038#endif
39#ifdef CONFIG_GENERATE_SFI_TABLE
Simon Glassf66fb302020-07-16 21:22:31 -060040 { "sfi", write_sfi_table, },
Bin Mengef47ed12016-02-27 22:58:01 -080041#endif
42#ifdef CONFIG_GENERATE_MP_TABLE
Simon Glassf66fb302020-07-16 21:22:31 -060043 { "mp", write_mp_table, },
Bin Mengef47ed12016-02-27 22:58:01 -080044#endif
45#ifdef CONFIG_GENERATE_ACPI_TABLE
Simon Glassf66fb302020-07-16 21:22:31 -060046 { "acpi", write_acpi_tables, },
Bin Mengef47ed12016-02-27 22:58:01 -080047#endif
48#ifdef CONFIG_GENERATE_SMBIOS_TABLE
Simon Glassf66fb302020-07-16 21:22:31 -060049 { "smbios", write_smbios_table, },
Bin Mengef47ed12016-02-27 22:58:01 -080050#endif
51};
52
Bin Mengf91cf6b2015-06-23 12:18:51 +080053void table_fill_string(char *dest, const char *src, size_t n, char pad)
54{
55 int start, len;
56 int i;
57
58 strncpy(dest, src, n);
59
60 /* Fill the remaining bytes with pad */
61 len = strlen(src);
62 start = len < n ? len : n;
63 for (i = start; i < n; i++)
64 dest[i] = pad;
65}
66
Bin Mengf17cea62015-04-24 18:10:04 +080067void write_tables(void)
68{
Bin Mengef47ed12016-02-27 22:58:01 -080069 u32 rom_table_start = ROM_TABLE_ADDR;
70 u32 rom_table_end;
Bin Meng96030fa2016-02-28 23:54:50 -080071#ifdef CONFIG_SEABIOS
Bin Mengca68d772016-02-27 22:58:02 -080072 u32 high_table, table_size;
Simon Glassf66fb302020-07-16 21:22:31 -060073 struct memory_area cfg_tables[ARRAY_SIZE(table_list) + 1];
Bin Meng96030fa2016-02-28 23:54:50 -080074#endif
Bin Mengef47ed12016-02-27 22:58:01 -080075 int i;
Bin Mengf17cea62015-04-24 18:10:04 +080076
Simon Glassf66fb302020-07-16 21:22:31 -060077 debug("Writing tables to %x:\n", rom_table_start);
78 for (i = 0; i < ARRAY_SIZE(table_list); i++) {
79 const struct table_info *table = &table_list[i];
80
81 rom_table_end = table->write(rom_table_start);
Bin Mengef47ed12016-02-27 22:58:01 -080082 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
Bin Mengca68d772016-02-27 22:58:02 -080083
Bin Meng96030fa2016-02-28 23:54:50 -080084#ifdef CONFIG_SEABIOS
Bin Mengca68d772016-02-27 22:58:02 -080085 table_size = rom_table_end - rom_table_start;
Bin Mengf8281742016-05-11 07:45:02 -070086 high_table = (u32)high_table_malloc(table_size);
Bin Mengca68d772016-02-27 22:58:02 -080087 if (high_table) {
Simon Glassf66fb302020-07-16 21:22:31 -060088 table->write(high_table);
Bin Meng96030fa2016-02-28 23:54:50 -080089
90 cfg_tables[i].start = high_table;
91 cfg_tables[i].size = table_size;
Bin Mengca68d772016-02-27 22:58:02 -080092 } else {
93 printf("%d: no memory for configuration tables\n", i);
94 }
Bin Meng96030fa2016-02-28 23:54:50 -080095#endif
Bin Mengca68d772016-02-27 22:58:02 -080096
Simon Glassf66fb302020-07-16 21:22:31 -060097 debug("- wrote '%s' to %x, end %x\n", table->name,
98 rom_table_start, rom_table_end);
Bin Mengef47ed12016-02-27 22:58:01 -080099 rom_table_start = rom_table_end;
100 }
Bin Meng96030fa2016-02-28 23:54:50 -0800101
102#ifdef CONFIG_SEABIOS
103 /* make sure the last item is zero */
104 cfg_tables[i].size = 0;
105 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
106#endif
Simon Glassf66fb302020-07-16 21:22:31 -0600107 debug("- done writing tables\n");
Bin Mengf17cea62015-04-24 18:10:04 +0800108}