hisi_uncore_pmu.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * HiSilicon SoC Hardware event counters support
  3. *
  4. * Copyright (C) 2017 Hisilicon Limited
  5. * Author: Anurup M <anurup.m@huawei.com>
  6. * Shaokun Zhang <zhangshaokun@hisilicon.com>
  7. *
  8. * This code is based on the uncore PMUs like arm-cci and arm-ccn.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #ifndef __HISI_UNCORE_PMU_H__
  15. #define __HISI_UNCORE_PMU_H__
  16. #include <linux/cpumask.h>
  17. #include <linux/device.h>
  18. #include <linux/kernel.h>
  19. #include <linux/perf_event.h>
  20. #include <linux/types.h>
  21. #undef pr_fmt
  22. #define pr_fmt(fmt) "hisi_pmu: " fmt
  23. #define HISI_MAX_COUNTERS 0x10
  24. #define to_hisi_pmu(p) (container_of(p, struct hisi_pmu, pmu))
  25. #define HISI_PMU_ATTR(_name, _func, _config) \
  26. (&((struct dev_ext_attribute[]) { \
  27. { __ATTR(_name, 0444, _func, NULL), (void *)_config } \
  28. })[0].attr.attr)
  29. #define HISI_PMU_FORMAT_ATTR(_name, _config) \
  30. HISI_PMU_ATTR(_name, hisi_format_sysfs_show, (void *)_config)
  31. #define HISI_PMU_EVENT_ATTR(_name, _config) \
  32. HISI_PMU_ATTR(_name, hisi_event_sysfs_show, (unsigned long)_config)
  33. struct hisi_pmu;
  34. struct hisi_uncore_ops {
  35. void (*write_evtype)(struct hisi_pmu *, int, u32);
  36. int (*get_event_idx)(struct perf_event *);
  37. u64 (*read_counter)(struct hisi_pmu *, struct hw_perf_event *);
  38. void (*write_counter)(struct hisi_pmu *, struct hw_perf_event *, u64);
  39. void (*enable_counter)(struct hisi_pmu *, struct hw_perf_event *);
  40. void (*disable_counter)(struct hisi_pmu *, struct hw_perf_event *);
  41. void (*enable_counter_int)(struct hisi_pmu *, struct hw_perf_event *);
  42. void (*disable_counter_int)(struct hisi_pmu *, struct hw_perf_event *);
  43. void (*start_counters)(struct hisi_pmu *);
  44. void (*stop_counters)(struct hisi_pmu *);
  45. };
  46. struct hisi_pmu_hwevents {
  47. struct perf_event *hw_events[HISI_MAX_COUNTERS];
  48. DECLARE_BITMAP(used_mask, HISI_MAX_COUNTERS);
  49. };
  50. /* Generic pmu struct for different pmu types */
  51. struct hisi_pmu {
  52. struct pmu pmu;
  53. const struct hisi_uncore_ops *ops;
  54. struct hisi_pmu_hwevents pmu_events;
  55. /* associated_cpus: All CPUs associated with the PMU */
  56. cpumask_t associated_cpus;
  57. /* CPU used for counting */
  58. int on_cpu;
  59. int irq;
  60. struct device *dev;
  61. struct hlist_node node;
  62. int sccl_id;
  63. int ccl_id;
  64. void __iomem *base;
  65. /* the ID of the PMU modules */
  66. u32 index_id;
  67. int num_counters;
  68. int counter_bits;
  69. /* check event code range */
  70. int check_event;
  71. };
  72. int hisi_uncore_pmu_counter_valid(struct hisi_pmu *hisi_pmu, int idx);
  73. int hisi_uncore_pmu_get_event_idx(struct perf_event *event);
  74. void hisi_uncore_pmu_read(struct perf_event *event);
  75. int hisi_uncore_pmu_add(struct perf_event *event, int flags);
  76. void hisi_uncore_pmu_del(struct perf_event *event, int flags);
  77. void hisi_uncore_pmu_start(struct perf_event *event, int flags);
  78. void hisi_uncore_pmu_stop(struct perf_event *event, int flags);
  79. void hisi_uncore_pmu_set_event_period(struct perf_event *event);
  80. void hisi_uncore_pmu_event_update(struct perf_event *event);
  81. int hisi_uncore_pmu_event_init(struct perf_event *event);
  82. void hisi_uncore_pmu_enable(struct pmu *pmu);
  83. void hisi_uncore_pmu_disable(struct pmu *pmu);
  84. ssize_t hisi_event_sysfs_show(struct device *dev,
  85. struct device_attribute *attr, char *buf);
  86. ssize_t hisi_format_sysfs_show(struct device *dev,
  87. struct device_attribute *attr, char *buf);
  88. ssize_t hisi_cpumask_sysfs_show(struct device *dev,
  89. struct device_attribute *attr, char *buf);
  90. int hisi_uncore_pmu_online_cpu(unsigned int cpu, struct hlist_node *node);
  91. int hisi_uncore_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node);
  92. #endif /* __HISI_UNCORE_PMU_H__ */