162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * POWER Dynamic Execution Control Facility (DEXCR)
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * This header file contains helper functions and macros
662306a36Sopenharmony_ci * required for all the DEXCR related test cases.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci#ifndef _SELFTESTS_POWERPC_DEXCR_DEXCR_H
962306a36Sopenharmony_ci#define _SELFTESTS_POWERPC_DEXCR_DEXCR_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <stdbool.h>
1262306a36Sopenharmony_ci#include <sys/types.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include "reg.h"
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define DEXCR_PR_BIT(aspect)	__MASK(63 - (32 + (aspect)))
1762306a36Sopenharmony_ci#define DEXCR_PR_SBHE		DEXCR_PR_BIT(0)
1862306a36Sopenharmony_ci#define DEXCR_PR_IBRTPD		DEXCR_PR_BIT(3)
1962306a36Sopenharmony_ci#define DEXCR_PR_SRAPD		DEXCR_PR_BIT(4)
2062306a36Sopenharmony_ci#define DEXCR_PR_NPHIE		DEXCR_PR_BIT(5)
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define PPC_RAW_HASH_ARGS(b, i, a) \
2362306a36Sopenharmony_ci	((((i) >> 3) & 0x1F) << 21 | (a) << 16 | (b) << 11 | (((i) >> 8) & 0x1))
2462306a36Sopenharmony_ci#define PPC_RAW_HASHST(b, i, a) \
2562306a36Sopenharmony_ci	str(.long (0x7C0005A4 | PPC_RAW_HASH_ARGS(b, i, a));)
2662306a36Sopenharmony_ci#define PPC_RAW_HASHCHK(b, i, a) \
2762306a36Sopenharmony_ci	str(.long (0x7C0005E4 | PPC_RAW_HASH_ARGS(b, i, a));)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cibool dexcr_exists(void);
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cibool hashchk_triggers(void);
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_cienum dexcr_source {
3462306a36Sopenharmony_ci	DEXCR,		/* Userspace DEXCR value */
3562306a36Sopenharmony_ci	HDEXCR,		/* Hypervisor enforced DEXCR value */
3662306a36Sopenharmony_ci	EFFECTIVE,	/* Bitwise OR of UDEXCR and ENFORCED DEXCR bits */
3762306a36Sopenharmony_ci};
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciunsigned int get_dexcr(enum dexcr_source source);
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_civoid await_child_success(pid_t pid);
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_civoid hashst(unsigned long lr, void *sp);
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_civoid hashchk(unsigned long lr, void *sp);
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_civoid do_bad_hashchk(void);
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#endif  /* _SELFTESTS_POWERPC_DEXCR_DEXCR_H */
50