blob: 59a86665479fad42b7bccba624e6820ff9f0d9e7 [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
Duncan Laurieaf980622013-07-18 23:02:18 -070048#ifndef __SMM__
Aaron Durbin76c37002012-10-30 09:03:43 -050049/* Path that the BIOS should take based on ME state */
50static const char *me_bios_path_values[] = {
51 [ME_NORMAL_BIOS_PATH] = "Normal",
52 [ME_S3WAKE_BIOS_PATH] = "S3 Wake",
53 [ME_ERROR_BIOS_PATH] = "Error",
54 [ME_RECOVERY_BIOS_PATH] = "Recovery",
55 [ME_DISABLE_BIOS_PATH] = "Disable",
56 [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update",
57};
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010058static int intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev);
Duncan Laurieaf980622013-07-18 23:02:18 -070059#endif
Aaron Durbin76c37002012-10-30 09:03:43 -050060
61/* MMIO base address for MEI interface */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080062static u32 *mei_base_address;
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010063#ifdef __SIMPLE_DEVICE__
64void intel_me_mbp_clear(pci_devfn_t dev);
65#else
66void intel_me_mbp_clear(struct device *dev);
67#endif
Aaron Durbin76c37002012-10-30 09:03:43 -050068
Julius Wernercd49cce2019-03-05 16:53:33 -080069#if CONFIG(DEBUG_INTEL_ME)
Aaron Durbin76c37002012-10-30 09:03:43 -050070static void mei_dump(void *ptr, int dword, int offset, const char *type)
71{
72 struct mei_csr *csr;
73
74 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}
99#else
100# define mei_dump(ptr,dword,offset,type) do {} while (0)
101#endif
102
103/*
104 * ME/MEI access helpers using memcpy to avoid aliasing.
105 */
106
107static inline void mei_read_dword_ptr(void *ptr, int offset)
108{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800109 u32 dword = read32(mei_base_address + (offset/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500110 memcpy(ptr, &dword, sizeof(dword));
111 mei_dump(ptr, dword, offset, "READ");
112}
113
114static inline void mei_write_dword_ptr(void *ptr, int offset)
115{
116 u32 dword = 0;
117 memcpy(&dword, ptr, sizeof(dword));
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800118 write32(mei_base_address + (offset/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500119 mei_dump(ptr, dword, offset, "WRITE");
120}
121
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100122#ifdef __SIMPLE_DEVICE__
123static inline void pci_read_dword_ptr(pci_devfn_t dev, void *ptr, int offset)
124#else
125static inline void pci_read_dword_ptr(struct device *dev, void *ptr, int offset)
126#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500127{
128 u32 dword = pci_read_config32(dev, offset);
129 memcpy(ptr, &dword, sizeof(dword));
130 mei_dump(ptr, dword, offset, "PCI READ");
131}
Aaron Durbin76c37002012-10-30 09:03:43 -0500132
133static inline void read_host_csr(struct mei_csr *csr)
134{
135 mei_read_dword_ptr(csr, MEI_H_CSR);
136}
137
138static inline void write_host_csr(struct mei_csr *csr)
139{
140 mei_write_dword_ptr(csr, MEI_H_CSR);
141}
142
143static inline void read_me_csr(struct mei_csr *csr)
144{
145 mei_read_dword_ptr(csr, MEI_ME_CSR_HA);
146}
147
148static inline void write_cb(u32 dword)
149{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800150 write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500151 mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE");
152}
153
154static inline u32 read_cb(void)
155{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800156 u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500157 mei_dump(NULL, dword, MEI_ME_CB_RW, "READ");
158 return dword;
159}
160
161/* Wait for ME ready bit to be asserted */
162static int mei_wait_for_me_ready(void)
163{
164 struct mei_csr me;
Martin Rothff744bf2019-10-23 21:46:03 -0600165 unsigned int try = ME_RETRY;
Aaron Durbin76c37002012-10-30 09:03:43 -0500166
167 while (try--) {
168 read_me_csr(&me);
169 if (me.ready)
170 return 0;
171 udelay(ME_DELAY);
172 }
173
174 printk(BIOS_ERR, "ME: failed to become ready\n");
175 return -1;
176}
177
178static void mei_reset(void)
179{
180 struct mei_csr host;
181
182 if (mei_wait_for_me_ready() < 0)
183 return;
184
185 /* Reset host and ME circular buffers for next message */
186 read_host_csr(&host);
187 host.reset = 1;
188 host.interrupt_generate = 1;
189 write_host_csr(&host);
190
191 if (mei_wait_for_me_ready() < 0)
192 return;
193
194 /* Re-init and indicate host is ready */
195 read_host_csr(&host);
196 host.interrupt_generate = 1;
197 host.ready = 1;
198 host.reset = 0;
199 write_host_csr(&host);
200}
201
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700202static int mei_send_packet(struct mei_header *mei, void *req_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500203{
204 struct mei_csr host;
Martin Rothff744bf2019-10-23 21:46:03 -0600205 unsigned int ndata, n;
Aaron Durbin76c37002012-10-30 09:03:43 -0500206 u32 *data;
207
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700208 /* Number of dwords to write */
Aaron Durbin76c37002012-10-30 09:03:43 -0500209 ndata = mei->length >> 2;
210
211 /* Pad non-dword aligned request message length */
212 if (mei->length & 3)
213 ndata++;
214 if (!ndata) {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700215 printk(BIOS_DEBUG, "ME: request has no data\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500216 return -1;
217 }
218 ndata++; /* Add MEI header */
219
220 /*
221 * Make sure there is still room left in the circular buffer.
222 * Reset the buffer pointers if the requested message will not fit.
223 */
224 read_host_csr(&host);
225 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
226 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
227 mei_reset();
228 read_host_csr(&host);
229 }
230
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700231 /* Ensure the requested length will fit in the circular buffer. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500232 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
233 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
234 ndata + 2, host.buffer_depth);
235 return -1;
236 }
237
238 /* Write MEI header */
239 mei_write_dword_ptr(mei, MEI_H_CB_WW);
240 ndata--;
241
Aaron Durbin76c37002012-10-30 09:03:43 -0500242 /* Write message data */
243 data = req_data;
244 for (n = 0; n < ndata; ++n)
245 write_cb(*data++);
246
247 /* Generate interrupt to the ME */
248 read_host_csr(&host);
249 host.interrupt_generate = 1;
250 write_host_csr(&host);
251
252 /* Make sure ME is ready after sending request data */
253 return mei_wait_for_me_ready();
254}
255
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700256static int mei_send_data(u8 me_address, u8 host_address,
257 void *req_data, int req_bytes)
258{
259 struct mei_header header = {
260 .client_address = me_address,
261 .host_address = host_address,
262 };
263 struct mei_csr host;
264 int current = 0;
265 u8 *req_ptr = req_data;
266
267 while (!header.is_complete) {
268 int remain = req_bytes - current;
269 int buf_len;
270
271 read_host_csr(&host);
272 buf_len = host.buffer_depth - host.buffer_write_ptr;
273
274 if (buf_len > remain) {
275 /* Send all remaining data as final message */
276 header.length = req_bytes - current;
277 header.is_complete = 1;
278 } else {
279 /* Send as much data as the buffer can hold */
280 header.length = buf_len;
281 }
282
283 mei_send_packet(&header, req_ptr);
284
285 req_ptr += header.length;
286 current += header.length;
287 }
288
289 return 0;
290}
291
292static int mei_send_header(u8 me_address, u8 host_address,
293 void *header, int header_len, int complete)
294{
295 struct mei_header mei = {
296 .client_address = me_address,
297 .host_address = host_address,
298 .length = header_len,
299 .is_complete = complete,
300 };
301 return mei_send_packet(&mei, header);
302}
303
304static int mei_recv_msg(void *header, int header_bytes,
Aaron Durbin76c37002012-10-30 09:03:43 -0500305 void *rsp_data, int rsp_bytes)
306{
307 struct mei_header mei_rsp;
Aaron Durbin76c37002012-10-30 09:03:43 -0500308 struct mei_csr me, host;
Martin Rothff744bf2019-10-23 21:46:03 -0600309 unsigned int ndata, n;
310 unsigned int expected;
Aaron Durbin76c37002012-10-30 09:03:43 -0500311 u32 *data;
312
313 /* Total number of dwords to read from circular buffer */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700314 expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500315 if (rsp_bytes & 3)
316 expected++;
317
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700318 if (mei_wait_for_me_ready() < 0)
319 return -1;
320
Aaron Durbin76c37002012-10-30 09:03:43 -0500321 /*
322 * The interrupt status bit does not appear to indicate that the
323 * message has actually been received. Instead we wait until the
324 * expected number of dwords are present in the circular buffer.
325 */
326 for (n = ME_RETRY; n; --n) {
327 read_me_csr(&me);
328 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
329 break;
330 udelay(ME_DELAY);
331 }
332 if (!n) {
333 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
334 "%u, available %u\n", expected,
335 me.buffer_write_ptr - me.buffer_read_ptr);
336 return -1;
337 }
338
339 /* Read and verify MEI response header from the ME */
340 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
341 if (!mei_rsp.is_complete) {
342 printk(BIOS_ERR, "ME: response is not complete\n");
343 return -1;
344 }
345
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700346 /* Handle non-dword responses and expect at least the header */
Aaron Durbin76c37002012-10-30 09:03:43 -0500347 ndata = mei_rsp.length >> 2;
348 if (mei_rsp.length & 3)
349 ndata++;
350 if (ndata != (expected - 1)) {
351 printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
352 ndata, (expected - 1));
353 return -1;
354 }
355
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700356 /* Read response header from the ME */
357 data = header;
358 for (n = 0; n < (header_bytes >> 2); ++n)
359 *data++ = read_cb();
360 ndata -= header_bytes >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500361
362 /* Make sure caller passed a buffer with enough space */
363 if (ndata != (rsp_bytes >> 2)) {
364 printk(BIOS_ERR, "ME: not enough room in response buffer: "
365 "%u != %u\n", ndata, rsp_bytes >> 2);
366 return -1;
367 }
368
369 /* Read response data from the circular buffer */
370 data = rsp_data;
371 for (n = 0; n < ndata; ++n)
372 *data++ = read_cb();
373
374 /* Tell the ME that we have consumed the response */
375 read_host_csr(&host);
376 host.interrupt_status = 1;
377 host.interrupt_generate = 1;
378 write_host_csr(&host);
379
380 return mei_wait_for_me_ready();
381}
382
Julius Wernercd49cce2019-03-05 16:53:33 -0800383#if CONFIG(DEBUG_INTEL_ME) || defined(__SMM__)
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700384static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
385 void *req_data, int req_bytes,
386 void *rsp_data, int rsp_bytes)
Aaron Durbin76c37002012-10-30 09:03:43 -0500387{
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700388 struct mkhi_header mkhi_rsp;
389
390 /* Send header */
391 if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
392 mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500393 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700394
395 /* Send data if available */
396 if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
397 req_data, req_bytes) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500398 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700399
400 /* Return now if no response expected */
401 if (!rsp_bytes)
402 return 0;
403
404 /* Read header and data */
405 if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
406 rsp_data, rsp_bytes) < 0)
407 return -1;
408
409 if (!mkhi_rsp.is_response ||
410 mkhi->group_id != mkhi_rsp.group_id ||
411 mkhi->command != mkhi_rsp.command) {
412 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
413 "command %u ?= %u, is_response %u\n", mkhi->group_id,
414 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
415 mkhi_rsp.is_response);
416 return -1;
417 }
418
Aaron Durbin76c37002012-10-30 09:03:43 -0500419 return 0;
420}
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100421#endif /* CONFIG_DEBUG_INTEL_ME || __SMM__ */
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700422
Duncan Laurie3d299c42013-07-19 08:48:05 -0700423/*
424 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
425 * state machine on the BIOS end doesn't match the ME's state machine.
426 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100427#ifdef __SIMPLE_DEVICE__
428static void intel_me_mbp_give_up(pci_devfn_t dev)
429#else
430static void intel_me_mbp_give_up(struct device *dev)
431#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700432{
433 struct mei_csr csr;
434
435 pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP);
436
437 read_host_csr(&csr);
438 csr.reset = 1;
439 csr.interrupt_generate = 1;
440 write_host_csr(&csr);
441}
442
443/*
444 * mbp clear routine. This will wait for the ME to indicate that
445 * the MBP has been read and cleared.
446 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100447#ifdef __SIMPLE_DEVICE__
448void intel_me_mbp_clear(pci_devfn_t dev)
449#else
450void intel_me_mbp_clear(struct device *dev)
451#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700452{
453 int count;
454 struct me_hfs2 hfs2;
455
456 /* Wait for the mbp_cleared indicator */
457 for (count = ME_RETRY; count > 0; --count) {
458 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
459 if (hfs2.mbp_cleared)
460 break;
461 udelay(ME_DELAY);
462 }
463
464 if (count == 0) {
465 printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n");
466 intel_me_mbp_give_up(dev);
467 } else {
468 printk(BIOS_INFO, "ME: MBP cleared\n");
469 }
470}
471
Duncan Laurieaf980622013-07-18 23:02:18 -0700472#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) && !defined(__SMM__)
Aaron Durbin76c37002012-10-30 09:03:43 -0500473static void me_print_fw_version(mbp_fw_version_name *vers_name)
474{
Aaron Durbinbe985242012-12-12 12:40:33 -0600475 if (!vers_name) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500476 printk(BIOS_ERR, "ME: mbp missing version report\n");
477 return;
478 }
479
480 printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
481 vers_name->major_version, vers_name->minor_version,
482 vers_name->hotfix_version, vers_name->build_version);
483}
484
Julius Wernercd49cce2019-03-05 16:53:33 -0800485#if CONFIG(DEBUG_INTEL_ME)
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000486static inline void print_cap(const char *name, int state)
487{
488 printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
489 name, state ? " en" : "dis");
490}
491
Aaron Durbin76c37002012-10-30 09:03:43 -0500492/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600493static int mkhi_get_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500494{
495 u32 rule_id = 0;
496 struct me_fwcaps cap_msg;
497 struct mkhi_header mkhi = {
498 .group_id = MKHI_GROUP_ID_FWCAPS,
499 .command = MKHI_FWCAPS_GET_RULE,
500 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500501
502 /* Send request and wait for response */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700503 if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
504 &cap_msg, sizeof(cap_msg)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500505 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
506 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200507 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500508 *cap = cap_msg.caps_sku;
509 return 0;
510}
511
512/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600513static void me_print_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500514{
Aaron Durbinbe985242012-12-12 12:40:33 -0600515 mbp_mefwcaps local_caps;
516 if (!cap) {
517 cap = &local_caps;
Aaron Durbin76c37002012-10-30 09:03:43 -0500518 printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
519 if (mkhi_get_fwcaps(cap))
520 return;
521 }
522
523 print_cap("Full Network manageability", cap->full_net);
524 print_cap("Regular Network manageability", cap->std_net);
525 print_cap("Manageability", cap->manageability);
Aaron Durbin76c37002012-10-30 09:03:43 -0500526 print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
527 print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
528 print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
529 print_cap("ICC Over Clocking", cap->icc_over_clocking);
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000530 print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
Aaron Durbin76c37002012-10-30 09:03:43 -0500531 print_cap("IPV6", cap->ipv6);
532 print_cap("KVM Remote Control (KVM)", cap->kvm);
533 print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
534 print_cap("Virtual LAN (VLAN)", cap->vlan);
535 print_cap("TLS", cap->tls);
536 print_cap("Wireless LAN (WLAN)", cap->wlan);
537}
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000538#endif /* CONFIG_DEBUG_INTEL_ME */
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700539#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500540
Julius Wernercd49cce2019-03-05 16:53:33 -0800541#if CONFIG(CHROMEOS) && 0 /* DISABLED */
Aaron Durbin76c37002012-10-30 09:03:43 -0500542/* Tell ME to issue a global reset */
543static int mkhi_global_reset(void)
544{
545 struct me_global_reset reset = {
546 .request_origin = GLOBAL_RESET_BIOS_POST,
547 .reset_type = CBM_RR_GLOBAL_RESET,
548 };
549 struct mkhi_header mkhi = {
550 .group_id = MKHI_GROUP_ID_CBM,
551 .command = MKHI_GLOBAL_RESET,
552 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500553
554 /* Send request and wait for response */
555 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700556 if (mei_sendrecv_mkhi(&mkhi, &reset, sizeof(reset), NULL, 0) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500557 /* No response means reset will happen shortly... */
Patrick Georgi546953c2014-11-29 10:38:17 +0100558 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500559 }
560
561 /* If the ME responded it rejected the reset request */
562 printk(BIOS_ERR, "ME: Global Reset failed\n");
563 return -1;
564}
565#endif
566
Duncan Laurieaf980622013-07-18 23:02:18 -0700567#ifdef __SMM__
568
Aaron Durbin76c37002012-10-30 09:03:43 -0500569/* Send END OF POST message to the ME */
570static int mkhi_end_of_post(void)
571{
572 struct mkhi_header mkhi = {
573 .group_id = MKHI_GROUP_ID_GEN,
574 .command = MKHI_END_OF_POST,
575 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500576 u32 eop_ack;
577
578 /* Send request and wait for response */
579 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700580 if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500581 printk(BIOS_ERR, "ME: END OF POST message failed\n");
582 return -1;
583 }
584
585 printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
586 return 0;
587}
588
Duncan Laurieaf980622013-07-18 23:02:18 -0700589void intel_me_finalize_smm(void)
590{
591 struct me_hfs hfs;
592 u32 reg32;
593
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800594 mei_base_address = (u32 *)
595 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Duncan Laurieaf980622013-07-18 23:02:18 -0700596
597 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800598 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700599 return;
600
Julius Wernercd49cce2019-03-05 16:53:33 -0800601#if CONFIG(ME_MBP_CLEAR_LATE)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700602 /* Wait for ME MBP Cleared indicator */
603 intel_me_mbp_clear(PCH_ME_DEV);
604#endif
605
Duncan Laurieaf980622013-07-18 23:02:18 -0700606 /* Make sure ME is in a mode that expects EOP */
607 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
608 memcpy(&hfs, &reg32, sizeof(u32));
609
610 /* Abort and leave device alone if not normal mode */
611 if (hfs.fpt_bad ||
612 hfs.working_state != ME_HFS_CWS_NORMAL ||
613 hfs.operation_mode != ME_HFS_MODE_NORMAL)
614 return;
615
616 /* Try to send EOP command so ME stops accepting other commands */
617 mkhi_end_of_post();
618
619 /* Make sure IO is disabled */
620 reg32 = pci_read_config32(PCH_ME_DEV, PCI_COMMAND);
621 reg32 &= ~(PCI_COMMAND_MASTER |
622 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
623 pci_write_config32(PCH_ME_DEV, PCI_COMMAND, reg32);
624
625 /* Hide the PCI device */
626 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
627}
628
629#else /* !__SMM__ */
630
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100631static inline int mei_sendrecv_icc(struct icc_header *icc,
632 void *req_data, int req_bytes,
633 void *rsp_data, int rsp_bytes)
634{
635 struct icc_header icc_rsp;
636
637 /* Send header */
638 if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
639 icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
640 return -1;
641
642 /* Send data if available */
643 if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
644 req_data, req_bytes) < 0)
645 return -1;
646
647 /* Read header and data, if needed */
648 if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
649 rsp_data, rsp_bytes) < 0)
650 return -1;
651
652 return 0;
653}
654
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700655static int me_icc_set_clock_enables(u32 mask)
656{
657 struct icc_clock_enables_msg clk = {
658 .clock_enables = 0, /* Turn off specified clocks */
659 .clock_mask = mask,
660 .no_response = 1, /* Do not expect response */
661 };
662 struct icc_header icc = {
663 .api_version = ICC_API_VERSION_LYNXPOINT,
664 .icc_command = ICC_SET_CLOCK_ENABLES,
665 .length = sizeof(clk),
666 };
667
668 /* Send request and wait for response */
669 if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
670 printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
671 return -1;
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700672 }
673
Elyes HAOUAS54f94242018-10-25 10:57:39 +0200674 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700675 return 0;
676}
677
Aaron Durbin76c37002012-10-30 09:03:43 -0500678/* Determine the path that we should take based on ME status */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100679static me_bios_path intel_me_path(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500680{
681 me_bios_path path = ME_DISABLE_BIOS_PATH;
682 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500683 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500684
Aaron Durbin76c37002012-10-30 09:03:43 -0500685 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500686 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500687
688 /* Check and dump status */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500689 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500690
691 /* Check Current Working State */
692 switch (hfs.working_state) {
693 case ME_HFS_CWS_NORMAL:
694 path = ME_NORMAL_BIOS_PATH;
695 break;
696 case ME_HFS_CWS_REC:
697 path = ME_RECOVERY_BIOS_PATH;
698 break;
699 default:
700 path = ME_DISABLE_BIOS_PATH;
701 break;
702 }
703
704 /* Check Current Operation Mode */
705 switch (hfs.operation_mode) {
706 case ME_HFS_MODE_NORMAL:
707 break;
708 case ME_HFS_MODE_DEBUG:
709 case ME_HFS_MODE_DIS:
710 case ME_HFS_MODE_OVER_JMPR:
711 case ME_HFS_MODE_OVER_MEI:
712 default:
713 path = ME_DISABLE_BIOS_PATH;
714 break;
715 }
716
717 /* Check for any error code and valid firmware and MBP */
718 if (hfs.error_code || hfs.fpt_bad)
719 path = ME_ERROR_BIOS_PATH;
720
721 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500722 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500723 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
724 __FUNCTION__);
725 path = ME_ERROR_BIOS_PATH;
726 }
727
Julius Wernercd49cce2019-03-05 16:53:33 -0800728#if CONFIG(ELOG)
Aaron Durbin76c37002012-10-30 09:03:43 -0500729 if (path != ME_NORMAL_BIOS_PATH) {
730 struct elog_event_data_me_extended data = {
731 .current_working_state = hfs.working_state,
732 .operation_state = hfs.operation_state,
733 .operation_mode = hfs.operation_mode,
734 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500735 .progress_code = hfs2.progress_code,
736 .current_pmevent = hfs2.current_pmevent,
737 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500738 };
739 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
740 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
741 &data, sizeof(data));
742 }
743#endif
744
745 return path;
746}
747
748/* Prepare ME for MEI messages */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100749static int intel_mei_setup(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500750{
751 struct resource *res;
752 struct mei_csr host;
753 u32 reg32;
754
755 /* Find the MMIO base for the ME interface */
756 res = find_resource(dev, PCI_BASE_ADDRESS_0);
757 if (!res || res->base == 0 || res->size == 0) {
758 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
759 return -1;
760 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800761 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500762
763 /* Ensure Memory and Bus Master bits are set */
764 reg32 = pci_read_config32(dev, PCI_COMMAND);
765 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
766 pci_write_config32(dev, PCI_COMMAND, reg32);
767
768 /* Clean up status for next message */
769 read_host_csr(&host);
770 host.interrupt_generate = 1;
771 host.ready = 1;
772 host.reset = 0;
773 write_host_csr(&host);
774
775 return 0;
776}
777
778/* Read the Extend register hash of ME firmware */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100779static int intel_me_extend_valid(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500780{
781 struct me_heres status;
782 u32 extend[8] = {0};
783 int i, count = 0;
784
785 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
786 if (!status.extend_feature_present) {
787 printk(BIOS_ERR, "ME: Extend Feature not present\n");
788 return -1;
789 }
790
791 if (!status.extend_reg_valid) {
792 printk(BIOS_ERR, "ME: Extend Register not valid\n");
793 return -1;
794 }
795
796 switch (status.extend_reg_algorithm) {
797 case PCI_ME_EXT_SHA1:
798 count = 5;
799 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
800 break;
801 case PCI_ME_EXT_SHA256:
802 count = 8;
803 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
804 break;
805 default:
806 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
807 status.extend_reg_algorithm);
808 return -1;
809 }
810
811 for (i = 0; i < count; ++i) {
812 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
813 printk(BIOS_DEBUG, "%08x", extend[i]);
814 }
815 printk(BIOS_DEBUG, "\n");
816
Julius Wernercd49cce2019-03-05 16:53:33 -0800817#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500818 /* Save hash in NVS for the OS to verify */
819 chromeos_set_me_hash(extend, count);
820#endif
821
822 return 0;
823}
824
Aaron Durbin76c37002012-10-30 09:03:43 -0500825/* Check whether ME is present and do basic init */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100826static void intel_me_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500827{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700828 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500829 me_bios_path path = intel_me_path(dev);
830 me_bios_payload mbp_data;
831
832 /* Do initial setup and determine the BIOS path */
833 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
834
Duncan Laurie8056dc62013-07-22 08:47:43 -0700835 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500836 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500837 intel_me_extend_valid(dev);
838 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500839
Aaron Durbinbe985242012-12-12 12:40:33 -0600840 memset(&mbp_data, 0, sizeof(mbp_data));
841
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500842 /*
843 * According to the ME9 BWG, BIOS is required to fetch MBP data in
844 * all boot flows except S3 Resume.
845 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500846
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500847 /* Prepare MEI MMIO interface */
848 if (intel_mei_setup(dev) < 0)
849 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500850
Duncan Laurie144f7b22013-05-01 11:27:58 -0700851 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500852 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500853
854#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG)
Aaron Durbinbe985242012-12-12 12:40:33 -0600855 me_print_fw_version(mbp_data.fw_version_name);
Julius Wernercd49cce2019-03-05 16:53:33 -0800856#if CONFIG(DEBUG_INTEL_ME)
Aaron Durbinbe985242012-12-12 12:40:33 -0600857 me_print_fwcaps(mbp_data.fw_capabilities);
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700858#endif
Duncan Laurie144f7b22013-05-01 11:27:58 -0700859
860 if (mbp_data.plat_time) {
861 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
862 mbp_data.plat_time->wake_event_mrst_time_ms);
863 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
864 mbp_data.plat_time->mrst_pltrst_time_ms);
865 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
866 mbp_data.plat_time->pltrst_cpurst_time_ms);
867 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500868#endif
869
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700870 /* Set clock enables according to devicetree */
871 if (config && config->icc_clock_disable)
872 me_icc_set_clock_enables(config->icc_clock_disable);
873
Duncan Laurieaf980622013-07-18 23:02:18 -0700874 /*
875 * Leave the ME unlocked. It will be locked via SMI command later.
876 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500877}
878
Aaron Durbin76c37002012-10-30 09:03:43 -0500879static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530880 .set_subsystem = pci_dev_set_subsystem,
Aaron Durbin76c37002012-10-30 09:03:43 -0500881};
882
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100883static void intel_me_enable(struct device *dev)
Duncan Laurie8056dc62013-07-22 08:47:43 -0700884{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700885 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300886 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700887 dev->enabled = 0;
888 pch_disable_devfn(dev);
889 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700890}
891
Aaron Durbin76c37002012-10-30 09:03:43 -0500892static struct device_operations device_ops = {
893 .read_resources = pci_dev_read_resources,
894 .set_resources = pci_dev_set_resources,
895 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700896 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500897 .init = intel_me_init,
Aaron Durbin76c37002012-10-30 09:03:43 -0500898 .ops_pci = &pci_ops,
899};
900
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800901static const unsigned short pci_device_ids[] = {
902 0x8c3a, /* Mobile */
903 0x9c3a, /* Low Power */
904 0
905};
906
Aaron Durbin76c37002012-10-30 09:03:43 -0500907static const struct pci_driver intel_me __pci_driver = {
908 .ops = &device_ops,
909 .vendor = PCI_VENDOR_ID_INTEL,
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800910 .devices= pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500911};
912
913/******************************************************************************
914 * */
915static u32 me_to_host_words_pending(void)
916{
917 struct mei_csr me;
918 read_me_csr(&me);
919 if (!me.ready)
920 return 0;
921 return (me.buffer_write_ptr - me.buffer_read_ptr) &
922 (me.buffer_depth - 1);
923}
924
925#if 0
926/* This function is not yet being used, keep it in for the future. */
927static u32 host_to_me_words_room(void)
928{
929 struct mei_csr csr;
930
931 read_me_csr(&csr);
932 if (!csr.ready)
933 return 0;
934
935 read_host_csr(&csr);
936 return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) &
937 (csr.buffer_depth - 1);
938}
939#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500940
Aaron Durbinbe985242012-12-12 12:40:33 -0600941struct mbp_payload {
942 mbp_header header;
943 u32 data[0];
944};
945
Aaron Durbin76c37002012-10-30 09:03:43 -0500946/*
947 * mbp seems to be following its own flow, let's retrieve it in a dedicated
948 * function.
949 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100950static int intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500951{
952 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500953 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500954 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500955 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600956 struct mbp_payload *mbp;
957 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500958
959 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
960
961 if (!hfs2.mbp_rdy) {
962 printk(BIOS_ERR, "ME: MBP not ready\n");
963 goto mbp_failure;
964 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500965
966 me2host_pending = me_to_host_words_pending();
967 if (!me2host_pending) {
968 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500969 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500970 }
971
972 /* we know for sure that at least the header is there */
973 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
974
975 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
976 (me2host_pending < mbp_hdr.mbp_size)) {
977 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
978 " buffer contains %d words\n",
979 mbp_hdr.num_entries, mbp_hdr.mbp_size,
980 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500981 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500982 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600983 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
984 if (!mbp)
985 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500986
Aaron Durbinbe985242012-12-12 12:40:33 -0600987 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500988 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500989
Aaron Durbinbe985242012-12-12 12:40:33 -0600990 i = 0;
991 while (i != me2host_pending) {
992 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
993 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500994 }
995
Aaron Durbinbe985242012-12-12 12:40:33 -0600996 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500997 read_host_csr(&host);
998 host.interrupt_generate = 1;
999 write_host_csr(&host);
1000
Julius Wernercd49cce2019-03-05 16:53:33 -08001001#if !CONFIG(ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -06001002 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -07001003 intel_me_mbp_clear(dev);
1004#endif
Aaron Durbin76c37002012-10-30 09:03:43 -05001005
Aaron Durbinbe985242012-12-12 12:40:33 -06001006 /* Dump out the MBP contents. */
1007#if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG)
1008 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
1009 mbp->header.num_entries, mbp->header.mbp_size);
Julius Wernercd49cce2019-03-05 16:53:33 -08001010#if CONFIG(DEBUG_INTEL_ME)
Aaron Durbinbe985242012-12-12 12:40:33 -06001011 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
1012 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
1013 }
1014#endif
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001015#endif
Aaron Durbinbe985242012-12-12 12:40:33 -06001016
1017 #define ASSIGN_FIELD_PTR(field_,val_) \
1018 { \
1019 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
1020 break; \
1021 }
1022 /* Setup the pointers in the me_bios_payload structure. */
1023 for (i = 0; i < mbp->header.mbp_size - 1;) {
1024 mbp_item_header *item = (void *)&mbp->data[i];
1025
Elyes HAOUASf9de5a42018-05-03 17:21:02 +02001026 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -06001027 case MBP_IDENT(KERNEL, FW_VER):
1028 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
1029
1030 case MBP_IDENT(ICC, PROFILE):
1031 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
1032
1033 case MBP_IDENT(INTEL_AT, STATE):
1034 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
1035
1036 case MBP_IDENT(KERNEL, FW_CAP):
1037 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
1038
1039 case MBP_IDENT(KERNEL, ROM_BIST):
1040 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
1041
1042 case MBP_IDENT(KERNEL, PLAT_KEY):
1043 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
1044
1045 case MBP_IDENT(KERNEL, FW_TYPE):
1046 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
1047
1048 case MBP_IDENT(KERNEL, MFS_FAILURE):
1049 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
1050
Duncan Laurie144f7b22013-05-01 11:27:58 -07001051 case MBP_IDENT(KERNEL, PLAT_TIME):
1052 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
1053
1054 case MBP_IDENT(NFC, SUPPORT_DATA):
1055 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
1056
Aaron Durbinbe985242012-12-12 12:40:33 -06001057 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001058 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
1059 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -06001060 break;
1061 }
1062 i += item->length;
1063 }
1064 #undef ASSIGN_FIELD_PTR
1065
Aaron Durbin76c37002012-10-30 09:03:43 -05001066 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001067
1068mbp_failure:
1069 intel_me_mbp_give_up(dev);
1070 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001071}
Duncan Laurieaf980622013-07-18 23:02:18 -07001072
1073#endif /* !__SMM__ */