tm.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2015, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #ifndef _SELFTESTS_POWERPC_TM_TM_H
  6. #define _SELFTESTS_POWERPC_TM_TM_H
  7. #include <asm/tm.h>
  8. #include <asm/cputable.h>
  9. #include <stdbool.h>
  10. #include "utils.h"
  11. static inline bool have_htm(void)
  12. {
  13. #ifdef PPC_FEATURE2_HTM
  14. return have_hwcap2(PPC_FEATURE2_HTM);
  15. #else
  16. printf("PPC_FEATURE2_HTM not defined, can't check AT_HWCAP2\n");
  17. return false;
  18. #endif
  19. }
  20. static inline bool have_htm_nosc(void)
  21. {
  22. #ifdef PPC_FEATURE2_HTM_NOSC
  23. return have_hwcap2(PPC_FEATURE2_HTM_NOSC);
  24. #else
  25. printf("PPC_FEATURE2_HTM_NOSC not defined, can't check AT_HWCAP2\n");
  26. return false;
  27. #endif
  28. }
  29. static inline long failure_code(void)
  30. {
  31. return __builtin_get_texasru() >> 24;
  32. }
  33. static inline bool failure_is_persistent(void)
  34. {
  35. return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
  36. }
  37. static inline bool failure_is_syscall(void)
  38. {
  39. return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
  40. }
  41. static inline bool failure_is_unavailable(void)
  42. {
  43. return (failure_code() & TM_CAUSE_FAC_UNAV) == TM_CAUSE_FAC_UNAV;
  44. }
  45. static inline bool failure_is_nesting(void)
  46. {
  47. return (__builtin_get_texasru() & 0x400000);
  48. }
  49. static inline int tcheck(void)
  50. {
  51. long cr;
  52. asm volatile ("tcheck 0" : "=r"(cr) : : "cr0");
  53. return (cr >> 28) & 4;
  54. }
  55. static inline bool tcheck_doomed(void)
  56. {
  57. return tcheck() & 8;
  58. }
  59. static inline bool tcheck_active(void)
  60. {
  61. return tcheck() & 4;
  62. }
  63. static inline bool tcheck_suspended(void)
  64. {
  65. return tcheck() & 2;
  66. }
  67. static inline bool tcheck_transactional(void)
  68. {
  69. return tcheck() & 6;
  70. }
  71. #endif /* _SELFTESTS_POWERPC_TM_TM_H */