blob: 5966e5862a31eddf5c2d39e582a6ec98e0c871d5 [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
Simon Glass5d3ee562016-11-07 08:47:03 -070015#ifdef CONFIG_GENERATE_SMBIOS_TABLE
Alexander Grafe4a59ae2016-08-19 01:23:25 +020016static u32 write_smbios_table_wrapper(u32 addr)
17{
18 return write_smbios_table(addr);
19}
Simon Glass5d3ee562016-11-07 08:47:03 -070020#endif
Alexander Grafe4a59ae2016-08-19 01:23:25 +020021
Bin Mengef47ed12016-02-27 22:58:01 -080022/**
23 * Function prototype to write a specific configuration table
24 *
25 * @addr: start address to write the table
26 * @return: end address of the table
27 */
28typedef u32 (*table_write)(u32 addr);
29
30static table_write table_write_funcs[] = {
31#ifdef CONFIG_GENERATE_PIRQ_TABLE
32 write_pirq_routing_table,
33#endif
34#ifdef CONFIG_GENERATE_SFI_TABLE
35 write_sfi_table,
36#endif
37#ifdef CONFIG_GENERATE_MP_TABLE
38 write_mp_table,
39#endif
40#ifdef CONFIG_GENERATE_ACPI_TABLE
41 write_acpi_tables,
42#endif
43#ifdef CONFIG_GENERATE_SMBIOS_TABLE
Alexander Grafe4a59ae2016-08-19 01:23:25 +020044 write_smbios_table_wrapper,
Bin Mengef47ed12016-02-27 22:58:01 -080045#endif
46};
47
Bin Mengf91cf6b2015-06-23 12:18:51 +080048void table_fill_string(char *dest, const char *src, size_t n, char pad)
49{
50 int start, len;
51 int i;
52
53 strncpy(dest, src, n);
54
55 /* Fill the remaining bytes with pad */
56 len = strlen(src);
57 start = len < n ? len : n;
58 for (i = start; i < n; i++)
59 dest[i] = pad;
60}
61
Bin Mengf17cea62015-04-24 18:10:04 +080062void write_tables(void)
63{
Bin Mengef47ed12016-02-27 22:58:01 -080064 u32 rom_table_start = ROM_TABLE_ADDR;
65 u32 rom_table_end;
Bin Meng96030fa2016-02-28 23:54:50 -080066#ifdef CONFIG_SEABIOS
Bin Mengca68d772016-02-27 22:58:02 -080067 u32 high_table, table_size;
Bin Meng96030fa2016-02-28 23:54:50 -080068 struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
69#endif
Bin Mengef47ed12016-02-27 22:58:01 -080070 int i;
Bin Mengf17cea62015-04-24 18:10:04 +080071
Bin Mengef47ed12016-02-27 22:58:01 -080072 for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
73 rom_table_end = table_write_funcs[i](rom_table_start);
74 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
Bin Mengca68d772016-02-27 22:58:02 -080075
Bin Meng96030fa2016-02-28 23:54:50 -080076#ifdef CONFIG_SEABIOS
Bin Mengca68d772016-02-27 22:58:02 -080077 table_size = rom_table_end - rom_table_start;
Bin Mengf8281742016-05-11 07:45:02 -070078 high_table = (u32)high_table_malloc(table_size);
Bin Mengca68d772016-02-27 22:58:02 -080079 if (high_table) {
Bin Mengca68d772016-02-27 22:58:02 -080080 table_write_funcs[i](high_table);
Bin Meng96030fa2016-02-28 23:54:50 -080081
82 cfg_tables[i].start = high_table;
83 cfg_tables[i].size = table_size;
Bin Mengca68d772016-02-27 22:58:02 -080084 } else {
85 printf("%d: no memory for configuration tables\n", i);
86 }
Bin Meng96030fa2016-02-28 23:54:50 -080087#endif
Bin Mengca68d772016-02-27 22:58:02 -080088
Bin Mengef47ed12016-02-27 22:58:01 -080089 rom_table_start = rom_table_end;
90 }
Bin Meng96030fa2016-02-28 23:54:50 -080091
92#ifdef CONFIG_SEABIOS
93 /* make sure the last item is zero */
94 cfg_tables[i].size = 0;
95 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
96#endif
Bin Mengf17cea62015-04-24 18:10:04 +080097}