perfmon.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #else
  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. #endif
  51. void (*perf_irq)(struct pt_regs *) = dummy_perf;
  52. /* Grab the interrupt, if it's free.
  53. * Returns 0 on success, -1 if the interrupt is taken already */
  54. int request_perfmon_irq(void (*handler)(struct pt_regs *))
  55. {
  56. int err = 0;
  57. spin_lock(&perfmon_lock);
  58. if (perf_irq == dummy_perf)
  59. perf_irq = handler;
  60. else {
  61. pr_info("perfmon irq already handled by %p\n", perf_irq);
  62. err = -1;
  63. }
  64. spin_unlock(&perfmon_lock);
  65. return err;
  66. }
  67. void free_perfmon_irq(void)
  68. {
  69. spin_lock(&perfmon_lock);
  70. perf_irq = dummy_perf;
  71. spin_unlock(&perfmon_lock);
  72. }
  73. EXPORT_SYMBOL(perf_irq);
  74. EXPORT_SYMBOL(request_perfmon_irq);
  75. EXPORT_SYMBOL(free_perfmon_irq);