pmu.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * linux/arch/arm/include/asm/pmu.h
  3. *
  4. * Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #ifndef __ARM_PMU_H__
  12. #define __ARM_PMU_H__
  13. #include <linux/interrupt.h>
  14. #include <linux/perf_event.h>
  15. /*
  16. * struct arm_pmu_platdata - ARM PMU platform data
  17. *
  18. * @handle_irq: an optional handler which will be called from the
  19. * interrupt and passed the address of the low level handler,
  20. * and can be used to implement any platform specific handling
  21. * before or after calling it.
  22. * @runtime_resume: an optional handler which will be called by the
  23. * runtime PM framework following a call to pm_runtime_get().
  24. * Note that if pm_runtime_get() is called more than once in
  25. * succession this handler will only be called once.
  26. * @runtime_suspend: an optional handler which will be called by the
  27. * runtime PM framework following a call to pm_runtime_put().
  28. * Note that if pm_runtime_get() is called more than once in
  29. * succession this handler will only be called following the
  30. * final call to pm_runtime_put() that actually disables the
  31. * hardware.
  32. */
  33. struct arm_pmu_platdata {
  34. irqreturn_t (*handle_irq)(int irq, void *dev,
  35. irq_handler_t pmu_handler);
  36. int (*runtime_resume)(struct device *dev);
  37. int (*runtime_suspend)(struct device *dev);
  38. };
  39. #ifdef CONFIG_HW_PERF_EVENTS
  40. /*
  41. * The ARMv7 CPU PMU supports up to 32 event counters.
  42. */
  43. #define ARMPMU_MAX_HWEVENTS 32
  44. #define HW_OP_UNSUPPORTED 0xFFFF
  45. #define C(_x) PERF_COUNT_HW_CACHE_##_x
  46. #define CACHE_OP_UNSUPPORTED 0xFFFF
  47. #define PERF_MAP_ALL_UNSUPPORTED \
  48. [0 ... PERF_COUNT_HW_MAX - 1] = HW_OP_UNSUPPORTED
  49. #define PERF_CACHE_MAP_ALL_UNSUPPORTED \
  50. [0 ... C(MAX) - 1] = { \
  51. [0 ... C(OP_MAX) - 1] = { \
  52. [0 ... C(RESULT_MAX) - 1] = CACHE_OP_UNSUPPORTED, \
  53. }, \
  54. }
  55. /* The events for a given PMU register set. */
  56. struct pmu_hw_events {
  57. /*
  58. * The events that are active on the PMU for the given index.
  59. */
  60. struct perf_event **events;
  61. /*
  62. * A 1 bit for an index indicates that the counter is being used for
  63. * an event. A 0 means that the counter can be used.
  64. */
  65. unsigned long *used_mask;
  66. /*
  67. * Hardware lock to serialize accesses to PMU registers. Needed for the
  68. * read/modify/write sequences.
  69. */
  70. raw_spinlock_t pmu_lock;
  71. };
  72. struct arm_pmu {
  73. struct pmu pmu;
  74. cpumask_t active_irqs;
  75. char *name;
  76. irqreturn_t (*handle_irq)(int irq_num, void *dev);
  77. void (*enable)(struct perf_event *event);
  78. void (*disable)(struct perf_event *event);
  79. int (*get_event_idx)(struct pmu_hw_events *hw_events,
  80. struct perf_event *event);
  81. void (*clear_event_idx)(struct pmu_hw_events *hw_events,
  82. struct perf_event *event);
  83. int (*set_event_filter)(struct hw_perf_event *evt,
  84. struct perf_event_attr *attr);
  85. u32 (*read_counter)(struct perf_event *event);
  86. void (*write_counter)(struct perf_event *event, u32 val);
  87. void (*start)(struct arm_pmu *);
  88. void (*stop)(struct arm_pmu *);
  89. void (*reset)(void *);
  90. int (*request_irq)(struct arm_pmu *, irq_handler_t handler);
  91. void (*free_irq)(struct arm_pmu *);
  92. int (*map_event)(struct perf_event *event);
  93. int num_events;
  94. atomic_t active_events;
  95. struct mutex reserve_mutex;
  96. u64 max_period;
  97. struct platform_device *plat_device;
  98. struct pmu_hw_events *(*get_hw_events)(void);
  99. };
  100. #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
  101. extern const struct dev_pm_ops armpmu_dev_pm_ops;
  102. int armpmu_register(struct arm_pmu *armpmu, int type);
  103. u64 armpmu_event_update(struct perf_event *event);
  104. int armpmu_event_set_period(struct perf_event *event);
  105. int armpmu_map_event(struct perf_event *event,
  106. const unsigned (*event_map)[PERF_COUNT_HW_MAX],
  107. const unsigned (*cache_map)[PERF_COUNT_HW_CACHE_MAX]
  108. [PERF_COUNT_HW_CACHE_OP_MAX]
  109. [PERF_COUNT_HW_CACHE_RESULT_MAX],
  110. u32 raw_event_mask);
  111. #endif /* CONFIG_HW_PERF_EVENTS */
  112. #endif /* __ARM_PMU_H__ */