resources.h 9.2 KB

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