pmu.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. * Types of PMUs that can be accessed directly and require mutual
  17. * exclusion between profiling tools.
  18. */
  19. enum arm_pmu_type {
  20. ARM_PMU_DEVICE_CPU = 0,
  21. ARM_PMU_DEVICE_L2CC = 1,
  22. ARM_NUM_PMU_DEVICES,
  23. };
  24. /*
  25. * struct arm_pmu_platdata - ARM PMU platform data
  26. *
  27. * @handle_irq: an optional handler which will be called from the
  28. * interrupt and passed the address of the low level handler,
  29. * and can be used to implement any platform specific handling
  30. * before or after calling it.
  31. * @request_pmu_irq: an optional handler in case the platform wants
  32. * to use a percpu IRQ API call. e.g. request_percpu_irq
  33. * @free_pmu_irq: an optional handler in case the platform wants
  34. * to use a percpu IRQ API call. e.g. free_percpu_irq
  35. * @enable_irq: an optional handler which will be called after
  36. * request_irq and be used to handle some platform specific
  37. * irq enablement
  38. * @disable_irq: an optional handler which will be called before
  39. * free_irq and be used to handle some platform specific
  40. * irq disablement
  41. */
  42. struct arm_pmu_platdata {
  43. irqreturn_t (*handle_irq)(int irq, void *dev,
  44. irq_handler_t pmu_handler);
  45. int (*request_pmu_irq)(int irq, irq_handler_t *irq_h);
  46. void (*free_pmu_irq)(int irq);
  47. void (*enable_irq)(int irq);
  48. void (*disable_irq)(int irq);
  49. };
  50. extern int multicore_request_irq(int irq, irq_handler_t *handle_irq);
  51. extern void multicore_free_irq(int irq);
  52. extern struct arm_pmu_platdata multicore_data;
  53. #ifdef CONFIG_CPU_HAS_PMU
  54. /**
  55. * reserve_pmu() - reserve the hardware performance counters
  56. *
  57. * Reserve the hardware performance counters in the system for exclusive use.
  58. * Returns 0 on success or -EBUSY if the lock is already held.
  59. */
  60. extern int
  61. reserve_pmu(enum arm_pmu_type type);
  62. /**
  63. * release_pmu() - Relinquish control of the performance counters
  64. *
  65. * Release the performance counters and allow someone else to use them.
  66. */
  67. extern void
  68. release_pmu(enum arm_pmu_type type);
  69. #else /* CONFIG_CPU_HAS_PMU */
  70. #include <linux/err.h>
  71. static inline int
  72. reserve_pmu(enum arm_pmu_type type)
  73. {
  74. return -ENODEV;
  75. }
  76. static inline void
  77. release_pmu(enum arm_pmu_type type) { }
  78. #endif /* CONFIG_CPU_HAS_PMU */
  79. #ifdef CONFIG_HW_PERF_EVENTS
  80. /* The events for a given PMU register set. */
  81. struct pmu_hw_events {
  82. /*
  83. * The events that are active on the PMU for the given index.
  84. */
  85. struct perf_event **events;
  86. /*
  87. * A 1 bit for an index indicates that the counter is being used for
  88. * an event. A 0 means that the counter can be used.
  89. */
  90. unsigned long *used_mask;
  91. /*
  92. * Hardware lock to serialize accesses to PMU registers. Needed for the
  93. * read/modify/write sequences.
  94. */
  95. raw_spinlock_t pmu_lock;
  96. };
  97. struct arm_pmu {
  98. struct pmu pmu;
  99. enum arm_perf_pmu_ids id;
  100. enum arm_pmu_type type;
  101. cpumask_t active_irqs;
  102. const char *name;
  103. int num_events;
  104. atomic_t active_events;
  105. struct mutex reserve_mutex;
  106. u64 max_period;
  107. struct platform_device *plat_device;
  108. irqreturn_t (*handle_irq)(int irq_num, void *dev);
  109. int (*request_pmu_irq)(int irq, irq_handler_t *irq_h);
  110. void (*free_pmu_irq)(int irq);
  111. void (*enable)(struct hw_perf_event *evt, int idx, int cpu);
  112. void (*disable)(struct hw_perf_event *evt, int idx);
  113. int (*get_event_idx)(struct pmu_hw_events *hw_events,
  114. struct hw_perf_event *hwc);
  115. int (*set_event_filter)(struct hw_perf_event *evt,
  116. struct perf_event_attr *attr);
  117. u32 (*read_counter)(int idx);
  118. void (*write_counter)(int idx, u32 val);
  119. void (*start)(void);
  120. void (*stop)(void);
  121. void (*reset)(void *);
  122. int (*map_event)(struct perf_event *event);
  123. struct pmu_hw_events *(*get_hw_events)(void);
  124. int (*test_set_event_constraints)(struct perf_event *event);
  125. int (*clear_event_constraints)(struct perf_event *event);
  126. void (*save_pm_registers)(void *hcpu);
  127. void (*restore_pm_registers)(void *hcpu);
  128. };
  129. #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
  130. int armpmu_register(struct arm_pmu *armpmu, char *name, int type);
  131. u64 armpmu_event_update(struct perf_event *event,
  132. struct hw_perf_event *hwc,
  133. int idx);
  134. int armpmu_event_set_period(struct perf_event *event,
  135. struct hw_perf_event *hwc,
  136. int idx);
  137. #endif /* CONFIG_HW_PERF_EVENTS */
  138. #endif /* __ARM_PMU_H__ */