1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_HW_BREAKPOINT_H
3 #define _LINUX_HW_BREAKPOINT_H
5 #include <linux/perf_event.h>
6 #include <uapi/linux/hw_breakpoint.h>
8 #ifdef CONFIG_HAVE_HW_BREAKPOINT
12 #if defined(CONFIG_HAVE_MIXED_BREAKPOINTS_REGS)
20 extern int __init
init_hw_breakpoint(void);
22 static inline void hw_breakpoint_init(struct perf_event_attr
*attr
)
24 memset(attr
, 0, sizeof(*attr
));
26 attr
->type
= PERF_TYPE_BREAKPOINT
;
27 attr
->size
= sizeof(*attr
);
29 * As it's for in-kernel or ptrace use, we want it to be pinned
30 * and to call its callback every hits.
33 attr
->sample_period
= 1;
36 static inline void ptrace_breakpoint_init(struct perf_event_attr
*attr
)
38 hw_breakpoint_init(attr
);
39 attr
->exclude_kernel
= 1;
42 static inline unsigned long hw_breakpoint_addr(struct perf_event
*bp
)
44 return bp
->attr
.bp_addr
;
47 static inline int hw_breakpoint_type(struct perf_event
*bp
)
49 return bp
->attr
.bp_type
;
52 static inline unsigned long hw_breakpoint_len(struct perf_event
*bp
)
54 return bp
->attr
.bp_len
;
57 extern struct perf_event
*
58 register_user_hw_breakpoint(struct perf_event_attr
*attr
,
59 perf_overflow_handler_t triggered
,
61 struct task_struct
*tsk
);
63 /* FIXME: only change from the attr, and don't unregister */
65 modify_user_hw_breakpoint(struct perf_event
*bp
, struct perf_event_attr
*attr
);
67 modify_user_hw_breakpoint_check(struct perf_event
*bp
, struct perf_event_attr
*attr
,
71 * Kernel breakpoints are not associated with any particular thread.
73 extern struct perf_event
*
74 register_wide_hw_breakpoint_cpu(struct perf_event_attr
*attr
,
75 perf_overflow_handler_t triggered
,
79 extern struct perf_event
* __percpu
*
80 register_wide_hw_breakpoint(struct perf_event_attr
*attr
,
81 perf_overflow_handler_t triggered
,
84 extern int register_perf_hw_breakpoint(struct perf_event
*bp
);
85 extern void unregister_hw_breakpoint(struct perf_event
*bp
);
86 extern void unregister_wide_hw_breakpoint(struct perf_event
* __percpu
*cpu_events
);
87 extern bool hw_breakpoint_is_used(void);
89 extern int dbg_reserve_bp_slot(struct perf_event
*bp
);
90 extern int dbg_release_bp_slot(struct perf_event
*bp
);
91 extern int reserve_bp_slot(struct perf_event
*bp
);
92 extern void release_bp_slot(struct perf_event
*bp
);
94 extern void flush_ptrace_hw_breakpoint(struct task_struct
*tsk
);
96 static inline struct arch_hw_breakpoint
*counter_arch_bp(struct perf_event
*bp
)
101 #else /* !CONFIG_HAVE_HW_BREAKPOINT */
103 static inline int __init
init_hw_breakpoint(void) { return 0; }
105 static inline struct perf_event
*
106 register_user_hw_breakpoint(struct perf_event_attr
*attr
,
107 perf_overflow_handler_t triggered
,
109 struct task_struct
*tsk
) { return NULL
; }
111 modify_user_hw_breakpoint(struct perf_event
*bp
,
112 struct perf_event_attr
*attr
) { return -ENOSYS
; }
114 modify_user_hw_breakpoint_check(struct perf_event
*bp
, struct perf_event_attr
*attr
,
115 bool check
) { return -ENOSYS
; }
117 static inline struct perf_event
*
118 register_wide_hw_breakpoint_cpu(struct perf_event_attr
*attr
,
119 perf_overflow_handler_t triggered
,
121 int cpu
) { return NULL
; }
122 static inline struct perf_event
* __percpu
*
123 register_wide_hw_breakpoint(struct perf_event_attr
*attr
,
124 perf_overflow_handler_t triggered
,
125 void *context
) { return NULL
; }
127 register_perf_hw_breakpoint(struct perf_event
*bp
) { return -ENOSYS
; }
128 static inline void unregister_hw_breakpoint(struct perf_event
*bp
) { }
130 unregister_wide_hw_breakpoint(struct perf_event
* __percpu
*cpu_events
) { }
131 static inline bool hw_breakpoint_is_used(void) { return false; }
134 reserve_bp_slot(struct perf_event
*bp
) {return -ENOSYS
; }
135 static inline void release_bp_slot(struct perf_event
*bp
) { }
137 static inline void flush_ptrace_hw_breakpoint(struct task_struct
*tsk
) { }
139 static inline struct arch_hw_breakpoint
*counter_arch_bp(struct perf_event
*bp
)
144 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
145 #endif /* _LINUX_HW_BREAKPOINT_H */