hw_breakpoint.h 3.5 KB

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