blob: d1e55fed2c7dc0281cd0cf653bb5a56a399265cb [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 {
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.Prasadb3328282009-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
Jason Wessel3c502e72010-11-04 17:33:01 -050036extern int __init init_hw_breakpoint(void);
37
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010038static inline void hw_breakpoint_init(struct perf_event_attr *attr)
39{
Frederic Weisbeckered872d02009-12-07 03:14:17 +010040 memset(attr, 0, sizeof(*attr));
41
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010042 attr->type = PERF_TYPE_BREAKPOINT;
43 attr->size = sizeof(*attr);
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010044 /*
45 * As it's for in-kernel or ptrace use, we want it to be pinned
46 * and to call its callback every hits.
47 */
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010048 attr->pinned = 1;
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010049 attr->sample_period = 1;
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010050}
51
Frederic Weisbecker73266fc2010-04-22 05:05:45 +020052static inline void ptrace_breakpoint_init(struct perf_event_attr *attr)
53{
54 hw_breakpoint_init(attr);
55 attr->exclude_kernel = 1;
56}
57
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020058static inline unsigned long hw_breakpoint_addr(struct perf_event *bp)
59{
60 return bp->attr.bp_addr;
61}
62
63static inline int hw_breakpoint_type(struct perf_event *bp)
64{
65 return bp->attr.bp_type;
66}
67
Mahesh Salgaonkarcd757642010-01-30 10:25:18 +053068static inline unsigned long hw_breakpoint_len(struct perf_event *bp)
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020069{
70 return bp->attr.bp_len;
71}
72
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020073extern struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010074register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010075 perf_overflow_handler_t triggered,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010076 struct task_struct *tsk);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020077
78/* FIXME: only change from the attr, and don't unregister */
Frederic Weisbecker44234ad2009-12-09 09:25:48 +010079extern int
Frederic Weisbecker2f0993e2009-12-05 07:06:10 +010080modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020081
K.Prasadb3328282009-06-01 23:43:10 +053082/*
83 * Kernel breakpoints are not associated with any particular thread.
84 */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020085extern struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010086register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010087 perf_overflow_handler_t triggered,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010088 int cpu);
K.Prasadb3328282009-06-01 23:43:10 +053089
Tejun Heo44ee6352010-02-17 10:50:50 +090090extern struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010091register_wide_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010092 perf_overflow_handler_t triggered);
K.Prasadb3328282009-06-01 23:43:10 +053093
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020094extern int register_perf_hw_breakpoint(struct perf_event *bp);
95extern int __register_perf_hw_breakpoint(struct perf_event *bp);
96extern void unregister_hw_breakpoint(struct perf_event *bp);
Tejun Heo44ee6352010-02-17 10:50:50 +090097extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020098
Jason Wessel5352ae62010-01-28 17:04:43 -060099extern int dbg_reserve_bp_slot(struct perf_event *bp);
100extern int dbg_release_bp_slot(struct perf_event *bp);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200101extern int reserve_bp_slot(struct perf_event *bp);
102extern void release_bp_slot(struct perf_event *bp);
103
104extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);
105
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100106static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
107{
108 return &bp->hw.info;
109}
110
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200111#else /* !CONFIG_HAVE_HW_BREAKPOINT */
112
Jason Wessel3c502e72010-11-04 17:33:01 -0500113static inline int __init init_hw_breakpoint(void) { return 0; }
114
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200115static inline struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +0100116register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100117 perf_overflow_handler_t triggered,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +0100118 struct task_struct *tsk) { return NULL; }
Frederic Weisbecker44234ad2009-12-09 09:25:48 +0100119static inline int
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200120modify_user_hw_breakpoint(struct perf_event *bp,
Frederic Weisbecker99ac64c2009-12-11 11:58:42 +0100121 struct perf_event_attr *attr) { return -ENOSYS; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200122static inline struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100123register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100124 perf_overflow_handler_t triggered,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100125 int cpu) { return NULL; }
Tejun Heo44ee6352010-02-17 10:50:50 +0900126static inline struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100127register_wide_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100128 perf_overflow_handler_t triggered) { return NULL; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200129static inline int
130register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
131static inline int
132__register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
133static inline void unregister_hw_breakpoint(struct perf_event *bp) { }
134static inline void
Tejun Heo44ee6352010-02-17 10:50:50 +0900135unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200136static inline int
137reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; }
138static inline void release_bp_slot(struct perf_event *bp) { }
139
140static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { }
141
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100142static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
143{
144 return NULL;
145}
146
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200147#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Frederic Weisbecker5093eba2009-11-22 05:21:35 +0100148#endif /* __KERNEL__ */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200149
150#endif /* _LINUX_HW_BREAKPOINT_H */