resources.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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_info {
  102. struct clk *clk;
  103. const char *name;
  104. u32 clk_id;
  105. bool has_scaling;
  106. u64 prev;
  107. #ifdef CONFIG_MSM_MMRM
  108. struct mmrm_client *mmrm_client;
  109. #endif
  110. };
  111. struct clock_set {
  112. struct clock_info *clock_tbl;
  113. u32 count;
  114. };
  115. struct reset_info {
  116. struct reset_control *rst;
  117. const char *name;
  118. bool exclusive_release;
  119. };
  120. struct reset_set {
  121. struct reset_info *reset_tbl;
  122. u32 count;
  123. };
  124. struct subcache_info {
  125. struct llcc_slice_desc *subcache;
  126. const char *name;
  127. u32 llcc_id;
  128. bool isactive;
  129. };
  130. struct subcache_set {
  131. struct subcache_info *subcache_tbl;
  132. u32 count;
  133. bool set_to_fw;
  134. };
  135. struct addr_range {
  136. u32 start;
  137. u32 size;
  138. };
  139. struct context_bank_info {
  140. const char *name;
  141. struct addr_range addr_range;
  142. bool secure;
  143. bool dma_coherant;
  144. struct device *dev;
  145. struct iommu_domain *domain;
  146. u32 region;
  147. u64 dma_mask;
  148. };
  149. struct context_bank_set {
  150. struct context_bank_info *context_bank_tbl;
  151. u32 count;
  152. };
  153. struct frequency_table {
  154. unsigned long freq;
  155. };
  156. struct freq_set {
  157. struct frequency_table *freq_tbl;
  158. u32 count;
  159. };
  160. struct msm_vidc_resource {
  161. void *core;
  162. u8 __iomem *register_base_addr;
  163. u32 irq;
  164. struct bus_set bus_set;
  165. struct regulator_set regulator_set;
  166. struct clock_set clock_set;
  167. struct reset_set reset_set;
  168. struct subcache_set subcache_set;
  169. struct context_bank_set context_bank_set;
  170. struct freq_set freq_set;
  171. int fw_cookie;
  172. };
  173. #define call_res_op(c, op, ...) \
  174. (((c) && (c)->res_ops && (c)->res_ops->op) ? \
  175. ((c)->res_ops->op(__VA_ARGS__)) : 0)
  176. struct msm_vidc_resources_ops {
  177. int (*init)(struct msm_vidc_core *core);
  178. int (*reset_bridge)(struct msm_vidc_core *core);
  179. int (*reset_control_acquire)(struct msm_vidc_core *core,
  180. const char *name);
  181. int (*reset_control_release)(struct msm_vidc_core *core,
  182. const char *name);
  183. int (*reset_control_assert)(struct msm_vidc_core *core,
  184. const char *name);
  185. int (*reset_control_deassert)(struct msm_vidc_core *core,
  186. const char *name);
  187. int (*gdsc_on)(struct msm_vidc_core *core, const char *name);
  188. int (*gdsc_off)(struct msm_vidc_core *core, const char *name);
  189. int (*gdsc_hw_ctrl)(struct msm_vidc_core *core);
  190. int (*gdsc_sw_ctrl)(struct msm_vidc_core *core);
  191. int (*llcc)(struct msm_vidc_core *core, bool enable);
  192. int (*set_bw)(struct msm_vidc_core *core, unsigned long bw_ddr,
  193. unsigned long bw_llcc);
  194. int (*set_clks)(struct msm_vidc_core *core, u64 rate);
  195. int (*clk_disable)(struct msm_vidc_core *core, const char *name);
  196. int (*clk_enable)(struct msm_vidc_core *core, const char *name);
  197. int (*clk_set_flag)(struct msm_vidc_core *core,
  198. const char *name, enum branch_mem_flags flag);
  199. };
  200. const struct msm_vidc_resources_ops *get_resources_ops(void);
  201. #endif