2 * linux/arch/ppc64/kernel/pmc.c
4 * Copyright (C) 2004 David Gibson, IBM Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/config.h>
13 #include <linux/errno.h>
14 #include <linux/spinlock.h>
15 #include <linux/module.h>
17 #include <asm/processor.h>
20 /* Ensure exceptions are disabled */
21 static void dummy_perf(struct pt_regs *regs)
23 unsigned int mmcr0 = mfspr(SPRN_MMCR0);
25 mmcr0 &= ~(MMCR0_PMXE|MMCR0_PMAO);
26 mtspr(SPRN_MMCR0, mmcr0);
29 static spinlock_t pmc_owner_lock = SPIN_LOCK_UNLOCKED;
30 static void *pmc_owner_caller; /* mostly for debugging */
31 perf_irq_t perf_irq = dummy_perf;
33 int reserve_pmc_hardware(perf_irq_t new_perf_irq)
37 spin_lock(&pmc_owner_lock);
39 if (pmc_owner_caller) {
40 printk(KERN_WARNING "reserve_pmc_hardware: "
41 "PMC hardware busy (reserved by caller %p)\n",
47 pmc_owner_caller = __builtin_return_address(0);
48 perf_irq = new_perf_irq ? : dummy_perf;
51 spin_unlock(&pmc_owner_lock);
54 EXPORT_SYMBOL_GPL(reserve_pmc_hardware);
56 void release_pmc_hardware(void)
58 spin_lock(&pmc_owner_lock);
60 WARN_ON(! pmc_owner_caller);
62 pmc_owner_caller = NULL;
63 perf_irq = dummy_perf;
65 spin_unlock(&pmc_owner_lock);
67 EXPORT_SYMBOL_GPL(release_pmc_hardware);
69 void power4_enable_pmcs(void)
74 hid0 |= 1UL << (63 - 20);
76 /* POWER4 requires the following sequence */
86 "isync" : "=&r" (hid0) : "i" (HID0), "0" (hid0):