Commit bfebd42d authored by Daniel Vetter's avatar Daniel Vetter

drm/modifiers: Enforce consistency between the cap an IN_FORMATS

It's very confusing for userspace to have to deal with inconsistencies
here, and some drivers screwed this up a bit. Most just ommitted the
format list when they meant to say that only linear modifier is
allowed, but some also meant that only implied modifiers are
acceptable (because actually none of the planes registered supported
modifiers).

Now that this is all done consistently across all drivers, document
the rules and enforce it in the drm core.

v2:
- Make the capability a link (Simon)
- Note that all is lost before 5.1.

v3:
- Use drm_WARN_ON (Lyude)
Acked-by: default avatarPekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: default avatarEmil Velikov <emil.velikov@collabora.com>
Reviewed-by: default avatarLyude Paul <lyude@redhat.com>
Acked-by: default avatarMaxime Ripard <maxime@cerno.tech>
Cc: Simon Ser <contact@emersion.fr>
Reviewed-by: default avatarLucas Stach <l.stach@pengutronix.de>
Cc: Pekka Paalanen <pekka.paalanen@collabora.com>
Signed-off-by: default avatarDaniel 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/20210506132343.2873699-1-daniel.vetter@ffwll.ch
parent dda6024b
...@@ -128,6 +128,13 @@ ...@@ -128,6 +128,13 @@
* pairs supported by this plane. The blob is a struct * pairs supported by this plane. The blob is a struct
* drm_format_modifier_blob. Without this property the plane doesn't * drm_format_modifier_blob. Without this property the plane doesn't
* support buffers with modifiers. Userspace cannot change this property. * support buffers with modifiers. Userspace cannot change this property.
*
* Note that userspace can check the &DRM_CAP_ADDFB2_MODIFIERS driver
* capability for general modifier support. If this flag is set then every
* plane will have the IN_FORMATS property, even when it only supports
* DRM_FORMAT_MOD_LINEAR. Before linux kernel release v5.1 there have been
* various bugs in this area with inconsistencies between the capability
* flag and per-plane properties.
*/ */
static unsigned int drm_num_planes(struct drm_device *dev) static unsigned int drm_num_planes(struct drm_device *dev)
...@@ -277,8 +284,14 @@ static int __drm_universal_plane_init(struct drm_device *dev, ...@@ -277,8 +284,14 @@ static int __drm_universal_plane_init(struct drm_device *dev,
format_modifier_count++; format_modifier_count++;
} }
if (format_modifier_count) /* autoset the cap and check for consistency across all planes */
if (format_modifier_count) {
drm_WARN_ON(dev, !config->allow_fb_modifiers &&
!list_empty(&config->plane_list));
config->allow_fb_modifiers = true; config->allow_fb_modifiers = true;
} else {
drm_WARN_ON(dev, config->allow_fb_modifiers);
}
plane->modifier_count = format_modifier_count; plane->modifier_count = format_modifier_count;
plane->modifiers = kmalloc_array(format_modifier_count, plane->modifiers = kmalloc_array(format_modifier_count,
...@@ -360,6 +373,9 @@ static int __drm_universal_plane_init(struct drm_device *dev, ...@@ -360,6 +373,9 @@ static int __drm_universal_plane_init(struct drm_device *dev,
* drm_universal_plane_init() to let the DRM managed resource infrastructure * drm_universal_plane_init() to let the DRM managed resource infrastructure
* take care of cleanup and deallocation. * take care of cleanup and deallocation.
* *
* Drivers supporting modifiers must set @format_modifiers on all their planes,
* even those that only support DRM_FORMAT_MOD_LINEAR.
*
* Returns: * Returns:
* Zero on success, error code on failure. * Zero on success, error code on failure.
*/ */
......
...@@ -909,6 +909,8 @@ struct drm_mode_config { ...@@ -909,6 +909,8 @@ struct drm_mode_config {
* @allow_fb_modifiers: * @allow_fb_modifiers:
* *
* Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call. * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
* Note that drivers should not set this directly, it is automatically
* set in drm_universal_plane_init().
* *
* IMPORTANT: * IMPORTANT:
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment