tm.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_reschedule(void)
  46. {
  47. if ((failure_code() & TM_CAUSE_RESCHED) == TM_CAUSE_RESCHED ||
  48. (failure_code() & TM_CAUSE_KVM_RESCHED) == TM_CAUSE_KVM_RESCHED)
  49. return true;
  50. return false;
  51. }
  52. static inline bool failure_is_nesting(void)
  53. {
  54. return (__builtin_get_texasru() & 0x400000);
  55. }
  56. static inline int tcheck(void)
  57. {
  58. long cr;
  59. asm volatile ("tcheck 0" : "=r"(cr) : : "cr0");
  60. return (cr >> 28) & 4;
  61. }
  62. static inline bool tcheck_doomed(void)
  63. {
  64. return tcheck() & 8;
  65. }
  66. static inline bool tcheck_active(void)
  67. {
  68. return tcheck() & 4;
  69. }
  70. static inline bool tcheck_suspended(void)
  71. {
  72. return tcheck() & 2;
  73. }
  74. static inline bool tcheck_transactional(void)
  75. {
  76. return tcheck() & 6;
  77. }
  78. #endif /* _SELFTESTS_POWERPC_TM_TM_H */