162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Copyright (C) 2020 ARM Limited */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci/* 562306a36Sopenharmony_ci * Below definitions may be found in kernel headers, However, they are 662306a36Sopenharmony_ci * redefined here to decouple the MTE selftests compilations from them. 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci#ifndef SEGV_MTEAERR 962306a36Sopenharmony_ci#define SEGV_MTEAERR 8 1062306a36Sopenharmony_ci#endif 1162306a36Sopenharmony_ci#ifndef SEGV_MTESERR 1262306a36Sopenharmony_ci#define SEGV_MTESERR 9 1362306a36Sopenharmony_ci#endif 1462306a36Sopenharmony_ci#ifndef PROT_MTE 1562306a36Sopenharmony_ci#define PROT_MTE 0x20 1662306a36Sopenharmony_ci#endif 1762306a36Sopenharmony_ci#ifndef HWCAP2_MTE 1862306a36Sopenharmony_ci#define HWCAP2_MTE (1 << 18) 1962306a36Sopenharmony_ci#endif 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#ifndef PR_MTE_TCF_SHIFT 2262306a36Sopenharmony_ci#define PR_MTE_TCF_SHIFT 1 2362306a36Sopenharmony_ci#endif 2462306a36Sopenharmony_ci#ifndef PR_MTE_TCF_NONE 2562306a36Sopenharmony_ci#define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) 2662306a36Sopenharmony_ci#endif 2762306a36Sopenharmony_ci#ifndef PR_MTE_TCF_SYNC 2862306a36Sopenharmony_ci#define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) 2962306a36Sopenharmony_ci#endif 3062306a36Sopenharmony_ci#ifndef PR_MTE_TCF_ASYNC 3162306a36Sopenharmony_ci#define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) 3262306a36Sopenharmony_ci#endif 3362306a36Sopenharmony_ci#ifndef PR_MTE_TAG_SHIFT 3462306a36Sopenharmony_ci#define PR_MTE_TAG_SHIFT 3 3562306a36Sopenharmony_ci#endif 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci/* MTE Hardware feature definitions below. */ 3862306a36Sopenharmony_ci#define MT_TAG_SHIFT 56 3962306a36Sopenharmony_ci#define MT_TAG_MASK 0xFUL 4062306a36Sopenharmony_ci#define MT_FREE_TAG 0x0UL 4162306a36Sopenharmony_ci#define MT_GRANULE_SIZE 16 4262306a36Sopenharmony_ci#define MT_TAG_COUNT 16 4362306a36Sopenharmony_ci#define MT_INCLUDE_TAG_MASK 0xFFFF 4462306a36Sopenharmony_ci#define MT_EXCLUDE_TAG_MASK 0x0 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define MT_ALIGN_GRANULE (MT_GRANULE_SIZE - 1) 4762306a36Sopenharmony_ci#define MT_CLEAR_TAG(x) ((x) & ~(MT_TAG_MASK << MT_TAG_SHIFT)) 4862306a36Sopenharmony_ci#define MT_SET_TAG(x, y) ((x) | (y << MT_TAG_SHIFT)) 4962306a36Sopenharmony_ci#define MT_FETCH_TAG(x) ((x >> MT_TAG_SHIFT) & (MT_TAG_MASK)) 5062306a36Sopenharmony_ci#define MT_ALIGN_UP(x) ((x + MT_ALIGN_GRANULE) & ~(MT_ALIGN_GRANULE)) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define MT_PSTATE_TCO_SHIFT 25 5362306a36Sopenharmony_ci#define MT_PSTATE_TCO_MASK ~(0x1 << MT_PSTATE_TCO_SHIFT) 5462306a36Sopenharmony_ci#define MT_PSTATE_TCO_EN 1 5562306a36Sopenharmony_ci#define MT_PSTATE_TCO_DIS 0 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#define MT_EXCLUDE_TAG(x) (1 << (x)) 5862306a36Sopenharmony_ci#define MT_INCLUDE_VALID_TAG(x) (MT_INCLUDE_TAG_MASK ^ MT_EXCLUDE_TAG(x)) 5962306a36Sopenharmony_ci#define MT_INCLUDE_VALID_TAGS(x) (MT_INCLUDE_TAG_MASK ^ (x)) 6062306a36Sopenharmony_ci#define MTE_ALLOW_NON_ZERO_TAG MT_INCLUDE_VALID_TAG(0) 61