WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / powerpc / tm / tm.h
blobc5a1e5c163fcdf79b9568f13d3c60bd3b7f5e6b3
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright 2015, Michael Ellerman, IBM Corp.
4 */
6 #ifndef _SELFTESTS_POWERPC_TM_TM_H
7 #define _SELFTESTS_POWERPC_TM_TM_H
9 #include <stdbool.h>
10 #include <asm/tm.h>
12 #include "utils.h"
14 static inline bool have_htm(void)
16 #ifdef PPC_FEATURE2_HTM
17 return have_hwcap2(PPC_FEATURE2_HTM);
18 #else
19 printf("PPC_FEATURE2_HTM not defined, can't check AT_HWCAP2\n");
20 return false;
21 #endif
24 static inline bool have_htm_nosc(void)
26 #ifdef PPC_FEATURE2_HTM_NOSC
27 return have_hwcap2(PPC_FEATURE2_HTM_NOSC);
28 #else
29 printf("PPC_FEATURE2_HTM_NOSC not defined, can't check AT_HWCAP2\n");
30 return false;
31 #endif
34 static inline long failure_code(void)
36 return __builtin_get_texasru() >> 24;
39 static inline bool failure_is_persistent(void)
41 return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
44 static inline bool failure_is_syscall(void)
46 return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
49 static inline bool failure_is_unavailable(void)
51 return (failure_code() & TM_CAUSE_FAC_UNAV) == TM_CAUSE_FAC_UNAV;
54 static inline bool failure_is_reschedule(void)
56 if ((failure_code() & TM_CAUSE_RESCHED) == TM_CAUSE_RESCHED ||
57 (failure_code() & TM_CAUSE_KVM_RESCHED) == TM_CAUSE_KVM_RESCHED ||
58 (failure_code() & TM_CAUSE_KVM_FAC_UNAV) == TM_CAUSE_KVM_FAC_UNAV)
59 return true;
61 return false;
64 static inline bool failure_is_nesting(void)
66 return (__builtin_get_texasru() & 0x400000);
69 static inline int tcheck(void)
71 long cr;
72 asm volatile ("tcheck 0" : "=r"(cr) : : "cr0");
73 return (cr >> 28) & 4;
76 static inline bool tcheck_doomed(void)
78 return tcheck() & 8;
81 static inline bool tcheck_active(void)
83 return tcheck() & 4;
86 static inline bool tcheck_suspended(void)
88 return tcheck() & 2;
91 static inline bool tcheck_transactional(void)
93 return tcheck() & 6;
96 #endif /* _SELFTESTS_POWERPC_TM_TM_H */