coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
me.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
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 
11 #include <acpi/acpi.h>
12 #include <device/mmio.h>
13 #include <device/pci_ops.h>
14 #include <console/console.h>
15 #include <device/device.h>
16 #include <device/pci.h>
17 #include <device/pci_ids.h>
18 #include <device/pci_def.h>
19 #include <string.h>
20 #include <delay.h>
21 #include <elog.h>
22 #include <stdlib.h>
23 
24 #include "chip.h"
25 #include "me.h"
26 #include "pch.h"
27 
28 #include <vendorcode/google/chromeos/chromeos.h>
29 
30 /* Path that the BIOS should take based on ME state */
31 static const char *const me_bios_path_values[] = {
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 };
39 
40 /* MMIO base address for MEI interface */
42 
43 static void mei_dump(u32 dword, int offset, const char *type)
44 {
45  union mei_csr csr;
46 
47  if (!CONFIG(DEBUG_INTEL_ME))
48  return;
49 
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.raw = dword;
56  printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
57  "reset=%u ig=%u is=%u ie=%u\n", csr.buffer_depth,
59  csr.ready, csr.reset, csr.interrupt_generate,
61  break;
62  case MEI_ME_CB_RW:
63  case MEI_H_CB_WW:
64  printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
65  break;
66  default:
67  printk(BIOS_SPEW, "0x%08x\n", offset);
68  break;
69  }
70 }
71 
72 /*
73  * ME/MEI access helpers using memcpy to avoid aliasing.
74  */
75 
76 static inline union mei_csr read_host_csr(void)
77 {
78  union mei_csr csr = { .raw = read32(mei_base_address + MEI_H_CSR) };
79  mei_dump(csr.raw, MEI_H_CSR, "READ");
80  return csr;
81 }
82 
83 static inline void write_host_csr(union mei_csr csr)
84 {
86  mei_dump(csr.raw, MEI_H_CSR, "WRITE");
87 }
88 
89 static inline union mei_csr read_me_csr(void)
90 {
91  union mei_csr csr = { .raw = read32(mei_base_address + MEI_ME_CSR_HA) };
92  mei_dump(csr.raw, MEI_ME_CSR_HA, "READ");
93  return csr;
94 }
95 
96 static inline void write_cb(u32 dword)
97 {
99  mei_dump(dword, MEI_H_CB_WW, "WRITE");
100 }
101 
102 static inline u32 read_cb(void)
103 {
105  mei_dump(dword, MEI_ME_CB_RW, "READ");
106  return dword;
107 }
108 
109 /* Wait for ME ready bit to be asserted */
110 static int mei_wait_for_me_ready(void)
111 {
112  union mei_csr me;
113  unsigned int try = ME_RETRY;
114 
115  while (try--) {
116  me = read_me_csr();
117  if (me.ready)
118  return 0;
119  udelay(ME_DELAY);
120  }
121 
122  printk(BIOS_ERR, "ME: failed to become ready\n");
123  return -1;
124 }
125 
126 static void mei_reset(void)
127 {
128  union mei_csr host;
129 
130  if (mei_wait_for_me_ready() < 0)
131  return;
132 
133  /* Reset host and ME circular buffers for next message */
134  host = read_host_csr();
135  host.reset = 1;
136  host.interrupt_generate = 1;
137  write_host_csr(host);
138 
139  if (mei_wait_for_me_ready() < 0)
140  return;
141 
142  /* Re-init and indicate host is ready */
143  host = read_host_csr();
144  host.interrupt_generate = 1;
145  host.ready = 1;
146  host.reset = 0;
147  write_host_csr(host);
148 }
149 
150 static int mei_send_packet(union mei_header *mei, void *req_data)
151 {
152  union mei_csr host;
153  unsigned int ndata, n;
154  u32 *data;
155 
156  /* Number of dwords to write */
157  ndata = mei->length >> 2;
158 
159  /* Pad non-dword aligned request message length */
160  if (mei->length & 3)
161  ndata++;
162  if (!ndata) {
163  printk(BIOS_DEBUG, "ME: request has no data\n");
164  return -1;
165  }
166  ndata++; /* Add MEI header */
167 
168  /*
169  * Make sure there is still room left in the circular buffer.
170  * Reset the buffer pointers if the requested message will not fit.
171  */
172  host = read_host_csr();
173  if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
174  printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
175  mei_reset();
176  host = read_host_csr();
177  }
178 
179  /* Ensure the requested length will fit in the circular buffer. */
180  if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
181  printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
182  ndata + 2, host.buffer_depth);
183  return -1;
184  }
185 
186  /* Write MEI header */
187  write_cb(mei->raw);
188  ndata--;
189 
190  /* Write message data */
191  data = req_data;
192  for (n = 0; n < ndata; ++n)
193  write_cb(*data++);
194 
195  /* Generate interrupt to the ME */
196  host = read_host_csr();
197  host.interrupt_generate = 1;
198  write_host_csr(host);
199 
200  /* Make sure ME is ready after sending request data */
201  return mei_wait_for_me_ready();
202 }
203 
204 static int mei_send_data(u8 me_address, u8 host_address,
205  void *req_data, int req_bytes)
206 {
207  union mei_header header = {
208  .client_address = me_address,
209  .host_address = host_address,
210  };
211  union mei_csr host;
212  int current = 0;
213  u8 *req_ptr = req_data;
214 
215  while (!header.is_complete) {
216  int remain = req_bytes - current;
217  int buf_len;
218 
219  host = read_host_csr();
220  buf_len = host.buffer_depth - host.buffer_write_ptr;
221 
222  if (buf_len > remain) {
223  /* Send all remaining data as final message */
224  header.length = req_bytes - current;
225  header.is_complete = 1;
226  } else {
227  /* Send as much data as the buffer can hold */
228  header.length = buf_len;
229  }
230 
231  mei_send_packet(&header, req_ptr);
232 
233  req_ptr += header.length;
234  current += header.length;
235  }
236 
237  return 0;
238 }
239 
240 static int mei_send_header(u8 me_address, u8 host_address,
241  void *header, int header_len, int complete)
242 {
243  union mei_header mei = {
244  .client_address = me_address,
245  .host_address = host_address,
246  .length = header_len,
247  .is_complete = complete,
248  };
249  return mei_send_packet(&mei, header);
250 }
251 
252 static int mei_recv_msg(void *header, int header_bytes,
253  void *rsp_data, int rsp_bytes)
254 {
255  union mei_header mei_rsp;
256  union mei_csr me, host;
257  unsigned int ndata, n;
258  unsigned int expected;
259  u32 *data;
260 
261  /* Total number of dwords to read from circular buffer */
262  expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
263  if (rsp_bytes & 3)
264  expected++;
265 
266  if (mei_wait_for_me_ready() < 0)
267  return -1;
268 
269  /*
270  * The interrupt status bit does not appear to indicate that the
271  * message has actually been received. Instead we wait until the
272  * expected number of dwords are present in the circular buffer.
273  */
274  for (n = ME_RETRY; n; --n) {
275  me = read_me_csr();
276  if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
277  break;
278  udelay(ME_DELAY);
279  }
280  if (!n) {
281  printk(BIOS_ERR, "ME: timeout waiting for data: expected "
282  "%u, available %u\n", expected,
284  return -1;
285  }
286 
287  /* Read and verify MEI response header from the ME */
288  mei_rsp.raw = read_cb();
289  if (!mei_rsp.is_complete) {
290  printk(BIOS_ERR, "ME: response is not complete\n");
291  return -1;
292  }
293 
294  /* Handle non-dword responses and expect at least the header */
295  ndata = mei_rsp.length >> 2;
296  if (mei_rsp.length & 3)
297  ndata++;
298  if (ndata != (expected - 1)) {
299  printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
300  ndata, (expected - 1));
301  return -1;
302  }
303 
304  /* Read response header from the ME */
305  data = header;
306  for (n = 0; n < (header_bytes >> 2); ++n)
307  *data++ = read_cb();
308  ndata -= header_bytes >> 2;
309 
310  /* Make sure caller passed a buffer with enough space */
311  if (ndata != (rsp_bytes >> 2)) {
312  printk(BIOS_ERR, "ME: not enough room in response buffer: "
313  "%u != %u\n", ndata, rsp_bytes >> 2);
314  return -1;
315  }
316 
317  /* Read response data from the circular buffer */
318  data = rsp_data;
319  for (n = 0; n < ndata; ++n)
320  *data++ = read_cb();
321 
322  /* Tell the ME that we have consumed the response */
323  host = read_host_csr();
324  host.interrupt_status = 1;
325  host.interrupt_generate = 1;
326  write_host_csr(host);
327 
328  return mei_wait_for_me_ready();
329 }
330 
331 static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
332  void *req_data, int req_bytes,
333  void *rsp_data, int rsp_bytes)
334 {
335  struct mkhi_header mkhi_rsp;
336 
337  /* Send header */
339  mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
340  return -1;
341 
342  /* Send data if available */
344  req_data, req_bytes) < 0)
345  return -1;
346 
347  /* Return now if no response expected */
348  if (!rsp_bytes)
349  return 0;
350 
351  /* Read header and data */
352  if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
353  rsp_data, rsp_bytes) < 0)
354  return -1;
355 
356  if (!mkhi_rsp.is_response ||
357  mkhi->group_id != mkhi_rsp.group_id ||
358  mkhi->command != mkhi_rsp.command) {
359  printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
360  "command %u ?= %u, is_response %u\n", mkhi->group_id,
361  mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
362  mkhi_rsp.is_response);
363  return -1;
364  }
365 
366  return 0;
367 }
368 
369 static inline int mei_sendrecv_icc(struct icc_header *icc,
370  void *req_data, int req_bytes,
371  void *rsp_data, int rsp_bytes)
372 {
373  struct icc_header icc_rsp;
374 
375  /* Send header */
377  icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
378  return -1;
379 
380  /* Send data if available */
382  req_data, req_bytes) < 0)
383  return -1;
384 
385  /* Read header and data, if needed */
386  if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
387  rsp_data, rsp_bytes) < 0)
388  return -1;
389 
390  return 0;
391 }
392 
393 /*
394  * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
395  * state machine on the BIOS end doesn't match the ME's state machine.
396  */
397 static void intel_me_mbp_give_up(struct device *dev)
398 {
399  union mei_csr csr;
400 
402 
403  csr = read_host_csr();
404  csr.reset = 1;
405  csr.interrupt_generate = 1;
406  write_host_csr(csr);
407 }
408 
409 /*
410  * mbp clear routine. This will wait for the ME to indicate that
411  * the MBP has been read and cleared.
412  */
413 static void intel_me_mbp_clear(struct device *dev)
414 {
415  int count;
416  union me_hfs2 hfs2;
417 
418  /* Wait for the mbp_cleared indicator */
419  for (count = ME_RETRY; count > 0; --count) {
420  hfs2.raw = pci_read_config32(dev, PCI_ME_HFS2);
421  if (hfs2.mbp_cleared)
422  break;
423  udelay(ME_DELAY);
424  }
425 
426  if (count == 0) {
427  printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n");
429  } else {
430  printk(BIOS_INFO, "ME: MBP cleared\n");
431  }
432 }
433 
434 static void me_print_fw_version(struct mbp_fw_version_name *vers_name)
435 {
436  if (!vers_name) {
437  printk(BIOS_ERR, "ME: mbp missing version report\n");
438  return;
439  }
440 
441  printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
442  vers_name->major_version, vers_name->minor_version,
443  vers_name->hotfix_version, vers_name->build_version);
444 }
445 
446 static inline void print_cap(const char *name, int state)
447 {
448  printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
449  name, state ? " en" : "dis");
450 }
451 
452 /* Get ME Firmware Capabilities */
453 static int mkhi_get_fwcaps(struct mbp_mefwcaps *cap)
454 {
455  u32 rule_id = 0;
456  struct me_fwcaps cap_msg;
457  struct mkhi_header mkhi = {
459  .command = MKHI_FWCAPS_GET_RULE,
460  };
461 
462  /* Send request and wait for response */
463  if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
464  &cap_msg, sizeof(cap_msg)) < 0) {
465  printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
466  return -1;
467  }
468  *cap = cap_msg.caps_sku;
469  return 0;
470 }
471 
472 /* Get ME Firmware Capabilities */
473 static void me_print_fwcaps(struct mbp_mefwcaps *cap)
474 {
475  struct mbp_mefwcaps local_caps;
476  if (!cap) {
477  cap = &local_caps;
478  printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
479  if (mkhi_get_fwcaps(cap))
480  return;
481  }
482 
483  print_cap("Full Network manageability", cap->full_net);
484  print_cap("Regular Network manageability", cap->std_net);
485  print_cap("Manageability", cap->manageability);
486  print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
487  print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
488  print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
489  print_cap("ICC Over Clocking", cap->icc_over_clocking);
490  print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
491  print_cap("IPV6", cap->ipv6);
492  print_cap("KVM Remote Control (KVM)", cap->kvm);
493  print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
494  print_cap("Virtual LAN (VLAN)", cap->vlan);
495  print_cap("TLS", cap->tls);
496  print_cap("Wireless LAN (WLAN)", cap->wlan);
497 }
498 
499 /* Send END OF POST message to the ME */
500 static int mkhi_end_of_post(void)
501 {
502  struct mkhi_header mkhi = {
504  .command = MKHI_END_OF_POST,
505  };
506  u32 eop_ack;
507 
508  /* Send request and wait for response */
509  printk(BIOS_NOTICE, "ME: %s\n", __func__);
510  if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
511  printk(BIOS_ERR, "ME: END OF POST message failed\n");
512  return -1;
513  }
514 
515  printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
516  return 0;
517 }
518 
519 void intel_me_finalize(struct device *dev)
520 {
521  union me_hfs hfs;
522  u32 reg32;
523 
526 
527  /* S3 path will have hidden this device already */
528  if (!mei_base_address || mei_base_address == (u8 *)0xfffffff0)
529  return;
530 
531  /* Wait for ME MBP Cleared indicator */
532  intel_me_mbp_clear(dev);
533 
534  /* Make sure ME is in a mode that expects EOP */
535  hfs.raw = pci_read_config32(dev, PCI_ME_HFS);
536 
537  /* Abort and leave device alone if not normal mode */
538  if (hfs.fpt_bad ||
541  return;
542 
543  /* Try to send EOP command so ME stops accepting other commands */
545 
546  /* Make sure IO is disabled */
549 
550  /* Hide the PCI device */
552 }
553 
555 {
556  struct icc_clock_enables_msg clk = {
557  .clock_enables = 0, /* Turn off specified clocks */
558  .clock_mask = mask,
559  .no_response = 1, /* Do not expect response */
560  };
561  struct icc_header icc = {
563  .icc_command = ICC_SET_CLOCK_ENABLES,
564  .length = sizeof(clk),
565  };
566 
567  /* Send request and wait for response */
568  if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
569  printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
570  return -1;
571  }
572  printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
573  return 0;
574 }
575 
576 /* Determine the path that we should take based on ME status */
577 static enum me_bios_path intel_me_path(struct device *dev)
578 {
580  union me_hfs hfs = { .raw = pci_read_config32(dev, PCI_ME_HFS) };
581  union me_hfs2 hfs2 = { .raw = pci_read_config32(dev, PCI_ME_HFS2) };
582 
583  /* Check and dump status */
584  intel_me_status(hfs, hfs2);
585 
586  /* Check Current Working State */
587  switch (hfs.working_state) {
588  case ME_HFS_CWS_NORMAL:
589  path = ME_NORMAL_BIOS_PATH;
590  break;
591  case ME_HFS_CWS_REC:
592  path = ME_RECOVERY_BIOS_PATH;
593  break;
594  default:
595  path = ME_DISABLE_BIOS_PATH;
596  break;
597  }
598 
599  /* Check Current Operation Mode */
600  switch (hfs.operation_mode) {
601  case ME_HFS_MODE_NORMAL:
602  break;
603  case ME_HFS_MODE_DEBUG:
604  case ME_HFS_MODE_DIS:
607  default:
608  path = ME_DISABLE_BIOS_PATH;
609  break;
610  }
611 
612  /* Check for any error code and valid firmware and MBP */
613  if (hfs.error_code || hfs.fpt_bad)
614  path = ME_ERROR_BIOS_PATH;
615 
616  /* Check if the MBP is ready */
617  if (!hfs2.mbp_rdy) {
618  printk(BIOS_CRIT, "%s: mbp is not ready!\n",
619  __func__);
620  path = ME_ERROR_BIOS_PATH;
621  }
622 
623  if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) {
624  struct elog_event_data_me_extended data = {
626  .operation_state = hfs.operation_state,
627  .operation_mode = hfs.operation_mode,
628  .error_code = hfs.error_code,
629  .progress_code = hfs2.progress_code,
630  .current_pmevent = hfs2.current_pmevent,
631  .current_state = hfs2.current_state,
632  };
635  &data, sizeof(data));
636  }
637 
638  return path;
639 }
640 
641 /* Prepare ME for MEI messages */
642 static int intel_mei_setup(struct device *dev)
643 {
644  struct resource *res;
645  union mei_csr host;
646 
647  /* Find the MMIO base for the ME interface */
649  if (!res || res->base == 0 || res->size == 0) {
650  printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
651  return -1;
652  }
653  mei_base_address = res2mmio(res, 0, 0);
654 
655  /* Ensure Memory and Bus Master bits are set */
657 
658  /* Clean up status for next message */
659  host = read_host_csr();
660  host.interrupt_generate = 1;
661  host.ready = 1;
662  host.reset = 0;
663  write_host_csr(host);
664 
665  return 0;
666 }
667 
668 /* Read the Extend register hash of ME firmware */
669 static int intel_me_extend_valid(struct device *dev)
670 {
671  union me_heres status = { .raw = pci_read_config32(dev, PCI_ME_HERES) };
672  u32 extend[8] = {0};
673  int i, count = 0;
674 
675  if (!status.extend_feature_present) {
676  printk(BIOS_ERR, "ME: Extend Feature not present\n");
677  return -1;
678  }
679 
680  if (!status.extend_reg_valid) {
681  printk(BIOS_ERR, "ME: Extend Register not valid\n");
682  return -1;
683  }
684 
685  switch (status.extend_reg_algorithm) {
686  case PCI_ME_EXT_SHA1:
687  count = 5;
688  printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
689  break;
690  case PCI_ME_EXT_SHA256:
691  count = 8;
692  printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
693  break;
694  default:
695  printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
696  status.extend_reg_algorithm);
697  return -1;
698  }
699 
700  for (i = 0; i < count; ++i) {
701  extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
702  printk(BIOS_DEBUG, "%08x", extend[i]);
703  }
704  printk(BIOS_DEBUG, "\n");
705 
706  /* Save hash in NVS for the OS to verify */
707  if (CONFIG(CHROMEOS_NVS))
708  chromeos_set_me_hash(extend, count);
709 
710  return 0;
711 }
712 
714 {
715  union mei_csr me = read_me_csr();
716  if (!me.ready)
717  return 0;
718  return (me.buffer_write_ptr - me.buffer_read_ptr) &
719  (me.buffer_depth - 1);
720 }
721 
722 struct mbp_payload {
723  union mbp_header header;
724  u32 data[0];
725 };
726 
727 /*
728  * Read and print ME MBP data
729  *
730  * Return -1 to indicate a problem (give up)
731  * Return 0 to indicate success (send LOCK+EOP)
732  */
733 static int intel_me_read_mbp(struct me_bios_payload *mbp_data, struct device *dev)
734 {
735  union mbp_header mbp_hdr;
736  u32 me2host_pending;
737  union mei_csr host;
738  union me_hfs2 hfs2 = { .raw = pci_read_config32(dev, PCI_ME_HFS2) };
739  struct mbp_payload *mbp;
740  int i;
741 
742  if (!hfs2.mbp_rdy) {
743  printk(BIOS_ERR, "ME: MBP not ready\n");
744  goto mbp_failure;
745  }
746 
747  me2host_pending = me_to_host_words_pending();
748  if (!me2host_pending) {
749  printk(BIOS_ERR, "ME: no mbp data!\n");
750  goto mbp_failure;
751  }
752 
753  /* we know for sure that at least the header is there */
754  mbp_hdr.raw = read_cb();
755 
756  if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
757  (me2host_pending < mbp_hdr.mbp_size)) {
758  printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
759  " buffer contains %d words\n",
760  mbp_hdr.num_entries, mbp_hdr.mbp_size,
761  me2host_pending);
762  goto mbp_failure;
763  }
764  mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
765  if (!mbp)
766  goto mbp_failure;
767 
768  mbp->header = mbp_hdr;
769  me2host_pending--;
770 
771  i = 0;
772  while (i != me2host_pending) {
773  mbp->data[i] = read_cb();
774  i++;
775  }
776 
777  /* Signal to the ME that the host has finished reading the MBP. */
778  host = read_host_csr();
779  host.interrupt_generate = 1;
780  write_host_csr(host);
781 
782  /* Dump out the MBP contents. */
783  if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
784  printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
785  mbp->header.num_entries, mbp->header.mbp_size);
786  if (CONFIG(DEBUG_INTEL_ME)) {
787  for (i = 0; i < mbp->header.mbp_size - 1; i++) {
788  printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
789  }
790  }
791  }
792 
793  #define ASSIGN_FIELD_PTR(field_,val_) \
794  { \
795  mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
796  break; \
797  }
798  /* Setup the pointers in the me_bios_payload structure. */
799  for (i = 0; i < mbp->header.mbp_size - 1;) {
800  struct mbp_item_header *item = (void *)&mbp->data[i];
801 
802  switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
803  case MBP_IDENT(KERNEL, FW_VER):
804  ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
805 
806  case MBP_IDENT(ICC, PROFILE):
807  ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
808 
809  case MBP_IDENT(INTEL_AT, STATE):
810  ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
811 
812  case MBP_IDENT(KERNEL, FW_CAP):
813  ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
814 
815  case MBP_IDENT(KERNEL, ROM_BIST):
816  ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
817 
818  case MBP_IDENT(KERNEL, PLAT_KEY):
819  ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
820 
821  case MBP_IDENT(KERNEL, FW_TYPE):
822  ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
823 
824  case MBP_IDENT(KERNEL, MFS_FAILURE):
825  ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
826 
827  case MBP_IDENT(KERNEL, PLAT_TIME):
828  ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
829 
830  case MBP_IDENT(NFC, SUPPORT_DATA):
831  ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
832 
833  default:
834  printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
835  "dw offset 0x%x\n", mbp->data[i], i);
836  break;
837  }
838  i += item->length;
839  }
840  #undef ASSIGN_FIELD_PTR
841 
842  return 0;
843 
844 mbp_failure:
846  return -1;
847 }
848 
849 /* Check whether ME is present and do basic init */
850 static void intel_me_init(struct device *dev)
851 {
853  enum me_bios_path path = intel_me_path(dev);
854  struct me_bios_payload mbp_data;
855 
856  /* Do initial setup and determine the BIOS path */
857  printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
858 
859  if (path == ME_NORMAL_BIOS_PATH) {
860  /* Validate the extend register */
862  }
863 
864  memset(&mbp_data, 0, sizeof(mbp_data));
865 
866  /*
867  * According to the ME9 BWG, BIOS is required to fetch MBP data in
868  * all boot flows except S3 Resume.
869  */
870 
871  /* Prepare MEI MMIO interface */
872  if (intel_mei_setup(dev) < 0)
873  return;
874 
875  if (intel_me_read_mbp(&mbp_data, dev))
876  return;
877 
878  if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
880 
881  if (CONFIG(DEBUG_INTEL_ME))
883 
884  if (mbp_data.plat_time) {
885  printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
887  printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
888  mbp_data.plat_time->mrst_pltrst_time_ms);
889  printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
890  mbp_data.plat_time->pltrst_cpurst_time_ms);
891  }
892  }
893 
894  /* Set clock enables according to devicetree */
895  if (config && config->icc_clock_disable)
896  me_icc_set_clock_enables(config->icc_clock_disable);
897 
898  /*
899  * Leave the ME unlocked. It will be locked later.
900  */
901 }
902 
903 static void intel_me_enable(struct device *dev)
904 {
905  /* Avoid talking to the device in S3 path */
906  if (acpi_is_wakeup_s3()) {
907  dev->enabled = 0;
908  pch_disable_devfn(dev);
909  }
910 }
911 
912 static struct device_operations device_ops = {
914  .set_resources = pci_dev_set_resources,
915  .enable_resources = pci_dev_enable_resources,
916  .enable = intel_me_enable,
917  .init = intel_me_init,
918  .final = intel_me_finalize,
919  .ops_pci = &pci_dev_ops_pci,
920 };
921 
922 static const unsigned short pci_device_ids[] = {
925  0
926 };
927 
928 static const struct pci_driver intel_me __pci_driver = {
929  .ops = &device_ops,
930  .vendor = PCI_VID_INTEL,
931  .devices = pci_device_ids,
932 };
struct arm64_kernel_header header
Definition: fit_payload.c:30
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
const char * name
Definition: mmu.c:92
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
void * memset(void *dstpp, int c, size_t len)
Definition: memset.c:12
#define ELOG_TYPE_MANAGEMENT_ENGINE
Definition: elog.h:212
#define ELOG_TYPE_MANAGEMENT_ENGINE_EXT
Definition: elog.h:220
#define printk(level,...)
Definition: stdlib.h:16
@ ICC
Definition: cse_layout.h:30
struct resource * probe_resource(const struct device *dev, unsigned int index)
See if a resource structure already exists for a given index.
Definition: device_util.c:323
int elog_add_event_raw(u8 event_type, void *data, u8 data_size)
Definition: elog.c:798
int elog_add_event_byte(u8 event_type, u8 data)
Definition: elog.c:868
@ CONFIG
Definition: dsi_common.h:201
static size_t offset
Definition: flashconsole.c:16
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline void pci_and_config16(const struct device *dev, u16 reg, u16 andmask)
Definition: pci_ops.h:147
static __always_inline void pci_or_config16(const struct device *dev, u16 reg, u16 ormask)
Definition: pci_ops.h:180
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
void * malloc(size_t size)
Definition: malloc.c:53
unsigned int type
Definition: edid.c:57
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_CRIT
BIOS_CRIT - Recovery unlikely.
Definition: loglevel.h:56
#define BIOS_NOTICE
BIOS_NOTICE - Unexpected but relatively insignificant.
Definition: loglevel.h:100
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
Definition: loglevel.h:142
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
enum board_config config
Definition: memory.c:448
state
Definition: raminit.c:1787
#define PCI_BASE_ADDRESS_MEM_ATTR_MASK
Definition: pci_def.h:77
#define PCI_COMMAND_IO
Definition: pci_def.h:11
#define PCI_COMMAND_MASTER
Definition: pci_def.h:13
#define PCI_COMMAND_MEMORY
Definition: pci_def.h:12
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_COMMAND
Definition: pci_def.h:10
void pci_dev_enable_resources(struct device *dev)
Definition: pci_device.c:721
void pci_dev_read_resources(struct device *dev)
Definition: pci_device.c:534
struct pci_operations pci_dev_ops_pci
Default device operation for PCI devices.
Definition: pci_device.c:911
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_DID_INTEL_LPT_LP_MEI
Definition: pci_ids.h:4229
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define PCI_DID_INTEL_LPT_H_MEI
Definition: pci_ids.h:4228
static void * res2mmio(const struct resource *res, unsigned long offset, unsigned long mask)
Definition: resource.h:87
#define ME_RETRY
Definition: me.h:8
#define PCI_ME_HERES
Definition: me.h:192
#define ICC_API_VERSION_LYNXPOINT
Definition: me.h:279
#define ME_DELAY
Definition: me.h:9
#define MEI_H_CSR
Definition: me.h:209
#define ME_HFS_CWS_REC
Definition: me.h:21
#define ME_HFS_MODE_NORMAL
Definition: me.h:36
#define ME_HFS_MODE_DIS
Definition: me.h:38
#define MKHI_GROUP_ID_FWCAPS
Definition: me.h:245
#define PCI_ME_HFS2
Definition: me.h:100
#define ME_HFS_MODE_OVER_MEI
Definition: me.h:40
#define MEI_ME_CSR_HA
Definition: me.h:211
#define MEI_ADDRESS_MKHI
Definition: me.h:229
#define PCI_ME_HFS
Definition: me.h:18
#define ME_HFS_CWS_NORMAL
Definition: me.h:22
#define MEI_ME_CB_RW
Definition: me.h:210
#define MBP_IDENT(appid, item)
Definition: me.h:347
#define PCI_ME_HER(x)
Definition: me.h:195
#define PCI_ME_EXT_SHA256
Definition: me.h:194
#define PCI_ME_MBP_GIVE_UP
Definition: me.h:190
#define ME_HFS_MODE_OVER_JMPR
Definition: me.h:39
#define MEI_HOST_ADDRESS
Definition: me.h:233
#define PCI_ME_H_GS2
Definition: me.h:189
#define MKHI_GROUP_ID_GEN
Definition: me.h:252
me_bios_path
Definition: me.h:310
@ ME_ERROR_BIOS_PATH
Definition: me.h:313
@ ME_RECOVERY_BIOS_PATH
Definition: me.h:314
@ ME_DISABLE_BIOS_PATH
Definition: me.h:315
@ ME_FIRMWARE_UPDATE_BIOS_PATH
Definition: me.h:316
@ ME_S3WAKE_BIOS_PATH
Definition: me.h:312
@ ME_NORMAL_BIOS_PATH
Definition: me.h:311
#define MKHI_FWCAPS_GET_RULE
Definition: me.h:246
#define ME_HFS_MODE_DEBUG
Definition: me.h:37
#define MEI_H_CB_WW
Definition: me.h:208
#define MEI_ADDRESS_ICC
Definition: me.h:230
#define PCI_ME_EXT_SHA1
Definition: me.h:193
#define ICC_SET_CLOCK_ENABLES
Definition: me.h:278
#define MKHI_END_OF_POST
Definition: me.h:254
#define MBP_MAKE_IDENT(appid, item)
Definition: me.h:346
void pch_disable_devfn(struct device *dev)
Definition: pch.c:77
#define PCH_DISABLE_MEI1
Definition: rcba.h:149
#define FD2
Definition: rcba.h:128
static const int mask[4]
Definition: gpio.c:308
void intel_me_status(void)
Definition: me.c:184
#define RCBA32_OR(x, or)
Definition: rcba.h:22
static u32 me_to_host_words_pending(void)
Definition: me.c:713
static struct device_operations device_ops
Definition: me.c:912
static int me_icc_set_clock_enables(u32 mask)
Definition: me.c:554
static const struct pci_driver intel_me __pci_driver
Definition: me.c:928
#define ASSIGN_FIELD_PTR(field_, val_)
static int intel_me_read_mbp(struct me_bios_payload *mbp_data, struct device *dev)
Definition: me.c:733
static enum me_bios_path intel_me_path(struct device *dev)
Definition: me.c:577
static int mei_wait_for_me_ready(void)
Definition: me.c:110
static void print_cap(const char *name, int state)
Definition: me.c:446
static void write_cb(u32 dword)
Definition: me.c:96
static void intel_me_init(struct device *dev)
Definition: me.c:850
static int intel_mei_setup(struct device *dev)
Definition: me.c:642
static void mei_dump(u32 dword, int offset, const char *type)
Definition: me.c:43
static int mei_sendrecv_icc(struct icc_header *icc, void *req_data, int req_bytes, void *rsp_data, int rsp_bytes)
Definition: me.c:369
static int mei_sendrecv_mkhi(struct mkhi_header *mkhi, void *req_data, int req_bytes, void *rsp_data, int rsp_bytes)
Definition: me.c:331
static union mei_csr read_me_csr(void)
Definition: me.c:89
static u8 * mei_base_address
Definition: me.c:41
static void write_host_csr(union mei_csr csr)
Definition: me.c:83
static int intel_me_extend_valid(struct device *dev)
Definition: me.c:669
static void me_print_fw_version(struct mbp_fw_version_name *vers_name)
Definition: me.c:434
static const unsigned short pci_device_ids[]
Definition: me.c:922
static u32 read_cb(void)
Definition: me.c:102
static void intel_me_enable(struct device *dev)
Definition: me.c:903
static void mei_reset(void)
Definition: me.c:126
void intel_me_finalize(struct device *dev)
Definition: me.c:519
static int mei_send_packet(union mei_header *mei, void *req_data)
Definition: me.c:150
static union mei_csr read_host_csr(void)
Definition: me.c:76
static int mkhi_end_of_post(void)
Definition: me.c:500
static void me_print_fwcaps(struct mbp_mefwcaps *cap)
Definition: me.c:473
static const char *const me_bios_path_values[]
Definition: me.c:31
static int mei_recv_msg(void *header, int header_bytes, void *rsp_data, int rsp_bytes)
Definition: me.c:252
static int mkhi_get_fwcaps(struct mbp_mefwcaps *cap)
Definition: me.c:453
static int mei_send_data(u8 me_address, u8 host_address, void *req_data, int req_bytes)
Definition: me.c:204
static void intel_me_mbp_clear(struct device *dev)
Definition: me.c:413
static int mei_send_header(u8 me_address, u8 host_address, void *header, int header_len, int complete)
Definition: me.c:240
static void intel_me_mbp_give_up(struct device *dev)
Definition: me.c:397
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
uint8_t u8
Definition: stdint.h:45
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int enabled
Definition: device.h:122
uint8_t current_working_state
Definition: elog.h:229
Definition: me.h:281
u32 api_version
Definition: me.h:282
u32 minor_version
Definition: me.h:395
u32 hotfix_version
Definition: me.h:396
u32 major_version
Definition: me.h:394
u32 build_version
Definition: me.h:397
u32 length
Definition: me.h:389
u32 app_id
Definition: me.h:387
u32 item_id
Definition: me.h:388
u32 wlan
Definition: me.h:418
u32 full_net
Definition: me.h:401
u32 icc_over_clocking
Definition: me.h:409
u32 och
Definition: me.h:414
u32 intel_cls
Definition: me.h:406
u32 intel_mpc
Definition: me.h:408
u32 pavp
Definition: me.h:410
u32 tls
Definition: me.h:416
u32 kvm
Definition: me.h:413
u32 manageability
Definition: me.h:403
u32 ipv6
Definition: me.h:412
u32 vlan
Definition: me.h:415
u32 std_net
Definition: me.h:402
u32 intel_at
Definition: me.h:405
u32 data[0]
Definition: me.c:807
mbp_header header
Definition: me.c:806
u32 pltrst_cpurst_time_ms
Definition: me.h:483
u32 wake_event_mrst_time_ms
Definition: me.h:481
u32 mrst_pltrst_time_ms
Definition: me.h:482
mbp_mefwcaps * fw_capabilities
Definition: me.h:463
mbp_plat_time * plat_time
Definition: me.h:470
mbp_fw_version_name * fw_version_name
Definition: me.h:462
Definition: me.h:474
mbp_mefwcaps caps_sku
Definition: me.h:477
Definition: me.h:197
u32 extend_reg_valid
Definition: me.h:201
u32 raw
Definition: me.h:142
u32 extend_reg_algorithm
Definition: me.h:198
u32 extend_feature_present
Definition: me.h:200
Definition: me.h:170
u32 current_state
Definition: me.h:182
u32 current_pmevent
Definition: me.h:183
u32 raw
Definition: me.h:194
u32 mbp_cleared
Definition: me.h:180
u32 progress_code
Definition: me.h:184
u32 mbp_rdy
Definition: me.h:175
Definition: me.h:51
u32 raw
Definition: me.h:69
u32 fpt_bad
Definition: me.h:54
u32 operation_state
Definition: me.h:55
u32 working_state
Definition: me.h:52
u32 operation_mode
Definition: me.h:60
u32 error_code
Definition: me.h:59
Definition: me.h:213
u32 interrupt_enable
Definition: me.h:214
u32 buffer_read_ptr
Definition: me.h:220
u32 interrupt_status
Definition: me.h:215
u32 buffer_depth
Definition: me.h:222
u32 reset
Definition: me.h:218
u32 interrupt_generate
Definition: me.h:216
u32 ready
Definition: me.h:217
u32 buffer_write_ptr
Definition: me.h:221
u32 raw
Definition: me.h:236
Definition: me.h:235
u32 is_complete
Definition: me.h:240
u32 raw
Definition: me.h:257
u32 length
Definition: me.h:238
u32 host_address
Definition: me.h:237
u32 client_address
Definition: me.h:236
u32 is_response
Definition: me.h:261
u32 group_id
Definition: me.h:259
u32 command
Definition: me.h:260
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46
void udelay(uint32_t us)
Definition: udelay.c:15
Definition: me.h:377
u32 raw
Definition: me.h:383
#define count
typedef void(X86APIP X86EMU_intrFuncs)(int num)