Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Dmitry Vyukov | 5c9a875 | 2016-03-22 14:27:30 -0700 | [diff] [blame] | 2 | #ifndef _LINUX_KCOV_H |
| 3 | #define _LINUX_KCOV_H |
| 4 | |
| 5 | #include <uapi/linux/kcov.h> |
| 6 | |
| 7 | struct task_struct; |
| 8 | |
| 9 | #ifdef CONFIG_KCOV |
| 10 | |
Dmitry Vyukov | 5c9a875 | 2016-03-22 14:27:30 -0700 | [diff] [blame] | 11 | enum kcov_mode { |
| 12 | /* Coverage collection is not enabled yet. */ |
| 13 | KCOV_MODE_DISABLED = 0, |
Victor Chibotaru | ded97d2 | 2017-11-17 15:30:46 -0800 | [diff] [blame] | 14 | /* KCOV was initialized, but tracing mode hasn't been chosen yet. */ |
| 15 | KCOV_MODE_INIT = 1, |
Dmitry Vyukov | 5c9a875 | 2016-03-22 14:27:30 -0700 | [diff] [blame] | 16 | /* |
| 17 | * Tracing coverage collection mode. |
| 18 | * Covered PCs are collected in a per-task buffer. |
| 19 | */ |
Victor Chibotaru | ded97d2 | 2017-11-17 15:30:46 -0800 | [diff] [blame] | 20 | KCOV_MODE_TRACE_PC = 2, |
| 21 | /* Collecting comparison operands mode. */ |
| 22 | KCOV_MODE_TRACE_CMP = 3, |
Dmitry Vyukov | 5c9a875 | 2016-03-22 14:27:30 -0700 | [diff] [blame] | 23 | }; |
| 24 | |
Mark Rutland | 0ed557a | 2018-06-14 15:27:41 -0700 | [diff] [blame] | 25 | #define KCOV_IN_CTXSW (1 << 30) |
| 26 | |
Victor Chibotaru | ded97d2 | 2017-11-17 15:30:46 -0800 | [diff] [blame] | 27 | void kcov_task_init(struct task_struct *t); |
| 28 | void kcov_task_exit(struct task_struct *t); |
| 29 | |
Mark Rutland | 0ed557a | 2018-06-14 15:27:41 -0700 | [diff] [blame] | 30 | #define kcov_prepare_switch(t) \ |
| 31 | do { \ |
| 32 | (t)->kcov_mode |= KCOV_IN_CTXSW; \ |
| 33 | } while (0) |
| 34 | |
| 35 | #define kcov_finish_switch(t) \ |
| 36 | do { \ |
| 37 | (t)->kcov_mode &= ~KCOV_IN_CTXSW; \ |
| 38 | } while (0) |
| 39 | |
Andrey Konovalov | eec028c | 2019-12-04 16:52:43 -0800 | [diff] [blame] | 40 | /* See Documentation/dev-tools/kcov.rst for usage details. */ |
| 41 | void kcov_remote_start(u64 handle); |
| 42 | void kcov_remote_stop(void); |
| 43 | u64 kcov_common_handle(void); |
| 44 | |
| 45 | static inline void kcov_remote_start_common(u64 id) |
| 46 | { |
| 47 | kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_COMMON, id)); |
| 48 | } |
| 49 | |
| 50 | static inline void kcov_remote_start_usb(u64 id) |
| 51 | { |
| 52 | kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_USB, id)); |
| 53 | } |
| 54 | |
Dmitry Vyukov | 5c9a875 | 2016-03-22 14:27:30 -0700 | [diff] [blame] | 55 | #else |
| 56 | |
| 57 | static inline void kcov_task_init(struct task_struct *t) {} |
| 58 | static inline void kcov_task_exit(struct task_struct *t) {} |
Mark Rutland | 0ed557a | 2018-06-14 15:27:41 -0700 | [diff] [blame] | 59 | static inline void kcov_prepare_switch(struct task_struct *t) {} |
| 60 | static inline void kcov_finish_switch(struct task_struct *t) {} |
Andrey Konovalov | eec028c | 2019-12-04 16:52:43 -0800 | [diff] [blame] | 61 | static inline void kcov_remote_start(u64 handle) {} |
| 62 | static inline void kcov_remote_stop(void) {} |
| 63 | static inline u64 kcov_common_handle(void) |
| 64 | { |
| 65 | return 0; |
| 66 | } |
| 67 | static inline void kcov_remote_start_common(u64 id) {} |
| 68 | static inline void kcov_remote_start_usb(u64 id) {} |
Dmitry Vyukov | 5c9a875 | 2016-03-22 14:27:30 -0700 | [diff] [blame] | 69 | |
| 70 | #endif /* CONFIG_KCOV */ |
| 71 | #endif /* _LINUX_KCOV_H */ |