162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright (c) 2019 Facebook */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef _TEST_BTF_H
562306a36Sopenharmony_ci#define _TEST_BTF_H
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#define BTF_END_RAW 0xdeadbeef
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#define BTF_INFO_ENC(kind, kind_flag, vlen)			\
1062306a36Sopenharmony_ci	((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#define BTF_TYPE_ENC(name, info, size_or_type)	\
1362306a36Sopenharmony_ci	(name), (info), (size_or_type)
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define BTF_INT_ENC(encoding, bits_offset, nr_bits)	\
1662306a36Sopenharmony_ci	((encoding) << 24 | (bits_offset) << 16 | (nr_bits))
1762306a36Sopenharmony_ci#define BTF_TYPE_INT_ENC(name, encoding, bits_offset, bits, sz)	\
1862306a36Sopenharmony_ci	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_INT, 0, 0), sz),	\
1962306a36Sopenharmony_ci	BTF_INT_ENC(encoding, bits_offset, bits)
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define BTF_FWD_ENC(name, kind_flag) \
2262306a36Sopenharmony_ci	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FWD, kind_flag, 0), 0)
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define BTF_ARRAY_ENC(type, index_type, nr_elems)	\
2562306a36Sopenharmony_ci	(type), (index_type), (nr_elems)
2662306a36Sopenharmony_ci#define BTF_TYPE_ARRAY_ENC(type, index_type, nr_elems) \
2762306a36Sopenharmony_ci	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_ARRAY, 0, 0), 0), \
2862306a36Sopenharmony_ci	BTF_ARRAY_ENC(type, index_type, nr_elems)
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci#define BTF_STRUCT_ENC(name, nr_elems, sz)	\
3162306a36Sopenharmony_ci	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_STRUCT, 0, nr_elems), sz)
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define BTF_UNION_ENC(name, nr_elems, sz)	\
3462306a36Sopenharmony_ci	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_UNION, 0, nr_elems), sz)
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define BTF_VAR_ENC(name, type, linkage)	\
3762306a36Sopenharmony_ci	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), type), (linkage)
3862306a36Sopenharmony_ci#define BTF_VAR_SECINFO_ENC(type, offset, size)	\
3962306a36Sopenharmony_ci	(type), (offset), (size)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define BTF_MEMBER_ENC(name, type, bits_offset)	\
4262306a36Sopenharmony_ci	(name), (type), (bits_offset)
4362306a36Sopenharmony_ci#define BTF_ENUM_ENC(name, val) (name), (val)
4462306a36Sopenharmony_ci#define BTF_ENUM64_ENC(name, val_lo32, val_hi32) (name), (val_lo32), (val_hi32)
4562306a36Sopenharmony_ci#define BTF_MEMBER_OFFSET(bitfield_size, bits_offset) \
4662306a36Sopenharmony_ci	((bitfield_size) << 24 | (bits_offset))
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define BTF_TYPEDEF_ENC(name, type) \
4962306a36Sopenharmony_ci	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0), type)
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define BTF_PTR_ENC(type) \
5262306a36Sopenharmony_ci	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_PTR, 0, 0), type)
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define BTF_CONST_ENC(type) \
5562306a36Sopenharmony_ci	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_CONST, 0, 0), type)
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define BTF_VOLATILE_ENC(type) \
5862306a36Sopenharmony_ci	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_VOLATILE, 0, 0), type)
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define BTF_RESTRICT_ENC(type) \
6162306a36Sopenharmony_ci	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_RESTRICT, 0, 0), type)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define BTF_FUNC_PROTO_ENC(ret_type, nargs) \
6462306a36Sopenharmony_ci	BTF_TYPE_ENC(0, BTF_INFO_ENC(BTF_KIND_FUNC_PROTO, 0, nargs), ret_type)
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define BTF_FUNC_PROTO_ARG_ENC(name, type) \
6762306a36Sopenharmony_ci	(name), (type)
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define BTF_FUNC_ENC(name, func_proto) \
7062306a36Sopenharmony_ci	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 0), func_proto)
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define BTF_TYPE_FLOAT_ENC(name, sz) \
7362306a36Sopenharmony_ci	BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define BTF_DECL_TAG_ENC(value, type, component_idx)	\
7662306a36Sopenharmony_ci	BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx)
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define BTF_TYPE_TAG_ENC(value, type)	\
7962306a36Sopenharmony_ci	BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#endif /* _TEST_BTF_H */
82