forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/soc/rockchip/fiq_debugger/fiq_debugger.c
....@@ -50,6 +50,7 @@
5050 #endif
5151
5252 #include <linux/uaccess.h>
53
+#include <linux/cpuhotplug.h>
5354
5455 #include "fiq_debugger.h"
5556 #include "fiq_debugger_priv.h"
....@@ -148,10 +149,7 @@
148149 static bool initial_console_enable;
149150 #endif
150151
151
-#ifdef CONFIG_FIQ_DEBUGGER_TRUST_ZONE
152
-static struct fiq_debugger_state *state_tf;
153
-#endif
154
-
152
+static struct fiq_debugger_state *g_state;
155153 static bool fiq_kgdb_enable;
156154 static bool fiq_debugger_disable;
157155
....@@ -263,10 +261,11 @@
263261 {
264262 char buf[512];
265263 size_t len;
266
- struct kmsg_dumper_iter dumper = { .active = true };
264
+ struct kmsg_dumper dumper = { .active = true };
267265
268
- kmsg_dump_rewind(&dumper);
269
- while (kmsg_dump_get_line(&dumper, true, buf,
266
+
267
+ kmsg_dump_rewind_nolock(&dumper);
268
+ while (kmsg_dump_get_line_nolock(&dumper, true, buf,
270269 sizeof(buf) - 1, &len)) {
271270 buf[len] = 0;
272271 fiq_debugger_puts(state, buf);
....@@ -1076,7 +1075,7 @@
10761075 #ifdef CONFIG_FIQ_DEBUGGER_TRUST_ZONE
10771076 void fiq_debugger_fiq(void *regs, u32 cpu)
10781077 {
1079
- struct fiq_debugger_state *state = state_tf;
1078
+ struct fiq_debugger_state *state = g_state;
10801079 bool need_irq;
10811080
10821081 if (!state)
....@@ -1443,6 +1442,18 @@
14431442 return 0;
14441443 }
14451444
1445
+static int fiq_debugger_cpu_offine_migrate_irq(unsigned int cpu)
1446
+{
1447
+ if (g_state && cpu == g_state->current_cpu) {
1448
+ unsigned int new_cpu = cpumask_any_but(cpu_online_mask, cpu);
1449
+
1450
+ if (new_cpu < nr_cpu_ids)
1451
+ g_state->current_cpu = new_cpu;
1452
+ }
1453
+
1454
+ return 0;
1455
+}
1456
+
14461457 static int fiq_debugger_probe(struct platform_device *pdev)
14471458 {
14481459 int ret;
....@@ -1450,6 +1461,7 @@
14501461 struct fiq_debugger_state *state;
14511462 int fiq;
14521463 int uart_irq;
1464
+ enum cpuhp_state cs = -1;
14531465
14541466 if (pdev->id >= MAX_FIQ_DEBUGGER_PORTS)
14551467 return -EINVAL;
....@@ -1555,7 +1567,7 @@
15551567 pr_err("%s: could not install nmi irq handler\n", __func__);
15561568 irq_clear_status_flags(state->uart_irq, IRQ_NOAUTOEN);
15571569 ret = request_irq(state->uart_irq, fiq_debugger_uart_irq,
1558
- IRQF_NO_SUSPEND, "debug", state);
1570
+ IRQF_NO_SUSPEND | IRQF_NOBALANCING, "debug", state);
15591571 } else {
15601572 enable_nmi(state->uart_irq);
15611573 }
....@@ -1569,6 +1581,15 @@
15691581 * can.
15701582 */
15711583 enable_irq_wake(state->uart_irq);
1584
+
1585
+ ret = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
1586
+ "soc/fiq_debugger",
1587
+ NULL,
1588
+ fiq_debugger_cpu_offine_migrate_irq);
1589
+ if (ret < 0)
1590
+ pr_err("%s: could not setup cpu offine handler\n", __func__);
1591
+ else
1592
+ cs = ret;
15721593 }
15731594
15741595 if (state->signal_irq >= 0) {
....@@ -1599,10 +1620,6 @@
15991620 if (state->no_sleep)
16001621 fiq_debugger_handle_wakeup(state);
16011622
1602
-#ifdef CONFIG_FIQ_DEBUGGER_TRUST_ZONE
1603
- state_tf = state;
1604
-#endif
1605
-
16061623 if (pdata->uart_init) {
16071624 ret = pdata->uart_init(pdev);
16081625 if (ret)
....@@ -1629,7 +1646,7 @@
16291646
16301647 /* switch to cpu0 default */
16311648 fiq_debugger_switch_cpu(state, 0);
1632
-
1649
+ g_state = state;
16331650 return 0;
16341651
16351652 err_register_irq:
....@@ -1640,6 +1657,8 @@
16401657 clk_disable(state->clk);
16411658 if (state->clk)
16421659 clk_put(state->clk);
1660
+ if (cs >= 0)
1661
+ cpuhp_remove_state_nocalls(cs);
16431662 wakeup_source_remove(&state->debugger_wake_src);
16441663 __pm_relax(&state->debugger_wake_src);
16451664 platform_set_drvdata(pdev, NULL);