2 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
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.
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>
21 static void ctrl_write(unsigned int i
, unsigned int val
)
24 unsigned long shift
= 0, mask
= 0;
26 dbg("ctrl_write %d %x\n", i
, val
);
30 tmp
= mfspr(SPRN_MMCR0
);
35 tmp
= mfspr(SPRN_MMCR0
);
40 tmp
= mfspr(SPRN_MMCR1
);
45 tmp
= mfspr(SPRN_MMCR1
);
50 tmp
= mfspr(SPRN_MMCR1
);
55 tmp
= mfspr(SPRN_MMCR1
);
60 tmp
= mfspr(SPRN_MMCR1
);
65 tmp
= mfspr(SPRN_MMCR1
);
71 tmp
= tmp
& ~(mask
<< shift
);
77 mtspr(SPRN_MMCR0
, tmp
);
80 mtspr(SPRN_MMCR1
, tmp
);
83 dbg("ctrl_write mmcr0 %lx mmcr1 %lx\n", mfspr(SPRN_MMCR0
),
87 static unsigned long reset_value
[OP_MAX_COUNTER
];
89 static int num_counters
;
91 static int rs64_reg_setup(struct op_counter_config
*ctr
,
92 struct op_system_config
*sys
,
97 num_counters
= num_ctrs
;
99 for (i
= 0; i
< num_counters
; ++i
)
100 reset_value
[i
] = 0x80000000UL
- ctr
[i
].count
;
102 /* XXX setup user and kernel profiling */
106 static int rs64_cpu_setup(struct op_counter_config
*ctr
)
110 /* reset MMCR0 and set the freeze bit */
112 mtspr(SPRN_MMCR0
, mmcr0
);
114 /* reset MMCR1, MMCRA */
115 mtspr(SPRN_MMCR1
, 0);
117 if (cpu_has_feature(CPU_FTR_MMCRA
))
118 mtspr(SPRN_MMCRA
, 0);
120 mmcr0
|= MMCR0_FCM1
|MMCR0_PMXE
|MMCR0_FCECE
;
121 /* Only applies to POWER3, but should be safe on RS64 */
122 mmcr0
|= MMCR0_PMC1CE
|MMCR0_PMCjCE
;
123 mtspr(SPRN_MMCR0
, mmcr0
);
125 dbg("setup on cpu %d, mmcr0 %lx\n", smp_processor_id(),
127 dbg("setup on cpu %d, mmcr1 %lx\n", smp_processor_id(),
133 static int rs64_start(struct op_counter_config
*ctr
)
138 /* set the PMM bit (see comment below) */
139 mtmsrd(mfmsr() | MSR_PMM
);
141 for (i
= 0; i
< num_counters
; ++i
) {
142 if (ctr
[i
].enabled
) {
143 classic_ctr_write(i
, reset_value
[i
]);
144 ctrl_write(i
, ctr
[i
].event
);
146 classic_ctr_write(i
, 0);
150 mmcr0
= mfspr(SPRN_MMCR0
);
153 * now clear the freeze bit, counting will not start until we
154 * rfid from this excetion, because only at that point will
155 * the PMM bit be cleared
158 mtspr(SPRN_MMCR0
, mmcr0
);
160 dbg("start on cpu %d, mmcr0 %x\n", smp_processor_id(), mmcr0
);
164 static void rs64_stop(void)
168 /* freeze counters */
169 mmcr0
= mfspr(SPRN_MMCR0
);
171 mtspr(SPRN_MMCR0
, mmcr0
);
173 dbg("stop on cpu %d, mmcr0 %x\n", smp_processor_id(), mmcr0
);
178 static void rs64_handle_interrupt(struct pt_regs
*regs
,
179 struct op_counter_config
*ctr
)
185 unsigned long pc
= mfspr(SPRN_SIAR
);
187 is_kernel
= is_kernel_addr(pc
);
189 /* set the PMM bit (see comment below) */
190 mtmsrd(mfmsr() | MSR_PMM
);
192 for (i
= 0; i
< num_counters
; ++i
) {
193 val
= classic_ctr_read(i
);
195 if (ctr
[i
].enabled
) {
196 oprofile_add_ext_sample(pc
, regs
, i
, is_kernel
);
197 classic_ctr_write(i
, reset_value
[i
]);
199 classic_ctr_write(i
, 0);
204 mmcr0
= mfspr(SPRN_MMCR0
);
206 /* reset the perfmon trigger */
210 * now clear the freeze bit, counting will not start until we
211 * rfid from this exception, because only at that point will
212 * the PMM bit be cleared
215 mtspr(SPRN_MMCR0
, mmcr0
);
218 struct op_powerpc_model op_model_rs64
= {
219 .reg_setup
= rs64_reg_setup
,
220 .cpu_setup
= rs64_cpu_setup
,
223 .handle_interrupt
= rs64_handle_interrupt
,