blob: 2787b73c6ed88f94039c251fd8d545b81e5473b7 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marshall Dawson68243a52017-06-15 16:59:20 -06002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Marshall Dawsond1cc3c22017-12-08 12:46:11 -07004#include <bootstate.h>
Marshall Dawson68243a52017-06-15 16:59:20 -06005#include <console/console.h>
6#include <amdblocks/psp.h>
Charles Marslett81655832018-07-24 10:43:33 -05007#include <soc/iomap.h>
Marshall Dawson3c578192020-01-19 17:16:01 -07008#include "psp_def.h"
Marshall Dawson68243a52017-06-15 16:59:20 -06009
10static const char *psp_status_nobase = "error: PSP BAR3 not assigned";
11static const char *psp_status_halted = "error: PSP in halted state";
12static const char *psp_status_recovery = "error: PSP recovery required";
13static const char *psp_status_errcmd = "error sending command";
14static const char *psp_status_init_timeout = "error: PSP init timeout";
15static const char *psp_status_cmd_timeout = "error: PSP command timeout";
16static const char *psp_status_noerror = "";
17
18static 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
Felix Held7d304182020-04-15 17:05:38 +020038static u32 rd_resp_sts(struct mbox_buffer_header *header)
Marshall Dawson68243a52017-06-15 16:59:20 -060039{
Felix Held7d304182020-04-15 17:05:38 +020040 return read32(&header->status);
Marshall Dawson68243a52017-06-15 16:59:20 -060041}
42
Marshall Dawson68243a52017-06-15 16:59:20 -060043/*
Marshall Dawson5646a642020-01-19 16:12:25 -070044 * Print meaningful status to the console. Caller only passes a pointer to a
Felix Held7d304182020-04-15 17:05:38 +020045 * buffer header if it's expected to contain its own status.
Marshall Dawson5646a642020-01-19 16:12:25 -070046 */
Felix Held7d304182020-04-15 17:05:38 +020047void psp_print_cmd_status(int cmd_status, struct mbox_buffer_header *header)
Marshall Dawson5646a642020-01-19 16:12:25 -070048{
Felix Held7d304182020-04-15 17:05:38 +020049 if (header && rd_resp_sts(header))
50 printk(BIOS_DEBUG, "buffer status=0x%x ", rd_resp_sts(header));
Marshall Dawson5646a642020-01-19 16:12:25 -070051
52 if (cmd_status)
53 printk(BIOS_DEBUG, "%s\n", status_to_string(cmd_status));
54 else
55 printk(BIOS_DEBUG, "OK\n");
56}
57
58/*
Marshall Dawson68243a52017-06-15 16:59:20 -060059 * Notify the PSP that DRAM is present. Upon receiving this command, the PSP
60 * will load its OS into fenced DRAM that is not accessible to the x86 cores.
61 */
62int psp_notify_dram(void)
63{
Marshall Dawson68243a52017-06-15 16:59:20 -060064 int cmd_status;
Marshall Dawson66dd3992017-12-13 10:51:13 -070065 struct mbox_default_buffer buffer = {
66 .header = {
67 .size = sizeof(buffer)
68 }
69 };
Marshall Dawson68243a52017-06-15 16:59:20 -060070
71 printk(BIOS_DEBUG, "PSP: Notify that DRAM is available... ");
72
Marshall Dawson68243a52017-06-15 16:59:20 -060073 cmd_status = send_psp_command(MBOX_BIOS_CMD_DRAM_INFO, &buffer);
74
75 /* buffer's status shouldn't change but report it if it does */
Felix Held7d304182020-04-15 17:05:38 +020076 psp_print_cmd_status(cmd_status, &buffer.header);
Marshall Dawson68243a52017-06-15 16:59:20 -060077
78 return cmd_status;
79}
Marshall Dawson596ecec2017-10-12 16:04:08 -060080
81/*
Marshall Dawsond1cc3c22017-12-08 12:46:11 -070082 * Notify the PSP that the system is completing the boot process. Upon
83 * receiving this command, the PSP will only honor commands where the buffer
84 * is in SMM space.
85 */
86static void psp_notify_boot_done(void *unused)
87{
88 int cmd_status;
89 struct mbox_default_buffer buffer = {
90 .header = {
91 .size = sizeof(buffer)
92 }
93 };
94
95 printk(BIOS_DEBUG, "PSP: Notify that POST is finishing... ");
96
97 cmd_status = send_psp_command(MBOX_BIOS_CMD_BOOT_DONE, &buffer);
98
99 /* buffer's status shouldn't change but report it if it does */
Felix Held7d304182020-04-15 17:05:38 +0200100 psp_print_cmd_status(cmd_status, &buffer.header);
Marshall Dawson596ecec2017-10-12 16:04:08 -0600101}
Marshall Dawsond1cc3c22017-12-08 12:46:11 -0700102
103BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY,
104 psp_notify_boot_done, NULL);