blob: 41235c93e4e95400bf0db52bf2f7b84399d22a39 [file] [log] [blame]
Frederic Weisbecker2da3e162009-11-05 23:06:50 +01001#ifndef _LINUX_HW_BREAKPOINT_H
2#define _LINUX_HW_BREAKPOINT_H
K.Prasadb332828c2009-06-01 23:43:10 +05303
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +02004enum {
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.Prasadb332828c2009-06-01 23:43:10 +05309};
10
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020011enum {
12 HW_BREAKPOINT_R = 1,
13 HW_BREAKPOINT_W = 2,
14 HW_BREAKPOINT_X = 4,
15};
K.Prasadb332828c2009-06-01 23:43:10 +053016
Frederic Weisbecker5093eba2009-11-22 05:21:35 +010017#ifdef __KERNEL__
Ingo Molnar688bcaf2009-11-14 01:12:47 +010018
Frederic Weisbeckere6db4872009-11-23 15:42:32 +010019#include <linux/perf_event.h>
20
Frederic Weisbeckerfa7c27e2009-11-23 22:30:12 +010021#ifdef CONFIG_HAVE_HW_BREAKPOINT
22
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010023static inline void hw_breakpoint_init(struct perf_event_attr *attr)
24{
Frederic Weisbeckered872d02009-12-07 03:14:17 +010025 memset(attr, 0, sizeof(*attr));
26
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010027 attr->type = PERF_TYPE_BREAKPOINT;
28 attr->size = sizeof(*attr);
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010029 /*
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 */
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010033 attr->pinned = 1;
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010034 attr->sample_period = 1;
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010035}
36
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020037static inline unsigned long hw_breakpoint_addr(struct perf_event *bp)
38{
39 return bp->attr.bp_addr;
40}
41
42static inline int hw_breakpoint_type(struct perf_event *bp)
43{
44 return bp->attr.bp_type;
45}
46
47static inline int hw_breakpoint_len(struct perf_event *bp)
48{
49 return bp->attr.bp_len;
50}
51
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020052extern struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010053register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010054 perf_overflow_handler_t triggered,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010055 struct task_struct *tsk);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020056
57/* FIXME: only change from the attr, and don't unregister */
Frederic Weisbecker44234ad2009-12-09 09:25:48 +010058extern int
Frederic Weisbecker2f0993e2009-12-05 07:06:10 +010059modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *attr);
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020060
K.Prasadb332828c2009-06-01 23:43:10 +053061/*
62 * Kernel breakpoints are not associated with any particular thread.
63 */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020064extern struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010065register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010066 perf_overflow_handler_t triggered,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010067 int cpu);
K.Prasadb332828c2009-06-01 23:43:10 +053068
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020069extern struct perf_event **
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010070register_wide_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010071 perf_overflow_handler_t triggered);
K.Prasadb332828c2009-06-01 23:43:10 +053072
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020073extern int register_perf_hw_breakpoint(struct perf_event *bp);
74extern int __register_perf_hw_breakpoint(struct perf_event *bp);
75extern void unregister_hw_breakpoint(struct perf_event *bp);
76extern void unregister_wide_hw_breakpoint(struct perf_event **cpu_events);
77
78extern int reserve_bp_slot(struct perf_event *bp);
79extern void release_bp_slot(struct perf_event *bp);
80
81extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk);
82
Frederic Weisbecker687b16f2009-11-13 13:16:15 +010083static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
84{
85 return &bp->hw.info;
86}
87
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020088#else /* !CONFIG_HAVE_HW_BREAKPOINT */
89
90static inline struct perf_event *
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010091register_user_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010092 perf_overflow_handler_t triggered,
Frederic Weisbecker5fa10b22009-11-27 04:55:53 +010093 struct task_struct *tsk) { return NULL; }
Frederic Weisbecker44234ad2009-12-09 09:25:48 +010094static inline int
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020095modify_user_hw_breakpoint(struct perf_event *bp,
Frederic Weisbecker99ac64c2009-12-11 11:58:42 +010096 struct perf_event_attr *attr) { return -ENOSYS; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +020097static inline struct perf_event *
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +010098register_wide_hw_breakpoint_cpu(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +010099 perf_overflow_handler_t triggered,
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100100 int cpu) { return NULL; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200101static inline struct perf_event **
Frederic Weisbeckerdd1853c2009-11-27 04:55:54 +0100102register_wide_hw_breakpoint(struct perf_event_attr *attr,
Frederic Weisbeckerb326e952009-12-05 09:44:31 +0100103 perf_overflow_handler_t triggered) { return NULL; }
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200104static inline int
105register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
106static inline int
107__register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; }
108static inline void unregister_hw_breakpoint(struct perf_event *bp) { }
109static inline void
110unregister_wide_hw_breakpoint(struct perf_event **cpu_events) { }
111static inline int
112reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; }
113static inline void release_bp_slot(struct perf_event *bp) { }
114
115static inline void flush_ptrace_hw_breakpoint(struct task_struct *tsk) { }
116
Frederic Weisbecker687b16f2009-11-13 13:16:15 +0100117static inline struct arch_hw_breakpoint *counter_arch_bp(struct perf_event *bp)
118{
119 return NULL;
120}
121
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200122#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Frederic Weisbecker5093eba2009-11-22 05:21:35 +0100123#endif /* __KERNEL__ */
Frederic Weisbecker24f1e32c2009-09-09 19:22:48 +0200124
125#endif /* _LINUX_HW_BREAKPOINT_H */