msm_vidc_power.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _MSM_VIDC_POWER_H_
  7. #define _MSM_VIDC_POWER_H_
  8. #include "fixedpoint.h"
  9. #include "msm_vidc_debug.h"
  10. #include "msm_vidc_internal.h"
  11. #include "msm_vidc_inst.h"
  12. #define COMPRESSION_RATIO_MAX 5
  13. /* TODO: Move to dtsi OR use source clock instead of branch clock.*/
  14. #define MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO 3
  15. enum vidc_bus_type {
  16. PERF,
  17. DDR,
  18. LLCC,
  19. };
  20. /*
  21. * Minimum dimensions for which to calculate bandwidth.
  22. * This means that anything bandwidth(0, 0) ==
  23. * bandwidth(BASELINE_DIMENSIONS.width, BASELINE_DIMENSIONS.height)
  24. */
  25. static const struct {
  26. int height, width;
  27. } BASELINE_DIMENSIONS = {
  28. .width = 1280,
  29. .height = 720,
  30. };
  31. /* converts Mbps to bps (the "b" part can be bits or bytes based on context) */
  32. #define kbps(__mbps) ((__mbps) * 1000)
  33. #define bps(__mbps) (kbps(__mbps) * 1000)
  34. #define GENERATE_COMPRESSION_PROFILE(__bpp, __worst) { \
  35. .bpp = __bpp, \
  36. .ratio = __worst, \
  37. }
  38. /*
  39. * The below table is a structural representation of the following table:
  40. * Resolution | Bitrate | Compression Ratio |
  41. * ............|............|.........................................|
  42. * Width Height|Average High|Avg_8bpc Worst_8bpc Avg_10bpc Worst_10bpc|
  43. * 1280 720| 7 14| 1.69 1.28 1.49 1.23|
  44. * 1920 1080| 20 40| 1.69 1.28 1.49 1.23|
  45. * 2560 1440| 32 64| 2.2 1.26 1.97 1.22|
  46. * 3840 2160| 42 84| 2.2 1.26 1.97 1.22|
  47. * 4096 2160| 44 88| 2.2 1.26 1.97 1.22|
  48. * 4096 2304| 48 96| 2.2 1.26 1.97 1.22|
  49. */
  50. static struct lut {
  51. int frame_size; /* width x height */
  52. int frame_rate;
  53. unsigned long bitrate;
  54. struct {
  55. int bpp;
  56. fp_t ratio;
  57. } compression_ratio[COMPRESSION_RATIO_MAX];
  58. } const LUT[] = {
  59. {
  60. .frame_size = 1280 * 720,
  61. .frame_rate = 30,
  62. .bitrate = 14,
  63. .compression_ratio = {
  64. GENERATE_COMPRESSION_PROFILE(8,
  65. FP(1, 28, 100)),
  66. GENERATE_COMPRESSION_PROFILE(10,
  67. FP(1, 23, 100)),
  68. }
  69. },
  70. {
  71. .frame_size = 1280 * 720,
  72. .frame_rate = 60,
  73. .bitrate = 22,
  74. .compression_ratio = {
  75. GENERATE_COMPRESSION_PROFILE(8,
  76. FP(1, 28, 100)),
  77. GENERATE_COMPRESSION_PROFILE(10,
  78. FP(1, 23, 100)),
  79. }
  80. },
  81. {
  82. .frame_size = 1920 * 1088,
  83. .frame_rate = 30,
  84. .bitrate = 40,
  85. .compression_ratio = {
  86. GENERATE_COMPRESSION_PROFILE(8,
  87. FP(1, 28, 100)),
  88. GENERATE_COMPRESSION_PROFILE(10,
  89. FP(1, 23, 100)),
  90. }
  91. },
  92. {
  93. .frame_size = 1920 * 1088,
  94. .frame_rate = 60,
  95. .bitrate = 64,
  96. .compression_ratio = {
  97. GENERATE_COMPRESSION_PROFILE(8,
  98. FP(1, 28, 100)),
  99. GENERATE_COMPRESSION_PROFILE(10,
  100. FP(1, 23, 100)),
  101. }
  102. },
  103. {
  104. .frame_size = 2560 * 1440,
  105. .frame_rate = 30,
  106. .bitrate = 64,
  107. .compression_ratio = {
  108. GENERATE_COMPRESSION_PROFILE(8,
  109. FP(1, 26, 100)),
  110. GENERATE_COMPRESSION_PROFILE(10,
  111. FP(1, 22, 100)),
  112. }
  113. },
  114. {
  115. .frame_size = 2560 * 1440,
  116. .frame_rate = 60,
  117. .bitrate = 102,
  118. .compression_ratio = {
  119. GENERATE_COMPRESSION_PROFILE(8,
  120. FP(1, 26, 100)),
  121. GENERATE_COMPRESSION_PROFILE(10,
  122. FP(1, 22, 100)),
  123. }
  124. },
  125. {
  126. .frame_size = 3840 * 2160,
  127. .frame_rate = 30,
  128. .bitrate = 84,
  129. .compression_ratio = {
  130. GENERATE_COMPRESSION_PROFILE(8,
  131. FP(1, 26, 100)),
  132. GENERATE_COMPRESSION_PROFILE(10,
  133. FP(1, 22, 100)),
  134. }
  135. },
  136. {
  137. .frame_size = 3840 * 2160,
  138. .frame_rate = 60,
  139. .bitrate = 134,
  140. .compression_ratio = {
  141. GENERATE_COMPRESSION_PROFILE(8,
  142. FP(1, 26, 100)),
  143. GENERATE_COMPRESSION_PROFILE(10,
  144. FP(1, 22, 100)),
  145. }
  146. },
  147. {
  148. .frame_size = 4096 * 2160,
  149. .frame_rate = 30,
  150. .bitrate = 88,
  151. .compression_ratio = {
  152. GENERATE_COMPRESSION_PROFILE(8,
  153. FP(1, 26, 100)),
  154. GENERATE_COMPRESSION_PROFILE(10,
  155. FP(1, 22, 100)),
  156. }
  157. },
  158. {
  159. .frame_size = 4096 * 2160,
  160. .frame_rate = 60,
  161. .bitrate = 141,
  162. .compression_ratio = {
  163. GENERATE_COMPRESSION_PROFILE(8,
  164. FP(1, 26, 100)),
  165. GENERATE_COMPRESSION_PROFILE(10,
  166. FP(1, 22, 100)),
  167. }
  168. },
  169. {
  170. .frame_size = 4096 * 2304,
  171. .frame_rate = 30,
  172. .bitrate = 96,
  173. .compression_ratio = {
  174. GENERATE_COMPRESSION_PROFILE(8,
  175. FP(1, 26, 100)),
  176. GENERATE_COMPRESSION_PROFILE(10,
  177. FP(1, 22, 100)),
  178. }
  179. },
  180. {
  181. .frame_size = 4096 * 2304,
  182. .frame_rate = 60,
  183. .bitrate = 154,
  184. .compression_ratio = {
  185. GENERATE_COMPRESSION_PROFILE(8,
  186. FP(1, 26, 100)),
  187. GENERATE_COMPRESSION_PROFILE(10,
  188. FP(1, 22, 100)),
  189. }
  190. },
  191. };
  192. static inline u32 get_type_frm_name(const char *name)
  193. {
  194. if (!strcmp(name, "venus-llcc"))
  195. return LLCC;
  196. else if (!strcmp(name, "venus-ddr"))
  197. return DDR;
  198. else
  199. return PERF;
  200. }
  201. #define DUMP_HEADER_MAGIC 0xdeadbeef
  202. #define DUMP_FP_FMT "%FP" /* special format for fp_t */
  203. struct dump {
  204. char *key;
  205. char *format;
  206. size_t val;
  207. };
  208. struct lut const *__lut(int width, int height, int fps);
  209. fp_t __compression_ratio(struct lut const *entry, int bpp);
  210. void __dump(struct dump dump[], int len);
  211. static inline bool __ubwc(enum msm_vidc_colorformat_type f)
  212. {
  213. switch (f) {
  214. case MSM_VIDC_FMT_NV12C:
  215. case MSM_VIDC_FMT_TP10C:
  216. return true;
  217. default:
  218. return false;
  219. }
  220. }
  221. static inline int __bpp(enum msm_vidc_colorformat_type f)
  222. {
  223. switch (f) {
  224. case MSM_VIDC_FMT_NV12:
  225. case MSM_VIDC_FMT_NV21:
  226. case MSM_VIDC_FMT_NV12C:
  227. case MSM_VIDC_FMT_RGBA8888C:
  228. return 8;
  229. case MSM_VIDC_FMT_P010:
  230. case MSM_VIDC_FMT_TP10C:
  231. return 10;
  232. default:
  233. d_vpr_e("Unsupported colorformat (%x)", f);
  234. return INT_MAX;
  235. }
  236. }
  237. u64 msm_vidc_max_freq(struct msm_vidc_inst *inst);
  238. int msm_vidc_scale_power(struct msm_vidc_inst *inst, bool scale_buses);
  239. void msm_vidc_power_data_reset(struct msm_vidc_inst *inst);
  240. #endif