Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 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. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * This is a ramstage driver for the Intel Management Engine found in the |
| 18 | * southbridge. It handles the required boot-time messages over the |
| 19 | * MMIO-based Management Engine Interface to tell the ME that the BIOS is |
| 20 | * finished with POST. Additional messages are defined for debug but are |
| 21 | * not used unless the console loglevel is high enough. |
| 22 | */ |
| 23 | |
| 24 | #include <arch/acpi.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 25 | #include <arch/io.h> |
| 26 | #include <console/console.h> |
| 27 | #include <device/device.h> |
| 28 | #include <device/pci.h> |
| 29 | #include <device/pci_ids.h> |
| 30 | #include <device/pci_def.h> |
| 31 | #include <string.h> |
| 32 | #include <delay.h> |
| 33 | #include <elog.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 34 | #include <soc/me.h> |
| 35 | #include <soc/lpc.h> |
| 36 | #include <soc/pch.h> |
| 37 | #include <soc/pci_devs.h> |
| 38 | #include <soc/ramstage.h> |
| 39 | #include <soc/rcba.h> |
| 40 | #include <soc/intel/broadwell/chip.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 41 | |
| 42 | #if CONFIG_CHROMEOS |
| 43 | #include <vendorcode/google/chromeos/chromeos.h> |
| 44 | #include <vendorcode/google/chromeos/gnvs.h> |
| 45 | #endif |
| 46 | |
| 47 | /* Path that the BIOS should take based on ME state */ |
| 48 | static const char *me_bios_path_values[] = { |
| 49 | [ME_NORMAL_BIOS_PATH] = "Normal", |
| 50 | [ME_S3WAKE_BIOS_PATH] = "S3 Wake", |
| 51 | [ME_ERROR_BIOS_PATH] = "Error", |
| 52 | [ME_RECOVERY_BIOS_PATH] = "Recovery", |
| 53 | [ME_DISABLE_BIOS_PATH] = "Disable", |
| 54 | [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update", |
| 55 | }; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 56 | |
| 57 | /* MMIO base address for MEI interface */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 58 | static u8 *mei_base_address; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 59 | |
| 60 | #if CONFIG_DEBUG_INTEL_ME |
| 61 | static void mei_dump(void *ptr, int dword, int offset, const char *type) |
| 62 | { |
| 63 | struct mei_csr *csr; |
| 64 | |
| 65 | printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset); |
| 66 | |
| 67 | switch (offset) { |
| 68 | case MEI_H_CSR: |
| 69 | case MEI_ME_CSR_HA: |
| 70 | csr = ptr; |
| 71 | if (!csr) { |
| 72 | printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword); |
| 73 | break; |
| 74 | } |
| 75 | printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u " |
| 76 | "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth, |
| 77 | csr->buffer_read_ptr, csr->buffer_write_ptr, |
| 78 | csr->ready, csr->reset, csr->interrupt_generate, |
| 79 | csr->interrupt_status, csr->interrupt_enable); |
| 80 | break; |
| 81 | case MEI_ME_CB_RW: |
| 82 | case MEI_H_CB_WW: |
| 83 | printk(BIOS_SPEW, "CB: 0x%08x\n", dword); |
| 84 | break; |
| 85 | default: |
| 86 | printk(BIOS_SPEW, "0x%08x\n", offset); |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | #else |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 91 | # define mei_dump(ptr, dword, offset, type) do {} while (0) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 92 | #endif |
| 93 | |
| 94 | /* |
| 95 | * ME/MEI access helpers using memcpy to avoid aliasing. |
| 96 | */ |
| 97 | |
| 98 | static inline void mei_read_dword_ptr(void *ptr, int offset) |
| 99 | { |
| 100 | u32 dword = read32(mei_base_address + offset); |
| 101 | memcpy(ptr, &dword, sizeof(dword)); |
| 102 | mei_dump(ptr, dword, offset, "READ"); |
| 103 | } |
| 104 | |
| 105 | static inline void mei_write_dword_ptr(void *ptr, int offset) |
| 106 | { |
| 107 | u32 dword = 0; |
| 108 | memcpy(&dword, ptr, sizeof(dword)); |
| 109 | write32(mei_base_address + offset, dword); |
| 110 | mei_dump(ptr, dword, offset, "WRITE"); |
| 111 | } |
| 112 | |
| 113 | static inline void pci_read_dword_ptr(device_t dev, void *ptr, int offset) |
| 114 | { |
| 115 | u32 dword = pci_read_config32(dev, offset); |
| 116 | memcpy(ptr, &dword, sizeof(dword)); |
| 117 | mei_dump(ptr, dword, offset, "PCI READ"); |
| 118 | } |
| 119 | |
| 120 | static inline void read_host_csr(struct mei_csr *csr) |
| 121 | { |
| 122 | mei_read_dword_ptr(csr, MEI_H_CSR); |
| 123 | } |
| 124 | |
| 125 | static inline void write_host_csr(struct mei_csr *csr) |
| 126 | { |
| 127 | mei_write_dword_ptr(csr, MEI_H_CSR); |
| 128 | } |
| 129 | |
| 130 | static inline void read_me_csr(struct mei_csr *csr) |
| 131 | { |
| 132 | mei_read_dword_ptr(csr, MEI_ME_CSR_HA); |
| 133 | } |
| 134 | |
| 135 | static inline void write_cb(u32 dword) |
| 136 | { |
| 137 | write32(mei_base_address + MEI_H_CB_WW, dword); |
| 138 | mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE"); |
| 139 | } |
| 140 | |
| 141 | static inline u32 read_cb(void) |
| 142 | { |
| 143 | u32 dword = read32(mei_base_address + MEI_ME_CB_RW); |
| 144 | mei_dump(NULL, dword, MEI_ME_CB_RW, "READ"); |
| 145 | return dword; |
| 146 | } |
| 147 | |
| 148 | /* Wait for ME ready bit to be asserted */ |
| 149 | static int mei_wait_for_me_ready(void) |
| 150 | { |
| 151 | struct mei_csr me; |
Lee Leahy | 23602df | 2017-03-16 19:00:37 -0700 | [diff] [blame^] | 152 | unsigned int try = ME_RETRY; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 153 | |
| 154 | while (try--) { |
| 155 | read_me_csr(&me); |
| 156 | if (me.ready) |
| 157 | return 0; |
| 158 | udelay(ME_DELAY); |
| 159 | } |
| 160 | |
| 161 | printk(BIOS_ERR, "ME: failed to become ready\n"); |
| 162 | return -1; |
| 163 | } |
| 164 | |
| 165 | static void mei_reset(void) |
| 166 | { |
| 167 | struct mei_csr host; |
| 168 | |
| 169 | if (mei_wait_for_me_ready() < 0) |
| 170 | return; |
| 171 | |
| 172 | /* Reset host and ME circular buffers for next message */ |
| 173 | read_host_csr(&host); |
| 174 | host.reset = 1; |
| 175 | host.interrupt_generate = 1; |
| 176 | write_host_csr(&host); |
| 177 | |
| 178 | if (mei_wait_for_me_ready() < 0) |
| 179 | return; |
| 180 | |
| 181 | /* Re-init and indicate host is ready */ |
| 182 | read_host_csr(&host); |
| 183 | host.interrupt_generate = 1; |
| 184 | host.ready = 1; |
| 185 | host.reset = 0; |
| 186 | write_host_csr(&host); |
| 187 | } |
| 188 | |
| 189 | static int mei_send_packet(struct mei_header *mei, void *req_data) |
| 190 | { |
| 191 | struct mei_csr host; |
Lee Leahy | 23602df | 2017-03-16 19:00:37 -0700 | [diff] [blame^] | 192 | unsigned int ndata, n; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 193 | u32 *data; |
| 194 | |
| 195 | /* Number of dwords to write */ |
| 196 | ndata = mei->length >> 2; |
| 197 | |
| 198 | /* Pad non-dword aligned request message length */ |
| 199 | if (mei->length & 3) |
| 200 | ndata++; |
| 201 | if (!ndata) { |
| 202 | printk(BIOS_DEBUG, "ME: request has no data\n"); |
| 203 | return -1; |
| 204 | } |
| 205 | ndata++; /* Add MEI header */ |
| 206 | |
| 207 | /* |
| 208 | * Make sure there is still room left in the circular buffer. |
| 209 | * Reset the buffer pointers if the requested message will not fit. |
| 210 | */ |
| 211 | read_host_csr(&host); |
| 212 | if ((host.buffer_depth - host.buffer_write_ptr) < ndata) { |
| 213 | printk(BIOS_ERR, "ME: circular buffer full, resetting...\n"); |
| 214 | mei_reset(); |
| 215 | read_host_csr(&host); |
| 216 | } |
| 217 | |
| 218 | /* Ensure the requested length will fit in the circular buffer. */ |
| 219 | if ((host.buffer_depth - host.buffer_write_ptr) < ndata) { |
| 220 | printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n", |
| 221 | ndata + 2, host.buffer_depth); |
| 222 | return -1; |
| 223 | } |
| 224 | |
| 225 | /* Write MEI header */ |
| 226 | mei_write_dword_ptr(mei, MEI_H_CB_WW); |
| 227 | ndata--; |
| 228 | |
| 229 | /* Write message data */ |
| 230 | data = req_data; |
| 231 | for (n = 0; n < ndata; ++n) |
| 232 | write_cb(*data++); |
| 233 | |
| 234 | /* Generate interrupt to the ME */ |
| 235 | read_host_csr(&host); |
| 236 | host.interrupt_generate = 1; |
| 237 | write_host_csr(&host); |
| 238 | |
| 239 | /* Make sure ME is ready after sending request data */ |
| 240 | return mei_wait_for_me_ready(); |
| 241 | } |
| 242 | |
| 243 | static int mei_send_data(u8 me_address, u8 host_address, |
| 244 | void *req_data, int req_bytes) |
| 245 | { |
| 246 | struct mei_header header = { |
| 247 | .client_address = me_address, |
| 248 | .host_address = host_address, |
| 249 | }; |
| 250 | struct mei_csr host; |
| 251 | int current = 0; |
| 252 | u8 *req_ptr = req_data; |
| 253 | |
| 254 | while (!header.is_complete) { |
| 255 | int remain = req_bytes - current; |
| 256 | int buf_len; |
| 257 | |
| 258 | read_host_csr(&host); |
| 259 | buf_len = host.buffer_depth - host.buffer_write_ptr; |
| 260 | |
| 261 | if (buf_len > remain) { |
| 262 | /* Send all remaining data as final message */ |
| 263 | header.length = req_bytes - current; |
| 264 | header.is_complete = 1; |
| 265 | } else { |
| 266 | /* Send as much data as the buffer can hold */ |
| 267 | header.length = buf_len; |
| 268 | } |
| 269 | |
| 270 | mei_send_packet(&header, req_ptr); |
| 271 | |
| 272 | req_ptr += header.length; |
| 273 | current += header.length; |
| 274 | } |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static int mei_send_header(u8 me_address, u8 host_address, |
| 280 | void *header, int header_len, int complete) |
| 281 | { |
| 282 | struct mei_header mei = { |
| 283 | .client_address = me_address, |
| 284 | .host_address = host_address, |
| 285 | .length = header_len, |
| 286 | .is_complete = complete, |
| 287 | }; |
| 288 | return mei_send_packet(&mei, header); |
| 289 | } |
| 290 | |
| 291 | static int mei_recv_msg(void *header, int header_bytes, |
| 292 | void *rsp_data, int rsp_bytes) |
| 293 | { |
| 294 | struct mei_header mei_rsp; |
| 295 | struct mei_csr me, host; |
Lee Leahy | 23602df | 2017-03-16 19:00:37 -0700 | [diff] [blame^] | 296 | unsigned int ndata, n; |
| 297 | unsigned int expected; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 298 | u32 *data; |
| 299 | |
| 300 | /* Total number of dwords to read from circular buffer */ |
| 301 | expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2; |
| 302 | if (rsp_bytes & 3) |
| 303 | expected++; |
| 304 | |
| 305 | if (mei_wait_for_me_ready() < 0) |
| 306 | return -1; |
| 307 | |
| 308 | /* |
| 309 | * The interrupt status bit does not appear to indicate that the |
| 310 | * message has actually been received. Instead we wait until the |
| 311 | * expected number of dwords are present in the circular buffer. |
| 312 | */ |
| 313 | for (n = ME_RETRY; n; --n) { |
| 314 | read_me_csr(&me); |
| 315 | if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected) |
| 316 | break; |
| 317 | udelay(ME_DELAY); |
| 318 | } |
| 319 | if (!n) { |
| 320 | printk(BIOS_ERR, "ME: timeout waiting for data: expected " |
| 321 | "%u, available %u\n", expected, |
| 322 | me.buffer_write_ptr - me.buffer_read_ptr); |
| 323 | return -1; |
| 324 | } |
| 325 | |
| 326 | /* Read and verify MEI response header from the ME */ |
| 327 | mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW); |
| 328 | if (!mei_rsp.is_complete) { |
| 329 | printk(BIOS_ERR, "ME: response is not complete\n"); |
| 330 | return -1; |
| 331 | } |
| 332 | |
| 333 | /* Handle non-dword responses and expect at least the header */ |
| 334 | ndata = mei_rsp.length >> 2; |
| 335 | if (mei_rsp.length & 3) |
| 336 | ndata++; |
| 337 | if (ndata != (expected - 1)) { |
| 338 | printk(BIOS_ERR, "ME: response is missing data %d != %d\n", |
| 339 | ndata, (expected - 1)); |
| 340 | return -1; |
| 341 | } |
| 342 | |
| 343 | /* Read response header from the ME */ |
| 344 | data = header; |
| 345 | for (n = 0; n < (header_bytes >> 2); ++n) |
| 346 | *data++ = read_cb(); |
| 347 | ndata -= header_bytes >> 2; |
| 348 | |
| 349 | /* Make sure caller passed a buffer with enough space */ |
| 350 | if (ndata != (rsp_bytes >> 2)) { |
| 351 | printk(BIOS_ERR, "ME: not enough room in response buffer: " |
| 352 | "%u != %u\n", ndata, rsp_bytes >> 2); |
| 353 | return -1; |
| 354 | } |
| 355 | |
| 356 | /* Read response data from the circular buffer */ |
| 357 | data = rsp_data; |
| 358 | for (n = 0; n < ndata; ++n) |
| 359 | *data++ = read_cb(); |
| 360 | |
| 361 | /* Tell the ME that we have consumed the response */ |
| 362 | read_host_csr(&host); |
| 363 | host.interrupt_status = 1; |
| 364 | host.interrupt_generate = 1; |
| 365 | write_host_csr(&host); |
| 366 | |
| 367 | return mei_wait_for_me_ready(); |
| 368 | } |
| 369 | |
| 370 | static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi, |
| 371 | void *req_data, int req_bytes, |
| 372 | void *rsp_data, int rsp_bytes) |
| 373 | { |
| 374 | struct mkhi_header mkhi_rsp; |
| 375 | |
| 376 | /* Send header */ |
| 377 | if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS, |
| 378 | mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0) |
| 379 | return -1; |
| 380 | |
| 381 | /* Send data if available */ |
| 382 | if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS, |
| 383 | req_data, req_bytes) < 0) |
| 384 | return -1; |
| 385 | |
| 386 | /* Return now if no response expected */ |
| 387 | if (!rsp_bytes) |
| 388 | return 0; |
| 389 | |
| 390 | /* Read header and data */ |
| 391 | if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp), |
| 392 | rsp_data, rsp_bytes) < 0) |
| 393 | return -1; |
| 394 | |
| 395 | if (!mkhi_rsp.is_response || |
| 396 | mkhi->group_id != mkhi_rsp.group_id || |
| 397 | mkhi->command != mkhi_rsp.command) { |
| 398 | printk(BIOS_ERR, "ME: invalid response, group %u ?= %u," |
| 399 | "command %u ?= %u, is_response %u\n", mkhi->group_id, |
| 400 | mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command, |
| 401 | mkhi_rsp.is_response); |
| 402 | return -1; |
| 403 | } |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static inline int mei_sendrecv_icc(struct icc_header *icc, |
| 409 | void *req_data, int req_bytes, |
| 410 | void *rsp_data, int rsp_bytes) |
| 411 | { |
| 412 | struct icc_header icc_rsp; |
| 413 | |
| 414 | /* Send header */ |
| 415 | if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS, |
| 416 | icc, sizeof(*icc), req_bytes ? 0 : 1) < 0) |
| 417 | return -1; |
| 418 | |
| 419 | /* Send data if available */ |
| 420 | if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS, |
| 421 | req_data, req_bytes) < 0) |
| 422 | return -1; |
| 423 | |
| 424 | /* Read header and data, if needed */ |
| 425 | if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp), |
| 426 | rsp_data, rsp_bytes) < 0) |
| 427 | return -1; |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read |
| 434 | * state machine on the BIOS end doesn't match the ME's state machine. |
| 435 | */ |
| 436 | static void intel_me_mbp_give_up(device_t dev) |
| 437 | { |
| 438 | struct mei_csr csr; |
| 439 | |
| 440 | pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP); |
| 441 | |
| 442 | read_host_csr(&csr); |
| 443 | csr.reset = 1; |
| 444 | csr.interrupt_generate = 1; |
| 445 | write_host_csr(&csr); |
| 446 | } |
| 447 | |
| 448 | /* |
| 449 | * mbp clear routine. This will wait for the ME to indicate that |
| 450 | * the MBP has been read and cleared. |
| 451 | */ |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 452 | static void intel_me_mbp_clear(device_t dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 453 | { |
| 454 | int count; |
| 455 | struct me_hfs2 hfs2; |
| 456 | |
| 457 | /* Wait for the mbp_cleared indicator */ |
| 458 | for (count = ME_RETRY; count > 0; --count) { |
| 459 | pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2); |
| 460 | if (hfs2.mbp_cleared) |
| 461 | break; |
| 462 | udelay(ME_DELAY); |
| 463 | } |
| 464 | |
| 465 | if (count == 0) { |
| 466 | printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n"); |
| 467 | intel_me_mbp_give_up(dev); |
| 468 | } else { |
| 469 | printk(BIOS_INFO, "ME: MBP cleared\n"); |
| 470 | } |
| 471 | } |
| 472 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 473 | static void me_print_fw_version(mbp_fw_version_name *vers_name) |
| 474 | { |
| 475 | if (!vers_name) { |
| 476 | printk(BIOS_ERR, "ME: mbp missing version report\n"); |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n", |
| 481 | vers_name->major_version, vers_name->minor_version, |
| 482 | vers_name->hotfix_version, vers_name->build_version); |
| 483 | } |
| 484 | |
| 485 | #if CONFIG_DEBUG_INTEL_ME |
Edward O'Callaghan | 8cc5dc1 | 2015-01-07 15:50:43 +1100 | [diff] [blame] | 486 | static inline void print_cap(const char *name, int state) |
| 487 | { |
| 488 | printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n", |
| 489 | name, state ? " en" : "dis"); |
| 490 | } |
| 491 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 492 | /* Get ME Firmware Capabilities */ |
| 493 | static int mkhi_get_fwcaps(mbp_mefwcaps *cap) |
| 494 | { |
| 495 | u32 rule_id = 0; |
| 496 | struct me_fwcaps cap_msg; |
| 497 | struct mkhi_header mkhi = { |
| 498 | .group_id = MKHI_GROUP_ID_FWCAPS, |
| 499 | .command = MKHI_FWCAPS_GET_RULE, |
| 500 | }; |
| 501 | |
| 502 | /* Send request and wait for response */ |
| 503 | if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32), |
| 504 | &cap_msg, sizeof(cap_msg)) < 0) { |
| 505 | printk(BIOS_ERR, "ME: GET FWCAPS message failed\n"); |
| 506 | return -1; |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 507 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 508 | *cap = cap_msg.caps_sku; |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | /* Get ME Firmware Capabilities */ |
| 513 | static void me_print_fwcaps(mbp_mefwcaps *cap) |
| 514 | { |
| 515 | mbp_mefwcaps local_caps; |
| 516 | if (!cap) { |
| 517 | cap = &local_caps; |
| 518 | printk(BIOS_ERR, "ME: mbp missing fwcaps report\n"); |
| 519 | if (mkhi_get_fwcaps(cap)) |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | print_cap("Full Network manageability", cap->full_net); |
| 524 | print_cap("Regular Network manageability", cap->std_net); |
| 525 | print_cap("Manageability", cap->manageability); |
| 526 | print_cap("IntelR Anti-Theft (AT)", cap->intel_at); |
| 527 | print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls); |
| 528 | print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc); |
| 529 | print_cap("ICC Over Clocking", cap->icc_over_clocking); |
Edward O'Callaghan | 8cc5dc1 | 2015-01-07 15:50:43 +1100 | [diff] [blame] | 530 | print_cap("Protected Audio Video Path (PAVP)", cap->pavp); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 531 | print_cap("IPV6", cap->ipv6); |
| 532 | print_cap("KVM Remote Control (KVM)", cap->kvm); |
| 533 | print_cap("Outbreak Containment Heuristic (OCH)", cap->och); |
| 534 | print_cap("Virtual LAN (VLAN)", cap->vlan); |
| 535 | print_cap("TLS", cap->tls); |
| 536 | print_cap("Wireless LAN (WLAN)", cap->wlan); |
| 537 | } |
| 538 | #endif |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 539 | |
| 540 | /* Send END OF POST message to the ME */ |
| 541 | static int mkhi_end_of_post(void) |
| 542 | { |
| 543 | struct mkhi_header mkhi = { |
| 544 | .group_id = MKHI_GROUP_ID_GEN, |
| 545 | .command = MKHI_END_OF_POST, |
| 546 | }; |
| 547 | u32 eop_ack; |
| 548 | |
| 549 | /* Send request and wait for response */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 550 | if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) { |
| 551 | printk(BIOS_ERR, "ME: END OF POST message failed\n"); |
| 552 | return -1; |
| 553 | } |
| 554 | |
| 555 | printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack); |
| 556 | return 0; |
| 557 | } |
| 558 | |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 559 | /* Send END OF POST message to the ME */ |
| 560 | static int mkhi_end_of_post_noack(void) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 561 | { |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 562 | struct mkhi_header mkhi = { |
| 563 | .group_id = MKHI_GROUP_ID_GEN, |
| 564 | .command = MKHI_END_OF_POST_NOACK, |
| 565 | }; |
| 566 | |
| 567 | /* Send request, do not wait for response */ |
| 568 | if (mei_sendrecv_mkhi(&mkhi, NULL, 0, NULL, 0) < 0) { |
| 569 | printk(BIOS_ERR, "ME: END OF POST NOACK message failed\n"); |
| 570 | return -1; |
| 571 | } |
| 572 | |
| 573 | printk(BIOS_INFO, "ME: END OF POST NOACK message successful\n"); |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | /* Send HMRFPO LOCK message to the ME */ |
| 578 | static int mkhi_hmrfpo_lock(void) |
| 579 | { |
| 580 | struct mkhi_header mkhi = { |
| 581 | .group_id = MKHI_GROUP_ID_HMRFPO, |
| 582 | .command = MKHI_HMRFPO_LOCK, |
| 583 | }; |
| 584 | u32 ack; |
| 585 | |
| 586 | /* Send request and wait for response */ |
| 587 | if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &ack, sizeof(ack)) < 0) { |
| 588 | printk(BIOS_ERR, "ME: HMRFPO LOCK message failed\n"); |
| 589 | return -1; |
| 590 | } |
| 591 | |
| 592 | printk(BIOS_INFO, "ME: HMRPFO LOCK message successful (%d)\n", ack); |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | /* Send HMRFPO LOCK message to the ME, do not wait for response */ |
| 597 | static int mkhi_hmrfpo_lock_noack(void) |
| 598 | { |
| 599 | struct mkhi_header mkhi = { |
| 600 | .group_id = MKHI_GROUP_ID_HMRFPO, |
| 601 | .command = MKHI_HMRFPO_LOCK_NOACK, |
| 602 | }; |
| 603 | |
| 604 | /* Send request, do not wait for response */ |
| 605 | if (mei_sendrecv_mkhi(&mkhi, NULL, 0, NULL, 0) < 0) { |
| 606 | printk(BIOS_ERR, "ME: HMRFPO LOCK NOACK message failed\n"); |
| 607 | return -1; |
| 608 | } |
| 609 | |
| 610 | printk(BIOS_INFO, "ME: HMRPFO LOCK NOACK message successful\n"); |
| 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | static void intel_me_finalize(device_t dev) |
| 615 | { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 616 | u32 reg32; |
| 617 | |
| 618 | /* S3 path will have hidden this device already */ |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 619 | if (!mei_base_address || mei_base_address == (u8 *) 0xfffffff0) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 620 | return; |
| 621 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 622 | /* Make sure IO is disabled */ |
| 623 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 624 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 625 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 626 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 627 | |
| 628 | /* Hide the PCI device */ |
| 629 | RCBA32_OR(FD2, PCH_DISABLE_MEI1); |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 630 | RCBA32(FD2); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | static int me_icc_set_clock_enables(u32 mask) |
| 634 | { |
| 635 | struct icc_clock_enables_msg clk = { |
| 636 | .clock_enables = 0, /* Turn off specified clocks */ |
| 637 | .clock_mask = mask, |
| 638 | .no_response = 1, /* Do not expect response */ |
| 639 | }; |
| 640 | struct icc_header icc = { |
| 641 | .api_version = ICC_API_VERSION_LYNXPOINT, |
| 642 | .icc_command = ICC_SET_CLOCK_ENABLES, |
| 643 | .length = sizeof(clk), |
| 644 | }; |
| 645 | |
| 646 | /* Send request and wait for response */ |
| 647 | if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) { |
| 648 | printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n"); |
| 649 | return -1; |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 650 | } else { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 651 | printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask); |
| 652 | } |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | /* Determine the path that we should take based on ME status */ |
| 658 | static me_bios_path intel_me_path(device_t dev) |
| 659 | { |
| 660 | me_bios_path path = ME_DISABLE_BIOS_PATH; |
| 661 | struct me_hfs hfs; |
| 662 | struct me_hfs2 hfs2; |
| 663 | |
| 664 | /* Check and dump status */ |
| 665 | intel_me_status(); |
| 666 | |
| 667 | pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS); |
| 668 | pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2); |
| 669 | |
| 670 | /* Check Current Working State */ |
| 671 | switch (hfs.working_state) { |
| 672 | case ME_HFS_CWS_NORMAL: |
| 673 | path = ME_NORMAL_BIOS_PATH; |
| 674 | break; |
| 675 | case ME_HFS_CWS_REC: |
| 676 | path = ME_RECOVERY_BIOS_PATH; |
| 677 | break; |
| 678 | default: |
| 679 | path = ME_DISABLE_BIOS_PATH; |
| 680 | break; |
| 681 | } |
| 682 | |
| 683 | /* Check Current Operation Mode */ |
| 684 | switch (hfs.operation_mode) { |
| 685 | case ME_HFS_MODE_NORMAL: |
| 686 | break; |
| 687 | case ME_HFS_MODE_DEBUG: |
| 688 | case ME_HFS_MODE_DIS: |
| 689 | case ME_HFS_MODE_OVER_JMPR: |
| 690 | case ME_HFS_MODE_OVER_MEI: |
| 691 | default: |
| 692 | path = ME_DISABLE_BIOS_PATH; |
| 693 | break; |
| 694 | } |
| 695 | |
| 696 | /* Check for any error code and valid firmware and MBP */ |
| 697 | if (hfs.error_code || hfs.fpt_bad) |
| 698 | path = ME_ERROR_BIOS_PATH; |
| 699 | |
| 700 | /* Check if the MBP is ready */ |
| 701 | if (!hfs2.mbp_rdy) { |
| 702 | printk(BIOS_CRIT, "%s: mbp is not ready!\n", |
| 703 | __FUNCTION__); |
| 704 | path = ME_ERROR_BIOS_PATH; |
| 705 | } |
| 706 | |
| 707 | #if CONFIG_ELOG |
| 708 | if (path != ME_NORMAL_BIOS_PATH) { |
| 709 | struct elog_event_data_me_extended data = { |
| 710 | .current_working_state = hfs.working_state, |
| 711 | .operation_state = hfs.operation_state, |
| 712 | .operation_mode = hfs.operation_mode, |
| 713 | .error_code = hfs.error_code, |
| 714 | .progress_code = hfs2.progress_code, |
| 715 | .current_pmevent = hfs2.current_pmevent, |
| 716 | .current_state = hfs2.current_state, |
| 717 | }; |
| 718 | elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path); |
| 719 | elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT, |
| 720 | &data, sizeof(data)); |
| 721 | } |
| 722 | #endif |
| 723 | |
| 724 | return path; |
| 725 | } |
| 726 | |
| 727 | /* Prepare ME for MEI messages */ |
| 728 | static int intel_mei_setup(device_t dev) |
| 729 | { |
| 730 | struct resource *res; |
| 731 | struct mei_csr host; |
| 732 | u32 reg32; |
| 733 | |
| 734 | /* Find the MMIO base for the ME interface */ |
| 735 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 736 | if (!res || res->base == 0 || res->size == 0) { |
| 737 | printk(BIOS_DEBUG, "ME: MEI resource not present!\n"); |
| 738 | return -1; |
| 739 | } |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 740 | mei_base_address = res2mmio(res, 0, 0); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 741 | |
| 742 | /* Ensure Memory and Bus Master bits are set */ |
| 743 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 744 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 745 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 746 | |
| 747 | /* Clean up status for next message */ |
| 748 | read_host_csr(&host); |
| 749 | host.interrupt_generate = 1; |
| 750 | host.ready = 1; |
| 751 | host.reset = 0; |
| 752 | write_host_csr(&host); |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | /* Read the Extend register hash of ME firmware */ |
| 758 | static int intel_me_extend_valid(device_t dev) |
| 759 | { |
| 760 | struct me_heres status; |
| 761 | u32 extend[8] = {0}; |
| 762 | int i, count = 0; |
| 763 | |
| 764 | pci_read_dword_ptr(dev, &status, PCI_ME_HERES); |
| 765 | if (!status.extend_feature_present) { |
| 766 | printk(BIOS_ERR, "ME: Extend Feature not present\n"); |
| 767 | return -1; |
| 768 | } |
| 769 | |
| 770 | if (!status.extend_reg_valid) { |
| 771 | printk(BIOS_ERR, "ME: Extend Register not valid\n"); |
| 772 | return -1; |
| 773 | } |
| 774 | |
| 775 | switch (status.extend_reg_algorithm) { |
| 776 | case PCI_ME_EXT_SHA1: |
| 777 | count = 5; |
| 778 | printk(BIOS_DEBUG, "ME: Extend SHA-1: "); |
| 779 | break; |
| 780 | case PCI_ME_EXT_SHA256: |
| 781 | count = 8; |
| 782 | printk(BIOS_DEBUG, "ME: Extend SHA-256: "); |
| 783 | break; |
| 784 | default: |
| 785 | printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n", |
| 786 | status.extend_reg_algorithm); |
| 787 | return -1; |
| 788 | } |
| 789 | |
| 790 | for (i = 0; i < count; ++i) { |
| 791 | extend[i] = pci_read_config32(dev, PCI_ME_HER(i)); |
| 792 | printk(BIOS_DEBUG, "%08x", extend[i]); |
| 793 | } |
| 794 | printk(BIOS_DEBUG, "\n"); |
| 795 | |
| 796 | #if CONFIG_CHROMEOS |
| 797 | /* Save hash in NVS for the OS to verify */ |
| 798 | chromeos_set_me_hash(extend, count); |
| 799 | #endif |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 804 | static void intel_me_print_mbp(me_bios_payload *mbp_data) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 805 | { |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 806 | me_print_fw_version(mbp_data->fw_version_name); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 807 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 808 | #if CONFIG_DEBUG_INTEL_ME |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 809 | me_print_fwcaps(mbp_data->fw_capabilities); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 810 | #endif |
| 811 | |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 812 | if (mbp_data->plat_time) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 813 | printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n", |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 814 | mbp_data->plat_time->wake_event_mrst_time_ms); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 815 | printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n", |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 816 | mbp_data->plat_time->mrst_pltrst_time_ms); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 817 | printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n", |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 818 | mbp_data->plat_time->pltrst_cpurst_time_ms); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 819 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 822 | static u32 me_to_host_words_pending(void) |
| 823 | { |
| 824 | struct mei_csr me; |
| 825 | read_me_csr(&me); |
| 826 | if (!me.ready) |
| 827 | return 0; |
| 828 | return (me.buffer_write_ptr - me.buffer_read_ptr) & |
| 829 | (me.buffer_depth - 1); |
| 830 | } |
| 831 | |
| 832 | struct mbp_payload { |
| 833 | mbp_header header; |
| 834 | u32 data[0]; |
| 835 | }; |
| 836 | |
| 837 | /* |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 838 | * Read and print ME MBP data |
| 839 | * |
| 840 | * Return -1 to indicate a problem (give up) |
| 841 | * Return 0 to indicate success (send LOCK+EOP) |
| 842 | * Return 1 to indicate success (send LOCK+EOP with NOACK) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 843 | */ |
| 844 | static int intel_me_read_mbp(me_bios_payload *mbp_data, device_t dev) |
| 845 | { |
| 846 | mbp_header mbp_hdr; |
| 847 | u32 me2host_pending; |
| 848 | struct mei_csr host; |
| 849 | struct me_hfs2 hfs2; |
| 850 | struct mbp_payload *mbp; |
| 851 | int i; |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 852 | int ret = 0; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 853 | |
| 854 | pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2); |
| 855 | |
| 856 | if (!hfs2.mbp_rdy) { |
| 857 | printk(BIOS_ERR, "ME: MBP not ready\n"); |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 858 | intel_me_mbp_give_up(dev); |
| 859 | return -1; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | me2host_pending = me_to_host_words_pending(); |
| 863 | if (!me2host_pending) { |
| 864 | printk(BIOS_ERR, "ME: no mbp data!\n"); |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 865 | intel_me_mbp_give_up(dev); |
| 866 | return -1; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | /* we know for sure that at least the header is there */ |
| 870 | mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW); |
| 871 | |
| 872 | if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) || |
| 873 | (me2host_pending < mbp_hdr.mbp_size)) { |
| 874 | printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words" |
| 875 | " buffer contains %d words\n", |
| 876 | mbp_hdr.num_entries, mbp_hdr.mbp_size, |
| 877 | me2host_pending); |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 878 | intel_me_mbp_give_up(dev); |
| 879 | return -1; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 880 | } |
| 881 | mbp = malloc(mbp_hdr.mbp_size * sizeof(u32)); |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 882 | if (!mbp) { |
| 883 | intel_me_mbp_give_up(dev); |
| 884 | return -1; |
| 885 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 886 | |
| 887 | mbp->header = mbp_hdr; |
| 888 | me2host_pending--; |
| 889 | |
| 890 | i = 0; |
| 891 | while (i != me2host_pending) { |
| 892 | mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW); |
| 893 | i++; |
| 894 | } |
| 895 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 896 | read_host_csr(&host); |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 897 | |
| 898 | /* Check that read and write pointers are equal. */ |
| 899 | if (host.buffer_read_ptr != host.buffer_write_ptr) { |
| 900 | printk(BIOS_INFO, "ME: MBP Read/Write pointer mismatch\n"); |
| 901 | printk(BIOS_INFO, "ME: MBP Waiting for MBP cleared flag\n"); |
| 902 | |
| 903 | /* Tell ME that the host has finished reading the MBP. */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 904 | host.interrupt_generate = 1; |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 905 | host.reset = 0; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 906 | write_host_csr(&host); |
| 907 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 908 | /* Wait for the mbp_cleared indicator. */ |
| 909 | intel_me_mbp_clear(dev); |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 910 | } else { |
| 911 | /* Indicate NOACK messages should be used. */ |
| 912 | ret = 1; |
| 913 | } |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 914 | |
| 915 | /* Dump out the MBP contents. */ |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 916 | #if CONFIG_DEBUG_INTEL_ME |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 917 | printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n", |
| 918 | mbp->header.num_entries, mbp->header.mbp_size); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 919 | for (i = 0; i < mbp->header.mbp_size - 1; i++) { |
| 920 | printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]); |
| 921 | } |
| 922 | #endif |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 923 | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 924 | #define ASSIGN_FIELD_PTR(field_, val_) \ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 925 | { \ |
| 926 | mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \ |
| 927 | break; \ |
| 928 | } |
| 929 | |
| 930 | /* Setup the pointers in the me_bios_payload structure. */ |
| 931 | for (i = 0; i < mbp->header.mbp_size - 1;) { |
| 932 | mbp_item_header *item = (void *)&mbp->data[i]; |
| 933 | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 934 | switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 935 | case MBP_IDENT(KERNEL, FW_VER): |
| 936 | ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]); |
| 937 | |
| 938 | case MBP_IDENT(ICC, PROFILE): |
| 939 | ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]); |
| 940 | |
| 941 | case MBP_IDENT(INTEL_AT, STATE): |
| 942 | ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]); |
| 943 | |
| 944 | case MBP_IDENT(KERNEL, FW_CAP): |
| 945 | ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]); |
| 946 | |
| 947 | case MBP_IDENT(KERNEL, ROM_BIST): |
| 948 | ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]); |
| 949 | |
| 950 | case MBP_IDENT(KERNEL, PLAT_KEY): |
| 951 | ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]); |
| 952 | |
| 953 | case MBP_IDENT(KERNEL, FW_TYPE): |
| 954 | ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]); |
| 955 | |
| 956 | case MBP_IDENT(KERNEL, MFS_FAILURE): |
| 957 | ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]); |
| 958 | |
| 959 | case MBP_IDENT(KERNEL, PLAT_TIME): |
| 960 | ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]); |
| 961 | |
| 962 | case MBP_IDENT(NFC, SUPPORT_DATA): |
| 963 | ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 964 | } |
| 965 | i += item->length; |
| 966 | } |
| 967 | #undef ASSIGN_FIELD_PTR |
| 968 | |
Patrick Georgi | b753eeb | 2016-10-18 19:46:33 +0200 | [diff] [blame] | 969 | free(mbp); |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 970 | return ret; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 971 | } |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 972 | |
| 973 | /* Check whether ME is present and do basic init */ |
| 974 | static void intel_me_init(device_t dev) |
| 975 | { |
| 976 | config_t *config = dev->chip_info; |
| 977 | me_bios_path path = intel_me_path(dev); |
| 978 | me_bios_payload mbp_data; |
| 979 | int mbp_ret; |
| 980 | struct me_hfs hfs; |
| 981 | struct mei_csr csr; |
| 982 | |
| 983 | /* Do initial setup and determine the BIOS path */ |
| 984 | printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]); |
| 985 | |
| 986 | if (path == ME_NORMAL_BIOS_PATH) { |
| 987 | /* Validate the extend register */ |
| 988 | intel_me_extend_valid(dev); |
| 989 | } |
| 990 | |
| 991 | memset(&mbp_data, 0, sizeof(mbp_data)); |
| 992 | |
| 993 | /* |
| 994 | * According to the ME9 BWG, BIOS is required to fetch MBP data in |
| 995 | * all boot flows except S3 Resume. |
| 996 | */ |
| 997 | |
| 998 | /* Prepare MEI MMIO interface */ |
| 999 | if (intel_mei_setup(dev) < 0) |
| 1000 | return; |
| 1001 | |
| 1002 | /* Read ME MBP data */ |
| 1003 | mbp_ret = intel_me_read_mbp(&mbp_data, dev); |
| 1004 | if (mbp_ret < 0) |
| 1005 | return; |
| 1006 | intel_me_print_mbp(&mbp_data); |
| 1007 | |
| 1008 | /* Set clock enables according to devicetree */ |
| 1009 | if (config && config->icc_clock_disable) |
| 1010 | me_icc_set_clock_enables(config->icc_clock_disable); |
| 1011 | |
| 1012 | /* Make sure ME is in a mode that expects EOP */ |
| 1013 | pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS); |
| 1014 | |
| 1015 | /* Abort and leave device alone if not normal mode */ |
| 1016 | if (hfs.fpt_bad || |
| 1017 | hfs.working_state != ME_HFS_CWS_NORMAL || |
| 1018 | hfs.operation_mode != ME_HFS_MODE_NORMAL) |
| 1019 | return; |
| 1020 | |
| 1021 | if (mbp_ret) { |
| 1022 | /* |
| 1023 | * MBP Cleared wait is skipped, |
| 1024 | * Do not expect ACK and reset when complete. |
| 1025 | */ |
| 1026 | |
| 1027 | /* Send HMRFPO Lock command, no response */ |
| 1028 | mkhi_hmrfpo_lock_noack(); |
| 1029 | |
| 1030 | /* Send END OF POST command, no response */ |
| 1031 | mkhi_end_of_post_noack(); |
| 1032 | |
| 1033 | /* Assert reset and interrupt */ |
| 1034 | read_host_csr(&csr); |
| 1035 | csr.interrupt_generate = 1; |
| 1036 | csr.reset = 1; |
| 1037 | write_host_csr(&csr); |
| 1038 | } else { |
| 1039 | /* |
| 1040 | * MBP Cleared wait was not skipped |
| 1041 | */ |
| 1042 | |
| 1043 | /* Send HMRFPO LOCK command */ |
| 1044 | mkhi_hmrfpo_lock(); |
| 1045 | |
| 1046 | /* Send EOP command so ME stops accepting other commands */ |
| 1047 | mkhi_end_of_post(); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | static void intel_me_enable(device_t dev) |
| 1052 | { |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 1053 | /* Avoid talking to the device in S3 path */ |
Kyösti Mälkki | 1ec23c9 | 2015-05-29 06:18:18 +0300 | [diff] [blame] | 1054 | if (acpi_is_wakeup_s3()) { |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 1055 | dev->enabled = 0; |
| 1056 | pch_disable_devfn(dev); |
| 1057 | } |
Duncan Laurie | c99681f | 2014-12-10 08:11:09 -0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static struct device_operations device_ops = { |
| 1061 | .read_resources = &pci_dev_read_resources, |
| 1062 | .set_resources = &pci_dev_set_resources, |
| 1063 | .enable_resources = &pci_dev_enable_resources, |
| 1064 | .enable = &intel_me_enable, |
| 1065 | .init = &intel_me_init, |
| 1066 | .final = &intel_me_finalize, |
| 1067 | .ops_pci = &broadwell_pci_ops, |
| 1068 | }; |
| 1069 | |
| 1070 | static const unsigned short pci_device_ids[] = { |
| 1071 | 0x9c3a, /* Low Power */ |
| 1072 | 0x9cba, /* WildcatPoint */ |
| 1073 | 0 |
| 1074 | }; |
| 1075 | |
| 1076 | static const struct pci_driver intel_me __pci_driver = { |
| 1077 | .ops = &device_ops, |
| 1078 | .vendor = PCI_VENDOR_ID_INTEL, |
| 1079 | .devices = pci_device_ids, |
| 1080 | }; |