]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/ppc/kernel/perfmon.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6-omap-h63xx.git] / arch / ppc / kernel / perfmon.c
1 /* kernel/perfmon.c
2  * PPC 32 Performance Monitor Infrastructure
3  *
4  * Author: Andy Fleming
5  * Copyright (c) 2004 Freescale Semiconductor, Inc
6  *
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.
11  */
12
13 #include <linux/errno.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h>
16 #include <linux/mm.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>
28
29 #include <asm/pgtable.h>
30 #include <asm/uaccess.h>
31 #include <asm/system.h>
32 #include <asm/io.h>
33 #include <asm/reg.h>
34 #include <asm/xmon.h>
35
36 /* A lock to regulate grabbing the interrupt */
37 DEFINE_SPINLOCK(perfmon_lock);
38
39 #if defined (CONFIG_FSL_BOOKE) && !defined (CONFIG_E200)
40 static void dummy_perf(struct pt_regs *regs)
41 {
42         unsigned int pmgc0 = mfpmr(PMRN_PMGC0);
43
44         pmgc0 &= ~PMGC0_PMIE;
45         mtpmr(PMRN_PMGC0, pmgc0);
46 }
47
48 #elif CONFIG_6xx
49 /* Ensure exceptions are disabled */
50
51 static void dummy_perf(struct pt_regs *regs)
52 {
53         unsigned int mmcr0 = mfspr(SPRN_MMCR0);
54
55         mmcr0 &= ~MMCR0_PMXE;
56         mtspr(SPRN_MMCR0, mmcr0);
57 }
58 #else
59 static void dummy_perf(struct pt_regs *regs)
60 {
61 }
62 #endif
63
64 void (*perf_irq)(struct pt_regs *) = dummy_perf;
65
66 /* Grab the interrupt, if it's free.
67  * Returns 0 on success, -1 if the interrupt is taken already */
68 int request_perfmon_irq(void (*handler)(struct pt_regs *))
69 {
70         int err = 0;
71
72         spin_lock(&perfmon_lock);
73
74         if (perf_irq == dummy_perf)
75                 perf_irq = handler;
76         else {
77                 pr_info("perfmon irq already handled by %p\n", perf_irq);
78                 err = -1;
79         }
80
81         spin_unlock(&perfmon_lock);
82
83         return err;
84 }
85
86 void free_perfmon_irq(void)
87 {
88         spin_lock(&perfmon_lock);
89
90         perf_irq = dummy_perf;
91
92         spin_unlock(&perfmon_lock);
93 }
94
95 EXPORT_SYMBOL(perf_irq);
96 EXPORT_SYMBOL(request_perfmon_irq);
97 EXPORT_SYMBOL(free_perfmon_irq);