xref: /linux/include/uapi/linux/kcov.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
25c9a8750SDmitry Vyukov #ifndef _LINUX_KCOV_IOCTLS_H
35c9a8750SDmitry Vyukov #define _LINUX_KCOV_IOCTLS_H
45c9a8750SDmitry Vyukov 
55c9a8750SDmitry Vyukov #include <linux/types.h>
65c9a8750SDmitry Vyukov 
7eec028c9SAndrey Konovalov /*
8eec028c9SAndrey Konovalov  * Argument for KCOV_REMOTE_ENABLE ioctl, see Documentation/dev-tools/kcov.rst
9eec028c9SAndrey Konovalov  * and the comment before kcov_remote_start() for usage details.
10eec028c9SAndrey Konovalov  */
11eec028c9SAndrey Konovalov struct kcov_remote_arg {
12a69b83e1SAndrey Konovalov 	__u32		trace_mode;	/* KCOV_TRACE_PC or KCOV_TRACE_CMP */
13a69b83e1SAndrey Konovalov 	__u32		area_size;	/* Length of coverage buffer in words */
14a69b83e1SAndrey Konovalov 	__u32		num_handles;	/* Size of handles array */
15a69b83e1SAndrey Konovalov 	__aligned_u64	common_handle;
16*94dfc73eSGustavo A. R. Silva 	__aligned_u64	handles[];
17eec028c9SAndrey Konovalov };
18eec028c9SAndrey Konovalov 
19eec028c9SAndrey Konovalov #define KCOV_REMOTE_MAX_HANDLES		0x100
20eec028c9SAndrey Konovalov 
215c9a8750SDmitry Vyukov #define KCOV_INIT_TRACE			_IOR('c', 1, unsigned long)
225c9a8750SDmitry Vyukov #define KCOV_ENABLE			_IO('c', 100)
235c9a8750SDmitry Vyukov #define KCOV_DISABLE			_IO('c', 101)
24eec028c9SAndrey Konovalov #define KCOV_REMOTE_ENABLE		_IOW('c', 102, struct kcov_remote_arg)
255c9a8750SDmitry Vyukov 
26ded97d2cSVictor Chibotaru enum {
27ded97d2cSVictor Chibotaru 	/*
28ded97d2cSVictor Chibotaru 	 * Tracing coverage collection mode.
29ded97d2cSVictor Chibotaru 	 * Covered PCs are collected in a per-task buffer.
30ded97d2cSVictor Chibotaru 	 * In new KCOV version the mode is chosen by calling
31ded97d2cSVictor Chibotaru 	 * ioctl(fd, KCOV_ENABLE, mode). In older versions the mode argument
32ded97d2cSVictor Chibotaru 	 * was supposed to be 0 in such a call. So, for reasons of backward
33ded97d2cSVictor Chibotaru 	 * compatibility, we have chosen the value KCOV_TRACE_PC to be 0.
34ded97d2cSVictor Chibotaru 	 */
35ded97d2cSVictor Chibotaru 	KCOV_TRACE_PC = 0,
36ded97d2cSVictor Chibotaru 	/* Collecting comparison operands mode. */
37ded97d2cSVictor Chibotaru 	KCOV_TRACE_CMP = 1,
38ded97d2cSVictor Chibotaru };
39ded97d2cSVictor Chibotaru 
40ded97d2cSVictor Chibotaru /*
41ded97d2cSVictor Chibotaru  * The format for the types of collected comparisons.
42ded97d2cSVictor Chibotaru  *
43ded97d2cSVictor Chibotaru  * Bit 0 shows whether one of the arguments is a compile-time constant.
44ded97d2cSVictor Chibotaru  * Bits 1 & 2 contain log2 of the argument size, up to 8 bytes.
45ded97d2cSVictor Chibotaru  */
46ded97d2cSVictor Chibotaru #define KCOV_CMP_CONST          (1 << 0)
47ded97d2cSVictor Chibotaru #define KCOV_CMP_SIZE(n)        ((n) << 1)
48ded97d2cSVictor Chibotaru #define KCOV_CMP_MASK           KCOV_CMP_SIZE(3)
49ded97d2cSVictor Chibotaru 
50eec028c9SAndrey Konovalov #define KCOV_SUBSYSTEM_COMMON	(0x00ull << 56)
51eec028c9SAndrey Konovalov #define KCOV_SUBSYSTEM_USB	(0x01ull << 56)
52eec028c9SAndrey Konovalov 
53eec028c9SAndrey Konovalov #define KCOV_SUBSYSTEM_MASK	(0xffull << 56)
54eec028c9SAndrey Konovalov #define KCOV_INSTANCE_MASK	(0xffffffffull)
55eec028c9SAndrey Konovalov 
kcov_remote_handle(__u64 subsys,__u64 inst)56eec028c9SAndrey Konovalov static inline __u64 kcov_remote_handle(__u64 subsys, __u64 inst)
57eec028c9SAndrey Konovalov {
58eec028c9SAndrey Konovalov 	if (subsys & ~KCOV_SUBSYSTEM_MASK || inst & ~KCOV_INSTANCE_MASK)
59eec028c9SAndrey Konovalov 		return 0;
60eec028c9SAndrey Konovalov 	return subsys | inst;
61eec028c9SAndrey Konovalov }
62eec028c9SAndrey Konovalov 
635c9a8750SDmitry Vyukov #endif /* _LINUX_KCOV_IOCTLS_H */
64