blob: 025b183d6bd7a61788e5680c370f82d555397fdc [file] [log] [blame]
Bin Mengf17cea62015-04-24 18:10:04 +08001/*
2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Alexander Graffb228082016-08-19 01:23:23 +02008#include <smbios.h>
Simon Glass07e922a2015-04-28 20:25:10 -06009#include <asm/sfi.h>
Bin Mengc4f407e2015-06-23 12:18:52 +080010#include <asm/mpspec.h>
Bin Mengf17cea62015-04-24 18:10:04 +080011#include <asm/tables.h>
Saket Sinha331141a2015-08-22 12:20:55 +053012#include <asm/acpi_table.h>
Bin Meng96030fa2016-02-28 23:54:50 -080013#include <asm/coreboot_tables.h>
Bin Mengf17cea62015-04-24 18:10:04 +080014
Alexander Grafe4a59ae2016-08-19 01:23:25 +020015static u32 write_smbios_table_wrapper(u32 addr)
16{
17 return write_smbios_table(addr);
18}
19
Bin Mengef47ed12016-02-27 22:58:01 -080020/**
21 * Function prototype to write a specific configuration table
22 *
23 * @addr: start address to write the table
24 * @return: end address of the table
25 */
26typedef u32 (*table_write)(u32 addr);
27
28static table_write table_write_funcs[] = {
29#ifdef CONFIG_GENERATE_PIRQ_TABLE
30 write_pirq_routing_table,
31#endif
32#ifdef CONFIG_GENERATE_SFI_TABLE
33 write_sfi_table,
34#endif
35#ifdef CONFIG_GENERATE_MP_TABLE
36 write_mp_table,
37#endif
38#ifdef CONFIG_GENERATE_ACPI_TABLE
39 write_acpi_tables,
40#endif
41#ifdef CONFIG_GENERATE_SMBIOS_TABLE
Alexander Grafe4a59ae2016-08-19 01:23:25 +020042 write_smbios_table_wrapper,
Bin Mengef47ed12016-02-27 22:58:01 -080043#endif
44};
45
Bin Mengf91cf6b2015-06-23 12:18:51 +080046void table_fill_string(char *dest, const char *src, size_t n, char pad)
47{
48 int start, len;
49 int i;
50
51 strncpy(dest, src, n);
52
53 /* Fill the remaining bytes with pad */
54 len = strlen(src);
55 start = len < n ? len : n;
56 for (i = start; i < n; i++)
57 dest[i] = pad;
58}
59
Bin Mengf17cea62015-04-24 18:10:04 +080060void write_tables(void)
61{
Bin Mengef47ed12016-02-27 22:58:01 -080062 u32 rom_table_start = ROM_TABLE_ADDR;
63 u32 rom_table_end;
Bin Meng96030fa2016-02-28 23:54:50 -080064#ifdef CONFIG_SEABIOS
Bin Mengca68d772016-02-27 22:58:02 -080065 u32 high_table, table_size;
Bin Meng96030fa2016-02-28 23:54:50 -080066 struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
67#endif
Bin Mengef47ed12016-02-27 22:58:01 -080068 int i;
Bin Mengf17cea62015-04-24 18:10:04 +080069
Bin Mengef47ed12016-02-27 22:58:01 -080070 for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
71 rom_table_end = table_write_funcs[i](rom_table_start);
72 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
Bin Mengca68d772016-02-27 22:58:02 -080073
Bin Meng96030fa2016-02-28 23:54:50 -080074#ifdef CONFIG_SEABIOS
Bin Mengca68d772016-02-27 22:58:02 -080075 table_size = rom_table_end - rom_table_start;
Bin Mengf8281742016-05-11 07:45:02 -070076 high_table = (u32)high_table_malloc(table_size);
Bin Mengca68d772016-02-27 22:58:02 -080077 if (high_table) {
Bin Mengca68d772016-02-27 22:58:02 -080078 table_write_funcs[i](high_table);
Bin Meng96030fa2016-02-28 23:54:50 -080079
80 cfg_tables[i].start = high_table;
81 cfg_tables[i].size = table_size;
Bin Mengca68d772016-02-27 22:58:02 -080082 } else {
83 printf("%d: no memory for configuration tables\n", i);
84 }
Bin Meng96030fa2016-02-28 23:54:50 -080085#endif
Bin Mengca68d772016-02-27 22:58:02 -080086
Bin Mengef47ed12016-02-27 22:58:01 -080087 rom_table_start = rom_table_end;
88 }
Bin Meng96030fa2016-02-28 23:54:50 -080089
90#ifdef CONFIG_SEABIOS
91 /* make sure the last item is zero */
92 cfg_tables[i].size = 0;
93 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
94#endif
Bin Mengf17cea62015-04-24 18:10:04 +080095}