| 1 |
|
| 2 |
|
| 3 |
#include <device/mmio.h> |
| 4 |
#include <cpu/x86/msr.h> |
| 5 |
#include <cpu/amd/msr.h> |
| 6 |
#include <region_file.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <amdblocks/psp.h> |
| 9 |
#include <amdblocks/smi.h> |
| 10 |
#include <soc/iomap.h> |
| 11 |
#include <spi_flash.h> |
| 12 |
#include <string.h> |
| 13 |
|
| 14 |
#include "psp_def.h" |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
struct { |
| 22 |
uint8_t buffer[C2P_BUFFER_MAXSIZE]; |
| 23 |
} __aligned(32) c2p_buffer; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
struct { |
| 30 |
uint8_t buffer[P2C_BUFFER_MAXSIZE]; |
| 31 |
} __aligned(32) p2c_buffer; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
static uint32_t smm_flag; |
| 38 |
|
| 39 |
static void set_smm_flag(void) |
| 40 |
{ |
| 41 |
smm_flag = 1; |
| 42 |
} |
| 43 |
|
| 44 |
static void clear_smm_flag(void) |
| 45 |
{ |
| 46 |
smm_flag = 0; |
| 47 |
} |
| 48 |
|
| 49 |
static int send_psp_command_smm(uint32_t command, void *buffer) |
| 50 |
{ |
| 51 |
int cmd_status; |
| 52 |
|
| 53 |
set_smm_flag(); |
| 54 |
cmd_status = send_psp_command(command, buffer); |
| 55 |
clear_smm_flag(); |
| 56 |
|
| 57 |
return cmd_status; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
int psp_notify_smm(void) |
| 68 |
{ |
| 69 |
msr_t msr; |
| 70 |
int cmd_status; |
| 71 |
struct mbox_cmd_smm_info_buffer buffer = { |
| 72 |
.header = { |
| 73 |
.size = sizeof(buffer) |
| 74 |
}, |
| 75 |
.req = { |
| 76 |
.psp_smm_data_region = (uintptr_t)p2c_buffer.buffer, |
| 77 |
.psp_smm_data_length = sizeof(p2c_buffer), |
| 78 |
.psp_mbox_smm_buffer_address = (uintptr_t)c2p_buffer.buffer, |
| 79 |
.psp_mbox_smm_flag_address = (uintptr_t)&smm_flag, |
| 80 |
} |
| 81 |
}; |
| 82 |
|
| 83 |
msr = rdmsr(SMM_ADDR_MSR); |
| 84 |
buffer.req.smm_base = msr.raw; |
| 85 |
msr = rdmsr(SMM_MASK_MSR); |
| 86 |
msr.lo &= 0xffff0000; |
| 87 |
buffer.req.smm_mask = msr.raw; |
| 88 |
|
| 89 |
soc_fill_smm_trig_info(&buffer.req.smm_trig_info); |
| 90 |
#if (CONFIG(SOC_AMD_COMMON_BLOCK_PSP_GEN2)) |
| 91 |
soc_fill_smm_reg_info(&buffer.req.smm_reg_info); |
| 92 |
#endif |
| 93 |
|
| 94 |
if (CONFIG(SOC_AMD_COMMON_BLOCK_PSP_SMI)) { |
| 95 |
configure_psp_smi(); |
| 96 |
enable_psp_smi(); |
| 97 |
|
| 98 |
|
| 99 |
assert(boot_device_spi_flash()); |
| 100 |
} |
| 101 |
|
| 102 |
printk(BIOS_DEBUG, "PSP: Notify SMM info... "); |
| 103 |
|
| 104 |
cmd_status = send_psp_command_smm(MBOX_BIOS_CMD_SMM_INFO, &buffer); |
| 105 |
|
| 106 |
|
| 107 |
psp_print_cmd_status(cmd_status, &buffer.header); |
| 108 |
|
| 109 |
return cmd_status; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
void psp_notify_sx_info(uint8_t sleep_type) |
| 114 |
{ |
| 115 |
int cmd_status; |
| 116 |
struct mbox_cmd_sx_info_buffer *buffer; |
| 117 |
|
| 118 |
|
| 119 |
buffer = (struct mbox_cmd_sx_info_buffer *)c2p_buffer.buffer; |
| 120 |
memset(buffer, 0, sizeof(*buffer)); |
| 121 |
buffer->header.size = sizeof(*buffer); |
| 122 |
|
| 123 |
if (sleep_type > MBOX_BIOS_CMD_SX_INFO_SLEEP_TYPE_MAX) { |
| 124 |
printk(BIOS_ERR, "PSP: BUG: invalid sleep type 0x%x requested\n", sleep_type); |
| 125 |
return; |
| 126 |
} |
| 127 |
|
| 128 |
printk(BIOS_DEBUG, "PSP: Prepare to enter sleep state %d... ", sleep_type); |
| 129 |
|
| 130 |
buffer->sleep_type = sleep_type; |
| 131 |
|
| 132 |
cmd_status = send_psp_command_smm(MBOX_BIOS_CMD_SX_INFO, buffer); |
| 133 |
|
| 134 |
|
| 135 |
psp_print_cmd_status(cmd_status, &buffer->header); |
| 136 |
} |