2 * PPC 64 oprofile support:
3 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
4 * PPC 32 oprofile support: (based on PPC 64 support)
5 * Copyright (C) Freescale Semiconductor, Inc 2004
8 * Based on alpha version.
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.
16 #include <linux/oprofile.h>
18 #include <linux/slab.h>
19 #endif /* ! __powerpc64__ */
20 #include <linux/init.h>
21 #include <linux/smp.h>
22 #include <linux/errno.h>
23 #include <asm/ptrace.h>
24 #include <asm/system.h>
27 #else /* __powerpc64__ */
28 #include <asm/perfmon.h>
29 #endif /* __powerpc64__ */
30 #include <asm/cputable.h>
31 #include <asm/oprofile_impl.h>
33 static struct op_powerpc_model *model;
35 static struct op_counter_config ctr[OP_MAX_COUNTER];
36 static struct op_system_config sys;
39 static char *cpu_type;
40 #endif /* ! __powerpc64__ */
42 static void op_handle_interrupt(struct pt_regs *regs)
44 model->handle_interrupt(regs, ctr);
47 static int op_powerpc_setup(void)
51 /* Grab the hardware */
52 err = reserve_pmc_hardware(op_handle_interrupt);
56 /* Pre-compute the values to stuff in the hardware registers. */
57 model->reg_setup(ctr, &sys, model->num_counters);
59 /* Configure the registers on all cpus. */
61 on_each_cpu(model->cpu_setup, NULL, 0, 1);
62 #else /* __powerpc64__ */
64 /* FIXME: Make multi-cpu work */
65 on_each_cpu(model->reg_setup, NULL, 0, 1);
67 #endif /* __powerpc64__ */
72 static void op_powerpc_shutdown(void)
74 release_pmc_hardware();
77 static void op_powerpc_cpu_start(void *dummy)
82 static int op_powerpc_start(void)
84 on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
88 static inline void op_powerpc_cpu_stop(void *dummy)
93 static void op_powerpc_stop(void)
95 on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
98 static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
104 * There is one mmcr0, mmcr1 and mmcra for setting the events for
105 * all of the counters.
107 oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
108 oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
109 oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
110 #endif /* __powerpc64__ */
112 for (i = 0; i < model->num_counters; ++i) {
116 snprintf(buf, sizeof buf, "%d", i);
117 dir = oprofilefs_mkdir(sb, root, buf);
119 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
120 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
121 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
124 * We dont support per counter user/kernel selection, but
125 * we leave the entries because userspace expects them
127 #endif /* __powerpc64__ */
128 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
129 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
131 #ifndef __powerpc64__
132 /* FIXME: Not sure if this is used */
133 #endif /* ! __powerpc64__ */
134 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
137 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
138 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
140 oprofilefs_create_ulong(sb, root, "backtrace_spinlocks",
141 &sys.backtrace_spinlocks);
142 #endif /* __powerpc64__ */
144 /* Default to tracing both kernel and user */
145 sys.enable_kernel = 1;
148 /* Turn on backtracing through spinlocks by default */
149 sys.backtrace_spinlocks = 1;
150 #endif /* __powerpc64__ */
155 int __init oprofile_arch_init(struct oprofile_operations *ops)
157 #ifndef __powerpc64__
158 int cpu_id = smp_processor_id();
160 #ifdef CONFIG_FSL_BOOKE
161 model = &op_model_fsl_booke;
166 cpu_type = kmalloc(32, GFP_KERNEL);
167 if (NULL == cpu_type)
170 sprintf(cpu_type, "ppc/%s", cur_cpu_spec[cpu_id]->cpu_name);
172 model->num_counters = cur_cpu_spec[cpu_id]->num_pmcs;
174 ops->cpu_type = cpu_type;
175 #else /* __powerpc64__ */
176 if (!cur_cpu_spec->oprofile_model || !cur_cpu_spec->oprofile_cpu_type)
178 model = cur_cpu_spec->oprofile_model;
179 model->num_counters = cur_cpu_spec->num_pmcs;
181 ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
182 #endif /* __powerpc64__ */
183 ops->create_files = op_powerpc_create_files;
184 ops->setup = op_powerpc_setup;
185 ops->shutdown = op_powerpc_shutdown;
186 ops->start = op_powerpc_start;
187 ops->stop = op_powerpc_stop;
189 printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
195 void oprofile_arch_exit(void)
197 #ifndef __powerpc64__
200 #endif /* ! __powerpc64__ */