1*4882a593Smuzhiyun /**
2*4882a593Smuzhiyun * @file arch/alpha/oprofile/common.c
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * @remark Copyright 2002 OProfile authors
5*4882a593Smuzhiyun * @remark Read the file COPYING
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * @author Richard Henderson <rth@twiddle.net>
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include <linux/oprofile.h>
11*4882a593Smuzhiyun #include <linux/init.h>
12*4882a593Smuzhiyun #include <linux/smp.h>
13*4882a593Smuzhiyun #include <linux/errno.h>
14*4882a593Smuzhiyun #include <asm/ptrace.h>
15*4882a593Smuzhiyun #include <asm/special_insns.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include "op_impl.h"
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun extern struct op_axp_model op_model_ev4 __attribute__((weak));
20*4882a593Smuzhiyun extern struct op_axp_model op_model_ev5 __attribute__((weak));
21*4882a593Smuzhiyun extern struct op_axp_model op_model_pca56 __attribute__((weak));
22*4882a593Smuzhiyun extern struct op_axp_model op_model_ev6 __attribute__((weak));
23*4882a593Smuzhiyun extern struct op_axp_model op_model_ev67 __attribute__((weak));
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun static struct op_axp_model *model;
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun extern void (*perf_irq)(unsigned long, struct pt_regs *);
28*4882a593Smuzhiyun static void (*save_perf_irq)(unsigned long, struct pt_regs *);
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun static struct op_counter_config ctr[20];
31*4882a593Smuzhiyun static struct op_system_config sys;
32*4882a593Smuzhiyun static struct op_register_config reg;
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun /* Called from do_entInt to handle the performance monitor interrupt. */
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun static void
op_handle_interrupt(unsigned long which,struct pt_regs * regs)37*4882a593Smuzhiyun op_handle_interrupt(unsigned long which, struct pt_regs *regs)
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun model->handle_interrupt(which, regs, ctr);
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun /* If the user has selected an interrupt frequency that is
42*4882a593Smuzhiyun not exactly the width of the counter, write a new value
43*4882a593Smuzhiyun into the counter such that it'll overflow after N more
44*4882a593Smuzhiyun events. */
45*4882a593Smuzhiyun if ((reg.need_reset >> which) & 1)
46*4882a593Smuzhiyun model->reset_ctr(®, which);
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun static int
op_axp_setup(void)50*4882a593Smuzhiyun op_axp_setup(void)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun unsigned long i, e;
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /* Install our interrupt handler into the existing hook. */
55*4882a593Smuzhiyun save_perf_irq = perf_irq;
56*4882a593Smuzhiyun perf_irq = op_handle_interrupt;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun /* Compute the mask of enabled counters. */
59*4882a593Smuzhiyun for (i = e = 0; i < model->num_counters; ++i)
60*4882a593Smuzhiyun if (ctr[i].enabled)
61*4882a593Smuzhiyun e |= 1 << i;
62*4882a593Smuzhiyun reg.enable = e;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /* Pre-compute the values to stuff in the hardware registers. */
65*4882a593Smuzhiyun model->reg_setup(®, ctr, &sys);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /* Configure the registers on all cpus. */
68*4882a593Smuzhiyun smp_call_function(model->cpu_setup, ®, 1);
69*4882a593Smuzhiyun model->cpu_setup(®);
70*4882a593Smuzhiyun return 0;
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun static void
op_axp_shutdown(void)74*4882a593Smuzhiyun op_axp_shutdown(void)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun /* Remove our interrupt handler. We may be removing this module. */
77*4882a593Smuzhiyun perf_irq = save_perf_irq;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun static void
op_axp_cpu_start(void * dummy)81*4882a593Smuzhiyun op_axp_cpu_start(void *dummy)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun wrperfmon(1, reg.enable);
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun static int
op_axp_start(void)87*4882a593Smuzhiyun op_axp_start(void)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun smp_call_function(op_axp_cpu_start, NULL, 1);
90*4882a593Smuzhiyun op_axp_cpu_start(NULL);
91*4882a593Smuzhiyun return 0;
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun static inline void
op_axp_cpu_stop(void * dummy)95*4882a593Smuzhiyun op_axp_cpu_stop(void *dummy)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun /* Disable performance monitoring for all counters. */
98*4882a593Smuzhiyun wrperfmon(0, -1);
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun static void
op_axp_stop(void)102*4882a593Smuzhiyun op_axp_stop(void)
103*4882a593Smuzhiyun {
104*4882a593Smuzhiyun smp_call_function(op_axp_cpu_stop, NULL, 1);
105*4882a593Smuzhiyun op_axp_cpu_stop(NULL);
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun static int
op_axp_create_files(struct dentry * root)109*4882a593Smuzhiyun op_axp_create_files(struct dentry *root)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun int i;
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun for (i = 0; i < model->num_counters; ++i) {
114*4882a593Smuzhiyun struct dentry *dir;
115*4882a593Smuzhiyun char buf[4];
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun snprintf(buf, sizeof buf, "%d", i);
118*4882a593Smuzhiyun dir = oprofilefs_mkdir(root, buf);
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
121*4882a593Smuzhiyun oprofilefs_create_ulong(dir, "event", &ctr[i].event);
122*4882a593Smuzhiyun oprofilefs_create_ulong(dir, "count", &ctr[i].count);
123*4882a593Smuzhiyun /* Dummies. */
124*4882a593Smuzhiyun oprofilefs_create_ulong(dir, "kernel", &ctr[i].kernel);
125*4882a593Smuzhiyun oprofilefs_create_ulong(dir, "user", &ctr[i].user);
126*4882a593Smuzhiyun oprofilefs_create_ulong(dir, "unit_mask", &ctr[i].unit_mask);
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun if (model->can_set_proc_mode) {
130*4882a593Smuzhiyun oprofilefs_create_ulong(root, "enable_pal",
131*4882a593Smuzhiyun &sys.enable_pal);
132*4882a593Smuzhiyun oprofilefs_create_ulong(root, "enable_kernel",
133*4882a593Smuzhiyun &sys.enable_kernel);
134*4882a593Smuzhiyun oprofilefs_create_ulong(root, "enable_user",
135*4882a593Smuzhiyun &sys.enable_user);
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun return 0;
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun int __init
oprofile_arch_init(struct oprofile_operations * ops)142*4882a593Smuzhiyun oprofile_arch_init(struct oprofile_operations *ops)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun struct op_axp_model *lmodel = NULL;
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun switch (implver()) {
147*4882a593Smuzhiyun case IMPLVER_EV4:
148*4882a593Smuzhiyun lmodel = &op_model_ev4;
149*4882a593Smuzhiyun break;
150*4882a593Smuzhiyun case IMPLVER_EV5:
151*4882a593Smuzhiyun /* 21164PC has a slightly different set of events.
152*4882a593Smuzhiyun Recognize the chip by the presence of the MAX insns. */
153*4882a593Smuzhiyun if (!amask(AMASK_MAX))
154*4882a593Smuzhiyun lmodel = &op_model_pca56;
155*4882a593Smuzhiyun else
156*4882a593Smuzhiyun lmodel = &op_model_ev5;
157*4882a593Smuzhiyun break;
158*4882a593Smuzhiyun case IMPLVER_EV6:
159*4882a593Smuzhiyun /* 21264A supports ProfileMe.
160*4882a593Smuzhiyun Recognize the chip by the presence of the CIX insns. */
161*4882a593Smuzhiyun if (!amask(AMASK_CIX))
162*4882a593Smuzhiyun lmodel = &op_model_ev67;
163*4882a593Smuzhiyun else
164*4882a593Smuzhiyun lmodel = &op_model_ev6;
165*4882a593Smuzhiyun break;
166*4882a593Smuzhiyun }
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun if (!lmodel)
169*4882a593Smuzhiyun return -ENODEV;
170*4882a593Smuzhiyun model = lmodel;
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun ops->create_files = op_axp_create_files;
173*4882a593Smuzhiyun ops->setup = op_axp_setup;
174*4882a593Smuzhiyun ops->shutdown = op_axp_shutdown;
175*4882a593Smuzhiyun ops->start = op_axp_start;
176*4882a593Smuzhiyun ops->stop = op_axp_stop;
177*4882a593Smuzhiyun ops->cpu_type = lmodel->cpu_type;
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
180*4882a593Smuzhiyun lmodel->cpu_type);
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun return 0;
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun void
oprofile_arch_exit(void)187*4882a593Smuzhiyun oprofile_arch_exit(void)
188*4882a593Smuzhiyun {
189*4882a593Smuzhiyun }
190