Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 2 | |
| 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 Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 11 | #include <acpi/acpi.h> |
Evgeny Zinoviev | 833e9ba | 2019-11-21 21:47:31 +0300 | [diff] [blame] | 12 | #include <cf9_reset.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 13 | #include <device/mmio.h> |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 14 | #include <device/device.h> |
| 15 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 16 | #include <device/pci_ops.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 17 | #include <console/console.h> |
| 18 | #include <device/pci_ids.h> |
| 19 | #include <device/pci_def.h> |
| 20 | #include <string.h> |
| 21 | #include <delay.h> |
Duncan Laurie | c1c9435 | 2012-07-13 10:11:54 -0700 | [diff] [blame] | 22 | #include <elog.h> |
Evgeny Zinoviev | 833e9ba | 2019-11-21 21:47:31 +0300 | [diff] [blame] | 23 | #include <halt.h> |
| 24 | #include <option.h> |
| 25 | #include <southbridge/intel/common/me.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 26 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 27 | #include "me.h" |
| 28 | #include "pch.h" |
| 29 | |
Angel Pons | 053fe8a | 2020-08-10 15:32:57 +0200 | [diff] [blame] | 30 | /* Send END OF POST message to the ME */ |
| 31 | static int __unused mkhi_end_of_post(void) |
| 32 | { |
| 33 | struct mkhi_header mkhi = { |
| 34 | .group_id = MKHI_GROUP_ID_GEN, |
| 35 | .command = MKHI_END_OF_POST, |
| 36 | }; |
| 37 | struct mei_header mei = { |
| 38 | .is_complete = 1, |
| 39 | .host_address = MEI_HOST_ADDRESS, |
| 40 | .client_address = MEI_ADDRESS_MKHI, |
| 41 | .length = sizeof(mkhi), |
| 42 | }; |
| 43 | |
| 44 | u32 eop_ack; |
| 45 | |
| 46 | /* Send request and wait for response */ |
| 47 | printk(BIOS_NOTICE, "ME: %s\n", __func__); |
| 48 | if (mei_sendrecv(&mei, &mkhi, NULL, &eop_ack, sizeof(eop_ack)) < 0) { |
| 49 | printk(BIOS_ERR, "ME: END OF POST message failed\n"); |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | printk(BIOS_INFO, "ME: END OF POST message successful (%d)\n", eop_ack); |
| 54 | return 0; |
| 55 | } |
| 56 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 57 | static inline void print_cap(const char *name, int state) |
| 58 | { |
| 59 | printk(BIOS_DEBUG, "ME Capability: %-41s : %sabled\n", |
| 60 | name, state ? " en" : "dis"); |
| 61 | } |
| 62 | |
Kyösti Mälkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 63 | static void __unused me_print_fw_version(mbp_fw_version_name *vers_name) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 64 | { |
| 65 | if (!vers_name->major_version) { |
| 66 | printk(BIOS_ERR, "ME: mbp missing version report\n"); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | printk(BIOS_DEBUG, "ME: found version %d.%d.%d.%d\n", |
| 71 | vers_name->major_version, vers_name->minor_version, |
| 72 | vers_name->hotfix_version, vers_name->build_version); |
| 73 | } |
| 74 | |
| 75 | /* Get ME Firmware Capabilities */ |
| 76 | static int mkhi_get_fwcaps(mefwcaps_sku *cap) |
| 77 | { |
| 78 | u32 rule_id = 0; |
| 79 | struct me_fwcaps cap_msg; |
| 80 | struct mkhi_header mkhi = { |
| 81 | .group_id = MKHI_GROUP_ID_FWCAPS, |
| 82 | .command = MKHI_FWCAPS_GET_RULE, |
| 83 | }; |
| 84 | struct mei_header mei = { |
| 85 | .is_complete = 1, |
| 86 | .host_address = MEI_HOST_ADDRESS, |
| 87 | .client_address = MEI_ADDRESS_MKHI, |
| 88 | .length = sizeof(mkhi) + sizeof(rule_id), |
| 89 | }; |
| 90 | |
| 91 | /* Send request and wait for response */ |
Edward O'Callaghan | 152e517 | 2014-07-13 00:28:05 +1000 | [diff] [blame] | 92 | if (mei_sendrecv(&mei, &mkhi, &rule_id, &cap_msg, sizeof(cap_msg)) < 0) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 93 | printk(BIOS_ERR, "ME: GET FWCAPS message failed\n"); |
| 94 | return -1; |
Edward O'Callaghan | 152e517 | 2014-07-13 00:28:05 +1000 | [diff] [blame] | 95 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 96 | *cap = cap_msg.caps_sku; |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | /* Get ME Firmware Capabilities */ |
Kyösti Mälkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 101 | static void __unused me_print_fwcaps(mbp_fw_caps *caps_section) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 102 | { |
| 103 | mefwcaps_sku *cap = &caps_section->fw_capabilities; |
| 104 | if (!caps_section->available) { |
| 105 | printk(BIOS_ERR, "ME: mbp missing fwcaps report\n"); |
| 106 | if (mkhi_get_fwcaps(cap)) |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | print_cap("Full Network manageability", cap->full_net); |
| 111 | print_cap("Regular Network manageability", cap->std_net); |
| 112 | print_cap("Manageability", cap->manageability); |
| 113 | print_cap("Small business technology", cap->small_business); |
| 114 | print_cap("Level III manageability", cap->l3manageability); |
| 115 | print_cap("IntelR Anti-Theft (AT)", cap->intel_at); |
| 116 | print_cap("IntelR Capability Licensing Service (CLS)", cap->intel_cls); |
| 117 | print_cap("IntelR Power Sharing Technology (MPC)", cap->intel_mpc); |
| 118 | print_cap("ICC Over Clocking", cap->icc_over_clocking); |
Edward O'Callaghan | 152e517 | 2014-07-13 00:28:05 +1000 | [diff] [blame] | 119 | print_cap("Protected Audio Video Path (PAVP)", cap->pavp); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 120 | print_cap("IPV6", cap->ipv6); |
| 121 | print_cap("KVM Remote Control (KVM)", cap->kvm); |
| 122 | print_cap("Outbreak Containment Heuristic (OCH)", cap->och); |
| 123 | print_cap("Virtual LAN (VLAN)", cap->vlan); |
| 124 | print_cap("TLS", cap->tls); |
| 125 | print_cap("Wireless LAN (WLAN)", cap->wlan); |
| 126 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 127 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 128 | #ifdef __SIMPLE_DEVICE__ |
| 129 | |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 130 | void intel_me8_finalize_smm(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 131 | { |
| 132 | struct me_hfs hfs; |
| 133 | u32 reg32; |
| 134 | |
Angel Pons | 2e29c3b | 2020-08-10 15:47:28 +0200 | [diff] [blame] | 135 | update_mei_base_address(); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 136 | |
| 137 | /* S3 path will have hidden this device already */ |
Angel Pons | 2e29c3b | 2020-08-10 15:47:28 +0200 | [diff] [blame] | 138 | if (!is_mei_base_address_valid()) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 139 | return; |
| 140 | |
| 141 | /* Make sure ME is in a mode that expects EOP */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 142 | reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 143 | memcpy(&hfs, ®32, sizeof(u32)); |
| 144 | |
| 145 | /* Abort and leave device alone if not normal mode */ |
| 146 | if (hfs.fpt_bad || |
| 147 | hfs.working_state != ME_HFS_CWS_NORMAL || |
| 148 | hfs.operation_mode != ME_HFS_MODE_NORMAL) |
| 149 | return; |
| 150 | |
| 151 | /* Try to send EOP command so ME stops accepting other commands */ |
| 152 | mkhi_end_of_post(); |
| 153 | |
| 154 | /* Make sure IO is disabled */ |
Angel Pons | c803f65 | 2020-06-07 22:09:01 +0200 | [diff] [blame] | 155 | pci_and_config16(PCH_ME_DEV, PCI_COMMAND, |
| 156 | ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO)); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 157 | |
| 158 | /* Hide the PCI device */ |
| 159 | RCBA32_OR(FD2, PCH_DISABLE_MEI1); |
| 160 | } |
| 161 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 162 | #else /* !__SIMPLE_DEVICE__ */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 163 | |
| 164 | /* Determine the path that we should take based on ME status */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 165 | static me_bios_path intel_me_path(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 166 | { |
| 167 | me_bios_path path = ME_DISABLE_BIOS_PATH; |
| 168 | struct me_hfs hfs; |
| 169 | struct me_gmes gmes; |
| 170 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 171 | /* S3 wake skips all MKHI messages */ |
Kyösti Mälkki | c3ed886 | 2014-06-19 19:50:51 +0300 | [diff] [blame] | 172 | if (acpi_is_wakeup_s3()) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 173 | return ME_S3WAKE_BIOS_PATH; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 174 | |
| 175 | pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS); |
| 176 | pci_read_dword_ptr(dev, &gmes, PCI_ME_GMES); |
| 177 | |
| 178 | /* Check and dump status */ |
| 179 | intel_me_status(&hfs, &gmes); |
| 180 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 181 | /* Check Current Working State */ |
| 182 | switch (hfs.working_state) { |
| 183 | case ME_HFS_CWS_NORMAL: |
| 184 | path = ME_NORMAL_BIOS_PATH; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 185 | break; |
| 186 | case ME_HFS_CWS_REC: |
| 187 | path = ME_RECOVERY_BIOS_PATH; |
| 188 | break; |
| 189 | default: |
| 190 | path = ME_DISABLE_BIOS_PATH; |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | /* Check Current Operation Mode */ |
| 195 | switch (hfs.operation_mode) { |
| 196 | case ME_HFS_MODE_NORMAL: |
| 197 | break; |
| 198 | case ME_HFS_MODE_DEBUG: |
| 199 | case ME_HFS_MODE_DIS: |
| 200 | case ME_HFS_MODE_OVER_JMPR: |
| 201 | case ME_HFS_MODE_OVER_MEI: |
| 202 | default: |
| 203 | path = ME_DISABLE_BIOS_PATH; |
| 204 | break; |
| 205 | } |
| 206 | |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 207 | /* Check for any error code and valid firmware and MBP */ |
| 208 | if (hfs.error_code || hfs.fpt_bad) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 209 | path = ME_ERROR_BIOS_PATH; |
| 210 | |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 211 | /* Check if the MBP is ready */ |
| 212 | if (!gmes.mbp_rdy) { |
Evgeny Zinoviev | 833e9ba | 2019-11-21 21:47:31 +0300 | [diff] [blame] | 213 | printk(BIOS_CRIT, "%s: mbp is not ready!\n", __func__); |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 214 | path = ME_ERROR_BIOS_PATH; |
| 215 | } |
| 216 | |
Kyösti Mälkki | be5317f | 2019-11-06 12:07:21 +0200 | [diff] [blame] | 217 | if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) { |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 218 | struct elog_event_data_me_extended data = { |
| 219 | .current_working_state = hfs.working_state, |
| 220 | .operation_state = hfs.operation_state, |
| 221 | .operation_mode = hfs.operation_mode, |
| 222 | .error_code = hfs.error_code, |
| 223 | .progress_code = gmes.progress_code, |
| 224 | .current_pmevent = gmes.current_pmevent, |
| 225 | .current_state = gmes.current_state, |
| 226 | }; |
| 227 | elog_add_event_byte(ELOG_TYPE_MANAGEMENT_ENGINE, path); |
| 228 | elog_add_event_raw(ELOG_TYPE_MANAGEMENT_ENGINE_EXT, |
| 229 | &data, sizeof(data)); |
| 230 | } |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 231 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 232 | return path; |
| 233 | } |
| 234 | |
Angel Pons | 7f32df3 | 2020-06-02 13:36:57 +0200 | [diff] [blame] | 235 | static int intel_me_read_mbp(me_bios_payload *mbp_data); |
| 236 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 237 | /* Check whether ME is present and do basic init */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 238 | static void intel_me_init(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 239 | { |
| 240 | me_bios_path path = intel_me_path(dev); |
| 241 | me_bios_payload mbp_data; |
Evgeny Zinoviev | 833e9ba | 2019-11-21 21:47:31 +0300 | [diff] [blame] | 242 | u8 me_state = 0, me_state_prev = 0; |
| 243 | bool need_reset = false; |
| 244 | struct me_hfs hfs; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 245 | |
| 246 | /* Do initial setup and determine the BIOS path */ |
Angel Pons | 2e29c3b | 2020-08-10 15:47:28 +0200 | [diff] [blame] | 247 | printk(BIOS_NOTICE, "ME: BIOS path: %s\n", me_get_bios_path_string(path)); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 248 | |
Evgeny Zinoviev | 833e9ba | 2019-11-21 21:47:31 +0300 | [diff] [blame] | 249 | get_option(&me_state, "me_state"); |
| 250 | get_option(&me_state_prev, "me_state_prev"); |
| 251 | |
| 252 | printk(BIOS_DEBUG, "ME: me_state=%u, me_state_prev=%u\n", me_state, me_state_prev); |
| 253 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 254 | switch (path) { |
| 255 | case ME_S3WAKE_BIOS_PATH: |
James Ye | a85d4a5 | 2020-02-22 20:30:49 +1100 | [diff] [blame] | 256 | #if CONFIG(HIDE_MEI_ON_ERROR) |
| 257 | case ME_ERROR_BIOS_PATH: |
| 258 | #endif |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 259 | intel_me_hide(dev); |
| 260 | break; |
| 261 | |
| 262 | case ME_NORMAL_BIOS_PATH: |
| 263 | /* Validate the extend register */ |
| 264 | if (intel_me_extend_valid(dev) < 0) |
| 265 | break; /* TODO: force recovery mode */ |
| 266 | |
| 267 | /* Prepare MEI MMIO interface */ |
| 268 | if (intel_mei_setup(dev) < 0) |
| 269 | break; |
| 270 | |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 271 | if (intel_me_read_mbp(&mbp_data)) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 272 | break; |
| 273 | |
Kyösti Mälkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 274 | if (CONFIG_DEFAULT_CONSOLE_LOGLEVEL >= BIOS_DEBUG) { |
| 275 | me_print_fw_version(&mbp_data.fw_version_name); |
| 276 | me_print_fwcaps(&mbp_data.fw_caps_sku); |
| 277 | } |
Duncan Laurie | 708f731 | 2012-07-10 15:15:41 -0700 | [diff] [blame] | 278 | |
Evgeny Zinoviev | 833e9ba | 2019-11-21 21:47:31 +0300 | [diff] [blame] | 279 | /* Put ME in Software Temporary Disable Mode, if needed */ |
| 280 | if (me_state == CMOS_ME_STATE_DISABLED |
| 281 | && CMOS_ME_STATE(me_state_prev) == CMOS_ME_STATE_NORMAL) { |
| 282 | printk(BIOS_INFO, "ME: disabling ME\n"); |
| 283 | if (enter_soft_temp_disable()) { |
| 284 | enter_soft_temp_disable_wait(); |
| 285 | need_reset = true; |
| 286 | } else { |
| 287 | printk(BIOS_ERR, "ME: failed to enter Soft Temporary Disable mode\n"); |
| 288 | } |
| 289 | |
| 290 | break; |
| 291 | } |
| 292 | |
Duncan Laurie | 708f731 | 2012-07-10 15:15:41 -0700 | [diff] [blame] | 293 | /* |
| 294 | * Leave the ME unlocked in this path. |
| 295 | * It will be locked via SMI command later. |
| 296 | */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 297 | break; |
| 298 | |
Evgeny Zinoviev | 833e9ba | 2019-11-21 21:47:31 +0300 | [diff] [blame] | 299 | case ME_DISABLE_BIOS_PATH: |
| 300 | /* Bring ME out of Soft Temporary Disable mode, if needed */ |
| 301 | pci_read_dword_ptr(dev, &hfs, PCI_ME_HFS); |
| 302 | if (hfs.operation_mode == ME_HFS_MODE_DIS |
| 303 | && me_state == CMOS_ME_STATE_NORMAL |
| 304 | && (CMOS_ME_STATE(me_state_prev) == CMOS_ME_STATE_DISABLED |
| 305 | || !CMOS_ME_CHANGED(me_state_prev))) { |
| 306 | printk(BIOS_INFO, "ME: re-enabling ME\n"); |
| 307 | |
| 308 | exit_soft_temp_disable(dev); |
| 309 | exit_soft_temp_disable_wait(dev); |
| 310 | |
| 311 | /* |
| 312 | * ME starts loading firmware immediately after writing to H_GS, |
| 313 | * but Lenovo BIOS performs a reboot after bringing ME back to |
| 314 | * Normal mode. Assume that global reset is needed. |
| 315 | */ |
| 316 | need_reset = true; |
| 317 | } else { |
| 318 | intel_me_hide(dev); |
| 319 | } |
| 320 | break; |
| 321 | |
James Ye | a85d4a5 | 2020-02-22 20:30:49 +1100 | [diff] [blame] | 322 | #if !CONFIG(HIDE_MEI_ON_ERROR) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 323 | case ME_ERROR_BIOS_PATH: |
James Ye | a85d4a5 | 2020-02-22 20:30:49 +1100 | [diff] [blame] | 324 | #endif |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 325 | case ME_RECOVERY_BIOS_PATH: |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 326 | case ME_FIRMWARE_UPDATE_BIOS_PATH: |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 327 | break; |
| 328 | } |
Evgeny Zinoviev | 833e9ba | 2019-11-21 21:47:31 +0300 | [diff] [blame] | 329 | |
| 330 | /* To avoid boot loops if ME fails to get back from disabled mode, |
| 331 | set the 'changed' bit here. */ |
| 332 | if (me_state != CMOS_ME_STATE(me_state_prev) || need_reset) { |
| 333 | u8 new_state = me_state | CMOS_ME_STATE_CHANGED; |
| 334 | set_option("me_state_prev", &new_state); |
| 335 | } |
| 336 | |
| 337 | if (need_reset) { |
| 338 | set_global_reset(true); |
| 339 | full_reset(); |
| 340 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 341 | } |
| 342 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 343 | static struct device_operations device_ops = { |
| 344 | .read_resources = pci_dev_read_resources, |
| 345 | .set_resources = pci_dev_set_resources, |
| 346 | .enable_resources = pci_dev_enable_resources, |
| 347 | .init = intel_me_init, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 348 | .ops_pci = &pci_dev_ops_pci, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | static const struct pci_driver intel_me __pci_driver = { |
| 352 | .ops = &device_ops, |
| 353 | .vendor = PCI_VENDOR_ID_INTEL, |
| 354 | .device = 0x1e3a, |
| 355 | }; |
| 356 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 357 | #endif /* !__SIMPLE_DEVICE__ */ |
| 358 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 359 | /****************************************************************************** |
| 360 | * */ |
| 361 | static u32 me_to_host_words_pending(void) |
| 362 | { |
| 363 | struct mei_csr me; |
| 364 | read_me_csr(&me); |
| 365 | if (!me.ready) |
| 366 | return 0; |
| 367 | return (me.buffer_write_ptr - me.buffer_read_ptr) & |
| 368 | (me.buffer_depth - 1); |
| 369 | } |
| 370 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 371 | /* |
| 372 | * mbp seems to be following its own flow, let's retrieve it in a dedicated |
| 373 | * function. |
| 374 | */ |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 375 | static int __unused intel_me_read_mbp(me_bios_payload *mbp_data) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 376 | { |
| 377 | mbp_header mbp_hdr; |
| 378 | mbp_item_header mbp_item_hdr; |
| 379 | u32 me2host_pending; |
| 380 | u32 mbp_item_id; |
| 381 | struct mei_csr host; |
| 382 | |
| 383 | me2host_pending = me_to_host_words_pending(); |
| 384 | if (!me2host_pending) { |
| 385 | printk(BIOS_ERR, "ME: no mbp data!\n"); |
| 386 | return -1; |
| 387 | } |
| 388 | |
| 389 | /* we know for sure that at least the header is there */ |
| 390 | mei_read_dword_ptr(&mbp_hdr, MEI_ME_CB_RW); |
| 391 | |
| 392 | if ((mbp_hdr.num_entries > (mbp_hdr.mbp_size / 2)) || |
| 393 | (me2host_pending < mbp_hdr.mbp_size)) { |
| 394 | printk(BIOS_ERR, "ME: mbp of %d entries, total size %d words" |
| 395 | " buffer contains %d words\n", |
| 396 | mbp_hdr.num_entries, mbp_hdr.mbp_size, |
| 397 | me2host_pending); |
| 398 | return -1; |
| 399 | } |
| 400 | |
| 401 | me2host_pending--; |
| 402 | memset(mbp_data, 0, sizeof(*mbp_data)); |
| 403 | |
| 404 | while (mbp_hdr.num_entries--) { |
Elyes HAOUAS | 448d9fb | 2018-05-22 12:51:27 +0200 | [diff] [blame] | 405 | u32 *copy_addr; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 406 | u32 copy_size, buffer_room; |
| 407 | void *p; |
| 408 | |
| 409 | if (!me2host_pending) { |
| 410 | printk(BIOS_ERR, "ME: no mbp data %d entries to go!\n", |
| 411 | mbp_hdr.num_entries + 1); |
| 412 | return -1; |
| 413 | } |
| 414 | |
| 415 | mei_read_dword_ptr(&mbp_item_hdr, MEI_ME_CB_RW); |
| 416 | |
| 417 | if (mbp_item_hdr.length > me2host_pending) { |
| 418 | printk(BIOS_ERR, "ME: insufficient mbp data %d " |
| 419 | "entries to go!\n", |
| 420 | mbp_hdr.num_entries + 1); |
| 421 | return -1; |
| 422 | } |
| 423 | |
| 424 | me2host_pending -= mbp_item_hdr.length; |
| 425 | |
| 426 | mbp_item_id = (((u32)mbp_item_hdr.item_id) << 8) + |
| 427 | mbp_item_hdr.app_id; |
| 428 | |
| 429 | copy_size = mbp_item_hdr.length - 1; |
| 430 | |
| 431 | #define SET_UP_COPY(field) { copy_addr = (u32 *)&mbp_data->field; \ |
| 432 | buffer_room = sizeof(mbp_data->field) / sizeof(u32); \ |
| 433 | break; \ |
| 434 | } |
| 435 | |
| 436 | p = &mbp_item_hdr; |
| 437 | printk(BIOS_INFO, "ME: MBP item header %8.8x\n", *((u32*)p)); |
| 438 | |
Elyes HAOUAS | f9de5a4 | 2018-05-03 17:21:02 +0200 | [diff] [blame] | 439 | switch (mbp_item_id) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 440 | case 0x101: |
| 441 | SET_UP_COPY(fw_version_name); |
| 442 | |
| 443 | case 0x102: |
| 444 | SET_UP_COPY(icc_profile); |
| 445 | |
| 446 | case 0x103: |
| 447 | SET_UP_COPY(at_state); |
| 448 | |
| 449 | case 0x201: |
| 450 | mbp_data->fw_caps_sku.available = 1; |
| 451 | SET_UP_COPY(fw_caps_sku.fw_capabilities); |
| 452 | |
| 453 | case 0x301: |
| 454 | SET_UP_COPY(rom_bist_data); |
| 455 | |
| 456 | case 0x401: |
| 457 | SET_UP_COPY(platform_key); |
| 458 | |
| 459 | case 0x501: |
| 460 | mbp_data->fw_plat_type.available = 1; |
| 461 | SET_UP_COPY(fw_plat_type.rule_data); |
| 462 | |
| 463 | case 0x601: |
| 464 | SET_UP_COPY(mfsintegrity); |
| 465 | |
| 466 | default: |
Vladimir Serbinenko | afc8d98 | 2014-06-11 18:52:55 +0000 | [diff] [blame] | 467 | printk(BIOS_ERR, "ME: unknown mbp item id 0x%x! Skipping\n", |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 468 | mbp_item_id); |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 469 | while (copy_size--) |
Vladimir Serbinenko | afc8d98 | 2014-06-11 18:52:55 +0000 | [diff] [blame] | 470 | read_cb(); |
| 471 | continue; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | if (buffer_room != copy_size) { |
| 475 | printk(BIOS_ERR, "ME: buffer room %d != %d copy size" |
| 476 | " for item 0x%x!!!\n", |
| 477 | buffer_room, copy_size, mbp_item_id); |
| 478 | return -1; |
| 479 | } |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 480 | while (copy_size--) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 481 | *copy_addr++ = read_cb(); |
| 482 | } |
| 483 | |
| 484 | read_host_csr(&host); |
| 485 | host.interrupt_generate = 1; |
| 486 | write_host_csr(&host); |
| 487 | |
| 488 | { |
| 489 | int cntr = 0; |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 490 | while (host.interrupt_generate) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 491 | read_host_csr(&host); |
| 492 | cntr++; |
| 493 | } |
| 494 | printk(BIOS_SPEW, "ME: mbp read OK after %d cycles\n", cntr); |
| 495 | } |
| 496 | |
| 497 | return 0; |
| 498 | } |