Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 2 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 3 | #include <device/mmio.h> |
Marshall Dawson | d1cc3c2 | 2017-12-08 12:46:11 -0700 | [diff] [blame] | 4 | #include <bootstate.h> |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <amdblocks/psp.h> |
Charles Marslett | 8165583 | 2018-07-24 10:43:33 -0500 | [diff] [blame] | 7 | #include <soc/iomap.h> |
Marshall Dawson | 3c57819 | 2020-01-19 17:16:01 -0700 | [diff] [blame] | 8 | #include "psp_def.h" |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 9 | |
| 10 | static const char *psp_status_nobase = "error: 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 | |
| 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 | |
Felix Held | 7d30418 | 2020-04-15 17:05:38 +0200 | [diff] [blame] | 38 | static u32 rd_resp_sts(struct mbox_buffer_header *header) |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 39 | { |
Felix Held | 7d30418 | 2020-04-15 17:05:38 +0200 | [diff] [blame] | 40 | return read32(&header->status); |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 41 | } |
| 42 | |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 43 | /* |
Marshall Dawson | 5646a64 | 2020-01-19 16:12:25 -0700 | [diff] [blame] | 44 | * Print meaningful status to the console. Caller only passes a pointer to a |
Felix Held | 7d30418 | 2020-04-15 17:05:38 +0200 | [diff] [blame] | 45 | * buffer header if it's expected to contain its own status. |
Marshall Dawson | 5646a64 | 2020-01-19 16:12:25 -0700 | [diff] [blame] | 46 | */ |
Felix Held | 7d30418 | 2020-04-15 17:05:38 +0200 | [diff] [blame] | 47 | void psp_print_cmd_status(int cmd_status, struct mbox_buffer_header *header) |
Marshall Dawson | 5646a64 | 2020-01-19 16:12:25 -0700 | [diff] [blame] | 48 | { |
Felix Held | 7d30418 | 2020-04-15 17:05:38 +0200 | [diff] [blame] | 49 | if (header && rd_resp_sts(header)) |
| 50 | printk(BIOS_DEBUG, "buffer status=0x%x ", rd_resp_sts(header)); |
Marshall Dawson | 5646a64 | 2020-01-19 16:12:25 -0700 | [diff] [blame] | 51 | |
| 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 Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 59 | * 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 | */ |
| 62 | int psp_notify_dram(void) |
| 63 | { |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 64 | int cmd_status; |
Marshall Dawson | 66dd399 | 2017-12-13 10:51:13 -0700 | [diff] [blame] | 65 | struct mbox_default_buffer buffer = { |
| 66 | .header = { |
| 67 | .size = sizeof(buffer) |
| 68 | } |
| 69 | }; |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 70 | |
| 71 | printk(BIOS_DEBUG, "PSP: Notify that DRAM is available... "); |
| 72 | |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 73 | 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 Held | 7d30418 | 2020-04-15 17:05:38 +0200 | [diff] [blame] | 76 | psp_print_cmd_status(cmd_status, &buffer.header); |
Marshall Dawson | 68243a5 | 2017-06-15 16:59:20 -0600 | [diff] [blame] | 77 | |
| 78 | return cmd_status; |
| 79 | } |
Marshall Dawson | 596ecec | 2017-10-12 16:04:08 -0600 | [diff] [blame] | 80 | |
| 81 | /* |
Marshall Dawson | d1cc3c2 | 2017-12-08 12:46:11 -0700 | [diff] [blame] | 82 | * 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 | */ |
| 86 | static 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 Held | 7d30418 | 2020-04-15 17:05:38 +0200 | [diff] [blame] | 100 | psp_print_cmd_status(cmd_status, &buffer.header); |
Marshall Dawson | 596ecec | 2017-10-12 16:04:08 -0600 | [diff] [blame] | 101 | } |
Marshall Dawson | d1cc3c2 | 2017-12-08 12:46:11 -0700 | [diff] [blame] | 102 | |
| 103 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, |
| 104 | psp_notify_boot_done, NULL); |