18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _LINUX_KCOV_H 38c2ecf20Sopenharmony_ci#define _LINUX_KCOV_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <uapi/linux/kcov.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_cistruct task_struct; 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifdef CONFIG_KCOV 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_cienum kcov_mode { 128c2ecf20Sopenharmony_ci /* Coverage collection is not enabled yet. */ 138c2ecf20Sopenharmony_ci KCOV_MODE_DISABLED = 0, 148c2ecf20Sopenharmony_ci /* KCOV was initialized, but tracing mode hasn't been chosen yet. */ 158c2ecf20Sopenharmony_ci KCOV_MODE_INIT = 1, 168c2ecf20Sopenharmony_ci /* 178c2ecf20Sopenharmony_ci * Tracing coverage collection mode. 188c2ecf20Sopenharmony_ci * Covered PCs are collected in a per-task buffer. 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_ci KCOV_MODE_TRACE_PC = 2, 218c2ecf20Sopenharmony_ci /* Collecting comparison operands mode. */ 228c2ecf20Sopenharmony_ci KCOV_MODE_TRACE_CMP = 3, 238c2ecf20Sopenharmony_ci}; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define KCOV_IN_CTXSW (1 << 30) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_civoid kcov_task_init(struct task_struct *t); 288c2ecf20Sopenharmony_civoid kcov_task_exit(struct task_struct *t); 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define kcov_prepare_switch(t) \ 318c2ecf20Sopenharmony_cido { \ 328c2ecf20Sopenharmony_ci (t)->kcov_mode |= KCOV_IN_CTXSW; \ 338c2ecf20Sopenharmony_ci} while (0) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define kcov_finish_switch(t) \ 368c2ecf20Sopenharmony_cido { \ 378c2ecf20Sopenharmony_ci (t)->kcov_mode &= ~KCOV_IN_CTXSW; \ 388c2ecf20Sopenharmony_ci} while (0) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* See Documentation/dev-tools/kcov.rst for usage details. */ 418c2ecf20Sopenharmony_civoid kcov_remote_start(u64 handle); 428c2ecf20Sopenharmony_civoid kcov_remote_stop(void); 438c2ecf20Sopenharmony_ciu64 kcov_common_handle(void); 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic inline void kcov_remote_start_common(u64 id) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_COMMON, id)); 488c2ecf20Sopenharmony_ci} 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic inline void kcov_remote_start_usb(u64 id) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_USB, id)); 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#else 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic inline void kcov_task_init(struct task_struct *t) {} 588c2ecf20Sopenharmony_cistatic inline void kcov_task_exit(struct task_struct *t) {} 598c2ecf20Sopenharmony_cistatic inline void kcov_prepare_switch(struct task_struct *t) {} 608c2ecf20Sopenharmony_cistatic inline void kcov_finish_switch(struct task_struct *t) {} 618c2ecf20Sopenharmony_cistatic inline void kcov_remote_start(u64 handle) {} 628c2ecf20Sopenharmony_cistatic inline void kcov_remote_stop(void) {} 638c2ecf20Sopenharmony_cistatic inline u64 kcov_common_handle(void) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci return 0; 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_cistatic inline void kcov_remote_start_common(u64 id) {} 688c2ecf20Sopenharmony_cistatic inline void kcov_remote_start_usb(u64 id) {} 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#endif /* CONFIG_KCOV */ 718c2ecf20Sopenharmony_ci#endif /* _LINUX_KCOV_H */ 72