Bin Meng | 5e2400e | 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> |
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 | 721e992 | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 10 | #include <asm/smbios.h> |
Bin Meng | 5e2400e | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 11 | #include <asm/tables.h> |
Saket Sinha | 867bcb6 | 2015-08-22 12:20:55 +0530 | [diff] [blame] | 12 | #include <asm/acpi_table.h> |
Bin Meng | 3cf2371 | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 13 | #include <asm/coreboot_tables.h> |
Bin Meng | 5e2400e | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 14 | |
Bin Meng | ef4d0a5 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 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 u32 (*table_write)(u32 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 | |
Bin Meng | 5e2400e | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 41 | u8 table_compute_checksum(void *v, int len) |
| 42 | { |
| 43 | u8 *bytes = v; |
| 44 | u8 checksum = 0; |
| 45 | int i; |
| 46 | |
| 47 | for (i = 0; i < len; i++) |
| 48 | checksum -= bytes[i]; |
| 49 | |
| 50 | return checksum; |
| 51 | } |
| 52 | |
Bin Meng | 7f5df8d | 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 | 5e2400e | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 67 | void write_tables(void) |
| 68 | { |
Bin Meng | ef4d0a5 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 69 | u32 rom_table_start = ROM_TABLE_ADDR; |
| 70 | u32 rom_table_end; |
Bin Meng | 3cf2371 | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 71 | #ifdef CONFIG_SEABIOS |
Bin Meng | ff94c21 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 72 | u32 high_table, table_size; |
Bin Meng | 3cf2371 | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 73 | struct memory_area cfg_tables[ARRAY_SIZE(table_write_funcs) + 1]; |
| 74 | #endif |
Bin Meng | ef4d0a5 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 75 | int i; |
Bin Meng | 5e2400e | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 76 | |
Bin Meng | ef4d0a5 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 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); |
Bin Meng | ff94c21 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 80 | |
Bin Meng | 3cf2371 | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 81 | #ifdef CONFIG_SEABIOS |
Bin Meng | ff94c21 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 82 | table_size = rom_table_end - rom_table_start; |
| 83 | high_table = (u32)memalign(ROM_TABLE_ALIGN, table_size); |
| 84 | if (high_table) { |
| 85 | memset((void *)high_table, 0, table_size); |
| 86 | table_write_funcs[i](high_table); |
Bin Meng | 3cf2371 | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 87 | |
| 88 | cfg_tables[i].start = high_table; |
| 89 | cfg_tables[i].size = table_size; |
Bin Meng | ff94c21 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 90 | } else { |
| 91 | printf("%d: no memory for configuration tables\n", i); |
| 92 | } |
Bin Meng | 3cf2371 | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 93 | #endif |
Bin Meng | ff94c21 | 2016-02-27 22:58:02 -0800 | [diff] [blame] | 94 | |
Bin Meng | ef4d0a5 | 2016-02-27 22:58:01 -0800 | [diff] [blame] | 95 | rom_table_start = rom_table_end; |
| 96 | } |
Bin Meng | 3cf2371 | 2016-02-28 23:54:50 -0800 | [diff] [blame] | 97 | |
| 98 | #ifdef CONFIG_SEABIOS |
| 99 | /* make sure the last item is zero */ |
| 100 | cfg_tables[i].size = 0; |
| 101 | write_coreboot_table(CB_TABLE_ADDR, cfg_tables); |
| 102 | #endif |
Bin Meng | 5e2400e | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 103 | } |