forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/soc/rockchip/rockchip_debug.c
....@@ -59,7 +59,11 @@
5959 #include <linux/irq.h>
6060 #include <linux/delay.h>
6161
62
-#include "../../staging/android/fiq_debugger/fiq_debugger_priv.h"
62
+#if IS_ENABLED(CONFIG_ROCKCHIP_MINIDUMP)
63
+#include <soc/rockchip/rk_minidump.h>
64
+#endif
65
+
66
+#include "fiq_debugger/fiq_debugger_priv.h"
6367 #include "rockchip_debug.h"
6468
6569 #define EDPCSR_LO 0x0a0
....@@ -85,6 +89,22 @@
8589 extern struct atomic_notifier_head hardlock_notifier_list;
8690 extern struct atomic_notifier_head rcu_stall_notifier_list;
8791
92
+static inline void rockchip_debug_serror_enable(void)
93
+{
94
+#ifdef CONFIG_ARM64
95
+ /* enable SError */
96
+ asm volatile("msr daifclr, #0x4");
97
+#endif
98
+}
99
+
100
+static inline void rockchip_debug_serror_disable(void)
101
+{
102
+#ifdef CONFIG_ARM64
103
+ /* disable SError */
104
+ asm volatile("msr daifset, #0x4");
105
+#endif
106
+}
107
+
88108 #if IS_ENABLED(CONFIG_FIQ_DEBUGGER)
89109 static int rockchip_debug_dump_edpcsr(struct fiq_debugger_output *output)
90110 {
....@@ -96,10 +116,7 @@
96116 void __iomem *base;
97117 u32 pu = 0, online = 0;
98118
99
-#ifdef CONFIG_ARM64
100
- /* disable SError */
101
- asm volatile("msr daifset, #0x4");
102
-#endif
119
+ rockchip_debug_serror_disable();
103120
104121 while (rockchip_cpu_debug[i]) {
105122 online = cpu_online(i);
....@@ -154,11 +171,7 @@
154171 printed = 0;
155172 }
156173
157
-#ifdef CONFIG_ARM64
158
- /* enable SError */
159
- asm volatile("msr daifclr, #0x4");
160
-#endif
161
-
174
+ rockchip_debug_serror_enable();
162175 return NOTIFY_OK;
163176 }
164177
....@@ -173,8 +186,7 @@
173186 void __iomem *base;
174187 u32 pu = 0, online = 0;
175188
176
- /* disable SError */
177
- asm volatile("msr daifset, #0x4");
189
+ rockchip_debug_serror_disable();
178190
179191 while (rockchip_cs_pmu[i]) {
180192 online = cpu_online(i);
....@@ -233,8 +245,7 @@
233245 prev_pc = NULL;
234246 printed = 0;
235247 }
236
- /* enable SError */
237
- asm volatile("msr daifclr, #0x4");
248
+ rockchip_debug_serror_enable();
238249 return NOTIFY_OK;
239250 }
240251 #else
....@@ -243,7 +254,6 @@
243254 return 0;
244255 }
245256 #endif
246
-
247257
248258 int rockchip_debug_dump_pcsr(struct fiq_debugger_output *output)
249259 {
....@@ -267,10 +277,7 @@
267277 void __iomem *base;
268278 u32 pu = 0;
269279
270
-#ifdef CONFIG_ARM64
271
- /* disable SError */
272
- asm volatile("msr daifset, #0x4");
273
-#endif
280
+ rockchip_debug_serror_disable();
274281
275282 /*
276283 * The panic handler will try to shut down the other CPUs.
....@@ -324,11 +331,6 @@
324331 printed = 0;
325332 }
326333
327
-#ifdef CONFIG_ARM64
328
- /* enable SError */
329
- asm volatile("msr daifclr, #0x4");
330
-#endif
331
-
332334 return NOTIFY_OK;
333335 }
334336
....@@ -344,8 +346,7 @@
344346 void __iomem *base;
345347 u32 pu = 0;
346348
347
- /* disable SError */
348
- asm volatile("msr daifset, #0x4");
349
+ rockchip_debug_serror_disable();
349350
350351 /*
351352 * The panic handler will try to shut down the other CPUs.
....@@ -403,8 +404,7 @@
403404 prev_pc = NULL;
404405 printed = 0;
405406 }
406
- /* enable SError */
407
- asm volatile("msr daifclr, #0x4");
407
+
408408 return NOTIFY_OK;
409409 }
410410 #else
....@@ -425,7 +425,7 @@
425425 struct irq_desc *desc;
426426
427427 if (i > nr_irqs)
428
- return -EINVAL;
428
+ return -1;
429429
430430 /* print header and calculate the width of the first column */
431431 if (i == 0) {
....@@ -439,15 +439,15 @@
439439 }
440440
441441 desc = irq_to_desc(i);
442
- if (!desc)
443
- return -EINVAL;
442
+ if (!desc || (desc->status_use_accessors & IRQ_HIDDEN))
443
+ goto outsparse;
444444
445445 if (desc->kstat_irqs)
446446 for_each_possible_cpu(j)
447447 any_count |= *per_cpu_ptr(desc->kstat_irqs, j);
448448
449
- if ((!desc->action || (desc->action && desc->action == &chained_action)) && !any_count)
450
- return -EINVAL;
449
+ if ((!desc->action) && !any_count)
450
+ goto outsparse;
451451
452452 buf += sprintf(buf, "%*d: ", prec, i);
453453 for_each_possible_cpu(j)
....@@ -463,7 +463,7 @@
463463 buf += sprintf(buf, " %8s", "None");
464464 }
465465 if (desc->irq_data.domain)
466
- buf += sprintf(buf, " %*d", prec, (int) desc->irq_data.hwirq);
466
+ buf += sprintf(buf, " %*lu", prec, desc->irq_data.hwirq);
467467 else
468468 buf += sprintf(buf, " %*s", prec, "");
469469 #ifdef CONFIG_GENERIC_IRQ_SHOW_LEVEL
....@@ -481,6 +481,8 @@
481481
482482 sprintf(buf, "\n");
483483 return 0;
484
+outsparse:
485
+ return -1;
484486 }
485487
486488 static void rockchip_panic_notify_dump_irqs(void)
....@@ -506,8 +508,73 @@
506508 rockchip_panic_notify_dump_irqs();
507509 return NOTIFY_OK;
508510 }
511
+
512
+static int rockchip_hardlock_notify(struct notifier_block *nb,
513
+ unsigned long event, void *p)
514
+{
515
+ u64 pmpcsr;
516
+ int el;
517
+ u32 pu = 0;
518
+ void *pc = NULL;
519
+ void __iomem *base;
520
+ unsigned long edpcsr;
521
+ unsigned long cpu = event;
522
+
523
+ rockchip_debug_serror_disable();
524
+
525
+ pu = (u32)readl(rockchip_cpu_debug[cpu] + EDPRSR) & EDPRSR_PU;
526
+ if (pu != EDPRSR_PU) {
527
+ pr_err("CPU%ld power down\n", cpu);
528
+ return NOTIFY_OK;
529
+ }
530
+
531
+ if (edpcsr_present) {
532
+ base = rockchip_cpu_debug[cpu];
533
+ /* Unlock EDLSR.SLK so that EDPCSRhi gets populated */
534
+ writel(EDLAR_UNLOCK, base + EDLAR);
535
+ if (sizeof(edpcsr) == 8)
536
+ edpcsr = ((u64)readl(base + EDPCSR_LO)) |
537
+ ((u64)readl(base + EDPCSR_HI) << 32);
538
+ else
539
+ edpcsr = (u32)readl(base + EDPCSR_LO);
540
+
541
+ /* NOTE: no offset on ARMv8; see DBGDEVID1.PCSROffset */
542
+ pc = (void *)(edpcsr & ~1);
543
+ } else {
544
+ base = rockchip_cs_pmu[cpu];
545
+ pmpcsr = ((u64)readl(base + PMPCSR_LO)) |
546
+ ((u64)readl(base + PMPCSR_HI) << 32);
547
+ el = (pmpcsr >> 61) & 0x3;
548
+ if (el == 2)
549
+ pmpcsr |= 0xff00000000000000;
550
+ else
551
+ pmpcsr &= 0x0fffffffffffffff;
552
+ /* NOTE: no offset on ARMv8; see DBGDEVID1.PCSROffset */
553
+ pc = (void *)(pmpcsr & ~1);
554
+ }
555
+
556
+ rockchip_debug_serror_enable();
557
+
558
+#if IS_ENABLED(CONFIG_ROCKCHIP_MINIDUMP)
559
+ rk_minidump_hardlock_notify(nb, event, pc);
560
+#endif
561
+
562
+#if !IS_ENABLED(CONFIG_BOOTPARAM_HARDLOCKUP_PANIC)
563
+ rockchip_panic_notify(nb, event, p);
564
+#endif
565
+ return NOTIFY_OK;
566
+}
567
+
509568 static struct notifier_block rockchip_panic_nb = {
510569 .notifier_call = rockchip_panic_notify,
570
+};
571
+
572
+static struct notifier_block rockchip_rcu_stall_nb = {
573
+ .notifier_call = rockchip_panic_notify,
574
+};
575
+
576
+static struct notifier_block rockchip_hardlock_nb = {
577
+ .notifier_call = rockchip_hardlock_notify,
511578 };
512579
513580 static const struct of_device_id rockchip_debug_dt_match[] __initconst = {
....@@ -525,7 +592,6 @@
525592 },
526593 { /* sentinel */ },
527594 };
528
-
529595
530596 static int __init rockchip_debug_init(void)
531597 {
....@@ -569,14 +635,15 @@
569635 return -ENODEV;
570636
571637 atomic_notifier_chain_register(&panic_notifier_list,
572
- &rockchip_panic_nb);
638
+ &rockchip_panic_nb);
639
+ if (IS_ENABLED(CONFIG_NO_GKI)) {
640
+ if (IS_ENABLED(CONFIG_HARDLOCKUP_DETECTOR))
641
+ atomic_notifier_chain_register(&hardlock_notifier_list,
642
+ &rockchip_hardlock_nb);
573643
574
- if (IS_ENABLED(CONFIG_HARDLOCKUP_DETECTOR))
575
- atomic_notifier_chain_register(&hardlock_notifier_list,
576
- &rockchip_panic_nb);
577
-
578
- atomic_notifier_chain_register(&rcu_stall_notifier_list,
579
- &rockchip_panic_nb);
644
+ atomic_notifier_chain_register(&rcu_stall_notifier_list,
645
+ &rockchip_rcu_stall_nb);
646
+ }
580647
581648 return 0;
582649 }
....@@ -588,13 +655,14 @@
588655
589656 atomic_notifier_chain_unregister(&panic_notifier_list,
590657 &rockchip_panic_nb);
658
+ if (IS_ENABLED(CONFIG_NO_GKI)) {
659
+ if (IS_ENABLED(CONFIG_HARDLOCKUP_DETECTOR))
660
+ atomic_notifier_chain_unregister(&hardlock_notifier_list,
661
+ &rockchip_hardlock_nb);
591662
592
- if (IS_ENABLED(CONFIG_HARDLOCKUP_DETECTOR))
593
- atomic_notifier_chain_unregister(&hardlock_notifier_list,
594
- &rockchip_panic_nb);
595
-
596
- atomic_notifier_chain_unregister(&rcu_stall_notifier_list,
597
- &rockchip_panic_nb);
663
+ atomic_notifier_chain_unregister(&rcu_stall_notifier_list,
664
+ &rockchip_rcu_stall_nb);
665
+ }
598666
599667 while (rockchip_cpu_debug[i])
600668 iounmap(rockchip_cpu_debug[i++]);