Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 2 | |
Subrata Banik | 05e06cd | 2017-11-09 15:04:09 +0530 | [diff] [blame] | 3 | #include <assert.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 4 | #include <commonlib/helpers.h> |
| 5 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 6 | #include <device/mmio.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 7 | #include <delay.h> |
| 8 | #include <device/pci.h> |
| 9 | #include <device/pci_ids.h> |
| 10 | #include <device/pci_ops.h> |
| 11 | #include <intelblocks/cse.h> |
Subrata Banik | 05e06cd | 2017-11-09 15:04:09 +0530 | [diff] [blame] | 12 | #include <soc/iomap.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 13 | #include <soc/pci_devs.h> |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 14 | #include <soc/me.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 15 | #include <string.h> |
| 16 | #include <timer.h> |
| 17 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 18 | #define MAX_HECI_MESSAGE_RETRY_COUNT 5 |
| 19 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 20 | /* Wait up to 15 sec for HECI to get ready */ |
| 21 | #define HECI_DELAY_READY (15 * 1000) |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 22 | /* Wait up to 100 usec between circular buffer polls */ |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 23 | #define HECI_DELAY 100 |
| 24 | /* Wait up to 5 sec for CSE to chew something we sent */ |
| 25 | #define HECI_SEND_TIMEOUT (5 * 1000) |
| 26 | /* Wait up to 5 sec for CSE to blurp a reply */ |
| 27 | #define HECI_READ_TIMEOUT (5 * 1000) |
| 28 | |
| 29 | #define SLOT_SIZE sizeof(uint32_t) |
| 30 | |
| 31 | #define MMIO_CSE_CB_WW 0x00 |
| 32 | #define MMIO_HOST_CSR 0x04 |
| 33 | #define MMIO_CSE_CB_RW 0x08 |
| 34 | #define MMIO_CSE_CSR 0x0c |
| 35 | |
| 36 | #define CSR_IE (1 << 0) |
| 37 | #define CSR_IS (1 << 1) |
| 38 | #define CSR_IG (1 << 2) |
| 39 | #define CSR_READY (1 << 3) |
| 40 | #define CSR_RESET (1 << 4) |
| 41 | #define CSR_RP_START 8 |
| 42 | #define CSR_RP (((1 << 8) - 1) << CSR_RP_START) |
| 43 | #define CSR_WP_START 16 |
| 44 | #define CSR_WP (((1 << 8) - 1) << CSR_WP_START) |
| 45 | #define CSR_CBD_START 24 |
| 46 | #define CSR_CBD (((1 << 8) - 1) << CSR_CBD_START) |
| 47 | |
| 48 | #define MEI_HDR_IS_COMPLETE (1 << 31) |
| 49 | #define MEI_HDR_LENGTH_START 16 |
| 50 | #define MEI_HDR_LENGTH_SIZE 9 |
| 51 | #define MEI_HDR_LENGTH (((1 << MEI_HDR_LENGTH_SIZE) - 1) \ |
| 52 | << MEI_HDR_LENGTH_START) |
| 53 | #define MEI_HDR_HOST_ADDR_START 8 |
| 54 | #define MEI_HDR_HOST_ADDR (((1 << 8) - 1) << MEI_HDR_HOST_ADDR_START) |
| 55 | #define MEI_HDR_CSE_ADDR_START 0 |
| 56 | #define MEI_HDR_CSE_ADDR (((1 << 8) - 1) << MEI_HDR_CSE_ADDR_START) |
| 57 | |
Sridhar Siricilla | 09ea371 | 2019-11-12 23:35:50 +0530 | [diff] [blame] | 58 | /* Wait up to 5 seconds for CSE to boot from RO(BP1) */ |
| 59 | #define CSE_DELAY_BOOT_TO_RO (5 * 1000) |
| 60 | |
Arthur Heymans | 3d6ccd0 | 2019-05-27 17:25:23 +0200 | [diff] [blame] | 61 | static struct cse_device { |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 62 | uintptr_t sec_bar; |
Patrick Georgi | c9b1359 | 2019-11-29 11:47:47 +0100 | [diff] [blame] | 63 | } cse; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Initialize the device with provided temporary BAR. If BAR is 0 use a |
| 67 | * default. This is intended for pre-mem usage only where BARs haven't been |
| 68 | * assigned yet and devices are not enabled. |
| 69 | */ |
| 70 | void heci_init(uintptr_t tempbar) |
| 71 | { |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 72 | #if defined(__SIMPLE_DEVICE__) |
| 73 | pci_devfn_t dev = PCH_DEV_CSE; |
| 74 | #else |
| 75 | struct device *dev = PCH_DEV_CSE; |
| 76 | #endif |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 77 | u16 pcireg; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 78 | |
| 79 | /* Assume it is already initialized, nothing else to do */ |
Patrick Georgi | c9b1359 | 2019-11-29 11:47:47 +0100 | [diff] [blame] | 80 | if (cse.sec_bar) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 81 | return; |
| 82 | |
| 83 | /* Use default pre-ram bar */ |
| 84 | if (!tempbar) |
| 85 | tempbar = HECI1_BASE_ADDRESS; |
| 86 | |
| 87 | /* Assign Resources to HECI1 */ |
| 88 | /* Clear BIT 1-2 of Command Register */ |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 89 | pcireg = pci_read_config16(dev, PCI_COMMAND); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 90 | pcireg &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 91 | pci_write_config16(dev, PCI_COMMAND, pcireg); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 92 | |
| 93 | /* Program Temporary BAR for HECI1 */ |
| 94 | pci_write_config32(dev, PCI_BASE_ADDRESS_0, tempbar); |
| 95 | pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0x0); |
| 96 | |
| 97 | /* Enable Bus Master and MMIO Space */ |
Elyes HAOUAS | 2ec1c13 | 2020-04-29 09:57:05 +0200 | [diff] [blame] | 98 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 99 | |
Patrick Georgi | c9b1359 | 2019-11-29 11:47:47 +0100 | [diff] [blame] | 100 | cse.sec_bar = tempbar; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Subrata Banik | 05e06cd | 2017-11-09 15:04:09 +0530 | [diff] [blame] | 103 | /* Get HECI BAR 0 from PCI configuration space */ |
| 104 | static uint32_t get_cse_bar(void) |
| 105 | { |
| 106 | uintptr_t bar; |
| 107 | |
| 108 | bar = pci_read_config32(PCH_DEV_CSE, PCI_BASE_ADDRESS_0); |
| 109 | assert(bar != 0); |
| 110 | /* |
| 111 | * Bits 31-12 are the base address as per EDS for SPI, |
| 112 | * Don't care about 0-11 bit |
| 113 | */ |
| 114 | return bar & ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
| 115 | } |
| 116 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 117 | static uint32_t read_bar(uint32_t offset) |
| 118 | { |
Patrick Georgi | 08c8cf9 | 2019-12-02 11:43:20 +0100 | [diff] [blame] | 119 | /* Load and cache BAR */ |
Patrick Georgi | c9b1359 | 2019-11-29 11:47:47 +0100 | [diff] [blame] | 120 | if (!cse.sec_bar) |
| 121 | cse.sec_bar = get_cse_bar(); |
| 122 | return read32((void *)(cse.sec_bar + offset)); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static void write_bar(uint32_t offset, uint32_t val) |
| 126 | { |
Patrick Georgi | 08c8cf9 | 2019-12-02 11:43:20 +0100 | [diff] [blame] | 127 | /* Load and cache BAR */ |
Patrick Georgi | c9b1359 | 2019-11-29 11:47:47 +0100 | [diff] [blame] | 128 | if (!cse.sec_bar) |
| 129 | cse.sec_bar = get_cse_bar(); |
| 130 | return write32((void *)(cse.sec_bar + offset), val); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static uint32_t read_cse_csr(void) |
| 134 | { |
| 135 | return read_bar(MMIO_CSE_CSR); |
| 136 | } |
| 137 | |
| 138 | static uint32_t read_host_csr(void) |
| 139 | { |
| 140 | return read_bar(MMIO_HOST_CSR); |
| 141 | } |
| 142 | |
| 143 | static void write_host_csr(uint32_t data) |
| 144 | { |
| 145 | write_bar(MMIO_HOST_CSR, data); |
| 146 | } |
| 147 | |
| 148 | static size_t filled_slots(uint32_t data) |
| 149 | { |
| 150 | uint8_t wp, rp; |
| 151 | rp = data >> CSR_RP_START; |
| 152 | wp = data >> CSR_WP_START; |
| 153 | return (uint8_t) (wp - rp); |
| 154 | } |
| 155 | |
| 156 | static size_t cse_filled_slots(void) |
| 157 | { |
| 158 | return filled_slots(read_cse_csr()); |
| 159 | } |
| 160 | |
| 161 | static size_t host_empty_slots(void) |
| 162 | { |
| 163 | uint32_t csr; |
| 164 | csr = read_host_csr(); |
| 165 | |
| 166 | return ((csr & CSR_CBD) >> CSR_CBD_START) - filled_slots(csr); |
| 167 | } |
| 168 | |
| 169 | static void clear_int(void) |
| 170 | { |
| 171 | uint32_t csr; |
| 172 | csr = read_host_csr(); |
| 173 | csr |= CSR_IS; |
| 174 | write_host_csr(csr); |
| 175 | } |
| 176 | |
| 177 | static uint32_t read_slot(void) |
| 178 | { |
| 179 | return read_bar(MMIO_CSE_CB_RW); |
| 180 | } |
| 181 | |
| 182 | static void write_slot(uint32_t val) |
| 183 | { |
| 184 | write_bar(MMIO_CSE_CB_WW, val); |
| 185 | } |
| 186 | |
| 187 | static int wait_write_slots(size_t cnt) |
| 188 | { |
| 189 | struct stopwatch sw; |
| 190 | |
| 191 | stopwatch_init_msecs_expire(&sw, HECI_SEND_TIMEOUT); |
| 192 | while (host_empty_slots() < cnt) { |
| 193 | udelay(HECI_DELAY); |
| 194 | if (stopwatch_expired(&sw)) { |
| 195 | printk(BIOS_ERR, "HECI: timeout, buffer not drained\n"); |
| 196 | return 0; |
| 197 | } |
| 198 | } |
| 199 | return 1; |
| 200 | } |
| 201 | |
| 202 | static int wait_read_slots(size_t cnt) |
| 203 | { |
| 204 | struct stopwatch sw; |
| 205 | |
| 206 | stopwatch_init_msecs_expire(&sw, HECI_READ_TIMEOUT); |
| 207 | while (cse_filled_slots() < cnt) { |
| 208 | udelay(HECI_DELAY); |
| 209 | if (stopwatch_expired(&sw)) { |
| 210 | printk(BIOS_ERR, "HECI: timed out reading answer!\n"); |
| 211 | return 0; |
| 212 | } |
| 213 | } |
| 214 | return 1; |
| 215 | } |
| 216 | |
| 217 | /* get number of full 4-byte slots */ |
| 218 | static size_t bytes_to_slots(size_t bytes) |
| 219 | { |
| 220 | return ALIGN_UP(bytes, SLOT_SIZE) / SLOT_SIZE; |
| 221 | } |
| 222 | |
| 223 | static int cse_ready(void) |
| 224 | { |
| 225 | uint32_t csr; |
| 226 | csr = read_cse_csr(); |
| 227 | return csr & CSR_READY; |
| 228 | } |
| 229 | |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 230 | static bool cse_check_hfs1_com(int mode) |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 231 | { |
| 232 | union me_hfsts1 hfs1; |
| 233 | hfs1.data = me_read_config32(PCI_ME_HFSTS1); |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 234 | return hfs1.fields.operation_mode == mode; |
| 235 | } |
| 236 | |
| 237 | bool cse_is_hfs1_cws_normal(void) |
| 238 | { |
| 239 | union me_hfsts1 hfs1; |
| 240 | hfs1.data = me_read_config32(PCI_ME_HFSTS1); |
| 241 | if (hfs1.fields.working_state == ME_HFS1_CWS_NORMAL) |
| 242 | return true; |
| 243 | return false; |
| 244 | } |
| 245 | |
| 246 | bool cse_is_hfs1_com_normal(void) |
| 247 | { |
| 248 | return cse_check_hfs1_com(ME_HFS1_COM_NORMAL); |
| 249 | } |
| 250 | |
| 251 | bool cse_is_hfs1_com_secover_mei_msg(void) |
| 252 | { |
| 253 | return cse_check_hfs1_com(ME_HFS1_COM_SECOVER_MEI_MSG); |
| 254 | } |
| 255 | |
| 256 | bool cse_is_hfs1_com_soft_temp_disable(void) |
| 257 | { |
| 258 | return cse_check_hfs1_com(ME_HFS1_COM_SOFT_TEMP_DISABLE); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 259 | } |
| 260 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 261 | bool cse_is_hfs3_fw_sku_lite(void) |
Sridhar Siricilla | 3465d27 | 2020-02-06 15:31:04 +0530 | [diff] [blame] | 262 | { |
| 263 | union me_hfsts3 hfs3; |
| 264 | hfs3.data = me_read_config32(PCI_ME_HFSTS3); |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 265 | return hfs3.fields.fw_sku == ME_HFS3_FW_SKU_LITE; |
Sridhar Siricilla | 3465d27 | 2020-02-06 15:31:04 +0530 | [diff] [blame] | 266 | } |
| 267 | |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 268 | /* Makes the host ready to communicate with CSE */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 269 | void cse_set_host_ready(void) |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 270 | { |
| 271 | uint32_t csr; |
| 272 | csr = read_host_csr(); |
| 273 | csr &= ~CSR_RESET; |
| 274 | csr |= (CSR_IG | CSR_READY); |
| 275 | write_host_csr(csr); |
| 276 | } |
| 277 | |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 278 | /* Polls for ME mode ME_HFS1_COM_SECOVER_MEI_MSG for 15 seconds */ |
| 279 | uint8_t cse_wait_sec_override_mode(void) |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 280 | { |
| 281 | struct stopwatch sw; |
| 282 | stopwatch_init_msecs_expire(&sw, HECI_DELAY_READY); |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 283 | while (!cse_is_hfs1_com_secover_mei_msg()) { |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 284 | udelay(HECI_DELAY); |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 285 | if (stopwatch_expired(&sw)) { |
| 286 | printk(BIOS_ERR, "HECI: Timed out waiting for SEC_OVERRIDE mode!\n"); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 287 | return 0; |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 288 | } |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 289 | } |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 290 | printk(BIOS_DEBUG, "HECI: CSE took %lu ms to enter security override mode\n", |
| 291 | stopwatch_duration_msecs(&sw)); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 292 | return 1; |
| 293 | } |
| 294 | |
Sridhar Siricilla | 09ea371 | 2019-11-12 23:35:50 +0530 | [diff] [blame] | 295 | /* |
| 296 | * Polls for CSE's current operation mode 'Soft Temporary Disable'. |
| 297 | * The CSE enters the current operation mode when it boots from RO(BP1). |
| 298 | */ |
| 299 | uint8_t cse_wait_com_soft_temp_disable(void) |
| 300 | { |
| 301 | struct stopwatch sw; |
| 302 | stopwatch_init_msecs_expire(&sw, CSE_DELAY_BOOT_TO_RO); |
| 303 | while (!cse_is_hfs1_com_soft_temp_disable()) { |
| 304 | udelay(HECI_DELAY); |
| 305 | if (stopwatch_expired(&sw)) { |
| 306 | printk(BIOS_ERR, "HECI: Timed out waiting for CSE to boot from RO!\n"); |
| 307 | return 0; |
| 308 | } |
| 309 | } |
| 310 | printk(BIOS_SPEW, "HECI: CSE took %lu ms to boot from RO\n", |
| 311 | stopwatch_duration_msecs(&sw)); |
| 312 | return 1; |
| 313 | } |
| 314 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 315 | static int wait_heci_ready(void) |
| 316 | { |
| 317 | struct stopwatch sw; |
| 318 | |
| 319 | stopwatch_init_msecs_expire(&sw, HECI_DELAY_READY); |
| 320 | while (!cse_ready()) { |
| 321 | udelay(HECI_DELAY); |
| 322 | if (stopwatch_expired(&sw)) |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | return 1; |
| 327 | } |
| 328 | |
| 329 | static void host_gen_interrupt(void) |
| 330 | { |
| 331 | uint32_t csr; |
| 332 | csr = read_host_csr(); |
| 333 | csr |= CSR_IG; |
| 334 | write_host_csr(csr); |
| 335 | } |
| 336 | |
| 337 | static size_t hdr_get_length(uint32_t hdr) |
| 338 | { |
| 339 | return (hdr & MEI_HDR_LENGTH) >> MEI_HDR_LENGTH_START; |
| 340 | } |
| 341 | |
| 342 | static int |
| 343 | send_one_message(uint32_t hdr, const void *buff) |
| 344 | { |
| 345 | size_t pend_len, pend_slots, remainder, i; |
| 346 | uint32_t tmp; |
| 347 | const uint32_t *p = buff; |
| 348 | |
| 349 | /* Get space for the header */ |
| 350 | if (!wait_write_slots(1)) |
| 351 | return 0; |
| 352 | |
| 353 | /* First, write header */ |
| 354 | write_slot(hdr); |
| 355 | |
| 356 | pend_len = hdr_get_length(hdr); |
| 357 | pend_slots = bytes_to_slots(pend_len); |
| 358 | |
| 359 | if (!wait_write_slots(pend_slots)) |
| 360 | return 0; |
| 361 | |
| 362 | /* Write the body in whole slots */ |
| 363 | i = 0; |
| 364 | while (i < ALIGN_DOWN(pend_len, SLOT_SIZE)) { |
| 365 | write_slot(*p++); |
| 366 | i += SLOT_SIZE; |
| 367 | } |
| 368 | |
| 369 | remainder = pend_len % SLOT_SIZE; |
| 370 | /* Pad to 4 bytes not touching caller's buffer */ |
| 371 | if (remainder) { |
| 372 | memcpy(&tmp, p, remainder); |
| 373 | write_slot(tmp); |
| 374 | } |
| 375 | |
| 376 | host_gen_interrupt(); |
| 377 | |
| 378 | /* Make sure nothing bad happened during transmission */ |
| 379 | if (!cse_ready()) |
| 380 | return 0; |
| 381 | |
| 382 | return pend_len; |
| 383 | } |
| 384 | |
| 385 | int |
| 386 | heci_send(const void *msg, size_t len, uint8_t host_addr, uint8_t client_addr) |
| 387 | { |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 388 | uint8_t retry; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 389 | uint32_t csr, hdr; |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 390 | size_t sent, remaining, cb_size, max_length; |
| 391 | const uint8_t *p; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 392 | |
| 393 | if (!msg || !len) |
| 394 | return 0; |
| 395 | |
| 396 | clear_int(); |
| 397 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 398 | for (retry = 0; retry < MAX_HECI_MESSAGE_RETRY_COUNT; retry++) { |
| 399 | p = msg; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 400 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 401 | if (!wait_heci_ready()) { |
| 402 | printk(BIOS_ERR, "HECI: not ready\n"); |
| 403 | continue; |
| 404 | } |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 405 | |
Subrata Banik | 4a722f5 | 2017-11-13 14:56:42 +0530 | [diff] [blame] | 406 | csr = read_host_csr(); |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 407 | cb_size = ((csr & CSR_CBD) >> CSR_CBD_START) * SLOT_SIZE; |
| 408 | /* |
| 409 | * Reserve one slot for the header. Limit max message |
| 410 | * length by 9 bits that are available in the header. |
| 411 | */ |
| 412 | max_length = MIN(cb_size, (1 << MEI_HDR_LENGTH_SIZE) - 1) |
| 413 | - SLOT_SIZE; |
| 414 | remaining = len; |
| 415 | |
| 416 | /* |
| 417 | * Fragment the message into smaller messages not exceeding |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 418 | * useful circular buffer length. Mark last message complete. |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 419 | */ |
| 420 | do { |
| 421 | hdr = MIN(max_length, remaining) |
| 422 | << MEI_HDR_LENGTH_START; |
| 423 | hdr |= client_addr << MEI_HDR_CSE_ADDR_START; |
| 424 | hdr |= host_addr << MEI_HDR_HOST_ADDR_START; |
| 425 | hdr |= (MIN(max_length, remaining) == remaining) ? |
Lee Leahy | 68ab0b5 | 2017-03-10 13:42:34 -0800 | [diff] [blame] | 426 | MEI_HDR_IS_COMPLETE : 0; |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 427 | sent = send_one_message(hdr, p); |
| 428 | p += sent; |
| 429 | remaining -= sent; |
| 430 | } while (remaining > 0 && sent != 0); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 431 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 432 | if (!remaining) |
| 433 | return 1; |
| 434 | } |
| 435 | return 0; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static size_t |
| 439 | recv_one_message(uint32_t *hdr, void *buff, size_t maxlen) |
| 440 | { |
| 441 | uint32_t reg, *p = buff; |
| 442 | size_t recv_slots, recv_len, remainder, i; |
| 443 | |
| 444 | /* first get the header */ |
| 445 | if (!wait_read_slots(1)) |
| 446 | return 0; |
| 447 | |
| 448 | *hdr = read_slot(); |
| 449 | recv_len = hdr_get_length(*hdr); |
| 450 | |
| 451 | if (!recv_len) |
| 452 | printk(BIOS_WARNING, "HECI: message is zero-sized\n"); |
| 453 | |
| 454 | recv_slots = bytes_to_slots(recv_len); |
| 455 | |
| 456 | i = 0; |
| 457 | if (recv_len > maxlen) { |
| 458 | printk(BIOS_ERR, "HECI: response is too big\n"); |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | /* wait for the rest of messages to arrive */ |
| 463 | wait_read_slots(recv_slots); |
| 464 | |
| 465 | /* fetch whole slots first */ |
| 466 | while (i < ALIGN_DOWN(recv_len, SLOT_SIZE)) { |
| 467 | *p++ = read_slot(); |
| 468 | i += SLOT_SIZE; |
| 469 | } |
| 470 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 471 | /* |
| 472 | * If ME is not ready, something went wrong and |
| 473 | * we received junk |
| 474 | */ |
| 475 | if (!cse_ready()) |
| 476 | return 0; |
| 477 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 478 | remainder = recv_len % SLOT_SIZE; |
| 479 | |
| 480 | if (remainder) { |
| 481 | reg = read_slot(); |
| 482 | memcpy(p, ®, remainder); |
| 483 | } |
| 484 | |
| 485 | return recv_len; |
| 486 | } |
| 487 | |
| 488 | int heci_receive(void *buff, size_t *maxlen) |
| 489 | { |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 490 | uint8_t retry; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 491 | size_t left, received; |
| 492 | uint32_t hdr = 0; |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 493 | uint8_t *p; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 494 | |
| 495 | if (!buff || !maxlen || !*maxlen) |
| 496 | return 0; |
| 497 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 498 | clear_int(); |
| 499 | |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 500 | for (retry = 0; retry < MAX_HECI_MESSAGE_RETRY_COUNT; retry++) { |
| 501 | p = buff; |
| 502 | left = *maxlen; |
| 503 | |
| 504 | if (!wait_heci_ready()) { |
| 505 | printk(BIOS_ERR, "HECI: not ready\n"); |
| 506 | continue; |
| 507 | } |
| 508 | |
| 509 | /* |
| 510 | * Receive multiple packets until we meet one marked |
| 511 | * complete or we run out of space in caller-provided buffer. |
| 512 | */ |
| 513 | do { |
| 514 | received = recv_one_message(&hdr, p, left); |
Lijian Zhao | c50296d | 2017-12-15 19:10:18 -0800 | [diff] [blame] | 515 | if (!received) { |
Elyes HAOUAS | 3d45000 | 2018-08-09 18:55:58 +0200 | [diff] [blame] | 516 | printk(BIOS_ERR, "HECI: Failed to receive!\n"); |
Lijian Zhao | c50296d | 2017-12-15 19:10:18 -0800 | [diff] [blame] | 517 | return 0; |
| 518 | } |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 519 | left -= received; |
| 520 | p += received; |
| 521 | /* If we read out everything ping to send more */ |
| 522 | if (!(hdr & MEI_HDR_IS_COMPLETE) && !cse_filled_slots()) |
| 523 | host_gen_interrupt(); |
| 524 | } while (received && !(hdr & MEI_HDR_IS_COMPLETE) && left > 0); |
| 525 | |
| 526 | if ((hdr & MEI_HDR_IS_COMPLETE) && received) { |
| 527 | *maxlen = p - (uint8_t *) buff; |
| 528 | return 1; |
| 529 | } |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 530 | } |
Subrata Banik | 5c08c73 | 2017-11-13 14:54:37 +0530 | [diff] [blame] | 531 | return 0; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 532 | } |
| 533 | |
Sridhar Siricilla | a5208f5 | 2019-08-30 17:10:24 +0530 | [diff] [blame] | 534 | int heci_send_receive(const void *snd_msg, size_t snd_sz, void *rcv_msg, size_t *rcv_sz) |
| 535 | { |
| 536 | if (!heci_send(snd_msg, snd_sz, BIOS_HOST_ADDR, HECI_MKHI_ADDR)) { |
| 537 | printk(BIOS_ERR, "HECI: send Failed\n"); |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | if (rcv_msg != NULL) { |
| 542 | if (!heci_receive(rcv_msg, rcv_sz)) { |
| 543 | printk(BIOS_ERR, "HECI: receive Failed\n"); |
| 544 | return 0; |
| 545 | } |
| 546 | } |
| 547 | return 1; |
| 548 | } |
| 549 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 550 | /* |
| 551 | * Attempt to reset the device. This is useful when host and ME are out |
| 552 | * of sync during transmission or ME didn't understand the message. |
| 553 | */ |
| 554 | int heci_reset(void) |
| 555 | { |
| 556 | uint32_t csr; |
| 557 | |
Duncan Laurie | 15ca903 | 2020-11-05 10:09:07 -0800 | [diff] [blame] | 558 | /* Clear post code to prevent eventlog entry from unknown code. */ |
| 559 | post_code(0); |
| 560 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 561 | /* Send reset request */ |
| 562 | csr = read_host_csr(); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 563 | csr |= (CSR_RESET | CSR_IG); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 564 | write_host_csr(csr); |
| 565 | |
| 566 | if (wait_heci_ready()) { |
| 567 | /* Device is back on its imaginary feet, clear reset */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 568 | cse_set_host_ready(); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 569 | return 1; |
| 570 | } |
| 571 | |
| 572 | printk(BIOS_CRIT, "HECI: reset failed\n"); |
| 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 577 | bool is_cse_enabled(void) |
| 578 | { |
| 579 | const struct device *cse_dev = pcidev_path_on_root(PCH_DEVFN_CSE); |
| 580 | |
| 581 | if (!cse_dev || !cse_dev->enabled) { |
| 582 | printk(BIOS_WARNING, "HECI: No CSE device\n"); |
| 583 | return false; |
| 584 | } |
| 585 | |
| 586 | if (pci_read_config16(PCH_DEV_CSE, PCI_VENDOR_ID) == 0xFFFF) { |
| 587 | printk(BIOS_WARNING, "HECI: CSE device is hidden\n"); |
| 588 | return false; |
| 589 | } |
| 590 | |
| 591 | return true; |
| 592 | } |
| 593 | |
| 594 | uint32_t me_read_config32(int offset) |
| 595 | { |
| 596 | return pci_read_config32(PCH_DEV_CSE, offset); |
| 597 | } |
| 598 | |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 599 | static bool cse_is_global_reset_allowed(void) |
| 600 | { |
| 601 | /* |
| 602 | * Allow sending GLOBAL_RESET command only if: |
| 603 | * - CSE's current working state is Normal and current operation mode is Normal. |
| 604 | * - (or) CSE's current working state is normal and current operation mode can |
| 605 | * be Soft Temp Disable or Security Override Mode if CSE's Firmware SKU is |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 606 | * Lite. |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 607 | */ |
| 608 | if (!cse_is_hfs1_cws_normal()) |
| 609 | return false; |
| 610 | |
| 611 | if (cse_is_hfs1_com_normal()) |
| 612 | return true; |
| 613 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 614 | if (cse_is_hfs3_fw_sku_lite()) { |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 615 | if (cse_is_hfs1_com_soft_temp_disable() || cse_is_hfs1_com_secover_mei_msg()) |
| 616 | return true; |
| 617 | } |
| 618 | return false; |
| 619 | } |
| 620 | |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 621 | /* |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 622 | * Sends GLOBAL_RESET_REQ cmd to CSE with reset type GLOBAL_RESET. |
| 623 | * Returns 0 on failure and 1 on success. |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 624 | */ |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 625 | static int cse_request_reset(enum rst_req_type rst_type) |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 626 | { |
| 627 | int status; |
| 628 | struct mkhi_hdr reply; |
| 629 | struct reset_message { |
| 630 | struct mkhi_hdr hdr; |
| 631 | uint8_t req_origin; |
| 632 | uint8_t reset_type; |
| 633 | } __packed; |
| 634 | struct reset_message msg = { |
| 635 | .hdr = { |
| 636 | .group_id = MKHI_GROUP_ID_CBM, |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 637 | .command = MKHI_CBM_GLOBAL_RESET_REQ, |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 638 | }, |
| 639 | .req_origin = GR_ORIGIN_BIOS_POST, |
| 640 | .reset_type = rst_type |
| 641 | }; |
| 642 | size_t reply_size; |
| 643 | |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 644 | printk(BIOS_DEBUG, "HECI: Global Reset(Type:%d) Command\n", rst_type); |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 645 | |
Sridhar Siricilla | c2a2d2b | 2020-02-27 17:16:13 +0530 | [diff] [blame] | 646 | if (!(rst_type == GLOBAL_RESET || rst_type == CSE_RESET_ONLY)) { |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 647 | printk(BIOS_ERR, "HECI: Unsupported reset type is requested\n"); |
| 648 | return 0; |
| 649 | } |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 650 | |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 651 | if (!cse_is_global_reset_allowed() || !is_cse_enabled()) { |
Sridhar Siricilla | 59c7cb7d | 2020-02-07 11:59:30 +0530 | [diff] [blame] | 652 | printk(BIOS_ERR, "HECI: CSE does not meet required prerequisites\n"); |
| 653 | return 0; |
| 654 | } |
| 655 | |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 656 | heci_reset(); |
| 657 | |
| 658 | reply_size = sizeof(reply); |
| 659 | memset(&reply, 0, reply_size); |
| 660 | |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 661 | if (rst_type == CSE_RESET_ONLY) |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 662 | status = heci_send(&msg, sizeof(msg), BIOS_HOST_ADDR, HECI_MKHI_ADDR); |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 663 | else |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 664 | status = heci_send_receive(&msg, sizeof(msg), &reply, &reply_size); |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 665 | |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 666 | printk(BIOS_DEBUG, "HECI: Global Reset %s!\n", status ? "success" : "failure"); |
| 667 | return status; |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 668 | } |
| 669 | |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 670 | int cse_request_global_reset(void) |
| 671 | { |
| 672 | return cse_request_reset(GLOBAL_RESET); |
| 673 | } |
| 674 | |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 675 | static bool cse_is_hmrfpo_enable_allowed(void) |
| 676 | { |
| 677 | /* |
| 678 | * Allow sending HMRFPO ENABLE command only if: |
| 679 | * - CSE's current working state is Normal and current operation mode is Normal |
| 680 | * - (or) cse's current working state is normal and current operation mode is |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 681 | * Soft Temp Disable if CSE's Firmware SKU is Lite |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 682 | */ |
| 683 | if (!cse_is_hfs1_cws_normal()) |
| 684 | return false; |
| 685 | |
| 686 | if (cse_is_hfs1_com_normal()) |
| 687 | return true; |
| 688 | |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 689 | if (cse_is_hfs3_fw_sku_lite() && cse_is_hfs1_com_soft_temp_disable()) |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 690 | return true; |
| 691 | |
| 692 | return false; |
| 693 | } |
| 694 | |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 695 | /* Sends HMRFPO Enable command to CSE */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 696 | int cse_hmrfpo_enable(void) |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 697 | { |
| 698 | struct hmrfpo_enable_msg { |
| 699 | struct mkhi_hdr hdr; |
| 700 | uint32_t nonce[2]; |
| 701 | } __packed; |
| 702 | |
| 703 | /* HMRFPO Enable message */ |
| 704 | struct hmrfpo_enable_msg msg = { |
| 705 | .hdr = { |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 706 | .group_id = MKHI_GROUP_ID_HMRFPO, |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 707 | .command = MKHI_HMRFPO_ENABLE, |
| 708 | }, |
| 709 | .nonce = {0}, |
| 710 | }; |
| 711 | |
| 712 | /* HMRFPO Enable response */ |
| 713 | struct hmrfpo_enable_resp { |
| 714 | struct mkhi_hdr hdr; |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 715 | /* Base addr for factory data area, not relevant for client SKUs */ |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 716 | uint32_t fct_base; |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 717 | /* Length of factory data area, not relevant for client SKUs */ |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 718 | uint32_t fct_limit; |
| 719 | uint8_t status; |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 720 | uint8_t reserved[3]; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 721 | } __packed; |
| 722 | |
| 723 | struct hmrfpo_enable_resp resp; |
| 724 | size_t resp_size = sizeof(struct hmrfpo_enable_resp); |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 725 | |
| 726 | printk(BIOS_DEBUG, "HECI: Send HMRFPO Enable Command\n"); |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 727 | |
| 728 | if (!cse_is_hmrfpo_enable_allowed()) { |
| 729 | printk(BIOS_ERR, "HECI: CSE does not meet required prerequisites\n"); |
| 730 | return 0; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | if (!heci_send_receive(&msg, sizeof(struct hmrfpo_enable_msg), |
| 734 | &resp, &resp_size)) |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 735 | return 0; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 736 | |
| 737 | if (resp.hdr.result) { |
| 738 | printk(BIOS_ERR, "HECI: Resp Failed:%d\n", resp.hdr.result); |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 739 | return 0; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 740 | } |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 741 | |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 742 | if (resp.status) { |
| 743 | printk(BIOS_ERR, "HECI: HMRFPO_Enable Failed (resp status: %d)\n", resp.status); |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | return 1; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* |
| 751 | * Sends HMRFPO Get Status command to CSE to get the HMRFPO status. |
Sridhar Siricilla | 63be918 | 2020-01-19 12:38:56 +0530 | [diff] [blame] | 752 | * The status can be DISABLED/LOCKED/ENABLED |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 753 | */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 754 | int cse_hmrfpo_get_status(void) |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 755 | { |
| 756 | struct hmrfpo_get_status_msg { |
| 757 | struct mkhi_hdr hdr; |
| 758 | } __packed; |
| 759 | |
| 760 | struct hmrfpo_get_status_resp { |
| 761 | struct mkhi_hdr hdr; |
| 762 | uint8_t status; |
Sridhar Siricilla | 63be918 | 2020-01-19 12:38:56 +0530 | [diff] [blame] | 763 | uint8_t reserved[3]; |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 764 | } __packed; |
| 765 | |
| 766 | struct hmrfpo_get_status_msg msg = { |
| 767 | .hdr = { |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 768 | .group_id = MKHI_GROUP_ID_HMRFPO, |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 769 | .command = MKHI_HMRFPO_GET_STATUS, |
| 770 | }, |
| 771 | }; |
| 772 | struct hmrfpo_get_status_resp resp; |
| 773 | size_t resp_size = sizeof(struct hmrfpo_get_status_resp); |
| 774 | |
| 775 | printk(BIOS_INFO, "HECI: Sending Get HMRFPO Status Command\n"); |
| 776 | |
Sridhar Siricilla | 206905c | 2020-02-06 18:48:22 +0530 | [diff] [blame] | 777 | if (!cse_is_hfs1_cws_normal()) { |
| 778 | printk(BIOS_ERR, "HECI: CSE's current working state is not Normal\n"); |
| 779 | return -1; |
| 780 | } |
| 781 | |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 782 | if (!heci_send_receive(&msg, sizeof(struct hmrfpo_get_status_msg), |
| 783 | &resp, &resp_size)) { |
| 784 | printk(BIOS_ERR, "HECI: HMRFPO send/receive fail\n"); |
| 785 | return -1; |
| 786 | } |
| 787 | |
| 788 | if (resp.hdr.result) { |
| 789 | printk(BIOS_ERR, "HECI: HMRFPO Resp Failed:%d\n", |
| 790 | resp.hdr.result); |
| 791 | return -1; |
| 792 | } |
| 793 | |
| 794 | return resp.status; |
| 795 | } |
| 796 | |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 797 | void print_me_fw_version(void *unused) |
| 798 | { |
| 799 | struct version { |
| 800 | uint16_t minor; |
| 801 | uint16_t major; |
| 802 | uint16_t build; |
| 803 | uint16_t hotfix; |
| 804 | } __packed; |
| 805 | |
| 806 | struct fw_ver_resp { |
| 807 | struct mkhi_hdr hdr; |
| 808 | struct version code; |
| 809 | struct version rec; |
| 810 | struct version fitc; |
| 811 | } __packed; |
| 812 | |
| 813 | const struct mkhi_hdr fw_ver_msg = { |
| 814 | .group_id = MKHI_GROUP_ID_GEN, |
| 815 | .command = MKHI_GEN_GET_FW_VERSION, |
| 816 | }; |
| 817 | |
| 818 | struct fw_ver_resp resp; |
| 819 | size_t resp_size = sizeof(resp); |
| 820 | |
| 821 | /* Ignore if UART debugging is disabled */ |
| 822 | if (!CONFIG(CONSOLE_SERIAL)) |
| 823 | return; |
| 824 | |
Wim Vervoorn | 8602fb7 | 2020-03-30 12:17:54 +0200 | [diff] [blame] | 825 | /* Ignore if CSE is disabled */ |
| 826 | if (!is_cse_enabled()) |
| 827 | return; |
| 828 | |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 829 | /* |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 830 | * Ignore if ME Firmware SKU type is Lite since |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 831 | * print_boot_partition_info() logs RO(BP1) and RW(BP2) versions. |
| 832 | */ |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 833 | if (cse_is_hfs3_fw_sku_lite()) |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 834 | return; |
| 835 | |
| 836 | /* |
| 837 | * Prerequisites: |
| 838 | * 1) HFSTS1 Current Working State is Normal |
| 839 | * 2) HFSTS1 Current Operation Mode is Normal |
| 840 | * 3) It's after DRAM INIT DONE message (taken care of by calling it |
| 841 | * during ramstage |
| 842 | */ |
| 843 | if (!cse_is_hfs1_cws_normal() || !cse_is_hfs1_com_normal()) |
| 844 | goto fail; |
| 845 | |
| 846 | heci_reset(); |
| 847 | |
| 848 | if (!heci_send_receive(&fw_ver_msg, sizeof(fw_ver_msg), &resp, &resp_size)) |
| 849 | goto fail; |
| 850 | |
| 851 | if (resp.hdr.result) |
| 852 | goto fail; |
| 853 | |
| 854 | printk(BIOS_DEBUG, "ME: Version: %d.%d.%d.%d\n", resp.code.major, |
| 855 | resp.code.minor, resp.code.hotfix, resp.code.build); |
| 856 | return; |
| 857 | |
| 858 | fail: |
| 859 | printk(BIOS_DEBUG, "ME: Version: Unavailable\n"); |
| 860 | } |
| 861 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 862 | #if ENV_RAMSTAGE |
| 863 | |
| 864 | static void update_sec_bar(struct device *dev) |
| 865 | { |
Patrick Georgi | c9b1359 | 2019-11-29 11:47:47 +0100 | [diff] [blame] | 866 | cse.sec_bar = find_resource(dev, PCI_BASE_ADDRESS_0)->base; |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static void cse_set_resources(struct device *dev) |
| 870 | { |
Subrata Banik | 2ee54db | 2017-03-05 12:37:00 +0530 | [diff] [blame] | 871 | if (dev->path.pci.devfn == PCH_DEVFN_CSE) |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 872 | update_sec_bar(dev); |
| 873 | |
| 874 | pci_dev_set_resources(dev); |
| 875 | } |
| 876 | |
| 877 | static struct device_operations cse_ops = { |
| 878 | .set_resources = cse_set_resources, |
| 879 | .read_resources = pci_dev_read_resources, |
| 880 | .enable_resources = pci_dev_enable_resources, |
| 881 | .init = pci_dev_init, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 882 | .ops_pci = &pci_dev_ops_pci, |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 883 | }; |
| 884 | |
Hannah Williams | 6314215 | 2017-06-12 14:03:18 -0700 | [diff] [blame] | 885 | static const unsigned short pci_device_ids[] = { |
| 886 | PCI_DEVICE_ID_INTEL_APL_CSE0, |
| 887 | PCI_DEVICE_ID_INTEL_GLK_CSE0, |
Andrey Petrov | 0405de9 | 2017-06-05 13:25:29 -0700 | [diff] [blame] | 888 | PCI_DEVICE_ID_INTEL_CNL_CSE0, |
Subrata Banik | d0586d2 | 2017-11-27 13:28:41 +0530 | [diff] [blame] | 889 | PCI_DEVICE_ID_INTEL_SKL_CSE0, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 890 | PCI_DEVICE_ID_INTEL_LWB_CSE0, |
| 891 | PCI_DEVICE_ID_INTEL_LWB_CSE0_SUPER, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 892 | PCI_DEVICE_ID_INTEL_CNP_H_CSE0, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 893 | PCI_DEVICE_ID_INTEL_ICL_CSE0, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 894 | PCI_DEVICE_ID_INTEL_CMP_CSE0, |
Gaggery Tsai | 12a651c | 2019-12-05 11:23:20 -0800 | [diff] [blame] | 895 | PCI_DEVICE_ID_INTEL_CMP_H_CSE0, |
Ravi Sarawadi | 6b5bf40 | 2019-10-21 22:25:04 -0700 | [diff] [blame] | 896 | PCI_DEVICE_ID_INTEL_TGL_CSE0, |
Tan, Lean Sheng | 2613609 | 2020-01-20 19:13:56 -0800 | [diff] [blame] | 897 | PCI_DEVICE_ID_INTEL_MCC_CSE0, |
| 898 | PCI_DEVICE_ID_INTEL_MCC_CSE1, |
| 899 | PCI_DEVICE_ID_INTEL_MCC_CSE2, |
| 900 | PCI_DEVICE_ID_INTEL_MCC_CSE3, |
Meera Ravindranath | 3f4af0d | 2020-02-12 16:01:22 +0530 | [diff] [blame] | 901 | PCI_DEVICE_ID_INTEL_JSP_CSE0, |
| 902 | PCI_DEVICE_ID_INTEL_JSP_CSE1, |
| 903 | PCI_DEVICE_ID_INTEL_JSP_CSE2, |
| 904 | PCI_DEVICE_ID_INTEL_JSP_CSE3, |
Subrata Banik | f672f7f | 2020-08-03 14:29:25 +0530 | [diff] [blame] | 905 | PCI_DEVICE_ID_INTEL_ADP_P_CSE0, |
| 906 | PCI_DEVICE_ID_INTEL_ADP_P_CSE1, |
| 907 | PCI_DEVICE_ID_INTEL_ADP_P_CSE2, |
| 908 | PCI_DEVICE_ID_INTEL_ADP_P_CSE3, |
| 909 | PCI_DEVICE_ID_INTEL_ADP_S_CSE0, |
| 910 | PCI_DEVICE_ID_INTEL_ADP_S_CSE1, |
| 911 | PCI_DEVICE_ID_INTEL_ADP_S_CSE2, |
| 912 | PCI_DEVICE_ID_INTEL_ADP_S_CSE3, |
Varshit Pandya | f4d98fdd2 | 2021-01-17 18:39:29 +0530 | [diff] [blame] | 913 | PCI_DEVICE_ID_INTEL_ADP_M_CSE0, |
| 914 | PCI_DEVICE_ID_INTEL_ADP_M_CSE1, |
| 915 | PCI_DEVICE_ID_INTEL_ADP_M_CSE2, |
| 916 | PCI_DEVICE_ID_INTEL_ADP_M_CSE3, |
Hannah Williams | 6314215 | 2017-06-12 14:03:18 -0700 | [diff] [blame] | 917 | 0, |
| 918 | }; |
| 919 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 920 | static const struct pci_driver cse_driver __pci_driver = { |
| 921 | .ops = &cse_ops, |
| 922 | .vendor = PCI_VENDOR_ID_INTEL, |
| 923 | /* SoC/chipset needs to provide PCI device ID */ |
Andrey Petrov | 0405de9 | 2017-06-05 13:25:29 -0700 | [diff] [blame] | 924 | .devices = pci_device_ids |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 925 | }; |
| 926 | |
| 927 | #endif |