Merge git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[deliverable/linux.git] / arch / powerpc / oprofile / common.c
CommitLineData
1da177e4 1/*
86a5cddb 2 * PPC 64 oprofile support:
1da177e4 3 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
86a5cddb
SR
4 * PPC 32 oprofile support: (based on PPC 64 support)
5 * Copyright (C) Freescale Semiconductor, Inc 2004
6 * Author: Andy Fleming
1da177e4
LT
7 *
8 * Based on alpha version.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16#include <linux/oprofile.h>
17#include <linux/init.h>
18#include <linux/smp.h>
19#include <linux/errno.h>
20#include <asm/ptrace.h>
21#include <asm/system.h>
22#include <asm/pmc.h>
a6908cd0 23#include <asm/cputable.h>
dca85932 24#include <asm/oprofile_impl.h>
2191fe3e 25#include <asm/firmware.h>
1da177e4 26
a3e48c10 27static struct op_powerpc_model *model;
1da177e4
LT
28
29static struct op_counter_config ctr[OP_MAX_COUNTER];
30static struct op_system_config sys;
31
32static void op_handle_interrupt(struct pt_regs *regs)
33{
34 model->handle_interrupt(regs, ctr);
35}
36
86a5cddb 37static int op_powerpc_setup(void)
1da177e4
LT
38{
39 int err;
40
41 /* Grab the hardware */
42 err = reserve_pmc_hardware(op_handle_interrupt);
43 if (err)
44 return err;
45
46 /* Pre-compute the values to stuff in the hardware registers. */
47 model->reg_setup(ctr, &sys, model->num_counters);
48
49 /* Configure the registers on all cpus. */
50 on_each_cpu(model->cpu_setup, NULL, 0, 1);
51
52 return 0;
53}
54
86a5cddb 55static void op_powerpc_shutdown(void)
1da177e4
LT
56{
57 release_pmc_hardware();
58}
59
86a5cddb 60static void op_powerpc_cpu_start(void *dummy)
1da177e4
LT
61{
62 model->start(ctr);
63}
64
86a5cddb 65static int op_powerpc_start(void)
1da177e4 66{
86a5cddb 67 on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
1da177e4
LT
68 return 0;
69}
70
86a5cddb 71static inline void op_powerpc_cpu_stop(void *dummy)
1da177e4
LT
72{
73 model->stop();
74}
75
86a5cddb 76static void op_powerpc_stop(void)
1da177e4 77{
86a5cddb 78 on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
1da177e4
LT
79}
80
86a5cddb 81static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
1da177e4
LT
82{
83 int i;
84
555d97ac 85#ifdef CONFIG_PPC64
1da177e4
LT
86 /*
87 * There is one mmcr0, mmcr1 and mmcra for setting the events for
88 * all of the counters.
89 */
90 oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
91 oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
92 oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
555d97ac 93#endif
1da177e4
LT
94
95 for (i = 0; i < model->num_counters; ++i) {
96 struct dentry *dir;
97 char buf[3];
98
99 snprintf(buf, sizeof buf, "%d", i);
100 dir = oprofilefs_mkdir(sb, root, buf);
101
102 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
103 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
104 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
555d97ac 105
1da177e4 106 /*
555d97ac
AF
107 * Classic PowerPC doesn't support per-counter
108 * control like this, but the options are
109 * expected, so they remain. For Freescale
110 * Book-E style performance monitors, we do
111 * support them.
1da177e4
LT
112 */
113 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
114 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
86a5cddb 115
1da177e4
LT
116 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
117 }
118
119 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
120 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
1da177e4
LT
121
122 /* Default to tracing both kernel and user */
123 sys.enable_kernel = 1;
124 sys.enable_user = 1;
1da177e4
LT
125
126 return 0;
127}
128
129int __init oprofile_arch_init(struct oprofile_operations *ops)
130{
32a33994 131 if (!cur_cpu_spec->oprofile_cpu_type)
8fef0306 132 return -ENODEV;
32a33994 133
2191fe3e
KD
134 if (firmware_has_feature(FW_FEATURE_ISERIES))
135 return -ENODEV;
136
32a33994
AB
137 switch (cur_cpu_spec->oprofile_type) {
138#ifdef CONFIG_PPC64
7a45fb19 139 case PPC_OPROFILE_RS64:
32a33994
AB
140 model = &op_model_rs64;
141 break;
7a45fb19 142 case PPC_OPROFILE_POWER4:
32a33994
AB
143 model = &op_model_power4;
144 break;
145#else
7a45fb19 146 case PPC_OPROFILE_G4:
32a33994
AB
147 model = &op_model_7450;
148 break;
149#endif
150#ifdef CONFIG_FSL_BOOKE
7a45fb19 151 case PPC_OPROFILE_BOOKE:
32a33994
AB
152 model = &op_model_fsl_booke;
153 break;
154#endif
155 default:
156 return -ENODEV;
157 }
158
a6908cd0 159 model->num_counters = cur_cpu_spec->num_pmcs;
8fef0306
AB
160
161 ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
86a5cddb
SR
162 ops->create_files = op_powerpc_create_files;
163 ops->setup = op_powerpc_setup;
164 ops->shutdown = op_powerpc_shutdown;
165 ops->start = op_powerpc_start;
166 ops->stop = op_powerpc_stop;
6c6bd754 167 ops->backtrace = op_powerpc_backtrace;
1da177e4 168
5e1415c3 169 printk(KERN_DEBUG "oprofile: using %s performance monitoring.\n",
1da177e4
LT
170 ops->cpu_type);
171
172 return 0;
173}
174
175void oprofile_arch_exit(void)
176{
177}
This page took 0.123784 seconds and 5 git commands to generate.