1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/oprofile.h>
19#include <linux/init.h>
20#include <linux/smp.h>
21#include <asm/ptrace.h>
22#include <asm/system.h>
23#include <asm/processor.h>
24#include <asm/cputable.h>
25#include <asm/page.h>
26#include <asm/pmc.h>
27#include <asm/oprofile_impl.h>
28
29static unsigned long reset_value[OP_MAX_COUNTER];
30
31static int oprofile_running;
32static u32 mmcr0_val, mmcr1_val, mmcr2_val, num_pmcs;
33
34#define MMCR0_PMC1_SHIFT 6
35#define MMCR0_PMC2_SHIFT 0
36#define MMCR1_PMC3_SHIFT 27
37#define MMCR1_PMC4_SHIFT 22
38#define MMCR1_PMC5_SHIFT 17
39#define MMCR1_PMC6_SHIFT 11
40
41#define mmcr0_event1(event) \
42 ((event << MMCR0_PMC1_SHIFT) & MMCR0_PMC1SEL)
43#define mmcr0_event2(event) \
44 ((event << MMCR0_PMC2_SHIFT) & MMCR0_PMC2SEL)
45
46#define mmcr1_event3(event) \
47 ((event << MMCR1_PMC3_SHIFT) & MMCR1_PMC3SEL)
48#define mmcr1_event4(event) \
49 ((event << MMCR1_PMC4_SHIFT) & MMCR1_PMC4SEL)
50#define mmcr1_event5(event) \
51 ((event << MMCR1_PMC5_SHIFT) & MMCR1_PMC5SEL)
52#define mmcr1_event6(event) \
53 ((event << MMCR1_PMC6_SHIFT) & MMCR1_PMC6SEL)
54
55#define MMCR0_INIT (MMCR0_FC | MMCR0_FCS | MMCR0_FCP | MMCR0_FCM1 | MMCR0_FCM0)
56
57
58
59
60
61static void pmc_start_ctrs(void)
62{
63 u32 mmcr0 = mfspr(SPRN_MMCR0);
64
65 mmcr0 &= ~(MMCR0_FC | MMCR0_FCM0);
66 mmcr0 |= (MMCR0_FCECE | MMCR0_PMC1CE | MMCR0_PMCnCE | MMCR0_PMXE);
67
68 mtspr(SPRN_MMCR0, mmcr0);
69}
70
71
72static void pmc_stop_ctrs(void)
73{
74 u32 mmcr0 = mfspr(SPRN_MMCR0);
75
76 mmcr0 |= MMCR0_FC;
77 mmcr0 &= ~(MMCR0_FCECE | MMCR0_PMC1CE | MMCR0_PMCnCE | MMCR0_PMXE);
78
79 mtspr(SPRN_MMCR0, mmcr0);
80}
81
82
83
84static int fsl7450_cpu_setup(struct op_counter_config *ctr)
85{
86
87 pmc_stop_ctrs();
88
89 mtspr(SPRN_MMCR0, mmcr0_val);
90 mtspr(SPRN_MMCR1, mmcr1_val);
91 if (num_pmcs > 4)
92 mtspr(SPRN_MMCR2, mmcr2_val);
93
94 return 0;
95}
96
97
98static int fsl7450_reg_setup(struct op_counter_config *ctr,
99 struct op_system_config *sys,
100 int num_ctrs)
101{
102 int i;
103
104 num_pmcs = num_ctrs;
105
106
107
108
109
110 for (i = 0; i < num_ctrs; ++i)
111 reset_value[i] = 0x80000000UL - ctr[i].count;
112
113
114 mmcr0_val = MMCR0_INIT | mmcr0_event1(ctr[0].event)
115 | mmcr0_event2(ctr[1].event);
116
117
118 if (sys->enable_kernel)
119 mmcr0_val &= ~(MMCR0_FCS);
120
121 if (sys->enable_user)
122 mmcr0_val &= ~(MMCR0_FCP);
123
124
125 mmcr1_val = mmcr1_event3(ctr[2].event)
126 | mmcr1_event4(ctr[3].event);
127 if (num_ctrs > 4)
128 mmcr1_val |= mmcr1_event5(ctr[4].event)
129 | mmcr1_event6(ctr[5].event);
130
131 mmcr2_val = 0;
132
133 return 0;
134}
135
136
137static int fsl7450_start(struct op_counter_config *ctr)
138{
139 int i;
140
141 mtmsr(mfmsr() | MSR_PMM);
142
143 for (i = 0; i < num_pmcs; ++i) {
144 if (ctr[i].enabled)
145 classic_ctr_write(i, reset_value[i]);
146 else
147 classic_ctr_write(i, 0);
148 }
149
150
151
152
153 pmc_start_ctrs();
154
155 oprofile_running = 1;
156
157 return 0;
158}
159
160
161static void fsl7450_stop(void)
162{
163
164 pmc_stop_ctrs();
165
166 oprofile_running = 0;
167
168 mb();
169}
170
171
172
173
174static void fsl7450_handle_interrupt(struct pt_regs *regs,
175 struct op_counter_config *ctr)
176{
177 unsigned long pc;
178 int is_kernel;
179 int val;
180 int i;
181
182
183 mtmsr(mfmsr() | MSR_PMM);
184
185 pc = mfspr(SPRN_SIAR);
186 is_kernel = is_kernel_addr(pc);
187
188 for (i = 0; i < num_pmcs; ++i) {
189 val = classic_ctr_read(i);
190 if (val < 0) {
191 if (oprofile_running && ctr[i].enabled) {
192 oprofile_add_ext_sample(pc, regs, i, is_kernel);
193 classic_ctr_write(i, reset_value[i]);
194 } else {
195 classic_ctr_write(i, 0);
196 }
197 }
198 }
199
200
201
202
203
204 pmc_start_ctrs();
205}
206
207struct op_powerpc_model op_model_7450= {
208 .reg_setup = fsl7450_reg_setup,
209 .cpu_setup = fsl7450_cpu_setup,
210 .start = fsl7450_start,
211 .stop = fsl7450_stop,
212 .handle_interrupt = fsl7450_handle_interrupt,
213};
214