blob: 99f142936318da1c78a110aafd8df586d2312eca [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>
Alexander Graffb228082016-08-19 01:23:23 +02007#include <smbios.h>
Simon Glass07e922a2015-04-28 20:25:10 -06008#include <asm/sfi.h>
Bin Mengc4f407e2015-06-23 12:18:52 +08009#include <asm/mpspec.h>
Bin Mengf17cea62015-04-24 18:10:04 +080010#include <asm/tables.h>
Saket Sinha331141a2015-08-22 12:20:55 +053011#include <asm/acpi_table.h>
Bin Meng96030fa2016-02-28 23:54:50 -080012#include <asm/coreboot_tables.h>
Bin Mengf17cea62015-04-24 18:10:04 +080013
Bin Mengef47ed12016-02-27 22:58:01 -080014/**
15 * Function prototype to write a specific configuration table
16 *
17 * @addr: start address to write the table
18 * @return: end address of the table
19 */
Simon Glassca37a392017-01-16 07:03:35 -070020typedef ulong (*table_write)(ulong addr);
Bin Mengef47ed12016-02-27 22:58:01 -080021
22static table_write table_write_funcs[] = {
23#ifdef CONFIG_GENERATE_PIRQ_TABLE
24 write_pirq_routing_table,
25#endif
26#ifdef CONFIG_GENERATE_SFI_TABLE
27 write_sfi_table,
28#endif
29#ifdef CONFIG_GENERATE_MP_TABLE
30 write_mp_table,
31#endif
32#ifdef CONFIG_GENERATE_ACPI_TABLE
33 write_acpi_tables,
34#endif
35#ifdef CONFIG_GENERATE_SMBIOS_TABLE
Simon Glassca37a392017-01-16 07:03:35 -070036 write_smbios_table,
Bin Mengef47ed12016-02-27 22:58:01 -080037#endif
38};
39
Bin Mengf91cf6b2015-06-23 12:18:51 +080040void table_fill_string(char *dest, const char *src, size_t n, char pad)
41{
42 int start, len;
43 int i;
44
45 strncpy(dest, src, n);
46
47 /* Fill the remaining bytes with pad */
48 len = strlen(src);
49 start = len < n ? len : n;
50 for (i = start; i < n; i++)
51 dest[i] = pad;
52}
53
Bin Mengf17cea62015-04-24 18:10:04 +080054void write_tables(void)
55{
Bin Mengef47ed12016-02-27 22:58:01 -080056 u32 rom_table_start = ROM_TABLE_ADDR;
57 u32 rom_table_end;
Bin Meng96030fa2016-02-28 23:54:50 -080058#ifdef CONFIG_SEABIOS
Bin Mengca68d772016-02-27 22:58:02 -080059 u32 high_table, table_size;
Bin Meng96030fa2016-02-28 23:54:50 -080060 struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
61#endif
Bin Mengef47ed12016-02-27 22:58:01 -080062 int i;
Bin Mengf17cea62015-04-24 18:10:04 +080063
Bin Mengef47ed12016-02-27 22:58:01 -080064 for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
65 rom_table_end = table_write_funcs[i](rom_table_start);
66 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
Bin Mengca68d772016-02-27 22:58:02 -080067
Bin Meng96030fa2016-02-28 23:54:50 -080068#ifdef CONFIG_SEABIOS
Bin Mengca68d772016-02-27 22:58:02 -080069 table_size = rom_table_end - rom_table_start;
Bin Mengf8281742016-05-11 07:45:02 -070070 high_table = (u32)high_table_malloc(table_size);
Bin Mengca68d772016-02-27 22:58:02 -080071 if (high_table) {
Bin Mengca68d772016-02-27 22:58:02 -080072 table_write_funcs[i](high_table);
Bin Meng96030fa2016-02-28 23:54:50 -080073
74 cfg_tables[i].start = high_table;
75 cfg_tables[i].size = table_size;
Bin Mengca68d772016-02-27 22:58:02 -080076 } else {
77 printf("%d: no memory for configuration tables\n", i);
78 }
Bin Meng96030fa2016-02-28 23:54:50 -080079#endif
Bin Mengca68d772016-02-27 22:58:02 -080080
Bin Mengef47ed12016-02-27 22:58:01 -080081 rom_table_start = rom_table_end;
82 }
Bin Meng96030fa2016-02-28 23:54:50 -080083
84#ifdef CONFIG_SEABIOS
85 /* make sure the last item is zero */
86 cfg_tables[i].size = 0;
87 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
88#endif
Bin Mengf17cea62015-04-24 18:10:04 +080089}