perfmon.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include <linux/errno.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/stddef.h>
  17. #include <linux/unistd.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/slab.h>
  20. #include <linux/user.h>
  21. #include <linux/a.out.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/config.h>
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/prctl.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/system.h>
  30. #include <asm/io.h>
  31. #include <asm/reg.h>
  32. #include <asm/xmon.h>
  33. /* A lock to regulate grabbing the interrupt */
  34. DEFINE_SPINLOCK(perfmon_lock);
  35. #if defined (CONFIG_FSL_BOOKE) && !defined (CONFIG_E200)
  36. static void dummy_perf(struct pt_regs *regs)
  37. {
  38. unsigned int pmgc0 = mfpmr(PMRN_PMGC0);
  39. pmgc0 &= ~PMGC0_PMIE;
  40. mtpmr(PMRN_PMGC0, pmgc0);
  41. }
  42. #elif CONFIG_6xx
  43. /* Ensure exceptions are disabled */
  44. static void dummy_perf(struct pt_regs *regs)
  45. {
  46. unsigned int mmcr0 = mfspr(SPRN_MMCR0);
  47. mmcr0 &= ~MMCR0_PMXE;
  48. mtspr(SPRN_MMCR0, mmcr0);
  49. }
  50. #else
  51. static void dummy_perf(struct pt_regs *regs)
  52. {
  53. }
  54. #endif
  55. void (*perf_irq)(struct pt_regs *) = dummy_perf;
  56. /* Grab the interrupt, if it's free.
  57. * Returns 0 on success, -1 if the interrupt is taken already */
  58. int reserve_pmc_hardware(void (*handler)(struct pt_regs *))
  59. {
  60. int err = 0;
  61. spin_lock(&perfmon_lock);
  62. if (perf_irq == dummy_perf)
  63. perf_irq = handler;
  64. else {
  65. pr_info("perfmon irq already handled by %p\n", perf_irq);
  66. err = -EBUSY;
  67. }
  68. spin_unlock(&perfmon_lock);
  69. return err;
  70. }
  71. void release_pmc_hardware(void)
  72. {
  73. spin_lock(&perfmon_lock);
  74. perf_irq = dummy_perf;
  75. spin_unlock(&perfmon_lock);
  76. }
  77. EXPORT_SYMBOL(perf_irq);
  78. EXPORT_SYMBOL(reserve_pmc_hardware);
  79. EXPORT_SYMBOL(release_pmc_hardware);