mdp5_plane.c 33 KB

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