Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 7 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 8 | #include <malloc.h> |
Alexander Graf | fb22808 | 2016-08-19 01:23:23 +0200 | [diff] [blame] | 9 | #include <smbios.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 10 | #include <acpi/acpi_table.h> |
Simon Glass | 07e922a | 2015-04-28 20:25:10 -0600 | [diff] [blame] | 11 | #include <asm/sfi.h> |
Bin Meng | c4f407e | 2015-06-23 12:18:52 +0800 | [diff] [blame] | 12 | #include <asm/mpspec.h> |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 13 | #include <asm/tables.h> |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 14 | #include <asm/coreboot_tables.h> |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 15 | |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 16 | /** |
| 17 | * Function prototype to write a specific configuration table |
| 18 | * |
| 19 | * @addr: start address to write the table |
| 20 | * @return: end address of the table |
| 21 | */ |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 22 | typedef ulong (*table_write)(ulong addr); |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 23 | |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 24 | /** |
| 25 | * struct table_info - Information about each table to write |
| 26 | * |
| 27 | * @name: Name of table (for debugging) |
| 28 | * @write: Function to call to write this table |
| 29 | */ |
| 30 | struct table_info { |
| 31 | const char *name; |
| 32 | table_write write; |
| 33 | }; |
| 34 | |
| 35 | static struct table_info table_list[] = { |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 36 | #ifdef CONFIG_GENERATE_PIRQ_TABLE |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 37 | { "pirq", write_pirq_routing_table }, |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 38 | #endif |
| 39 | #ifdef CONFIG_GENERATE_SFI_TABLE |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 40 | { "sfi", write_sfi_table, }, |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 41 | #endif |
| 42 | #ifdef CONFIG_GENERATE_MP_TABLE |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 43 | { "mp", write_mp_table, }, |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 44 | #endif |
| 45 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 46 | { "acpi", write_acpi_tables, }, |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 47 | #endif |
| 48 | #ifdef CONFIG_GENERATE_SMBIOS_TABLE |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 49 | { "smbios", write_smbios_table, }, |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 50 | #endif |
| 51 | }; |
| 52 | |
Bin Meng | f91cf6b | 2015-06-23 12:18:51 +0800 | [diff] [blame] | 53 | void table_fill_string(char *dest, const char *src, size_t n, char pad) |
| 54 | { |
| 55 | int start, len; |
| 56 | int i; |
| 57 | |
| 58 | strncpy(dest, src, n); |
| 59 | |
| 60 | /* Fill the remaining bytes with pad */ |
| 61 | len = strlen(src); |
| 62 | start = len < n ? len : n; |
| 63 | for (i = start; i < n; i++) |
| 64 | dest[i] = pad; |
| 65 | } |
| 66 | |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 67 | void write_tables(void) |
| 68 | { |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 69 | u32 rom_table_start = ROM_TABLE_ADDR; |
| 70 | u32 rom_table_end; |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 71 | #ifdef CONFIG_SEABIOS |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 72 | u32 high_table, table_size; |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 73 | struct memory_area cfg_tables[ARRAY_SIZE(table_list) + 1]; |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 74 | #endif |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 75 | int i; |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 76 | |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 77 | debug("Writing tables to %x:\n", rom_table_start); |
| 78 | for (i = 0; i < ARRAY_SIZE(table_list); i++) { |
| 79 | const struct table_info *table = &table_list[i]; |
| 80 | |
| 81 | rom_table_end = table->write(rom_table_start); |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 82 | rom_table_end = ALIGN(rom_table_end, ROM_TABLE_ALIGN); |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 83 | |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 84 | #ifdef CONFIG_SEABIOS |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 85 | table_size = rom_table_end - rom_table_start; |
Bin Meng | f828174 | 2016-05-11 07:45:02 -0700 | [diff] [blame] | 86 | high_table = (u32)high_table_malloc(table_size); |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 87 | if (high_table) { |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 88 | table->write(high_table); |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 89 | |
| 90 | cfg_tables[i].start = high_table; |
| 91 | cfg_tables[i].size = table_size; |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 92 | } else { |
| 93 | printf("%d: no memory for configuration tables\n", i); |
| 94 | } |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 95 | #endif |
Bin Meng | ca68d77 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 96 | |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 97 | debug("- wrote '%s' to %x, end %x\n", table->name, |
| 98 | rom_table_start, rom_table_end); |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 99 | rom_table_start = rom_table_end; |
| 100 | } |
Bin Meng | 96030fa | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 101 | |
| 102 | #ifdef CONFIG_SEABIOS |
| 103 | /* make sure the last item is zero */ |
| 104 | cfg_tables[i].size = 0; |
| 105 | write_coreboot_table(CB_TABLE_ADDR, cfg_tables); |
| 106 | #endif |
Simon Glass | f66fb30 | 2020-07-16 21:22:31 -0600 | [diff] [blame] | 107 | debug("- done writing tables\n"); |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 108 | } |