Angel Pons | a2ee761 | 2020-04-04 18:51:15 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 2 | |
Elyes HAOUAS | 0edf6a5 | 2019-10-26 18:41:47 +0200 | [diff] [blame] | 3 | #include <boot/coreboot_tables.h> |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 4 | #include <cbfs.h> |
| 5 | #include <cbmem.h> |
| 6 | #include <console/console.h> |
| 7 | #include <soc/mtc.h> |
| 8 | #include <string.h> |
| 9 | |
| 10 | static size_t mtc_table_size; |
| 11 | |
| 12 | #define MAX_MTC_TABLE_ENTRIES 20 |
| 13 | #define MTC_TABLE_ENTRY_SIZE 4880 |
| 14 | #define MTC_TABLE_MAX_SIZE (MAX_MTC_TABLE_ENTRIES * MTC_TABLE_ENTRY_SIZE) |
| 15 | |
| 16 | int tegra210_run_mtc(void) |
| 17 | { |
Julius Werner | 77639e4 | 2021-02-05 16:51:25 -0800 | [diff] [blame] | 18 | size_t nread; |
Elyes HAOUAS | 39303d5 | 2018-07-08 12:40:45 +0200 | [diff] [blame] | 19 | void *const mtc = (void *)(uintptr_t)CONFIG_MTC_ADDRESS; |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 20 | void *dvfs_table; |
| 21 | size_t (*mtc_fw)(void **dvfs_table) = (void *)mtc; |
| 22 | |
Julius Werner | 77639e4 | 2021-02-05 16:51:25 -0800 | [diff] [blame] | 23 | nread = cbfs_load("tegra_mtc.bin", mtc, 1*GiB); |
| 24 | if (!nread) { |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 25 | printk(BIOS_ERR, "MTC file not found: tegra_mtc.bin\n"); |
| 26 | return -1; |
| 27 | } |
| 28 | |
Patrick Georgi | 40a3e32 | 2015-06-22 19:41:29 +0200 | [diff] [blame] | 29 | printk(BIOS_INFO, "MTC: %zu bytes loaded @ %p\n", nread, mtc); |
| 30 | |
| 31 | mtc_table_size = (*mtc_fw)(&dvfs_table); |
| 32 | |
| 33 | if ((mtc_table_size == 0) || (mtc_table_size > MTC_TABLE_MAX_SIZE)) { |
| 34 | printk(BIOS_ERR, "MTC Training table size is invalid.!\n"); |
| 35 | return -1; |
| 36 | } |
| 37 | |
| 38 | printk(BIOS_INFO, "MTC: Done. Entries size 0x%zx located at %p\n", |
| 39 | mtc_table_size, dvfs_table); |
| 40 | |
| 41 | void *cbmem_tab = cbmem_add(CBMEM_ID_MTC, mtc_table_size); |
| 42 | if (cbmem_tab == NULL) { |
| 43 | printk(BIOS_ERR, "MTC table allocation in cbmem failed!\n"); |
| 44 | return -1; |
| 45 | } |
| 46 | |
| 47 | memcpy(cbmem_tab, dvfs_table, mtc_table_size); |
| 48 | printk(BIOS_INFO, "MTC: Copied 0x%zx bytes from %p to %p\n", |
| 49 | mtc_table_size, dvfs_table, cbmem_tab); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | void soc_add_mtc(struct lb_header *header) |
| 55 | { |
| 56 | struct lb_range *mtc; |
| 57 | mtc = (struct lb_range *)lb_new_record(header); |
| 58 | mtc->tag = LB_TAG_MTC; |
| 59 | mtc->size = sizeof(*mtc); |
| 60 | |
| 61 | mtc->range_start = (uintptr_t)cbmem_find(CBMEM_ID_MTC); |
| 62 | mtc->range_size = mtc_table_size; |
| 63 | } |