resources.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. /* Clock set helpers */
  60. #define venus_hfi_for_each_clock(__device, __cinfo) \
  61. venus_hfi_for_each_thing(__device, __cinfo, clock)
  62. #define venus_hfi_for_each_clock_reverse(__device, __cinfo) \
  63. venus_hfi_for_each_thing_reverse(__device, __cinfo, clock)
  64. /* Reset clock set helpers */
  65. #define venus_hfi_for_each_reset_clock(__device, __rcinfo) \
  66. venus_hfi_for_each_thing(__device, __rcinfo, reset)
  67. #define venus_hfi_for_each_reset_clock_reverse(__device, __rcinfo) \
  68. venus_hfi_for_each_thing_reverse(__device, __rcinfo, reset)
  69. #define venus_hfi_for_each_reset_clock_reverse_continue(__device, __rinfo, \
  70. __from) \
  71. venus_hfi_for_each_thing_reverse_continue(__device, __rinfo, \
  72. reset, __from)
  73. /* Subcache set helpers */
  74. #define venus_hfi_for_each_subcache(__device, __sinfo) \
  75. venus_hfi_for_each_thing(__device, __sinfo, subcache)
  76. #define venus_hfi_for_each_subcache_reverse(__device, __sinfo) \
  77. venus_hfi_for_each_thing_reverse(__device, __sinfo, subcache)
  78. /* Contextbank set helpers */
  79. #define venus_hfi_for_each_context_bank(__device, __sinfo) \
  80. venus_hfi_for_each_thing(__device, __sinfo, context_bank)
  81. #define venus_hfi_for_each_context_bank_reverse(__device, __sinfo) \
  82. venus_hfi_for_each_thing_reverse(__device, __sinfo, context_bank)
  83. /* Device region set helper */
  84. #define venus_hfi_for_each_device_region(__device, __sinfo) \
  85. venus_hfi_for_each_thing(__device, __sinfo, device_region)
  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 clock_residency {
  106. struct list_head list;
  107. u64 rate;
  108. u64 start_time_us;
  109. u64 total_time_us;
  110. };
  111. struct clock_info {
  112. struct clk *clk;
  113. const char *name;
  114. u32 clk_id;
  115. bool has_scaling;
  116. u64 prev;
  117. #ifdef CONFIG_MSM_MMRM
  118. struct mmrm_client *mmrm_client;
  119. #endif
  120. struct list_head residency_list; /* list of struct clock_residency */
  121. };
  122. struct clock_set {
  123. struct clock_info *clock_tbl;
  124. u32 count;
  125. };
  126. struct reset_info {
  127. struct reset_control *rst;
  128. const char *name;
  129. bool exclusive_release;
  130. };
  131. struct reset_set {
  132. struct reset_info *reset_tbl;
  133. u32 count;
  134. };
  135. struct subcache_info {
  136. struct llcc_slice_desc *subcache;
  137. const char *name;
  138. u32 llcc_id;
  139. bool isactive;
  140. };
  141. struct subcache_set {
  142. struct subcache_info *subcache_tbl;
  143. u32 count;
  144. bool set_to_fw;
  145. };
  146. struct addr_range {
  147. u32 start;
  148. u32 size;
  149. };
  150. struct context_bank_info {
  151. const char *name;
  152. struct addr_range addr_range;
  153. bool secure;
  154. bool dma_coherant;
  155. struct device *dev;
  156. struct iommu_domain *domain;
  157. u32 region;
  158. u64 dma_mask;
  159. };
  160. struct context_bank_set {
  161. struct context_bank_info *context_bank_tbl;
  162. u32 count;
  163. };
  164. struct frequency_table {
  165. unsigned long freq;
  166. };
  167. struct freq_set {
  168. struct frequency_table *freq_tbl;
  169. u32 count;
  170. };
  171. struct device_region_info {
  172. const char *name;
  173. phys_addr_t phy_addr;
  174. u32 size;
  175. u32 dev_addr;
  176. u32 region;
  177. };
  178. struct device_region_set {
  179. struct device_region_info *device_region_tbl;
  180. u32 count;
  181. };
  182. struct msm_vidc_resource {
  183. void *core;
  184. u8 __iomem *register_base_addr;
  185. u32 irq;
  186. struct bus_set bus_set;
  187. struct regulator_set regulator_set;
  188. struct clock_set clock_set;
  189. struct reset_set reset_set;
  190. struct subcache_set subcache_set;
  191. struct context_bank_set context_bank_set;
  192. struct freq_set freq_set;
  193. struct device_region_set device_region_set;
  194. int fw_cookie;
  195. };
  196. #define call_res_op(c, op, ...) \
  197. (((c) && (c)->res_ops && (c)->res_ops->op) ? \
  198. ((c)->res_ops->op(__VA_ARGS__)) : 0)
  199. struct msm_vidc_resources_ops {
  200. int (*init)(struct msm_vidc_core *core);
  201. int (*reset_bridge)(struct msm_vidc_core *core);
  202. int (*reset_control_acquire)(struct msm_vidc_core *core,
  203. const char *name);
  204. int (*reset_control_release)(struct msm_vidc_core *core,
  205. const char *name);
  206. int (*reset_control_assert)(struct msm_vidc_core *core,
  207. const char *name);
  208. int (*reset_control_deassert)(struct msm_vidc_core *core,
  209. const char *name);
  210. int (*gdsc_on)(struct msm_vidc_core *core, const char *name);
  211. int (*gdsc_off)(struct msm_vidc_core *core, const char *name);
  212. int (*gdsc_hw_ctrl)(struct msm_vidc_core *core);
  213. int (*gdsc_sw_ctrl)(struct msm_vidc_core *core);
  214. int (*llcc)(struct msm_vidc_core *core, bool enable);
  215. int (*set_bw)(struct msm_vidc_core *core, unsigned long bw_ddr,
  216. unsigned long bw_llcc);
  217. int (*set_clks)(struct msm_vidc_core *core, u64 rate);
  218. int (*clk_disable)(struct msm_vidc_core *core, const char *name);
  219. int (*clk_enable)(struct msm_vidc_core *core, const char *name);
  220. int (*clk_set_flag)(struct msm_vidc_core *core,
  221. const char *name, enum branch_mem_flags flag);
  222. int (*clk_print_residency_stats)(struct msm_vidc_core *core);
  223. int (*clk_reset_residency_stats)(struct msm_vidc_core *core);
  224. };
  225. const struct msm_vidc_resources_ops *get_resources_ops(void);
  226. #endif