resources.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. /* Device region set helper */
  87. #define venus_hfi_for_each_device_region(__device, __sinfo) \
  88. venus_hfi_for_each_thing(__device, __sinfo, device_region)
  89. struct bus_info {
  90. struct icc_path *icc;
  91. const char *name;
  92. u32 min_kbps;
  93. u32 max_kbps;
  94. };
  95. struct bus_set {
  96. struct bus_info *bus_tbl;
  97. u32 count;
  98. };
  99. struct regulator_info {
  100. struct regulator *regulator;
  101. const char *name;
  102. bool hw_power_collapse;
  103. };
  104. struct regulator_set {
  105. struct regulator_info *regulator_tbl;
  106. u32 count;
  107. };
  108. struct power_domain_info {
  109. struct device *genpd_dev;
  110. const char *name;
  111. };
  112. struct power_domain_set {
  113. struct power_domain_info *power_domain_tbl;
  114. u32 count;
  115. };
  116. struct clock_residency {
  117. struct list_head list;
  118. u64 rate;
  119. u64 start_time_us;
  120. u64 total_time_us;
  121. };
  122. struct clock_info {
  123. struct clk *clk;
  124. const char *name;
  125. u32 clk_id;
  126. bool has_scaling;
  127. u64 prev;
  128. #ifdef CONFIG_MSM_MMRM
  129. struct mmrm_client *mmrm_client;
  130. #endif
  131. struct list_head residency_list; /* list of struct clock_residency */
  132. };
  133. struct clock_set {
  134. struct clock_info *clock_tbl;
  135. u32 count;
  136. };
  137. struct reset_info {
  138. struct reset_control *rst;
  139. const char *name;
  140. bool exclusive_release;
  141. };
  142. struct reset_set {
  143. struct reset_info *reset_tbl;
  144. u32 count;
  145. };
  146. struct subcache_info {
  147. struct llcc_slice_desc *subcache;
  148. const char *name;
  149. u32 llcc_id;
  150. bool isactive;
  151. };
  152. struct subcache_set {
  153. struct subcache_info *subcache_tbl;
  154. u32 count;
  155. bool set_to_fw;
  156. };
  157. struct addr_range {
  158. u32 start;
  159. u32 size;
  160. };
  161. struct context_bank_info {
  162. const char *name;
  163. struct addr_range addr_range;
  164. bool secure;
  165. bool dma_coherant;
  166. struct device *dev;
  167. struct iommu_domain *domain;
  168. u32 region;
  169. u64 dma_mask;
  170. };
  171. struct context_bank_set {
  172. struct context_bank_info *context_bank_tbl;
  173. u32 count;
  174. };
  175. struct frequency_table {
  176. unsigned long freq;
  177. };
  178. struct freq_set {
  179. struct frequency_table *freq_tbl;
  180. u32 count;
  181. };
  182. struct device_region_info {
  183. const char *name;
  184. phys_addr_t phy_addr;
  185. u32 size;
  186. u32 dev_addr;
  187. u32 region;
  188. };
  189. struct device_region_set {
  190. struct device_region_info *device_region_tbl;
  191. u32 count;
  192. };
  193. struct msm_vidc_resource {
  194. void *core;
  195. u8 __iomem *register_base_addr;
  196. u32 irq;
  197. struct bus_set bus_set;
  198. struct regulator_set regulator_set;
  199. struct power_domain_set power_domain_set;
  200. struct clock_set clock_set;
  201. struct reset_set reset_set;
  202. struct subcache_set subcache_set;
  203. struct context_bank_set context_bank_set;
  204. struct freq_set freq_set;
  205. struct device_region_set device_region_set;
  206. int fw_cookie;
  207. };
  208. #define call_res_op(c, op, ...) \
  209. (((c) && (c)->res_ops && (c)->res_ops->op) ? \
  210. ((c)->res_ops->op(__VA_ARGS__)) : 0)
  211. struct msm_vidc_resources_ops {
  212. int (*init)(struct msm_vidc_core *core);
  213. int (*reset_bridge)(struct msm_vidc_core *core);
  214. int (*reset_control_acquire)(struct msm_vidc_core *core,
  215. const char *name);
  216. int (*reset_control_release)(struct msm_vidc_core *core,
  217. const char *name);
  218. int (*reset_control_assert)(struct msm_vidc_core *core,
  219. const char *name);
  220. int (*reset_control_deassert)(struct msm_vidc_core *core,
  221. const char *name);
  222. int (*gdsc_init)(struct msm_vidc_core *core);
  223. int (*gdsc_on)(struct msm_vidc_core *core, const char *name);
  224. int (*gdsc_off)(struct msm_vidc_core *core, const char *name);
  225. int (*gdsc_hw_ctrl)(struct msm_vidc_core *core);
  226. int (*gdsc_sw_ctrl)(struct msm_vidc_core *core);
  227. int (*llcc)(struct msm_vidc_core *core, bool enable);
  228. int (*set_bw)(struct msm_vidc_core *core, unsigned long bw_ddr,
  229. unsigned long bw_llcc);
  230. int (*set_clks)(struct msm_vidc_core *core, u64 rate);
  231. int (*clk_disable)(struct msm_vidc_core *core, const char *name);
  232. int (*clk_enable)(struct msm_vidc_core *core, const char *name);
  233. int (*clk_set_flag)(struct msm_vidc_core *core,
  234. const char *name, enum branch_mem_flags flag);
  235. int (*clk_print_residency_stats)(struct msm_vidc_core *core);
  236. int (*clk_reset_residency_stats)(struct msm_vidc_core *core);
  237. };
  238. const struct msm_vidc_resources_ops *get_resources_ops(void);
  239. #endif