blob: 574a8308d6037355f97cb1bcf64ef2d5e8b73482 [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;
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700653 }
654
Elyes HAOUAS54f94242018-10-25 10:57:39 +0200655 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700656 return 0;
657}
658
Aaron Durbin76c37002012-10-30 09:03:43 -0500659/* Determine the path that we should take based on ME status */
660static me_bios_path intel_me_path(device_t dev)
661{
662 me_bios_path path = ME_DISABLE_BIOS_PATH;
663 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500664 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500665
Aaron Durbin76c37002012-10-30 09:03:43 -0500666 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500667 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500668
669 /* Check and dump status */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500670 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500671
672 /* Check Current Working State */
673 switch (hfs.working_state) {
674 case ME_HFS_CWS_NORMAL:
675 path = ME_NORMAL_BIOS_PATH;
676 break;
677 case ME_HFS_CWS_REC:
678 path = ME_RECOVERY_BIOS_PATH;
679 break;
680 default:
681 path = ME_DISABLE_BIOS_PATH;
682 break;
683 }
684
685 /* Check Current Operation Mode */
686 switch (hfs.operation_mode) {
687 case ME_HFS_MODE_NORMAL:
688 break;
689 case ME_HFS_MODE_DEBUG:
690 case ME_HFS_MODE_DIS:
691 case ME_HFS_MODE_OVER_JMPR:
692 case ME_HFS_MODE_OVER_MEI:
693 default:
694 path = ME_DISABLE_BIOS_PATH;
695 break;
696 }
697
698 /* Check for any error code and valid firmware and MBP */
699 if (hfs.error_code || hfs.fpt_bad)
700 path = ME_ERROR_BIOS_PATH;
701
702 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500703 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500704 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
705 __FUNCTION__);
706 path = ME_ERROR_BIOS_PATH;
707 }
708
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600709#if IS_ENABLED(CONFIG_ELOG)
Aaron Durbin76c37002012-10-30 09:03:43 -0500710 if (path != ME_NORMAL_BIOS_PATH) {
711 struct elog_event_data_me_extended data = {
712 .current_working_state = hfs.working_state,
713 .operation_state = hfs.operation_state,
714 .operation_mode = hfs.operation_mode,
715 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500716 .progress_code = hfs2.progress_code,
717 .current_pmevent = hfs2.current_pmevent,
718 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500719 };
720 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
721 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
722 &data, sizeof(data));
723 }
724#endif
725
726 return path;
727}
728
729/* Prepare ME for MEI messages */
730static int intel_mei_setup(device_t dev)
731{
732 struct resource *res;
733 struct mei_csr host;
734 u32 reg32;
735
736 /* Find the MMIO base for the ME interface */
737 res = find_resource(dev, PCI_BASE_ADDRESS_0);
738 if (!res || res->base == 0 || res->size == 0) {
739 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
740 return -1;
741 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800742 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500743
744 /* Ensure Memory and Bus Master bits are set */
745 reg32 = pci_read_config32(dev, PCI_COMMAND);
746 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
747 pci_write_config32(dev, PCI_COMMAND, reg32);
748
749 /* Clean up status for next message */
750 read_host_csr(&host);
751 host.interrupt_generate = 1;
752 host.ready = 1;
753 host.reset = 0;
754 write_host_csr(&host);
755
756 return 0;
757}
758
759/* Read the Extend register hash of ME firmware */
760static int intel_me_extend_valid(device_t dev)
761{
762 struct me_heres status;
763 u32 extend[8] = {0};
764 int i, count = 0;
765
766 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
767 if (!status.extend_feature_present) {
768 printk(BIOS_ERR, "ME: Extend Feature not present\n");
769 return -1;
770 }
771
772 if (!status.extend_reg_valid) {
773 printk(BIOS_ERR, "ME: Extend Register not valid\n");
774 return -1;
775 }
776
777 switch (status.extend_reg_algorithm) {
778 case PCI_ME_EXT_SHA1:
779 count = 5;
780 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
781 break;
782 case PCI_ME_EXT_SHA256:
783 count = 8;
784 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
785 break;
786 default:
787 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
788 status.extend_reg_algorithm);
789 return -1;
790 }
791
792 for (i = 0; i < count; ++i) {
793 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
794 printk(BIOS_DEBUG, "%08x", extend[i]);
795 }
796 printk(BIOS_DEBUG, "\n");
797
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600798#if IS_ENABLED(CONFIG_CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500799 /* Save hash in NVS for the OS to verify */
800 chromeos_set_me_hash(extend, count);
801#endif
802
803 return 0;
804}
805
Aaron Durbin76c37002012-10-30 09:03:43 -0500806/* Check whether ME is present and do basic init */
807static void intel_me_init(device_t dev)
808{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700809 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500810 me_bios_path path = intel_me_path(dev);
811 me_bios_payload mbp_data;
812
813 /* Do initial setup and determine the BIOS path */
814 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
815
Duncan Laurie8056dc62013-07-22 08:47:43 -0700816 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500817 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500818 intel_me_extend_valid(dev);
819 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500820
Aaron Durbinbe985242012-12-12 12:40:33 -0600821 memset(&mbp_data, 0, sizeof(mbp_data));
822
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500823 /*
824 * According to the ME9 BWG, BIOS is required to fetch MBP data in
825 * all boot flows except S3 Resume.
826 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500827
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500828 /* Prepare MEI MMIO interface */
829 if (intel_mei_setup(dev) < 0)
830 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500831
Duncan Laurie144f7b22013-05-01 11:27:58 -0700832 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500833 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500834
835#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG)
Aaron Durbinbe985242012-12-12 12:40:33 -0600836 me_print_fw_version(mbp_data.fw_version_name);
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600837#if IS_ENABLED(CONFIG_DEBUG_INTEL_ME)
Aaron Durbinbe985242012-12-12 12:40:33 -0600838 me_print_fwcaps(mbp_data.fw_capabilities);
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700839#endif
Duncan Laurie144f7b22013-05-01 11:27:58 -0700840
841 if (mbp_data.plat_time) {
842 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
843 mbp_data.plat_time->wake_event_mrst_time_ms);
844 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
845 mbp_data.plat_time->mrst_pltrst_time_ms);
846 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
847 mbp_data.plat_time->pltrst_cpurst_time_ms);
848 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500849#endif
850
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700851 /* Set clock enables according to devicetree */
852 if (config && config->icc_clock_disable)
853 me_icc_set_clock_enables(config->icc_clock_disable);
854
Duncan Laurieaf980622013-07-18 23:02:18 -0700855 /*
856 * Leave the ME unlocked. It will be locked via SMI command later.
857 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500858}
859
860static void set_subsystem(device_t dev, unsigned vendor, unsigned device)
861{
862 if (!vendor || !device) {
863 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
864 pci_read_config32(dev, PCI_VENDOR_ID));
865 } else {
866 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
867 ((device & 0xffff) << 16) | (vendor & 0xffff));
868 }
869}
870
871static struct pci_operations pci_ops = {
872 .set_subsystem = set_subsystem,
873};
874
Duncan Laurie8056dc62013-07-22 08:47:43 -0700875static void intel_me_enable(device_t dev)
876{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700877 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300878 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700879 dev->enabled = 0;
880 pch_disable_devfn(dev);
881 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700882}
883
Aaron Durbin76c37002012-10-30 09:03:43 -0500884static struct device_operations device_ops = {
885 .read_resources = pci_dev_read_resources,
886 .set_resources = pci_dev_set_resources,
887 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700888 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500889 .init = intel_me_init,
Aaron Durbin76c37002012-10-30 09:03:43 -0500890 .ops_pci = &pci_ops,
891};
892
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800893static const unsigned short pci_device_ids[] = {
894 0x8c3a, /* Mobile */
895 0x9c3a, /* Low Power */
896 0
897};
898
Aaron Durbin76c37002012-10-30 09:03:43 -0500899static const struct pci_driver intel_me __pci_driver = {
900 .ops = &device_ops,
901 .vendor = PCI_VENDOR_ID_INTEL,
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800902 .devices= pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500903};
904
905/******************************************************************************
906 * */
907static u32 me_to_host_words_pending(void)
908{
909 struct mei_csr me;
910 read_me_csr(&me);
911 if (!me.ready)
912 return 0;
913 return (me.buffer_write_ptr - me.buffer_read_ptr) &
914 (me.buffer_depth - 1);
915}
916
917#if 0
918/* This function is not yet being used, keep it in for the future. */
919static u32 host_to_me_words_room(void)
920{
921 struct mei_csr csr;
922
923 read_me_csr(&csr);
924 if (!csr.ready)
925 return 0;
926
927 read_host_csr(&csr);
928 return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) &
929 (csr.buffer_depth - 1);
930}
931#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500932
Aaron Durbinbe985242012-12-12 12:40:33 -0600933struct mbp_payload {
934 mbp_header header;
935 u32 data[0];
936};
937
Aaron Durbin76c37002012-10-30 09:03:43 -0500938/*
939 * mbp seems to be following its own flow, let's retrieve it in a dedicated
940 * function.
941 */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500942static int intel_me_read_mbp(me_bios_payload *mbp_data, device_t dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500943{
944 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500945 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500946 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500947 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600948 struct mbp_payload *mbp;
949 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500950
951 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
952
953 if (!hfs2.mbp_rdy) {
954 printk(BIOS_ERR, "ME: MBP not ready\n");
955 goto mbp_failure;
956 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500957
958 me2host_pending = me_to_host_words_pending();
959 if (!me2host_pending) {
960 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500961 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500962 }
963
964 /* we know for sure that at least the header is there */
965 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
966
967 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
968 (me2host_pending < mbp_hdr.mbp_size)) {
969 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
970 " buffer contains %d words\n",
971 mbp_hdr.num_entries, mbp_hdr.mbp_size,
972 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500973 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500974 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600975 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
976 if (!mbp)
977 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500978
Aaron Durbinbe985242012-12-12 12:40:33 -0600979 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500980 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500981
Aaron Durbinbe985242012-12-12 12:40:33 -0600982 i = 0;
983 while (i != me2host_pending) {
984 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
985 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500986 }
987
Aaron Durbinbe985242012-12-12 12:40:33 -0600988 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500989 read_host_csr(&host);
990 host.interrupt_generate = 1;
991 write_host_csr(&host);
992
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600993#if !IS_ENABLED(CONFIG_ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -0600994 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -0700995 intel_me_mbp_clear(dev);
996#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500997
Aaron Durbinbe985242012-12-12 12:40:33 -0600998 /* Dump out the MBP contents. */
999#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG)
1000 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
1001 mbp->header.num_entries, mbp->header.mbp_size);
Martin Roth7a1a3ad2017-06-24 21:29:38 -06001002#if IS_ENABLED(CONFIG_DEBUG_INTEL_ME)
Aaron Durbinbe985242012-12-12 12:40:33 -06001003 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
1004 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
1005 }
1006#endif
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001007#endif
Aaron Durbinbe985242012-12-12 12:40:33 -06001008
1009 #define ASSIGN_FIELD_PTR(field_,val_) \
1010 { \
1011 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
1012 break; \
1013 }
1014 /* Setup the pointers in the me_bios_payload structure. */
1015 for (i = 0; i < mbp->header.mbp_size - 1;) {
1016 mbp_item_header *item = (void *)&mbp->data[i];
1017
Elyes HAOUASf9de5a42018-05-03 17:21:02 +02001018 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -06001019 case MBP_IDENT(KERNEL, FW_VER):
1020 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
1021
1022 case MBP_IDENT(ICC, PROFILE):
1023 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
1024
1025 case MBP_IDENT(INTEL_AT, STATE):
1026 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
1027
1028 case MBP_IDENT(KERNEL, FW_CAP):
1029 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
1030
1031 case MBP_IDENT(KERNEL, ROM_BIST):
1032 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
1033
1034 case MBP_IDENT(KERNEL, PLAT_KEY):
1035 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
1036
1037 case MBP_IDENT(KERNEL, FW_TYPE):
1038 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
1039
1040 case MBP_IDENT(KERNEL, MFS_FAILURE):
1041 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
1042
Duncan Laurie144f7b22013-05-01 11:27:58 -07001043 case MBP_IDENT(KERNEL, PLAT_TIME):
1044 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
1045
1046 case MBP_IDENT(NFC, SUPPORT_DATA):
1047 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
1048
Aaron Durbinbe985242012-12-12 12:40:33 -06001049 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001050 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
1051 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -06001052 break;
1053 }
1054 i += item->length;
1055 }
1056 #undef ASSIGN_FIELD_PTR
1057
Aaron Durbin76c37002012-10-30 09:03:43 -05001058 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001059
1060mbp_failure:
1061 intel_me_mbp_give_up(dev);
1062 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001063}
Duncan Laurieaf980622013-07-18 23:02:18 -07001064
1065#endif /* !__SMM__ */