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> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 12 | #include <device/mmio.h> |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 13 | #include <device/device.h> |
| 14 | #include <device/pci.h> |
Angel Pons | 7f32df3 | 2020-06-02 13:36:57 +0200 | [diff] [blame] | 15 | #include <device/pci_ops.h> |
| 16 | #include <console/console.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 17 | #include <device/pci_ids.h> |
| 18 | #include <device/pci_def.h> |
| 19 | #include <string.h> |
| 20 | #include <delay.h> |
Duncan Laurie | c1c9435 | 2012-07-13 10:11:54 -0700 | [diff] [blame] | 21 | #include <elog.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 22 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 23 | #include "me.h" |
| 24 | #include "pch.h" |
| 25 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 26 | /* Send END OF POST message to the ME */ |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 27 | static int __unused mkhi_end_of_post(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 28 | { |
| 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 Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 50 | /* Get ME firmware version */ |
Kyösti Mälkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 51 | static int __unused mkhi_get_fw_version(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 52 | { |
| 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 | |
| 81 | static 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älkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 88 | static int __unused mkhi_get_fwcaps(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 89 | { |
| 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 HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 120 | print_cap("Protected Audio Video Path (PAVP)", cap.caps_sku.pavp); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 121 | 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 Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 130 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 131 | #ifdef __SIMPLE_DEVICE__ |
| 132 | |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 133 | static void intel_me7_finalize_smm(void) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 134 | { |
| 135 | struct me_hfs hfs; |
| 136 | u32 reg32; |
| 137 | |
Angel Pons | 2e29c3b | 2020-08-10 15:47:28 +0200 | [diff] [blame] | 138 | update_mei_base_address(); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 139 | |
| 140 | /* S3 path will have hidden this device already */ |
Angel Pons | 2e29c3b | 2020-08-10 15:47:28 +0200 | [diff] [blame] | 141 | if (!is_mei_base_address_valid()) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 142 | return; |
| 143 | |
| 144 | /* Make sure ME is in a mode that expects EOP */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 145 | reg32 = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 146 | memcpy(&hfs, ®32, 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 Pons | c803f65 | 2020-06-07 22:09:01 +0200 | [diff] [blame] | 158 | pci_and_config16(PCH_ME_DEV, PCI_COMMAND, |
| 159 | ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO)); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 160 | |
| 161 | /* Hide the PCI device */ |
| 162 | RCBA32_OR(FD2, PCH_DISABLE_MEI1); |
| 163 | } |
| 164 | |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 165 | void intel_me_finalize_smm(void) |
| 166 | { |
Angel Pons | a7db40e | 2020-09-10 12:51:38 +0200 | [diff] [blame] | 167 | u16 did = pci_read_config16(PCH_ME_DEV, PCI_DEVICE_ID); |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 168 | switch (did) { |
Angel Pons | a7db40e | 2020-09-10 12:51:38 +0200 | [diff] [blame] | 169 | case 0x1c3a: |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 170 | intel_me7_finalize_smm(); |
| 171 | break; |
Angel Pons | a7db40e | 2020-09-10 12:51:38 +0200 | [diff] [blame] | 172 | case 0x1e3a: |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 173 | intel_me8_finalize_smm(); |
| 174 | break; |
| 175 | default: |
Angel Pons | a7db40e | 2020-09-10 12:51:38 +0200 | [diff] [blame] | 176 | printk(BIOS_ERR, "No finalize handler for ME %04x.\n", did); |
Stefan Reinauer | 998f3a2 | 2012-06-11 15:15:46 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 179 | |
| 180 | #else |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 181 | |
| 182 | /* Determine the path that we should take based on ME status */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 183 | static me_bios_path intel_me_path(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 184 | { |
| 185 | me_bios_path path = ME_DISABLE_BIOS_PATH; |
| 186 | struct me_hfs hfs; |
| 187 | struct me_gmes gmes; |
| 188 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 189 | /* S3 wake skips all MKHI messages */ |
Kyösti Mälkki | c3ed886 | 2014-06-19 19:50:51 +0300 | [diff] [blame] | 190 | if (acpi_is_wakeup_s3()) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 191 | return ME_S3WAKE_BIOS_PATH; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 192 | |
| 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 Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 199 | /* 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 Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 225 | /* Check for any error code and valid firmware */ |
| 226 | if (hfs.error_code || hfs.fpt_bad) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 227 | path = ME_ERROR_BIOS_PATH; |
| 228 | |
Kyösti Mälkki | be5317f | 2019-11-06 12:07:21 +0200 | [diff] [blame] | 229 | if (CONFIG(ELOG) && path != ME_NORMAL_BIOS_PATH) { |
Duncan Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 230 | 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 Laurie | 5c88c6f | 2012-09-01 14:00:23 -0700 | [diff] [blame] | 243 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 244 | return path; |
| 245 | } |
| 246 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 247 | /* Check whether ME is present and do basic init */ |
Elyes HAOUAS | dc03528 | 2018-09-18 13:28:49 +0200 | [diff] [blame] | 248 | static void intel_me_init(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 249 | { |
| 250 | me_bios_path path = intel_me_path(dev); |
| 251 | |
| 252 | /* Do initial setup and determine the BIOS path */ |
Angel Pons | 2e29c3b | 2020-08-10 15:47:28 +0200 | [diff] [blame] | 253 | 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] | 254 | |
| 255 | switch (path) { |
| 256 | case ME_S3WAKE_BIOS_PATH: |
James Ye | a85d4a5 | 2020-02-22 20:30:49 +1100 | [diff] [blame^] | 257 | case ME_DISABLE_BIOS_PATH: |
| 258 | #if CONFIG(HIDE_MEI_ON_ERROR) |
| 259 | case ME_ERROR_BIOS_PATH: |
| 260 | #endif |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 261 | 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älkki | c86fc8e | 2019-11-06 06:32:27 +0200 | [diff] [blame] | 273 | 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 Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 279 | |
| 280 | /* |
| 281 | * Leave the ME unlocked in this path. |
| 282 | * It will be locked via SMI command later. |
| 283 | */ |
| 284 | break; |
| 285 | |
James Ye | a85d4a5 | 2020-02-22 20:30:49 +1100 | [diff] [blame^] | 286 | #if !CONFIG(HIDE_MEI_ON_ERROR) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 287 | case ME_ERROR_BIOS_PATH: |
James Ye | a85d4a5 | 2020-02-22 20:30:49 +1100 | [diff] [blame^] | 288 | #endif |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 289 | case ME_RECOVERY_BIOS_PATH: |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 290 | case ME_FIRMWARE_UPDATE_BIOS_PATH: |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 291 | break; |
| 292 | } |
| 293 | } |
| 294 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 295 | static 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 Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 300 | .ops_pci = &pci_dev_ops_pci, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | static 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älkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 309 | #endif /* __SIMPLE_DEVICE__ */ |