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