blob: 1c45e2d99bdbf7093cebde7354d88089d77f7f11 [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
Aaron Durbin76c37002012-10-30 09:03:43 -050069static void mei_dump(void *ptr, int dword, int offset, const char *type)
70{
71 struct mei_csr *csr;
72
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +020073 if (!CONFIG(DEBUG_INTEL_ME))
74 return;
75
Aaron Durbin76c37002012-10-30 09:03:43 -050076 printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset);
77
78 switch (offset) {
79 case MEI_H_CSR:
80 case MEI_ME_CSR_HA:
81 csr = ptr;
82 if (!csr) {
83 printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword);
84 break;
85 }
86 printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
87 "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth,
88 csr->buffer_read_ptr, csr->buffer_write_ptr,
89 csr->ready, csr->reset, csr->interrupt_generate,
90 csr->interrupt_status, csr->interrupt_enable);
91 break;
92 case MEI_ME_CB_RW:
93 case MEI_H_CB_WW:
94 printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
95 break;
96 default:
97 printk(BIOS_SPEW, "0x%08x\n", offset);
98 break;
99 }
100}
Aaron Durbin76c37002012-10-30 09:03:43 -0500101
102/*
103 * ME/MEI access helpers using memcpy to avoid aliasing.
104 */
105
106static inline void mei_read_dword_ptr(void *ptr, int offset)
107{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800108 u32 dword = read32(mei_base_address + (offset/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500109 memcpy(ptr, &dword, sizeof(dword));
110 mei_dump(ptr, dword, offset, "READ");
111}
112
113static inline void mei_write_dword_ptr(void *ptr, int offset)
114{
115 u32 dword = 0;
116 memcpy(&dword, ptr, sizeof(dword));
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800117 write32(mei_base_address + (offset/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500118 mei_dump(ptr, dword, offset, "WRITE");
119}
120
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100121#ifdef __SIMPLE_DEVICE__
122static inline void pci_read_dword_ptr(pci_devfn_t dev, void *ptr, int offset)
123#else
124static inline void pci_read_dword_ptr(struct device *dev, void *ptr, int offset)
125#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500126{
127 u32 dword = pci_read_config32(dev, offset);
128 memcpy(ptr, &dword, sizeof(dword));
129 mei_dump(ptr, dword, offset, "PCI READ");
130}
Aaron Durbin76c37002012-10-30 09:03:43 -0500131
132static inline void read_host_csr(struct mei_csr *csr)
133{
134 mei_read_dword_ptr(csr, MEI_H_CSR);
135}
136
137static inline void write_host_csr(struct mei_csr *csr)
138{
139 mei_write_dword_ptr(csr, MEI_H_CSR);
140}
141
142static inline void read_me_csr(struct mei_csr *csr)
143{
144 mei_read_dword_ptr(csr, MEI_ME_CSR_HA);
145}
146
147static inline void write_cb(u32 dword)
148{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800149 write32(mei_base_address + (MEI_H_CB_WW/sizeof(u32)), dword);
Aaron Durbin76c37002012-10-30 09:03:43 -0500150 mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE");
151}
152
153static inline u32 read_cb(void)
154{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800155 u32 dword = read32(mei_base_address + (MEI_ME_CB_RW/sizeof(u32)));
Aaron Durbin76c37002012-10-30 09:03:43 -0500156 mei_dump(NULL, dword, MEI_ME_CB_RW, "READ");
157 return dword;
158}
159
160/* Wait for ME ready bit to be asserted */
161static int mei_wait_for_me_ready(void)
162{
163 struct mei_csr me;
Martin Rothff744bf2019-10-23 21:46:03 -0600164 unsigned int try = ME_RETRY;
Aaron Durbin76c37002012-10-30 09:03:43 -0500165
166 while (try--) {
167 read_me_csr(&me);
168 if (me.ready)
169 return 0;
170 udelay(ME_DELAY);
171 }
172
173 printk(BIOS_ERR, "ME: failed to become ready\n");
174 return -1;
175}
176
177static void mei_reset(void)
178{
179 struct mei_csr host;
180
181 if (mei_wait_for_me_ready() < 0)
182 return;
183
184 /* Reset host and ME circular buffers for next message */
185 read_host_csr(&host);
186 host.reset = 1;
187 host.interrupt_generate = 1;
188 write_host_csr(&host);
189
190 if (mei_wait_for_me_ready() < 0)
191 return;
192
193 /* Re-init and indicate host is ready */
194 read_host_csr(&host);
195 host.interrupt_generate = 1;
196 host.ready = 1;
197 host.reset = 0;
198 write_host_csr(&host);
199}
200
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700201static int mei_send_packet(struct mei_header *mei, void *req_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500202{
203 struct mei_csr host;
Martin Rothff744bf2019-10-23 21:46:03 -0600204 unsigned int ndata, n;
Aaron Durbin76c37002012-10-30 09:03:43 -0500205 u32 *data;
206
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700207 /* Number of dwords to write */
Aaron Durbin76c37002012-10-30 09:03:43 -0500208 ndata = mei->length >> 2;
209
210 /* Pad non-dword aligned request message length */
211 if (mei->length & 3)
212 ndata++;
213 if (!ndata) {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700214 printk(BIOS_DEBUG, "ME: request has no data\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500215 return -1;
216 }
217 ndata++; /* Add MEI header */
218
219 /*
220 * Make sure there is still room left in the circular buffer.
221 * Reset the buffer pointers if the requested message will not fit.
222 */
223 read_host_csr(&host);
224 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
225 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
226 mei_reset();
227 read_host_csr(&host);
228 }
229
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700230 /* Ensure the requested length will fit in the circular buffer. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500231 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
232 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
233 ndata + 2, host.buffer_depth);
234 return -1;
235 }
236
237 /* Write MEI header */
238 mei_write_dword_ptr(mei, MEI_H_CB_WW);
239 ndata--;
240
Aaron Durbin76c37002012-10-30 09:03:43 -0500241 /* Write message data */
242 data = req_data;
243 for (n = 0; n < ndata; ++n)
244 write_cb(*data++);
245
246 /* Generate interrupt to the ME */
247 read_host_csr(&host);
248 host.interrupt_generate = 1;
249 write_host_csr(&host);
250
251 /* Make sure ME is ready after sending request data */
252 return mei_wait_for_me_ready();
253}
254
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700255static int mei_send_data(u8 me_address, u8 host_address,
256 void *req_data, int req_bytes)
257{
258 struct mei_header header = {
259 .client_address = me_address,
260 .host_address = host_address,
261 };
262 struct mei_csr host;
263 int current = 0;
264 u8 *req_ptr = req_data;
265
266 while (!header.is_complete) {
267 int remain = req_bytes - current;
268 int buf_len;
269
270 read_host_csr(&host);
271 buf_len = host.buffer_depth - host.buffer_write_ptr;
272
273 if (buf_len > remain) {
274 /* Send all remaining data as final message */
275 header.length = req_bytes - current;
276 header.is_complete = 1;
277 } else {
278 /* Send as much data as the buffer can hold */
279 header.length = buf_len;
280 }
281
282 mei_send_packet(&header, req_ptr);
283
284 req_ptr += header.length;
285 current += header.length;
286 }
287
288 return 0;
289}
290
291static int mei_send_header(u8 me_address, u8 host_address,
292 void *header, int header_len, int complete)
293{
294 struct mei_header mei = {
295 .client_address = me_address,
296 .host_address = host_address,
297 .length = header_len,
298 .is_complete = complete,
299 };
300 return mei_send_packet(&mei, header);
301}
302
303static int mei_recv_msg(void *header, int header_bytes,
Aaron Durbin76c37002012-10-30 09:03:43 -0500304 void *rsp_data, int rsp_bytes)
305{
306 struct mei_header mei_rsp;
Aaron Durbin76c37002012-10-30 09:03:43 -0500307 struct mei_csr me, host;
Martin Rothff744bf2019-10-23 21:46:03 -0600308 unsigned int ndata, n;
309 unsigned int expected;
Aaron Durbin76c37002012-10-30 09:03:43 -0500310 u32 *data;
311
312 /* Total number of dwords to read from circular buffer */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700313 expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500314 if (rsp_bytes & 3)
315 expected++;
316
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700317 if (mei_wait_for_me_ready() < 0)
318 return -1;
319
Aaron Durbin76c37002012-10-30 09:03:43 -0500320 /*
321 * The interrupt status bit does not appear to indicate that the
322 * message has actually been received. Instead we wait until the
323 * expected number of dwords are present in the circular buffer.
324 */
325 for (n = ME_RETRY; n; --n) {
326 read_me_csr(&me);
327 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
328 break;
329 udelay(ME_DELAY);
330 }
331 if (!n) {
332 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
333 "%u, available %u\n", expected,
334 me.buffer_write_ptr - me.buffer_read_ptr);
335 return -1;
336 }
337
338 /* Read and verify MEI response header from the ME */
339 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
340 if (!mei_rsp.is_complete) {
341 printk(BIOS_ERR, "ME: response is not complete\n");
342 return -1;
343 }
344
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700345 /* Handle non-dword responses and expect at least the header */
Aaron Durbin76c37002012-10-30 09:03:43 -0500346 ndata = mei_rsp.length >> 2;
347 if (mei_rsp.length & 3)
348 ndata++;
349 if (ndata != (expected - 1)) {
350 printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
351 ndata, (expected - 1));
352 return -1;
353 }
354
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700355 /* Read response header from the ME */
356 data = header;
357 for (n = 0; n < (header_bytes >> 2); ++n)
358 *data++ = read_cb();
359 ndata -= header_bytes >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500360
361 /* Make sure caller passed a buffer with enough space */
362 if (ndata != (rsp_bytes >> 2)) {
363 printk(BIOS_ERR, "ME: not enough room in response buffer: "
364 "%u != %u\n", ndata, rsp_bytes >> 2);
365 return -1;
366 }
367
368 /* Read response data from the circular buffer */
369 data = rsp_data;
370 for (n = 0; n < ndata; ++n)
371 *data++ = read_cb();
372
373 /* Tell the ME that we have consumed the response */
374 read_host_csr(&host);
375 host.interrupt_status = 1;
376 host.interrupt_generate = 1;
377 write_host_csr(&host);
378
379 return mei_wait_for_me_ready();
380}
381
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700382static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
383 void *req_data, int req_bytes,
384 void *rsp_data, int rsp_bytes)
Aaron Durbin76c37002012-10-30 09:03:43 -0500385{
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700386 struct mkhi_header mkhi_rsp;
387
388 /* Send header */
389 if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
390 mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500391 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700392
393 /* Send data if available */
394 if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
395 req_data, req_bytes) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500396 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700397
398 /* Return now if no response expected */
399 if (!rsp_bytes)
400 return 0;
401
402 /* Read header and data */
403 if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
404 rsp_data, rsp_bytes) < 0)
405 return -1;
406
407 if (!mkhi_rsp.is_response ||
408 mkhi->group_id != mkhi_rsp.group_id ||
409 mkhi->command != mkhi_rsp.command) {
410 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
411 "command %u ?= %u, is_response %u\n", mkhi->group_id,
412 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
413 mkhi_rsp.is_response);
414 return -1;
415 }
416
Aaron Durbin76c37002012-10-30 09:03:43 -0500417 return 0;
418}
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700419
Duncan Laurie3d299c42013-07-19 08:48:05 -0700420/*
421 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
422 * state machine on the BIOS end doesn't match the ME's state machine.
423 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100424#ifdef __SIMPLE_DEVICE__
425static void intel_me_mbp_give_up(pci_devfn_t dev)
426#else
427static void intel_me_mbp_give_up(struct device *dev)
428#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700429{
430 struct mei_csr csr;
431
432 pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP);
433
434 read_host_csr(&csr);
435 csr.reset = 1;
436 csr.interrupt_generate = 1;
437 write_host_csr(&csr);
438}
439
440/*
441 * mbp clear routine. This will wait for the ME to indicate that
442 * the MBP has been read and cleared.
443 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100444#ifdef __SIMPLE_DEVICE__
445void intel_me_mbp_clear(pci_devfn_t dev)
446#else
447void intel_me_mbp_clear(struct device *dev)
448#endif
Duncan Laurie3d299c42013-07-19 08:48:05 -0700449{
450 int count;
451 struct me_hfs2 hfs2;
452
453 /* Wait for the mbp_cleared indicator */
454 for (count = ME_RETRY; count > 0; --count) {
455 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
456 if (hfs2.mbp_cleared)
457 break;
458 udelay(ME_DELAY);
459 }
460
461 if (count == 0) {
462 printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n");
463 intel_me_mbp_give_up(dev);
464 } else {
465 printk(BIOS_INFO, "ME: MBP cleared\n");
466 }
467}
468
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200469static void __unused me_print_fw_version(mbp_fw_version_name *vers_name)
Aaron Durbin76c37002012-10-30 09:03:43 -0500470{
Aaron Durbinbe985242012-12-12 12:40:33 -0600471 if (!vers_name) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500472 printk(BIOS_ERR, "ME: mbp missing version report\n");
473 return;
474 }
475
476 printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
477 vers_name->major_version, vers_name->minor_version,
478 vers_name->hotfix_version, vers_name->build_version);
479}
480
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000481static inline void print_cap(const char *name, int state)
482{
483 printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
484 name, state ? " en" : "dis");
485}
486
Aaron Durbin76c37002012-10-30 09:03:43 -0500487/* Get ME Firmware Capabilities */
Aaron Durbinbe985242012-12-12 12:40:33 -0600488static int mkhi_get_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500489{
490 u32 rule_id = 0;
491 struct me_fwcaps cap_msg;
492 struct mkhi_header mkhi = {
493 .group_id = MKHI_GROUP_ID_FWCAPS,
494 .command = MKHI_FWCAPS_GET_RULE,
495 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500496
497 /* Send request and wait for response */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700498 if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
499 &cap_msg, sizeof(cap_msg)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500500 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
501 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200502 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500503 *cap = cap_msg.caps_sku;
504 return 0;
505}
506
507/* Get ME Firmware Capabilities */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200508static void __unused me_print_fwcaps(mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500509{
Aaron Durbinbe985242012-12-12 12:40:33 -0600510 mbp_mefwcaps local_caps;
511 if (!cap) {
512 cap = &local_caps;
Aaron Durbin76c37002012-10-30 09:03:43 -0500513 printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
514 if (mkhi_get_fwcaps(cap))
515 return;
516 }
517
518 print_cap("Full Network manageability", cap->full_net);
519 print_cap("Regular Network manageability", cap->std_net);
520 print_cap("Manageability", cap->manageability);
Aaron Durbin76c37002012-10-30 09:03:43 -0500521 print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
522 print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
523 print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
524 print_cap("ICC Over Clocking", cap->icc_over_clocking);
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000525 print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
Aaron Durbin76c37002012-10-30 09:03:43 -0500526 print_cap("IPV6", cap->ipv6);
527 print_cap("KVM Remote Control (KVM)", cap->kvm);
528 print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
529 print_cap("Virtual LAN (VLAN)", cap->vlan);
530 print_cap("TLS", cap->tls);
531 print_cap("Wireless LAN (WLAN)", cap->wlan);
532}
Aaron Durbin76c37002012-10-30 09:03:43 -0500533
Julius Wernercd49cce2019-03-05 16:53:33 -0800534#if CONFIG(CHROMEOS) && 0 /* DISABLED */
Aaron Durbin76c37002012-10-30 09:03:43 -0500535/* Tell ME to issue a global reset */
536static int mkhi_global_reset(void)
537{
538 struct me_global_reset reset = {
539 .request_origin = GLOBAL_RESET_BIOS_POST,
540 .reset_type = CBM_RR_GLOBAL_RESET,
541 };
542 struct mkhi_header mkhi = {
543 .group_id = MKHI_GROUP_ID_CBM,
544 .command = MKHI_GLOBAL_RESET,
545 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500546
547 /* Send request and wait for response */
548 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700549 if (mei_sendrecv_mkhi(&mkhi, &reset, sizeof(reset), NULL, 0) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500550 /* No response means reset will happen shortly... */
Patrick Georgi546953c2014-11-29 10:38:17 +0100551 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500552 }
553
554 /* If the ME responded it rejected the reset request */
555 printk(BIOS_ERR, "ME: Global Reset failed\n");
556 return -1;
557}
558#endif
559
Duncan Laurieaf980622013-07-18 23:02:18 -0700560#ifdef __SMM__
561
Aaron Durbin76c37002012-10-30 09:03:43 -0500562/* Send END OF POST message to the ME */
563static int mkhi_end_of_post(void)
564{
565 struct mkhi_header mkhi = {
566 .group_id = MKHI_GROUP_ID_GEN,
567 .command = MKHI_END_OF_POST,
568 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500569 u32 eop_ack;
570
571 /* Send request and wait for response */
572 printk(BIOS_NOTICE, "ME: %s\n", __FUNCTION__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700573 if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500574 printk(BIOS_ERR, "ME: END OF POST message failed\n");
575 return -1;
576 }
577
578 printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
579 return 0;
580}
581
Duncan Laurieaf980622013-07-18 23:02:18 -0700582void intel_me_finalize_smm(void)
583{
584 struct me_hfs hfs;
585 u32 reg32;
586
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800587 mei_base_address = (u32 *)
588 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Duncan Laurieaf980622013-07-18 23:02:18 -0700589
590 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800591 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700592 return;
593
Julius Wernercd49cce2019-03-05 16:53:33 -0800594#if CONFIG(ME_MBP_CLEAR_LATE)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700595 /* Wait for ME MBP Cleared indicator */
596 intel_me_mbp_clear(PCH_ME_DEV);
597#endif
598
Duncan Laurieaf980622013-07-18 23:02:18 -0700599 /* Make sure ME is in a mode that expects EOP */
600 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
601 memcpy(&hfs, &reg32, sizeof(u32));
602
603 /* Abort and leave device alone if not normal mode */
604 if (hfs.fpt_bad ||
605 hfs.working_state != ME_HFS_CWS_NORMAL ||
606 hfs.operation_mode != ME_HFS_MODE_NORMAL)
607 return;
608
609 /* Try to send EOP command so ME stops accepting other commands */
610 mkhi_end_of_post();
611
612 /* Make sure IO is disabled */
613 reg32 = pci_read_config32(PCH_ME_DEV, PCI_COMMAND);
614 reg32 &= ~(PCI_COMMAND_MASTER |
615 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
616 pci_write_config32(PCH_ME_DEV, PCI_COMMAND, reg32);
617
618 /* Hide the PCI device */
619 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
620}
621
622#else /* !__SMM__ */
623
Edward O'Callaghan97ccefd2015-01-07 15:53:00 +1100624static inline int mei_sendrecv_icc(struct icc_header *icc,
625 void *req_data, int req_bytes,
626 void *rsp_data, int rsp_bytes)
627{
628 struct icc_header icc_rsp;
629
630 /* Send header */
631 if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
632 icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
633 return -1;
634
635 /* Send data if available */
636 if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
637 req_data, req_bytes) < 0)
638 return -1;
639
640 /* Read header and data, if needed */
641 if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
642 rsp_data, rsp_bytes) < 0)
643 return -1;
644
645 return 0;
646}
647
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700648static int me_icc_set_clock_enables(u32 mask)
649{
650 struct icc_clock_enables_msg clk = {
651 .clock_enables = 0, /* Turn off specified clocks */
652 .clock_mask = mask,
653 .no_response = 1, /* Do not expect response */
654 };
655 struct icc_header icc = {
656 .api_version = ICC_API_VERSION_LYNXPOINT,
657 .icc_command = ICC_SET_CLOCK_ENABLES,
658 .length = sizeof(clk),
659 };
660
661 /* Send request and wait for response */
662 if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
663 printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
664 return -1;
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700665 }
666
Elyes HAOUAS54f94242018-10-25 10:57:39 +0200667 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700668 return 0;
669}
670
Aaron Durbin76c37002012-10-30 09:03:43 -0500671/* Determine the path that we should take based on ME status */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100672static me_bios_path intel_me_path(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500673{
674 me_bios_path path = ME_DISABLE_BIOS_PATH;
675 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500676 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500677
Aaron Durbin76c37002012-10-30 09:03:43 -0500678 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500679 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500680
681 /* Check and dump status */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500682 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500683
684 /* Check Current Working State */
685 switch (hfs.working_state) {
686 case ME_HFS_CWS_NORMAL:
687 path = ME_NORMAL_BIOS_PATH;
688 break;
689 case ME_HFS_CWS_REC:
690 path = ME_RECOVERY_BIOS_PATH;
691 break;
692 default:
693 path = ME_DISABLE_BIOS_PATH;
694 break;
695 }
696
697 /* Check Current Operation Mode */
698 switch (hfs.operation_mode) {
699 case ME_HFS_MODE_NORMAL:
700 break;
701 case ME_HFS_MODE_DEBUG:
702 case ME_HFS_MODE_DIS:
703 case ME_HFS_MODE_OVER_JMPR:
704 case ME_HFS_MODE_OVER_MEI:
705 default:
706 path = ME_DISABLE_BIOS_PATH;
707 break;
708 }
709
710 /* Check for any error code and valid firmware and MBP */
711 if (hfs.error_code || hfs.fpt_bad)
712 path = ME_ERROR_BIOS_PATH;
713
714 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500715 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500716 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
717 __FUNCTION__);
718 path = ME_ERROR_BIOS_PATH;
719 }
720
Julius Wernercd49cce2019-03-05 16:53:33 -0800721#if CONFIG(ELOG)
Aaron Durbin76c37002012-10-30 09:03:43 -0500722 if (path != ME_NORMAL_BIOS_PATH) {
723 struct elog_event_data_me_extended data = {
724 .current_working_state = hfs.working_state,
725 .operation_state = hfs.operation_state,
726 .operation_mode = hfs.operation_mode,
727 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500728 .progress_code = hfs2.progress_code,
729 .current_pmevent = hfs2.current_pmevent,
730 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500731 };
732 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
733 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
734 &data, sizeof(data));
735 }
736#endif
737
738 return path;
739}
740
741/* Prepare ME for MEI messages */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100742static int intel_mei_setup(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500743{
744 struct resource *res;
745 struct mei_csr host;
746 u32 reg32;
747
748 /* Find the MMIO base for the ME interface */
749 res = find_resource(dev, PCI_BASE_ADDRESS_0);
750 if (!res || res->base == 0 || res->size == 0) {
751 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
752 return -1;
753 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800754 mei_base_address = (u32 *)(uintptr_t)res->base;
Aaron Durbin76c37002012-10-30 09:03:43 -0500755
756 /* Ensure Memory and Bus Master bits are set */
757 reg32 = pci_read_config32(dev, PCI_COMMAND);
758 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
759 pci_write_config32(dev, PCI_COMMAND, reg32);
760
761 /* Clean up status for next message */
762 read_host_csr(&host);
763 host.interrupt_generate = 1;
764 host.ready = 1;
765 host.reset = 0;
766 write_host_csr(&host);
767
768 return 0;
769}
770
771/* Read the Extend register hash of ME firmware */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100772static int intel_me_extend_valid(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500773{
774 struct me_heres status;
775 u32 extend[8] = {0};
776 int i, count = 0;
777
778 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
779 if (!status.extend_feature_present) {
780 printk(BIOS_ERR, "ME: Extend Feature not present\n");
781 return -1;
782 }
783
784 if (!status.extend_reg_valid) {
785 printk(BIOS_ERR, "ME: Extend Register not valid\n");
786 return -1;
787 }
788
789 switch (status.extend_reg_algorithm) {
790 case PCI_ME_EXT_SHA1:
791 count = 5;
792 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
793 break;
794 case PCI_ME_EXT_SHA256:
795 count = 8;
796 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
797 break;
798 default:
799 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
800 status.extend_reg_algorithm);
801 return -1;
802 }
803
804 for (i = 0; i < count; ++i) {
805 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
806 printk(BIOS_DEBUG, "%08x", extend[i]);
807 }
808 printk(BIOS_DEBUG, "\n");
809
Julius Wernercd49cce2019-03-05 16:53:33 -0800810#if CONFIG(CHROMEOS)
Aaron Durbin76c37002012-10-30 09:03:43 -0500811 /* Save hash in NVS for the OS to verify */
812 chromeos_set_me_hash(extend, count);
813#endif
814
815 return 0;
816}
817
Aaron Durbin76c37002012-10-30 09:03:43 -0500818/* Check whether ME is present and do basic init */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100819static void intel_me_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500820{
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700821 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Aaron Durbin76c37002012-10-30 09:03:43 -0500822 me_bios_path path = intel_me_path(dev);
823 me_bios_payload mbp_data;
824
825 /* Do initial setup and determine the BIOS path */
826 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
827
Duncan Laurie8056dc62013-07-22 08:47:43 -0700828 if (path == ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500829 /* Validate the extend register */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500830 intel_me_extend_valid(dev);
831 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500832
Aaron Durbinbe985242012-12-12 12:40:33 -0600833 memset(&mbp_data, 0, sizeof(mbp_data));
834
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500835 /*
836 * According to the ME9 BWG, BIOS is required to fetch MBP data in
837 * all boot flows except S3 Resume.
838 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500839
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500840 /* Prepare MEI MMIO interface */
841 if (intel_mei_setup(dev) < 0)
842 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500843
Duncan Laurie144f7b22013-05-01 11:27:58 -0700844 if (intel_me_read_mbp(&mbp_data, dev))
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500845 return;
Aaron Durbin76c37002012-10-30 09:03:43 -0500846
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200847 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
848 me_print_fw_version(mbp_data.fw_version_name);
Duncan Laurie144f7b22013-05-01 11:27:58 -0700849
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200850 if (CONFIG(DEBUG_INTEL_ME))
851 me_print_fwcaps(mbp_data.fw_capabilities);
852
853 if (mbp_data.plat_time) {
854 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
855 mbp_data.plat_time->wake_event_mrst_time_ms);
856 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
857 mbp_data.plat_time->mrst_pltrst_time_ms);
858 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
859 mbp_data.plat_time->pltrst_cpurst_time_ms);
860 }
Duncan Laurie144f7b22013-05-01 11:27:58 -0700861 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500862
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700863 /* Set clock enables according to devicetree */
864 if (config && config->icc_clock_disable)
865 me_icc_set_clock_enables(config->icc_clock_disable);
866
Duncan Laurieaf980622013-07-18 23:02:18 -0700867 /*
868 * Leave the ME unlocked. It will be locked via SMI command later.
869 */
Aaron Durbin76c37002012-10-30 09:03:43 -0500870}
871
Aaron Durbin76c37002012-10-30 09:03:43 -0500872static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530873 .set_subsystem = pci_dev_set_subsystem,
Aaron Durbin76c37002012-10-30 09:03:43 -0500874};
875
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100876static void intel_me_enable(struct device *dev)
Duncan Laurie8056dc62013-07-22 08:47:43 -0700877{
Duncan Laurie8056dc62013-07-22 08:47:43 -0700878 /* Avoid talking to the device in S3 path */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300879 if (acpi_is_wakeup_s3()) {
Duncan Laurie8056dc62013-07-22 08:47:43 -0700880 dev->enabled = 0;
881 pch_disable_devfn(dev);
882 }
Duncan Laurie8056dc62013-07-22 08:47:43 -0700883}
884
Aaron Durbin76c37002012-10-30 09:03:43 -0500885static struct device_operations device_ops = {
886 .read_resources = pci_dev_read_resources,
887 .set_resources = pci_dev_set_resources,
888 .enable_resources = pci_dev_enable_resources,
Duncan Laurie8056dc62013-07-22 08:47:43 -0700889 .enable = intel_me_enable,
Aaron Durbin76c37002012-10-30 09:03:43 -0500890 .init = intel_me_init,
Aaron Durbin76c37002012-10-30 09:03:43 -0500891 .ops_pci = &pci_ops,
892};
893
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800894static const unsigned short pci_device_ids[] = {
895 0x8c3a, /* Mobile */
896 0x9c3a, /* Low Power */
897 0
898};
899
Aaron Durbin76c37002012-10-30 09:03:43 -0500900static const struct pci_driver intel_me __pci_driver = {
901 .ops = &device_ops,
902 .vendor = PCI_VENDOR_ID_INTEL,
Duncan Laurie26e7dd72012-12-19 09:12:31 -0800903 .devices= pci_device_ids,
Aaron Durbin76c37002012-10-30 09:03:43 -0500904};
905
906/******************************************************************************
907 * */
908static u32 me_to_host_words_pending(void)
909{
910 struct mei_csr me;
911 read_me_csr(&me);
912 if (!me.ready)
913 return 0;
914 return (me.buffer_write_ptr - me.buffer_read_ptr) &
915 (me.buffer_depth - 1);
916}
917
918#if 0
919/* This function is not yet being used, keep it in for the future. */
920static u32 host_to_me_words_room(void)
921{
922 struct mei_csr csr;
923
924 read_me_csr(&csr);
925 if (!csr.ready)
926 return 0;
927
928 read_host_csr(&csr);
929 return (csr.buffer_read_ptr - csr.buffer_write_ptr - 1) &
930 (csr.buffer_depth - 1);
931}
932#endif
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500933
Aaron Durbinbe985242012-12-12 12:40:33 -0600934struct mbp_payload {
935 mbp_header header;
936 u32 data[0];
937};
938
Aaron Durbin76c37002012-10-30 09:03:43 -0500939/*
940 * mbp seems to be following its own flow, let's retrieve it in a dedicated
941 * function.
942 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100943static int intel_me_read_mbp(me_bios_payload *mbp_data, struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500944{
945 mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500946 u32 me2host_pending;
Aaron Durbin76c37002012-10-30 09:03:43 -0500947 struct mei_csr host;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500948 struct me_hfs2 hfs2;
Aaron Durbinbe985242012-12-12 12:40:33 -0600949 struct mbp_payload *mbp;
950 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500951
952 pci_read_dword_ptr(dev, &hfs2, PCI_ME_HFS2);
953
954 if (!hfs2.mbp_rdy) {
955 printk(BIOS_ERR, "ME: MBP not ready\n");
956 goto mbp_failure;
957 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500958
959 me2host_pending = me_to_host_words_pending();
960 if (!me2host_pending) {
961 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500962 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500963 }
964
965 /* we know for sure that at least the header is there */
966 mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW);
967
968 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
969 (me2host_pending < mbp_hdr.mbp_size)) {
970 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
971 " buffer contains %d words\n",
972 mbp_hdr.num_entries, mbp_hdr.mbp_size,
973 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500974 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500975 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600976 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
977 if (!mbp)
978 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500979
Aaron Durbinbe985242012-12-12 12:40:33 -0600980 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500981 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500982
Aaron Durbinbe985242012-12-12 12:40:33 -0600983 i = 0;
984 while (i != me2host_pending) {
985 mei_read_dword_ptr(&mbp->data[i], MEI_ME_CB_RW);
986 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500987 }
988
Aaron Durbinbe985242012-12-12 12:40:33 -0600989 /* Signal to the ME that the host has finished reading the MBP. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500990 read_host_csr(&host);
991 host.interrupt_generate = 1;
992 write_host_csr(&host);
993
Julius Wernercd49cce2019-03-05 16:53:33 -0800994#if !CONFIG(ME_MBP_CLEAR_LATE)
Aaron Durbinbe985242012-12-12 12:40:33 -0600995 /* Wait for the mbp_cleared indicator. */
Duncan Laurie3d299c42013-07-19 08:48:05 -0700996 intel_me_mbp_clear(dev);
997#endif
Aaron Durbin76c37002012-10-30 09:03:43 -0500998
Aaron Durbinbe985242012-12-12 12:40:33 -0600999 /* Dump out the MBP contents. */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +02001000 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
1001 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
1002 mbp->header.num_entries, mbp->header.mbp_size);
1003 if (CONFIG(DEBUG_INTEL_ME)) {
1004 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
1005 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
1006 }
1007 }
Aaron Durbinbe985242012-12-12 12:40:33 -06001008 }
Aaron Durbinbe985242012-12-12 12:40:33 -06001009
1010 #define ASSIGN_FIELD_PTR(field_,val_) \
1011 { \
1012 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
1013 break; \
1014 }
1015 /* Setup the pointers in the me_bios_payload structure. */
1016 for (i = 0; i < mbp->header.mbp_size - 1;) {
1017 mbp_item_header *item = (void *)&mbp->data[i];
1018
Elyes HAOUASf9de5a42018-05-03 17:21:02 +02001019 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -06001020 case MBP_IDENT(KERNEL, FW_VER):
1021 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
1022
1023 case MBP_IDENT(ICC, PROFILE):
1024 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
1025
1026 case MBP_IDENT(INTEL_AT, STATE):
1027 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
1028
1029 case MBP_IDENT(KERNEL, FW_CAP):
1030 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
1031
1032 case MBP_IDENT(KERNEL, ROM_BIST):
1033 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
1034
1035 case MBP_IDENT(KERNEL, PLAT_KEY):
1036 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
1037
1038 case MBP_IDENT(KERNEL, FW_TYPE):
1039 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
1040
1041 case MBP_IDENT(KERNEL, MFS_FAILURE):
1042 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
1043
Duncan Laurie144f7b22013-05-01 11:27:58 -07001044 case MBP_IDENT(KERNEL, PLAT_TIME):
1045 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
1046
1047 case MBP_IDENT(NFC, SUPPORT_DATA):
1048 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
1049
Aaron Durbinbe985242012-12-12 12:40:33 -06001050 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -07001051 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
1052 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -06001053 break;
1054 }
1055 i += item->length;
1056 }
1057 #undef ASSIGN_FIELD_PTR
1058
Aaron Durbin76c37002012-10-30 09:03:43 -05001059 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -05001060
1061mbp_failure:
1062 intel_me_mbp_give_up(dev);
1063 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -05001064}
Duncan Laurieaf980622013-07-18 23:02:18 -07001065
1066#endif /* !__SMM__ */