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