1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/mmio.h>
5 #include <console/console.h>
6 #include <amdblocks/psp.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
)
22 return psp_status_nobase
;
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
;
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
));
53 printk(BIOS_WARNING
, "%s\n", status_to_string(cmd_status
));
55 printk(BIOS_DEBUG
, "OK\n");
58 enum cb_err
psp_get_ftpm_capabilties(uint32_t *capabilities
)
61 struct mbox_cmd_capability_query_buffer buffer
= {
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
);
77 *capabilities
= read32(&buffer
.capabilities
);
81 enum cb_err
psp_get_hsti_state(uint32_t *state
)
84 struct mbox_cmd_hsti_query_buffer buffer
= {
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
);
100 *state
= read32(&buffer
.state
);
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
109 static void psp_notify_boot_done(void *unused
)
112 struct mbox_default_buffer buffer
= {
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
);