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