pcr.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* pcr.c: Generic sparc64 performance counter infrastructure.
  2. *
  3. * Copyright (C) 2009 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/init.h>
  8. #include <linux/irq.h>
  9. #include <asm/pil.h>
  10. #include <asm/pcr.h>
  11. #include <asm/nmi.h>
  12. /* This code is shared between various users of the performance
  13. * counters. Users will be oprofile, pseudo-NMI watchdog, and the
  14. * perf_counter support layer.
  15. */
  16. #define PCR_SUN4U_ENABLE (PCR_PIC_PRIV | PCR_STRACE | PCR_UTRACE)
  17. #define PCR_N2_ENABLE (PCR_PIC_PRIV | PCR_STRACE | PCR_UTRACE | \
  18. PCR_N2_TOE_OV1 | \
  19. (2 << PCR_N2_SL1_SHIFT) | \
  20. (0xff << PCR_N2_MASK1_SHIFT))
  21. u64 pcr_enable;
  22. unsigned int picl_shift;
  23. /* Performance counter interrupts run unmasked at PIL level 15.
  24. * Therefore we can't do things like wakeups and other work
  25. * that expects IRQ disabling to be adhered to in locking etc.
  26. *
  27. * Therefore in such situations we defer the work by signalling
  28. * a lower level cpu IRQ.
  29. */
  30. void deferred_pcr_work_irq(int irq, struct pt_regs *regs)
  31. {
  32. clear_softint(1 << PIL_DEFERRED_PCR_WORK);
  33. }
  34. void schedule_deferred_pcr_work(void)
  35. {
  36. set_softint(1 << PIL_DEFERRED_PCR_WORK);
  37. }
  38. const struct pcr_ops *pcr_ops;
  39. EXPORT_SYMBOL_GPL(pcr_ops);
  40. static u64 direct_pcr_read(void)
  41. {
  42. u64 val;
  43. read_pcr(val);
  44. return val;
  45. }
  46. static void direct_pcr_write(u64 val)
  47. {
  48. write_pcr(val);
  49. }
  50. static const struct pcr_ops direct_pcr_ops = {
  51. .read = direct_pcr_read,
  52. .write = direct_pcr_write,
  53. };
  54. static void n2_pcr_write(u64 val)
  55. {
  56. unsigned long ret;
  57. ret = sun4v_niagara2_setperf(HV_N2_PERF_SPARC_CTL, val);
  58. if (val != HV_EOK)
  59. write_pcr(val);
  60. }
  61. static const struct pcr_ops n2_pcr_ops = {
  62. .read = direct_pcr_read,
  63. .write = n2_pcr_write,
  64. };
  65. static unsigned long perf_hsvc_group;
  66. static unsigned long perf_hsvc_major;
  67. static unsigned long perf_hsvc_minor;
  68. static int __init register_perf_hsvc(void)
  69. {
  70. if (tlb_type == hypervisor) {
  71. switch (sun4v_chip_type) {
  72. case SUN4V_CHIP_NIAGARA1:
  73. perf_hsvc_group = HV_GRP_NIAG_PERF;
  74. break;
  75. case SUN4V_CHIP_NIAGARA2:
  76. perf_hsvc_group = HV_GRP_N2_CPU;
  77. break;
  78. default:
  79. return -ENODEV;
  80. }
  81. perf_hsvc_major = 1;
  82. perf_hsvc_minor = 0;
  83. if (sun4v_hvapi_register(perf_hsvc_group,
  84. perf_hsvc_major,
  85. &perf_hsvc_minor)) {
  86. printk("perfmon: Could not register hvapi.\n");
  87. return -ENODEV;
  88. }
  89. }
  90. return 0;
  91. }
  92. static void __init unregister_perf_hsvc(void)
  93. {
  94. if (tlb_type != hypervisor)
  95. return;
  96. sun4v_hvapi_unregister(perf_hsvc_group);
  97. }
  98. int __init pcr_arch_init(void)
  99. {
  100. int err = register_perf_hsvc();
  101. if (err)
  102. return err;
  103. switch (tlb_type) {
  104. case hypervisor:
  105. pcr_ops = &n2_pcr_ops;
  106. pcr_enable = PCR_N2_ENABLE;
  107. picl_shift = 2;
  108. break;
  109. case cheetah:
  110. case cheetah_plus:
  111. pcr_ops = &direct_pcr_ops;
  112. pcr_enable = PCR_SUN4U_ENABLE;
  113. break;
  114. case spitfire:
  115. /* UltraSPARC-I/II and derivatives lack a profile
  116. * counter overflow interrupt so we can't make use of
  117. * their hardware currently.
  118. */
  119. /* fallthrough */
  120. default:
  121. err = -ENODEV;
  122. goto out_unregister;
  123. }
  124. return nmi_init();
  125. out_unregister:
  126. unregister_perf_hsvc();
  127. return err;
  128. }
  129. arch_initcall(pcr_arch_init);