sde_hw_wb.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. if (IS_UBWC_10_SUPPORTED(ctx->catalog->ubwc_version))
  146. SDE_REG_WRITE(c, WB_UBWC_STATIC_CTRL,
  147. (ctx->mdp->ubwc_swizzle << 0) |
  148. BIT(8) |
  149. (ctx->mdp->highest_bank_bit << 4));
  150. }
  151. if (data->is_secure)
  152. dst_addr_sw |= BIT(0);
  153. SDE_REG_WRITE(c, WB_ALPHA_X_VALUE, 0xFF);
  154. SDE_REG_WRITE(c, WB_DST_FORMAT, dst_format);
  155. SDE_REG_WRITE(c, WB_DST_OP_MODE, opmode);
  156. SDE_REG_WRITE(c, WB_DST_PACK_PATTERN, pattern);
  157. SDE_REG_WRITE(c, WB_DST_YSTRIDE0, ystride0);
  158. SDE_REG_WRITE(c, WB_DST_YSTRIDE1, ystride1);
  159. SDE_REG_WRITE(c, WB_OUT_SIZE, outsize);
  160. SDE_REG_WRITE(c, WB_DST_WRITE_CONFIG, write_config);
  161. SDE_REG_WRITE(c, WB_DST_ADDR_SW_STATUS, dst_addr_sw);
  162. }
  163. static void sde_hw_wb_roi(struct sde_hw_wb *ctx, struct sde_hw_wb_cfg *wb)
  164. {
  165. struct sde_hw_blk_reg_map *c = &ctx->hw;
  166. u32 image_size, out_size, out_xy;
  167. image_size = (wb->dest.height << 16) | wb->dest.width;
  168. out_xy = (wb->roi.y << 16) | wb->roi.x;
  169. out_size = (wb->roi.h << 16) | wb->roi.w;
  170. SDE_REG_WRITE(c, WB_OUT_IMAGE_SIZE, image_size);
  171. SDE_REG_WRITE(c, WB_OUT_XY, out_xy);
  172. SDE_REG_WRITE(c, WB_OUT_SIZE, out_size);
  173. }
  174. static void sde_hw_wb_setup_danger_safe_lut(struct sde_hw_wb *ctx,
  175. struct sde_hw_wb_qos_cfg *cfg)
  176. {
  177. struct sde_hw_blk_reg_map *c = &ctx->hw;
  178. if (!ctx || !cfg)
  179. return;
  180. SDE_REG_WRITE(c, WB_DANGER_LUT, cfg->danger_lut);
  181. SDE_REG_WRITE(c, WB_SAFE_LUT, cfg->safe_lut);
  182. }
  183. static void sde_hw_wb_setup_creq_lut(struct sde_hw_wb *ctx,
  184. struct sde_hw_wb_qos_cfg *cfg)
  185. {
  186. struct sde_hw_blk_reg_map *c = &ctx->hw;
  187. if (!ctx || !cfg)
  188. return;
  189. if (ctx->caps && test_bit(SDE_WB_QOS_8LVL, &ctx->caps->features)) {
  190. SDE_REG_WRITE(c, WB_CREQ_LUT_0, cfg->creq_lut);
  191. SDE_REG_WRITE(c, WB_CREQ_LUT_1, cfg->creq_lut >> 32);
  192. }
  193. }
  194. static void sde_hw_wb_setup_qos_ctrl(struct sde_hw_wb *ctx,
  195. struct sde_hw_wb_qos_cfg *cfg)
  196. {
  197. struct sde_hw_blk_reg_map *c = &ctx->hw;
  198. u32 qos_ctrl = 0;
  199. if (!ctx || !cfg)
  200. return;
  201. if (cfg->danger_safe_en)
  202. qos_ctrl |= WB_QOS_CTRL_DANGER_SAFE_EN;
  203. SDE_REG_WRITE(c, WB_QOS_CTRL, qos_ctrl);
  204. }
  205. static void sde_hw_wb_setup_cdp(struct sde_hw_wb *ctx,
  206. struct sde_hw_wb_cdp_cfg *cfg)
  207. {
  208. struct sde_hw_blk_reg_map *c;
  209. u32 cdp_cntl = 0;
  210. if (!ctx || !cfg)
  211. return;
  212. c = &ctx->hw;
  213. if (cfg->enable)
  214. cdp_cntl |= BIT(0);
  215. if (cfg->ubwc_meta_enable)
  216. cdp_cntl |= BIT(1);
  217. if (cfg->preload_ahead == SDE_WB_CDP_PRELOAD_AHEAD_64)
  218. cdp_cntl |= BIT(3);
  219. SDE_REG_WRITE(c, WB_CDP_CNTL, cdp_cntl);
  220. }
  221. static void sde_hw_wb_bind_pingpong_blk(
  222. struct sde_hw_wb *ctx,
  223. bool enable,
  224. const enum sde_pingpong pp)
  225. {
  226. struct sde_hw_blk_reg_map *c;
  227. int mux_cfg = 0xF;
  228. if (!ctx)
  229. return;
  230. c = &ctx->hw;
  231. if (enable)
  232. mux_cfg = (pp - PINGPONG_0) & 0x7;
  233. SDE_REG_WRITE(c, WB_MUX, mux_cfg);
  234. }
  235. static void sde_hw_wb_program_cwb_ctrl(struct sde_hw_wb *ctx,
  236. const enum sde_cwb cur_idx,
  237. const enum sde_cwb data_src, bool dspp_out)
  238. {
  239. struct sde_hw_blk_reg_map *c;
  240. u32 blk_base;
  241. if (!ctx)
  242. return;
  243. c = &ctx->cwb_hw;
  244. blk_base = CWB_CTRL_BLK_SIZE * (cur_idx - CWB_0);
  245. SDE_REG_WRITE(c, blk_base + CWB_CTRL_SRC_SEL, data_src - CWB_0);
  246. SDE_REG_WRITE(c, blk_base + CWB_CTRL_MODE, dspp_out);
  247. }
  248. static void _setup_wb_ops(struct sde_hw_wb_ops *ops,
  249. unsigned long features)
  250. {
  251. ops->setup_outaddress = sde_hw_wb_setup_outaddress;
  252. ops->setup_outformat = sde_hw_wb_setup_format;
  253. if (test_bit(SDE_WB_XY_ROI_OFFSET, &features))
  254. ops->setup_roi = sde_hw_wb_roi;
  255. if (test_bit(SDE_WB_QOS, &features)) {
  256. ops->setup_danger_safe_lut =
  257. sde_hw_wb_setup_danger_safe_lut;
  258. ops->setup_creq_lut = sde_hw_wb_setup_creq_lut;
  259. ops->setup_qos_ctrl = sde_hw_wb_setup_qos_ctrl;
  260. }
  261. if (test_bit(SDE_WB_CDP, &features))
  262. ops->setup_cdp = sde_hw_wb_setup_cdp;
  263. if (test_bit(SDE_WB_INPUT_CTRL, &features))
  264. ops->bind_pingpong_blk = sde_hw_wb_bind_pingpong_blk;
  265. if (test_bit(SDE_WB_CWB_CTRL, &features))
  266. ops->program_cwb_ctrl = sde_hw_wb_program_cwb_ctrl;
  267. }
  268. static struct sde_hw_blk_ops sde_hw_ops = {
  269. .start = NULL,
  270. .stop = NULL,
  271. };
  272. struct sde_hw_wb *sde_hw_wb_init(enum sde_wb idx,
  273. void __iomem *addr,
  274. struct sde_mdss_cfg *m,
  275. struct sde_hw_mdp *hw_mdp)
  276. {
  277. struct sde_hw_wb *c;
  278. struct sde_wb_cfg *cfg;
  279. int rc;
  280. if (!addr || !m || !hw_mdp)
  281. return ERR_PTR(-EINVAL);
  282. c = kzalloc(sizeof(*c), GFP_KERNEL);
  283. if (!c)
  284. return ERR_PTR(-ENOMEM);
  285. cfg = _wb_offset(idx, m, addr, &c->hw);
  286. if (IS_ERR(cfg)) {
  287. WARN(1, "Unable to find wb idx=%d\n", idx);
  288. kfree(c);
  289. return ERR_PTR(-EINVAL);
  290. }
  291. /* Assign ops */
  292. c->catalog = m;
  293. c->mdp = &m->mdp[0];
  294. c->idx = idx;
  295. c->caps = cfg;
  296. _setup_wb_ops(&c->ops, c->caps->features);
  297. c->hw_mdp = hw_mdp;
  298. rc = sde_hw_blk_init(&c->base, SDE_HW_BLK_WB, idx, &sde_hw_ops);
  299. if (rc) {
  300. SDE_ERROR("failed to init hw blk %d\n", rc);
  301. goto blk_init_error;
  302. }
  303. sde_dbg_reg_register_dump_range(SDE_DBG_NAME, cfg->name, c->hw.blk_off,
  304. c->hw.blk_off + c->hw.length, c->hw.xin_id);
  305. if (test_bit(SDE_WB_CWB_CTRL, &cfg->features))
  306. _sde_hw_cwb_ctrl_init(m, addr, &c->cwb_hw);
  307. return c;
  308. blk_init_error:
  309. kzfree(c);
  310. return ERR_PTR(rc);
  311. }
  312. void sde_hw_wb_destroy(struct sde_hw_wb *hw_wb)
  313. {
  314. if (hw_wb)
  315. sde_hw_blk_destroy(&hw_wb->base);
  316. kfree(hw_wb);
  317. }