Loading...
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2007 Atmel Corporation
4 */
5#include <linux/delay.h>
6#include <linux/kdebug.h>
7#include <linux/notifier.h>
8#include <linux/sched.h>
9#include <linux/sched/debug.h>
10#include <linux/hardirq.h>
11
12enum nmi_action {
13 NMI_SHOW_STATE = 1 << 0,
14 NMI_SHOW_REGS = 1 << 1,
15 NMI_DIE = 1 << 2,
16 NMI_DEBOUNCE = 1 << 3,
17};
18
19static unsigned long nmi_actions;
20
21static int nmi_debug_notify(struct notifier_block *self,
22 unsigned long val, void *data)
23{
24 struct die_args *args = data;
25
26 if (likely(val != DIE_NMI))
27 return NOTIFY_DONE;
28
29 if (nmi_actions & NMI_SHOW_STATE)
30 show_state();
31 if (nmi_actions & NMI_SHOW_REGS)
32 show_regs(args->regs);
33 if (nmi_actions & NMI_DEBOUNCE)
34 mdelay(10);
35 if (nmi_actions & NMI_DIE)
36 return NOTIFY_BAD;
37
38 return NOTIFY_OK;
39}
40
41static struct notifier_block nmi_debug_nb = {
42 .notifier_call = nmi_debug_notify,
43};
44
45static int __init nmi_debug_setup(char *str)
46{
47 char *p, *sep;
48
49 register_die_notifier(&nmi_debug_nb);
50
51 if (*str != '=')
52 return 0;
53
54 for (p = str + 1; *p; p = sep + 1) {
55 sep = strchr(p, ',');
56 if (sep)
57 *sep = 0;
58 if (strcmp(p, "state") == 0)
59 nmi_actions |= NMI_SHOW_STATE;
60 else if (strcmp(p, "regs") == 0)
61 nmi_actions |= NMI_SHOW_REGS;
62 else if (strcmp(p, "debounce") == 0)
63 nmi_actions |= NMI_DEBOUNCE;
64 else if (strcmp(p, "die") == 0)
65 nmi_actions |= NMI_DIE;
66 else
67 printk(KERN_WARNING "NMI: Unrecognized action `%s'\n",
68 p);
69 if (!sep)
70 break;
71 }
72
73 return 0;
74}
75__setup("nmi_debug", nmi_debug_setup);
1/*
2 * Copyright (C) 2007 Atmel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#include <linux/delay.h>
9#include <linux/kdebug.h>
10#include <linux/notifier.h>
11#include <linux/sched.h>
12#include <linux/sched/debug.h>
13#include <linux/hardirq.h>
14
15enum nmi_action {
16 NMI_SHOW_STATE = 1 << 0,
17 NMI_SHOW_REGS = 1 << 1,
18 NMI_DIE = 1 << 2,
19 NMI_DEBOUNCE = 1 << 3,
20};
21
22static unsigned long nmi_actions;
23
24static int nmi_debug_notify(struct notifier_block *self,
25 unsigned long val, void *data)
26{
27 struct die_args *args = data;
28
29 if (likely(val != DIE_NMI))
30 return NOTIFY_DONE;
31
32 if (nmi_actions & NMI_SHOW_STATE)
33 show_state();
34 if (nmi_actions & NMI_SHOW_REGS)
35 show_regs(args->regs);
36 if (nmi_actions & NMI_DEBOUNCE)
37 mdelay(10);
38 if (nmi_actions & NMI_DIE)
39 return NOTIFY_BAD;
40
41 return NOTIFY_OK;
42}
43
44static struct notifier_block nmi_debug_nb = {
45 .notifier_call = nmi_debug_notify,
46};
47
48static int __init nmi_debug_setup(char *str)
49{
50 char *p, *sep;
51
52 register_die_notifier(&nmi_debug_nb);
53
54 if (*str != '=')
55 return 0;
56
57 for (p = str + 1; *p; p = sep + 1) {
58 sep = strchr(p, ',');
59 if (sep)
60 *sep = 0;
61 if (strcmp(p, "state") == 0)
62 nmi_actions |= NMI_SHOW_STATE;
63 else if (strcmp(p, "regs") == 0)
64 nmi_actions |= NMI_SHOW_REGS;
65 else if (strcmp(p, "debounce") == 0)
66 nmi_actions |= NMI_DEBOUNCE;
67 else if (strcmp(p, "die") == 0)
68 nmi_actions |= NMI_DIE;
69 else
70 printk(KERN_WARNING "NMI: Unrecognized action `%s'\n",
71 p);
72 if (!sep)
73 break;
74 }
75
76 return 0;
77}
78__setup("nmi_debug", nmi_debug_setup);