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