Blame view

arch/powerpc/kernel/pmc.c 2.32 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
f7f6f4fea   David Gibson   [PATCH] powerpc: ...
2
   *  arch/powerpc/kernel/pmc.c
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
   *
   *  Copyright (C) 2004 David Gibson, IBM Corporation.
f7f6f4fea   David Gibson   [PATCH] powerpc: ...
5
6
7
   *  Includes code formerly from arch/ppc/kernel/perfmon.c:
   *    Author: Andy Fleming
   *    Copyright (c) 2004 Freescale Semiconductor, Inc
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
11
12
13
   *
   *  This program is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU General Public License
   *  as published by the Free Software Foundation; either version
   *  2 of the License, or (at your option) any later version.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
  #include <linux/errno.h>
  #include <linux/spinlock.h>
4b16f8e2d   Paul Gortmaker   powerpc: various ...
16
  #include <linux/export.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
  
  #include <asm/processor.h>
6529c13df   Olof Johansson   [POWERPC] PA6T PM...
19
  #include <asm/cputable.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
  #include <asm/pmc.h>
177e9ea49   Anton Blanchard   [POWERPC] Fix typ...
21
22
  #ifndef MMCR0_PMAO
  #define MMCR0_PMAO	0
f7f6f4fea   David Gibson   [PATCH] powerpc: ...
23
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
  static void dummy_perf(struct pt_regs *regs)
  {
39aef685a   Andy Fleming   [POWERPC] Made FS...
26
  #if defined(CONFIG_FSL_EMB_PERFMON)
1bd2e5ae1   Olof Johansson   [POWERPC] Add PMC...
27
28
  	mtpmr(PMRN_PMGC0, mfpmr(PMRN_PMGC0) & ~PMGC0_PMIE);
  #elif defined(CONFIG_PPC64) || defined(CONFIG_6xx)
6529c13df   Olof Johansson   [POWERPC] PA6T PM...
29
  	if (cur_cpu_spec->pmc_type == PPC_PMC_IBM)
177e9ea49   Anton Blanchard   [POWERPC] Fix typ...
30
  		mtspr(SPRN_MMCR0, mfspr(SPRN_MMCR0) & ~(MMCR0_PMXE|MMCR0_PMAO));
f7f6f4fea   David Gibson   [PATCH] powerpc: ...
31
  #else
1bd2e5ae1   Olof Johansson   [POWERPC] Add PMC...
32
  	mtspr(SPRN_MMCR0, mfspr(SPRN_MMCR0) & ~MMCR0_PMXE);
f7f6f4fea   David Gibson   [PATCH] powerpc: ...
33
  #endif
1bd2e5ae1   Olof Johansson   [POWERPC] Add PMC...
34
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35

071c06cb5   Thomas Gleixner   powerpc: Convert ...
36
  static DEFINE_RAW_SPINLOCK(pmc_owner_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
40
41
42
  static void *pmc_owner_caller; /* mostly for debugging */
  perf_irq_t perf_irq = dummy_perf;
  
  int reserve_pmc_hardware(perf_irq_t new_perf_irq)
  {
  	int err = 0;
071c06cb5   Thomas Gleixner   powerpc: Convert ...
43
  	raw_spin_lock(&pmc_owner_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
46
47
48
49
50
51
52
53
54
  
  	if (pmc_owner_caller) {
  		printk(KERN_WARNING "reserve_pmc_hardware: "
  		       "PMC hardware busy (reserved by caller %p)
  ",
  		       pmc_owner_caller);
  		err = -EBUSY;
  		goto out;
  	}
  
  	pmc_owner_caller = __builtin_return_address(0);
dd6c89f68   Andy Fleming   [POWERPC] Fix opr...
55
  	perf_irq = new_perf_irq ? new_perf_irq : dummy_perf;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
57
  
   out:
071c06cb5   Thomas Gleixner   powerpc: Convert ...
58
  	raw_spin_unlock(&pmc_owner_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
61
62
63
64
  	return err;
  }
  EXPORT_SYMBOL_GPL(reserve_pmc_hardware);
  
  void release_pmc_hardware(void)
  {
071c06cb5   Thomas Gleixner   powerpc: Convert ...
65
  	raw_spin_lock(&pmc_owner_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
  
  	WARN_ON(! pmc_owner_caller);
  
  	pmc_owner_caller = NULL;
  	perf_irq = dummy_perf;
071c06cb5   Thomas Gleixner   powerpc: Convert ...
71
  	raw_spin_unlock(&pmc_owner_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
  }
  EXPORT_SYMBOL_GPL(release_pmc_hardware);
180a33627   Michael Ellerman   [PATCH] ppc64: Mo...
74

f7f6f4fea   David Gibson   [PATCH] powerpc: ...
75
  #ifdef CONFIG_PPC64
180a33627   Michael Ellerman   [PATCH] ppc64: Mo...
76
77
78
  void power4_enable_pmcs(void)
  {
  	unsigned long hid0;
b5bbeb237   Paul Mackerras   powerpc: Use SPRN...
79
  	hid0 = mfspr(SPRN_HID0);
180a33627   Michael Ellerman   [PATCH] ppc64: Mo...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  	hid0 |= 1UL << (63 - 20);
  
  	/* POWER4 requires the following sequence */
  	asm volatile(
  		"sync
  "
  		"mtspr     %1, %0
  "
  		"mfspr     %0, %1
  "
  		"mfspr     %0, %1
  "
  		"mfspr     %0, %1
  "
  		"mfspr     %0, %1
  "
  		"mfspr     %0, %1
  "
  		"mfspr     %0, %1
  "
b5bbeb237   Paul Mackerras   powerpc: Use SPRN...
100
  		"isync" : "=&r" (hid0) : "i" (SPRN_HID0), "0" (hid0):
180a33627   Michael Ellerman   [PATCH] ppc64: Mo...
101
102
  		"memory");
  }
f7f6f4fea   David Gibson   [PATCH] powerpc: ...
103
  #endif /* CONFIG_PPC64 */