mdp5_plane.c 32 KB

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