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> |
Felix Held | 26d54b7 | 2023-03-24 20:37:47 +0100 | [diff] [blame] | 5 | #include <cpu/x86/tsc.h> |
Martin Roth | 4b34193 | 2020-10-06 15:29:28 -0600 | [diff] [blame] | 6 | #include <soc/psp_transfer.h> |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 7 | #include <symbols.h> |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 8 | #include <timestamp.h> |
Felix Held | 26d54b7 | 2023-03-24 20:37:47 +0100 | [diff] [blame] | 9 | #include <types.h> |
| 10 | |
| 11 | /* |
| 12 | * Verstage on PSP uses the weak timestamp_tick_freq_mhz implementation returning 1, so the |
| 13 | * unit of the timestamps in the transfer buffer is microseconds. The x86 side uses the TSC |
| 14 | * rate as reference for the timestamps, so the values from the PSP transfer buffer need to be |
| 15 | * multiplied by the TSC frequency in MHz. |
| 16 | */ |
| 17 | static uint64_t timestamp_from_usec(uint64_t usec) |
| 18 | { |
| 19 | return usec * tsc_freq_mhz(); |
| 20 | } |
Raul E Rangel | 86302a8 | 2022-01-18 15:29:54 -0700 | [diff] [blame] | 21 | |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 22 | void boot_with_psp_timestamp(uint64_t base_timestamp) |
| 23 | { |
| 24 | const struct transfer_info_struct *info = (const struct transfer_info_struct *) |
| 25 | (void *)(uintptr_t)_transfer_buffer; |
| 26 | |
| 27 | if (!transfer_buffer_valid(info) || info->timestamp == 0) |
| 28 | return; |
| 29 | |
Raul E Rangel | 08de3e3 | 2022-02-25 17:10:09 -0700 | [diff] [blame] | 30 | replay_transfer_buffer_cbmemc(); |
Raul E Rangel | 86302a8 | 2022-01-18 15:29:54 -0700 | [diff] [blame] | 31 | |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 32 | /* |
| 33 | * info->timestamp is PSP's timestamp (in microseconds) |
| 34 | * when x86 processor is released. |
| 35 | */ |
Felix Held | 26d54b7 | 2023-03-24 20:37:47 +0100 | [diff] [blame] | 36 | uint64_t psp_last_ts_usec = info->timestamp; |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 37 | |
| 38 | int i; |
| 39 | struct timestamp_table *psp_ts_table = |
| 40 | (struct timestamp_table *)(void *) |
| 41 | ((uintptr_t)_transfer_buffer + info->timestamp_offset); |
| 42 | /* new base_timestamp will be offset for all PSP timestamps. */ |
Felix Held | 26d54b7 | 2023-03-24 20:37:47 +0100 | [diff] [blame] | 43 | base_timestamp -= timestamp_from_usec(psp_last_ts_usec); |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 44 | |
| 45 | for (i = 0; i < psp_ts_table->num_entries; i++) { |
| 46 | struct timestamp_entry *tse = &psp_ts_table->entries[i]; |
| 47 | /* |
| 48 | * We ignore the time between x86 processor release and bootblock. |
| 49 | * Since timestamp_add subtracts base_time, we first add old base_time |
| 50 | * to make it absolute then add base_timestamp again since |
| 51 | * it'll be a new base_time. |
| 52 | * |
Felix Held | 26d54b7 | 2023-03-24 20:37:47 +0100 | [diff] [blame] | 53 | * Verstage on PSP uses a 1 microsecond timestamp granularity while the x86 |
| 54 | * part of coreboot uses the TSC tick time as granularity, so this needs to be |
| 55 | * converted. |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 56 | */ |
Felix Held | 26d54b7 | 2023-03-24 20:37:47 +0100 | [diff] [blame] | 57 | tse->entry_stamp += timestamp_from_usec(psp_ts_table->base_time) + |
| 58 | base_timestamp; |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | bootblock_main_with_timestamp(base_timestamp, psp_ts_table->entries, |
| 62 | psp_ts_table->num_entries); |
| 63 | } |