| 1 |
|
| 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 |
|
| 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 |
|
| 38 |
static uint32_t rd_resp_sts(struct mbox_buffer_header *header) |
| 39 |
{ |
| 40 |
return read32(&header->status); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 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 |
enum cb_err psp_get_ftpm_capabilties(uint32_t *capabilities) |
| 59 |
{ |
| 60 |
int cmd_status; |
| 61 |
struct mbox_cmd_capability_query_buffer buffer = { |
| 62 |
.header = { |
| 63 |
.size = sizeof(buffer) |
| 64 |
}, |
| 65 |
}; |
| 66 |
|
| 67 |
printk(BIOS_DEBUG, "PSP: Querying fTPM capabilities..."); |
| 68 |
|
| 69 |
cmd_status = send_psp_command(MBOX_BIOS_CMD_PSP_FTPM_QUERY, &buffer); |
| 70 |
|
| 71 |
|
| 72 |
psp_print_cmd_status(cmd_status, &buffer.header); |
| 73 |
|
| 74 |
if (cmd_status) |
| 75 |
return CB_ERR; |
| 76 |
|
| 77 |
*capabilities = read32(&buffer.capabilities); |
| 78 |
return CB_SUCCESS; |
| 79 |
} |
| 80 |
|
| 81 |
enum cb_err psp_get_hsti_state(uint32_t *state) |
| 82 |
{ |
| 83 |
int cmd_status; |
| 84 |
struct mbox_cmd_hsti_query_buffer buffer = { |
| 85 |
.header = { |
| 86 |
.size = sizeof(buffer) |
| 87 |
}, |
| 88 |
}; |
| 89 |
|
| 90 |
printk(BIOS_DEBUG, "PSP: Querying HSTI state..."); |
| 91 |
|
| 92 |
cmd_status = send_psp_command(MBOX_BIOS_CMD_HSTI_QUERY, &buffer); |
| 93 |
|
| 94 |
|
| 95 |
psp_print_cmd_status(cmd_status, &buffer.header); |
| 96 |
|
| 97 |
if (cmd_status) |
| 98 |
return CB_ERR; |
| 99 |
|
| 100 |
*state = read32(&buffer.state); |
| 101 |
return CB_SUCCESS; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
static void psp_notify_boot_done(void *unused) |
| 110 |
{ |
| 111 |
int cmd_status; |
| 112 |
struct mbox_default_buffer buffer = { |
| 113 |
.header = { |
| 114 |
.size = sizeof(buffer) |
| 115 |
} |
| 116 |
}; |
| 117 |
|
| 118 |
printk(BIOS_DEBUG, "PSP: Notify that POST is finishing... "); |
| 119 |
|
| 120 |
cmd_status = send_psp_command(MBOX_BIOS_CMD_BOOT_DONE, &buffer); |
| 121 |
|
| 122 |
|
| 123 |
psp_print_cmd_status(cmd_status, &buffer.header); |
| 124 |
} |
| 125 |
|
| 126 |
BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, psp_notify_boot_done, NULL); |