2424/* Crashlog discovery header types */
2525#define CRASH_TYPE_OOBMSM 1
2626
27- /* Control Flags */
28- #define CRASHLOG_FLAG_DISABLE BIT(28)
29-
30- /*
31- * Bits 29 and 30 control the state of bit 31.
32- *
33- * Bit 29 will clear bit 31, if set, allowing a new crashlog to be captured.
34- * Bit 30 will immediately trigger a crashlog to be generated, setting bit 31.
35- * Bit 31 is the read-only status with a 1 indicating log is complete.
36- */
37- #define CRASHLOG_FLAG_TRIGGER_CLEAR BIT(29)
38- #define CRASHLOG_FLAG_TRIGGER_EXECUTE BIT(30)
39- #define CRASHLOG_FLAG_TRIGGER_COMPLETE BIT(31)
40- #define CRASHLOG_FLAG_TRIGGER_MASK GENMASK(31, 28)
41-
4227/* Crashlog Discovery Header */
4328#define CONTROL_OFFSET 0x0
4429#define GUID_OFFSET 0x4
5035/* size is in bytes */
5136#define GET_SIZE (v ) ((v) * sizeof(u32))
5237
38+ /*
39+ * Type 1 Version 0
40+ * status and control registers are combined.
41+ *
42+ * Bits 29 and 30 control the state of bit 31.
43+ * Bit 29 will clear bit 31, if set, allowing a new crashlog to be captured.
44+ * Bit 30 will immediately trigger a crashlog to be generated, setting bit 31.
45+ * Bit 31 is the read-only status with a 1 indicating log is complete.
46+ */
47+ #define TYPE1_VER0_STATUS_OFFSET 0x00
48+ #define TYPE1_VER0_CONTROL_OFFSET 0x00
49+
50+ #define TYPE1_VER0_DISABLE BIT(28)
51+ #define TYPE1_VER0_CLEAR BIT(29)
52+ #define TYPE1_VER0_EXECUTE BIT(30)
53+ #define TYPE1_VER0_COMPLETE BIT(31)
54+ #define TYPE1_VER0_TRIGGER_MASK GENMASK(31, 28)
55+
56+ /* After offset, order alphabetically, not bit ordered */
57+ struct crashlog_status {
58+ u32 offset ;
59+ u32 cleared ;
60+ u32 complete ;
61+ u32 disabled ;
62+ };
63+
64+ struct crashlog_control {
65+ u32 offset ;
66+ u32 trigger_mask ;
67+ u32 clear ;
68+ u32 disable ;
69+ u32 manual ;
70+ };
71+
72+ struct crashlog_info {
73+ const struct crashlog_status status ;
74+ const struct crashlog_control control ;
75+ };
76+
5377struct crashlog_entry {
5478 /* entry must be first member of struct */
5579 struct intel_pmt_entry entry ;
5680 struct mutex control_mutex ;
81+ const struct crashlog_info * info ;
5782};
5883
5984struct pmt_crashlog_priv {
@@ -68,38 +93,39 @@ struct pmt_crashlog_priv {
6893/* Read, modify, write the control register, setting or clearing @bit based on @set */
6994static void pmt_crashlog_rmw (struct crashlog_entry * crashlog , u32 bit , bool set )
7095{
96+ const struct crashlog_control * control = & crashlog -> info -> control ;
7197 struct intel_pmt_entry * entry = & crashlog -> entry ;
72- u32 reg = readl (entry -> disc_table + CONTROL_OFFSET );
98+ u32 reg = readl (entry -> disc_table + control -> offset );
7399
74- reg &= ~CRASHLOG_FLAG_TRIGGER_MASK ;
100+ reg &= ~control -> trigger_mask ;
75101
76102 if (set )
77103 reg |= bit ;
78104 else
79105 reg &= ~bit ;
80106
81- writel (reg , entry -> disc_table + CONTROL_OFFSET );
107+ writel (reg , entry -> disc_table + control -> offset );
82108}
83109
84110/* Read the status register and see if the specified @bit is set */
85111static bool pmt_crashlog_rc (struct crashlog_entry * crashlog , u32 bit )
86112{
87- struct intel_pmt_entry * entry = & crashlog -> entry ;
88- u32 reg = readl (entry -> disc_table + CONTROL_OFFSET );
113+ const struct crashlog_status * status = & crashlog -> info -> status ;
114+ u32 reg = readl (crashlog -> entry . disc_table + status -> offset );
89115
90116 return !!(reg & bit );
91117}
92118
93119static bool pmt_crashlog_complete (struct crashlog_entry * crashlog )
94120{
95121 /* return current value of the crashlog complete flag */
96- return pmt_crashlog_rc (crashlog , CRASHLOG_FLAG_TRIGGER_COMPLETE );
122+ return pmt_crashlog_rc (crashlog , crashlog -> info -> status . complete );
97123}
98124
99125static bool pmt_crashlog_disabled (struct crashlog_entry * crashlog )
100126{
101127 /* return current value of the crashlog disabled flag */
102- return pmt_crashlog_rc (crashlog , CRASHLOG_FLAG_DISABLE );
128+ return pmt_crashlog_rc (crashlog , crashlog -> info -> status . disabled );
103129}
104130
105131static bool pmt_crashlog_supported (struct intel_pmt_entry * entry )
@@ -120,17 +146,17 @@ static bool pmt_crashlog_supported(struct intel_pmt_entry *entry)
120146static void pmt_crashlog_set_disable (struct crashlog_entry * crashlog ,
121147 bool disable )
122148{
123- pmt_crashlog_rmw (crashlog , CRASHLOG_FLAG_DISABLE , disable );
149+ pmt_crashlog_rmw (crashlog , crashlog -> info -> control . disable , disable );
124150}
125151
126152static void pmt_crashlog_set_clear (struct crashlog_entry * crashlog )
127153{
128- pmt_crashlog_rmw (crashlog , CRASHLOG_FLAG_TRIGGER_CLEAR , true);
154+ pmt_crashlog_rmw (crashlog , crashlog -> info -> control . clear , true);
129155}
130156
131157static void pmt_crashlog_set_execute (struct crashlog_entry * crashlog )
132158{
133- pmt_crashlog_rmw (crashlog , CRASHLOG_FLAG_TRIGGER_EXECUTE , true);
159+ pmt_crashlog_rmw (crashlog , crashlog -> info -> control . manual , true);
134160}
135161
136162/*
@@ -224,6 +250,19 @@ static const struct attribute_group pmt_crashlog_group = {
224250 .attrs = pmt_crashlog_attrs ,
225251};
226252
253+ static const struct crashlog_info crashlog_type1_ver0 = {
254+ .status .offset = TYPE1_VER0_STATUS_OFFSET ,
255+ .status .cleared = TYPE1_VER0_CLEAR ,
256+ .status .complete = TYPE1_VER0_COMPLETE ,
257+ .status .disabled = TYPE1_VER0_DISABLE ,
258+
259+ .control .offset = TYPE1_VER0_CONTROL_OFFSET ,
260+ .control .trigger_mask = TYPE1_VER0_TRIGGER_MASK ,
261+ .control .clear = TYPE1_VER0_CLEAR ,
262+ .control .disable = TYPE1_VER0_DISABLE ,
263+ .control .manual = TYPE1_VER0_EXECUTE ,
264+ };
265+
227266static int pmt_crashlog_header_decode (struct intel_pmt_entry * entry ,
228267 struct device * dev )
229268{
@@ -234,9 +273,10 @@ static int pmt_crashlog_header_decode(struct intel_pmt_entry *entry,
234273 if (!pmt_crashlog_supported (entry ))
235274 return 1 ;
236275
237- /* initialize control mutex */
276+ /* initialize the crashlog struct */
238277 crashlog = container_of (entry , struct crashlog_entry , entry );
239278 mutex_init (& crashlog -> control_mutex );
279+ crashlog -> info = & crashlog_type1_ver0 ;
240280
241281 header -> access_type = GET_ACCESS (readl (disc_table ));
242282 header -> guid = readl (disc_table + GUID_OFFSET );
0 commit comments