Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <amdblocks/reset.h> |
| 4 | #include <console/cbmem_console.h> |
| 5 | #include <console/console.h> |
| 6 | #include <pc80/mc146818rtc.h> |
| 7 | #include <security/vboot/vbnv.h> |
| 8 | #include <security/vboot/symbols.h> |
| 9 | #include <soc/psp_transfer.h> |
| 10 | #include <timestamp.h> |
| 11 | #include <2struct.h> |
| 12 | |
Raul E Rangel | bd58aea | 2022-02-28 12:43:02 -0700 | [diff] [blame^] | 13 | DECLARE_REGION(cbmemc_transfer) |
| 14 | |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 15 | int transfer_buffer_valid(const struct transfer_info_struct *ptr) |
| 16 | { |
| 17 | if (ptr->magic_val == TRANSFER_MAGIC_VAL && ptr->struct_bytes == sizeof(*ptr)) |
| 18 | return 1; |
| 19 | else |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | void verify_psp_transfer_buf(void) |
| 24 | { |
| 25 | if (*(uint32_t *)_vboot2_work == VB2_SHARED_DATA_MAGIC) { |
| 26 | cmos_write(0x00, CMOS_RECOVERY_BYTE); |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | /* |
| 31 | * If CMOS is valid and the system has already been rebooted once, but |
| 32 | * still returns here, instead of rebooting to verstage again, assume |
| 33 | * that the system is in a reboot loop and halt. |
| 34 | */ |
| 35 | if ((!vbnv_cmos_failed()) && cmos_read(CMOS_RECOVERY_BYTE) == |
| 36 | CMOS_RECOVERY_MAGIC_VAL) |
| 37 | die("Error: Reboot into recovery was unsuccessful. Halting."); |
| 38 | |
| 39 | printk(BIOS_ERR, "VBOOT workbuf not valid.\n"); |
| 40 | printk(BIOS_DEBUG, "Signature: %#08x\n", *(uint32_t *)_vboot2_work); |
| 41 | cmos_init(0); |
| 42 | cmos_write(CMOS_RECOVERY_MAGIC_VAL, CMOS_RECOVERY_BYTE); |
| 43 | warm_reset(); |
| 44 | } |
| 45 | |
| 46 | void show_psp_transfer_info(void) |
| 47 | { |
| 48 | struct transfer_info_struct *info = (struct transfer_info_struct *) |
| 49 | (void *)(uintptr_t)_transfer_buffer; |
| 50 | |
| 51 | if (transfer_buffer_valid(info)) { |
| 52 | if ((info->psp_info & PSP_INFO_VALID) == 0) { |
| 53 | printk(BIOS_INFO, "No PSP info found in transfer buffer.\n"); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | printk(BIOS_INFO, "PSP boot mode: %s\n", |
| 58 | info->psp_info & PSP_INFO_PRODUCTION_MODE ? |
| 59 | "Production" : "Development"); |
| 60 | printk(BIOS_INFO, "Silicon level: %s\n", |
| 61 | info->psp_info & PSP_INFO_PRODUCTION_SILICON ? |
| 62 | "Production" : "Pre-Production"); |
| 63 | } |
| 64 | } |
| 65 | |
Raul E Rangel | 08de3e3 | 2022-02-25 17:10:09 -0700 | [diff] [blame] | 66 | void replay_transfer_buffer_cbmemc(void) |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 67 | { |
Raul E Rangel | 08de3e3 | 2022-02-25 17:10:09 -0700 | [diff] [blame] | 68 | const struct transfer_info_struct *info = (const struct transfer_info_struct *) |
| 69 | (void *)(uintptr_t)_transfer_buffer; |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 70 | |
| 71 | void *cbmemc; |
| 72 | size_t cbmemc_size; |
| 73 | |
Raul E Rangel | 08de3e3 | 2022-02-25 17:10:09 -0700 | [diff] [blame] | 74 | if (!transfer_buffer_valid(info)) |
| 75 | return; |
| 76 | |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 77 | if (info->console_offset < sizeof(*info)) |
| 78 | return; |
| 79 | |
| 80 | if (info->timestamp_offset <= info->console_offset) |
| 81 | return; |
| 82 | |
| 83 | cbmemc_size = info->timestamp_offset - info->console_offset; |
| 84 | |
| 85 | if (info->console_offset + cbmemc_size > info->buffer_size) |
| 86 | return; |
| 87 | |
| 88 | cbmemc = (void *)((uintptr_t)info + info->console_offset); |
| 89 | |
Raul E Rangel | bd58aea | 2022-02-28 12:43:02 -0700 | [diff] [blame^] | 90 | /* Verify the cbmemc transfer buffer is where we expect it to be. */ |
| 91 | if ((void *)_cbmemc_transfer != (void *)cbmemc) |
| 92 | return; |
| 93 | |
| 94 | if (REGION_SIZE(cbmemc_transfer) != cbmemc_size) |
| 95 | return; |
| 96 | |
Raul E Rangel | fe1418d | 2022-02-24 12:36:38 -0700 | [diff] [blame] | 97 | /* We need to manually initialize cbmemc so we can fill the new buffer. cbmemc_init() |
| 98 | * will also be called later in console_hw_init(), but it will be a no-op. */ |
| 99 | cbmemc_init(); |
| 100 | cbmemc_copy_in(cbmemc, cbmemc_size); |
| 101 | } |