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
10 extern int __init
init_hw_breakpoint(void);
12 static inline void hw_breakpoint_init(struct perf_event_attr
*attr
)
14 memset(attr
, 0, sizeof(*attr
));
16 attr
->type
= PERF_TYPE_BREAKPOINT
;
17 attr
->size
= sizeof(*attr
);
19 * As it's for in-kernel or ptrace use, we want it to be pinned
20 * and to call its callback every hits.
23 attr
->sample_period
= 1;
26 static inline void ptrace_breakpoint_init(struct perf_event_attr
*attr
)
28 hw_breakpoint_init(attr
);
29 attr
->exclude_kernel
= 1;
32 static inline unsigned long hw_breakpoint_addr(struct perf_event
*bp
)
34 return bp
->attr
.bp_addr
;
37 static inline int hw_breakpoint_type(struct perf_event
*bp
)
39 return bp
->attr
.bp_type
;
42 static inline unsigned long hw_breakpoint_len(struct perf_event
*bp
)
44 return bp
->attr
.bp_len
;
47 extern struct perf_event
*
48 register_user_hw_breakpoint(struct perf_event_attr
*attr
,
49 perf_overflow_handler_t triggered
,
51 struct task_struct
*tsk
);
53 /* FIXME: only change from the attr, and don't unregister */
55 modify_user_hw_breakpoint(struct perf_event
*bp
, struct perf_event_attr
*attr
);
58 * Kernel breakpoints are not associated with any particular thread.
60 extern struct perf_event
*
61 register_wide_hw_breakpoint_cpu(struct perf_event_attr
*attr
,
62 perf_overflow_handler_t triggered
,
66 extern struct perf_event
* __percpu
*
67 register_wide_hw_breakpoint(struct perf_event_attr
*attr
,
68 perf_overflow_handler_t triggered
,
71 extern int register_perf_hw_breakpoint(struct perf_event
*bp
);
72 extern int __register_perf_hw_breakpoint(struct perf_event
*bp
);
73 extern void unregister_hw_breakpoint(struct perf_event
*bp
);
74 extern void unregister_wide_hw_breakpoint(struct perf_event
* __percpu
*cpu_events
);
76 extern int dbg_reserve_bp_slot(struct perf_event
*bp
);
77 extern int dbg_release_bp_slot(struct perf_event
*bp
);
78 extern int reserve_bp_slot(struct perf_event
*bp
);
79 extern void release_bp_slot(struct perf_event
*bp
);
81 extern void flush_ptrace_hw_breakpoint(struct task_struct
*tsk
);
83 static inline struct arch_hw_breakpoint
*counter_arch_bp(struct perf_event
*bp
)
88 #else /* !CONFIG_HAVE_HW_BREAKPOINT */
90 static inline int __init
init_hw_breakpoint(void) { return 0; }
92 static inline struct perf_event
*
93 register_user_hw_breakpoint(struct perf_event_attr
*attr
,
94 perf_overflow_handler_t triggered
,
96 struct task_struct
*tsk
) { return NULL
; }
98 modify_user_hw_breakpoint(struct perf_event
*bp
,
99 struct perf_event_attr
*attr
) { return -ENOSYS
; }
100 static inline struct perf_event
*
101 register_wide_hw_breakpoint_cpu(struct perf_event_attr
*attr
,
102 perf_overflow_handler_t triggered
,
104 int cpu
) { return NULL
; }
105 static inline struct perf_event
* __percpu
*
106 register_wide_hw_breakpoint(struct perf_event_attr
*attr
,
107 perf_overflow_handler_t triggered
,
108 void *context
) { return NULL
; }
110 register_perf_hw_breakpoint(struct perf_event
*bp
) { return -ENOSYS
; }
112 __register_perf_hw_breakpoint(struct perf_event
*bp
) { return -ENOSYS
; }
113 static inline void unregister_hw_breakpoint(struct perf_event
*bp
) { }
115 unregister_wide_hw_breakpoint(struct perf_event
* __percpu
*cpu_events
) { }
117 reserve_bp_slot(struct perf_event
*bp
) {return -ENOSYS
; }
118 static inline void release_bp_slot(struct perf_event
*bp
) { }
120 static inline void flush_ptrace_hw_breakpoint(struct task_struct
*tsk
) { }
122 static inline struct arch_hw_breakpoint
*counter_arch_bp(struct perf_event
*bp
)
127 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
128 #endif /* _LINUX_HW_BREAKPOINT_H */