blob: 08085afb581b1076be343ad12b8c727fb24311d5 [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>
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>
Aaron Durbin76c37002012-10-30 09:03:43 -050037
Aaron Durbin76c37002012-10-30 09:03:43 -050038#include "me.h"
39#include "pch.h"
40
Martin Roth7a1a3ad2017-06-24 21:29:38 -060041#if IS_ENABLED(CONFIG_CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -050042#include <vendorcode/google/chromeos/chromeos.h>
43#include <vendorcode/google/chromeos/gnvs.h>
44#endif
45
Duncan Laurieaf980622013-07-18 23:02:18 -070046#ifndef __SMM__
Aaron Durbin76c37002012-10-30 09:03:43 -050047/* Path that the BIOS should take based on ME state */
48static const char *me_bios_path_values[] = {
49 [ME_NORMAL_BIOS_PATH] = "Normal",
50 [ME_S3WAKE_BIOS_PATH] = "S3 Wake",
51 [ME_ERROR_BIOS_PATH] = "Error",
52 [ME_RECOVERY_BIOS_PATH] = "Recovery",
53 [ME_DISABLE_BIOS_PATH] = "Disable",
54 [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update",
55};
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010056static int intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev);
Duncan Laurieaf980622013-07-18 23:02:18 -070057#endif
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
Martin Roth7a1a3ad2017-06-24 21:29:38 -060067#if IS_ENABLED(CONFIG_DEBUG_INTEL_ME)
Aaron Durbin76c37002012-10-30 09:03:43 -050068static void mei_dump(void *ptr, int dword, int offset, const char *type)
69{
70 struct mei_csr *csr;
71
72 printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset);
73
74 switch (offset) {
75 case MEI_H_CSR:
76 case MEI_ME_CSR_HA:
77 csr = ptr;
78 if (!csr) {
79 printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword);
80 break;
81 }
82 printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
83 "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth,
84 csr->buffer_read_ptr, csr->buffer_write_ptr,
85 csr->ready, csr->reset, csr->interrupt_generate,
86 csr->interrupt_status, csr->interrupt_enable);
87 break;
88 case MEI_ME_CB_RW:
89 case MEI_H_CB_WW:
90 printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
91 break;
92 default:
93 printk(BIOS_SPEW, "0x%08x\n", offset);
94 break;
95 }
96}
97#else
98# define mei_dump(ptr,dword,offset,type) do {} while (0)
99#endif
100
101/*
102 * ME/MEI access helpers using memcpy to avoid aliasing.
103 */
104
105static inline void mei_read_dword_ptr(void *ptr, int offset)
106{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800107 u32 dword = read32(mei_base_address + (offset/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500108 memcpy(ptr, &dword, sizeof(dword));
109 mei_dump(ptr, dword, offset, "READ");
110}
111
112static inline void mei_write_dword_ptr(void *ptr, int offset)
113{
114 u32 dword = 0;
115 memcpy(&dword, ptr, sizeof(dword));
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800116 write32(mei_base_address + (offset/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500117 mei_dump(ptr, dword, offset, "WRITE");
118}
119
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100120#ifdef __SIMPLE_DEVICE__
121static inline void pci_read_dword_ptr(pci_devfn_t dev, void *ptr, int offset)
122#else
123static inline void pci_read_dword_ptr(struct device *dev, void *ptr, int offset)
124#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500125{
126 u32 dword = pci_read_config32(dev, offset);
127 memcpy(ptr, &dword, sizeof(dword));
128 mei_dump(ptr, dword, offset, "PCI READ");
129}
Aaron Durbin76c37002012-10-30 09:03:43 -0500130
131static inline void read_host_csr(struct mei_csr *csr)
132{
133 mei_read_dword_ptr(csr, MEI_H_CSR);
134}
135
136static inline void write_host_csr(struct mei_csr *csr)
137{
138 mei_write_dword_ptr(csr, MEI_H_CSR);
139}
140
141static inline void read_me_csr(struct mei_csr *csr)
142{
143 mei_read_dword_ptr(csr, MEI_ME_CSR_HA);
144}
145
146static inline void write_cb(u32 dword)
147{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800148 write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500149 mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE");
150}
151
152static inline u32 read_cb(void)
153{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800154 u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500155 mei_dump(NULL, dword, MEI_ME_CB_RW, "READ");
156 return dword;
157}
158
159/* Wait for ME ready bit to be asserted */
160static int mei_wait_for_me_ready(void)
161{
162 struct mei_csr me;
163 unsigned try = ME_RETRY;
164
165 while (try--) {
166 read_me_csr(&me);
167 if (me.ready)
168 return 0;
169 udelay(ME_DELAY);
170 }
171
172 printk(BIOS_ERR, "ME: failed to become ready\n");
173 return -1;
174}
175
176static void mei_reset(void)
177{
178 struct mei_csr host;
179
180 if (mei_wait_for_me_ready() < 0)
181 return;
182
183 /* Reset host and ME circular buffers for next message */
184 read_host_csr(&host);
185 host.reset = 1;
186 host.interrupt_generate = 1;
187 write_host_csr(&host);
188
189 if (mei_wait_for_me_ready() < 0)
190 return;
191
192 /* Re-init and indicate host is ready */
193 read_host_csr(&host);
194 host.interrupt_generate = 1;
195 host.ready = 1;
196 host.reset = 0;
197 write_host_csr(&host);
198}
199
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700200static int mei_send_packet(struct mei_header *mei, void *req_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500201{
202 struct mei_csr host;
203 unsigned ndata, n;
204 u32 *data;
205
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700206 /* Number of dwords to write */
Aaron Durbin76c37002012-10-30 09:03:43 -0500207 ndata = mei->length >> 2;
208
209 /* Pad non-dword aligned request message length */
210 if (mei->length & 3)
211 ndata++;
212 if (!ndata) {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700213 printk(BIOS_DEBUG, "ME: request has no data\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500214 return -1;
215 }
216 ndata++; /* Add MEI header */
217
218 /*
219 * Make sure there is still room left in the circular buffer.
220 * Reset the buffer pointers if the requested message will not fit.
221 */
222 read_host_csr(&host);
223 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
224 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
225 mei_reset();
226 read_host_csr(&host);
227 }
228
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700229 /* Ensure the requested length will fit in the circular buffer. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500230 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
231 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
232 ndata + 2, host.buffer_depth);
233 return -1;
234 }
235
236 /* Write MEI header */
237 mei_write_dword_ptr(mei, MEI_H_CB_WW);
238 ndata--;
239
Aaron Durbin76c37002012-10-30 09:03:43 -0500240 /* Write message data */
241 data = req_data;
242 for (n = 0; n < ndata; ++n)
243 write_cb(*data++);
244
245 /* Generate interrupt to the ME */
246 read_host_csr(&host);
247 host.interrupt_generate = 1;
248 write_host_csr(&host);
249
250 /* Make sure ME is ready after sending request data */
251 return mei_wait_for_me_ready();
252}
253
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700254static int mei_send_data(u8 me_address, u8 host_address,
255 void *req_data, int req_bytes)
256{
257 struct mei_header header = {
258 .client_address = me_address,
259 .host_address = host_address,
260 };
261 struct mei_csr host;
262 int current = 0;
263 u8 *req_ptr = req_data;
264
265 while (!header.is_complete) {
266 int remain = req_bytes - current;
267 int buf_len;
268
269 read_host_csr(&host);
270 buf_len = host.buffer_depth - host.buffer_write_ptr;
271
272 if (buf_len > remain) {
273 /* Send all remaining data as final message */
274 header.length = req_bytes - current;
275 header.is_complete = 1;
276 } else {
277 /* Send as much data as the buffer can hold */
278 header.length = buf_len;
279 }
280
281 mei_send_packet(&header, req_ptr);
282
283 req_ptr += header.length;
284 current += header.length;
285 }
286
287 return 0;
288}
289
290static int mei_send_header(u8 me_address, u8 host_address,
291 void *header, int header_len, int complete)
292{
293 struct mei_header mei = {
294 .client_address = me_address,
295 .host_address = host_address,
296 .length = header_len,
297 .is_complete = complete,
298 };
299 return mei_send_packet(&mei, header);
300}
301
302static int mei_recv_msg(void *header, int header_bytes,
Aaron Durbin76c37002012-10-30 09:03:43 -0500303 void *rsp_data, int rsp_bytes)
304{
305 struct mei_header mei_rsp;
Aaron Durbin76c37002012-10-30 09:03:43 -0500306 struct mei_csr me, host;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700307 unsigned ndata, n;
Aaron Durbin76c37002012-10-30 09:03:43 -0500308 unsigned expected;
309 u32 *data;
310
311 /* Total number of dwords to read from circular buffer */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700312 expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500313 if (rsp_bytes & 3)
314 expected++;
315
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700316 if (mei_wait_for_me_ready() < 0)
317 return -1;
318
Aaron Durbin76c37002012-10-30 09:03:43 -0500319 /*
320 * The interrupt status bit does not appear to indicate that the
321 * message has actually been received. Instead we wait until the
322 * expected number of dwords are present in the circular buffer.
323 */
324 for (n = ME_RETRY; n; --n) {
325 read_me_csr(&me);
326 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
327 break;
328 udelay(ME_DELAY);
329 }
330 if (!n) {
331 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
332 "%u, available %u\n", expected,
333 me.buffer_write_ptr - me.buffer_read_ptr);
334 return -1;
335 }
336
337 /* Read and verify MEI response header from the ME */
338 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
339 if (!mei_rsp.is_complete) {
340 printk(BIOS_ERR, "ME: response is not complete\n");
341 return -1;
342 }
343
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700344 /* Handle non-dword responses and expect at least the header */
Aaron Durbin76c37002012-10-30 09:03:43 -0500345 ndata = mei_rsp.length >> 2;
346 if (mei_rsp.length & 3)
347 ndata++;
348 if (ndata != (expected - 1)) {
349 printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
350 ndata, (expected - 1));
351 return -1;
352 }
353
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700354 /* Read response header from the ME */
355 data = header;
356 for (n = 0; n < (header_bytes >> 2); ++n)
357 *data++ = read_cb();
358 ndata -= header_bytes >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500359
360 /* Make sure caller passed a buffer with enough space */
361 if (ndata != (rsp_bytes >> 2)) {
362 printk(BIOS_ERR, "ME: not enough room in response buffer: "
363 "%u != %u\n", ndata, rsp_bytes >> 2);
364 return -1;
365 }
366
367 /* Read response data from the circular buffer */
368 data = rsp_data;
369 for (n = 0; n < ndata; ++n)
370 *data++ = read_cb();
371
372 /* Tell the ME that we have consumed the response */
373 read_host_csr(&host);
374 host.interrupt_status = 1;
375 host.interrupt_generate = 1;
376 write_host_csr(&host);
377
378 return mei_wait_for_me_ready();
379}
380
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100381#if IS_ENABLED (CONFIG_DEBUG_INTEL_ME) || defined(__SMM__)
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700382static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
383 void *req_data, int req_bytes,
384 void *rsp_data, int rsp_bytes)
Aaron Durbin76c37002012-10-30 09:03:43 -0500385{
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700386 struct mkhi_header mkhi_rsp;
387
388 /* Send header */
389 if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
390 mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500391 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700392
393 /* Send data if available */
394 if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
395 req_data, req_bytes) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500396 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700397
398 /* Return now if no response expected */
399 if (!rsp_bytes)
400 return 0;
401
402 /* Read header and data */
403 if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
404 rsp_data, rsp_bytes) < 0)
405 return -1;
406
407 if (!mkhi_rsp.is_response ||
408 mkhi->group_id != mkhi_rsp.group_id ||
409 mkhi->command != mkhi_rsp.command) {
410 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
411 "command %u ?= %u, is_response %u\n", mkhi->group_id,
412 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
413 mkhi_rsp.is_response);
414 return -1;
415 }
416
Aaron Durbin76c37002012-10-30 09:03:43 -0500417 return 0;
418}
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100419#endif /* CONFIG_DEBUG_INTEL_ME || __SMM__ */
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700420
Duncan Laurie3d299c42013-07-19 08:48:05 -0700421/*
422 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
423 * state machine on the BIOS end doesn't match the ME's state machine.
424 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100425#ifdef __SIMPLE_DEVICE__
426static void intel_me_mbp_give_up(pci_devfn_t dev)
427#else
428static void intel_me_mbp_give_up(struct device *dev)
429#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700430{
431 struct mei_csr csr;
432
433 pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP);
434
435 read_host_csr(&csr);
436 csr.reset = 1;
437 csr.interrupt_generate = 1;
438 write_host_csr(&csr);
439}
440
441/*
442 * mbp clear routine. This will wait for the ME to indicate that
443 * the MBP has been read and cleared.
444 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100445#ifdef __SIMPLE_DEVICE__
446void intel_me_mbp_clear(pci_devfn_t dev)
447#else
448void intel_me_mbp_clear(struct device *dev)
449#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700450{
451 int count;
452 struct me_hfs2 hfs2;
453
454 /* Wait for the mbp_cleared indicator */
455 for (count = ME_RETRY; count > 0; --count) {
456 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
457 if (hfs2.mbp_cleared)
458 break;
459 udelay(ME_DELAY);
460 }
461
462 if (count == 0) {
463 printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n");
464 intel_me_mbp_give_up(dev);
465 } else {
466 printk(BIOS_INFO, "ME: MBP cleared\n");
467 }
468}
469
Duncan Laurieaf980622013-07-18 23:02:18 -0700470#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) && !defined(__SMM__)
Aaron Durbin76c37002012-10-30 09:03:43 -0500471static void me_print_fw_version(mbp_fw_version_name *vers_name)
472{
Aaron Durbinbe985242012-12-12 12:40:33 -0600473 if (!vers_name) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500474 printk(BIOS_ERR, "ME: mbp missing version report\n");
475 return;
476 }
477
478 printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
479 vers_name->major_version, vers_name->minor_version,
480 vers_name->hotfix_version, vers_name->build_version);
481}
482
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000483#if IS_ENABLED (CONFIG_DEBUG_INTEL_ME)
484static inline void print_cap(const char *name, int state)
485{
486 printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
487 name, state ? " en" : "dis");
488}
489
Aaron Durbin76c37002012-10-30 09:03:43 -0500490/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600491static int mkhi_get_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500492{
493 u32 rule_id = 0;
494 struct me_fwcaps cap_msg;
495 struct mkhi_header mkhi = {
496 .group_id = MKHI_GROUP_ID_FWCAPS,
497 .command = MKHI_FWCAPS_GET_RULE,
498 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500499
500 /* Send request and wait for response */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700501 if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
502 &cap_msg, sizeof(cap_msg)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500503 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
504 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200505 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500506 *cap = cap_msg.caps_sku;
507 return 0;
508}
509
510/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600511static void me_print_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500512{
Aaron Durbinbe985242012-12-12 12:40:33 -0600513 mbp_mefwcaps local_caps;
514 if (!cap) {
515 cap = &local_caps;
Aaron Durbin76c37002012-10-30 09:03:43 -0500516 printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
517 if (mkhi_get_fwcaps(cap))
518 return;
519 }
520
521 print_cap("Full Network manageability", cap->full_net);
522 print_cap("Regular Network manageability", cap->std_net);
523 print_cap("Manageability", cap->manageability);
Aaron Durbin76c37002012-10-30 09:03:43 -0500524 print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
525 print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
526 print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
527 print_cap("ICC Over Clocking", cap->icc_over_clocking);
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000528 print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
Aaron Durbin76c37002012-10-30 09:03:43 -0500529 print_cap("IPV6", cap->ipv6);
530 print_cap("KVM Remote Control (KVM)", cap->kvm);
531 print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
532 print_cap("Virtual LAN (VLAN)", cap->vlan);
533 print_cap("TLS", cap->tls);
534 print_cap("Wireless LAN (WLAN)", cap->wlan);
535}
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000536#endif /* CONFIG_DEBUG_INTEL_ME */
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700537#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500538
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600539#if IS_ENABLED(CONFIG_CHROMEOS) && 0 /* DISABLED */
Aaron Durbin76c37002012-10-30 09:03:43 -0500540/* Tell ME to issue a global reset */
541static int mkhi_global_reset(void)
542{
543 struct me_global_reset reset = {
544 .request_origin = GLOBAL_RESET_BIOS_POST,
545 .reset_type = CBM_RR_GLOBAL_RESET,
546 };
547 struct mkhi_header mkhi = {
548 .group_id = MKHI_GROUP_ID_CBM,
549 .command = MKHI_GLOBAL_RESET,
550 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500551
552 /* Send request and wait for response */
553 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700554 if (mei_sendrecv_mkhi(&mkhi, &reset, sizeof(reset), NULL, 0) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500555 /* No response means reset will happen shortly... */
Patrick Georgi546953c2014-11-29 10:38:17 +0100556 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500557 }
558
559 /* If the ME responded it rejected the reset request */
560 printk(BIOS_ERR, "ME: Global Reset failed\n");
561 return -1;
562}
563#endif
564
Duncan Laurieaf980622013-07-18 23:02:18 -0700565#ifdef __SMM__
566
Aaron Durbin76c37002012-10-30 09:03:43 -0500567/* Send END OF POST message to the ME */
568static int mkhi_end_of_post(void)
569{
570 struct mkhi_header mkhi = {
571 .group_id = MKHI_GROUP_ID_GEN,
572 .command = MKHI_END_OF_POST,
573 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500574 u32 eop_ack;
575
576 /* Send request and wait for response */
577 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700578 if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500579 printk(BIOS_ERR, "ME: END OF POST message failed\n");
580 return -1;
581 }
582
583 printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
584 return 0;
585}
586
Duncan Laurieaf980622013-07-18 23:02:18 -0700587void intel_me_finalize_smm(void)
588{
589 struct me_hfs hfs;
590 u32 reg32;
591
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800592 mei_base_address = (u32 *)
593 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Duncan Laurieaf980622013-07-18 23:02:18 -0700594
595 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800596 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700597 return;
598
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600599#if IS_ENABLED(CONFIG_ME_MBP_CLEAR_LATE)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700600 /* Wait for ME MBP Cleared indicator */
601 intel_me_mbp_clear(PCH_ME_DEV);
602#endif
603
Duncan Laurieaf980622013-07-18 23:02:18 -0700604 /* Make sure ME is in a mode that expects EOP */
605 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
606 memcpy(&hfs, &reg32, sizeof(u32));
607
608 /* Abort and leave device alone if not normal mode */
609 if (hfs.fpt_bad ||
610 hfs.working_state != ME_HFS_CWS_NORMAL ||
611 hfs.operation_mode != ME_HFS_MODE_NORMAL)
612 return;
613
614 /* Try to send EOP command so ME stops accepting other commands */
615 mkhi_end_of_post();
616
617 /* Make sure IO is disabled */
618 reg32 = pci_read_config32(PCH_ME_DEV, PCI_COMMAND);
619 reg32 &= ~(PCI_COMMAND_MASTER |
620 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
621 pci_write_config32(PCH_ME_DEV, PCI_COMMAND, reg32);
622
623 /* Hide the PCI device */
624 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
625}
626
627#else /* !__SMM__ */
628
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100629static inline int mei_sendrecv_icc(struct icc_header *icc,
630 void *req_data, int req_bytes,
631 void *rsp_data, int rsp_bytes)
632{
633 struct icc_header icc_rsp;
634
635 /* Send header */
636 if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
637 icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
638 return -1;
639
640 /* Send data if available */
641 if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
642 req_data, req_bytes) < 0)
643 return -1;
644
645 /* Read header and data, if needed */
646 if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
647 rsp_data, rsp_bytes) < 0)
648 return -1;
649
650 return 0;
651}
652
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700653static int me_icc_set_clock_enables(u32 mask)
654{
655 struct icc_clock_enables_msg clk = {
656 .clock_enables = 0, /* Turn off specified clocks */
657 .clock_mask = mask,
658 .no_response = 1, /* Do not expect response */
659 };
660 struct icc_header icc = {
661 .api_version = ICC_API_VERSION_LYNXPOINT,
662 .icc_command = ICC_SET_CLOCK_ENABLES,
663 .length = sizeof(clk),
664 };
665
666 /* Send request and wait for response */
667 if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
668 printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
669 return -1;
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700670 }
671
Elyes HAOUAS54f94242018-10-25 10:57:39 +0200672 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700673 return 0;
674}
675
Aaron Durbin76c37002012-10-30 09:03:43 -0500676/* Determine the path that we should take based on ME status */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100677static me_bios_path intel_me_path(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500678{
679 me_bios_path path = ME_DISABLE_BIOS_PATH;
680 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500681 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500682
Aaron Durbin76c37002012-10-30 09:03:43 -0500683 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500684 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500685
686 /* Check and dump status */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500687 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500688
689 /* Check Current Working State */
690 switch (hfs.working_state) {
691 case ME_HFS_CWS_NORMAL:
692 path = ME_NORMAL_BIOS_PATH;
693 break;
694 case ME_HFS_CWS_REC:
695 path = ME_RECOVERY_BIOS_PATH;
696 break;
697 default:
698 path = ME_DISABLE_BIOS_PATH;
699 break;
700 }
701
702 /* Check Current Operation Mode */
703 switch (hfs.operation_mode) {
704 case ME_HFS_MODE_NORMAL:
705 break;
706 case ME_HFS_MODE_DEBUG:
707 case ME_HFS_MODE_DIS:
708 case ME_HFS_MODE_OVER_JMPR:
709 case ME_HFS_MODE_OVER_MEI:
710 default:
711 path = ME_DISABLE_BIOS_PATH;
712 break;
713 }
714
715 /* Check for any error code and valid firmware and MBP */
716 if (hfs.error_code || hfs.fpt_bad)
717 path = ME_ERROR_BIOS_PATH;
718
719 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500720 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500721 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
722 __FUNCTION__);
723 path = ME_ERROR_BIOS_PATH;
724 }
725
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600726#if IS_ENABLED(CONFIG_ELOG)
Aaron Durbin76c37002012-10-30 09:03:43 -0500727 if (path != ME_NORMAL_BIOS_PATH) {
728 struct elog_event_data_me_extended data = {
729 .current_working_state = hfs.working_state,
730 .operation_state = hfs.operation_state,
731 .operation_mode = hfs.operation_mode,
732 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500733 .progress_code = hfs2.progress_code,
734 .current_pmevent = hfs2.current_pmevent,
735 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500736 };
737 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
738 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
739 &data, sizeof(data));
740 }
741#endif
742
743 return path;
744}
745
746/* Prepare ME for MEI messages */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100747static int intel_mei_setup(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500748{
749 struct resource *res;
750 struct mei_csr host;
751 u32 reg32;
752
753 /* Find the MMIO base for the ME interface */
754 res = find_resource(dev, PCI_BASE_ADDRESS_0);
755 if (!res || res->base == 0 || res->size == 0) {
756 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
757 return -1;
758 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800759 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500760
761 /* Ensure Memory and Bus Master bits are set */
762 reg32 = pci_read_config32(dev, PCI_COMMAND);
763 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
764 pci_write_config32(dev, PCI_COMMAND, reg32);
765
766 /* Clean up status for next message */
767 read_host_csr(&host);
768 host.interrupt_generate = 1;
769 host.ready = 1;
770 host.reset = 0;
771 write_host_csr(&host);
772
773 return 0;
774}
775
776/* Read the Extend register hash of ME firmware */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100777static int intel_me_extend_valid(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500778{
779 struct me_heres status;
780 u32 extend[8] = {0};
781 int i, count = 0;
782
783 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
784 if (!status.extend_feature_present) {
785 printk(BIOS_ERR, "ME: Extend Feature not present\n");
786 return -1;
787 }
788
789 if (!status.extend_reg_valid) {
790 printk(BIOS_ERR, "ME: Extend Register not valid\n");
791 return -1;
792 }
793
794 switch (status.extend_reg_algorithm) {
795 case PCI_ME_EXT_SHA1:
796 count = 5;
797 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
798 break;
799 case PCI_ME_EXT_SHA256:
800 count = 8;
801 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
802 break;
803 default:
804 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
805 status.extend_reg_algorithm);
806 return -1;
807 }
808
809 for (i = 0; i < count; ++i) {
810 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
811 printk(BIOS_DEBUG, "%08x", extend[i]);
812 }
813 printk(BIOS_DEBUG, "\n");
814
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600815#if IS_ENABLED(CONFIG_CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500816 /* Save hash in NVS for the OS to verify */
817 chromeos_set_me_hash(extend, count);
818#endif
819
820 return 0;
821}
822
Aaron Durbin76c37002012-10-30 09:03:43 -0500823/* Check whether ME is present and do basic init */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100824static void intel_me_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500825{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700826 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500827 me_bios_path path = intel_me_path(dev);
828 me_bios_payload mbp_data;
829
830 /* Do initial setup and determine the BIOS path */
831 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
832
Duncan Laurie8056dc62013-07-22 08:47:43 -0700833 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500834 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500835 intel_me_extend_valid(dev);
836 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500837
Aaron Durbinbe985242012-12-12 12:40:33 -0600838 memset(&mbp_data, 0, sizeof(mbp_data));
839
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500840 /*
841 * According to the ME9 BWG, BIOS is required to fetch MBP data in
842 * all boot flows except S3 Resume.
843 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500844
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500845 /* Prepare MEI MMIO interface */
846 if (intel_mei_setup(dev) < 0)
847 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500848
Duncan Laurie144f7b22013-05-01 11:27:58 -0700849 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500850 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500851
852#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG)
Aaron Durbinbe985242012-12-12 12:40:33 -0600853 me_print_fw_version(mbp_data.fw_version_name);
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600854#if IS_ENABLED(CONFIG_DEBUG_INTEL_ME)
Aaron Durbinbe985242012-12-12 12:40:33 -0600855 me_print_fwcaps(mbp_data.fw_capabilities);
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700856#endif
Duncan Laurie144f7b22013-05-01 11:27:58 -0700857
858 if (mbp_data.plat_time) {
859 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
860 mbp_data.plat_time->wake_event_mrst_time_ms);
861 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
862 mbp_data.plat_time->mrst_pltrst_time_ms);
863 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
864 mbp_data.plat_time->pltrst_cpurst_time_ms);
865 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500866#endif
867
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700868 /* Set clock enables according to devicetree */
869 if (config && config->icc_clock_disable)
870 me_icc_set_clock_enables(config->icc_clock_disable);
871
Duncan Laurieaf980622013-07-18 23:02:18 -0700872 /*
873 * Leave the ME unlocked. It will be locked via SMI command later.
874 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500875}
876
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100877static void set_subsystem(struct device *dev, unsigned int vendor,
878 unsigned int device)
Aaron Durbin76c37002012-10-30 09:03:43 -0500879{
880 if (!vendor || !device) {
881 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
882 pci_read_config32(dev, PCI_VENDOR_ID));
883 } else {
884 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
885 ((device & 0xffff) << 16) | (vendor & 0xffff));
886 }
887}
888
889static struct pci_operations pci_ops = {
890 .set_subsystem = set_subsystem,
891};
892
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100893static void intel_me_enable(struct device *dev)
Duncan Laurie8056dc62013-07-22 08:47:43 -0700894{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700895 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300896 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700897 dev->enabled = 0;
898 pch_disable_devfn(dev);
899 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700900}
901
Aaron Durbin76c37002012-10-30 09:03:43 -0500902static struct device_operations device_ops = {
903 .read_resources = pci_dev_read_resources,
904 .set_resources = pci_dev_set_resources,
905 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700906 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500907 .init = intel_me_init,
Aaron Durbin76c37002012-10-30 09:03:43 -0500908 .ops_pci = &pci_ops,
909};
910
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800911static const unsigned short pci_device_ids[] = {
912 0x8c3a, /* Mobile */
913 0x9c3a, /* Low Power */
914 0
915};
916
Aaron Durbin76c37002012-10-30 09:03:43 -0500917static const struct pci_driver intel_me __pci_driver = {
918 .ops = &device_ops,
919 .vendor = PCI_VENDOR_ID_INTEL,
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800920 .devices= pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500921};
922
923/******************************************************************************
924 * */
925static u32 me_to_host_words_pending(void)
926{
927 struct mei_csr me;
928 read_me_csr(&me);
929 if (!me.ready)
930 return 0;
931 return (me.buffer_write_ptr - me.buffer_read_ptr) &
932 (me.buffer_depth - 1);
933}
934
935#if 0
936/* This function is not yet being used, keep it in for the future. */
937static u32 host_to_me_words_room(void)
938{
939 struct mei_csr csr;
940
941 read_me_csr(&csr);
942 if (!csr.ready)
943 return 0;
944
945 read_host_csr(&csr);
946 return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) &
947 (csr.buffer_depth - 1);
948}
949#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500950
Aaron Durbinbe985242012-12-12 12:40:33 -0600951struct mbp_payload {
952 mbp_header header;
953 u32 data[0];
954};
955
Aaron Durbin76c37002012-10-30 09:03:43 -0500956/*
957 * mbp seems to be following its own flow, let's retrieve it in a dedicated
958 * function.
959 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100960static int intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500961{
962 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500963 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500964 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500965 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600966 struct mbp_payload *mbp;
967 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500968
969 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
970
971 if (!hfs2.mbp_rdy) {
972 printk(BIOS_ERR, "ME: MBP not ready\n");
973 goto mbp_failure;
974 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500975
976 me2host_pending = me_to_host_words_pending();
977 if (!me2host_pending) {
978 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500979 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500980 }
981
982 /* we know for sure that at least the header is there */
983 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
984
985 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
986 (me2host_pending < mbp_hdr.mbp_size)) {
987 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
988 " buffer contains %d words\n",
989 mbp_hdr.num_entries, mbp_hdr.mbp_size,
990 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500991 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500992 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600993 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
994 if (!mbp)
995 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500996
Aaron Durbinbe985242012-12-12 12:40:33 -0600997 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500998 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500999
Aaron Durbinbe985242012-12-12 12:40:33 -06001000 i = 0;
1001 while (i != me2host_pending) {
1002 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
1003 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -05001004 }
1005
Aaron Durbinbe985242012-12-12 12:40:33 -06001006 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -05001007 read_host_csr(&host);
1008 host.interrupt_generate = 1;
1009 write_host_csr(&host);
1010
Martin Roth7a1a3ad2017-06-24 21:29:38 -06001011#if !IS_ENABLED(CONFIG_ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -06001012 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -07001013 intel_me_mbp_clear(dev);
1014#endif
Aaron Durbin76c37002012-10-30 09:03:43 -05001015
Aaron Durbinbe985242012-12-12 12:40:33 -06001016 /* Dump out the MBP contents. */
1017#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG)
1018 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
1019 mbp->header.num_entries, mbp->header.mbp_size);
Martin Roth7a1a3ad2017-06-24 21:29:38 -06001020#if IS_ENABLED(CONFIG_DEBUG_INTEL_ME)
Aaron Durbinbe985242012-12-12 12:40:33 -06001021 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
1022 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
1023 }
1024#endif
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001025#endif
Aaron Durbinbe985242012-12-12 12:40:33 -06001026
1027 #define ASSIGN_FIELD_PTR(field_,val_) \
1028 { \
1029 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
1030 break; \
1031 }
1032 /* Setup the pointers in the me_bios_payload structure. */
1033 for (i = 0; i < mbp->header.mbp_size - 1;) {
1034 mbp_item_header *item = (void *)&mbp->data[i];
1035
Elyes HAOUASf9de5a42018-05-03 17:21:02 +02001036 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -06001037 case MBP_IDENT(KERNEL, FW_VER):
1038 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
1039
1040 case MBP_IDENT(ICC, PROFILE):
1041 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
1042
1043 case MBP_IDENT(INTEL_AT, STATE):
1044 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
1045
1046 case MBP_IDENT(KERNEL, FW_CAP):
1047 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
1048
1049 case MBP_IDENT(KERNEL, ROM_BIST):
1050 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
1051
1052 case MBP_IDENT(KERNEL, PLAT_KEY):
1053 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
1054
1055 case MBP_IDENT(KERNEL, FW_TYPE):
1056 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
1057
1058 case MBP_IDENT(KERNEL, MFS_FAILURE):
1059 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
1060
Duncan Laurie144f7b22013-05-01 11:27:58 -07001061 case MBP_IDENT(KERNEL, PLAT_TIME):
1062 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
1063
1064 case MBP_IDENT(NFC, SUPPORT_DATA):
1065 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
1066
Aaron Durbinbe985242012-12-12 12:40:33 -06001067 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001068 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
1069 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -06001070 break;
1071 }
1072 i += item->length;
1073 }
1074 #undef ASSIGN_FIELD_PTR
1075
Aaron Durbin76c37002012-10-30 09:03:43 -05001076 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001077
1078mbp_failure:
1079 intel_me_mbp_give_up(dev);
1080 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001081}
Duncan Laurieaf980622013-07-18 23:02:18 -07001082
1083#endif /* !__SMM__ */