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)
52 /* Grab the hardware */
53 err = reserve_pmc_hardware(op_handle_interrupt);
56 #else /* __powerpc64__ */
57 /* Install our interrupt handler into the existing hook. */
58 if (request_perfmon_irq(&op_handle_interrupt))
61 #endif /* __powerpc64__ */
63 /* Pre-compute the values to stuff in the hardware registers. */
64 model->reg_setup(ctr, &sys, model->num_counters);
66 /* Configure the registers on all cpus. */
68 on_each_cpu(model->cpu_setup, NULL, 0, 1);
69 #else /* __powerpc64__ */
71 /* FIXME: Make multi-cpu work */
72 on_each_cpu(model->reg_setup, NULL, 0, 1);
74 #endif /* __powerpc64__ */
79 static void op_powerpc_shutdown(void)
82 release_pmc_hardware();
83 #else /* __powerpc64__ */
85 /* Remove our interrupt handler. We may be removing this module. */
87 #endif /* __powerpc64__ */
90 static void op_powerpc_cpu_start(void *dummy)
95 static int op_powerpc_start(void)
97 on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
101 static inline void op_powerpc_cpu_stop(void *dummy)
106 static void op_powerpc_stop(void)
108 on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
111 static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
117 * There is one mmcr0, mmcr1 and mmcra for setting the events for
118 * all of the counters.
120 oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
121 oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
122 oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
123 #endif /* __powerpc64__ */
125 for (i = 0; i < model->num_counters; ++i) {
129 snprintf(buf, sizeof buf, "%d", i);
130 dir = oprofilefs_mkdir(sb, root, buf);
132 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
133 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
134 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
137 * We dont support per counter user/kernel selection, but
138 * we leave the entries because userspace expects them
140 #endif /* __powerpc64__ */
141 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
142 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
144 #ifndef __powerpc64__
145 /* FIXME: Not sure if this is used */
146 #endif /* ! __powerpc64__ */
147 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
150 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
151 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
153 oprofilefs_create_ulong(sb, root, "backtrace_spinlocks",
154 &sys.backtrace_spinlocks);
155 #endif /* __powerpc64__ */
157 /* Default to tracing both kernel and user */
158 sys.enable_kernel = 1;
161 /* Turn on backtracing through spinlocks by default */
162 sys.backtrace_spinlocks = 1;
163 #endif /* __powerpc64__ */
168 int __init oprofile_arch_init(struct oprofile_operations *ops)
170 #ifndef __powerpc64__
171 int cpu_id = smp_processor_id();
173 #ifdef CONFIG_FSL_BOOKE
174 model = &op_model_fsl_booke;
179 cpu_type = kmalloc(32, GFP_KERNEL);
180 if (NULL == cpu_type)
183 sprintf(cpu_type, "ppc/%s", cur_cpu_spec[cpu_id]->cpu_name);
185 model->num_counters = cur_cpu_spec[cpu_id]->num_pmcs;
187 ops->cpu_type = cpu_type;
188 #else /* __powerpc64__ */
189 if (!cur_cpu_spec->oprofile_model || !cur_cpu_spec->oprofile_cpu_type)
191 model = cur_cpu_spec->oprofile_model;
192 model->num_counters = cur_cpu_spec->num_pmcs;
194 ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
195 #endif /* __powerpc64__ */
196 ops->create_files = op_powerpc_create_files;
197 ops->setup = op_powerpc_setup;
198 ops->shutdown = op_powerpc_shutdown;
199 ops->start = op_powerpc_start;
200 ops->stop = op_powerpc_stop;
202 printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
208 void oprofile_arch_exit(void)
210 #ifndef __powerpc64__
213 #endif /* ! __powerpc64__ */