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