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 
46 #define MT_ALIGN_GRANULE	(MT_GRANULE_SIZE - 1)
47 #define MT_CLEAR_TAG(x)		((x) & ~(MT_TAG_MASK << MT_TAG_SHIFT))
48 #define MT_SET_TAG(x, y)	((x) | (y << MT_TAG_SHIFT))
49 #define MT_FETCH_TAG(x)		((x >> MT_TAG_SHIFT) & (MT_TAG_MASK))
50 #define MT_ALIGN_UP(x)		((x + MT_ALIGN_GRANULE) & ~(MT_ALIGN_GRANULE))
51 
52 #define MT_PSTATE_TCO_SHIFT	25
53 #define MT_PSTATE_TCO_MASK	~(0x1 << MT_PSTATE_TCO_SHIFT)
54 #define MT_PSTATE_TCO_EN	1
55 #define MT_PSTATE_TCO_DIS	0
56 
57 #define MT_EXCLUDE_TAG(x)		(1 << (x))
58 #define MT_INCLUDE_VALID_TAG(x)		(MT_INCLUDE_TAG_MASK ^ MT_EXCLUDE_TAG(x))
59 #define MT_INCLUDE_VALID_TAGS(x)	(MT_INCLUDE_TAG_MASK ^ (x))
60 #define MTE_ALLOW_NON_ZERO_TAG		MT_INCLUDE_VALID_TAG(0)
61