blob: 4599c26cffa8d6fa065bbad5d6531f964a24b3e5 [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;
Elyes HAOUAS73ae0762020-04-28 10:13:05 +0200571 u16 reg16;
Duncan Laurieaf980622013-07-18 23:02:18 -0700572
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800573 mei_base_address = (u32 *)
574 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Duncan Laurieaf980622013-07-18 23:02:18 -0700575
576 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800577 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700578 return;
579
Julius Wernercd49cce2019-03-05 16:53:33 -0800580#if CONFIG(ME_MBP_CLEAR_LATE)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700581 /* Wait for ME MBP Cleared indicator */
582 intel_me_mbp_clear(PCH_ME_DEV);
583#endif
584
Duncan Laurieaf980622013-07-18 23:02:18 -0700585 /* Make sure ME is in a mode that expects EOP */
586 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
587 memcpy(&hfs, &reg32, sizeof(u32));
588
589 /* Abort and leave device alone if not normal mode */
590 if (hfs.fpt_bad ||
591 hfs.working_state != ME_HFS_CWS_NORMAL ||
592 hfs.operation_mode != ME_HFS_MODE_NORMAL)
593 return;
594
595 /* Try to send EOP command so ME stops accepting other commands */
596 mkhi_end_of_post();
597
598 /* Make sure IO is disabled */
Elyes HAOUAS73ae0762020-04-28 10:13:05 +0200599 reg16 = pci_read_config16(PCH_ME_DEV, PCI_COMMAND);
600 reg16 &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
601 pci_write_config16(PCH_ME_DEV, PCI_COMMAND, reg16);
Duncan Laurieaf980622013-07-18 23:02:18 -0700602
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;
Aaron Durbin76c37002012-10-30 09:03:43 -0500729
730 /* Find the MMIO base for the ME interface */
731 res = find_resource(dev, PCI_BASE_ADDRESS_0);
732 if (!res || res->base == 0 || res->size == 0) {
733 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
734 return -1;
735 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800736 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500737
738 /* Ensure Memory and Bus Master bits are set */
Elyes HAOUAS73ae0762020-04-28 10:13:05 +0200739 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
Aaron Durbin76c37002012-10-30 09:03:43 -0500740
741 /* Clean up status for next message */
742 read_host_csr(&host);
743 host.interrupt_generate = 1;
744 host.ready = 1;
745 host.reset = 0;
746 write_host_csr(&host);
747
748 return 0;
749}
750
751/* Read the Extend register hash of ME firmware */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100752static int intel_me_extend_valid(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500753{
754 struct me_heres status;
755 u32 extend[8] = {0};
756 int i, count = 0;
757
758 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
759 if (!status.extend_feature_present) {
760 printk(BIOS_ERR, "ME: Extend Feature not present\n");
761 return -1;
762 }
763
764 if (!status.extend_reg_valid) {
765 printk(BIOS_ERR, "ME: Extend Register not valid\n");
766 return -1;
767 }
768
769 switch (status.extend_reg_algorithm) {
770 case PCI_ME_EXT_SHA1:
771 count = 5;
772 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
773 break;
774 case PCI_ME_EXT_SHA256:
775 count = 8;
776 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
777 break;
778 default:
779 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
780 status.extend_reg_algorithm);
781 return -1;
782 }
783
784 for (i = 0; i < count; ++i) {
785 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
786 printk(BIOS_DEBUG, "%08x", extend[i]);
787 }
788 printk(BIOS_DEBUG, "\n");
789
Julius Wernercd49cce2019-03-05 16:53:33 -0800790#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500791 /* Save hash in NVS for the OS to verify */
792 chromeos_set_me_hash(extend, count);
793#endif
794
795 return 0;
796}
797
Aaron Durbin76c37002012-10-30 09:03:43 -0500798/* Check whether ME is present and do basic init */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100799static void intel_me_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500800{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700801 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500802 me_bios_path path = intel_me_path(dev);
803 me_bios_payload mbp_data;
804
805 /* Do initial setup and determine the BIOS path */
806 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
807
Duncan Laurie8056dc62013-07-22 08:47:43 -0700808 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500809 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500810 intel_me_extend_valid(dev);
811 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500812
Aaron Durbinbe985242012-12-12 12:40:33 -0600813 memset(&mbp_data, 0, sizeof(mbp_data));
814
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500815 /*
816 * According to the ME9 BWG, BIOS is required to fetch MBP data in
817 * all boot flows except S3 Resume.
818 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500819
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500820 /* Prepare MEI MMIO interface */
821 if (intel_mei_setup(dev) < 0)
822 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500823
Duncan Laurie144f7b22013-05-01 11:27:58 -0700824 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500825 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500826
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200827 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
828 me_print_fw_version(mbp_data.fw_version_name);
Duncan Laurie144f7b22013-05-01 11:27:58 -0700829
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200830 if (CONFIG(DEBUG_INTEL_ME))
831 me_print_fwcaps(mbp_data.fw_capabilities);
832
833 if (mbp_data.plat_time) {
834 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
835 mbp_data.plat_time->wake_event_mrst_time_ms);
836 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
837 mbp_data.plat_time->mrst_pltrst_time_ms);
838 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
839 mbp_data.plat_time->pltrst_cpurst_time_ms);
840 }
Duncan Laurie144f7b22013-05-01 11:27:58 -0700841 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500842
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700843 /* Set clock enables according to devicetree */
844 if (config && config->icc_clock_disable)
845 me_icc_set_clock_enables(config->icc_clock_disable);
846
Duncan Laurieaf980622013-07-18 23:02:18 -0700847 /*
848 * Leave the ME unlocked. It will be locked via SMI command later.
849 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500850}
851
Aaron Durbin76c37002012-10-30 09:03:43 -0500852static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530853 .set_subsystem = pci_dev_set_subsystem,
Aaron Durbin76c37002012-10-30 09:03:43 -0500854};
855
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100856static void intel_me_enable(struct device *dev)
Duncan Laurie8056dc62013-07-22 08:47:43 -0700857{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700858 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300859 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700860 dev->enabled = 0;
861 pch_disable_devfn(dev);
862 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700863}
864
Aaron Durbin76c37002012-10-30 09:03:43 -0500865static struct device_operations device_ops = {
866 .read_resources = pci_dev_read_resources,
867 .set_resources = pci_dev_set_resources,
868 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700869 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500870 .init = intel_me_init,
Aaron Durbin76c37002012-10-30 09:03:43 -0500871 .ops_pci = &pci_ops,
872};
873
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800874static const unsigned short pci_device_ids[] = {
875 0x8c3a, /* Mobile */
876 0x9c3a, /* Low Power */
877 0
878};
879
Aaron Durbin76c37002012-10-30 09:03:43 -0500880static const struct pci_driver intel_me __pci_driver = {
881 .ops = &device_ops,
882 .vendor = PCI_VENDOR_ID_INTEL,
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800883 .devices= pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500884};
885
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200886#endif /* !__SIMPLE_DEVICE__ */
887
Aaron Durbin76c37002012-10-30 09:03:43 -0500888/******************************************************************************
889 * */
890static u32 me_to_host_words_pending(void)
891{
892 struct mei_csr me;
893 read_me_csr(&me);
894 if (!me.ready)
895 return 0;
896 return (me.buffer_write_ptr - me.buffer_read_ptr) &
897 (me.buffer_depth - 1);
898}
899
900#if 0
901/* This function is not yet being used, keep it in for the future. */
902static u32 host_to_me_words_room(void)
903{
904 struct mei_csr csr;
905
906 read_me_csr(&csr);
907 if (!csr.ready)
908 return 0;
909
910 read_host_csr(&csr);
911 return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) &
912 (csr.buffer_depth - 1);
913}
914#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500915
Aaron Durbinbe985242012-12-12 12:40:33 -0600916struct mbp_payload {
917 mbp_header header;
918 u32 data[0];
919};
920
Aaron Durbin76c37002012-10-30 09:03:43 -0500921/*
922 * mbp seems to be following its own flow, let's retrieve it in a dedicated
923 * function.
924 */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200925static int __unused intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500926{
927 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500928 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500929 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500930 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600931 struct mbp_payload *mbp;
932 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500933
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200934#ifdef __SIMPLE_DEVICE__
935 pci_read_dword_ptr(PCI_BDF(dev), &hfs2, PCI_ME_HFS2);
936#else
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500937 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200938#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500939
940 if (!hfs2.mbp_rdy) {
941 printk(BIOS_ERR, "ME: MBP not ready\n");
942 goto mbp_failure;
943 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500944
945 me2host_pending = me_to_host_words_pending();
946 if (!me2host_pending) {
947 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500948 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500949 }
950
951 /* we know for sure that at least the header is there */
952 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
953
954 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
955 (me2host_pending < mbp_hdr.mbp_size)) {
956 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
957 " buffer contains %d words\n",
958 mbp_hdr.num_entries, mbp_hdr.mbp_size,
959 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500960 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500961 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600962 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
963 if (!mbp)
964 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500965
Aaron Durbinbe985242012-12-12 12:40:33 -0600966 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500967 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500968
Aaron Durbinbe985242012-12-12 12:40:33 -0600969 i = 0;
970 while (i != me2host_pending) {
971 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
972 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500973 }
974
Aaron Durbinbe985242012-12-12 12:40:33 -0600975 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500976 read_host_csr(&host);
977 host.interrupt_generate = 1;
978 write_host_csr(&host);
979
Julius Wernercd49cce2019-03-05 16:53:33 -0800980#if !CONFIG(ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -0600981 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -0700982 intel_me_mbp_clear(dev);
983#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500984
Aaron Durbinbe985242012-12-12 12:40:33 -0600985 /* Dump out the MBP contents. */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200986 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
987 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
988 mbp->header.num_entries, mbp->header.mbp_size);
989 if (CONFIG(DEBUG_INTEL_ME)) {
990 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
991 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
992 }
993 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600994 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600995
996 #define ASSIGN_FIELD_PTR(field_,val_) \
997 { \
998 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
999 break; \
1000 }
1001 /* Setup the pointers in the me_bios_payload structure. */
1002 for (i = 0; i < mbp->header.mbp_size - 1;) {
1003 mbp_item_header *item = (void *)&mbp->data[i];
1004
Elyes HAOUASf9de5a42018-05-03 17:21:02 +02001005 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -06001006 case MBP_IDENT(KERNEL, FW_VER):
1007 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
1008
1009 case MBP_IDENT(ICC, PROFILE):
1010 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
1011
1012 case MBP_IDENT(INTEL_AT, STATE):
1013 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
1014
1015 case MBP_IDENT(KERNEL, FW_CAP):
1016 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
1017
1018 case MBP_IDENT(KERNEL, ROM_BIST):
1019 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
1020
1021 case MBP_IDENT(KERNEL, PLAT_KEY):
1022 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
1023
1024 case MBP_IDENT(KERNEL, FW_TYPE):
1025 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
1026
1027 case MBP_IDENT(KERNEL, MFS_FAILURE):
1028 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
1029
Duncan Laurie144f7b22013-05-01 11:27:58 -07001030 case MBP_IDENT(KERNEL, PLAT_TIME):
1031 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
1032
1033 case MBP_IDENT(NFC, SUPPORT_DATA):
1034 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
1035
Aaron Durbinbe985242012-12-12 12:40:33 -06001036 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001037 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
1038 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -06001039 break;
1040 }
1041 i += item->length;
1042 }
1043 #undef ASSIGN_FIELD_PTR
1044
Aaron Durbin76c37002012-10-30 09:03:43 -05001045 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001046
1047mbp_failure:
Kyösti Mälkki21d6a272019-11-05 18:50:38 +02001048#ifdef __SIMPLE_DEVICE__
1049 intel_me_mbp_give_up(PCI_BDF(dev));
1050#else
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001051 intel_me_mbp_give_up(dev);
Kyösti Mälkki21d6a272019-11-05 18:50:38 +02001052#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001053 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001054}