2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/mpspec.h>
10 #include <asm/smbios.h>
11 #include <asm/tables.h>
12 #include <asm/acpi_table.h>
13 #include <asm/coreboot_tables.h>
16 * Function prototype to write a specific configuration table
18 * @addr: start address to write the table
19 * @return: end address of the table
21 typedef u32 (*table_write)(u32 addr);
23 static table_write table_write_funcs[] = {
24 #ifdef CONFIG_GENERATE_PIRQ_TABLE
25 write_pirq_routing_table,
27 #ifdef CONFIG_GENERATE_SFI_TABLE
30 #ifdef CONFIG_GENERATE_MP_TABLE
33 #ifdef CONFIG_GENERATE_ACPI_TABLE
36 #ifdef CONFIG_GENERATE_SMBIOS_TABLE
41 u8 table_compute_checksum(void *v, int len)
47 for (i = 0; i < len; i++)
53 void table_fill_string(char *dest, const char *src, size_t n, char pad)
58 strncpy(dest, src, n);
60 /* Fill the remaining bytes with pad */
62 start = len < n ? len : n;
63 for (i = start; i < n; i++)
67 void write_tables(void)
69 u32 rom_table_start = ROM_TABLE_ADDR;
72 u32 high_table, table_size;
73 struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1];
77 for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) {
78 rom_table_end = table_write_funcs[i](rom_table_start);
79 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN);
82 table_size = rom_table_end - rom_table_start;
83 high_table = (u32)memalign(ROM_TABLE_ALIGN, table_size);
85 memset((void *)high_table, 0, table_size);
86 table_write_funcs[i](high_table);
88 cfg_tables[i].start = high_table;
89 cfg_tables[i].size = table_size;
91 printf("%d: no memory for configuration tables\n", i);
95 rom_table_start = rom_table_end;
99 /* make sure the last item is zero */
100 cfg_tables[i].size = 0;
101 write_coreboot_table(CB_TABLE_ADDR, cfg_tables);