xref: /linux/tools/testing/selftests/arm64/mte/mte_def.h (revision 6fb44438a5e1897a72dd11139274735256be8069)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2020 ARM Limited */
3 
4 /*
5  * Below definitions may be found in kernel headers, However, they are
6  * redefined here to decouple the MTE selftests compilations from them.
7  */
8 #ifndef SEGV_MTEAERR
9 #define	SEGV_MTEAERR	8
10 #endif
11 #ifndef SEGV_MTESERR
12 #define	SEGV_MTESERR	9
13 #endif
14 #ifndef PROT_MTE
15 #define PROT_MTE	 0x20
16 #endif
17 #ifndef HWCAP2_MTE
18 #define HWCAP2_MTE	(1 << 18)
19 #endif
20 
21 #ifndef PR_MTE_TCF_SHIFT
22 #define PR_MTE_TCF_SHIFT	1
23 #endif
24 #ifndef PR_MTE_TCF_NONE
25 #define PR_MTE_TCF_NONE		(0UL << PR_MTE_TCF_SHIFT)
26 #endif
27 #ifndef PR_MTE_TCF_SYNC
28 #define	PR_MTE_TCF_SYNC		(1UL << PR_MTE_TCF_SHIFT)
29 #endif
30 #ifndef PR_MTE_TCF_ASYNC
31 #define PR_MTE_TCF_ASYNC	(2UL << PR_MTE_TCF_SHIFT)
32 #endif
33 #ifndef PR_MTE_TAG_SHIFT
34 #define	PR_MTE_TAG_SHIFT	3
35 #endif
36 
37 /* MTE Hardware feature definitions below. */
38 #define MT_TAG_SHIFT		56
39 #define MT_TAG_MASK		0xFUL
40 #define MT_FREE_TAG		0x0UL
41 #define MT_GRANULE_SIZE         16
42 #define MT_TAG_COUNT		16
43 #define MT_INCLUDE_TAG_MASK	0xFFFF
44 #define MT_EXCLUDE_TAG_MASK	0x0
45 #define MT_ATAG_SHIFT		60
46 #define MT_ATAG_MASK		0xFUL
47 
48 #define MT_ALIGN_GRANULE	(MT_GRANULE_SIZE - 1)
49 #define MT_CLEAR_TAG(x)		((x) & ~(MT_TAG_MASK << MT_TAG_SHIFT))
50 #define MT_SET_TAG(x, y)	((x) | (y << MT_TAG_SHIFT))
51 #define MT_FETCH_TAG(x)		((x >> MT_TAG_SHIFT) & (MT_TAG_MASK))
52 #define MT_ALIGN_UP(x)		((x + MT_ALIGN_GRANULE) & ~(MT_ALIGN_GRANULE))
53 
54 #define MT_CLEAR_ATAG(x)	((x) & ~(MT_TAG_MASK << MT_ATAG_SHIFT))
55 #define MT_SET_ATAG(x, y)	((x) | (((y) & MT_ATAG_MASK) << MT_ATAG_SHIFT))
56 #define MT_FETCH_ATAG(x)	((x >> MT_ATAG_SHIFT) & (MT_ATAG_MASK))
57 
58 #define MT_CLEAR_TAGS(x) 	(MT_CLEAR_ATAG(MT_CLEAR_TAG(x)))
59 
60 #define MT_PSTATE_TCO_SHIFT	25
61 #define MT_PSTATE_TCO_MASK	~(0x1 << MT_PSTATE_TCO_SHIFT)
62 #define MT_PSTATE_TCO_EN	1
63 #define MT_PSTATE_TCO_DIS	0
64 
65 #define MT_EXCLUDE_TAG(x)		(1 << (x))
66 #define MT_INCLUDE_VALID_TAG(x)		(MT_INCLUDE_TAG_MASK ^ MT_EXCLUDE_TAG(x))
67 #define MT_INCLUDE_VALID_TAGS(x)	(MT_INCLUDE_TAG_MASK ^ (x))
68 #define MTE_ALLOW_NON_ZERO_TAG		MT_INCLUDE_VALID_TAG(0)
69