resources.h 8.3 KB

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