xref: /aosp_15_r20/external/coreboot/src/soc/amd/common/block/psp/psp.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
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"
9 
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 = "";
17 
status_to_string(int err)18 static const char *status_to_string(int err)
19 {
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;
35 	}
36 }
37 
rd_resp_sts(struct mbox_buffer_header * header)38 static u32 rd_resp_sts(struct mbox_buffer_header *header)
39 {
40 	return read32(&header->status);
41 }
42 
43 /*
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.
46  */
psp_print_cmd_status(int cmd_status,struct mbox_buffer_header * header)47 void psp_print_cmd_status(int cmd_status, struct mbox_buffer_header *header)
48 {
49 	if (header && rd_resp_sts(header))
50 		printk(BIOS_DEBUG, "buffer status=0x%x ", rd_resp_sts(header));
51 
52 	if (cmd_status)
53 		printk(BIOS_WARNING, "%s\n", status_to_string(cmd_status));
54 	else
55 		printk(BIOS_DEBUG, "OK\n");
56 }
57 
58 /*
59  * Notify the PSP that the system is completing the boot process.  Upon
60  * receiving this command, the PSP will only honor commands where the buffer
61  * is in SMM space.
62  */
psp_notify_boot_done(void * unused)63 static void psp_notify_boot_done(void *unused)
64 {
65 	int cmd_status;
66 	struct mbox_default_buffer buffer = {
67 		.header = {
68 			.size = sizeof(buffer)
69 		}
70 	};
71 
72 	printk(BIOS_DEBUG, "PSP: Notify that POST is finishing... ");
73 
74 	cmd_status = send_psp_command(MBOX_BIOS_CMD_BOOT_DONE, &buffer);
75 
76 	/* buffer's status shouldn't change but report it if it does */
77 	psp_print_cmd_status(cmd_status, &buffer.header);
78 }
79 
80 BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, psp_notify_boot_done, NULL);
81