blob: 61684985a8cd687463e1a9d832f524a30d0cb01f [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Aaron Durbin76c37002012-10-30 09:03:43 -050015 */
16
17/*
18 * This is a ramstage driver for the Intel Management Engine found in the
19 * 6-series chipset. It handles the required boot-time messages over the
20 * MMIO-based Management Engine Interface to tell the ME that the BIOS is
21 * finished with POST. Additional messages are defined for debug but are
22 * not used unless the console loglevel is high enough.
23 */
24
25#include <arch/acpi.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050026#include <arch/io.h>
27#include <console/console.h>
Stefan Reinauer24d1d4b2013-03-21 11:51:41 -070028#include <device/device.h>
29#include <device/pci.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050030#include <device/pci_ids.h>
31#include <device/pci_def.h>
32#include <string.h>
33#include <delay.h>
34#include <elog.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010035#include <halt.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050036
Aaron Durbin76c37002012-10-30 09:03:43 -050037#include "me.h"
38#include "pch.h"
39
Martin Roth7a1a3ad2017-06-24 21:29:38 -060040#if IS_ENABLED(CONFIG_CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -050041#include <vendorcode/google/chromeos/chromeos.h>
42#include <vendorcode/google/chromeos/gnvs.h>
43#endif
44
Duncan Laurieaf980622013-07-18 23:02:18 -070045#ifndef __SMM__
Aaron Durbin76c37002012-10-30 09:03:43 -050046/* Path that the BIOS should take based on ME state */
47static const char *me_bios_path_values[] = {
48 [ME_NORMAL_BIOS_PATH] = "Normal",
49 [ME_S3WAKE_BIOS_PATH] = "S3 Wake",
50 [ME_ERROR_BIOS_PATH] = "Error",
51 [ME_RECOVERY_BIOS_PATH] = "Recovery",
52 [ME_DISABLE_BIOS_PATH] = "Disable",
53 [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update",
54};
Aaron Durbin9aa031e2012-11-02 09:16:46 -050055static int intel_me_read_mbp(me_bios_payload *mbp_data, device_t dev);
Duncan Laurieaf980622013-07-18 23:02:18 -070056#endif
Aaron Durbin76c37002012-10-30 09:03:43 -050057
58/* MMIO base address for MEI interface */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080059static u32 *mei_base_address;
Duncan Laurie3d299c42013-07-19 08:48:05 -070060void intel_me_mbp_clear(device_t dev);
Aaron Durbin76c37002012-10-30 09:03:43 -050061
Martin Roth7a1a3ad2017-06-24 21:29:38 -060062#if IS_ENABLED(CONFIG_DEBUG_INTEL_ME)
Aaron Durbin76c37002012-10-30 09:03:43 -050063static void mei_dump(void *ptr, int dword, int offset, const char *type)
64{
65 struct mei_csr *csr;
66
67 printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset);
68
69 switch (offset) {
70 case MEI_H_CSR:
71 case MEI_ME_CSR_HA:
72 csr = ptr;
73 if (!csr) {
74 printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword);
75 break;
76 }
77 printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
78 "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth,
79 csr->buffer_read_ptr, csr->buffer_write_ptr,
80 csr->ready, csr->reset, csr->interrupt_generate,
81 csr->interrupt_status, csr->interrupt_enable);
82 break;
83 case MEI_ME_CB_RW:
84 case MEI_H_CB_WW:
85 printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
86 break;
87 default:
88 printk(BIOS_SPEW, "0x%08x\n", offset);
89 break;
90 }
91}
92#else
93# define mei_dump(ptr,dword,offset,type) do {} while (0)
94#endif
95
96/*
97 * ME/MEI access helpers using memcpy to avoid aliasing.
98 */
99
100static inline void mei_read_dword_ptr(void *ptr, int offset)
101{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800102 u32 dword = read32(mei_base_address + (offset/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500103 memcpy(ptr, &dword, sizeof(dword));
104 mei_dump(ptr, dword, offset, "READ");
105}
106
107static inline void mei_write_dword_ptr(void *ptr, int offset)
108{
109 u32 dword = 0;
110 memcpy(&dword, ptr, sizeof(dword));
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800111 write32(mei_base_address + (offset/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500112 mei_dump(ptr, dword, offset, "WRITE");
113}
114
Aaron Durbin76c37002012-10-30 09:03:43 -0500115static inline void pci_read_dword_ptr(device_t dev, void *ptr, int offset)
116{
117 u32 dword = pci_read_config32(dev, offset);
118 memcpy(ptr, &dword, sizeof(dword));
119 mei_dump(ptr, dword, offset, "PCI READ");
120}
Aaron Durbin76c37002012-10-30 09:03:43 -0500121
122static inline void read_host_csr(struct mei_csr *csr)
123{
124 mei_read_dword_ptr(csr, MEI_H_CSR);
125}
126
127static inline void write_host_csr(struct mei_csr *csr)
128{
129 mei_write_dword_ptr(csr, MEI_H_CSR);
130}
131
132static inline void read_me_csr(struct mei_csr *csr)
133{
134 mei_read_dword_ptr(csr, MEI_ME_CSR_HA);
135}
136
137static inline void write_cb(u32 dword)
138{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800139 write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500140 mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE");
141}
142
143static inline u32 read_cb(void)
144{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800145 u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500146 mei_dump(NULL, dword, MEI_ME_CB_RW, "READ");
147 return dword;
148}
149
150/* Wait for ME ready bit to be asserted */
151static int mei_wait_for_me_ready(void)
152{
153 struct mei_csr me;
154 unsigned try = ME_RETRY;
155
156 while (try--) {
157 read_me_csr(&me);
158 if (me.ready)
159 return 0;
160 udelay(ME_DELAY);
161 }
162
163 printk(BIOS_ERR, "ME: failed to become ready\n");
164 return -1;
165}
166
167static void mei_reset(void)
168{
169 struct mei_csr host;
170
171 if (mei_wait_for_me_ready() < 0)
172 return;
173
174 /* Reset host and ME circular buffers for next message */
175 read_host_csr(&host);
176 host.reset = 1;
177 host.interrupt_generate = 1;
178 write_host_csr(&host);
179
180 if (mei_wait_for_me_ready() < 0)
181 return;
182
183 /* Re-init and indicate host is ready */
184 read_host_csr(&host);
185 host.interrupt_generate = 1;
186 host.ready = 1;
187 host.reset = 0;
188 write_host_csr(&host);
189}
190
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700191static int mei_send_packet(struct mei_header *mei, void *req_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500192{
193 struct mei_csr host;
194 unsigned ndata, n;
195 u32 *data;
196
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700197 /* Number of dwords to write */
Aaron Durbin76c37002012-10-30 09:03:43 -0500198 ndata = mei->length >> 2;
199
200 /* Pad non-dword aligned request message length */
201 if (mei->length & 3)
202 ndata++;
203 if (!ndata) {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700204 printk(BIOS_DEBUG, "ME: request has no data\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500205 return -1;
206 }
207 ndata++; /* Add MEI header */
208
209 /*
210 * Make sure there is still room left in the circular buffer.
211 * Reset the buffer pointers if the requested message will not fit.
212 */
213 read_host_csr(&host);
214 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
215 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
216 mei_reset();
217 read_host_csr(&host);
218 }
219
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700220 /* Ensure the requested length will fit in the circular buffer. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500221 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
222 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
223 ndata + 2, host.buffer_depth);
224 return -1;
225 }
226
227 /* Write MEI header */
228 mei_write_dword_ptr(mei, MEI_H_CB_WW);
229 ndata--;
230
Aaron Durbin76c37002012-10-30 09:03:43 -0500231 /* Write message data */
232 data = req_data;
233 for (n = 0; n < ndata; ++n)
234 write_cb(*data++);
235
236 /* Generate interrupt to the ME */
237 read_host_csr(&host);
238 host.interrupt_generate = 1;
239 write_host_csr(&host);
240
241 /* Make sure ME is ready after sending request data */
242 return mei_wait_for_me_ready();
243}
244
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700245static int mei_send_data(u8 me_address, u8 host_address,
246 void *req_data, int req_bytes)
247{
248 struct mei_header header = {
249 .client_address = me_address,
250 .host_address = host_address,
251 };
252 struct mei_csr host;
253 int current = 0;
254 u8 *req_ptr = req_data;
255
256 while (!header.is_complete) {
257 int remain = req_bytes - current;
258 int buf_len;
259
260 read_host_csr(&host);
261 buf_len = host.buffer_depth - host.buffer_write_ptr;
262
263 if (buf_len > remain) {
264 /* Send all remaining data as final message */
265 header.length = req_bytes - current;
266 header.is_complete = 1;
267 } else {
268 /* Send as much data as the buffer can hold */
269 header.length = buf_len;
270 }
271
272 mei_send_packet(&header, req_ptr);
273
274 req_ptr += header.length;
275 current += header.length;
276 }
277
278 return 0;
279}
280
281static int mei_send_header(u8 me_address, u8 host_address,
282 void *header, int header_len, int complete)
283{
284 struct mei_header mei = {
285 .client_address = me_address,
286 .host_address = host_address,
287 .length = header_len,
288 .is_complete = complete,
289 };
290 return mei_send_packet(&mei, header);
291}
292
293static int mei_recv_msg(void *header, int header_bytes,
Aaron Durbin76c37002012-10-30 09:03:43 -0500294 void *rsp_data, int rsp_bytes)
295{
296 struct mei_header mei_rsp;
Aaron Durbin76c37002012-10-30 09:03:43 -0500297 struct mei_csr me, host;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700298 unsigned ndata, n;
Aaron Durbin76c37002012-10-30 09:03:43 -0500299 unsigned expected;
300 u32 *data;
301
302 /* Total number of dwords to read from circular buffer */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700303 expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500304 if (rsp_bytes & 3)
305 expected++;
306
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700307 if (mei_wait_for_me_ready() < 0)
308 return -1;
309
Aaron Durbin76c37002012-10-30 09:03:43 -0500310 /*
311 * The interrupt status bit does not appear to indicate that the
312 * message has actually been received. Instead we wait until the
313 * expected number of dwords are present in the circular buffer.
314 */
315 for (n = ME_RETRY; n; --n) {
316 read_me_csr(&me);
317 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
318 break;
319 udelay(ME_DELAY);
320 }
321 if (!n) {
322 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
323 "%u, available %u\n", expected,
324 me.buffer_write_ptr - me.buffer_read_ptr);
325 return -1;
326 }
327
328 /* Read and verify MEI response header from the ME */
329 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
330 if (!mei_rsp.is_complete) {
331 printk(BIOS_ERR, "ME: response is not complete\n");
332 return -1;
333 }
334
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700335 /* Handle non-dword responses and expect at least the header */
Aaron Durbin76c37002012-10-30 09:03:43 -0500336 ndata = mei_rsp.length >> 2;
337 if (mei_rsp.length & 3)
338 ndata++;
339 if (ndata != (expected - 1)) {
340 printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
341 ndata, (expected - 1));
342 return -1;
343 }
344
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700345 /* Read response header from the ME */
346 data = header;
347 for (n = 0; n < (header_bytes >> 2); ++n)
348 *data++ = read_cb();
349 ndata -= header_bytes >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500350
351 /* Make sure caller passed a buffer with enough space */
352 if (ndata != (rsp_bytes >> 2)) {
353 printk(BIOS_ERR, "ME: not enough room in response buffer: "
354 "%u != %u\n", ndata, rsp_bytes >> 2);
355 return -1;
356 }
357
358 /* Read response data from the circular buffer */
359 data = rsp_data;
360 for (n = 0; n < ndata; ++n)
361 *data++ = read_cb();
362
363 /* Tell the ME that we have consumed the response */
364 read_host_csr(&host);
365 host.interrupt_status = 1;
366 host.interrupt_generate = 1;
367 write_host_csr(&host);
368
369 return mei_wait_for_me_ready();
370}
371
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100372#if IS_ENABLED (CONFIG_DEBUG_INTEL_ME) || defined(__SMM__)
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700373static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
374 void *req_data, int req_bytes,
375 void *rsp_data, int rsp_bytes)
Aaron Durbin76c37002012-10-30 09:03:43 -0500376{
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700377 struct mkhi_header mkhi_rsp;
378
379 /* Send header */
380 if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
381 mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500382 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700383
384 /* Send data if available */
385 if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
386 req_data, req_bytes) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500387 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700388
389 /* Return now if no response expected */
390 if (!rsp_bytes)
391 return 0;
392
393 /* Read header and data */
394 if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
395 rsp_data, rsp_bytes) < 0)
396 return -1;
397
398 if (!mkhi_rsp.is_response ||
399 mkhi->group_id != mkhi_rsp.group_id ||
400 mkhi->command != mkhi_rsp.command) {
401 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
402 "command %u ?= %u, is_response %u\n", mkhi->group_id,
403 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
404 mkhi_rsp.is_response);
405 return -1;
406 }
407
Aaron Durbin76c37002012-10-30 09:03:43 -0500408 return 0;
409}
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100410#endif /* CONFIG_DEBUG_INTEL_ME || __SMM__ */
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700411
Duncan Laurie3d299c42013-07-19 08:48:05 -0700412/*
413 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
414 * state machine on the BIOS end doesn't match the ME's state machine.
415 */
416static void intel_me_mbp_give_up(device_t dev)
417{
418 struct mei_csr csr;
419
420 pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP);
421
422 read_host_csr(&csr);
423 csr.reset = 1;
424 csr.interrupt_generate = 1;
425 write_host_csr(&csr);
426}
427
428/*
429 * mbp clear routine. This will wait for the ME to indicate that
430 * the MBP has been read and cleared.
431 */
432void intel_me_mbp_clear(device_t dev)
433{
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
Duncan Laurieaf980622013-07-18 23:02:18 -0700453#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) && !defined(__SMM__)
Aaron Durbin76c37002012-10-30 09:03:43 -0500454static void me_print_fw_version(mbp_fw_version_name *vers_name)
455{
Aaron Durbinbe985242012-12-12 12:40:33 -0600456 if (!vers_name) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500457 printk(BIOS_ERR, "ME: mbp missing version report\n");
458 return;
459 }
460
461 printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
462 vers_name->major_version, vers_name->minor_version,
463 vers_name->hotfix_version, vers_name->build_version);
464}
465
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000466#if IS_ENABLED (CONFIG_DEBUG_INTEL_ME)
467static inline void print_cap(const char *name, int state)
468{
469 printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
470 name, state ? " en" : "dis");
471}
472
Aaron Durbin76c37002012-10-30 09:03:43 -0500473/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600474static int mkhi_get_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500475{
476 u32 rule_id = 0;
477 struct me_fwcaps cap_msg;
478 struct mkhi_header mkhi = {
479 .group_id = MKHI_GROUP_ID_FWCAPS,
480 .command = MKHI_FWCAPS_GET_RULE,
481 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500482
483 /* Send request and wait for response */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700484 if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
485 &cap_msg, sizeof(cap_msg)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500486 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
487 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200488 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500489 *cap = cap_msg.caps_sku;
490 return 0;
491}
492
493/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600494static void me_print_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500495{
Aaron Durbinbe985242012-12-12 12:40:33 -0600496 mbp_mefwcaps local_caps;
497 if (!cap) {
498 cap = &local_caps;
Aaron Durbin76c37002012-10-30 09:03:43 -0500499 printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
500 if (mkhi_get_fwcaps(cap))
501 return;
502 }
503
504 print_cap("Full Network manageability", cap->full_net);
505 print_cap("Regular Network manageability", cap->std_net);
506 print_cap("Manageability", cap->manageability);
Aaron Durbin76c37002012-10-30 09:03:43 -0500507 print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
508 print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
509 print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
510 print_cap("ICC Over Clocking", cap->icc_over_clocking);
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000511 print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
Aaron Durbin76c37002012-10-30 09:03:43 -0500512 print_cap("IPV6", cap->ipv6);
513 print_cap("KVM Remote Control (KVM)", cap->kvm);
514 print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
515 print_cap("Virtual LAN (VLAN)", cap->vlan);
516 print_cap("TLS", cap->tls);
517 print_cap("Wireless LAN (WLAN)", cap->wlan);
518}
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000519#endif /* CONFIG_DEBUG_INTEL_ME */
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700520#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500521
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600522#if IS_ENABLED(CONFIG_CHROMEOS) && 0 /* DISABLED */
Aaron Durbin76c37002012-10-30 09:03:43 -0500523/* Tell ME to issue a global reset */
524static int mkhi_global_reset(void)
525{
526 struct me_global_reset reset = {
527 .request_origin = GLOBAL_RESET_BIOS_POST,
528 .reset_type = CBM_RR_GLOBAL_RESET,
529 };
530 struct mkhi_header mkhi = {
531 .group_id = MKHI_GROUP_ID_CBM,
532 .command = MKHI_GLOBAL_RESET,
533 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500534
535 /* Send request and wait for response */
536 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700537 if (mei_sendrecv_mkhi(&mkhi, &reset, sizeof(reset), NULL, 0) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500538 /* No response means reset will happen shortly... */
Patrick Georgi546953c2014-11-29 10:38:17 +0100539 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500540 }
541
542 /* If the ME responded it rejected the reset request */
543 printk(BIOS_ERR, "ME: Global Reset failed\n");
544 return -1;
545}
546#endif
547
Duncan Laurieaf980622013-07-18 23:02:18 -0700548#ifdef __SMM__
549
Aaron Durbin76c37002012-10-30 09:03:43 -0500550/* Send END OF POST message to the ME */
551static int mkhi_end_of_post(void)
552{
553 struct mkhi_header mkhi = {
554 .group_id = MKHI_GROUP_ID_GEN,
555 .command = MKHI_END_OF_POST,
556 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500557 u32 eop_ack;
558
559 /* Send request and wait for response */
560 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700561 if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500562 printk(BIOS_ERR, "ME: END OF POST message failed\n");
563 return -1;
564 }
565
566 printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
567 return 0;
568}
569
Duncan Laurieaf980622013-07-18 23:02:18 -0700570void intel_me_finalize_smm(void)
571{
572 struct me_hfs hfs;
573 u32 reg32;
574
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800575 mei_base_address = (u32 *)
576 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Duncan Laurieaf980622013-07-18 23:02:18 -0700577
578 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800579 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700580 return;
581
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600582#if IS_ENABLED(CONFIG_ME_MBP_CLEAR_LATE)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700583 /* Wait for ME MBP Cleared indicator */
584 intel_me_mbp_clear(PCH_ME_DEV);
585#endif
586
Duncan Laurieaf980622013-07-18 23:02:18 -0700587 /* Make sure ME is in a mode that expects EOP */
588 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
589 memcpy(&hfs, &reg32, sizeof(u32));
590
591 /* Abort and leave device alone if not normal mode */
592 if (hfs.fpt_bad ||
593 hfs.working_state != ME_HFS_CWS_NORMAL ||
594 hfs.operation_mode != ME_HFS_MODE_NORMAL)
595 return;
596
597 /* Try to send EOP command so ME stops accepting other commands */
598 mkhi_end_of_post();
599
600 /* Make sure IO is disabled */
601 reg32 = pci_read_config32(PCH_ME_DEV, PCI_COMMAND);
602 reg32 &= ~(PCI_COMMAND_MASTER |
603 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
604 pci_write_config32(PCH_ME_DEV, PCI_COMMAND, reg32);
605
606 /* Hide the PCI device */
607 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
608}
609
610#else /* !__SMM__ */
611
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100612static inline int mei_sendrecv_icc(struct icc_header *icc,
613 void *req_data, int req_bytes,
614 void *rsp_data, int rsp_bytes)
615{
616 struct icc_header icc_rsp;
617
618 /* Send header */
619 if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
620 icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
621 return -1;
622
623 /* Send data if available */
624 if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
625 req_data, req_bytes) < 0)
626 return -1;
627
628 /* Read header and data, if needed */
629 if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
630 rsp_data, rsp_bytes) < 0)
631 return -1;
632
633 return 0;
634}
635
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700636static int me_icc_set_clock_enables(u32 mask)
637{
638 struct icc_clock_enables_msg clk = {
639 .clock_enables = 0, /* Turn off specified clocks */
640 .clock_mask = mask,
641 .no_response = 1, /* Do not expect response */
642 };
643 struct icc_header icc = {
644 .api_version = ICC_API_VERSION_LYNXPOINT,
645 .icc_command = ICC_SET_CLOCK_ENABLES,
646 .length = sizeof(clk),
647 };
648
649 /* Send request and wait for response */
650 if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
651 printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
652 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200653 } else {
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700654 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
655 }
656
657 return 0;
658}
659
Aaron Durbin76c37002012-10-30 09:03:43 -0500660/* Determine the path that we should take based on ME status */
661static me_bios_path intel_me_path(device_t dev)
662{
663 me_bios_path path = ME_DISABLE_BIOS_PATH;
664 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500665 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500666
Aaron Durbin76c37002012-10-30 09:03:43 -0500667 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500668 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500669
670 /* Check and dump status */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500671 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500672
673 /* Check Current Working State */
674 switch (hfs.working_state) {
675 case ME_HFS_CWS_NORMAL:
676 path = ME_NORMAL_BIOS_PATH;
677 break;
678 case ME_HFS_CWS_REC:
679 path = ME_RECOVERY_BIOS_PATH;
680 break;
681 default:
682 path = ME_DISABLE_BIOS_PATH;
683 break;
684 }
685
686 /* Check Current Operation Mode */
687 switch (hfs.operation_mode) {
688 case ME_HFS_MODE_NORMAL:
689 break;
690 case ME_HFS_MODE_DEBUG:
691 case ME_HFS_MODE_DIS:
692 case ME_HFS_MODE_OVER_JMPR:
693 case ME_HFS_MODE_OVER_MEI:
694 default:
695 path = ME_DISABLE_BIOS_PATH;
696 break;
697 }
698
699 /* Check for any error code and valid firmware and MBP */
700 if (hfs.error_code || hfs.fpt_bad)
701 path = ME_ERROR_BIOS_PATH;
702
703 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500704 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500705 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
706 __FUNCTION__);
707 path = ME_ERROR_BIOS_PATH;
708 }
709
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600710#if IS_ENABLED(CONFIG_ELOG)
Aaron Durbin76c37002012-10-30 09:03:43 -0500711 if (path != ME_NORMAL_BIOS_PATH) {
712 struct elog_event_data_me_extended data = {
713 .current_working_state = hfs.working_state,
714 .operation_state = hfs.operation_state,
715 .operation_mode = hfs.operation_mode,
716 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500717 .progress_code = hfs2.progress_code,
718 .current_pmevent = hfs2.current_pmevent,
719 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500720 };
721 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
722 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
723 &data, sizeof(data));
724 }
725#endif
726
727 return path;
728}
729
730/* Prepare ME for MEI messages */
731static int intel_mei_setup(device_t dev)
732{
733 struct resource *res;
734 struct mei_csr host;
735 u32 reg32;
736
737 /* Find the MMIO base for the ME interface */
738 res = find_resource(dev, PCI_BASE_ADDRESS_0);
739 if (!res || res->base == 0 || res->size == 0) {
740 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
741 return -1;
742 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800743 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500744
745 /* Ensure Memory and Bus Master bits are set */
746 reg32 = pci_read_config32(dev, PCI_COMMAND);
747 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
748 pci_write_config32(dev, PCI_COMMAND, reg32);
749
750 /* Clean up status for next message */
751 read_host_csr(&host);
752 host.interrupt_generate = 1;
753 host.ready = 1;
754 host.reset = 0;
755 write_host_csr(&host);
756
757 return 0;
758}
759
760/* Read the Extend register hash of ME firmware */
761static int intel_me_extend_valid(device_t dev)
762{
763 struct me_heres status;
764 u32 extend[8] = {0};
765 int i, count = 0;
766
767 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
768 if (!status.extend_feature_present) {
769 printk(BIOS_ERR, "ME: Extend Feature not present\n");
770 return -1;
771 }
772
773 if (!status.extend_reg_valid) {
774 printk(BIOS_ERR, "ME: Extend Register not valid\n");
775 return -1;
776 }
777
778 switch (status.extend_reg_algorithm) {
779 case PCI_ME_EXT_SHA1:
780 count = 5;
781 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
782 break;
783 case PCI_ME_EXT_SHA256:
784 count = 8;
785 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
786 break;
787 default:
788 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
789 status.extend_reg_algorithm);
790 return -1;
791 }
792
793 for (i = 0; i < count; ++i) {
794 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
795 printk(BIOS_DEBUG, "%08x", extend[i]);
796 }
797 printk(BIOS_DEBUG, "\n");
798
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600799#if IS_ENABLED(CONFIG_CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500800 /* Save hash in NVS for the OS to verify */
801 chromeos_set_me_hash(extend, count);
802#endif
803
804 return 0;
805}
806
Aaron Durbin76c37002012-10-30 09:03:43 -0500807/* Check whether ME is present and do basic init */
808static void intel_me_init(device_t dev)
809{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700810 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500811 me_bios_path path = intel_me_path(dev);
812 me_bios_payload mbp_data;
813
814 /* Do initial setup and determine the BIOS path */
815 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
816
Duncan Laurie8056dc62013-07-22 08:47:43 -0700817 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500818 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500819 intel_me_extend_valid(dev);
820 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500821
Aaron Durbinbe985242012-12-12 12:40:33 -0600822 memset(&mbp_data, 0, sizeof(mbp_data));
823
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500824 /*
825 * According to the ME9 BWG, BIOS is required to fetch MBP data in
826 * all boot flows except S3 Resume.
827 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500828
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500829 /* Prepare MEI MMIO interface */
830 if (intel_mei_setup(dev) < 0)
831 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500832
Duncan Laurie144f7b22013-05-01 11:27:58 -0700833 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500834 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500835
836#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG)
Aaron Durbinbe985242012-12-12 12:40:33 -0600837 me_print_fw_version(mbp_data.fw_version_name);
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600838#if IS_ENABLED(CONFIG_DEBUG_INTEL_ME)
Aaron Durbinbe985242012-12-12 12:40:33 -0600839 me_print_fwcaps(mbp_data.fw_capabilities);
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700840#endif
Duncan Laurie144f7b22013-05-01 11:27:58 -0700841
842 if (mbp_data.plat_time) {
843 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
844 mbp_data.plat_time->wake_event_mrst_time_ms);
845 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
846 mbp_data.plat_time->mrst_pltrst_time_ms);
847 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
848 mbp_data.plat_time->pltrst_cpurst_time_ms);
849 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500850#endif
851
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700852 /* Set clock enables according to devicetree */
853 if (config && config->icc_clock_disable)
854 me_icc_set_clock_enables(config->icc_clock_disable);
855
Duncan Laurieaf980622013-07-18 23:02:18 -0700856 /*
857 * Leave the ME unlocked. It will be locked via SMI command later.
858 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500859}
860
861static void set_subsystem(device_t dev, unsigned vendor, unsigned device)
862{
863 if (!vendor || !device) {
864 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
865 pci_read_config32(dev, PCI_VENDOR_ID));
866 } else {
867 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
868 ((device & 0xffff) << 16) | (vendor & 0xffff));
869 }
870}
871
872static struct pci_operations pci_ops = {
873 .set_subsystem = set_subsystem,
874};
875
Duncan Laurie8056dc62013-07-22 08:47:43 -0700876static void intel_me_enable(device_t dev)
877{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700878 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300879 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700880 dev->enabled = 0;
881 pch_disable_devfn(dev);
882 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700883}
884
Aaron Durbin76c37002012-10-30 09:03:43 -0500885static struct device_operations device_ops = {
886 .read_resources = pci_dev_read_resources,
887 .set_resources = pci_dev_set_resources,
888 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700889 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500890 .init = intel_me_init,
Aaron Durbin76c37002012-10-30 09:03:43 -0500891 .ops_pci = &pci_ops,
892};
893
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800894static const unsigned short pci_device_ids[] = {
895 0x8c3a, /* Mobile */
896 0x9c3a, /* Low Power */
897 0
898};
899
Aaron Durbin76c37002012-10-30 09:03:43 -0500900static const struct pci_driver intel_me __pci_driver = {
901 .ops = &device_ops,
902 .vendor = PCI_VENDOR_ID_INTEL,
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800903 .devices= pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500904};
905
906/******************************************************************************
907 * */
908static u32 me_to_host_words_pending(void)
909{
910 struct mei_csr me;
911 read_me_csr(&me);
912 if (!me.ready)
913 return 0;
914 return (me.buffer_write_ptr - me.buffer_read_ptr) &
915 (me.buffer_depth - 1);
916}
917
918#if 0
919/* This function is not yet being used, keep it in for the future. */
920static u32 host_to_me_words_room(void)
921{
922 struct mei_csr csr;
923
924 read_me_csr(&csr);
925 if (!csr.ready)
926 return 0;
927
928 read_host_csr(&csr);
929 return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) &
930 (csr.buffer_depth - 1);
931}
932#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500933
Aaron Durbinbe985242012-12-12 12:40:33 -0600934struct mbp_payload {
935 mbp_header header;
936 u32 data[0];
937};
938
Aaron Durbin76c37002012-10-30 09:03:43 -0500939/*
940 * mbp seems to be following its own flow, let's retrieve it in a dedicated
941 * function.
942 */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500943static int intel_me_read_mbp(me_bios_payload *mbp_data, device_t dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500944{
945 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500946 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500947 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500948 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600949 struct mbp_payload *mbp;
950 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500951
952 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
953
954 if (!hfs2.mbp_rdy) {
955 printk(BIOS_ERR, "ME: MBP not ready\n");
956 goto mbp_failure;
957 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500958
959 me2host_pending = me_to_host_words_pending();
960 if (!me2host_pending) {
961 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500962 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500963 }
964
965 /* we know for sure that at least the header is there */
966 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
967
968 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
969 (me2host_pending < mbp_hdr.mbp_size)) {
970 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
971 " buffer contains %d words\n",
972 mbp_hdr.num_entries, mbp_hdr.mbp_size,
973 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500974 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500975 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600976 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
977 if (!mbp)
978 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500979
Aaron Durbinbe985242012-12-12 12:40:33 -0600980 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500981 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500982
Aaron Durbinbe985242012-12-12 12:40:33 -0600983 i = 0;
984 while (i != me2host_pending) {
985 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
986 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500987 }
988
Aaron Durbinbe985242012-12-12 12:40:33 -0600989 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500990 read_host_csr(&host);
991 host.interrupt_generate = 1;
992 write_host_csr(&host);
993
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600994#if !IS_ENABLED(CONFIG_ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -0600995 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -0700996 intel_me_mbp_clear(dev);
997#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500998
Aaron Durbinbe985242012-12-12 12:40:33 -0600999 /* Dump out the MBP contents. */
1000#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG)
1001 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
1002 mbp->header.num_entries, mbp->header.mbp_size);
Martin Roth7a1a3ad2017-06-24 21:29:38 -06001003#if IS_ENABLED(CONFIG_DEBUG_INTEL_ME)
Aaron Durbinbe985242012-12-12 12:40:33 -06001004 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
1005 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
1006 }
1007#endif
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001008#endif
Aaron Durbinbe985242012-12-12 12:40:33 -06001009
1010 #define ASSIGN_FIELD_PTR(field_,val_) \
1011 { \
1012 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
1013 break; \
1014 }
1015 /* Setup the pointers in the me_bios_payload structure. */
1016 for (i = 0; i < mbp->header.mbp_size - 1;) {
1017 mbp_item_header *item = (void *)&mbp->data[i];
1018
Elyes HAOUASf9de5a42018-05-03 17:21:02 +02001019 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -06001020 case MBP_IDENT(KERNEL, FW_VER):
1021 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
1022
1023 case MBP_IDENT(ICC, PROFILE):
1024 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
1025
1026 case MBP_IDENT(INTEL_AT, STATE):
1027 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
1028
1029 case MBP_IDENT(KERNEL, FW_CAP):
1030 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
1031
1032 case MBP_IDENT(KERNEL, ROM_BIST):
1033 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
1034
1035 case MBP_IDENT(KERNEL, PLAT_KEY):
1036 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
1037
1038 case MBP_IDENT(KERNEL, FW_TYPE):
1039 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
1040
1041 case MBP_IDENT(KERNEL, MFS_FAILURE):
1042 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
1043
Duncan Laurie144f7b22013-05-01 11:27:58 -07001044 case MBP_IDENT(KERNEL, PLAT_TIME):
1045 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
1046
1047 case MBP_IDENT(NFC, SUPPORT_DATA):
1048 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
1049
Aaron Durbinbe985242012-12-12 12:40:33 -06001050 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001051 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
1052 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -06001053 break;
1054 }
1055 i += item->length;
1056 }
1057 #undef ASSIGN_FIELD_PTR
1058
Aaron Durbin76c37002012-10-30 09:03:43 -05001059 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001060
1061mbp_failure:
1062 intel_me_mbp_give_up(dev);
1063 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001064}
Duncan Laurieaf980622013-07-18 23:02:18 -07001065
1066#endif /* !__SMM__ */