[PATCH] powerpc: reduce oprofile/common.c differences
[deliverable/linux.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>
86a5cddb
SR
17#ifndef __powerpc64__
18#include <linux/slab.h>
19#endif /* ! __powerpc64__ */
1da177e4
LT
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>
86a5cddb 25#ifdef __powerpc64__
1da177e4 26#include <asm/pmc.h>
86a5cddb
SR
27#else /* __powerpc64__ */
28#include <asm/perfmon.h>
29#endif /* __powerpc64__ */
a6908cd0 30#include <asm/cputable.h>
dca85932 31#include <asm/oprofile_impl.h>
1da177e4 32
a3e48c10 33static struct op_powerpc_model *model;
1da177e4
LT
34
35static struct op_counter_config ctr[OP_MAX_COUNTER];
36static struct op_system_config sys;
37
86a5cddb
SR
38#ifndef __powerpc64__
39static char *cpu_type;
40#endif /* ! __powerpc64__ */
41
1da177e4
LT
42static void op_handle_interrupt(struct pt_regs *regs)
43{
44 model->handle_interrupt(regs, ctr);
45}
46
86a5cddb 47static int op_powerpc_setup(void)
1da177e4
LT
48{
49 int err;
50
51 /* Grab the hardware */
52 err = reserve_pmc_hardware(op_handle_interrupt);
53 if (err)
54 return err;
55
56 /* Pre-compute the values to stuff in the hardware registers. */
57 model->reg_setup(ctr, &sys, model->num_counters);
58
59 /* Configure the registers on all cpus. */
86a5cddb 60#ifdef __powerpc64__
1da177e4 61 on_each_cpu(model->cpu_setup, NULL, 0, 1);
86a5cddb
SR
62#else /* __powerpc64__ */
63#if 0
64 /* FIXME: Make multi-cpu work */
65 on_each_cpu(model->reg_setup, NULL, 0, 1);
66#endif
67#endif /* __powerpc64__ */
1da177e4
LT
68
69 return 0;
70}
71
86a5cddb 72static void op_powerpc_shutdown(void)
1da177e4
LT
73{
74 release_pmc_hardware();
75}
76
86a5cddb 77static void op_powerpc_cpu_start(void *dummy)
1da177e4
LT
78{
79 model->start(ctr);
80}
81
86a5cddb 82static int op_powerpc_start(void)
1da177e4 83{
86a5cddb 84 on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
1da177e4
LT
85 return 0;
86}
87
86a5cddb 88static inline void op_powerpc_cpu_stop(void *dummy)
1da177e4
LT
89{
90 model->stop();
91}
92
86a5cddb 93static void op_powerpc_stop(void)
1da177e4 94{
86a5cddb 95 on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
1da177e4
LT
96}
97
86a5cddb 98static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
1da177e4
LT
99{
100 int i;
101
86a5cddb 102#ifdef __powerpc64__
1da177e4
LT
103 /*
104 * There is one mmcr0, mmcr1 and mmcra for setting the events for
105 * all of the counters.
106 */
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);
86a5cddb 110#endif /* __powerpc64__ */
1da177e4
LT
111
112 for (i = 0; i < model->num_counters; ++i) {
113 struct dentry *dir;
114 char buf[3];
115
116 snprintf(buf, sizeof buf, "%d", i);
117 dir = oprofilefs_mkdir(sb, root, buf);
118
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);
86a5cddb 122#ifdef __powerpc64__
1da177e4
LT
123 /*
124 * We dont support per counter user/kernel selection, but
125 * we leave the entries because userspace expects them
126 */
86a5cddb 127#endif /* __powerpc64__ */
1da177e4
LT
128 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
129 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
86a5cddb
SR
130
131#ifndef __powerpc64__
132 /* FIXME: Not sure if this is used */
133#endif /* ! __powerpc64__ */
1da177e4
LT
134 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
135 }
136
137 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
138 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
86a5cddb 139#ifdef __powerpc64__
1da177e4
LT
140 oprofilefs_create_ulong(sb, root, "backtrace_spinlocks",
141 &sys.backtrace_spinlocks);
86a5cddb 142#endif /* __powerpc64__ */
1da177e4
LT
143
144 /* Default to tracing both kernel and user */
145 sys.enable_kernel = 1;
146 sys.enable_user = 1;
86a5cddb 147#ifdef __powerpc64__
1da177e4
LT
148 /* Turn on backtracing through spinlocks by default */
149 sys.backtrace_spinlocks = 1;
86a5cddb 150#endif /* __powerpc64__ */
1da177e4
LT
151
152 return 0;
153}
154
155int __init oprofile_arch_init(struct oprofile_operations *ops)
156{
86a5cddb
SR
157#ifndef __powerpc64__
158 int cpu_id = smp_processor_id();
159
160#ifdef CONFIG_FSL_BOOKE
161 model = &op_model_fsl_booke;
162#else
163 return -ENODEV;
164#endif
165
166 cpu_type = kmalloc(32, GFP_KERNEL);
167 if (NULL == cpu_type)
168 return -ENOMEM;
169
170 sprintf(cpu_type, "ppc/%s", cur_cpu_spec[cpu_id]->cpu_name);
171
172 model->num_counters = cur_cpu_spec[cpu_id]->num_pmcs;
173
174 ops->cpu_type = cpu_type;
175#else /* __powerpc64__ */
8fef0306
AB
176 if (!cur_cpu_spec->oprofile_model || !cur_cpu_spec->oprofile_cpu_type)
177 return -ENODEV;
8fef0306 178 model = cur_cpu_spec->oprofile_model;
a6908cd0 179 model->num_counters = cur_cpu_spec->num_pmcs;
8fef0306
AB
180
181 ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
86a5cddb
SR
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;
1da177e4
LT
188
189 printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
190 ops->cpu_type);
191
192 return 0;
193}
194
195void oprofile_arch_exit(void)
196{
86a5cddb
SR
197#ifndef __powerpc64__
198 kfree(cpu_type);
199 cpu_type = NULL;
200#endif /* ! __powerpc64__ */
1da177e4 201}
This page took 0.121405 seconds and 5 git commands to generate.