1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019 Facebook */
3 
4 #ifndef _TEST_BTF_H
5 #define _TEST_BTF_H
6 
7 #define BTF_INFO_ENC(kind, kind_flag, vlen)			\
8 	((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
9 
10 #define BTF_TYPE_ENC(name, info, size_or_type)	\
11 	(name), (info), (size_or_type)
12 
13 #define BTF_INT_ENC(encoding, bits_offset, nr_bits)	\
14 	((encoding) << 24 | (bits_offset) << 16 | (nr_bits))
15 #define BTF_TYPE_INT_ENC(name, encoding, bits_offset, bits, sz)	\
16 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz),	\
17 	BTF_INT_ENC(encoding, bits_offset, bits)
18 
19 #define BTF_FWD_ENC(name, kind_flag) \
20 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FWD, kind_flag, 0), 0)
21 
22 #define BTF_ARRAY_ENC(type, index_type, nr_elems)	\
23 	(type), (index_type), (nr_elems)
24 #define BTF_TYPE_ARRAY_ENC(type, index_type, nr_elems) \
25 	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 0), \
26 	BTF_ARRAY_ENC(type, index_type, nr_elems)
27 
28 #define BTF_STRUCT_ENC(name, nr_elems, sz)	\
29 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, nr_elems), sz)
30 
31 #define BTF_UNION_ENC(name, nr_elems, sz)	\
32 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_UNION, 0, nr_elems), sz)
33 
34 #define BTF_VAR_ENC(name, type, linkage)	\
35 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), type), (linkage)
36 #define BTF_VAR_SECINFO_ENC(type, offset, size)	\
37 	(type), (offset), (size)
38 
39 #define BTF_MEMBER_ENC(name, type, bits_offset)	\
40 	(name), (type), (bits_offset)
41 #define BTF_ENUM_ENC(name, val) (name), (val)
42 #define BTF_MEMBER_OFFSET(bitfield_size, bits_offset) \
43 	((bitfield_size) << 24 | (bits_offset))
44 
45 #define BTF_TYPEDEF_ENC(name, type) \
46 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), type)
47 
48 #define BTF_PTR_ENC(type) \
49 	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), type)
50 
51 #define BTF_CONST_ENC(type) \
52 	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), type)
53 
54 #define BTF_VOLATILE_ENC(type) \
55 	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), type)
56 
57 #define BTF_RESTRICT_ENC(type) \
58 	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_RESTRICT, 0, 0), type)
59 
60 #define BTF_FUNC_PROTO_ENC(ret_type, nargs) \
61 	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, nargs), ret_type)
62 
63 #define BTF_FUNC_PROTO_ARG_ENC(name, type) \
64 	(name), (type)
65 
66 #define BTF_FUNC_ENC(name, func_proto) \
67 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 0), func_proto)
68 
69 #define BTF_TYPE_FLOAT_ENC(name, sz) \
70 	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
71 
72 #endif /* _TEST_BTF_H */
73