• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015, Michael Ellerman, IBM Corp.
3  * Licensed under GPLv2.
4  */
5 
6 #ifndef _SELFTESTS_POWERPC_TM_TM_H
7 #define _SELFTESTS_POWERPC_TM_TM_H
8 
9 #include <asm/tm.h>
10 #include <asm/cputable.h>
11 #include <stdbool.h>
12 
13 #include "utils.h"
14 
have_htm(void)15 static inline bool have_htm(void)
16 {
17 #ifdef PPC_FEATURE2_HTM
18 	return have_hwcap2(PPC_FEATURE2_HTM);
19 #else
20 	printf("PPC_FEATURE2_HTM not defined, can't check AT_HWCAP2\n");
21 	return false;
22 #endif
23 }
24 
have_htm_nosc(void)25 static inline bool have_htm_nosc(void)
26 {
27 #ifdef PPC_FEATURE2_HTM_NOSC
28 	return have_hwcap2(PPC_FEATURE2_HTM_NOSC);
29 #else
30 	printf("PPC_FEATURE2_HTM_NOSC not defined, can't check AT_HWCAP2\n");
31 	return false;
32 #endif
33 }
34 
failure_code(void)35 static inline long failure_code(void)
36 {
37 	return __builtin_get_texasru() >> 24;
38 }
39 
failure_is_persistent(void)40 static inline bool failure_is_persistent(void)
41 {
42 	return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
43 }
44 
failure_is_syscall(void)45 static inline bool failure_is_syscall(void)
46 {
47 	return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
48 }
49 
failure_is_unavailable(void)50 static inline bool failure_is_unavailable(void)
51 {
52 	return (failure_code() & TM_CAUSE_FAC_UNAV) == TM_CAUSE_FAC_UNAV;
53 }
54 
failure_is_reschedule(void)55 static inline bool failure_is_reschedule(void)
56 {
57 	if ((failure_code() & TM_CAUSE_RESCHED) == TM_CAUSE_RESCHED ||
58 	    (failure_code() & TM_CAUSE_KVM_RESCHED) == TM_CAUSE_KVM_RESCHED)
59 		return true;
60 
61 	return false;
62 }
63 
failure_is_nesting(void)64 static inline bool failure_is_nesting(void)
65 {
66 	return (__builtin_get_texasru() & 0x400000);
67 }
68 
tcheck(void)69 static inline int tcheck(void)
70 {
71 	long cr;
72 	asm volatile ("tcheck 0" : "=r"(cr) : : "cr0");
73 	return (cr >> 28) & 4;
74 }
75 
tcheck_doomed(void)76 static inline bool tcheck_doomed(void)
77 {
78 	return tcheck() & 8;
79 }
80 
tcheck_active(void)81 static inline bool tcheck_active(void)
82 {
83 	return tcheck() & 4;
84 }
85 
tcheck_suspended(void)86 static inline bool tcheck_suspended(void)
87 {
88 	return tcheck() & 2;
89 }
90 
tcheck_transactional(void)91 static inline bool tcheck_transactional(void)
92 {
93 	return tcheck() & 6;
94 }
95 
96 #endif /* _SELFTESTS_POWERPC_TM_TM_H */
97