blob: fe2a37c849200c4915a80aaa1c188901245154df [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer8e073822012-04-04 00:07:22 +02002
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älkki21d6a272019-11-05 18:50:38 +020013#include <device/device.h>
14#include <device/pci.h>
Angel Pons7f32df32020-06-02 13:36:57 +020015#include <device/pci_ops.h>
16#include <console/console.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020017#include <device/pci_ids.h>
18#include <device/pci_def.h>
19#include <string.h>
20#include <delay.h>
Duncan Lauriec1c94352012-07-13 10:11:54 -070021#include <elog.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020022
Stefan Reinauer8e073822012-04-04 00:07:22 +020023#include "me.h"
24#include "pch.h"
25
Stefan Reinauer8e073822012-04-04 00:07:22 +020026/* Send END OF POST message to the ME */
Kyösti Mälkki21d6a272019-11-05 18:50:38 +020027static int __unused mkhi_end_of_post(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +020028{
29 struct mkhi_header mkhi = {
30 .group_id = MKHI_GROUP_ID_GEN,
31 .command = MKHI_END_OF_POST,
32 };
33 struct mei_header mei = {
34 .is_complete = 1,
35 .host_address = MEI_HOST_ADDRESS,
36 .client_address = MEI_ADDRESS_MKHI,
37 .length = sizeof(mkhi),
38 };
39
40 /* Send request and wait for response */
41 if (mei_sendrecv(&mei, &mkhi, NULL, NULL, 0) < 0) {
42 printk(BIOS_ERR, "ME: END OF POST message failed\n");
43 return -1;
44 }
45
46 printk(BIOS_INFO, "ME: END OF POST message successful\n");
47 return 0;
48}
49
Stefan Reinauer8e073822012-04-04 00:07:22 +020050/* Get ME firmware version */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +020051static int __unused mkhi_get_fw_version(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +020052{
53 struct me_fw_version version;
54 struct mkhi_header mkhi = {
55 .group_id = MKHI_GROUP_ID_GEN,
56 .command = MKHI_GET_FW_VERSION,
57 };
58 struct mei_header mei = {
59 .is_complete = 1,
60 .host_address = MEI_HOST_ADDRESS,
61 .client_address = MEI_ADDRESS_MKHI,
62 .length = sizeof(mkhi),
63 };
64
65 /* Send request and wait for response */
66 if (mei_sendrecv(&mei, &mkhi, NULL, &version, sizeof(version)) < 0) {
67 printk(BIOS_ERR, "ME: GET FW VERSION message failed\n");
68 return -1;
69 }
70
71 printk(BIOS_INFO, "ME: Firmware Version %u.%u.%u.%u (code) "
72 "%u.%u.%u.%u (recovery)\n",
73 version.code_major, version.code_minor,
74 version.code_build_number, version.code_hot_fix,
75 version.recovery_major, version.recovery_minor,
76 version.recovery_build_number, version.recovery_hot_fix);
77
78 return 0;
79}
80
81static inline void print_cap(const char *name, int state)
82{
83 printk(BIOS_DEBUG, "ME Capability: %-30s : %sabled\n",
84 name, state ? "en" : "dis");
85}
86
87/* Get ME Firmware Capabilities */
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +020088static int __unused mkhi_get_fwcaps(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +020089{
90 u32 rule_id = 0;
91 struct me_fwcaps cap;
92 struct mkhi_header mkhi = {
93 .group_id = MKHI_GROUP_ID_FWCAPS,
94 .command = MKHI_FWCAPS_GET_RULE,
95 };
96 struct mei_header mei = {
97 .is_complete = 1,
98 .host_address = MEI_HOST_ADDRESS,
99 .client_address = MEI_ADDRESS_MKHI,
100 .length = sizeof(mkhi) + sizeof(rule_id),
101 };
102
103 /* Send request and wait for response */
104 if (mei_sendrecv(&mei, &mkhi, &rule_id, &cap, sizeof(cap)) < 0) {
105 printk(BIOS_ERR, "ME: GET FWCAPS message failed\n");
106 return -1;
107 }
108
109 print_cap("Full Network manageability", cap.caps_sku.full_net);
110 print_cap("Regular Network manageability", cap.caps_sku.std_net);
111 print_cap("Manageability", cap.caps_sku.manageability);
112 print_cap("Small business technology", cap.caps_sku.small_business);
113 print_cap("Level III manageability", cap.caps_sku.l3manageability);
114 print_cap("IntelR Anti-Theft (AT)", cap.caps_sku.intel_at);
115 print_cap("IntelR Capability Licensing Service (CLS)",
116 cap.caps_sku.intel_cls);
117 print_cap("IntelR Power Sharing Technology (MPC)",
118 cap.caps_sku.intel_mpc);
119 print_cap("ICC Over Clocking", cap.caps_sku.icc_over_clocking);
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200120 print_cap("Protected Audio Video Path (PAVP)", cap.caps_sku.pavp);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200121 print_cap("IPV6", cap.caps_sku.ipv6);
122 print_cap("KVM Remote Control (KVM)", cap.caps_sku.kvm);
123 print_cap("Outbreak Containment Heuristic (OCH)", cap.caps_sku.och);
124 print_cap("Virtual LAN (VLAN)", cap.caps_sku.vlan);
125 print_cap("TLS", cap.caps_sku.tls);
126 print_cap("Wireless LAN (WLAN)", cap.caps_sku.wlan);
127
128 return 0;
129}
Stefan Reinauer8e073822012-04-04 00:07:22 +0200130
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200131#ifdef __SIMPLE_DEVICE__
132
Stefan Reinauer998f3a22012-06-11 15:15:46 -0700133static void intel_me7_finalize_smm(void)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200134{
135 struct me_hfs hfs;
136 u32 reg32;
137
Angel Pons2e29c3b2020-08-10 15:47:28 +0200138 update_mei_base_address();
Stefan Reinauer8e073822012-04-04 00:07:22 +0200139
140 /* S3 path will have hidden this device already */
Angel Pons2e29c3b2020-08-10 15:47:28 +0200141 if (!is_mei_base_address_valid())
Stefan Reinauer8e073822012-04-04 00:07:22 +0200142 return;
143
144 /* Make sure ME is in a mode that expects EOP */
Kyösti Mälkkifd98c652013-07-26 08:50:53 +0300145 reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200146 memcpy(&hfs, &reg32, sizeof(u32));
147
148 /* Abort and leave device alone if not normal mode */
149 if (hfs.fpt_bad ||
150 hfs.working_state != ME_HFS_CWS_NORMAL ||
151 hfs.operation_mode != ME_HFS_MODE_NORMAL)
152 return;
153
154 /* Try to send EOP command so ME stops accepting other commands */
155 mkhi_end_of_post();
156
157 /* Make sure IO is disabled */
Angel Ponsc803f652020-06-07 22:09:01 +0200158 pci_and_config16(PCH_ME_DEV, PCI_COMMAND,
159 ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
Stefan Reinauer8e073822012-04-04 00:07:22 +0200160
161 /* Hide the PCI device */
162 RCBA32_OR(FD2, PCH_DISABLE_MEI1);
163}
164
Stefan Reinauer998f3a22012-06-11 15:15:46 -0700165void intel_me_finalize_smm(void)
166{
Angel Ponsa7db40e2020-09-10 12:51:38 +0200167 u16 did = pci_read_config16(PCH_ME_DEV, PCI_DEVICE_ID);
Stefan Reinauer998f3a22012-06-11 15:15:46 -0700168 switch (did) {
Angel Ponsa7db40e2020-09-10 12:51:38 +0200169 case 0x1c3a:
Stefan Reinauer998f3a22012-06-11 15:15:46 -0700170 intel_me7_finalize_smm();
171 break;
Angel Ponsa7db40e2020-09-10 12:51:38 +0200172 case 0x1e3a:
Stefan Reinauer998f3a22012-06-11 15:15:46 -0700173 intel_me8_finalize_smm();
174 break;
175 default:
Angel Ponsa7db40e2020-09-10 12:51:38 +0200176 printk(BIOS_ERR, "No finalize handler for ME %04x.\n", did);
Stefan Reinauer998f3a22012-06-11 15:15:46 -0700177 }
178}
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200179
180#else
Stefan Reinauer8e073822012-04-04 00:07:22 +0200181
182/* Determine the path that we should take based on ME status */
Elyes HAOUASdc035282018-09-18 13:28:49 +0200183static me_bios_path intel_me_path(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200184{
185 me_bios_path path = ME_DISABLE_BIOS_PATH;
186 struct me_hfs hfs;
187 struct me_gmes gmes;
188
Stefan Reinauer8e073822012-04-04 00:07:22 +0200189 /* S3 wake skips all MKHI messages */
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300190 if (acpi_is_wakeup_s3())
Stefan Reinauer8e073822012-04-04 00:07:22 +0200191 return ME_S3WAKE_BIOS_PATH;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200192
193 pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS);
194 pci_read_dword_ptr(dev, &gmes, PCI_ME_GMES);
195
196 /* Check and dump status */
197 intel_me_status(&hfs, &gmes);
198
Stefan Reinauer8e073822012-04-04 00:07:22 +0200199 /* Check Current Working State */
200 switch (hfs.working_state) {
201 case ME_HFS_CWS_NORMAL:
202 path = ME_NORMAL_BIOS_PATH;
203 break;
204 case ME_HFS_CWS_REC:
205 path = ME_RECOVERY_BIOS_PATH;
206 break;
207 default:
208 path = ME_DISABLE_BIOS_PATH;
209 break;
210 }
211
212 /* Check Current Operation Mode */
213 switch (hfs.operation_mode) {
214 case ME_HFS_MODE_NORMAL:
215 break;
216 case ME_HFS_MODE_DEBUG:
217 case ME_HFS_MODE_DIS:
218 case ME_HFS_MODE_OVER_JMPR:
219 case ME_HFS_MODE_OVER_MEI:
220 default:
221 path = ME_DISABLE_BIOS_PATH;
222 break;
223 }
224
Duncan Laurie5c88c6f2012-09-01 14:00:23 -0700225 /* Check for any error code and valid firmware */
226 if (hfs.error_code || hfs.fpt_bad)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200227 path = ME_ERROR_BIOS_PATH;
228
Kyösti Mälkkibe5317f2019-11-06 12:07:21 +0200229 if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) {
Duncan Laurie5c88c6f2012-09-01 14:00:23 -0700230 struct elog_event_data_me_extended data = {
231 .current_working_state = hfs.working_state,
232 .operation_state = hfs.operation_state,
233 .operation_mode = hfs.operation_mode,
234 .error_code = hfs.error_code,
235 .progress_code = gmes.progress_code,
236 .current_pmevent = gmes.current_pmevent,
237 .current_state = gmes.current_state,
238 };
239 elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path);
240 elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT,
241 &data, sizeof(data));
242 }
Duncan Laurie5c88c6f2012-09-01 14:00:23 -0700243
Stefan Reinauer8e073822012-04-04 00:07:22 +0200244 return path;
245}
246
Stefan Reinauer8e073822012-04-04 00:07:22 +0200247/* Check whether ME is present and do basic init */
Elyes HAOUASdc035282018-09-18 13:28:49 +0200248static void intel_me_init(struct device *dev)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200249{
250 me_bios_path path = intel_me_path(dev);
251
252 /* Do initial setup and determine the BIOS path */
Angel Pons2e29c3b2020-08-10 15:47:28 +0200253 printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_get_bios_path_string(path));
Stefan Reinauer8e073822012-04-04 00:07:22 +0200254
255 switch (path) {
256 case ME_S3WAKE_BIOS_PATH:
James Yea85d4a52020-02-22 20:30:49 +1100257 case ME_DISABLE_BIOS_PATH:
258#if CONFIG(HIDE_MEI_ON_ERROR)
259 case ME_ERROR_BIOS_PATH:
260#endif
Stefan Reinauer8e073822012-04-04 00:07:22 +0200261 intel_me_hide(dev);
262 break;
263
264 case ME_NORMAL_BIOS_PATH:
265 /* Validate the extend register */
266 if (intel_me_extend_valid(dev) < 0)
267 break; /* TODO: force recovery mode */
268
269 /* Prepare MEI MMIO interface */
270 if (intel_mei_setup(dev) < 0)
271 break;
272
Kyösti Mälkkic86fc8e2019-11-06 06:32:27 +0200273 if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) {
274 /* Print ME firmware version */
275 mkhi_get_fw_version();
276 /* Print ME firmware capabilities */
277 mkhi_get_fwcaps();
278 }
Stefan Reinauer8e073822012-04-04 00:07:22 +0200279
280 /*
281 * Leave the ME unlocked in this path.
282 * It will be locked via SMI command later.
283 */
284 break;
285
James Yea85d4a52020-02-22 20:30:49 +1100286#if !CONFIG(HIDE_MEI_ON_ERROR)
Stefan Reinauer8e073822012-04-04 00:07:22 +0200287 case ME_ERROR_BIOS_PATH:
James Yea85d4a52020-02-22 20:30:49 +1100288#endif
Stefan Reinauer8e073822012-04-04 00:07:22 +0200289 case ME_RECOVERY_BIOS_PATH:
Stefan Reinauer8e073822012-04-04 00:07:22 +0200290 case ME_FIRMWARE_UPDATE_BIOS_PATH:
Stefan Reinauer8e073822012-04-04 00:07:22 +0200291 break;
292 }
293}
294
Stefan Reinauer8e073822012-04-04 00:07:22 +0200295static struct device_operations device_ops = {
296 .read_resources = pci_dev_read_resources,
297 .set_resources = pci_dev_set_resources,
298 .enable_resources = pci_dev_enable_resources,
299 .init = intel_me_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200300 .ops_pci = &pci_dev_ops_pci,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200301};
302
303static const struct pci_driver intel_me __pci_driver = {
304 .ops = &device_ops,
305 .vendor = PCI_VENDOR_ID_INTEL,
306 .device = 0x1c3a,
307};
308
Kyösti Mälkki21d6a272019-11-05 18:50:38 +0200309#endif /* __SIMPLE_DEVICE__ */