blob: 2df03c9cdc40123dde5c3bc6d110c1dcb01757f0 [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>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020026#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020027#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050028#include <console/console.h>
Stefan Reinauer24d1d4b2013-03-21 11:51:41 -070029#include <device/device.h>
30#include <device/pci.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050031#include <device/pci_ids.h>
32#include <device/pci_def.h>
33#include <string.h>
34#include <delay.h>
35#include <elog.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010036#include <halt.h>
Elyes HAOUAS400f9ca2019-06-23 07:01:22 +020037#include <stdlib.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050038
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030039#include "chip.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050040#include "me.h"
41#include "pch.h"
42
Julius Wernercd49cce2019-03-05 16:53:33 -080043#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -050044#include <vendorcode/google/chromeos/chromeos.h>
45#include <vendorcode/google/chromeos/gnvs.h>
46#endif
47
Aaron Durbin76c37002012-10-30 09:03:43 -050048/* Path that the BIOS should take based on ME state */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +020049static const char *me_bios_path_values[] __unused = {
Aaron Durbin76c37002012-10-30 09:03:43 -050050 [ME_NORMAL_BIOS_PATH] = "Normal",
51 [ME_S3WAKE_BIOS_PATH] = "S3 Wake",
52 [ME_ERROR_BIOS_PATH] = "Error",
53 [ME_RECOVERY_BIOS_PATH] = "Recovery",
54 [ME_DISABLE_BIOS_PATH] = "Disable",
55 [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update",
56};
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010057static int intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev);
Aaron Durbin76c37002012-10-30 09:03:43 -050058
59/* MMIO base address for MEI interface */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080060static u32 *mei_base_address;
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010061#ifdef __SIMPLE_DEVICE__
62void intel_me_mbp_clear(pci_devfn_t dev);
63#else
64void intel_me_mbp_clear(struct device *dev);
65#endif
Aaron Durbin76c37002012-10-30 09:03:43 -050066
Aaron Durbin76c37002012-10-30 09:03:43 -050067static void mei_dump(void *ptr, int dword, int offset, const char *type)
68{
69 struct mei_csr *csr;
70
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +020071 if (!CONFIG(DEBUG_INTEL_ME))
72 return;
73
Aaron Durbin76c37002012-10-30 09:03:43 -050074 printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset);
75
76 switch (offset) {
77 case MEI_H_CSR:
78 case MEI_ME_CSR_HA:
79 csr = ptr;
80 if (!csr) {
81 printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword);
82 break;
83 }
84 printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
85 "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth,
86 csr->buffer_read_ptr, csr->buffer_write_ptr,
87 csr->ready, csr->reset, csr->interrupt_generate,
88 csr->interrupt_status, csr->interrupt_enable);
89 break;
90 case MEI_ME_CB_RW:
91 case MEI_H_CB_WW:
92 printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
93 break;
94 default:
95 printk(BIOS_SPEW, "0x%08x\n", offset);
96 break;
97 }
98}
Aaron Durbin76c37002012-10-30 09:03:43 -050099
100/*
101 * ME/MEI access helpers using memcpy to avoid aliasing.
102 */
103
104static inline void mei_read_dword_ptr(void *ptr, int offset)
105{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800106 u32 dword = read32(mei_base_address + (offset/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500107 memcpy(ptr, &dword, sizeof(dword));
108 mei_dump(ptr, dword, offset, "READ");
109}
110
111static inline void mei_write_dword_ptr(void *ptr, int offset)
112{
113 u32 dword = 0;
114 memcpy(&dword, ptr, sizeof(dword));
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800115 write32(mei_base_address + (offset/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500116 mei_dump(ptr, dword, offset, "WRITE");
117}
118
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100119#ifdef __SIMPLE_DEVICE__
120static inline void pci_read_dword_ptr(pci_devfn_t dev, void *ptr, int offset)
121#else
122static inline void pci_read_dword_ptr(struct device *dev, void *ptr, int offset)
123#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500124{
125 u32 dword = pci_read_config32(dev, offset);
126 memcpy(ptr, &dword, sizeof(dword));
127 mei_dump(ptr, dword, offset, "PCI READ");
128}
Aaron Durbin76c37002012-10-30 09:03:43 -0500129
130static inline void read_host_csr(struct mei_csr *csr)
131{
132 mei_read_dword_ptr(csr, MEI_H_CSR);
133}
134
135static inline void write_host_csr(struct mei_csr *csr)
136{
137 mei_write_dword_ptr(csr, MEI_H_CSR);
138}
139
140static inline void read_me_csr(struct mei_csr *csr)
141{
142 mei_read_dword_ptr(csr, MEI_ME_CSR_HA);
143}
144
145static inline void write_cb(u32 dword)
146{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800147 write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500148 mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE");
149}
150
151static inline u32 read_cb(void)
152{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800153 u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500154 mei_dump(NULL, dword, MEI_ME_CB_RW, "READ");
155 return dword;
156}
157
158/* Wait for ME ready bit to be asserted */
159static int mei_wait_for_me_ready(void)
160{
161 struct mei_csr me;
Martin Rothff744bf2019-10-23 21:46:03 -0600162 unsigned int try = ME_RETRY;
Aaron Durbin76c37002012-10-30 09:03:43 -0500163
164 while (try--) {
165 read_me_csr(&me);
166 if (me.ready)
167 return 0;
168 udelay(ME_DELAY);
169 }
170
171 printk(BIOS_ERR, "ME: failed to become ready\n");
172 return -1;
173}
174
175static void mei_reset(void)
176{
177 struct mei_csr host;
178
179 if (mei_wait_for_me_ready() < 0)
180 return;
181
182 /* Reset host and ME circular buffers for next message */
183 read_host_csr(&host);
184 host.reset = 1;
185 host.interrupt_generate = 1;
186 write_host_csr(&host);
187
188 if (mei_wait_for_me_ready() < 0)
189 return;
190
191 /* Re-init and indicate host is ready */
192 read_host_csr(&host);
193 host.interrupt_generate = 1;
194 host.ready = 1;
195 host.reset = 0;
196 write_host_csr(&host);
197}
198
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700199static int mei_send_packet(struct mei_header *mei, void *req_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500200{
201 struct mei_csr host;
Martin Rothff744bf2019-10-23 21:46:03 -0600202 unsigned int ndata, n;
Aaron Durbin76c37002012-10-30 09:03:43 -0500203 u32 *data;
204
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700205 /* Number of dwords to write */
Aaron Durbin76c37002012-10-30 09:03:43 -0500206 ndata = mei->length >> 2;
207
208 /* Pad non-dword aligned request message length */
209 if (mei->length & 3)
210 ndata++;
211 if (!ndata) {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700212 printk(BIOS_DEBUG, "ME: request has no data\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500213 return -1;
214 }
215 ndata++; /* Add MEI header */
216
217 /*
218 * Make sure there is still room left in the circular buffer.
219 * Reset the buffer pointers if the requested message will not fit.
220 */
221 read_host_csr(&host);
222 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
223 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
224 mei_reset();
225 read_host_csr(&host);
226 }
227
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700228 /* Ensure the requested length will fit in the circular buffer. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500229 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
230 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
231 ndata + 2, host.buffer_depth);
232 return -1;
233 }
234
235 /* Write MEI header */
236 mei_write_dword_ptr(mei, MEI_H_CB_WW);
237 ndata--;
238
Aaron Durbin76c37002012-10-30 09:03:43 -0500239 /* Write message data */
240 data = req_data;
241 for (n = 0; n < ndata; ++n)
242 write_cb(*data++);
243
244 /* Generate interrupt to the ME */
245 read_host_csr(&host);
246 host.interrupt_generate = 1;
247 write_host_csr(&host);
248
249 /* Make sure ME is ready after sending request data */
250 return mei_wait_for_me_ready();
251}
252
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700253static int mei_send_data(u8 me_address, u8 host_address,
254 void *req_data, int req_bytes)
255{
256 struct mei_header header = {
257 .client_address = me_address,
258 .host_address = host_address,
259 };
260 struct mei_csr host;
261 int current = 0;
262 u8 *req_ptr = req_data;
263
264 while (!header.is_complete) {
265 int remain = req_bytes - current;
266 int buf_len;
267
268 read_host_csr(&host);
269 buf_len = host.buffer_depth - host.buffer_write_ptr;
270
271 if (buf_len > remain) {
272 /* Send all remaining data as final message */
273 header.length = req_bytes - current;
274 header.is_complete = 1;
275 } else {
276 /* Send as much data as the buffer can hold */
277 header.length = buf_len;
278 }
279
280 mei_send_packet(&header, req_ptr);
281
282 req_ptr += header.length;
283 current += header.length;
284 }
285
286 return 0;
287}
288
289static int mei_send_header(u8 me_address, u8 host_address,
290 void *header, int header_len, int complete)
291{
292 struct mei_header mei = {
293 .client_address = me_address,
294 .host_address = host_address,
295 .length = header_len,
296 .is_complete = complete,
297 };
298 return mei_send_packet(&mei, header);
299}
300
301static int mei_recv_msg(void *header, int header_bytes,
Aaron Durbin76c37002012-10-30 09:03:43 -0500302 void *rsp_data, int rsp_bytes)
303{
304 struct mei_header mei_rsp;
Aaron Durbin76c37002012-10-30 09:03:43 -0500305 struct mei_csr me, host;
Martin Rothff744bf2019-10-23 21:46:03 -0600306 unsigned int ndata, n;
307 unsigned int expected;
Aaron Durbin76c37002012-10-30 09:03:43 -0500308 u32 *data;
309
310 /* Total number of dwords to read from circular buffer */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700311 expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500312 if (rsp_bytes & 3)
313 expected++;
314
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700315 if (mei_wait_for_me_ready() < 0)
316 return -1;
317
Aaron Durbin76c37002012-10-30 09:03:43 -0500318 /*
319 * The interrupt status bit does not appear to indicate that the
320 * message has actually been received. Instead we wait until the
321 * expected number of dwords are present in the circular buffer.
322 */
323 for (n = ME_RETRY; n; --n) {
324 read_me_csr(&me);
325 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
326 break;
327 udelay(ME_DELAY);
328 }
329 if (!n) {
330 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
331 "%u, available %u\n", expected,
332 me.buffer_write_ptr - me.buffer_read_ptr);
333 return -1;
334 }
335
336 /* Read and verify MEI response header from the ME */
337 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
338 if (!mei_rsp.is_complete) {
339 printk(BIOS_ERR, "ME: response is not complete\n");
340 return -1;
341 }
342
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700343 /* Handle non-dword responses and expect at least the header */
Aaron Durbin76c37002012-10-30 09:03:43 -0500344 ndata = mei_rsp.length >> 2;
345 if (mei_rsp.length & 3)
346 ndata++;
347 if (ndata != (expected - 1)) {
348 printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
349 ndata, (expected - 1));
350 return -1;
351 }
352
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700353 /* Read response header from the ME */
354 data = header;
355 for (n = 0; n < (header_bytes >> 2); ++n)
356 *data++ = read_cb();
357 ndata -= header_bytes >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500358
359 /* Make sure caller passed a buffer with enough space */
360 if (ndata != (rsp_bytes >> 2)) {
361 printk(BIOS_ERR, "ME: not enough room in response buffer: "
362 "%u != %u\n", ndata, rsp_bytes >> 2);
363 return -1;
364 }
365
366 /* Read response data from the circular buffer */
367 data = rsp_data;
368 for (n = 0; n < ndata; ++n)
369 *data++ = read_cb();
370
371 /* Tell the ME that we have consumed the response */
372 read_host_csr(&host);
373 host.interrupt_status = 1;
374 host.interrupt_generate = 1;
375 write_host_csr(&host);
376
377 return mei_wait_for_me_ready();
378}
379
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700380static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
381 void *req_data, int req_bytes,
382 void *rsp_data, int rsp_bytes)
Aaron Durbin76c37002012-10-30 09:03:43 -0500383{
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700384 struct mkhi_header mkhi_rsp;
385
386 /* Send header */
387 if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
388 mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500389 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700390
391 /* Send data if available */
392 if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
393 req_data, req_bytes) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500394 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700395
396 /* Return now if no response expected */
397 if (!rsp_bytes)
398 return 0;
399
400 /* Read header and data */
401 if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
402 rsp_data, rsp_bytes) < 0)
403 return -1;
404
405 if (!mkhi_rsp.is_response ||
406 mkhi->group_id != mkhi_rsp.group_id ||
407 mkhi->command != mkhi_rsp.command) {
408 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
409 "command %u ?= %u, is_response %u\n", mkhi->group_id,
410 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
411 mkhi_rsp.is_response);
412 return -1;
413 }
414
Aaron Durbin76c37002012-10-30 09:03:43 -0500415 return 0;
416}
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700417
Duncan Laurie3d299c42013-07-19 08:48:05 -0700418/*
419 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
420 * state machine on the BIOS end doesn't match the ME's state machine.
421 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100422#ifdef __SIMPLE_DEVICE__
423static void intel_me_mbp_give_up(pci_devfn_t dev)
424#else
425static void intel_me_mbp_give_up(struct device *dev)
426#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700427{
428 struct mei_csr csr;
429
430 pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP);
431
432 read_host_csr(&csr);
433 csr.reset = 1;
434 csr.interrupt_generate = 1;
435 write_host_csr(&csr);
436}
437
438/*
439 * mbp clear routine. This will wait for the ME to indicate that
440 * the MBP has been read and cleared.
441 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100442#ifdef __SIMPLE_DEVICE__
443void intel_me_mbp_clear(pci_devfn_t dev)
444#else
445void intel_me_mbp_clear(struct device *dev)
446#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700447{
448 int count;
449 struct me_hfs2 hfs2;
450
451 /* Wait for the mbp_cleared indicator */
452 for (count = ME_RETRY; count > 0; --count) {
453 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
454 if (hfs2.mbp_cleared)
455 break;
456 udelay(ME_DELAY);
457 }
458
459 if (count == 0) {
460 printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n");
461 intel_me_mbp_give_up(dev);
462 } else {
463 printk(BIOS_INFO, "ME: MBP cleared\n");
464 }
465}
466
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200467static void __unused me_print_fw_version(mbp_fw_version_name *vers_name)
Aaron Durbin76c37002012-10-30 09:03:43 -0500468{
Aaron Durbinbe985242012-12-12 12:40:33 -0600469 if (!vers_name) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500470 printk(BIOS_ERR, "ME: mbp missing version report\n");
471 return;
472 }
473
474 printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
475 vers_name->major_version, vers_name->minor_version,
476 vers_name->hotfix_version, vers_name->build_version);
477}
478
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000479static inline void print_cap(const char *name, int state)
480{
481 printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
482 name, state ? " en" : "dis");
483}
484
Aaron Durbin76c37002012-10-30 09:03:43 -0500485/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600486static int mkhi_get_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500487{
488 u32 rule_id = 0;
489 struct me_fwcaps cap_msg;
490 struct mkhi_header mkhi = {
491 .group_id = MKHI_GROUP_ID_FWCAPS,
492 .command = MKHI_FWCAPS_GET_RULE,
493 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500494
495 /* Send request and wait for response */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700496 if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
497 &cap_msg, sizeof(cap_msg)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500498 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
499 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200500 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500501 *cap = cap_msg.caps_sku;
502 return 0;
503}
504
505/* Get ME Firmware Capabilities */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200506static void __unused me_print_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500507{
Aaron Durbinbe985242012-12-12 12:40:33 -0600508 mbp_mefwcaps local_caps;
509 if (!cap) {
510 cap = &local_caps;
Aaron Durbin76c37002012-10-30 09:03:43 -0500511 printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
512 if (mkhi_get_fwcaps(cap))
513 return;
514 }
515
516 print_cap("Full Network manageability", cap->full_net);
517 print_cap("Regular Network manageability", cap->std_net);
518 print_cap("Manageability", cap->manageability);
Aaron Durbin76c37002012-10-30 09:03:43 -0500519 print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
520 print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
521 print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
522 print_cap("ICC Over Clocking", cap->icc_over_clocking);
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000523 print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
Aaron Durbin76c37002012-10-30 09:03:43 -0500524 print_cap("IPV6", cap->ipv6);
525 print_cap("KVM Remote Control (KVM)", cap->kvm);
526 print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
527 print_cap("Virtual LAN (VLAN)", cap->vlan);
528 print_cap("TLS", cap->tls);
529 print_cap("Wireless LAN (WLAN)", cap->wlan);
530}
Aaron Durbin76c37002012-10-30 09:03:43 -0500531
Julius Wernercd49cce2019-03-05 16:53:33 -0800532#if CONFIG(CHROMEOS) && 0 /* DISABLED */
Aaron Durbin76c37002012-10-30 09:03:43 -0500533/* Tell ME to issue a global reset */
534static int mkhi_global_reset(void)
535{
536 struct me_global_reset reset = {
537 .request_origin = GLOBAL_RESET_BIOS_POST,
538 .reset_type = CBM_RR_GLOBAL_RESET,
539 };
540 struct mkhi_header mkhi = {
541 .group_id = MKHI_GROUP_ID_CBM,
542 .command = MKHI_GLOBAL_RESET,
543 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500544
545 /* Send request and wait for response */
546 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700547 if (mei_sendrecv_mkhi(&mkhi, &reset, sizeof(reset), NULL, 0) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500548 /* No response means reset will happen shortly... */
Patrick Georgi546953c2014-11-29 10:38:17 +0100549 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500550 }
551
552 /* If the ME responded it rejected the reset request */
553 printk(BIOS_ERR, "ME: Global Reset failed\n");
554 return -1;
555}
556#endif
557
Aaron Durbin76c37002012-10-30 09:03:43 -0500558/* Send END OF POST message to the ME */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200559static int __unused mkhi_end_of_post(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500560{
561 struct mkhi_header mkhi = {
562 .group_id = MKHI_GROUP_ID_GEN,
563 .command = MKHI_END_OF_POST,
564 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500565 u32 eop_ack;
566
567 /* Send request and wait for response */
568 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700569 if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500570 printk(BIOS_ERR, "ME: END OF POST message failed\n");
571 return -1;
572 }
573
574 printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
575 return 0;
576}
577
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200578#ifdef __SIMPLE_DEVICE__
579
Duncan Laurieaf980622013-07-18 23:02:18 -0700580void intel_me_finalize_smm(void)
581{
582 struct me_hfs hfs;
583 u32 reg32;
584
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800585 mei_base_address = (u32 *)
586 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Duncan Laurieaf980622013-07-18 23:02:18 -0700587
588 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800589 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700590 return;
591
Julius Wernercd49cce2019-03-05 16:53:33 -0800592#if CONFIG(ME_MBP_CLEAR_LATE)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700593 /* Wait for ME MBP Cleared indicator */
594 intel_me_mbp_clear(PCH_ME_DEV);
595#endif
596
Duncan Laurieaf980622013-07-18 23:02:18 -0700597 /* Make sure ME is in a mode that expects EOP */
598 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
599 memcpy(&hfs, &reg32, sizeof(u32));
600
601 /* Abort and leave device alone if not normal mode */
602 if (hfs.fpt_bad ||
603 hfs.working_state != ME_HFS_CWS_NORMAL ||
604 hfs.operation_mode != ME_HFS_MODE_NORMAL)
605 return;
606
607 /* Try to send EOP command so ME stops accepting other commands */
608 mkhi_end_of_post();
609
610 /* Make sure IO is disabled */
611 reg32 = pci_read_config32(PCH_ME_DEV, PCI_COMMAND);
612 reg32 &= ~(PCI_COMMAND_MASTER |
613 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
614 pci_write_config32(PCH_ME_DEV, PCI_COMMAND, reg32);
615
616 /* Hide the PCI device */
617 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
618}
619
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200620#else /* !__SIMPLE_DEVICE__ */
Duncan Laurieaf980622013-07-18 23:02:18 -0700621
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100622static inline int mei_sendrecv_icc(struct icc_header *icc,
623 void *req_data, int req_bytes,
624 void *rsp_data, int rsp_bytes)
625{
626 struct icc_header icc_rsp;
627
628 /* Send header */
629 if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
630 icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
631 return -1;
632
633 /* Send data if available */
634 if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
635 req_data, req_bytes) < 0)
636 return -1;
637
638 /* Read header and data, if needed */
639 if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
640 rsp_data, rsp_bytes) < 0)
641 return -1;
642
643 return 0;
644}
645
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700646static int me_icc_set_clock_enables(u32 mask)
647{
648 struct icc_clock_enables_msg clk = {
649 .clock_enables = 0, /* Turn off specified clocks */
650 .clock_mask = mask,
651 .no_response = 1, /* Do not expect response */
652 };
653 struct icc_header icc = {
654 .api_version = ICC_API_VERSION_LYNXPOINT,
655 .icc_command = ICC_SET_CLOCK_ENABLES,
656 .length = sizeof(clk),
657 };
658
659 /* Send request and wait for response */
660 if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
661 printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
662 return -1;
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700663 }
664
Elyes HAOUAS54f94242018-10-25 10:57:39 +0200665 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700666 return 0;
667}
668
Aaron Durbin76c37002012-10-30 09:03:43 -0500669/* Determine the path that we should take based on ME status */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100670static me_bios_path intel_me_path(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500671{
672 me_bios_path path = ME_DISABLE_BIOS_PATH;
673 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500674 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500675
Aaron Durbin76c37002012-10-30 09:03:43 -0500676 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500677 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500678
679 /* Check and dump status */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500680 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500681
682 /* Check Current Working State */
683 switch (hfs.working_state) {
684 case ME_HFS_CWS_NORMAL:
685 path = ME_NORMAL_BIOS_PATH;
686 break;
687 case ME_HFS_CWS_REC:
688 path = ME_RECOVERY_BIOS_PATH;
689 break;
690 default:
691 path = ME_DISABLE_BIOS_PATH;
692 break;
693 }
694
695 /* Check Current Operation Mode */
696 switch (hfs.operation_mode) {
697 case ME_HFS_MODE_NORMAL:
698 break;
699 case ME_HFS_MODE_DEBUG:
700 case ME_HFS_MODE_DIS:
701 case ME_HFS_MODE_OVER_JMPR:
702 case ME_HFS_MODE_OVER_MEI:
703 default:
704 path = ME_DISABLE_BIOS_PATH;
705 break;
706 }
707
708 /* Check for any error code and valid firmware and MBP */
709 if (hfs.error_code || hfs.fpt_bad)
710 path = ME_ERROR_BIOS_PATH;
711
712 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500713 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500714 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
715 __FUNCTION__);
716 path = ME_ERROR_BIOS_PATH;
717 }
718
Kyösti Mälkkibe5317f2019-11-06 12:07:21 +0200719 if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500720 struct elog_event_data_me_extended data = {
721 .current_working_state = hfs.working_state,
722 .operation_state = hfs.operation_state,
723 .operation_mode = hfs.operation_mode,
724 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500725 .progress_code = hfs2.progress_code,
726 .current_pmevent = hfs2.current_pmevent,
727 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500728 };
729 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
730 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
731 &data, sizeof(data));
732 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500733
734 return path;
735}
736
737/* Prepare ME for MEI messages */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100738static int intel_mei_setup(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500739{
740 struct resource *res;
741 struct mei_csr host;
742 u32 reg32;
743
744 /* Find the MMIO base for the ME interface */
745 res = find_resource(dev, PCI_BASE_ADDRESS_0);
746 if (!res || res->base == 0 || res->size == 0) {
747 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
748 return -1;
749 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800750 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500751
752 /* Ensure Memory and Bus Master bits are set */
753 reg32 = pci_read_config32(dev, PCI_COMMAND);
754 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
755 pci_write_config32(dev, PCI_COMMAND, reg32);
756
757 /* Clean up status for next message */
758 read_host_csr(&host);
759 host.interrupt_generate = 1;
760 host.ready = 1;
761 host.reset = 0;
762 write_host_csr(&host);
763
764 return 0;
765}
766
767/* Read the Extend register hash of ME firmware */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100768static int intel_me_extend_valid(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500769{
770 struct me_heres status;
771 u32 extend[8] = {0};
772 int i, count = 0;
773
774 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
775 if (!status.extend_feature_present) {
776 printk(BIOS_ERR, "ME: Extend Feature not present\n");
777 return -1;
778 }
779
780 if (!status.extend_reg_valid) {
781 printk(BIOS_ERR, "ME: Extend Register not valid\n");
782 return -1;
783 }
784
785 switch (status.extend_reg_algorithm) {
786 case PCI_ME_EXT_SHA1:
787 count = 5;
788 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
789 break;
790 case PCI_ME_EXT_SHA256:
791 count = 8;
792 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
793 break;
794 default:
795 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
796 status.extend_reg_algorithm);
797 return -1;
798 }
799
800 for (i = 0; i < count; ++i) {
801 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
802 printk(BIOS_DEBUG, "%08x", extend[i]);
803 }
804 printk(BIOS_DEBUG, "\n");
805
Julius Wernercd49cce2019-03-05 16:53:33 -0800806#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500807 /* Save hash in NVS for the OS to verify */
808 chromeos_set_me_hash(extend, count);
809#endif
810
811 return 0;
812}
813
Aaron Durbin76c37002012-10-30 09:03:43 -0500814/* Check whether ME is present and do basic init */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100815static void intel_me_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500816{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700817 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500818 me_bios_path path = intel_me_path(dev);
819 me_bios_payload mbp_data;
820
821 /* Do initial setup and determine the BIOS path */
822 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
823
Duncan Laurie8056dc62013-07-22 08:47:43 -0700824 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500825 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500826 intel_me_extend_valid(dev);
827 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500828
Aaron Durbinbe985242012-12-12 12:40:33 -0600829 memset(&mbp_data, 0, sizeof(mbp_data));
830
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500831 /*
832 * According to the ME9 BWG, BIOS is required to fetch MBP data in
833 * all boot flows except S3 Resume.
834 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500835
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500836 /* Prepare MEI MMIO interface */
837 if (intel_mei_setup(dev) < 0)
838 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500839
Duncan Laurie144f7b22013-05-01 11:27:58 -0700840 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500841 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500842
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200843 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
844 me_print_fw_version(mbp_data.fw_version_name);
Duncan Laurie144f7b22013-05-01 11:27:58 -0700845
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200846 if (CONFIG(DEBUG_INTEL_ME))
847 me_print_fwcaps(mbp_data.fw_capabilities);
848
849 if (mbp_data.plat_time) {
850 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
851 mbp_data.plat_time->wake_event_mrst_time_ms);
852 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
853 mbp_data.plat_time->mrst_pltrst_time_ms);
854 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
855 mbp_data.plat_time->pltrst_cpurst_time_ms);
856 }
Duncan Laurie144f7b22013-05-01 11:27:58 -0700857 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500858
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700859 /* Set clock enables according to devicetree */
860 if (config && config->icc_clock_disable)
861 me_icc_set_clock_enables(config->icc_clock_disable);
862
Duncan Laurieaf980622013-07-18 23:02:18 -0700863 /*
864 * Leave the ME unlocked. It will be locked via SMI command later.
865 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500866}
867
Aaron Durbin76c37002012-10-30 09:03:43 -0500868static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530869 .set_subsystem = pci_dev_set_subsystem,
Aaron Durbin76c37002012-10-30 09:03:43 -0500870};
871
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100872static void intel_me_enable(struct device *dev)
Duncan Laurie8056dc62013-07-22 08:47:43 -0700873{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700874 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300875 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700876 dev->enabled = 0;
877 pch_disable_devfn(dev);
878 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700879}
880
Aaron Durbin76c37002012-10-30 09:03:43 -0500881static struct device_operations device_ops = {
882 .read_resources = pci_dev_read_resources,
883 .set_resources = pci_dev_set_resources,
884 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700885 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500886 .init = intel_me_init,
Aaron Durbin76c37002012-10-30 09:03:43 -0500887 .ops_pci = &pci_ops,
888};
889
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800890static const unsigned short pci_device_ids[] = {
891 0x8c3a, /* Mobile */
892 0x9c3a, /* Low Power */
893 0
894};
895
Aaron Durbin76c37002012-10-30 09:03:43 -0500896static const struct pci_driver intel_me __pci_driver = {
897 .ops = &device_ops,
898 .vendor = PCI_VENDOR_ID_INTEL,
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800899 .devices= pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500900};
901
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200902#endif /* !__SIMPLE_DEVICE__ */
903
Aaron Durbin76c37002012-10-30 09:03:43 -0500904/******************************************************************************
905 * */
906static u32 me_to_host_words_pending(void)
907{
908 struct mei_csr me;
909 read_me_csr(&me);
910 if (!me.ready)
911 return 0;
912 return (me.buffer_write_ptr - me.buffer_read_ptr) &
913 (me.buffer_depth - 1);
914}
915
916#if 0
917/* This function is not yet being used, keep it in for the future. */
918static u32 host_to_me_words_room(void)
919{
920 struct mei_csr csr;
921
922 read_me_csr(&csr);
923 if (!csr.ready)
924 return 0;
925
926 read_host_csr(&csr);
927 return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) &
928 (csr.buffer_depth - 1);
929}
930#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500931
Aaron Durbinbe985242012-12-12 12:40:33 -0600932struct mbp_payload {
933 mbp_header header;
934 u32 data[0];
935};
936
Aaron Durbin76c37002012-10-30 09:03:43 -0500937/*
938 * mbp seems to be following its own flow, let's retrieve it in a dedicated
939 * function.
940 */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200941static int __unused intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500942{
943 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500944 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500945 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500946 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600947 struct mbp_payload *mbp;
948 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500949
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200950#ifdef __SIMPLE_DEVICE__
951 pci_read_dword_ptr(PCI_BDF(dev), &hfs2, PCI_ME_HFS2);
952#else
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500953 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200954#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500955
956 if (!hfs2.mbp_rdy) {
957 printk(BIOS_ERR, "ME: MBP not ready\n");
958 goto mbp_failure;
959 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500960
961 me2host_pending = me_to_host_words_pending();
962 if (!me2host_pending) {
963 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500964 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500965 }
966
967 /* we know for sure that at least the header is there */
968 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
969
970 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
971 (me2host_pending < mbp_hdr.mbp_size)) {
972 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
973 " buffer contains %d words\n",
974 mbp_hdr.num_entries, mbp_hdr.mbp_size,
975 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500976 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500977 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600978 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
979 if (!mbp)
980 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500981
Aaron Durbinbe985242012-12-12 12:40:33 -0600982 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500983 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500984
Aaron Durbinbe985242012-12-12 12:40:33 -0600985 i = 0;
986 while (i != me2host_pending) {
987 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
988 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500989 }
990
Aaron Durbinbe985242012-12-12 12:40:33 -0600991 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500992 read_host_csr(&host);
993 host.interrupt_generate = 1;
994 write_host_csr(&host);
995
Julius Wernercd49cce2019-03-05 16:53:33 -0800996#if !CONFIG(ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -0600997 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -0700998 intel_me_mbp_clear(dev);
999#endif
Aaron Durbin76c37002012-10-30 09:03:43 -05001000
Aaron Durbinbe985242012-12-12 12:40:33 -06001001 /* Dump out the MBP contents. */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +02001002 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
1003 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
1004 mbp->header.num_entries, mbp->header.mbp_size);
1005 if (CONFIG(DEBUG_INTEL_ME)) {
1006 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
1007 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
1008 }
1009 }
Aaron Durbinbe985242012-12-12 12:40:33 -06001010 }
Aaron Durbinbe985242012-12-12 12:40:33 -06001011
1012 #define ASSIGN_FIELD_PTR(field_,val_) \
1013 { \
1014 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
1015 break; \
1016 }
1017 /* Setup the pointers in the me_bios_payload structure. */
1018 for (i = 0; i < mbp->header.mbp_size - 1;) {
1019 mbp_item_header *item = (void *)&mbp->data[i];
1020
Elyes HAOUASf9de5a42018-05-03 17:21:02 +02001021 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -06001022 case MBP_IDENT(KERNEL, FW_VER):
1023 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
1024
1025 case MBP_IDENT(ICC, PROFILE):
1026 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
1027
1028 case MBP_IDENT(INTEL_AT, STATE):
1029 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
1030
1031 case MBP_IDENT(KERNEL, FW_CAP):
1032 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
1033
1034 case MBP_IDENT(KERNEL, ROM_BIST):
1035 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
1036
1037 case MBP_IDENT(KERNEL, PLAT_KEY):
1038 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
1039
1040 case MBP_IDENT(KERNEL, FW_TYPE):
1041 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
1042
1043 case MBP_IDENT(KERNEL, MFS_FAILURE):
1044 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
1045
Duncan Laurie144f7b22013-05-01 11:27:58 -07001046 case MBP_IDENT(KERNEL, PLAT_TIME):
1047 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
1048
1049 case MBP_IDENT(NFC, SUPPORT_DATA):
1050 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
1051
Aaron Durbinbe985242012-12-12 12:40:33 -06001052 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001053 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
1054 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -06001055 break;
1056 }
1057 i += item->length;
1058 }
1059 #undef ASSIGN_FIELD_PTR
1060
Aaron Durbin76c37002012-10-30 09:03:43 -05001061 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001062
1063mbp_failure:
Kyösti Mälkki21d6a272019-11-05 18:50:38 +02001064#ifdef __SIMPLE_DEVICE__
1065 intel_me_mbp_give_up(PCI_BDF(dev));
1066#else
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001067 intel_me_mbp_give_up(dev);
Kyösti Mälkki21d6a272019-11-05 18:50:38 +02001068#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001069 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001070}