x86/efi: Enforce CONFIG_RELOCATABLE for EFI boot stub
[linux/fpc-iii.git] / arch / powerpc / oprofile / op_model_fsl_emb.c
blob2a82d3ed464d09123db06c59c429014176611272
1 /*
2 * Freescale Embedded oprofile support, based on ppc64 oprofile support
3 * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
5 * Copyright (c) 2004, 2010 Freescale Semiconductor, Inc
7 * Author: Andy Fleming
8 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
16 #include <linux/oprofile.h>
17 #include <linux/init.h>
18 #include <linux/smp.h>
19 #include <asm/ptrace.h>
20 #include <asm/processor.h>
21 #include <asm/cputable.h>
22 #include <asm/reg_fsl_emb.h>
23 #include <asm/page.h>
24 #include <asm/pmc.h>
25 #include <asm/oprofile_impl.h>
27 static unsigned long reset_value[OP_MAX_COUNTER];
29 static int num_counters;
30 static int oprofile_running;
32 static inline u32 get_pmlca(int ctr)
34 u32 pmlca;
36 switch (ctr) {
37 case 0:
38 pmlca = mfpmr(PMRN_PMLCA0);
39 break;
40 case 1:
41 pmlca = mfpmr(PMRN_PMLCA1);
42 break;
43 case 2:
44 pmlca = mfpmr(PMRN_PMLCA2);
45 break;
46 case 3:
47 pmlca = mfpmr(PMRN_PMLCA3);
48 break;
49 case 4:
50 pmlca = mfpmr(PMRN_PMLCA4);
51 break;
52 case 5:
53 pmlca = mfpmr(PMRN_PMLCA5);
54 break;
55 default:
56 panic("Bad ctr number\n");
59 return pmlca;
62 static inline void set_pmlca(int ctr, u32 pmlca)
64 switch (ctr) {
65 case 0:
66 mtpmr(PMRN_PMLCA0, pmlca);
67 break;
68 case 1:
69 mtpmr(PMRN_PMLCA1, pmlca);
70 break;
71 case 2:
72 mtpmr(PMRN_PMLCA2, pmlca);
73 break;
74 case 3:
75 mtpmr(PMRN_PMLCA3, pmlca);
76 break;
77 case 4:
78 mtpmr(PMRN_PMLCA4, pmlca);
79 break;
80 case 5:
81 mtpmr(PMRN_PMLCA5, pmlca);
82 break;
83 default:
84 panic("Bad ctr number\n");
88 static inline unsigned int ctr_read(unsigned int i)
90 switch(i) {
91 case 0:
92 return mfpmr(PMRN_PMC0);
93 case 1:
94 return mfpmr(PMRN_PMC1);
95 case 2:
96 return mfpmr(PMRN_PMC2);
97 case 3:
98 return mfpmr(PMRN_PMC3);
99 case 4:
100 return mfpmr(PMRN_PMC4);
101 case 5:
102 return mfpmr(PMRN_PMC5);
103 default:
104 return 0;
108 static inline void ctr_write(unsigned int i, unsigned int val)
110 switch(i) {
111 case 0:
112 mtpmr(PMRN_PMC0, val);
113 break;
114 case 1:
115 mtpmr(PMRN_PMC1, val);
116 break;
117 case 2:
118 mtpmr(PMRN_PMC2, val);
119 break;
120 case 3:
121 mtpmr(PMRN_PMC3, val);
122 break;
123 case 4:
124 mtpmr(PMRN_PMC4, val);
125 break;
126 case 5:
127 mtpmr(PMRN_PMC5, val);
128 break;
129 default:
130 break;
135 static void init_pmc_stop(int ctr)
137 u32 pmlca = (PMLCA_FC | PMLCA_FCS | PMLCA_FCU |
138 PMLCA_FCM1 | PMLCA_FCM0);
139 u32 pmlcb = 0;
141 switch (ctr) {
142 case 0:
143 mtpmr(PMRN_PMLCA0, pmlca);
144 mtpmr(PMRN_PMLCB0, pmlcb);
145 break;
146 case 1:
147 mtpmr(PMRN_PMLCA1, pmlca);
148 mtpmr(PMRN_PMLCB1, pmlcb);
149 break;
150 case 2:
151 mtpmr(PMRN_PMLCA2, pmlca);
152 mtpmr(PMRN_PMLCB2, pmlcb);
153 break;
154 case 3:
155 mtpmr(PMRN_PMLCA3, pmlca);
156 mtpmr(PMRN_PMLCB3, pmlcb);
157 break;
158 case 4:
159 mtpmr(PMRN_PMLCA4, pmlca);
160 mtpmr(PMRN_PMLCB4, pmlcb);
161 break;
162 case 5:
163 mtpmr(PMRN_PMLCA5, pmlca);
164 mtpmr(PMRN_PMLCB5, pmlcb);
165 break;
166 default:
167 panic("Bad ctr number!\n");
171 static void set_pmc_event(int ctr, int event)
173 u32 pmlca;
175 pmlca = get_pmlca(ctr);
177 pmlca = (pmlca & ~PMLCA_EVENT_MASK) |
178 ((event << PMLCA_EVENT_SHIFT) &
179 PMLCA_EVENT_MASK);
181 set_pmlca(ctr, pmlca);
184 static void set_pmc_user_kernel(int ctr, int user, int kernel)
186 u32 pmlca;
188 pmlca = get_pmlca(ctr);
190 if(user)
191 pmlca &= ~PMLCA_FCU;
192 else
193 pmlca |= PMLCA_FCU;
195 if(kernel)
196 pmlca &= ~PMLCA_FCS;
197 else
198 pmlca |= PMLCA_FCS;
200 set_pmlca(ctr, pmlca);
203 static void set_pmc_marked(int ctr, int mark0, int mark1)
205 u32 pmlca = get_pmlca(ctr);
207 if(mark0)
208 pmlca &= ~PMLCA_FCM0;
209 else
210 pmlca |= PMLCA_FCM0;
212 if(mark1)
213 pmlca &= ~PMLCA_FCM1;
214 else
215 pmlca |= PMLCA_FCM1;
217 set_pmlca(ctr, pmlca);
220 static void pmc_start_ctr(int ctr, int enable)
222 u32 pmlca = get_pmlca(ctr);
224 pmlca &= ~PMLCA_FC;
226 if (enable)
227 pmlca |= PMLCA_CE;
228 else
229 pmlca &= ~PMLCA_CE;
231 set_pmlca(ctr, pmlca);
234 static void pmc_start_ctrs(int enable)
236 u32 pmgc0 = mfpmr(PMRN_PMGC0);
238 pmgc0 &= ~PMGC0_FAC;
239 pmgc0 |= PMGC0_FCECE;
241 if (enable)
242 pmgc0 |= PMGC0_PMIE;
243 else
244 pmgc0 &= ~PMGC0_PMIE;
246 mtpmr(PMRN_PMGC0, pmgc0);
249 static void pmc_stop_ctrs(void)
251 u32 pmgc0 = mfpmr(PMRN_PMGC0);
253 pmgc0 |= PMGC0_FAC;
255 pmgc0 &= ~(PMGC0_PMIE | PMGC0_FCECE);
257 mtpmr(PMRN_PMGC0, pmgc0);
260 static int fsl_emb_cpu_setup(struct op_counter_config *ctr)
262 int i;
264 /* freeze all counters */
265 pmc_stop_ctrs();
267 for (i = 0;i < num_counters;i++) {
268 init_pmc_stop(i);
270 set_pmc_event(i, ctr[i].event);
272 set_pmc_user_kernel(i, ctr[i].user, ctr[i].kernel);
275 return 0;
278 static int fsl_emb_reg_setup(struct op_counter_config *ctr,
279 struct op_system_config *sys,
280 int num_ctrs)
282 int i;
284 num_counters = num_ctrs;
286 /* Our counters count up, and "count" refers to
287 * how much before the next interrupt, and we interrupt
288 * on overflow. So we calculate the starting value
289 * which will give us "count" until overflow.
290 * Then we set the events on the enabled counters */
291 for (i = 0; i < num_counters; ++i)
292 reset_value[i] = 0x80000000UL - ctr[i].count;
294 return 0;
297 static int fsl_emb_start(struct op_counter_config *ctr)
299 int i;
301 mtmsr(mfmsr() | MSR_PMM);
303 for (i = 0; i < num_counters; ++i) {
304 if (ctr[i].enabled) {
305 ctr_write(i, reset_value[i]);
306 /* Set each enabled counter to only
307 * count when the Mark bit is *not* set */
308 set_pmc_marked(i, 1, 0);
309 pmc_start_ctr(i, 1);
310 } else {
311 ctr_write(i, 0);
313 /* Set the ctr to be stopped */
314 pmc_start_ctr(i, 0);
318 /* Clear the freeze bit, and enable the interrupt.
319 * The counters won't actually start until the rfi clears
320 * the PMM bit */
321 pmc_start_ctrs(1);
323 oprofile_running = 1;
325 pr_debug("start on cpu %d, pmgc0 %x\n", smp_processor_id(),
326 mfpmr(PMRN_PMGC0));
328 return 0;
331 static void fsl_emb_stop(void)
333 /* freeze counters */
334 pmc_stop_ctrs();
336 oprofile_running = 0;
338 pr_debug("stop on cpu %d, pmgc0 %x\n", smp_processor_id(),
339 mfpmr(PMRN_PMGC0));
341 mb();
345 static void fsl_emb_handle_interrupt(struct pt_regs *regs,
346 struct op_counter_config *ctr)
348 unsigned long pc;
349 int is_kernel;
350 int val;
351 int i;
353 pc = regs->nip;
354 is_kernel = is_kernel_addr(pc);
356 for (i = 0; i < num_counters; ++i) {
357 val = ctr_read(i);
358 if (val < 0) {
359 if (oprofile_running && ctr[i].enabled) {
360 oprofile_add_ext_sample(pc, regs, i, is_kernel);
361 ctr_write(i, reset_value[i]);
362 } else {
363 ctr_write(i, 0);
368 /* The freeze bit was set by the interrupt. */
369 /* Clear the freeze bit, and reenable the interrupt. The
370 * counters won't actually start until the rfi clears the PMM
371 * bit. The PMM bit should not be set until after the interrupt
372 * is cleared to avoid it getting lost in some hypervisor
373 * environments.
375 mtmsr(mfmsr() | MSR_PMM);
376 pmc_start_ctrs(1);
379 struct op_powerpc_model op_model_fsl_emb = {
380 .reg_setup = fsl_emb_reg_setup,
381 .cpu_setup = fsl_emb_cpu_setup,
382 .start = fsl_emb_start,
383 .stop = fsl_emb_stop,
384 .handle_interrupt = fsl_emb_handle_interrupt,