2 * @file arch/alpha/oprofile/op_model_ev5.c
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author Richard Henderson <rth@twiddle.net>
10 #include <linux/oprofile.h>
11 #include <linux/init.h>
12 #include <linux/smp.h>
13 #include <asm/ptrace.h>
14 #include <asm/system.h>
19 /* Compute all of the registers in preparation for enabling profiling.
21 The 21164 (EV5) and 21164PC (PCA65) vary in the bit placement and
22 meaning of the "CBOX" events. Given that we don't care about meaning
23 at this point, arrange for the difference in bit placement to be
24 handled by common code. */
27 common_reg_setup(struct op_register_config *reg,
28 struct op_counter_config *ctr,
29 struct op_system_config *sys,
30 int cbox1_ofs, int cbox2_ofs)
32 int i, ctl, reset, need_reset;
34 /* Select desired events. The event numbers are selected such
35 that they map directly into the event selection fields:
43 There are two special cases, in that CYCLES can be measured
44 on PCSEL[02], and SCACHE_WRITE can be measured on CBOX[12].
45 These event numbers are canonicalizes to their first appearance. */
48 for (i = 0; i < 3; ++i) {
49 unsigned long event = ctr[i].event;
53 /* Remap the duplicate events, as described above. */
57 else if (event == 2+41)
61 /* Convert the event numbers onto mux_select bit mask. */
67 ctl |= (event - 24) << 4;
69 ctl |= (event - 40) << cbox1_ofs | 15 << 4;
73 ctl |= (event - 64) << cbox2_ofs | 15;
75 reg->mux_select = ctl;
77 /* Select processor mode. */
78 /* ??? Need to come up with some mechanism to trace only selected
79 processes. For now select from pal, kernel and user mode. */
81 ctl |= !sys->enable_pal << 9;
82 ctl |= !sys->enable_kernel << 8;
83 ctl |= !sys->enable_user << 30;
86 /* Select interrupt frequencies. Take the interrupt count selected
87 by the user, and map it onto one of the possible counter widths.
88 If the user value is in between, compute a value to which the
89 counter is reset at each interrupt. */
91 ctl = reset = need_reset = 0;
92 for (i = 0; i < 3; ++i) {
93 unsigned long max, hilo, count = ctr[i].count;
98 count = 256, hilo = 3, max = 256;
100 max = (i == 2 ? 16384 : 65536);
105 ctr[i].count = count;
107 ctl |= hilo << (8 - i*2);
108 reset |= (max - count) << (48 - 16*i);
110 need_reset |= 1 << i;
113 reg->reset_values = reset;
114 reg->need_reset = need_reset;
118 ev5_reg_setup(struct op_register_config *reg,
119 struct op_counter_config *ctr,
120 struct op_system_config *sys)
122 common_reg_setup(reg, ctr, sys, 19, 22);
126 pca56_reg_setup(struct op_register_config *reg,
127 struct op_counter_config *ctr,
128 struct op_system_config *sys)
130 common_reg_setup(reg, ctr, sys, 8, 11);
133 /* Program all of the registers in preparation for enabling profiling. */
136 ev5_cpu_setup (void *x)
138 struct op_register_config *reg = x;
140 wrperfmon(2, reg->mux_select);
141 wrperfmon(3, reg->proc_mode);
142 wrperfmon(4, reg->freq);
143 wrperfmon(6, reg->reset_values);
146 /* CTR is a counter for which the user has requested an interrupt count
147 in between one of the widths selectable in hardware. Reset the count
148 for CTR to the value stored in REG->RESET_VALUES.
150 For EV5, this means disabling profiling, reading the current values,
151 masking in the value for the desired register, writing, then turning
154 This can be streamlined if profiling is only enabled for user mode.
155 In that case we know that the counters are not currently incrementing
156 (due to being in kernel mode). */
159 ev5_reset_ctr(struct op_register_config *reg, unsigned long ctr)
161 unsigned long values, mask, not_pk, reset_values;
163 mask = (ctr == 0 ? 0xfffful << 48
164 : ctr == 1 ? 0xfffful << 32
167 not_pk = 1 << 9 | 1 << 8;
169 reset_values = reg->reset_values;
171 if ((reg->proc_mode & not_pk) == not_pk) {
172 values = wrperfmon(5, 0);
173 values = (reset_values & mask) | (values & ~mask & -2);
174 wrperfmon(6, values);
177 values = wrperfmon(5, 0);
178 values = (reset_values & mask) | (values & ~mask & -2);
179 wrperfmon(6, values);
180 wrperfmon(1, reg->enable);
185 ev5_handle_interrupt(unsigned long which, struct pt_regs *regs,
186 struct op_counter_config *ctr)
188 /* Record the sample. */
189 oprofile_add_sample(regs, which);
193 struct op_axp_model op_model_ev5 = {
194 .reg_setup = ev5_reg_setup,
195 .cpu_setup = ev5_cpu_setup,
196 .reset_ctr = ev5_reset_ctr,
197 .handle_interrupt = ev5_handle_interrupt,
198 .cpu_type = "alpha/ev5",
200 .can_set_proc_mode = 1,
203 struct op_axp_model op_model_pca56 = {
204 .reg_setup = pca56_reg_setup,
205 .cpu_setup = ev5_cpu_setup,
206 .reset_ctr = ev5_reset_ctr,
207 .handle_interrupt = ev5_handle_interrupt,
208 .cpu_type = "alpha/pca56",
210 .can_set_proc_mode = 1,