2 * arch/sh/oprofile/init.c
4 * Copyright (C) 2003 - 2008 Paul Mundt
6 * Based on arch/mips/oprofile/common.c:
8 * Copyright (C) 2004, 2005 Ralf Baechle
9 * Copyright (C) 2005 MIPS Technologies, Inc.
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
15 #include <linux/kernel.h>
16 #include <linux/oprofile.h>
17 #include <linux/init.h>
18 #include <linux/errno.h>
19 #include <linux/smp.h>
20 #include <asm/processor.h>
23 extern struct op_sh_model op_model_sh7750_ops __weak;
24 extern struct op_sh_model op_model_sh4a_ops __weak;
26 static struct op_sh_model *model;
28 static struct op_counter_config ctr[20];
30 extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth);
32 static int op_sh_setup(void)
34 /* Pre-compute the values to stuff in the hardware registers. */
35 model->reg_setup(ctr);
37 /* Configure the registers on all cpus. */
38 on_each_cpu(model->cpu_setup, NULL, 1);
43 static int op_sh_create_files(struct super_block *sb, struct dentry *root)
47 for (i = 0; i < model->num_counters; i++) {
51 snprintf(buf, sizeof(buf), "%d", i);
52 dir = oprofilefs_mkdir(sb, root, buf);
54 ret |= oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
55 ret |= oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
56 ret |= oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
57 ret |= oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
59 if (model->create_files)
60 ret |= model->create_files(sb, dir);
62 ret |= oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
65 ret |= oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
71 static int op_sh_start(void)
73 /* Enable performance monitoring for all counters. */
74 on_each_cpu(model->cpu_start, NULL, 1);
79 static void op_sh_stop(void)
81 /* Disable performance monitoring for all counters. */
82 on_each_cpu(model->cpu_stop, NULL, 1);
85 int __init oprofile_arch_init(struct oprofile_operations *ops)
87 struct op_sh_model *lmodel = NULL;
91 * Always assign the backtrace op. If the counter initialization
92 * fails, we fall back to the timer which will still make use of
95 ops->backtrace = sh_backtrace;
97 switch (current_cpu_data.type) {
101 lmodel = &op_model_sh7750_ops;
113 lmodel = &op_model_sh4a_ops;
116 /* SH4AL-DSP types */
120 lmodel = &op_model_sh4a_ops;
126 if (!(current_cpu_data.flags & CPU_HAS_PERF_COUNTER))
129 ret = lmodel->init();
130 if (unlikely(ret != 0))
135 ops->setup = op_sh_setup;
136 ops->create_files = op_sh_create_files;
137 ops->start = op_sh_start;
138 ops->stop = op_sh_stop;
139 ops->cpu_type = lmodel->cpu_type;
141 printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
147 void oprofile_arch_exit(void)
149 if (model && model->exit)