Martin Roth | 4b34193 | 2020-10-06 15:29:28 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 3 | #include <bootblock_common.h> |
Martin Roth | 4b34193 | 2020-10-06 15:29:28 -0600 | [diff] [blame] | 4 | #include <console/console.h> |
Martin Roth | 4b34193 | 2020-10-06 15:29:28 -0600 | [diff] [blame] | 5 | #include <soc/psp_transfer.h> |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 6 | #include <symbols.h> |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 7 | #include <timestamp.h> |
Raul E Rangel | 86302a8 | 2022-01-18 15:29:54 -0700 | [diff] [blame] | 8 | |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 9 | void boot_with_psp_timestamp(uint64_t base_timestamp) |
| 10 | { |
| 11 | const struct transfer_info_struct *info = (const struct transfer_info_struct *) |
| 12 | (void *)(uintptr_t)_transfer_buffer; |
| 13 | |
| 14 | if (!transfer_buffer_valid(info) || info->timestamp == 0) |
| 15 | return; |
| 16 | |
Raul E Rangel | 08de3e3 | 2022-02-25 17:10:09 -0700 | [diff] [blame^] | 17 | replay_transfer_buffer_cbmemc(); |
Raul E Rangel | 86302a8 | 2022-01-18 15:29:54 -0700 | [diff] [blame] | 18 | |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 19 | /* |
| 20 | * info->timestamp is PSP's timestamp (in microseconds) |
| 21 | * when x86 processor is released. |
| 22 | */ |
| 23 | uint64_t psp_last_ts = info->timestamp; |
| 24 | |
| 25 | int i; |
| 26 | struct timestamp_table *psp_ts_table = |
| 27 | (struct timestamp_table *)(void *) |
| 28 | ((uintptr_t)_transfer_buffer + info->timestamp_offset); |
| 29 | /* new base_timestamp will be offset for all PSP timestamps. */ |
| 30 | base_timestamp -= psp_last_ts; |
| 31 | |
| 32 | for (i = 0; i < psp_ts_table->num_entries; i++) { |
| 33 | struct timestamp_entry *tse = &psp_ts_table->entries[i]; |
| 34 | /* |
| 35 | * We ignore the time between x86 processor release and bootblock. |
| 36 | * Since timestamp_add subtracts base_time, we first add old base_time |
| 37 | * to make it absolute then add base_timestamp again since |
| 38 | * it'll be a new base_time. |
| 39 | * |
| 40 | * We don't need to convert unit since both PSP and coreboot |
| 41 | * will use 1us granularity. |
| 42 | * |
| 43 | */ |
| 44 | tse->entry_stamp += psp_ts_table->base_time + base_timestamp; |
| 45 | } |
| 46 | |
| 47 | bootblock_main_with_timestamp(base_timestamp, psp_ts_table->entries, |
| 48 | psp_ts_table->num_entries); |
| 49 | } |