blob: b355d9dbdb70e394dc89015f944a1c6cbb9f9c35 [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{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800122 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{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800128 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) {
264 printk(BIOS_ERR, "ME: timeout waiting for data: expected "
265 "%u, available %u\n", expected,
266 me.buffer_write_ptr - me.buffer_read_ptr);
267 return -1;
268 }
269
270 /* Read and verify MEI response header from the ME */
271 mei_read_dword_ptr(&mei_rsp, MEI_ME_CB_RW);
272 if (!mei_rsp.is_complete) {
273 printk(BIOS_ERR, "ME: response is not complete\n");
274 return -1;
275 }
276
277 /* Handle non-dword responses and expect at least MKHI header */
278 ndata = mei_rsp.length >> 2;
279 if (mei_rsp.length & 3)
280 ndata++;
281 if (ndata != (expected - 1)) {
282 printk(BIOS_ERR, "ME: response is missing data\n");
283 return -1;
284 }
285
286 /* Read and verify MKHI response header from the ME */
287 mei_read_dword_ptr(&mkhi_rsp, MEI_ME_CB_RW);
288 if (!mkhi_rsp.is_response ||
289 mkhi->group_id != mkhi_rsp.group_id ||
290 mkhi->command != mkhi_rsp.command) {
291 printk(BIOS_ERR, "ME: invalid response, group %u ?= %u, "
292 "command %u ?= %u, is_response %u\n", mkhi->group_id,
293 mkhi_rsp.group_id, mkhi->command, mkhi_rsp.command,
294 mkhi_rsp.is_response);
295 return -1;
296 }
297 ndata--; /* MKHI header has been read */
298
299 /* Make sure caller passed a buffer with enough space */
300 if (ndata != (rsp_bytes >> 2)) {
301 printk(BIOS_ERR, "ME: not enough room in response buffer: "
302 "%u != %u\n", ndata, rsp_bytes >> 2);
303 return -1;
304 }
305
306 /* Read response data from the circular buffer */
307 data = rsp_data;
308 for (n = 0; n < ndata; ++n)
309 *data++ = read_cb();
310
311 /* Tell the ME that we have consumed the response */
312 read_host_csr(&host);
313 host.interrupt_status = 1;
314 host.interrupt_generate = 1;
315 write_host_csr(&host);
316
317 return mei_wait_for_me_ready();
318}
319
320static inline int mei_sendrecv(struct mei_header *mei, struct mkhi_header *mkhi,
321 void *req_data, void *rsp_data, int rsp_bytes)
322{
323 if (mei_send_msg(mei, mkhi, req_data) < 0)
324 return -1;
325 if (mei_recv_msg(mei, mkhi, rsp_data, rsp_bytes) < 0)
326 return -1;
327 return 0;
328}
329
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100330/* Send END OF POST message to the ME */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200331static int __unused mkhi_end_of_post(void)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100332{
333 struct mkhi_header mkhi = {
334 .group_id = MKHI_GROUP_ID_GEN,
335 .command = MKHI_END_OF_POST,
336 };
337 struct mei_header mei = {
338 .is_complete = 1,
339 .host_address = MEI_HOST_ADDRESS,
340 .client_address = MEI_ADDRESS_MKHI,
341 .length = sizeof(mkhi),
342 };
343
344 /* Send request and wait for response */
345 if (mei_sendrecv(&mei, &mkhi, NULL, NULL, 0) < 0) {
346 printk(BIOS_ERR, "ME: END OF POST message failed\n");
347 return -1;
348 }
349
350 printk(BIOS_INFO, "ME: END OF POST message successful\n");
351 return 0;
352}
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100353
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200354#ifdef __SIMPLE_DEVICE__
355
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100356static void intel_me7_finalize_smm(void)
357{
358 struct me_hfs hfs;
359 u32 reg32;
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200360 u16 reg16;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100361
Patrick Rudolph819c2062019-11-29 19:27:37 +0100362 mei_base_address = (u32 *)(uintptr_t)
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800363 (pci_read_config32(PCH_ME_DEV, PCI_BASE_ADDRESS_0) & ~0xf);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100364
365 /* S3 path will have hidden this device already */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800366 if (!mei_base_address || mei_base_address == (u32 *)0xfffffff0)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100367 return;
368
369 /* Make sure ME is in a mode that expects EOP */
370 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
371 memcpy(&hfs, &reg32, sizeof(u32));
372
373 /* Abort and leave device alone if not normal mode */
374 if (hfs.fpt_bad ||
375 hfs.working_state != ME_HFS_CWS_NORMAL ||
376 hfs.operation_mode != ME_HFS_MODE_NORMAL)
377 return;
378
379 /* Try to send EOP command so ME stops accepting other commands */
380 mkhi_end_of_post();
381
382 /* Make sure IO is disabled */
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200383 reg16 = pci_read_config16(PCH_ME_DEV, PCI_COMMAND);
384 reg16 &= ~(PCI_COMMAND_MASTER |
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100385 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200386 pci_write_config16(PCH_ME_DEV, PCI_COMMAND, reg16);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100387
388 /* Hide the PCI device */
389 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
390}
391
392void intel_me_finalize_smm(void)
393{
394 u32 did = pci_read_config32(PCH_ME_DEV, PCI_VENDOR_ID);
395 switch (did) {
396 case 0x1c3a8086:
397 intel_me7_finalize_smm();
398 break;
399 case 0x1e3a8086:
400 intel_me8_finalize_smm();
401 break;
402 default:
403 printk(BIOS_ERR, "No finalize handler for ME %08x.\n", did);
404 }
405}
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200406#else /* !__SIMPLE_DEVICE__ */
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100407
408/* Determine the path that we should take based on ME status */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200409static me_bios_path intel_me_path(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100410{
411 me_bios_path path = ME_DISABLE_BIOS_PATH;
412 struct me_hfs hfs;
413 struct me_gmes gmes;
414
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100415 /* S3 wake skips all MKHI messages */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300416 if (acpi_is_wakeup_s3())
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100417 return ME_S3WAKE_BIOS_PATH;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100418
419 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
420 pci_read_dword_ptr(dev, &gmes, PCI_ME_GMES);
421
422 /* Check and dump status */
423 intel_me_status(&hfs, &gmes);
424
425 /* Check Current Working State */
426 switch (hfs.working_state) {
427 case ME_HFS_CWS_NORMAL:
428 path = ME_NORMAL_BIOS_PATH;
429 break;
430 case ME_HFS_CWS_REC:
431 path = ME_RECOVERY_BIOS_PATH;
432 break;
433 default:
434 path = ME_DISABLE_BIOS_PATH;
435 break;
436 }
437
438 /* Check Current Operation Mode */
439 switch (hfs.operation_mode) {
440 case ME_HFS_MODE_NORMAL:
441 break;
442 case ME_HFS_MODE_DEBUG:
443 case ME_HFS_MODE_DIS:
444 case ME_HFS_MODE_OVER_JMPR:
445 case ME_HFS_MODE_OVER_MEI:
446 default:
447 path = ME_DISABLE_BIOS_PATH;
448 break;
449 }
450
451 /* Check for any error code and valid firmware */
452 if (hfs.error_code || hfs.fpt_bad)
453 path = ME_ERROR_BIOS_PATH;
454
Kyösti Mälkkibe5317f2019-11-06 12:07:21 +0200455 if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) {
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100456 struct elog_event_data_me_extended data = {
457 .current_working_state = hfs.working_state,
458 .operation_state = hfs.operation_state,
459 .operation_mode = hfs.operation_mode,
460 .error_code = hfs.error_code,
461 .progress_code = gmes.progress_code,
462 .current_pmevent = gmes.current_pmevent,
463 .current_state = gmes.current_state,
464 };
465 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
466 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
467 &data, sizeof(data));
468 }
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100469
470 return path;
471}
472
473/* Prepare ME for MEI messages */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200474static int intel_mei_setup(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100475{
476 struct resource *res;
477 struct mei_csr host;
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200478 u16 reg16;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100479
480 /* Find the MMIO base for the ME interface */
481 res = find_resource(dev, PCI_BASE_ADDRESS_0);
482 if (!res || res->base == 0 || res->size == 0) {
483 printk(BIOS_DEBUG, "ME: MEI resource not present!\n");
484 return -1;
485 }
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800486 mei_base_address = (u32 *)(uintptr_t)res->base;
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100487
488 /* Ensure Memory and Bus Master bits are set */
Elyes HAOUAS8b6dfde2020-04-28 09:58:21 +0200489 reg16 = pci_read_config16(dev, PCI_COMMAND);
490 reg16 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
491 pci_write_config16(dev, PCI_COMMAND, reg16);
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100492
493 /* Clean up status for next message */
494 read_host_csr(&host);
495 host.interrupt_generate = 1;
496 host.ready = 1;
497 host.reset = 0;
498 write_host_csr(&host);
499
500 return 0;
501}
502
503/* Read the Extend register hash of ME firmware */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200504static int intel_me_extend_valid(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100505{
506 struct me_heres status;
507 u32 extend[8] = {0};
508 int i, count = 0;
509
510 pci_read_dword_ptr(dev, &status, PCI_ME_HERES);
511 if (!status.extend_feature_present) {
512 printk(BIOS_ERR, "ME: Extend Feature not present\n");
513 return -1;
514 }
515
516 if (!status.extend_reg_valid) {
517 printk(BIOS_ERR, "ME: Extend Register not valid\n");
518 return -1;
519 }
520
521 switch (status.extend_reg_algorithm) {
522 case PCI_ME_EXT_SHA1:
523 count = 5;
524 printk(BIOS_DEBUG, "ME: Extend SHA-1: ");
525 break;
526 case PCI_ME_EXT_SHA256:
527 count = 8;
528 printk(BIOS_DEBUG, "ME: Extend SHA-256: ");
529 break;
530 default:
531 printk(BIOS_ERR, "ME: Extend Algorithm %d unknown\n",
532 status.extend_reg_algorithm);
533 return -1;
534 }
535
536 for (i = 0; i < count; ++i) {
537 extend[i] = pci_read_config32(dev, PCI_ME_HER(i));
538 printk(BIOS_DEBUG, "%08x", extend[i]);
539 }
540 printk(BIOS_DEBUG, "\n");
541
Julius Wernercd49cce2019-03-05 16:53:33 -0800542#if CONFIG(CHROMEOS)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100543 /* Save hash in NVS for the OS to verify */
544 chromeos_set_me_hash(extend, count);
545#endif
546
547 return 0;
548}
549
550/* Hide the ME virtual PCI devices */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200551static void intel_me_hide(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100552{
553 dev->enabled = 0;
554 pch_enable(dev);
555}
556
557/* Check whether ME is present and do basic init */
Elyes HAOUASbe841402018-05-13 13:40:39 +0200558static void intel_me_init(struct device *dev)
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100559{
560 me_bios_path path = intel_me_path(dev);
561
562 /* Do initial setup and determine the BIOS path */
563 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_bios_path_values[path]);
564
565 switch (path) {
566 case ME_S3WAKE_BIOS_PATH:
567 intel_me_hide(dev);
568 break;
569
570 case ME_NORMAL_BIOS_PATH:
571 /* Validate the extend register */
572 if (intel_me_extend_valid(dev) < 0)
573 break; /* TODO: force recovery mode */
574
575 /* Prepare MEI MMIO interface */
576 if (intel_mei_setup(dev) < 0)
577 break;
578
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100579 /*
580 * Leave the ME unlocked in this path.
581 * It will be locked via SMI command later.
582 */
583 break;
584
585 case ME_ERROR_BIOS_PATH:
586 case ME_RECOVERY_BIOS_PATH:
587 case ME_DISABLE_BIOS_PATH:
588 case ME_FIRMWARE_UPDATE_BIOS_PATH:
589 break;
590 }
591}
592
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100593static struct device_operations device_ops = {
594 .read_resources = pci_dev_read_resources,
595 .set_resources = pci_dev_set_resources,
596 .enable_resources = pci_dev_enable_resources,
597 .init = intel_me_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200598 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100599};
600
Felix Singer838fbc72019-11-21 21:23:32 +0100601static const unsigned short pci_device_ids[] = {
602 0x1c3a,
603 PCI_DID_INTEL_IBEXPEAK_HECI1,
604 0
605};
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100606
Vladimir Serbinenko888d5592013-11-13 17:53:38 +0100607static const struct pci_driver intel_me __pci_driver = {
608 .ops = &device_ops,
609 .vendor = PCI_VENDOR_ID_INTEL,
610 .devices = pci_device_ids
611};
612
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200613#endif /* !__SIMPLE_DEVICE__ */