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