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