Merge 2.6.38-rc5 into staging-next
[deliverable/linux.git] / arch / arm / oprofile / common.c
CommitLineData
1da177e4
LT
1/**
2 * @file common.c
3 *
4 * @remark Copyright 2004 Oprofile Authors
8c1fc96f 5 * @remark Copyright 2010 ARM Ltd.
1da177e4
LT
6 * @remark Read the file COPYING
7 *
8 * @author Zwane Mwaikambo
8c1fc96f 9 * @author Will Deacon [move to perf]
1da177e4
LT
10 */
11
8c1fc96f 12#include <linux/cpumask.h>
1da177e4 13#include <linux/init.h>
8c1fc96f 14#include <linux/mutex.h>
1da177e4 15#include <linux/oprofile.h>
8c1fc96f 16#include <linux/perf_event.h>
d1e86d64 17#include <linux/platform_device.h>
ae92dc9f 18#include <linux/slab.h>
8c1fc96f
WD
19#include <asm/stacktrace.h>
20#include <linux/uaccess.h>
21
22#include <asm/perf_event.h>
23#include <asm/ptrace.h>
1da177e4 24
8c1fc96f 25#ifdef CONFIG_HW_PERF_EVENTS
56946331 26char *op_name_from_perf_id(void)
8c1fc96f 27{
56946331
MF
28 enum arm_perf_pmu_ids id = armpmu_get_pmu_id();
29
8c1fc96f
WD
30 switch (id) {
31 case ARM_PERF_PMU_ID_XSCALE1:
32 return "arm/xscale1";
33 case ARM_PERF_PMU_ID_XSCALE2:
34 return "arm/xscale2";
35 case ARM_PERF_PMU_ID_V6:
36 return "arm/armv6";
37 case ARM_PERF_PMU_ID_V6MP:
38 return "arm/mpcore";
39 case ARM_PERF_PMU_ID_CA8:
40 return "arm/armv7";
41 case ARM_PERF_PMU_ID_CA9:
42 return "arm/armv7-ca9";
43 default:
44 return NULL;
45 }
46}
d14dd7e2 47#endif
1da177e4 48
8c1fc96f 49static int report_trace(struct stackframe *frame, void *d)
1da177e4 50{
8c1fc96f 51 unsigned int *depth = d;
c6b9dafc 52
8c1fc96f
WD
53 if (*depth) {
54 oprofile_add_trace(frame->pc);
55 (*depth)--;
56 }
1b7b5698 57
8c1fc96f
WD
58 return *depth == 0;
59}
c6b9dafc 60
8c1fc96f
WD
61/*
62 * The registers we're interested in are at the end of the variable
63 * length saved register structure. The fp points at the end of this
64 * structure so the address of this struct is:
65 * (struct frame_tail *)(xxx->fp)-1
66 */
67struct frame_tail {
68 struct frame_tail *fp;
69 unsigned long sp;
70 unsigned long lr;
71} __attribute__((packed));
2d9e1ae0 72
8c1fc96f
WD
73static struct frame_tail* user_backtrace(struct frame_tail *tail)
74{
75 struct frame_tail buftail[2];
10c03f69 76
8c1fc96f
WD
77 /* Also check accessibility of one struct frame_tail beyond */
78 if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
79 return NULL;
80 if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
81 return NULL;
d7ac4e28 82
8c1fc96f 83 oprofile_add_trace(buftail[0].lr);
c6b9dafc 84
8c1fc96f
WD
85 /* frame pointers should strictly progress back up the stack
86 * (towards higher addresses) */
cb06199b 87 if (tail + 1 >= buftail[0].fp)
8c1fc96f
WD
88 return NULL;
89
90 return buftail[0].fp-1;
91}
92
93static void arm_backtrace(struct pt_regs * const regs, unsigned int depth)
94{
95 struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;
96
97 if (!user_mode(regs)) {
98 struct stackframe frame;
99 frame.fp = regs->ARM_fp;
100 frame.sp = regs->ARM_sp;
101 frame.lr = regs->ARM_lr;
102 frame.pc = regs->ARM_pc;
103 walk_stackframe(&frame, report_trace, &depth);
104 return;
105 }
106
107 while (depth-- && tail && !((unsigned long) tail & 3))
108 tail = user_backtrace(tail);
109}
110
58850e21
MF
111int __init oprofile_arch_init(struct oprofile_operations *ops)
112{
d14dd7e2 113 /* provide backtrace support also in timer mode: */
58850e21
MF
114 ops->backtrace = arm_backtrace;
115
116 return oprofile_perf_init(ops);
117}
118
58850e21
MF
119void __exit oprofile_arch_exit(void)
120{
121 oprofile_perf_exit();
122}
This page took 0.498496 seconds and 5 git commands to generate.