drm_plane_helper.c 19.6 KB
Newer Older
M
Matt Roper 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright (C) 2014 Intel Corporation
 *
 * DRM universal plane helper functions
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <linux/list.h>
#include <drm/drmP.h>
28
#include <drm/drm_plane_helper.h>
M
Matt Roper 已提交
29
#include <drm/drm_rect.h>
30
#include <drm/drm_atomic.h>
31
#include <drm/drm_crtc_helper.h>
32
#include <drm/drm_encoder.h>
33
#include <drm/drm_atomic_helper.h>
M
Matt Roper 已提交
34 35 36

#define SUBPIXEL_MASK 0xffff

37 38 39 40 41
/**
 * DOC: overview
 *
 * This helper library has two parts. The first part has support to implement
 * primary plane support on top of the normal CRTC configuration interface.
42 43 44
 * Since the legacy &drm_mode_config_funcs.set_config interface ties the primary
 * plane together with the CRTC state this does not allow userspace to disable
 * the primary plane itself.  To avoid too much duplicated code use
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
 * drm_plane_helper_check_update() which can be used to enforce the same
 * restrictions as primary planes had thus. The default primary plane only
 * expose XRBG8888 and ARGB8888 as valid pixel formats for the attached
 * framebuffer.
 *
 * Drivers are highly recommended to implement proper support for primary
 * planes, and newly merged drivers must not rely upon these transitional
 * helpers.
 *
 * The second part also implements transitional helpers which allow drivers to
 * gradually switch to the atomic helper infrastructure for plane updates. Once
 * that switch is complete drivers shouldn't use these any longer, instead using
 * the proper legacy implementations for update and disable plane hooks provided
 * by the atomic helpers.
 *
 * Again drivers are strongly urged to switch to the new interfaces.
61 62
 *
 * The plane helpers share the function table structures with other helpers,
63
 * specifically also the atomic helpers. See &struct drm_plane_helper_funcs for
64
 * the details.
65 66
 */

M
Matt Roper 已提交
67 68 69 70 71 72 73 74 75 76 77
/*
 * Returns the connectors currently associated with a CRTC.  This function
 * should be called twice:  once with a NULL connector list to retrieve
 * the list size, and once with the properly allocated list to be filled in.
 */
static int get_connectors_for_crtc(struct drm_crtc *crtc,
				   struct drm_connector **connector_list,
				   int num_connectors)
{
	struct drm_device *dev = crtc->dev;
	struct drm_connector *connector;
78
	struct drm_connector_list_iter conn_iter;
M
Matt Roper 已提交
79 80
	int count = 0;

81 82 83 84 85
	/*
	 * Note: Once we change the plane hooks to more fine-grained locking we
	 * need to grab the connection_mutex here to be able to make these
	 * checks.
	 */
86
	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
87

88
	drm_connector_list_iter_begin(dev, &conn_iter);
89
	drm_for_each_connector_iter(connector, &conn_iter) {
M
Matt Roper 已提交
90 91 92 93 94 95
		if (connector->encoder && connector->encoder->crtc == crtc) {
			if (connector_list != NULL && count < num_connectors)
				*(connector_list++) = connector;

			count++;
		}
96
	}
97
	drm_connector_list_iter_end(&conn_iter);
M
Matt Roper 已提交
98 99 100 101

	return count;
}

102
/**
103 104
 * drm_plane_helper_check_state() - Check plane state for validity
 * @state: plane state to check
105 106 107 108 109 110 111 112 113
 * @clip: integer clipping coordinates
 * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
 * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
 * @can_position: is it legal to position the plane such that it
 *                doesn't cover the entire crtc?  This will generally
 *                only be false for primary planes.
 * @can_update_disabled: can the plane be updated while the crtc
 *                       is disabled?
 *
114 115
 * Checks that a desired plane update is valid, and updates various
 * bits of derived state (clipped coordinates etc.). Drivers that provide
116 117 118 119 120 121 122
 * their own plane handling rather than helper-provided implementations may
 * still wish to call this function to avoid duplication of error checking
 * code.
 *
 * RETURNS:
 * Zero if update appears valid, error code on failure
 */
123 124 125 126 127 128
int drm_plane_helper_check_state(struct drm_plane_state *state,
				 const struct drm_rect *clip,
				 int min_scale,
				 int max_scale,
				 bool can_position,
				 bool can_update_disabled)
129
{
130 131 132 133 134
	struct drm_crtc *crtc = state->crtc;
	struct drm_framebuffer *fb = state->fb;
	struct drm_rect *src = &state->src;
	struct drm_rect *dst = &state->dst;
	unsigned int rotation = state->rotation;
135 136
	int hscale, vscale;

137 138
	*src = drm_plane_state_src(state);
	*dst = drm_plane_state_dest(state);
139

140
	if (!fb) {
141
		state->visible = false;
142 143 144 145 146
		return 0;
	}

	/* crtc should only be NULL when disabling (i.e., !fb) */
	if (WARN_ON(!crtc)) {
147
		state->visible = false;
148 149 150
		return 0;
	}

151 152 153 154 155
	if (!crtc->enabled && !can_update_disabled) {
		DRM_DEBUG_KMS("Cannot update plane of a disabled CRTC.\n");
		return -EINVAL;
	}

156 157
	drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation);

158
	/* Check scaling */
159 160
	hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
	vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
161 162
	if (hscale < 0 || vscale < 0) {
		DRM_DEBUG_KMS("Invalid scaling of plane\n");
163 164
		drm_rect_debug_print("src: ", &state->src, true);
		drm_rect_debug_print("dst: ", &state->dst, false);
165 166 167
		return -ERANGE;
	}

168
	state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
169 170 171

	drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation);

172
	if (!state->visible)
173 174 175 176 177 178 179 180 181
		/*
		 * Plane isn't visible; some drivers can handle this
		 * so we just return success here.  Drivers that can't
		 * (including those that use the primary plane helper's
		 * update function) will return an error from their
		 * update_plane handler.
		 */
		return 0;

182
	if (!can_position && !drm_rect_equals(dst, clip)) {
183
		DRM_DEBUG_KMS("Plane must cover entire CRTC\n");
184
		drm_rect_debug_print("dst: ", dst, false);
185
		drm_rect_debug_print("clip: ", clip, false);
186 187 188 189 190
		return -EINVAL;
	}

	return 0;
}
191 192 193 194 195 196 197 198
EXPORT_SYMBOL(drm_plane_helper_check_state);

/**
 * drm_plane_helper_check_update() - Check plane update for validity
 * @plane: plane object to update
 * @crtc: owning CRTC of owning plane
 * @fb: framebuffer to flip onto plane
 * @src: source coordinates in 16.16 fixed point
199
 * @dst: integer destination coordinates
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
 * @clip: integer clipping coordinates
 * @rotation: plane rotation
 * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
 * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
 * @can_position: is it legal to position the plane such that it
 *                doesn't cover the entire crtc?  This will generally
 *                only be false for primary planes.
 * @can_update_disabled: can the plane be updated while the crtc
 *                       is disabled?
 * @visible: output parameter indicating whether plane is still visible after
 *           clipping
 *
 * Checks that a desired plane update is valid.  Drivers that provide
 * their own plane handling rather than helper-provided implementations may
 * still wish to call this function to avoid duplication of error checking
 * code.
 *
 * RETURNS:
 * Zero if update appears valid, error code on failure
 */
int drm_plane_helper_check_update(struct drm_plane *plane,
				  struct drm_crtc *crtc,
				  struct drm_framebuffer *fb,
				  struct drm_rect *src,
				  struct drm_rect *dst,
				  const struct drm_rect *clip,
				  unsigned int rotation,
				  int min_scale,
				  int max_scale,
				  bool can_position,
				  bool can_update_disabled,
				  bool *visible)
{
	struct drm_plane_state state = {
		.plane = plane,
		.crtc = crtc,
		.fb = fb,
		.src_x = src->x1,
		.src_y = src->y1,
		.src_w = drm_rect_width(src),
		.src_h = drm_rect_height(src),
		.crtc_x = dst->x1,
		.crtc_y = dst->y1,
		.crtc_w = drm_rect_width(dst),
		.crtc_h = drm_rect_height(dst),
		.rotation = rotation,
		.visible = *visible,
	};
	int ret;

	ret = drm_plane_helper_check_state(&state, clip,
					   min_scale, max_scale,
					   can_position,
					   can_update_disabled);
	if (ret)
		return ret;

	*src = state.src;
	*dst = state.dst;
	*visible = state.visible;

	return 0;
}
263 264
EXPORT_SYMBOL(drm_plane_helper_check_update);

M
Matt Roper 已提交
265 266 267 268 269 270 271 272 273 274 275 276 277
/**
 * drm_primary_helper_update() - Helper for primary plane update
 * @plane: plane object to update
 * @crtc: owning CRTC of owning plane
 * @fb: framebuffer to flip onto plane
 * @crtc_x: x offset of primary plane on crtc
 * @crtc_y: y offset of primary plane on crtc
 * @crtc_w: width of primary plane rectangle on crtc
 * @crtc_h: height of primary plane rectangle on crtc
 * @src_x: x offset of @fb for panning
 * @src_y: y offset of @fb for panning
 * @src_w: width of source rectangle in @fb
 * @src_h: height of source rectangle in @fb
278
 * @ctx: lock acquire context, not used here
M
Matt Roper 已提交
279 280 281 282 283 284 285 286 287 288 289
 *
 * Provides a default plane update handler for primary planes.  This is handler
 * is called in response to a userspace SetPlane operation on the plane with a
 * non-NULL framebuffer.  We call the driver's modeset handler to update the
 * framebuffer.
 *
 * SetPlane() on a primary plane of a disabled CRTC is not supported, and will
 * return an error.
 *
 * Note that we make some assumptions about hardware limitations that may not be
 * true for all hardware --
D
Daniel Vetter 已提交
290 291 292 293 294 295
 *
 * 1. Primary plane cannot be repositioned.
 * 2. Primary plane cannot be scaled.
 * 3. Primary plane must cover the entire CRTC.
 * 4. Subpixel positioning is not supported.
 *
M
Matt Roper 已提交
296 297 298 299 300 301 302 303 304 305 306
 * Drivers for hardware that don't have these restrictions can provide their
 * own implementation rather than using this helper.
 *
 * RETURNS:
 * Zero on success, error code on failure
 */
int drm_primary_helper_update(struct drm_plane *plane, struct drm_crtc *crtc,
			      struct drm_framebuffer *fb,
			      int crtc_x, int crtc_y,
			      unsigned int crtc_w, unsigned int crtc_h,
			      uint32_t src_x, uint32_t src_y,
307 308
			      uint32_t src_w, uint32_t src_h,
			      struct drm_modeset_acquire_ctx *ctx)
M
Matt Roper 已提交
309 310 311 312 313 314 315 316
{
	struct drm_mode_set set = {
		.crtc = crtc,
		.fb = fb,
		.mode = &crtc->mode,
		.x = src_x >> 16,
		.y = src_y >> 16,
	};
317 318 319 320 321 322
	struct drm_rect src = {
		.x1 = src_x,
		.y1 = src_y,
		.x2 = src_x + src_w,
		.y2 = src_y + src_h,
	};
M
Matt Roper 已提交
323 324 325 326 327 328
	struct drm_rect dest = {
		.x1 = crtc_x,
		.y1 = crtc_y,
		.x2 = crtc_x + crtc_w,
		.y2 = crtc_y + crtc_h,
	};
329
	const struct drm_rect clip = {
M
Matt Roper 已提交
330 331 332 333 334
		.x2 = crtc->mode.hdisplay,
		.y2 = crtc->mode.vdisplay,
	};
	struct drm_connector **connector_list;
	int num_connectors, ret;
335
	bool visible;
M
Matt Roper 已提交
336

337 338
	ret = drm_plane_helper_check_update(plane, crtc, fb,
					    &src, &dest, &clip,
339
					    DRM_ROTATE_0,
340 341 342
					    DRM_PLANE_HELPER_NO_SCALING,
					    DRM_PLANE_HELPER_NO_SCALING,
					    false, false, &visible);
M
Matt Roper 已提交
343 344 345
	if (ret)
		return ret;

346 347 348 349 350 351
	if (!visible)
		/*
		 * Primary plane isn't visible.  Note that unless a driver
		 * provides their own disable function, this will just
		 * wind up returning -EINVAL to userspace.
		 */
352
		return plane->funcs->disable_plane(plane, ctx);
353

M
Matt Roper 已提交
354 355 356 357 358 359 360 361 362 363 364 365 366
	/* Find current connectors for CRTC */
	num_connectors = get_connectors_for_crtc(crtc, NULL, 0);
	BUG_ON(num_connectors == 0);
	connector_list = kzalloc(num_connectors * sizeof(*connector_list),
				 GFP_KERNEL);
	if (!connector_list)
		return -ENOMEM;
	get_connectors_for_crtc(crtc, connector_list, num_connectors);

	set.connectors = connector_list;
	set.num_connectors = num_connectors;

	/*
367
	 * We call set_config() directly here rather than using
M
Matt Roper 已提交
368 369 370 371 372 373
	 * drm_mode_set_config_internal.  We're reprogramming the same
	 * connectors that were already in use, so we shouldn't need the extra
	 * cross-CRTC fb refcounting to accomodate stealing connectors.
	 * drm_mode_setplane() already handles the basic refcounting for the
	 * framebuffers involved in this operation.
	 */
374
	ret = crtc->funcs->set_config(&set, ctx);
M
Matt Roper 已提交
375 376 377 378 379 380 381 382 383

	kfree(connector_list);
	return ret;
}
EXPORT_SYMBOL(drm_primary_helper_update);

/**
 * drm_primary_helper_disable() - Helper for primary plane disable
 * @plane: plane to disable
384
 * @ctx: lock acquire context, not used here
M
Matt Roper 已提交
385 386 387
 *
 * Provides a default plane disable handler for primary planes.  This is handler
 * is called in response to a userspace SetPlane operation on the plane with a
388 389
 * NULL framebuffer parameter.  It unconditionally fails the disable call with
 * -EINVAL the only way to disable the primary plane without driver support is
390 391
 * to disable the entire CRTC. Which does not match the plane
 * &drm_plane_funcs.disable_plane hook.
M
Matt Roper 已提交
392 393 394 395 396 397 398 399
 *
 * Note that some hardware may be able to disable the primary plane without
 * disabling the whole CRTC.  Drivers for such hardware should provide their
 * own disable handler that disables just the primary plane (and they'll likely
 * need to provide their own update handler as well to properly re-enable a
 * disabled primary plane).
 *
 * RETURNS:
400
 * Unconditionally returns -EINVAL.
M
Matt Roper 已提交
401
 */
402 403
int drm_primary_helper_disable(struct drm_plane *plane,
			       struct drm_modeset_acquire_ctx *ctx)
M
Matt Roper 已提交
404
{
405
	return -EINVAL;
M
Matt Roper 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
}
EXPORT_SYMBOL(drm_primary_helper_disable);

/**
 * drm_primary_helper_destroy() - Helper for primary plane destruction
 * @plane: plane to destroy
 *
 * Provides a default plane destroy handler for primary planes.  This handler
 * is called during CRTC destruction.  We disable the primary plane, remove
 * it from the DRM plane list, and deallocate the plane structure.
 */
void drm_primary_helper_destroy(struct drm_plane *plane)
{
	drm_plane_cleanup(plane);
	kfree(plane);
}
EXPORT_SYMBOL(drm_primary_helper_destroy);

const struct drm_plane_funcs drm_primary_helper_funcs = {
	.update_plane = drm_primary_helper_update,
	.disable_plane = drm_primary_helper_disable,
	.destroy = drm_primary_helper_destroy,
};
EXPORT_SYMBOL(drm_primary_helper_funcs);

431 432 433
int drm_plane_helper_commit(struct drm_plane *plane,
			    struct drm_plane_state *plane_state,
			    struct drm_framebuffer *old_fb)
434
{
435
	const struct drm_plane_helper_funcs *plane_funcs;
436
	struct drm_crtc *crtc[2];
437
	const struct drm_crtc_helper_funcs *crtc_funcs[2];
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
	int i, ret = 0;

	plane_funcs = plane->helper_private;

	/* Since this is a transitional helper we can't assume that plane->state
	 * is always valid. Hence we need to use plane->crtc instead of
	 * plane->state->crtc as the old crtc. */
	crtc[0] = plane->crtc;
	crtc[1] = crtc[0] != plane_state->crtc ? plane_state->crtc : NULL;

	for (i = 0; i < 2; i++)
		crtc_funcs[i] = crtc[i] ? crtc[i]->helper_private : NULL;

	if (plane_funcs->atomic_check) {
		ret = plane_funcs->atomic_check(plane, plane_state);
		if (ret)
			goto out;
	}

457
	if (plane_funcs->prepare_fb && plane_state->fb != old_fb) {
458
		ret = plane_funcs->prepare_fb(plane,
459
					      plane_state);
460 461 462 463 464 465 466 467 468
		if (ret)
			goto out;
	}

	/* Point of no return, commit sw state. */
	swap(plane->state, plane_state);

	for (i = 0; i < 2; i++) {
		if (crtc_funcs[i] && crtc_funcs[i]->atomic_begin)
469
			crtc_funcs[i]->atomic_begin(crtc[i], crtc[i]->state);
470 471
	}

472 473 474 475
	/*
	 * Drivers may optionally implement the ->atomic_disable callback, so
	 * special-case that here.
	 */
476
	if (drm_atomic_plane_disabling(plane_state, plane->state) &&
477 478 479 480
	    plane_funcs->atomic_disable)
		plane_funcs->atomic_disable(plane, plane_state);
	else
		plane_funcs->atomic_update(plane, plane_state);
481 482 483

	for (i = 0; i < 2; i++) {
		if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)
484
			crtc_funcs[i]->atomic_flush(crtc[i], crtc[i]->state);
485 486
	}

487 488 489 490 491 492 493
	/*
	 * If we only moved the plane and didn't change fb's, there's no need to
	 * wait for vblank.
	 */
	if (plane->state->fb == old_fb)
		goto out;

494 495 496 497
	for (i = 0; i < 2; i++) {
		if (!crtc[i])
			continue;

498 499 500
		if (crtc[i]->cursor == plane)
			continue;

501 502 503 504 505 506 507 508 509 510
		/* There's no other way to figure out whether the crtc is running. */
		ret = drm_crtc_vblank_get(crtc[i]);
		if (ret == 0) {
			drm_crtc_wait_one_vblank(crtc[i]);
			drm_crtc_vblank_put(crtc[i]);
		}

		ret = 0;
	}

511 512
	if (plane_funcs->cleanup_fb)
		plane_funcs->cleanup_fb(plane, plane_state);
513
out:
514 515 516 517
	if (plane->funcs->atomic_destroy_state)
		plane->funcs->atomic_destroy_state(plane, plane_state);
	else
		drm_atomic_helper_plane_destroy_state(plane, plane_state);
518 519 520 521 522

	return ret;
}

/**
523
 * drm_plane_helper_update() - Transitional helper for plane update
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
 * @plane: plane object to update
 * @crtc: owning CRTC of owning plane
 * @fb: framebuffer to flip onto plane
 * @crtc_x: x offset of primary plane on crtc
 * @crtc_y: y offset of primary plane on crtc
 * @crtc_w: width of primary plane rectangle on crtc
 * @crtc_h: height of primary plane rectangle on crtc
 * @src_x: x offset of @fb for panning
 * @src_y: y offset of @fb for panning
 * @src_w: width of source rectangle in @fb
 * @src_h: height of source rectangle in @fb
 *
 * Provides a default plane update handler using the atomic plane update
 * functions. It is fully left to the driver to check plane constraints and
 * handle corner-cases like a fully occluded or otherwise invisible plane.
 *
 * This is useful for piecewise transitioning of a driver to the atomic helpers.
 *
 * RETURNS:
 * Zero on success, error code on failure
 */
int drm_plane_helper_update(struct drm_plane *plane, struct drm_crtc *crtc,
			    struct drm_framebuffer *fb,
			    int crtc_x, int crtc_y,
			    unsigned int crtc_w, unsigned int crtc_h,
			    uint32_t src_x, uint32_t src_y,
			    uint32_t src_w, uint32_t src_h)
{
	struct drm_plane_state *plane_state;

	if (plane->funcs->atomic_duplicate_state)
		plane_state = plane->funcs->atomic_duplicate_state(plane);
556 557 558 559
	else {
		if (!plane->state)
			drm_atomic_helper_plane_reset(plane);

560
		plane_state = drm_atomic_helper_plane_duplicate_state(plane);
561
	}
562 563
	if (!plane_state)
		return -ENOMEM;
564
	plane_state->plane = plane;
565 566

	plane_state->crtc = crtc;
567
	drm_atomic_set_fb_for_plane(plane_state, fb);
568 569 570 571 572 573 574 575 576
	plane_state->crtc_x = crtc_x;
	plane_state->crtc_y = crtc_y;
	plane_state->crtc_h = crtc_h;
	plane_state->crtc_w = crtc_w;
	plane_state->src_x = src_x;
	plane_state->src_y = src_y;
	plane_state->src_h = src_h;
	plane_state->src_w = src_w;

577
	return drm_plane_helper_commit(plane, plane_state, plane->fb);
578 579 580 581
}
EXPORT_SYMBOL(drm_plane_helper_update);

/**
582
 * drm_plane_helper_disable() - Transitional helper for plane disable
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
 * @plane: plane to disable
 *
 * Provides a default plane disable handler using the atomic plane update
 * functions. It is fully left to the driver to check plane constraints and
 * handle corner-cases like a fully occluded or otherwise invisible plane.
 *
 * This is useful for piecewise transitioning of a driver to the atomic helpers.
 *
 * RETURNS:
 * Zero on success, error code on failure
 */
int drm_plane_helper_disable(struct drm_plane *plane)
{
	struct drm_plane_state *plane_state;

	/* crtc helpers love to call disable functions for already disabled hw
	 * functions. So cope with that. */
	if (!plane->crtc)
		return 0;

	if (plane->funcs->atomic_duplicate_state)
		plane_state = plane->funcs->atomic_duplicate_state(plane);
605 606 607 608
	else {
		if (!plane->state)
			drm_atomic_helper_plane_reset(plane);

609
		plane_state = drm_atomic_helper_plane_duplicate_state(plane);
610
	}
611 612
	if (!plane_state)
		return -ENOMEM;
613
	plane_state->plane = plane;
614 615

	plane_state->crtc = NULL;
616
	drm_atomic_set_fb_for_plane(plane_state, NULL);
617

618
	return drm_plane_helper_commit(plane, plane_state, plane->fb);
619 620
}
EXPORT_SYMBOL(drm_plane_helper_disable);