riscv_pmu.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2018 SiFive
  4. * Copyright (C) 2018 Andes Technology Corporation
  5. * Copyright (C) 2021 Western Digital Corporation or its affiliates.
  6. *
  7. */
  8. #ifndef _ASM_RISCV_PERF_EVENT_H
  9. #define _ASM_RISCV_PERF_EVENT_H
  10. #include <linux/perf_event.h>
  11. #include <linux/ptrace.h>
  12. #include <linux/interrupt.h>
  13. #ifdef CONFIG_RISCV_PMU
  14. /*
  15. * The RISCV_MAX_COUNTERS parameter should be specified.
  16. */
  17. #define RISCV_MAX_COUNTERS 64
  18. #define RISCV_OP_UNSUPP (-EOPNOTSUPP)
  19. #define RISCV_PMU_PDEV_NAME "riscv-pmu"
  20. #define RISCV_PMU_LEGACY_PDEV_NAME "riscv-pmu-legacy"
  21. #define RISCV_PMU_STOP_FLAG_RESET 1
  22. struct cpu_hw_events {
  23. /* currently enabled events */
  24. int n_events;
  25. /* Counter overflow interrupt */
  26. int irq;
  27. /* currently enabled events */
  28. struct perf_event *events[RISCV_MAX_COUNTERS];
  29. /* currently enabled hardware counters */
  30. DECLARE_BITMAP(used_hw_ctrs, RISCV_MAX_COUNTERS);
  31. /* currently enabled firmware counters */
  32. DECLARE_BITMAP(used_fw_ctrs, RISCV_MAX_COUNTERS);
  33. };
  34. struct riscv_pmu {
  35. struct pmu pmu;
  36. char *name;
  37. irqreturn_t (*handle_irq)(int irq_num, void *dev);
  38. unsigned long cmask;
  39. u64 (*ctr_read)(struct perf_event *event);
  40. int (*ctr_get_idx)(struct perf_event *event);
  41. int (*ctr_get_width)(int idx);
  42. void (*ctr_clear_idx)(struct perf_event *event);
  43. void (*ctr_start)(struct perf_event *event, u64 init_val);
  44. void (*ctr_stop)(struct perf_event *event, unsigned long flag);
  45. int (*event_map)(struct perf_event *event, u64 *config);
  46. struct cpu_hw_events __percpu *hw_events;
  47. struct hlist_node node;
  48. struct notifier_block riscv_pm_nb;
  49. };
  50. #define to_riscv_pmu(p) (container_of(p, struct riscv_pmu, pmu))
  51. void riscv_pmu_start(struct perf_event *event, int flags);
  52. void riscv_pmu_stop(struct perf_event *event, int flags);
  53. unsigned long riscv_pmu_ctr_read_csr(unsigned long csr);
  54. int riscv_pmu_event_set_period(struct perf_event *event);
  55. uint64_t riscv_pmu_ctr_get_width_mask(struct perf_event *event);
  56. u64 riscv_pmu_event_update(struct perf_event *event);
  57. #ifdef CONFIG_RISCV_PMU_LEGACY
  58. void riscv_pmu_legacy_skip_init(void);
  59. #else
  60. static inline void riscv_pmu_legacy_skip_init(void) {};
  61. #endif
  62. struct riscv_pmu *riscv_pmu_alloc(void);
  63. #endif /* CONFIG_RISCV_PMU */
  64. #endif /* _ASM_RISCV_PERF_EVENT_H */