Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/plane-helper: Add a drm_plane_helper_atomic_check() helper

Provides a default plane state check handler for primary planes that are a
fullscreen scanout buffer and whose state scale and position can't change.

There are some drivers that duplicate this logic in their helpers, such as
simpledrm and ssd130x. Factor out this common code into a plane helper and
make drivers use it.

Suggested-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20220913162307.121503-1-javierm@redhat.com

+33 -41
+30
drivers/gpu/drm/drm_plane_helper.c
··· 278 278 kfree(plane); 279 279 } 280 280 EXPORT_SYMBOL(drm_plane_helper_destroy); 281 + 282 + /** 283 + * drm_plane_helper_atomic_check() - Helper to check plane atomic-state 284 + * @plane: plane to check 285 + * @state: atomic state object 286 + * 287 + * Provides a default plane-state check handler for planes whose atomic-state 288 + * scale and positioning are not expected to change since the plane is always 289 + * a fullscreen scanout buffer. 290 + * 291 + * This is often the case for the primary plane of simple framebuffers. 292 + * 293 + * RETURNS: 294 + * Zero on success, or an errno code otherwise. 295 + */ 296 + int drm_plane_helper_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state) 297 + { 298 + struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane); 299 + struct drm_crtc *new_crtc = new_plane_state->crtc; 300 + struct drm_crtc_state *new_crtc_state = NULL; 301 + 302 + if (new_crtc) 303 + new_crtc_state = drm_atomic_get_new_crtc_state(state, new_crtc); 304 + 305 + return drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state, 306 + DRM_PLANE_NO_SCALING, 307 + DRM_PLANE_NO_SCALING, 308 + false, false); 309 + } 310 + EXPORT_SYMBOL(drm_plane_helper_atomic_check);
+1 -17
drivers/gpu/drm/solomon/ssd130x.c
··· 565 565 return ret; 566 566 } 567 567 568 - static int ssd130x_primary_plane_helper_atomic_check(struct drm_plane *plane, 569 - struct drm_atomic_state *new_state) 570 - { 571 - struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane); 572 - struct drm_crtc *new_crtc = new_plane_state->crtc; 573 - struct drm_crtc_state *new_crtc_state = NULL; 574 - 575 - if (new_crtc) 576 - new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc); 577 - 578 - return drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state, 579 - DRM_PLANE_NO_SCALING, 580 - DRM_PLANE_NO_SCALING, 581 - false, false); 582 - } 583 - 584 568 static void ssd130x_primary_plane_helper_atomic_update(struct drm_plane *plane, 585 569 struct drm_atomic_state *old_state) 586 570 { ··· 607 623 608 624 static const struct drm_plane_helper_funcs ssd130x_primary_plane_helper_funcs = { 609 625 DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, 610 - .atomic_check = ssd130x_primary_plane_helper_atomic_check, 626 + .atomic_check = drm_plane_helper_atomic_check, 611 627 .atomic_update = ssd130x_primary_plane_helper_atomic_update, 612 628 .atomic_disable = ssd130x_primary_plane_helper_atomic_disable, 613 629 };
+1 -24
drivers/gpu/drm/tiny/simpledrm.c
··· 469 469 DRM_FORMAT_MOD_INVALID 470 470 }; 471 471 472 - static int simpledrm_primary_plane_helper_atomic_check(struct drm_plane *plane, 473 - struct drm_atomic_state *new_state) 474 - { 475 - struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane); 476 - struct drm_crtc *new_crtc = new_plane_state->crtc; 477 - struct drm_crtc_state *new_crtc_state = NULL; 478 - int ret; 479 - 480 - if (new_crtc) 481 - new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc); 482 - 483 - ret = drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state, 484 - DRM_PLANE_NO_SCALING, 485 - DRM_PLANE_NO_SCALING, 486 - false, false); 487 - if (ret) 488 - return ret; 489 - else if (!new_plane_state->visible) 490 - return 0; 491 - 492 - return 0; 493 - } 494 - 495 472 static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane, 496 473 struct drm_atomic_state *old_state) 497 474 { ··· 520 543 521 544 static const struct drm_plane_helper_funcs simpledrm_primary_plane_helper_funcs = { 522 545 DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, 523 - .atomic_check = simpledrm_primary_plane_helper_atomic_check, 546 + .atomic_check = drm_plane_helper_atomic_check, 524 547 .atomic_update = simpledrm_primary_plane_helper_atomic_update, 525 548 .atomic_disable = simpledrm_primary_plane_helper_atomic_disable, 526 549 };
+1
include/drm/drm_plane_helper.h
··· 41 41 int drm_plane_helper_disable_primary(struct drm_plane *plane, 42 42 struct drm_modeset_acquire_ctx *ctx); 43 43 void drm_plane_helper_destroy(struct drm_plane *plane); 44 + int drm_plane_helper_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state); 44 45 45 46 #endif