resources.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2022, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _MSM_VIDC_RESOURCES_H_
  6. #define _MSM_VIDC_RESOURCES_H_
  7. #include <linux/clk/qcom.h>
  8. struct icc_path;
  9. struct regulator;
  10. struct clk;
  11. struct reset_control;
  12. struct llcc_slice_desc;
  13. struct iommu_domain;
  14. struct device;
  15. struct msm_vidc_core;
  16. /*
  17. * These are helper macros to iterate over various lists within
  18. * msm_vidc_core->resource. The intention is to cut down on a lot of boiler-plate
  19. * code
  20. */
  21. /* Read as "for each 'thing' in a set of 'thingies'" */
  22. #define venus_hfi_for_each_thing(__device, __thing, __thingy) \
  23. venus_hfi_for_each_thing_continue(__device, __thing, __thingy, 0)
  24. #define venus_hfi_for_each_thing_reverse(__device, __thing, __thingy) \
  25. venus_hfi_for_each_thing_reverse_continue(__device, __thing, __thingy, \
  26. (__device)->resource->__thingy##_set.count - 1)
  27. /* TODO: the __from parameter technically not required since we can figure it
  28. * out with some pointer magic (i.e. __thing - __thing##_tbl[0]). If this macro
  29. * sees extensive use, probably worth cleaning it up but for now omitting it
  30. * since it introduces unnecessary complexity.
  31. */
  32. #define venus_hfi_for_each_thing_continue(__device, __thing, __thingy, __from) \
  33. for (__thing = &(__device)->resource->\
  34. __thingy##_set.__thingy##_tbl[__from]; \
  35. __thing < &(__device)->resource->__thingy##_set.__thingy##_tbl[0] + \
  36. ((__device)->resource->__thingy##_set.count - __from); \
  37. ++__thing)
  38. #define venus_hfi_for_each_thing_reverse_continue(__device, __thing, __thingy, \
  39. __from) \
  40. for (__thing = &(__device)->resource->\
  41. __thingy##_set.__thingy##_tbl[__from]; \
  42. __thing >= &(__device)->resource->__thingy##_set.__thingy##_tbl[0]; \
  43. --__thing)
  44. /* Bus set helpers */
  45. #define venus_hfi_for_each_bus(__device, __binfo) \
  46. venus_hfi_for_each_thing(__device, __binfo, bus)
  47. #define venus_hfi_for_each_bus_reverse(__device, __binfo) \
  48. venus_hfi_for_each_thing_reverse(__device, __binfo, bus)
  49. /* Regular set helpers */
  50. #define venus_hfi_for_each_regulator(__device, __rinfo) \
  51. venus_hfi_for_each_thing(__device, __rinfo, regulator)
  52. #define venus_hfi_for_each_regulator_reverse(__device, __rinfo) \
  53. venus_hfi_for_each_thing_reverse(__device, __rinfo, regulator)
  54. #define venus_hfi_for_each_regulator_reverse_continue(__device, __rinfo, \
  55. __from) \
  56. venus_hfi_for_each_thing_reverse_continue(__device, __rinfo, \
  57. regulator, __from)
  58. /* Clock set helpers */
  59. #define venus_hfi_for_each_clock(__device, __cinfo) \
  60. venus_hfi_for_each_thing(__device, __cinfo, clock)
  61. #define venus_hfi_for_each_clock_reverse(__device, __cinfo) \
  62. venus_hfi_for_each_thing_reverse(__device, __cinfo, clock)
  63. /* Reset clock set helpers */
  64. #define venus_hfi_for_each_reset_clock(__device, __rcinfo) \
  65. venus_hfi_for_each_thing(__device, __rcinfo, reset)
  66. #define venus_hfi_for_each_reset_clock_reverse(__device, __rcinfo) \
  67. venus_hfi_for_each_thing_reverse(__device, __rcinfo, reset)
  68. #define venus_hfi_for_each_reset_clock_reverse_continue(__device, __rinfo, \
  69. __from) \
  70. venus_hfi_for_each_thing_reverse_continue(__device, __rinfo, \
  71. reset, __from)
  72. /* Subcache set helpers */
  73. #define venus_hfi_for_each_subcache(__device, __sinfo) \
  74. venus_hfi_for_each_thing(__device, __sinfo, subcache)
  75. #define venus_hfi_for_each_subcache_reverse(__device, __sinfo) \
  76. venus_hfi_for_each_thing_reverse(__device, __sinfo, subcache)
  77. /* Contextbank set helpers */
  78. #define venus_hfi_for_each_context_bank(__device, __sinfo) \
  79. venus_hfi_for_each_thing(__device, __sinfo, context_bank)
  80. #define venus_hfi_for_each_context_bank_reverse(__device, __sinfo) \
  81. venus_hfi_for_each_thing_reverse(__device, __sinfo, context_bank)
  82. struct bus_info {
  83. struct icc_path *icc;
  84. const char *name;
  85. u32 min_kbps;
  86. u32 max_kbps;
  87. };
  88. struct bus_set {
  89. struct bus_info *bus_tbl;
  90. u32 count;
  91. };
  92. struct regulator_info {
  93. struct regulator *regulator;
  94. const char *name;
  95. bool hw_power_collapse;
  96. };
  97. struct regulator_set {
  98. struct regulator_info *regulator_tbl;
  99. u32 count;
  100. };
  101. struct clock_residency {
  102. struct list_head list;
  103. u64 rate;
  104. u64 start_time_us;
  105. u64 total_time_us;
  106. };
  107. struct clock_info {
  108. struct clk *clk;
  109. const char *name;
  110. u32 clk_id;
  111. bool has_scaling;
  112. u64 prev;
  113. #ifdef CONFIG_MSM_MMRM
  114. struct mmrm_client *mmrm_client;
  115. #endif
  116. struct list_head residency_list; /* list of struct clock_residency */
  117. };
  118. struct clock_set {
  119. struct clock_info *clock_tbl;
  120. u32 count;
  121. };
  122. struct reset_info {
  123. struct reset_control *rst;
  124. const char *name;
  125. };
  126. struct reset_set {
  127. struct reset_info *reset_tbl;
  128. u32 count;
  129. };
  130. struct subcache_info {
  131. struct llcc_slice_desc *subcache;
  132. const char *name;
  133. u32 llcc_id;
  134. bool isactive;
  135. };
  136. struct subcache_set {
  137. struct subcache_info *subcache_tbl;
  138. u32 count;
  139. bool set_to_fw;
  140. };
  141. struct addr_range {
  142. u32 start;
  143. u32 size;
  144. };
  145. struct context_bank_info {
  146. const char *name;
  147. struct addr_range addr_range;
  148. bool secure;
  149. bool dma_coherant;
  150. struct device *dev;
  151. struct iommu_domain *domain;
  152. u32 region;
  153. u64 dma_mask;
  154. };
  155. struct context_bank_set {
  156. struct context_bank_info *context_bank_tbl;
  157. u32 count;
  158. };
  159. struct frequency_table {
  160. unsigned long freq;
  161. };
  162. struct freq_set {
  163. struct frequency_table *freq_tbl;
  164. u32 count;
  165. };
  166. struct msm_vidc_resource {
  167. void *core;
  168. u8 __iomem *register_base_addr;
  169. u32 irq;
  170. struct bus_set bus_set;
  171. struct regulator_set regulator_set;
  172. struct clock_set clock_set;
  173. struct reset_set reset_set;
  174. struct subcache_set subcache_set;
  175. struct context_bank_set context_bank_set;
  176. struct freq_set freq_set;
  177. int fw_cookie;
  178. };
  179. #define call_res_op(c, op, ...) \
  180. (((c) && (c)->res_ops && (c)->res_ops->op) ? \
  181. ((c)->res_ops->op(__VA_ARGS__)) : 0)
  182. struct msm_vidc_resources_ops {
  183. int (*init)(struct msm_vidc_core *core);
  184. int (*reset_bridge)(struct msm_vidc_core *core);
  185. int (*reset_control_assert)(struct msm_vidc_core *core,
  186. const char *name);
  187. int (*reset_control_deassert)(struct msm_vidc_core *core,
  188. const char *name);
  189. int (*gdsc_on)(struct msm_vidc_core *core, const char *name);
  190. int (*gdsc_off)(struct msm_vidc_core *core, const char *name);
  191. int (*gdsc_hw_ctrl)(struct msm_vidc_core *core);
  192. int (*gdsc_sw_ctrl)(struct msm_vidc_core *core);
  193. int (*llcc)(struct msm_vidc_core *core, bool enable);
  194. int (*set_bw)(struct msm_vidc_core *core, unsigned long bw_ddr,
  195. unsigned long bw_llcc);
  196. int (*set_clks)(struct msm_vidc_core *core, u64 rate);
  197. int (*clk_disable)(struct msm_vidc_core *core, const char *name);
  198. int (*clk_enable)(struct msm_vidc_core *core, const char *name);
  199. int (*clk_set_flag)(struct msm_vidc_core *core,
  200. const char *name, enum branch_mem_flags flag);
  201. int (*clk_print_residency_stats)(struct msm_vidc_core *core);
  202. int (*clk_reset_residency_stats)(struct msm_vidc_core *core);
  203. };
  204. const struct msm_vidc_resources_ops *get_resources_ops(void);
  205. #endif