blob: 7bad5dd30327a526f174d755a91906e59235e4b4 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng5e2400e2015-04-24 18:10:04 +08002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
Bin Meng5e2400e2015-04-24 18:10:04 +08004 */
5
6#include <common.h>
Simon Glassb336a2b2020-07-16 21:22:31 -06007#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -07008#include <malloc.h>
Alexander Graf4b6dddc2016-08-19 01:23:23 +02009#include <smbios.h>
Simon Glass776cc202020-04-08 16:57:36 -060010#include <acpi/acpi_table.h>
Simon Glass6388e352015-04-28 20:25:10 -060011#include <asm/sfi.h>
Bin Meng07545d82015-06-23 12:18:52 +080012#include <asm/mpspec.h>
Bin Meng5e2400e2015-04-24 18:10:04 +080013#include <asm/tables.h>
Bin Meng3cf23712016-02-28 23:54:50 -080014#include <asm/coreboot_tables.h>
Bin Meng5e2400e2015-04-24 18:10:04 +080015
Bin Mengef4d0a52016-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 Glass42fd8c12017-01-16 07:03:35 -070022typedef ulong (*table_write)(ulong addr);
Bin Mengef4d0a52016-02-27 22:58:01 -080023
Simon Glassb336a2b2020-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 Mengef4d0a52016-02-27 22:58:01 -080036#ifdef CONFIG_GENERATE_PIRQ_TABLE
Simon Glassb336a2b2020-07-16 21:22:31 -060037 { "pirq", write_pirq_routing_table },
Bin Mengef4d0a52016-02-27 22:58:01 -080038#endif
39#ifdef CONFIG_GENERATE_SFI_TABLE
Simon Glassb336a2b2020-07-16 21:22:31 -060040 { "sfi", write_sfi_table, },
Bin Mengef4d0a52016-02-27 22:58:01 -080041#endif
42#ifdef CONFIG_GENERATE_MP_TABLE
Simon Glassb336a2b2020-07-16 21:22:31 -060043 { "mp", write_mp_table, },
Bin Mengef4d0a52016-02-27 22:58:01 -080044#endif
45#ifdef CONFIG_GENERATE_ACPI_TABLE
Simon Glassb336a2b2020-07-16 21:22:31 -060046 { "acpi", write_acpi_tables, },
Bin Mengef4d0a52016-02-27 22:58:01 -080047#endif
48#ifdef CONFIG_GENERATE_SMBIOS_TABLE
Simon Glassb336a2b2020-07-16 21:22:31 -060049 { "smbios", write_smbios_table, },
Bin Mengef4d0a52016-02-27 22:58:01 -080050#endif
51};
52
Bin Meng7f5df8d2015-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 Meng5e2400e2015-04-24 18:10:04 +080067void write_tables(void)
68{
Bin Mengef4d0a52016-02-27 22:58:01 -080069 u32 rom_table_start = ROM_TABLE_ADDR;
70 u32 rom_table_end;
Bin Meng3cf23712016-02-28 23:54:50 -080071#ifdef CONFIG_SEABIOS
Bin Mengff94c212016-02-27 22:58:02 -080072 u32 high_table, table_size;
Simon Glassb336a2b2020-07-16 21:22:31 -060073 struct memory_area cfg_tables[ARRAY_SIZE(table_list) + 1];
Bin Meng3cf23712016-02-28 23:54:50 -080074#endif
Bin Mengef4d0a52016-02-27 22:58:01 -080075 int i;
Bin Meng5e2400e2015-04-24 18:10:04 +080076
Simon Glassb336a2b2020-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 Mengef4d0a52016-02-27 22:58:01 -080082 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
Bin Mengff94c212016-02-27 22:58:02 -080083
Bin Meng3cf23712016-02-28 23:54:50 -080084#ifdef CONFIG_SEABIOS
Bin Mengff94c212016-02-27 22:58:02 -080085 table_size = rom_table_end - rom_table_start;
Bin Meng644a7672016-05-11 07:45:02 -070086 high_table = (u32)high_table_malloc(table_size);
Bin Mengff94c212016-02-27 22:58:02 -080087 if (high_table) {
Simon Glassb336a2b2020-07-16 21:22:31 -060088 table->write(high_table);
Bin Meng3cf23712016-02-28 23:54:50 -080089
90 cfg_tables[i].start = high_table;
91 cfg_tables[i].size = table_size;
Bin Mengff94c212016-02-27 22:58:02 -080092 } else {
93 printf("%d: no memory for configuration tables\n", i);
94 }
Bin Meng3cf23712016-02-28 23:54:50 -080095#endif
Bin Mengff94c212016-02-27 22:58:02 -080096
Simon Glassb336a2b2020-07-16 21:22:31 -060097 debug("- wrote '%s' to %x, end %x\n", table->name,
98 rom_table_start, rom_table_end);
Bin Mengef4d0a52016-02-27 22:58:01 -080099 rom_table_start = rom_table_end;
100 }
Bin Meng3cf23712016-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 Glassb336a2b2020-07-16 21:22:31 -0600107 debug("- done writing tables\n");
Bin Meng5e2400e2015-04-24 18:10:04 +0800108}