resources.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. struct icc_path;
  8. struct regulator;
  9. struct clk;
  10. struct reset_control;
  11. struct llcc_slice_desc;
  12. struct iommu_domain;
  13. struct device;
  14. struct msm_vidc_core;
  15. /*
  16. * These are helper macros to iterate over various lists within
  17. * msm_vidc_core->resource. The intention is to cut down on a lot of boiler-plate
  18. * code
  19. */
  20. /* Read as "for each 'thing' in a set of 'thingies'" */
  21. #define venus_hfi_for_each_thing(__device, __thing, __thingy) \
  22. venus_hfi_for_each_thing_continue(__device, __thing, __thingy, 0)
  23. #define venus_hfi_for_each_thing_reverse(__device, __thing, __thingy) \
  24. venus_hfi_for_each_thing_reverse_continue(__device, __thing, __thingy, \
  25. (__device)->resource->__thingy##_set.count - 1)
  26. /* TODO: the __from parameter technically not required since we can figure it
  27. * out with some pointer magic (i.e. __thing - __thing##_tbl[0]). If this macro
  28. * sees extensive use, probably worth cleaning it up but for now omitting it
  29. * since it introduces unnecessary complexity.
  30. */
  31. #define venus_hfi_for_each_thing_continue(__device, __thing, __thingy, __from) \
  32. for (__thing = &(__device)->resource->\
  33. __thingy##_set.__thingy##_tbl[__from]; \
  34. __thing < &(__device)->resource->__thingy##_set.__thingy##_tbl[0] + \
  35. ((__device)->resource->__thingy##_set.count - __from); \
  36. ++__thing)
  37. #define venus_hfi_for_each_thing_reverse_continue(__device, __thing, __thingy, \
  38. __from) \
  39. for (__thing = &(__device)->resource->\
  40. __thingy##_set.__thingy##_tbl[__from]; \
  41. __thing >= &(__device)->resource->__thingy##_set.__thingy##_tbl[0]; \
  42. --__thing)
  43. /* Bus set helpers */
  44. #define venus_hfi_for_each_bus(__device, __binfo) \
  45. venus_hfi_for_each_thing(__device, __binfo, bus)
  46. #define venus_hfi_for_each_bus_reverse(__device, __binfo) \
  47. venus_hfi_for_each_thing_reverse(__device, __binfo, bus)
  48. /* Regular set helpers */
  49. #define venus_hfi_for_each_regulator(__device, __rinfo) \
  50. venus_hfi_for_each_thing(__device, __rinfo, regulator)
  51. #define venus_hfi_for_each_regulator_reverse(__device, __rinfo) \
  52. venus_hfi_for_each_thing_reverse(__device, __rinfo, regulator)
  53. #define venus_hfi_for_each_regulator_reverse_continue(__device, __rinfo, \
  54. __from) \
  55. venus_hfi_for_each_thing_reverse_continue(__device, __rinfo, \
  56. regulator, __from)
  57. /* Clock set helpers */
  58. #define venus_hfi_for_each_clock(__device, __cinfo) \
  59. venus_hfi_for_each_thing(__device, __cinfo, clock)
  60. #define venus_hfi_for_each_clock_reverse(__device, __cinfo) \
  61. venus_hfi_for_each_thing_reverse(__device, __cinfo, clock)
  62. /* Reset clock set helpers */
  63. #define venus_hfi_for_each_reset_clock(__device, __rcinfo) \
  64. venus_hfi_for_each_thing(__device, __rcinfo, reset)
  65. #define venus_hfi_for_each_reset_clock_reverse(__device, __rcinfo) \
  66. venus_hfi_for_each_thing_reverse(__device, __rcinfo, reset)
  67. #define venus_hfi_for_each_reset_clock_reverse_continue(__device, __rinfo, \
  68. __from) \
  69. venus_hfi_for_each_thing_reverse_continue(__device, __rinfo, \
  70. reset, __from)
  71. /* Subcache set helpers */
  72. #define venus_hfi_for_each_subcache(__device, __sinfo) \
  73. venus_hfi_for_each_thing(__device, __sinfo, subcache)
  74. #define venus_hfi_for_each_subcache_reverse(__device, __sinfo) \
  75. venus_hfi_for_each_thing_reverse(__device, __sinfo, subcache)
  76. /* Contextbank set helpers */
  77. #define venus_hfi_for_each_context_bank(__device, __sinfo) \
  78. venus_hfi_for_each_thing(__device, __sinfo, context_bank)
  79. #define venus_hfi_for_each_context_bank_reverse(__device, __sinfo) \
  80. venus_hfi_for_each_thing_reverse(__device, __sinfo, context_bank)
  81. struct bus_info {
  82. struct icc_path *icc;
  83. const char *name;
  84. u32 min_kbps;
  85. u32 max_kbps;
  86. };
  87. struct bus_set {
  88. struct bus_info *bus_tbl;
  89. u32 count;
  90. };
  91. struct regulator_info {
  92. struct regulator *regulator;
  93. const char *name;
  94. bool hw_power_collapse;
  95. };
  96. struct regulator_set {
  97. struct regulator_info *regulator_tbl;
  98. u32 count;
  99. };
  100. struct clock_info {
  101. struct clk *clk;
  102. const char *name;
  103. u32 clk_id;
  104. bool has_scaling;
  105. u64 prev;
  106. #ifdef CONFIG_MSM_MMRM
  107. struct mmrm_client *mmrm_client;
  108. #endif
  109. };
  110. struct clock_set {
  111. struct clock_info *clock_tbl;
  112. u32 count;
  113. };
  114. struct reset_info {
  115. struct reset_control *rst;
  116. const char *name;
  117. };
  118. struct reset_set {
  119. struct reset_info *reset_tbl;
  120. u32 count;
  121. };
  122. struct subcache_info {
  123. struct llcc_slice_desc *subcache;
  124. const char *name;
  125. u32 llcc_id;
  126. bool isactive;
  127. };
  128. struct subcache_set {
  129. struct subcache_info *subcache_tbl;
  130. u32 count;
  131. bool set_to_fw;
  132. };
  133. struct addr_range {
  134. u32 start;
  135. u32 size;
  136. };
  137. struct context_bank_info {
  138. const char *name;
  139. struct addr_range addr_range;
  140. bool secure;
  141. bool dma_coherant;
  142. struct device *dev;
  143. struct iommu_domain *domain;
  144. u32 region;
  145. };
  146. struct context_bank_set {
  147. struct context_bank_info *context_bank_tbl;
  148. u32 count;
  149. };
  150. struct frequency_table {
  151. unsigned long freq;
  152. };
  153. struct freq_set {
  154. struct frequency_table *freq_tbl;
  155. u32 count;
  156. };
  157. struct msm_vidc_resource {
  158. void *core;
  159. u8 __iomem *register_base_addr;
  160. u32 irq;
  161. struct bus_set bus_set;
  162. struct regulator_set regulator_set;
  163. struct clock_set clock_set;
  164. struct reset_set reset_set;
  165. struct subcache_set subcache_set;
  166. struct context_bank_set context_bank_set;
  167. struct freq_set freq_set;
  168. int fw_cookie;
  169. };
  170. struct msm_vidc_resources_ops {
  171. int (*init)(struct msm_vidc_core *core);
  172. int (*reset_bridge)(struct msm_vidc_core *core);
  173. int (*gdsc_on)(struct msm_vidc_core *core, const char *name);
  174. int (*gdsc_off)(struct msm_vidc_core *core, const char *name);
  175. int (*gdsc_hw_ctrl)(struct msm_vidc_core *core);
  176. int (*gdsc_sw_ctrl)(struct msm_vidc_core *core);
  177. int (*llcc)(struct msm_vidc_core *core, bool enable);
  178. int (*set_bw)(struct msm_vidc_core *core, unsigned long bw_ddr,
  179. unsigned long bw_llcc);
  180. int (*set_clks)(struct msm_vidc_core *core, u64 rate);
  181. int (*clk_disable)(struct msm_vidc_core *core, const char *name);
  182. int (*clk_enable)(struct msm_vidc_core *core, const char *name);
  183. };
  184. const struct msm_vidc_resources_ops *get_resources_ops(void);
  185. #endif