Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / ppc / oprofile / common.c
blob3169c67abea745c8ab254b85aba45363d2d252b7
1 /*
2 * PPC 32 oprofile support
3 * Based on PPC64 oprofile support
4 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
6 * Copyright (C) Freescale Semiconductor, Inc 2004
8 * Author: Andy Fleming
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/slab.h>
18 #include <linux/init.h>
19 #include <linux/smp.h>
20 #include <linux/errno.h>
21 #include <asm/ptrace.h>
22 #include <asm/system.h>
23 #include <asm/perfmon.h>
24 #include <asm/cputable.h>
26 #include "op_impl.h"
28 static struct op_ppc32_model *model;
30 static struct op_counter_config ctr[OP_MAX_COUNTER];
31 static struct op_system_config sys;
33 static void op_handle_interrupt(struct pt_regs *regs)
35 model->handle_interrupt(regs, ctr);
38 static int op_ppc32_setup(void)
40 /* Install our interrupt handler into the existing hook. */
41 if(request_perfmon_irq(&op_handle_interrupt))
42 return -EBUSY;
44 mb();
46 /* Pre-compute the values to stuff in the hardware registers. */
47 model->reg_setup(ctr, &sys, model->num_counters);
49 #if 0
50 /* FIXME: Make multi-cpu work */
51 /* Configure the registers on all cpus. */
52 on_each_cpu(model->reg_setup, NULL, 0, 1);
53 #endif
55 return 0;
58 static void op_ppc32_shutdown(void)
60 mb();
62 /* Remove our interrupt handler. We may be removing this module. */
63 free_perfmon_irq();
66 static void op_ppc32_cpu_start(void *dummy)
68 model->start(ctr);
71 static int op_ppc32_start(void)
73 on_each_cpu(op_ppc32_cpu_start, NULL, 0, 1);
74 return 0;
77 static inline void op_ppc32_cpu_stop(void *dummy)
79 model->stop();
82 static void op_ppc32_stop(void)
84 on_each_cpu(op_ppc32_cpu_stop, NULL, 0, 1);
87 static int op_ppc32_create_files(struct super_block *sb, struct dentry *root)
89 int i;
91 for (i = 0; i < model->num_counters; ++i) {
92 struct dentry *dir;
93 char buf[3];
95 snprintf(buf, sizeof buf, "%d", i);
96 dir = oprofilefs_mkdir(sb, root, buf);
98 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
99 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
100 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
101 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
102 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
104 /* FIXME: Not sure if this is used */
105 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
108 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
109 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
111 /* Default to tracing both kernel and user */
112 sys.enable_kernel = 1;
113 sys.enable_user = 1;
115 return 0;
118 static struct oprofile_operations oprof_ppc32_ops = {
119 .create_files = op_ppc32_create_files,
120 .setup = op_ppc32_setup,
121 .shutdown = op_ppc32_shutdown,
122 .start = op_ppc32_start,
123 .stop = op_ppc32_stop,
124 .cpu_type = NULL /* To be filled in below. */
127 int __init oprofile_arch_init(struct oprofile_operations *ops)
129 char *name;
130 int cpu_id = smp_processor_id();
132 #ifdef CONFIG_FSL_BOOKE
133 model = &op_model_fsl_booke;
134 #else
135 return -ENODEV;
136 #endif
138 name = kmalloc(32, GFP_KERNEL);
140 if (NULL == name)
141 return -ENOMEM;
143 sprintf(name, "ppc/%s", cur_cpu_spec[cpu_id]->cpu_name);
145 oprof_ppc32_ops.cpu_type = name;
147 model->num_counters = cur_cpu_spec[cpu_id]->num_pmcs;
149 *ops = oprof_ppc32_ops;
151 printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
152 oprof_ppc32_ops.cpu_type);
154 return 0;
157 void oprofile_arch_exit(void)
159 kfree(oprof_ppc32_ops.cpu_type);
160 oprof_ppc32_ops.cpu_type = NULL;