blob: c70d27af03f9f081c4a434151f7634bb5eceb93a [file] [log] [blame]
Frederic Weisbecker2da3e162009-11-05 23:06:50 +01001#ifndef _LINUX_HW_BREAKPOINT_H
2#define _LINUX_HW_BREAKPOINT_H
K.Prasadb3328282009-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.Prasadb3328282009-06-01 23:43:10 +05309};
10
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020011enum {
12 HW_BREAKPOINT_R = 1,
13 HW_BREAKPOINT_W = 2,
14 HW_BREAKPOINT_X = 4,
15};
K.Prasadb3328282009-06-01 23:43:10 +053016
Frederic Weisbecker5093eba2009-11-22 05:21:35 +010017#ifdef __KERNEL__
Ingo Molnar688bcaf2009-11-14 01:12:47 +010018
Frederic Weisbeckere6db4872009-11-23 15:42:32 +010019#include <linux/perf_event.h>
20
Frederic Weisbeckerfa7c27e2009-11-23 22:30:12 +010021#ifdef CONFIG_HAVE_HW_BREAKPOINT
22
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010023static inline void hw_breakpoint_init(struct perf_event_attr *attr)
24{
Frederic Weisbeckered872d02009-12-07 03:14:17 +010025 memset(attr, 0, sizeof(*attr));
26
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010027 attr->type = PERF_TYPE_BREAKPOINT;
28 attr->size = sizeof(*attr);
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010029 /*
30 * As it's for in-kernel or ptrace use, we want it to be pinned
31 * and to call its callback every hits.
32 */
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010033 attr->pinned = 1;
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010034 attr->sample_period = 1;
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010035}
36
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020037static inline unsigned long hw_breakpoint_addr(struct perf_event *bp)
38{
39 return bp->attr.bp_addr;
40}
41
42static inline int hw_breakpoint_type(struct perf_event *bp)
43{
44 return bp->attr.bp_type;
45}
46
Mahesh Salgaonkarcd757642010-01-30 10:25:18 +053047static inline unsigned long hw_breakpoint_len(struct perf_event *bp)
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020048{
49 return bp->attr.bp_len;
50}
51
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020052extern struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010053register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010054 perf_overflow_handler_t triggered,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010055 struct task_struct *tsk);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020056
57/* FIXME: only change from the attr, and don't unregister */
Frederic Weisbecker44234ad2009-12-09 09:25:48 +010058extern int
Frederic Weisbecker2f0993e2009-12-05 07:06:10 +010059modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020060
K.Prasadb3328282009-06-01 23:43:10 +053061/*
62 * Kernel breakpoints are not associated with any particular thread.
63 */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020064extern struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010065register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010066 perf_overflow_handler_t triggered,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010067 int cpu);
K.Prasadb3328282009-06-01 23:43:10 +053068
Tejun Heo44ee6352010-02-17 10:50:50 +090069extern struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010070register_wide_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010071 perf_overflow_handler_t triggered);
K.Prasadb3328282009-06-01 23:43:10 +053072
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020073extern int register_perf_hw_breakpoint(struct perf_event *bp);
74extern int __register_perf_hw_breakpoint(struct perf_event *bp);
75extern void unregister_hw_breakpoint(struct perf_event *bp);
Tejun Heo44ee6352010-02-17 10:50:50 +090076extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020077
Jason Wessel5352ae62010-01-28 17:04:43 -060078extern int dbg_reserve_bp_slot(struct perf_event *bp);
79extern int dbg_release_bp_slot(struct perf_event *bp);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020080extern int reserve_bp_slot(struct perf_event *bp);
81extern void release_bp_slot(struct perf_event *bp);
82
83extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);
84
Frederic Weisbecker687b16f2009-11-13 13:16:15 +010085static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
86{
87 return &bp->hw.info;
88}
89
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020090#else /* !CONFIG_HAVE_HW_BREAKPOINT */
91
92static inline struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010093register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010094 perf_overflow_handler_t triggered,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010095 struct task_struct *tsk) { return NULL; }
Frederic Weisbecker44234ad2009-12-09 09:25:48 +010096static inline int
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020097modify_user_hw_breakpoint(struct perf_event *bp,
Frederic Weisbecker99ac64c2009-12-11 11:58:42 +010098 struct perf_event_attr *attr) { return -ENOSYS; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020099static inline struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100100register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100101 perf_overflow_handler_t triggered,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100102 int cpu) { return NULL; }
Tejun Heo44ee6352010-02-17 10:50:50 +0900103static inline struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100104register_wide_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100105 perf_overflow_handler_t triggered) { return NULL; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200106static inline int
107register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
108static inline int
109__register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
110static inline void unregister_hw_breakpoint(struct perf_event *bp) { }
111static inline void
Tejun Heo44ee6352010-02-17 10:50:50 +0900112unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200113static inline int
114reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; }
115static inline void release_bp_slot(struct perf_event *bp) { }
116
117static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { }
118
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100119static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
120{
121 return NULL;
122}
123
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200124#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Frederic Weisbecker5093eba2009-11-22 05:21:35 +0100125#endif /* __KERNEL__ */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200126
127#endif /* _LINUX_HW_BREAKPOINT_H */