blob: c5562c5cfca1507c51c14f6641452d7cc121ae10 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Aaron Durbin76c37002012-10-30 09:03:43 -05003
4/*
5 * This is a ramstage driver for the Intel Management Engine found in the
6 * 6-series chipset. It handles the required boot-time messages over the
7 * MMIO-based Management Engine Interface to tell the ME that the BIOS is
8 * finished with POST. Additional messages are defined for debug but are
9 * not used unless the console loglevel is high enough.
10 */
11
12#include <arch/acpi.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020013#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020014#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050015#include <console/console.h>
Stefan Reinauer24d1d4b2013-03-21 11:51:41 -070016#include <device/device.h>
17#include <device/pci.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050018#include <device/pci_ids.h>
19#include <device/pci_def.h>
20#include <string.h>
21#include <delay.h>
22#include <elog.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010023#include <halt.h>
Elyes HAOUAS400f9ca2019-06-23 07:01:22 +020024#include <stdlib.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050025
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030026#include "chip.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050027#include "me.h"
28#include "pch.h"
29
Julius Wernercd49cce2019-03-05 16:53:33 -080030#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -050031#include <vendorcode/google/chromeos/chromeos.h>
32#include <vendorcode/google/chromeos/gnvs.h>
33#endif
34
Aaron Durbin76c37002012-10-30 09:03:43 -050035/* Path that the BIOS should take based on ME state */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +020036static const char *me_bios_path_values[] __unused = {
Aaron Durbin76c37002012-10-30 09:03:43 -050037 [ME_NORMAL_BIOS_PATH] = "Normal",
38 [ME_S3WAKE_BIOS_PATH] = "S3 Wake",
39 [ME_ERROR_BIOS_PATH] = "Error",
40 [ME_RECOVERY_BIOS_PATH] = "Recovery",
41 [ME_DISABLE_BIOS_PATH] = "Disable",
42 [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update",
43};
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010044static int intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev);
Aaron Durbin76c37002012-10-30 09:03:43 -050045
46/* MMIO base address for MEI interface */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080047static u32 *mei_base_address;
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +010048#ifdef __SIMPLE_DEVICE__
49void intel_me_mbp_clear(pci_devfn_t dev);
50#else
51void intel_me_mbp_clear(struct device *dev);
52#endif
Aaron Durbin76c37002012-10-30 09:03:43 -050053
Aaron Durbin76c37002012-10-30 09:03:43 -050054static void mei_dump(void *ptr, int dword, int offset, const char *type)
55{
56 struct mei_csr *csr;
57
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +020058 if (!CONFIG(DEBUG_INTEL_ME))
59 return;
60
Aaron Durbin76c37002012-10-30 09:03:43 -050061 printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset);
62
63 switch (offset) {
64 case MEI_H_CSR:
65 case MEI_ME_CSR_HA:
66 csr = ptr;
67 if (!csr) {
68 printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword);
69 break;
70 }
71 printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
72 "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth,
73 csr->buffer_read_ptr, csr->buffer_write_ptr,
74 csr->ready, csr->reset, csr->interrupt_generate,
75 csr->interrupt_status, csr->interrupt_enable);
76 break;
77 case MEI_ME_CB_RW:
78 case MEI_H_CB_WW:
79 printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
80 break;
81 default:
82 printk(BIOS_SPEW, "0x%08x\n", offset);
83 break;
84 }
85}
Aaron Durbin76c37002012-10-30 09:03:43 -050086
87/*
88 * ME/MEI access helpers using memcpy to avoid aliasing.
89 */
90
91static inline void mei_read_dword_ptr(void *ptr, int offset)
92{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080093 u32 dword = read32(mei_base_address + (offset/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -050094 memcpy(ptr, &dword, sizeof(dword));
95 mei_dump(ptr, dword, offset, "READ");
96}
97
98static inline void mei_write_dword_ptr(void *ptr, int offset)
99{
100 u32 dword = 0;
101 memcpy(&dword, ptr, sizeof(dword));
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800102 write32(mei_base_address + (offset/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500103 mei_dump(ptr, dword, offset, "WRITE");
104}
105
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100106#ifdef __SIMPLE_DEVICE__
107static inline void pci_read_dword_ptr(pci_devfn_t dev, void *ptr, int offset)
108#else
109static inline void pci_read_dword_ptr(struct device *dev, void *ptr, int offset)
110#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500111{
112 u32 dword = pci_read_config32(dev, offset);
113 memcpy(ptr, &dword, sizeof(dword));
114 mei_dump(ptr, dword, offset, "PCI READ");
115}
Aaron Durbin76c37002012-10-30 09:03:43 -0500116
117static inline void read_host_csr(struct mei_csr *csr)
118{
119 mei_read_dword_ptr(csr, MEI_H_CSR);
120}
121
122static inline void write_host_csr(struct mei_csr *csr)
123{
124 mei_write_dword_ptr(csr, MEI_H_CSR);
125}
126
127static inline void read_me_csr(struct mei_csr *csr)
128{
129 mei_read_dword_ptr(csr, MEI_ME_CSR_HA);
130}
131
132static inline void write_cb(u32 dword)
133{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800134 write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500135 mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE");
136}
137
138static inline u32 read_cb(void)
139{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800140 u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500141 mei_dump(NULL, dword, MEI_ME_CB_RW, "READ");
142 return dword;
143}
144
145/* Wait for ME ready bit to be asserted */
146static int mei_wait_for_me_ready(void)
147{
148 struct mei_csr me;
Martin Rothff744bf2019-10-23 21:46:03 -0600149 unsigned int try = ME_RETRY;
Aaron Durbin76c37002012-10-30 09:03:43 -0500150
151 while (try--) {
152 read_me_csr(&me);
153 if (me.ready)
154 return 0;
155 udelay(ME_DELAY);
156 }
157
158 printk(BIOS_ERR, "ME: failed to become ready\n");
159 return -1;
160}
161
162static void mei_reset(void)
163{
164 struct mei_csr host;
165
166 if (mei_wait_for_me_ready() < 0)
167 return;
168
169 /* Reset host and ME circular buffers for next message */
170 read_host_csr(&host);
171 host.reset = 1;
172 host.interrupt_generate = 1;
173 write_host_csr(&host);
174
175 if (mei_wait_for_me_ready() < 0)
176 return;
177
178 /* Re-init and indicate host is ready */
179 read_host_csr(&host);
180 host.interrupt_generate = 1;
181 host.ready = 1;
182 host.reset = 0;
183 write_host_csr(&host);
184}
185
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700186static int mei_send_packet(struct mei_header *mei, void *req_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500187{
188 struct mei_csr host;
Martin Rothff744bf2019-10-23 21:46:03 -0600189 unsigned int ndata, n;
Aaron Durbin76c37002012-10-30 09:03:43 -0500190 u32 *data;
191
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700192 /* Number of dwords to write */
Aaron Durbin76c37002012-10-30 09:03:43 -0500193 ndata = mei->length >> 2;
194
195 /* Pad non-dword aligned request message length */
196 if (mei->length & 3)
197 ndata++;
198 if (!ndata) {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700199 printk(BIOS_DEBUG, "ME: request has no data\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500200 return -1;
201 }
202 ndata++; /* Add MEI header */
203
204 /*
205 * Make sure there is still room left in the circular buffer.
206 * Reset the buffer pointers if the requested message will not fit.
207 */
208 read_host_csr(&host);
209 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
210 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
211 mei_reset();
212 read_host_csr(&host);
213 }
214
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700215 /* Ensure the requested length will fit in the circular buffer. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500216 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
217 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
218 ndata + 2, host.buffer_depth);
219 return -1;
220 }
221
222 /* Write MEI header */
223 mei_write_dword_ptr(mei, MEI_H_CB_WW);
224 ndata--;
225
Aaron Durbin76c37002012-10-30 09:03:43 -0500226 /* Write message data */
227 data = req_data;
228 for (n = 0; n < ndata; ++n)
229 write_cb(*data++);
230
231 /* Generate interrupt to the ME */
232 read_host_csr(&host);
233 host.interrupt_generate = 1;
234 write_host_csr(&host);
235
236 /* Make sure ME is ready after sending request data */
237 return mei_wait_for_me_ready();
238}
239
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700240static int mei_send_data(u8 me_address, u8 host_address,
241 void *req_data, int req_bytes)
242{
243 struct mei_header header = {
244 .client_address = me_address,
245 .host_address = host_address,
246 };
247 struct mei_csr host;
248 int current = 0;
249 u8 *req_ptr = req_data;
250
251 while (!header.is_complete) {
252 int remain = req_bytes - current;
253 int buf_len;
254
255 read_host_csr(&host);
256 buf_len = host.buffer_depth - host.buffer_write_ptr;
257
258 if (buf_len > remain) {
259 /* Send all remaining data as final message */
260 header.length = req_bytes - current;
261 header.is_complete = 1;
262 } else {
263 /* Send as much data as the buffer can hold */
264 header.length = buf_len;
265 }
266
267 mei_send_packet(&header, req_ptr);
268
269 req_ptr += header.length;
270 current += header.length;
271 }
272
273 return 0;
274}
275
276static int mei_send_header(u8 me_address, u8 host_address,
277 void *header, int header_len, int complete)
278{
279 struct mei_header mei = {
280 .client_address = me_address,
281 .host_address = host_address,
282 .length = header_len,
283 .is_complete = complete,
284 };
285 return mei_send_packet(&mei, header);
286}
287
288static int mei_recv_msg(void *header, int header_bytes,
Aaron Durbin76c37002012-10-30 09:03:43 -0500289 void *rsp_data, int rsp_bytes)
290{
291 struct mei_header mei_rsp;
Aaron Durbin76c37002012-10-30 09:03:43 -0500292 struct mei_csr me, host;
Martin Rothff744bf2019-10-23 21:46:03 -0600293 unsigned int ndata, n;
294 unsigned int expected;
Aaron Durbin76c37002012-10-30 09:03:43 -0500295 u32 *data;
296
297 /* Total number of dwords to read from circular buffer */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700298 expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500299 if (rsp_bytes & 3)
300 expected++;
301
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700302 if (mei_wait_for_me_ready() < 0)
303 return -1;
304
Aaron Durbin76c37002012-10-30 09:03:43 -0500305 /*
306 * The interrupt status bit does not appear to indicate that the
307 * message has actually been received. Instead we wait until the
308 * expected number of dwords are present in the circular buffer.
309 */
310 for (n = ME_RETRY; n; --n) {
311 read_me_csr(&me);
312 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
313 break;
314 udelay(ME_DELAY);
315 }
316 if (!n) {
317 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
318 "%u, available %u\n", expected,
319 me.buffer_write_ptr - me.buffer_read_ptr);
320 return -1;
321 }
322
323 /* Read and verify MEI response header from the ME */
324 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
325 if (!mei_rsp.is_complete) {
326 printk(BIOS_ERR, "ME: response is not complete\n");
327 return -1;
328 }
329
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700330 /* Handle non-dword responses and expect at least the header */
Aaron Durbin76c37002012-10-30 09:03:43 -0500331 ndata = mei_rsp.length >> 2;
332 if (mei_rsp.length & 3)
333 ndata++;
334 if (ndata != (expected - 1)) {
335 printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
336 ndata, (expected - 1));
337 return -1;
338 }
339
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700340 /* Read response header from the ME */
341 data = header;
342 for (n = 0; n < (header_bytes >> 2); ++n)
343 *data++ = read_cb();
344 ndata -= header_bytes >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500345
346 /* Make sure caller passed a buffer with enough space */
347 if (ndata != (rsp_bytes >> 2)) {
348 printk(BIOS_ERR, "ME: not enough room in response buffer: "
349 "%u != %u\n", ndata, rsp_bytes >> 2);
350 return -1;
351 }
352
353 /* Read response data from the circular buffer */
354 data = rsp_data;
355 for (n = 0; n < ndata; ++n)
356 *data++ = read_cb();
357
358 /* Tell the ME that we have consumed the response */
359 read_host_csr(&host);
360 host.interrupt_status = 1;
361 host.interrupt_generate = 1;
362 write_host_csr(&host);
363
364 return mei_wait_for_me_ready();
365}
366
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700367static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
368 void *req_data, int req_bytes,
369 void *rsp_data, int rsp_bytes)
Aaron Durbin76c37002012-10-30 09:03:43 -0500370{
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700371 struct mkhi_header mkhi_rsp;
372
373 /* Send header */
374 if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
375 mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500376 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700377
378 /* Send data if available */
379 if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
380 req_data, req_bytes) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500381 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700382
383 /* Return now if no response expected */
384 if (!rsp_bytes)
385 return 0;
386
387 /* Read header and data */
388 if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
389 rsp_data, rsp_bytes) < 0)
390 return -1;
391
392 if (!mkhi_rsp.is_response ||
393 mkhi->group_id != mkhi_rsp.group_id ||
394 mkhi->command != mkhi_rsp.command) {
395 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
396 "command %u ?= %u, is_response %u\n", mkhi->group_id,
397 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
398 mkhi_rsp.is_response);
399 return -1;
400 }
401
Aaron Durbin76c37002012-10-30 09:03:43 -0500402 return 0;
403}
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700404
Duncan Laurie3d299c42013-07-19 08:48:05 -0700405/*
406 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
407 * state machine on the BIOS end doesn't match the ME's state machine.
408 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100409#ifdef __SIMPLE_DEVICE__
410static void intel_me_mbp_give_up(pci_devfn_t dev)
411#else
412static void intel_me_mbp_give_up(struct device *dev)
413#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700414{
415 struct mei_csr csr;
416
417 pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP);
418
419 read_host_csr(&csr);
420 csr.reset = 1;
421 csr.interrupt_generate = 1;
422 write_host_csr(&csr);
423}
424
425/*
426 * mbp clear routine. This will wait for the ME to indicate that
427 * the MBP has been read and cleared.
428 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100429#ifdef __SIMPLE_DEVICE__
430void intel_me_mbp_clear(pci_devfn_t dev)
431#else
432void intel_me_mbp_clear(struct device *dev)
433#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700434{
435 int count;
436 struct me_hfs2 hfs2;
437
438 /* Wait for the mbp_cleared indicator */
439 for (count = ME_RETRY; count > 0; --count) {
440 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
441 if (hfs2.mbp_cleared)
442 break;
443 udelay(ME_DELAY);
444 }
445
446 if (count == 0) {
447 printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n");
448 intel_me_mbp_give_up(dev);
449 } else {
450 printk(BIOS_INFO, "ME: MBP cleared\n");
451 }
452}
453
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200454static void __unused me_print_fw_version(mbp_fw_version_name *vers_name)
Aaron Durbin76c37002012-10-30 09:03:43 -0500455{
Aaron Durbinbe985242012-12-12 12:40:33 -0600456 if (!vers_name) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500457 printk(BIOS_ERR, "ME: mbp missing version report\n");
458 return;
459 }
460
461 printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
462 vers_name->major_version, vers_name->minor_version,
463 vers_name->hotfix_version, vers_name->build_version);
464}
465
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000466static inline void print_cap(const char *name, int state)
467{
468 printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
469 name, state ? " en" : "dis");
470}
471
Aaron Durbin76c37002012-10-30 09:03:43 -0500472/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600473static int mkhi_get_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500474{
475 u32 rule_id = 0;
476 struct me_fwcaps cap_msg;
477 struct mkhi_header mkhi = {
478 .group_id = MKHI_GROUP_ID_FWCAPS,
479 .command = MKHI_FWCAPS_GET_RULE,
480 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500481
482 /* Send request and wait for response */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700483 if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
484 &cap_msg, sizeof(cap_msg)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500485 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
486 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200487 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500488 *cap = cap_msg.caps_sku;
489 return 0;
490}
491
492/* Get ME Firmware Capabilities */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200493static void __unused me_print_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500494{
Aaron Durbinbe985242012-12-12 12:40:33 -0600495 mbp_mefwcaps local_caps;
496 if (!cap) {
497 cap = &local_caps;
Aaron Durbin76c37002012-10-30 09:03:43 -0500498 printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
499 if (mkhi_get_fwcaps(cap))
500 return;
501 }
502
503 print_cap("Full Network manageability", cap->full_net);
504 print_cap("Regular Network manageability", cap->std_net);
505 print_cap("Manageability", cap->manageability);
Aaron Durbin76c37002012-10-30 09:03:43 -0500506 print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
507 print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
508 print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
509 print_cap("ICC Over Clocking", cap->icc_over_clocking);
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000510 print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
Aaron Durbin76c37002012-10-30 09:03:43 -0500511 print_cap("IPV6", cap->ipv6);
512 print_cap("KVM Remote Control (KVM)", cap->kvm);
513 print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
514 print_cap("Virtual LAN (VLAN)", cap->vlan);
515 print_cap("TLS", cap->tls);
516 print_cap("Wireless LAN (WLAN)", cap->wlan);
517}
Aaron Durbin76c37002012-10-30 09:03:43 -0500518
Julius Wernercd49cce2019-03-05 16:53:33 -0800519#if CONFIG(CHROMEOS) && 0 /* DISABLED */
Aaron Durbin76c37002012-10-30 09:03:43 -0500520/* Tell ME to issue a global reset */
521static int mkhi_global_reset(void)
522{
523 struct me_global_reset reset = {
524 .request_origin = GLOBAL_RESET_BIOS_POST,
525 .reset_type = CBM_RR_GLOBAL_RESET,
526 };
527 struct mkhi_header mkhi = {
528 .group_id = MKHI_GROUP_ID_CBM,
529 .command = MKHI_GLOBAL_RESET,
530 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500531
532 /* Send request and wait for response */
533 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700534 if (mei_sendrecv_mkhi(&mkhi, &reset, sizeof(reset), NULL, 0) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500535 /* No response means reset will happen shortly... */
Patrick Georgi546953c2014-11-29 10:38:17 +0100536 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500537 }
538
539 /* If the ME responded it rejected the reset request */
540 printk(BIOS_ERR, "ME: Global Reset failed\n");
541 return -1;
542}
543#endif
544
Aaron Durbin76c37002012-10-30 09:03:43 -0500545/* Send END OF POST message to the ME */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200546static int __unused mkhi_end_of_post(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500547{
548 struct mkhi_header mkhi = {
549 .group_id = MKHI_GROUP_ID_GEN,
550 .command = MKHI_END_OF_POST,
551 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500552 u32 eop_ack;
553
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, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500557 printk(BIOS_ERR, "ME: END OF POST message failed\n");
558 return -1;
559 }
560
561 printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
562 return 0;
563}
564
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200565#ifdef __SIMPLE_DEVICE__
566
Duncan Laurieaf980622013-07-18 23:02:18 -0700567void intel_me_finalize_smm(void)
568{
569 struct me_hfs hfs;
570 u32 reg32;
571
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800572 mei_base_address = (u32 *)
573 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Duncan Laurieaf980622013-07-18 23:02:18 -0700574
575 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800576 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700577 return;
578
Julius Wernercd49cce2019-03-05 16:53:33 -0800579#if CONFIG(ME_MBP_CLEAR_LATE)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700580 /* Wait for ME MBP Cleared indicator */
581 intel_me_mbp_clear(PCH_ME_DEV);
582#endif
583
Duncan Laurieaf980622013-07-18 23:02:18 -0700584 /* Make sure ME is in a mode that expects EOP */
585 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
586 memcpy(&hfs, &reg32, sizeof(u32));
587
588 /* Abort and leave device alone if not normal mode */
589 if (hfs.fpt_bad ||
590 hfs.working_state != ME_HFS_CWS_NORMAL ||
591 hfs.operation_mode != ME_HFS_MODE_NORMAL)
592 return;
593
594 /* Try to send EOP command so ME stops accepting other commands */
595 mkhi_end_of_post();
596
597 /* Make sure IO is disabled */
598 reg32 = pci_read_config32(PCH_ME_DEV, PCI_COMMAND);
599 reg32 &= ~(PCI_COMMAND_MASTER |
600 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
601 pci_write_config32(PCH_ME_DEV, PCI_COMMAND, reg32);
602
603 /* Hide the PCI device */
604 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
605}
606
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200607#else /* !__SIMPLE_DEVICE__ */
Duncan Laurieaf980622013-07-18 23:02:18 -0700608
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100609static inline int mei_sendrecv_icc(struct icc_header *icc,
610 void *req_data, int req_bytes,
611 void *rsp_data, int rsp_bytes)
612{
613 struct icc_header icc_rsp;
614
615 /* Send header */
616 if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
617 icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
618 return -1;
619
620 /* Send data if available */
621 if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
622 req_data, req_bytes) < 0)
623 return -1;
624
625 /* Read header and data, if needed */
626 if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
627 rsp_data, rsp_bytes) < 0)
628 return -1;
629
630 return 0;
631}
632
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700633static int me_icc_set_clock_enables(u32 mask)
634{
635 struct icc_clock_enables_msg clk = {
636 .clock_enables = 0, /* Turn off specified clocks */
637 .clock_mask = mask,
638 .no_response = 1, /* Do not expect response */
639 };
640 struct icc_header icc = {
641 .api_version = ICC_API_VERSION_LYNXPOINT,
642 .icc_command = ICC_SET_CLOCK_ENABLES,
643 .length = sizeof(clk),
644 };
645
646 /* Send request and wait for response */
647 if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
648 printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
649 return -1;
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700650 }
651
Elyes HAOUAS54f94242018-10-25 10:57:39 +0200652 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700653 return 0;
654}
655
Aaron Durbin76c37002012-10-30 09:03:43 -0500656/* Determine the path that we should take based on ME status */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100657static me_bios_path intel_me_path(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500658{
659 me_bios_path path = ME_DISABLE_BIOS_PATH;
660 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500661 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500662
Aaron Durbin76c37002012-10-30 09:03:43 -0500663 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500664 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500665
666 /* Check and dump status */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500667 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500668
669 /* Check Current Working State */
670 switch (hfs.working_state) {
671 case ME_HFS_CWS_NORMAL:
672 path = ME_NORMAL_BIOS_PATH;
673 break;
674 case ME_HFS_CWS_REC:
675 path = ME_RECOVERY_BIOS_PATH;
676 break;
677 default:
678 path = ME_DISABLE_BIOS_PATH;
679 break;
680 }
681
682 /* Check Current Operation Mode */
683 switch (hfs.operation_mode) {
684 case ME_HFS_MODE_NORMAL:
685 break;
686 case ME_HFS_MODE_DEBUG:
687 case ME_HFS_MODE_DIS:
688 case ME_HFS_MODE_OVER_JMPR:
689 case ME_HFS_MODE_OVER_MEI:
690 default:
691 path = ME_DISABLE_BIOS_PATH;
692 break;
693 }
694
695 /* Check for any error code and valid firmware and MBP */
696 if (hfs.error_code || hfs.fpt_bad)
697 path = ME_ERROR_BIOS_PATH;
698
699 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500700 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500701 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
702 __FUNCTION__);
703 path = ME_ERROR_BIOS_PATH;
704 }
705
Kyösti Mälkkibe5317f2019-11-06 12:07:21 +0200706 if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500707 struct elog_event_data_me_extended data = {
708 .current_working_state = hfs.working_state,
709 .operation_state = hfs.operation_state,
710 .operation_mode = hfs.operation_mode,
711 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500712 .progress_code = hfs2.progress_code,
713 .current_pmevent = hfs2.current_pmevent,
714 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500715 };
716 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
717 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
718 &data, sizeof(data));
719 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500720
721 return path;
722}
723
724/* Prepare ME for MEI messages */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100725static int intel_mei_setup(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500726{
727 struct resource *res;
728 struct mei_csr host;
729 u32 reg32;
730
731 /* Find the MMIO base for the ME interface */
732 res = find_resource(dev, PCI_BASE_ADDRESS_0);
733 if (!res || res->base == 0 || res->size == 0) {
734 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
735 return -1;
736 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800737 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500738
739 /* Ensure Memory and Bus Master bits are set */
740 reg32 = pci_read_config32(dev, PCI_COMMAND);
741 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
742 pci_write_config32(dev, PCI_COMMAND, reg32);
743
744 /* Clean up status for next message */
745 read_host_csr(&host);
746 host.interrupt_generate = 1;
747 host.ready = 1;
748 host.reset = 0;
749 write_host_csr(&host);
750
751 return 0;
752}
753
754/* Read the Extend register hash of ME firmware */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100755static int intel_me_extend_valid(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500756{
757 struct me_heres status;
758 u32 extend[8] = {0};
759 int i, count = 0;
760
761 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
762 if (!status.extend_feature_present) {
763 printk(BIOS_ERR, "ME: Extend Feature not present\n");
764 return -1;
765 }
766
767 if (!status.extend_reg_valid) {
768 printk(BIOS_ERR, "ME: Extend Register not valid\n");
769 return -1;
770 }
771
772 switch (status.extend_reg_algorithm) {
773 case PCI_ME_EXT_SHA1:
774 count = 5;
775 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
776 break;
777 case PCI_ME_EXT_SHA256:
778 count = 8;
779 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
780 break;
781 default:
782 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
783 status.extend_reg_algorithm);
784 return -1;
785 }
786
787 for (i = 0; i < count; ++i) {
788 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
789 printk(BIOS_DEBUG, "%08x", extend[i]);
790 }
791 printk(BIOS_DEBUG, "\n");
792
Julius Wernercd49cce2019-03-05 16:53:33 -0800793#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500794 /* Save hash in NVS for the OS to verify */
795 chromeos_set_me_hash(extend, count);
796#endif
797
798 return 0;
799}
800
Aaron Durbin76c37002012-10-30 09:03:43 -0500801/* Check whether ME is present and do basic init */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100802static void intel_me_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500803{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700804 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500805 me_bios_path path = intel_me_path(dev);
806 me_bios_payload mbp_data;
807
808 /* Do initial setup and determine the BIOS path */
809 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
810
Duncan Laurie8056dc62013-07-22 08:47:43 -0700811 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500812 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500813 intel_me_extend_valid(dev);
814 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500815
Aaron Durbinbe985242012-12-12 12:40:33 -0600816 memset(&mbp_data, 0, sizeof(mbp_data));
817
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500818 /*
819 * According to the ME9 BWG, BIOS is required to fetch MBP data in
820 * all boot flows except S3 Resume.
821 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500822
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500823 /* Prepare MEI MMIO interface */
824 if (intel_mei_setup(dev) < 0)
825 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500826
Duncan Laurie144f7b22013-05-01 11:27:58 -0700827 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500828 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500829
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200830 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
831 me_print_fw_version(mbp_data.fw_version_name);
Duncan Laurie144f7b22013-05-01 11:27:58 -0700832
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200833 if (CONFIG(DEBUG_INTEL_ME))
834 me_print_fwcaps(mbp_data.fw_capabilities);
835
836 if (mbp_data.plat_time) {
837 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
838 mbp_data.plat_time->wake_event_mrst_time_ms);
839 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
840 mbp_data.plat_time->mrst_pltrst_time_ms);
841 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
842 mbp_data.plat_time->pltrst_cpurst_time_ms);
843 }
Duncan Laurie144f7b22013-05-01 11:27:58 -0700844 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500845
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700846 /* Set clock enables according to devicetree */
847 if (config && config->icc_clock_disable)
848 me_icc_set_clock_enables(config->icc_clock_disable);
849
Duncan Laurieaf980622013-07-18 23:02:18 -0700850 /*
851 * Leave the ME unlocked. It will be locked via SMI command later.
852 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500853}
854
Aaron Durbin76c37002012-10-30 09:03:43 -0500855static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530856 .set_subsystem = pci_dev_set_subsystem,
Aaron Durbin76c37002012-10-30 09:03:43 -0500857};
858
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100859static void intel_me_enable(struct device *dev)
Duncan Laurie8056dc62013-07-22 08:47:43 -0700860{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700861 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300862 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700863 dev->enabled = 0;
864 pch_disable_devfn(dev);
865 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700866}
867
Aaron Durbin76c37002012-10-30 09:03:43 -0500868static struct device_operations device_ops = {
869 .read_resources = pci_dev_read_resources,
870 .set_resources = pci_dev_set_resources,
871 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700872 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500873 .init = intel_me_init,
Aaron Durbin76c37002012-10-30 09:03:43 -0500874 .ops_pci = &pci_ops,
875};
876
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800877static const unsigned short pci_device_ids[] = {
878 0x8c3a, /* Mobile */
879 0x9c3a, /* Low Power */
880 0
881};
882
Aaron Durbin76c37002012-10-30 09:03:43 -0500883static const struct pci_driver intel_me __pci_driver = {
884 .ops = &device_ops,
885 .vendor = PCI_VENDOR_ID_INTEL,
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800886 .devices= pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500887};
888
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200889#endif /* !__SIMPLE_DEVICE__ */
890
Aaron Durbin76c37002012-10-30 09:03:43 -0500891/******************************************************************************
892 * */
893static u32 me_to_host_words_pending(void)
894{
895 struct mei_csr me;
896 read_me_csr(&me);
897 if (!me.ready)
898 return 0;
899 return (me.buffer_write_ptr - me.buffer_read_ptr) &
900 (me.buffer_depth - 1);
901}
902
903#if 0
904/* This function is not yet being used, keep it in for the future. */
905static u32 host_to_me_words_room(void)
906{
907 struct mei_csr csr;
908
909 read_me_csr(&csr);
910 if (!csr.ready)
911 return 0;
912
913 read_host_csr(&csr);
914 return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) &
915 (csr.buffer_depth - 1);
916}
917#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500918
Aaron Durbinbe985242012-12-12 12:40:33 -0600919struct mbp_payload {
920 mbp_header header;
921 u32 data[0];
922};
923
Aaron Durbin76c37002012-10-30 09:03:43 -0500924/*
925 * mbp seems to be following its own flow, let's retrieve it in a dedicated
926 * function.
927 */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200928static int __unused intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500929{
930 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500931 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500932 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500933 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600934 struct mbp_payload *mbp;
935 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500936
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200937#ifdef __SIMPLE_DEVICE__
938 pci_read_dword_ptr(PCI_BDF(dev), &hfs2, PCI_ME_HFS2);
939#else
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500940 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200941#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500942
943 if (!hfs2.mbp_rdy) {
944 printk(BIOS_ERR, "ME: MBP not ready\n");
945 goto mbp_failure;
946 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500947
948 me2host_pending = me_to_host_words_pending();
949 if (!me2host_pending) {
950 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500951 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500952 }
953
954 /* we know for sure that at least the header is there */
955 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
956
957 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
958 (me2host_pending < mbp_hdr.mbp_size)) {
959 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
960 " buffer contains %d words\n",
961 mbp_hdr.num_entries, mbp_hdr.mbp_size,
962 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500963 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500964 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600965 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
966 if (!mbp)
967 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500968
Aaron Durbinbe985242012-12-12 12:40:33 -0600969 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500970 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500971
Aaron Durbinbe985242012-12-12 12:40:33 -0600972 i = 0;
973 while (i != me2host_pending) {
974 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
975 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500976 }
977
Aaron Durbinbe985242012-12-12 12:40:33 -0600978 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500979 read_host_csr(&host);
980 host.interrupt_generate = 1;
981 write_host_csr(&host);
982
Julius Wernercd49cce2019-03-05 16:53:33 -0800983#if !CONFIG(ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -0600984 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -0700985 intel_me_mbp_clear(dev);
986#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500987
Aaron Durbinbe985242012-12-12 12:40:33 -0600988 /* Dump out the MBP contents. */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200989 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
990 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
991 mbp->header.num_entries, mbp->header.mbp_size);
992 if (CONFIG(DEBUG_INTEL_ME)) {
993 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
994 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
995 }
996 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600997 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600998
999 #define ASSIGN_FIELD_PTR(field_,val_) \
1000 { \
1001 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
1002 break; \
1003 }
1004 /* Setup the pointers in the me_bios_payload structure. */
1005 for (i = 0; i < mbp->header.mbp_size - 1;) {
1006 mbp_item_header *item = (void *)&mbp->data[i];
1007
Elyes HAOUASf9de5a42018-05-03 17:21:02 +02001008 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -06001009 case MBP_IDENT(KERNEL, FW_VER):
1010 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
1011
1012 case MBP_IDENT(ICC, PROFILE):
1013 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
1014
1015 case MBP_IDENT(INTEL_AT, STATE):
1016 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
1017
1018 case MBP_IDENT(KERNEL, FW_CAP):
1019 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
1020
1021 case MBP_IDENT(KERNEL, ROM_BIST):
1022 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
1023
1024 case MBP_IDENT(KERNEL, PLAT_KEY):
1025 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
1026
1027 case MBP_IDENT(KERNEL, FW_TYPE):
1028 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
1029
1030 case MBP_IDENT(KERNEL, MFS_FAILURE):
1031 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
1032
Duncan Laurie144f7b22013-05-01 11:27:58 -07001033 case MBP_IDENT(KERNEL, PLAT_TIME):
1034 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
1035
1036 case MBP_IDENT(NFC, SUPPORT_DATA):
1037 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
1038
Aaron Durbinbe985242012-12-12 12:40:33 -06001039 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001040 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
1041 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -06001042 break;
1043 }
1044 i += item->length;
1045 }
1046 #undef ASSIGN_FIELD_PTR
1047
Aaron Durbin76c37002012-10-30 09:03:43 -05001048 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001049
1050mbp_failure:
Kyösti Mälkki21d6a272019-11-05 18:50:38 +02001051#ifdef __SIMPLE_DEVICE__
1052 intel_me_mbp_give_up(PCI_BDF(dev));
1053#else
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001054 intel_me_mbp_give_up(dev);
Kyösti Mälkki21d6a272019-11-05 18:50:38 +02001055#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001056 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001057}