162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 262306a36Sopenharmony_ci#ifndef _LINUX_KCOV_IOCTLS_H 362306a36Sopenharmony_ci#define _LINUX_KCOV_IOCTLS_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/types.h> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci/* 862306a36Sopenharmony_ci * Argument for KCOV_REMOTE_ENABLE ioctl, see Documentation/dev-tools/kcov.rst 962306a36Sopenharmony_ci * and the comment before kcov_remote_start() for usage details. 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_cistruct kcov_remote_arg { 1262306a36Sopenharmony_ci __u32 trace_mode; /* KCOV_TRACE_PC or KCOV_TRACE_CMP */ 1362306a36Sopenharmony_ci __u32 area_size; /* Length of coverage buffer in words */ 1462306a36Sopenharmony_ci __u32 num_handles; /* Size of handles array */ 1562306a36Sopenharmony_ci __aligned_u64 common_handle; 1662306a36Sopenharmony_ci __aligned_u64 handles[]; 1762306a36Sopenharmony_ci}; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define KCOV_REMOTE_MAX_HANDLES 0x100 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define KCOV_INIT_TRACE _IOR('c', 1, unsigned long) 2262306a36Sopenharmony_ci#define KCOV_ENABLE _IO('c', 100) 2362306a36Sopenharmony_ci#define KCOV_DISABLE _IO('c', 101) 2462306a36Sopenharmony_ci#define KCOV_REMOTE_ENABLE _IOW('c', 102, struct kcov_remote_arg) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_cienum { 2762306a36Sopenharmony_ci /* 2862306a36Sopenharmony_ci * Tracing coverage collection mode. 2962306a36Sopenharmony_ci * Covered PCs are collected in a per-task buffer. 3062306a36Sopenharmony_ci * In new KCOV version the mode is chosen by calling 3162306a36Sopenharmony_ci * ioctl(fd, KCOV_ENABLE, mode). In older versions the mode argument 3262306a36Sopenharmony_ci * was supposed to be 0 in such a call. So, for reasons of backward 3362306a36Sopenharmony_ci * compatibility, we have chosen the value KCOV_TRACE_PC to be 0. 3462306a36Sopenharmony_ci */ 3562306a36Sopenharmony_ci KCOV_TRACE_PC = 0, 3662306a36Sopenharmony_ci /* Collecting comparison operands mode. */ 3762306a36Sopenharmony_ci KCOV_TRACE_CMP = 1, 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* 4162306a36Sopenharmony_ci * The format for the types of collected comparisons. 4262306a36Sopenharmony_ci * 4362306a36Sopenharmony_ci * Bit 0 shows whether one of the arguments is a compile-time constant. 4462306a36Sopenharmony_ci * Bits 1 & 2 contain log2 of the argument size, up to 8 bytes. 4562306a36Sopenharmony_ci */ 4662306a36Sopenharmony_ci#define KCOV_CMP_CONST (1 << 0) 4762306a36Sopenharmony_ci#define KCOV_CMP_SIZE(n) ((n) << 1) 4862306a36Sopenharmony_ci#define KCOV_CMP_MASK KCOV_CMP_SIZE(3) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define KCOV_SUBSYSTEM_COMMON (0x00ull << 56) 5162306a36Sopenharmony_ci#define KCOV_SUBSYSTEM_USB (0x01ull << 56) 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define KCOV_SUBSYSTEM_MASK (0xffull << 56) 5462306a36Sopenharmony_ci#define KCOV_INSTANCE_MASK (0xffffffffull) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_cistatic inline __u64 kcov_remote_handle(__u64 subsys, __u64 inst) 5762306a36Sopenharmony_ci{ 5862306a36Sopenharmony_ci if (subsys & ~KCOV_SUBSYSTEM_MASK || inst & ~KCOV_INSTANCE_MASK) 5962306a36Sopenharmony_ci return 0; 6062306a36Sopenharmony_ci return subsys | inst; 6162306a36Sopenharmony_ci} 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#endif /* _LINUX_KCOV_IOCTLS_H */ 64