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