tm.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_nesting(void)
  42. {
  43. return (__builtin_get_texasru() & 0x400000);
  44. }
  45. static inline int tcheck(void)
  46. {
  47. long cr;
  48. asm volatile ("tcheck 0" : "=r"(cr) : : "cr0");
  49. return (cr >> 28) & 4;
  50. }
  51. static inline bool tcheck_doomed(void)
  52. {
  53. return tcheck() & 8;
  54. }
  55. static inline bool tcheck_active(void)
  56. {
  57. return tcheck() & 4;
  58. }
  59. static inline bool tcheck_suspended(void)
  60. {
  61. return tcheck() & 2;
  62. }
  63. static inline bool tcheck_transactional(void)
  64. {
  65. return tcheck() & 6;
  66. }
  67. #endif /* _SELFTESTS_POWERPC_TM_TM_H */