1 /* 2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <smbios.h> 9 #include <asm/sfi.h> 10 #include <asm/mpspec.h> 11 #include <asm/tables.h> 12 #include <asm/acpi_table.h> 13 #include <asm/coreboot_tables.h> 14 15 /** 16 * Function prototype to write a specific configuration table 17 * 18 * @addr: start address to write the table 19 * @return: end address of the table 20 */ 21 typedef ulong (*table_write)(ulong addr); 22 23 static table_write table_write_funcs[] = { 24 #ifdef CONFIG_GENERATE_PIRQ_TABLE 25 write_pirq_routing_table, 26 #endif 27 #ifdef CONFIG_GENERATE_SFI_TABLE 28 write_sfi_table, 29 #endif 30 #ifdef CONFIG_GENERATE_MP_TABLE 31 write_mp_table, 32 #endif 33 #ifdef CONFIG_GENERATE_ACPI_TABLE 34 write_acpi_tables, 35 #endif 36 #ifdef CONFIG_GENERATE_SMBIOS_TABLE 37 write_smbios_table, 38 #endif 39 }; 40 41 void table_fill_string(char *dest, const char *src, size_t n, char pad) 42 { 43 int start, len; 44 int i; 45 46 strncpy(dest, src, n); 47 48 /* Fill the remaining bytes with pad */ 49 len = strlen(src); 50 start = len < n ? len : n; 51 for (i = start; i < n; i++) 52 dest[i] = pad; 53 } 54 55 void write_tables(void) 56 { 57 u32 rom_table_start = ROM_TABLE_ADDR; 58 u32 rom_table_end; 59 #ifdef CONFIG_SEABIOS 60 u32 high_table, table_size; 61 struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1]; 62 #endif 63 int i; 64 65 for (i = 0; i < ARRAY_SIZE(table_write_funcs); i++) { 66 rom_table_end = table_write_funcs[i](rom_table_start); 67 rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN); 68 69 #ifdef CONFIG_SEABIOS 70 table_size = rom_table_end - rom_table_start; 71 high_table = (u32)high_table_malloc(table_size); 72 if (high_table) { 73 table_write_funcs[i](high_table); 74 75 cfg_tables[i].start = high_table; 76 cfg_tables[i].size = table_size; 77 } else { 78 printf("%d: no memory for configuration tables\n", i); 79 } 80 #endif 81 82 rom_table_start = rom_table_end; 83 } 84 85 #ifdef CONFIG_SEABIOS 86 /* make sure the last item is zero */ 87 cfg_tables[i].size = 0; 88 write_coreboot_table(CB_TABLE_ADDR, cfg_tables); 89 #endif 90 } 91