msm_vidc_power.h 5.6 KB

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