blob: 40626c2362e5d35a98b8594966006833745b33ec [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
3/*
4 * This is a ramstage driver for the Intel Management Engine found in the
5 * 6-series chipset. It handles the required boot-time messages over the
6 * MMIO-based Management Engine Interface to tell the ME that the BIOS is
7 * finished with POST. Additional messages are defined for debug but are
8 * not used unless the console loglevel is high enough.
9 */
10
Furquan Shaikh76cedd22020-05-02 10:24:23 -070011#include <acpi/acpi.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020012#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020013#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050014#include <console/console.h>
Stefan Reinauer24d1d4b2013-03-21 11:51:41 -070015#include <device/device.h>
16#include <device/pci.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050017#include <device/pci_ids.h>
18#include <device/pci_def.h>
19#include <string.h>
20#include <delay.h>
21#include <elog.h>
Elyes HAOUAS400f9ca2019-06-23 07:01:22 +020022#include <stdlib.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050023
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030024#include "chip.h"
Aaron Durbin76c37002012-10-30 09:03:43 -050025#include "me.h"
26#include "pch.h"
27
Aaron Durbin76c37002012-10-30 09:03:43 -050028#include <vendorcode/google/chromeos/chromeos.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050029
Aaron Durbin76c37002012-10-30 09:03:43 -050030/* Path that the BIOS should take based on ME state */
Angel Pons10274d82021-02-23 14:19:28 +010031static const char *const me_bios_path_values[] = {
Aaron Durbin76c37002012-10-30 09:03:43 -050032 [ME_NORMAL_BIOS_PATH] = "Normal",
33 [ME_S3WAKE_BIOS_PATH] = "S3 Wake",
34 [ME_ERROR_BIOS_PATH] = "Error",
35 [ME_RECOVERY_BIOS_PATH] = "Recovery",
36 [ME_DISABLE_BIOS_PATH] = "Disable",
37 [ME_FIRMWARE_UPDATE_BIOS_PATH] = "Firmware Update",
38};
Aaron Durbin76c37002012-10-30 09:03:43 -050039
40/* MMIO base address for MEI interface */
Angel Ponsa3492d72021-02-23 14:12:25 +010041static u8 *mei_base_address;
Aaron Durbin76c37002012-10-30 09:03:43 -050042
Angel Ponsdf2049b2021-11-24 14:39:10 +010043static void mei_dump(u32 dword, int offset, const char *type)
Aaron Durbin76c37002012-10-30 09:03:43 -050044{
Angel Ponsdf2049b2021-11-24 14:39:10 +010045 union mei_csr csr;
Aaron Durbin76c37002012-10-30 09:03:43 -050046
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +020047 if (!CONFIG(DEBUG_INTEL_ME))
48 return;
49
Aaron Durbin76c37002012-10-30 09:03:43 -050050 printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset);
51
52 switch (offset) {
53 case MEI_H_CSR:
54 case MEI_ME_CSR_HA:
Angel Ponsdf2049b2021-11-24 14:39:10 +010055 csr.raw = dword;
Aaron Durbin76c37002012-10-30 09:03:43 -050056 printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
Angel Ponsdf2049b2021-11-24 14:39:10 +010057 "reset=%u ig=%u is=%u ie=%u\n", csr.buffer_depth,
58 csr.buffer_read_ptr, csr.buffer_write_ptr,
59 csr.ready, csr.reset, csr.interrupt_generate,
60 csr.interrupt_status, csr.interrupt_enable);
Aaron Durbin76c37002012-10-30 09:03:43 -050061 break;
62 case MEI_ME_CB_RW:
63 case MEI_H_CB_WW:
64 printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
65 break;
66 default:
67 printk(BIOS_SPEW, "0x%08x\n", offset);
68 break;
69 }
70}
Aaron Durbin76c37002012-10-30 09:03:43 -050071
72/*
73 * ME/MEI access helpers using memcpy to avoid aliasing.
74 */
75
Angel Pons310d3272021-11-24 14:59:42 +010076static inline union mei_csr read_host_csr(void)
Aaron Durbin76c37002012-10-30 09:03:43 -050077{
Angel Pons310d3272021-11-24 14:59:42 +010078 union mei_csr csr = { .raw = read32(mei_base_address + MEI_H_CSR) };
79 mei_dump(csr.raw, MEI_H_CSR, "READ");
80 return csr;
Aaron Durbin76c37002012-10-30 09:03:43 -050081}
82
Angel Pons310d3272021-11-24 14:59:42 +010083static inline void write_host_csr(union mei_csr csr)
Aaron Durbin76c37002012-10-30 09:03:43 -050084{
Angel Pons310d3272021-11-24 14:59:42 +010085 write32(mei_base_address + MEI_H_CSR, csr.raw);
86 mei_dump(csr.raw, MEI_H_CSR, "WRITE");
Aaron Durbin76c37002012-10-30 09:03:43 -050087}
88
Angel Pons310d3272021-11-24 14:59:42 +010089static inline union mei_csr read_me_csr(void)
Aaron Durbin76c37002012-10-30 09:03:43 -050090{
Angel Pons310d3272021-11-24 14:59:42 +010091 union mei_csr csr = { .raw = read32(mei_base_address + MEI_ME_CSR_HA) };
92 mei_dump(csr.raw, MEI_ME_CSR_HA, "READ");
93 return csr;
Aaron Durbin76c37002012-10-30 09:03:43 -050094}
95
96static inline void write_cb(u32 dword)
97{
Angel Ponsa3492d72021-02-23 14:12:25 +010098 write32(mei_base_address + MEI_H_CB_WW, dword);
Angel Ponsdf2049b2021-11-24 14:39:10 +010099 mei_dump(dword, MEI_H_CB_WW, "WRITE");
Aaron Durbin76c37002012-10-30 09:03:43 -0500100}
101
102static inline u32 read_cb(void)
103{
Angel Ponsa3492d72021-02-23 14:12:25 +0100104 u32 dword = read32(mei_base_address + MEI_ME_CB_RW);
Angel Ponsdf2049b2021-11-24 14:39:10 +0100105 mei_dump(dword, MEI_ME_CB_RW, "READ");
Aaron Durbin76c37002012-10-30 09:03:43 -0500106 return dword;
107}
108
109/* Wait for ME ready bit to be asserted */
110static int mei_wait_for_me_ready(void)
111{
Angel Ponsdf2049b2021-11-24 14:39:10 +0100112 union mei_csr me;
Martin Rothff744bf2019-10-23 21:46:03 -0600113 unsigned int try = ME_RETRY;
Aaron Durbin76c37002012-10-30 09:03:43 -0500114
115 while (try--) {
Angel Pons310d3272021-11-24 14:59:42 +0100116 me = read_me_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500117 if (me.ready)
118 return 0;
119 udelay(ME_DELAY);
120 }
121
122 printk(BIOS_ERR, "ME: failed to become ready\n");
123 return -1;
124}
125
126static void mei_reset(void)
127{
Angel Ponsdf2049b2021-11-24 14:39:10 +0100128 union mei_csr host;
Aaron Durbin76c37002012-10-30 09:03:43 -0500129
130 if (mei_wait_for_me_ready() < 0)
131 return;
132
133 /* Reset host and ME circular buffers for next message */
Angel Pons310d3272021-11-24 14:59:42 +0100134 host = read_host_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500135 host.reset = 1;
136 host.interrupt_generate = 1;
Angel Pons310d3272021-11-24 14:59:42 +0100137 write_host_csr(host);
Aaron Durbin76c37002012-10-30 09:03:43 -0500138
139 if (mei_wait_for_me_ready() < 0)
140 return;
141
142 /* Re-init and indicate host is ready */
Angel Pons310d3272021-11-24 14:59:42 +0100143 host = read_host_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500144 host.interrupt_generate = 1;
145 host.ready = 1;
146 host.reset = 0;
Angel Pons310d3272021-11-24 14:59:42 +0100147 write_host_csr(host);
Aaron Durbin76c37002012-10-30 09:03:43 -0500148}
149
Angel Ponsdf2049b2021-11-24 14:39:10 +0100150static int mei_send_packet(union mei_header *mei, void *req_data)
Aaron Durbin76c37002012-10-30 09:03:43 -0500151{
Angel Ponsdf2049b2021-11-24 14:39:10 +0100152 union mei_csr host;
Martin Rothff744bf2019-10-23 21:46:03 -0600153 unsigned int ndata, n;
Aaron Durbin76c37002012-10-30 09:03:43 -0500154 u32 *data;
155
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700156 /* Number of dwords to write */
Aaron Durbin76c37002012-10-30 09:03:43 -0500157 ndata = mei->length >> 2;
158
159 /* Pad non-dword aligned request message length */
160 if (mei->length & 3)
161 ndata++;
162 if (!ndata) {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700163 printk(BIOS_DEBUG, "ME: request has no data\n");
Aaron Durbin76c37002012-10-30 09:03:43 -0500164 return -1;
165 }
166 ndata++; /* Add MEI header */
167
168 /*
169 * Make sure there is still room left in the circular buffer.
170 * Reset the buffer pointers if the requested message will not fit.
171 */
Angel Pons310d3272021-11-24 14:59:42 +0100172 host = read_host_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500173 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
174 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
175 mei_reset();
Angel Pons310d3272021-11-24 14:59:42 +0100176 host = read_host_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500177 }
178
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700179 /* Ensure the requested length will fit in the circular buffer. */
Aaron Durbin76c37002012-10-30 09:03:43 -0500180 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
181 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
182 ndata + 2, host.buffer_depth);
183 return -1;
184 }
185
186 /* Write MEI header */
Angel Ponsdf2049b2021-11-24 14:39:10 +0100187 write_cb(mei->raw);
Aaron Durbin76c37002012-10-30 09:03:43 -0500188 ndata--;
189
Aaron Durbin76c37002012-10-30 09:03:43 -0500190 /* Write message data */
191 data = req_data;
192 for (n = 0; n < ndata; ++n)
193 write_cb(*data++);
194
195 /* Generate interrupt to the ME */
Angel Pons310d3272021-11-24 14:59:42 +0100196 host = read_host_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500197 host.interrupt_generate = 1;
Angel Pons310d3272021-11-24 14:59:42 +0100198 write_host_csr(host);
Aaron Durbin76c37002012-10-30 09:03:43 -0500199
200 /* Make sure ME is ready after sending request data */
201 return mei_wait_for_me_ready();
202}
203
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700204static int mei_send_data(u8 me_address, u8 host_address,
205 void *req_data, int req_bytes)
206{
Angel Ponsdf2049b2021-11-24 14:39:10 +0100207 union mei_header header = {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700208 .client_address = me_address,
209 .host_address = host_address,
210 };
Angel Ponsdf2049b2021-11-24 14:39:10 +0100211 union mei_csr host;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700212 int current = 0;
213 u8 *req_ptr = req_data;
214
215 while (!header.is_complete) {
216 int remain = req_bytes - current;
217 int buf_len;
218
Angel Pons310d3272021-11-24 14:59:42 +0100219 host = read_host_csr();
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700220 buf_len = host.buffer_depth - host.buffer_write_ptr;
221
222 if (buf_len > remain) {
223 /* Send all remaining data as final message */
224 header.length = req_bytes - current;
225 header.is_complete = 1;
226 } else {
227 /* Send as much data as the buffer can hold */
228 header.length = buf_len;
229 }
230
231 mei_send_packet(&header, req_ptr);
232
233 req_ptr += header.length;
234 current += header.length;
235 }
236
237 return 0;
238}
239
240static int mei_send_header(u8 me_address, u8 host_address,
241 void *header, int header_len, int complete)
242{
Angel Ponsdf2049b2021-11-24 14:39:10 +0100243 union mei_header mei = {
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700244 .client_address = me_address,
245 .host_address = host_address,
246 .length = header_len,
247 .is_complete = complete,
248 };
249 return mei_send_packet(&mei, header);
250}
251
252static int mei_recv_msg(void *header, int header_bytes,
Aaron Durbin76c37002012-10-30 09:03:43 -0500253 void *rsp_data, int rsp_bytes)
254{
Angel Ponsdf2049b2021-11-24 14:39:10 +0100255 union mei_header mei_rsp;
256 union mei_csr me, host;
Martin Rothff744bf2019-10-23 21:46:03 -0600257 unsigned int ndata, n;
258 unsigned int expected;
Aaron Durbin76c37002012-10-30 09:03:43 -0500259 u32 *data;
260
261 /* Total number of dwords to read from circular buffer */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700262 expected = (rsp_bytes + sizeof(mei_rsp) + header_bytes) >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500263 if (rsp_bytes & 3)
264 expected++;
265
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700266 if (mei_wait_for_me_ready() < 0)
267 return -1;
268
Aaron Durbin76c37002012-10-30 09:03:43 -0500269 /*
270 * The interrupt status bit does not appear to indicate that the
271 * message has actually been received. Instead we wait until the
272 * expected number of dwords are present in the circular buffer.
273 */
274 for (n = ME_RETRY; n; --n) {
Angel Pons310d3272021-11-24 14:59:42 +0100275 me = read_me_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500276 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
277 break;
278 udelay(ME_DELAY);
279 }
280 if (!n) {
281 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
282 "%u, available %u\n", expected,
283 me.buffer_write_ptr - me.buffer_read_ptr);
284 return -1;
285 }
286
287 /* Read and verify MEI response header from the ME */
Angel Ponsdf2049b2021-11-24 14:39:10 +0100288 mei_rsp.raw = read_cb();
Aaron Durbin76c37002012-10-30 09:03:43 -0500289 if (!mei_rsp.is_complete) {
290 printk(BIOS_ERR, "ME: response is not complete\n");
291 return -1;
292 }
293
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700294 /* Handle non-dword responses and expect at least the header */
Aaron Durbin76c37002012-10-30 09:03:43 -0500295 ndata = mei_rsp.length >> 2;
296 if (mei_rsp.length & 3)
297 ndata++;
298 if (ndata != (expected - 1)) {
299 printk(BIOS_ERR, "ME: response is missing data %d != %d\n",
300 ndata, (expected - 1));
301 return -1;
302 }
303
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700304 /* Read response header from the ME */
305 data = header;
306 for (n = 0; n < (header_bytes >> 2); ++n)
307 *data++ = read_cb();
308 ndata -= header_bytes >> 2;
Aaron Durbin76c37002012-10-30 09:03:43 -0500309
310 /* Make sure caller passed a buffer with enough space */
311 if (ndata != (rsp_bytes >> 2)) {
312 printk(BIOS_ERR, "ME: not enough room in response buffer: "
313 "%u != %u\n", ndata, rsp_bytes >> 2);
314 return -1;
315 }
316
317 /* Read response data from the circular buffer */
318 data = rsp_data;
319 for (n = 0; n < ndata; ++n)
320 *data++ = read_cb();
321
322 /* Tell the ME that we have consumed the response */
Angel Pons310d3272021-11-24 14:59:42 +0100323 host = read_host_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500324 host.interrupt_status = 1;
325 host.interrupt_generate = 1;
Angel Pons310d3272021-11-24 14:59:42 +0100326 write_host_csr(host);
Aaron Durbin76c37002012-10-30 09:03:43 -0500327
328 return mei_wait_for_me_ready();
329}
330
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700331static inline int mei_sendrecv_mkhi(struct mkhi_header *mkhi,
332 void *req_data, int req_bytes,
333 void *rsp_data, int rsp_bytes)
Aaron Durbin76c37002012-10-30 09:03:43 -0500334{
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700335 struct mkhi_header mkhi_rsp;
336
337 /* Send header */
338 if (mei_send_header(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
339 mkhi, sizeof(*mkhi), req_bytes ? 0 : 1) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500340 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700341
342 /* Send data if available */
343 if (req_bytes && mei_send_data(MEI_ADDRESS_MKHI, MEI_HOST_ADDRESS,
344 req_data, req_bytes) < 0)
Aaron Durbin76c37002012-10-30 09:03:43 -0500345 return -1;
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700346
347 /* Return now if no response expected */
348 if (!rsp_bytes)
349 return 0;
350
351 /* Read header and data */
352 if (mei_recv_msg(&mkhi_rsp, sizeof(mkhi_rsp),
353 rsp_data, rsp_bytes) < 0)
354 return -1;
355
356 if (!mkhi_rsp.is_response ||
357 mkhi->group_id != mkhi_rsp.group_id ||
358 mkhi->command != mkhi_rsp.command) {
359 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u,"
360 "command %u ?= %u, is_response %u\n", mkhi->group_id,
361 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
362 mkhi_rsp.is_response);
363 return -1;
364 }
365
Aaron Durbin76c37002012-10-30 09:03:43 -0500366 return 0;
367}
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700368
Angel Pons7f8da792021-02-23 14:27:39 +0100369static inline int mei_sendrecv_icc(struct icc_header *icc,
370 void *req_data, int req_bytes,
371 void *rsp_data, int rsp_bytes)
372{
373 struct icc_header icc_rsp;
374
375 /* Send header */
376 if (mei_send_header(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
377 icc, sizeof(*icc), req_bytes ? 0 : 1) < 0)
378 return -1;
379
380 /* Send data if available */
381 if (req_bytes && mei_send_data(MEI_ADDRESS_ICC, MEI_HOST_ADDRESS,
382 req_data, req_bytes) < 0)
383 return -1;
384
385 /* Read header and data, if needed */
386 if (rsp_bytes && mei_recv_msg(&icc_rsp, sizeof(icc_rsp),
387 rsp_data, rsp_bytes) < 0)
388 return -1;
389
390 return 0;
391}
392
Duncan Laurie3d299c42013-07-19 08:48:05 -0700393/*
394 * mbp give up routine. This path is taken if hfs.mpb_rdy is 0 or the read
395 * state machine on the BIOS end doesn't match the ME's state machine.
396 */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100397static void intel_me_mbp_give_up(struct device *dev)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700398{
Angel Ponsdf2049b2021-11-24 14:39:10 +0100399 union mei_csr csr;
Duncan Laurie3d299c42013-07-19 08:48:05 -0700400
401 pci_write_config32(dev, PCI_ME_H_GS2, PCI_ME_MBP_GIVE_UP);
402
Angel Pons310d3272021-11-24 14:59:42 +0100403 csr = read_host_csr();
Duncan Laurie3d299c42013-07-19 08:48:05 -0700404 csr.reset = 1;
405 csr.interrupt_generate = 1;
Angel Pons310d3272021-11-24 14:59:42 +0100406 write_host_csr(csr);
Duncan Laurie3d299c42013-07-19 08:48:05 -0700407}
408
409/*
410 * mbp clear routine. This will wait for the ME to indicate that
411 * the MBP has been read and cleared.
412 */
Angel Pons10274d82021-02-23 14:19:28 +0100413static void intel_me_mbp_clear(struct device *dev)
Duncan Laurie3d299c42013-07-19 08:48:05 -0700414{
415 int count;
Angel Pons032255c2021-11-24 14:12:38 +0100416 union me_hfs2 hfs2;
Duncan Laurie3d299c42013-07-19 08:48:05 -0700417
418 /* Wait for the mbp_cleared indicator */
419 for (count = ME_RETRY; count > 0; --count) {
Angel Pons032255c2021-11-24 14:12:38 +0100420 hfs2.raw = pci_read_config32(dev, PCI_ME_HFS2);
Duncan Laurie3d299c42013-07-19 08:48:05 -0700421 if (hfs2.mbp_cleared)
422 break;
423 udelay(ME_DELAY);
424 }
425
426 if (count == 0) {
427 printk(BIOS_WARNING, "ME: Timeout waiting for mbp_cleared\n");
428 intel_me_mbp_give_up(dev);
429 } else {
430 printk(BIOS_INFO, "ME: MBP cleared\n");
431 }
432}
433
Angel Pons01c9b982021-11-24 11:58:04 +0100434static void me_print_fw_version(struct mbp_fw_version_name *vers_name)
Aaron Durbin76c37002012-10-30 09:03:43 -0500435{
Aaron Durbinbe985242012-12-12 12:40:33 -0600436 if (!vers_name) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500437 printk(BIOS_ERR, "ME: mbp missing version report\n");
438 return;
439 }
440
441 printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n",
442 vers_name->major_version, vers_name->minor_version,
443 vers_name->hotfix_version, vers_name->build_version);
444}
445
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000446static inline void print_cap(const char *name, int state)
447{
448 printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n",
449 name, state ? " en" : "dis");
450}
451
Aaron Durbin76c37002012-10-30 09:03:43 -0500452/* Get ME Firmware Capabilities */
Angel Pons01c9b982021-11-24 11:58:04 +0100453static int mkhi_get_fwcaps(struct mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500454{
455 u32 rule_id = 0;
456 struct me_fwcaps cap_msg;
457 struct mkhi_header mkhi = {
458 .group_id = MKHI_GROUP_ID_FWCAPS,
459 .command = MKHI_FWCAPS_GET_RULE,
460 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500461
462 /* Send request and wait for response */
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700463 if (mei_sendrecv_mkhi(&mkhi, &rule_id, sizeof(u32),
464 &cap_msg, sizeof(cap_msg)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500465 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
466 return -1;
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200467 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500468 *cap = cap_msg.caps_sku;
469 return 0;
470}
471
472/* Get ME Firmware Capabilities */
Angel Pons01c9b982021-11-24 11:58:04 +0100473static void me_print_fwcaps(struct mbp_mefwcaps *cap)
Aaron Durbin76c37002012-10-30 09:03:43 -0500474{
Angel Pons01c9b982021-11-24 11:58:04 +0100475 struct mbp_mefwcaps local_caps;
Aaron Durbinbe985242012-12-12 12:40:33 -0600476 if (!cap) {
477 cap = &local_caps;
Aaron Durbin76c37002012-10-30 09:03:43 -0500478 printk(BIOS_ERR, "ME: mbp missing fwcaps report\n");
479 if (mkhi_get_fwcaps(cap))
480 return;
481 }
482
483 print_cap("Full Network manageability", cap->full_net);
484 print_cap("Regular Network manageability", cap->std_net);
485 print_cap("Manageability", cap->manageability);
Aaron Durbin76c37002012-10-30 09:03:43 -0500486 print_cap("IntelR Anti-Theft (AT)", cap->intel_at);
487 print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls);
488 print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc);
489 print_cap("ICC Over Clocking", cap->icc_over_clocking);
Edward O'Callaghan7bf4f482014-06-17 15:12:09 +1000490 print_cap("Protected Audio Video Path (PAVP)", cap->pavp);
Aaron Durbin76c37002012-10-30 09:03:43 -0500491 print_cap("IPV6", cap->ipv6);
492 print_cap("KVM Remote Control (KVM)", cap->kvm);
493 print_cap("Outbreak Containment Heuristic (OCH)", cap->och);
494 print_cap("Virtual LAN (VLAN)", cap->vlan);
495 print_cap("TLS", cap->tls);
496 print_cap("Wireless LAN (WLAN)", cap->wlan);
497}
Aaron Durbin76c37002012-10-30 09:03:43 -0500498
Aaron Durbin76c37002012-10-30 09:03:43 -0500499/* Send END OF POST message to the ME */
Angel Pons10274d82021-02-23 14:19:28 +0100500static int mkhi_end_of_post(void)
Aaron Durbin76c37002012-10-30 09:03:43 -0500501{
502 struct mkhi_header mkhi = {
503 .group_id = MKHI_GROUP_ID_GEN,
504 .command = MKHI_END_OF_POST,
505 };
Aaron Durbin76c37002012-10-30 09:03:43 -0500506 u32 eop_ack;
507
508 /* Send request and wait for response */
Angel Pons08e8cab2020-06-18 15:20:37 +0200509 printk(BIOS_NOTICE, "ME: %s\n", __func__);
Duncan Laurie2017b4a2013-08-08 15:07:12 -0700510 if (mei_sendrecv_mkhi(&mkhi, NULL, 0, &eop_ack, sizeof(eop_ack)) < 0) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500511 printk(BIOS_ERR, "ME: END OF POST message failed\n");
512 return -1;
513 }
514
515 printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack);
516 return 0;
517}
518
Angel Pons10274d82021-02-23 14:19:28 +0100519void intel_me_finalize(struct device *dev)
Duncan Laurieaf980622013-07-18 23:02:18 -0700520{
Angel Pons032255c2021-11-24 14:12:38 +0100521 union me_hfs hfs;
Duncan Laurieaf980622013-07-18 23:02:18 -0700522 u32 reg32;
523
Angel Pons10274d82021-02-23 14:19:28 +0100524 reg32 = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
Angel Ponsa3492d72021-02-23 14:12:25 +0100525 mei_base_address = (u8 *)(uintptr_t)(reg32 & ~PCI_BASE_ADDRESS_MEM_ATTR_MASK);
Duncan Laurieaf980622013-07-18 23:02:18 -0700526
527 /* S3 path will have hidden this device already */
Angel Ponsa3492d72021-02-23 14:12:25 +0100528 if (!mei_base_address || mei_base_address == (u8 *)0xfffffff0)
Duncan Laurieaf980622013-07-18 23:02:18 -0700529 return;
530
Duncan Laurie3d299c42013-07-19 08:48:05 -0700531 /* Wait for ME MBP Cleared indicator */
Angel Pons10274d82021-02-23 14:19:28 +0100532 intel_me_mbp_clear(dev);
Duncan Laurie3d299c42013-07-19 08:48:05 -0700533
Duncan Laurieaf980622013-07-18 23:02:18 -0700534 /* Make sure ME is in a mode that expects EOP */
Angel Pons032255c2021-11-24 14:12:38 +0100535 hfs.raw = pci_read_config32(dev, PCI_ME_HFS);
Duncan Laurieaf980622013-07-18 23:02:18 -0700536
537 /* Abort and leave device alone if not normal mode */
538 if (hfs.fpt_bad ||
539 hfs.working_state != ME_HFS_CWS_NORMAL ||
540 hfs.operation_mode != ME_HFS_MODE_NORMAL)
541 return;
542
543 /* Try to send EOP command so ME stops accepting other commands */
544 mkhi_end_of_post();
545
546 /* Make sure IO is disabled */
Angel Pons10274d82021-02-23 14:19:28 +0100547 pci_and_config16(dev, PCI_COMMAND,
Angel Ponsbf9bc502020-06-08 00:12:43 +0200548 ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
Duncan Laurieaf980622013-07-18 23:02:18 -0700549
550 /* Hide the PCI device */
551 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
552}
553
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700554static int me_icc_set_clock_enables(u32 mask)
555{
556 struct icc_clock_enables_msg clk = {
557 .clock_enables = 0, /* Turn off specified clocks */
558 .clock_mask = mask,
559 .no_response = 1, /* Do not expect response */
560 };
561 struct icc_header icc = {
562 .api_version = ICC_API_VERSION_LYNXPOINT,
563 .icc_command = ICC_SET_CLOCK_ENABLES,
564 .length = sizeof(clk),
565 };
566
567 /* Send request and wait for response */
568 if (mei_sendrecv_icc(&icc, &clk, sizeof(clk), NULL, 0) < 0) {
569 printk(BIOS_ERR, "ME: ICC SET CLOCK ENABLES message failed\n");
570 return -1;
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700571 }
Elyes HAOUAS54f94242018-10-25 10:57:39 +0200572 printk(BIOS_INFO, "ME: ICC SET CLOCK ENABLES 0x%08x\n", mask);
Duncan Laurie0dc0d132013-08-08 15:31:51 -0700573 return 0;
574}
575
Aaron Durbin76c37002012-10-30 09:03:43 -0500576/* Determine the path that we should take based on ME status */
Angel Pons9f043742021-11-24 12:46:12 +0100577static enum me_bios_path intel_me_path(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500578{
Angel Pons9f043742021-11-24 12:46:12 +0100579 enum me_bios_path path = ME_DISABLE_BIOS_PATH;
Angel Pons032255c2021-11-24 14:12:38 +0100580 union me_hfs hfs = { .raw = pci_read_config32(dev, PCI_ME_HFS) };
581 union me_hfs2 hfs2 = { .raw = pci_read_config32(dev, PCI_ME_HFS2) };
Aaron Durbin76c37002012-10-30 09:03:43 -0500582
583 /* Check and dump status */
Angel Pons55405a32021-11-24 15:04:05 +0100584 intel_me_status(hfs, hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -0500585
586 /* Check Current Working State */
587 switch (hfs.working_state) {
588 case ME_HFS_CWS_NORMAL:
589 path = ME_NORMAL_BIOS_PATH;
590 break;
591 case ME_HFS_CWS_REC:
592 path = ME_RECOVERY_BIOS_PATH;
593 break;
594 default:
595 path = ME_DISABLE_BIOS_PATH;
596 break;
597 }
598
599 /* Check Current Operation Mode */
600 switch (hfs.operation_mode) {
601 case ME_HFS_MODE_NORMAL:
602 break;
603 case ME_HFS_MODE_DEBUG:
604 case ME_HFS_MODE_DIS:
605 case ME_HFS_MODE_OVER_JMPR:
606 case ME_HFS_MODE_OVER_MEI:
607 default:
608 path = ME_DISABLE_BIOS_PATH;
609 break;
610 }
611
612 /* Check for any error code and valid firmware and MBP */
613 if (hfs.error_code || hfs.fpt_bad)
614 path = ME_ERROR_BIOS_PATH;
615
616 /* Check if the MBP is ready */
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500617 if (!hfs2.mbp_rdy) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500618 printk(BIOS_CRIT, "%s: mbp is not ready!\n",
Angel Pons08e8cab2020-06-18 15:20:37 +0200619 __func__);
Aaron Durbin76c37002012-10-30 09:03:43 -0500620 path = ME_ERROR_BIOS_PATH;
621 }
622
Kyösti Mälkkibe5317f2019-11-06 12:07:21 +0200623 if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500624 struct elog_event_data_me_extended data = {
625 .current_working_state = hfs.working_state,
626 .operation_state = hfs.operation_state,
627 .operation_mode = hfs.operation_mode,
628 .error_code = hfs.error_code,
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500629 .progress_code = hfs2.progress_code,
630 .current_pmevent = hfs2.current_pmevent,
631 .current_state = hfs2.current_state,
Aaron Durbin76c37002012-10-30 09:03:43 -0500632 };
633 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
634 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
635 &data, sizeof(data));
636 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500637
638 return path;
639}
640
641/* Prepare ME for MEI messages */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100642static int intel_mei_setup(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500643{
644 struct resource *res;
Angel Ponsdf2049b2021-11-24 14:39:10 +0100645 union mei_csr host;
Aaron Durbin76c37002012-10-30 09:03:43 -0500646
647 /* Find the MMIO base for the ME interface */
Angel Ponsf32ae102021-11-03 13:07:14 +0100648 res = probe_resource(dev, PCI_BASE_ADDRESS_0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500649 if (!res || res->base == 0 || res->size == 0) {
650 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
651 return -1;
652 }
Angel Ponsd32b5142021-02-23 14:23:49 +0100653 mei_base_address = res2mmio(res, 0, 0);
Aaron Durbin76c37002012-10-30 09:03:43 -0500654
655 /* Ensure Memory and Bus Master bits are set */
Angel Ponsd5d4fbc2020-05-31 01:03:59 +0200656 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Aaron Durbin76c37002012-10-30 09:03:43 -0500657
658 /* Clean up status for next message */
Angel Pons310d3272021-11-24 14:59:42 +0100659 host = read_host_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500660 host.interrupt_generate = 1;
661 host.ready = 1;
662 host.reset = 0;
Angel Pons310d3272021-11-24 14:59:42 +0100663 write_host_csr(host);
Aaron Durbin76c37002012-10-30 09:03:43 -0500664
665 return 0;
666}
667
668/* Read the Extend register hash of ME firmware */
Elyes HAOUAS1dcd8db2018-12-05 10:59:42 +0100669static int intel_me_extend_valid(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500670{
Angel Pons032255c2021-11-24 14:12:38 +0100671 union me_heres status = { .raw = pci_read_config32(dev, PCI_ME_HERES) };
Aaron Durbin76c37002012-10-30 09:03:43 -0500672 u32 extend[8] = {0};
673 int i, count = 0;
674
Aaron Durbin76c37002012-10-30 09:03:43 -0500675 if (!status.extend_feature_present) {
676 printk(BIOS_ERR, "ME: Extend Feature not present\n");
677 return -1;
678 }
679
680 if (!status.extend_reg_valid) {
681 printk(BIOS_ERR, "ME: Extend Register not valid\n");
682 return -1;
683 }
684
685 switch (status.extend_reg_algorithm) {
686 case PCI_ME_EXT_SHA1:
687 count = 5;
688 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
689 break;
690 case PCI_ME_EXT_SHA256:
691 count = 8;
692 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
693 break;
694 default:
695 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
696 status.extend_reg_algorithm);
697 return -1;
698 }
699
700 for (i = 0; i < count; ++i) {
701 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
702 printk(BIOS_DEBUG, "%08x", extend[i]);
703 }
704 printk(BIOS_DEBUG, "\n");
705
Aaron Durbin76c37002012-10-30 09:03:43 -0500706 /* Save hash in NVS for the OS to verify */
Kyösti Mälkki84d10cc2021-02-10 17:53:34 +0200707 if (CONFIG(CHROMEOS_NVS))
Kyösti Mälkki26e0f4c2020-12-19 19:10:45 +0200708 chromeos_set_me_hash(extend, count);
Aaron Durbin76c37002012-10-30 09:03:43 -0500709
710 return 0;
711}
712
Aaron Durbin76c37002012-10-30 09:03:43 -0500713static u32 me_to_host_words_pending(void)
714{
Angel Pons310d3272021-11-24 14:59:42 +0100715 union mei_csr me = read_me_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500716 if (!me.ready)
717 return 0;
718 return (me.buffer_write_ptr - me.buffer_read_ptr) &
719 (me.buffer_depth - 1);
720}
721
Aaron Durbinbe985242012-12-12 12:40:33 -0600722struct mbp_payload {
Angel Ponsdf2049b2021-11-24 14:39:10 +0100723 union mbp_header header;
Aaron Durbinbe985242012-12-12 12:40:33 -0600724 u32 data[0];
725};
726
Aaron Durbin76c37002012-10-30 09:03:43 -0500727/*
Angel Pons7f8da792021-02-23 14:27:39 +0100728 * Read and print ME MBP data
729 *
730 * Return -1 to indicate a problem (give up)
731 * Return 0 to indicate success (send LOCK+EOP)
Aaron Durbin76c37002012-10-30 09:03:43 -0500732 */
Angel Pons01c9b982021-11-24 11:58:04 +0100733static int intel_me_read_mbp(struct me_bios_payload *mbp_data, struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500734{
Angel Ponsdf2049b2021-11-24 14:39:10 +0100735 union mbp_header mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500736 u32 me2host_pending;
Angel Ponsdf2049b2021-11-24 14:39:10 +0100737 union mei_csr host;
Angel Pons032255c2021-11-24 14:12:38 +0100738 union me_hfs2 hfs2 = { .raw = pci_read_config32(dev, PCI_ME_HFS2) };
Aaron Durbinbe985242012-12-12 12:40:33 -0600739 struct mbp_payload *mbp;
740 int i;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500741
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500742 if (!hfs2.mbp_rdy) {
743 printk(BIOS_ERR, "ME: MBP not ready\n");
744 goto mbp_failure;
745 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500746
747 me2host_pending = me_to_host_words_pending();
748 if (!me2host_pending) {
749 printk(BIOS_ERR, "ME: no mbp data!\n");
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500750 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500751 }
752
753 /* we know for sure that at least the header is there */
Angel Ponsdf2049b2021-11-24 14:39:10 +0100754 mbp_hdr.raw = read_cb();
Aaron Durbin76c37002012-10-30 09:03:43 -0500755
756 if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) ||
757 (me2host_pending < mbp_hdr.mbp_size)) {
758 printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words"
759 " buffer contains %d words\n",
760 mbp_hdr.num_entries, mbp_hdr.mbp_size,
761 me2host_pending);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500762 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500763 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600764 mbp = malloc(mbp_hdr.mbp_size * sizeof(u32));
765 if (!mbp)
766 goto mbp_failure;
Aaron Durbin76c37002012-10-30 09:03:43 -0500767
Aaron Durbinbe985242012-12-12 12:40:33 -0600768 mbp->header = mbp_hdr;
Aaron Durbin76c37002012-10-30 09:03:43 -0500769 me2host_pending--;
Aaron Durbin76c37002012-10-30 09:03:43 -0500770
Aaron Durbinbe985242012-12-12 12:40:33 -0600771 i = 0;
772 while (i != me2host_pending) {
Angel Ponsdf2049b2021-11-24 14:39:10 +0100773 mbp->data[i] = read_cb();
Aaron Durbinbe985242012-12-12 12:40:33 -0600774 i++;
Aaron Durbin76c37002012-10-30 09:03:43 -0500775 }
776
Aaron Durbinbe985242012-12-12 12:40:33 -0600777 /* Signal to the ME that the host has finished reading the MBP. */
Angel Pons310d3272021-11-24 14:59:42 +0100778 host = read_host_csr();
Aaron Durbin76c37002012-10-30 09:03:43 -0500779 host.interrupt_generate = 1;
Angel Pons310d3272021-11-24 14:59:42 +0100780 write_host_csr(host);
Aaron Durbin76c37002012-10-30 09:03:43 -0500781
Aaron Durbinbe985242012-12-12 12:40:33 -0600782 /* Dump out the MBP contents. */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200783 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
784 printk(BIOS_INFO, "ME MBP: Header: items: %d, size dw: %d\n",
785 mbp->header.num_entries, mbp->header.mbp_size);
786 if (CONFIG(DEBUG_INTEL_ME)) {
787 for (i = 0; i < mbp->header.mbp_size - 1; i++) {
788 printk(BIOS_INFO, "ME MBP: %04x: 0x%08x\n", i, mbp->data[i]);
789 }
790 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600791 }
Aaron Durbinbe985242012-12-12 12:40:33 -0600792
793 #define ASSIGN_FIELD_PTR(field_,val_) \
794 { \
795 mbp_data->field_ = (typeof(mbp_data->field_))(void *)val_; \
796 break; \
797 }
798 /* Setup the pointers in the me_bios_payload structure. */
799 for (i = 0; i < mbp->header.mbp_size - 1;) {
Angel Pons01c9b982021-11-24 11:58:04 +0100800 struct mbp_item_header *item = (void *)&mbp->data[i];
Aaron Durbinbe985242012-12-12 12:40:33 -0600801
Elyes HAOUASf9de5a42018-05-03 17:21:02 +0200802 switch (MBP_MAKE_IDENT(item->app_id, item->item_id)) {
Aaron Durbinbe985242012-12-12 12:40:33 -0600803 case MBP_IDENT(KERNEL, FW_VER):
804 ASSIGN_FIELD_PTR(fw_version_name, &mbp->data[i+1]);
805
806 case MBP_IDENT(ICC, PROFILE):
807 ASSIGN_FIELD_PTR(icc_profile, &mbp->data[i+1]);
808
809 case MBP_IDENT(INTEL_AT, STATE):
810 ASSIGN_FIELD_PTR(at_state, &mbp->data[i+1]);
811
812 case MBP_IDENT(KERNEL, FW_CAP):
813 ASSIGN_FIELD_PTR(fw_capabilities, &mbp->data[i+1]);
814
815 case MBP_IDENT(KERNEL, ROM_BIST):
816 ASSIGN_FIELD_PTR(rom_bist_data, &mbp->data[i+1]);
817
818 case MBP_IDENT(KERNEL, PLAT_KEY):
819 ASSIGN_FIELD_PTR(platform_key, &mbp->data[i+1]);
820
821 case MBP_IDENT(KERNEL, FW_TYPE):
822 ASSIGN_FIELD_PTR(fw_plat_type, &mbp->data[i+1]);
823
824 case MBP_IDENT(KERNEL, MFS_FAILURE):
825 ASSIGN_FIELD_PTR(mfsintegrity, &mbp->data[i+1]);
826
Duncan Laurie144f7b22013-05-01 11:27:58 -0700827 case MBP_IDENT(KERNEL, PLAT_TIME):
828 ASSIGN_FIELD_PTR(plat_time, &mbp->data[i+1]);
829
830 case MBP_IDENT(NFC, SUPPORT_DATA):
831 ASSIGN_FIELD_PTR(nfc_data, &mbp->data[i+1]);
832
Aaron Durbinbe985242012-12-12 12:40:33 -0600833 default:
Duncan Laurie0b3cd362013-08-08 15:40:01 -0700834 printk(BIOS_ERR, "ME MBP: unknown item 0x%x @ "
835 "dw offset 0x%x\n", mbp->data[i], i);
Aaron Durbinbe985242012-12-12 12:40:33 -0600836 break;
837 }
838 i += item->length;
839 }
840 #undef ASSIGN_FIELD_PTR
841
Aaron Durbin76c37002012-10-30 09:03:43 -0500842 return 0;
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500843
844mbp_failure:
845 intel_me_mbp_give_up(dev);
846 return -1;
Aaron Durbin76c37002012-10-30 09:03:43 -0500847}
Angel Pons7f8da792021-02-23 14:27:39 +0100848
849/* Check whether ME is present and do basic init */
850static void intel_me_init(struct device *dev)
851{
852 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
Angel Pons9f043742021-11-24 12:46:12 +0100853 enum me_bios_path path = intel_me_path(dev);
Angel Pons01c9b982021-11-24 11:58:04 +0100854 struct me_bios_payload mbp_data;
Angel Pons7f8da792021-02-23 14:27:39 +0100855
856 /* Do initial setup and determine the BIOS path */
857 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
858
859 if (path == ME_NORMAL_BIOS_PATH) {
860 /* Validate the extend register */
861 intel_me_extend_valid(dev);
862 }
863
864 memset(&mbp_data, 0, sizeof(mbp_data));
865
866 /*
867 * According to the ME9 BWG, BIOS is required to fetch MBP data in
868 * all boot flows except S3 Resume.
869 */
870
871 /* Prepare MEI MMIO interface */
872 if (intel_mei_setup(dev) < 0)
873 return;
874
875 if (intel_me_read_mbp(&mbp_data, dev))
876 return;
877
878 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
879 me_print_fw_version(mbp_data.fw_version_name);
880
881 if (CONFIG(DEBUG_INTEL_ME))
882 me_print_fwcaps(mbp_data.fw_capabilities);
883
884 if (mbp_data.plat_time) {
885 printk(BIOS_DEBUG, "ME: Wake Event to ME Reset: %u ms\n",
886 mbp_data.plat_time->wake_event_mrst_time_ms);
887 printk(BIOS_DEBUG, "ME: ME Reset to Platform Reset: %u ms\n",
888 mbp_data.plat_time->mrst_pltrst_time_ms);
889 printk(BIOS_DEBUG, "ME: Platform Reset to CPU Reset: %u ms\n",
890 mbp_data.plat_time->pltrst_cpurst_time_ms);
891 }
892 }
893
894 /* Set clock enables according to devicetree */
895 if (config && config->icc_clock_disable)
896 me_icc_set_clock_enables(config->icc_clock_disable);
897
898 /*
899 * Leave the ME unlocked. It will be locked later.
900 */
901}
902
903static void intel_me_enable(struct device *dev)
904{
905 /* Avoid talking to the device in S3 path */
906 if (acpi_is_wakeup_s3()) {
907 dev->enabled = 0;
908 pch_disable_devfn(dev);
909 }
910}
911
912static struct device_operations device_ops = {
913 .read_resources = pci_dev_read_resources,
914 .set_resources = pci_dev_set_resources,
915 .enable_resources = pci_dev_enable_resources,
916 .enable = intel_me_enable,
917 .init = intel_me_init,
918 .final = intel_me_finalize,
919 .ops_pci = &pci_dev_ops_pci,
920};
921
922static const unsigned short pci_device_ids[] = {
Felix Singer43b7f412022-03-07 04:34:52 +0100923 PCI_DID_INTEL_LPT_H_MEI,
924 PCI_DID_INTEL_LPT_LP_MEI,
Angel Pons7f8da792021-02-23 14:27:39 +0100925 0
926};
927
928static const struct pci_driver intel_me __pci_driver = {
929 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100930 .vendor = PCI_VID_INTEL,
Angel Pons7f8da792021-02-23 14:27:39 +0100931 .devices = pci_device_ids,
932};