blob: 0464c85e63fd05d1fc10f0f03eeac56fe03f3e8e [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 Weisbeckere6db4872009-11-23 15:42:32 +01004#include <linux/perf_event.h>
David Howellsd2709c72012-11-19 22:21:03 +00005#include <uapi/linux/hw_breakpoint.h>
Frederic Weisbeckere6db4872009-11-23 15:42:32 +01006
Frederic Weisbeckerfa7c27e2009-11-23 22:30:12 +01007#ifdef CONFIG_HAVE_HW_BREAKPOINT
8
Jason Wessel3c502e72010-11-04 17:33:01 -05009extern int __init init_hw_breakpoint(void);
10
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010011static inline void hw_breakpoint_init(struct perf_event_attr *attr)
12{
Frederic Weisbeckered872d02009-12-07 03:14:17 +010013 memset(attr, 0, sizeof(*attr));
14
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010015 attr->type = PERF_TYPE_BREAKPOINT;
16 attr->size = sizeof(*attr);
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010017 /*
18 * As it's for in-kernel or ptrace use, we want it to be pinned
19 * and to call its callback every hits.
20 */
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010021 attr->pinned = 1;
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010022 attr->sample_period = 1;
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010023}
24
Frederic Weisbecker73266fc2010-04-22 05:05:45 +020025static inline void ptrace_breakpoint_init(struct perf_event_attr *attr)
26{
27 hw_breakpoint_init(attr);
28 attr->exclude_kernel = 1;
29}
30
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020031static inline unsigned long hw_breakpoint_addr(struct perf_event *bp)
32{
33 return bp->attr.bp_addr;
34}
35
36static inline int hw_breakpoint_type(struct perf_event *bp)
37{
38 return bp->attr.bp_type;
39}
40
Mahesh Salgaonkarcd757642010-01-30 10:25:18 +053041static inline unsigned long hw_breakpoint_len(struct perf_event *bp)
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020042{
43 return bp->attr.bp_len;
44}
45
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020046extern struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010047register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010048 perf_overflow_handler_t triggered,
Avi Kivity4dc0da82011-06-29 18:42:35 +030049 void *context,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010050 struct task_struct *tsk);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020051
52/* FIXME: only change from the attr, and don't unregister */
Frederic Weisbecker44234ad2009-12-09 09:25:48 +010053extern int
Frederic Weisbecker2f0993e2009-12-05 07:06:10 +010054modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020055
K.Prasadb332828c2009-06-01 23:43:10 +053056/*
57 * Kernel breakpoints are not associated with any particular thread.
58 */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020059extern struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010060register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010061 perf_overflow_handler_t triggered,
Avi Kivity4dc0da82011-06-29 18:42:35 +030062 void *context,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010063 int cpu);
K.Prasadb332828c2009-06-01 23:43:10 +053064
Tejun Heo44ee6352010-02-17 10:50:50 +090065extern struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010066register_wide_hw_breakpoint(struct perf_event_attr *attr,
Avi Kivity4dc0da82011-06-29 18:42:35 +030067 perf_overflow_handler_t triggered,
68 void *context);
K.Prasadb332828c2009-06-01 23:43:10 +053069
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020070extern int register_perf_hw_breakpoint(struct perf_event *bp);
71extern int __register_perf_hw_breakpoint(struct perf_event *bp);
72extern void unregister_hw_breakpoint(struct perf_event *bp);
Tejun Heo44ee6352010-02-17 10:50:50 +090073extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020074
Jason Wessel5352ae632010-01-28 17:04:43 -060075extern int dbg_reserve_bp_slot(struct perf_event *bp);
76extern int dbg_release_bp_slot(struct perf_event *bp);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020077extern int reserve_bp_slot(struct perf_event *bp);
78extern void release_bp_slot(struct perf_event *bp);
79
80extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);
81
Frederic Weisbecker687b16f2009-11-13 13:16:15 +010082static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
83{
84 return &bp->hw.info;
85}
86
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020087#else /* !CONFIG_HAVE_HW_BREAKPOINT */
88
Jason Wessel3c502e72010-11-04 17:33:01 -050089static inline int __init init_hw_breakpoint(void) { return 0; }
90
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020091static inline struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010092register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010093 perf_overflow_handler_t triggered,
Avi Kivity4dc0da82011-06-29 18:42:35 +030094 void *context,
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,
Avi Kivity4dc0da82011-06-29 18:42:35 +0300102 void *context,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100103 int cpu) { return NULL; }
Tejun Heo44ee6352010-02-17 10:50:50 +0900104static inline struct perf_event * __percpu *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100105register_wide_hw_breakpoint(struct perf_event_attr *attr,
Avi Kivity4dc0da82011-06-29 18:42:35 +0300106 perf_overflow_handler_t triggered,
107 void *context) { return NULL; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200108static inline int
109register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
110static inline int
111__register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
112static inline void unregister_hw_breakpoint(struct perf_event *bp) { }
113static inline void
Tejun Heo44ee6352010-02-17 10:50:50 +0900114unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200115static inline int
116reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; }
117static inline void release_bp_slot(struct perf_event *bp) { }
118
119static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { }
120
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100121static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
122{
123 return NULL;
124}
125
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200126#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200127#endif /* _LINUX_HW_BREAKPOINT_H */