Aaron Durbin | 7d14af8 | 2017-02-07 11:33:56 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2017 Google, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
| 17 | #include <bootstate.h> |
| 18 | #include <console/console.h> |
Andrey Petrov | b1aded2 | 2017-03-03 08:12:36 -0800 | [diff] [blame] | 19 | #include <intelblocks/cse.h> |
Aaron Durbin | 7d14af8 | 2017-02-07 11:33:56 -0600 | [diff] [blame] | 20 | #include <soc/pci_devs.h> |
| 21 | #include <stdint.h> |
| 22 | |
| 23 | #define PCI_ME_HFSTS1 0x40 |
| 24 | #define PCI_ME_HFSTS2 0x48 |
| 25 | #define PCI_ME_HFSTS3 0x60 |
| 26 | #define PCI_ME_HFSTS4 0x64 |
| 27 | #define PCI_ME_HFSTS5 0x68 |
| 28 | #define PCI_ME_HFSTS6 0x6c |
| 29 | |
Andrey Petrov | b1aded2 | 2017-03-03 08:12:36 -0800 | [diff] [blame] | 30 | #define MKHI_GROUP_ID_MCA 0x0a |
| 31 | #define READ_FILE 0x02 |
| 32 | #define READ_FILE_FLAG_DEFAULT (1 << 0) |
| 33 | #define READ_FILE_FLAG_HASH (1 << 1) |
| 34 | #define READ_FILE_FLAG_EMULATED (1 << 2) |
| 35 | #define READ_FILE_FLAG_HW (1 << 3) |
| 36 | |
| 37 | #define MCA_MAX_FILE_PATH_SIZE 64 |
| 38 | |
| 39 | #define FUSE_LOCK_FILE "/fpf/intel/SocCfgLock" |
| 40 | |
| 41 | static int8_t g_fuse_status; |
| 42 | |
| 43 | /* |
| 44 | * Read file from CSE internal filesystem. |
| 45 | * size is maximum length of provided buffer buff, which is updated with actual |
| 46 | * size of the file read. flags indicate whether real file or fuse is used. |
| 47 | * Returns 1 on success and 0 otherwise. |
| 48 | */ |
| 49 | static int read_cse_file(const char *path, void *buff, size_t *size, |
| 50 | size_t offset, uint32_t flags) |
| 51 | { |
| 52 | int res; |
| 53 | size_t reply_size; |
| 54 | |
| 55 | union mkhi_header { |
| 56 | uint32_t data; |
| 57 | struct { |
| 58 | uint32_t group_id: 8; |
| 59 | uint32_t command: 7; |
| 60 | uint32_t is_response: 1; |
| 61 | uint32_t reserved: 8; |
| 62 | uint32_t result: 8; |
| 63 | } __attribute__ ((packed)) fields; |
| 64 | }; |
| 65 | |
| 66 | struct mca_command { |
| 67 | union mkhi_header mkhi_hdr; |
| 68 | char file_name[MCA_MAX_FILE_PATH_SIZE]; |
| 69 | uint32_t offset; |
| 70 | uint32_t data_size; |
| 71 | uint8_t flags; |
| 72 | } __attribute__ ((packed)) msg; |
| 73 | |
| 74 | struct mca_response { |
| 75 | union mkhi_header mkhi_hdr; |
| 76 | uint32_t data_size; |
| 77 | uint8_t buffer[128]; |
| 78 | } __attribute__ ((packed)) rmsg; |
| 79 | |
| 80 | if (sizeof(rmsg.buffer) < *size) { |
| 81 | printk(BIOS_ERR, "internal buffer is too small\n"); |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | strncpy(msg.file_name, path, sizeof(msg.file_name)); |
| 86 | msg.mkhi_hdr.fields.group_id = MKHI_GROUP_ID_MCA; |
| 87 | msg.mkhi_hdr.fields.command = READ_FILE; |
| 88 | msg.flags = flags; |
| 89 | msg.data_size = *size; |
| 90 | msg.offset = offset; |
| 91 | |
| 92 | res = heci_send(&msg, sizeof(msg), BIOS_HOST_ADDR, HECI_MKHI_ADDR); |
| 93 | |
| 94 | if (!res) { |
| 95 | printk(BIOS_ERR, "failed to send HECI message\n"); |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | reply_size = sizeof(rmsg); |
| 100 | res = heci_receive(&rmsg, &reply_size); |
| 101 | |
| 102 | if (!res) { |
| 103 | printk(BIOS_ERR, "failed to receive HECI reply\n"); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | if (rmsg.data_size > *size) { |
| 108 | printk(BIOS_ERR, "reply is too large\n"); |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | memcpy(buff, rmsg.buffer, rmsg.data_size); |
| 113 | *size = rmsg.data_size; |
| 114 | |
| 115 | return 1; |
| 116 | } |
| 117 | |
| 118 | static void fpf_blown(void *unused) |
| 119 | { |
| 120 | int8_t fuse; |
| 121 | size_t sz = sizeof(fuse); |
| 122 | |
| 123 | if (read_cse_file(FUSE_LOCK_FILE, &fuse, &sz, 0, READ_FILE_FLAG_HW)) { |
| 124 | g_fuse_status = fuse; |
| 125 | return; |
| 126 | } |
| 127 | g_fuse_status = -1; |
| 128 | } |
| 129 | |
Aaron Durbin | 7d14af8 | 2017-02-07 11:33:56 -0600 | [diff] [blame] | 130 | static uint32_t dump_status(int index, int reg_addr) |
| 131 | { |
Andrey Petrov | fba7489 | 2017-03-02 08:50:57 -0800 | [diff] [blame] | 132 | uint32_t reg = pci_read_config32(HECI1_DEV, reg_addr); |
Aaron Durbin | 7d14af8 | 2017-02-07 11:33:56 -0600 | [diff] [blame] | 133 | |
| 134 | printk(BIOS_DEBUG, "CSE FWSTS%d: 0x%08x\n", index, reg); |
| 135 | |
| 136 | return reg; |
| 137 | } |
| 138 | |
| 139 | static void dump_cse_state(void *unused) |
| 140 | { |
| 141 | uint32_t fwsts1; |
| 142 | |
| 143 | fwsts1 = dump_status(1, PCI_ME_HFSTS1); |
| 144 | dump_status(2, PCI_ME_HFSTS2); |
| 145 | dump_status(3, PCI_ME_HFSTS3); |
| 146 | dump_status(4, PCI_ME_HFSTS4); |
| 147 | dump_status(5, PCI_ME_HFSTS5); |
| 148 | dump_status(6, PCI_ME_HFSTS6); |
| 149 | |
| 150 | /* Minimal decoding is done here in order to call out most important |
| 151 | pieces. Manufacturing mode needs to be locked down prior to shipping |
| 152 | the product so it's called out explicitly. */ |
| 153 | printk(BIOS_DEBUG, "ME: Manufacturing Mode : %s\n", |
| 154 | (fwsts1 & (1 << 0x4)) ? "YES" : "NO"); |
Aaron Durbin | 7d14af8 | 2017-02-07 11:33:56 -0600 | [diff] [blame] | 155 | |
Andrey Petrov | b1aded2 | 2017-03-03 08:12:36 -0800 | [diff] [blame] | 156 | printk(BIOS_DEBUG, "ME: FPF status : "); |
| 157 | switch (g_fuse_status) { |
| 158 | case 0: |
| 159 | printk(BIOS_DEBUG, "unfused"); |
| 160 | break; |
| 161 | case 1: |
| 162 | printk(BIOS_DEBUG, "fused"); |
| 163 | break; |
| 164 | default: |
| 165 | case -1: |
| 166 | printk(BIOS_DEBUG, "unknown"); |
| 167 | } |
| 168 | printk(BIOS_DEBUG, "\n"); |
| 169 | } |
| 170 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, fpf_blown, NULL); |
Aaron Durbin | 7d14af8 | 2017-02-07 11:33:56 -0600 | [diff] [blame] | 171 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, dump_cse_state, NULL); |
| 172 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, dump_cse_state, NULL); |