hw_breakpoint.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /* Breakpoint */
  46. #define ARM_BREAKPOINT_EXECUTE 0
  47. /* Watchpoints */
  48. #define ARM_BREAKPOINT_LOAD 1
  49. #define ARM_BREAKPOINT_STORE 2
  50. /* Privilege Levels */
  51. #define ARM_BREAKPOINT_PRIV 1
  52. #define ARM_BREAKPOINT_USER 2
  53. /* Lengths */
  54. #define ARM_BREAKPOINT_LEN_1 0x1
  55. #define ARM_BREAKPOINT_LEN_2 0x3
  56. #define ARM_BREAKPOINT_LEN_4 0xf
  57. #define ARM_BREAKPOINT_LEN_8 0xff
  58. /* Limits */
  59. #define ARM_MAX_BRP 16
  60. #define ARM_MAX_WRP 16
  61. #define ARM_MAX_HBP_SLOTS (ARM_MAX_BRP + ARM_MAX_WRP)
  62. /* DSCR method of entry bits. */
  63. #define ARM_DSCR_MOE(x) ((x >> 2) & 0xf)
  64. #define ARM_ENTRY_BREAKPOINT 0x1
  65. #define ARM_ENTRY_ASYNC_WATCHPOINT 0x2
  66. #define ARM_ENTRY_SYNC_WATCHPOINT 0xa
  67. /* DSCR monitor/halting bits. */
  68. #define ARM_DSCR_HDBGEN (1 << 14)
  69. #define ARM_DSCR_MDBGEN (1 << 15)
  70. /* opcode2 numbers for the co-processor instructions. */
  71. #define ARM_OP2_BVR 4
  72. #define ARM_OP2_BCR 5
  73. #define ARM_OP2_WVR 6
  74. #define ARM_OP2_WCR 7
  75. /* Base register numbers for the debug registers. */
  76. #define ARM_BASE_BVR 64
  77. #define ARM_BASE_BCR 80
  78. #define ARM_BASE_WVR 96
  79. #define ARM_BASE_WCR 112
  80. /* Accessor macros for the debug registers. */
  81. #define ARM_DBG_READ(M, OP2, VAL) do {\
  82. asm volatile("mrc p14, 0, %0, c0," #M ", " #OP2 : "=r" (VAL));\
  83. } while (0)
  84. #define ARM_DBG_WRITE(M, OP2, VAL) do {\
  85. asm volatile("mcr p14, 0, %0, c0," #M ", " #OP2 : : "r" (VAL));\
  86. } while (0)
  87. struct notifier_block;
  88. struct perf_event;
  89. struct pmu;
  90. extern struct pmu perf_ops_bp;
  91. extern int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,
  92. int *gen_len, int *gen_type);
  93. extern int arch_check_bp_in_kernelspace(struct perf_event *bp);
  94. extern int arch_validate_hwbkpt_settings(struct perf_event *bp);
  95. extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
  96. unsigned long val, void *data);
  97. extern u8 arch_get_debug_arch(void);
  98. extern u8 arch_get_max_wp_len(void);
  99. extern void clear_ptrace_hw_breakpoint(struct task_struct *tsk);
  100. int arch_install_hw_breakpoint(struct perf_event *bp);
  101. void arch_uninstall_hw_breakpoint(struct perf_event *bp);
  102. void hw_breakpoint_pmu_read(struct perf_event *bp);
  103. int hw_breakpoint_slots(int type);
  104. #else
  105. static inline void clear_ptrace_hw_breakpoint(struct task_struct *tsk) {}
  106. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  107. #endif /* __KERNEL__ */
  108. #endif /* _ARM_HW_BREAKPOINT_H */