blob: 9d1d34710d0d2277efe45843afb4b538ab105201 [file] [log] [blame]
Martin Roth4b341932020-10-06 15:29:28 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <amdblocks/reset.h>
Felix Heldcd507152020-11-24 20:37:15 +01004#include <bootblock_common.h>
Raul E Rangel86302a82022-01-18 15:29:54 -07005#include <console/cbmem_console.h>
Martin Roth4b341932020-10-06 15:29:28 -06006#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 Heldcd507152020-11-24 20:37:15 +010011#include <timestamp.h>
Martin Roth4b341932020-10-06 15:29:28 -060012#include <2struct.h>
13
Felix Heldcd507152020-11-24 20:37:15 +010014static int transfer_buffer_valid(const struct transfer_info_struct *ptr)
15{
Raul E Rangel3b589c82022-01-18 15:05:49 -070016 if (ptr->magic_val == TRANSFER_MAGIC_VAL && ptr->struct_bytes == sizeof(*ptr))
Felix Heldcd507152020-11-24 20:37:15 +010017 return 1;
18 else
19 return 0;
20}
21
Martin Roth4b341932020-10-06 15:29:28 -060022void 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 Roth0f3ef702020-10-06 18:11:12 -060044
45void show_psp_transfer_info(void)
46{
47 struct transfer_info_struct *info = (struct transfer_info_struct *)
48 (void *)(uintptr_t)_transfer_buffer;
49
Felix Held3e22cb62020-11-24 20:51:54 +010050 if (transfer_buffer_valid(info)) {
Martin Roth0f3ef702020-10-06 18:11:12 -060051 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 Heldcd507152020-11-24 20:37:15 +010064
Raul E Rangel86302a82022-01-18 15:29:54 -070065static void setup_cbmem_console(const struct transfer_info_struct *info)
66{
67
68 void *cbmemc;
69 size_t cbmemc_size;
70
71 if (info->console_offset < sizeof(*info))
72 return;
73
74 if (info->timestamp_offset <= info->console_offset)
75 return;
76
77 cbmemc_size = info->timestamp_offset - info->console_offset;
78
79 if (info->console_offset + cbmemc_size > info->buffer_size)
80 return;
81
82 cbmemc = (void *)((uintptr_t)info + info->console_offset);
83
84 /* We need to manually initialize cbmemc so we can fill the new buffer. cbmemc_init()
85 * will also be called later in console_hw_init(), but it will be a no-op. */
86 cbmemc_init();
87 cbmemc_copy_in(cbmemc, cbmemc_size);
88}
89
Felix Heldcd507152020-11-24 20:37:15 +010090void boot_with_psp_timestamp(uint64_t base_timestamp)
91{
92 const struct transfer_info_struct *info = (const struct transfer_info_struct *)
93 (void *)(uintptr_t)_transfer_buffer;
94
95 if (!transfer_buffer_valid(info) || info->timestamp == 0)
96 return;
97
Raul E Rangel86302a82022-01-18 15:29:54 -070098 setup_cbmem_console(info);
99
Felix Heldcd507152020-11-24 20:37:15 +0100100 /*
101 * info->timestamp is PSP's timestamp (in microseconds)
102 * when x86 processor is released.
103 */
104 uint64_t psp_last_ts = info->timestamp;
105
106 int i;
107 struct timestamp_table *psp_ts_table =
108 (struct timestamp_table *)(void *)
109 ((uintptr_t)_transfer_buffer + info->timestamp_offset);
110 /* new base_timestamp will be offset for all PSP timestamps. */
111 base_timestamp -= psp_last_ts;
112
113 for (i = 0; i < psp_ts_table->num_entries; i++) {
114 struct timestamp_entry *tse = &psp_ts_table->entries[i];
115 /*
116 * We ignore the time between x86 processor release and bootblock.
117 * Since timestamp_add subtracts base_time, we first add old base_time
118 * to make it absolute then add base_timestamp again since
119 * it'll be a new base_time.
120 *
121 * We don't need to convert unit since both PSP and coreboot
122 * will use 1us granularity.
123 *
124 */
125 tse->entry_stamp += psp_ts_table->base_time + base_timestamp;
126 }
127
128 bootblock_main_with_timestamp(base_timestamp, psp_ts_table->entries,
129 psp_ts_table->num_entries);
130}