hw_breakpoint.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ARM_HW_BREAKPOINT_H
  3. #define _ARM_HW_BREAKPOINT_H
  4. #ifdef __KERNEL__
  5. struct task_struct;
  6. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  7. struct arch_hw_breakpoint_ctrl {
  8. u32 __reserved : 9,
  9. mismatch : 1,
  10. : 9,
  11. len : 8,
  12. type : 2,
  13. privilege : 2,
  14. enabled : 1;
  15. };
  16. struct arch_hw_breakpoint {
  17. u32 address;
  18. u32 trigger;
  19. struct arch_hw_breakpoint_ctrl step_ctrl;
  20. struct arch_hw_breakpoint_ctrl ctrl;
  21. };
  22. static inline u32 encode_ctrl_reg(struct arch_hw_breakpoint_ctrl ctrl)
  23. {
  24. return (ctrl.mismatch << 22) | (ctrl.len << 5) | (ctrl.type << 3) |
  25. (ctrl.privilege << 1) | ctrl.enabled;
  26. }
  27. static inline void decode_ctrl_reg(u32 reg,
  28. struct arch_hw_breakpoint_ctrl *ctrl)
  29. {
  30. ctrl->enabled = reg & 0x1;
  31. reg >>= 1;
  32. ctrl->privilege = reg & 0x3;
  33. reg >>= 2;
  34. ctrl->type = reg & 0x3;
  35. reg >>= 2;
  36. ctrl->len = reg & 0xff;
  37. reg >>= 17;
  38. ctrl->mismatch = reg & 0x1;
  39. }
  40. /* Debug architecture numbers. */
  41. #define ARM_DEBUG_ARCH_RESERVED 0 /* In case of ptrace ABI updates. */
  42. #define ARM_DEBUG_ARCH_V6 1
  43. #define ARM_DEBUG_ARCH_V6_1 2
  44. #define ARM_DEBUG_ARCH_V7_ECP14 3
  45. #define ARM_DEBUG_ARCH_V7_MM 4
  46. #define ARM_DEBUG_ARCH_V7_1 5
  47. #define ARM_DEBUG_ARCH_V8 6
  48. #define ARM_DEBUG_ARCH_V8_1 7
  49. #define ARM_DEBUG_ARCH_V8_2 8
  50. #define ARM_DEBUG_ARCH_V8_4 9
  51. /* Breakpoint */
  52. #define ARM_BREAKPOINT_EXECUTE 0
  53. /* Watchpoints */
  54. #define ARM_BREAKPOINT_LOAD 1
  55. #define ARM_BREAKPOINT_STORE 2
  56. #define ARM_FSR_ACCESS_MASK (1 << 11)
  57. /* Privilege Levels */
  58. #define ARM_BREAKPOINT_PRIV 1
  59. #define ARM_BREAKPOINT_USER 2
  60. /* Lengths */
  61. #define ARM_BREAKPOINT_LEN_1 0x1
  62. #define ARM_BREAKPOINT_LEN_2 0x3
  63. #define ARM_BREAKPOINT_LEN_4 0xf
  64. #define ARM_BREAKPOINT_LEN_8 0xff
  65. /* Limits */
  66. #define ARM_MAX_BRP 16
  67. #define ARM_MAX_WRP 16
  68. #define ARM_MAX_HBP_SLOTS (ARM_MAX_BRP + ARM_MAX_WRP)
  69. /* DSCR method of entry bits. */
  70. #define ARM_DSCR_MOE(x) ((x >> 2) & 0xf)
  71. #define ARM_ENTRY_BREAKPOINT 0x1
  72. #define ARM_ENTRY_ASYNC_WATCHPOINT 0x2
  73. #define ARM_ENTRY_SYNC_WATCHPOINT 0xa
  74. /* DSCR monitor/halting bits. */
  75. #define ARM_DSCR_HDBGEN (1 << 14)
  76. #define ARM_DSCR_MDBGEN (1 << 15)
  77. /* OSLSR os lock model bits */
  78. #define ARM_OSLSR_OSLM0 (1 << 0)
  79. /* opcode2 numbers for the co-processor instructions. */
  80. #define ARM_OP2_BVR 4
  81. #define ARM_OP2_BCR 5
  82. #define ARM_OP2_WVR 6
  83. #define ARM_OP2_WCR 7
  84. /* Base register numbers for the debug registers. */
  85. #define ARM_BASE_BVR 64
  86. #define ARM_BASE_BCR 80
  87. #define ARM_BASE_WVR 96
  88. #define ARM_BASE_WCR 112
  89. /* Accessor macros for the debug registers. */
  90. #define ARM_DBG_READ(N, M, OP2, VAL) do {\
  91. asm volatile("mrc p14, 0, %0, " #N "," #M ", " #OP2 : "=r" (VAL));\
  92. } while (0)
  93. #define ARM_DBG_WRITE(N, M, OP2, VAL) do {\
  94. asm volatile("mcr p14, 0, %0, " #N "," #M ", " #OP2 : : "r" (VAL));\
  95. } while (0)
  96. struct perf_event_attr;
  97. struct notifier_block;
  98. struct perf_event;
  99. struct pmu;
  100. extern int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,
  101. int *gen_len, int *gen_type);
  102. extern int arch_check_bp_in_kernelspace(struct arch_hw_breakpoint *hw);
  103. extern int hw_breakpoint_arch_parse(struct perf_event *bp,
  104. const struct perf_event_attr *attr,
  105. struct arch_hw_breakpoint *hw);
  106. extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
  107. unsigned long val, void *data);
  108. extern u8 arch_get_debug_arch(void);
  109. extern u8 arch_get_max_wp_len(void);
  110. extern void clear_ptrace_hw_breakpoint(struct task_struct *tsk);
  111. int arch_install_hw_breakpoint(struct perf_event *bp);
  112. void arch_uninstall_hw_breakpoint(struct perf_event *bp);
  113. void hw_breakpoint_pmu_read(struct perf_event *bp);
  114. int hw_breakpoint_slots(int type);
  115. #else
  116. static inline void clear_ptrace_hw_breakpoint(struct task_struct *tsk) {}
  117. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  118. #endif /* __KERNEL__ */
  119. #endif /* _ARM_HW_BREAKPOINT_H */