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