hw-breakpoints: Separate constraint space for data and instruction breakpoints
[linux-2.6.git] / include / linux / hw_breakpoint.h
1 #ifndef _LINUX_HW_BREAKPOINT_H
2 #define _LINUX_HW_BREAKPOINT_H
3
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,
9 };
10
11 enum {
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,
18 };
19
20 #ifdef __KERNEL__
21
22 #include <linux/perf_event.h>
23
24 #ifdef CONFIG_HAVE_HW_BREAKPOINT
25
26 static inline void hw_breakpoint_init(struct perf_event_attr *attr)
27 {
28         memset(attr, 0, sizeof(*attr));
29
30         attr->type = PERF_TYPE_BREAKPOINT;
31         attr->size = sizeof(*attr);
32         /*
33          * As it's for in-kernel or ptrace use, we want it to be pinned
34          * and to call its callback every hits.
35          */
36         attr->pinned = 1;
37         attr->sample_period = 1;
38 }
39
40 static inline void ptrace_breakpoint_init(struct perf_event_attr *attr)
41 {
42         hw_breakpoint_init(attr);
43         attr->exclude_kernel = 1;
44 }
45
46 static inline unsigned long hw_breakpoint_addr(struct perf_event *bp)
47 {
48         return bp->attr.bp_addr;
49 }
50
51 static inline int hw_breakpoint_type(struct perf_event *bp)
52 {
53         return bp->attr.bp_type;
54 }
55
56 static inline unsigned long hw_breakpoint_len(struct perf_event *bp)
57 {
58         return bp->attr.bp_len;
59 }
60
61 extern struct perf_event *
62 register_user_hw_breakpoint(struct perf_event_attr *attr,
63                             perf_overflow_handler_t triggered,
64                             struct task_struct *tsk);
65
66 /* FIXME: only change from the attr, and don't unregister */
67 extern int
68 modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr);
69
70 /*
71  * Kernel breakpoints are not associated with any particular thread.
72  */
73 extern struct perf_event *
74 register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
75                                 perf_overflow_handler_t triggered,
76                                 int cpu);
77
78 extern struct perf_event * __percpu *
79 register_wide_hw_breakpoint(struct perf_event_attr *attr,
80                             perf_overflow_handler_t triggered);
81
82 extern int register_perf_hw_breakpoint(struct perf_event *bp);
83 extern int __register_perf_hw_breakpoint(struct perf_event *bp);
84 extern void unregister_hw_breakpoint(struct perf_event *bp);
85 extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events);
86
87 extern int dbg_reserve_bp_slot(struct perf_event *bp);
88 extern int dbg_release_bp_slot(struct perf_event *bp);
89 extern int reserve_bp_slot(struct perf_event *bp);
90 extern void release_bp_slot(struct perf_event *bp);
91
92 extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);
93
94 static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
95 {
96         return &bp->hw.info;
97 }
98
99 #else /* !CONFIG_HAVE_HW_BREAKPOINT */
100
101 static inline struct perf_event *
102 register_user_hw_breakpoint(struct perf_event_attr *attr,
103                             perf_overflow_handler_t triggered,
104                             struct task_struct *tsk)    { return NULL; }
105 static inline int
106 modify_user_hw_breakpoint(struct perf_event *bp,
107                           struct perf_event_attr *attr) { return -ENOSYS; }
108 static inline struct perf_event *
109 register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
110                                 perf_overflow_handler_t  triggered,
111                                 int cpu)                { return NULL; }
112 static inline struct perf_event * __percpu *
113 register_wide_hw_breakpoint(struct perf_event_attr *attr,
114                             perf_overflow_handler_t triggered)  { return NULL; }
115 static inline int
116 register_perf_hw_breakpoint(struct perf_event *bp)      { return -ENOSYS; }
117 static inline int
118 __register_perf_hw_breakpoint(struct perf_event *bp)    { return -ENOSYS; }
119 static inline void unregister_hw_breakpoint(struct perf_event *bp)      { }
120 static inline void
121 unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { }
122 static inline int
123 reserve_bp_slot(struct perf_event *bp)                  {return -ENOSYS; }
124 static inline void release_bp_slot(struct perf_event *bp)               { }
125
126 static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk)  { }
127
128 static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
129 {
130         return NULL;
131 }
132
133 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
134 #endif /* __KERNEL__ */
135
136 #endif /* _LINUX_HW_BREAKPOINT_H */