Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #ifndef SOC_INTEL_COMMON_BLOCK_CRASHLOG_H |
| 4 | #define SOC_INTEL_COMMON_BLOCK_CRASHLOG_H |
| 5 | |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 6 | #include <fsp/util.h> |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 7 | #include <types.h> |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 8 | |
| 9 | /* PMC CrashLog Command */ |
| 10 | #define PMC_IPC_CMD_CRASHLOG 0xA6 |
| 11 | #define PMC_IPC_CMD_ID_CRASHLOG_DISCOVERY 0x01 |
| 12 | #define PMC_IPC_CMD_ID_CRASHLOG_DISABLE 0x02 |
| 13 | #define PMC_IPC_CMD_ID_CRASHLOG_ERASE 0x04 |
| 14 | #define PMC_IPC_CMD_ID_CRASHLOG_ON_RESET 0x05 |
| 15 | #define PMC_IPC_CMD_ID_CRASHLOG_RE_ARM_ON_RESET 0x06 |
| 16 | |
| 17 | /* CPU CrashLog Mailbox commands */ |
| 18 | #define CPU_CRASHLOG_CMD_DISABLE 0 |
| 19 | #define CPU_CRASHLOG_CMD_CLEAR 2 |
| 20 | #define CPU_CRASHLOG_MAILBOX_WAIT_STALL 1 |
| 21 | #define CPU_CRASHLOG_MAILBOX_WAIT_TIMEOUT 1000 |
| 22 | #define CPU_CRASHLOG_DISC_TAB_GUID_VALID 0x1600 |
| 23 | |
| 24 | #define CRASHLOG_SIZE_DEBUG_PURPOSE 0x640 |
| 25 | |
Pratikkumar Prajapati | 5f3b654 | 2023-05-30 11:28:21 -0700 | [diff] [blame] | 26 | #define INVALID_CRASHLOG_RECORD 0xdeadbeef |
| 27 | |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 28 | /* Tag field definitions */ |
| 29 | #define CRASHLOG_DESCRIPTOR_TABLE_TAG_SOC 0x0 |
| 30 | #define CRASHLOG_DESCRIPTOR_TABLE_TAG_IOE 0x1 |
| 31 | |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 32 | /* PMC crashlog discovery structs */ |
| 33 | typedef union { |
| 34 | struct { |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 35 | u16 offset :16; |
| 36 | u16 size :13; |
| 37 | u16 assign_tag :3; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 38 | } bits; |
| 39 | u32 data; |
| 40 | } __packed pmc_crashlog_discov_region_t; |
| 41 | |
| 42 | typedef struct { |
| 43 | u32 numb_regions; |
| 44 | pmc_crashlog_discov_region_t regions[256]; |
| 45 | } __packed pmc_crashlog_desc_table_t; |
| 46 | |
| 47 | typedef union { |
| 48 | struct { |
| 49 | u32 supported :1; |
| 50 | u32 dis :1; |
| 51 | u32 discov_mechanism :2; |
| 52 | u32 size :12; |
| 53 | u32 base_offset :16; /* Start offset of CrashLog in PMC SSRAM */ |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 54 | u32 rsvd :16; |
| 55 | u32 desc_tabl_offset :16; /* Start offset of descriptor table */ |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 56 | } bits; |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 57 | u64 val_64_bits; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 58 | |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 59 | /* Converged Capability and Status - PMC */ |
| 60 | struct { |
| 61 | /* Capability */ |
| 62 | u32 supported :1; /* CrashLog feature availability bit */ |
| 63 | u32 dis :1; /* CrashLog Disable bit */ |
| 64 | u32 discov_mechanism :2; /* CrashLog discovery mechanism */ |
| 65 | u32 manu_trig_cmd :1; /* Manuel trigger command */ |
| 66 | u32 clear :1; /* Clear Command */ |
| 67 | u32 all_reset :1; /* Trigger on all reset command */ |
| 68 | u32 re_arm :1; /* Re-arm command */ |
| 69 | u32 glb_rst_trig_mask_sup:1; /* Global reset trigger mask supported */ |
| 70 | u32 rsvd :18; /* Pch Specific reserved */ |
| 71 | /* Status */ |
| 72 | u32 glb_rst_trig_mask_sts :1; /* Global reset trigger mask status */ |
| 73 | u32 crashLog_req :1; /* CrashLog requestor flow */ |
| 74 | u32 trig_armed_sts :1; /* Trigger armed status */ |
| 75 | u32 trig_all_rst :1; /* Trigger on all resets status */ |
| 76 | u32 crash_dis_sts :1; /* Crash log disabled status */ |
| 77 | u32 pch_rsvd :16; /* Pch Specific reserved */ |
| 78 | u32 desc_tabl_offset :16; /* Descriptor Table offset */ |
| 79 | } conv_bits64; |
| 80 | u64 conv_val_64_bits; |
| 81 | } __packed pmc_ipc_discovery_buf_t; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 82 | |
| 83 | /* CPU/TELEMETRY crashlog discovery structs */ |
| 84 | |
| 85 | typedef union { |
| 86 | struct { |
| 87 | u32 pcie_cap_id :16; |
| 88 | u32 cap_ver :4; |
| 89 | u32 next_cap_offset :12; |
| 90 | } fields; |
| 91 | u32 data; |
| 92 | } __packed cap_data_t; |
| 93 | |
| 94 | typedef union { |
| 95 | struct { |
| 96 | u64 devsc_ven_id :16; |
| 97 | u64 devsc_ver :4; |
| 98 | u64 devsc_len :12; |
| 99 | u64 devsc_id :16; |
| 100 | u64 num_entries :8; /*Numb of telemetry aggregators in lookup table. */ |
| 101 | u64 entries_size :8; /* Entry Size in DWORDS */ |
| 102 | } fields; |
| 103 | u64 data_64; |
| 104 | u32 data_32[2]; |
| 105 | } __packed devsc_data_t; |
| 106 | |
| 107 | typedef union { |
| 108 | struct { |
| 109 | u32 t_bir_q :3; /* tBIR, The BAR to be used */ |
| 110 | u32 discovery_table_offset :29; |
| 111 | } fields; |
| 112 | u32 data; |
| 113 | } __packed discovery_data_t; |
| 114 | |
| 115 | typedef struct { |
| 116 | cap_data_t cap_data; |
| 117 | devsc_data_t devsc_data; |
| 118 | discovery_data_t discovery_data; |
| 119 | } __packed tel_crashlog_devsc_cap_t; |
| 120 | |
| 121 | typedef union { |
| 122 | struct { |
| 123 | u64 access_type :4; |
| 124 | u64 crash_type :4; |
| 125 | u64 count :8; |
| 126 | u64 reserved :16; |
| 127 | u64 guid :32; |
| 128 | } fields; |
| 129 | u64 data; |
| 130 | } __packed cpu_crashlog_header_t; |
| 131 | |
| 132 | |
| 133 | /* Structures for CPU CrashLog mailbox interface */ |
| 134 | typedef union { |
| 135 | struct { |
| 136 | u32 command :8; |
| 137 | u32 param :8; |
| 138 | u32 reserved :15; |
| 139 | u32 busy :1; |
| 140 | } fields; |
| 141 | u32 data; |
| 142 | } __packed cpu_crashlog_mailbox_t; |
| 143 | |
| 144 | typedef union { |
| 145 | struct { |
| 146 | u32 offset :32; |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 147 | u32 size :32; |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 148 | } fields; |
| 149 | u64 data; |
| 150 | } __packed cpu_crashlog_buffer_info_t; |
| 151 | |
| 152 | typedef struct { |
| 153 | cpu_crashlog_header_t header; |
| 154 | cpu_crashlog_mailbox_t cmd_mailbox; |
| 155 | u32 mailbox_data; |
| 156 | cpu_crashlog_buffer_info_t buffers[256]; |
| 157 | } __packed cpu_crashlog_discovery_table_t; |
| 158 | |
| 159 | int cl_get_cpu_record_size(void); |
| 160 | int cl_get_pmc_record_size(void); |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 161 | int cl_get_ioe_record_size(void); |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 162 | u32 cl_get_cpu_bar_addr(void); |
| 163 | u32 cl_get_cpu_tmp_bar(void); |
| 164 | u32 cl_get_cpu_mb_int_addr(void); |
| 165 | int cl_get_total_data_size(void); |
| 166 | bool cl_pmc_sram_has_mmio_access(void); |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 167 | bool cl_ioe_sram_has_mmio_access(void); |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 168 | bool cpu_crashlog_support(void); |
| 169 | bool pmc_crashlog_support(void); |
| 170 | bool cl_cpu_data_present(void); |
| 171 | bool cl_pmc_data_present(void); |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 172 | bool cl_ioe_data_present(void); |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 173 | void cl_get_cpu_sram_data(void); |
| 174 | void cl_get_pmc_sram_data(void); |
| 175 | void reset_discovery_buffers(void); |
| 176 | void update_new_pmc_crashlog_size(u32 *pmc_crash_size); |
| 177 | void update_new_cpu_crashlog_size(u32 *cpu_crash_size); |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 178 | void update_new_ioe_crashlog_size(u32 *pmc_crash_size); |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 179 | pmc_ipc_discovery_buf_t cl_get_pmc_discovery_buf(void); |
| 180 | pmc_crashlog_desc_table_t cl_get_pmc_descriptor_table(void); |
| 181 | cpu_crashlog_discovery_table_t cl_get_cpu_discovery_table(void); |
| 182 | u32 cl_gen_cpu_bar_addr(void); |
| 183 | int cpu_cl_poll_mailbox_ready(u32 cl_mailbox_addr); |
| 184 | int cpu_cl_mailbox_cmd(u8 cmd, u8 param); |
| 185 | int cpu_cl_clear_data(void); |
| 186 | int pmc_cl_gen_descriptor_table(u32 desc_table_addr, |
| 187 | pmc_crashlog_desc_table_t *descriptor_table); |
| 188 | bool pmc_cl_discovery(void); |
| 189 | bool cpu_cl_discovery(void); |
| 190 | int cl_pmc_re_arm_after_reset(void); |
| 191 | int cl_pmc_clear(void); |
| 192 | int cl_pmc_en_gen_on_all_reboot(void); |
| 193 | bool discover_crashlog(void); |
| 194 | bool cl_copy_data_from_sram(u32 src_bar, |
| 195 | u32 offset, |
| 196 | u32 size, |
| 197 | u32 *dest_addr, |
| 198 | u32 buffer_index, |
| 199 | bool pmc_sram); |
| 200 | void collect_pmc_and_cpu_crashlog_from_srams(void); |
| 201 | bool cl_fill_cpu_records(void *cl_record); |
| 202 | bool cl_fill_pmc_records(void *cl_record); |
Pratikkumar Prajapati | e4893d6 | 2023-05-30 12:30:36 -0700 | [diff] [blame^] | 203 | bool cl_fill_ioe_records(void *cl_record); |
Francois Toguo | 15cbc3b | 2021-01-26 10:27:49 -0800 | [diff] [blame] | 204 | |
| 205 | static const EFI_GUID FW_ERR_SECTION_GUID = { |
| 206 | 0x81212a96, 0x09ed, 0x4996, |
| 207 | { 0x94, 0x71, 0x8d, 0x72, 0x9c, 0x8e, 0x69, 0xed } |
| 208 | }; |
| 209 | |
| 210 | #endif /* SOC_INTEL_COMMON_BLOCK_CRASHLOG */ |