drm_plane_helper.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * Copyright (C) 2014 Intel Corporation
  3. *
  4. * DRM universal plane helper functions
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. #include <linux/list.h>
  26. #include <drm/drmP.h>
  27. #include <drm/drm_plane_helper.h>
  28. #include <drm/drm_rect.h>
  29. #include <drm/drm_atomic.h>
  30. #include <drm/drm_crtc_helper.h>
  31. #include <drm/drm_encoder.h>
  32. #include <drm/drm_atomic_helper.h>
  33. #define SUBPIXEL_MASK 0xffff
  34. /**
  35. * DOC: overview
  36. *
  37. * This helper library has two parts. The first part has support to implement
  38. * primary plane support on top of the normal CRTC configuration interface.
  39. * Since the legacy &drm_mode_config_funcs.set_config interface ties the primary
  40. * plane together with the CRTC state this does not allow userspace to disable
  41. * the primary plane itself. To avoid too much duplicated code use
  42. * drm_plane_helper_check_update() which can be used to enforce the same
  43. * restrictions as primary planes had thus. The default primary plane only
  44. * expose XRBG8888 and ARGB8888 as valid pixel formats for the attached
  45. * framebuffer.
  46. *
  47. * Drivers are highly recommended to implement proper support for primary
  48. * planes, and newly merged drivers must not rely upon these transitional
  49. * helpers.
  50. *
  51. * The second part also implements transitional helpers which allow drivers to
  52. * gradually switch to the atomic helper infrastructure for plane updates. Once
  53. * that switch is complete drivers shouldn't use these any longer, instead using
  54. * the proper legacy implementations for update and disable plane hooks provided
  55. * by the atomic helpers.
  56. *
  57. * Again drivers are strongly urged to switch to the new interfaces.
  58. *
  59. * The plane helpers share the function table structures with other helpers,
  60. * specifically also the atomic helpers. See &struct drm_plane_helper_funcs for
  61. * the details.
  62. */
  63. /*
  64. * Returns the connectors currently associated with a CRTC. This function
  65. * should be called twice: once with a NULL connector list to retrieve
  66. * the list size, and once with the properly allocated list to be filled in.
  67. */
  68. static int get_connectors_for_crtc(struct drm_crtc *crtc,
  69. struct drm_connector **connector_list,
  70. int num_connectors)
  71. {
  72. struct drm_device *dev = crtc->dev;
  73. struct drm_connector *connector;
  74. struct drm_connector_list_iter conn_iter;
  75. int count = 0;
  76. /*
  77. * Note: Once we change the plane hooks to more fine-grained locking we
  78. * need to grab the connection_mutex here to be able to make these
  79. * checks.
  80. */
  81. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  82. drm_connector_list_iter_get(dev, &conn_iter);
  83. drm_for_each_connector_iter(connector, &conn_iter) {
  84. if (connector->encoder && connector->encoder->crtc == crtc) {
  85. if (connector_list != NULL && count < num_connectors)
  86. *(connector_list++) = connector;
  87. count++;
  88. }
  89. }
  90. drm_connector_list_iter_put(&conn_iter);
  91. return count;
  92. }
  93. /**
  94. * drm_plane_helper_check_state() - Check plane state for validity
  95. * @state: plane state to check
  96. * @clip: integer clipping coordinates
  97. * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
  98. * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
  99. * @can_position: is it legal to position the plane such that it
  100. * doesn't cover the entire crtc? This will generally
  101. * only be false for primary planes.
  102. * @can_update_disabled: can the plane be updated while the crtc
  103. * is disabled?
  104. *
  105. * Checks that a desired plane update is valid, and updates various
  106. * bits of derived state (clipped coordinates etc.). Drivers that provide
  107. * their own plane handling rather than helper-provided implementations may
  108. * still wish to call this function to avoid duplication of error checking
  109. * code.
  110. *
  111. * RETURNS:
  112. * Zero if update appears valid, error code on failure
  113. */
  114. int drm_plane_helper_check_state(struct drm_plane_state *state,
  115. const struct drm_rect *clip,
  116. int min_scale,
  117. int max_scale,
  118. bool can_position,
  119. bool can_update_disabled)
  120. {
  121. struct drm_crtc *crtc = state->crtc;
  122. struct drm_framebuffer *fb = state->fb;
  123. struct drm_rect *src = &state->src;
  124. struct drm_rect *dst = &state->dst;
  125. unsigned int rotation = state->rotation;
  126. int hscale, vscale;
  127. *src = drm_plane_state_src(state);
  128. *dst = drm_plane_state_dest(state);
  129. if (!fb) {
  130. state->visible = false;
  131. return 0;
  132. }
  133. /* crtc should only be NULL when disabling (i.e., !fb) */
  134. if (WARN_ON(!crtc)) {
  135. state->visible = false;
  136. return 0;
  137. }
  138. if (!crtc->enabled && !can_update_disabled) {
  139. DRM_DEBUG_KMS("Cannot update plane of a disabled CRTC.\n");
  140. return -EINVAL;
  141. }
  142. drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation);
  143. /* Check scaling */
  144. hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
  145. vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
  146. if (hscale < 0 || vscale < 0) {
  147. DRM_DEBUG_KMS("Invalid scaling of plane\n");
  148. drm_rect_debug_print("src: ", &state->src, true);
  149. drm_rect_debug_print("dst: ", &state->dst, false);
  150. return -ERANGE;
  151. }
  152. state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
  153. drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation);
  154. if (!state->visible)
  155. /*
  156. * Plane isn't visible; some drivers can handle this
  157. * so we just return success here. Drivers that can't
  158. * (including those that use the primary plane helper's
  159. * update function) will return an error from their
  160. * update_plane handler.
  161. */
  162. return 0;
  163. if (!can_position && !drm_rect_equals(dst, clip)) {
  164. DRM_DEBUG_KMS("Plane must cover entire CRTC\n");
  165. drm_rect_debug_print("dst: ", dst, false);
  166. drm_rect_debug_print("clip: ", clip, false);
  167. return -EINVAL;
  168. }
  169. return 0;
  170. }
  171. EXPORT_SYMBOL(drm_plane_helper_check_state);
  172. /**
  173. * drm_plane_helper_check_update() - Check plane update for validity
  174. * @plane: plane object to update
  175. * @crtc: owning CRTC of owning plane
  176. * @fb: framebuffer to flip onto plane
  177. * @src: source coordinates in 16.16 fixed point
  178. * @dst: integer destination coordinates
  179. * @clip: integer clipping coordinates
  180. * @rotation: plane rotation
  181. * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
  182. * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
  183. * @can_position: is it legal to position the plane such that it
  184. * doesn't cover the entire crtc? This will generally
  185. * only be false for primary planes.
  186. * @can_update_disabled: can the plane be updated while the crtc
  187. * is disabled?
  188. * @visible: output parameter indicating whether plane is still visible after
  189. * clipping
  190. *
  191. * Checks that a desired plane update is valid. Drivers that provide
  192. * their own plane handling rather than helper-provided implementations may
  193. * still wish to call this function to avoid duplication of error checking
  194. * code.
  195. *
  196. * RETURNS:
  197. * Zero if update appears valid, error code on failure
  198. */
  199. int drm_plane_helper_check_update(struct drm_plane *plane,
  200. struct drm_crtc *crtc,
  201. struct drm_framebuffer *fb,
  202. struct drm_rect *src,
  203. struct drm_rect *dst,
  204. const struct drm_rect *clip,
  205. unsigned int rotation,
  206. int min_scale,
  207. int max_scale,
  208. bool can_position,
  209. bool can_update_disabled,
  210. bool *visible)
  211. {
  212. struct drm_plane_state state = {
  213. .plane = plane,
  214. .crtc = crtc,
  215. .fb = fb,
  216. .src_x = src->x1,
  217. .src_y = src->y1,
  218. .src_w = drm_rect_width(src),
  219. .src_h = drm_rect_height(src),
  220. .crtc_x = dst->x1,
  221. .crtc_y = dst->y1,
  222. .crtc_w = drm_rect_width(dst),
  223. .crtc_h = drm_rect_height(dst),
  224. .rotation = rotation,
  225. .visible = *visible,
  226. };
  227. int ret;
  228. ret = drm_plane_helper_check_state(&state, clip,
  229. min_scale, max_scale,
  230. can_position,
  231. can_update_disabled);
  232. if (ret)
  233. return ret;
  234. *src = state.src;
  235. *dst = state.dst;
  236. *visible = state.visible;
  237. return 0;
  238. }
  239. EXPORT_SYMBOL(drm_plane_helper_check_update);
  240. /**
  241. * drm_primary_helper_update() - Helper for primary plane update
  242. * @plane: plane object to update
  243. * @crtc: owning CRTC of owning plane
  244. * @fb: framebuffer to flip onto plane
  245. * @crtc_x: x offset of primary plane on crtc
  246. * @crtc_y: y offset of primary plane on crtc
  247. * @crtc_w: width of primary plane rectangle on crtc
  248. * @crtc_h: height of primary plane rectangle on crtc
  249. * @src_x: x offset of @fb for panning
  250. * @src_y: y offset of @fb for panning
  251. * @src_w: width of source rectangle in @fb
  252. * @src_h: height of source rectangle in @fb
  253. *
  254. * Provides a default plane update handler for primary planes. This is handler
  255. * is called in response to a userspace SetPlane operation on the plane with a
  256. * non-NULL framebuffer. We call the driver's modeset handler to update the
  257. * framebuffer.
  258. *
  259. * SetPlane() on a primary plane of a disabled CRTC is not supported, and will
  260. * return an error.
  261. *
  262. * Note that we make some assumptions about hardware limitations that may not be
  263. * true for all hardware --
  264. *
  265. * 1. Primary plane cannot be repositioned.
  266. * 2. Primary plane cannot be scaled.
  267. * 3. Primary plane must cover the entire CRTC.
  268. * 4. Subpixel positioning is not supported.
  269. *
  270. * Drivers for hardware that don't have these restrictions can provide their
  271. * own implementation rather than using this helper.
  272. *
  273. * RETURNS:
  274. * Zero on success, error code on failure
  275. */
  276. int drm_primary_helper_update(struct drm_plane *plane, struct drm_crtc *crtc,
  277. struct drm_framebuffer *fb,
  278. int crtc_x, int crtc_y,
  279. unsigned int crtc_w, unsigned int crtc_h,
  280. uint32_t src_x, uint32_t src_y,
  281. uint32_t src_w, uint32_t src_h)
  282. {
  283. struct drm_mode_set set = {
  284. .crtc = crtc,
  285. .fb = fb,
  286. .mode = &crtc->mode,
  287. .x = src_x >> 16,
  288. .y = src_y >> 16,
  289. };
  290. struct drm_rect src = {
  291. .x1 = src_x,
  292. .y1 = src_y,
  293. .x2 = src_x + src_w,
  294. .y2 = src_y + src_h,
  295. };
  296. struct drm_rect dest = {
  297. .x1 = crtc_x,
  298. .y1 = crtc_y,
  299. .x2 = crtc_x + crtc_w,
  300. .y2 = crtc_y + crtc_h,
  301. };
  302. const struct drm_rect clip = {
  303. .x2 = crtc->mode.hdisplay,
  304. .y2 = crtc->mode.vdisplay,
  305. };
  306. struct drm_connector **connector_list;
  307. int num_connectors, ret;
  308. bool visible;
  309. ret = drm_plane_helper_check_update(plane, crtc, fb,
  310. &src, &dest, &clip,
  311. DRM_ROTATE_0,
  312. DRM_PLANE_HELPER_NO_SCALING,
  313. DRM_PLANE_HELPER_NO_SCALING,
  314. false, false, &visible);
  315. if (ret)
  316. return ret;
  317. if (!visible)
  318. /*
  319. * Primary plane isn't visible. Note that unless a driver
  320. * provides their own disable function, this will just
  321. * wind up returning -EINVAL to userspace.
  322. */
  323. return plane->funcs->disable_plane(plane);
  324. /* Find current connectors for CRTC */
  325. num_connectors = get_connectors_for_crtc(crtc, NULL, 0);
  326. BUG_ON(num_connectors == 0);
  327. connector_list = kzalloc(num_connectors * sizeof(*connector_list),
  328. GFP_KERNEL);
  329. if (!connector_list)
  330. return -ENOMEM;
  331. get_connectors_for_crtc(crtc, connector_list, num_connectors);
  332. set.connectors = connector_list;
  333. set.num_connectors = num_connectors;
  334. /*
  335. * We call set_config() directly here rather than using
  336. * drm_mode_set_config_internal. We're reprogramming the same
  337. * connectors that were already in use, so we shouldn't need the extra
  338. * cross-CRTC fb refcounting to accomodate stealing connectors.
  339. * drm_mode_setplane() already handles the basic refcounting for the
  340. * framebuffers involved in this operation.
  341. */
  342. ret = crtc->funcs->set_config(&set);
  343. kfree(connector_list);
  344. return ret;
  345. }
  346. EXPORT_SYMBOL(drm_primary_helper_update);
  347. /**
  348. * drm_primary_helper_disable() - Helper for primary plane disable
  349. * @plane: plane to disable
  350. *
  351. * Provides a default plane disable handler for primary planes. This is handler
  352. * is called in response to a userspace SetPlane operation on the plane with a
  353. * NULL framebuffer parameter. It unconditionally fails the disable call with
  354. * -EINVAL the only way to disable the primary plane without driver support is
  355. * to disable the entire CRTC. Which does not match the plane
  356. * &drm_plane_funcs.disable_plane hook.
  357. *
  358. * Note that some hardware may be able to disable the primary plane without
  359. * disabling the whole CRTC. Drivers for such hardware should provide their
  360. * own disable handler that disables just the primary plane (and they'll likely
  361. * need to provide their own update handler as well to properly re-enable a
  362. * disabled primary plane).
  363. *
  364. * RETURNS:
  365. * Unconditionally returns -EINVAL.
  366. */
  367. int drm_primary_helper_disable(struct drm_plane *plane)
  368. {
  369. return -EINVAL;
  370. }
  371. EXPORT_SYMBOL(drm_primary_helper_disable);
  372. /**
  373. * drm_primary_helper_destroy() - Helper for primary plane destruction
  374. * @plane: plane to destroy
  375. *
  376. * Provides a default plane destroy handler for primary planes. This handler
  377. * is called during CRTC destruction. We disable the primary plane, remove
  378. * it from the DRM plane list, and deallocate the plane structure.
  379. */
  380. void drm_primary_helper_destroy(struct drm_plane *plane)
  381. {
  382. drm_plane_cleanup(plane);
  383. kfree(plane);
  384. }
  385. EXPORT_SYMBOL(drm_primary_helper_destroy);
  386. const struct drm_plane_funcs drm_primary_helper_funcs = {
  387. .update_plane = drm_primary_helper_update,
  388. .disable_plane = drm_primary_helper_disable,
  389. .destroy = drm_primary_helper_destroy,
  390. };
  391. EXPORT_SYMBOL(drm_primary_helper_funcs);
  392. int drm_plane_helper_commit(struct drm_plane *plane,
  393. struct drm_plane_state *plane_state,
  394. struct drm_framebuffer *old_fb)
  395. {
  396. const struct drm_plane_helper_funcs *plane_funcs;
  397. struct drm_crtc *crtc[2];
  398. const struct drm_crtc_helper_funcs *crtc_funcs[2];
  399. int i, ret = 0;
  400. plane_funcs = plane->helper_private;
  401. /* Since this is a transitional helper we can't assume that plane->state
  402. * is always valid. Hence we need to use plane->crtc instead of
  403. * plane->state->crtc as the old crtc. */
  404. crtc[0] = plane->crtc;
  405. crtc[1] = crtc[0] != plane_state->crtc ? plane_state->crtc : NULL;
  406. for (i = 0; i < 2; i++)
  407. crtc_funcs[i] = crtc[i] ? crtc[i]->helper_private : NULL;
  408. if (plane_funcs->atomic_check) {
  409. ret = plane_funcs->atomic_check(plane, plane_state);
  410. if (ret)
  411. goto out;
  412. }
  413. if (plane_funcs->prepare_fb && plane_state->fb &&
  414. plane_state->fb != old_fb) {
  415. ret = plane_funcs->prepare_fb(plane,
  416. plane_state);
  417. if (ret)
  418. goto out;
  419. }
  420. /* Point of no return, commit sw state. */
  421. swap(plane->state, plane_state);
  422. for (i = 0; i < 2; i++) {
  423. if (crtc_funcs[i] && crtc_funcs[i]->atomic_begin)
  424. crtc_funcs[i]->atomic_begin(crtc[i], crtc[i]->state);
  425. }
  426. /*
  427. * Drivers may optionally implement the ->atomic_disable callback, so
  428. * special-case that here.
  429. */
  430. if (drm_atomic_plane_disabling(plane, plane_state) &&
  431. plane_funcs->atomic_disable)
  432. plane_funcs->atomic_disable(plane, plane_state);
  433. else
  434. plane_funcs->atomic_update(plane, plane_state);
  435. for (i = 0; i < 2; i++) {
  436. if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)
  437. crtc_funcs[i]->atomic_flush(crtc[i], crtc[i]->state);
  438. }
  439. /*
  440. * If we only moved the plane and didn't change fb's, there's no need to
  441. * wait for vblank.
  442. */
  443. if (plane->state->fb == old_fb)
  444. goto out;
  445. for (i = 0; i < 2; i++) {
  446. if (!crtc[i])
  447. continue;
  448. if (crtc[i]->cursor == plane)
  449. continue;
  450. /* There's no other way to figure out whether the crtc is running. */
  451. ret = drm_crtc_vblank_get(crtc[i]);
  452. if (ret == 0) {
  453. drm_crtc_wait_one_vblank(crtc[i]);
  454. drm_crtc_vblank_put(crtc[i]);
  455. }
  456. ret = 0;
  457. }
  458. if (plane_funcs->cleanup_fb)
  459. plane_funcs->cleanup_fb(plane, plane_state);
  460. out:
  461. if (plane_state) {
  462. if (plane->funcs->atomic_destroy_state)
  463. plane->funcs->atomic_destroy_state(plane, plane_state);
  464. else
  465. drm_atomic_helper_plane_destroy_state(plane, plane_state);
  466. }
  467. return ret;
  468. }
  469. /**
  470. * drm_plane_helper_update() - Transitional helper for plane update
  471. * @plane: plane object to update
  472. * @crtc: owning CRTC of owning plane
  473. * @fb: framebuffer to flip onto plane
  474. * @crtc_x: x offset of primary plane on crtc
  475. * @crtc_y: y offset of primary plane on crtc
  476. * @crtc_w: width of primary plane rectangle on crtc
  477. * @crtc_h: height of primary plane rectangle on crtc
  478. * @src_x: x offset of @fb for panning
  479. * @src_y: y offset of @fb for panning
  480. * @src_w: width of source rectangle in @fb
  481. * @src_h: height of source rectangle in @fb
  482. *
  483. * Provides a default plane update handler using the atomic plane update
  484. * functions. It is fully left to the driver to check plane constraints and
  485. * handle corner-cases like a fully occluded or otherwise invisible plane.
  486. *
  487. * This is useful for piecewise transitioning of a driver to the atomic helpers.
  488. *
  489. * RETURNS:
  490. * Zero on success, error code on failure
  491. */
  492. int drm_plane_helper_update(struct drm_plane *plane, struct drm_crtc *crtc,
  493. struct drm_framebuffer *fb,
  494. int crtc_x, int crtc_y,
  495. unsigned int crtc_w, unsigned int crtc_h,
  496. uint32_t src_x, uint32_t src_y,
  497. uint32_t src_w, uint32_t src_h)
  498. {
  499. struct drm_plane_state *plane_state;
  500. if (plane->funcs->atomic_duplicate_state)
  501. plane_state = plane->funcs->atomic_duplicate_state(plane);
  502. else {
  503. if (!plane->state)
  504. drm_atomic_helper_plane_reset(plane);
  505. plane_state = drm_atomic_helper_plane_duplicate_state(plane);
  506. }
  507. if (!plane_state)
  508. return -ENOMEM;
  509. plane_state->plane = plane;
  510. plane_state->crtc = crtc;
  511. drm_atomic_set_fb_for_plane(plane_state, fb);
  512. plane_state->crtc_x = crtc_x;
  513. plane_state->crtc_y = crtc_y;
  514. plane_state->crtc_h = crtc_h;
  515. plane_state->crtc_w = crtc_w;
  516. plane_state->src_x = src_x;
  517. plane_state->src_y = src_y;
  518. plane_state->src_h = src_h;
  519. plane_state->src_w = src_w;
  520. return drm_plane_helper_commit(plane, plane_state, plane->fb);
  521. }
  522. EXPORT_SYMBOL(drm_plane_helper_update);
  523. /**
  524. * drm_plane_helper_disable() - Transitional helper for plane disable
  525. * @plane: plane to disable
  526. *
  527. * Provides a default plane disable handler using the atomic plane update
  528. * functions. It is fully left to the driver to check plane constraints and
  529. * handle corner-cases like a fully occluded or otherwise invisible plane.
  530. *
  531. * This is useful for piecewise transitioning of a driver to the atomic helpers.
  532. *
  533. * RETURNS:
  534. * Zero on success, error code on failure
  535. */
  536. int drm_plane_helper_disable(struct drm_plane *plane)
  537. {
  538. struct drm_plane_state *plane_state;
  539. /* crtc helpers love to call disable functions for already disabled hw
  540. * functions. So cope with that. */
  541. if (!plane->crtc)
  542. return 0;
  543. if (plane->funcs->atomic_duplicate_state)
  544. plane_state = plane->funcs->atomic_duplicate_state(plane);
  545. else {
  546. if (!plane->state)
  547. drm_atomic_helper_plane_reset(plane);
  548. plane_state = drm_atomic_helper_plane_duplicate_state(plane);
  549. }
  550. if (!plane_state)
  551. return -ENOMEM;
  552. plane_state->plane = plane;
  553. plane_state->crtc = NULL;
  554. drm_atomic_set_fb_for_plane(plane_state, NULL);
  555. return drm_plane_helper_commit(plane, plane_state, plane->fb);
  556. }
  557. EXPORT_SYMBOL(drm_plane_helper_disable);