From b1aded2f0ca2225d4363bec2e206e7c955df70c2 Mon Sep 17 00:00:00 2001 From: Andrey Petrov Date: Fri, 3 Mar 2017 08:12:36 -0800 Subject: soc/intel/apollolake: Add check if FPFs are blown Apollolake platform comes with FPF (field-programmable-fuses). FPF can be blown only once, typically at the end of the manufacturing process. This patch adds code that sends a request to CSE to figure out if FPFs have already been blown. Change-Id: I9e768a8b95a3cb48adf66e1f17803c720908802d Signed-off-by: Andrey Petrov Reviewed-on: https://review.coreboot.org/18604 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) --- src/soc/intel/apollolake/cse.c | 117 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) (limited to 'src/soc/intel/apollolake/cse.c') diff --git a/src/soc/intel/apollolake/cse.c b/src/soc/intel/apollolake/cse.c index ba3898dad0..a8e3b5b97f 100644 --- a/src/soc/intel/apollolake/cse.c +++ b/src/soc/intel/apollolake/cse.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -26,6 +27,106 @@ #define PCI_ME_HFSTS5 0x68 #define PCI_ME_HFSTS6 0x6c +#define MKHI_GROUP_ID_MCA 0x0a +#define READ_FILE 0x02 +#define READ_FILE_FLAG_DEFAULT (1 << 0) +#define READ_FILE_FLAG_HASH (1 << 1) +#define READ_FILE_FLAG_EMULATED (1 << 2) +#define READ_FILE_FLAG_HW (1 << 3) + +#define MCA_MAX_FILE_PATH_SIZE 64 + +#define FUSE_LOCK_FILE "/fpf/intel/SocCfgLock" + +static int8_t g_fuse_status; + +/* + * Read file from CSE internal filesystem. + * size is maximum length of provided buffer buff, which is updated with actual + * size of the file read. flags indicate whether real file or fuse is used. + * Returns 1 on success and 0 otherwise. + */ +static int read_cse_file(const char *path, void *buff, size_t *size, + size_t offset, uint32_t flags) +{ + int res; + size_t reply_size; + + union mkhi_header { + uint32_t data; + struct { + uint32_t group_id: 8; + uint32_t command: 7; + uint32_t is_response: 1; + uint32_t reserved: 8; + uint32_t result: 8; + } __attribute__ ((packed)) fields; + }; + + struct mca_command { + union mkhi_header mkhi_hdr; + char file_name[MCA_MAX_FILE_PATH_SIZE]; + uint32_t offset; + uint32_t data_size; + uint8_t flags; + } __attribute__ ((packed)) msg; + + struct mca_response { + union mkhi_header mkhi_hdr; + uint32_t data_size; + uint8_t buffer[128]; + } __attribute__ ((packed)) rmsg; + + if (sizeof(rmsg.buffer) < *size) { + printk(BIOS_ERR, "internal buffer is too small\n"); + return 0; + } + + strncpy(msg.file_name, path, sizeof(msg.file_name)); + msg.mkhi_hdr.fields.group_id = MKHI_GROUP_ID_MCA; + msg.mkhi_hdr.fields.command = READ_FILE; + msg.flags = flags; + msg.data_size = *size; + msg.offset = offset; + + res = heci_send(&msg, sizeof(msg), BIOS_HOST_ADDR, HECI_MKHI_ADDR); + + if (!res) { + printk(BIOS_ERR, "failed to send HECI message\n"); + return 0; + } + + reply_size = sizeof(rmsg); + res = heci_receive(&rmsg, &reply_size); + + if (!res) { + printk(BIOS_ERR, "failed to receive HECI reply\n"); + return 0; + } + + if (rmsg.data_size > *size) { + printk(BIOS_ERR, "reply is too large\n"); + return 0; + } + + memcpy(buff, rmsg.buffer, rmsg.data_size); + *size = rmsg.data_size; + + return 1; +} + +static void fpf_blown(void *unused) +{ + int8_t fuse; + size_t sz = sizeof(fuse); + + if (read_cse_file(FUSE_LOCK_FILE, &fuse, &sz, 0, READ_FILE_FLAG_HW)) { + g_fuse_status = fuse; + return; + } + g_fuse_status = -1; +} + static uint32_t dump_status(int index, int reg_addr) { uint32_t reg = pci_read_config32(HECI1_DEV, reg_addr); @@ -51,7 +152,21 @@ static void dump_cse_state(void *unused) the product so it's called out explicitly. */ printk(BIOS_DEBUG, "ME: Manufacturing Mode : %s\n", (fwsts1 & (1 << 0x4)) ? "YES" : "NO"); -} + printk(BIOS_DEBUG, "ME: FPF status : "); + switch (g_fuse_status) { + case 0: + printk(BIOS_DEBUG, "unfused"); + break; + case 1: + printk(BIOS_DEBUG, "fused"); + break; + default: + case -1: + printk(BIOS_DEBUG, "unknown"); + } + printk(BIOS_DEBUG, "\n"); +} +BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, fpf_blown, NULL); BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, dump_cse_state, NULL); BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, dump_cse_state, NULL); -- cgit v1.2.3