blob: c3e4c18ef8d4d1ca5e4dc74ffd990b800ca0fd1b [file] [log] [blame]
Ralf Baechle54176732005-02-07 02:54:29 +00001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
Ralf Baechle937a8012006-10-07 19:44:33 +01006 * Copyright (C) 2004, 05, 06 by Ralf Baechle
Ralf Baechle54176732005-02-07 02:54:29 +00007 * Copyright (C) 2005 by MIPS Technologies, Inc.
8 */
Ralf Baechle5e2862e2007-12-06 09:12:28 +00009#include <linux/cpumask.h>
Ralf Baechle54176732005-02-07 02:54:29 +000010#include <linux/oprofile.h>
11#include <linux/interrupt.h>
12#include <linux/smp.h>
Ralf Baechle937a8012006-10-07 19:44:33 +010013#include <asm/irq_regs.h>
Andrew Brestickera669efc2014-09-18 14:47:12 -070014#include <asm/time.h>
Ralf Baechle54176732005-02-07 02:54:29 +000015
16#include "op_impl.h"
17
James Hogan26542942017-02-06 12:37:45 +000018#define M_PERFCTL_EVENT(event) (((event) << MIPS_PERFCTRL_EVENT_S) & \
19 MIPS_PERFCTRL_EVENT)
20#define M_PERFCTL_VPEID(vpe) ((vpe) << MIPS_PERFCTRL_VPEID_S)
Ralf Baechle54176732005-02-07 02:54:29 +000021
Ralf Baechle70342282013-01-22 12:59:30 +010022#define M_COUNTER_OVERFLOW (1UL << 31)
Ralf Baechle92c7b622006-06-23 18:39:00 +010023
Dmitri Vorobiev46684732008-04-02 03:58:38 +040024static int (*save_perf_irq)(void);
Andrew Brestickera669efc2014-09-18 14:47:12 -070025static int perfcount_irq;
Dmitri Vorobiev46684732008-04-02 03:58:38 +040026
Madhusudan Bhatc7833902012-10-31 12:01:27 +000027/*
28 * XLR has only one set of counters per core. Designate the
29 * first hardware thread in the core for setup and init.
30 * Skip CPUs with non-zero hardware thread id (4 hwt per core)
31 */
Jayachandran C83a18412013-03-25 06:51:52 +000032#if defined(CONFIG_CPU_XLR) && defined(CONFIG_SMP)
Madhusudan Bhatc7833902012-10-31 12:01:27 +000033#define oprofile_skip_cpu(c) ((cpu_logical_map(c) & 0x3) != 0)
34#else
35#define oprofile_skip_cpu(c) 0
36#endif
37
Ralf Baechle92c7b622006-06-23 18:39:00 +010038#ifdef CONFIG_MIPS_MT_SMP
Ralf Baechle39b8d522008-04-28 17:14:26 +010039static int cpu_has_mipsmt_pertccounters;
James Hogan26542942017-02-06 12:37:45 +000040#define WHAT (MIPS_PERFCTRL_MT_EN_VPE | \
Paul Burtonf875a8322017-08-12 19:49:35 -070041 M_PERFCTL_VPEID(cpu_vpe_id(&current_cpu_data)))
Ralf Baechle39b8d522008-04-28 17:14:26 +010042#define vpe_id() (cpu_has_mipsmt_pertccounters ? \
Paul Burtonf875a8322017-08-12 19:49:35 -070043 0 : cpu_vpe_id(&current_cpu_data))
Ralf Baechle5e2862e2007-12-06 09:12:28 +000044
45/*
46 * The number of bits to shift to convert between counters per core and
47 * counters per VPE. There is no reasonable interface atm to obtain the
48 * number of VPEs used by Linux and in the 34K this number is fixed to two
49 * anyways so we hardcore a few things here for the moment. The way it's
50 * done here will ensure that oprofile VSMP kernel will run right on a lesser
51 * core like a 24K also or with maxcpus=1.
52 */
53static inline unsigned int vpe_shift(void)
54{
55 if (num_possible_cpus() > 1)
56 return 1;
57
58 return 0;
59}
60
Ralf Baechle92c7b622006-06-23 18:39:00 +010061#else
Ralf Baechle5e2862e2007-12-06 09:12:28 +000062
Ralf Baechlebe609f32006-10-23 13:22:06 +010063#define WHAT 0
Ralf Baechle6f4c5bd2007-04-24 21:42:20 +010064#define vpe_id() 0
Ralf Baechle5e2862e2007-12-06 09:12:28 +000065
66static inline unsigned int vpe_shift(void)
67{
68 return 0;
69}
70
Ralf Baechle92c7b622006-06-23 18:39:00 +010071#endif
72
Ralf Baechle5e2862e2007-12-06 09:12:28 +000073static inline unsigned int counters_total_to_per_cpu(unsigned int counters)
74{
75 return counters >> vpe_shift();
76}
77
78static inline unsigned int counters_per_cpu_to_total(unsigned int counters)
79{
80 return counters << vpe_shift();
81}
82
Ralf Baechle92c7b622006-06-23 18:39:00 +010083#define __define_perf_accessors(r, n, np) \
84 \
85static inline unsigned int r_c0_ ## r ## n(void) \
86{ \
Ralf Baechlebe609f32006-10-23 13:22:06 +010087 unsigned int cpu = vpe_id(); \
Ralf Baechle92c7b622006-06-23 18:39:00 +010088 \
89 switch (cpu) { \
90 case 0: \
91 return read_c0_ ## r ## n(); \
92 case 1: \
93 return read_c0_ ## r ## np(); \
94 default: \
95 BUG(); \
96 } \
Thiemo Seufer30f244a2006-07-07 10:38:51 +010097 return 0; \
Ralf Baechle92c7b622006-06-23 18:39:00 +010098} \
99 \
100static inline void w_c0_ ## r ## n(unsigned int value) \
101{ \
Ralf Baechlebe609f32006-10-23 13:22:06 +0100102 unsigned int cpu = vpe_id(); \
Ralf Baechle92c7b622006-06-23 18:39:00 +0100103 \
104 switch (cpu) { \
105 case 0: \
106 write_c0_ ## r ## n(value); \
107 return; \
108 case 1: \
109 write_c0_ ## r ## np(value); \
110 return; \
111 default: \
112 BUG(); \
113 } \
Thiemo Seufer30f244a2006-07-07 10:38:51 +0100114 return; \
Ralf Baechle92c7b622006-06-23 18:39:00 +0100115} \
116
117__define_perf_accessors(perfcntr, 0, 2)
118__define_perf_accessors(perfcntr, 1, 3)
Chris Dearman795a2252007-03-01 17:58:24 +0000119__define_perf_accessors(perfcntr, 2, 0)
120__define_perf_accessors(perfcntr, 3, 1)
Ralf Baechle92c7b622006-06-23 18:39:00 +0100121
122__define_perf_accessors(perfctrl, 0, 2)
123__define_perf_accessors(perfctrl, 1, 3)
Chris Dearman795a2252007-03-01 17:58:24 +0000124__define_perf_accessors(perfctrl, 2, 0)
125__define_perf_accessors(perfctrl, 3, 1)
Ralf Baechle54176732005-02-07 02:54:29 +0000126
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900127struct op_mips_model op_model_mipsxx_ops;
Ralf Baechle54176732005-02-07 02:54:29 +0000128
129static struct mipsxx_register_config {
130 unsigned int control[4];
131 unsigned int counter[4];
132} reg;
133
Ralf Baechle70342282013-01-22 12:59:30 +0100134/* Compute all of the registers in preparation for enabling profiling. */
Ralf Baechle54176732005-02-07 02:54:29 +0000135
136static void mipsxx_reg_setup(struct op_counter_config *ctr)
137{
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900138 unsigned int counters = op_model_mipsxx_ops.num_counters;
Ralf Baechle54176732005-02-07 02:54:29 +0000139 int i;
140
141 /* Compute the performance counter control word. */
Ralf Baechle54176732005-02-07 02:54:29 +0000142 for (i = 0; i < counters; i++) {
143 reg.control[i] = 0;
144 reg.counter[i] = 0;
145
146 if (!ctr[i].enabled)
147 continue;
148
149 reg.control[i] = M_PERFCTL_EVENT(ctr[i].event) |
James Hogan26542942017-02-06 12:37:45 +0000150 MIPS_PERFCTRL_IE;
Ralf Baechle54176732005-02-07 02:54:29 +0000151 if (ctr[i].kernel)
James Hogan26542942017-02-06 12:37:45 +0000152 reg.control[i] |= MIPS_PERFCTRL_K;
Ralf Baechle54176732005-02-07 02:54:29 +0000153 if (ctr[i].user)
James Hogan26542942017-02-06 12:37:45 +0000154 reg.control[i] |= MIPS_PERFCTRL_U;
Ralf Baechle54176732005-02-07 02:54:29 +0000155 if (ctr[i].exl)
James Hogan26542942017-02-06 12:37:45 +0000156 reg.control[i] |= MIPS_PERFCTRL_EXL;
Ralf Baechlecf5b2d232013-08-01 18:31:05 +0200157 if (boot_cpu_type() == CPU_XLR)
James Hogan26542942017-02-06 12:37:45 +0000158 reg.control[i] |= XLR_PERFCTRL_ALLTHREADS;
Ralf Baechle54176732005-02-07 02:54:29 +0000159 reg.counter[i] = 0x80000000 - ctr[i].count;
160 }
161}
162
Ralf Baechle70342282013-01-22 12:59:30 +0100163/* Program all of the registers in preparation for enabling profiling. */
Ralf Baechle54176732005-02-07 02:54:29 +0000164
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100165static void mipsxx_cpu_setup(void *args)
Ralf Baechle54176732005-02-07 02:54:29 +0000166{
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900167 unsigned int counters = op_model_mipsxx_ops.num_counters;
Ralf Baechle54176732005-02-07 02:54:29 +0000168
Madhusudan Bhatc7833902012-10-31 12:01:27 +0000169 if (oprofile_skip_cpu(smp_processor_id()))
170 return;
171
Ralf Baechle54176732005-02-07 02:54:29 +0000172 switch (counters) {
173 case 4:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100174 w_c0_perfctrl3(0);
175 w_c0_perfcntr3(reg.counter[3]);
Ralf Baechle54176732005-02-07 02:54:29 +0000176 case 3:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100177 w_c0_perfctrl2(0);
178 w_c0_perfcntr2(reg.counter[2]);
Ralf Baechle54176732005-02-07 02:54:29 +0000179 case 2:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100180 w_c0_perfctrl1(0);
181 w_c0_perfcntr1(reg.counter[1]);
Ralf Baechle54176732005-02-07 02:54:29 +0000182 case 1:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100183 w_c0_perfctrl0(0);
184 w_c0_perfcntr0(reg.counter[0]);
Ralf Baechle54176732005-02-07 02:54:29 +0000185 }
186}
187
188/* Start all counters on current CPU */
189static void mipsxx_cpu_start(void *args)
190{
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900191 unsigned int counters = op_model_mipsxx_ops.num_counters;
Ralf Baechle54176732005-02-07 02:54:29 +0000192
Madhusudan Bhatc7833902012-10-31 12:01:27 +0000193 if (oprofile_skip_cpu(smp_processor_id()))
194 return;
195
Ralf Baechle54176732005-02-07 02:54:29 +0000196 switch (counters) {
197 case 4:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100198 w_c0_perfctrl3(WHAT | reg.control[3]);
Ralf Baechle54176732005-02-07 02:54:29 +0000199 case 3:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100200 w_c0_perfctrl2(WHAT | reg.control[2]);
Ralf Baechle54176732005-02-07 02:54:29 +0000201 case 2:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100202 w_c0_perfctrl1(WHAT | reg.control[1]);
Ralf Baechle54176732005-02-07 02:54:29 +0000203 case 1:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100204 w_c0_perfctrl0(WHAT | reg.control[0]);
Ralf Baechle54176732005-02-07 02:54:29 +0000205 }
206}
207
208/* Stop all counters on current CPU */
209static void mipsxx_cpu_stop(void *args)
210{
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900211 unsigned int counters = op_model_mipsxx_ops.num_counters;
Ralf Baechle54176732005-02-07 02:54:29 +0000212
Madhusudan Bhatc7833902012-10-31 12:01:27 +0000213 if (oprofile_skip_cpu(smp_processor_id()))
214 return;
215
Ralf Baechle54176732005-02-07 02:54:29 +0000216 switch (counters) {
217 case 4:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100218 w_c0_perfctrl3(0);
Ralf Baechle54176732005-02-07 02:54:29 +0000219 case 3:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100220 w_c0_perfctrl2(0);
Ralf Baechle54176732005-02-07 02:54:29 +0000221 case 2:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100222 w_c0_perfctrl1(0);
Ralf Baechle54176732005-02-07 02:54:29 +0000223 case 1:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100224 w_c0_perfctrl0(0);
Ralf Baechle54176732005-02-07 02:54:29 +0000225 }
226}
227
Ralf Baechle937a8012006-10-07 19:44:33 +0100228static int mipsxx_perfcount_handler(void)
Ralf Baechle54176732005-02-07 02:54:29 +0000229{
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900230 unsigned int counters = op_model_mipsxx_ops.num_counters;
Ralf Baechle54176732005-02-07 02:54:29 +0000231 unsigned int control;
232 unsigned int counter;
Chris Dearmanffe9ee42007-05-24 22:24:20 +0100233 int handled = IRQ_NONE;
234
James Hogan3ba50402015-01-27 21:45:48 +0000235 if (cpu_has_mips_r2 && !(read_c0_cause() & CAUSEF_PCI))
Chris Dearmanffe9ee42007-05-24 22:24:20 +0100236 return handled;
Ralf Baechle54176732005-02-07 02:54:29 +0000237
238 switch (counters) {
239#define HANDLE_COUNTER(n) \
240 case n + 1: \
Ralf Baechle92c7b622006-06-23 18:39:00 +0100241 control = r_c0_perfctrl ## n(); \
242 counter = r_c0_perfcntr ## n(); \
James Hogan26542942017-02-06 12:37:45 +0000243 if ((control & MIPS_PERFCTRL_IE) && \
Ralf Baechle54176732005-02-07 02:54:29 +0000244 (counter & M_COUNTER_OVERFLOW)) { \
Ralf Baechle937a8012006-10-07 19:44:33 +0100245 oprofile_add_sample(get_irq_regs(), n); \
Ralf Baechle92c7b622006-06-23 18:39:00 +0100246 w_c0_perfcntr ## n(reg.counter[n]); \
Chris Dearmanffe9ee42007-05-24 22:24:20 +0100247 handled = IRQ_HANDLED; \
Ralf Baechle54176732005-02-07 02:54:29 +0000248 }
249 HANDLE_COUNTER(3)
250 HANDLE_COUNTER(2)
251 HANDLE_COUNTER(1)
252 HANDLE_COUNTER(0)
253 }
Ralf Baechleba339c02005-12-09 12:29:38 +0000254
255 return handled;
Ralf Baechle54176732005-02-07 02:54:29 +0000256}
257
Ralf Baechle92c7b622006-06-23 18:39:00 +0100258static inline int __n_counters(void)
Ralf Baechle54176732005-02-07 02:54:29 +0000259{
James Hogan30228c42016-05-11 13:50:53 +0100260 if (!cpu_has_perf)
Ralf Baechle54176732005-02-07 02:54:29 +0000261 return 0;
James Hogan26542942017-02-06 12:37:45 +0000262 if (!(read_c0_perfctrl0() & MIPS_PERFCTRL_M))
Ralf Baechle54176732005-02-07 02:54:29 +0000263 return 1;
James Hogan26542942017-02-06 12:37:45 +0000264 if (!(read_c0_perfctrl1() & MIPS_PERFCTRL_M))
Ralf Baechle54176732005-02-07 02:54:29 +0000265 return 2;
James Hogan26542942017-02-06 12:37:45 +0000266 if (!(read_c0_perfctrl2() & MIPS_PERFCTRL_M))
Ralf Baechle54176732005-02-07 02:54:29 +0000267 return 3;
268
269 return 4;
270}
271
Ralf Baechle92c7b622006-06-23 18:39:00 +0100272static inline int n_counters(void)
273{
Ralf Baechle714cfe72006-10-23 00:44:02 +0100274 int counters;
275
Ralf Baechle10cc3522007-10-11 23:46:15 +0100276 switch (current_cpu_type()) {
Ralf Baechle714cfe72006-10-23 00:44:02 +0100277 case CPU_R10000:
278 counters = 2;
Ralf Baechle148171b2007-02-28 15:34:22 +0000279 break;
Ralf Baechle714cfe72006-10-23 00:44:02 +0100280
281 case CPU_R12000:
282 case CPU_R14000:
Joshua Kinard30577392015-01-21 07:59:45 -0500283 case CPU_R16000:
Ralf Baechle714cfe72006-10-23 00:44:02 +0100284 counters = 4;
Ralf Baechle148171b2007-02-28 15:34:22 +0000285 break;
Ralf Baechle714cfe72006-10-23 00:44:02 +0100286
287 default:
288 counters = __n_counters();
289 }
Ralf Baechle92c7b622006-06-23 18:39:00 +0100290
Ralf Baechle92c7b622006-06-23 18:39:00 +0100291 return counters;
292}
293
Ralf Baechle39b8d522008-04-28 17:14:26 +0100294static void reset_counters(void *arg)
Ralf Baechle54176732005-02-07 02:54:29 +0000295{
Thiemo Seufer005ca9a2008-05-06 11:23:33 +0100296 int counters = (int)(long)arg;
Ralf Baechle54176732005-02-07 02:54:29 +0000297 switch (counters) {
298 case 4:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100299 w_c0_perfctrl3(0);
300 w_c0_perfcntr3(0);
Ralf Baechle54176732005-02-07 02:54:29 +0000301 case 3:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100302 w_c0_perfctrl2(0);
303 w_c0_perfcntr2(0);
Ralf Baechle54176732005-02-07 02:54:29 +0000304 case 2:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100305 w_c0_perfctrl1(0);
306 w_c0_perfcntr1(0);
Ralf Baechle54176732005-02-07 02:54:29 +0000307 case 1:
Ralf Baechle92c7b622006-06-23 18:39:00 +0100308 w_c0_perfctrl0(0);
309 w_c0_perfcntr0(0);
Ralf Baechle54176732005-02-07 02:54:29 +0000310 }
311}
312
Felix Fietkau3572a2c2012-05-02 17:33:04 +0200313static irqreturn_t mipsxx_perfcount_int(int irq, void *dev_id)
314{
315 return mipsxx_perfcount_handler();
316}
317
Ralf Baechle54176732005-02-07 02:54:29 +0000318static int __init mipsxx_init(void)
319{
320 int counters;
321
322 counters = n_counters();
Ralf Baechle9efeae92005-12-09 12:34:45 +0000323 if (counters == 0) {
324 printk(KERN_ERR "Oprofile: CPU has no performance counters\n");
Ralf Baechle54176732005-02-07 02:54:29 +0000325 return -ENODEV;
Ralf Baechle9efeae92005-12-09 12:34:45 +0000326 }
Ralf Baechle54176732005-02-07 02:54:29 +0000327
Ralf Baechle39b8d522008-04-28 17:14:26 +0100328#ifdef CONFIG_MIPS_MT_SMP
329 cpu_has_mipsmt_pertccounters = read_c0_config7() & (1<<19);
330 if (!cpu_has_mipsmt_pertccounters)
331 counters = counters_total_to_per_cpu(counters);
332#endif
Ingo Molnarf6f88e92008-07-15 22:08:52 +0200333 on_each_cpu(reset_counters, (void *)(long)counters, 1);
Chris Dearman795a2252007-03-01 17:58:24 +0000334
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900335 op_model_mipsxx_ops.num_counters = counters;
Ralf Baechle10cc3522007-10-11 23:46:15 +0100336 switch (current_cpu_type()) {
Steven J. Hill113c62d2012-07-06 23:56:00 +0200337 case CPU_M14KC:
338 op_model_mipsxx_ops.cpu_type = "mips/M14Kc";
339 break;
340
Steven J. Hillf8fa4812012-12-07 03:51:35 +0000341 case CPU_M14KEC:
342 op_model_mipsxx_ops.cpu_type = "mips/M14KEc";
343 break;
344
Ralf Baechle20659882005-12-09 12:42:13 +0000345 case CPU_20KC:
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900346 op_model_mipsxx_ops.cpu_type = "mips/20K";
Ralf Baechle20659882005-12-09 12:42:13 +0000347 break;
348
Ralf Baechle54176732005-02-07 02:54:29 +0000349 case CPU_24K:
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900350 op_model_mipsxx_ops.cpu_type = "mips/24K";
Ralf Baechle54176732005-02-07 02:54:29 +0000351 break;
352
Ralf Baechle20659882005-12-09 12:42:13 +0000353 case CPU_25KF:
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900354 op_model_mipsxx_ops.cpu_type = "mips/25K";
Ralf Baechle20659882005-12-09 12:42:13 +0000355 break;
356
Ralf Baechle39b8d522008-04-28 17:14:26 +0100357 case CPU_1004K:
Ralf Baechlefcfd9802006-02-01 17:54:30 +0000358 case CPU_34K:
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900359 op_model_mipsxx_ops.cpu_type = "mips/34K";
Ralf Baechlefcfd9802006-02-01 17:54:30 +0000360 break;
Chris Dearmanc6209532006-05-02 14:08:46 +0100361
Steven J. Hill442e14a2014-01-17 15:03:50 -0600362 case CPU_1074K:
Chris Dearmanc6209532006-05-02 14:08:46 +0100363 case CPU_74K:
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900364 op_model_mipsxx_ops.cpu_type = "mips/74K";
Chris Dearmanc6209532006-05-02 14:08:46 +0100365 break;
Ralf Baechlefcfd9802006-02-01 17:54:30 +0000366
Leonid Yegoshin26ab96d2013-11-27 10:07:53 +0000367 case CPU_INTERAPTIV:
368 op_model_mipsxx_ops.cpu_type = "mips/interAptiv";
369 break;
370
Leonid Yegoshin708ac4b2013-11-14 16:12:27 +0000371 case CPU_PROAPTIV:
372 op_model_mipsxx_ops.cpu_type = "mips/proAptiv";
373 break;
374
James Hogan8c7f6ba2014-01-22 16:19:41 +0000375 case CPU_P5600:
376 op_model_mipsxx_ops.cpu_type = "mips/P5600";
377 break;
378
Markos Chandras4e88a862015-07-09 10:40:36 +0100379 case CPU_I6400:
380 op_model_mipsxx_ops.cpu_type = "mips/I6400";
381 break;
382
Leonid Yegoshinf36c4722014-03-04 13:34:43 +0000383 case CPU_M5150:
384 op_model_mipsxx_ops.cpu_type = "mips/M5150";
385 break;
386
Ralf Baechle20659882005-12-09 12:42:13 +0000387 case CPU_5KC:
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900388 op_model_mipsxx_ops.cpu_type = "mips/5K";
Ralf Baechle20659882005-12-09 12:42:13 +0000389 break;
390
Ralf Baechle714cfe72006-10-23 00:44:02 +0100391 case CPU_R10000:
392 if ((current_cpu_data.processor_id & 0xff) == 0x20)
393 op_model_mipsxx_ops.cpu_type = "mips/r10000-v2.x";
394 else
395 op_model_mipsxx_ops.cpu_type = "mips/r10000";
396 break;
397
398 case CPU_R12000:
399 case CPU_R14000:
400 op_model_mipsxx_ops.cpu_type = "mips/r12000";
401 break;
402
Joshua Kinard30577392015-01-21 07:59:45 -0500403 case CPU_R16000:
404 op_model_mipsxx_ops.cpu_type = "mips/r16000";
405 break;
406
Mark Masonc03bc122006-01-17 12:06:32 -0800407 case CPU_SB1:
408 case CPU_SB1A:
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900409 op_model_mipsxx_ops.cpu_type = "mips/sb1";
Mark Masonc03bc122006-01-17 12:06:32 -0800410 break;
411
Kelvin Cheung2fa36392012-06-20 20:05:32 +0100412 case CPU_LOONGSON1:
413 op_model_mipsxx_ops.cpu_type = "mips/loongson1";
414 break;
415
Madhusudan Bhatc7833902012-10-31 12:01:27 +0000416 case CPU_XLR:
417 op_model_mipsxx_ops.cpu_type = "mips/xlr";
418 break;
419
Ralf Baechle54176732005-02-07 02:54:29 +0000420 default:
421 printk(KERN_ERR "Profiling unsupported for this CPU\n");
422
423 return -ENODEV;
424 }
425
Dmitri Vorobiev46684732008-04-02 03:58:38 +0400426 save_perf_irq = perf_irq;
Ralf Baechle54176732005-02-07 02:54:29 +0000427 perf_irq = mipsxx_perfcount_handler;
428
Andrew Brestickera669efc2014-09-18 14:47:12 -0700429 if (get_c0_perfcount_int)
430 perfcount_irq = get_c0_perfcount_int();
James Hogan7eca5b12015-01-27 21:45:49 +0000431 else if (cp0_perfcount_irq >= 0)
Andrew Brestickera669efc2014-09-18 14:47:12 -0700432 perfcount_irq = MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
433 else
434 perfcount_irq = -1;
435
436 if (perfcount_irq >= 0)
437 return request_irq(perfcount_irq, mipsxx_perfcount_int,
James Hogan369a93b2015-01-27 21:45:54 +0000438 IRQF_PERCPU | IRQF_NOBALANCING |
439 IRQF_NO_THREAD | IRQF_NO_SUSPEND |
440 IRQF_SHARED,
441 "Perfcounter", save_perf_irq);
Felix Fietkau3572a2c2012-05-02 17:33:04 +0200442
Ralf Baechle54176732005-02-07 02:54:29 +0000443 return 0;
444}
445
446static void mipsxx_exit(void)
447{
Chris Dearman795a2252007-03-01 17:58:24 +0000448 int counters = op_model_mipsxx_ops.num_counters;
Ralf Baechle5e2862e2007-12-06 09:12:28 +0000449
Andrew Brestickera669efc2014-09-18 14:47:12 -0700450 if (perfcount_irq >= 0)
451 free_irq(perfcount_irq, save_perf_irq);
Felix Fietkau3572a2c2012-05-02 17:33:04 +0200452
Ralf Baechle5e2862e2007-12-06 09:12:28 +0000453 counters = counters_per_cpu_to_total(counters);
Ingo Molnarf6f88e92008-07-15 22:08:52 +0200454 on_each_cpu(reset_counters, (void *)(long)counters, 1);
Ralf Baechle54176732005-02-07 02:54:29 +0000455
Dmitri Vorobiev46684732008-04-02 03:58:38 +0400456 perf_irq = save_perf_irq;
Ralf Baechle54176732005-02-07 02:54:29 +0000457}
458
Atsushi Nemoto1acf1ca2006-05-23 16:42:38 +0900459struct op_mips_model op_model_mipsxx_ops = {
Ralf Baechle54176732005-02-07 02:54:29 +0000460 .reg_setup = mipsxx_reg_setup,
461 .cpu_setup = mipsxx_cpu_setup,
462 .init = mipsxx_init,
463 .exit = mipsxx_exit,
464 .cpu_start = mipsxx_cpu_start,
465 .cpu_stop = mipsxx_cpu_stop,
466};