Hello Rizwan Qureshi,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/35229
to review the following change.
Change subject: src/soc/inte/common/block/cse: Add hmrfpo related functions to cse lib ......................................................................
src/soc/inte/common/block/cse: Add hmrfpo related functions to cse lib
Below new function are added: * send_hmrfpo_enable_msg() - Sends HMRFPO Enable command to CSE * send_hmrfpo_get_status_msg() - Sends HMRFPO Get Status command to CSE
Change-Id: I559bc4641e12df7ed39b1c97097bf068f9a232db Signed-off-by: Rizwan Qureshi rizwan.qureshi@intel.com Signed-off-by: sridhar sridhar.siricilla@intel.com --- M src/soc/intel/common/block/cse/cse.c M src/soc/intel/common/block/include/intelblocks/cse.h 2 files changed, 139 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/29/35229/1
diff --git a/src/soc/intel/common/block/cse/cse.c b/src/soc/intel/common/block/cse/cse.c index 9585a09..d85209b 100644 --- a/src/soc/intel/common/block/cse/cse.c +++ b/src/soc/intel/common/block/cse/cse.c @@ -76,6 +76,15 @@ /* RST Origin */ #define GR_ORIGIN_BIOS_POST 2
+#define MKHI_HMRFPO_GROUP_ID 5 + +/* HMRFPO Command Ids */ +#define MKHI_HMRFPO_ENABLE 1 +#define MKHI_HMRFPO_GET_STATUS 3 + +#define ME_HFS_CWS_NORMAL 5 +#define ME_HFS_MODE_NORMAL 0 + static struct cse_device { uintptr_t sec_bar; } g_cse; @@ -104,6 +113,16 @@ } __packed fields; };
+ +struct mkhi_hdr { + uint8_t group_id; + uint8_t command:7; + uint8_t is_resp:1; + uint8_t rsvd; + uint8_t result; +}__packed; + + /* * Initialize the device with provided temporary BAR. If BAR is 0 use a * default. This is intended for pre-mem usage only where BARs haven't been @@ -652,6 +671,109 @@ return 0; }
+/* + * Sends HMRFPO Enable command to CSE + */ +int send_hmrfpo_enable_msg(void) +{ + + struct hmrfpo_enable_msg { + struct mkhi_hdr hdr; + uint32_t nonce[2]; + }__packed; + + /* HMRFPO Enable message */ + struct hmrfpo_enable_msg msg = { + .hdr = { + .group_id = MKHI_HMRFPO_GROUP_ID, + .command = MKHI_HMRFPO_ENABLE, + }, + .nonce = {0}, + }; + + /* HMRFPO Enable response */ + struct hmrfpo_enable_resp { + struct mkhi_hdr hdr; + uint32_t fct_base; + uint32_t fct_limit; + uint8_t status; + uint8_t padding[3]; + }__packed; + + struct hmrfpo_enable_resp resp; + size_t resp_size = sizeof(struct hmrfpo_enable_resp); + union me_hfs hfs; + + printk(BIOS_DEBUG, "Send HMRFPO Enable Command\n"); + hfs.data = me_read_config32(PCI_ME_HFSTS1); + /* + * This command can be run only if: + * - Working state is normal and + * - Operation mode is normal. + */ + if ((hfs.fields.working_state != ME_HFS_CWS_NORMAL) || + (hfs.fields.operation_mode != ME_HFS_MODE_NORMAL)) { + printk(BIOS_ERR, "ME not in normal Mode\n"); + goto failed; + } + + if (!heci_send_receive(&msg, sizeof(struct hmrfpo_enable_msg), + &resp, &resp_size)) + goto failed; + + if (resp.hdr.result) { + printk(BIOS_ERR, "Heci resp Failed:%d\n", resp.hdr.result); + goto failed; + } + return 1; + +failed: + return 0; +} + +/* + * Sends HMRFPO Get Status command to CSE to get the HMRFPO status. + * The status can be DISABLES/LOCKED/ENABLED + */ +int send_hmrfpo_get_status_msg(void) +{ + struct hmrfpo_get_status_msg { + struct mkhi_hdr hdr; + }__packed; + + struct hmrfpo_get_status_resp { + struct mkhi_hdr hdr; + uint8_t status; + uint8_t padding[3]; + }__packed; + + /* HMRFPO STATUS message */ + struct hmrfpo_get_status_msg msg = { + .hdr = { + .group_id = MKHI_HMRFPO_GROUP_ID, + .command = MKHI_HMRFPO_GET_STATUS, + }, + }; + struct hmrfpo_get_status_resp resp; + size_t resp_size = sizeof(struct hmrfpo_get_status_resp); + + printk(BIOS_ERR, "HMRFPO Status Command\n"); + + if (!heci_send_receive(&msg, sizeof(struct hmrfpo_get_status_msg), + &resp, &resp_size)) + goto failed; + + if (resp.hdr.result) { + printk(BIOS_ERR, "Heci resp Failed:%d\n", resp.hdr.result); + goto failed; + } + + return resp.status; + +failed: + return -1; +} + #if ENV_RAMSTAGE
static void update_sec_bar(struct device *dev) diff --git a/src/soc/intel/common/block/include/intelblocks/cse.h b/src/soc/intel/common/block/include/intelblocks/cse.h index ceeca88e..c0a5fef 100644 --- a/src/soc/intel/common/block/include/intelblocks/cse.h +++ b/src/soc/intel/common/block/include/intelblocks/cse.h @@ -77,6 +77,19 @@ */ int send_heci_reset_req_message(u8 rst_type);
+/* + * Send HMRFPO_ENABLE command. + * returns 0 on failure and 1 on success. + */ +int send_hmrfpo_enable_msg(void); + +/* + * Send HMRFPO_GET_STATUS command. + * returns -1 on failure and 0 (DISABLED) or 1 (LOCKED) or 2 (ENABLED). + */ +int send_hmrfpo_get_status_msg(void); + + #define BIOS_HOST_ADDR 0x00 #define HECI_MKHI_ADDR 0x07
@@ -96,5 +109,9 @@ #define HOST_RESET_ONLY 2 #define CSE_RESET_ONLY 3
+/*HMRFPO Status types */ +#define MKHI_HMRFPO_DISABLED 0 +#define MKHI_HMRFPO_LOCKED 1 +#define MKHI_HMRFPO_ENABLED 2
#endif // SOC_INTEL_COMMON_MSR_H