blob: 6ae9c631a1be51c7221321a9a2ceb787217e4ff0 [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
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,
Avi Kivity4dc0da82011-06-29 18:42:35 +030076 void *context,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010077 struct task_struct *tsk);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020078
79/* FIXME: only change from the attr, and don't unregister */
Frederic Weisbecker44234ad2009-12-09 09:25:48 +010080extern int
Frederic Weisbecker2f0993e2009-12-05 07:06:10 +010081modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020082
K.Prasadb332828c2009-06-01 23:43:10 +053083/*
84 * Kernel breakpoints are not associated with any particular thread.
85 */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020086extern struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010087register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010088 perf_overflow_handler_t triggered,
Avi Kivity4dc0da82011-06-29 18:42:35 +030089 void *context,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010090 int cpu);
K.Prasadb332828c2009-06-01 23:43:10 +053091
Tejun Heo44ee6352010-02-17 10:50:50 +090092extern struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010093register_wide_hw_breakpoint(struct perf_event_attr *attr,
Avi Kivity4dc0da82011-06-29 18:42:35 +030094 perf_overflow_handler_t triggered,
95 void *context);
K.Prasadb332828c2009-06-01 23:43:10 +053096
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020097extern int register_perf_hw_breakpoint(struct perf_event *bp);
98extern int __register_perf_hw_breakpoint(struct perf_event *bp);
99extern void unregister_hw_breakpoint(struct perf_event *bp);
Tejun Heo44ee6352010-02-17 10:50:50 +0900100extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200101
Jason Wessel5352ae62010-01-28 17:04:43 -0600102extern int dbg_reserve_bp_slot(struct perf_event *bp);
103extern int dbg_release_bp_slot(struct perf_event *bp);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200104extern int reserve_bp_slot(struct perf_event *bp);
105extern void release_bp_slot(struct perf_event *bp);
106
107extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);
108
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100109static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
110{
111 return &bp->hw.info;
112}
113
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200114#else /* !CONFIG_HAVE_HW_BREAKPOINT */
115
Jason Wessel3c502e72010-11-04 17:33:01 -0500116static inline int __init init_hw_breakpoint(void) { return 0; }
117
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200118static inline struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +0100119register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100120 perf_overflow_handler_t triggered,
Avi Kivity4dc0da82011-06-29 18:42:35 +0300121 void *context,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +0100122 struct task_struct *tsk) { return NULL; }
Frederic Weisbecker44234ad2009-12-09 09:25:48 +0100123static inline int
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200124modify_user_hw_breakpoint(struct perf_event *bp,
Frederic Weisbecker99ac64c2009-12-11 11:58:42 +0100125 struct perf_event_attr *attr) { return -ENOSYS; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200126static inline struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100127register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100128 perf_overflow_handler_t triggered,
Avi Kivity4dc0da82011-06-29 18:42:35 +0300129 void *context,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100130 int cpu) { return NULL; }
Tejun Heo44ee6352010-02-17 10:50:50 +0900131static inline struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100132register_wide_hw_breakpoint(struct perf_event_attr *attr,
Avi Kivity4dc0da82011-06-29 18:42:35 +0300133 perf_overflow_handler_t triggered,
134 void *context) { return NULL; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200135static inline int
136register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
137static inline int
138__register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
139static inline void unregister_hw_breakpoint(struct perf_event *bp) { }
140static inline void
Tejun Heo44ee6352010-02-17 10:50:50 +0900141unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200142static inline int
143reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; }
144static inline void release_bp_slot(struct perf_event *bp) { }
145
146static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { }
147
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100148static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
149{
150 return NULL;
151}
152
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200153#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Frederic Weisbecker5093eba2009-11-22 05:21:35 +0100154#endif /* __KERNEL__ */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200155
156#endif /* _LINUX_HW_BREAKPOINT_H */