imc-pmu.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __ASM_POWERPC_IMC_PMU_H
  3. #define __ASM_POWERPC_IMC_PMU_H
  4. /*
  5. * IMC Nest Performance Monitor counter support.
  6. *
  7. * Copyright (C) 2017 Madhavan Srinivasan, IBM Corporation.
  8. * (C) 2017 Anju T Sudhakar, IBM Corporation.
  9. * (C) 2017 Hemant K Shaw, IBM Corporation.
  10. */
  11. #include <linux/perf_event.h>
  12. #include <linux/slab.h>
  13. #include <linux/of.h>
  14. #include <linux/io.h>
  15. #include <asm/opal.h>
  16. /*
  17. * Compatibility macros for IMC devices
  18. */
  19. #define IMC_DTB_COMPAT "ibm,opal-in-memory-counters"
  20. #define IMC_DTB_UNIT_COMPAT "ibm,imc-counters"
  21. /*
  22. * LDBAR: Counter address and Enable/Disable macro.
  23. * perf/imc-pmu.c has the LDBAR layout information.
  24. */
  25. #define THREAD_IMC_LDBAR_MASK 0x0003ffffffffe000ULL
  26. #define THREAD_IMC_ENABLE 0x8000000000000000ULL
  27. #define TRACE_IMC_ENABLE 0x4000000000000000ULL
  28. /*
  29. * For debugfs interface for imc-mode and imc-command
  30. */
  31. #define IMC_CNTL_BLK_OFFSET 0x3FC00
  32. #define IMC_CNTL_BLK_CMD_OFFSET 8
  33. #define IMC_CNTL_BLK_MODE_OFFSET 32
  34. /*
  35. * Structure to hold memory address information for imc units.
  36. */
  37. struct imc_mem_info {
  38. u64 *vbase;
  39. u32 id;
  40. };
  41. /*
  42. * Place holder for nest pmu events and values.
  43. */
  44. struct imc_events {
  45. u32 value;
  46. char *name;
  47. char *unit;
  48. char *scale;
  49. };
  50. /*
  51. * Trace IMC hardware updates a 64bytes record on
  52. * Core Performance Monitoring Counter (CPMC)
  53. * overflow. Here is the layout for the trace imc record
  54. *
  55. * DW 0 : Timebase
  56. * DW 1 : Program Counter
  57. * DW 2 : PIDR information
  58. * DW 3 : CPMC1
  59. * DW 4 : CPMC2
  60. * DW 5 : CPMC3
  61. * Dw 6 : CPMC4
  62. * DW 7 : Timebase
  63. * .....
  64. *
  65. * The following is the data structure to hold trace imc data.
  66. */
  67. struct trace_imc_data {
  68. u64 tb1;
  69. u64 ip;
  70. u64 val;
  71. u64 cpmc1;
  72. u64 cpmc2;
  73. u64 cpmc3;
  74. u64 cpmc4;
  75. u64 tb2;
  76. };
  77. /* Event attribute array index */
  78. #define IMC_FORMAT_ATTR 0
  79. #define IMC_EVENT_ATTR 1
  80. #define IMC_CPUMASK_ATTR 2
  81. #define IMC_NULL_ATTR 3
  82. /* PMU Format attribute macros */
  83. #define IMC_EVENT_OFFSET_MASK 0xffffffffULL
  84. /*
  85. * Macro to mask bits 0:21 of first double word(which is the timebase) to
  86. * compare with 8th double word (timebase) of trace imc record data.
  87. */
  88. #define IMC_TRACE_RECORD_TB1_MASK 0x3ffffffffffULL
  89. /*
  90. * Bit 0:1 in third DW of IMC trace record
  91. * specifies the MSR[HV PR] values.
  92. */
  93. #define IMC_TRACE_RECORD_VAL_HVPR(x) ((x) >> 62)
  94. /*
  95. * Device tree parser code detects IMC pmu support and
  96. * registers new IMC pmus. This structure will hold the
  97. * pmu functions, events, counter memory information
  98. * and attrs for each imc pmu and will be referenced at
  99. * the time of pmu registration.
  100. */
  101. struct imc_pmu {
  102. struct pmu pmu;
  103. struct imc_mem_info *mem_info;
  104. struct imc_events *events;
  105. /*
  106. * Attribute groups for the PMU. Slot 0 used for
  107. * format attribute, slot 1 used for cpusmask attribute,
  108. * slot 2 used for event attribute. Slot 3 keep as
  109. * NULL.
  110. */
  111. const struct attribute_group *attr_groups[4];
  112. u32 counter_mem_size;
  113. int domain;
  114. /*
  115. * flag to notify whether the memory is mmaped
  116. * or allocated by kernel.
  117. */
  118. bool imc_counter_mmaped;
  119. };
  120. /*
  121. * Structure to hold id, lock and reference count for the imc events which
  122. * are inited.
  123. */
  124. struct imc_pmu_ref {
  125. spinlock_t lock;
  126. unsigned int id;
  127. int refc;
  128. };
  129. /*
  130. * In-Memory Collection Counters type.
  131. * Data comes from Device tree.
  132. * Three device type are supported.
  133. */
  134. enum {
  135. IMC_TYPE_THREAD = 0x1,
  136. IMC_TYPE_TRACE = 0x2,
  137. IMC_TYPE_CORE = 0x4,
  138. IMC_TYPE_CHIP = 0x10,
  139. };
  140. /*
  141. * Domains for IMC PMUs
  142. */
  143. #define IMC_DOMAIN_NEST 1
  144. #define IMC_DOMAIN_CORE 2
  145. #define IMC_DOMAIN_THREAD 3
  146. /* For trace-imc the domain is still thread but it operates in trace-mode */
  147. #define IMC_DOMAIN_TRACE 4
  148. extern int init_imc_pmu(struct device_node *parent,
  149. struct imc_pmu *pmu_ptr, int pmu_id);
  150. extern void thread_imc_disable(void);
  151. extern int get_max_nest_dev(void);
  152. extern void unregister_thread_imc(void);
  153. #endif /* __ASM_POWERPC_IMC_PMU_H */