hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
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,7 +41,14 @@
4441 const char *irq_name;
4542 };
4643
47
-static DEFINE_RAW_SPINLOCK(wakeup_reason_lock);
44
+enum wakeup_reason_flag {
45
+ RESUME_NONE = 0,
46
+ RESUME_IRQ,
47
+ RESUME_ABORT,
48
+ RESUME_ABNORMAL,
49
+};
50
+
51
+static DEFINE_SPINLOCK(wakeup_reason_lock);
4852
4953 static LIST_HEAD(leaf_irqs); /* kept in ascending IRQ sorted order */
5054 static LIST_HEAD(parent_irqs); /* unordered */
....@@ -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 */
....@@ -149,17 +152,22 @@
149152 {
150153 unsigned long flags;
151154
152
- raw_spin_lock_irqsave(&wakeup_reason_lock, flags);
155
+ 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) {
155
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
162
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
156163 return;
157164 }
158165
159166 if (find_node_in_list(&parent_irqs, irq) == NULL)
160167 add_sibling_node_sorted(&leaf_irqs, irq);
161168
162
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
169
+ wakeup_reason = RESUME_IRQ;
170
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
163171 }
164172
165173 void log_threaded_irq_wakeup_reason(int irq, int parent_irq)
....@@ -177,10 +185,15 @@
177185 if (!capture_reasons)
178186 return;
179187
180
- raw_spin_lock_irqsave(&wakeup_reason_lock, flags);
188
+ spin_lock_irqsave(&wakeup_reason_lock, flags);
189
+
190
+ if (wakeup_reason == RESUME_ABNORMAL || wakeup_reason == RESUME_ABORT) {
191
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
192
+ return;
193
+ }
181194
182195 if (!capture_reasons || (find_node_in_list(&leaf_irqs, irq) != NULL)) {
183
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
196
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
184197 return;
185198 }
186199
....@@ -196,27 +209,31 @@
196209 }
197210 }
198211
199
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
212
+ 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)
204218 {
205219 unsigned long flags;
206220
207
- raw_spin_lock_irqsave(&wakeup_reason_lock, flags);
221
+ 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) {
211
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
224
+ if (wakeup_reason != RESUME_NONE) {
225
+ 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
219
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
236
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
220237 }
221238
222239 void log_suspend_abort_reason(const char *fmt, ...)
....@@ -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,20 +254,20 @@
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 {
242261 unsigned long flags;
243262
244
- raw_spin_lock_irqsave(&wakeup_reason_lock, flags);
263
+ spin_lock_irqsave(&wakeup_reason_lock, flags);
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
252
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
270
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
253271 }
254272
255273 static void print_wakeup_sources(void)
....@@ -257,26 +275,26 @@
257275 struct wakeup_irq_node *n;
258276 unsigned long flags;
259277
260
- raw_spin_lock_irqsave(&wakeup_reason_lock, flags);
278
+ spin_lock_irqsave(&wakeup_reason_lock, flags);
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);
266
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
284
+ 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");
278296
279
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
297
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
280298 }
281299
282300 static ssize_t last_resume_reason_show(struct kobject *kobj,
....@@ -286,25 +304,25 @@
286304 struct wakeup_irq_node *n;
287305 unsigned long flags;
288306
289
- raw_spin_lock_irqsave(&wakeup_reason_lock, flags);
307
+ 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);
294
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
312
+ 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
307
- raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags);
325
+ spin_unlock_irqrestore(&wakeup_reason_lock, flags);
308326
309327 return buf_offset;
310328 }
....@@ -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 = {