blob: 1c84cc257fc7ec7a6c3df970722b381f0ed17ff3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file arch/alpha/oprofile/op_model_ev6.c
3 *
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author Richard Henderson <rth@twiddle.net>
8 */
9
10#include <linux/oprofile.h>
11#include <linux/init.h>
12#include <linux/smp.h>
13#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include "op_impl.h"
16
17
18/* Compute all of the registers in preparation for enabling profiling. */
19
20static void
21ev6_reg_setup(struct op_register_config *reg,
22 struct op_counter_config *ctr,
23 struct op_system_config *sys)
24{
25 unsigned long ctl, reset, need_reset, i;
26
27 /* Select desired events. We've mapped the event numbers
28 such that they fit directly into the event selection fields. */
29 ctl = 0;
30 if (ctr[0].enabled && ctr[0].event)
31 ctl |= (ctr[0].event & 1) << 4;
32 if (ctr[1].enabled)
33 ctl |= (ctr[1].event - 2) & 15;
34 reg->mux_select = ctl;
35
36 /* Select logging options. */
37 /* ??? Need to come up with some mechanism to trace only
38 selected processes. EV6 does not have a mechanism to
39 select kernel or user mode only. For now, enable always. */
40 reg->proc_mode = 0;
41
42 /* EV6 cannot change the width of the counters as with the
43 other implementations. But fortunately, we can write to
44 the counters and set the value such that it will overflow
45 at the right time. */
46 reset = need_reset = 0;
47 for (i = 0; i < 2; ++i) {
48 unsigned long count = ctr[i].count;
49 if (!ctr[i].enabled)
50 continue;
51
52 if (count > 0x100000)
53 count = 0x100000;
54 ctr[i].count = count;
55 reset |= (0x100000 - count) << (i ? 6 : 28);
56 if (count != 0x100000)
57 need_reset |= 1 << i;
58 }
59 reg->reset_values = reset;
60 reg->need_reset = need_reset;
61}
62
63/* Program all of the registers in preparation for enabling profiling. */
64
65static void
66ev6_cpu_setup (void *x)
67{
68 struct op_register_config *reg = x;
69
70 wrperfmon(2, reg->mux_select);
71 wrperfmon(3, reg->proc_mode);
72 wrperfmon(6, reg->reset_values | 3);
73}
74
75/* CTR is a counter for which the user has requested an interrupt count
76 in between one of the widths selectable in hardware. Reset the count
77 for CTR to the value stored in REG->RESET_VALUES. */
78
79static void
80ev6_reset_ctr(struct op_register_config *reg, unsigned long ctr)
81{
82 wrperfmon(6, reg->reset_values | (1 << ctr));
83}
84
85static void
86ev6_handle_interrupt(unsigned long which, struct pt_regs *regs,
87 struct op_counter_config *ctr)
88{
89 /* Record the sample. */
90 oprofile_add_sample(regs, which);
91}
92
93
94struct op_axp_model op_model_ev6 = {
95 .reg_setup = ev6_reg_setup,
96 .cpu_setup = ev6_cpu_setup,
97 .reset_ctr = ev6_reset_ctr,
98 .handle_interrupt = ev6_handle_interrupt,
99 .cpu_type = "alpha/ev6",
100 .num_counters = 2,
101 .can_set_proc_mode = 0,
102};