sde_hw_wb.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include "sde_hw_mdss.h"
  6. #include "sde_hwio.h"
  7. #include "sde_hw_catalog.h"
  8. #include "sde_hw_wb.h"
  9. #include "sde_formats.h"
  10. #include "sde_dbg.h"
  11. #include "sde_kms.h"
  12. #define WB_DST_FORMAT 0x000
  13. #define WB_DST_OP_MODE 0x004
  14. #define WB_DST_PACK_PATTERN 0x008
  15. #define WB_DST0_ADDR 0x00C
  16. #define WB_DST1_ADDR 0x010
  17. #define WB_DST2_ADDR 0x014
  18. #define WB_DST3_ADDR 0x018
  19. #define WB_DST_YSTRIDE0 0x01C
  20. #define WB_DST_YSTRIDE1 0x020
  21. #define WB_DST_YSTRIDE1 0x020
  22. #define WB_DST_DITHER_BITDEPTH 0x024
  23. #define WB_DST_MATRIX_ROW0 0x030
  24. #define WB_DST_MATRIX_ROW1 0x034
  25. #define WB_DST_MATRIX_ROW2 0x038
  26. #define WB_DST_MATRIX_ROW3 0x03C
  27. #define WB_DST_WRITE_CONFIG 0x048
  28. #define WB_ROTATION_DNSCALER 0x050
  29. #define WB_ROTATOR_PIPE_DOWNSCALER 0x054
  30. #define WB_N16_INIT_PHASE_X_C03 0x060
  31. #define WB_N16_INIT_PHASE_X_C12 0x064
  32. #define WB_N16_INIT_PHASE_Y_C03 0x068
  33. #define WB_N16_INIT_PHASE_Y_C12 0x06C
  34. #define WB_OUT_SIZE 0x074
  35. #define WB_ALPHA_X_VALUE 0x078
  36. #define WB_DANGER_LUT 0x084
  37. #define WB_SAFE_LUT 0x088
  38. #define WB_QOS_CTRL 0x090
  39. #define WB_CREQ_LUT_0 0x098
  40. #define WB_CREQ_LUT_1 0x09C
  41. #define WB_UBWC_STATIC_CTRL 0x144
  42. #define WB_MUX 0x150
  43. #define WB_CSC_BASE 0x260
  44. #define WB_DST_ADDR_SW_STATUS 0x2B0
  45. #define WB_CDP_CNTL 0x2B4
  46. #define WB_OUT_IMAGE_SIZE 0x2C0
  47. #define WB_OUT_XY 0x2C4
  48. #define CWB_CTRL_SRC_SEL 0x0
  49. #define CWB_CTRL_MODE 0x4
  50. #define CWB_CTRL_BLK_SIZE 0x100
  51. #define CWB_CTRL_BASE_OFFSET 0x83000
  52. /* WB_QOS_CTRL */
  53. #define WB_QOS_CTRL_DANGER_SAFE_EN BIT(0)
  54. static struct sde_wb_cfg *_wb_offset(enum sde_wb wb,
  55. struct sde_mdss_cfg *m,
  56. void __iomem *addr,
  57. struct sde_hw_blk_reg_map *b)
  58. {
  59. int i;
  60. for (i = 0; i < m->wb_count; i++) {
  61. if (wb == m->wb[i].id) {
  62. b->base_off = addr;
  63. b->blk_off = m->wb[i].base;
  64. b->length = m->wb[i].len;
  65. b->hwversion = m->hwversion;
  66. b->log_mask = SDE_DBG_MASK_WB;
  67. return &m->wb[i];
  68. }
  69. }
  70. return ERR_PTR(-EINVAL);
  71. }
  72. static void _sde_hw_cwb_ctrl_init(struct sde_mdss_cfg *m,
  73. void __iomem *addr, struct sde_hw_blk_reg_map *b)
  74. {
  75. if (b) {
  76. b->base_off = addr;
  77. b->blk_off = CWB_CTRL_BASE_OFFSET;
  78. b->length = CWB_CTRL_BLK_SIZE * m->pingpong_count;
  79. b->hwversion = m->hwversion;
  80. b->log_mask = SDE_DBG_MASK_WB;
  81. }
  82. }
  83. static void sde_hw_wb_setup_outaddress(struct sde_hw_wb *ctx,
  84. struct sde_hw_wb_cfg *data)
  85. {
  86. struct sde_hw_blk_reg_map *c = &ctx->hw;
  87. SDE_REG_WRITE(c, WB_DST0_ADDR, data->dest.plane_addr[0]);
  88. SDE_REG_WRITE(c, WB_DST1_ADDR, data->dest.plane_addr[1]);
  89. SDE_REG_WRITE(c, WB_DST2_ADDR, data->dest.plane_addr[2]);
  90. SDE_REG_WRITE(c, WB_DST3_ADDR, data->dest.plane_addr[3]);
  91. }
  92. static void sde_hw_wb_setup_format(struct sde_hw_wb *ctx,
  93. struct sde_hw_wb_cfg *data)
  94. {
  95. struct sde_hw_blk_reg_map *c = &ctx->hw;
  96. const struct sde_format *fmt = data->dest.format;
  97. u32 dst_format, pattern, ystride0, ystride1, outsize, chroma_samp;
  98. u32 write_config = 0;
  99. u32 opmode = 0;
  100. u32 dst_addr_sw = 0;
  101. chroma_samp = fmt->chroma_sample;
  102. dst_format = (chroma_samp << 23) |
  103. (fmt->fetch_planes << 19) |
  104. (fmt->bits[C3_ALPHA] << 6) |
  105. (fmt->bits[C2_R_Cr] << 4) |
  106. (fmt->bits[C1_B_Cb] << 2) |
  107. (fmt->bits[C0_G_Y] << 0);
  108. if (fmt->bits[C3_ALPHA] || fmt->alpha_enable) {
  109. dst_format |= BIT(8); /* DSTC3_EN */
  110. if (!fmt->alpha_enable ||
  111. !(ctx->caps->features & BIT(SDE_WB_PIPE_ALPHA)))
  112. dst_format |= BIT(14); /* DST_ALPHA_X */
  113. }
  114. if (SDE_FORMAT_IS_YUV(fmt) &&
  115. (ctx->caps->features & BIT(SDE_WB_YUV_CONFIG)))
  116. dst_format |= BIT(15);
  117. if (SDE_FORMAT_IS_DX(fmt))
  118. dst_format |= BIT(21);
  119. pattern = (fmt->element[3] << 24) |
  120. (fmt->element[2] << 16) |
  121. (fmt->element[1] << 8) |
  122. (fmt->element[0] << 0);
  123. dst_format |= (fmt->unpack_align_msb << 18) |
  124. (fmt->unpack_tight << 17) |
  125. ((fmt->unpack_count - 1) << 12) |
  126. ((fmt->bpp - 1) << 9);
  127. ystride0 = data->dest.plane_pitch[0] |
  128. (data->dest.plane_pitch[1] << 16);
  129. ystride1 = data->dest.plane_pitch[2] |
  130. (data->dest.plane_pitch[3] << 16);
  131. if (data->roi.h && data->roi.w)
  132. outsize = (data->roi.h << 16) | data->roi.w;
  133. else
  134. outsize = (data->dest.height << 16) | data->dest.width;
  135. if (SDE_FORMAT_IS_UBWC(fmt)) {
  136. opmode |= BIT(0);
  137. dst_format |= BIT(31);
  138. write_config |= (ctx->mdp->highest_bank_bit << 8);
  139. if (fmt->base.pixel_format == DRM_FORMAT_RGB565)
  140. write_config |= 0x8;
  141. if (IS_UBWC_20_SUPPORTED(ctx->catalog->ubwc_version))
  142. SDE_REG_WRITE(c, WB_UBWC_STATIC_CTRL,
  143. (ctx->mdp->ubwc_swizzle << 0) |
  144. (ctx->mdp->highest_bank_bit << 4));
  145. }
  146. if (data->is_secure)
  147. dst_addr_sw |= BIT(0);
  148. SDE_REG_WRITE(c, WB_ALPHA_X_VALUE, 0xFF);
  149. SDE_REG_WRITE(c, WB_DST_FORMAT, dst_format);
  150. SDE_REG_WRITE(c, WB_DST_OP_MODE, opmode);
  151. SDE_REG_WRITE(c, WB_DST_PACK_PATTERN, pattern);
  152. SDE_REG_WRITE(c, WB_DST_YSTRIDE0, ystride0);
  153. SDE_REG_WRITE(c, WB_DST_YSTRIDE1, ystride1);
  154. SDE_REG_WRITE(c, WB_OUT_SIZE, outsize);
  155. SDE_REG_WRITE(c, WB_DST_WRITE_CONFIG, write_config);
  156. SDE_REG_WRITE(c, WB_DST_ADDR_SW_STATUS, dst_addr_sw);
  157. }
  158. static void sde_hw_wb_roi(struct sde_hw_wb *ctx, struct sde_hw_wb_cfg *wb)
  159. {
  160. struct sde_hw_blk_reg_map *c = &ctx->hw;
  161. u32 image_size, out_size, out_xy;
  162. image_size = (wb->dest.height << 16) | wb->dest.width;
  163. out_xy = (wb->roi.y << 16) | wb->roi.x;
  164. out_size = (wb->roi.h << 16) | wb->roi.w;
  165. SDE_REG_WRITE(c, WB_OUT_IMAGE_SIZE, image_size);
  166. SDE_REG_WRITE(c, WB_OUT_XY, out_xy);
  167. SDE_REG_WRITE(c, WB_OUT_SIZE, out_size);
  168. }
  169. static void sde_hw_wb_setup_danger_safe_lut(struct sde_hw_wb *ctx,
  170. struct sde_hw_wb_qos_cfg *cfg)
  171. {
  172. struct sde_hw_blk_reg_map *c = &ctx->hw;
  173. if (!ctx || !cfg)
  174. return;
  175. SDE_REG_WRITE(c, WB_DANGER_LUT, cfg->danger_lut);
  176. SDE_REG_WRITE(c, WB_SAFE_LUT, cfg->safe_lut);
  177. }
  178. static void sde_hw_wb_setup_creq_lut(struct sde_hw_wb *ctx,
  179. struct sde_hw_wb_qos_cfg *cfg)
  180. {
  181. struct sde_hw_blk_reg_map *c = &ctx->hw;
  182. if (!ctx || !cfg)
  183. return;
  184. if (ctx->caps && test_bit(SDE_WB_QOS_8LVL, &ctx->caps->features)) {
  185. SDE_REG_WRITE(c, WB_CREQ_LUT_0, cfg->creq_lut);
  186. SDE_REG_WRITE(c, WB_CREQ_LUT_1, cfg->creq_lut >> 32);
  187. }
  188. }
  189. static void sde_hw_wb_setup_qos_ctrl(struct sde_hw_wb *ctx,
  190. struct sde_hw_wb_qos_cfg *cfg)
  191. {
  192. struct sde_hw_blk_reg_map *c = &ctx->hw;
  193. u32 qos_ctrl = 0;
  194. if (!ctx || !cfg)
  195. return;
  196. if (cfg->danger_safe_en)
  197. qos_ctrl |= WB_QOS_CTRL_DANGER_SAFE_EN;
  198. SDE_REG_WRITE(c, WB_QOS_CTRL, qos_ctrl);
  199. }
  200. static void sde_hw_wb_setup_cdp(struct sde_hw_wb *ctx,
  201. struct sde_hw_wb_cdp_cfg *cfg)
  202. {
  203. struct sde_hw_blk_reg_map *c;
  204. u32 cdp_cntl = 0;
  205. if (!ctx || !cfg)
  206. return;
  207. c = &ctx->hw;
  208. if (cfg->enable)
  209. cdp_cntl |= BIT(0);
  210. if (cfg->ubwc_meta_enable)
  211. cdp_cntl |= BIT(1);
  212. if (cfg->preload_ahead == SDE_WB_CDP_PRELOAD_AHEAD_64)
  213. cdp_cntl |= BIT(3);
  214. SDE_REG_WRITE(c, WB_CDP_CNTL, cdp_cntl);
  215. }
  216. static void sde_hw_wb_bind_pingpong_blk(
  217. struct sde_hw_wb *ctx,
  218. bool enable,
  219. const enum sde_pingpong pp)
  220. {
  221. struct sde_hw_blk_reg_map *c;
  222. int mux_cfg = 0xF;
  223. if (!ctx)
  224. return;
  225. c = &ctx->hw;
  226. if (enable)
  227. mux_cfg = (pp - PINGPONG_0) & 0x7;
  228. SDE_REG_WRITE(c, WB_MUX, mux_cfg);
  229. }
  230. static void sde_hw_wb_program_cwb_ctrl(struct sde_hw_wb *ctx,
  231. const enum sde_cwb cur_idx,
  232. const enum sde_cwb data_src, bool dspp_out)
  233. {
  234. struct sde_hw_blk_reg_map *c;
  235. u32 blk_base;
  236. if (!ctx)
  237. return;
  238. c = &ctx->cwb_hw;
  239. blk_base = CWB_CTRL_BLK_SIZE * (cur_idx - CWB_0);
  240. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, data_src - CWB_0);
  241. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, dspp_out);
  242. }
  243. static void _setup_wb_ops(struct sde_hw_wb_ops *ops,
  244. unsigned long features)
  245. {
  246. ops->setup_outaddress = sde_hw_wb_setup_outaddress;
  247. ops->setup_outformat = sde_hw_wb_setup_format;
  248. if (test_bit(SDE_WB_XY_ROI_OFFSET, &features))
  249. ops->setup_roi = sde_hw_wb_roi;
  250. if (test_bit(SDE_WB_QOS, &features)) {
  251. ops->setup_danger_safe_lut =
  252. sde_hw_wb_setup_danger_safe_lut;
  253. ops->setup_creq_lut = sde_hw_wb_setup_creq_lut;
  254. ops->setup_qos_ctrl = sde_hw_wb_setup_qos_ctrl;
  255. }
  256. if (test_bit(SDE_WB_CDP, &features))
  257. ops->setup_cdp = sde_hw_wb_setup_cdp;
  258. if (test_bit(SDE_WB_INPUT_CTRL, &features))
  259. ops->bind_pingpong_blk = sde_hw_wb_bind_pingpong_blk;
  260. if (test_bit(SDE_WB_CWB_CTRL, &features))
  261. ops->program_cwb_ctrl = sde_hw_wb_program_cwb_ctrl;
  262. }
  263. static struct sde_hw_blk_ops sde_hw_ops = {
  264. .start = NULL,
  265. .stop = NULL,
  266. };
  267. struct sde_hw_wb *sde_hw_wb_init(enum sde_wb idx,
  268. void __iomem *addr,
  269. struct sde_mdss_cfg *m,
  270. struct sde_hw_mdp *hw_mdp)
  271. {
  272. struct sde_hw_wb *c;
  273. struct sde_wb_cfg *cfg;
  274. int rc;
  275. if (!addr || !m || !hw_mdp)
  276. return ERR_PTR(-EINVAL);
  277. c = kzalloc(sizeof(*c), GFP_KERNEL);
  278. if (!c)
  279. return ERR_PTR(-ENOMEM);
  280. cfg = _wb_offset(idx, m, addr, &c->hw);
  281. if (IS_ERR(cfg)) {
  282. WARN(1, "Unable to find wb idx=%d\n", idx);
  283. kfree(c);
  284. return ERR_PTR(-EINVAL);
  285. }
  286. /* Assign ops */
  287. c->catalog = m;
  288. c->mdp = &m->mdp[0];
  289. c->idx = idx;
  290. c->caps = cfg;
  291. _setup_wb_ops(&c->ops, c->caps->features);
  292. c->hw_mdp = hw_mdp;
  293. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_WB, idx, &sde_hw_ops);
  294. if (rc) {
  295. SDE_ERROR("failed to init hw blk %d\n", rc);
  296. goto blk_init_error;
  297. }
  298. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  299. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  300. if (test_bit(SDE_WB_CWB_CTRL, &cfg->features))
  301. _sde_hw_cwb_ctrl_init(m, addr, &c->cwb_hw);
  302. return c;
  303. blk_init_error:
  304. kzfree(c);
  305. return ERR_PTR(rc);
  306. }
  307. void sde_hw_wb_destroy(struct sde_hw_wb *hw_wb)
  308. {
  309. if (hw_wb)
  310. sde_hw_blk_destroy(&hw_wb->base);
  311. kfree(hw_wb);
  312. }