mdp5_plane.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /*
  2. * Copyright (C) 2014-2015 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <drm/drm_print.h>
  19. #include "mdp5_kms.h"
  20. struct mdp5_plane {
  21. struct drm_plane base;
  22. spinlock_t pipe_lock; /* protect REG_MDP5_PIPE_* registers */
  23. uint32_t nformats;
  24. uint32_t formats[32];
  25. };
  26. #define to_mdp5_plane(x) container_of(x, struct mdp5_plane, base)
  27. static int mdp5_plane_mode_set(struct drm_plane *plane,
  28. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  29. struct drm_rect *src, struct drm_rect *dest);
  30. static int mdp5_update_cursor_plane_legacy(struct drm_plane *plane,
  31. struct drm_crtc *crtc,
  32. struct drm_framebuffer *fb,
  33. int crtc_x, int crtc_y,
  34. unsigned int crtc_w, unsigned int crtc_h,
  35. uint32_t src_x, uint32_t src_y,
  36. uint32_t src_w, uint32_t src_h,
  37. struct drm_modeset_acquire_ctx *ctx);
  38. static struct mdp5_kms *get_kms(struct drm_plane *plane)
  39. {
  40. struct msm_drm_private *priv = plane->dev->dev_private;
  41. return to_mdp5_kms(to_mdp_kms(priv->kms));
  42. }
  43. static bool plane_enabled(struct drm_plane_state *state)
  44. {
  45. return state->visible;
  46. }
  47. static void mdp5_plane_destroy(struct drm_plane *plane)
  48. {
  49. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  50. drm_plane_helper_disable(plane);
  51. drm_plane_cleanup(plane);
  52. kfree(mdp5_plane);
  53. }
  54. static void mdp5_plane_install_rotation_property(struct drm_device *dev,
  55. struct drm_plane *plane)
  56. {
  57. drm_plane_create_rotation_property(plane,
  58. DRM_ROTATE_0,
  59. DRM_ROTATE_0 |
  60. DRM_ROTATE_180 |
  61. DRM_REFLECT_X |
  62. DRM_REFLECT_Y);
  63. }
  64. /* helper to install properties which are common to planes and crtcs */
  65. static void mdp5_plane_install_properties(struct drm_plane *plane,
  66. struct drm_mode_object *obj)
  67. {
  68. struct drm_device *dev = plane->dev;
  69. struct msm_drm_private *dev_priv = dev->dev_private;
  70. struct drm_property *prop;
  71. #define INSTALL_PROPERTY(name, NAME, init_val, fnc, ...) do { \
  72. prop = dev_priv->plane_property[PLANE_PROP_##NAME]; \
  73. if (!prop) { \
  74. prop = drm_property_##fnc(dev, 0, #name, \
  75. ##__VA_ARGS__); \
  76. if (!prop) { \
  77. dev_warn(dev->dev, \
  78. "Create property %s failed\n", \
  79. #name); \
  80. return; \
  81. } \
  82. dev_priv->plane_property[PLANE_PROP_##NAME] = prop; \
  83. } \
  84. drm_object_attach_property(&plane->base, prop, init_val); \
  85. } while (0)
  86. #define INSTALL_RANGE_PROPERTY(name, NAME, min, max, init_val) \
  87. INSTALL_PROPERTY(name, NAME, init_val, \
  88. create_range, min, max)
  89. #define INSTALL_ENUM_PROPERTY(name, NAME, init_val) \
  90. INSTALL_PROPERTY(name, NAME, init_val, \
  91. create_enum, name##_prop_enum_list, \
  92. ARRAY_SIZE(name##_prop_enum_list))
  93. INSTALL_RANGE_PROPERTY(zpos, ZPOS, 1, 255, 1);
  94. mdp5_plane_install_rotation_property(dev, plane);
  95. #undef INSTALL_RANGE_PROPERTY
  96. #undef INSTALL_ENUM_PROPERTY
  97. #undef INSTALL_PROPERTY
  98. }
  99. static int mdp5_plane_atomic_set_property(struct drm_plane *plane,
  100. struct drm_plane_state *state, struct drm_property *property,
  101. uint64_t val)
  102. {
  103. struct drm_device *dev = plane->dev;
  104. struct mdp5_plane_state *pstate;
  105. struct msm_drm_private *dev_priv = dev->dev_private;
  106. int ret = 0;
  107. pstate = to_mdp5_plane_state(state);
  108. #define SET_PROPERTY(name, NAME, type) do { \
  109. if (dev_priv->plane_property[PLANE_PROP_##NAME] == property) { \
  110. pstate->name = (type)val; \
  111. DBG("Set property %s %d", #name, (type)val); \
  112. goto done; \
  113. } \
  114. } while (0)
  115. SET_PROPERTY(zpos, ZPOS, uint8_t);
  116. dev_err(dev->dev, "Invalid property\n");
  117. ret = -EINVAL;
  118. done:
  119. return ret;
  120. #undef SET_PROPERTY
  121. }
  122. static int mdp5_plane_atomic_get_property(struct drm_plane *plane,
  123. const struct drm_plane_state *state,
  124. struct drm_property *property, uint64_t *val)
  125. {
  126. struct drm_device *dev = plane->dev;
  127. struct mdp5_plane_state *pstate;
  128. struct msm_drm_private *dev_priv = dev->dev_private;
  129. int ret = 0;
  130. pstate = to_mdp5_plane_state(state);
  131. #define GET_PROPERTY(name, NAME, type) do { \
  132. if (dev_priv->plane_property[PLANE_PROP_##NAME] == property) { \
  133. *val = pstate->name; \
  134. DBG("Get property %s %lld", #name, *val); \
  135. goto done; \
  136. } \
  137. } while (0)
  138. GET_PROPERTY(zpos, ZPOS, uint8_t);
  139. dev_err(dev->dev, "Invalid property\n");
  140. ret = -EINVAL;
  141. done:
  142. return ret;
  143. #undef SET_PROPERTY
  144. }
  145. static void
  146. mdp5_plane_atomic_print_state(struct drm_printer *p,
  147. const struct drm_plane_state *state)
  148. {
  149. struct mdp5_plane_state *pstate = to_mdp5_plane_state(state);
  150. struct mdp5_kms *mdp5_kms = get_kms(state->plane);
  151. drm_printf(p, "\thwpipe=%s\n", pstate->hwpipe ?
  152. pstate->hwpipe->name : "(null)");
  153. if (mdp5_kms->caps & MDP_CAP_SRC_SPLIT)
  154. drm_printf(p, "\tright-hwpipe=%s\n",
  155. pstate->r_hwpipe ? pstate->r_hwpipe->name :
  156. "(null)");
  157. drm_printf(p, "\tpremultiplied=%u\n", pstate->premultiplied);
  158. drm_printf(p, "\tzpos=%u\n", pstate->zpos);
  159. drm_printf(p, "\talpha=%u\n", pstate->alpha);
  160. drm_printf(p, "\tstage=%s\n", stage2name(pstate->stage));
  161. }
  162. static void mdp5_plane_reset(struct drm_plane *plane)
  163. {
  164. struct mdp5_plane_state *mdp5_state;
  165. if (plane->state && plane->state->fb)
  166. drm_framebuffer_unreference(plane->state->fb);
  167. kfree(to_mdp5_plane_state(plane->state));
  168. mdp5_state = kzalloc(sizeof(*mdp5_state), GFP_KERNEL);
  169. /* assign default blend parameters */
  170. mdp5_state->alpha = 255;
  171. mdp5_state->premultiplied = 0;
  172. if (plane->type == DRM_PLANE_TYPE_PRIMARY)
  173. mdp5_state->zpos = STAGE_BASE;
  174. else
  175. mdp5_state->zpos = STAGE0 + drm_plane_index(plane);
  176. mdp5_state->base.plane = plane;
  177. plane->state = &mdp5_state->base;
  178. }
  179. static struct drm_plane_state *
  180. mdp5_plane_duplicate_state(struct drm_plane *plane)
  181. {
  182. struct mdp5_plane_state *mdp5_state;
  183. if (WARN_ON(!plane->state))
  184. return NULL;
  185. mdp5_state = kmemdup(to_mdp5_plane_state(plane->state),
  186. sizeof(*mdp5_state), GFP_KERNEL);
  187. if (!mdp5_state)
  188. return NULL;
  189. __drm_atomic_helper_plane_duplicate_state(plane, &mdp5_state->base);
  190. return &mdp5_state->base;
  191. }
  192. static void mdp5_plane_destroy_state(struct drm_plane *plane,
  193. struct drm_plane_state *state)
  194. {
  195. struct mdp5_plane_state *pstate = to_mdp5_plane_state(state);
  196. if (state->fb)
  197. drm_framebuffer_unreference(state->fb);
  198. kfree(pstate);
  199. }
  200. static const struct drm_plane_funcs mdp5_plane_funcs = {
  201. .update_plane = drm_atomic_helper_update_plane,
  202. .disable_plane = drm_atomic_helper_disable_plane,
  203. .destroy = mdp5_plane_destroy,
  204. .set_property = drm_atomic_helper_plane_set_property,
  205. .atomic_set_property = mdp5_plane_atomic_set_property,
  206. .atomic_get_property = mdp5_plane_atomic_get_property,
  207. .reset = mdp5_plane_reset,
  208. .atomic_duplicate_state = mdp5_plane_duplicate_state,
  209. .atomic_destroy_state = mdp5_plane_destroy_state,
  210. .atomic_print_state = mdp5_plane_atomic_print_state,
  211. };
  212. static const struct drm_plane_funcs mdp5_cursor_plane_funcs = {
  213. .update_plane = mdp5_update_cursor_plane_legacy,
  214. .disable_plane = drm_atomic_helper_disable_plane,
  215. .destroy = mdp5_plane_destroy,
  216. .set_property = drm_atomic_helper_plane_set_property,
  217. .atomic_set_property = mdp5_plane_atomic_set_property,
  218. .atomic_get_property = mdp5_plane_atomic_get_property,
  219. .reset = mdp5_plane_reset,
  220. .atomic_duplicate_state = mdp5_plane_duplicate_state,
  221. .atomic_destroy_state = mdp5_plane_destroy_state,
  222. .atomic_print_state = mdp5_plane_atomic_print_state,
  223. };
  224. static int mdp5_plane_prepare_fb(struct drm_plane *plane,
  225. struct drm_plane_state *new_state)
  226. {
  227. struct mdp5_kms *mdp5_kms = get_kms(plane);
  228. struct drm_framebuffer *fb = new_state->fb;
  229. if (!new_state->fb)
  230. return 0;
  231. DBG("%s: prepare: FB[%u]", plane->name, fb->base.id);
  232. return msm_framebuffer_prepare(fb, mdp5_kms->id);
  233. }
  234. static void mdp5_plane_cleanup_fb(struct drm_plane *plane,
  235. struct drm_plane_state *old_state)
  236. {
  237. struct mdp5_kms *mdp5_kms = get_kms(plane);
  238. struct drm_framebuffer *fb = old_state->fb;
  239. if (!fb)
  240. return;
  241. DBG("%s: cleanup: FB[%u]", plane->name, fb->base.id);
  242. msm_framebuffer_cleanup(fb, mdp5_kms->id);
  243. }
  244. #define FRAC_16_16(mult, div) (((mult) << 16) / (div))
  245. static int mdp5_plane_atomic_check_with_state(struct drm_crtc_state *crtc_state,
  246. struct drm_plane_state *state)
  247. {
  248. struct mdp5_plane_state *mdp5_state = to_mdp5_plane_state(state);
  249. struct drm_plane *plane = state->plane;
  250. struct drm_plane_state *old_state = plane->state;
  251. struct mdp5_cfg *config = mdp5_cfg_get_config(get_kms(plane)->cfg);
  252. bool new_hwpipe = false;
  253. bool need_right_hwpipe = false;
  254. uint32_t max_width, max_height;
  255. bool out_of_bounds = false;
  256. uint32_t caps = 0;
  257. struct drm_rect clip;
  258. int min_scale, max_scale;
  259. int ret;
  260. DBG("%s: check (%d -> %d)", plane->name,
  261. plane_enabled(old_state), plane_enabled(state));
  262. max_width = config->hw->lm.max_width << 16;
  263. max_height = config->hw->lm.max_height << 16;
  264. /* Make sure source dimensions are within bounds. */
  265. if (state->src_h > max_height)
  266. out_of_bounds = true;
  267. if (state->src_w > max_width) {
  268. /* If source split is supported, we can go up to 2x
  269. * the max LM width, but we'd need to stage another
  270. * hwpipe to the right LM. So, the drm_plane would
  271. * consist of 2 hwpipes.
  272. */
  273. if (config->hw->mdp.caps & MDP_CAP_SRC_SPLIT &&
  274. (state->src_w <= 2 * max_width))
  275. need_right_hwpipe = true;
  276. else
  277. out_of_bounds = true;
  278. }
  279. if (out_of_bounds) {
  280. struct drm_rect src = drm_plane_state_src(state);
  281. DBG("Invalid source size "DRM_RECT_FP_FMT,
  282. DRM_RECT_FP_ARG(&src));
  283. return -ERANGE;
  284. }
  285. clip.x1 = 0;
  286. clip.y1 = 0;
  287. clip.x2 = crtc_state->adjusted_mode.hdisplay;
  288. clip.y2 = crtc_state->adjusted_mode.vdisplay;
  289. min_scale = FRAC_16_16(1, 8);
  290. max_scale = FRAC_16_16(8, 1);
  291. ret = drm_plane_helper_check_state(state, &clip, min_scale,
  292. max_scale, true, true);
  293. if (ret)
  294. return ret;
  295. if (plane_enabled(state)) {
  296. unsigned int rotation;
  297. const struct mdp_format *format;
  298. struct mdp5_kms *mdp5_kms = get_kms(plane);
  299. uint32_t blkcfg = 0;
  300. format = to_mdp_format(msm_framebuffer_format(state->fb));
  301. if (MDP_FORMAT_IS_YUV(format))
  302. caps |= MDP_PIPE_CAP_SCALE | MDP_PIPE_CAP_CSC;
  303. if (((state->src_w >> 16) != state->crtc_w) ||
  304. ((state->src_h >> 16) != state->crtc_h))
  305. caps |= MDP_PIPE_CAP_SCALE;
  306. rotation = drm_rotation_simplify(state->rotation,
  307. DRM_ROTATE_0 |
  308. DRM_REFLECT_X |
  309. DRM_REFLECT_Y);
  310. if (rotation & DRM_REFLECT_X)
  311. caps |= MDP_PIPE_CAP_HFLIP;
  312. if (rotation & DRM_REFLECT_Y)
  313. caps |= MDP_PIPE_CAP_VFLIP;
  314. if (plane->type == DRM_PLANE_TYPE_CURSOR)
  315. caps |= MDP_PIPE_CAP_CURSOR;
  316. /* (re)allocate hw pipe if we don't have one or caps-mismatch: */
  317. if (!mdp5_state->hwpipe || (caps & ~mdp5_state->hwpipe->caps))
  318. new_hwpipe = true;
  319. /*
  320. * (re)allocte hw pipe if we're either requesting for 2 hw pipes
  321. * or we're switching from 2 hw pipes to 1 hw pipe because the
  322. * new src_w can be supported by 1 hw pipe itself.
  323. */
  324. if ((need_right_hwpipe && !mdp5_state->r_hwpipe) ||
  325. (!need_right_hwpipe && mdp5_state->r_hwpipe))
  326. new_hwpipe = true;
  327. if (mdp5_kms->smp) {
  328. const struct mdp_format *format =
  329. to_mdp_format(msm_framebuffer_format(state->fb));
  330. blkcfg = mdp5_smp_calculate(mdp5_kms->smp, format,
  331. state->src_w >> 16, false);
  332. if (mdp5_state->hwpipe && (mdp5_state->hwpipe->blkcfg != blkcfg))
  333. new_hwpipe = true;
  334. }
  335. /* (re)assign hwpipe if needed, otherwise keep old one: */
  336. if (new_hwpipe) {
  337. /* TODO maybe we want to re-assign hwpipe sometimes
  338. * in cases when we no-longer need some caps to make
  339. * it available for other planes?
  340. */
  341. struct mdp5_hw_pipe *old_hwpipe = mdp5_state->hwpipe;
  342. struct mdp5_hw_pipe *old_right_hwpipe =
  343. mdp5_state->r_hwpipe;
  344. mdp5_state->hwpipe = mdp5_pipe_assign(state->state,
  345. plane, caps, blkcfg);
  346. if (IS_ERR(mdp5_state->hwpipe)) {
  347. DBG("%s: failed to assign hwpipe!", plane->name);
  348. return PTR_ERR(mdp5_state->hwpipe);
  349. }
  350. if (need_right_hwpipe) {
  351. mdp5_state->r_hwpipe =
  352. mdp5_pipe_assign(state->state, plane,
  353. caps, blkcfg);
  354. if (IS_ERR(mdp5_state->r_hwpipe)) {
  355. DBG("%s: failed to assign right hwpipe",
  356. plane->name);
  357. return PTR_ERR(mdp5_state->r_hwpipe);
  358. }
  359. } else {
  360. /*
  361. * set it to NULL so that the driver knows we
  362. * don't have a right hwpipe when committing a
  363. * new state
  364. */
  365. mdp5_state->r_hwpipe = NULL;
  366. }
  367. mdp5_pipe_release(state->state, old_hwpipe);
  368. mdp5_pipe_release(state->state, old_right_hwpipe);
  369. }
  370. } else {
  371. mdp5_pipe_release(state->state, mdp5_state->hwpipe);
  372. mdp5_pipe_release(state->state, mdp5_state->r_hwpipe);
  373. mdp5_state->hwpipe = mdp5_state->r_hwpipe = NULL;
  374. }
  375. return 0;
  376. }
  377. static int mdp5_plane_atomic_check(struct drm_plane *plane,
  378. struct drm_plane_state *state)
  379. {
  380. struct drm_crtc *crtc;
  381. struct drm_crtc_state *crtc_state;
  382. crtc = state->crtc ? state->crtc : plane->state->crtc;
  383. if (!crtc)
  384. return 0;
  385. crtc_state = drm_atomic_get_existing_crtc_state(state->state, crtc);
  386. if (WARN_ON(!crtc_state))
  387. return -EINVAL;
  388. return mdp5_plane_atomic_check_with_state(crtc_state, state);
  389. }
  390. static void mdp5_plane_atomic_update(struct drm_plane *plane,
  391. struct drm_plane_state *old_state)
  392. {
  393. struct drm_plane_state *state = plane->state;
  394. DBG("%s: update", plane->name);
  395. if (plane_enabled(state)) {
  396. int ret;
  397. ret = mdp5_plane_mode_set(plane,
  398. state->crtc, state->fb,
  399. &state->src, &state->dst);
  400. /* atomic_check should have ensured that this doesn't fail */
  401. WARN_ON(ret < 0);
  402. }
  403. }
  404. static const struct drm_plane_helper_funcs mdp5_plane_helper_funcs = {
  405. .prepare_fb = mdp5_plane_prepare_fb,
  406. .cleanup_fb = mdp5_plane_cleanup_fb,
  407. .atomic_check = mdp5_plane_atomic_check,
  408. .atomic_update = mdp5_plane_atomic_update,
  409. };
  410. static void set_scanout_locked(struct mdp5_kms *mdp5_kms,
  411. enum mdp5_pipe pipe,
  412. struct drm_framebuffer *fb)
  413. {
  414. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_STRIDE_A(pipe),
  415. MDP5_PIPE_SRC_STRIDE_A_P0(fb->pitches[0]) |
  416. MDP5_PIPE_SRC_STRIDE_A_P1(fb->pitches[1]));
  417. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_STRIDE_B(pipe),
  418. MDP5_PIPE_SRC_STRIDE_B_P2(fb->pitches[2]) |
  419. MDP5_PIPE_SRC_STRIDE_B_P3(fb->pitches[3]));
  420. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC0_ADDR(pipe),
  421. msm_framebuffer_iova(fb, mdp5_kms->id, 0));
  422. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC1_ADDR(pipe),
  423. msm_framebuffer_iova(fb, mdp5_kms->id, 1));
  424. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC2_ADDR(pipe),
  425. msm_framebuffer_iova(fb, mdp5_kms->id, 2));
  426. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC3_ADDR(pipe),
  427. msm_framebuffer_iova(fb, mdp5_kms->id, 3));
  428. }
  429. /* Note: mdp5_plane->pipe_lock must be locked */
  430. static void csc_disable(struct mdp5_kms *mdp5_kms, enum mdp5_pipe pipe)
  431. {
  432. uint32_t value = mdp5_read(mdp5_kms, REG_MDP5_PIPE_OP_MODE(pipe)) &
  433. ~MDP5_PIPE_OP_MODE_CSC_1_EN;
  434. mdp5_write(mdp5_kms, REG_MDP5_PIPE_OP_MODE(pipe), value);
  435. }
  436. /* Note: mdp5_plane->pipe_lock must be locked */
  437. static void csc_enable(struct mdp5_kms *mdp5_kms, enum mdp5_pipe pipe,
  438. struct csc_cfg *csc)
  439. {
  440. uint32_t i, mode = 0; /* RGB, no CSC */
  441. uint32_t *matrix;
  442. if (unlikely(!csc))
  443. return;
  444. if ((csc->type == CSC_YUV2RGB) || (CSC_YUV2YUV == csc->type))
  445. mode |= MDP5_PIPE_OP_MODE_CSC_SRC_DATA_FORMAT(DATA_FORMAT_YUV);
  446. if ((csc->type == CSC_RGB2YUV) || (CSC_YUV2YUV == csc->type))
  447. mode |= MDP5_PIPE_OP_MODE_CSC_DST_DATA_FORMAT(DATA_FORMAT_YUV);
  448. mode |= MDP5_PIPE_OP_MODE_CSC_1_EN;
  449. mdp5_write(mdp5_kms, REG_MDP5_PIPE_OP_MODE(pipe), mode);
  450. matrix = csc->matrix;
  451. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_MATRIX_COEFF_0(pipe),
  452. MDP5_PIPE_CSC_1_MATRIX_COEFF_0_COEFF_11(matrix[0]) |
  453. MDP5_PIPE_CSC_1_MATRIX_COEFF_0_COEFF_12(matrix[1]));
  454. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_MATRIX_COEFF_1(pipe),
  455. MDP5_PIPE_CSC_1_MATRIX_COEFF_1_COEFF_13(matrix[2]) |
  456. MDP5_PIPE_CSC_1_MATRIX_COEFF_1_COEFF_21(matrix[3]));
  457. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_MATRIX_COEFF_2(pipe),
  458. MDP5_PIPE_CSC_1_MATRIX_COEFF_2_COEFF_22(matrix[4]) |
  459. MDP5_PIPE_CSC_1_MATRIX_COEFF_2_COEFF_23(matrix[5]));
  460. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_MATRIX_COEFF_3(pipe),
  461. MDP5_PIPE_CSC_1_MATRIX_COEFF_3_COEFF_31(matrix[6]) |
  462. MDP5_PIPE_CSC_1_MATRIX_COEFF_3_COEFF_32(matrix[7]));
  463. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_MATRIX_COEFF_4(pipe),
  464. MDP5_PIPE_CSC_1_MATRIX_COEFF_4_COEFF_33(matrix[8]));
  465. for (i = 0; i < ARRAY_SIZE(csc->pre_bias); i++) {
  466. uint32_t *pre_clamp = csc->pre_clamp;
  467. uint32_t *post_clamp = csc->post_clamp;
  468. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_PRE_CLAMP(pipe, i),
  469. MDP5_PIPE_CSC_1_PRE_CLAMP_REG_HIGH(pre_clamp[2*i+1]) |
  470. MDP5_PIPE_CSC_1_PRE_CLAMP_REG_LOW(pre_clamp[2*i]));
  471. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_POST_CLAMP(pipe, i),
  472. MDP5_PIPE_CSC_1_POST_CLAMP_REG_HIGH(post_clamp[2*i+1]) |
  473. MDP5_PIPE_CSC_1_POST_CLAMP_REG_LOW(post_clamp[2*i]));
  474. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_PRE_BIAS(pipe, i),
  475. MDP5_PIPE_CSC_1_PRE_BIAS_REG_VALUE(csc->pre_bias[i]));
  476. mdp5_write(mdp5_kms, REG_MDP5_PIPE_CSC_1_POST_BIAS(pipe, i),
  477. MDP5_PIPE_CSC_1_POST_BIAS_REG_VALUE(csc->post_bias[i]));
  478. }
  479. }
  480. #define PHASE_STEP_SHIFT 21
  481. #define DOWN_SCALE_RATIO_MAX 32 /* 2^(26-21) */
  482. static int calc_phase_step(uint32_t src, uint32_t dst, uint32_t *out_phase)
  483. {
  484. uint32_t unit;
  485. if (src == 0 || dst == 0)
  486. return -EINVAL;
  487. /*
  488. * PHASE_STEP_X/Y is coded on 26 bits (25:0),
  489. * where 2^21 represents the unity "1" in fixed-point hardware design.
  490. * This leaves 5 bits for the integer part (downscale case):
  491. * -> maximum downscale ratio = 0b1_1111 = 31
  492. */
  493. if (src > (dst * DOWN_SCALE_RATIO_MAX))
  494. return -EOVERFLOW;
  495. unit = 1 << PHASE_STEP_SHIFT;
  496. *out_phase = mult_frac(unit, src, dst);
  497. return 0;
  498. }
  499. static int calc_scalex_steps(struct drm_plane *plane,
  500. uint32_t pixel_format, uint32_t src, uint32_t dest,
  501. uint32_t phasex_steps[COMP_MAX])
  502. {
  503. struct mdp5_kms *mdp5_kms = get_kms(plane);
  504. struct device *dev = mdp5_kms->dev->dev;
  505. uint32_t phasex_step;
  506. unsigned int hsub;
  507. int ret;
  508. ret = calc_phase_step(src, dest, &phasex_step);
  509. if (ret) {
  510. dev_err(dev, "X scaling (%d->%d) failed: %d\n", src, dest, ret);
  511. return ret;
  512. }
  513. hsub = drm_format_horz_chroma_subsampling(pixel_format);
  514. phasex_steps[COMP_0] = phasex_step;
  515. phasex_steps[COMP_3] = phasex_step;
  516. phasex_steps[COMP_1_2] = phasex_step / hsub;
  517. return 0;
  518. }
  519. static int calc_scaley_steps(struct drm_plane *plane,
  520. uint32_t pixel_format, uint32_t src, uint32_t dest,
  521. uint32_t phasey_steps[COMP_MAX])
  522. {
  523. struct mdp5_kms *mdp5_kms = get_kms(plane);
  524. struct device *dev = mdp5_kms->dev->dev;
  525. uint32_t phasey_step;
  526. unsigned int vsub;
  527. int ret;
  528. ret = calc_phase_step(src, dest, &phasey_step);
  529. if (ret) {
  530. dev_err(dev, "Y scaling (%d->%d) failed: %d\n", src, dest, ret);
  531. return ret;
  532. }
  533. vsub = drm_format_vert_chroma_subsampling(pixel_format);
  534. phasey_steps[COMP_0] = phasey_step;
  535. phasey_steps[COMP_3] = phasey_step;
  536. phasey_steps[COMP_1_2] = phasey_step / vsub;
  537. return 0;
  538. }
  539. static uint32_t get_scale_config(const struct mdp_format *format,
  540. uint32_t src, uint32_t dst, bool horz)
  541. {
  542. bool scaling = format->is_yuv ? true : (src != dst);
  543. uint32_t sub, pix_fmt = format->base.pixel_format;
  544. uint32_t ya_filter, uv_filter;
  545. bool yuv = format->is_yuv;
  546. if (!scaling)
  547. return 0;
  548. if (yuv) {
  549. sub = horz ? drm_format_horz_chroma_subsampling(pix_fmt) :
  550. drm_format_vert_chroma_subsampling(pix_fmt);
  551. uv_filter = ((src / sub) <= dst) ?
  552. SCALE_FILTER_BIL : SCALE_FILTER_PCMN;
  553. }
  554. ya_filter = (src <= dst) ? SCALE_FILTER_BIL : SCALE_FILTER_PCMN;
  555. if (horz)
  556. return MDP5_PIPE_SCALE_CONFIG_SCALEX_EN |
  557. MDP5_PIPE_SCALE_CONFIG_SCALEX_FILTER_COMP_0(ya_filter) |
  558. MDP5_PIPE_SCALE_CONFIG_SCALEX_FILTER_COMP_3(ya_filter) |
  559. COND(yuv, MDP5_PIPE_SCALE_CONFIG_SCALEX_FILTER_COMP_1_2(uv_filter));
  560. else
  561. return MDP5_PIPE_SCALE_CONFIG_SCALEY_EN |
  562. MDP5_PIPE_SCALE_CONFIG_SCALEY_FILTER_COMP_0(ya_filter) |
  563. MDP5_PIPE_SCALE_CONFIG_SCALEY_FILTER_COMP_3(ya_filter) |
  564. COND(yuv, MDP5_PIPE_SCALE_CONFIG_SCALEY_FILTER_COMP_1_2(uv_filter));
  565. }
  566. static void calc_pixel_ext(const struct mdp_format *format,
  567. uint32_t src, uint32_t dst, uint32_t phase_step[2],
  568. int pix_ext_edge1[COMP_MAX], int pix_ext_edge2[COMP_MAX],
  569. bool horz)
  570. {
  571. bool scaling = format->is_yuv ? true : (src != dst);
  572. int i;
  573. /*
  574. * Note:
  575. * We assume here that:
  576. * 1. PCMN filter is used for downscale
  577. * 2. bilinear filter is used for upscale
  578. * 3. we are in a single pipe configuration
  579. */
  580. for (i = 0; i < COMP_MAX; i++) {
  581. pix_ext_edge1[i] = 0;
  582. pix_ext_edge2[i] = scaling ? 1 : 0;
  583. }
  584. }
  585. static void mdp5_write_pixel_ext(struct mdp5_kms *mdp5_kms, enum mdp5_pipe pipe,
  586. const struct mdp_format *format,
  587. uint32_t src_w, int pe_left[COMP_MAX], int pe_right[COMP_MAX],
  588. uint32_t src_h, int pe_top[COMP_MAX], int pe_bottom[COMP_MAX])
  589. {
  590. uint32_t pix_fmt = format->base.pixel_format;
  591. uint32_t lr, tb, req;
  592. int i;
  593. for (i = 0; i < COMP_MAX; i++) {
  594. uint32_t roi_w = src_w;
  595. uint32_t roi_h = src_h;
  596. if (format->is_yuv && i == COMP_1_2) {
  597. roi_w /= drm_format_horz_chroma_subsampling(pix_fmt);
  598. roi_h /= drm_format_vert_chroma_subsampling(pix_fmt);
  599. }
  600. lr = (pe_left[i] >= 0) ?
  601. MDP5_PIPE_SW_PIX_EXT_LR_LEFT_RPT(pe_left[i]) :
  602. MDP5_PIPE_SW_PIX_EXT_LR_LEFT_OVF(pe_left[i]);
  603. lr |= (pe_right[i] >= 0) ?
  604. MDP5_PIPE_SW_PIX_EXT_LR_RIGHT_RPT(pe_right[i]) :
  605. MDP5_PIPE_SW_PIX_EXT_LR_RIGHT_OVF(pe_right[i]);
  606. tb = (pe_top[i] >= 0) ?
  607. MDP5_PIPE_SW_PIX_EXT_TB_TOP_RPT(pe_top[i]) :
  608. MDP5_PIPE_SW_PIX_EXT_TB_TOP_OVF(pe_top[i]);
  609. tb |= (pe_bottom[i] >= 0) ?
  610. MDP5_PIPE_SW_PIX_EXT_TB_BOTTOM_RPT(pe_bottom[i]) :
  611. MDP5_PIPE_SW_PIX_EXT_TB_BOTTOM_OVF(pe_bottom[i]);
  612. req = MDP5_PIPE_SW_PIX_EXT_REQ_PIXELS_LEFT_RIGHT(roi_w +
  613. pe_left[i] + pe_right[i]);
  614. req |= MDP5_PIPE_SW_PIX_EXT_REQ_PIXELS_TOP_BOTTOM(roi_h +
  615. pe_top[i] + pe_bottom[i]);
  616. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SW_PIX_EXT_LR(pipe, i), lr);
  617. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SW_PIX_EXT_TB(pipe, i), tb);
  618. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SW_PIX_EXT_REQ_PIXELS(pipe, i), req);
  619. DBG("comp-%d (L/R): rpt=%d/%d, ovf=%d/%d, req=%d", i,
  620. FIELD(lr, MDP5_PIPE_SW_PIX_EXT_LR_LEFT_RPT),
  621. FIELD(lr, MDP5_PIPE_SW_PIX_EXT_LR_RIGHT_RPT),
  622. FIELD(lr, MDP5_PIPE_SW_PIX_EXT_LR_LEFT_OVF),
  623. FIELD(lr, MDP5_PIPE_SW_PIX_EXT_LR_RIGHT_OVF),
  624. FIELD(req, MDP5_PIPE_SW_PIX_EXT_REQ_PIXELS_LEFT_RIGHT));
  625. DBG("comp-%d (T/B): rpt=%d/%d, ovf=%d/%d, req=%d", i,
  626. FIELD(tb, MDP5_PIPE_SW_PIX_EXT_TB_TOP_RPT),
  627. FIELD(tb, MDP5_PIPE_SW_PIX_EXT_TB_BOTTOM_RPT),
  628. FIELD(tb, MDP5_PIPE_SW_PIX_EXT_TB_TOP_OVF),
  629. FIELD(tb, MDP5_PIPE_SW_PIX_EXT_TB_BOTTOM_OVF),
  630. FIELD(req, MDP5_PIPE_SW_PIX_EXT_REQ_PIXELS_TOP_BOTTOM));
  631. }
  632. }
  633. struct pixel_ext {
  634. int left[COMP_MAX];
  635. int right[COMP_MAX];
  636. int top[COMP_MAX];
  637. int bottom[COMP_MAX];
  638. };
  639. struct phase_step {
  640. u32 x[COMP_MAX];
  641. u32 y[COMP_MAX];
  642. };
  643. static void mdp5_hwpipe_mode_set(struct mdp5_kms *mdp5_kms,
  644. struct mdp5_hw_pipe *hwpipe,
  645. struct drm_framebuffer *fb,
  646. struct phase_step *step,
  647. struct pixel_ext *pe,
  648. u32 scale_config, u32 hdecm, u32 vdecm,
  649. bool hflip, bool vflip,
  650. int crtc_x, int crtc_y,
  651. unsigned int crtc_w, unsigned int crtc_h,
  652. u32 src_img_w, u32 src_img_h,
  653. u32 src_x, u32 src_y,
  654. u32 src_w, u32 src_h)
  655. {
  656. enum mdp5_pipe pipe = hwpipe->pipe;
  657. bool has_pe = hwpipe->caps & MDP_PIPE_CAP_SW_PIX_EXT;
  658. const struct mdp_format *format =
  659. to_mdp_format(msm_framebuffer_format(fb));
  660. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_IMG_SIZE(pipe),
  661. MDP5_PIPE_SRC_IMG_SIZE_WIDTH(src_img_w) |
  662. MDP5_PIPE_SRC_IMG_SIZE_HEIGHT(src_img_h));
  663. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_SIZE(pipe),
  664. MDP5_PIPE_SRC_SIZE_WIDTH(src_w) |
  665. MDP5_PIPE_SRC_SIZE_HEIGHT(src_h));
  666. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_XY(pipe),
  667. MDP5_PIPE_SRC_XY_X(src_x) |
  668. MDP5_PIPE_SRC_XY_Y(src_y));
  669. mdp5_write(mdp5_kms, REG_MDP5_PIPE_OUT_SIZE(pipe),
  670. MDP5_PIPE_OUT_SIZE_WIDTH(crtc_w) |
  671. MDP5_PIPE_OUT_SIZE_HEIGHT(crtc_h));
  672. mdp5_write(mdp5_kms, REG_MDP5_PIPE_OUT_XY(pipe),
  673. MDP5_PIPE_OUT_XY_X(crtc_x) |
  674. MDP5_PIPE_OUT_XY_Y(crtc_y));
  675. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_FORMAT(pipe),
  676. MDP5_PIPE_SRC_FORMAT_A_BPC(format->bpc_a) |
  677. MDP5_PIPE_SRC_FORMAT_R_BPC(format->bpc_r) |
  678. MDP5_PIPE_SRC_FORMAT_G_BPC(format->bpc_g) |
  679. MDP5_PIPE_SRC_FORMAT_B_BPC(format->bpc_b) |
  680. COND(format->alpha_enable, MDP5_PIPE_SRC_FORMAT_ALPHA_ENABLE) |
  681. MDP5_PIPE_SRC_FORMAT_CPP(format->cpp - 1) |
  682. MDP5_PIPE_SRC_FORMAT_UNPACK_COUNT(format->unpack_count - 1) |
  683. COND(format->unpack_tight, MDP5_PIPE_SRC_FORMAT_UNPACK_TIGHT) |
  684. MDP5_PIPE_SRC_FORMAT_FETCH_TYPE(format->fetch_type) |
  685. MDP5_PIPE_SRC_FORMAT_CHROMA_SAMP(format->chroma_sample));
  686. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_UNPACK(pipe),
  687. MDP5_PIPE_SRC_UNPACK_ELEM0(format->unpack[0]) |
  688. MDP5_PIPE_SRC_UNPACK_ELEM1(format->unpack[1]) |
  689. MDP5_PIPE_SRC_UNPACK_ELEM2(format->unpack[2]) |
  690. MDP5_PIPE_SRC_UNPACK_ELEM3(format->unpack[3]));
  691. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_OP_MODE(pipe),
  692. (hflip ? MDP5_PIPE_SRC_OP_MODE_FLIP_LR : 0) |
  693. (vflip ? MDP5_PIPE_SRC_OP_MODE_FLIP_UD : 0) |
  694. COND(has_pe, MDP5_PIPE_SRC_OP_MODE_SW_PIX_EXT_OVERRIDE) |
  695. MDP5_PIPE_SRC_OP_MODE_BWC(BWC_LOSSLESS));
  696. /* not using secure mode: */
  697. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SRC_ADDR_SW_STATUS(pipe), 0);
  698. if (hwpipe->caps & MDP_PIPE_CAP_SW_PIX_EXT)
  699. mdp5_write_pixel_ext(mdp5_kms, pipe, format,
  700. src_w, pe->left, pe->right,
  701. src_h, pe->top, pe->bottom);
  702. if (hwpipe->caps & MDP_PIPE_CAP_SCALE) {
  703. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SCALE_PHASE_STEP_X(pipe),
  704. step->x[COMP_0]);
  705. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SCALE_PHASE_STEP_Y(pipe),
  706. step->y[COMP_0]);
  707. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SCALE_CR_PHASE_STEP_X(pipe),
  708. step->x[COMP_1_2]);
  709. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SCALE_CR_PHASE_STEP_Y(pipe),
  710. step->y[COMP_1_2]);
  711. mdp5_write(mdp5_kms, REG_MDP5_PIPE_DECIMATION(pipe),
  712. MDP5_PIPE_DECIMATION_VERT(vdecm) |
  713. MDP5_PIPE_DECIMATION_HORZ(hdecm));
  714. mdp5_write(mdp5_kms, REG_MDP5_PIPE_SCALE_CONFIG(pipe),
  715. scale_config);
  716. }
  717. if (hwpipe->caps & MDP_PIPE_CAP_CSC) {
  718. if (MDP_FORMAT_IS_YUV(format))
  719. csc_enable(mdp5_kms, pipe,
  720. mdp_get_default_csc_cfg(CSC_YUV2RGB));
  721. else
  722. csc_disable(mdp5_kms, pipe);
  723. }
  724. set_scanout_locked(mdp5_kms, pipe, fb);
  725. }
  726. static int mdp5_plane_mode_set(struct drm_plane *plane,
  727. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  728. struct drm_rect *src, struct drm_rect *dest)
  729. {
  730. struct mdp5_plane *mdp5_plane = to_mdp5_plane(plane);
  731. struct drm_plane_state *pstate = plane->state;
  732. struct mdp5_hw_pipe *hwpipe = to_mdp5_plane_state(pstate)->hwpipe;
  733. struct mdp5_kms *mdp5_kms = get_kms(plane);
  734. enum mdp5_pipe pipe = hwpipe->pipe;
  735. struct mdp5_hw_pipe *right_hwpipe;
  736. const struct mdp_format *format;
  737. uint32_t nplanes, config = 0;
  738. struct phase_step step = { 0 };
  739. struct pixel_ext pe = { 0 };
  740. uint32_t hdecm = 0, vdecm = 0;
  741. uint32_t pix_format;
  742. unsigned int rotation;
  743. bool vflip, hflip;
  744. int crtc_x, crtc_y;
  745. unsigned int crtc_w, crtc_h;
  746. uint32_t src_x, src_y;
  747. uint32_t src_w, src_h;
  748. uint32_t src_img_w, src_img_h;
  749. uint32_t src_x_r;
  750. int crtc_x_r;
  751. unsigned long flags;
  752. int ret;
  753. nplanes = fb->format->num_planes;
  754. /* bad formats should already be rejected: */
  755. if (WARN_ON(nplanes > pipe2nclients(pipe)))
  756. return -EINVAL;
  757. format = to_mdp_format(msm_framebuffer_format(fb));
  758. pix_format = format->base.pixel_format;
  759. src_x = src->x1;
  760. src_y = src->y1;
  761. src_w = drm_rect_width(src);
  762. src_h = drm_rect_height(src);
  763. crtc_x = dest->x1;
  764. crtc_y = dest->y1;
  765. crtc_w = drm_rect_width(dest);
  766. crtc_h = drm_rect_height(dest);
  767. /* src values are in Q16 fixed point, convert to integer: */
  768. src_x = src_x >> 16;
  769. src_y = src_y >> 16;
  770. src_w = src_w >> 16;
  771. src_h = src_h >> 16;
  772. src_img_w = min(fb->width, src_w);
  773. src_img_h = min(fb->height, src_h);
  774. DBG("%s: FB[%u] %u,%u,%u,%u -> CRTC[%u] %d,%d,%u,%u", plane->name,
  775. fb->base.id, src_x, src_y, src_w, src_h,
  776. crtc->base.id, crtc_x, crtc_y, crtc_w, crtc_h);
  777. right_hwpipe = to_mdp5_plane_state(pstate)->r_hwpipe;
  778. if (right_hwpipe) {
  779. /*
  780. * if the plane comprises of 2 hw pipes, assume that the width
  781. * is split equally across them. The only parameters that varies
  782. * between the 2 pipes are src_x and crtc_x
  783. */
  784. crtc_w /= 2;
  785. src_w /= 2;
  786. src_img_w /= 2;
  787. crtc_x_r = crtc_x + crtc_w;
  788. src_x_r = src_x + src_w;
  789. }
  790. ret = calc_scalex_steps(plane, pix_format, src_w, crtc_w, step.x);
  791. if (ret)
  792. return ret;
  793. ret = calc_scaley_steps(plane, pix_format, src_h, crtc_h, step.y);
  794. if (ret)
  795. return ret;
  796. if (hwpipe->caps & MDP_PIPE_CAP_SW_PIX_EXT) {
  797. calc_pixel_ext(format, src_w, crtc_w, step.x,
  798. pe.left, pe.right, true);
  799. calc_pixel_ext(format, src_h, crtc_h, step.y,
  800. pe.top, pe.bottom, false);
  801. }
  802. /* TODO calc hdecm, vdecm */
  803. /* SCALE is used to both scale and up-sample chroma components */
  804. config |= get_scale_config(format, src_w, crtc_w, true);
  805. config |= get_scale_config(format, src_h, crtc_h, false);
  806. DBG("scale config = %x", config);
  807. rotation = drm_rotation_simplify(pstate->rotation,
  808. DRM_ROTATE_0 |
  809. DRM_REFLECT_X |
  810. DRM_REFLECT_Y);
  811. hflip = !!(rotation & DRM_REFLECT_X);
  812. vflip = !!(rotation & DRM_REFLECT_Y);
  813. spin_lock_irqsave(&mdp5_plane->pipe_lock, flags);
  814. mdp5_hwpipe_mode_set(mdp5_kms, hwpipe, fb, &step, &pe,
  815. config, hdecm, vdecm, hflip, vflip,
  816. crtc_x, crtc_y, crtc_w, crtc_h,
  817. src_img_w, src_img_h,
  818. src_x, src_y, src_w, src_h);
  819. if (right_hwpipe)
  820. mdp5_hwpipe_mode_set(mdp5_kms, right_hwpipe, fb, &step, &pe,
  821. config, hdecm, vdecm, hflip, vflip,
  822. crtc_x_r, crtc_y, crtc_w, crtc_h,
  823. src_img_w, src_img_h,
  824. src_x_r, src_y, src_w, src_h);
  825. spin_unlock_irqrestore(&mdp5_plane->pipe_lock, flags);
  826. plane->fb = fb;
  827. return ret;
  828. }
  829. static int mdp5_update_cursor_plane_legacy(struct drm_plane *plane,
  830. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  831. int crtc_x, int crtc_y,
  832. unsigned int crtc_w, unsigned int crtc_h,
  833. uint32_t src_x, uint32_t src_y,
  834. uint32_t src_w, uint32_t src_h,
  835. struct drm_modeset_acquire_ctx *ctx)
  836. {
  837. struct drm_plane_state *plane_state, *new_plane_state;
  838. struct mdp5_plane_state *mdp5_pstate;
  839. struct drm_crtc_state *crtc_state = crtc->state;
  840. int ret;
  841. if (!crtc_state->active || drm_atomic_crtc_needs_modeset(crtc_state))
  842. goto slow;
  843. plane_state = plane->state;
  844. mdp5_pstate = to_mdp5_plane_state(plane_state);
  845. /* don't use fast path if we don't have a hwpipe allocated yet */
  846. if (!mdp5_pstate->hwpipe)
  847. goto slow;
  848. /* only allow changing of position(crtc x/y or src x/y) in fast path */
  849. if (plane_state->crtc != crtc ||
  850. plane_state->src_w != src_w ||
  851. plane_state->src_h != src_h ||
  852. plane_state->crtc_w != crtc_w ||
  853. plane_state->crtc_h != crtc_h ||
  854. !plane_state->fb ||
  855. plane_state->fb != fb)
  856. goto slow;
  857. new_plane_state = mdp5_plane_duplicate_state(plane);
  858. if (!new_plane_state)
  859. return -ENOMEM;
  860. new_plane_state->src_x = src_x;
  861. new_plane_state->src_y = src_y;
  862. new_plane_state->src_w = src_w;
  863. new_plane_state->src_h = src_h;
  864. new_plane_state->crtc_x = crtc_x;
  865. new_plane_state->crtc_y = crtc_y;
  866. new_plane_state->crtc_w = crtc_w;
  867. new_plane_state->crtc_h = crtc_h;
  868. ret = mdp5_plane_atomic_check_with_state(crtc_state, new_plane_state);
  869. if (ret)
  870. goto slow_free;
  871. if (new_plane_state->visible) {
  872. struct mdp5_ctl *ctl;
  873. struct mdp5_pipeline *pipeline = mdp5_crtc_get_pipeline(crtc);
  874. ret = mdp5_plane_mode_set(plane, crtc, fb,
  875. &new_plane_state->src,
  876. &new_plane_state->dst);
  877. WARN_ON(ret < 0);
  878. ctl = mdp5_crtc_get_ctl(crtc);
  879. mdp5_ctl_commit(ctl, pipeline, mdp5_plane_get_flush(plane));
  880. }
  881. *to_mdp5_plane_state(plane_state) =
  882. *to_mdp5_plane_state(new_plane_state);
  883. mdp5_plane_destroy_state(plane, new_plane_state);
  884. return 0;
  885. slow_free:
  886. mdp5_plane_destroy_state(plane, new_plane_state);
  887. slow:
  888. return drm_atomic_helper_update_plane(plane, crtc, fb,
  889. crtc_x, crtc_y, crtc_w, crtc_h,
  890. src_x, src_y, src_w, src_h, ctx);
  891. }
  892. /*
  893. * Use this func and the one below only after the atomic state has been
  894. * successfully swapped
  895. */
  896. enum mdp5_pipe mdp5_plane_pipe(struct drm_plane *plane)
  897. {
  898. struct mdp5_plane_state *pstate = to_mdp5_plane_state(plane->state);
  899. if (WARN_ON(!pstate->hwpipe))
  900. return SSPP_NONE;
  901. return pstate->hwpipe->pipe;
  902. }
  903. enum mdp5_pipe mdp5_plane_right_pipe(struct drm_plane *plane)
  904. {
  905. struct mdp5_plane_state *pstate = to_mdp5_plane_state(plane->state);
  906. if (!pstate->r_hwpipe)
  907. return SSPP_NONE;
  908. return pstate->r_hwpipe->pipe;
  909. }
  910. uint32_t mdp5_plane_get_flush(struct drm_plane *plane)
  911. {
  912. struct mdp5_plane_state *pstate = to_mdp5_plane_state(plane->state);
  913. u32 mask;
  914. if (WARN_ON(!pstate->hwpipe))
  915. return 0;
  916. mask = pstate->hwpipe->flush_mask;
  917. if (pstate->r_hwpipe)
  918. mask |= pstate->r_hwpipe->flush_mask;
  919. return mask;
  920. }
  921. /* initialize plane */
  922. struct drm_plane *mdp5_plane_init(struct drm_device *dev,
  923. enum drm_plane_type type)
  924. {
  925. struct drm_plane *plane = NULL;
  926. struct mdp5_plane *mdp5_plane;
  927. int ret;
  928. mdp5_plane = kzalloc(sizeof(*mdp5_plane), GFP_KERNEL);
  929. if (!mdp5_plane) {
  930. ret = -ENOMEM;
  931. goto fail;
  932. }
  933. plane = &mdp5_plane->base;
  934. mdp5_plane->nformats = mdp_get_formats(mdp5_plane->formats,
  935. ARRAY_SIZE(mdp5_plane->formats), false);
  936. spin_lock_init(&mdp5_plane->pipe_lock);
  937. if (type == DRM_PLANE_TYPE_CURSOR)
  938. ret = drm_universal_plane_init(dev, plane, 0xff,
  939. &mdp5_cursor_plane_funcs,
  940. mdp5_plane->formats, mdp5_plane->nformats,
  941. type, NULL);
  942. else
  943. ret = drm_universal_plane_init(dev, plane, 0xff,
  944. &mdp5_plane_funcs,
  945. mdp5_plane->formats, mdp5_plane->nformats,
  946. type, NULL);
  947. if (ret)
  948. goto fail;
  949. drm_plane_helper_add(plane, &mdp5_plane_helper_funcs);
  950. mdp5_plane_install_properties(plane, &plane->base);
  951. return plane;
  952. fail:
  953. if (plane)
  954. mdp5_plane_destroy(plane);
  955. return ERR_PTR(ret);
  956. }