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 { |
| 12 | HW_BREAKPOINT_R = 1, |
| 13 | HW_BREAKPOINT_W = 2, |
| 14 | HW_BREAKPOINT_X = 4, |
| 15 | }; |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 16 | |
Frederic Weisbecker | 5093eba | 2009-11-22 05:21:35 +0100 | [diff] [blame] | 17 | #ifdef __KERNEL__ |
Ingo Molnar | 688bcaf | 2009-11-14 01:12:47 +0100 | [diff] [blame] | 18 | |
Frederic Weisbecker | e6db487 | 2009-11-23 15:42:32 +0100 | [diff] [blame] | 19 | #include <linux/perf_event.h> |
| 20 | |
Frederic Weisbecker | fa7c27e | 2009-11-23 22:30:12 +0100 | [diff] [blame] | 21 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 22 | |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 23 | /* As it's for in-kernel or ptrace use, we want it to be pinned */ |
| 24 | #define DEFINE_BREAKPOINT_ATTR(name) \ |
| 25 | struct perf_event_attr name = { \ |
| 26 | .type = PERF_TYPE_BREAKPOINT, \ |
| 27 | .size = sizeof(name), \ |
| 28 | .pinned = 1, \ |
| 29 | }; |
| 30 | |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 31 | static inline void hw_breakpoint_init(struct perf_event_attr *attr) |
| 32 | { |
| 33 | attr->type = PERF_TYPE_BREAKPOINT; |
| 34 | attr->size = sizeof(*attr); |
| 35 | attr->pinned = 1; |
| 36 | } |
| 37 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 38 | static inline unsigned long hw_breakpoint_addr(struct perf_event *bp) |
| 39 | { |
| 40 | return bp->attr.bp_addr; |
| 41 | } |
| 42 | |
| 43 | static inline int hw_breakpoint_type(struct perf_event *bp) |
| 44 | { |
| 45 | return bp->attr.bp_type; |
| 46 | } |
| 47 | |
| 48 | static inline int hw_breakpoint_len(struct perf_event *bp) |
| 49 | { |
| 50 | return bp->attr.bp_len; |
| 51 | } |
| 52 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 53 | extern struct perf_event * |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 54 | register_user_hw_breakpoint(struct perf_event_attr *attr, |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 55 | perf_callback_t triggered, |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 56 | struct task_struct *tsk); |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 57 | |
| 58 | /* FIXME: only change from the attr, and don't unregister */ |
| 59 | extern struct perf_event * |
Frederic Weisbecker | 2f0993e | 2009-12-05 07:06:10 +0100 | [diff] [blame^] | 60 | 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] | 61 | |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 62 | /* |
| 63 | * Kernel breakpoints are not associated with any particular thread. |
| 64 | */ |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 65 | extern struct perf_event * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 66 | register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 67 | perf_callback_t triggered, |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 68 | int cpu); |
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 struct perf_event ** |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 71 | register_wide_hw_breakpoint(struct perf_event_attr *attr, |
| 72 | perf_callback_t triggered); |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 73 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 74 | extern int register_perf_hw_breakpoint(struct perf_event *bp); |
| 75 | extern int __register_perf_hw_breakpoint(struct perf_event *bp); |
| 76 | extern void unregister_hw_breakpoint(struct perf_event *bp); |
| 77 | extern void unregister_wide_hw_breakpoint(struct perf_event **cpu_events); |
| 78 | |
| 79 | extern int reserve_bp_slot(struct perf_event *bp); |
| 80 | extern void release_bp_slot(struct perf_event *bp); |
| 81 | |
| 82 | extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk); |
| 83 | |
Frederic Weisbecker | 687b16f | 2009-11-13 13:16:15 +0100 | [diff] [blame] | 84 | static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) |
| 85 | { |
| 86 | return &bp->hw.info; |
| 87 | } |
| 88 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 89 | #else /* !CONFIG_HAVE_HW_BREAKPOINT */ |
| 90 | |
| 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 | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 93 | perf_callback_t triggered, |
Frederic Weisbecker | 5fa10b2 | 2009-11-27 04:55:53 +0100 | [diff] [blame] | 94 | struct task_struct *tsk) { return NULL; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 95 | static inline struct perf_event * |
| 96 | modify_user_hw_breakpoint(struct perf_event *bp, |
Frederic Weisbecker | 2f0993e | 2009-12-05 07:06:10 +0100 | [diff] [blame^] | 97 | struct perf_event_attr *attr) { return NULL; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 98 | static inline struct perf_event * |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 99 | register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr, |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 100 | perf_callback_t triggered, |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 101 | int cpu) { return NULL; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 102 | static inline struct perf_event ** |
Frederic Weisbecker | dd1853c | 2009-11-27 04:55:54 +0100 | [diff] [blame] | 103 | register_wide_hw_breakpoint(struct perf_event_attr *attr, |
| 104 | perf_callback_t triggered) { return NULL; } |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 105 | static inline int |
| 106 | register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } |
| 107 | static inline int |
| 108 | __register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } |
| 109 | static inline void unregister_hw_breakpoint(struct perf_event *bp) { } |
| 110 | static inline void |
| 111 | unregister_wide_hw_breakpoint(struct perf_event **cpu_events) { } |
| 112 | static inline int |
| 113 | reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; } |
| 114 | static inline void release_bp_slot(struct perf_event *bp) { } |
| 115 | |
| 116 | static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { } |
| 117 | |
Frederic Weisbecker | 687b16f | 2009-11-13 13:16:15 +0100 | [diff] [blame] | 118 | static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp) |
| 119 | { |
| 120 | return NULL; |
| 121 | } |
| 122 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 123 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Frederic Weisbecker | 5093eba | 2009-11-22 05:21:35 +0100 | [diff] [blame] | 124 | #endif /* __KERNEL__ */ |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 125 | |
| 126 | #endif /* _LINUX_HW_BREAKPOINT_H */ |