Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 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> |
Alexander Graf | fb22808 | 2016-08-19 01:23:23 +0200 | [diff] [blame] | 8 | #include <smbios.h> |
Simon Glass | 07e922a | 2015-04-28 20:25:10 -0600 | [diff] [blame] | 9 | #include <asm/sfi.h> |
Bin Meng | c4f407e | 2015-06-23 12:18:52 +0800 | [diff] [blame] | 10 | #include <asm/mpspec.h> |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 11 | #include <asm/tables.h> |
Saket Sinha | 331141a | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 12 | #include <asm/acpi_table.h> |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 13 | #include <asm/coreboot_tables.h> |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 14 | |
Simon Glass | 5d3ee56 | 2016-11-07 08:47:03 -0700 | [diff] [blame] | 15 | #ifdef CONFIG_GENERATE_SMBIOS_TABLE |
Alexander Graf | e4a59ae | 2016-08-19 01:23:25 +0200 | [diff] [blame] | 16 | static u32 write_smbios_table_wrapper(u32 addr) |
| 17 | { |
| 18 | return write_smbios_table(addr); |
| 19 | } |
Simon Glass | 5d3ee56 | 2016-11-07 08:47:03 -0700 | [diff] [blame] | 20 | #endif |
Alexander Graf | e4a59ae | 2016-08-19 01:23:25 +0200 | [diff] [blame] | 21 | |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 22 | /** |
| 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 | */ |
| 28 | typedef u32 (*table_write)(u32 addr); |
| 29 | |
| 30 | static 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 Graf | e4a59ae | 2016-08-19 01:23:25 +0200 | [diff] [blame] | 44 | write_smbios_table_wrapper, |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 45 | #endif |
| 46 | }; |
| 47 | |
Bin Meng | f91cf6b | 2015-06-23 12:18:51 +0800 | [diff] [blame] | 48 | void 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 Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 62 | void write_tables(void) |
| 63 | { |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 64 | u32 rom_table_start = ROM_TABLE_ADDR; |
| 65 | u32 rom_table_end; |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 66 | #ifdef CONFIG_SEABIOS |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 67 | u32 high_table, table_size; |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 68 | struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1]; |
| 69 | #endif |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 70 | int i; |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 71 | |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 72 | 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 Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 75 | |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 76 | #ifdef CONFIG_SEABIOS |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 77 | table_size = rom_table_end - rom_table_start; |
Bin Meng | f828174 | 2016-05-11 07:45:02 -0700 | [diff] [blame] | 78 | high_table = (u32)high_table_malloc(table_size); |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 79 | if (high_table) { |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 80 | table_write_funcs[i](high_table); |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 81 | |
| 82 | cfg_tables[i].start = high_table; |
| 83 | cfg_tables[i].size = table_size; |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 84 | } else { |
| 85 | printf("%d: no memory for configuration tables\n", i); |
| 86 | } |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 87 | #endif |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 88 | |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 89 | rom_table_start = rom_table_end; |
| 90 | } |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 91 | |
| 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 Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 97 | } |