Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [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. |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [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> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 26 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 27 | #include <device/pci_ops.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 28 | #include <console/console.h> |
| 29 | #include <device/pci_ids.h> |
| 30 | #include <device/pci_def.h> |
| 31 | #include <string.h> |
| 32 | #include <delay.h> |
Duncan Laurie | c1c9435 | 2012-07-13 10:11:54 -0700 | [diff] [blame] | 33 | #include <elog.h> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 34 | #include <halt.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 35 | |
Elyes HAOUAS | ead574e | 2018-11-11 20:52:30 +0100 | [diff] [blame] | 36 | #ifndef __SMM__ |
| 37 | #include <device/device.h> |
| 38 | #include <device/pci.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 39 | #endif |
| 40 | |
| 41 | #include "me.h" |
| 42 | #include "pch.h" |
| 43 | |
Martin Roth | 7a1a3ad | 2017-06-24 21:29:38 -0600 | [diff] [blame] | 44 | #if IS_ENABLED(CONFIG_CHROMEOS) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 45 | #include <vendorcode/google/chromeos/chromeos.h> |
Stefan Reinauer | 49058c0 | 2012-06-11 14:13:09 -0700 | [diff] [blame] | 46 | #include <vendorcode/google/chromeos/gnvs.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 47 | #endif |
| 48 | |
| 49 | #ifndef __SMM__ |
| 50 | /* Path that the BIOS should take based on ME state */ |
| 51 | static const char *me_bios_path_values[] = { |
| 52 | [ME_NORMAL_BIOS_PATH] = "Normal", |
| 53 | [ME_S3WAKE_BIOS_PATH] = "S3 Wake", |
| 54 | [ME_ERROR_BIOS_PATH] = "Error", |
| 55 | [ME_RECOVERY_BIOS_PATH] = "Recovery", |
| 56 | [ME_DISABLE_BIOS_PATH] = "Disable", |
| 57 | [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update", |
| 58 | }; |
| 59 | static int intel_me_read_mbp(me_bios_payload *mbp_data); |
| 60 | #endif |
| 61 | |
| 62 | /* MMIO base address for MEI interface */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 63 | static u32 *mei_base_address; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 64 | |
Martin Roth | 7a1a3ad | 2017-06-24 21:29:38 -0600 | [diff] [blame] | 65 | #if IS_ENABLED(CONFIG_DEBUG_INTEL_ME) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 66 | static void mei_dump(void *ptr, int dword, int offset, const char *type) |
| 67 | { |
| 68 | struct mei_csr *csr; |
| 69 | |
| 70 | printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset); |
| 71 | |
| 72 | switch (offset) { |
| 73 | case MEI_H_CSR: |
| 74 | case MEI_ME_CSR_HA: |
| 75 | csr = ptr; |
| 76 | if (!csr) { |
| 77 | printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword); |
| 78 | break; |
| 79 | } |
| 80 | printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u " |
| 81 | "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth, |
| 82 | csr->buffer_read_ptr, csr->buffer_write_ptr, |
| 83 | csr->ready, csr->reset, csr->interrupt_generate, |
| 84 | csr->interrupt_status, csr->interrupt_enable); |
| 85 | break; |
| 86 | case MEI_ME_CB_RW: |
| 87 | case MEI_H_CB_WW: |
| 88 | printk(BIOS_SPEW, "CB: 0x%08x\n", dword); |
| 89 | break; |
| 90 | default: |
| 91 | printk(BIOS_SPEW, "0x%08x\n", offset); |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | #else |
| 96 | # define mei_dump(ptr,dword,offset,type) do {} while (0) |
| 97 | #endif |
| 98 | |
| 99 | /* |
| 100 | * ME/MEI access helpers using memcpy to avoid aliasing. |
| 101 | */ |
| 102 | |
| 103 | static inline void mei_read_dword_ptr(void *ptr, int offset) |
| 104 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 105 | u32 dword = read32(mei_base_address + (offset/sizeof(u32))); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 106 | memcpy(ptr, &dword, sizeof(dword)); |
| 107 | mei_dump(ptr, dword, offset, "READ"); |
| 108 | } |
| 109 | |
| 110 | static inline void mei_write_dword_ptr(void *ptr, int offset) |
| 111 | { |
| 112 | u32 dword = 0; |
| 113 | memcpy(&dword, ptr, sizeof(dword)); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 114 | write32(mei_base_address + (offset/sizeof(u32)), dword); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 115 | mei_dump(ptr, dword, offset, "WRITE"); |
| 116 | } |
| 117 | |
| 118 | #ifndef __SMM__ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 119 | 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] | 120 | { |
| 121 | u32 dword = pci_read_config32(dev, offset); |
| 122 | memcpy(ptr, &dword, sizeof(dword)); |
| 123 | mei_dump(ptr, dword, offset, "PCI READ"); |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | static inline void read_host_csr(struct mei_csr *csr) |
| 128 | { |
| 129 | mei_read_dword_ptr(csr, MEI_H_CSR); |
| 130 | } |
| 131 | |
| 132 | static inline void write_host_csr(struct mei_csr *csr) |
| 133 | { |
| 134 | mei_write_dword_ptr(csr, MEI_H_CSR); |
| 135 | } |
| 136 | |
| 137 | static inline void read_me_csr(struct mei_csr *csr) |
| 138 | { |
| 139 | mei_read_dword_ptr(csr, MEI_ME_CSR_HA); |
| 140 | } |
| 141 | |
| 142 | static inline void write_cb(u32 dword) |
| 143 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 144 | write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 145 | mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE"); |
| 146 | } |
| 147 | |
| 148 | static inline u32 read_cb(void) |
| 149 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 150 | u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32))); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 151 | mei_dump(NULL, dword, MEI_ME_CB_RW, "READ"); |
| 152 | return dword; |
| 153 | } |
| 154 | |
| 155 | /* Wait for ME ready bit to be asserted */ |
| 156 | static int mei_wait_for_me_ready(void) |
| 157 | { |
| 158 | struct mei_csr me; |
| 159 | unsigned try = ME_RETRY; |
| 160 | |
| 161 | while (try--) { |
| 162 | read_me_csr(&me); |
| 163 | if (me.ready) |
| 164 | return 0; |
| 165 | udelay(ME_DELAY); |
| 166 | } |
| 167 | |
| 168 | printk(BIOS_ERR, "ME: failed to become ready\n"); |
| 169 | return -1; |
| 170 | } |
| 171 | |
| 172 | static void mei_reset(void) |
| 173 | { |
| 174 | struct mei_csr host; |
| 175 | |
| 176 | if (mei_wait_for_me_ready() < 0) |
| 177 | return; |
| 178 | |
| 179 | /* Reset host and ME circular buffers for next message */ |
| 180 | read_host_csr(&host); |
| 181 | host.reset = 1; |
| 182 | host.interrupt_generate = 1; |
| 183 | write_host_csr(&host); |
| 184 | |
| 185 | if (mei_wait_for_me_ready() < 0) |
| 186 | return; |
| 187 | |
| 188 | /* Re-init and indicate host is ready */ |
| 189 | read_host_csr(&host); |
| 190 | host.interrupt_generate = 1; |
| 191 | host.ready = 1; |
| 192 | host.reset = 0; |
| 193 | write_host_csr(&host); |
| 194 | } |
| 195 | |
| 196 | static int mei_send_msg(struct mei_header *mei, struct mkhi_header *mkhi, |
| 197 | void *req_data) |
| 198 | { |
| 199 | struct mei_csr host; |
| 200 | unsigned ndata, n; |
| 201 | u32 *data; |
| 202 | |
| 203 | /* Number of dwords to write, ignoring MKHI */ |
| 204 | ndata = mei->length >> 2; |
| 205 | |
| 206 | /* Pad non-dword aligned request message length */ |
| 207 | if (mei->length & 3) |
| 208 | ndata++; |
| 209 | if (!ndata) { |
| 210 | printk(BIOS_DEBUG, "ME: request does not include MKHI\n"); |
| 211 | return -1; |
| 212 | } |
| 213 | ndata++; /* Add MEI header */ |
| 214 | |
| 215 | /* |
| 216 | * Make sure there is still room left in the circular buffer. |
| 217 | * Reset the buffer pointers if the requested message will not fit. |
| 218 | */ |
| 219 | read_host_csr(&host); |
| 220 | if ((host.buffer_depth - host.buffer_write_ptr) < ndata) { |
| 221 | printk(BIOS_ERR, "ME: circular buffer full, resetting...\n"); |
| 222 | mei_reset(); |
| 223 | read_host_csr(&host); |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * This implementation does not handle splitting large messages |
| 228 | * across multiple transactions. Ensure the requested length |
| 229 | * will fit in the available circular buffer depth. |
| 230 | */ |
| 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 | |
| 241 | /* Write MKHI header */ |
| 242 | mei_write_dword_ptr(mkhi, MEI_H_CB_WW); |
| 243 | ndata--; |
| 244 | |
| 245 | /* Write message data */ |
| 246 | data = req_data; |
| 247 | for (n = 0; n < ndata; ++n) |
| 248 | write_cb(*data++); |
| 249 | |
| 250 | /* Generate interrupt to the ME */ |
| 251 | read_host_csr(&host); |
| 252 | host.interrupt_generate = 1; |
| 253 | write_host_csr(&host); |
| 254 | |
| 255 | /* Make sure ME is ready after sending request data */ |
| 256 | return mei_wait_for_me_ready(); |
| 257 | } |
| 258 | |
| 259 | static int mei_recv_msg(struct mkhi_header *mkhi, |
| 260 | void *rsp_data, int rsp_bytes) |
| 261 | { |
| 262 | struct mei_header mei_rsp; |
| 263 | struct mkhi_header mkhi_rsp; |
| 264 | struct mei_csr me, host; |
| 265 | unsigned ndata, n/*, me_data_len*/; |
| 266 | unsigned expected; |
| 267 | u32 *data; |
| 268 | |
| 269 | /* Total number of dwords to read from circular buffer */ |
| 270 | expected = (rsp_bytes + sizeof(mei_rsp) + sizeof(mkhi_rsp)) >> 2; |
| 271 | if (rsp_bytes & 3) |
| 272 | expected++; |
| 273 | |
| 274 | /* |
| 275 | * The interrupt status bit does not appear to indicate that the |
| 276 | * message has actually been received. Instead we wait until the |
| 277 | * expected number of dwords are present in the circular buffer. |
| 278 | */ |
| 279 | for (n = ME_RETRY; n; --n) { |
| 280 | read_me_csr(&me); |
| 281 | if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected) |
| 282 | break; |
| 283 | udelay(ME_DELAY); |
| 284 | } |
| 285 | if (!n) { |
| 286 | printk(BIOS_ERR, "ME: timeout waiting for data: expected " |
| 287 | "%u, available %u\n", expected, |
| 288 | me.buffer_write_ptr - me.buffer_read_ptr); |
| 289 | return -1; |
| 290 | } |
| 291 | |
| 292 | /* Read and verify MEI response header from the ME */ |
| 293 | mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW); |
| 294 | if (!mei_rsp.is_complete) { |
| 295 | printk(BIOS_ERR, "ME: response is not complete\n"); |
| 296 | return -1; |
| 297 | } |
| 298 | |
| 299 | /* Handle non-dword responses and expect at least MKHI header */ |
| 300 | ndata = mei_rsp.length >> 2; |
| 301 | if (mei_rsp.length & 3) |
| 302 | ndata++; |
| 303 | if (ndata != (expected - 1)) { |
| 304 | printk(BIOS_ERR, "ME: response is missing data %d != %d\n", |
| 305 | ndata, (expected - 1)); |
| 306 | return -1; |
| 307 | } |
| 308 | |
| 309 | /* Read and verify MKHI response header from the ME */ |
| 310 | mei_read_dword_ptr(&mkhi_rsp, MEI_ME_CB_RW); |
| 311 | if (!mkhi_rsp.is_response || |
| 312 | mkhi->group_id != mkhi_rsp.group_id || |
| 313 | mkhi->command != mkhi_rsp.command) { |
| 314 | printk(BIOS_ERR, "ME: invalid response, group %u ?= %u," |
| 315 | "command %u ?= %u, is_response %u\n", mkhi->group_id, |
| 316 | mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command, |
| 317 | mkhi_rsp.is_response); |
| 318 | return -1; |
| 319 | } |
| 320 | ndata--; /* MKHI header has been read */ |
| 321 | |
| 322 | /* Make sure caller passed a buffer with enough space */ |
| 323 | if (ndata != (rsp_bytes >> 2)) { |
| 324 | printk(BIOS_ERR, "ME: not enough room in response buffer: " |
| 325 | "%u != %u\n", ndata, rsp_bytes >> 2); |
| 326 | return -1; |
| 327 | } |
| 328 | |
| 329 | /* Read response data from the circular buffer */ |
| 330 | data = rsp_data; |
| 331 | for (n = 0; n < ndata; ++n) |
| 332 | *data++ = read_cb(); |
| 333 | |
| 334 | /* Tell the ME that we have consumed the response */ |
| 335 | read_host_csr(&host); |
| 336 | host.interrupt_status = 1; |
| 337 | host.interrupt_generate = 1; |
| 338 | write_host_csr(&host); |
| 339 | |
| 340 | return mei_wait_for_me_ready(); |
| 341 | } |
| 342 | |
| 343 | static inline int mei_sendrecv(struct mei_header *mei, struct mkhi_header *mkhi, |
| 344 | void *req_data, void *rsp_data, int rsp_bytes) |
| 345 | { |
| 346 | if (mei_send_msg(mei, mkhi, req_data) < 0) |
| 347 | return -1; |
| 348 | if (mei_recv_msg(mkhi, rsp_data, rsp_bytes) < 0) |
| 349 | return -1; |
| 350 | return 0; |
| 351 | } |
| 352 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 353 | #if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) && !defined(__SMM__) |
| 354 | static inline void print_cap(const char *name, int state) |
| 355 | { |
| 356 | printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n", |
| 357 | name, state ? " en" : "dis"); |
| 358 | } |
| 359 | |
| 360 | static void me_print_fw_version(mbp_fw_version_name *vers_name) |
| 361 | { |
| 362 | if (!vers_name->major_version) { |
| 363 | printk(BIOS_ERR, "ME: mbp missing version report\n"); |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n", |
| 368 | vers_name->major_version, vers_name->minor_version, |
| 369 | vers_name->hotfix_version, vers_name->build_version); |
| 370 | } |
| 371 | |
| 372 | /* Get ME Firmware Capabilities */ |
| 373 | static int mkhi_get_fwcaps(mefwcaps_sku *cap) |
| 374 | { |
| 375 | u32 rule_id = 0; |
| 376 | struct me_fwcaps cap_msg; |
| 377 | struct mkhi_header mkhi = { |
| 378 | .group_id = MKHI_GROUP_ID_FWCAPS, |
| 379 | .command = MKHI_FWCAPS_GET_RULE, |
| 380 | }; |
| 381 | struct mei_header mei = { |
| 382 | .is_complete = 1, |
| 383 | .host_address = MEI_HOST_ADDRESS, |
| 384 | .client_address = MEI_ADDRESS_MKHI, |
| 385 | .length = sizeof(mkhi) + sizeof(rule_id), |
| 386 | }; |
| 387 | |
| 388 | /* Send request and wait for response */ |
Edward O'Callaghan | 152e517 | 2014-07-13 00:28:05 +1000 | [diff] [blame] | 389 | if (mei_sendrecv(&mei, &mkhi, &rule_id, &cap_msg, sizeof(cap_msg)) < 0) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 390 | printk(BIOS_ERR, "ME: GET FWCAPS message failed\n"); |
| 391 | return -1; |
Edward O'Callaghan | 152e517 | 2014-07-13 00:28:05 +1000 | [diff] [blame] | 392 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 393 | *cap = cap_msg.caps_sku; |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | /* Get ME Firmware Capabilities */ |
| 398 | static void me_print_fwcaps(mbp_fw_caps *caps_section) |
| 399 | { |
| 400 | mefwcaps_sku *cap = &caps_section->fw_capabilities; |
| 401 | if (!caps_section->available) { |
| 402 | printk(BIOS_ERR, "ME: mbp missing fwcaps report\n"); |
| 403 | if (mkhi_get_fwcaps(cap)) |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | print_cap("Full Network manageability", cap->full_net); |
| 408 | print_cap("Regular Network manageability", cap->std_net); |
| 409 | print_cap("Manageability", cap->manageability); |
| 410 | print_cap("Small business technology", cap->small_business); |
| 411 | print_cap("Level III manageability", cap->l3manageability); |
| 412 | print_cap("IntelR Anti-Theft (AT)", cap->intel_at); |
| 413 | print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls); |
| 414 | print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc); |
| 415 | print_cap("ICC Over Clocking", cap->icc_over_clocking); |
Edward O'Callaghan | 152e517 | 2014-07-13 00:28:05 +1000 | [diff] [blame] | 416 | print_cap("Protected Audio Video Path (PAVP)", cap->pavp); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 417 | print_cap("IPV6", cap->ipv6); |
| 418 | print_cap("KVM Remote Control (KVM)", cap->kvm); |
| 419 | print_cap("Outbreak Containment Heuristic (OCH)", cap->och); |
| 420 | print_cap("Virtual LAN (VLAN)", cap->vlan); |
| 421 | print_cap("TLS", cap->tls); |
| 422 | print_cap("Wireless LAN (WLAN)", cap->wlan); |
| 423 | } |
| 424 | #endif |
| 425 | |
Martin Roth | 7a1a3ad | 2017-06-24 21:29:38 -0600 | [diff] [blame] | 426 | #if IS_ENABLED(CONFIG_CHROMEOS) && 0 /* DISABLED */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 427 | /* Tell ME to issue a global reset */ |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 428 | static int mkhi_global_reset(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 429 | { |
| 430 | struct me_global_reset reset = { |
| 431 | .request_origin = GLOBAL_RESET_BIOS_POST, |
| 432 | .reset_type = CBM_RR_GLOBAL_RESET, |
| 433 | }; |
| 434 | struct mkhi_header mkhi = { |
| 435 | .group_id = MKHI_GROUP_ID_CBM, |
| 436 | .command = MKHI_GLOBAL_RESET, |
| 437 | }; |
| 438 | struct mei_header mei = { |
| 439 | .is_complete = 1, |
| 440 | .length = sizeof(mkhi) + sizeof(reset), |
| 441 | .host_address = MEI_HOST_ADDRESS, |
| 442 | .client_address = MEI_ADDRESS_MKHI, |
| 443 | }; |
| 444 | |
| 445 | /* Send request and wait for response */ |
| 446 | printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__); |
| 447 | if (mei_sendrecv(&mei, &mkhi, &reset, NULL, 0) < 0) { |
| 448 | /* No response means reset will happen shortly... */ |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 449 | halt(); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | /* If the ME responded it rejected the reset request */ |
| 453 | printk(BIOS_ERR, "ME: Global Reset failed\n"); |
| 454 | return -1; |
| 455 | } |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 456 | #endif |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 457 | |
| 458 | #ifdef __SMM__ |
| 459 | |
Duncan Laurie | 708f731 | 2012-07-10 15:15:41 -0700 | [diff] [blame] | 460 | /* Send END OF POST message to the ME */ |
| 461 | static int mkhi_end_of_post(void) |
| 462 | { |
| 463 | struct mkhi_header mkhi = { |
| 464 | .group_id = MKHI_GROUP_ID_GEN, |
| 465 | .command = MKHI_END_OF_POST, |
| 466 | }; |
| 467 | struct mei_header mei = { |
| 468 | .is_complete = 1, |
| 469 | .host_address = MEI_HOST_ADDRESS, |
| 470 | .client_address = MEI_ADDRESS_MKHI, |
| 471 | .length = sizeof(mkhi), |
| 472 | }; |
| 473 | |
| 474 | u32 eop_ack; |
| 475 | |
| 476 | /* Send request and wait for response */ |
| 477 | printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__); |
| 478 | if (mei_sendrecv(&mei, &mkhi, NULL, &eop_ack, sizeof(eop_ack)) < 0) { |
| 479 | printk(BIOS_ERR, "ME: END OF POST message failed\n"); |
| 480 | return -1; |
| 481 | } |
| 482 | |
| 483 | printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack); |
| 484 | return 0; |
| 485 | } |
| 486 | |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 487 | void intel_me8_finalize_smm(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 488 | { |
| 489 | struct me_hfs hfs; |
| 490 | u32 reg32; |
| 491 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 492 | mei_base_address = (void *) |
| 493 | (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 494 | |
| 495 | /* S3 path will have hidden this device already */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 496 | if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 497 | return; |
| 498 | |
| 499 | /* Make sure ME is in a mode that expects EOP */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 500 | reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 501 | memcpy(&hfs, ®32, sizeof(u32)); |
| 502 | |
| 503 | /* Abort and leave device alone if not normal mode */ |
| 504 | if (hfs.fpt_bad || |
| 505 | hfs.working_state != ME_HFS_CWS_NORMAL || |
| 506 | hfs.operation_mode != ME_HFS_MODE_NORMAL) |
| 507 | return; |
| 508 | |
| 509 | /* Try to send EOP command so ME stops accepting other commands */ |
| 510 | mkhi_end_of_post(); |
| 511 | |
| 512 | /* Make sure IO is disabled */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 513 | reg32 = pci_read_config32(PCH_ME_DEV, PCI_COMMAND); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 514 | reg32 &= ~(PCI_COMMAND_MASTER | |
| 515 | PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 516 | pci_write_config32(PCH_ME_DEV, PCI_COMMAND, reg32); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 517 | |
| 518 | /* Hide the PCI device */ |
| 519 | RCBA32_OR(FD2, PCH_DISABLE_MEI1); |
| 520 | } |
| 521 | |
| 522 | #else /* !__SMM__ */ |
| 523 | |
| 524 | /* Determine the path that we should take based on ME status */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 525 | static me_bios_path intel_me_path(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 526 | { |
| 527 | me_bios_path path = ME_DISABLE_BIOS_PATH; |
| 528 | struct me_hfs hfs; |
| 529 | struct me_gmes gmes; |
| 530 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 531 | /* S3 wake skips all MKHI messages */ |
Kyösti Mälkki | c3ed886 | 2014-06-19 19:50:51 +0300 | [diff] [blame] | 532 | if (acpi_is_wakeup_s3()) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 533 | return ME_S3WAKE_BIOS_PATH; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 534 | |
| 535 | pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS); |
| 536 | pci_read_dword_ptr(dev, &gmes, PCI_ME_GMES); |
| 537 | |
| 538 | /* Check and dump status */ |
| 539 | intel_me_status(&hfs, &gmes); |
| 540 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 541 | /* Check Current Working State */ |
| 542 | switch (hfs.working_state) { |
| 543 | case ME_HFS_CWS_NORMAL: |
| 544 | path = ME_NORMAL_BIOS_PATH; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 545 | break; |
| 546 | case ME_HFS_CWS_REC: |
| 547 | path = ME_RECOVERY_BIOS_PATH; |
| 548 | break; |
| 549 | default: |
| 550 | path = ME_DISABLE_BIOS_PATH; |
| 551 | break; |
| 552 | } |
| 553 | |
| 554 | /* Check Current Operation Mode */ |
| 555 | switch (hfs.operation_mode) { |
| 556 | case ME_HFS_MODE_NORMAL: |
| 557 | break; |
| 558 | case ME_HFS_MODE_DEBUG: |
| 559 | case ME_HFS_MODE_DIS: |
| 560 | case ME_HFS_MODE_OVER_JMPR: |
| 561 | case ME_HFS_MODE_OVER_MEI: |
| 562 | default: |
| 563 | path = ME_DISABLE_BIOS_PATH; |
| 564 | break; |
| 565 | } |
| 566 | |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 567 | /* Check for any error code and valid firmware and MBP */ |
| 568 | if (hfs.error_code || hfs.fpt_bad) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 569 | path = ME_ERROR_BIOS_PATH; |
| 570 | |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 571 | /* Check if the MBP is ready */ |
| 572 | if (!gmes.mbp_rdy) { |
| 573 | printk(BIOS_CRIT, "%s: mbp is not ready!\n", |
| 574 | __FUNCTION__); |
| 575 | path = ME_ERROR_BIOS_PATH; |
| 576 | } |
| 577 | |
Martin Roth | 7a1a3ad | 2017-06-24 21:29:38 -0600 | [diff] [blame] | 578 | #if IS_ENABLED(CONFIG_ELOG) |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 579 | if (path != ME_NORMAL_BIOS_PATH) { |
| 580 | struct elog_event_data_me_extended data = { |
| 581 | .current_working_state = hfs.working_state, |
| 582 | .operation_state = hfs.operation_state, |
| 583 | .operation_mode = hfs.operation_mode, |
| 584 | .error_code = hfs.error_code, |
| 585 | .progress_code = gmes.progress_code, |
| 586 | .current_pmevent = gmes.current_pmevent, |
| 587 | .current_state = gmes.current_state, |
| 588 | }; |
| 589 | elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path); |
| 590 | elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT, |
| 591 | &data, sizeof(data)); |
| 592 | } |
| 593 | #endif |
| 594 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 595 | return path; |
| 596 | } |
| 597 | |
| 598 | /* Prepare ME for MEI messages */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 599 | static int intel_mei_setup(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 600 | { |
| 601 | struct resource *res; |
| 602 | struct mei_csr host; |
| 603 | u32 reg32; |
| 604 | |
| 605 | /* Find the MMIO base for the ME interface */ |
| 606 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 607 | if (!res || res->base == 0 || res->size == 0) { |
| 608 | printk(BIOS_DEBUG, "ME: MEI resource not present!\n"); |
| 609 | return -1; |
| 610 | } |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 611 | mei_base_address = (u32 *)(uintptr_t)res->base; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 612 | |
| 613 | /* Ensure Memory and Bus Master bits are set */ |
| 614 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 615 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 616 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 617 | |
| 618 | /* Clean up status for next message */ |
| 619 | read_host_csr(&host); |
| 620 | host.interrupt_generate = 1; |
| 621 | host.ready = 1; |
| 622 | host.reset = 0; |
| 623 | write_host_csr(&host); |
| 624 | |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | /* Read the Extend register hash of ME firmware */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 629 | static int intel_me_extend_valid(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 630 | { |
| 631 | struct me_heres status; |
Stefan Reinauer | 49058c0 | 2012-06-11 14:13:09 -0700 | [diff] [blame] | 632 | u32 extend[8] = {0}; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 633 | int i, count = 0; |
| 634 | |
| 635 | pci_read_dword_ptr(dev, &status, PCI_ME_HERES); |
| 636 | if (!status.extend_feature_present) { |
| 637 | printk(BIOS_ERR, "ME: Extend Feature not present\n"); |
| 638 | return -1; |
| 639 | } |
| 640 | |
| 641 | if (!status.extend_reg_valid) { |
| 642 | printk(BIOS_ERR, "ME: Extend Register not valid\n"); |
| 643 | return -1; |
| 644 | } |
| 645 | |
| 646 | switch (status.extend_reg_algorithm) { |
| 647 | case PCI_ME_EXT_SHA1: |
| 648 | count = 5; |
| 649 | printk(BIOS_DEBUG, "ME: Extend SHA-1: "); |
| 650 | break; |
| 651 | case PCI_ME_EXT_SHA256: |
| 652 | count = 8; |
| 653 | printk(BIOS_DEBUG, "ME: Extend SHA-256: "); |
| 654 | break; |
| 655 | default: |
| 656 | printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n", |
| 657 | status.extend_reg_algorithm); |
| 658 | return -1; |
| 659 | } |
| 660 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 661 | for (i = 0; i < count; ++i) { |
Stefan Reinauer | 49058c0 | 2012-06-11 14:13:09 -0700 | [diff] [blame] | 662 | extend[i] = pci_read_config32(dev, PCI_ME_HER(i)); |
| 663 | printk(BIOS_DEBUG, "%08x", extend[i]); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 664 | } |
| 665 | printk(BIOS_DEBUG, "\n"); |
| 666 | |
Martin Roth | 7a1a3ad | 2017-06-24 21:29:38 -0600 | [diff] [blame] | 667 | #if IS_ENABLED(CONFIG_CHROMEOS) |
Stefan Reinauer | 49058c0 | 2012-06-11 14:13:09 -0700 | [diff] [blame] | 668 | /* Save hash in NVS for the OS to verify */ |
| 669 | chromeos_set_me_hash(extend, count); |
| 670 | #endif |
| 671 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | /* Hide the ME virtual PCI devices */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 676 | static void intel_me_hide(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 677 | { |
| 678 | dev->enabled = 0; |
| 679 | pch_enable(dev); |
| 680 | } |
| 681 | |
| 682 | /* Check whether ME is present and do basic init */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 683 | static void intel_me_init(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 684 | { |
| 685 | me_bios_path path = intel_me_path(dev); |
| 686 | me_bios_payload mbp_data; |
| 687 | |
| 688 | /* Do initial setup and determine the BIOS path */ |
| 689 | printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]); |
| 690 | |
| 691 | switch (path) { |
| 692 | case ME_S3WAKE_BIOS_PATH: |
| 693 | intel_me_hide(dev); |
| 694 | break; |
| 695 | |
| 696 | case ME_NORMAL_BIOS_PATH: |
| 697 | /* Validate the extend register */ |
| 698 | if (intel_me_extend_valid(dev) < 0) |
| 699 | break; /* TODO: force recovery mode */ |
| 700 | |
| 701 | /* Prepare MEI MMIO interface */ |
| 702 | if (intel_mei_setup(dev) < 0) |
| 703 | break; |
| 704 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 705 | if (intel_me_read_mbp(&mbp_data)) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 706 | break; |
| 707 | |
Martin Roth | 7a1a3ad | 2017-06-24 21:29:38 -0600 | [diff] [blame] | 708 | #if IS_ENABLED(CONFIG_CHROMEOS) && 0 /* DISABLED */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 709 | /* |
| 710 | * Unlock ME in recovery mode. |
| 711 | */ |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 712 | if (vboot_recovery_mode_enabled()) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 713 | /* Unlock ME flash region */ |
| 714 | mkhi_hmrfpo_enable(); |
| 715 | |
| 716 | /* Issue global reset */ |
| 717 | mkhi_global_reset(); |
| 718 | return; |
| 719 | } |
| 720 | #endif |
| 721 | |
| 722 | #if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) |
| 723 | me_print_fw_version(&mbp_data.fw_version_name); |
| 724 | me_print_fwcaps(&mbp_data.fw_caps_sku); |
| 725 | #endif |
Duncan Laurie | 708f731 | 2012-07-10 15:15:41 -0700 | [diff] [blame] | 726 | |
| 727 | /* |
| 728 | * Leave the ME unlocked in this path. |
| 729 | * It will be locked via SMI command later. |
| 730 | */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 731 | break; |
| 732 | |
| 733 | case ME_ERROR_BIOS_PATH: |
| 734 | case ME_RECOVERY_BIOS_PATH: |
| 735 | case ME_DISABLE_BIOS_PATH: |
| 736 | case ME_FIRMWARE_UPDATE_BIOS_PATH: |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 737 | break; |
| 738 | } |
| 739 | } |
| 740 | |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 741 | static void set_subsystem(struct device *dev, unsigned vendor, unsigned device) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 742 | { |
| 743 | if (!vendor || !device) { |
| 744 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 745 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 746 | } else { |
| 747 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 748 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | static struct pci_operations pci_ops = { |
| 753 | .set_subsystem = set_subsystem, |
| 754 | }; |
| 755 | |
| 756 | static struct device_operations device_ops = { |
| 757 | .read_resources = pci_dev_read_resources, |
| 758 | .set_resources = pci_dev_set_resources, |
| 759 | .enable_resources = pci_dev_enable_resources, |
| 760 | .init = intel_me_init, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 761 | .ops_pci = &pci_ops, |
| 762 | }; |
| 763 | |
| 764 | static const struct pci_driver intel_me __pci_driver = { |
| 765 | .ops = &device_ops, |
| 766 | .vendor = PCI_VENDOR_ID_INTEL, |
| 767 | .device = 0x1e3a, |
| 768 | }; |
| 769 | |
| 770 | /****************************************************************************** |
| 771 | * */ |
| 772 | static u32 me_to_host_words_pending(void) |
| 773 | { |
| 774 | struct mei_csr me; |
| 775 | read_me_csr(&me); |
| 776 | if (!me.ready) |
| 777 | return 0; |
| 778 | return (me.buffer_write_ptr - me.buffer_read_ptr) & |
| 779 | (me.buffer_depth - 1); |
| 780 | } |
| 781 | |
| 782 | #if 0 |
| 783 | /* This function is not yet being used, keep it in for the future. */ |
| 784 | static u32 host_to_me_words_room(void) |
| 785 | { |
| 786 | struct mei_csr csr; |
| 787 | |
| 788 | read_me_csr(&csr); |
| 789 | if (!csr.ready) |
| 790 | return 0; |
| 791 | |
| 792 | read_host_csr(&csr); |
| 793 | return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) & |
| 794 | (csr.buffer_depth - 1); |
| 795 | } |
| 796 | #endif |
| 797 | /* |
| 798 | * mbp seems to be following its own flow, let's retrieve it in a dedicated |
| 799 | * function. |
| 800 | */ |
| 801 | static int intel_me_read_mbp(me_bios_payload *mbp_data) |
| 802 | { |
| 803 | mbp_header mbp_hdr; |
| 804 | mbp_item_header mbp_item_hdr; |
| 805 | u32 me2host_pending; |
| 806 | u32 mbp_item_id; |
| 807 | struct mei_csr host; |
| 808 | |
| 809 | me2host_pending = me_to_host_words_pending(); |
| 810 | if (!me2host_pending) { |
| 811 | printk(BIOS_ERR, "ME: no mbp data!\n"); |
| 812 | return -1; |
| 813 | } |
| 814 | |
| 815 | /* we know for sure that at least the header is there */ |
| 816 | mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW); |
| 817 | |
| 818 | if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) || |
| 819 | (me2host_pending < mbp_hdr.mbp_size)) { |
| 820 | printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words" |
| 821 | " buffer contains %d words\n", |
| 822 | mbp_hdr.num_entries, mbp_hdr.mbp_size, |
| 823 | me2host_pending); |
| 824 | return -1; |
| 825 | } |
| 826 | |
| 827 | me2host_pending--; |
| 828 | memset(mbp_data, 0, sizeof(*mbp_data)); |
| 829 | |
| 830 | while (mbp_hdr.num_entries--) { |
Elyes HAOUAS | 448d9fb | 2018-05-22 12:51:27 +0200 | [diff] [blame] | 831 | u32 *copy_addr; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 832 | u32 copy_size, buffer_room; |
| 833 | void *p; |
| 834 | |
| 835 | if (!me2host_pending) { |
| 836 | printk(BIOS_ERR, "ME: no mbp data %d entries to go!\n", |
| 837 | mbp_hdr.num_entries + 1); |
| 838 | return -1; |
| 839 | } |
| 840 | |
| 841 | mei_read_dword_ptr(&mbp_item_hdr, MEI_ME_CB_RW); |
| 842 | |
| 843 | if (mbp_item_hdr.length > me2host_pending) { |
| 844 | printk(BIOS_ERR, "ME: insufficient mbp data %d " |
| 845 | "entries to go!\n", |
| 846 | mbp_hdr.num_entries + 1); |
| 847 | return -1; |
| 848 | } |
| 849 | |
| 850 | me2host_pending -= mbp_item_hdr.length; |
| 851 | |
| 852 | mbp_item_id = (((u32)mbp_item_hdr.item_id) << 8) + |
| 853 | mbp_item_hdr.app_id; |
| 854 | |
| 855 | copy_size = mbp_item_hdr.length - 1; |
| 856 | |
| 857 | #define SET_UP_COPY(field) { copy_addr = (u32 *)&mbp_data->field; \ |
| 858 | buffer_room = sizeof(mbp_data->field) / sizeof(u32); \ |
| 859 | break; \ |
| 860 | } |
| 861 | |
| 862 | p = &mbp_item_hdr; |
| 863 | printk(BIOS_INFO, "ME: MBP item header %8.8x\n", *((u32*)p)); |
| 864 | |
Elyes HAOUAS | f9de5a4 | 2018-05-03 17:21:02 +0200 | [diff] [blame] | 865 | switch (mbp_item_id) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 866 | case 0x101: |
| 867 | SET_UP_COPY(fw_version_name); |
| 868 | |
| 869 | case 0x102: |
| 870 | SET_UP_COPY(icc_profile); |
| 871 | |
| 872 | case 0x103: |
| 873 | SET_UP_COPY(at_state); |
| 874 | |
| 875 | case 0x201: |
| 876 | mbp_data->fw_caps_sku.available = 1; |
| 877 | SET_UP_COPY(fw_caps_sku.fw_capabilities); |
| 878 | |
| 879 | case 0x301: |
| 880 | SET_UP_COPY(rom_bist_data); |
| 881 | |
| 882 | case 0x401: |
| 883 | SET_UP_COPY(platform_key); |
| 884 | |
| 885 | case 0x501: |
| 886 | mbp_data->fw_plat_type.available = 1; |
| 887 | SET_UP_COPY(fw_plat_type.rule_data); |
| 888 | |
| 889 | case 0x601: |
| 890 | SET_UP_COPY(mfsintegrity); |
| 891 | |
| 892 | default: |
Vladimir Serbinenko | afc8d98 | 2014-06-11 18:52:55 +0000 | [diff] [blame] | 893 | printk(BIOS_ERR, "ME: unknown mbp item id 0x%x! Skipping\n", |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 894 | mbp_item_id); |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 895 | while (copy_size--) |
Vladimir Serbinenko | afc8d98 | 2014-06-11 18:52:55 +0000 | [diff] [blame] | 896 | read_cb(); |
| 897 | continue; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | if (buffer_room != copy_size) { |
| 901 | printk(BIOS_ERR, "ME: buffer room %d != %d copy size" |
| 902 | " for item 0x%x!!!\n", |
| 903 | buffer_room, copy_size, mbp_item_id); |
| 904 | return -1; |
| 905 | } |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 906 | while (copy_size--) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 907 | *copy_addr++ = read_cb(); |
| 908 | } |
| 909 | |
| 910 | read_host_csr(&host); |
| 911 | host.interrupt_generate = 1; |
| 912 | write_host_csr(&host); |
| 913 | |
| 914 | { |
| 915 | int cntr = 0; |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 916 | while (host.interrupt_generate) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 917 | read_host_csr(&host); |
| 918 | cntr++; |
| 919 | } |
| 920 | printk(BIOS_SPEW, "ME: mbp read OK after %d cycles\n", cntr); |
| 921 | } |
| 922 | |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | #endif /* !__SMM__ */ |