sde_rotator_r1_pipe.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012, 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #define pr_fmt(fmt) "%s: " fmt, __func__
  6. #include <linux/bitmap.h>
  7. #include <linux/errno.h>
  8. #include <linux/iopoll.h>
  9. #include <linux/mutex.h>
  10. #include "sde_rotator_r1_hwio.h"
  11. #include "sde_rotator_base.h"
  12. #include "sde_rotator_util.h"
  13. #include "sde_rotator_r1_internal.h"
  14. #include "sde_rotator_core.h"
  15. #include "sde_rotator_trace.h"
  16. #define SMP_MB_SIZE (mdss_res->smp_mb_size)
  17. #define SMP_MB_CNT (mdss_res->smp_mb_cnt)
  18. #define SMP_MB_ENTRY_SIZE 16
  19. #define MAX_BPP 4
  20. #define PIPE_CLEANUP_TIMEOUT_US 100000
  21. /* following offsets are relative to ctrl register bit offset */
  22. #define CLK_FORCE_ON_OFFSET 0x0
  23. #define CLK_FORCE_OFF_OFFSET 0x1
  24. /* following offsets are relative to status register bit offset */
  25. #define CLK_STATUS_OFFSET 0x0
  26. #define QOS_LUT_NRT_READ 0x0
  27. #define PANIC_LUT_NRT_READ 0x0
  28. #define ROBUST_LUT_NRT_READ 0xFFFF
  29. /* Priority 2, no panic */
  30. #define VBLANK_PANIC_DEFAULT_CONFIG 0x200000
  31. static inline void sde_mdp_pipe_write(struct sde_mdp_pipe *pipe,
  32. u32 reg, u32 val)
  33. {
  34. SDEROT_DBG("pipe%d:%6.6x:%8.8x\n", pipe->num, pipe->offset + reg, val);
  35. writel_relaxed(val, pipe->base + reg);
  36. }
  37. static int sde_mdp_pipe_qos_lut(struct sde_mdp_pipe *pipe)
  38. {
  39. u32 qos_lut;
  40. qos_lut = QOS_LUT_NRT_READ; /* low priority for nrt */
  41. trace_rot_perf_set_qos_luts(pipe->num, pipe->src_fmt->format,
  42. qos_lut, sde_mdp_is_linear_format(pipe->src_fmt));
  43. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_CREQ_LUT,
  44. qos_lut);
  45. return 0;
  46. }
  47. /**
  48. * @sde_mdp_pipe_nrt_vbif_setup -
  49. * @mdata: pointer to global driver data.
  50. * @pipe: pointer to a pipe
  51. *
  52. * This function assumes that clocks are enabled, so it is callers
  53. * responsibility to enable clocks before calling this function.
  54. */
  55. static void sde_mdp_pipe_nrt_vbif_setup(struct sde_rot_data_type *mdata,
  56. struct sde_mdp_pipe *pipe)
  57. {
  58. uint32_t nrt_vbif_client_sel;
  59. if (pipe->type != SDE_MDP_PIPE_TYPE_DMA)
  60. return;
  61. nrt_vbif_client_sel = readl_relaxed(mdata->mdp_base +
  62. MMSS_MDP_RT_NRT_VBIF_CLIENT_SEL);
  63. if (sde_mdp_is_nrt_vbif_client(mdata, pipe))
  64. nrt_vbif_client_sel |= BIT(pipe->num - SDE_MDP_SSPP_DMA0);
  65. else
  66. nrt_vbif_client_sel &= ~BIT(pipe->num - SDE_MDP_SSPP_DMA0);
  67. SDEROT_DBG("mdp:%6.6x:%8.8x\n", MMSS_MDP_RT_NRT_VBIF_CLIENT_SEL,
  68. nrt_vbif_client_sel);
  69. writel_relaxed(nrt_vbif_client_sel,
  70. mdata->mdp_base + MMSS_MDP_RT_NRT_VBIF_CLIENT_SEL);
  71. }
  72. /**
  73. * sde_mdp_qos_vbif_remapper_setup - Program the VBIF QoS remapper
  74. * registers based on real or non real time clients
  75. * @mdata: Pointer to the global mdss data structure.
  76. * @pipe: Pointer to source pipe struct to get xin id's.
  77. * @is_realtime: To determine if pipe's client is real or
  78. * non real time.
  79. * This function assumes that clocks are on, so it is caller responsibility to
  80. * call this function with clocks enabled.
  81. */
  82. static void sde_mdp_qos_vbif_remapper_setup(struct sde_rot_data_type *mdata,
  83. struct sde_mdp_pipe *pipe, bool is_realtime)
  84. {
  85. u32 mask, reg_val, i, vbif_qos;
  86. if (mdata->npriority_lvl == 0)
  87. return;
  88. for (i = 0; i < mdata->npriority_lvl; i++) {
  89. reg_val = SDE_VBIF_READ(mdata, SDE_VBIF_QOS_REMAP_BASE + i*4);
  90. mask = 0x3 << (pipe->xin_id * 2);
  91. reg_val &= ~(mask);
  92. vbif_qos = is_realtime ?
  93. mdata->vbif_rt_qos[i] : mdata->vbif_nrt_qos[i];
  94. reg_val |= vbif_qos << (pipe->xin_id * 2);
  95. SDE_VBIF_WRITE(mdata, SDE_VBIF_QOS_REMAP_BASE + i*4, reg_val);
  96. }
  97. }
  98. struct sde_mdp_pipe *sde_mdp_pipe_assign(struct sde_rot_data_type *mdata,
  99. struct sde_mdp_mixer *mixer, u32 ndx)
  100. {
  101. struct sde_mdp_pipe *pipe = NULL;
  102. static struct sde_mdp_pipe sde_pipe[16];
  103. static const u32 offset[] = {0x00025000, 0x00027000};
  104. static const u32 xin_id[] = {2, 10};
  105. static const struct sde_mdp_shared_reg_ctrl clk_ctrl[] = {
  106. {0x2AC, 8},
  107. {0x2B4, 8}
  108. };
  109. if (ndx >= ARRAY_SIZE(offset)) {
  110. SDEROT_ERR("invalid parameters\n");
  111. return ERR_PTR(-EINVAL);
  112. }
  113. pipe = &sde_pipe[ndx];
  114. pipe->num = ndx + SDE_MDP_SSPP_DMA0;
  115. pipe->offset = offset[pipe->num - SDE_MDP_SSPP_DMA0];
  116. pipe->xin_id = xin_id[pipe->num - SDE_MDP_SSPP_DMA0];
  117. pipe->base = mdata->sde_io.base + pipe->offset;
  118. pipe->type = SDE_MDP_PIPE_TYPE_DMA;
  119. pipe->mixer_left = mixer;
  120. pipe->clk_ctrl = clk_ctrl[pipe->num - SDE_MDP_SSPP_DMA0];
  121. return pipe;
  122. }
  123. int sde_mdp_pipe_destroy(struct sde_mdp_pipe *pipe)
  124. {
  125. return 0;
  126. }
  127. void sde_mdp_pipe_position_update(struct sde_mdp_pipe *pipe,
  128. struct sde_rect *src, struct sde_rect *dst)
  129. {
  130. u32 src_size, src_xy, dst_size, dst_xy;
  131. src_size = (src->h << 16) | src->w;
  132. src_xy = (src->y << 16) | src->x;
  133. dst_size = (dst->h << 16) | dst->w;
  134. dst_xy = (dst->y << 16) | dst->x;
  135. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_SIZE, src_size);
  136. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_XY, src_xy);
  137. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_OUT_SIZE, dst_size);
  138. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_OUT_XY, dst_xy);
  139. }
  140. static int sde_mdp_image_setup(struct sde_mdp_pipe *pipe,
  141. struct sde_mdp_data *data)
  142. {
  143. u32 img_size, ystride0, ystride1;
  144. u32 width, height, decimation;
  145. int ret = 0;
  146. struct sde_rect dst, src;
  147. bool rotation = false;
  148. SDEROT_DBG(
  149. "ctl: %d pnum=%d wh=%dx%d src={%d,%d,%d,%d} dst={%d,%d,%d,%d}\n",
  150. pipe->mixer_left->ctl->num, pipe->num,
  151. pipe->img_width, pipe->img_height,
  152. pipe->src.x, pipe->src.y, pipe->src.w, pipe->src.h,
  153. pipe->dst.x, pipe->dst.y, pipe->dst.w, pipe->dst.h);
  154. width = pipe->img_width;
  155. height = pipe->img_height;
  156. if (pipe->flags & SDE_SOURCE_ROTATED_90)
  157. rotation = true;
  158. sde_mdp_get_plane_sizes(pipe->src_fmt, width, height,
  159. &pipe->src_planes, pipe->bwc_mode, rotation);
  160. if (data != NULL) {
  161. ret = sde_mdp_data_check(data, &pipe->src_planes,
  162. pipe->src_fmt);
  163. if (ret)
  164. return ret;
  165. }
  166. if ((pipe->flags & SDE_DEINTERLACE) &&
  167. !(pipe->flags & SDE_SOURCE_ROTATED_90)) {
  168. int i;
  169. for (i = 0; i < pipe->src_planes.num_planes; i++)
  170. pipe->src_planes.ystride[i] *= 2;
  171. width *= 2;
  172. height /= 2;
  173. }
  174. decimation = ((1 << pipe->horz_deci) - 1) << 8;
  175. decimation |= ((1 << pipe->vert_deci) - 1);
  176. if (decimation)
  177. SDEROT_DBG("Image decimation h=%d v=%d\n",
  178. pipe->horz_deci, pipe->vert_deci);
  179. dst = pipe->dst;
  180. src = pipe->src;
  181. ystride0 = (pipe->src_planes.ystride[0]) |
  182. (pipe->src_planes.ystride[1] << 16);
  183. ystride1 = (pipe->src_planes.ystride[2]) |
  184. (pipe->src_planes.ystride[3] << 16);
  185. img_size = (height << 16) | width;
  186. sde_mdp_pipe_position_update(pipe, &src, &dst);
  187. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_IMG_SIZE, img_size);
  188. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_YSTRIDE0, ystride0);
  189. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_YSTRIDE1, ystride1);
  190. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_DECIMATION_CONFIG,
  191. decimation);
  192. return 0;
  193. }
  194. static int sde_mdp_format_setup(struct sde_mdp_pipe *pipe)
  195. {
  196. struct sde_mdp_format_params *fmt;
  197. u32 chroma_samp, unpack, src_format;
  198. u32 secure = 0;
  199. u32 opmode;
  200. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  201. fmt = pipe->src_fmt;
  202. if (pipe->flags & SDE_SECURE_OVERLAY_SESSION)
  203. secure = 0xF;
  204. opmode = pipe->bwc_mode;
  205. if (pipe->flags & SDE_FLIP_LR)
  206. opmode |= SDE_MDP_OP_FLIP_LR;
  207. if (pipe->flags & SDE_FLIP_UD)
  208. opmode |= SDE_MDP_OP_FLIP_UD;
  209. SDEROT_DBG("pnum=%d format=%d opmode=%x\n", pipe->num, fmt->format,
  210. opmode);
  211. chroma_samp = fmt->chroma_sample;
  212. if (pipe->flags & SDE_SOURCE_ROTATED_90) {
  213. if (chroma_samp == SDE_MDP_CHROMA_H2V1)
  214. chroma_samp = SDE_MDP_CHROMA_H1V2;
  215. else if (chroma_samp == SDE_MDP_CHROMA_H1V2)
  216. chroma_samp = SDE_MDP_CHROMA_H2V1;
  217. }
  218. src_format = (chroma_samp << 23) |
  219. (fmt->fetch_planes << 19) |
  220. (fmt->bits[C3_ALPHA] << 6) |
  221. (fmt->bits[C2_R_Cr] << 4) |
  222. (fmt->bits[C1_B_Cb] << 2) |
  223. (fmt->bits[C0_G_Y] << 0);
  224. if (sde_mdp_is_tilea4x_format(fmt))
  225. src_format |= BIT(30);
  226. if (sde_mdp_is_tilea5x_format(fmt))
  227. src_format |= BIT(31);
  228. if (pipe->flags & SDE_ROT_90)
  229. src_format |= BIT(11); /* ROT90 */
  230. if (fmt->alpha_enable &&
  231. fmt->fetch_planes != SDE_MDP_PLANE_INTERLEAVED)
  232. src_format |= BIT(8); /* SRCC3_EN */
  233. unpack = (fmt->element[3] << 24) | (fmt->element[2] << 16) |
  234. (fmt->element[1] << 8) | (fmt->element[0] << 0);
  235. src_format |= ((fmt->unpack_count - 1) << 12) |
  236. (fmt->unpack_tight << 17) |
  237. (fmt->unpack_align_msb << 18) |
  238. ((fmt->bpp - 1) << 9);
  239. if (sde_mdp_is_ubwc_format(fmt))
  240. opmode |= BIT(0);
  241. if (fmt->is_yuv)
  242. src_format |= BIT(15);
  243. if (fmt->frame_format != SDE_MDP_FMT_LINEAR
  244. && mdata->highest_bank_bit) {
  245. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_FETCH_CONFIG,
  246. SDE_MDP_FETCH_CONFIG_RESET_VALUE |
  247. mdata->highest_bank_bit << 18);
  248. }
  249. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_FORMAT, src_format);
  250. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_UNPACK_PATTERN, unpack);
  251. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_OP_MODE, opmode);
  252. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC_ADDR_SW_STATUS, secure);
  253. /* clear UBWC error */
  254. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_UBWC_ERROR_STATUS, BIT(31));
  255. return 0;
  256. }
  257. static int sde_mdp_src_addr_setup(struct sde_mdp_pipe *pipe,
  258. struct sde_mdp_data *src_data)
  259. {
  260. struct sde_mdp_data data = *src_data;
  261. u32 x = 0, y = 0;
  262. int ret = 0;
  263. SDEROT_DBG("pnum=%d\n", pipe->num);
  264. ret = sde_mdp_data_check(&data, &pipe->src_planes, pipe->src_fmt);
  265. if (ret)
  266. return ret;
  267. sde_rot_data_calc_offset(&data, x, y,
  268. &pipe->src_planes, pipe->src_fmt);
  269. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC0_ADDR, data.p[0].addr);
  270. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC1_ADDR, data.p[1].addr);
  271. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC2_ADDR, data.p[2].addr);
  272. sde_mdp_pipe_write(pipe, SDE_MDP_REG_SSPP_SRC3_ADDR, data.p[3].addr);
  273. return 0;
  274. }
  275. static void sde_mdp_set_ot_limit_pipe(struct sde_mdp_pipe *pipe)
  276. {
  277. struct sde_mdp_set_ot_params ot_params = {0,};
  278. ot_params.xin_id = pipe->xin_id;
  279. ot_params.num = pipe->num;
  280. ot_params.width = pipe->src.w;
  281. ot_params.height = pipe->src.h;
  282. ot_params.fps = 60;
  283. ot_params.reg_off_vbif_lim_conf = MMSS_VBIF_RD_LIM_CONF;
  284. ot_params.reg_off_mdp_clk_ctrl = pipe->clk_ctrl.reg_off;
  285. ot_params.bit_off_mdp_clk_ctrl = pipe->clk_ctrl.bit_off +
  286. CLK_FORCE_ON_OFFSET;
  287. ot_params.fmt = (pipe->src_fmt) ? pipe->src_fmt->format : 0;
  288. sde_mdp_set_ot_limit(&ot_params);
  289. }
  290. int sde_mdp_pipe_queue_data(struct sde_mdp_pipe *pipe,
  291. struct sde_mdp_data *src_data)
  292. {
  293. int ret = 0;
  294. u32 params_changed;
  295. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  296. if (!pipe) {
  297. SDEROT_ERR("pipe not setup properly for queue\n");
  298. return -ENODEV;
  299. }
  300. /*
  301. * Reprogram the pipe when there is no dedicated wfd blk and
  302. * virtual mixer is allocated for the DMA pipe during concurrent
  303. * line and block mode operations
  304. */
  305. params_changed = (pipe->params_changed);
  306. if (params_changed) {
  307. bool is_realtime = !(pipe->mixer_left->rotator_mode);
  308. sde_mdp_qos_vbif_remapper_setup(mdata, pipe, is_realtime);
  309. if (mdata->vbif_nrt_io.base)
  310. sde_mdp_pipe_nrt_vbif_setup(mdata, pipe);
  311. }
  312. if (params_changed) {
  313. pipe->params_changed = 0;
  314. ret = sde_mdp_image_setup(pipe, src_data);
  315. if (ret) {
  316. SDEROT_ERR("image setup error for pnum=%d\n",
  317. pipe->num);
  318. goto done;
  319. }
  320. ret = sde_mdp_format_setup(pipe);
  321. if (ret) {
  322. SDEROT_ERR("format %d setup error pnum=%d\n",
  323. pipe->src_fmt->format, pipe->num);
  324. goto done;
  325. }
  326. if (test_bit(SDE_QOS_PER_PIPE_LUT, mdata->sde_qos_map))
  327. sde_mdp_pipe_qos_lut(pipe);
  328. sde_mdp_set_ot_limit_pipe(pipe);
  329. }
  330. ret = sde_mdp_src_addr_setup(pipe, src_data);
  331. if (ret) {
  332. SDEROT_ERR("addr setup error for pnum=%d\n", pipe->num);
  333. goto done;
  334. }
  335. sde_mdp_mixer_pipe_update(pipe, pipe->mixer_left,
  336. params_changed);
  337. done:
  338. return ret;
  339. }