hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/kernel/power/wakeup_reason.c
....@@ -27,9 +27,6 @@
2727 #include <linux/notifier.h>
2828 #include <linux/suspend.h>
2929 #include <linux/slab.h>
30
-#if defined(CONFIG_ROCKCHIP_SIP)
31
-#include <linux/rockchip/rockchip_sip.h>
32
-#endif
3330
3431 /*
3532 * struct wakeup_irq_node - stores data and relationships for IRQs logged as
....@@ -44,6 +41,13 @@
4441 const char *irq_name;
4542 };
4643
44
+enum wakeup_reason_flag {
45
+ RESUME_NONE = 0,
46
+ RESUME_IRQ,
47
+ RESUME_ABORT,
48
+ RESUME_ABNORMAL,
49
+};
50
+
4751 static DEFINE_SPINLOCK(wakeup_reason_lock);
4852
4953 static LIST_HEAD(leaf_irqs); /* kept in ascending IRQ sorted order */
....@@ -56,8 +60,7 @@
5660 static struct kobject *kobj;
5761
5862 static bool capture_reasons;
59
-static bool suspend_abort;
60
-static bool abnormal_wake;
63
+static int wakeup_reason;
6164 static char non_irq_wake_reason[MAX_SUSPEND_ABORT_LEN];
6265
6366 static ktime_t last_monotime; /* monotonic time before last suspend */
....@@ -150,6 +153,10 @@
150153 unsigned long flags;
151154
152155 spin_lock_irqsave(&wakeup_reason_lock, flags);
156
+ if (wakeup_reason == RESUME_ABNORMAL || wakeup_reason == RESUME_ABORT) {
157
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
158
+ return;
159
+ }
153160
154161 if (!capture_reasons) {
155162 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
....@@ -159,6 +166,7 @@
159166 if (find_node_in_list(&parent_irqs, irq) == NULL)
160167 add_sibling_node_sorted(&leaf_irqs, irq);
161168
169
+ wakeup_reason = RESUME_IRQ;
162170 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
163171 }
164172
....@@ -179,6 +187,11 @@
179187
180188 spin_lock_irqsave(&wakeup_reason_lock, flags);
181189
190
+ if (wakeup_reason == RESUME_ABNORMAL || wakeup_reason == RESUME_ABORT) {
191
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
192
+ return;
193
+ }
194
+
182195 if (!capture_reasons || (find_node_in_list(&leaf_irqs, irq) != NULL)) {
183196 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
184197 return;
....@@ -198,6 +211,7 @@
198211
199212 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
200213 }
214
+EXPORT_SYMBOL_GPL(log_threaded_irq_wakeup_reason);
201215
202216 static void __log_abort_or_abnormal_wake(bool abort, const char *fmt,
203217 va_list args)
....@@ -207,13 +221,16 @@
207221 spin_lock_irqsave(&wakeup_reason_lock, flags);
208222
209223 /* Suspend abort or abnormal wake reason has already been logged. */
210
- if (suspend_abort || abnormal_wake) {
224
+ if (wakeup_reason != RESUME_NONE) {
211225 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
212226 return;
213227 }
214228
215
- suspend_abort = abort;
216
- abnormal_wake = !abort;
229
+ if (abort)
230
+ wakeup_reason = RESUME_ABORT;
231
+ else
232
+ wakeup_reason = RESUME_ABNORMAL;
233
+
217234 vsnprintf(non_irq_wake_reason, MAX_SUSPEND_ABORT_LEN, fmt, args);
218235
219236 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
....@@ -227,6 +244,7 @@
227244 __log_abort_or_abnormal_wake(true, fmt, args);
228245 va_end(args);
229246 }
247
+EXPORT_SYMBOL_GPL(log_suspend_abort_reason);
230248
231249 void log_abnormal_wakeup_reason(const char *fmt, ...)
232250 {
....@@ -236,6 +254,7 @@
236254 __log_abort_or_abnormal_wake(false, fmt, args);
237255 va_end(args);
238256 }
257
+EXPORT_SYMBOL_GPL(log_abnormal_wakeup_reason);
239258
240259 void clear_wakeup_reasons(void)
241260 {
....@@ -245,8 +264,7 @@
245264
246265 delete_list(&leaf_irqs);
247266 delete_list(&parent_irqs);
248
- suspend_abort = false;
249
- abnormal_wake = false;
267
+ wakeup_reason = RESUME_NONE;
250268 capture_reasons = true;
251269
252270 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
....@@ -261,17 +279,17 @@
261279
262280 capture_reasons = false;
263281
264
- if (suspend_abort) {
282
+ if (wakeup_reason == RESUME_ABORT) {
265283 pr_info("Abort: %s\n", non_irq_wake_reason);
266284 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
267285 return;
268286 }
269287
270
- if (!list_empty(&leaf_irqs))
288
+ if (wakeup_reason == RESUME_IRQ && !list_empty(&leaf_irqs))
271289 list_for_each_entry(n, &leaf_irqs, siblings)
272290 pr_info("Resume caused by IRQ %d, %s\n", n->irq,
273291 n->irq_name);
274
- else if (abnormal_wake)
292
+ else if (wakeup_reason == RESUME_ABNORMAL)
275293 pr_info("Resume caused by %s\n", non_irq_wake_reason);
276294 else
277295 pr_info("Resume cause unknown\n");
....@@ -288,19 +306,19 @@
288306
289307 spin_lock_irqsave(&wakeup_reason_lock, flags);
290308
291
- if (suspend_abort) {
309
+ if (wakeup_reason == RESUME_ABORT) {
292310 buf_offset = scnprintf(buf, PAGE_SIZE, "Abort: %s",
293311 non_irq_wake_reason);
294312 spin_unlock_irqrestore(&wakeup_reason_lock, flags);
295313 return buf_offset;
296314 }
297315
298
- if (!list_empty(&leaf_irqs))
316
+ if (wakeup_reason == RESUME_IRQ && !list_empty(&leaf_irqs))
299317 list_for_each_entry(n, &leaf_irqs, siblings)
300318 buf_offset += scnprintf(buf + buf_offset,
301319 PAGE_SIZE - buf_offset,
302320 "%d %s\n", n->irq, n->irq_name);
303
- else if (abnormal_wake)
321
+ else if (wakeup_reason == RESUME_ABNORMAL)
304322 buf_offset = scnprintf(buf, PAGE_SIZE, "-1 %s",
305323 non_irq_wake_reason);
306324
....@@ -340,37 +358,12 @@
340358 sleep_time.tv_nsec);
341359 }
342360
343
-#if defined(CONFIG_ROCKCHIP_SIP)
344
-static ssize_t total_suspend_wfi_time_show(struct kobject *kobj,
345
- struct kobj_attribute *attr,
346
- char *buf)
347
-{
348
- struct arm_smccc_res res;
349
- unsigned long wfi_time_ms;
350
-
351
- res = sip_smc_get_suspend_info(SUSPEND_WFI_TIME_MS);
352
- if (res.a0)
353
- wfi_time_ms = 0;
354
- else
355
- wfi_time_ms = res.a1;
356
-
357
- return sprintf(buf, "%lu.%02lu\n", wfi_time_ms / MSEC_PER_SEC,
358
- (wfi_time_ms % MSEC_PER_SEC) / 10);
359
-}
360
-#endif
361
-
362361 static struct kobj_attribute resume_reason = __ATTR_RO(last_resume_reason);
363362 static struct kobj_attribute suspend_time = __ATTR_RO(last_suspend_time);
364
-#if defined(CONFIG_ROCKCHIP_SIP)
365
-static struct kobj_attribute suspend_wfi_time = __ATTR_RO(total_suspend_wfi_time);
366
-#endif
367363
368364 static struct attribute *attrs[] = {
369365 &resume_reason.attr,
370366 &suspend_time.attr,
371
-#if defined(CONFIG_ROCKCHIP_SIP)
372
- &suspend_wfi_time.attr,
373
-#endif
374367 NULL,
375368 };
376369 static struct attribute_group attr_group = {