blob: f7b71c5cd13b80d9cf6b4c37cfe73ab8382501fa [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
Simon Glasse50129a2020-11-04 09:57:18 -070067int write_tables(void)
Bin Mengf17cea62015-04-24 18:10:04 +080068{
Bin Mengef47ed12016-02-27 22:58:01 -080069 u32 rom_table_start = ROM_TABLE_ADDR;
70 u32 rom_table_end;
Bin Mengca68d772016-02-27 22:58:02 -080071 u32 high_table, table_size;
Simon Glassf66fb302020-07-16 21:22:31 -060072 struct memory_area cfg_tables[ARRAY_SIZE(table_list) + 1];
Bin Mengef47ed12016-02-27 22:58:01 -080073 int i;
Bin Mengf17cea62015-04-24 18:10:04 +080074
Simon Glassf66fb302020-07-16 21:22:31 -060075 debug("Writing tables to %x:\n", rom_table_start);
76 for (i = 0; i < ARRAY_SIZE(table_list); i++) {
77 const struct table_info *table = &table_list[i];
78
79 rom_table_end = table->write(rom_table_start);
Bin Mengef47ed12016-02-27 22:58:01 -080080 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
Bin Mengca68d772016-02-27 22:58:02 -080081
Simon Glass9b90b242020-11-04 09:57:24 -070082 if (IS_ENABLED(CONFIG_SEABIOS)) {
83 table_size = rom_table_end - rom_table_start;
84 high_table = (u32)(ulong)high_table_malloc(table_size);
85 if (high_table) {
86 table->write(high_table);
Bin Meng96030fa2016-02-28 23:54:50 -080087
Simon Glass9b90b242020-11-04 09:57:24 -070088 cfg_tables[i].start = high_table;
89 cfg_tables[i].size = table_size;
90 } else {
91 printf("%d: no memory for configuration tables\n",
92 i);
93 return -ENOSPC;
94 }
Bin Mengca68d772016-02-27 22:58:02 -080095 }
96
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
Simon Glass9b90b242020-11-04 09:57:24 -0700102 if (IS_ENABLED(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 }
107
Simon Glassf66fb302020-07-16 21:22:31 -0600108 debug("- done writing tables\n");
Simon Glasse50129a2020-11-04 09:57:18 -0700109
110 return 0;
Bin Mengf17cea62015-04-24 18:10:04 +0800111}