1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * This is a ramstage driver for the Intel Management Engine found in the
5 * southbridge. 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.
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>
25 #include <soc/pci_devs.h>
27 #include <soc/intel/broadwell/pch/chip.h>
29 #include <vendorcode/google/chromeos/chromeos.h>
31 /* Path that the BIOS should take based on ME state */
32 static const char *me_bios_path_values
[] = {
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",
41 /* MMIO base address for MEI interface */
42 static u8
*mei_base_address
;
44 static void mei_dump(void *ptr
, int dword
, int offset
, const char *type
)
48 if (!CONFIG(DEBUG_INTEL_ME
))
51 printk(BIOS_SPEW
, "%-9s[%02x] : ", type
, offset
);
58 printk(BIOS_SPEW
, "ERROR: 0x%08x\n", dword
);
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
);
69 printk(BIOS_SPEW
, "CB: 0x%08x\n", dword
);
72 printk(BIOS_SPEW
, "0x%08x\n", offset
);
78 * ME/MEI access helpers using memcpy to avoid aliasing.
81 static inline void mei_read_dword_ptr(void *ptr
, int offset
)
83 u32 dword
= read32(mei_base_address
+ offset
);
84 memcpy(ptr
, &dword
, sizeof(dword
));
85 mei_dump(ptr
, dword
, offset
, "READ");
88 static inline void mei_write_dword_ptr(void *ptr
, int offset
)
91 memcpy(&dword
, ptr
, sizeof(dword
));
92 write32(mei_base_address
+ offset
, dword
);
93 mei_dump(ptr
, dword
, offset
, "WRITE");
96 static inline void pci_read_dword_ptr(struct device
*dev
, void *ptr
, int offset
)
98 u32 dword
= pci_read_config32(dev
, offset
);
99 memcpy(ptr
, &dword
, sizeof(dword
));
100 mei_dump(ptr
, dword
, offset
, "PCI READ");
103 static inline void read_host_csr(struct mei_csr
*csr
)
105 mei_read_dword_ptr(csr
, MEI_H_CSR
);
108 static inline void write_host_csr(struct mei_csr
*csr
)
110 mei_write_dword_ptr(csr
, MEI_H_CSR
);
113 static inline void read_me_csr(struct mei_csr
*csr
)
115 mei_read_dword_ptr(csr
, MEI_ME_CSR_HA
);
118 static inline void write_cb(u32 dword
)
120 write32(mei_base_address
+ MEI_H_CB_WW
, dword
);
121 mei_dump(NULL
, dword
, MEI_H_CB_WW
, "WRITE");
124 static inline u32
read_cb(void)
126 u32 dword
= read32(mei_base_address
+ MEI_ME_CB_RW
);
127 mei_dump(NULL
, dword
, MEI_ME_CB_RW
, "READ");
131 /* Wait for ME ready bit to be asserted */
132 static int mei_wait_for_me_ready(void)
135 unsigned int try = ME_RETRY
;
144 printk(BIOS_ERR
, "ME: failed to become ready\n");
148 static void mei_reset(void)
152 if (mei_wait_for_me_ready() < 0)
155 /* Reset host and ME circular buffers for next message */
156 read_host_csr(&host
);
158 host
.interrupt_generate
= 1;
159 write_host_csr(&host
);
161 if (mei_wait_for_me_ready() < 0)
164 /* Re-init and indicate host is ready */
165 read_host_csr(&host
);
166 host
.interrupt_generate
= 1;
169 write_host_csr(&host
);
172 static int mei_send_packet(struct mei_header
*mei
, void *req_data
)
175 unsigned int ndata
, n
;
178 /* Number of dwords to write */
179 ndata
= mei
->length
>> 2;
181 /* Pad non-dword aligned request message length */
185 printk(BIOS_DEBUG
, "ME: request has no data\n");
188 ndata
++; /* Add MEI header */
191 * Make sure there is still room left in the circular buffer.
192 * Reset the buffer pointers if the requested message will not fit.
194 read_host_csr(&host
);
195 if ((host
.buffer_depth
- host
.buffer_write_ptr
) < ndata
) {
196 printk(BIOS_ERR
, "ME: circular buffer full, resetting...\n");
198 read_host_csr(&host
);
201 /* Ensure the requested length will fit in the circular buffer. */
202 if ((host
.buffer_depth
- host
.buffer_write_ptr
) < ndata
) {
203 printk(BIOS_ERR
, "ME: message (%u) too large for buffer (%u)\n",
204 ndata
+ 2, host
.buffer_depth
);
208 /* Write MEI header */
209 mei_write_dword_ptr(mei
, MEI_H_CB_WW
);
212 /* Write message data */
214 for (n
= 0; n
< ndata
; ++n
)
217 /* Generate interrupt to the ME */
218 read_host_csr(&host
);
219 host
.interrupt_generate
= 1;
220 write_host_csr(&host
);
222 /* Make sure ME is ready after sending request data */
223 return mei_wait_for_me_ready();
226 static int mei_send_data(u8 me_address
, u8 host_address
,
227 void *req_data
, int req_bytes
)
229 struct mei_header header
= {
230 .client_address
= me_address
,
231 .host_address
= host_address
,
235 u8
*req_ptr
= req_data
;
237 while (!header
.is_complete
) {
238 int remain
= req_bytes
- current
;
241 read_host_csr(&host
);
242 buf_len
= host
.buffer_depth
- host
.buffer_write_ptr
;
244 if (buf_len
> remain
) {
245 /* Send all remaining data as final message */
246 header
.length
= req_bytes
- current
;
247 header
.is_complete
= 1;
249 /* Send as much data as the buffer can hold */
250 header
.length
= buf_len
;
253 mei_send_packet(&header
, req_ptr
);
255 req_ptr
+= header
.length
;
256 current
+= header
.length
;
262 static int mei_send_header(u8 me_address
, u8 host_address
,
263 void *header
, int header_len
, int complete
)
265 struct mei_header mei
= {
266 .client_address
= me_address
,
267 .host_address
= host_address
,
268 .length
= header_len
,
269 .is_complete
= complete
,
271 return mei_send_packet(&mei
, header
);
274 static int mei_recv_msg(void *header
, int header_bytes
,
275 void *rsp_data
, int rsp_bytes
)
277 struct mei_header mei_rsp
;
278 struct mei_csr me
, host
;
279 unsigned int ndata
, n
;
280 unsigned int expected
;
283 /* Total number of dwords to read from circular buffer */
284 expected
= (rsp_bytes
+ sizeof(mei_rsp
) + header_bytes
) >> 2;
288 if (mei_wait_for_me_ready() < 0)
292 * The interrupt status bit does not appear to indicate that the
293 * message has actually been received. Instead we wait until the
294 * expected number of dwords are present in the circular buffer.
296 for (n
= ME_RETRY
; n
; --n
) {
298 if ((me
.buffer_write_ptr
- me
.buffer_read_ptr
) >= expected
)
303 printk(BIOS_ERR
, "ME: timeout waiting for data: expected "
304 "%u, available %u\n", expected
,
305 me
.buffer_write_ptr
- me
.buffer_read_ptr
);
309 /* Read and verify MEI response header from the ME */
310 mei_read_dword_ptr(&mei_rsp
, MEI_ME_CB_RW
);
311 if (!mei_rsp
.is_complete
) {
312 printk(BIOS_ERR
, "ME: response is not complete\n");
316 /* Handle non-dword responses and expect at least the header */
317 ndata
= mei_rsp
.length
>> 2;
318 if (mei_rsp
.length
& 3)
320 if (ndata
!= (expected
- 1)) {
321 printk(BIOS_ERR
, "ME: response is missing data %d != %d\n",
322 ndata
, (expected
- 1));
326 /* Read response header from the ME */
328 for (n
= 0; n
< (header_bytes
>> 2); ++n
)
330 ndata
-= header_bytes
>> 2;
332 /* Make sure caller passed a buffer with enough space */
333 if (ndata
!= (rsp_bytes
>> 2)) {
334 printk(BIOS_ERR
, "ME: not enough room in response buffer: "
335 "%u != %u\n", ndata
, rsp_bytes
>> 2);
339 /* Read response data from the circular buffer */
341 for (n
= 0; n
< ndata
; ++n
)
344 /* Tell the ME that we have consumed the response */
345 read_host_csr(&host
);
346 host
.interrupt_status
= 1;
347 host
.interrupt_generate
= 1;
348 write_host_csr(&host
);
350 return mei_wait_for_me_ready();
353 static inline int mei_sendrecv_mkhi(struct mkhi_header
*mkhi
,
354 void *req_data
, int req_bytes
,
355 void *rsp_data
, int rsp_bytes
)
357 struct mkhi_header mkhi_rsp
;
360 if (mei_send_header(MEI_ADDRESS_MKHI
, MEI_HOST_ADDRESS
,
361 mkhi
, sizeof(*mkhi
), req_bytes
? 0 : 1) < 0)
364 /* Send data if available */
365 if (req_bytes
&& mei_send_data(MEI_ADDRESS_MKHI
, MEI_HOST_ADDRESS
,
366 req_data
, req_bytes
) < 0)
369 /* Return now if no response expected */
373 /* Read header and data */
374 if (mei_recv_msg(&mkhi_rsp
, sizeof(mkhi_rsp
),
375 rsp_data
, rsp_bytes
) < 0)
378 if (!mkhi_rsp
.is_response
||
379 mkhi
->group_id
!= mkhi_rsp
.group_id
||
380 mkhi
->command
!= mkhi_rsp
.command
) {
381 printk(BIOS_ERR
, "ME: invalid response, group %u ?= %u,"
382 "command %u ?= %u, is_response %u\n", mkhi
->group_id
,
383 mkhi_rsp
.group_id
, mkhi
->command
, mkhi_rsp
.command
,
384 mkhi_rsp
.is_response
);
391 static inline int mei_sendrecv_icc(struct icc_header
*icc
,
392 void *req_data
, int req_bytes
,
393 void *rsp_data
, int rsp_bytes
)
395 struct icc_header icc_rsp
;
398 if (mei_send_header(MEI_ADDRESS_ICC
, MEI_HOST_ADDRESS
,
399 icc
, sizeof(*icc
), req_bytes
? 0 : 1) < 0)
402 /* Send data if available */
403 if (req_bytes
&& mei_send_data(MEI_ADDRESS_ICC
, MEI_HOST_ADDRESS
,
404 req_data
, req_bytes
) < 0)
407 /* Read header and data, if needed */
408 if (rsp_bytes
&& mei_recv_msg(&icc_rsp
, sizeof(icc_rsp
),
409 rsp_data
, rsp_bytes
) < 0)
416 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
417 * state machine on the BIOS end doesn't match the ME's state machine.
419 static void intel_me_mbp_give_up(struct device
*dev
)
423 pci_write_config32(dev
, PCI_ME_H_GS2
, PCI_ME_MBP_GIVE_UP
);
427 csr
.interrupt_generate
= 1;
428 write_host_csr(&csr
);
432 * mbp clear routine. This will wait for the ME to indicate that
433 * the MBP has been read and cleared.
435 static void intel_me_mbp_clear(struct device
*dev
)
440 /* Wait for the mbp_cleared indicator */
441 for (count
= ME_RETRY
; count
> 0; --count
) {
442 pci_read_dword_ptr(dev
, &hfs2
, PCI_ME_HFS2
);
443 if (hfs2
.mbp_cleared
)
449 printk(BIOS_WARNING
, "ME: Timeout waiting for mbp_cleared\n");
450 intel_me_mbp_give_up(dev
);
452 printk(BIOS_INFO
, "ME: MBP cleared\n");
456 static void me_print_fw_version(mbp_fw_version_name
*vers_name
)
459 printk(BIOS_ERR
, "ME: mbp missing version report\n");
463 printk(BIOS_DEBUG
, "ME: found version %d.%d.%d.%d\n",
464 vers_name
->major_version
, vers_name
->minor_version
,
465 vers_name
->hotfix_version
, vers_name
->build_version
);
468 static inline void print_cap(const char *name
, int state
)
470 printk(BIOS_DEBUG
, "ME Capability: %-41s : %sabled\n",
471 name
, state
? " en" : "dis");
474 /* Get ME Firmware Capabilities */
475 static int mkhi_get_fwcaps(mbp_mefwcaps
*cap
)
478 struct me_fwcaps cap_msg
;
479 struct mkhi_header mkhi
= {
480 .group_id
= MKHI_GROUP_ID_FWCAPS
,
481 .command
= MKHI_FWCAPS_GET_RULE
,
484 /* Send request and wait for response */
485 if (mei_sendrecv_mkhi(&mkhi
, &rule_id
, sizeof(u32
),
486 &cap_msg
, sizeof(cap_msg
)) < 0) {
487 printk(BIOS_ERR
, "ME: GET FWCAPS message failed\n");
490 *cap
= cap_msg
.caps_sku
;
494 /* Get ME Firmware Capabilities */
495 static void me_print_fwcaps(mbp_mefwcaps
*cap
)
497 mbp_mefwcaps local_caps
;
500 printk(BIOS_ERR
, "ME: mbp missing fwcaps report\n");
501 if (mkhi_get_fwcaps(cap
))
505 print_cap("Full Network manageability", cap
->full_net
);
506 print_cap("Regular Network manageability", cap
->std_net
);
507 print_cap("Manageability", cap
->manageability
);
508 print_cap("IntelR Anti-Theft (AT)", cap
->intel_at
);
509 print_cap("IntelR Capability Licensing Service (CLS)", cap
->intel_cls
);
510 print_cap("IntelR Power Sharing Technology (MPC)", cap
->intel_mpc
);
511 print_cap("ICC Over Clocking", cap
->icc_over_clocking
);
512 print_cap("Protected Audio Video Path (PAVP)", cap
->pavp
);
513 print_cap("IPV6", cap
->ipv6
);
514 print_cap("KVM Remote Control (KVM)", cap
->kvm
);
515 print_cap("Outbreak Containment Heuristic (OCH)", cap
->och
);
516 print_cap("Virtual LAN (VLAN)", cap
->vlan
);
517 print_cap("TLS", cap
->tls
);
518 print_cap("Wireless LAN (WLAN)", cap
->wlan
);
521 /* Send END OF POST message to the ME */
522 static int mkhi_end_of_post(void)
524 struct mkhi_header mkhi
= {
525 .group_id
= MKHI_GROUP_ID_GEN
,
526 .command
= MKHI_END_OF_POST
,
530 /* Send request and wait for response */
531 if (mei_sendrecv_mkhi(&mkhi
, NULL
, 0, &eop_ack
, sizeof(eop_ack
)) < 0) {
532 printk(BIOS_ERR
, "ME: END OF POST message failed\n");
536 printk(BIOS_INFO
, "ME: END OF POST message successful (%d)\n", eop_ack
);
540 /* Send END OF POST message to the ME */
541 static int mkhi_end_of_post_noack(void)
543 struct mkhi_header mkhi
= {
544 .group_id
= MKHI_GROUP_ID_GEN
,
545 .command
= MKHI_END_OF_POST_NOACK
,
548 /* Send request, do not wait for response */
549 if (mei_sendrecv_mkhi(&mkhi
, NULL
, 0, NULL
, 0) < 0) {
550 printk(BIOS_ERR
, "ME: END OF POST NOACK message failed\n");
554 printk(BIOS_INFO
, "ME: END OF POST NOACK message successful\n");
558 /* Send HMRFPO LOCK message to the ME */
559 static int mkhi_hmrfpo_lock(void)
561 struct mkhi_header mkhi
= {
562 .group_id
= MKHI_GROUP_ID_HMRFPO
,
563 .command
= MKHI_HMRFPO_LOCK
,
567 /* Send request and wait for response */
568 if (mei_sendrecv_mkhi(&mkhi
, NULL
, 0, &ack
, sizeof(ack
)) < 0) {
569 printk(BIOS_ERR
, "ME: HMRFPO LOCK message failed\n");
573 printk(BIOS_INFO
, "ME: HMRFPO LOCK message successful (%d)\n", ack
);
577 /* Send HMRFPO LOCK message to the ME, do not wait for response */
578 static int mkhi_hmrfpo_lock_noack(void)
580 struct mkhi_header mkhi
= {
581 .group_id
= MKHI_GROUP_ID_HMRFPO
,
582 .command
= MKHI_HMRFPO_LOCK_NOACK
,
585 /* Send request, do not wait for response */
586 if (mei_sendrecv_mkhi(&mkhi
, NULL
, 0, NULL
, 0) < 0) {
587 printk(BIOS_ERR
, "ME: HMRFPO LOCK NOACK message failed\n");
591 printk(BIOS_INFO
, "ME: HMRFPO LOCK NOACK message successful\n");
595 static void intel_me_finalize(struct device
*dev
)
599 /* S3 path will have hidden this device already */
600 if (!mei_base_address
|| mei_base_address
== (u8
*)0xfffffff0)
603 if (!CONFIG(DISABLE_ME_PCI
))
606 /* Make sure IO is disabled */
607 reg16
= pci_read_config16(dev
, PCI_COMMAND
);
608 reg16
&= ~(PCI_COMMAND_MASTER
|
609 PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
);
610 pci_write_config16(dev
, PCI_COMMAND
, reg16
);
612 /* Hide the PCI device */
613 RCBA32_OR(FD2
, PCH_DISABLE_MEI1
);
617 static int me_icc_set_clock_enables(u32 mask
)
619 struct icc_clock_enables_msg clk
= {
620 .clock_enables
= 0, /* Turn off specified clocks */
622 .no_response
= 1, /* Do not expect response */
624 struct icc_header icc
= {
625 .api_version
= ICC_API_VERSION_LYNXPOINT
,
626 .icc_command
= ICC_SET_CLOCK_ENABLES
,
627 .length
= sizeof(clk
),
630 /* Send request and wait for response */
631 if (mei_sendrecv_icc(&icc
, &clk
, sizeof(clk
), NULL
, 0) < 0) {
632 printk(BIOS_ERR
, "ME: ICC SET CLOCK ENABLES message failed\n");
635 printk(BIOS_INFO
, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask
);
639 /* Determine the path that we should take based on ME status */
640 static me_bios_path
intel_me_path(struct device
*dev
)
642 me_bios_path path
= ME_DISABLE_BIOS_PATH
;
646 /* Check and dump status */
649 pci_read_dword_ptr(dev
, &hfs
, PCI_ME_HFS
);
650 pci_read_dword_ptr(dev
, &hfs2
, PCI_ME_HFS2
);
652 /* Check Current Working State */
653 switch (hfs
.working_state
) {
654 case ME_HFS_CWS_NORMAL
:
655 path
= ME_NORMAL_BIOS_PATH
;
658 path
= ME_RECOVERY_BIOS_PATH
;
661 path
= ME_DISABLE_BIOS_PATH
;
665 /* Check Current Operation Mode */
666 switch (hfs
.operation_mode
) {
667 case ME_HFS_MODE_NORMAL
:
669 case ME_HFS_MODE_DEBUG
:
670 case ME_HFS_MODE_DIS
:
671 case ME_HFS_MODE_OVER_JMPR
:
672 case ME_HFS_MODE_OVER_MEI
:
674 path
= ME_DISABLE_BIOS_PATH
;
678 /* Check for any error code and valid firmware and MBP */
679 if (hfs
.error_code
|| hfs
.fpt_bad
)
680 path
= ME_ERROR_BIOS_PATH
;
682 /* Check if the MBP is ready */
684 printk(BIOS_CRIT
, "%s: mbp is not ready!\n",
686 path
= ME_ERROR_BIOS_PATH
;
689 if (CONFIG(ELOG
) && path
!= ME_NORMAL_BIOS_PATH
) {
690 struct elog_event_data_me_extended data
= {
691 .current_working_state
= hfs
.working_state
,
692 .operation_state
= hfs
.operation_state
,
693 .operation_mode
= hfs
.operation_mode
,
694 .error_code
= hfs
.error_code
,
695 .progress_code
= hfs2
.progress_code
,
696 .current_pmevent
= hfs2
.current_pmevent
,
697 .current_state
= hfs2
.current_state
,
699 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE
, path
);
700 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT
,
701 &data
, sizeof(data
));
707 /* Prepare ME for MEI messages */
708 static int intel_mei_setup(struct device
*dev
)
710 struct resource
*res
;
713 /* Find the MMIO base for the ME interface */
714 res
= probe_resource(dev
, PCI_BASE_ADDRESS_0
);
715 if (!res
|| res
->base
== 0 || res
->size
== 0) {
716 printk(BIOS_DEBUG
, "ME: MEI resource not present!\n");
719 mei_base_address
= res2mmio(res
, 0, 0);
721 /* Ensure Memory and Bus Master bits are set */
722 pci_or_config16(dev
, PCI_COMMAND
, PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
);
724 /* Clean up status for next message */
725 read_host_csr(&host
);
726 host
.interrupt_generate
= 1;
729 write_host_csr(&host
);
734 /* Read the Extend register hash of ME firmware */
735 static int intel_me_extend_valid(struct device
*dev
)
737 struct me_heres status
;
741 pci_read_dword_ptr(dev
, &status
, PCI_ME_HERES
);
742 if (!status
.extend_feature_present
) {
743 printk(BIOS_ERR
, "ME: Extend Feature not present\n");
747 if (!status
.extend_reg_valid
) {
748 printk(BIOS_ERR
, "ME: Extend Register not valid\n");
752 switch (status
.extend_reg_algorithm
) {
753 case PCI_ME_EXT_SHA1
:
755 printk(BIOS_DEBUG
, "ME: Extend SHA-1: ");
757 case PCI_ME_EXT_SHA256
:
759 printk(BIOS_DEBUG
, "ME: Extend SHA-256: ");
762 printk(BIOS_ERR
, "ME: Extend Algorithm %d unknown\n",
763 status
.extend_reg_algorithm
);
767 for (i
= 0; i
< count
; ++i
) {
768 extend
[i
] = pci_read_config32(dev
, PCI_ME_HER(i
));
769 printk(BIOS_DEBUG
, "%08x", extend
[i
]);
771 printk(BIOS_DEBUG
, "\n");
773 /* Save hash in NVS for the OS to verify */
774 if (CONFIG(CHROMEOS_NVS
))
775 chromeos_set_me_hash(extend
, count
);
780 static void intel_me_print_mbp(me_bios_payload
*mbp_data
)
782 me_print_fw_version(mbp_data
->fw_version_name
);
784 if (CONFIG(DEBUG_INTEL_ME
))
785 me_print_fwcaps(mbp_data
->fw_capabilities
);
787 if (mbp_data
->plat_time
) {
788 printk(BIOS_DEBUG
, "ME: Wake Event to ME Reset: %u ms\n",
789 mbp_data
->plat_time
->wake_event_mrst_time_ms
);
790 printk(BIOS_DEBUG
, "ME: ME Reset to Platform Reset: %u ms\n",
791 mbp_data
->plat_time
->mrst_pltrst_time_ms
);
792 printk(BIOS_DEBUG
, "ME: Platform Reset to CPU Reset: %u ms\n",
793 mbp_data
->plat_time
->pltrst_cpurst_time_ms
);
797 static u32
me_to_host_words_pending(void)
803 return (me
.buffer_write_ptr
- me
.buffer_read_ptr
) &
804 (me
.buffer_depth
- 1);
813 * Read and print ME MBP data
815 * Return -1 to indicate a problem (give up)
816 * Return 0 to indicate success (send LOCK+EOP)
817 * Return 1 to indicate success (send LOCK+EOP with NOACK)
819 static int intel_me_read_mbp(me_bios_payload
*mbp_data
, struct device
*dev
)
825 struct mbp_payload
*mbp
;
829 pci_read_dword_ptr(dev
, &hfs2
, PCI_ME_HFS2
);
832 printk(BIOS_ERR
, "ME: MBP not ready\n");
833 intel_me_mbp_give_up(dev
);
837 me2host_pending
= me_to_host_words_pending();
838 if (!me2host_pending
) {
839 printk(BIOS_ERR
, "ME: no mbp data!\n");
840 intel_me_mbp_give_up(dev
);
844 /* we know for sure that at least the header is there */
845 mei_read_dword_ptr(&mbp_hdr
, MEI_ME_CB_RW
);
847 if ((mbp_hdr
.num_entries
> (mbp_hdr
.mbp_size
/ 2)) ||
848 (me2host_pending
< mbp_hdr
.mbp_size
)) {
849 printk(BIOS_ERR
, "ME: mbp of %d entries, total size %d words"
850 " buffer contains %d words\n",
851 mbp_hdr
.num_entries
, mbp_hdr
.mbp_size
,
853 intel_me_mbp_give_up(dev
);
856 mbp
= malloc(mbp_hdr
.mbp_size
* sizeof(u32
));
858 intel_me_mbp_give_up(dev
);
862 mbp
->header
= mbp_hdr
;
866 while (i
!= me2host_pending
) {
867 mei_read_dword_ptr(&mbp
->data
[i
], MEI_ME_CB_RW
);
871 read_host_csr(&host
);
873 /* Check that read and write pointers are equal. */
874 if (host
.buffer_read_ptr
!= host
.buffer_write_ptr
) {
875 printk(BIOS_INFO
, "ME: MBP Read/Write pointer mismatch\n");
876 printk(BIOS_INFO
, "ME: MBP Waiting for MBP cleared flag\n");
878 /* Tell ME that the host has finished reading the MBP. */
879 host
.interrupt_generate
= 1;
881 write_host_csr(&host
);
883 /* Wait for the mbp_cleared indicator. */
884 intel_me_mbp_clear(dev
);
886 /* Indicate NOACK messages should be used. */
890 /* Dump out the MBP contents. */
891 if (CONFIG(DEBUG_INTEL_ME
)) {
892 printk(BIOS_INFO
, "ME MBP: Header: items: %d, size dw: %d\n",
893 mbp
->header
.num_entries
, mbp
->header
.mbp_size
);
894 for (i
= 0; i
< mbp
->header
.mbp_size
- 1; i
++)
895 printk(BIOS_INFO
, "ME MBP: %04x: 0x%08x\n", i
, mbp
->data
[i
]);
898 #define ASSIGN_FIELD_PTR(field_, val_) \
900 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
904 /* Setup the pointers in the me_bios_payload structure. */
905 for (i
= 0; i
< mbp
->header
.mbp_size
- 1;) {
906 mbp_item_header
*item
= (void *)&mbp
->data
[i
];
908 switch (MBP_MAKE_IDENT(item
->app_id
, item
->item_id
)) {
909 case MBP_IDENT(KERNEL
, FW_VER
):
910 ASSIGN_FIELD_PTR(fw_version_name
, &mbp
->data
[i
+1]);
912 case MBP_IDENT(ICC
, PROFILE
):
913 ASSIGN_FIELD_PTR(icc_profile
, &mbp
->data
[i
+1]);
915 case MBP_IDENT(INTEL_AT
, STATE
):
916 ASSIGN_FIELD_PTR(at_state
, &mbp
->data
[i
+1]);
918 case MBP_IDENT(KERNEL
, FW_CAP
):
919 ASSIGN_FIELD_PTR(fw_capabilities
, &mbp
->data
[i
+1]);
921 case MBP_IDENT(KERNEL
, ROM_BIST
):
922 ASSIGN_FIELD_PTR(rom_bist_data
, &mbp
->data
[i
+1]);
924 case MBP_IDENT(KERNEL
, PLAT_KEY
):
925 ASSIGN_FIELD_PTR(platform_key
, &mbp
->data
[i
+1]);
927 case MBP_IDENT(KERNEL
, FW_TYPE
):
928 ASSIGN_FIELD_PTR(fw_plat_type
, &mbp
->data
[i
+1]);
930 case MBP_IDENT(KERNEL
, MFS_FAILURE
):
931 ASSIGN_FIELD_PTR(mfsintegrity
, &mbp
->data
[i
+1]);
933 case MBP_IDENT(KERNEL
, PLAT_TIME
):
934 ASSIGN_FIELD_PTR(plat_time
, &mbp
->data
[i
+1]);
936 case MBP_IDENT(NFC
, SUPPORT_DATA
):
937 ASSIGN_FIELD_PTR(nfc_data
, &mbp
->data
[i
+1]);
941 #undef ASSIGN_FIELD_PTR
947 /* Check whether ME is present and do basic init */
948 static void intel_me_init(struct device
*dev
)
950 const struct soc_intel_broadwell_pch_config
*config
= config_of(dev
);
951 me_bios_path path
= intel_me_path(dev
);
952 me_bios_payload mbp_data
;
957 /* Do initial setup and determine the BIOS path */
958 printk(BIOS_NOTICE
, "ME: BIOS path: %s\n", me_bios_path_values
[path
]);
960 if (path
== ME_NORMAL_BIOS_PATH
) {
961 /* Validate the extend register */
962 intel_me_extend_valid(dev
);
965 memset(&mbp_data
, 0, sizeof(mbp_data
));
968 * According to the ME9 BWG, BIOS is required to fetch MBP data in
969 * all boot flows except S3 Resume.
972 /* Prepare MEI MMIO interface */
973 if (intel_mei_setup(dev
) < 0)
976 /* Read ME MBP data */
977 mbp_ret
= intel_me_read_mbp(&mbp_data
, dev
);
980 intel_me_print_mbp(&mbp_data
);
982 /* Set clock enables according to devicetree */
983 if (config
->icc_clock_disable
)
984 me_icc_set_clock_enables(config
->icc_clock_disable
);
986 /* Make sure ME is in a mode that expects EOP */
987 pci_read_dword_ptr(dev
, &hfs
, PCI_ME_HFS
);
989 /* Abort and leave device alone if not normal mode */
991 hfs
.working_state
!= ME_HFS_CWS_NORMAL
||
992 hfs
.operation_mode
!= ME_HFS_MODE_NORMAL
)
997 * MBP Cleared wait is skipped,
998 * Do not expect ACK and reset when complete.
1001 /* Send HMRFPO Lock command, no response */
1002 mkhi_hmrfpo_lock_noack();
1004 /* Send END OF POST command, no response */
1005 mkhi_end_of_post_noack();
1007 /* Assert reset and interrupt */
1008 read_host_csr(&csr
);
1009 csr
.interrupt_generate
= 1;
1011 write_host_csr(&csr
);
1014 * MBP Cleared wait was not skipped
1017 /* Send HMRFPO LOCK command */
1020 /* Send EOP command so ME stops accepting other commands */
1025 static void intel_me_enable(struct device
*dev
)
1027 /* Avoid talking to the device in S3 path */
1028 if (acpi_is_wakeup_s3() && CONFIG(DISABLE_ME_PCI
)) {
1030 pch_disable_devfn(dev
);
1034 static struct device_operations device_ops
= {
1035 .read_resources
= &pci_dev_read_resources
,
1036 .set_resources
= &pci_dev_set_resources
,
1037 .enable_resources
= &pci_dev_enable_resources
,
1038 .enable
= &intel_me_enable
,
1039 .init
= &intel_me_init
,
1040 .final
= &intel_me_finalize
,
1041 .ops_pci
= &pci_dev_ops_pci
,
1044 static const unsigned short pci_device_ids
[] = {
1045 0x9c3a, /* Low Power */
1046 0x9cba, /* WildcatPoint */
1050 static const struct pci_driver intel_me __pci_driver
= {
1052 .vendor
= PCI_VID_INTEL
,
1053 .devices
= pci_device_ids
,