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