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>
17 #include <linux/init.h>
18 #include <linux/smp.h>
19 #include <linux/errno.h>
20 #include <asm/ptrace.h>
21 #include <asm/system.h>
23 #include <asm/cputable.h>
24 #include <asm/oprofile_impl.h>
25 #include <asm/firmware.h>
27 static struct op_powerpc_model *model;
29 static struct op_counter_config ctr[OP_MAX_COUNTER];
30 static struct op_system_config sys;
32 static void op_handle_interrupt(struct pt_regs *regs)
34 model->handle_interrupt(regs, ctr);
37 static void op_powerpc_cpu_setup(void *dummy)
39 model->cpu_setup(ctr);
42 static int op_powerpc_setup(void)
46 /* Grab the hardware */
47 err = reserve_pmc_hardware(op_handle_interrupt);
51 /* Pre-compute the values to stuff in the hardware registers. */
52 model->reg_setup(ctr, &sys, model->num_counters);
54 /* Configure the registers on all cpus. */
55 on_each_cpu(op_powerpc_cpu_setup, NULL, 0, 1);
60 static void op_powerpc_shutdown(void)
62 release_pmc_hardware();
65 static void op_powerpc_cpu_start(void *dummy)
70 static int op_powerpc_start(void)
72 if (model->global_start)
73 model->global_start(ctr);
75 on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
79 static inline void op_powerpc_cpu_stop(void *dummy)
84 static void op_powerpc_stop(void)
87 on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
88 if (model->global_stop)
92 static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
98 * There is one mmcr0, mmcr1 and mmcra for setting the events for
99 * all of the counters.
101 oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
102 oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
103 oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
106 for (i = 0; i < model->num_counters; ++i) {
110 snprintf(buf, sizeof buf, "%d", i);
111 dir = oprofilefs_mkdir(sb, root, buf);
113 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
114 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
115 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
118 * Classic PowerPC doesn't support per-counter
119 * control like this, but the options are
120 * expected, so they remain. For Freescale
121 * Book-E style performance monitors, we do
124 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
125 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
127 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
130 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
131 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
133 /* Default to tracing both kernel and user */
134 sys.enable_kernel = 1;
140 int __init oprofile_arch_init(struct oprofile_operations *ops)
142 if (!cur_cpu_spec->oprofile_cpu_type)
145 if (firmware_has_feature(FW_FEATURE_ISERIES))
148 switch (cur_cpu_spec->oprofile_type) {
150 #ifdef CONFIG_PPC_CELL_NATIVE
151 case PPC_OPROFILE_CELL:
152 model = &op_model_cell;
155 case PPC_OPROFILE_RS64:
156 model = &op_model_rs64;
158 case PPC_OPROFILE_POWER4:
159 model = &op_model_power4;
163 case PPC_OPROFILE_G4:
164 model = &op_model_7450;
167 #ifdef CONFIG_FSL_BOOKE
168 case PPC_OPROFILE_BOOKE:
169 model = &op_model_fsl_booke;
176 model->num_counters = cur_cpu_spec->num_pmcs;
178 ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
179 ops->create_files = op_powerpc_create_files;
180 ops->setup = op_powerpc_setup;
181 ops->shutdown = op_powerpc_shutdown;
182 ops->start = op_powerpc_start;
183 ops->stop = op_powerpc_stop;
184 ops->backtrace = op_powerpc_backtrace;
186 printk(KERN_DEBUG "oprofile: using %s performance monitoring.\n",
192 void oprofile_arch_exit(void)