mdp5_plane.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "mdp5_kms.h"
  18. struct mdp5_plane {
  19. struct drm_plane base;
  20. const char *name;
  21. enum mdp5_pipe pipe;
  22. uint32_t nformats;
  23. uint32_t formats[32];
  24. bool enabled;
  25. };
  26. #define to_mdp5_plane(x) container_of(x, struct mdp5_plane, base)
  27. static struct mdp5_kms *get_kms(struct drm_plane *plane)
  28. {
  29. struct msm_drm_private *priv = plane->dev->dev_private;
  30. return to_mdp5_kms(to_mdp_kms(priv->kms));
  31. }
  32. static int mdp5_plane_update(struct drm_plane *plane,
  33. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  34. int crtc_x, int crtc_y,
  35. unsigned int crtc_w, unsigned int crtc_h,
  36. uint32_t src_x, uint32_t src_y,
  37. uint32_t src_w, uint32_t src_h)
  38. {
  39. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  40. mdp5_plane->enabled = true;
  41. if (plane->fb)
  42. drm_framebuffer_unreference(plane->fb);
  43. drm_framebuffer_reference(fb);
  44. return mdp5_plane_mode_set(plane, crtc, fb,
  45. crtc_x, crtc_y, crtc_w, crtc_h,
  46. src_x, src_y, src_w, src_h);
  47. }
  48. static int mdp5_plane_disable(struct drm_plane *plane)
  49. {
  50. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  51. struct mdp5_kms *mdp5_kms = get_kms(plane);
  52. enum mdp5_pipe pipe = mdp5_plane->pipe;
  53. int i;
  54. DBG("%s: disable", mdp5_plane->name);
  55. /* update our SMP request to zero (release all our blks): */
  56. for (i = 0; i < pipe2nclients(pipe); i++)
  57. mdp5_smp_request(mdp5_kms, pipe2client(pipe, i), 0);
  58. /* TODO detaching now will cause us not to get the last
  59. * vblank and mdp5_smp_commit().. so other planes will
  60. * still see smp blocks previously allocated to us as
  61. * in-use..
  62. */
  63. if (plane->crtc)
  64. mdp5_crtc_detach(plane->crtc, plane);
  65. return 0;
  66. }
  67. static void mdp5_plane_destroy(struct drm_plane *plane)
  68. {
  69. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  70. mdp5_plane_disable(plane);
  71. drm_plane_cleanup(plane);
  72. kfree(mdp5_plane);
  73. }
  74. /* helper to install properties which are common to planes and crtcs */
  75. void mdp5_plane_install_properties(struct drm_plane *plane,
  76. struct drm_mode_object *obj)
  77. {
  78. // XXX
  79. }
  80. int mdp5_plane_set_property(struct drm_plane *plane,
  81. struct drm_property *property, uint64_t val)
  82. {
  83. // XXX
  84. return -EINVAL;
  85. }
  86. static const struct drm_plane_funcs mdp5_plane_funcs = {
  87. .update_plane = mdp5_plane_update,
  88. .disable_plane = mdp5_plane_disable,
  89. .destroy = mdp5_plane_destroy,
  90. .set_property = mdp5_plane_set_property,
  91. };
  92. void mdp5_plane_set_scanout(struct drm_plane *plane,
  93. struct drm_framebuffer *fb)
  94. {
  95. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  96. struct mdp5_kms *mdp5_kms = get_kms(plane);
  97. enum mdp5_pipe pipe = mdp5_plane->pipe;
  98. uint32_t nplanes = drm_format_num_planes(fb->pixel_format);
  99. uint32_t iova[4];
  100. int i;
  101. for (i = 0; i < nplanes; i++) {
  102. struct drm_gem_object *bo = msm_framebuffer_bo(fb, i);
  103. msm_gem_get_iova(bo, mdp5_kms->id, &iova[i]);
  104. }
  105. for (; i < 4; i++)
  106. iova[i] = 0;
  107. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_STRIDE_A(pipe),
  108. MDP5_PIPE_SRC_STRIDE_A_P0(fb->pitches[0]) |
  109. MDP5_PIPE_SRC_STRIDE_A_P1(fb->pitches[1]));
  110. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_STRIDE_B(pipe),
  111. MDP5_PIPE_SRC_STRIDE_B_P2(fb->pitches[2]) |
  112. MDP5_PIPE_SRC_STRIDE_B_P3(fb->pitches[3]));
  113. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC0_ADDR(pipe), iova[0]);
  114. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC1_ADDR(pipe), iova[1]);
  115. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC2_ADDR(pipe), iova[2]);
  116. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC3_ADDR(pipe), iova[3]);
  117. plane->fb = fb;
  118. }
  119. /* NOTE: looks like if horizontal decimation is used (if we supported that)
  120. * then the width used to calculate SMP block requirements is the post-
  121. * decimated width. Ie. SMP buffering sits downstream of decimation (which
  122. * presumably happens during the dma from scanout buffer).
  123. */
  124. static int request_smp_blocks(struct drm_plane *plane, uint32_t format,
  125. uint32_t nplanes, uint32_t width)
  126. {
  127. struct drm_device *dev = plane->dev;
  128. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  129. struct mdp5_kms *mdp5_kms = get_kms(plane);
  130. enum mdp5_pipe pipe = mdp5_plane->pipe;
  131. int i, hsub, nlines, nblks, ret;
  132. hsub = drm_format_horz_chroma_subsampling(format);
  133. /* different if BWC (compressed framebuffer?) enabled: */
  134. nlines = 2;
  135. for (i = 0, nblks = 0; i < nplanes; i++) {
  136. int n, fetch_stride, cpp;
  137. cpp = drm_format_plane_cpp(format, i);
  138. fetch_stride = width * cpp / (i ? hsub : 1);
  139. n = DIV_ROUND_UP(fetch_stride * nlines, SMP_BLK_SIZE);
  140. /* for hw rev v1.00 */
  141. if (mdp5_kms->rev == 0)
  142. n = roundup_pow_of_two(n);
  143. DBG("%s[%d]: request %d SMP blocks", mdp5_plane->name, i, n);
  144. ret = mdp5_smp_request(mdp5_kms, pipe2client(pipe, i), n);
  145. if (ret) {
  146. dev_err(dev->dev, "Could not allocate %d SMP blocks: %d\n",
  147. n, ret);
  148. return ret;
  149. }
  150. nblks += n;
  151. }
  152. /* in success case, return total # of blocks allocated: */
  153. return nblks;
  154. }
  155. static void set_fifo_thresholds(struct drm_plane *plane, int nblks)
  156. {
  157. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  158. struct mdp5_kms *mdp5_kms = get_kms(plane);
  159. enum mdp5_pipe pipe = mdp5_plane->pipe;
  160. uint32_t val;
  161. /* 1/4 of SMP pool that is being fetched */
  162. val = (nblks * SMP_ENTRIES_PER_BLK) / 4;
  163. mdp5_write(mdp5_kms, REG_MDP5_PIPE_REQPRIO_FIFO_WM_0(pipe), val * 1);
  164. mdp5_write(mdp5_kms, REG_MDP5_PIPE_REQPRIO_FIFO_WM_1(pipe), val * 2);
  165. mdp5_write(mdp5_kms, REG_MDP5_PIPE_REQPRIO_FIFO_WM_2(pipe), val * 3);
  166. }
  167. int mdp5_plane_mode_set(struct drm_plane *plane,
  168. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  169. int crtc_x, int crtc_y,
  170. unsigned int crtc_w, unsigned int crtc_h,
  171. uint32_t src_x, uint32_t src_y,
  172. uint32_t src_w, uint32_t src_h)
  173. {
  174. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  175. struct mdp5_kms *mdp5_kms = get_kms(plane);
  176. enum mdp5_pipe pipe = mdp5_plane->pipe;
  177. const struct mdp_format *format;
  178. uint32_t nplanes, config = 0;
  179. uint32_t phasex_step = 0, phasey_step = 0;
  180. uint32_t hdecm = 0, vdecm = 0;
  181. int i, nblks;
  182. nplanes = drm_format_num_planes(fb->pixel_format);
  183. /* bad formats should already be rejected: */
  184. if (WARN_ON(nplanes > pipe2nclients(pipe)))
  185. return -EINVAL;
  186. /* src values are in Q16 fixed point, convert to integer: */
  187. src_x = src_x >> 16;
  188. src_y = src_y >> 16;
  189. src_w = src_w >> 16;
  190. src_h = src_h >> 16;
  191. DBG("%s: FB[%u] %u,%u,%u,%u -> CRTC[%u] %d,%d,%u,%u", mdp5_plane->name,
  192. fb->base.id, src_x, src_y, src_w, src_h,
  193. crtc->base.id, crtc_x, crtc_y, crtc_w, crtc_h);
  194. /*
  195. * Calculate and request required # of smp blocks:
  196. */
  197. nblks = request_smp_blocks(plane, fb->pixel_format, nplanes, src_w);
  198. if (nblks < 0)
  199. return nblks;
  200. /*
  201. * Currently we update the hw for allocations/requests immediately,
  202. * but once atomic modeset/pageflip is in place, the allocation
  203. * would move into atomic->check_plane_state(), while updating the
  204. * hw would remain here:
  205. */
  206. for (i = 0; i < pipe2nclients(pipe); i++)
  207. mdp5_smp_configure(mdp5_kms, pipe2client(pipe, i));
  208. if (src_w != crtc_w) {
  209. config |= MDP5_PIPE_SCALE_CONFIG_SCALEX_EN;
  210. /* TODO calc phasex_step, hdecm */
  211. }
  212. if (src_h != crtc_h) {
  213. config |= MDP5_PIPE_SCALE_CONFIG_SCALEY_EN;
  214. /* TODO calc phasey_step, vdecm */
  215. }
  216. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_IMG_SIZE(pipe),
  217. MDP5_PIPE_SRC_IMG_SIZE_WIDTH(src_w) |
  218. MDP5_PIPE_SRC_IMG_SIZE_HEIGHT(src_h));
  219. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_SIZE(pipe),
  220. MDP5_PIPE_SRC_SIZE_WIDTH(src_w) |
  221. MDP5_PIPE_SRC_SIZE_HEIGHT(src_h));
  222. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_XY(pipe),
  223. MDP5_PIPE_SRC_XY_X(src_x) |
  224. MDP5_PIPE_SRC_XY_Y(src_y));
  225. mdp5_write(mdp5_kms, REG_MDP5_PIPE_OUT_SIZE(pipe),
  226. MDP5_PIPE_OUT_SIZE_WIDTH(crtc_w) |
  227. MDP5_PIPE_OUT_SIZE_HEIGHT(crtc_h));
  228. mdp5_write(mdp5_kms, REG_MDP5_PIPE_OUT_XY(pipe),
  229. MDP5_PIPE_OUT_XY_X(crtc_x) |
  230. MDP5_PIPE_OUT_XY_Y(crtc_y));
  231. mdp5_plane_set_scanout(plane, fb);
  232. format = to_mdp_format(msm_framebuffer_format(fb));
  233. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_FORMAT(pipe),
  234. MDP5_PIPE_SRC_FORMAT_A_BPC(format->bpc_a) |
  235. MDP5_PIPE_SRC_FORMAT_R_BPC(format->bpc_r) |
  236. MDP5_PIPE_SRC_FORMAT_G_BPC(format->bpc_g) |
  237. MDP5_PIPE_SRC_FORMAT_B_BPC(format->bpc_b) |
  238. COND(format->alpha_enable, MDP5_PIPE_SRC_FORMAT_ALPHA_ENABLE) |
  239. MDP5_PIPE_SRC_FORMAT_CPP(format->cpp - 1) |
  240. MDP5_PIPE_SRC_FORMAT_UNPACK_COUNT(format->unpack_count - 1) |
  241. COND(format->unpack_tight, MDP5_PIPE_SRC_FORMAT_UNPACK_TIGHT) |
  242. MDP5_PIPE_SRC_FORMAT_NUM_PLANES(nplanes - 1) |
  243. MDP5_PIPE_SRC_FORMAT_CHROMA_SAMP(CHROMA_RGB));
  244. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_UNPACK(pipe),
  245. MDP5_PIPE_SRC_UNPACK_ELEM0(format->unpack[0]) |
  246. MDP5_PIPE_SRC_UNPACK_ELEM1(format->unpack[1]) |
  247. MDP5_PIPE_SRC_UNPACK_ELEM2(format->unpack[2]) |
  248. MDP5_PIPE_SRC_UNPACK_ELEM3(format->unpack[3]));
  249. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_OP_MODE(pipe),
  250. MDP5_PIPE_SRC_OP_MODE_BWC(BWC_LOSSLESS));
  251. /* not using secure mode: */
  252. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_ADDR_SW_STATUS(pipe), 0);
  253. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SCALE_PHASE_STEP_X(pipe), phasex_step);
  254. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SCALE_PHASE_STEP_Y(pipe), phasey_step);
  255. mdp5_write(mdp5_kms, REG_MDP5_PIPE_DECIMATION(pipe),
  256. MDP5_PIPE_DECIMATION_VERT(vdecm) |
  257. MDP5_PIPE_DECIMATION_HORZ(hdecm));
  258. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SCALE_CONFIG(pipe),
  259. MDP5_PIPE_SCALE_CONFIG_SCALEX_MIN_FILTER(SCALE_FILTER_NEAREST) |
  260. MDP5_PIPE_SCALE_CONFIG_SCALEY_MIN_FILTER(SCALE_FILTER_NEAREST) |
  261. MDP5_PIPE_SCALE_CONFIG_SCALEX_CR_FILTER(SCALE_FILTER_NEAREST) |
  262. MDP5_PIPE_SCALE_CONFIG_SCALEY_CR_FILTER(SCALE_FILTER_NEAREST) |
  263. MDP5_PIPE_SCALE_CONFIG_SCALEX_MAX_FILTER(SCALE_FILTER_NEAREST) |
  264. MDP5_PIPE_SCALE_CONFIG_SCALEY_MAX_FILTER(SCALE_FILTER_NEAREST));
  265. set_fifo_thresholds(plane, nblks);
  266. /* TODO detach from old crtc (if we had more than one) */
  267. mdp5_crtc_attach(crtc, plane);
  268. return 0;
  269. }
  270. void mdp5_plane_complete_flip(struct drm_plane *plane)
  271. {
  272. struct mdp5_kms *mdp5_kms = get_kms(plane);
  273. enum mdp5_pipe pipe = to_mdp5_plane(plane)->pipe;
  274. int i;
  275. for (i = 0; i < pipe2nclients(pipe); i++)
  276. mdp5_smp_commit(mdp5_kms, pipe2client(pipe, i));
  277. }
  278. enum mdp5_pipe mdp5_plane_pipe(struct drm_plane *plane)
  279. {
  280. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  281. return mdp5_plane->pipe;
  282. }
  283. /* initialize plane */
  284. struct drm_plane *mdp5_plane_init(struct drm_device *dev,
  285. enum mdp5_pipe pipe, bool private_plane)
  286. {
  287. struct drm_plane *plane = NULL;
  288. struct mdp5_plane *mdp5_plane;
  289. int ret;
  290. mdp5_plane = kzalloc(sizeof(*mdp5_plane), GFP_KERNEL);
  291. if (!mdp5_plane) {
  292. ret = -ENOMEM;
  293. goto fail;
  294. }
  295. plane = &mdp5_plane->base;
  296. mdp5_plane->pipe = pipe;
  297. mdp5_plane->name = pipe2name(pipe);
  298. mdp5_plane->nformats = mdp5_get_formats(pipe, mdp5_plane->formats,
  299. ARRAY_SIZE(mdp5_plane->formats));
  300. drm_plane_init(dev, plane, 0xff, &mdp5_plane_funcs,
  301. mdp5_plane->formats, mdp5_plane->nformats,
  302. private_plane);
  303. mdp5_plane_install_properties(plane, &plane->base);
  304. return plane;
  305. fail:
  306. if (plane)
  307. mdp5_plane_destroy(plane);
  308. return ERR_PTR(ret);
  309. }