drivers/usb/acpi: Don't add GPIOs to _CRS for Intel Bluetooth
[coreboot2.git] / src / soc / amd / common / vboot / transfer_buffer.c
blob4adb6dc2a8dc79b1dc893f7bdc6bd62f44f60c8c
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <amdblocks/reset.h>
4 #include <console/cbmem_console.h>
5 #include <console/console.h>
6 #include <pc80/mc146818rtc.h>
7 #include <psp_verstage/psp_transfer.h>
8 #include <security/vboot/vbnv.h>
9 #include <security/vboot/symbols.h>
10 #include <2struct.h>
12 DECLARE_REGION(cbmemc_transfer)
14 int transfer_buffer_valid(const struct transfer_info_struct *ptr)
16 if (ptr->magic_val == TRANSFER_MAGIC_VAL && ptr->struct_bytes == sizeof(*ptr))
17 return 1;
18 else
19 return 0;
22 void verify_psp_transfer_buf(void)
24 if (*(uint32_t *)_vboot2_work == VB2_SHARED_DATA_MAGIC) {
25 cmos_write(0x00, CMOS_RECOVERY_BYTE);
26 return;
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.
34 if ((!vbnv_cmos_failed()) && cmos_read(CMOS_RECOVERY_BYTE) ==
35 CMOS_RECOVERY_MAGIC_VAL)
36 die("Error: Reboot into recovery was unsuccessful. Halting.");
38 printk(BIOS_ERR, "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();
45 void show_psp_transfer_info(void)
47 struct transfer_info_struct *info = (struct transfer_info_struct *)
48 (void *)(uintptr_t)_transfer_buffer;
50 if (transfer_buffer_valid(info)) {
51 if ((info->psp_info & PSP_INFO_VALID) == 0) {
52 printk(BIOS_INFO, "No PSP info found in transfer buffer.\n");
53 return;
56 printk(BIOS_INFO, "PSP boot mode: %s\n",
57 info->psp_info & PSP_INFO_PRODUCTION_MODE ?
58 "Production" : "Development");
62 void replay_transfer_buffer_cbmemc(void)
64 const struct transfer_info_struct *info = (const struct transfer_info_struct *)
65 (void *)(uintptr_t)_transfer_buffer;
67 void *cbmemc;
68 size_t cbmemc_size;
70 if (!transfer_buffer_valid(info))
71 return;
73 if (info->console_offset < sizeof(*info))
74 return;
76 if (info->timestamp_offset <= info->console_offset)
77 return;
79 cbmemc_size = info->timestamp_offset - info->console_offset;
81 if (info->console_offset + cbmemc_size > info->buffer_size)
82 return;
84 cbmemc = (void *)((uintptr_t)info + info->console_offset);
86 /* Verify the cbmemc transfer buffer is where we expect it to be. */
87 if ((void *)_cbmemc_transfer != (void *)cbmemc)
88 return;
90 if (REGION_SIZE(cbmemc_transfer) != cbmemc_size)
91 return;
93 /* We need to manually initialize cbmemc so we can fill the new buffer. cbmemc_init()
94 * will also be called later in console_hw_init(), but it will be a no-op. */
95 cbmemc_init();
96 cbmemc_copy_in(cbmemc, cbmemc_size);