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> |
Simon Glass | 07e922a | 2015-04-28 20:25:10 -0600 | [diff] [blame] | 8 | #include <asm/sfi.h> |
Bin Meng | c4f407e | 2015-06-23 12:18:52 +0800 | [diff] [blame] | 9 | #include <asm/mpspec.h> |
Bin Meng | ae5bedb | 2015-10-12 05:23:41 -0700 | [diff] [blame] | 10 | #include <asm/smbios.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 | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 13 | |
Bin Meng | ef47ed1 | 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 | */ |
| 20 | typedef u32 (*table_write)(u32 addr); |
| 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 |
| 36 | write_smbios_table, |
| 37 | #endif |
| 38 | }; |
| 39 | |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 40 | u8 table_compute_checksum(void *v, int len) |
| 41 | { |
| 42 | u8 *bytes = v; |
| 43 | u8 checksum = 0; |
| 44 | int i; |
| 45 | |
| 46 | for (i = 0; i < len; i++) |
| 47 | checksum -= bytes[i]; |
| 48 | |
| 49 | return checksum; |
| 50 | } |
| 51 | |
Bin Meng | f91cf6b | 2015-06-23 12:18:51 +0800 | [diff] [blame] | 52 | void table_fill_string(char *dest, const char *src, size_t n, char pad) |
| 53 | { |
| 54 | int start, len; |
| 55 | int i; |
| 56 | |
| 57 | strncpy(dest, src, n); |
| 58 | |
| 59 | /* Fill the remaining bytes with pad */ |
| 60 | len = strlen(src); |
| 61 | start = len < n ? len : n; |
| 62 | for (i = start; i < n; i++) |
| 63 | dest[i] = pad; |
| 64 | } |
| 65 | |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 66 | void write_tables(void) |
| 67 | { |
Bin Meng | ef47ed1 | 2016-02-27 22:58:01 -0800 | [diff] [blame^] | 68 | u32 rom_table_start = ROM_TABLE_ADDR; |
| 69 | u32 rom_table_end; |
| 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); |
| 75 | rom_table_start = rom_table_end; |
| 76 | } |
Bin Meng | f17cea6 | 2015-04-24 18:10:04 +0800 | [diff] [blame] | 77 | } |