Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 2 | |
| 3 | #ifndef SOC_INTEL_COMMON_CSE_H |
| 4 | #define SOC_INTEL_COMMON_CSE_H |
| 5 | |
Bora Guvendik | 9405049 | 2023-03-12 12:24:58 -0700 | [diff] [blame] | 6 | #include <intelblocks/cse_telemetry.h> |
Rizwan Qureshi | b8b8ec8 | 2020-03-30 16:52:19 +0530 | [diff] [blame] | 7 | #include <types.h> |
V Sowmya | 338b83c | 2020-11-11 07:04:13 +0530 | [diff] [blame] | 8 | #include <vb2_api.h> |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 9 | |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 10 | /* MKHI Command groups */ |
Sridhar Siricilla | e9f4e56 | 2023-05-05 10:50:43 +0530 | [diff] [blame] | 11 | enum mkhi_group_id { |
| 12 | MKHI_GROUP_ID_CBM = 0x0, |
| 13 | MKHI_GROUP_ID_HMRFPO = 0x5, |
| 14 | MKHI_GROUP_ID_GEN = 0xff, |
| 15 | MKHI_GROUP_ID_BUP_COMMON = 0xf0, |
| 16 | MKHI_GROUP_ID_FWCAPS = 0x3, |
| 17 | }; |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 18 | |
| 19 | /* Global Reset Command ID */ |
Sridhar Siricilla | 1d20cfa | 2020-01-12 12:29:15 +0530 | [diff] [blame] | 20 | #define MKHI_CBM_GLOBAL_RESET_REQ 0xb |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 21 | |
Sean Rhodes | 69ed3ed | 2021-04-30 16:38:17 +0100 | [diff] [blame] | 22 | /* Set State Command ID */ |
| 23 | #define MKHI_SET_ME_DISABLE 0x3 |
| 24 | #define MKHI_SET_ME_ENABLE 0x3 |
| 25 | |
Sridhar Siricilla | 83af733 | 2020-01-08 00:13:21 +0530 | [diff] [blame] | 26 | /* Origin of Global Reset command */ |
Sridhar Siricilla | 1d20cfa | 2020-01-12 12:29:15 +0530 | [diff] [blame] | 27 | #define GR_ORIGIN_BIOS_POST 0x2 |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 28 | |
| 29 | /* HMRFPO Command Ids */ |
Sridhar Siricilla | 1d20cfa | 2020-01-12 12:29:15 +0530 | [diff] [blame] | 30 | #define MKHI_HMRFPO_ENABLE 0x1 |
| 31 | #define MKHI_HMRFPO_GET_STATUS 0x3 |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 32 | |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 33 | /* Get Firmware Version Command Id */ |
| 34 | #define MKHI_GEN_GET_FW_VERSION 0x2 |
| 35 | |
Michał Żygowski | daa1710 | 2022-10-04 10:55:38 +0200 | [diff] [blame] | 36 | /* Firmware Feature Shipment Time State Override Command Id */ |
| 37 | #define MKHI_GEN_FW_FEATURE_SHIPMENT_OVER 0x14 |
| 38 | #define ME_FW_FEATURE_PTT BIT(29) |
| 39 | |
| 40 | /* Get Firmware Feature State Command Id */ |
| 41 | #define MKHI_FWCAPS_GET_FW_FEATURE_STATE 0x02 |
| 42 | #define ME_FEATURE_STATE_RULE_ID 0x20 |
| 43 | |
Tim Wawrzynczak | 9fdd2b2 | 2021-06-18 10:34:09 -0600 | [diff] [blame] | 44 | /* MEI bus disable command. Must be sent to MEI client endpoint, not MKHI */ |
| 45 | #define MEI_BUS_DISABLE_COMMAND 0xc |
| 46 | |
Tim Wawrzynczak | 064ca18 | 2021-06-17 12:40:13 -0600 | [diff] [blame] | 47 | /* Set End-of-POST in CSE */ |
| 48 | #define MKHI_END_OF_POST 0xc |
| 49 | |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 50 | /* Boot partition info and set boot partition info command ids */ |
| 51 | #define MKHI_BUP_COMMON_GET_BOOT_PARTITION_INFO 0x1c |
| 52 | #define MKHI_BUP_COMMON_SET_BOOT_PARTITION_INFO 0x1d |
Sridhar Siricilla | 2f6d555 | 2020-04-19 23:39:02 +0530 | [diff] [blame] | 53 | #define MKHI_BUP_COMMON_DATA_CLEAR 0x20 |
Dinesh Gehlot | f963feb | 2023-03-24 06:39:33 +0000 | [diff] [blame] | 54 | #define GEN_GET_IMAGE_FW_VERSION 0x1c |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 55 | |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 56 | /* Get boot performance command id */ |
| 57 | #define MKHI_BUP_COMMON_GET_BOOT_PERF_DATA 0x8 |
| 58 | |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 59 | /* ME Current Working States */ |
Sridhar Siricilla | 1d20cfa | 2020-01-12 12:29:15 +0530 | [diff] [blame] | 60 | #define ME_HFS1_CWS_NORMAL 0x5 |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 61 | |
| 62 | /* ME Current Operation Modes */ |
Sridhar Siricilla | 1d20cfa | 2020-01-12 12:29:15 +0530 | [diff] [blame] | 63 | #define ME_HFS1_COM_NORMAL 0x0 |
| 64 | #define ME_HFS1_COM_SOFT_TEMP_DISABLE 0x3 |
| 65 | #define ME_HFS1_COM_SECOVER_MEI_MSG 0x5 |
Sridhar Siricilla | e202e67 | 2020-01-07 23:36:40 +0530 | [diff] [blame] | 66 | |
Sean Rhodes | 69ed3ed | 2021-04-30 16:38:17 +0100 | [diff] [blame] | 67 | /* ME Disable Rule */ |
| 68 | #define ME_DISABLE_RULE_ID 6 |
| 69 | #define ME_DISABLE_RULE_LENGTH 4 |
| 70 | #define ME_DISABLE_COMMAND 0 |
| 71 | #define ME_DISABLE_ATTEMPTS 3 |
| 72 | |
Sridhar Siricilla | 3d27705 | 2020-02-06 14:21:49 +0530 | [diff] [blame] | 73 | /* ME Firmware SKU Types */ |
Sridhar Siricilla | e9f4e56 | 2023-05-05 10:50:43 +0530 | [diff] [blame] | 74 | enum me_fw_sku { |
| 75 | ME_HFS3_FW_SKU_CONSUMER = 0x2, |
| 76 | ME_HFS3_FW_SKU_CORPORATE = 0x3, |
| 77 | ME_HFS3_FW_SKU_LITE = 0x5, |
| 78 | }; |
Sridhar Siricilla | 3d27705 | 2020-02-06 14:21:49 +0530 | [diff] [blame] | 79 | |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 80 | /* Number of cse boot performance data */ |
| 81 | #define NUM_CSE_BOOT_PERF_DATA 64 |
| 82 | |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 83 | /* HFSTS register offsets in PCI config space */ |
| 84 | enum { |
| 85 | PCI_ME_HFSTS1 = 0x40, |
| 86 | PCI_ME_HFSTS2 = 0x48, |
| 87 | PCI_ME_HFSTS3 = 0x60, |
| 88 | PCI_ME_HFSTS4 = 0x64, |
| 89 | PCI_ME_HFSTS5 = 0x68, |
| 90 | PCI_ME_HFSTS6 = 0x6C, |
| 91 | }; |
| 92 | |
Dinesh Gehlot | f963feb | 2023-03-24 06:39:33 +0000 | [diff] [blame] | 93 | /* CSE partition list */ |
| 94 | enum fpt_partition_id { |
| 95 | FPT_PARTITION_NAME_UNDEFINED = 0x0, |
| 96 | FPT_PARTITION_NAME_ISHC = 0x43485349, |
| 97 | }; |
| 98 | |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 99 | /* MKHI Message Header */ |
Sridhar Siricilla | f35eee9 | 2019-09-23 19:38:21 +0530 | [diff] [blame] | 100 | struct mkhi_hdr { |
| 101 | uint8_t group_id; |
| 102 | uint8_t command:7; |
| 103 | uint8_t is_resp:1; |
| 104 | uint8_t rsvd; |
| 105 | uint8_t result; |
| 106 | } __packed; |
| 107 | |
V Sowmya | 338b83c | 2020-11-11 07:04:13 +0530 | [diff] [blame] | 108 | /* CSE FW Version */ |
| 109 | struct fw_version { |
| 110 | uint16_t major; |
| 111 | uint16_t minor; |
| 112 | uint16_t hotfix; |
| 113 | uint16_t build; |
| 114 | } __packed; |
| 115 | |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 116 | /* ME FW Version */ |
| 117 | struct me_version { |
| 118 | uint16_t minor; |
| 119 | uint16_t major; |
| 120 | uint16_t build; |
| 121 | uint16_t hotfix; |
| 122 | } __packed; |
| 123 | |
| 124 | /* ME FW Version response */ |
| 125 | struct me_fw_ver_resp { |
| 126 | struct mkhi_hdr hdr; |
| 127 | struct me_version code; |
| 128 | struct me_version rec; |
| 129 | struct me_version fitc; |
| 130 | } __packed; |
| 131 | |
Dinesh Gehlot | f963feb | 2023-03-24 06:39:33 +0000 | [diff] [blame] | 132 | /* Module data from manifest */ |
| 133 | struct flash_partition_data { |
| 134 | enum fpt_partition_id partition_id; |
| 135 | uint8_t reserved1[8]; |
| 136 | struct fw_version version; |
| 137 | uint32_t vendor_id; |
| 138 | uint32_t tcb_svn; |
| 139 | uint32_t arb_svn; |
| 140 | uint32_t vcn; |
| 141 | uint32_t reserved2[13]; |
| 142 | }; |
| 143 | |
| 144 | /* Response header for partition information request */ |
| 145 | struct fw_version_resp { |
| 146 | struct mkhi_hdr hdr; |
| 147 | uint32_t module_count; |
| 148 | struct flash_partition_data manifest_data; |
| 149 | }; |
| 150 | |
Subrata Banik | fc313d6 | 2023-04-14 01:31:29 +0530 | [diff] [blame] | 151 | /* ISHC version */ |
| 152 | struct cse_fw_ish_version_info { |
| 153 | struct fw_version prev_cse_fw_version; |
| 154 | struct fw_version cur_ish_fw_version; |
| 155 | }; |
| 156 | |
| 157 | /* CSE and ISHC version */ |
| 158 | struct cse_fw_partition_info { |
| 159 | struct fw_version cur_cse_fw_version; |
| 160 | struct cse_fw_ish_version_info ish_partition_info; |
| 161 | }; |
| 162 | |
Sridhar Siricilla | 6836da2 | 2022-02-23 23:36:45 +0530 | [diff] [blame] | 163 | /* CSE RX and TX error status */ |
| 164 | enum cse_tx_rx_status { |
| 165 | /* |
| 166 | * Transmission of HECI message is success or |
| 167 | * Reception of HECI message is success. |
| 168 | */ |
| 169 | CSE_TX_RX_SUCCESS = 0, |
| 170 | |
| 171 | /* Timeout to send a message to CSE */ |
| 172 | CSE_TX_ERR_TIMEOUT = 1, |
| 173 | |
| 174 | /* Timeout to receive the response message from CSE */ |
| 175 | CSE_RX_ERR_TIMEOUT = 2, |
| 176 | |
| 177 | /* |
| 178 | * Response length doesn't match with expected |
| 179 | * response message length |
| 180 | */ |
| 181 | CSE_RX_ERR_RESP_LEN_MISMATCH = 3, |
| 182 | |
| 183 | /* CSE is not ready during TX flow */ |
| 184 | CSE_TX_ERR_CSE_NOT_READY = 4, |
| 185 | |
| 186 | /* CSE is not ready during RX flow */ |
| 187 | CSE_RX_ERR_CSE_NOT_READY = 5, |
| 188 | |
| 189 | /* Invalid input arguments provided for TX API */ |
| 190 | CSE_TX_ERR_INPUT = 6, |
| 191 | |
| 192 | /* Invalid input arguments provided for RX API */ |
| 193 | CSE_RX_ERR_INPUT = 7, |
| 194 | }; |
| 195 | |
Tim Wawrzynczak | e380a43 | 2021-06-18 09:54:55 -0600 | [diff] [blame] | 196 | /* CSE recovery sub-error codes */ |
| 197 | enum csme_failure_reason { |
| 198 | /* No error */ |
| 199 | CSE_NO_ERROR = 0, |
| 200 | |
| 201 | /* Unspecified error */ |
| 202 | CSE_ERROR_UNSPECIFIED = 1, |
| 203 | |
| 204 | /* CSE fails to boot from RW */ |
| 205 | CSE_LITE_SKU_RW_JUMP_ERROR = 2, |
| 206 | |
| 207 | /* CSE RW boot partition access error */ |
| 208 | CSE_LITE_SKU_RW_ACCESS_ERROR = 3, |
| 209 | |
| 210 | /* Fails to set next boot partition as RW */ |
| 211 | CSE_LITE_SKU_RW_SWITCH_ERROR = 4, |
| 212 | |
| 213 | /* CSE firmware update failure */ |
| 214 | CSE_LITE_SKU_FW_UPDATE_ERROR = 5, |
| 215 | |
| 216 | /* Fails to communicate with CSE */ |
| 217 | CSE_COMMUNICATION_ERROR = 6, |
| 218 | |
| 219 | /* Fails to wipe CSE runtime data */ |
| 220 | CSE_LITE_SKU_DATA_WIPE_ERROR = 7, |
| 221 | |
| 222 | /* CSE RW is not found */ |
| 223 | CSE_LITE_SKU_RW_BLOB_NOT_FOUND = 8, |
| 224 | |
| 225 | /* CSE CBFS RW SHA-256 mismatch with the provided SHA */ |
| 226 | CSE_LITE_SKU_RW_BLOB_SHA256_MISMATCH = 9, |
| 227 | |
| 228 | /* CSE CBFS RW metadata is not found */ |
| 229 | CSE_LITE_SKU_RW_METADATA_NOT_FOUND = 10, |
| 230 | |
| 231 | /* CSE CBFS RW blob layout is not correct */ |
| 232 | CSE_LITE_SKU_LAYOUT_MISMATCH_ERROR = 11, |
Tim Wawrzynczak | 064ca18 | 2021-06-17 12:40:13 -0600 | [diff] [blame] | 233 | |
| 234 | /* Error sending EOP to CSE */ |
| 235 | CSE_EOP_FAIL = 12, |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 236 | |
| 237 | /* CSE Sub-partition update fail */ |
| 238 | CSE_LITE_SKU_SUB_PART_UPDATE_FAIL = 13, |
| 239 | |
| 240 | /* CSE sub-partition access failure */ |
| 241 | CSE_LITE_SKU_SUB_PART_ACCESS_ERR = 14, |
| 242 | |
| 243 | /* CSE CBFS sub-partition access error */ |
| 244 | CSE_LITE_SKU_SUB_PART_BLOB_ACCESS_ERR = 15, |
| 245 | |
| 246 | /* CSE Lite sub-partition update is not required */ |
| 247 | CSE_LITE_SKU_SUB_PART_UPDATE_NOT_REQ = 16, |
| 248 | |
| 249 | /* CSE Lite sub-partition layout mismatch error */ |
| 250 | CSE_LITE_SKU_SUB_PART_LAYOUT_MISMATCH_ERROR = 17, |
| 251 | |
| 252 | /* CSE Lite sub-partition update success */ |
| 253 | CSE_LITE_SKU_PART_UPDATE_SUCCESS = 18, |
Tim Wawrzynczak | e380a43 | 2021-06-18 09:54:55 -0600 | [diff] [blame] | 254 | }; |
| 255 | |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 256 | /* CSE boot performance data */ |
| 257 | struct cse_boot_perf_rsp { |
| 258 | struct mkhi_hdr hdr; |
| 259 | |
| 260 | /* Data version */ |
| 261 | uint32_t version; |
| 262 | |
| 263 | /* Data length in DWORDs, represents number of valid elements in timestamp array */ |
| 264 | uint32_t num_valid_timestamps; |
| 265 | |
| 266 | /* Boot performance data */ |
| 267 | uint32_t timestamp[NUM_CSE_BOOT_PERF_DATA]; |
| 268 | } __packed; |
| 269 | |
Subrata Banik | 0b92aa6 | 2022-06-01 06:54:44 +0000 | [diff] [blame] | 270 | /* |
| 271 | * Initialize the CSE device. |
| 272 | * |
| 273 | * Set up CSE device for use in early boot environment with temp bar. |
| 274 | */ |
| 275 | void cse_init(uintptr_t bar); |
Sridhar Siricilla | a5208f5 | 2019-08-30 17:10:24 +0530 | [diff] [blame] | 276 | |
Subrata Banik | 801dbf4 | 2022-06-01 07:56:40 +0000 | [diff] [blame] | 277 | /* Initialize the HECI devices. */ |
| 278 | void heci_init(void); |
| 279 | |
Sridhar Siricilla | a5208f5 | 2019-08-30 17:10:24 +0530 | [diff] [blame] | 280 | /* |
Jeremy Compostella | 0e1be04 | 2023-03-13 13:41:43 -0700 | [diff] [blame] | 281 | * Send message msg of size len to host from host_addr to cse_addr. |
| 282 | * Returns CSE_TX_RX_SUCCESS on success and other enum values on failure scenarios. |
| 283 | * Also, in case of errors, heci_reset() is triggered. |
| 284 | */ |
| 285 | enum cse_tx_rx_status heci_send(const void *msg, size_t len, uint8_t host_addr, |
| 286 | uint8_t client_addr); |
| 287 | |
| 288 | /* |
| 289 | * Receive message into buff not exceeding maxlen. Message is considered |
| 290 | * successfully received if a 'complete' indication is read from ME side |
| 291 | * and there was enough space in the buffer to fit that message. maxlen |
| 292 | * is updated with size of message that was received. |
| 293 | * Returns CSE_TX_RX_SUCCESS on success and other enum values on failure scenarios. |
| 294 | * Also, in case of errors, heci_reset() is triggered. |
| 295 | */ |
| 296 | enum cse_tx_rx_status heci_receive(void *buff, size_t *maxlen); |
| 297 | |
| 298 | /* |
Rizwan Qureshi | 957857d | 2021-08-30 16:43:57 +0530 | [diff] [blame] | 299 | * Send message from BIOS_HOST_ADDR to cse_addr. |
Sridhar Siricilla | a5208f5 | 2019-08-30 17:10:24 +0530 | [diff] [blame] | 300 | * Sends snd_msg of size snd_sz, and reads message into buffer pointed by |
| 301 | * rcv_msg of size rcv_sz |
Sridhar Siricilla | 6836da2 | 2022-02-23 23:36:45 +0530 | [diff] [blame] | 302 | * Returns CSE_TX_RX_SUCCESS on success and other enum values on failure scenarios. |
Sridhar Siricilla | a5208f5 | 2019-08-30 17:10:24 +0530 | [diff] [blame] | 303 | */ |
Sridhar Siricilla | 6836da2 | 2022-02-23 23:36:45 +0530 | [diff] [blame] | 304 | enum cse_tx_rx_status heci_send_receive(const void *snd_msg, size_t snd_sz, void *rcv_msg, |
| 305 | size_t *rcv_sz, uint8_t cse_addr); |
Sridhar Siricilla | a5208f5 | 2019-08-30 17:10:24 +0530 | [diff] [blame] | 306 | |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 307 | /* |
| 308 | * Attempt device reset. This is useful and perhaps only thing left to do when |
| 309 | * CPU and CSE are out of sync or CSE fails to respond. |
Sridhar Siricilla | 1d20cfa | 2020-01-12 12:29:15 +0530 | [diff] [blame] | 310 | * Returns 0 on failure and 1 on success. |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 311 | */ |
| 312 | int heci_reset(void); |
Subrata Banik | 32e0673 | 2022-01-28 02:05:15 +0530 | [diff] [blame] | 313 | /* Disable HECI1 using Sideband interface communication */ |
| 314 | void heci1_disable(void); |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 315 | |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 316 | /* Reads config value from a specified offset in the CSE PCI Config space. */ |
| 317 | uint32_t me_read_config32(int offset); |
| 318 | |
| 319 | /* |
Subrata Banik | 3710e99 | 2021-09-30 16:59:09 +0530 | [diff] [blame] | 320 | * Check if the CSE device as per function argument `devfn` is enabled in device tree |
| 321 | * and also visible on the PCI bus. |
| 322 | */ |
| 323 | bool is_cse_devfn_visible(unsigned int devfn); |
| 324 | |
| 325 | /* |
Sridhar Siricilla | 2cc6691 | 2019-08-31 11:20:34 +0530 | [diff] [blame] | 326 | * Check if the CSE device is enabled in device tree. Also check if the device |
| 327 | * is visible on the PCI bus by reading config space. |
| 328 | * Return true if device present and config space enabled, else return false. |
| 329 | */ |
| 330 | bool is_cse_enabled(void); |
| 331 | |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 332 | /* Makes the host ready to communicate with CSE */ |
| 333 | void cse_set_host_ready(void); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 334 | |
| 335 | /* |
| 336 | * Polls for ME state 'HECI_OP_MODE_SEC_OVERRIDE' for 15 seconds. |
Sridhar Siricilla | 1d20cfa | 2020-01-12 12:29:15 +0530 | [diff] [blame] | 337 | * Returns 0 on failure and 1 on success. |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 338 | */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 339 | uint8_t cse_wait_sec_override_mode(void); |
Sridhar Siricilla | b9d075b | 2019-08-31 11:38:33 +0530 | [diff] [blame] | 340 | |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 341 | enum rst_req_type { |
| 342 | GLOBAL_RESET = 1, |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 343 | CSE_RESET_ONLY = 3, |
| 344 | }; |
| 345 | |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 346 | /* |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 347 | * Sends GLOBAL_RESET_REQ cmd to CSE with reset type GLOBAL_RESET. |
Sridhar Siricilla | f2eb687 | 2019-12-05 19:54:16 +0530 | [diff] [blame] | 348 | * Returns 0 on failure and 1 on success. |
Sridhar Siricilla | d415c20 | 2019-08-31 14:54:57 +0530 | [diff] [blame] | 349 | */ |
Subrata Banik | f463dc0 | 2020-09-14 19:04:03 +0530 | [diff] [blame] | 350 | int cse_request_global_reset(void); |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 351 | /* |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 352 | * Sends HMRFPO_ENABLE command. |
| 353 | * HMRFPO - Host ME Region Flash Protection Override. |
Sridhar Siricilla | 6ad7010 | 2020-05-12 21:28:53 +0530 | [diff] [blame] | 354 | * For CSE Lite SKU, procedure to place CSE in HMRFPO (SECOVER_MEI_MSG) mode: |
| 355 | * 1. Ensure CSE boots from RO(BP1). |
| 356 | * - Set CSE's next boot partition to RO |
| 357 | * - Issue GLOBAL_RESET command to reset the system |
Sridhar Siricilla | d16187e | 2019-11-27 16:02:47 +0530 | [diff] [blame] | 358 | * 2. Send HMRFPO_ENABLE command to CSE. Further, no reset is required. |
| 359 | * |
| 360 | * The HMRFPO mode prevents CSE to execute SPI I/O cycles to CSE region, and unlocks |
| 361 | * the CSE region to perform updates to it. |
| 362 | * This command is only valid before EOP. |
| 363 | * |
| 364 | * Returns 0 on failure to send HECI command and to enable HMRFPO mode, and 1 on success. |
| 365 | * |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 366 | */ |
Sridhar Siricilla | ad6d312 | 2023-01-10 14:59:35 +0530 | [diff] [blame] | 367 | enum cb_err cse_hmrfpo_enable(void); |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * Send HMRFPO_GET_STATUS command. |
| 371 | * returns -1 on failure and 0 (DISABLED)/ 1 (LOCKED)/ 2 (ENABLED) |
| 372 | * on success. |
| 373 | */ |
Sridhar Siricilla | ff072e6 | 2019-11-27 14:55:16 +0530 | [diff] [blame] | 374 | int cse_hmrfpo_get_status(void); |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 375 | |
Sridhar Siricilla | 83af733 | 2020-01-08 00:13:21 +0530 | [diff] [blame] | 376 | /* Fixed Address MEI Header's Host Address field value */ |
| 377 | #define BIOS_HOST_ADDR 0x00 |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 378 | |
Sridhar Siricilla | 83af733 | 2020-01-08 00:13:21 +0530 | [diff] [blame] | 379 | /* Fixed Address MEI Header's ME Address field value */ |
| 380 | #define HECI_MKHI_ADDR 0x07 |
Andrey Petrov | 04a72c4 | 2017-03-01 15:51:57 -0800 | [diff] [blame] | 381 | |
Tim Wawrzynczak | 9fdd2b2 | 2021-06-18 10:34:09 -0600 | [diff] [blame] | 382 | /* Fixed Address MEI Header's ME Address for MEI bus messages */ |
| 383 | #define HECI_MEI_ADDR 0x00 |
| 384 | |
Sridhar Siricilla | 83af733 | 2020-01-08 00:13:21 +0530 | [diff] [blame] | 385 | /* HMRFPO Status types */ |
Sridhar Siricilla | 63be918 | 2020-01-19 12:38:56 +0530 | [diff] [blame] | 386 | /* Host can't access ME region */ |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 387 | #define MKHI_HMRFPO_DISABLED 0 |
Sridhar Siricilla | 63be918 | 2020-01-19 12:38:56 +0530 | [diff] [blame] | 388 | |
| 389 | /* |
| 390 | * ME Firmware locked down HMRFPO Feature. |
| 391 | * Host can't access ME region. |
| 392 | */ |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 393 | #define MKHI_HMRFPO_LOCKED 1 |
Sridhar Siricilla | 63be918 | 2020-01-19 12:38:56 +0530 | [diff] [blame] | 394 | |
| 395 | /* Host can access ME region */ |
Sridhar Siricilla | e30a0e6 | 2019-08-31 16:12:21 +0530 | [diff] [blame] | 396 | #define MKHI_HMRFPO_ENABLED 2 |
| 397 | |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 398 | /* |
Sridhar Siricilla | 24a974a | 2020-02-19 14:41:36 +0530 | [diff] [blame] | 399 | * Queries and logs ME firmware version |
| 400 | */ |
| 401 | void print_me_fw_version(void *unused); |
| 402 | |
| 403 | /* |
Johnny Lin | 72e7667 | 2021-10-09 12:35:35 +0800 | [diff] [blame] | 404 | * Queries and gets ME firmware version |
| 405 | */ |
| 406 | enum cb_err get_me_fw_version(struct me_fw_ver_resp *resp); |
| 407 | |
| 408 | /* |
Sridhar Siricilla | 8e46545 | 2019-09-23 20:59:38 +0530 | [diff] [blame] | 409 | * Checks current working operation state is normal or not. |
| 410 | * Returns true if CSE's current working state is normal, otherwise false. |
| 411 | */ |
| 412 | bool cse_is_hfs1_cws_normal(void); |
| 413 | |
| 414 | /* |
| 415 | * Checks CSE's current operation mode is normal or not. |
| 416 | * Returns true if CSE's current operation mode is normal, otherwise false. |
| 417 | */ |
| 418 | bool cse_is_hfs1_com_normal(void); |
| 419 | |
| 420 | /* |
| 421 | * Checks CSE's current operation mode is SECOVER_MEI_MSG or not. |
| 422 | * Returns true if CSE's current operation mode is SECOVER_MEI_MSG, otherwise false. |
| 423 | */ |
| 424 | bool cse_is_hfs1_com_secover_mei_msg(void); |
| 425 | |
| 426 | /* |
| 427 | * Checks CSE's current operation mode is Soft Disable Mode or not. |
| 428 | * Returns true if CSE's current operation mode is Soft Disable Mode, otherwise false. |
| 429 | */ |
| 430 | bool cse_is_hfs1_com_soft_temp_disable(void); |
| 431 | |
Sridhar Siricilla | 3465d27 | 2020-02-06 15:31:04 +0530 | [diff] [blame] | 432 | /* |
Subrata Banik | e74ebcd | 2021-12-27 10:49:19 +0000 | [diff] [blame] | 433 | * Checks CSE's spi protection mode is protected or unprotected. |
| 434 | * Returns true if CSE's spi protection mode is protected, otherwise false. |
| 435 | */ |
| 436 | bool cse_is_hfs1_spi_protected(void); |
| 437 | |
| 438 | /* |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 439 | * Checks CSE's Firmware SKU is Lite or not. |
| 440 | * Returns true if CSE's Firmware SKU is Lite, otherwise false |
Sridhar Siricilla | 3465d27 | 2020-02-06 15:31:04 +0530 | [diff] [blame] | 441 | */ |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 442 | bool cse_is_hfs3_fw_sku_lite(void); |
Sridhar Siricilla | 3465d27 | 2020-02-06 15:31:04 +0530 | [diff] [blame] | 443 | |
Sridhar Siricilla | 09ea371 | 2019-11-12 23:35:50 +0530 | [diff] [blame] | 444 | /* |
| 445 | * Polls for CSE's current operation mode 'Soft Temp Disable'. |
| 446 | * Returns 0 on failure and 1 on success. |
| 447 | */ |
| 448 | uint8_t cse_wait_com_soft_temp_disable(void); |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 449 | |
| 450 | /* |
Sridhar Siricilla | 99dbca3 | 2020-05-12 21:05:04 +0530 | [diff] [blame] | 451 | * The CSE Lite SKU supports notion of RO and RW boot partitions. The function will set |
Jon Murphy | c4e9045 | 2022-06-28 10:36:23 -0600 | [diff] [blame] | 452 | * CSE's boot partition as per ChromeOS boot modes. In normal mode, the function allows CSE to |
Sridhar Siricilla | f87ff33 | 2019-09-12 17:18:20 +0530 | [diff] [blame] | 453 | * boot from RW and triggers recovery mode if CSE fails to jump to RW. |
| 454 | * In software triggered recovery mode, the function allows CSE to boot from whatever is |
| 455 | * currently selected partition. |
| 456 | */ |
Sridhar Siricilla | 1a2b702 | 2020-12-04 02:22:28 +0530 | [diff] [blame] | 457 | void cse_fw_sync(void); |
Karthikeyan Ramasubramanian | f9cc637 | 2020-08-04 16:38:58 -0600 | [diff] [blame] | 458 | |
| 459 | /* Perform a board-specific reset sequence for CSE RO<->RW jump */ |
| 460 | void cse_board_reset(void); |
| 461 | |
Jeremy Compostella | 08b5200d | 2023-01-19 11:32:25 -0700 | [diff] [blame] | 462 | /* Perform a misc operation before CSE firmware update. */ |
| 463 | void cse_fw_update_misc_oper(void); |
| 464 | |
Tim Wawrzynczak | 09635f4 | 2021-06-18 10:08:47 -0600 | [diff] [blame] | 465 | /* Trigger vboot recovery mode on a CSE error */ |
| 466 | void cse_trigger_vboot_recovery(enum csme_failure_reason reason); |
| 467 | |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 468 | enum cse_device_state { |
| 469 | DEV_IDLE, |
| 470 | DEV_ACTIVE, |
| 471 | }; |
| 472 | |
| 473 | /* Function to get the current CSE device state as per `cse_device_state` */ |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 474 | enum cse_device_state get_cse_device_state(unsigned int devfn); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 475 | |
| 476 | /* Function that put the CSE into desired state based on `requested_state` */ |
Subrata Banik | c6e2552 | 2021-09-30 18:14:09 +0530 | [diff] [blame] | 477 | bool set_cse_device_state(unsigned int devfn, enum cse_device_state requested_state); |
Subrata Banik | a219edb | 2021-09-25 15:02:37 +0530 | [diff] [blame] | 478 | |
Krishna Prasad Bhat | 333edcc | 2021-11-26 06:52:27 +0530 | [diff] [blame] | 479 | /* |
| 480 | * Check if cse sub-parition update is required or not. |
| 481 | * Returns true if cse sub-parition update is required otherwise false. |
| 482 | */ |
| 483 | bool skip_cse_sub_part_update(void); |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 484 | |
| 485 | /* |
| 486 | * This command retrieves a set of boot performance timestamps CSME collected during |
| 487 | * the last platform boot flow. |
| 488 | */ |
Sridhar Siricilla | dd7d51d | 2023-01-10 15:05:07 +0530 | [diff] [blame] | 489 | enum cb_err cse_get_boot_performance_data(struct cse_boot_perf_rsp *boot_perf); |
Bora Guvendik | f33c9bf | 2021-11-05 23:09:25 -0700 | [diff] [blame] | 490 | |
Subrata Banik | 736f9cc | 2022-01-27 20:52:46 +0530 | [diff] [blame] | 491 | /* Function to make cse disable using PMC IPC */ |
| 492 | bool cse_disable_mei_devices(void); |
| 493 | |
Subrata Banik | 526cc3e | 2022-01-31 21:55:51 +0530 | [diff] [blame] | 494 | /* Set CSE device state to D0I3 */ |
| 495 | void cse_set_to_d0i3(void); |
| 496 | |
| 497 | /* Function sets D0I3 for all HECI devices */ |
| 498 | void heci_set_to_d0i3(void); |
| 499 | |
Subrata Banik | 80c9289 | 2022-02-01 00:26:55 +0530 | [diff] [blame] | 500 | /* Function performs the global reset lock */ |
| 501 | void cse_control_global_reset_lock(void); |
| 502 | |
Subrata Banik | 7c31d17 | 2022-02-01 00:11:29 +0530 | [diff] [blame] | 503 | /* Send End of Post (EOP) command to CSE device */ |
| 504 | void cse_send_end_of_post(void); |
| 505 | |
Subrata Banik | 32e0673 | 2022-01-28 02:05:15 +0530 | [diff] [blame] | 506 | /* |
Subrata Banik | 17a3da8 | 2022-11-24 21:51:42 +0530 | [diff] [blame] | 507 | * This function to perform essential post EOP cse related operations |
| 508 | * upon SoC selecting `SOC_INTEL_CSE_SEND_EOP_LATE` config |
| 509 | */ |
| 510 | void cse_late_finalize(void); |
| 511 | |
| 512 | /* |
Subrata Banik | 32e0673 | 2022-01-28 02:05:15 +0530 | [diff] [blame] | 513 | * SoC override API to make heci1 disable using PCR. |
| 514 | * |
| 515 | * Allow SoC to implement heci1 disable override due to PSF registers being |
| 516 | * different across SoC generation. |
| 517 | */ |
| 518 | void soc_disable_heci1_using_pcr(void); |
| 519 | |
Bora Guvendik | 860672e | 2021-09-26 17:25:48 -0700 | [diff] [blame] | 520 | /* |
Subrata Banik | fc313d6 | 2023-04-14 01:31:29 +0530 | [diff] [blame] | 521 | * SoC override API to identify if ISH Firmware existed inside CSE FPT. |
| 522 | * |
| 523 | * This override is required to avoid making default call into non-ISH |
| 524 | * supported SKU to attempt to retrieve ISH version which would results into |
| 525 | * increased boot time by 100ms+. |
| 526 | * |
| 527 | * Ideally SoC with UFS enabled would like to keep ISH enabled as well, hence |
| 528 | * identifying the UFS enabled device is enough to conclude if ISH partition is |
| 529 | * available. |
| 530 | */ |
Subrata Banik | 272ce9a | 2023-06-13 00:44:44 +0530 | [diff] [blame^] | 531 | #if CONFIG(SOC_INTEL_STORE_ISH_FW_VERSION) |
Subrata Banik | fc313d6 | 2023-04-14 01:31:29 +0530 | [diff] [blame] | 532 | bool soc_is_ish_partition_enabled(void); |
| 533 | #else |
| 534 | static inline bool soc_is_ish_partition_enabled(void) |
| 535 | { |
| 536 | /* Default implementation, ISH not enabled. */ |
| 537 | return false; |
| 538 | } |
| 539 | #endif |
| 540 | |
| 541 | /* |
Bora Guvendik | 9405049 | 2023-03-12 12:24:58 -0700 | [diff] [blame] | 542 | * Injects CSE timestamps into cbmem timestamp table. SoC code needs to |
| 543 | * implement it since timestamp definitions differ from SoC to SoC. |
| 544 | */ |
| 545 | void soc_cbmem_inject_telemetry_data(s64 *ts, s64 current_time); |
| 546 | |
| 547 | /* |
Bora Guvendik | 860672e | 2021-09-26 17:25:48 -0700 | [diff] [blame] | 548 | * Get all the timestamps CSE collected using cse_get_boot_performance_data() and |
| 549 | * insert them into the CBMEM timestamp table. |
| 550 | */ |
| 551 | void cse_get_telemetry_data(void); |
| 552 | |
Subrata Banik | da527ec | 2022-11-24 15:42:35 +0530 | [diff] [blame] | 553 | /* Function to log the cse WP information like range, if WP etc. */ |
| 554 | void cse_log_ro_write_protection_info(bool mfg_mode); |
| 555 | |
Michał Żygowski | daa1710 | 2022-10-04 10:55:38 +0200 | [diff] [blame] | 556 | /* |
| 557 | * Changes Intel PTT feature state at runtime. Global reset is required after |
| 558 | * successful HECI command completion. |
| 559 | */ |
| 560 | void cse_enable_ptt(bool state); |
| 561 | |
| 562 | /* |
| 563 | * Queries CSE for runtime status of firmware features. |
| 564 | * Returns 0 on success and < 0 on failure. |
| 565 | */ |
| 566 | enum cb_err cse_get_fw_feature_state(uint32_t *feature_state); |
| 567 | |
Sridhar Siricilla | 83af733 | 2020-01-08 00:13:21 +0530 | [diff] [blame] | 568 | #endif // SOC_INTEL_COMMON_CSE_H |