adreno_perfcounter.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2008-2015,2017,2019-2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __ADRENO_PERFCOUNTER_H
  7. #define __ADRENO_PERFCOUNTER_H
  8. struct adreno_device;
  9. /* ADRENO_PERFCOUNTERS - Given an adreno device, return the perfcounters list */
  10. #define ADRENO_PERFCOUNTERS(_a) ((_a)->gpucore->perfcounters)
  11. #define PERFCOUNTER_FLAG_NONE 0x0
  12. #define PERFCOUNTER_FLAG_KERNEL 0x1
  13. #define PERFCOUNTER_REG_DEPENDENCY_LEN 2
  14. /* Structs to maintain the list of active performance counters */
  15. /**
  16. * struct adreno_perfcount_register: register state
  17. * @countable: countable the register holds
  18. * @kernelcount: number of user space users of the register
  19. * @usercount: number of kernel users of the register
  20. * @offset: register hardware offset
  21. * @load_bit: The bit number in LOAD register which corresponds to this counter
  22. * @select: The countable register offset
  23. * @value: The 64 bit countable register value
  24. */
  25. struct adreno_perfcount_register {
  26. unsigned int countable;
  27. unsigned int kernelcount;
  28. unsigned int usercount;
  29. unsigned int offset;
  30. unsigned int offset_hi;
  31. int load_bit;
  32. unsigned int select;
  33. uint64_t value;
  34. /*
  35. * @reg_dependency: Dependent registers that should be programmed along
  36. * with this register.
  37. */
  38. u32 reg_dependency[PERFCOUNTER_REG_DEPENDENCY_LEN];
  39. };
  40. /**
  41. * struct adreno_perfcount_group: registers for a hardware group
  42. * @regs: available registers for this group
  43. * @reg_count: total registers for this group
  44. * @name: group name for this group
  45. */
  46. struct adreno_perfcount_group {
  47. struct adreno_perfcount_register *regs;
  48. unsigned int reg_count;
  49. const char *name;
  50. unsigned long flags;
  51. int (*enable)(struct adreno_device *adreno_dev,
  52. const struct adreno_perfcount_group *group,
  53. unsigned int counter, unsigned int countable);
  54. u64 (*read)(struct adreno_device *adreno_dev,
  55. const struct adreno_perfcount_group *group,
  56. unsigned int counter);
  57. void (*load)(struct adreno_device *adreno_dev,
  58. struct adreno_perfcount_register *reg);
  59. };
  60. /*
  61. * ADRENO_PERFCOUNTER_GROUP_FIXED indicates that a perfcounter group is fixed -
  62. * instead of having configurable countables like the other groups, registers in
  63. * fixed groups have a hardwired countable. So when the user requests a
  64. * countable in one of these groups, that countable should be used as the
  65. * register offset to return
  66. */
  67. #define ADRENO_PERFCOUNTER_GROUP_FIXED BIT(0)
  68. /*
  69. * ADRENO_PERFCOUNTER_GROUP_RESTORE indicates CP needs to restore the select
  70. * registers of this perfcounter group as part of preemption and IFPC
  71. */
  72. #define ADRENO_PERFCOUNTER_GROUP_RESTORE BIT(1)
  73. /**
  74. * adreno_perfcounts: all available perfcounter groups
  75. * @groups: available groups for this device
  76. * @group_count: total groups for this device
  77. */
  78. struct adreno_perfcounters {
  79. const struct adreno_perfcount_group *groups;
  80. unsigned int group_count;
  81. };
  82. #define ADRENO_PERFCOUNTER_GROUP_FLAGS(core, offset, name, flags, \
  83. enable, read, load) \
  84. [KGSL_PERFCOUNTER_GROUP_##offset] = { core##_perfcounters_##name, \
  85. ARRAY_SIZE(core##_perfcounters_##name), __stringify(name), flags, \
  86. enable, read, load }
  87. #define ADRENO_PERFCOUNTER_GROUP(core, offset, name, enable, read, load) \
  88. ADRENO_PERFCOUNTER_GROUP_FLAGS(core, offset, name, 0, enable, read, \
  89. load)
  90. int adreno_perfcounter_query_group(struct adreno_device *adreno_dev,
  91. unsigned int groupid, unsigned int __user *countables,
  92. unsigned int count, unsigned int *max_counters);
  93. int adreno_perfcounter_read_group(struct adreno_device *adreno_dev,
  94. struct kgsl_perfcounter_read_group __user *reads, unsigned int count);
  95. void adreno_perfcounter_restore(struct adreno_device *adreno_dev);
  96. void adreno_perfcounter_save(struct adreno_device *adreno_dev);
  97. void adreno_perfcounter_start(struct adreno_device *adreno_dev);
  98. int adreno_perfcounter_get_groupid(struct adreno_device *adreno_dev,
  99. const char *name);
  100. uint64_t adreno_perfcounter_read(struct adreno_device *adreno_dev,
  101. unsigned int group, unsigned int counter);
  102. const char *adreno_perfcounter_get_name(struct adreno_device
  103. *adreno_dev, unsigned int groupid);
  104. int adreno_perfcounter_get(struct adreno_device *adreno_dev,
  105. unsigned int groupid, unsigned int countable, unsigned int *offset,
  106. unsigned int *offset_hi, unsigned int flags);
  107. int adreno_perfcounter_put(struct adreno_device *adreno_dev,
  108. unsigned int groupid, unsigned int countable, unsigned int flags);
  109. static inline int adreno_perfcounter_kernel_get(
  110. struct adreno_device *adreno_dev,
  111. int group, int countable, u32 *lo, u32 *hi)
  112. {
  113. if (*lo)
  114. return 0;
  115. return adreno_perfcounter_get(adreno_dev, group, countable, lo, hi,
  116. PERFCOUNTER_FLAG_KERNEL);
  117. }
  118. #endif /* __ADRENO_PERFCOUNTER_H */