blob: 574d331d76fef78ebab521272ee81a5c07d02d14 [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 Glass336d4612020-02-03 07:36:16 -07007#include <malloc.h>
Alexander Graf4b6dddc2016-08-19 01:23:23 +02008#include <smbios.h>
Simon Glass776cc202020-04-08 16:57:36 -06009#include <acpi/acpi_table.h>
Simon Glass6388e352015-04-28 20:25:10 -060010#include <asm/sfi.h>
Bin Meng07545d82015-06-23 12:18:52 +080011#include <asm/mpspec.h>
Bin Meng5e2400e2015-04-24 18:10:04 +080012#include <asm/tables.h>
Bin Meng3cf23712016-02-28 23:54:50 -080013#include <asm/coreboot_tables.h>
Bin Meng5e2400e2015-04-24 18:10:04 +080014
Bin Mengef4d0a52016-02-27 22:58:01 -080015/**
16 * Function prototype to write a specific configuration table
17 *
18 * @addr: start address to write the table
19 * @return: end address of the table
20 */
Simon Glass42fd8c12017-01-16 07:03:35 -070021typedef ulong (*table_write)(ulong addr);
Bin Mengef4d0a52016-02-27 22:58:01 -080022
23static table_write table_write_funcs[] = {
24#ifdef CONFIG_GENERATE_PIRQ_TABLE
25 write_pirq_routing_table,
26#endif
27#ifdef CONFIG_GENERATE_SFI_TABLE
28 write_sfi_table,
29#endif
30#ifdef CONFIG_GENERATE_MP_TABLE
31 write_mp_table,
32#endif
33#ifdef CONFIG_GENERATE_ACPI_TABLE
34 write_acpi_tables,
35#endif
36#ifdef CONFIG_GENERATE_SMBIOS_TABLE
Simon Glass42fd8c12017-01-16 07:03:35 -070037 write_smbios_table,
Bin Mengef4d0a52016-02-27 22:58:01 -080038#endif
39};
40
Bin Meng7f5df8d2015-06-23 12:18:51 +080041void table_fill_string(char *dest, const char *src, size_t n, char pad)
42{
43 int start, len;
44 int i;
45
46 strncpy(dest, src, n);
47
48 /* Fill the remaining bytes with pad */
49 len = strlen(src);
50 start = len < n ? len : n;
51 for (i = start; i < n; i++)
52 dest[i] = pad;
53}
54
Bin Meng5e2400e2015-04-24 18:10:04 +080055void write_tables(void)
56{
Bin Mengef4d0a52016-02-27 22:58:01 -080057 u32 rom_table_start = ROM_TABLE_ADDR;
58 u32 rom_table_end;
Bin Meng3cf23712016-02-28 23:54:50 -080059#ifdef CONFIG_SEABIOS
Bin Mengff94c212016-02-27 22:58:02 -080060 u32 high_table, table_size;
Bin Meng3cf23712016-02-28 23:54:50 -080061 struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
62#endif
Bin Mengef4d0a52016-02-27 22:58:01 -080063 int i;
Bin Meng5e2400e2015-04-24 18:10:04 +080064
Bin Mengef4d0a52016-02-27 22:58:01 -080065 for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
66 rom_table_end = table_write_funcs[i](rom_table_start);
67 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
Bin Mengff94c212016-02-27 22:58:02 -080068
Bin Meng3cf23712016-02-28 23:54:50 -080069#ifdef CONFIG_SEABIOS
Bin Mengff94c212016-02-27 22:58:02 -080070 table_size = rom_table_end - rom_table_start;
Bin Meng644a7672016-05-11 07:45:02 -070071 high_table = (u32)high_table_malloc(table_size);
Bin Mengff94c212016-02-27 22:58:02 -080072 if (high_table) {
Bin Mengff94c212016-02-27 22:58:02 -080073 table_write_funcs[i](high_table);
Bin Meng3cf23712016-02-28 23:54:50 -080074
75 cfg_tables[i].start = high_table;
76 cfg_tables[i].size = table_size;
Bin Mengff94c212016-02-27 22:58:02 -080077 } else {
78 printf("%d: no memory for configuration tables\n", i);
79 }
Bin Meng3cf23712016-02-28 23:54:50 -080080#endif
Bin Mengff94c212016-02-27 22:58:02 -080081
Bin Mengef4d0a52016-02-27 22:58:01 -080082 rom_table_start = rom_table_end;
83 }
Bin Meng3cf23712016-02-28 23:54:50 -080084
85#ifdef CONFIG_SEABIOS
86 /* make sure the last item is zero */
87 cfg_tables[i].size = 0;
88 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
89#endif
Bin Meng5e2400e2015-04-24 18:10:04 +080090}