arm_pmu.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #include <linux/sysfs.h>
  16. #include <asm/cputype.h>
  17. /*
  18. * struct arm_pmu_platdata - ARM PMU platform data
  19. *
  20. * @handle_irq: an optional handler which will be called from the
  21. * interrupt and passed the address of the low level handler,
  22. * and can be used to implement any platform specific handling
  23. * before or after calling it.
  24. */
  25. struct arm_pmu_platdata {
  26. irqreturn_t (*handle_irq)(int irq, void *dev,
  27. irq_handler_t pmu_handler);
  28. };
  29. #ifdef CONFIG_ARM_PMU
  30. /*
  31. * The ARMv7 CPU PMU supports up to 32 event counters.
  32. */
  33. #define ARMPMU_MAX_HWEVENTS 32
  34. #define HW_OP_UNSUPPORTED 0xFFFF
  35. #define C(_x) PERF_COUNT_HW_CACHE_##_x
  36. #define CACHE_OP_UNSUPPORTED 0xFFFF
  37. #define PERF_MAP_ALL_UNSUPPORTED \
  38. [0 ... PERF_COUNT_HW_MAX - 1] = HW_OP_UNSUPPORTED
  39. #define PERF_CACHE_MAP_ALL_UNSUPPORTED \
  40. [0 ... C(MAX) - 1] = { \
  41. [0 ... C(OP_MAX) - 1] = { \
  42. [0 ... C(RESULT_MAX) - 1] = CACHE_OP_UNSUPPORTED, \
  43. }, \
  44. }
  45. /* The events for a given PMU register set. */
  46. struct pmu_hw_events {
  47. /*
  48. * The events that are active on the PMU for the given index.
  49. */
  50. struct perf_event *events[ARMPMU_MAX_HWEVENTS];
  51. /*
  52. * A 1 bit for an index indicates that the counter is being used for
  53. * an event. A 0 means that the counter can be used.
  54. */
  55. DECLARE_BITMAP(used_mask, ARMPMU_MAX_HWEVENTS);
  56. /*
  57. * Hardware lock to serialize accesses to PMU registers. Needed for the
  58. * read/modify/write sequences.
  59. */
  60. raw_spinlock_t pmu_lock;
  61. /*
  62. * When using percpu IRQs, we need a percpu dev_id. Place it here as we
  63. * already have to allocate this struct per cpu.
  64. */
  65. struct arm_pmu *percpu_pmu;
  66. };
  67. enum armpmu_attr_groups {
  68. ARMPMU_ATTR_GROUP_COMMON,
  69. ARMPMU_ATTR_GROUP_EVENTS,
  70. ARMPMU_ATTR_GROUP_FORMATS,
  71. ARMPMU_NR_ATTR_GROUPS
  72. };
  73. struct arm_pmu {
  74. struct pmu pmu;
  75. cpumask_t active_irqs;
  76. cpumask_t supported_cpus;
  77. int *irq_affinity;
  78. char *name;
  79. irqreturn_t (*handle_irq)(int irq_num, void *dev);
  80. void (*enable)(struct perf_event *event);
  81. void (*disable)(struct perf_event *event);
  82. int (*get_event_idx)(struct pmu_hw_events *hw_events,
  83. struct perf_event *event);
  84. void (*clear_event_idx)(struct pmu_hw_events *hw_events,
  85. struct perf_event *event);
  86. int (*set_event_filter)(struct hw_perf_event *evt,
  87. struct perf_event_attr *attr);
  88. u32 (*read_counter)(struct perf_event *event);
  89. void (*write_counter)(struct perf_event *event, u32 val);
  90. void (*start)(struct arm_pmu *);
  91. void (*stop)(struct arm_pmu *);
  92. void (*reset)(void *);
  93. int (*request_irq)(struct arm_pmu *, irq_handler_t handler);
  94. void (*free_irq)(struct arm_pmu *);
  95. int (*map_event)(struct perf_event *event);
  96. int num_events;
  97. atomic_t active_events;
  98. struct mutex reserve_mutex;
  99. u64 max_period;
  100. bool secure_access; /* 32-bit ARM only */
  101. #define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40
  102. DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS);
  103. struct platform_device *plat_device;
  104. struct pmu_hw_events __percpu *hw_events;
  105. struct hlist_node node;
  106. struct notifier_block cpu_pm_nb;
  107. /* the attr_groups array must be NULL-terminated */
  108. const struct attribute_group *attr_groups[ARMPMU_NR_ATTR_GROUPS + 1];
  109. };
  110. #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu))
  111. u64 armpmu_event_update(struct perf_event *event);
  112. int armpmu_event_set_period(struct perf_event *event);
  113. int armpmu_map_event(struct perf_event *event,
  114. const unsigned (*event_map)[PERF_COUNT_HW_MAX],
  115. const unsigned (*cache_map)[PERF_COUNT_HW_CACHE_MAX]
  116. [PERF_COUNT_HW_CACHE_OP_MAX]
  117. [PERF_COUNT_HW_CACHE_RESULT_MAX],
  118. u32 raw_event_mask);
  119. struct pmu_probe_info {
  120. unsigned int cpuid;
  121. unsigned int mask;
  122. int (*init)(struct arm_pmu *);
  123. };
  124. #define PMU_PROBE(_cpuid, _mask, _fn) \
  125. { \
  126. .cpuid = (_cpuid), \
  127. .mask = (_mask), \
  128. .init = (_fn), \
  129. }
  130. #define ARM_PMU_PROBE(_cpuid, _fn) \
  131. PMU_PROBE(_cpuid, ARM_CPU_PART_MASK, _fn)
  132. #define ARM_PMU_XSCALE_MASK ((0xff << 24) | ARM_CPU_XSCALE_ARCH_MASK)
  133. #define XSCALE_PMU_PROBE(_version, _fn) \
  134. PMU_PROBE(ARM_CPU_IMP_INTEL << 24 | _version, ARM_PMU_XSCALE_MASK, _fn)
  135. int arm_pmu_device_probe(struct platform_device *pdev,
  136. const struct of_device_id *of_table,
  137. const struct pmu_probe_info *probe_table);
  138. #define ARMV8_PMU_PDEV_NAME "armv8-pmu"
  139. #endif /* CONFIG_ARM_PMU */
  140. #endif /* __ARM_PMU_H__ */