Merge tag 'gvt-next-2019-02-01' of https://github.com/intel/gvt-linux into drm-intel...
[linux-2.6-block.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>
1da177e4 21#include <asm/pmc.h>
a6908cd0 22#include <asm/cputable.h>
dca85932 23#include <asm/oprofile_impl.h>
2191fe3e 24#include <asm/firmware.h>
1da177e4 25
a3e48c10 26static struct op_powerpc_model *model;
1da177e4
LT
27
28static struct op_counter_config ctr[OP_MAX_COUNTER];
29static struct op_system_config sys;
30
1474855d
BN
31static int op_per_cpu_rc;
32
1da177e4
LT
33static void op_handle_interrupt(struct pt_regs *regs)
34{
35 model->handle_interrupt(regs, ctr);
36}
37
dd6c89f6
AF
38static void op_powerpc_cpu_setup(void *dummy)
39{
1474855d
BN
40 int ret;
41
42 ret = model->cpu_setup(ctr);
43
44 if (ret != 0)
45 op_per_cpu_rc = ret;
dd6c89f6
AF
46}
47
86a5cddb 48static int op_powerpc_setup(void)
1da177e4
LT
49{
50 int err;
51
1474855d
BN
52 op_per_cpu_rc = 0;
53
1da177e4
LT
54 /* Grab the hardware */
55 err = reserve_pmc_hardware(op_handle_interrupt);
56 if (err)
57 return err;
58
59 /* Pre-compute the values to stuff in the hardware registers. */
1474855d 60 op_per_cpu_rc = model->reg_setup(ctr, &sys, model->num_counters);
1da177e4 61
1474855d
BN
62 if (op_per_cpu_rc)
63 goto out;
64
65 /* Configure the registers on all cpus. If an error occurs on one
66 * of the cpus, op_per_cpu_rc will be set to the error */
15c8b6c1 67 on_each_cpu(op_powerpc_cpu_setup, NULL, 1);
1da177e4 68
1474855d
BN
69out: if (op_per_cpu_rc) {
70 /* error on setup release the performance counter hardware */
71 release_pmc_hardware();
72 }
73
74 return op_per_cpu_rc;
1da177e4
LT
75}
76
86a5cddb 77static void op_powerpc_shutdown(void)
1da177e4
LT
78{
79 release_pmc_hardware();
80}
81
86a5cddb 82static void op_powerpc_cpu_start(void *dummy)
1da177e4 83{
1474855d
BN
84 /* If any of the cpus have return an error, set the
85 * global flag to the error so it can be returned
86 * to the generic OProfile caller.
87 */
88 int ret;
89
90 ret = model->start(ctr);
91 if (ret != 0)
92 op_per_cpu_rc = ret;
1da177e4
LT
93}
94
86a5cddb 95static int op_powerpc_start(void)
1da177e4 96{
1474855d
BN
97 op_per_cpu_rc = 0;
98
18f2190d 99 if (model->global_start)
1474855d
BN
100 return model->global_start(ctr);
101 if (model->start) {
15c8b6c1 102 on_each_cpu(op_powerpc_cpu_start, NULL, 1);
1474855d
BN
103 return op_per_cpu_rc;
104 }
105 return -EIO; /* No start function is defined for this
106 power architecture */
1da177e4
LT
107}
108
86a5cddb 109static inline void op_powerpc_cpu_stop(void *dummy)
1da177e4
LT
110{
111 model->stop();
112}
113
86a5cddb 114static void op_powerpc_stop(void)
1da177e4 115{
18f2190d 116 if (model->stop)
15c8b6c1 117 on_each_cpu(op_powerpc_cpu_stop, NULL, 1);
18f2190d
MJ
118 if (model->global_stop)
119 model->global_stop();
1da177e4
LT
120}
121
ef7bca14 122static int op_powerpc_create_files(struct dentry *root)
1da177e4
LT
123{
124 int i;
125
555d97ac 126#ifdef CONFIG_PPC64
1da177e4
LT
127 /*
128 * There is one mmcr0, mmcr1 and mmcra for setting the events for
129 * all of the counters.
130 */
6af4ea0b
AV
131 oprofilefs_create_ulong(root, "mmcr0", &sys.mmcr0);
132 oprofilefs_create_ulong(root, "mmcr1", &sys.mmcr1);
133 oprofilefs_create_ulong(root, "mmcra", &sys.mmcra);
88382329
CL
134#ifdef CONFIG_OPROFILE_CELL
135 /* create a file the user tool can check to see what level of profiling
136 * support exits with this kernel. Initialize bit mask to indicate
137 * what support the kernel has:
138 * bit 0 - Supports SPU event profiling in addition to PPU
139 * event and cycles; and SPU cycle profiling
140 * bits 1-31 - Currently unused.
141 *
142 * If the file does not exist, then the kernel only supports SPU
143 * cycle profiling, PPU event and cycle profiling.
144 */
6af4ea0b 145 oprofilefs_create_ulong(root, "cell_support", &sys.cell_support);
88382329
CL
146 sys.cell_support = 0x1; /* Note, the user OProfile tool must check
147 * that this bit is set before attempting to
148 * user SPU event profiling. Older kernels
149 * will not have this file, hence the user
150 * tool is not allowed to do SPU event
151 * profiling on older kernels. Older kernels
152 * will accept SPU events but collected data
153 * is garbage.
154 */
155#endif
555d97ac 156#endif
1da177e4
LT
157
158 for (i = 0; i < model->num_counters; ++i) {
159 struct dentry *dir;
0c6856f7 160 char buf[4];
1da177e4
LT
161
162 snprintf(buf, sizeof buf, "%d", i);
ecde2823 163 dir = oprofilefs_mkdir(root, buf);
1da177e4 164
6af4ea0b
AV
165 oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
166 oprofilefs_create_ulong(dir, "event", &ctr[i].event);
167 oprofilefs_create_ulong(dir, "count", &ctr[i].count);
555d97ac 168
1da177e4 169 /*
555d97ac
AF
170 * Classic PowerPC doesn't support per-counter
171 * control like this, but the options are
172 * expected, so they remain. For Freescale
173 * Book-E style performance monitors, we do
174 * support them.
1da177e4 175 */
6af4ea0b
AV
176 oprofilefs_create_ulong(dir, "kernel", &ctr[i].kernel);
177 oprofilefs_create_ulong(dir, "user", &ctr[i].user);
86a5cddb 178
6af4ea0b 179 oprofilefs_create_ulong(dir, "unit_mask", &ctr[i].unit_mask);
1da177e4
LT
180 }
181
6af4ea0b
AV
182 oprofilefs_create_ulong(root, "enable_kernel", &sys.enable_kernel);
183 oprofilefs_create_ulong(root, "enable_user", &sys.enable_user);
1da177e4
LT
184
185 /* Default to tracing both kernel and user */
186 sys.enable_kernel = 1;
187 sys.enable_user = 1;
1da177e4
LT
188
189 return 0;
190}
191
192int __init oprofile_arch_init(struct oprofile_operations *ops)
193{
32a33994 194 if (!cur_cpu_spec->oprofile_cpu_type)
8fef0306 195 return -ENODEV;
32a33994
AB
196
197 switch (cur_cpu_spec->oprofile_type) {
1caca371 198#ifdef CONFIG_PPC_BOOK3S_64
1474855d 199#ifdef CONFIG_OPROFILE_CELL
18f2190d 200 case PPC_OPROFILE_CELL:
ef66f796
IK
201 if (firmware_has_feature(FW_FEATURE_LPAR))
202 return -ENODEV;
18f2190d 203 model = &op_model_cell;
1474855d
BN
204 ops->sync_start = model->sync_start;
205 ops->sync_stop = model->sync_stop;
18f2190d
MJ
206 break;
207#endif
7a45fb19 208 case PPC_OPROFILE_POWER4:
32a33994
AB
209 model = &op_model_power4;
210 break;
25fc530e
OJ
211 case PPC_OPROFILE_PA6T:
212 model = &op_model_pa6t;
213 break;
dd6c89f6 214#endif
d7cceda9 215#ifdef CONFIG_PPC_BOOK3S_32
7a45fb19 216 case PPC_OPROFILE_G4:
32a33994
AB
217 model = &op_model_7450;
218 break;
219#endif
39aef685
AF
220#if defined(CONFIG_FSL_EMB_PERFMON)
221 case PPC_OPROFILE_FSL_EMB:
222 model = &op_model_fsl_emb;
32a33994
AB
223 break;
224#endif
225 default:
226 return -ENODEV;
227 }
228
a6908cd0 229 model->num_counters = cur_cpu_spec->num_pmcs;
8fef0306
AB
230
231 ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
86a5cddb
SR
232 ops->create_files = op_powerpc_create_files;
233 ops->setup = op_powerpc_setup;
234 ops->shutdown = op_powerpc_shutdown;
235 ops->start = op_powerpc_start;
236 ops->stop = op_powerpc_stop;
6c6bd754 237 ops->backtrace = op_powerpc_backtrace;
1da177e4 238
5e1415c3 239 printk(KERN_DEBUG "oprofile: using %s performance monitoring.\n",
1da177e4
LT
240 ops->cpu_type);
241
242 return 0;
243}
244
245void oprofile_arch_exit(void)
246{
247}