blob: 1213a9cd2b8c3c8b1f765a7314c4329d40a8778d [file] [log] [blame]
Bin Meng5e2400e2015-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>
Bin Meng5cb0f0d2016-05-07 07:46:11 -07008#include <malloc.h>
Simon Glass6388e352015-04-28 20:25:10 -06009#include <asm/sfi.h>
Bin Meng07545d82015-06-23 12:18:52 +080010#include <asm/mpspec.h>
Bin Meng721e9922015-10-12 05:23:41 -070011#include <asm/smbios.h>
Bin Meng5e2400e2015-04-24 18:10:04 +080012#include <asm/tables.h>
Saket Sinha867bcb62015-08-22 12:20:55 +053013#include <asm/acpi_table.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 */
22typedef u32 (*table_write)(u32 addr);
23
24static table_write table_write_funcs[] = {
25#ifdef CONFIG_GENERATE_PIRQ_TABLE
26 write_pirq_routing_table,
27#endif
28#ifdef CONFIG_GENERATE_SFI_TABLE
29 write_sfi_table,
30#endif
31#ifdef CONFIG_GENERATE_MP_TABLE
32 write_mp_table,
33#endif
34#ifdef CONFIG_GENERATE_ACPI_TABLE
35 write_acpi_tables,
36#endif
37#ifdef CONFIG_GENERATE_SMBIOS_TABLE
38 write_smbios_table,
39#endif
40};
41
Bin Meng5e2400e2015-04-24 18:10:04 +080042u8 table_compute_checksum(void *v, int len)
43{
44 u8 *bytes = v;
45 u8 checksum = 0;
46 int i;
47
48 for (i = 0; i < len; i++)
49 checksum -= bytes[i];
50
51 return checksum;
52}
53
Bin Meng7f5df8d2015-06-23 12:18:51 +080054void table_fill_string(char *dest, const char *src, size_t n, char pad)
55{
56 int start, len;
57 int i;
58
59 strncpy(dest, src, n);
60
61 /* Fill the remaining bytes with pad */
62 len = strlen(src);
63 start = len < n ? len : n;
64 for (i = start; i < n; i++)
65 dest[i] = pad;
66}
67
Bin Meng5e2400e2015-04-24 18:10:04 +080068void write_tables(void)
69{
Bin Mengef4d0a52016-02-27 22:58:01 -080070 u32 rom_table_start = ROM_TABLE_ADDR;
71 u32 rom_table_end;
Bin Meng3cf23712016-02-28 23:54:50 -080072#ifdef CONFIG_SEABIOS
Bin Mengff94c212016-02-27 22:58:02 -080073 u32 high_table, table_size;
Bin Meng3cf23712016-02-28 23:54:50 -080074 struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
75#endif
Bin Mengef4d0a52016-02-27 22:58:01 -080076 int i;
Bin Meng5e2400e2015-04-24 18:10:04 +080077
Bin Mengef4d0a52016-02-27 22:58:01 -080078 for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
79 rom_table_end = table_write_funcs[i](rom_table_start);
80 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
Bin Mengff94c212016-02-27 22:58:02 -080081
Bin Meng3cf23712016-02-28 23:54:50 -080082#ifdef CONFIG_SEABIOS
Bin Mengff94c212016-02-27 22:58:02 -080083 table_size = rom_table_end - rom_table_start;
84 high_table = (u32)memalign(ROM_TABLE_ALIGN, table_size);
85 if (high_table) {
86 memset((void *)high_table, 0, table_size);
87 table_write_funcs[i](high_table);
Bin Meng3cf23712016-02-28 23:54:50 -080088
89 cfg_tables[i].start = high_table;
90 cfg_tables[i].size = table_size;
Bin Mengff94c212016-02-27 22:58:02 -080091 } else {
92 printf("%d: no memory for configuration tables\n", i);
93 }
Bin Meng3cf23712016-02-28 23:54:50 -080094#endif
Bin Mengff94c212016-02-27 22:58:02 -080095
Bin Mengef4d0a52016-02-27 22:58:01 -080096 rom_table_start = rom_table_end;
97 }
Bin Meng3cf23712016-02-28 23:54:50 -080098
99#ifdef CONFIG_SEABIOS
100 /* make sure the last item is zero */
101 cfg_tables[i].size = 0;
102 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);
103#endif
Bin Meng5e2400e2015-04-24 18:10:04 +0800104}