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