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

drm/atomic-helper: make drm_gem_plane_helper_prepare_fb the default

There's a bunch of atomic drivers who don't do this quite correctly,
luckily most of them aren't in wide use or people would have noticed
the tearing.

By making this the default we avoid the constant audit pain and can
additionally remove a ton of lines from vfuncs for a bit more clarity
in smaller drivers.

While at it complain if there's a cleanup_fb hook but no prepare_fb
hook, because that makes no sense. I haven't found any driver which
violates this, but better safe than sorry.

Subsequent patches will reap the benefits.

v2: It's neither ... nor, not not (Sam)

Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210623162200.3372056-1-daniel.vetter@ffwll.ch

+18 -2
+10
drivers/gpu/drm/drm_atomic_helper.c
··· 35 35 #include <drm/drm_damage_helper.h> 36 36 #include <drm/drm_device.h> 37 37 #include <drm/drm_drv.h> 38 + #include <drm/drm_gem_atomic_helper.h> 38 39 #include <drm/drm_plane_helper.h> 39 40 #include <drm/drm_print.h> 40 41 #include <drm/drm_self_refresh_helper.h> ··· 2404 2403 2405 2404 if (funcs->prepare_fb) { 2406 2405 ret = funcs->prepare_fb(plane, new_plane_state); 2406 + if (ret) 2407 + goto fail; 2408 + } else { 2409 + WARN_ON_ONCE(funcs->cleanup_fb); 2410 + 2411 + if (!drm_core_check_feature(dev, DRIVER_GEM)) 2412 + continue; 2413 + 2414 + ret = drm_gem_plane_helper_prepare_fb(plane, new_plane_state); 2407 2415 if (ret) 2408 2416 goto fail; 2409 2417 }
+3
drivers/gpu/drm/drm_gem_atomic_helper.c
··· 135 135 * GEM based framebuffer drivers which have their buffers always pinned in 136 136 * memory. 137 137 * 138 + * This function is the default implementation for GEM drivers of 139 + * &drm_plane_helper_funcs.prepare_fb if no callback is provided. 140 + * 138 141 * See drm_atomic_set_fence_for_plane() for a discussion of implicit and 139 142 * explicit fencing in atomic modeset updates. 140 143 */
+5 -2
include/drm/drm_modeset_helper_vtables.h
··· 1178 1178 * equivalent functionality should be implemented through private 1179 1179 * members in the plane structure. 1180 1180 * 1181 - * Drivers which always have their buffers pinned should use 1182 - * drm_gem_plane_helper_prepare_fb() for this hook. 1181 + * For GEM drivers who neither have a @prepare_fb nor @cleanup_fb hook 1182 + * set drm_gem_plane_helper_prepare_fb() is called automatically to 1183 + * implement this. Other drivers which need additional plane processing 1184 + * can call drm_gem_plane_helper_prepare_fb() from their @prepare_fb 1185 + * hook. 1183 1186 * 1184 1187 * The helpers will call @cleanup_fb with matching arguments for every 1185 1188 * successful call to this hook.