blob: d182e317fa1f735518934aef18e8550b1bbcf7ed [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
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 Shaikh76cedd22020-05-02 10:24:23 -070011#include <acpi/acpi.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020012#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020013#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050014#include <console/console.h>
Stefan Reinauer24d1d4b2013-03-21 11:51:41 -070015#include <device/device.h>
16#include <device/pci.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050017#include <device/pci_ids.h>
18#include <device/pci_def.h>
19#include <string.h>
20#include <delay.h>
21#include <elog.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010022#include <halt.h>
Elyes HAOUAS400f9ca2019-06-23 07:01:22 +020023#include <stdlib.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050024
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030025#include "chip.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050026#include "me.h"
27#include "pch.h"
28
Julius Wernercd49cce2019-03-05 16:53:33 -080029#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -050030#include <vendorcode/google/chromeos/chromeos.h>
31#include <vendorcode/google/chromeos/gnvs.h>
32#endif
33
Aaron Durbin76c37002012-10-30 09:03:43 -050034/* Path that the BIOS should take based on ME state */
Angel Ponsf01884e2020-06-21 12:48:48 +020035static const char *const me_bios_path_values[] __unused = {
Aaron Durbin76c37002012-10-30 09:03:43 -050036 [ME_NORMAL_BIOS_PATH] = "Normal",
37 [ME_S3WAKE_BIOS_PATH] = "S3 Wake",
38 [ME_ERROR_BIOS_PATH] = "Error",
39 [ME_RECOVERY_BIOS_PATH] = "Recovery",
40 [ME_DISABLE_BIOS_PATH] = "Disable",
41 [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update",
42};
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010043static int intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev);
Aaron Durbin76c37002012-10-30 09:03:43 -050044
45/* MMIO base address for MEI interface */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080046static u32 *mei_base_address;
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010047#ifdef __SIMPLE_DEVICE__
48void intel_me_mbp_clear(pci_devfn_t dev);
49#else
50void intel_me_mbp_clear(struct device *dev);
51#endif
Aaron Durbin76c37002012-10-30 09:03:43 -050052
Aaron Durbin76c37002012-10-30 09:03:43 -050053static void mei_dump(void *ptr, int dword, int offset, const char *type)
54{
55 struct mei_csr *csr;
56
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +020057 if (!CONFIG(DEBUG_INTEL_ME))
58 return;
59
Aaron Durbin76c37002012-10-30 09:03:43 -050060 printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset);
61
62 switch (offset) {
63 case MEI_H_CSR:
64 case MEI_ME_CSR_HA:
65 csr = ptr;
66 if (!csr) {
67 printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword);
68 break;
69 }
70 printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
71 "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth,
72 csr->buffer_read_ptr, csr->buffer_write_ptr,
73 csr->ready, csr->reset, csr->interrupt_generate,
74 csr->interrupt_status, csr->interrupt_enable);
75 break;
76 case MEI_ME_CB_RW:
77 case MEI_H_CB_WW:
78 printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
79 break;
80 default:
81 printk(BIOS_SPEW, "0x%08x\n", offset);
82 break;
83 }
84}
Aaron Durbin76c37002012-10-30 09:03:43 -050085
86/*
87 * ME/MEI access helpers using memcpy to avoid aliasing.
88 */
89
90static inline void mei_read_dword_ptr(void *ptr, int offset)
91{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080092 u32 dword = read32(mei_base_address + (offset/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -050093 memcpy(ptr, &dword, sizeof(dword));
94 mei_dump(ptr, dword, offset, "READ");
95}
96
97static inline void mei_write_dword_ptr(void *ptr, int offset)
98{
99 u32 dword = 0;
100 memcpy(&dword, ptr, sizeof(dword));
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800101 write32(mei_base_address + (offset/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500102 mei_dump(ptr, dword, offset, "WRITE");
103}
104
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100105#ifdef __SIMPLE_DEVICE__
106static inline void pci_read_dword_ptr(pci_devfn_t dev, void *ptr, int offset)
107#else
108static inline void pci_read_dword_ptr(struct device *dev, void *ptr, int offset)
109#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500110{
111 u32 dword = pci_read_config32(dev, offset);
112 memcpy(ptr, &dword, sizeof(dword));
113 mei_dump(ptr, dword, offset, "PCI READ");
114}
Aaron Durbin76c37002012-10-30 09:03:43 -0500115
116static inline void read_host_csr(struct mei_csr *csr)
117{
118 mei_read_dword_ptr(csr, MEI_H_CSR);
119}
120
121static inline void write_host_csr(struct mei_csr *csr)
122{
123 mei_write_dword_ptr(csr, MEI_H_CSR);
124}
125
126static inline void read_me_csr(struct mei_csr *csr)
127{
128 mei_read_dword_ptr(csr, MEI_ME_CSR_HA);
129}
130
131static inline void write_cb(u32 dword)
132{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800133 write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500134 mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE");
135}
136
137static inline u32 read_cb(void)
138{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800139 u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500140 mei_dump(NULL, dword, MEI_ME_CB_RW, "READ");
141 return dword;
142}
143
144/* Wait for ME ready bit to be asserted */
145static int mei_wait_for_me_ready(void)
146{
147 struct mei_csr me;
Martin Rothff744bf2019-10-23 21:46:03 -0600148 unsigned int try = ME_RETRY;
Aaron Durbin76c37002012-10-30 09:03:43 -0500149
150 while (try--) {
151 read_me_csr(&me);
152 if (me.ready)
153 return 0;
154 udelay(ME_DELAY);
155 }
156
157 printk(BIOS_ERR, "ME: failed to become ready\n");
158 return -1;
159}
160
161static void mei_reset(void)
162{
163 struct mei_csr host;
164
165 if (mei_wait_for_me_ready() < 0)
166 return;
167
168 /* Reset host and ME circular buffers for next message */
169 read_host_csr(&host);
170 host.reset = 1;
171 host.interrupt_generate = 1;
172 write_host_csr(&host);
173
174 if (mei_wait_for_me_ready() < 0)
175 return;
176
177 /* Re-init and indicate host is ready */
178 read_host_csr(&host);
179 host.interrupt_generate = 1;
180 host.ready = 1;
181 host.reset = 0;
182 write_host_csr(&host);
183}
184
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700185static int mei_send_packet(struct mei_header *mei, void *req_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500186{
187 struct mei_csr host;
Martin Rothff744bf2019-10-23 21:46:03 -0600188 unsigned int ndata, n;
Aaron Durbin76c37002012-10-30 09:03:43 -0500189 u32 *data;
190
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700191 /* Number of dwords to write */
Aaron Durbin76c37002012-10-30 09:03:43 -0500192 ndata = mei->length >> 2;
193
194 /* Pad non-dword aligned request message length */
195 if (mei->length & 3)
196 ndata++;
197 if (!ndata) {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700198 printk(BIOS_DEBUG, "ME: request has no data\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500199 return -1;
200 }
201 ndata++; /* Add MEI header */
202
203 /*
204 * Make sure there is still room left in the circular buffer.
205 * Reset the buffer pointers if the requested message will not fit.
206 */
207 read_host_csr(&host);
208 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
209 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
210 mei_reset();
211 read_host_csr(&host);
212 }
213
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700214 /* Ensure the requested length will fit in the circular buffer. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500215 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
216 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
217 ndata + 2, host.buffer_depth);
218 return -1;
219 }
220
221 /* Write MEI header */
222 mei_write_dword_ptr(mei, MEI_H_CB_WW);
223 ndata--;
224
Aaron Durbin76c37002012-10-30 09:03:43 -0500225 /* Write message data */
226 data = req_data;
227 for (n = 0; n < ndata; ++n)
228 write_cb(*data++);
229
230 /* Generate interrupt to the ME */
231 read_host_csr(&host);
232 host.interrupt_generate = 1;
233 write_host_csr(&host);
234
235 /* Make sure ME is ready after sending request data */
236 return mei_wait_for_me_ready();
237}
238
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700239static int mei_send_data(u8 me_address, u8 host_address,
240 void *req_data, int req_bytes)
241{
242 struct mei_header header = {
243 .client_address = me_address,
244 .host_address = host_address,
245 };
246 struct mei_csr host;
247 int current = 0;
248 u8 *req_ptr = req_data;
249
250 while (!header.is_complete) {
251 int remain = req_bytes - current;
252 int buf_len;
253
254 read_host_csr(&host);
255 buf_len = host.buffer_depth - host.buffer_write_ptr;
256
257 if (buf_len > remain) {
258 /* Send all remaining data as final message */
259 header.length = req_bytes - current;
260 header.is_complete = 1;
261 } else {
262 /* Send as much data as the buffer can hold */
263 header.length = buf_len;
264 }
265
266 mei_send_packet(&header, req_ptr);
267
268 req_ptr += header.length;
269 current += header.length;
270 }
271
272 return 0;
273}
274
275static int mei_send_header(u8 me_address, u8 host_address,
276 void *header, int header_len, int complete)
277{
278 struct mei_header mei = {
279 .client_address = me_address,
280 .host_address = host_address,
281 .length = header_len,
282 .is_complete = complete,
283 };
284 return mei_send_packet(&mei, header);
285}
286
287static int mei_recv_msg(void *header, int header_bytes,
Aaron Durbin76c37002012-10-30 09:03:43 -0500288 void *rsp_data, int rsp_bytes)
289{
290 struct mei_header mei_rsp;
Aaron Durbin76c37002012-10-30 09:03:43 -0500291 struct mei_csr me, host;
Martin Rothff744bf2019-10-23 21:46:03 -0600292 unsigned int ndata, n;
293 unsigned int expected;
Aaron Durbin76c37002012-10-30 09:03:43 -0500294 u32 *data;
295
296 /* Total number of dwords to read from circular buffer */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700297 expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500298 if (rsp_bytes & 3)
299 expected++;
300
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700301 if (mei_wait_for_me_ready() < 0)
302 return -1;
303
Aaron Durbin76c37002012-10-30 09:03:43 -0500304 /*
305 * The interrupt status bit does not appear to indicate that the
306 * message has actually been received. Instead we wait until the
307 * expected number of dwords are present in the circular buffer.
308 */
309 for (n = ME_RETRY; n; --n) {
310 read_me_csr(&me);
311 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
312 break;
313 udelay(ME_DELAY);
314 }
315 if (!n) {
316 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
317 "%u, available %u\n", expected,
318 me.buffer_write_ptr - me.buffer_read_ptr);
319 return -1;
320 }
321
322 /* Read and verify MEI response header from the ME */
323 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
324 if (!mei_rsp.is_complete) {
325 printk(BIOS_ERR, "ME: response is not complete\n");
326 return -1;
327 }
328
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700329 /* Handle non-dword responses and expect at least the header */
Aaron Durbin76c37002012-10-30 09:03:43 -0500330 ndata = mei_rsp.length >> 2;
331 if (mei_rsp.length & 3)
332 ndata++;
333 if (ndata != (expected - 1)) {
334 printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
335 ndata, (expected - 1));
336 return -1;
337 }
338
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700339 /* Read response header from the ME */
340 data = header;
341 for (n = 0; n < (header_bytes >> 2); ++n)
342 *data++ = read_cb();
343 ndata -= header_bytes >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500344
345 /* Make sure caller passed a buffer with enough space */
346 if (ndata != (rsp_bytes >> 2)) {
347 printk(BIOS_ERR, "ME: not enough room in response buffer: "
348 "%u != %u\n", ndata, rsp_bytes >> 2);
349 return -1;
350 }
351
352 /* Read response data from the circular buffer */
353 data = rsp_data;
354 for (n = 0; n < ndata; ++n)
355 *data++ = read_cb();
356
357 /* Tell the ME that we have consumed the response */
358 read_host_csr(&host);
359 host.interrupt_status = 1;
360 host.interrupt_generate = 1;
361 write_host_csr(&host);
362
363 return mei_wait_for_me_ready();
364}
365
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700366static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
367 void *req_data, int req_bytes,
368 void *rsp_data, int rsp_bytes)
Aaron Durbin76c37002012-10-30 09:03:43 -0500369{
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700370 struct mkhi_header mkhi_rsp;
371
372 /* Send header */
373 if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
374 mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500375 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700376
377 /* Send data if available */
378 if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
379 req_data, req_bytes) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500380 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700381
382 /* Return now if no response expected */
383 if (!rsp_bytes)
384 return 0;
385
386 /* Read header and data */
387 if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
388 rsp_data, rsp_bytes) < 0)
389 return -1;
390
391 if (!mkhi_rsp.is_response ||
392 mkhi->group_id != mkhi_rsp.group_id ||
393 mkhi->command != mkhi_rsp.command) {
394 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
395 "command %u ?= %u, is_response %u\n", mkhi->group_id,
396 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
397 mkhi_rsp.is_response);
398 return -1;
399 }
400
Aaron Durbin76c37002012-10-30 09:03:43 -0500401 return 0;
402}
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700403
Duncan Laurie3d299c42013-07-19 08:48:05 -0700404/*
405 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
406 * state machine on the BIOS end doesn't match the ME's state machine.
407 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100408#ifdef __SIMPLE_DEVICE__
409static void intel_me_mbp_give_up(pci_devfn_t dev)
410#else
411static void intel_me_mbp_give_up(struct device *dev)
412#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700413{
414 struct mei_csr csr;
415
416 pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP);
417
418 read_host_csr(&csr);
419 csr.reset = 1;
420 csr.interrupt_generate = 1;
421 write_host_csr(&csr);
422}
423
424/*
425 * mbp clear routine. This will wait for the ME to indicate that
426 * the MBP has been read and cleared.
427 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100428#ifdef __SIMPLE_DEVICE__
429void intel_me_mbp_clear(pci_devfn_t dev)
430#else
431void intel_me_mbp_clear(struct device *dev)
432#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700433{
434 int count;
435 struct me_hfs2 hfs2;
436
437 /* Wait for the mbp_cleared indicator */
438 for (count = ME_RETRY; count > 0; --count) {
439 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
440 if (hfs2.mbp_cleared)
441 break;
442 udelay(ME_DELAY);
443 }
444
445 if (count == 0) {
446 printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n");
447 intel_me_mbp_give_up(dev);
448 } else {
449 printk(BIOS_INFO, "ME: MBP cleared\n");
450 }
451}
452
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200453static void __unused me_print_fw_version(mbp_fw_version_name *vers_name)
Aaron Durbin76c37002012-10-30 09:03:43 -0500454{
Aaron Durbinbe985242012-12-12 12:40:33 -0600455 if (!vers_name) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500456 printk(BIOS_ERR, "ME: mbp missing version report\n");
457 return;
458 }
459
460 printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
461 vers_name->major_version, vers_name->minor_version,
462 vers_name->hotfix_version, vers_name->build_version);
463}
464
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000465static inline void print_cap(const char *name, int state)
466{
467 printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
468 name, state ? " en" : "dis");
469}
470
Aaron Durbin76c37002012-10-30 09:03:43 -0500471/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600472static int mkhi_get_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500473{
474 u32 rule_id = 0;
475 struct me_fwcaps cap_msg;
476 struct mkhi_header mkhi = {
477 .group_id = MKHI_GROUP_ID_FWCAPS,
478 .command = MKHI_FWCAPS_GET_RULE,
479 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500480
481 /* Send request and wait for response */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700482 if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
483 &cap_msg, sizeof(cap_msg)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500484 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
485 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200486 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500487 *cap = cap_msg.caps_sku;
488 return 0;
489}
490
491/* Get ME Firmware Capabilities */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200492static void __unused me_print_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500493{
Aaron Durbinbe985242012-12-12 12:40:33 -0600494 mbp_mefwcaps local_caps;
495 if (!cap) {
496 cap = &local_caps;
Aaron Durbin76c37002012-10-30 09:03:43 -0500497 printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
498 if (mkhi_get_fwcaps(cap))
499 return;
500 }
501
502 print_cap("Full Network manageability", cap->full_net);
503 print_cap("Regular Network manageability", cap->std_net);
504 print_cap("Manageability", cap->manageability);
Aaron Durbin76c37002012-10-30 09:03:43 -0500505 print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
506 print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
507 print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
508 print_cap("ICC Over Clocking", cap->icc_over_clocking);
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000509 print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
Aaron Durbin76c37002012-10-30 09:03:43 -0500510 print_cap("IPV6", cap->ipv6);
511 print_cap("KVM Remote Control (KVM)", cap->kvm);
512 print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
513 print_cap("Virtual LAN (VLAN)", cap->vlan);
514 print_cap("TLS", cap->tls);
515 print_cap("Wireless LAN (WLAN)", cap->wlan);
516}
Aaron Durbin76c37002012-10-30 09:03:43 -0500517
Aaron Durbin76c37002012-10-30 09:03:43 -0500518/* Send END OF POST message to the ME */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200519static int __unused mkhi_end_of_post(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500520{
521 struct mkhi_header mkhi = {
522 .group_id = MKHI_GROUP_ID_GEN,
523 .command = MKHI_END_OF_POST,
524 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500525 u32 eop_ack;
526
527 /* Send request and wait for response */
Angel Pons08e8cab2020-06-18 15:20:37 +0200528 printk(BIOS_NOTICE, "ME: %s\n", __func__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700529 if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500530 printk(BIOS_ERR, "ME: END OF POST message failed\n");
531 return -1;
532 }
533
534 printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
535 return 0;
536}
537
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200538#ifdef __SIMPLE_DEVICE__
539
Duncan Laurieaf980622013-07-18 23:02:18 -0700540void intel_me_finalize_smm(void)
541{
542 struct me_hfs hfs;
543 u32 reg32;
Elyes HAOUAS73ae0762020-04-28 10:13:05 +0200544 u16 reg16;
Duncan Laurieaf980622013-07-18 23:02:18 -0700545
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800546 mei_base_address = (u32 *)
547 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Duncan Laurieaf980622013-07-18 23:02:18 -0700548
549 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800550 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700551 return;
552
Julius Wernercd49cce2019-03-05 16:53:33 -0800553#if CONFIG(ME_MBP_CLEAR_LATE)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700554 /* Wait for ME MBP Cleared indicator */
555 intel_me_mbp_clear(PCH_ME_DEV);
556#endif
557
Duncan Laurieaf980622013-07-18 23:02:18 -0700558 /* Make sure ME is in a mode that expects EOP */
559 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
560 memcpy(&hfs, &reg32, sizeof(u32));
561
562 /* Abort and leave device alone if not normal mode */
563 if (hfs.fpt_bad ||
564 hfs.working_state != ME_HFS_CWS_NORMAL ||
565 hfs.operation_mode != ME_HFS_MODE_NORMAL)
566 return;
567
568 /* Try to send EOP command so ME stops accepting other commands */
569 mkhi_end_of_post();
570
571 /* Make sure IO is disabled */
Elyes HAOUAS73ae0762020-04-28 10:13:05 +0200572 reg16 = pci_read_config16(PCH_ME_DEV, PCI_COMMAND);
573 reg16 &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
574 pci_write_config16(PCH_ME_DEV, PCI_COMMAND, reg16);
Duncan Laurieaf980622013-07-18 23:02:18 -0700575
576 /* Hide the PCI device */
577 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
578}
579
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200580#else /* !__SIMPLE_DEVICE__ */
Duncan Laurieaf980622013-07-18 23:02:18 -0700581
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100582static inline int mei_sendrecv_icc(struct icc_header *icc,
583 void *req_data, int req_bytes,
584 void *rsp_data, int rsp_bytes)
585{
586 struct icc_header icc_rsp;
587
588 /* Send header */
589 if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
590 icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
591 return -1;
592
593 /* Send data if available */
594 if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
595 req_data, req_bytes) < 0)
596 return -1;
597
598 /* Read header and data, if needed */
599 if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
600 rsp_data, rsp_bytes) < 0)
601 return -1;
602
603 return 0;
604}
605
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700606static int me_icc_set_clock_enables(u32 mask)
607{
608 struct icc_clock_enables_msg clk = {
609 .clock_enables = 0, /* Turn off specified clocks */
610 .clock_mask = mask,
611 .no_response = 1, /* Do not expect response */
612 };
613 struct icc_header icc = {
614 .api_version = ICC_API_VERSION_LYNXPOINT,
615 .icc_command = ICC_SET_CLOCK_ENABLES,
616 .length = sizeof(clk),
617 };
618
619 /* Send request and wait for response */
620 if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
621 printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
622 return -1;
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700623 }
624
Elyes HAOUAS54f94242018-10-25 10:57:39 +0200625 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700626 return 0;
627}
628
Aaron Durbin76c37002012-10-30 09:03:43 -0500629/* Determine the path that we should take based on ME status */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100630static me_bios_path intel_me_path(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500631{
632 me_bios_path path = ME_DISABLE_BIOS_PATH;
633 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500634 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500635
Aaron Durbin76c37002012-10-30 09:03:43 -0500636 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500637 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500638
639 /* Check and dump status */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500640 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500641
642 /* Check Current Working State */
643 switch (hfs.working_state) {
644 case ME_HFS_CWS_NORMAL:
645 path = ME_NORMAL_BIOS_PATH;
646 break;
647 case ME_HFS_CWS_REC:
648 path = ME_RECOVERY_BIOS_PATH;
649 break;
650 default:
651 path = ME_DISABLE_BIOS_PATH;
652 break;
653 }
654
655 /* Check Current Operation Mode */
656 switch (hfs.operation_mode) {
657 case ME_HFS_MODE_NORMAL:
658 break;
659 case ME_HFS_MODE_DEBUG:
660 case ME_HFS_MODE_DIS:
661 case ME_HFS_MODE_OVER_JMPR:
662 case ME_HFS_MODE_OVER_MEI:
663 default:
664 path = ME_DISABLE_BIOS_PATH;
665 break;
666 }
667
668 /* Check for any error code and valid firmware and MBP */
669 if (hfs.error_code || hfs.fpt_bad)
670 path = ME_ERROR_BIOS_PATH;
671
672 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500673 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500674 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
Angel Pons08e8cab2020-06-18 15:20:37 +0200675 __func__);
Aaron Durbin76c37002012-10-30 09:03:43 -0500676 path = ME_ERROR_BIOS_PATH;
677 }
678
Kyösti Mälkkibe5317f2019-11-06 12:07:21 +0200679 if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500680 struct elog_event_data_me_extended data = {
681 .current_working_state = hfs.working_state,
682 .operation_state = hfs.operation_state,
683 .operation_mode = hfs.operation_mode,
684 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500685 .progress_code = hfs2.progress_code,
686 .current_pmevent = hfs2.current_pmevent,
687 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500688 };
689 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
690 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
691 &data, sizeof(data));
692 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500693
694 return path;
695}
696
697/* Prepare ME for MEI messages */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100698static int intel_mei_setup(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500699{
700 struct resource *res;
701 struct mei_csr host;
Aaron Durbin76c37002012-10-30 09:03:43 -0500702
703 /* Find the MMIO base for the ME interface */
704 res = find_resource(dev, PCI_BASE_ADDRESS_0);
705 if (!res || res->base == 0 || res->size == 0) {
706 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
707 return -1;
708 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800709 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500710
711 /* Ensure Memory and Bus Master bits are set */
Angel Ponsd5d4fbc2020-05-31 01:03:59 +0200712 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Aaron Durbin76c37002012-10-30 09:03:43 -0500713
714 /* Clean up status for next message */
715 read_host_csr(&host);
716 host.interrupt_generate = 1;
717 host.ready = 1;
718 host.reset = 0;
719 write_host_csr(&host);
720
721 return 0;
722}
723
724/* Read the Extend register hash of ME firmware */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100725static int intel_me_extend_valid(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500726{
727 struct me_heres status;
728 u32 extend[8] = {0};
729 int i, count = 0;
730
731 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
732 if (!status.extend_feature_present) {
733 printk(BIOS_ERR, "ME: Extend Feature not present\n");
734 return -1;
735 }
736
737 if (!status.extend_reg_valid) {
738 printk(BIOS_ERR, "ME: Extend Register not valid\n");
739 return -1;
740 }
741
742 switch (status.extend_reg_algorithm) {
743 case PCI_ME_EXT_SHA1:
744 count = 5;
745 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
746 break;
747 case PCI_ME_EXT_SHA256:
748 count = 8;
749 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
750 break;
751 default:
752 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
753 status.extend_reg_algorithm);
754 return -1;
755 }
756
757 for (i = 0; i < count; ++i) {
758 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
759 printk(BIOS_DEBUG, "%08x", extend[i]);
760 }
761 printk(BIOS_DEBUG, "\n");
762
Julius Wernercd49cce2019-03-05 16:53:33 -0800763#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500764 /* Save hash in NVS for the OS to verify */
765 chromeos_set_me_hash(extend, count);
766#endif
767
768 return 0;
769}
770
Aaron Durbin76c37002012-10-30 09:03:43 -0500771/* Check whether ME is present and do basic init */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100772static void intel_me_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500773{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700774 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500775 me_bios_path path = intel_me_path(dev);
776 me_bios_payload mbp_data;
777
778 /* Do initial setup and determine the BIOS path */
779 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
780
Duncan Laurie8056dc62013-07-22 08:47:43 -0700781 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500782 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500783 intel_me_extend_valid(dev);
784 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500785
Aaron Durbinbe985242012-12-12 12:40:33 -0600786 memset(&mbp_data, 0, sizeof(mbp_data));
787
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500788 /*
789 * According to the ME9 BWG, BIOS is required to fetch MBP data in
790 * all boot flows except S3 Resume.
791 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500792
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500793 /* Prepare MEI MMIO interface */
794 if (intel_mei_setup(dev) < 0)
795 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500796
Duncan Laurie144f7b22013-05-01 11:27:58 -0700797 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500798 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500799
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200800 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
801 me_print_fw_version(mbp_data.fw_version_name);
Duncan Laurie144f7b22013-05-01 11:27:58 -0700802
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200803 if (CONFIG(DEBUG_INTEL_ME))
804 me_print_fwcaps(mbp_data.fw_capabilities);
805
806 if (mbp_data.plat_time) {
807 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
808 mbp_data.plat_time->wake_event_mrst_time_ms);
809 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
810 mbp_data.plat_time->mrst_pltrst_time_ms);
811 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
812 mbp_data.plat_time->pltrst_cpurst_time_ms);
813 }
Duncan Laurie144f7b22013-05-01 11:27:58 -0700814 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500815
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700816 /* Set clock enables according to devicetree */
817 if (config && config->icc_clock_disable)
818 me_icc_set_clock_enables(config->icc_clock_disable);
819
Duncan Laurieaf980622013-07-18 23:02:18 -0700820 /*
821 * Leave the ME unlocked. It will be locked via SMI command later.
822 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500823}
824
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100825static void intel_me_enable(struct device *dev)
Duncan Laurie8056dc62013-07-22 08:47:43 -0700826{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700827 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300828 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700829 dev->enabled = 0;
830 pch_disable_devfn(dev);
831 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700832}
833
Aaron Durbin76c37002012-10-30 09:03:43 -0500834static struct device_operations device_ops = {
835 .read_resources = pci_dev_read_resources,
836 .set_resources = pci_dev_set_resources,
837 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700838 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500839 .init = intel_me_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200840 .ops_pci = &pci_dev_ops_pci,
Aaron Durbin76c37002012-10-30 09:03:43 -0500841};
842
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800843static const unsigned short pci_device_ids[] = {
844 0x8c3a, /* Mobile */
845 0x9c3a, /* Low Power */
846 0
847};
848
Aaron Durbin76c37002012-10-30 09:03:43 -0500849static const struct pci_driver intel_me __pci_driver = {
Angel Ponsb4b4e322020-06-21 12:47:13 +0200850 .ops = &device_ops,
851 .vendor = PCI_VENDOR_ID_INTEL,
852 .devices = pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500853};
854
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200855#endif /* !__SIMPLE_DEVICE__ */
856
Aaron Durbin76c37002012-10-30 09:03:43 -0500857/******************************************************************************
858 * */
859static u32 me_to_host_words_pending(void)
860{
861 struct mei_csr me;
862 read_me_csr(&me);
863 if (!me.ready)
864 return 0;
865 return (me.buffer_write_ptr - me.buffer_read_ptr) &
866 (me.buffer_depth - 1);
867}
868
Aaron Durbinbe985242012-12-12 12:40:33 -0600869struct mbp_payload {
870 mbp_header header;
871 u32 data[0];
872};
873
Aaron Durbin76c37002012-10-30 09:03:43 -0500874/*
875 * mbp seems to be following its own flow, let's retrieve it in a dedicated
876 * function.
877 */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200878static int __unused intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500879{
880 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500881 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500882 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500883 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600884 struct mbp_payload *mbp;
885 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500886
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200887#ifdef __SIMPLE_DEVICE__
888 pci_read_dword_ptr(PCI_BDF(dev), &hfs2, PCI_ME_HFS2);
889#else
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500890 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200891#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500892
893 if (!hfs2.mbp_rdy) {
894 printk(BIOS_ERR, "ME: MBP not ready\n");
895 goto mbp_failure;
896 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500897
898 me2host_pending = me_to_host_words_pending();
899 if (!me2host_pending) {
900 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500901 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500902 }
903
904 /* we know for sure that at least the header is there */
905 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
906
907 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
908 (me2host_pending < mbp_hdr.mbp_size)) {
909 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
910 " buffer contains %d words\n",
911 mbp_hdr.num_entries, mbp_hdr.mbp_size,
912 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500913 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500914 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600915 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
916 if (!mbp)
917 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500918
Aaron Durbinbe985242012-12-12 12:40:33 -0600919 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500920 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500921
Aaron Durbinbe985242012-12-12 12:40:33 -0600922 i = 0;
923 while (i != me2host_pending) {
924 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
925 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500926 }
927
Aaron Durbinbe985242012-12-12 12:40:33 -0600928 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500929 read_host_csr(&host);
930 host.interrupt_generate = 1;
931 write_host_csr(&host);
932
Julius Wernercd49cce2019-03-05 16:53:33 -0800933#if !CONFIG(ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -0600934 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -0700935 intel_me_mbp_clear(dev);
936#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500937
Aaron Durbinbe985242012-12-12 12:40:33 -0600938 /* Dump out the MBP contents. */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200939 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
940 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
941 mbp->header.num_entries, mbp->header.mbp_size);
942 if (CONFIG(DEBUG_INTEL_ME)) {
943 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
944 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
945 }
946 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600947 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600948
949 #define ASSIGN_FIELD_PTR(field_,val_) \
950 { \
951 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
952 break; \
953 }
954 /* Setup the pointers in the me_bios_payload structure. */
955 for (i = 0; i < mbp->header.mbp_size - 1;) {
956 mbp_item_header *item = (void *)&mbp->data[i];
957
Elyes HAOUASf9de5a42018-05-03 17:21:02 +0200958 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -0600959 case MBP_IDENT(KERNEL, FW_VER):
960 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
961
962 case MBP_IDENT(ICC, PROFILE):
963 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
964
965 case MBP_IDENT(INTEL_AT, STATE):
966 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
967
968 case MBP_IDENT(KERNEL, FW_CAP):
969 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
970
971 case MBP_IDENT(KERNEL, ROM_BIST):
972 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
973
974 case MBP_IDENT(KERNEL, PLAT_KEY):
975 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
976
977 case MBP_IDENT(KERNEL, FW_TYPE):
978 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
979
980 case MBP_IDENT(KERNEL, MFS_FAILURE):
981 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
982
Duncan Laurie144f7b22013-05-01 11:27:58 -0700983 case MBP_IDENT(KERNEL, PLAT_TIME):
984 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
985
986 case MBP_IDENT(NFC, SUPPORT_DATA):
987 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
988
Aaron Durbinbe985242012-12-12 12:40:33 -0600989 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700990 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
991 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -0600992 break;
993 }
994 i += item->length;
995 }
996 #undef ASSIGN_FIELD_PTR
997
Aaron Durbin76c37002012-10-30 09:03:43 -0500998 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500999
1000mbp_failure:
Kyösti Mälkki21d6a272019-11-05 18:50:38 +02001001#ifdef __SIMPLE_DEVICE__
1002 intel_me_mbp_give_up(PCI_BDF(dev));
1003#else
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001004 intel_me_mbp_give_up(dev);
Kyösti Mälkki21d6a272019-11-05 18:50:38 +02001005#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001006 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001007}