blob: a2d6ea49ec564e825ebffc3ebb059f57079fc73d [file] [log] [blame]
Frederic Weisbecker2da3e162009-11-05 23:06:50 +01001#ifndef _LINUX_HW_BREAKPOINT_H
2#define _LINUX_HW_BREAKPOINT_H
K.Prasadb332828c2009-06-01 23:43:10 +05303
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +02004enum {
5 HW_BREAKPOINT_LEN_1 = 1,
6 HW_BREAKPOINT_LEN_2 = 2,
7 HW_BREAKPOINT_LEN_4 = 4,
8 HW_BREAKPOINT_LEN_8 = 8,
K.Prasadb332828c2009-06-01 23:43:10 +05309};
10
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020011enum {
Frederic Weisbecker01027522010-04-11 18:55:56 +020012 HW_BREAKPOINT_EMPTY = 0,
13 HW_BREAKPOINT_R = 1,
14 HW_BREAKPOINT_W = 2,
15 HW_BREAKPOINT_RW = HW_BREAKPOINT_R | HW_BREAKPOINT_W,
16 HW_BREAKPOINT_X = 4,
17 HW_BREAKPOINT_INVALID = HW_BREAKPOINT_RW | HW_BREAKPOINT_X,
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020018};
K.Prasadb332828c2009-06-01 23:43:10 +053019
Frederic Weisbeckerfeef47d2010-04-23 05:59:55 +020020enum bp_type_idx {
21 TYPE_INST = 0,
22#ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
23 TYPE_DATA = 0,
24#else
25 TYPE_DATA = 1,
26#endif
27 TYPE_MAX
28};
29
Frederic Weisbecker5093eba2009-11-22 05:21:35 +010030#ifdef __KERNEL__
Ingo Molnar688bcaf2009-11-14 01:12:47 +010031
Frederic Weisbeckere6db4872009-11-23 15:42:32 +010032#include <linux/perf_event.h>
33
Frederic Weisbeckerfa7c27e2009-11-23 22:30:12 +010034#ifdef CONFIG_HAVE_HW_BREAKPOINT
35
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010036static inline void hw_breakpoint_init(struct perf_event_attr *attr)
37{
Frederic Weisbeckered872d02009-12-07 03:14:17 +010038 memset(attr, 0, sizeof(*attr));
39
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010040 attr->type = PERF_TYPE_BREAKPOINT;
41 attr->size = sizeof(*attr);
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010042 /*
43 * As it's for in-kernel or ptrace use, we want it to be pinned
44 * and to call its callback every hits.
45 */
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010046 attr->pinned = 1;
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010047 attr->sample_period = 1;
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010048}
49
Frederic Weisbecker73266fc2010-04-22 05:05:45 +020050static inline void ptrace_breakpoint_init(struct perf_event_attr *attr)
51{
52 hw_breakpoint_init(attr);
53 attr->exclude_kernel = 1;
54}
55
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020056static inline unsigned long hw_breakpoint_addr(struct perf_event *bp)
57{
58 return bp->attr.bp_addr;
59}
60
61static inline int hw_breakpoint_type(struct perf_event *bp)
62{
63 return bp->attr.bp_type;
64}
65
Mahesh Salgaonkarcd757642010-01-30 10:25:18 +053066static inline unsigned long hw_breakpoint_len(struct perf_event *bp)
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020067{
68 return bp->attr.bp_len;
69}
70
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020071extern struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010072register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010073 perf_overflow_handler_t triggered,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010074 struct task_struct *tsk);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020075
76/* FIXME: only change from the attr, and don't unregister */
Frederic Weisbecker44234ad2009-12-09 09:25:48 +010077extern int
Frederic Weisbecker2f0993e2009-12-05 07:06:10 +010078modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020079
K.Prasadb332828c2009-06-01 23:43:10 +053080/*
81 * Kernel breakpoints are not associated with any particular thread.
82 */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020083extern struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010084register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010085 perf_overflow_handler_t triggered,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010086 int cpu);
K.Prasadb332828c2009-06-01 23:43:10 +053087
Tejun Heo44ee6352010-02-17 10:50:50 +090088extern struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010089register_wide_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010090 perf_overflow_handler_t triggered);
K.Prasadb332828c2009-06-01 23:43:10 +053091
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020092extern int register_perf_hw_breakpoint(struct perf_event *bp);
93extern int __register_perf_hw_breakpoint(struct perf_event *bp);
94extern void unregister_hw_breakpoint(struct perf_event *bp);
Tejun Heo44ee6352010-02-17 10:50:50 +090095extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020096
Jason Wessel5352ae62010-01-28 17:04:43 -060097extern int dbg_reserve_bp_slot(struct perf_event *bp);
98extern int dbg_release_bp_slot(struct perf_event *bp);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020099extern int reserve_bp_slot(struct perf_event *bp);
100extern void release_bp_slot(struct perf_event *bp);
101
102extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);
103
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100104static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
105{
106 return &bp->hw.info;
107}
108
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200109#else /* !CONFIG_HAVE_HW_BREAKPOINT */
110
111static inline struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +0100112register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100113 perf_overflow_handler_t triggered,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +0100114 struct task_struct *tsk) { return NULL; }
Frederic Weisbecker44234ad2009-12-09 09:25:48 +0100115static inline int
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200116modify_user_hw_breakpoint(struct perf_event *bp,
Frederic Weisbecker99ac64c2009-12-11 11:58:42 +0100117 struct perf_event_attr *attr) { return -ENOSYS; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200118static inline struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100119register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100120 perf_overflow_handler_t triggered,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100121 int cpu) { return NULL; }
Tejun Heo44ee6352010-02-17 10:50:50 +0900122static inline struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100123register_wide_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100124 perf_overflow_handler_t triggered) { return NULL; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200125static inline int
126register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
127static inline int
128__register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
129static inline void unregister_hw_breakpoint(struct perf_event *bp) { }
130static inline void
Tejun Heo44ee6352010-02-17 10:50:50 +0900131unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200132static inline int
133reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; }
134static inline void release_bp_slot(struct perf_event *bp) { }
135
136static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { }
137
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100138static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
139{
140 return NULL;
141}
142
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200143#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Frederic Weisbecker5093eba2009-11-22 05:21:35 +0100144#endif /* __KERNEL__ */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200145
146#endif /* _LINUX_HW_BREAKPOINT_H */