soc/mediatek/mt8196: Correct the region size for mcufw_reserved
[coreboot2.git] / src / soc / amd / common / block / psp / psp.c
blob9ad04e1ce60b0ecd9907033226c77014ae9aba9f
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/mmio.h>
4 #include <bootstate.h>
5 #include <console/console.h>
6 #include <amdblocks/psp.h>
7 #include <soc/iomap.h>
8 #include "psp_def.h"
10 static const char *psp_status_nobase = "error: PSP_ADDR_MSR and PSP BAR3 not assigned";
11 static const char *psp_status_halted = "error: PSP in halted state";
12 static const char *psp_status_recovery = "error: PSP recovery required";
13 static const char *psp_status_errcmd = "error sending command";
14 static const char *psp_status_init_timeout = "error: PSP init timeout";
15 static const char *psp_status_cmd_timeout = "error: PSP command timeout";
16 static const char *psp_status_noerror = "";
18 static const char *status_to_string(int err)
20 switch (err) {
21 case -PSPSTS_NOBASE:
22 return psp_status_nobase;
23 case -PSPSTS_HALTED:
24 return psp_status_halted;
25 case -PSPSTS_RECOVERY:
26 return psp_status_recovery;
27 case -PSPSTS_SEND_ERROR:
28 return psp_status_errcmd;
29 case -PSPSTS_INIT_TIMEOUT:
30 return psp_status_init_timeout;
31 case -PSPSTS_CMD_TIMEOUT:
32 return psp_status_cmd_timeout;
33 default:
34 return psp_status_noerror;
38 static uint32_t rd_resp_sts(struct mbox_buffer_header *header)
40 return read32(&header->status);
44 * Print meaningful status to the console. Caller only passes a pointer to a
45 * buffer header if it's expected to contain its own status.
47 void psp_print_cmd_status(int cmd_status, struct mbox_buffer_header *header)
49 if (header && rd_resp_sts(header))
50 printk(BIOS_DEBUG, "buffer status=0x%x ", rd_resp_sts(header));
52 if (cmd_status)
53 printk(BIOS_WARNING, "%s\n", status_to_string(cmd_status));
54 else
55 printk(BIOS_DEBUG, "OK\n");
58 enum cb_err psp_get_ftpm_capabilties(uint32_t *capabilities)
60 int cmd_status;
61 struct mbox_cmd_capability_query_buffer buffer = {
62 .header = {
63 .size = sizeof(buffer)
67 printk(BIOS_DEBUG, "PSP: Querying fTPM capabilities...");
69 cmd_status = send_psp_command(MBOX_BIOS_CMD_PSP_FTPM_QUERY, &buffer);
71 /* buffer's status shouldn't change but report it if it does */
72 psp_print_cmd_status(cmd_status, &buffer.header);
74 if (cmd_status)
75 return CB_ERR;
77 *capabilities = read32(&buffer.capabilities);
78 return CB_SUCCESS;
81 enum cb_err psp_get_hsti_state(uint32_t *state)
83 int cmd_status;
84 struct mbox_cmd_hsti_query_buffer buffer = {
85 .header = {
86 .size = sizeof(buffer)
90 printk(BIOS_DEBUG, "PSP: Querying HSTI state...");
92 cmd_status = send_psp_command(MBOX_BIOS_CMD_HSTI_QUERY, &buffer);
94 /* buffer's status shouldn't change but report it if it does */
95 psp_print_cmd_status(cmd_status, &buffer.header);
97 if (cmd_status)
98 return CB_ERR;
100 *state = read32(&buffer.state);
101 return CB_SUCCESS;
105 * Notify the PSP that the system is completing the boot process. Upon
106 * receiving this command, the PSP will only honor commands where the buffer
107 * is in SMM space.
109 static void psp_notify_boot_done(void *unused)
111 int cmd_status;
112 struct mbox_default_buffer buffer = {
113 .header = {
114 .size = sizeof(buffer)
118 printk(BIOS_DEBUG, "PSP: Notify that POST is finishing... ");
120 cmd_status = send_psp_command(MBOX_BIOS_CMD_BOOT_DONE, &buffer);
122 /* buffer's status shouldn't change but report it if it does */
123 psp_print_cmd_status(cmd_status, &buffer.header);
126 BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, psp_notify_boot_done, NULL);