Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 3 | |
| 4 | /* |
| 5 | * This is a ramstage driver for the Intel Management Engine found in the |
| 6 | * 6-series chipset. It handles the required boot-time messages over the |
| 7 | * MMIO-based Management Engine Interface to tell the ME that the BIOS is |
| 8 | * finished with POST. Additional messages are defined for debug but are |
| 9 | * not used unless the console loglevel is high enough. |
| 10 | */ |
| 11 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame^] | 12 | #include <acpi/acpi.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 13 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 14 | #include <device/pci_ops.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 15 | #include <console/console.h> |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 16 | #include <device/device.h> |
| 17 | #include <device/pci.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 18 | #include <device/pci_ids.h> |
| 19 | #include <device/pci_def.h> |
| 20 | #include <string.h> |
| 21 | #include <delay.h> |
Duncan Laurie | c1c9435 | 2012-07-13 10:11:54 -0700 | [diff] [blame] | 22 | #include <elog.h> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 23 | #include <halt.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 24 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 25 | #include "me.h" |
| 26 | #include "pch.h" |
| 27 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 28 | #if CONFIG(CHROMEOS) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 29 | #include <vendorcode/google/chromeos/gnvs.h> |
| 30 | #endif |
| 31 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 32 | /* Path that the BIOS should take based on ME state */ |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 33 | static const char *me_bios_path_values[] __unused = { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 34 | [ME_NORMAL_BIOS_PATH] = "Normal", |
| 35 | [ME_S3WAKE_BIOS_PATH] = "S3 Wake", |
| 36 | [ME_ERROR_BIOS_PATH] = "Error", |
| 37 | [ME_RECOVERY_BIOS_PATH] = "Recovery", |
| 38 | [ME_DISABLE_BIOS_PATH] = "Disable", |
| 39 | [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update", |
| 40 | }; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 41 | |
| 42 | /* MMIO base address for MEI interface */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 43 | static u32 *mei_base_address; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 44 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 45 | static void mei_dump(void *ptr, int dword, int offset, const char *type) |
| 46 | { |
| 47 | struct mei_csr *csr; |
| 48 | |
Kyösti Mälkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 49 | if (!CONFIG(DEBUG_INTEL_ME)) |
| 50 | return; |
| 51 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 52 | printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset); |
| 53 | |
| 54 | switch (offset) { |
| 55 | case MEI_H_CSR: |
| 56 | case MEI_ME_CSR_HA: |
| 57 | csr = ptr; |
| 58 | if (!csr) { |
| 59 | printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword); |
| 60 | break; |
| 61 | } |
| 62 | printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u " |
| 63 | "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth, |
| 64 | csr->buffer_read_ptr, csr->buffer_write_ptr, |
| 65 | csr->ready, csr->reset, csr->interrupt_generate, |
| 66 | csr->interrupt_status, csr->interrupt_enable); |
| 67 | break; |
| 68 | case MEI_ME_CB_RW: |
| 69 | case MEI_H_CB_WW: |
| 70 | printk(BIOS_SPEW, "CB: 0x%08x\n", dword); |
| 71 | break; |
| 72 | default: |
| 73 | printk(BIOS_SPEW, "0x%08x\n", offset); |
| 74 | break; |
| 75 | } |
| 76 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * ME/MEI access helpers using memcpy to avoid aliasing. |
| 80 | */ |
| 81 | |
| 82 | static inline void mei_read_dword_ptr(void *ptr, int offset) |
| 83 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 84 | u32 dword = read32(mei_base_address + (offset/sizeof(u32))); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 85 | memcpy(ptr, &dword, sizeof(dword)); |
| 86 | mei_dump(ptr, dword, offset, "READ"); |
| 87 | } |
| 88 | |
| 89 | static inline void mei_write_dword_ptr(void *ptr, int offset) |
| 90 | { |
| 91 | u32 dword = 0; |
| 92 | memcpy(&dword, ptr, sizeof(dword)); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 93 | write32(mei_base_address + (offset/sizeof(u32)), dword); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 94 | mei_dump(ptr, dword, offset, "WRITE"); |
| 95 | } |
| 96 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 97 | #ifndef __SIMPLE_DEVICE__ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 98 | static inline void pci_read_dword_ptr(struct device *dev, void *ptr, int offset) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 99 | { |
| 100 | u32 dword = pci_read_config32(dev, offset); |
| 101 | memcpy(ptr, &dword, sizeof(dword)); |
| 102 | mei_dump(ptr, dword, offset, "PCI READ"); |
| 103 | } |
| 104 | #endif |
| 105 | |
| 106 | static inline void read_host_csr(struct mei_csr *csr) |
| 107 | { |
| 108 | mei_read_dword_ptr(csr, MEI_H_CSR); |
| 109 | } |
| 110 | |
| 111 | static inline void write_host_csr(struct mei_csr *csr) |
| 112 | { |
| 113 | mei_write_dword_ptr(csr, MEI_H_CSR); |
| 114 | } |
| 115 | |
| 116 | static inline void read_me_csr(struct mei_csr *csr) |
| 117 | { |
| 118 | mei_read_dword_ptr(csr, MEI_ME_CSR_HA); |
| 119 | } |
| 120 | |
| 121 | static inline void write_cb(u32 dword) |
| 122 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 123 | write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 124 | mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE"); |
| 125 | } |
| 126 | |
| 127 | static inline u32 read_cb(void) |
| 128 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 129 | u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32))); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 130 | mei_dump(NULL, dword, MEI_ME_CB_RW, "READ"); |
| 131 | return dword; |
| 132 | } |
| 133 | |
| 134 | /* Wait for ME ready bit to be asserted */ |
| 135 | static int mei_wait_for_me_ready(void) |
| 136 | { |
| 137 | struct mei_csr me; |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 138 | unsigned int try = ME_RETRY; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 139 | |
| 140 | while (try--) { |
| 141 | read_me_csr(&me); |
| 142 | if (me.ready) |
| 143 | return 0; |
| 144 | udelay(ME_DELAY); |
| 145 | } |
| 146 | |
| 147 | printk(BIOS_ERR, "ME: failed to become ready\n"); |
| 148 | return -1; |
| 149 | } |
| 150 | |
| 151 | static void mei_reset(void) |
| 152 | { |
| 153 | struct mei_csr host; |
| 154 | |
| 155 | if (mei_wait_for_me_ready() < 0) |
| 156 | return; |
| 157 | |
| 158 | /* Reset host and ME circular buffers for next message */ |
| 159 | read_host_csr(&host); |
| 160 | host.reset = 1; |
| 161 | host.interrupt_generate = 1; |
| 162 | write_host_csr(&host); |
| 163 | |
| 164 | if (mei_wait_for_me_ready() < 0) |
| 165 | return; |
| 166 | |
| 167 | /* Re-init and indicate host is ready */ |
| 168 | read_host_csr(&host); |
| 169 | host.interrupt_generate = 1; |
| 170 | host.ready = 1; |
| 171 | host.reset = 0; |
| 172 | write_host_csr(&host); |
| 173 | } |
| 174 | |
| 175 | static int mei_send_msg(struct mei_header *mei, struct mkhi_header *mkhi, |
| 176 | void *req_data) |
| 177 | { |
| 178 | struct mei_csr host; |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 179 | unsigned int ndata, n; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 180 | u32 *data; |
| 181 | |
| 182 | /* Number of dwords to write, ignoring MKHI */ |
| 183 | ndata = mei->length >> 2; |
| 184 | |
| 185 | /* Pad non-dword aligned request message length */ |
| 186 | if (mei->length & 3) |
| 187 | ndata++; |
| 188 | if (!ndata) { |
| 189 | printk(BIOS_DEBUG, "ME: request does not include MKHI\n"); |
| 190 | return -1; |
| 191 | } |
| 192 | ndata++; /* Add MEI header */ |
| 193 | |
| 194 | /* |
| 195 | * Make sure there is still room left in the circular buffer. |
| 196 | * Reset the buffer pointers if the requested message will not fit. |
| 197 | */ |
| 198 | read_host_csr(&host); |
| 199 | if ((host.buffer_depth - host.buffer_write_ptr) < ndata) { |
| 200 | printk(BIOS_ERR, "ME: circular buffer full, resetting...\n"); |
| 201 | mei_reset(); |
| 202 | read_host_csr(&host); |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * This implementation does not handle splitting large messages |
| 207 | * across multiple transactions. Ensure the requested length |
| 208 | * will fit in the available circular buffer depth. |
| 209 | */ |
| 210 | if ((host.buffer_depth - host.buffer_write_ptr) < ndata) { |
| 211 | printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n", |
| 212 | ndata + 2, host.buffer_depth); |
| 213 | return -1; |
| 214 | } |
| 215 | |
| 216 | /* Write MEI header */ |
| 217 | mei_write_dword_ptr(mei, MEI_H_CB_WW); |
| 218 | ndata--; |
| 219 | |
| 220 | /* Write MKHI header */ |
| 221 | mei_write_dword_ptr(mkhi, MEI_H_CB_WW); |
| 222 | ndata--; |
| 223 | |
| 224 | /* Write message data */ |
| 225 | data = req_data; |
| 226 | for (n = 0; n < ndata; ++n) |
| 227 | write_cb(*data++); |
| 228 | |
| 229 | /* Generate interrupt to the ME */ |
| 230 | read_host_csr(&host); |
| 231 | host.interrupt_generate = 1; |
| 232 | write_host_csr(&host); |
| 233 | |
| 234 | /* Make sure ME is ready after sending request data */ |
| 235 | return mei_wait_for_me_ready(); |
| 236 | } |
| 237 | |
| 238 | static int mei_recv_msg(struct mei_header *mei, struct mkhi_header *mkhi, |
| 239 | void *rsp_data, int rsp_bytes) |
| 240 | { |
| 241 | struct mei_header mei_rsp; |
| 242 | struct mkhi_header mkhi_rsp; |
| 243 | struct mei_csr me, host; |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 244 | unsigned int ndata, n; |
| 245 | unsigned int expected; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 246 | u32 *data; |
| 247 | |
| 248 | /* Total number of dwords to read from circular buffer */ |
| 249 | expected = (rsp_bytes + sizeof(mei_rsp) + sizeof(mkhi_rsp)) >> 2; |
| 250 | if (rsp_bytes & 3) |
| 251 | expected++; |
| 252 | |
| 253 | /* |
| 254 | * The interrupt status bit does not appear to indicate that the |
| 255 | * message has actually been received. Instead we wait until the |
| 256 | * expected number of dwords are present in the circular buffer. |
| 257 | */ |
| 258 | for (n = ME_RETRY; n; --n) { |
| 259 | read_me_csr(&me); |
| 260 | if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected) |
| 261 | break; |
| 262 | udelay(ME_DELAY); |
| 263 | } |
| 264 | if (!n) { |
| 265 | printk(BIOS_ERR, "ME: timeout waiting for data: expected " |
| 266 | "%u, available %u\n", expected, |
| 267 | me.buffer_write_ptr - me.buffer_read_ptr); |
| 268 | return -1; |
| 269 | } |
| 270 | |
| 271 | /* Read and verify MEI response header from the ME */ |
| 272 | mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW); |
| 273 | if (!mei_rsp.is_complete) { |
| 274 | printk(BIOS_ERR, "ME: response is not complete\n"); |
| 275 | return -1; |
| 276 | } |
| 277 | |
| 278 | /* Handle non-dword responses and expect at least MKHI header */ |
| 279 | ndata = mei_rsp.length >> 2; |
| 280 | if (mei_rsp.length & 3) |
| 281 | ndata++; |
| 282 | if (ndata != (expected - 1)) { |
| 283 | printk(BIOS_ERR, "ME: response is missing data\n"); |
| 284 | return -1; |
| 285 | } |
| 286 | |
| 287 | /* Read and verify MKHI response header from the ME */ |
| 288 | mei_read_dword_ptr(&mkhi_rsp, MEI_ME_CB_RW); |
| 289 | if (!mkhi_rsp.is_response || |
| 290 | mkhi->group_id != mkhi_rsp.group_id || |
| 291 | mkhi->command != mkhi_rsp.command) { |
| 292 | printk(BIOS_ERR, "ME: invalid response, group %u ?= %u, " |
| 293 | "command %u ?= %u, is_response %u\n", mkhi->group_id, |
| 294 | mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command, |
| 295 | mkhi_rsp.is_response); |
| 296 | return -1; |
| 297 | } |
| 298 | ndata--; /* MKHI header has been read */ |
| 299 | |
| 300 | /* Make sure caller passed a buffer with enough space */ |
| 301 | if (ndata != (rsp_bytes >> 2)) { |
| 302 | printk(BIOS_ERR, "ME: not enough room in response buffer: " |
| 303 | "%u != %u\n", ndata, rsp_bytes >> 2); |
| 304 | return -1; |
| 305 | } |
| 306 | |
| 307 | /* Read response data from the circular buffer */ |
| 308 | data = rsp_data; |
| 309 | for (n = 0; n < ndata; ++n) |
| 310 | *data++ = read_cb(); |
| 311 | |
| 312 | /* Tell the ME that we have consumed the response */ |
| 313 | read_host_csr(&host); |
| 314 | host.interrupt_status = 1; |
| 315 | host.interrupt_generate = 1; |
| 316 | write_host_csr(&host); |
| 317 | |
| 318 | return mei_wait_for_me_ready(); |
| 319 | } |
| 320 | |
| 321 | static inline int mei_sendrecv(struct mei_header *mei, struct mkhi_header *mkhi, |
| 322 | void *req_data, void *rsp_data, int rsp_bytes) |
| 323 | { |
| 324 | if (mei_send_msg(mei, mkhi, req_data) < 0) |
| 325 | return -1; |
| 326 | if (mei_recv_msg(mei, mkhi, rsp_data, rsp_bytes) < 0) |
| 327 | return -1; |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | /* Send END OF POST message to the ME */ |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 332 | static int __unused mkhi_end_of_post(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 333 | { |
| 334 | struct mkhi_header mkhi = { |
| 335 | .group_id = MKHI_GROUP_ID_GEN, |
| 336 | .command = MKHI_END_OF_POST, |
| 337 | }; |
| 338 | struct mei_header mei = { |
| 339 | .is_complete = 1, |
| 340 | .host_address = MEI_HOST_ADDRESS, |
| 341 | .client_address = MEI_ADDRESS_MKHI, |
| 342 | .length = sizeof(mkhi), |
| 343 | }; |
| 344 | |
| 345 | /* Send request and wait for response */ |
| 346 | if (mei_sendrecv(&mei, &mkhi, NULL, NULL, 0) < 0) { |
| 347 | printk(BIOS_ERR, "ME: END OF POST message failed\n"); |
| 348 | return -1; |
| 349 | } |
| 350 | |
| 351 | printk(BIOS_INFO, "ME: END OF POST message successful\n"); |
| 352 | return 0; |
| 353 | } |
| 354 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 355 | /* Get ME firmware version */ |
Kyösti Mälkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 356 | static int __unused mkhi_get_fw_version(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 357 | { |
| 358 | struct me_fw_version version; |
| 359 | struct mkhi_header mkhi = { |
| 360 | .group_id = MKHI_GROUP_ID_GEN, |
| 361 | .command = MKHI_GET_FW_VERSION, |
| 362 | }; |
| 363 | struct mei_header mei = { |
| 364 | .is_complete = 1, |
| 365 | .host_address = MEI_HOST_ADDRESS, |
| 366 | .client_address = MEI_ADDRESS_MKHI, |
| 367 | .length = sizeof(mkhi), |
| 368 | }; |
| 369 | |
| 370 | /* Send request and wait for response */ |
| 371 | if (mei_sendrecv(&mei, &mkhi, NULL, &version, sizeof(version)) < 0) { |
| 372 | printk(BIOS_ERR, "ME: GET FW VERSION message failed\n"); |
| 373 | return -1; |
| 374 | } |
| 375 | |
| 376 | printk(BIOS_INFO, "ME: Firmware Version %u.%u.%u.%u (code) " |
| 377 | "%u.%u.%u.%u (recovery)\n", |
| 378 | version.code_major, version.code_minor, |
| 379 | version.code_build_number, version.code_hot_fix, |
| 380 | version.recovery_major, version.recovery_minor, |
| 381 | version.recovery_build_number, version.recovery_hot_fix); |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static inline void print_cap(const char *name, int state) |
| 387 | { |
| 388 | printk(BIOS_DEBUG, "ME Capability: %-30s : %sabled\n", |
| 389 | name, state ? "en" : "dis"); |
| 390 | } |
| 391 | |
| 392 | /* Get ME Firmware Capabilities */ |
Kyösti Mälkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 393 | static int __unused mkhi_get_fwcaps(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 394 | { |
| 395 | u32 rule_id = 0; |
| 396 | struct me_fwcaps cap; |
| 397 | struct mkhi_header mkhi = { |
| 398 | .group_id = MKHI_GROUP_ID_FWCAPS, |
| 399 | .command = MKHI_FWCAPS_GET_RULE, |
| 400 | }; |
| 401 | struct mei_header mei = { |
| 402 | .is_complete = 1, |
| 403 | .host_address = MEI_HOST_ADDRESS, |
| 404 | .client_address = MEI_ADDRESS_MKHI, |
| 405 | .length = sizeof(mkhi) + sizeof(rule_id), |
| 406 | }; |
| 407 | |
| 408 | /* Send request and wait for response */ |
| 409 | if (mei_sendrecv(&mei, &mkhi, &rule_id, &cap, sizeof(cap)) < 0) { |
| 410 | printk(BIOS_ERR, "ME: GET FWCAPS message failed\n"); |
| 411 | return -1; |
| 412 | } |
| 413 | |
| 414 | print_cap("Full Network manageability", cap.caps_sku.full_net); |
| 415 | print_cap("Regular Network manageability", cap.caps_sku.std_net); |
| 416 | print_cap("Manageability", cap.caps_sku.manageability); |
| 417 | print_cap("Small business technology", cap.caps_sku.small_business); |
| 418 | print_cap("Level III manageability", cap.caps_sku.l3manageability); |
| 419 | print_cap("IntelR Anti-Theft (AT)", cap.caps_sku.intel_at); |
| 420 | print_cap("IntelR Capability Licensing Service (CLS)", |
| 421 | cap.caps_sku.intel_cls); |
| 422 | print_cap("IntelR Power Sharing Technology (MPC)", |
| 423 | cap.caps_sku.intel_mpc); |
| 424 | print_cap("ICC Over Clocking", cap.caps_sku.icc_over_clocking); |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 425 | print_cap("Protected Audio Video Path (PAVP)", cap.caps_sku.pavp); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 426 | print_cap("IPV6", cap.caps_sku.ipv6); |
| 427 | print_cap("KVM Remote Control (KVM)", cap.caps_sku.kvm); |
| 428 | print_cap("Outbreak Containment Heuristic (OCH)", cap.caps_sku.och); |
| 429 | print_cap("Virtual LAN (VLAN)", cap.caps_sku.vlan); |
| 430 | print_cap("TLS", cap.caps_sku.tls); |
| 431 | print_cap("Wireless LAN (WLAN)", cap.caps_sku.wlan); |
| 432 | |
| 433 | return 0; |
| 434 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 435 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 436 | #if CONFIG(CHROMEOS) && 0 /* DISABLED */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 437 | /* Tell ME to issue a global reset */ |
| 438 | int mkhi_global_reset(void) |
| 439 | { |
| 440 | struct me_global_reset reset = { |
| 441 | .request_origin = GLOBAL_RESET_BIOS_POST, |
| 442 | .reset_type = CBM_RR_GLOBAL_RESET, |
| 443 | }; |
| 444 | struct mkhi_header mkhi = { |
| 445 | .group_id = MKHI_GROUP_ID_CBM, |
| 446 | .command = MKHI_GLOBAL_RESET, |
| 447 | }; |
| 448 | struct mei_header mei = { |
| 449 | .is_complete = 1, |
| 450 | .length = sizeof(mkhi) + sizeof(reset), |
| 451 | .host_address = MEI_HOST_ADDRESS, |
| 452 | .client_address = MEI_ADDRESS_MKHI, |
| 453 | }; |
| 454 | |
| 455 | printk(BIOS_NOTICE, "ME: Requesting global reset\n"); |
| 456 | |
| 457 | /* Send request and wait for response */ |
| 458 | if (mei_sendrecv(&mei, &mkhi, &reset, NULL, 0) < 0) { |
| 459 | /* No response means reset will happen shortly... */ |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 460 | halt(); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /* If the ME responded it rejected the reset request */ |
| 464 | printk(BIOS_ERR, "ME: Global Reset failed\n"); |
| 465 | return -1; |
| 466 | } |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 467 | #endif |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 468 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 469 | #ifdef __SIMPLE_DEVICE__ |
| 470 | |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 471 | static void intel_me7_finalize_smm(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 472 | { |
| 473 | struct me_hfs hfs; |
| 474 | u32 reg32; |
| 475 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 476 | mei_base_address = (u32 *) |
| 477 | (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 478 | |
| 479 | /* S3 path will have hidden this device already */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 480 | if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 481 | return; |
| 482 | |
| 483 | /* Make sure ME is in a mode that expects EOP */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 484 | reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 485 | memcpy(&hfs, ®32, sizeof(u32)); |
| 486 | |
| 487 | /* Abort and leave device alone if not normal mode */ |
| 488 | if (hfs.fpt_bad || |
| 489 | hfs.working_state != ME_HFS_CWS_NORMAL || |
| 490 | hfs.operation_mode != ME_HFS_MODE_NORMAL) |
| 491 | return; |
| 492 | |
| 493 | /* Try to send EOP command so ME stops accepting other commands */ |
| 494 | mkhi_end_of_post(); |
| 495 | |
| 496 | /* Make sure IO is disabled */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 497 | reg32 = pci_read_config32(PCH_ME_DEV, PCI_COMMAND); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 498 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 499 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 500 | pci_write_config32(PCH_ME_DEV, PCI_COMMAND, reg32); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 501 | |
| 502 | /* Hide the PCI device */ |
| 503 | RCBA32_OR(FD2, PCH_DISABLE_MEI1); |
| 504 | } |
| 505 | |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 506 | void intel_me_finalize_smm(void) |
| 507 | { |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 508 | u32 did = pci_read_config32(PCH_ME_DEV, PCI_VENDOR_ID); |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 509 | switch (did) { |
Duncan Laurie | 708f731 | 2012-07-10 15:15:41 -0700 | [diff] [blame] | 510 | case 0x1c3a8086: |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 511 | intel_me7_finalize_smm(); |
| 512 | break; |
Duncan Laurie | 708f731 | 2012-07-10 15:15:41 -0700 | [diff] [blame] | 513 | case 0x1e3a8086: |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 514 | intel_me8_finalize_smm(); |
| 515 | break; |
| 516 | default: |
| 517 | printk(BIOS_ERR, "No finalize handler for ME %08x.\n", did); |
| 518 | } |
| 519 | } |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 520 | |
| 521 | #else |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 522 | |
| 523 | /* Determine the path that we should take based on ME status */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 524 | static me_bios_path intel_me_path(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 525 | { |
| 526 | me_bios_path path = ME_DISABLE_BIOS_PATH; |
| 527 | struct me_hfs hfs; |
| 528 | struct me_gmes gmes; |
| 529 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 530 | /* S3 wake skips all MKHI messages */ |
Kyösti Mälkki | c3ed886 | 2014-06-19 19:50:51 +0300 | [diff] [blame] | 531 | if (acpi_is_wakeup_s3()) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 532 | return ME_S3WAKE_BIOS_PATH; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 533 | |
| 534 | pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS); |
| 535 | pci_read_dword_ptr(dev, &gmes, PCI_ME_GMES); |
| 536 | |
| 537 | /* Check and dump status */ |
| 538 | intel_me_status(&hfs, &gmes); |
| 539 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 540 | /* Check Current Working State */ |
| 541 | switch (hfs.working_state) { |
| 542 | case ME_HFS_CWS_NORMAL: |
| 543 | path = ME_NORMAL_BIOS_PATH; |
| 544 | break; |
| 545 | case ME_HFS_CWS_REC: |
| 546 | path = ME_RECOVERY_BIOS_PATH; |
| 547 | break; |
| 548 | default: |
| 549 | path = ME_DISABLE_BIOS_PATH; |
| 550 | break; |
| 551 | } |
| 552 | |
| 553 | /* Check Current Operation Mode */ |
| 554 | switch (hfs.operation_mode) { |
| 555 | case ME_HFS_MODE_NORMAL: |
| 556 | break; |
| 557 | case ME_HFS_MODE_DEBUG: |
| 558 | case ME_HFS_MODE_DIS: |
| 559 | case ME_HFS_MODE_OVER_JMPR: |
| 560 | case ME_HFS_MODE_OVER_MEI: |
| 561 | default: |
| 562 | path = ME_DISABLE_BIOS_PATH; |
| 563 | break; |
| 564 | } |
| 565 | |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 566 | /* Check for any error code and valid firmware */ |
| 567 | if (hfs.error_code || hfs.fpt_bad) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 568 | path = ME_ERROR_BIOS_PATH; |
| 569 | |
Kyösti Mälkki | be5317f | 2019-11-06 12:07:21 +0200 | [diff] [blame] | 570 | if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) { |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 571 | struct elog_event_data_me_extended data = { |
| 572 | .current_working_state = hfs.working_state, |
| 573 | .operation_state = hfs.operation_state, |
| 574 | .operation_mode = hfs.operation_mode, |
| 575 | .error_code = hfs.error_code, |
| 576 | .progress_code = gmes.progress_code, |
| 577 | .current_pmevent = gmes.current_pmevent, |
| 578 | .current_state = gmes.current_state, |
| 579 | }; |
| 580 | elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path); |
| 581 | elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT, |
| 582 | &data, sizeof(data)); |
| 583 | } |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 584 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 585 | return path; |
| 586 | } |
| 587 | |
| 588 | /* Prepare ME for MEI messages */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 589 | static int intel_mei_setup(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 590 | { |
| 591 | struct resource *res; |
| 592 | struct mei_csr host; |
| 593 | u32 reg32; |
| 594 | |
| 595 | /* Find the MMIO base for the ME interface */ |
| 596 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 597 | if (!res || res->base == 0 || res->size == 0) { |
| 598 | printk(BIOS_DEBUG, "ME: MEI resource not present!\n"); |
| 599 | return -1; |
| 600 | } |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 601 | mei_base_address = (u32*)(uintptr_t)res->base; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 602 | |
| 603 | /* Ensure Memory and Bus Master bits are set */ |
| 604 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 605 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 606 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 607 | |
| 608 | /* Clean up status for next message */ |
| 609 | read_host_csr(&host); |
| 610 | host.interrupt_generate = 1; |
| 611 | host.ready = 1; |
| 612 | host.reset = 0; |
| 613 | write_host_csr(&host); |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | /* Read the Extend register hash of ME firmware */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 619 | static int intel_me_extend_valid(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 620 | { |
| 621 | struct me_heres status; |
Stefan Reinauer | 49058c0 | 2012-06-11 14:13:09 -0700 | [diff] [blame] | 622 | u32 extend[8] = {0}; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 623 | int i, count = 0; |
| 624 | |
| 625 | pci_read_dword_ptr(dev, &status, PCI_ME_HERES); |
| 626 | if (!status.extend_feature_present) { |
| 627 | printk(BIOS_ERR, "ME: Extend Feature not present\n"); |
| 628 | return -1; |
| 629 | } |
| 630 | |
| 631 | if (!status.extend_reg_valid) { |
| 632 | printk(BIOS_ERR, "ME: Extend Register not valid\n"); |
| 633 | return -1; |
| 634 | } |
| 635 | |
| 636 | switch (status.extend_reg_algorithm) { |
| 637 | case PCI_ME_EXT_SHA1: |
| 638 | count = 5; |
| 639 | printk(BIOS_DEBUG, "ME: Extend SHA-1: "); |
| 640 | break; |
| 641 | case PCI_ME_EXT_SHA256: |
| 642 | count = 8; |
| 643 | printk(BIOS_DEBUG, "ME: Extend SHA-256: "); |
| 644 | break; |
| 645 | default: |
| 646 | printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n", |
| 647 | status.extend_reg_algorithm); |
| 648 | return -1; |
| 649 | } |
| 650 | |
| 651 | for (i = 0; i < count; ++i) { |
| 652 | extend[i] = pci_read_config32(dev, PCI_ME_HER(i)); |
| 653 | printk(BIOS_DEBUG, "%08x", extend[i]); |
| 654 | } |
| 655 | printk(BIOS_DEBUG, "\n"); |
| 656 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 657 | #if CONFIG(CHROMEOS) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 658 | /* Save hash in NVS for the OS to verify */ |
| 659 | chromeos_set_me_hash(extend, count); |
| 660 | #endif |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | /* Hide the ME virtual PCI devices */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 666 | static void intel_me_hide(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 667 | { |
| 668 | dev->enabled = 0; |
| 669 | pch_enable(dev); |
| 670 | } |
| 671 | |
| 672 | /* Check whether ME is present and do basic init */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 673 | static void intel_me_init(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 674 | { |
| 675 | me_bios_path path = intel_me_path(dev); |
| 676 | |
| 677 | /* Do initial setup and determine the BIOS path */ |
| 678 | printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]); |
| 679 | |
| 680 | switch (path) { |
| 681 | case ME_S3WAKE_BIOS_PATH: |
| 682 | intel_me_hide(dev); |
| 683 | break; |
| 684 | |
| 685 | case ME_NORMAL_BIOS_PATH: |
| 686 | /* Validate the extend register */ |
| 687 | if (intel_me_extend_valid(dev) < 0) |
| 688 | break; /* TODO: force recovery mode */ |
| 689 | |
| 690 | /* Prepare MEI MMIO interface */ |
| 691 | if (intel_mei_setup(dev) < 0) |
| 692 | break; |
| 693 | |
Kyösti Mälkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 694 | if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) { |
| 695 | /* Print ME firmware version */ |
| 696 | mkhi_get_fw_version(); |
| 697 | /* Print ME firmware capabilities */ |
| 698 | mkhi_get_fwcaps(); |
| 699 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 700 | |
| 701 | /* |
| 702 | * Leave the ME unlocked in this path. |
| 703 | * It will be locked via SMI command later. |
| 704 | */ |
| 705 | break; |
| 706 | |
| 707 | case ME_ERROR_BIOS_PATH: |
| 708 | case ME_RECOVERY_BIOS_PATH: |
| 709 | case ME_DISABLE_BIOS_PATH: |
| 710 | case ME_FIRMWARE_UPDATE_BIOS_PATH: |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 711 | break; |
| 712 | } |
| 713 | } |
| 714 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 715 | static struct pci_operations pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 716 | .set_subsystem = pci_dev_set_subsystem, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | static struct device_operations device_ops = { |
| 720 | .read_resources = pci_dev_read_resources, |
| 721 | .set_resources = pci_dev_set_resources, |
| 722 | .enable_resources = pci_dev_enable_resources, |
| 723 | .init = intel_me_init, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 724 | .ops_pci = &pci_ops, |
| 725 | }; |
| 726 | |
| 727 | static const struct pci_driver intel_me __pci_driver = { |
| 728 | .ops = &device_ops, |
| 729 | .vendor = PCI_VENDOR_ID_INTEL, |
| 730 | .device = 0x1c3a, |
| 731 | }; |
| 732 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 733 | #endif /* __SIMPLE_DEVICE__ */ |