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>
18 #include <device/pci_def.h>
26 #include <soc/pci_devs.h>
28 #include <soc/intel/broadwell/pch/chip.h>
30 #include <vendorcode/google/chromeos/chromeos.h>
32 /* Path that the BIOS should take based on ME state */
33 static const char *me_bios_path_values
[] = {
34 [ME_NORMAL_BIOS_PATH
] = "Normal",
35 [ME_S3WAKE_BIOS_PATH
] = "S3 Wake",
36 [ME_ERROR_BIOS_PATH
] = "Error",
37 [ME_RECOVERY_BIOS_PATH
] = "Recovery",
38 [ME_DISABLE_BIOS_PATH
] = "Disable",
39 [ME_FIRMWARE_UPDATE_BIOS_PATH
] = "Firmware Update",
42 /* MMIO base address for MEI interface */
43 static u8
*mei_base_address
;
45 static void mei_dump(void *ptr
, int dword
, int offset
, const char *type
)
49 if (!CONFIG(DEBUG_INTEL_ME
))
52 printk(BIOS_SPEW
, "%-9s[%02x] : ", type
, offset
);
59 printk(BIOS_SPEW
, "ERROR: 0x%08x\n", dword
);
62 printk(BIOS_SPEW
, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
63 "reset=%u ig=%u is=%u ie=%u\n", csr
->buffer_depth
,
64 csr
->buffer_read_ptr
, csr
->buffer_write_ptr
,
65 csr
->ready
, csr
->reset
, csr
->interrupt_generate
,
66 csr
->interrupt_status
, csr
->interrupt_enable
);
70 printk(BIOS_SPEW
, "CB: 0x%08x\n", dword
);
73 printk(BIOS_SPEW
, "0x%08x\n", offset
);
79 * ME/MEI access helpers using memcpy to avoid aliasing.
82 static inline void mei_read_dword_ptr(void *ptr
, int offset
)
84 u32 dword
= read32(mei_base_address
+ offset
);
85 memcpy(ptr
, &dword
, sizeof(dword
));
86 mei_dump(ptr
, dword
, offset
, "READ");
89 static inline void mei_write_dword_ptr(void *ptr
, int offset
)
92 memcpy(&dword
, ptr
, sizeof(dword
));
93 write32(mei_base_address
+ offset
, dword
);
94 mei_dump(ptr
, dword
, offset
, "WRITE");
97 static inline void pci_read_dword_ptr(struct device
*dev
, void *ptr
, int offset
)
99 u32 dword
= pci_read_config32(dev
, offset
);
100 memcpy(ptr
, &dword
, sizeof(dword
));
101 mei_dump(ptr
, dword
, offset
, "PCI READ");
104 static inline void read_host_csr(struct mei_csr
*csr
)
106 mei_read_dword_ptr(csr
, MEI_H_CSR
);
109 static inline void write_host_csr(struct mei_csr
*csr
)
111 mei_write_dword_ptr(csr
, MEI_H_CSR
);
114 static inline void read_me_csr(struct mei_csr
*csr
)
116 mei_read_dword_ptr(csr
, MEI_ME_CSR_HA
);
119 static inline void write_cb(u32 dword
)
121 write32(mei_base_address
+ MEI_H_CB_WW
, dword
);
122 mei_dump(NULL
, dword
, MEI_H_CB_WW
, "WRITE");
125 static inline u32
read_cb(void)
127 u32 dword
= read32(mei_base_address
+ MEI_ME_CB_RW
);
128 mei_dump(NULL
, dword
, MEI_ME_CB_RW
, "READ");
132 /* Wait for ME ready bit to be asserted */
133 static int mei_wait_for_me_ready(void)
136 unsigned int try = ME_RETRY
;
145 printk(BIOS_ERR
, "ME: failed to become ready\n");
149 static void mei_reset(void)
153 if (mei_wait_for_me_ready() < 0)
156 /* Reset host and ME circular buffers for next message */
157 read_host_csr(&host
);
159 host
.interrupt_generate
= 1;
160 write_host_csr(&host
);
162 if (mei_wait_for_me_ready() < 0)
165 /* Re-init and indicate host is ready */
166 read_host_csr(&host
);
167 host
.interrupt_generate
= 1;
170 write_host_csr(&host
);
173 static int mei_send_packet(struct mei_header
*mei
, void *req_data
)
176 unsigned int ndata
, n
;
179 /* Number of dwords to write */
180 ndata
= mei
->length
>> 2;
182 /* Pad non-dword aligned request message length */
186 printk(BIOS_DEBUG
, "ME: request has no data\n");
189 ndata
++; /* Add MEI header */
192 * Make sure there is still room left in the circular buffer.
193 * Reset the buffer pointers if the requested message will not fit.
195 read_host_csr(&host
);
196 if ((host
.buffer_depth
- host
.buffer_write_ptr
) < ndata
) {
197 printk(BIOS_ERR
, "ME: circular buffer full, resetting...\n");
199 read_host_csr(&host
);
202 /* Ensure the requested length will fit in the circular buffer. */
203 if ((host
.buffer_depth
- host
.buffer_write_ptr
) < ndata
) {
204 printk(BIOS_ERR
, "ME: message (%u) too large for buffer (%u)\n",
205 ndata
+ 2, host
.buffer_depth
);
209 /* Write MEI header */
210 mei_write_dword_ptr(mei
, MEI_H_CB_WW
);
213 /* Write message data */
215 for (n
= 0; n
< ndata
; ++n
)
218 /* Generate interrupt to the ME */
219 read_host_csr(&host
);
220 host
.interrupt_generate
= 1;
221 write_host_csr(&host
);
223 /* Make sure ME is ready after sending request data */
224 return mei_wait_for_me_ready();
227 static int mei_send_data(u8 me_address
, u8 host_address
,
228 void *req_data
, int req_bytes
)
230 struct mei_header header
= {
231 .client_address
= me_address
,
232 .host_address
= host_address
,
236 u8
*req_ptr
= req_data
;
238 while (!header
.is_complete
) {
239 int remain
= req_bytes
- current
;
242 read_host_csr(&host
);
243 buf_len
= host
.buffer_depth
- host
.buffer_write_ptr
;
245 if (buf_len
> remain
) {
246 /* Send all remaining data as final message */
247 header
.length
= req_bytes
- current
;
248 header
.is_complete
= 1;
250 /* Send as much data as the buffer can hold */
251 header
.length
= buf_len
;
254 mei_send_packet(&header
, req_ptr
);
256 req_ptr
+= header
.length
;
257 current
+= header
.length
;
263 static int mei_send_header(u8 me_address
, u8 host_address
,
264 void *header
, int header_len
, int complete
)
266 struct mei_header mei
= {
267 .client_address
= me_address
,
268 .host_address
= host_address
,
269 .length
= header_len
,
270 .is_complete
= complete
,
272 return mei_send_packet(&mei
, header
);
275 static int mei_recv_msg(void *header
, int header_bytes
,
276 void *rsp_data
, int rsp_bytes
)
278 struct mei_header mei_rsp
;
279 struct mei_csr me
, host
;
280 unsigned int ndata
, n
;
281 unsigned int expected
;
284 /* Total number of dwords to read from circular buffer */
285 expected
= (rsp_bytes
+ sizeof(mei_rsp
) + header_bytes
) >> 2;
289 if (mei_wait_for_me_ready() < 0)
293 * The interrupt status bit does not appear to indicate that the
294 * message has actually been received. Instead we wait until the
295 * expected number of dwords are present in the circular buffer.
297 for (n
= ME_RETRY
; n
; --n
) {
299 if ((me
.buffer_write_ptr
- me
.buffer_read_ptr
) >= expected
)
304 printk(BIOS_ERR
, "ME: timeout waiting for data: expected "
305 "%u, available %u\n", expected
,
306 me
.buffer_write_ptr
- me
.buffer_read_ptr
);
310 /* Read and verify MEI response header from the ME */
311 mei_read_dword_ptr(&mei_rsp
, MEI_ME_CB_RW
);
312 if (!mei_rsp
.is_complete
) {
313 printk(BIOS_ERR
, "ME: response is not complete\n");
317 /* Handle non-dword responses and expect at least the header */
318 ndata
= mei_rsp
.length
>> 2;
319 if (mei_rsp
.length
& 3)
321 if (ndata
!= (expected
- 1)) {
322 printk(BIOS_ERR
, "ME: response is missing data %d != %d\n",
323 ndata
, (expected
- 1));
327 /* Read response header from the ME */
329 for (n
= 0; n
< (header_bytes
>> 2); ++n
)
331 ndata
-= header_bytes
>> 2;
333 /* Make sure caller passed a buffer with enough space */
334 if (ndata
!= (rsp_bytes
>> 2)) {
335 printk(BIOS_ERR
, "ME: not enough room in response buffer: "
336 "%u != %u\n", ndata
, rsp_bytes
>> 2);
340 /* Read response data from the circular buffer */
342 for (n
= 0; n
< ndata
; ++n
)
345 /* Tell the ME that we have consumed the response */
346 read_host_csr(&host
);
347 host
.interrupt_status
= 1;
348 host
.interrupt_generate
= 1;
349 write_host_csr(&host
);
351 return mei_wait_for_me_ready();
354 static inline int mei_sendrecv_mkhi(struct mkhi_header
*mkhi
,
355 void *req_data
, int req_bytes
,
356 void *rsp_data
, int rsp_bytes
)
358 struct mkhi_header mkhi_rsp
;
361 if (mei_send_header(MEI_ADDRESS_MKHI
, MEI_HOST_ADDRESS
,
362 mkhi
, sizeof(*mkhi
), req_bytes
? 0 : 1) < 0)
365 /* Send data if available */
366 if (req_bytes
&& mei_send_data(MEI_ADDRESS_MKHI
, MEI_HOST_ADDRESS
,
367 req_data
, req_bytes
) < 0)
370 /* Return now if no response expected */
374 /* Read header and data */
375 if (mei_recv_msg(&mkhi_rsp
, sizeof(mkhi_rsp
),
376 rsp_data
, rsp_bytes
) < 0)
379 if (!mkhi_rsp
.is_response
||
380 mkhi
->group_id
!= mkhi_rsp
.group_id
||
381 mkhi
->command
!= mkhi_rsp
.command
) {
382 printk(BIOS_ERR
, "ME: invalid response, group %u ?= %u,"
383 "command %u ?= %u, is_response %u\n", mkhi
->group_id
,
384 mkhi_rsp
.group_id
, mkhi
->command
, mkhi_rsp
.command
,
385 mkhi_rsp
.is_response
);
392 static inline int mei_sendrecv_icc(struct icc_header
*icc
,
393 void *req_data
, int req_bytes
,
394 void *rsp_data
, int rsp_bytes
)
396 struct icc_header icc_rsp
;
399 if (mei_send_header(MEI_ADDRESS_ICC
, MEI_HOST_ADDRESS
,
400 icc
, sizeof(*icc
), req_bytes
? 0 : 1) < 0)
403 /* Send data if available */
404 if (req_bytes
&& mei_send_data(MEI_ADDRESS_ICC
, MEI_HOST_ADDRESS
,
405 req_data
, req_bytes
) < 0)
408 /* Read header and data, if needed */
409 if (rsp_bytes
&& mei_recv_msg(&icc_rsp
, sizeof(icc_rsp
),
410 rsp_data
, rsp_bytes
) < 0)
417 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
418 * state machine on the BIOS end doesn't match the ME's state machine.
420 static void intel_me_mbp_give_up(struct device
*dev
)
424 pci_write_config32(dev
, PCI_ME_H_GS2
, PCI_ME_MBP_GIVE_UP
);
428 csr
.interrupt_generate
= 1;
429 write_host_csr(&csr
);
433 * mbp clear routine. This will wait for the ME to indicate that
434 * the MBP has been read and cleared.
436 static void intel_me_mbp_clear(struct device
*dev
)
441 /* Wait for the mbp_cleared indicator */
442 for (count
= ME_RETRY
; count
> 0; --count
) {
443 pci_read_dword_ptr(dev
, &hfs2
, PCI_ME_HFS2
);
444 if (hfs2
.mbp_cleared
)
450 printk(BIOS_WARNING
, "ME: Timeout waiting for mbp_cleared\n");
451 intel_me_mbp_give_up(dev
);
453 printk(BIOS_INFO
, "ME: MBP cleared\n");
457 static void me_print_fw_version(mbp_fw_version_name
*vers_name
)
460 printk(BIOS_ERR
, "ME: mbp missing version report\n");
464 printk(BIOS_DEBUG
, "ME: found version %d.%d.%d.%d\n",
465 vers_name
->major_version
, vers_name
->minor_version
,
466 vers_name
->hotfix_version
, vers_name
->build_version
);
469 static inline void print_cap(const char *name
, int state
)
471 printk(BIOS_DEBUG
, "ME Capability: %-41s : %sabled\n",
472 name
, state
? " en" : "dis");
475 /* Get ME Firmware Capabilities */
476 static int mkhi_get_fwcaps(mbp_mefwcaps
*cap
)
479 struct me_fwcaps cap_msg
;
480 struct mkhi_header mkhi
= {
481 .group_id
= MKHI_GROUP_ID_FWCAPS
,
482 .command
= MKHI_FWCAPS_GET_RULE
,
485 /* Send request and wait for response */
486 if (mei_sendrecv_mkhi(&mkhi
, &rule_id
, sizeof(u32
),
487 &cap_msg
, sizeof(cap_msg
)) < 0) {
488 printk(BIOS_ERR
, "ME: GET FWCAPS message failed\n");
491 *cap
= cap_msg
.caps_sku
;
495 /* Get ME Firmware Capabilities */
496 static void me_print_fwcaps(mbp_mefwcaps
*cap
)
498 mbp_mefwcaps local_caps
;
501 printk(BIOS_ERR
, "ME: mbp missing fwcaps report\n");
502 if (mkhi_get_fwcaps(cap
))
506 print_cap("Full Network manageability", cap
->full_net
);
507 print_cap("Regular Network manageability", cap
->std_net
);
508 print_cap("Manageability", cap
->manageability
);
509 print_cap("IntelR Anti-Theft (AT)", cap
->intel_at
);
510 print_cap("IntelR Capability Licensing Service (CLS)", cap
->intel_cls
);
511 print_cap("IntelR Power Sharing Technology (MPC)", cap
->intel_mpc
);
512 print_cap("ICC Over Clocking", cap
->icc_over_clocking
);
513 print_cap("Protected Audio Video Path (PAVP)", cap
->pavp
);
514 print_cap("IPV6", cap
->ipv6
);
515 print_cap("KVM Remote Control (KVM)", cap
->kvm
);
516 print_cap("Outbreak Containment Heuristic (OCH)", cap
->och
);
517 print_cap("Virtual LAN (VLAN)", cap
->vlan
);
518 print_cap("TLS", cap
->tls
);
519 print_cap("Wireless LAN (WLAN)", cap
->wlan
);
522 /* Send END OF POST message to the ME */
523 static int mkhi_end_of_post(void)
525 struct mkhi_header mkhi
= {
526 .group_id
= MKHI_GROUP_ID_GEN
,
527 .command
= MKHI_END_OF_POST
,
531 /* Send request and wait for response */
532 if (mei_sendrecv_mkhi(&mkhi
, NULL
, 0, &eop_ack
, sizeof(eop_ack
)) < 0) {
533 printk(BIOS_ERR
, "ME: END OF POST message failed\n");
537 printk(BIOS_INFO
, "ME: END OF POST message successful (%d)\n", eop_ack
);
541 /* Send END OF POST message to the ME */
542 static int mkhi_end_of_post_noack(void)
544 struct mkhi_header mkhi
= {
545 .group_id
= MKHI_GROUP_ID_GEN
,
546 .command
= MKHI_END_OF_POST_NOACK
,
549 /* Send request, do not wait for response */
550 if (mei_sendrecv_mkhi(&mkhi
, NULL
, 0, NULL
, 0) < 0) {
551 printk(BIOS_ERR
, "ME: END OF POST NOACK message failed\n");
555 printk(BIOS_INFO
, "ME: END OF POST NOACK message successful\n");
559 /* Send HMRFPO LOCK message to the ME */
560 static int mkhi_hmrfpo_lock(void)
562 struct mkhi_header mkhi
= {
563 .group_id
= MKHI_GROUP_ID_HMRFPO
,
564 .command
= MKHI_HMRFPO_LOCK
,
568 /* Send request and wait for response */
569 if (mei_sendrecv_mkhi(&mkhi
, NULL
, 0, &ack
, sizeof(ack
)) < 0) {
570 printk(BIOS_ERR
, "ME: HMRFPO LOCK message failed\n");
574 printk(BIOS_INFO
, "ME: HMRFPO LOCK message successful (%d)\n", ack
);
578 /* Send HMRFPO LOCK message to the ME, do not wait for response */
579 static int mkhi_hmrfpo_lock_noack(void)
581 struct mkhi_header mkhi
= {
582 .group_id
= MKHI_GROUP_ID_HMRFPO
,
583 .command
= MKHI_HMRFPO_LOCK_NOACK
,
586 /* Send request, do not wait for response */
587 if (mei_sendrecv_mkhi(&mkhi
, NULL
, 0, NULL
, 0) < 0) {
588 printk(BIOS_ERR
, "ME: HMRFPO LOCK NOACK message failed\n");
592 printk(BIOS_INFO
, "ME: HMRFPO LOCK NOACK message successful\n");
596 static void intel_me_finalize(struct device
*dev
)
600 /* S3 path will have hidden this device already */
601 if (!mei_base_address
|| mei_base_address
== (u8
*) 0xfffffff0)
604 /* Make sure IO is disabled */
605 reg16
= pci_read_config16(dev
, PCI_COMMAND
);
606 reg16
&= ~(PCI_COMMAND_MASTER
|
607 PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
);
608 pci_write_config16(dev
, PCI_COMMAND
, reg16
);
610 /* Hide the PCI device */
611 RCBA32_OR(FD2
, PCH_DISABLE_MEI1
);
615 static int me_icc_set_clock_enables(u32 mask
)
617 struct icc_clock_enables_msg clk
= {
618 .clock_enables
= 0, /* Turn off specified clocks */
620 .no_response
= 1, /* Do not expect response */
622 struct icc_header icc
= {
623 .api_version
= ICC_API_VERSION_LYNXPOINT
,
624 .icc_command
= ICC_SET_CLOCK_ENABLES
,
625 .length
= sizeof(clk
),
628 /* Send request and wait for response */
629 if (mei_sendrecv_icc(&icc
, &clk
, sizeof(clk
), NULL
, 0) < 0) {
630 printk(BIOS_ERR
, "ME: ICC SET CLOCK ENABLES message failed\n");
633 printk(BIOS_INFO
, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask
);
637 /* Determine the path that we should take based on ME status */
638 static me_bios_path
intel_me_path(struct device
*dev
)
640 me_bios_path path
= ME_DISABLE_BIOS_PATH
;
644 /* Check and dump status */
647 pci_read_dword_ptr(dev
, &hfs
, PCI_ME_HFS
);
648 pci_read_dword_ptr(dev
, &hfs2
, PCI_ME_HFS2
);
650 /* Check Current Working State */
651 switch (hfs
.working_state
) {
652 case ME_HFS_CWS_NORMAL
:
653 path
= ME_NORMAL_BIOS_PATH
;
656 path
= ME_RECOVERY_BIOS_PATH
;
659 path
= ME_DISABLE_BIOS_PATH
;
663 /* Check Current Operation Mode */
664 switch (hfs
.operation_mode
) {
665 case ME_HFS_MODE_NORMAL
:
667 case ME_HFS_MODE_DEBUG
:
668 case ME_HFS_MODE_DIS
:
669 case ME_HFS_MODE_OVER_JMPR
:
670 case ME_HFS_MODE_OVER_MEI
:
672 path
= ME_DISABLE_BIOS_PATH
;
676 /* Check for any error code and valid firmware and MBP */
677 if (hfs
.error_code
|| hfs
.fpt_bad
)
678 path
= ME_ERROR_BIOS_PATH
;
680 /* Check if the MBP is ready */
682 printk(BIOS_CRIT
, "%s: mbp is not ready!\n",
684 path
= ME_ERROR_BIOS_PATH
;
687 if (CONFIG(ELOG
) && path
!= ME_NORMAL_BIOS_PATH
) {
688 struct elog_event_data_me_extended data
= {
689 .current_working_state
= hfs
.working_state
,
690 .operation_state
= hfs
.operation_state
,
691 .operation_mode
= hfs
.operation_mode
,
692 .error_code
= hfs
.error_code
,
693 .progress_code
= hfs2
.progress_code
,
694 .current_pmevent
= hfs2
.current_pmevent
,
695 .current_state
= hfs2
.current_state
,
697 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE
, path
);
698 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT
,
699 &data
, sizeof(data
));
705 /* Prepare ME for MEI messages */
706 static int intel_mei_setup(struct device
*dev
)
708 struct resource
*res
;
711 /* Find the MMIO base for the ME interface */
712 res
= find_resource(dev
, PCI_BASE_ADDRESS_0
);
713 if (!res
|| res
->base
== 0 || res
->size
== 0) {
714 printk(BIOS_DEBUG
, "ME: MEI resource not present!\n");
717 mei_base_address
= res2mmio(res
, 0, 0);
719 /* Ensure Memory and Bus Master bits are set */
720 pci_or_config16(dev
, PCI_COMMAND
, PCI_COMMAND_MASTER
| PCI_COMMAND_MEMORY
);
722 /* Clean up status for next message */
723 read_host_csr(&host
);
724 host
.interrupt_generate
= 1;
727 write_host_csr(&host
);
732 /* Read the Extend register hash of ME firmware */
733 static int intel_me_extend_valid(struct device
*dev
)
735 struct me_heres status
;
739 pci_read_dword_ptr(dev
, &status
, PCI_ME_HERES
);
740 if (!status
.extend_feature_present
) {
741 printk(BIOS_ERR
, "ME: Extend Feature not present\n");
745 if (!status
.extend_reg_valid
) {
746 printk(BIOS_ERR
, "ME: Extend Register not valid\n");
750 switch (status
.extend_reg_algorithm
) {
751 case PCI_ME_EXT_SHA1
:
753 printk(BIOS_DEBUG
, "ME: Extend SHA-1: ");
755 case PCI_ME_EXT_SHA256
:
757 printk(BIOS_DEBUG
, "ME: Extend SHA-256: ");
760 printk(BIOS_ERR
, "ME: Extend Algorithm %d unknown\n",
761 status
.extend_reg_algorithm
);
765 for (i
= 0; i
< count
; ++i
) {
766 extend
[i
] = pci_read_config32(dev
, PCI_ME_HER(i
));
767 printk(BIOS_DEBUG
, "%08x", extend
[i
]);
769 printk(BIOS_DEBUG
, "\n");
771 /* Save hash in NVS for the OS to verify */
772 if (CONFIG(CHROMEOS_NVS
))
773 chromeos_set_me_hash(extend
, count
);
778 static void intel_me_print_mbp(me_bios_payload
*mbp_data
)
780 me_print_fw_version(mbp_data
->fw_version_name
);
782 if (CONFIG(DEBUG_INTEL_ME
))
783 me_print_fwcaps(mbp_data
->fw_capabilities
);
785 if (mbp_data
->plat_time
) {
786 printk(BIOS_DEBUG
, "ME: Wake Event to ME Reset: %u ms\n",
787 mbp_data
->plat_time
->wake_event_mrst_time_ms
);
788 printk(BIOS_DEBUG
, "ME: ME Reset to Platform Reset: %u ms\n",
789 mbp_data
->plat_time
->mrst_pltrst_time_ms
);
790 printk(BIOS_DEBUG
, "ME: Platform Reset to CPU Reset: %u ms\n",
791 mbp_data
->plat_time
->pltrst_cpurst_time_ms
);
795 static u32
me_to_host_words_pending(void)
801 return (me
.buffer_write_ptr
- me
.buffer_read_ptr
) &
802 (me
.buffer_depth
- 1);
811 * Read and print ME MBP data
813 * Return -1 to indicate a problem (give up)
814 * Return 0 to indicate success (send LOCK+EOP)
815 * Return 1 to indicate success (send LOCK+EOP with NOACK)
817 static int intel_me_read_mbp(me_bios_payload
*mbp_data
, struct device
*dev
)
823 struct mbp_payload
*mbp
;
827 pci_read_dword_ptr(dev
, &hfs2
, PCI_ME_HFS2
);
830 printk(BIOS_ERR
, "ME: MBP not ready\n");
831 intel_me_mbp_give_up(dev
);
835 me2host_pending
= me_to_host_words_pending();
836 if (!me2host_pending
) {
837 printk(BIOS_ERR
, "ME: no mbp data!\n");
838 intel_me_mbp_give_up(dev
);
842 /* we know for sure that at least the header is there */
843 mei_read_dword_ptr(&mbp_hdr
, MEI_ME_CB_RW
);
845 if ((mbp_hdr
.num_entries
> (mbp_hdr
.mbp_size
/ 2)) ||
846 (me2host_pending
< mbp_hdr
.mbp_size
)) {
847 printk(BIOS_ERR
, "ME: mbp of %d entries, total size %d words"
848 " buffer contains %d words\n",
849 mbp_hdr
.num_entries
, mbp_hdr
.mbp_size
,
851 intel_me_mbp_give_up(dev
);
854 mbp
= malloc(mbp_hdr
.mbp_size
* sizeof(u32
));
856 intel_me_mbp_give_up(dev
);
860 mbp
->header
= mbp_hdr
;
864 while (i
!= me2host_pending
) {
865 mei_read_dword_ptr(&mbp
->data
[i
], MEI_ME_CB_RW
);
869 read_host_csr(&host
);
871 /* Check that read and write pointers are equal. */
872 if (host
.buffer_read_ptr
!= host
.buffer_write_ptr
) {
873 printk(BIOS_INFO
, "ME: MBP Read/Write pointer mismatch\n");
874 printk(BIOS_INFO
, "ME: MBP Waiting for MBP cleared flag\n");
876 /* Tell ME that the host has finished reading the MBP. */
877 host
.interrupt_generate
= 1;
879 write_host_csr(&host
);
881 /* Wait for the mbp_cleared indicator. */
882 intel_me_mbp_clear(dev
);
884 /* Indicate NOACK messages should be used. */
888 /* Dump out the MBP contents. */
889 if (CONFIG(DEBUG_INTEL_ME
)) {
890 printk(BIOS_INFO
, "ME MBP: Header: items: %d, size dw: %d\n",
891 mbp
->header
.num_entries
, mbp
->header
.mbp_size
);
892 for (i
= 0; i
< mbp
->header
.mbp_size
- 1; i
++)
893 printk(BIOS_INFO
, "ME MBP: %04x: 0x%08x\n", i
, mbp
->data
[i
]);
896 #define ASSIGN_FIELD_PTR(field_, val_) \
898 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
902 /* Setup the pointers in the me_bios_payload structure. */
903 for (i
= 0; i
< mbp
->header
.mbp_size
- 1;) {
904 mbp_item_header
*item
= (void *)&mbp
->data
[i
];
906 switch (MBP_MAKE_IDENT(item
->app_id
, item
->item_id
)) {
907 case MBP_IDENT(KERNEL
, FW_VER
):
908 ASSIGN_FIELD_PTR(fw_version_name
, &mbp
->data
[i
+1]);
910 case MBP_IDENT(ICC
, PROFILE
):
911 ASSIGN_FIELD_PTR(icc_profile
, &mbp
->data
[i
+1]);
913 case MBP_IDENT(INTEL_AT
, STATE
):
914 ASSIGN_FIELD_PTR(at_state
, &mbp
->data
[i
+1]);
916 case MBP_IDENT(KERNEL
, FW_CAP
):
917 ASSIGN_FIELD_PTR(fw_capabilities
, &mbp
->data
[i
+1]);
919 case MBP_IDENT(KERNEL
, ROM_BIST
):
920 ASSIGN_FIELD_PTR(rom_bist_data
, &mbp
->data
[i
+1]);
922 case MBP_IDENT(KERNEL
, PLAT_KEY
):
923 ASSIGN_FIELD_PTR(platform_key
, &mbp
->data
[i
+1]);
925 case MBP_IDENT(KERNEL
, FW_TYPE
):
926 ASSIGN_FIELD_PTR(fw_plat_type
, &mbp
->data
[i
+1]);
928 case MBP_IDENT(KERNEL
, MFS_FAILURE
):
929 ASSIGN_FIELD_PTR(mfsintegrity
, &mbp
->data
[i
+1]);
931 case MBP_IDENT(KERNEL
, PLAT_TIME
):
932 ASSIGN_FIELD_PTR(plat_time
, &mbp
->data
[i
+1]);
934 case MBP_IDENT(NFC
, SUPPORT_DATA
):
935 ASSIGN_FIELD_PTR(nfc_data
, &mbp
->data
[i
+1]);
939 #undef ASSIGN_FIELD_PTR
945 /* Check whether ME is present and do basic init */
946 static void intel_me_init(struct device
*dev
)
948 const struct soc_intel_broadwell_pch_config
*config
= config_of(dev
);
949 me_bios_path path
= intel_me_path(dev
);
950 me_bios_payload mbp_data
;
955 /* Do initial setup and determine the BIOS path */
956 printk(BIOS_NOTICE
, "ME: BIOS path: %s\n", me_bios_path_values
[path
]);
958 if (path
== ME_NORMAL_BIOS_PATH
) {
959 /* Validate the extend register */
960 intel_me_extend_valid(dev
);
963 memset(&mbp_data
, 0, sizeof(mbp_data
));
966 * According to the ME9 BWG, BIOS is required to fetch MBP data in
967 * all boot flows except S3 Resume.
970 /* Prepare MEI MMIO interface */
971 if (intel_mei_setup(dev
) < 0)
974 /* Read ME MBP data */
975 mbp_ret
= intel_me_read_mbp(&mbp_data
, dev
);
978 intel_me_print_mbp(&mbp_data
);
980 /* Set clock enables according to devicetree */
981 if (config
->icc_clock_disable
)
982 me_icc_set_clock_enables(config
->icc_clock_disable
);
984 /* Make sure ME is in a mode that expects EOP */
985 pci_read_dword_ptr(dev
, &hfs
, PCI_ME_HFS
);
987 /* Abort and leave device alone if not normal mode */
989 hfs
.working_state
!= ME_HFS_CWS_NORMAL
||
990 hfs
.operation_mode
!= ME_HFS_MODE_NORMAL
)
995 * MBP Cleared wait is skipped,
996 * Do not expect ACK and reset when complete.
999 /* Send HMRFPO Lock command, no response */
1000 mkhi_hmrfpo_lock_noack();
1002 /* Send END OF POST command, no response */
1003 mkhi_end_of_post_noack();
1005 /* Assert reset and interrupt */
1006 read_host_csr(&csr
);
1007 csr
.interrupt_generate
= 1;
1009 write_host_csr(&csr
);
1012 * MBP Cleared wait was not skipped
1015 /* Send HMRFPO LOCK command */
1018 /* Send EOP command so ME stops accepting other commands */
1023 static void intel_me_enable(struct device
*dev
)
1025 /* Avoid talking to the device in S3 path */
1026 if (acpi_is_wakeup_s3()) {
1028 pch_disable_devfn(dev
);
1032 static struct device_operations device_ops
= {
1033 .read_resources
= &pci_dev_read_resources
,
1034 .set_resources
= &pci_dev_set_resources
,
1035 .enable_resources
= &pci_dev_enable_resources
,
1036 .enable
= &intel_me_enable
,
1037 .init
= &intel_me_init
,
1038 .final
= &intel_me_finalize
,
1039 .ops_pci
= &pci_dev_ops_pci
,
1042 static const unsigned short pci_device_ids
[] = {
1043 0x9c3a, /* Low Power */
1044 0x9cba, /* WildcatPoint */
1048 static const struct pci_driver intel_me __pci_driver
= {
1050 .vendor
= PCI_VENDOR_ID_INTEL
,
1051 .devices
= pci_device_ids
,