1 /* SPDX-License-Identifier: GPL-2.0-only */
6 #include <device/device.h>
9 #define ME_RETRY 100000 /* 1 second */
10 #define ME_DELAY 10 /* 10 us */
13 * Management Engine PCI registers
16 #define PCI_CPU_DEVICE PCI_DEV(0,0,0)
17 #define PCI_CPU_MEBASE_L 0x70 /* Set by MRC */
18 #define PCI_CPU_MEBASE_H 0x74 /* Set by MRC */
20 #define PCI_ME_HFS 0x40
21 #define ME_HFS_CWS_RESET 0
22 #define ME_HFS_CWS_INIT 1
23 #define ME_HFS_CWS_REC 2
24 #define ME_HFS_CWS_NORMAL 5
25 #define ME_HFS_CWS_WAIT 6
26 #define ME_HFS_CWS_TRANS 7
27 #define ME_HFS_CWS_INVALID 8
28 #define ME_HFS_STATE_PREBOOT 0
29 #define ME_HFS_STATE_M0_UMA 1
30 #define ME_HFS_STATE_M3 4
31 #define ME_HFS_STATE_M0 5
32 #define ME_HFS_STATE_BRINGUP 6
33 #define ME_HFS_STATE_ERROR 7
34 #define ME_HFS_ERROR_NONE 0
35 #define ME_HFS_ERROR_UNCAT 1
36 #define ME_HFS_ERROR_IMAGE 3
37 #define ME_HFS_ERROR_DEBUG 4
38 #define ME_HFS_MODE_NORMAL 0
39 #define ME_HFS_MODE_DEBUG 2
40 #define ME_HFS_MODE_DIS 3
41 #define ME_HFS_MODE_OVER_JMPR 4
42 #define ME_HFS_MODE_OVER_MEI 5
43 #define ME_HFS_BIOS_DRAM_ACK 1
44 #define ME_HFS_ACK_NO_DID 0
45 #define ME_HFS_ACK_RESET 1
46 #define ME_HFS_ACK_PWR_CYCLE 2
47 #define ME_HFS_ACK_S3 3
48 #define ME_HFS_ACK_S4 4
49 #define ME_HFS_ACK_S5 5
50 #define ME_HFS_ACK_GBL_RESET 6
51 #define ME_HFS_ACK_CONTINUE 7
58 u32 operation_state
: 3;
59 u32 fw_init_complete
: 1;
61 u32 update_in_progress
: 1;
63 u32 operation_mode
: 4;
65 u32 boot_options_present
: 1;
72 #define PCI_ME_UMA 0x44
85 #define PCI_ME_H_GS 0x4c
86 #define ME_INIT_DONE 1
87 #define ME_INIT_STATUS_SUCCESS 0
88 #define ME_INIT_STATUS_NOMEM 1
89 #define ME_INIT_STATUS_ERROR 2
101 #define PCI_ME_GMES 0x48
102 #define ME_GMES_PHASE_ROM 0
103 #define ME_GMES_PHASE_BUP 1
104 #define ME_GMES_PHASE_UKERNEL 2
105 #define ME_GMES_PHASE_POLICY 3
106 #define ME_GMES_PHASE_MODULE 4
107 #define ME_GMES_PHASE_UNKNOWN 5
108 #define ME_GMES_PHASE_HOST 6
112 u32 bist_in_prog
: 1;
113 u32 icc_prog_sts
: 2;
115 u32 cpu_replaced_sts
: 1;
118 u32 warm_rst_req_for_df
: 1;
119 u32 cpu_replaced_valid
: 1;
123 u32 current_state
: 8;
124 u32 current_pmevent
: 4;
125 u32 progress_code
: 4;
130 #define PCI_ME_HERES 0xbc
131 #define PCI_ME_EXT_SHA1 0x00
132 #define PCI_ME_EXT_SHA256 0x02
133 #define PCI_ME_HER(x) (0xc0+(4*(x)))
137 u32 extend_reg_algorithm
: 4;
139 u32 extend_feature_present
: 1;
140 u32 extend_reg_valid
: 1;
146 * Management Engine MEI registers
149 #define MEI_H_CB_WW 0x00
150 #define MEI_H_CSR 0x04
151 #define MEI_ME_CB_RW 0x08
152 #define MEI_ME_CSR_HA 0x0c
155 u32 interrupt_enable
: 1;
156 u32 interrupt_status
: 1;
157 u32 interrupt_generate
: 1;
161 u32 buffer_read_ptr
: 8;
162 u32 buffer_write_ptr
: 8;
166 #define MEI_ADDRESS_CORE 0x01
167 #define MEI_ADDRESS_AMT 0x02
168 #define MEI_ADDRESS_RESERVED 0x03
169 #define MEI_ADDRESS_WDT 0x04
170 #define MEI_ADDRESS_MKHI 0x07
171 #define MEI_ADDRESS_ICC 0x08
172 #define MEI_ADDRESS_THERMAL 0x09
174 #define MEI_HOST_ADDRESS 0
177 u32 client_address
: 8;
184 #define MKHI_GROUP_ID_CBM 0x00
185 #define MKHI_GROUP_ID_FWCAPS 0x03
186 #define MKHI_GROUP_ID_MDES 0x08
187 #define MKHI_GROUP_ID_GEN 0xff
189 #define MKHI_GLOBAL_RESET 0x0b
191 #define MKHI_FWCAPS_GET_RULE 0x02
192 #define MKHI_FWCAPS_SET_RULE 0x03
194 #define MKHI_DISABLE_RULE_ID 0x06
196 #define CMOS_ME_STATE(state) ((state) & 0x1)
197 #define CMOS_ME_CHANGED(state) (((state) & 0x2) >> 1)
198 #define CMOS_ME_STATE_NORMAL 0
199 #define CMOS_ME_STATE_DISABLED 1
200 #define CMOS_ME_STATE_CHANGED 2
202 #define ME_ENABLE_TIMEOUT 20000
209 #define MKHI_MDES_ENABLE 0x09
211 #define MKHI_GET_FW_VERSION 0x02
212 #define MKHI_END_OF_POST 0x0c
213 #define MKHI_FEATURE_OVERRIDE 0x14
223 struct me_fw_version
{
226 u16 code_build_number
;
230 u16 recovery_build_number
;
231 u16 recovery_hot_fix
;
234 #define HECI_EOP_STATUS_SUCCESS 0x0
235 #define HECI_EOP_PERFORM_GLOBAL_RESET 0x1
237 #define CBM_RR_GLOBAL_RESET 0x01
239 #define GLOBAL_RESET_BIOS_MRC 0x01
240 #define GLOBAL_RESET_BIOS_POST 0x02
241 #define GLOBAL_RESET_MEBX 0x03
243 struct me_global_reset
{
252 ME_RECOVERY_BIOS_PATH
,
253 ME_DISABLE_BIOS_PATH
,
254 ME_FIRMWARE_UPDATE_BIOS_PATH
,
257 /* Defined in me_common.c for both ramstage and smm */
258 const char *const me_get_bios_path_string(int path
);
260 void mei_read_dword_ptr(void *ptr
, int offset
);
261 void mei_write_dword_ptr(void *ptr
, int offset
);
263 #ifndef __SIMPLE_DEVICE__
264 bool enter_soft_temp_disable(void);
265 void enter_soft_temp_disable_wait(void);
266 void exit_soft_temp_disable(struct device
*dev
);
267 void exit_soft_temp_disable_wait(struct device
*dev
);
270 void read_host_csr(struct mei_csr
*csr
);
271 void write_host_csr(struct mei_csr
*csr
);
273 void read_me_csr(struct mei_csr
*csr
);
275 void write_cb(u32 dword
);
278 int mei_sendrecv(struct mei_header
*mei
, struct mkhi_header
*mkhi
,
279 void *req_data
, void *rsp_data
, int rsp_bytes
);
281 void update_mei_base_address(void);
282 bool is_mei_base_address_valid(void);
283 int intel_mei_setup(struct device
*dev
);
284 int intel_me_extend_valid(struct device
*dev
);
285 void intel_me_hide(struct device
*dev
);
287 /* Defined in me_status.c for both romstage and ramstage */
288 void intel_me_status(union me_hfs
*hfs
, union me_gmes
*gmes
);
290 void intel_early_me_status(void);
291 int intel_early_me_init(void);
292 int intel_early_me_uma_size(void);
293 int intel_early_me_init_done(u8 status
);
295 void intel_me_finalize_smm(void);
298 u32 major_version
: 16;
299 u32 minor_version
: 16;
300 u32 hotfix_version
: 16;
301 u32 build_version
: 16;
302 } __packed mbp_fw_version_name
;
306 u8 icc_profile_soft_strap
;
307 u8 icc_profile_index
;
309 u32 register_lock_mask
[3];
310 } __packed mbp_icc_profile
;
315 u32 manageability
: 1;
316 u32 small_business
: 1;
317 u32 l3manageability
: 1;
322 u32 icc_over_clocking
: 1;
333 } __packed mefwcaps_sku
;
337 u16 authenticate_module
: 1;
338 u16 s3authentication
: 1;
339 u16 flash_wear_out
: 1;
340 u16 flash_variable_security
: 1;
341 u16 wwan3gpresent
: 1;
344 } __packed tdt_state_flag
;
348 u8 last_theft_trigger
;
349 tdt_state_flag flags
;
350 } __packed tdt_state_info
;
353 u32 platform_target_usage_type
: 4;
354 u32 platform_target_market_type
: 2;
357 u32 intel_me_fw_image_type
: 4;
358 u32 platform_brand
: 4;
360 } __packed platform_type_rule_data
;
363 mefwcaps_sku fw_capabilities
;
371 } __packed mbp_rom_bist_data
;
378 platform_type_rule_data rule_data
;
383 mbp_fw_version_name fw_version_name
;
384 mbp_fw_caps fw_caps_sku
;
385 mbp_rom_bist_data rom_bist_data
;
386 mbp_platform_key platform_key
;
387 mbp_plat_type fw_plat_type
;
388 mbp_icc_profile icc_profile
;
389 tdt_state_info at_state
;
397 } __packed mbp_header
;
404 } __packed mbp_item_header
;
409 mefwcaps_sku caps_sku
;
413 #endif /* _INTEL_ME_H */