Martin Roth | 4b34193 | 2020-10-06 15:29:28 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <amdblocks/reset.h> |
Martin Roth | 0f3ef70 | 2020-10-06 18:11:12 -0600 | [diff] [blame] | 4 | #include <bl_uapp/bl_syscall_public.h> |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 5 | #include <bootblock_common.h> |
Martin Roth | 4b34193 | 2020-10-06 15:29:28 -0600 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <pc80/mc146818rtc.h> |
| 8 | #include <security/vboot/vbnv.h> |
| 9 | #include <security/vboot/symbols.h> |
| 10 | #include <soc/psp_transfer.h> |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 11 | #include <timestamp.h> |
Martin Roth | 4b34193 | 2020-10-06 15:29:28 -0600 | [diff] [blame] | 12 | #include <2struct.h> |
| 13 | |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 14 | static int transfer_buffer_valid(const struct transfer_info_struct *ptr) |
| 15 | { |
| 16 | if (ptr->magic_val == TRANSFER_MAGIC_VAL) |
| 17 | return 1; |
| 18 | else |
| 19 | return 0; |
| 20 | } |
| 21 | |
Martin Roth | 4b34193 | 2020-10-06 15:29:28 -0600 | [diff] [blame] | 22 | void verify_psp_transfer_buf(void) |
| 23 | { |
| 24 | if (*(uint32_t *)_vboot2_work == VB2_SHARED_DATA_MAGIC) { |
| 25 | cmos_write(0x00, CMOS_RECOVERY_BYTE); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | /* |
| 30 | * If CMOS is valid and the system has already been rebooted once, but |
| 31 | * still returns here, instead of rebooting to verstage again, assume |
| 32 | * that the system is in a reboot loop and halt. |
| 33 | */ |
| 34 | if ((!vbnv_cmos_failed()) && cmos_read(CMOS_RECOVERY_BYTE) == |
| 35 | CMOS_RECOVERY_MAGIC_VAL) |
| 36 | die("Error: Reboot into recovery was unsuccessful. Halting."); |
| 37 | |
| 38 | printk(BIOS_ERR, "ERROR: VBOOT workbuf not valid.\n"); |
| 39 | printk(BIOS_DEBUG, "Signature: %#08x\n", *(uint32_t *)_vboot2_work); |
| 40 | cmos_init(0); |
| 41 | cmos_write(CMOS_RECOVERY_MAGIC_VAL, CMOS_RECOVERY_BYTE); |
| 42 | warm_reset(); |
| 43 | } |
Martin Roth | 0f3ef70 | 2020-10-06 18:11:12 -0600 | [diff] [blame] | 44 | |
| 45 | void show_psp_transfer_info(void) |
| 46 | { |
| 47 | struct transfer_info_struct *info = (struct transfer_info_struct *) |
| 48 | (void *)(uintptr_t)_transfer_buffer; |
| 49 | |
Felix Held | 3e22cb6 | 2020-11-24 20:51:54 +0100 | [diff] [blame^] | 50 | if (transfer_buffer_valid(info)) { |
Martin Roth | 0f3ef70 | 2020-10-06 18:11:12 -0600 | [diff] [blame] | 51 | if ((info->psp_info & PSP_INFO_VALID) == 0) { |
| 52 | printk(BIOS_INFO, "No PSP info found in transfer buffer.\n"); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | printk(BIOS_INFO, "PSP boot mode: %s\n", |
| 57 | info->psp_info & PSP_INFO_PRODUCTION_MODE ? |
| 58 | "Production" : "Development"); |
| 59 | printk(BIOS_INFO, "Silicon level: %s\n", |
| 60 | info->psp_info & PSP_INFO_PRODUCTION_SILICON ? |
| 61 | "Production" : "Pre-Production"); |
| 62 | } |
| 63 | } |
Felix Held | cd50715 | 2020-11-24 20:37:15 +0100 | [diff] [blame] | 64 | |
| 65 | void boot_with_psp_timestamp(uint64_t base_timestamp) |
| 66 | { |
| 67 | const struct transfer_info_struct *info = (const struct transfer_info_struct *) |
| 68 | (void *)(uintptr_t)_transfer_buffer; |
| 69 | |
| 70 | if (!transfer_buffer_valid(info) || info->timestamp == 0) |
| 71 | return; |
| 72 | |
| 73 | /* |
| 74 | * info->timestamp is PSP's timestamp (in microseconds) |
| 75 | * when x86 processor is released. |
| 76 | */ |
| 77 | uint64_t psp_last_ts = info->timestamp; |
| 78 | |
| 79 | int i; |
| 80 | struct timestamp_table *psp_ts_table = |
| 81 | (struct timestamp_table *)(void *) |
| 82 | ((uintptr_t)_transfer_buffer + info->timestamp_offset); |
| 83 | /* new base_timestamp will be offset for all PSP timestamps. */ |
| 84 | base_timestamp -= psp_last_ts; |
| 85 | |
| 86 | for (i = 0; i < psp_ts_table->num_entries; i++) { |
| 87 | struct timestamp_entry *tse = &psp_ts_table->entries[i]; |
| 88 | /* |
| 89 | * We ignore the time between x86 processor release and bootblock. |
| 90 | * Since timestamp_add subtracts base_time, we first add old base_time |
| 91 | * to make it absolute then add base_timestamp again since |
| 92 | * it'll be a new base_time. |
| 93 | * |
| 94 | * We don't need to convert unit since both PSP and coreboot |
| 95 | * will use 1us granularity. |
| 96 | * |
| 97 | */ |
| 98 | tse->entry_stamp += psp_ts_table->base_time + base_timestamp; |
| 99 | } |
| 100 | |
| 101 | bootblock_main_with_timestamp(base_timestamp, psp_ts_table->entries, |
| 102 | psp_ts_table->num_entries); |
| 103 | } |