blob: bff8d24510bb5f18f58e7e884091ff5d3859d6d3 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +01002
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>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010012#include <console/console.h>
Kyösti Mälkki21d6a272019-11-05 18:50:38 +020013#include <device/device.h>
14#include <device/mmio.h>
15#include <device/pci.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010016#include <device/pci_def.h>
Kyösti Mälkki21d6a272019-11-05 18:50:38 +020017#include <device/pci_ids.h>
18#include <device/pci_ops.h>
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010019#include <string.h>
20#include <delay.h>
21#include <elog.h>
22
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010023#include "me.h"
24#include "pch.h"
25
Julius Wernercd49cce2019-03-05 16:53:33 -080026#if CONFIG(CHROMEOS)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010027#include <vendorcode/google/chromeos/gnvs.h>
28#endif
29
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010030/* Path that the BIOS should take based on ME state */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +020031static const char *me_bios_path_values[] __unused = {
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010032 [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};
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010039
40/* MMIO base address for MEI interface */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080041static u32 *mei_base_address;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010042
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010043static void mei_dump(void *ptr, int dword, int offset, const char *type)
44{
45 struct mei_csr *csr;
46
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +020047 if (!CONFIG(DEBUG_INTEL_ME))
48 return;
49
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010050 printk(BIOS_SPEW, "%-9s[%02x] : ", type, offset);
51
52 switch (offset) {
53 case MEI_H_CSR:
54 case MEI_ME_CSR_HA:
55 csr = ptr;
56 if (!csr) {
57 printk(BIOS_SPEW, "ERROR: 0x%08x\n", dword);
58 break;
59 }
60 printk(BIOS_SPEW, "cbd=%u cbrp=%02u cbwp=%02u ready=%u "
61 "reset=%u ig=%u is=%u ie=%u\n", csr->buffer_depth,
62 csr->buffer_read_ptr, csr->buffer_write_ptr,
63 csr->ready, csr->reset, csr->interrupt_generate,
64 csr->interrupt_status, csr->interrupt_enable);
65 break;
66 case MEI_ME_CB_RW:
67 case MEI_H_CB_WW:
68 printk(BIOS_SPEW, "CB: 0x%08x\n", dword);
69 break;
70 default:
71 printk(BIOS_SPEW, "0x%08x\n", offset);
72 break;
73 }
74}
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010075
76/*
77 * ME/MEI access helpers using memcpy to avoid aliasing.
78 */
79
80static inline void mei_read_dword_ptr(void *ptr, int offset)
81{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080082 u32 dword = read32(mei_base_address + (offset/sizeof(u32)));
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010083 memcpy(ptr, &dword, sizeof(dword));
84 mei_dump(ptr, dword, offset, "READ");
85}
86
87static inline void mei_write_dword_ptr(void *ptr, int offset)
88{
89 u32 dword = 0;
90 memcpy(&dword, ptr, sizeof(dword));
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080091 write32(mei_base_address + (offset/sizeof(u32)), dword);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010092 mei_dump(ptr, dword, offset, "WRITE");
93}
94
Kyösti Mälkki21d6a272019-11-05 18:50:38 +020095#ifndef __SIMPLE_DEVICE__
Elyes HAOUASbe841402018-05-13 13:40:39 +020096static inline void pci_read_dword_ptr(struct device *dev,void *ptr,
97 int offset)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +010098{
99 u32 dword = pci_read_config32(dev, offset);
100 memcpy(ptr, &dword, sizeof(dword));
101 mei_dump(ptr, dword, offset, "PCI READ");
102}
103#endif
104
105static inline void read_host_csr(struct mei_csr *csr)
106{
107 mei_read_dword_ptr(csr, MEI_H_CSR);
108}
109
110static inline void write_host_csr(struct mei_csr *csr)
111{
112 mei_write_dword_ptr(csr, MEI_H_CSR);
113}
114
115static inline void read_me_csr(struct mei_csr *csr)
116{
117 mei_read_dword_ptr(csr, MEI_ME_CSR_HA);
118}
119
120static inline void write_cb(u32 dword)
121{
Angel Pons77f340a2020-10-17 18:39:04 +0200122 write32(mei_base_address + (MEI_H_CB_WW / sizeof(u32)), dword);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100123 mei_dump(NULL, dword, MEI_H_CB_WW, "WRITE");
124}
125
126static inline u32 read_cb(void)
127{
Angel Pons77f340a2020-10-17 18:39:04 +0200128 u32 dword = read32(mei_base_address + (MEI_ME_CB_RW / sizeof(u32)));
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100129 mei_dump(NULL, dword, MEI_ME_CB_RW, "READ");
130 return dword;
131}
132
133/* Wait for ME ready bit to be asserted */
134static int mei_wait_for_me_ready(void)
135{
136 struct mei_csr me;
Martin Rothff744bf2019-10-23 21:46:03 -0600137 unsigned int try = ME_RETRY;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100138
139 while (try--) {
140 read_me_csr(&me);
141 if (me.ready)
142 return 0;
143 udelay(ME_DELAY);
144 }
145
146 printk(BIOS_ERR, "ME: failed to become ready\n");
147 return -1;
148}
149
150static void mei_reset(void)
151{
152 struct mei_csr host;
153
154 if (mei_wait_for_me_ready() < 0)
155 return;
156
157 /* Reset host and ME circular buffers for next message */
158 read_host_csr(&host);
159 host.reset = 1;
160 host.interrupt_generate = 1;
161 write_host_csr(&host);
162
163 if (mei_wait_for_me_ready() < 0)
164 return;
165
166 /* Re-init and indicate host is ready */
167 read_host_csr(&host);
168 host.interrupt_generate = 1;
169 host.ready = 1;
170 host.reset = 0;
171 write_host_csr(&host);
172}
173
174static int mei_send_msg(struct mei_header *mei, struct mkhi_header *mkhi,
175 void *req_data)
176{
177 struct mei_csr host;
Martin Rothff744bf2019-10-23 21:46:03 -0600178 unsigned int ndata, n;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100179 u32 *data;
180
181 /* Number of dwords to write, ignoring MKHI */
182 ndata = mei->length >> 2;
183
184 /* Pad non-dword aligned request message length */
185 if (mei->length & 3)
186 ndata++;
187 if (!ndata) {
188 printk(BIOS_DEBUG, "ME: request does not include MKHI\n");
189 return -1;
190 }
191 ndata++; /* Add MEI header */
192
193 /*
194 * Make sure there is still room left in the circular buffer.
195 * Reset the buffer pointers if the requested message will not fit.
196 */
197 read_host_csr(&host);
198 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
199 printk(BIOS_ERR, "ME: circular buffer full, resetting...\n");
200 mei_reset();
201 read_host_csr(&host);
202 }
203
204 /*
205 * This implementation does not handle splitting large messages
206 * across multiple transactions. Ensure the requested length
207 * will fit in the available circular buffer depth.
208 */
209 if ((host.buffer_depth - host.buffer_write_ptr) < ndata) {
210 printk(BIOS_ERR, "ME: message (%u) too large for buffer (%u)\n",
211 ndata + 2, host.buffer_depth);
212 return -1;
213 }
214
215 /* Write MEI header */
216 mei_write_dword_ptr(mei, MEI_H_CB_WW);
217 ndata--;
218
219 /* Write MKHI header */
220 mei_write_dword_ptr(mkhi, MEI_H_CB_WW);
221 ndata--;
222
223 /* Write message data */
224 data = req_data;
225 for (n = 0; n < ndata; ++n)
226 write_cb(*data++);
227
228 /* Generate interrupt to the ME */
229 read_host_csr(&host);
230 host.interrupt_generate = 1;
231 write_host_csr(&host);
232
233 /* Make sure ME is ready after sending request data */
234 return mei_wait_for_me_ready();
235}
236
237static int mei_recv_msg(struct mei_header *mei, struct mkhi_header *mkhi,
238 void *rsp_data, int rsp_bytes)
239{
240 struct mei_header mei_rsp;
241 struct mkhi_header mkhi_rsp;
242 struct mei_csr me, host;
Martin Rothff744bf2019-10-23 21:46:03 -0600243 unsigned int ndata, n;
244 unsigned int expected;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100245 u32 *data;
246
247 /* Total number of dwords to read from circular buffer */
248 expected = (rsp_bytes + sizeof(mei_rsp) + sizeof(mkhi_rsp)) >> 2;
249 if (rsp_bytes & 3)
250 expected++;
251
252 /*
253 * The interrupt status bit does not appear to indicate that the
254 * message has actually been received. Instead we wait until the
255 * expected number of dwords are present in the circular buffer.
256 */
257 for (n = ME_RETRY; n; --n) {
258 read_me_csr(&me);
259 if ((me.buffer_write_ptr - me.buffer_read_ptr) >= expected)
260 break;
261 udelay(ME_DELAY);
262 }
263 if (!n) {
Angel Pons77f340a2020-10-17 18:39:04 +0200264 printk(BIOS_ERR, "ME: timeout waiting for data: expected %u, available %u\n",
265 expected, me.buffer_write_ptr - me.buffer_read_ptr);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100266 return -1;
267 }
268
269 /* Read and verify MEI response header from the ME */
270 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
271 if (!mei_rsp.is_complete) {
272 printk(BIOS_ERR, "ME: response is not complete\n");
273 return -1;
274 }
275
276 /* Handle non-dword responses and expect at least MKHI header */
277 ndata = mei_rsp.length >> 2;
278 if (mei_rsp.length & 3)
279 ndata++;
280 if (ndata != (expected - 1)) {
281 printk(BIOS_ERR, "ME: response is missing data\n");
282 return -1;
283 }
284
285 /* Read and verify MKHI response header from the ME */
286 mei_read_dword_ptr(&mkhi_rsp, MEI_ME_CB_RW);
287 if (!mkhi_rsp.is_response ||
288 mkhi->group_id != mkhi_rsp.group_id ||
289 mkhi->command != mkhi_rsp.command) {
290 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u, "
291 "command %u ?= %u, is_response %u\n", mkhi->group_id,
292 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
293 mkhi_rsp.is_response);
294 return -1;
295 }
296 ndata--; /* MKHI header has been read */
297
298 /* Make sure caller passed a buffer with enough space */
299 if (ndata != (rsp_bytes >> 2)) {
Angel Pons77f340a2020-10-17 18:39:04 +0200300 printk(BIOS_ERR, "ME: not enough room in response buffer: %u != %u\n",
301 ndata, rsp_bytes >> 2);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100302 return -1;
303 }
304
305 /* Read response data from the circular buffer */
306 data = rsp_data;
307 for (n = 0; n < ndata; ++n)
308 *data++ = read_cb();
309
310 /* Tell the ME that we have consumed the response */
311 read_host_csr(&host);
312 host.interrupt_status = 1;
313 host.interrupt_generate = 1;
314 write_host_csr(&host);
315
316 return mei_wait_for_me_ready();
317}
318
319static inline int mei_sendrecv(struct mei_header *mei, struct mkhi_header *mkhi,
320 void *req_data, void *rsp_data, int rsp_bytes)
321{
322 if (mei_send_msg(mei, mkhi, req_data) < 0)
323 return -1;
324 if (mei_recv_msg(mei, mkhi, rsp_data, rsp_bytes) < 0)
325 return -1;
326 return 0;
327}
328
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100329/* Send END OF POST message to the ME */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200330static int __unused mkhi_end_of_post(void)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100331{
332 struct mkhi_header mkhi = {
333 .group_id = MKHI_GROUP_ID_GEN,
334 .command = MKHI_END_OF_POST,
335 };
336 struct mei_header mei = {
337 .is_complete = 1,
338 .host_address = MEI_HOST_ADDRESS,
339 .client_address = MEI_ADDRESS_MKHI,
340 .length = sizeof(mkhi),
341 };
342
343 /* Send request and wait for response */
344 if (mei_sendrecv(&mei, &mkhi, NULL, NULL, 0) < 0) {
345 printk(BIOS_ERR, "ME: END OF POST message failed\n");
346 return -1;
347 }
348
349 printk(BIOS_INFO, "ME: END OF POST message successful\n");
350 return 0;
351}
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100352
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200353#ifdef __SIMPLE_DEVICE__
354
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100355static void intel_me7_finalize_smm(void)
356{
357 struct me_hfs hfs;
358 u32 reg32;
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200359 u16 reg16;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100360
Patrick Rudolph819c2062019-11-29 19:27:37 +0100361 mei_base_address = (u32 *)(uintptr_t)
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800362 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100363
364 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800365 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100366 return;
367
368 /* Make sure ME is in a mode that expects EOP */
369 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
370 memcpy(&hfs, &reg32, sizeof(u32));
371
372 /* Abort and leave device alone if not normal mode */
373 if (hfs.fpt_bad ||
374 hfs.working_state != ME_HFS_CWS_NORMAL ||
375 hfs.operation_mode != ME_HFS_MODE_NORMAL)
376 return;
377
378 /* Try to send EOP command so ME stops accepting other commands */
379 mkhi_end_of_post();
380
381 /* Make sure IO is disabled */
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200382 reg16 = pci_read_config16(PCH_ME_DEV, PCI_COMMAND);
383 reg16 &= ~(PCI_COMMAND_MASTER |
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100384 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200385 pci_write_config16(PCH_ME_DEV, PCI_COMMAND, reg16);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100386
387 /* Hide the PCI device */
388 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
389}
390
391void intel_me_finalize_smm(void)
392{
393 u32 did = pci_read_config32(PCH_ME_DEV, PCI_VENDOR_ID);
394 switch (did) {
395 case 0x1c3a8086:
396 intel_me7_finalize_smm();
397 break;
398 case 0x1e3a8086:
399 intel_me8_finalize_smm();
400 break;
401 default:
402 printk(BIOS_ERR, "No finalize handler for ME %08x.\n", did);
403 }
404}
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200405#else /* !__SIMPLE_DEVICE__ */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100406
407/* Determine the path that we should take based on ME status */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200408static me_bios_path intel_me_path(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100409{
410 me_bios_path path = ME_DISABLE_BIOS_PATH;
411 struct me_hfs hfs;
412 struct me_gmes gmes;
413
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100414 /* S3 wake skips all MKHI messages */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300415 if (acpi_is_wakeup_s3())
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100416 return ME_S3WAKE_BIOS_PATH;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100417
418 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
419 pci_read_dword_ptr(dev, &gmes, PCI_ME_GMES);
420
421 /* Check and dump status */
422 intel_me_status(&hfs, &gmes);
423
424 /* Check Current Working State */
425 switch (hfs.working_state) {
426 case ME_HFS_CWS_NORMAL:
427 path = ME_NORMAL_BIOS_PATH;
428 break;
429 case ME_HFS_CWS_REC:
430 path = ME_RECOVERY_BIOS_PATH;
431 break;
432 default:
433 path = ME_DISABLE_BIOS_PATH;
434 break;
435 }
436
437 /* Check Current Operation Mode */
438 switch (hfs.operation_mode) {
439 case ME_HFS_MODE_NORMAL:
440 break;
441 case ME_HFS_MODE_DEBUG:
442 case ME_HFS_MODE_DIS:
443 case ME_HFS_MODE_OVER_JMPR:
444 case ME_HFS_MODE_OVER_MEI:
445 default:
446 path = ME_DISABLE_BIOS_PATH;
447 break;
448 }
449
450 /* Check for any error code and valid firmware */
451 if (hfs.error_code || hfs.fpt_bad)
452 path = ME_ERROR_BIOS_PATH;
453
Kyösti Mälkkibe5317f2019-11-06 12:07:21 +0200454 if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) {
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100455 struct elog_event_data_me_extended data = {
456 .current_working_state = hfs.working_state,
457 .operation_state = hfs.operation_state,
458 .operation_mode = hfs.operation_mode,
459 .error_code = hfs.error_code,
460 .progress_code = gmes.progress_code,
461 .current_pmevent = gmes.current_pmevent,
462 .current_state = gmes.current_state,
463 };
464 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
465 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
466 &data, sizeof(data));
467 }
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100468
469 return path;
470}
471
472/* Prepare ME for MEI messages */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200473static int intel_mei_setup(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100474{
475 struct resource *res;
476 struct mei_csr host;
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200477 u16 reg16;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100478
479 /* Find the MMIO base for the ME interface */
480 res = find_resource(dev, PCI_BASE_ADDRESS_0);
481 if (!res || res->base == 0 || res->size == 0) {
482 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
483 return -1;
484 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800485 mei_base_address = (u32 *)(uintptr_t)res->base;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100486
487 /* Ensure Memory and Bus Master bits are set */
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200488 reg16 = pci_read_config16(dev, PCI_COMMAND);
489 reg16 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
490 pci_write_config16(dev, PCI_COMMAND, reg16);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100491
492 /* Clean up status for next message */
493 read_host_csr(&host);
494 host.interrupt_generate = 1;
495 host.ready = 1;
496 host.reset = 0;
497 write_host_csr(&host);
498
499 return 0;
500}
501
502/* Read the Extend register hash of ME firmware */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200503static int intel_me_extend_valid(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100504{
505 struct me_heres status;
506 u32 extend[8] = {0};
507 int i, count = 0;
508
509 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
510 if (!status.extend_feature_present) {
511 printk(BIOS_ERR, "ME: Extend Feature not present\n");
512 return -1;
513 }
514
515 if (!status.extend_reg_valid) {
516 printk(BIOS_ERR, "ME: Extend Register not valid\n");
517 return -1;
518 }
519
520 switch (status.extend_reg_algorithm) {
521 case PCI_ME_EXT_SHA1:
522 count = 5;
523 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
524 break;
525 case PCI_ME_EXT_SHA256:
526 count = 8;
527 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
528 break;
529 default:
530 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
531 status.extend_reg_algorithm);
532 return -1;
533 }
534
535 for (i = 0; i < count; ++i) {
536 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
537 printk(BIOS_DEBUG, "%08x", extend[i]);
538 }
539 printk(BIOS_DEBUG, "\n");
540
Julius Wernercd49cce2019-03-05 16:53:33 -0800541#if CONFIG(CHROMEOS)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100542 /* Save hash in NVS for the OS to verify */
543 chromeos_set_me_hash(extend, count);
544#endif
545
546 return 0;
547}
548
549/* Hide the ME virtual PCI devices */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200550static void intel_me_hide(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100551{
552 dev->enabled = 0;
553 pch_enable(dev);
554}
555
556/* Check whether ME is present and do basic init */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200557static void intel_me_init(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100558{
559 me_bios_path path = intel_me_path(dev);
560
561 /* Do initial setup and determine the BIOS path */
562 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
563
564 switch (path) {
565 case ME_S3WAKE_BIOS_PATH:
566 intel_me_hide(dev);
567 break;
568
569 case ME_NORMAL_BIOS_PATH:
570 /* Validate the extend register */
571 if (intel_me_extend_valid(dev) < 0)
572 break; /* TODO: force recovery mode */
573
574 /* Prepare MEI MMIO interface */
575 if (intel_mei_setup(dev) < 0)
576 break;
577
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100578 /*
579 * Leave the ME unlocked in this path.
580 * It will be locked via SMI command later.
581 */
582 break;
583
584 case ME_ERROR_BIOS_PATH:
585 case ME_RECOVERY_BIOS_PATH:
586 case ME_DISABLE_BIOS_PATH:
587 case ME_FIRMWARE_UPDATE_BIOS_PATH:
588 break;
589 }
590}
591
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100592static struct device_operations device_ops = {
593 .read_resources = pci_dev_read_resources,
594 .set_resources = pci_dev_set_resources,
595 .enable_resources = pci_dev_enable_resources,
596 .init = intel_me_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200597 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100598};
599
Felix Singer838fbc72019-11-21 21:23:32 +0100600static const unsigned short pci_device_ids[] = {
601 0x1c3a,
602 PCI_DID_INTEL_IBEXPEAK_HECI1,
603 0
604};
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100605
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100606static const struct pci_driver intel_me __pci_driver = {
607 .ops = &device_ops,
608 .vendor = PCI_VENDOR_ID_INTEL,
609 .devices = pci_device_ids
610};
611
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200612#endif /* !__SIMPLE_DEVICE__ */