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/config.h>
25 #include <linux/init.h>
26 #include <linux/module.h>
27 #include <linux/prctl.h>
29 #include <asm/pgtable.h>
30 #include <asm/uaccess.h>
31 #include <asm/system.h>
35 #include <asm/perfmon.h>
37 static inline u32 get_pmlca(int ctr);
38 static inline void set_pmlca(int ctr, u32 pmlca);
40 static inline u32 get_pmlca(int ctr)
46 pmlca = mfpmr(PMRN_PMLCA0);
49 pmlca = mfpmr(PMRN_PMLCA1);
52 pmlca = mfpmr(PMRN_PMLCA2);
55 pmlca = mfpmr(PMRN_PMLCA3);
58 panic("Bad ctr number\n");
64 static inline void set_pmlca(int ctr, u32 pmlca)
68 mtpmr(PMRN_PMLCA0, pmlca);
71 mtpmr(PMRN_PMLCA1, pmlca);
74 mtpmr(PMRN_PMLCA2, pmlca);
77 mtpmr(PMRN_PMLCA3, pmlca);
80 panic("Bad ctr number\n");
84 void init_pmc_stop(int ctr)
86 u32 pmlca = (PMLCA_FC | PMLCA_FCS | PMLCA_FCU |
87 PMLCA_FCM1 | PMLCA_FCM0);
92 mtpmr(PMRN_PMLCA0, pmlca);
93 mtpmr(PMRN_PMLCB0, pmlcb);
96 mtpmr(PMRN_PMLCA1, pmlca);
97 mtpmr(PMRN_PMLCB1, pmlcb);
100 mtpmr(PMRN_PMLCA2, pmlca);
101 mtpmr(PMRN_PMLCB2, pmlcb);
104 mtpmr(PMRN_PMLCA3, pmlca);
105 mtpmr(PMRN_PMLCB3, pmlcb);
108 panic("Bad ctr number!\n");
112 void set_pmc_event(int ctr, int event)
116 pmlca = get_pmlca(ctr);
118 pmlca = (pmlca & ~PMLCA_EVENT_MASK) |
119 ((event << PMLCA_EVENT_SHIFT) &
122 set_pmlca(ctr, pmlca);
125 void set_pmc_user_kernel(int ctr, int user, int kernel)
129 pmlca = get_pmlca(ctr);
141 set_pmlca(ctr, pmlca);
144 void set_pmc_marked(int ctr, int mark0, int mark1)
146 u32 pmlca = get_pmlca(ctr);
149 pmlca &= ~PMLCA_FCM0;
154 pmlca &= ~PMLCA_FCM1;
158 set_pmlca(ctr, pmlca);
161 void pmc_start_ctr(int ctr, int enable)
163 u32 pmlca = get_pmlca(ctr);
172 set_pmlca(ctr, pmlca);
175 void pmc_start_ctrs(int enable)
177 u32 pmgc0 = mfpmr(PMRN_PMGC0);
180 pmgc0 |= PMGC0_FCECE;
185 pmgc0 &= ~PMGC0_PMIE;
187 mtpmr(PMRN_PMGC0, pmgc0);
190 void pmc_stop_ctrs(void)
192 u32 pmgc0 = mfpmr(PMRN_PMGC0);
196 pmgc0 &= ~(PMGC0_PMIE | PMGC0_FCECE);
198 mtpmr(PMRN_PMGC0, pmgc0);
203 printk("pmgc0: %x\n", mfpmr(PMRN_PMGC0));
204 printk("pmc\t\tpmlca\t\tpmlcb\n");
205 printk("%8x\t%8x\t%8x\n", mfpmr(PMRN_PMC0),
206 mfpmr(PMRN_PMLCA0), mfpmr(PMRN_PMLCB0));
207 printk("%8x\t%8x\t%8x\n", mfpmr(PMRN_PMC1),
208 mfpmr(PMRN_PMLCA1), mfpmr(PMRN_PMLCB1));
209 printk("%8x\t%8x\t%8x\n", mfpmr(PMRN_PMC2),
210 mfpmr(PMRN_PMLCA2), mfpmr(PMRN_PMLCB2));
211 printk("%8x\t%8x\t%8x\n", mfpmr(PMRN_PMC3),
212 mfpmr(PMRN_PMLCA3), mfpmr(PMRN_PMLCB3));
215 EXPORT_SYMBOL(init_pmc_stop);
216 EXPORT_SYMBOL(set_pmc_event);
217 EXPORT_SYMBOL(set_pmc_user_kernel);
218 EXPORT_SYMBOL(set_pmc_marked);
219 EXPORT_SYMBOL(pmc_start_ctr);
220 EXPORT_SYMBOL(pmc_start_ctrs);
221 EXPORT_SYMBOL(pmc_stop_ctrs);
222 EXPORT_SYMBOL(dump_pmcs);