[PATCH] more SPIN_LOCK_UNLOCKED -> DEFINE_SPINLOCK conversions
[linux-2.6/libata-dev.git] / arch / ppc64 / kernel / pmc.c
blob63d9481c3ec2f7548cda86435c5b6a1311292b0f
1 /*
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>
18 #include <asm/pmc.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 DEFINE_SPINLOCK(pmc_owner_lock);
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)
35 int err = 0;
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",
42 pmc_owner_caller);
43 err = -EBUSY;
44 goto out;
47 pmc_owner_caller = __builtin_return_address(0);
48 perf_irq = new_perf_irq ? : dummy_perf;
50 out:
51 spin_unlock(&pmc_owner_lock);
52 return err;
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)
71 unsigned long hid0;
73 hid0 = mfspr(HID0);
74 hid0 |= 1UL << (63 - 20);
76 /* POWER4 requires the following sequence */
77 asm volatile(
78 "sync\n"
79 "mtspr %1, %0\n"
80 "mfspr %0, %1\n"
81 "mfspr %0, %1\n"
82 "mfspr %0, %1\n"
83 "mfspr %0, %1\n"
84 "mfspr %0, %1\n"
85 "mfspr %0, %1\n"
86 "isync" : "=&r" (hid0) : "i" (HID0), "0" (hid0):
87 "memory");