1 /* kernel/perfmon_fsl_booke.c
2 * Freescale Book-E Performance Monitor code
5 * Copyright (c) 2004 Freescale Semiconductor, Inc
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/errno.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h>
17 #include <linux/stddef.h>
18 #include <linux/unistd.h>
19 #include <linux/ptrace.h>
20 #include <linux/slab.h>
21 #include <linux/user.h>
22 #include <linux/a.out.h>
23 #include <linux/interrupt.h>
24 #include <linux/init.h>
25 #include <linux/module.h>
26 #include <linux/prctl.h>
28 #include <asm/pgtable.h>
29 #include <asm/uaccess.h>
30 #include <asm/system.h>
36 static inline u32 get_pmlca(int ctr);
37 static inline void set_pmlca(int ctr, u32 pmlca);
39 static inline u32 get_pmlca(int ctr)
45 pmlca = mfpmr(PMRN_PMLCA0);
48 pmlca = mfpmr(PMRN_PMLCA1);
51 pmlca = mfpmr(PMRN_PMLCA2);
54 pmlca = mfpmr(PMRN_PMLCA3);
57 panic("Bad ctr number\n");
63 static inline void set_pmlca(int ctr, u32 pmlca)
67 mtpmr(PMRN_PMLCA0, pmlca);
70 mtpmr(PMRN_PMLCA1, pmlca);
73 mtpmr(PMRN_PMLCA2, pmlca);
76 mtpmr(PMRN_PMLCA3, pmlca);
79 panic("Bad ctr number\n");
83 void init_pmc_stop(int ctr)
85 u32 pmlca = (PMLCA_FC | PMLCA_FCS | PMLCA_FCU |
86 PMLCA_FCM1 | PMLCA_FCM0);
91 mtpmr(PMRN_PMLCA0, pmlca);
92 mtpmr(PMRN_PMLCB0, pmlcb);
95 mtpmr(PMRN_PMLCA1, pmlca);
96 mtpmr(PMRN_PMLCB1, pmlcb);
99 mtpmr(PMRN_PMLCA2, pmlca);
100 mtpmr(PMRN_PMLCB2, pmlcb);
103 mtpmr(PMRN_PMLCA3, pmlca);
104 mtpmr(PMRN_PMLCB3, pmlcb);
107 panic("Bad ctr number!\n");
111 void set_pmc_event(int ctr, int event)
115 pmlca = get_pmlca(ctr);
117 pmlca = (pmlca & ~PMLCA_EVENT_MASK) |
118 ((event << PMLCA_EVENT_SHIFT) &
121 set_pmlca(ctr, pmlca);
124 void set_pmc_user_kernel(int ctr, int user, int kernel)
128 pmlca = get_pmlca(ctr);
140 set_pmlca(ctr, pmlca);
143 void set_pmc_marked(int ctr, int mark0, int mark1)
145 u32 pmlca = get_pmlca(ctr);
148 pmlca &= ~PMLCA_FCM0;
153 pmlca &= ~PMLCA_FCM1;
157 set_pmlca(ctr, pmlca);
160 void pmc_start_ctr(int ctr, int enable)
162 u32 pmlca = get_pmlca(ctr);
171 set_pmlca(ctr, pmlca);
174 void pmc_start_ctrs(int enable)
176 u32 pmgc0 = mfpmr(PMRN_PMGC0);
179 pmgc0 |= PMGC0_FCECE;
184 pmgc0 &= ~PMGC0_PMIE;
186 mtpmr(PMRN_PMGC0, pmgc0);
189 void pmc_stop_ctrs(void)
191 u32 pmgc0 = mfpmr(PMRN_PMGC0);
195 pmgc0 &= ~(PMGC0_PMIE | PMGC0_FCECE);
197 mtpmr(PMRN_PMGC0, pmgc0);
202 printk("pmgc0: %x\n", mfpmr(PMRN_PMGC0));
203 printk("pmc\t\tpmlca\t\tpmlcb\n");
204 printk("%8x\t%8x\t%8x\n", mfpmr(PMRN_PMC0),
205 mfpmr(PMRN_PMLCA0), mfpmr(PMRN_PMLCB0));
206 printk("%8x\t%8x\t%8x\n", mfpmr(PMRN_PMC1),
207 mfpmr(PMRN_PMLCA1), mfpmr(PMRN_PMLCB1));
208 printk("%8x\t%8x\t%8x\n", mfpmr(PMRN_PMC2),
209 mfpmr(PMRN_PMLCA2), mfpmr(PMRN_PMLCB2));
210 printk("%8x\t%8x\t%8x\n", mfpmr(PMRN_PMC3),
211 mfpmr(PMRN_PMLCA3), mfpmr(PMRN_PMLCB3));
214 EXPORT_SYMBOL(init_pmc_stop);
215 EXPORT_SYMBOL(set_pmc_event);
216 EXPORT_SYMBOL(set_pmc_user_kernel);
217 EXPORT_SYMBOL(set_pmc_marked);
218 EXPORT_SYMBOL(pmc_start_ctr);
219 EXPORT_SYMBOL(pmc_start_ctrs);
220 EXPORT_SYMBOL(pmc_stop_ctrs);
221 EXPORT_SYMBOL(dump_pmcs);