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