diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2005-09-19 09:24:08 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2005-09-21 05:21:08 -0400 |
commit | 86a5cddbd9676b129cfa2ed7a1a11759d3b2b512 (patch) | |
tree | 7d5d4fdda4df9067c43870f5dcb3d5c714fdf227 /arch/ppc64 | |
parent | 654810ec899ea5f2fc2138fca1793b603d481ff4 (diff) |
[PATCH] powerpc: merge the rest of arch/ppc*/oprofile
- merge common.c
- move model specific files
- remove stub Makefiles
- clean up arch/ppc*/Makefile
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/ppc64')
-rw-r--r-- | arch/ppc64/Makefile | 2 | ||||
-rw-r--r-- | arch/ppc64/oprofile/Makefile | 1 | ||||
-rw-r--r-- | arch/ppc64/oprofile/common.c | 145 | ||||
-rw-r--r-- | arch/ppc64/oprofile/op_model_power4.c | 309 | ||||
-rw-r--r-- | arch/ppc64/oprofile/op_model_rs64.c | 218 |
5 files changed, 1 insertions, 674 deletions
diff --git a/arch/ppc64/Makefile b/arch/ppc64/Makefile index 17d2c1eac3b8..a8877881bb48 100644 --- a/arch/ppc64/Makefile +++ b/arch/ppc64/Makefile | |||
@@ -85,7 +85,7 @@ libs-y += arch/ppc64/lib/ | |||
85 | core-y += arch/ppc64/kernel/ | 85 | core-y += arch/ppc64/kernel/ |
86 | core-y += arch/ppc64/mm/ | 86 | core-y += arch/ppc64/mm/ |
87 | core-$(CONFIG_XMON) += arch/ppc64/xmon/ | 87 | core-$(CONFIG_XMON) += arch/ppc64/xmon/ |
88 | drivers-$(CONFIG_OPROFILE) += arch/ppc64/oprofile/ | 88 | drivers-$(CONFIG_OPROFILE) += arch/powerpc/oprofile/ |
89 | 89 | ||
90 | boot := arch/ppc64/boot | 90 | boot := arch/ppc64/boot |
91 | 91 | ||
diff --git a/arch/ppc64/oprofile/Makefile b/arch/ppc64/oprofile/Makefile deleted file mode 100644 index 4bf75b776c5b..000000000000 --- a/arch/ppc64/oprofile/Makefile +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | include arch/powerpc/oprofile/Makefile | ||
diff --git a/arch/ppc64/oprofile/common.c b/arch/ppc64/oprofile/common.c deleted file mode 100644 index ff9361a07d39..000000000000 --- a/arch/ppc64/oprofile/common.c +++ /dev/null | |||
@@ -1,145 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM | ||
3 | * | ||
4 | * Based on alpha version. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/oprofile.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/smp.h> | ||
15 | #include <linux/errno.h> | ||
16 | #include <asm/ptrace.h> | ||
17 | #include <asm/system.h> | ||
18 | #include <asm/pmc.h> | ||
19 | #include <asm/cputable.h> | ||
20 | #include <asm/oprofile_impl.h> | ||
21 | |||
22 | static struct op_powerpc_model *model; | ||
23 | |||
24 | static struct op_counter_config ctr[OP_MAX_COUNTER]; | ||
25 | static struct op_system_config sys; | ||
26 | |||
27 | static void op_handle_interrupt(struct pt_regs *regs) | ||
28 | { | ||
29 | model->handle_interrupt(regs, ctr); | ||
30 | } | ||
31 | |||
32 | static int op_ppc64_setup(void) | ||
33 | { | ||
34 | int err; | ||
35 | |||
36 | /* Grab the hardware */ | ||
37 | err = reserve_pmc_hardware(op_handle_interrupt); | ||
38 | if (err) | ||
39 | return err; | ||
40 | |||
41 | /* Pre-compute the values to stuff in the hardware registers. */ | ||
42 | model->reg_setup(ctr, &sys, model->num_counters); | ||
43 | |||
44 | /* Configure the registers on all cpus. */ | ||
45 | on_each_cpu(model->cpu_setup, NULL, 0, 1); | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static void op_ppc64_shutdown(void) | ||
51 | { | ||
52 | release_pmc_hardware(); | ||
53 | } | ||
54 | |||
55 | static void op_ppc64_cpu_start(void *dummy) | ||
56 | { | ||
57 | model->start(ctr); | ||
58 | } | ||
59 | |||
60 | static int op_ppc64_start(void) | ||
61 | { | ||
62 | on_each_cpu(op_ppc64_cpu_start, NULL, 0, 1); | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | static inline void op_ppc64_cpu_stop(void *dummy) | ||
67 | { | ||
68 | model->stop(); | ||
69 | } | ||
70 | |||
71 | static void op_ppc64_stop(void) | ||
72 | { | ||
73 | on_each_cpu(op_ppc64_cpu_stop, NULL, 0, 1); | ||
74 | } | ||
75 | |||
76 | static int op_ppc64_create_files(struct super_block *sb, struct dentry *root) | ||
77 | { | ||
78 | int i; | ||
79 | |||
80 | /* | ||
81 | * There is one mmcr0, mmcr1 and mmcra for setting the events for | ||
82 | * all of the counters. | ||
83 | */ | ||
84 | oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0); | ||
85 | oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1); | ||
86 | oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra); | ||
87 | |||
88 | for (i = 0; i < model->num_counters; ++i) { | ||
89 | struct dentry *dir; | ||
90 | char buf[3]; | ||
91 | |||
92 | snprintf(buf, sizeof buf, "%d", i); | ||
93 | dir = oprofilefs_mkdir(sb, root, buf); | ||
94 | |||
95 | oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); | ||
96 | oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); | ||
97 | oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); | ||
98 | /* | ||
99 | * We dont support per counter user/kernel selection, but | ||
100 | * we leave the entries because userspace expects them | ||
101 | */ | ||
102 | oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); | ||
103 | oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); | ||
104 | oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); | ||
105 | } | ||
106 | |||
107 | oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel); | ||
108 | oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user); | ||
109 | oprofilefs_create_ulong(sb, root, "backtrace_spinlocks", | ||
110 | &sys.backtrace_spinlocks); | ||
111 | |||
112 | /* Default to tracing both kernel and user */ | ||
113 | sys.enable_kernel = 1; | ||
114 | sys.enable_user = 1; | ||
115 | |||
116 | /* Turn on backtracing through spinlocks by default */ | ||
117 | sys.backtrace_spinlocks = 1; | ||
118 | |||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | int __init oprofile_arch_init(struct oprofile_operations *ops) | ||
123 | { | ||
124 | if (!cur_cpu_spec->oprofile_model || !cur_cpu_spec->oprofile_cpu_type) | ||
125 | return -ENODEV; | ||
126 | |||
127 | model = cur_cpu_spec->oprofile_model; | ||
128 | model->num_counters = cur_cpu_spec->num_pmcs; | ||
129 | |||
130 | ops->cpu_type = cur_cpu_spec->oprofile_cpu_type; | ||
131 | ops->create_files = op_ppc64_create_files; | ||
132 | ops->setup = op_ppc64_setup; | ||
133 | ops->shutdown = op_ppc64_shutdown; | ||
134 | ops->start = op_ppc64_start; | ||
135 | ops->stop = op_ppc64_stop; | ||
136 | |||
137 | printk(KERN_INFO "oprofile: using %s performance monitoring.\n", | ||
138 | ops->cpu_type); | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | void oprofile_arch_exit(void) | ||
144 | { | ||
145 | } | ||
diff --git a/arch/ppc64/oprofile/op_model_power4.c b/arch/ppc64/oprofile/op_model_power4.c deleted file mode 100644 index 886449315847..000000000000 --- a/arch/ppc64/oprofile/op_model_power4.c +++ /dev/null | |||
@@ -1,309 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | */ | ||
9 | |||
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> | ||
15 | #include <asm/processor.h> | ||
16 | #include <asm/cputable.h> | ||
17 | #include <asm/systemcfg.h> | ||
18 | #include <asm/rtas.h> | ||
19 | #include <asm/oprofile_impl.h> | ||
20 | |||
21 | #define dbg(args...) | ||
22 | |||
23 | static unsigned long reset_value[OP_MAX_COUNTER]; | ||
24 | |||
25 | static int oprofile_running; | ||
26 | static int mmcra_has_sihv; | ||
27 | |||
28 | /* mmcr values are set in power4_reg_setup, used in power4_cpu_setup */ | ||
29 | static u32 mmcr0_val; | ||
30 | static u64 mmcr1_val; | ||
31 | static u32 mmcra_val; | ||
32 | |||
33 | /* | ||
34 | * Since we do not have an NMI, backtracing through spinlocks is | ||
35 | * only a best guess. In light of this, allow it to be disabled at | ||
36 | * runtime. | ||
37 | */ | ||
38 | static int backtrace_spinlocks; | ||
39 | |||
40 | static void power4_reg_setup(struct op_counter_config *ctr, | ||
41 | struct op_system_config *sys, | ||
42 | int num_ctrs) | ||
43 | { | ||
44 | int i; | ||
45 | |||
46 | /* | ||
47 | * SIHV / SIPR bits are only implemented on POWER4+ (GQ) and above. | ||
48 | * However we disable it on all POWER4 until we verify it works | ||
49 | * (I was seeing some strange behaviour last time I tried). | ||
50 | * | ||
51 | * It has been verified to work on POWER5 so we enable it there. | ||
52 | */ | ||
53 | if (cpu_has_feature(CPU_FTR_MMCRA_SIHV)) | ||
54 | mmcra_has_sihv = 1; | ||
55 | |||
56 | /* | ||
57 | * The performance counter event settings are given in the mmcr0, | ||
58 | * mmcr1 and mmcra values passed from the user in the | ||
59 | * op_system_config structure (sys variable). | ||
60 | */ | ||
61 | mmcr0_val = sys->mmcr0; | ||
62 | mmcr1_val = sys->mmcr1; | ||
63 | mmcra_val = sys->mmcra; | ||
64 | |||
65 | backtrace_spinlocks = sys->backtrace_spinlocks; | ||
66 | |||
67 | for (i = 0; i < cur_cpu_spec->num_pmcs; ++i) | ||
68 | reset_value[i] = 0x80000000UL - ctr[i].count; | ||
69 | |||
70 | /* setup user and kernel profiling */ | ||
71 | if (sys->enable_kernel) | ||
72 | mmcr0_val &= ~MMCR0_KERNEL_DISABLE; | ||
73 | else | ||
74 | mmcr0_val |= MMCR0_KERNEL_DISABLE; | ||
75 | |||
76 | if (sys->enable_user) | ||
77 | mmcr0_val &= ~MMCR0_PROBLEM_DISABLE; | ||
78 | else | ||
79 | mmcr0_val |= MMCR0_PROBLEM_DISABLE; | ||
80 | } | ||
81 | |||
82 | extern void ppc64_enable_pmcs(void); | ||
83 | |||
84 | static void power4_cpu_setup(void *unused) | ||
85 | { | ||
86 | unsigned int mmcr0 = mmcr0_val; | ||
87 | unsigned long mmcra = mmcra_val; | ||
88 | |||
89 | ppc64_enable_pmcs(); | ||
90 | |||
91 | /* set the freeze bit */ | ||
92 | mmcr0 |= MMCR0_FC; | ||
93 | mtspr(SPRN_MMCR0, mmcr0); | ||
94 | |||
95 | mmcr0 |= MMCR0_FCM1|MMCR0_PMXE|MMCR0_FCECE; | ||
96 | mmcr0 |= MMCR0_PMC1CE|MMCR0_PMCjCE; | ||
97 | mtspr(SPRN_MMCR0, mmcr0); | ||
98 | |||
99 | mtspr(SPRN_MMCR1, mmcr1_val); | ||
100 | |||
101 | mmcra |= MMCRA_SAMPLE_ENABLE; | ||
102 | mtspr(SPRN_MMCRA, mmcra); | ||
103 | |||
104 | dbg("setup on cpu %d, mmcr0 %lx\n", smp_processor_id(), | ||
105 | mfspr(SPRN_MMCR0)); | ||
106 | dbg("setup on cpu %d, mmcr1 %lx\n", smp_processor_id(), | ||
107 | mfspr(SPRN_MMCR1)); | ||
108 | dbg("setup on cpu %d, mmcra %lx\n", smp_processor_id(), | ||
109 | mfspr(SPRN_MMCRA)); | ||
110 | } | ||
111 | |||
112 | static void power4_start(struct op_counter_config *ctr) | ||
113 | { | ||
114 | int i; | ||
115 | unsigned int mmcr0; | ||
116 | |||
117 | /* set the PMM bit (see comment below) */ | ||
118 | mtmsrd(mfmsr() | MSR_PMM); | ||
119 | |||
120 | for (i = 0; i < cur_cpu_spec->num_pmcs; ++i) { | ||
121 | if (ctr[i].enabled) { | ||
122 | ctr_write(i, reset_value[i]); | ||
123 | } else { | ||
124 | ctr_write(i, 0); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | mmcr0 = mfspr(SPRN_MMCR0); | ||
129 | |||
130 | /* | ||
131 | * We must clear the PMAO bit on some (GQ) chips. Just do it | ||
132 | * all the time | ||
133 | */ | ||
134 | mmcr0 &= ~MMCR0_PMAO; | ||
135 | |||
136 | /* | ||
137 | * now clear the freeze bit, counting will not start until we | ||
138 | * rfid from this excetion, because only at that point will | ||
139 | * the PMM bit be cleared | ||
140 | */ | ||
141 | mmcr0 &= ~MMCR0_FC; | ||
142 | mtspr(SPRN_MMCR0, mmcr0); | ||
143 | |||
144 | oprofile_running = 1; | ||
145 | |||
146 | dbg("start on cpu %d, mmcr0 %x\n", smp_processor_id(), mmcr0); | ||
147 | } | ||
148 | |||
149 | static void power4_stop(void) | ||
150 | { | ||
151 | unsigned int mmcr0; | ||
152 | |||
153 | /* freeze counters */ | ||
154 | mmcr0 = mfspr(SPRN_MMCR0); | ||
155 | mmcr0 |= MMCR0_FC; | ||
156 | mtspr(SPRN_MMCR0, mmcr0); | ||
157 | |||
158 | oprofile_running = 0; | ||
159 | |||
160 | dbg("stop on cpu %d, mmcr0 %x\n", smp_processor_id(), mmcr0); | ||
161 | |||
162 | mb(); | ||
163 | } | ||
164 | |||
165 | /* Fake functions used by canonicalize_pc */ | ||
166 | static void __attribute_used__ hypervisor_bucket(void) | ||
167 | { | ||
168 | } | ||
169 | |||
170 | static void __attribute_used__ rtas_bucket(void) | ||
171 | { | ||
172 | } | ||
173 | |||
174 | static void __attribute_used__ kernel_unknown_bucket(void) | ||
175 | { | ||
176 | } | ||
177 | |||
178 | static unsigned long check_spinlock_pc(struct pt_regs *regs, | ||
179 | unsigned long profile_pc) | ||
180 | { | ||
181 | unsigned long pc = instruction_pointer(regs); | ||
182 | |||
183 | /* | ||
184 | * If both the SIAR (sampled instruction) and the perfmon exception | ||
185 | * occurred in a spinlock region then we account the sample to the | ||
186 | * calling function. This isnt 100% correct, we really need soft | ||
187 | * IRQ disable so we always get the perfmon exception at the | ||
188 | * point at which the SIAR is set. | ||
189 | */ | ||
190 | if (backtrace_spinlocks && in_lock_functions(pc) && | ||
191 | in_lock_functions(profile_pc)) | ||
192 | return regs->link; | ||
193 | else | ||
194 | return profile_pc; | ||
195 | } | ||
196 | |||
197 | /* | ||
198 | * On GQ and newer the MMCRA stores the HV and PR bits at the time | ||
199 | * the SIAR was sampled. We use that to work out if the SIAR was sampled in | ||
200 | * the hypervisor, our exception vectors or RTAS. | ||
201 | */ | ||
202 | static unsigned long get_pc(struct pt_regs *regs) | ||
203 | { | ||
204 | unsigned long pc = mfspr(SPRN_SIAR); | ||
205 | unsigned long mmcra; | ||
206 | |||
207 | /* Cant do much about it */ | ||
208 | if (!mmcra_has_sihv) | ||
209 | return check_spinlock_pc(regs, pc); | ||
210 | |||
211 | mmcra = mfspr(SPRN_MMCRA); | ||
212 | |||
213 | /* Were we in the hypervisor? */ | ||
214 | if ((systemcfg->platform == PLATFORM_PSERIES_LPAR) && | ||
215 | (mmcra & MMCRA_SIHV)) | ||
216 | /* function descriptor madness */ | ||
217 | return *((unsigned long *)hypervisor_bucket); | ||
218 | |||
219 | /* We were in userspace, nothing to do */ | ||
220 | if (mmcra & MMCRA_SIPR) | ||
221 | return pc; | ||
222 | |||
223 | #ifdef CONFIG_PPC_RTAS | ||
224 | /* Were we in RTAS? */ | ||
225 | if (pc >= rtas.base && pc < (rtas.base + rtas.size)) | ||
226 | /* function descriptor madness */ | ||
227 | return *((unsigned long *)rtas_bucket); | ||
228 | #endif | ||
229 | |||
230 | /* Were we in our exception vectors or SLB real mode miss handler? */ | ||
231 | if (pc < 0x1000000UL) | ||
232 | return (unsigned long)__va(pc); | ||
233 | |||
234 | /* Not sure where we were */ | ||
235 | if (pc < KERNELBASE) | ||
236 | /* function descriptor madness */ | ||
237 | return *((unsigned long *)kernel_unknown_bucket); | ||
238 | |||
239 | return check_spinlock_pc(regs, pc); | ||
240 | } | ||
241 | |||
242 | static int get_kernel(unsigned long pc) | ||
243 | { | ||
244 | int is_kernel; | ||
245 | |||
246 | if (!mmcra_has_sihv) { | ||
247 | is_kernel = (pc >= KERNELBASE); | ||
248 | } else { | ||
249 | unsigned long mmcra = mfspr(SPRN_MMCRA); | ||
250 | is_kernel = ((mmcra & MMCRA_SIPR) == 0); | ||
251 | } | ||
252 | |||
253 | return is_kernel; | ||
254 | } | ||
255 | |||
256 | static void power4_handle_interrupt(struct pt_regs *regs, | ||
257 | struct op_counter_config *ctr) | ||
258 | { | ||
259 | unsigned long pc; | ||
260 | int is_kernel; | ||
261 | int val; | ||
262 | int i; | ||
263 | unsigned int mmcr0; | ||
264 | |||
265 | pc = get_pc(regs); | ||
266 | is_kernel = get_kernel(pc); | ||
267 | |||
268 | /* set the PMM bit (see comment below) */ | ||
269 | mtmsrd(mfmsr() | MSR_PMM); | ||
270 | |||
271 | for (i = 0; i < cur_cpu_spec->num_pmcs; ++i) { | ||
272 | val = ctr_read(i); | ||
273 | if (val < 0) { | ||
274 | if (oprofile_running && ctr[i].enabled) { | ||
275 | oprofile_add_pc(pc, is_kernel, i); | ||
276 | ctr_write(i, reset_value[i]); | ||
277 | } else { | ||
278 | ctr_write(i, 0); | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | mmcr0 = mfspr(SPRN_MMCR0); | ||
284 | |||
285 | /* reset the perfmon trigger */ | ||
286 | mmcr0 |= MMCR0_PMXE; | ||
287 | |||
288 | /* | ||
289 | * We must clear the PMAO bit on some (GQ) chips. Just do it | ||
290 | * all the time | ||
291 | */ | ||
292 | mmcr0 &= ~MMCR0_PMAO; | ||
293 | |||
294 | /* | ||
295 | * now clear the freeze bit, counting will not start until we | ||
296 | * rfid from this exception, because only at that point will | ||
297 | * the PMM bit be cleared | ||
298 | */ | ||
299 | mmcr0 &= ~MMCR0_FC; | ||
300 | mtspr(SPRN_MMCR0, mmcr0); | ||
301 | } | ||
302 | |||
303 | struct op_powerpc_model op_model_power4 = { | ||
304 | .reg_setup = power4_reg_setup, | ||
305 | .cpu_setup = power4_cpu_setup, | ||
306 | .start = power4_start, | ||
307 | .stop = power4_stop, | ||
308 | .handle_interrupt = power4_handle_interrupt, | ||
309 | }; | ||
diff --git a/arch/ppc64/oprofile/op_model_rs64.c b/arch/ppc64/oprofile/op_model_rs64.c deleted file mode 100644 index e010b85996e8..000000000000 --- a/arch/ppc64/oprofile/op_model_rs64.c +++ /dev/null | |||
@@ -1,218 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | */ | ||
9 | |||
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> | ||
15 | #include <asm/processor.h> | ||
16 | #include <asm/cputable.h> | ||
17 | #include <asm/oprofile_impl.h> | ||
18 | |||
19 | #define dbg(args...) | ||
20 | |||
21 | static void ctrl_write(unsigned int i, unsigned int val) | ||
22 | { | ||
23 | unsigned int tmp = 0; | ||
24 | unsigned long shift = 0, mask = 0; | ||
25 | |||
26 | dbg("ctrl_write %d %x\n", i, val); | ||
27 | |||
28 | switch(i) { | ||
29 | case 0: | ||
30 | tmp = mfspr(SPRN_MMCR0); | ||
31 | shift = 6; | ||
32 | mask = 0x7F; | ||
33 | break; | ||
34 | case 1: | ||
35 | tmp = mfspr(SPRN_MMCR0); | ||
36 | shift = 0; | ||
37 | mask = 0x3F; | ||
38 | break; | ||
39 | case 2: | ||
40 | tmp = mfspr(SPRN_MMCR1); | ||
41 | shift = 31 - 4; | ||
42 | mask = 0x1F; | ||
43 | break; | ||
44 | case 3: | ||
45 | tmp = mfspr(SPRN_MMCR1); | ||
46 | shift = 31 - 9; | ||
47 | mask = 0x1F; | ||
48 | break; | ||
49 | case 4: | ||
50 | tmp = mfspr(SPRN_MMCR1); | ||
51 | shift = 31 - 14; | ||
52 | mask = 0x1F; | ||
53 | break; | ||
54 | case 5: | ||
55 | tmp = mfspr(SPRN_MMCR1); | ||
56 | shift = 31 - 19; | ||
57 | mask = 0x1F; | ||
58 | break; | ||
59 | case 6: | ||
60 | tmp = mfspr(SPRN_MMCR1); | ||
61 | shift = 31 - 24; | ||
62 | mask = 0x1F; | ||
63 | break; | ||
64 | case 7: | ||
65 | tmp = mfspr(SPRN_MMCR1); | ||
66 | shift = 31 - 28; | ||
67 | mask = 0xF; | ||
68 | break; | ||
69 | } | ||
70 | |||
71 | tmp = tmp & ~(mask << shift); | ||
72 | tmp |= val << shift; | ||
73 | |||
74 | switch(i) { | ||
75 | case 0: | ||
76 | case 1: | ||
77 | mtspr(SPRN_MMCR0, tmp); | ||
78 | break; | ||
79 | default: | ||
80 | mtspr(SPRN_MMCR1, tmp); | ||
81 | } | ||
82 | |||
83 | dbg("ctrl_write mmcr0 %lx mmcr1 %lx\n", mfspr(SPRN_MMCR0), | ||
84 | mfspr(SPRN_MMCR1)); | ||
85 | } | ||
86 | |||
87 | static unsigned long reset_value[OP_MAX_COUNTER]; | ||
88 | |||
89 | static int num_counters; | ||
90 | |||
91 | static void rs64_reg_setup(struct op_counter_config *ctr, | ||
92 | struct op_system_config *sys, | ||
93 | int num_ctrs) | ||
94 | { | ||
95 | int i; | ||
96 | |||
97 | num_counters = num_ctrs; | ||
98 | |||
99 | for (i = 0; i < num_counters; ++i) | ||
100 | reset_value[i] = 0x80000000UL - ctr[i].count; | ||
101 | |||
102 | /* XXX setup user and kernel profiling */ | ||
103 | } | ||
104 | |||
105 | static void rs64_cpu_setup(void *unused) | ||
106 | { | ||
107 | unsigned int mmcr0; | ||
108 | |||
109 | /* reset MMCR0 and set the freeze bit */ | ||
110 | mmcr0 = MMCR0_FC; | ||
111 | mtspr(SPRN_MMCR0, mmcr0); | ||
112 | |||
113 | /* reset MMCR1, MMCRA */ | ||
114 | mtspr(SPRN_MMCR1, 0); | ||
115 | |||
116 | if (cpu_has_feature(CPU_FTR_MMCRA)) | ||
117 | mtspr(SPRN_MMCRA, 0); | ||
118 | |||
119 | mmcr0 |= MMCR0_FCM1|MMCR0_PMXE|MMCR0_FCECE; | ||
120 | /* Only applies to POWER3, but should be safe on RS64 */ | ||
121 | mmcr0 |= MMCR0_PMC1CE|MMCR0_PMCjCE; | ||
122 | mtspr(SPRN_MMCR0, mmcr0); | ||
123 | |||
124 | dbg("setup on cpu %d, mmcr0 %lx\n", smp_processor_id(), | ||
125 | mfspr(SPRN_MMCR0)); | ||
126 | dbg("setup on cpu %d, mmcr1 %lx\n", smp_processor_id(), | ||
127 | mfspr(SPRN_MMCR1)); | ||
128 | } | ||
129 | |||
130 | static void rs64_start(struct op_counter_config *ctr) | ||
131 | { | ||
132 | int i; | ||
133 | unsigned int mmcr0; | ||
134 | |||
135 | /* set the PMM bit (see comment below) */ | ||
136 | mtmsrd(mfmsr() | MSR_PMM); | ||
137 | |||
138 | for (i = 0; i < num_counters; ++i) { | ||
139 | if (ctr[i].enabled) { | ||
140 | ctr_write(i, reset_value[i]); | ||
141 | ctrl_write(i, ctr[i].event); | ||
142 | } else { | ||
143 | ctr_write(i, 0); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | mmcr0 = mfspr(SPRN_MMCR0); | ||
148 | |||
149 | /* | ||
150 | * now clear the freeze bit, counting will not start until we | ||
151 | * rfid from this excetion, because only at that point will | ||
152 | * the PMM bit be cleared | ||
153 | */ | ||
154 | mmcr0 &= ~MMCR0_FC; | ||
155 | mtspr(SPRN_MMCR0, mmcr0); | ||
156 | |||
157 | dbg("start on cpu %d, mmcr0 %x\n", smp_processor_id(), mmcr0); | ||
158 | } | ||
159 | |||
160 | static void rs64_stop(void) | ||
161 | { | ||
162 | unsigned int mmcr0; | ||
163 | |||
164 | /* freeze counters */ | ||
165 | mmcr0 = mfspr(SPRN_MMCR0); | ||
166 | mmcr0 |= MMCR0_FC; | ||
167 | mtspr(SPRN_MMCR0, mmcr0); | ||
168 | |||
169 | dbg("stop on cpu %d, mmcr0 %x\n", smp_processor_id(), mmcr0); | ||
170 | |||
171 | mb(); | ||
172 | } | ||
173 | |||
174 | static void rs64_handle_interrupt(struct pt_regs *regs, | ||
175 | struct op_counter_config *ctr) | ||
176 | { | ||
177 | unsigned int mmcr0; | ||
178 | int val; | ||
179 | int i; | ||
180 | unsigned long pc = mfspr(SPRN_SIAR); | ||
181 | int is_kernel = (pc >= KERNELBASE); | ||
182 | |||
183 | /* set the PMM bit (see comment below) */ | ||
184 | mtmsrd(mfmsr() | MSR_PMM); | ||
185 | |||
186 | for (i = 0; i < num_counters; ++i) { | ||
187 | val = ctr_read(i); | ||
188 | if (val < 0) { | ||
189 | if (ctr[i].enabled) { | ||
190 | oprofile_add_pc(pc, is_kernel, i); | ||
191 | ctr_write(i, reset_value[i]); | ||
192 | } else { | ||
193 | ctr_write(i, 0); | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | |||
198 | mmcr0 = mfspr(SPRN_MMCR0); | ||
199 | |||
200 | /* reset the perfmon trigger */ | ||
201 | mmcr0 |= MMCR0_PMXE; | ||
202 | |||
203 | /* | ||
204 | * now clear the freeze bit, counting will not start until we | ||
205 | * rfid from this exception, because only at that point will | ||
206 | * the PMM bit be cleared | ||
207 | */ | ||
208 | mmcr0 &= ~MMCR0_FC; | ||
209 | mtspr(SPRN_MMCR0, mmcr0); | ||
210 | } | ||
211 | |||
212 | struct op_powerpc_model op_model_rs64 = { | ||
213 | .reg_setup = rs64_reg_setup, | ||
214 | .cpu_setup = rs64_cpu_setup, | ||
215 | .start = rs64_start, | ||
216 | .stop = rs64_stop, | ||
217 | .handle_interrupt = rs64_handle_interrupt, | ||
218 | }; | ||