mtk_layering_rule_base.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright (C) 2016 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
  12. */
  13. #ifndef __MTK_LAYERING_RULE_BASE__
  14. #define __MTK_LAYERING_RULE_BASE__
  15. #if 0
  16. #include "disp_session.h"
  17. #include "disp_lcm.h"
  18. #include "disp_drv_log.h"
  19. #include "primary_display.h"
  20. #include "disp_drv_platform.h"
  21. #include "display_recorder.h"
  22. #endif
  23. #include <drm/drmP.h>
  24. #include <drm/drm_crtc_helper.h>
  25. #include <drm/drm_fb_helper.h>
  26. #include <drm/drm_gem.h>
  27. #include <drm/mediatek_drm.h>
  28. #include <drm/drm_modes.h>
  29. /* move to Platform dependent part? */
  30. #define TOTAL_OVL_LAYER_NUM (4 + 3 + 2 + 3)
  31. #define PRIMARY_SESSION_INPUT_LAYER_COUNT (12) /* phy(4+2) + ext(3+3) */
  32. #define EXTERNAL_SESSION_INPUT_LAYER_COUNT \
  33. (2 /*2+3*/) /* 2 is enough, no need ext layer */
  34. /* ***************************************** */
  35. #define PRIMARY_OVL_LAYER_NUM PRIMARY_SESSION_INPUT_LAYER_COUNT
  36. #define SECONDARY_OVL_LAYER_NUM EXTERNAL_SESSION_INPUT_LAYER_COUNT
  37. /* #define HRT_DEBUG_LEVEL1 */
  38. /* #define HRT_DEBUG_LEVEL2 */
  39. /* #define HRT_UT_DEBUG */
  40. #define PATH_FMT_RSZ_SHIFT 9
  41. #define PATH_FMT_PIPE_SHIFT 7
  42. #define PATH_FMT_DISP_SHIFT 5
  43. #define PATH_FMT_ID_SHIFT 0
  44. #define HRT_UINT_BOUND_BPP 4
  45. #define HRT_UINT_WEIGHT 100
  46. /* bpp x uint weight = 2 x 100 */
  47. #define HRT_AEE_WEIGHT 200
  48. #define HRT_ROUND_CORNER_WEIGHT 200
  49. #define HRT_GET_FIRST_SET_BIT(n) (((n) - ((n) & ((n) - 1))))
  50. enum HRT_DISP_TYPE {
  51. HRT_PRIMARY = 0,
  52. HRT_SECONDARY,
  53. HRT_THIRD,
  54. HRT_TYPE_NUM,
  55. };
  56. enum HRT_DEBUG_LAYER_DATA {
  57. HRT_LAYER_DATA_ID = 0,
  58. HRT_LAYER_DATA_SRC_FMT,
  59. HRT_LAYER_DATA_DST_OFFSET_X,
  60. HRT_LAYER_DATA_DST_OFFSET_Y,
  61. HRT_LAYER_DATA_DST_WIDTH,
  62. /*5*/
  63. HRT_LAYER_DATA_DST_HEIGHT,
  64. HRT_LAYER_DATA_SRC_WIDTH,
  65. HRT_LAYER_DATA_SRC_HEIGHT,
  66. HRT_LAYER_DATA_SRC_OFFSET_X,
  67. HRT_LAYER_DATA_SRC_OFFSET_Y,
  68. HRT_LAYER_DATA_COMPRESS,
  69. HRT_LAYER_DATA_CAPS,
  70. HRT_LAYER_DATA_NUM,
  71. };
  72. enum HRT_TYPE {
  73. HRT_TYPE_LARB0 = 0,
  74. HRT_TYPE_LARB1,
  75. HRT_TYPE_EMI,
  76. HRT_TYPE_UNKNOWN,
  77. };
  78. enum HRT_SYS_STATE {
  79. DISP_HRT_MJC_ON = 0,
  80. DISP_HRT_FORCE_DUAL_OFF,
  81. DISP_HRT_MULTI_TUI_ON,
  82. };
  83. enum DISP_HW_MAPPING_TB_TYPE {
  84. DISP_HW_EMI_BOUND_TB,
  85. DISP_HW_LARB_BOUND_TB,
  86. DISP_HW_OVL_TB,
  87. DISP_HW_LARB_TB,
  88. DISP_HW_LAYER_TB,
  89. };
  90. enum LYE_HELPER_OPT {
  91. LYE_OPT_DUAL_PIPE,
  92. LYE_OPT_EXT_LAYER,
  93. LYE_OPT_RPO,
  94. LYE_OPT_CLEAR_LAYER,
  95. LYE_OPT_NUM
  96. };
  97. enum ADJUST_LAYOUT_PURPOSE {
  98. ADJUST_LAYOUT_EXT_GROUPING,
  99. ADJUST_LAYOUT_OVERLAP_CAL,
  100. };
  101. enum LYE_TYPE {
  102. LYE_NORMAL,
  103. LYE_EXT0,
  104. LYE_EXT1,
  105. LYE_EXT2,
  106. };
  107. struct hrt_sort_entry {
  108. struct hrt_sort_entry *head, *tail;
  109. struct drm_mtk_layer_config *layer_info;
  110. int key;
  111. int overlap_w;
  112. };
  113. struct layering_rule_info_t {
  114. int bound_tb_idx;
  115. int addon_scn[HRT_TYPE_NUM];
  116. int dal_enable;
  117. int primary_fps;
  118. int hrt_sys_state;
  119. int wrot_sram;
  120. unsigned int hrt_idx;
  121. };
  122. enum SCN_FACTOR {
  123. SCN_NEED_VP_PQ = 0x00000001,
  124. SCN_NEED_GAME_PQ = 0x00000002,
  125. SCN_TRIPLE_DISP = 0x00000004,
  126. };
  127. struct layering_rule_ops {
  128. void (*scenario_decision)(unsigned int scn_decision_flag,
  129. unsigned int scale_num);
  130. int *(*get_bound_table)(enum DISP_HW_MAPPING_TB_TYPE tb_type);
  131. uint16_t (*get_mapping_table)(struct drm_device *dev, int disp_idx,
  132. enum DISP_HW_MAPPING_TB_TYPE tb_type,
  133. int param);
  134. /* should be removed */
  135. int (*get_hrt_bound)(int is_larb, int hrt_level);
  136. void (*copy_hrt_bound_table)(struct drm_mtk_layering_info *disp_info,
  137. int is_larb, int *hrt_table, struct drm_device *dev);
  138. bool (*rollback_to_gpu_by_hw_limitation)(
  139. struct drm_device *dev,
  140. struct drm_mtk_layering_info *disp_info);
  141. bool (*rollback_all_to_GPU_for_idle)(struct drm_device *dev);
  142. /* for fbdc */
  143. void (*fbdc_pre_calculate)(struct drm_mtk_layering_info *disp_info);
  144. void (*fbdc_adjust_layout)(struct drm_mtk_layering_info *disp_info,
  145. enum ADJUST_LAYOUT_PURPOSE p);
  146. void (*fbdc_restore_layout)(struct drm_mtk_layering_info *dst_info,
  147. enum ADJUST_LAYOUT_PURPOSE p);
  148. void (*fbdc_rule)(struct drm_mtk_layering_info *disp_info);
  149. };
  150. #define HRT_GET_DVFS_LEVEL(hrt_num) (hrt_num & 0xF)
  151. #define HRT_SET_DVFS_LEVEL(hrt_num, value) \
  152. (hrt_num = ((hrt_num & ~(0xF)) | (value & 0xF)))
  153. #define HRT_GET_SCALE_SCENARIO(hrt_num) ((hrt_num & 0xF0) >> 4)
  154. #define HRT_SET_SCALE_SCENARIO(hrt_num, value) \
  155. (hrt_num = ((hrt_num & ~(0xF0)) | ((value & 0xF) << 4)))
  156. #define HRT_GET_AEE_FLAG(hrt_num) ((hrt_num & 0x100) >> 8)
  157. #define HRT_SET_AEE_FLAG(hrt_num, value) \
  158. (hrt_num = ((hrt_num & ~(0x100)) | ((value & 0x1) << 8)))
  159. #define HRT_GET_WROT_SRAM_FLAG(hrt_num) ((hrt_num & 0x600) >> 9)
  160. #define HRT_SET_WROT_SRAM_FLAG(hrt_num, value) \
  161. (hrt_num = ((hrt_num & ~(0x600)) | ((value & 0x3) << 9)))
  162. #define HRT_GET_NO_COMPRESS_FLAG(hrt_num) ((hrt_num & 0x7800) >> 11)
  163. #define HRT_SET_NO_COMPRESS_FLAG(hrt_num, value) \
  164. (hrt_num = ((hrt_num & ~(0x7800)) | ((value & 0xf) << 11)))
  165. #define HRT_GET_PATH_ID(hrt_path) (hrt_path & 0x1F)
  166. // int layering_rule_start(struct drm_mtk_layering_info *disp_info, int
  167. // debug_mode);
  168. extern int hdmi_get_dev_info(int is_sf, void *info);
  169. // int gen_hrt_pattern(void);
  170. // int set_hrt_state(enum HRT_SYS_STATE sys_state, int en);
  171. void mtk_register_layering_rule_ops(struct layering_rule_ops *ops,
  172. struct layering_rule_info_t *info);
  173. int mtk_get_phy_layer_limit(uint16_t layer_map_tb);
  174. // int get_phy_ovl_layer_cnt(struct drm_mtk_layering_info *disp_info, int
  175. // disp_idx);
  176. // bool is_decouple_path(struct drm_mtk_layering_info *disp_info);
  177. int mtk_rollback_resize_layer_to_GPU_range(
  178. struct drm_mtk_layering_info *disp_info, int disp_idx, int start_idx,
  179. int end_idx);
  180. int mtk_rollback_all_resize_layer_to_GPU(
  181. struct drm_mtk_layering_info *disp_info, int disp_idx);
  182. bool mtk_is_yuv(uint32_t format);
  183. // bool is_argb_fmt(uint32_t format);
  184. bool mtk_is_gles_layer(struct drm_mtk_layering_info *disp_info, int disp_idx,
  185. int layer_idx);
  186. bool mtk_has_layer_cap(struct drm_mtk_layer_config *layer_info,
  187. enum MTK_LAYERING_CAPS l_caps);
  188. void mtk_set_layering_opt(enum LYE_HELPER_OPT opt, int value);
  189. void mtk_rollback_layer_to_GPU(struct drm_mtk_layering_info *disp_info,
  190. int disp_idx, int i);
  191. /* rollback and set NO_FBDC flag */
  192. void mtk_rollback_compress_layer_to_GPU(struct drm_mtk_layering_info *disp_info,
  193. int disp_idx, int i);
  194. bool mtk_is_layer_id_valid(struct drm_mtk_layering_info *disp_info,
  195. int disp_idx, int i);
  196. int mtk_layering_rule_ioctl(struct drm_device *drm, void *data,
  197. struct drm_file *file_priv);
  198. bool is_triple_disp(struct drm_mtk_layering_info *disp_info);
  199. #endif