hw_breakpoint.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 ARM Ltd.
  4. */
  5. #ifndef __ASM_HW_BREAKPOINT_H
  6. #define __ASM_HW_BREAKPOINT_H
  7. #include <asm/cputype.h>
  8. #include <asm/cpufeature.h>
  9. #include <asm/sysreg.h>
  10. #include <asm/virt.h>
  11. struct arch_hw_breakpoint_ctrl {
  12. u32 __reserved : 19,
  13. len : 8,
  14. type : 2,
  15. privilege : 2,
  16. enabled : 1;
  17. };
  18. struct arch_hw_breakpoint {
  19. u64 address;
  20. u64 trigger;
  21. struct arch_hw_breakpoint_ctrl ctrl;
  22. };
  23. /* Privilege Levels */
  24. #define AARCH64_BREAKPOINT_EL1 1
  25. #define AARCH64_BREAKPOINT_EL0 2
  26. #define DBG_HMC_HYP (1 << 13)
  27. static inline u32 encode_ctrl_reg(struct arch_hw_breakpoint_ctrl ctrl)
  28. {
  29. u32 val = (ctrl.len << 5) | (ctrl.type << 3) | (ctrl.privilege << 1) |
  30. ctrl.enabled;
  31. if (is_kernel_in_hyp_mode() && ctrl.privilege == AARCH64_BREAKPOINT_EL1)
  32. val |= DBG_HMC_HYP;
  33. return val;
  34. }
  35. static inline void decode_ctrl_reg(u32 reg,
  36. struct arch_hw_breakpoint_ctrl *ctrl)
  37. {
  38. ctrl->enabled = reg & 0x1;
  39. reg >>= 1;
  40. ctrl->privilege = reg & 0x3;
  41. reg >>= 2;
  42. ctrl->type = reg & 0x3;
  43. reg >>= 2;
  44. ctrl->len = reg & 0xff;
  45. }
  46. /* Breakpoint */
  47. #define ARM_BREAKPOINT_EXECUTE 0
  48. /* Watchpoints */
  49. #define ARM_BREAKPOINT_LOAD 1
  50. #define ARM_BREAKPOINT_STORE 2
  51. #define AARCH64_ESR_ACCESS_MASK (1 << 6)
  52. /* Lengths */
  53. #define ARM_BREAKPOINT_LEN_1 0x1
  54. #define ARM_BREAKPOINT_LEN_2 0x3
  55. #define ARM_BREAKPOINT_LEN_3 0x7
  56. #define ARM_BREAKPOINT_LEN_4 0xf
  57. #define ARM_BREAKPOINT_LEN_5 0x1f
  58. #define ARM_BREAKPOINT_LEN_6 0x3f
  59. #define ARM_BREAKPOINT_LEN_7 0x7f
  60. #define ARM_BREAKPOINT_LEN_8 0xff
  61. /* Kernel stepping */
  62. #define ARM_KERNEL_STEP_NONE 0
  63. #define ARM_KERNEL_STEP_ACTIVE 1
  64. #define ARM_KERNEL_STEP_SUSPEND 2
  65. /*
  66. * Limits.
  67. * Changing these will require modifications to the register accessors.
  68. */
  69. #define ARM_MAX_BRP 16
  70. #define ARM_MAX_WRP 16
  71. /* Virtual debug register bases. */
  72. #define AARCH64_DBG_REG_BVR 0
  73. #define AARCH64_DBG_REG_BCR (AARCH64_DBG_REG_BVR + ARM_MAX_BRP)
  74. #define AARCH64_DBG_REG_WVR (AARCH64_DBG_REG_BCR + ARM_MAX_BRP)
  75. #define AARCH64_DBG_REG_WCR (AARCH64_DBG_REG_WVR + ARM_MAX_WRP)
  76. /* Debug register names. */
  77. #define AARCH64_DBG_REG_NAME_BVR bvr
  78. #define AARCH64_DBG_REG_NAME_BCR bcr
  79. #define AARCH64_DBG_REG_NAME_WVR wvr
  80. #define AARCH64_DBG_REG_NAME_WCR wcr
  81. /* Accessor macros for the debug registers. */
  82. #define AARCH64_DBG_READ(N, REG, VAL) do {\
  83. VAL = read_sysreg(dbg##REG##N##_el1);\
  84. } while (0)
  85. #define AARCH64_DBG_WRITE(N, REG, VAL) do {\
  86. write_sysreg(VAL, dbg##REG##N##_el1);\
  87. } while (0)
  88. struct task_struct;
  89. struct notifier_block;
  90. struct perf_event_attr;
  91. struct perf_event;
  92. struct pmu;
  93. extern int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,
  94. int *gen_len, int *gen_type, int *offset);
  95. extern int arch_check_bp_in_kernelspace(struct arch_hw_breakpoint *hw);
  96. extern int hw_breakpoint_arch_parse(struct perf_event *bp,
  97. const struct perf_event_attr *attr,
  98. struct arch_hw_breakpoint *hw);
  99. extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
  100. unsigned long val, void *data);
  101. extern int arch_install_hw_breakpoint(struct perf_event *bp);
  102. extern void arch_uninstall_hw_breakpoint(struct perf_event *bp);
  103. extern void hw_breakpoint_pmu_read(struct perf_event *bp);
  104. extern int hw_breakpoint_slots(int type);
  105. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  106. extern void hw_breakpoint_thread_switch(struct task_struct *next);
  107. extern void ptrace_hw_copy_thread(struct task_struct *task);
  108. #else
  109. static inline void hw_breakpoint_thread_switch(struct task_struct *next)
  110. {
  111. }
  112. static inline void ptrace_hw_copy_thread(struct task_struct *task)
  113. {
  114. }
  115. #endif
  116. /* Determine number of BRP registers available. */
  117. static inline int get_num_brps(void)
  118. {
  119. u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
  120. return 1 +
  121. cpuid_feature_extract_unsigned_field(dfr0,
  122. ID_AA64DFR0_EL1_BRPs_SHIFT);
  123. }
  124. /* Determine number of WRP registers available. */
  125. static inline int get_num_wrps(void)
  126. {
  127. u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1);
  128. return 1 +
  129. cpuid_feature_extract_unsigned_field(dfr0,
  130. ID_AA64DFR0_EL1_WRPs_SHIFT);
  131. }
  132. #endif /* __ASM_BREAKPOINT_H */