Frederic Weisbecker | 2da3e16 | 2009-11-05 23:06:50 +0100 | [diff] [blame] | 1 | #ifndef _LINUX_HW_BREAKPOINT_H |
| 2 | #define _LINUX_HW_BREAKPOINT_H |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 3 | |
Frederic Weisbecker | e6db487 | 2009-11-23 15:42:32 +0100 | [diff] [blame] | 4 | #include <linux/perf_event.h> |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 5 | #include <uapi/linux/hw_breakpoint.h> |
Frederic Weisbecker | e6db487 | 2009-11-23 15:42:32 +0100 | [diff] [blame] | 6 | |
Frederic Weisbecker | fa7c27e | 2009-11-23 22:30:12 +0100 | [diff] [blame] | 7 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 8 | |
Jason Wessel | 3c502e7 | 2010-11-04 17:33:01 -0500 | [diff] [blame] | 9 | extern int __init init_hw_breakpoint(void); |
| 10 | |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 11 | static inline void hw_breakpoint_init(struct perf_event_attr *attr) |
| 12 | { |
Frederic Weisbecker | ed872d0 | 2009-12-07 03:14:17 +0100 | [diff] [blame] | 13 | memset(attr, 0, sizeof(*attr)); |
| 14 | |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 15 | attr->type = PERF_TYPE_BREAKPOINT; |
| 16 | attr->size = sizeof(*attr); |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 17 | /* |
| 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 Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 21 | attr->pinned = 1; |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 22 | attr->sample_period = 1; |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 23 | } |
| 24 | |
Frederic Weisbecker | 73266fc | 2010-04-22 05:05:45 +0200 | [diff] [blame] | 25 | static inline void ptrace_breakpoint_init(struct perf_event_attr *attr) |
| 26 | { |
| 27 | hw_breakpoint_init(attr); |
| 28 | attr->exclude_kernel = 1; |
| 29 | } |
| 30 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 31 | static inline unsigned long hw_breakpoint_addr(struct perf_event *bp) |
| 32 | { |
| 33 | return bp->attr.bp_addr; |
| 34 | } |
| 35 | |
| 36 | static inline int hw_breakpoint_type(struct perf_event *bp) |
| 37 | { |
| 38 | return bp->attr.bp_type; |
| 39 | } |
| 40 | |
Mahesh Salgaonkar | cd75764 | 2010-01-30 10:25:18 +0530 | [diff] [blame] | 41 | static inline unsigned long hw_breakpoint_len(struct perf_event *bp) |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 42 | { |
| 43 | return bp->attr.bp_len; |
| 44 | } |
| 45 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 46 | extern struct perf_event * |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 47 | register_user_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 48 | perf_overflow_handler_t triggered, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 49 | void *context, |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 50 | struct task_struct *tsk); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 51 | |
| 52 | /* FIXME: only change from the attr, and don't unregister */ |
Frederic Weisbecker | 44234ad | 2009-12-09 09:25:48 +0100 | [diff] [blame] | 53 | extern int |
Frederic Weisbecker | 2f0993e | 2009-12-05 07:06:10 +0100 | [diff] [blame] | 54 | modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 55 | |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 56 | /* |
| 57 | * Kernel breakpoints are not associated with any particular thread. |
| 58 | */ |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 59 | extern struct perf_event * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 60 | register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 61 | perf_overflow_handler_t triggered, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 62 | void *context, |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 63 | int cpu); |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 64 | |
Tejun Heo | 44ee635 | 2010-02-17 10:50:50 +0900 | [diff] [blame] | 65 | extern struct perf_event * __percpu * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 66 | register_wide_hw_breakpoint(struct perf_event_attr *attr, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 67 | perf_overflow_handler_t triggered, |
| 68 | void *context); |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 69 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 70 | extern int register_perf_hw_breakpoint(struct perf_event *bp); |
| 71 | extern int __register_perf_hw_breakpoint(struct perf_event *bp); |
| 72 | extern void unregister_hw_breakpoint(struct perf_event *bp); |
Tejun Heo | 44ee635 | 2010-02-17 10:50:50 +0900 | [diff] [blame] | 73 | extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 74 | |
Jason Wessel | 5352ae6 | 2010-01-28 17:04:43 -0600 | [diff] [blame] | 75 | extern int dbg_reserve_bp_slot(struct perf_event *bp); |
| 76 | extern int dbg_release_bp_slot(struct perf_event *bp); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 77 | extern int reserve_bp_slot(struct perf_event *bp); |
| 78 | extern void release_bp_slot(struct perf_event *bp); |
| 79 | |
| 80 | extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk); |
| 81 | |
Frederic Weisbecker | 687b16f | 2009-11-13 13:16:15 +0100 | [diff] [blame] | 82 | static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) |
| 83 | { |
| 84 | return &bp->hw.info; |
| 85 | } |
| 86 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 87 | #else /* !CONFIG_HAVE_HW_BREAKPOINT */ |
| 88 | |
Jason Wessel | 3c502e7 | 2010-11-04 17:33:01 -0500 | [diff] [blame] | 89 | static inline int __init init_hw_breakpoint(void) { return 0; } |
| 90 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 91 | static inline struct perf_event * |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 92 | register_user_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 93 | perf_overflow_handler_t triggered, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 94 | void *context, |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 95 | struct task_struct *tsk) { return NULL; } |
Frederic Weisbecker | 44234ad | 2009-12-09 09:25:48 +0100 | [diff] [blame] | 96 | static inline int |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 97 | modify_user_hw_breakpoint(struct perf_event *bp, |
Frederic Weisbecker | 99ac64c | 2009-12-11 11:58:42 +0100 | [diff] [blame] | 98 | struct perf_event_attr *attr) { return -ENOSYS; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 99 | static inline struct perf_event * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 100 | register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, |
Frederic Weisbecker | b326e95 | 2009-12-05 09:44:31 +0100 | [diff] [blame] | 101 | perf_overflow_handler_t triggered, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 102 | void *context, |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 103 | int cpu) { return NULL; } |
Tejun Heo | 44ee635 | 2010-02-17 10:50:50 +0900 | [diff] [blame] | 104 | static inline struct perf_event * __percpu * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 105 | register_wide_hw_breakpoint(struct perf_event_attr *attr, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 106 | perf_overflow_handler_t triggered, |
| 107 | void *context) { return NULL; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 108 | static inline int |
| 109 | register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } |
| 110 | static inline int |
| 111 | __register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } |
| 112 | static inline void unregister_hw_breakpoint(struct perf_event *bp) { } |
| 113 | static inline void |
Tejun Heo | 44ee635 | 2010-02-17 10:50:50 +0900 | [diff] [blame] | 114 | unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 115 | static inline int |
| 116 | reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; } |
| 117 | static inline void release_bp_slot(struct perf_event *bp) { } |
| 118 | |
| 119 | static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { } |
| 120 | |
Frederic Weisbecker | 687b16f | 2009-11-13 13:16:15 +0100 | [diff] [blame] | 121 | static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) |
| 122 | { |
| 123 | return NULL; |
| 124 | } |
| 125 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 126 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 127 | #endif /* _LINUX_HW_BREAKPOINT_H */ |