2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/mpspec.h>
11 #include <asm/smbios.h>
12 #include <asm/tables.h>
13 #include <asm/acpi_table.h>
14 #include <asm/coreboot_tables.h>
17 * Function prototype to write a specific configuration table
19 * @addr: start address to write the table
20 * @return: end address of the table
22 typedef u32 (*table_write)(u32 addr);
24 static table_write table_write_funcs[] = {
25 #ifdef CONFIG_GENERATE_PIRQ_TABLE
26 write_pirq_routing_table,
28 #ifdef CONFIG_GENERATE_SFI_TABLE
31 #ifdef CONFIG_GENERATE_MP_TABLE
34 #ifdef CONFIG_GENERATE_ACPI_TABLE
37 #ifdef CONFIG_GENERATE_SMBIOS_TABLE
42 u8 table_compute_checksum(void *v, int len)
48 for (i = 0; i < len; i++)
54 void table_fill_string(char *dest, const char *src, size_t n, char pad)
59 strncpy(dest, src, n);
61 /* Fill the remaining bytes with pad */
63 start = len < n ? len : n;
64 for (i = start; i < n; i++)
68 void write_tables(void)
70 u32 rom_table_start = ROM_TABLE_ADDR;
73 u32 high_table, table_size;
74 struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
78 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);
83 table_size = rom_table_end - rom_table_start;
84 high_table = (u32)memalign(ROM_TABLE_ALIGN, table_size);
86 memset((void *)high_table, 0, table_size);
87 table_write_funcs[i](high_table);
89 cfg_tables[i].start = high_table;
90 cfg_tables[i].size = table_size;
92 printf("%d: no memory for configuration tables\n", i);
96 rom_table_start = rom_table_end;
100 /* make sure the last item is zero */
101 cfg_tables[i].size = 0;
102 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);