[RAMEN9610-13997][COMMON] drivers: usb/usbpd: support role swap
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / include / linux / nmi.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * linux/include/linux/nmi.h
4 */
5 #ifndef LINUX_NMI_H
6 #define LINUX_NMI_H
7
8 #include <linux/sched.h>
9 #include <asm/irq.h>
10 #if defined(CONFIG_HAVE_NMI_WATCHDOG)
11 #include <asm/nmi.h>
12 #endif
13
14 #ifdef CONFIG_LOCKUP_DETECTOR
15 void lockup_detector_init(void);
16 void lockup_detector_soft_poweroff(void);
17 void lockup_detector_cleanup(void);
18 bool is_hardlockup(void);
19
20 extern int watchdog_user_enabled;
21 extern int nmi_watchdog_user_enabled;
22 extern int soft_watchdog_user_enabled;
23 extern int watchdog_thresh;
24 extern unsigned long watchdog_enabled;
25
26 extern struct cpumask watchdog_cpumask;
27 extern unsigned long *watchdog_cpumask_bits;
28 #ifdef CONFIG_SMP
29 extern int sysctl_softlockup_all_cpu_backtrace;
30 extern int sysctl_hardlockup_all_cpu_backtrace;
31 #else
32 #define sysctl_softlockup_all_cpu_backtrace 0
33 #define sysctl_hardlockup_all_cpu_backtrace 0
34 #endif /* !CONFIG_SMP */
35
36 #else /* CONFIG_LOCKUP_DETECTOR */
37 static inline void lockup_detector_init(void) { }
38 static inline void lockup_detector_soft_poweroff(void) { }
39 static inline void lockup_detector_cleanup(void) { }
40 #endif /* !CONFIG_LOCKUP_DETECTOR */
41
42 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
43 extern void touch_softlockup_watchdog_sched(void);
44 extern void touch_softlockup_watchdog(void);
45 extern void touch_softlockup_watchdog_sync(void);
46 extern void touch_all_softlockup_watchdogs(void);
47 extern unsigned int softlockup_panic;
48 #else
49 static inline void touch_softlockup_watchdog_sched(void) { }
50 static inline void touch_softlockup_watchdog(void) { }
51 static inline void touch_softlockup_watchdog_sync(void) { }
52 static inline void touch_all_softlockup_watchdogs(void) { }
53 #endif
54
55 #ifdef CONFIG_DETECT_HUNG_TASK
56 void reset_hung_task_detector(void);
57 #else
58 static inline void reset_hung_task_detector(void) { }
59 #endif
60
61 /*
62 * The run state of the lockup detectors is controlled by the content of the
63 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
64 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
65 *
66 * 'watchdog_user_enabled', 'nmi_watchdog_user_enabled' and
67 * 'soft_watchdog_user_enabled' are variables that are only used as an
68 * 'interface' between the parameters in /proc/sys/kernel and the internal
69 * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is
70 * handled differently because its value is not boolean, and the lockup
71 * detectors are 'suspended' while 'watchdog_thresh' is equal zero.
72 */
73 #define NMI_WATCHDOG_ENABLED_BIT 0
74 #define SOFT_WATCHDOG_ENABLED_BIT 1
75 #define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
76 #define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
77
78 #if defined(CONFIG_HARDLOCKUP_DETECTOR) || defined(CONFIG_HARDLOCKUP_DETECTOR_OTHER_CPU)
79 extern void hardlockup_detector_disable(void);
80 extern unsigned int hardlockup_panic;
81 #else
82 static inline void hardlockup_detector_disable(void) {}
83 #endif
84
85 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
86 # define NMI_WATCHDOG_SYSCTL_PERM 0644
87 #else
88 # define NMI_WATCHDOG_SYSCTL_PERM 0444
89 #endif
90
91 #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
92 extern void arch_touch_nmi_watchdog(void);
93 extern void hardlockup_detector_perf_stop(void);
94 extern void hardlockup_detector_perf_restart(void);
95 extern void hardlockup_detector_perf_disable(void);
96 extern void hardlockup_detector_perf_enable(void);
97 extern void hardlockup_detector_perf_cleanup(void);
98 extern int hardlockup_detector_perf_init(void);
99 #else
100 static inline void hardlockup_detector_perf_stop(void) { }
101 static inline void hardlockup_detector_perf_restart(void) { }
102 static inline void hardlockup_detector_perf_disable(void) { }
103 static inline void hardlockup_detector_perf_enable(void) { }
104 static inline void hardlockup_detector_perf_cleanup(void) { }
105 # if !defined(CONFIG_HAVE_NMI_WATCHDOG)
106 static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
107 static inline void arch_touch_nmi_watchdog(void) {}
108 # else
109 static inline int hardlockup_detector_perf_init(void) { return 0; }
110 # endif
111 #endif
112
113 void watchdog_nmi_stop(void);
114 void watchdog_nmi_start(void);
115 int watchdog_nmi_probe(void);
116
117 /**
118 * touch_nmi_watchdog - restart NMI watchdog timeout.
119 *
120 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
121 * may be used to reset the timeout - for code which intentionally
122 * disables interrupts for a long time. This call is stateless.
123 */
124 #if defined(CONFIG_HARDLOCKUP_DETECTOR_OTHER_CPU)
125 extern void touch_nmi_watchdog(void);
126 #else
127 static inline void touch_nmi_watchdog(void)
128 {
129 arch_touch_nmi_watchdog();
130 touch_softlockup_watchdog();
131 }
132 #endif
133 /*
134 * Create trigger_all_cpu_backtrace() out of the arch-provided
135 * base function. Return whether such support was available,
136 * to allow calling code to fall back to some other mechanism:
137 */
138 #ifdef arch_trigger_cpumask_backtrace
139 static inline bool trigger_all_cpu_backtrace(void)
140 {
141 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
142 return true;
143 }
144
145 static inline bool trigger_allbutself_cpu_backtrace(void)
146 {
147 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
148 return true;
149 }
150
151 static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
152 {
153 arch_trigger_cpumask_backtrace(mask, false);
154 return true;
155 }
156
157 static inline bool trigger_single_cpu_backtrace(int cpu)
158 {
159 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
160 return true;
161 }
162
163 /* generic implementation */
164 void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
165 bool exclude_self,
166 void (*raise)(cpumask_t *mask));
167 bool nmi_cpu_backtrace(struct pt_regs *regs);
168
169 #else
170 static inline bool trigger_all_cpu_backtrace(void)
171 {
172 return false;
173 }
174 static inline bool trigger_allbutself_cpu_backtrace(void)
175 {
176 return false;
177 }
178 static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
179 {
180 return false;
181 }
182 static inline bool trigger_single_cpu_backtrace(int cpu)
183 {
184 return false;
185 }
186 #endif
187
188 #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
189 u64 hw_nmi_get_sample_period(int watchdog_thresh);
190 #endif
191
192 #if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
193 defined(CONFIG_HARDLOCKUP_DETECTOR)
194 void watchdog_update_hrtimer_threshold(u64 period);
195 #else
196 static inline void watchdog_update_hrtimer_threshold(u64 period) { }
197 #endif
198
199 struct ctl_table;
200 extern int proc_watchdog(struct ctl_table *, int ,
201 void __user *, size_t *, loff_t *);
202 extern int proc_nmi_watchdog(struct ctl_table *, int ,
203 void __user *, size_t *, loff_t *);
204 extern int proc_soft_watchdog(struct ctl_table *, int ,
205 void __user *, size_t *, loff_t *);
206 extern int proc_watchdog_thresh(struct ctl_table *, int ,
207 void __user *, size_t *, loff_t *);
208 extern int proc_watchdog_cpumask(struct ctl_table *, int,
209 void __user *, size_t *, loff_t *);
210
211 #ifdef CONFIG_HAVE_ACPI_APEI_NMI
212 #include <asm/nmi.h>
213 #endif
214
215 #endif