mdp5_plane.c 32 KB

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