blob: ff80b1c4266746a13ab1dc452d235a94cb19ec1f [file] [log] [blame]
Francois Toguo15cbc3b2021-01-26 10:27:49 -08001/* 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 Toguo15cbc3b2021-01-26 10:27:49 -08006#include <fsp/util.h>
Francois Toguo15cbc3b2021-01-26 10:27:49 -08007#include <types.h>
Francois Toguo15cbc3b2021-01-26 10:27:49 -08008
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
Pratikkumar Prajapati5849f5b2023-08-15 11:45:15 -070020#define CPU_CRASHLOG_WAIT_STALL 1
21#define CPU_CRASHLOG_WAIT_TIMEOUT 1000
Francois Toguo15cbc3b2021-01-26 10:27:49 -080022#define CPU_CRASHLOG_DISC_TAB_GUID_VALID 0x1600
23
24#define CRASHLOG_SIZE_DEBUG_PURPOSE 0x640
25
Pratikkumar Prajapati5f3b6542023-05-30 11:28:21 -070026#define INVALID_CRASHLOG_RECORD 0xdeadbeef
27
Pratikkumar Prajapatib757fac2023-07-31 15:44:16 -070028/*
29 * Tag field definitions.
30 * Each region pointed by the descriptor table contains TAG information. This TAG information
31 * is used to identify the type of SRAM the region belongs to, for example:
32 * - TAG 0 represents the SoC PMC region
33 * - TAG 1 represents the IOE PMC region
34 * - TAG 7 represents a special case aka metadata information. This metadata information can be
35 * SoC specific too.
36 */
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -070037#define CRASHLOG_DESCRIPTOR_TABLE_TAG_SOC 0x0
38#define CRASHLOG_DESCRIPTOR_TABLE_TAG_IOE 0x1
Pratikkumar Prajapatib757fac2023-07-31 15:44:16 -070039#define CRASHLOG_DESCRIPTOR_TABLE_TAG_META 0x7
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -070040
Francois Toguo15cbc3b2021-01-26 10:27:49 -080041/* PMC crashlog discovery structs */
42typedef union {
43 struct {
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -070044 u16 offset :16;
45 u16 size :13;
46 u16 assign_tag :3;
Francois Toguo15cbc3b2021-01-26 10:27:49 -080047 } bits;
48 u32 data;
49} __packed pmc_crashlog_discov_region_t;
50
51typedef struct {
52 u32 numb_regions;
53 pmc_crashlog_discov_region_t regions[256];
54} __packed pmc_crashlog_desc_table_t;
55
56typedef union {
57 struct {
58 u32 supported :1;
59 u32 dis :1;
60 u32 discov_mechanism :2;
61 u32 size :12;
62 u32 base_offset :16; /* Start offset of CrashLog in PMC SSRAM */
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -070063 u32 rsvd :16;
64 u32 desc_tabl_offset :16; /* Start offset of descriptor table */
Francois Toguo15cbc3b2021-01-26 10:27:49 -080065 } bits;
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -070066 u64 val_64_bits;
Francois Toguo15cbc3b2021-01-26 10:27:49 -080067
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -070068 /* Converged Capability and Status - PMC */
69 struct {
70 /* Capability */
71 u32 supported :1; /* CrashLog feature availability bit */
72 u32 dis :1; /* CrashLog Disable bit */
73 u32 discov_mechanism :2; /* CrashLog discovery mechanism */
74 u32 manu_trig_cmd :1; /* Manuel trigger command */
75 u32 clear :1; /* Clear Command */
76 u32 all_reset :1; /* Trigger on all reset command */
77 u32 re_arm :1; /* Re-arm command */
78 u32 glb_rst_trig_mask_sup:1; /* Global reset trigger mask supported */
79 u32 rsvd :18; /* Pch Specific reserved */
80 /* Status */
81 u32 glb_rst_trig_mask_sts :1; /* Global reset trigger mask status */
82 u32 crashLog_req :1; /* CrashLog requestor flow */
83 u32 trig_armed_sts :1; /* Trigger armed status */
84 u32 trig_all_rst :1; /* Trigger on all resets status */
85 u32 crash_dis_sts :1; /* Crash log disabled status */
86 u32 pch_rsvd :16; /* Pch Specific reserved */
87 u32 desc_tabl_offset :16; /* Descriptor Table offset */
88 } conv_bits64;
89 u64 conv_val_64_bits;
90} __packed pmc_ipc_discovery_buf_t;
Francois Toguo15cbc3b2021-01-26 10:27:49 -080091
92/* CPU/TELEMETRY crashlog discovery structs */
93
94typedef union {
95 struct {
96 u32 pcie_cap_id :16;
97 u32 cap_ver :4;
98 u32 next_cap_offset :12;
99 } fields;
100 u32 data;
101} __packed cap_data_t;
102
103typedef union {
104 struct {
105 u64 devsc_ven_id :16;
106 u64 devsc_ver :4;
107 u64 devsc_len :12;
108 u64 devsc_id :16;
109 u64 num_entries :8; /*Numb of telemetry aggregators in lookup table. */
110 u64 entries_size :8; /* Entry Size in DWORDS */
111 } fields;
112 u64 data_64;
113 u32 data_32[2];
114} __packed devsc_data_t;
115
116typedef union {
117 struct {
118 u32 t_bir_q :3; /* tBIR, The BAR to be used */
119 u32 discovery_table_offset :29;
120 } fields;
121 u32 data;
122} __packed discovery_data_t;
123
124typedef struct {
125 cap_data_t cap_data;
126 devsc_data_t devsc_data;
127 discovery_data_t discovery_data;
128} __packed tel_crashlog_devsc_cap_t;
129
130typedef union {
131 struct {
Pratikkumar Prajapati71e39322023-08-30 10:18:51 -0700132 u64 access_type :4;
133 u64 crash_type :4;
134 u64 count :8;
135 u64 reserved1 :4;
136 u64 clr_support :1;
137 u64 storage_off_support :1;
138 u64 reserved2 :2;
139 u64 storage_off_status :1;
140 u64 re_arm_status :1;
141 u64 reserved3 :6;
142 u64 guid :32;
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800143 } fields;
144 u64 data;
145} __packed cpu_crashlog_header_t;
146
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800147/* Structures for CPU CrashLog mailbox interface */
148typedef union {
149 struct {
150 u32 command :8;
151 u32 param :8;
152 u32 reserved :15;
153 u32 busy :1;
154 } fields;
155 u32 data;
156} __packed cpu_crashlog_mailbox_t;
157
158typedef union {
159 struct {
160 u32 offset :32;
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -0700161 u32 size :32;
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800162 } fields;
163 u64 data;
164} __packed cpu_crashlog_buffer_info_t;
165
166typedef struct {
167 cpu_crashlog_header_t header;
168 cpu_crashlog_mailbox_t cmd_mailbox;
169 u32 mailbox_data;
170 cpu_crashlog_buffer_info_t buffers[256];
171} __packed cpu_crashlog_discovery_table_t;
172
Pratikkumar Prajapati4db92132023-10-05 13:12:12 -0700173typedef struct cl_node_t {
174 u32 size;
175 void *data;
176 struct cl_node_t *next;
177} cl_node_t;
178
179cl_node_t *malloc_cl_node(size_t len);
180void free_cl_node(cl_node_t *node);
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800181int cl_get_cpu_record_size(void);
182int cl_get_pmc_record_size(void);
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -0700183int cl_get_ioe_record_size(void);
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800184u32 cl_get_cpu_bar_addr(void);
185u32 cl_get_cpu_tmp_bar(void);
186u32 cl_get_cpu_mb_int_addr(void);
187int cl_get_total_data_size(void);
188bool cl_pmc_sram_has_mmio_access(void);
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -0700189bool cl_ioe_sram_has_mmio_access(void);
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800190bool cpu_crashlog_support(void);
191bool pmc_crashlog_support(void);
192bool cl_cpu_data_present(void);
193bool cl_pmc_data_present(void);
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -0700194bool cl_ioe_data_present(void);
Pratikkumar Prajapati4db92132023-10-05 13:12:12 -0700195void cl_get_cpu_sram_data(cl_node_t *head);
196void cl_get_pmc_sram_data(cl_node_t *head);
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800197void reset_discovery_buffers(void);
198void update_new_pmc_crashlog_size(u32 *pmc_crash_size);
199void update_new_cpu_crashlog_size(u32 *cpu_crash_size);
Pratikkumar Prajapatie4893d62023-05-30 12:30:36 -0700200void update_new_ioe_crashlog_size(u32 *pmc_crash_size);
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800201pmc_ipc_discovery_buf_t cl_get_pmc_discovery_buf(void);
202pmc_crashlog_desc_table_t cl_get_pmc_descriptor_table(void);
203cpu_crashlog_discovery_table_t cl_get_cpu_discovery_table(void);
204u32 cl_gen_cpu_bar_addr(void);
205int cpu_cl_poll_mailbox_ready(u32 cl_mailbox_addr);
206int cpu_cl_mailbox_cmd(u8 cmd, u8 param);
207int cpu_cl_clear_data(void);
Pratikkumar Prajapati0f56f832023-08-15 11:56:29 -0700208void cpu_cl_rearm(void);
209void cpu_cl_cleanup(void);
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800210int pmc_cl_gen_descriptor_table(u32 desc_table_addr,
211 pmc_crashlog_desc_table_t *descriptor_table);
212bool pmc_cl_discovery(void);
213bool cpu_cl_discovery(void);
214int cl_pmc_re_arm_after_reset(void);
215int cl_pmc_clear(void);
216int cl_pmc_en_gen_on_all_reboot(void);
217bool discover_crashlog(void);
218bool cl_copy_data_from_sram(u32 src_bar,
219 u32 offset,
220 u32 size,
221 u32 *dest_addr,
222 u32 buffer_index,
223 bool pmc_sram);
Pratikkumar Prajapati4db92132023-10-05 13:12:12 -0700224void collect_pmc_and_cpu_crashlog_from_srams(cl_node_t *head);
Francois Toguo15cbc3b2021-01-26 10:27:49 -0800225static const EFI_GUID FW_ERR_SECTION_GUID = {
226 0x81212a96, 0x09ed, 0x4996,
227 { 0x94, 0x71, 0x8d, 0x72, 0x9c, 0x8e, 0x69, 0xed }
228};
229
230#endif /* SOC_INTEL_COMMON_BLOCK_CRASHLOG */